bcachefs: Fix snapshot_key_missing_inode_snapshot repair
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 13 Jun 2025 22:27:33 +0000 (18:27 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 16 Jun 2025 02:11:56 +0000 (22:11 -0400)
When the inode was a whiteout, we were inserting a new whiteout at the
wrong (old) snapshot.

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

index 68ed69a255e16d07e333d3956f603e6e060a52ec..b80a56e19b403d19e0acb8e9552141eb956f8a04 100644 (file)
@@ -903,17 +903,15 @@ lookup_inode_for_snapshot(struct btree_trans *trans, struct inode_walker *w, str
                         w->last_pos.inode, k.k->p.snapshot, i->inode.bi_snapshot,
                         (bch2_bkey_val_to_text(&buf, c, k),
                          buf.buf))) {
-               struct bch_inode_unpacked new = i->inode;
-               struct bkey_i whiteout;
-
-               new.bi_snapshot = k.k->p.snapshot;
-
                if (!i->whiteout) {
+                       struct bch_inode_unpacked new = i->inode;
+                       new.bi_snapshot = k.k->p.snapshot;
                        ret = __bch2_fsck_write_inode(trans, &new);
                } else {
+                       struct bkey_i whiteout;
                        bkey_init(&whiteout.k);
                        whiteout.k.type = KEY_TYPE_whiteout;
-                       whiteout.k.p = SPOS(0, i->inode.bi_inum, i->inode.bi_snapshot);
+                       whiteout.k.p = SPOS(0, i->inode.bi_inum, k.k->p.snapshot);
                        ret = bch2_btree_insert_nonextent(trans, BTREE_ID_inodes,
                                                          &whiteout,
                                                          BTREE_UPDATE_internal_snapshot_node);