bcachefs: fsck: walk_inode() now takes is_whiteout
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 16 Jul 2023 18:19:08 +0000 (14:19 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:07 +0000 (17:10 -0400)
We only want to synthesize an inode for the current snapshot ID for non
whiteouts - this refactoring lets us call walk_inode() earlier and clean
up some control flow.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fsck.c

index aa11f33c2384a136f2eac40efea34e04e470af12..f3e3cf475c2310c7ab96975dab19ae3128e1c0ba 100644 (file)
@@ -675,8 +675,8 @@ static int get_inodes_all_snapshots(struct btree_trans *trans,
 }
 
 static struct inode_walker_entry *
-lookup_inode_for_snapshot(struct bch_fs *c,
-                         struct inode_walker *w, u32 snapshot)
+lookup_inode_for_snapshot(struct bch_fs *c, struct inode_walker *w,
+                         u32 snapshot, bool is_whiteout)
 {
        struct inode_walker_entry *i;
 
@@ -690,7 +690,7 @@ lookup_inode_for_snapshot(struct bch_fs *c,
 found:
        BUG_ON(snapshot > i->snapshot);
 
-       if (snapshot != i->snapshot) {
+       if (snapshot != i->snapshot && !is_whiteout) {
                struct inode_walker_entry new = *i;
                int ret;
 
@@ -712,7 +712,8 @@ found:
 }
 
 static struct inode_walker_entry *walk_inode(struct btree_trans *trans,
-                                            struct inode_walker *w, struct bpos pos)
+                                            struct inode_walker *w, struct bpos pos,
+                                            bool is_whiteout)
 {
        if (w->last_pos.inode != pos.inode) {
                int ret = get_inodes_all_snapshots(trans, w, pos.inode);
@@ -728,7 +729,7 @@ static struct inode_walker_entry *walk_inode(struct btree_trans *trans,
 
        w->last_pos = pos;
 
-       return lookup_inode_for_snapshot(trans->c, w, pos.snapshot);
+       return lookup_inode_for_snapshot(trans->c, w, pos.snapshot, is_whiteout);
 }
 
 static int __get_visible_inodes(struct btree_trans *trans,
@@ -1359,6 +1360,11 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
                extent_ends_reset(extent_ends);
        }
 
+       i = walk_inode(trans, inode, equiv, k.k->type == KEY_TYPE_whiteout);
+       ret = PTR_ERR_OR_ZERO(i);
+       if (ret)
+               goto err;
+
        ret = check_overlapping_extents(trans, s, extent_ends, k, iter);
        if (ret < 0)
                goto err;
@@ -1370,11 +1376,6 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
        if (ret)
                goto err;
 
-       i = walk_inode(trans, inode, equiv);
-       ret = PTR_ERR_OR_ZERO(i);
-       if (ret)
-               goto err;
-
        if (fsck_err_on(!i, c,
                        "extent in missing inode:\n  %s",
                        (printbuf_reset(&buf),
@@ -1682,7 +1683,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
 
        BUG_ON(!iter->path->should_be_locked);
 
-       i = walk_inode(trans, dir, equiv);
+       i = walk_inode(trans, dir, equiv, k.k->type == KEY_TYPE_whiteout);
        ret = PTR_ERR_OR_ZERO(i);
        if (ret < 0)
                goto err;
@@ -1859,7 +1860,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter,
        if (ret)
                return ret;
 
-       i = walk_inode(trans, inode, k.k->p);
+       i = walk_inode(trans, inode, k.k->p, k.k->type == KEY_TYPE_whiteout);
        ret = PTR_ERR_OR_ZERO(i);
        if (ret)
                return ret;