Skip to content

Commit ecd76c5

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_dirent_create_snapshot() for casefolding
bch2_dirent_create_snapshot(), used in fsck, neglected to create a casefolded dirent. Just move this into dirent_create_key(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent 8d5ac18 commit ecd76c5

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

fs/bcachefs/dirent.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,27 @@ static void dirent_init_casefolded_name(struct bkey_i_dirent *dirent,
288288
}
289289

290290
static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans,
291+
const struct bch_hash_info *hash_info,
291292
subvol_inum dir,
292293
u8 type,
293294
const struct qstr *name,
294295
const struct qstr *cf_name,
295296
u64 dst)
296297
{
297298
struct bkey_i_dirent *dirent;
299+
struct qstr _cf_name;
298300

299301
if (name->len > BCH_NAME_MAX)
300302
return ERR_PTR(-ENAMETOOLONG);
301303

304+
if (hash_info->cf_encoding && !cf_name) {
305+
int ret = bch2_casefold(trans, hash_info, name, &_cf_name);
306+
if (ret)
307+
return ERR_PTR(ret);
308+
309+
cf_name = &_cf_name;
310+
}
311+
302312
dirent = dirent_alloc_key(trans, dir, type, name->len, cf_name ? cf_name->len : 0, dst);
303313
if (IS_ERR(dirent))
304314
return dirent;
@@ -324,7 +334,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
324334
struct bkey_i_dirent *dirent;
325335
int ret;
326336

327-
dirent = dirent_create_key(trans, dir_inum, type, name, NULL, dst_inum);
337+
dirent = dirent_create_key(trans, hash_info, dir_inum, type, name, NULL, dst_inum);
328338
ret = PTR_ERR_OR_ZERO(dirent);
329339
if (ret)
330340
return ret;
@@ -333,8 +343,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
333343
dirent->k.p.snapshot = snapshot;
334344

335345
ret = bch2_hash_set_in_snapshot(trans, bch2_dirent_hash_desc, hash_info,
336-
dir_inum, snapshot, &dirent->k_i,
337-
flags|BTREE_UPDATE_internal_snapshot_node);
346+
dir_inum, snapshot, &dirent->k_i, flags);
338347
*dir_offset = dirent->k.p.offset;
339348

340349
return ret;
@@ -344,28 +353,16 @@ int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir,
344353
const struct bch_hash_info *hash_info,
345354
u8 type, const struct qstr *name, u64 dst_inum,
346355
u64 *dir_offset,
347-
u64 *i_size,
348356
enum btree_iter_update_trigger_flags flags)
349357
{
350358
struct bkey_i_dirent *dirent;
351359
int ret;
352360

353-
if (hash_info->cf_encoding) {
354-
struct qstr cf_name;
355-
ret = bch2_casefold(trans, hash_info, name, &cf_name);
356-
if (ret)
357-
return ret;
358-
dirent = dirent_create_key(trans, dir, type, name, &cf_name, dst_inum);
359-
} else {
360-
dirent = dirent_create_key(trans, dir, type, name, NULL, dst_inum);
361-
}
362-
361+
dirent = dirent_create_key(trans, hash_info, dir, type, name, NULL, dst_inum);
363362
ret = PTR_ERR_OR_ZERO(dirent);
364363
if (ret)
365364
return ret;
366365

367-
*i_size += bkey_bytes(&dirent->k);
368-
369366
ret = bch2_hash_set(trans, bch2_dirent_hash_desc, hash_info,
370367
dir, &dirent->k_i, flags);
371368
*dir_offset = dirent->k.p.offset;
@@ -466,7 +463,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
466463
*src_offset = dst_iter.pos.offset;
467464

468465
/* Create new dst key: */
469-
new_dst = dirent_create_key(trans, dst_dir, 0, dst_name,
466+
new_dst = dirent_create_key(trans, dst_hash, dst_dir, 0, dst_name,
470467
dst_hash->cf_encoding ? &dst_name_lookup : NULL, 0);
471468
ret = PTR_ERR_OR_ZERO(new_dst);
472469
if (ret)
@@ -477,7 +474,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
477474

478475
/* Create new src key: */
479476
if (mode == BCH_RENAME_EXCHANGE) {
480-
new_src = dirent_create_key(trans, src_dir, 0, src_name,
477+
new_src = dirent_create_key(trans, src_hash, src_dir, 0, src_name,
481478
src_hash->cf_encoding ? &src_name_lookup : NULL, 0);
482479
ret = PTR_ERR_OR_ZERO(new_src);
483480
if (ret)

fs/bcachefs/dirent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *, u32, u64, u32,
6565
enum btree_iter_update_trigger_flags);
6666
int bch2_dirent_create(struct btree_trans *, subvol_inum,
6767
const struct bch_hash_info *, u8,
68-
const struct qstr *, u64, u64 *, u64 *,
68+
const struct qstr *, u64, u64 *,
6969
enum btree_iter_update_trigger_flags);
7070

7171
static inline unsigned vfs_d_type(unsigned type)

fs/bcachefs/fsck.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
306306
&lostfound_str,
307307
lostfound->bi_inum,
308308
&lostfound->bi_dir_offset,
309+
BTREE_UPDATE_internal_snapshot_node|
309310
STR_HASH_must_create) ?:
310311
bch2_inode_write_flags(trans, &lostfound_iter, lostfound,
311312
BTREE_UPDATE_internal_snapshot_node);
@@ -431,6 +432,7 @@ static int reattach_inode(struct btree_trans *trans, struct bch_inode_unpacked *
431432
&name,
432433
inode->bi_subvol ?: inode->bi_inum,
433434
&inode->bi_dir_offset,
435+
BTREE_UPDATE_internal_snapshot_node|
434436
STR_HASH_must_create);
435437
if (ret) {
436438
bch_err_msg(c, ret, "error creating dirent");

fs/bcachefs/namei.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ int bch2_create_trans(struct btree_trans *trans,
158158
name,
159159
dir_target,
160160
&dir_offset,
161-
&dir_u->bi_size,
162161
STR_HASH_must_create|BTREE_ITER_with_updates) ?:
163162
bch2_inode_write(trans, &dir_iter, dir_u);
164163
if (ret)
@@ -225,7 +224,6 @@ int bch2_link_trans(struct btree_trans *trans,
225224
mode_to_type(inode_u->bi_mode),
226225
name, inum.inum,
227226
&dir_offset,
228-
&dir_u->bi_size,
229227
STR_HASH_must_create);
230228
if (ret)
231229
goto err;

0 commit comments

Comments
 (0)