bcachefs: check bi_parent_subvol in check_inode()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 7 Feb 2024 04:41:46 +0000 (23:41 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 14 Mar 2024 01:22:23 +0000 (21:22 -0400)
check for inodes with a nonzero bi_parent_subvol field that aren't
actually subvolume roots

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

index 5b059b4fff8c06996060b11afaa9abec8dda3208..cb20a3d3f44ae68c7bac4cb8a91c8831e62e879f 100644 (file)
@@ -1009,6 +1009,16 @@ static int check_inode(struct btree_trans *trans,
                        goto err;
        }
 
+       if (fsck_err_on(u.bi_parent_subvol &&
+                       (u.bi_subvol == 0 ||
+                        u.bi_subvol == BCACHEFS_ROOT_SUBVOL),
+                       c, inode_bi_parent_subvol_nonzero,
+                       "inode %llu:%u has subvol %u but nonzero parent subvol %u",
+                       u.bi_inum, k.k->p.snapshot, u.bi_subvol, u.bi_parent_subvol)) {
+               u.bi_parent_subvol = 0;
+               do_update = true;
+       }
+
        if (u.bi_subvol) {
                struct bch_subvolume s;