Skip to content

Commit f402d97

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_readdir() now calls str_hash_check_key()
More self healing code: readdir will now notice if there are dirents hashed incorrectly, and it'll repair them if errors=fix_safe. Signed-off-by: Kent Overstreet <[email protected]>
1 parent a592268 commit f402d97

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

fs/bcachefs/dirent.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,9 @@ static int bch2_dir_emit(struct dir_context *ctx, struct bkey_s_c_dirent d, subv
692692
return !ret;
693693
}
694694

695-
int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx)
695+
int bch2_readdir(struct bch_fs *c, subvol_inum inum,
696+
struct bch_hash_info *hash_info,
697+
struct dir_context *ctx)
696698
{
697699
struct bkey_buf sk;
698700
bch2_bkey_buf_init(&sk);
@@ -710,7 +712,10 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx)
710712
struct bkey_s_c_dirent dirent = bkey_i_to_s_c_dirent(sk.k);
711713

712714
subvol_inum target;
713-
int ret2 = bch2_dirent_read_target(trans, inum, dirent, &target);
715+
716+
int ret2 = bch2_str_hash_check_key(trans, NULL, &bch2_dirent_hash_desc,
717+
hash_info, &iter, k) ?:
718+
bch2_dirent_read_target(trans, inum, dirent, &target);
714719
if (ret2 > 0)
715720
continue;
716721

fs/bcachefs/dirent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ u64 bch2_dirent_lookup(struct bch_fs *, subvol_inum,
9595

9696
int bch2_empty_dir_snapshot(struct btree_trans *, u64, u32, u32);
9797
int bch2_empty_dir_trans(struct btree_trans *, subvol_inum);
98-
int bch2_readdir(struct bch_fs *, subvol_inum, struct dir_context *);
98+
int bch2_readdir(struct bch_fs *, subvol_inum, struct bch_hash_info *, struct dir_context *);
9999

100100
int bch2_fsck_remove_dirent(struct btree_trans *, struct bpos);
101101

fs/bcachefs/fs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,11 +1573,12 @@ static int bch2_vfs_readdir(struct file *file, struct dir_context *ctx)
15731573
{
15741574
struct bch_inode_info *inode = file_bch_inode(file);
15751575
struct bch_fs *c = inode->v.i_sb->s_fs_info;
1576+
struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
15761577

15771578
if (!dir_emit_dots(file, ctx))
15781579
return 0;
15791580

1580-
int ret = bch2_readdir(c, inode_inum(inode), ctx);
1581+
int ret = bch2_readdir(c, inode_inum(inode), &hash, ctx);
15811582

15821583
bch_err_fn(c, ret);
15831584
return bch2_err_class(ret);

0 commit comments

Comments
 (0)