Commit fe38b720 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Don't use inode btree key cache in fsck code

We had a cache coherency bug with the btree key cache in the fsck code -
this fixes fsck to be consistent about not using it.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent bcdb4b97
...@@ -58,7 +58,7 @@ static int __remove_dirent(struct btree_trans *trans, ...@@ -58,7 +58,7 @@ static int __remove_dirent(struct btree_trans *trans,
buf[name.len] = '\0'; buf[name.len] = '\0';
name.name = buf; name.name = buf;
ret = bch2_inode_find_by_inum_trans(trans, dir_inum, &dir_inode); ret = __bch2_inode_find_by_inum_trans(trans, dir_inum, &dir_inode, 0);
if (ret && ret != -EINTR) if (ret && ret != -EINTR)
bch_err(c, "remove_dirent: err %i looking up directory inode", ret); bch_err(c, "remove_dirent: err %i looking up directory inode", ret);
if (ret) if (ret)
...@@ -126,8 +126,8 @@ static int walk_inode(struct btree_trans *trans, ...@@ -126,8 +126,8 @@ static int walk_inode(struct btree_trans *trans,
struct inode_walker *w, u64 inum) struct inode_walker *w, u64 inum)
{ {
if (inum != w->cur_inum) { if (inum != w->cur_inum) {
int ret = bch2_inode_find_by_inum_trans(trans, inum, int ret = __bch2_inode_find_by_inum_trans(trans, inum,
&w->inode); &w->inode, 0);
if (ret && ret != -ENOENT) if (ret && ret != -ENOENT)
return ret; return ret;
...@@ -673,7 +673,7 @@ static int check_dirents(struct bch_fs *c) ...@@ -673,7 +673,7 @@ static int check_dirents(struct bch_fs *c)
continue; continue;
} }
ret = bch2_inode_find_by_inum_trans(&trans, d_inum, &target); ret = __bch2_inode_find_by_inum_trans(&trans, d_inum, &target, 0);
if (ret && ret != -ENOENT) if (ret && ret != -ENOENT)
break; break;
...@@ -787,7 +787,9 @@ static int check_root(struct bch_fs *c, struct bch_inode_unpacked *root_inode) ...@@ -787,7 +787,9 @@ static int check_root(struct bch_fs *c, struct bch_inode_unpacked *root_inode)
bch_verbose(c, "checking root directory"); bch_verbose(c, "checking root directory");
ret = bch2_inode_find_by_inum(c, BCACHEFS_ROOT_INO, root_inode); ret = bch2_trans_do(c, NULL, NULL, 0,
__bch2_inode_find_by_inum_trans(&trans, BCACHEFS_ROOT_INO,
root_inode, 0));
if (ret && ret != -ENOENT) if (ret && ret != -ENOENT)
return ret; return ret;
...@@ -834,7 +836,8 @@ static int check_lostfound(struct bch_fs *c, ...@@ -834,7 +836,8 @@ static int check_lostfound(struct bch_fs *c,
goto create_lostfound; goto create_lostfound;
} }
ret = bch2_inode_find_by_inum(c, inum, lostfound_inode); ret = bch2_trans_do(c, NULL, NULL, 0,
__bch2_inode_find_by_inum_trans(&trans, inum, lostfound_inode, 0));
if (ret && ret != -ENOENT) if (ret && ret != -ENOENT)
return ret; return ret;
......
...@@ -628,16 +628,19 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached) ...@@ -628,16 +628,19 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
return ret; return ret;
} }
int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr, int __bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
struct bch_inode_unpacked *inode) struct bch_inode_unpacked *inode,
unsigned flags)
{ {
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
iter = bch2_trans_get_iter(trans, BTREE_ID_INODES, iter = bch2_trans_get_iter(trans, BTREE_ID_INODES,
POS(0, inode_nr), BTREE_ITER_CACHED); POS(0, inode_nr), flags);
k = bch2_btree_iter_peek_cached(iter); k = (flags & BTREE_ITER_TYPE) == BTREE_ITER_CACHED
? bch2_btree_iter_peek_cached(iter)
: bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
goto err; goto err;
...@@ -650,6 +653,14 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr, ...@@ -650,6 +653,14 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
return ret; return ret;
} }
int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
struct bch_inode_unpacked *inode)
{
return __bch2_inode_find_by_inum_trans(trans, inode_nr,
inode, BTREE_ITER_CACHED);
}
int bch2_inode_find_by_inum(struct bch_fs *c, u64 inode_nr, int bch2_inode_find_by_inum(struct bch_fs *c, u64 inode_nr,
struct bch_inode_unpacked *inode) struct bch_inode_unpacked *inode)
{ {
......
...@@ -73,6 +73,8 @@ int bch2_inode_create(struct btree_trans *, struct bch_inode_unpacked *); ...@@ -73,6 +73,8 @@ int bch2_inode_create(struct btree_trans *, struct bch_inode_unpacked *);
int bch2_inode_rm(struct bch_fs *, u64, bool); int bch2_inode_rm(struct bch_fs *, u64, bool);
int __bch2_inode_find_by_inum_trans(struct btree_trans *, u64,
struct bch_inode_unpacked *, unsigned);
int bch2_inode_find_by_inum_trans(struct btree_trans *, u64, int bch2_inode_find_by_inum_trans(struct btree_trans *, u64,
struct bch_inode_unpacked *); struct bch_inode_unpacked *);
int bch2_inode_find_by_inum(struct bch_fs *, u64, struct bch_inode_unpacked *); int bch2_inode_find_by_inum(struct bch_fs *, u64, struct bch_inode_unpacked *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment