bcachefs: Don't use inode btree key cache in fsck code
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 8 Mar 2021 02:43:21 +0000 (21:43 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:53 +0000 (17:08 -0400)
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: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fsck.c
fs/bcachefs/inode.c
fs/bcachefs/inode.h

index b2d9d55b19518934e1181db676b9deb10922b2dd..66c9dad2ef3e14e868db1bcbe3d480f237da75d5 100644 (file)
@@ -58,7 +58,7 @@ static int __remove_dirent(struct btree_trans *trans,
        buf[name.len] = '\0';
        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)
                bch_err(c, "remove_dirent: err %i looking up directory inode", ret);
        if (ret)
@@ -126,8 +126,8 @@ static int walk_inode(struct btree_trans *trans,
                      struct inode_walker *w, u64 inum)
 {
        if (inum != w->cur_inum) {
-               int ret = bch2_inode_find_by_inum_trans(trans, inum,
-                                                       &w->inode);
+               int ret = __bch2_inode_find_by_inum_trans(trans, inum,
+                                                         &w->inode, 0);
 
                if (ret && ret != -ENOENT)
                        return ret;
@@ -673,7 +673,7 @@ retry:
                        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)
                        break;
 
@@ -787,7 +787,9 @@ static int check_root(struct bch_fs *c, struct bch_inode_unpacked *root_inode)
 
        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)
                return ret;
 
@@ -834,7 +836,8 @@ static int check_lostfound(struct bch_fs *c,
                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)
                return ret;
 
index 3462e248c9540b9756334a63c904372e163b5b31..8377d39ccc4d2390d14b6a2a89e212ce430cb4a4 100644 (file)
@@ -628,16 +628,19 @@ err:
        return ret;
 }
 
-int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
-                                 struct bch_inode_unpacked *inode)
+int __bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
+                                   struct bch_inode_unpacked *inode,
+                                   unsigned flags)
 {
        struct btree_iter *iter;
        struct bkey_s_c k;
        int ret;
 
        iter = bch2_trans_get_iter(trans, BTREE_ID_INODES,
-                       POS(0, inode_nr), BTREE_ITER_CACHED);
-       k = bch2_btree_iter_peek_cached(iter);
+                       POS(0, inode_nr), flags);
+       k = (flags & BTREE_ITER_TYPE) == BTREE_ITER_CACHED
+               ? bch2_btree_iter_peek_cached(iter)
+               : bch2_btree_iter_peek_slot(iter);
        ret = bkey_err(k);
        if (ret)
                goto err;
@@ -650,6 +653,14 @@ err:
        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,
                            struct bch_inode_unpacked *inode)
 {
index dbdfcf63d07992fc2e0a5a070fd593f3c0e3b404..1caf036ae928fe822a8426fe952ac50774c891b6 100644 (file)
@@ -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_find_by_inum_trans(struct btree_trans *, u64,
+                                   struct bch_inode_unpacked *, unsigned);
 int bch2_inode_find_by_inum_trans(struct btree_trans *, u64,
                                  struct bch_inode_unpacked *);
 int bch2_inode_find_by_inum(struct bch_fs *, u64, struct bch_inode_unpacked *);