Skip to content

Commit b938d3c

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_fsck_rename_dirent() for casefold
bch2_fsck_renamed_dirent was creating bch_dirent keys open-coded - but we need to use the appropriate helper, if the directory is casefolded. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 35c1f13 commit b938d3c

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

fs/bcachefs/fsck.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,10 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
21842184
*hash_info = bch2_hash_info_init(c, &i->inode);
21852185
dir->first_this_inode = false;
21862186

2187+
#ifdef CONFIG_UNICODE
2188+
hash_info->cf_encoding = bch2_inode_casefold(c, &i->inode) ? c->cf_encoding : NULL;
2189+
#endif
2190+
21872191
ret = bch2_str_hash_check_key(trans, s, &bch2_dirent_hash_desc, hash_info,
21882192
iter, k, need_second_pass);
21892193
if (ret < 0)

fs/bcachefs/str_hash.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static noinline int fsck_rename_dirent(struct btree_trans *trans,
3939
bool *updated_before_k_pos)
4040
{
4141
struct qstr old_name = bch2_dirent_get_name(old);
42-
struct bkey_i_dirent *new = bch2_trans_kmalloc(trans, bkey_bytes(old.k) + 32);
42+
struct bkey_i_dirent *new = bch2_trans_kmalloc(trans, BKEY_U64s_MAX * sizeof(u64));
4343
int ret = PTR_ERR_OR_ZERO(new);
4444
if (ret)
4545
return ret;
@@ -48,20 +48,27 @@ static noinline int fsck_rename_dirent(struct btree_trans *trans,
4848
dirent_copy_target(new, old);
4949
new->k.p = old.k->p;
5050

51+
char *renamed_buf = bch2_trans_kmalloc(trans, old_name.len + 20);
52+
ret = PTR_ERR_OR_ZERO(renamed_buf);
53+
if (ret)
54+
return ret;
55+
5156
for (unsigned i = 0; i < 1000; i++) {
52-
unsigned len = sprintf(new->v.d_name, "%.*s.fsck_renamed-%u",
53-
old_name.len, old_name.name, i);
54-
unsigned u64s = BKEY_U64s + dirent_val_u64s(len, 0);
57+
new->k.u64s = BKEY_U64s_MAX;
5558

56-
if (u64s > U8_MAX)
57-
return -EINVAL;
59+
struct qstr renamed_name = (struct qstr) QSTR_INIT(renamed_buf,
60+
sprintf(renamed_buf, "%.*s.fsck_renamed-%u",
61+
old_name.len, old_name.name, i));
5862

59-
new->k.u64s = u64s;
63+
ret = bch2_dirent_init_name(new, hash_info, &renamed_name, NULL);
64+
if (ret)
65+
return ret;
6066

6167
ret = bch2_hash_set_in_snapshot(trans, bch2_dirent_hash_desc, hash_info,
6268
(subvol_inum) { 0, old.k->p.inode },
6369
old.k->p.snapshot, &new->k_i,
64-
BTREE_UPDATE_internal_snapshot_node);
70+
BTREE_UPDATE_internal_snapshot_node|
71+
STR_HASH_must_create);
6572
if (ret && !bch2_err_matches(ret, EEXIST))
6673
break;
6774
if (!ret) {

fs/bcachefs/super.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,12 @@ int bch2_fs_start(struct bch_fs *c)
11481148

11491149
print_mount_opts(c);
11501150

1151-
if (IS_ENABLED(CONFIG_UNICODE))
1152-
bch_info(c, "Using encoding defined by superblock: utf8-%u.%u.%u",
1153-
unicode_major(BCH_FS_DEFAULT_UTF8_ENCODING),
1154-
unicode_minor(BCH_FS_DEFAULT_UTF8_ENCODING),
1155-
unicode_rev(BCH_FS_DEFAULT_UTF8_ENCODING));
1151+
#ifdef CONFIG_UNICODE
1152+
bch_info(c, "Using encoding defined by superblock: utf8-%u.%u.%u",
1153+
unicode_major(BCH_FS_DEFAULT_UTF8_ENCODING),
1154+
unicode_minor(BCH_FS_DEFAULT_UTF8_ENCODING),
1155+
unicode_rev(BCH_FS_DEFAULT_UTF8_ENCODING));
1156+
#endif
11561157

11571158
if (!bch2_fs_may_start(c))
11581159
return bch_err_throw(c, insufficient_devices_to_start);

0 commit comments

Comments
 (0)