]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: fsck_err()s don't need to manually check c->sb.version anymore
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 4 Jan 2024 04:29:02 +0000 (23:29 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 04:24:21 +0000 (23:24 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/backpointers.c
fs/bcachefs/fs-common.c
fs/bcachefs/fsck.c
fs/bcachefs/reflink.c
fs/bcachefs/sb-downgrade.c
fs/bcachefs/sb-errors_types.h
fs/bcachefs/snapshot.c

index f7fd534b85ed43e414494e87b71c358f0d00a304..a09b9d00226a4e1dd510c0c097ac59e7cb7d3c77 100644 (file)
@@ -1232,9 +1232,6 @@ int bch2_check_alloc_hole_bucket_gens(struct btree_trans *trans,
        unsigned i, gens_offset, gens_end_offset;
        int ret;
 
-       if (c->sb.version < bcachefs_metadata_version_bucket_gens)
-               return 0;
-
        bch2_btree_iter_set_pos(bucket_gens_iter, alloc_gens_pos(start, &gens_offset));
 
        k = bch2_btree_iter_peek_slot(bucket_gens_iter);
index a97fc2b61ee2dc48e64180b253064a750f669381..e358a2ffffdea48c80eee18ab299cd7103d72991 100644 (file)
@@ -467,8 +467,7 @@ missing:
        prt_printf(&buf, "\nbp pos ");
        bch2_bpos_to_text(&buf, bp_iter.pos);
 
-       if (c->sb.version_upgrade_complete < bcachefs_metadata_version_backpointers ||
-           c->opts.reconstruct_alloc ||
+       if (c->opts.reconstruct_alloc ||
            fsck_err(c, ptr_to_missing_backpointer, "%s", buf.buf))
                ret = bch2_bucket_backpointer_mod(trans, bucket, bp, orig_k, true);
 
index 4496cf91a4c17bcde4e4a934eb0475007ff1311c..1c1ea0f0c692a6fdd4c262ef184bbcdda32d154f 100644 (file)
@@ -166,10 +166,8 @@ int bch2_create_trans(struct btree_trans *trans,
                if (ret)
                        goto err;
 
-               if (c->sb.version >= bcachefs_metadata_version_inode_backpointers) {
-                       new_inode->bi_dir               = dir_u->bi_inum;
-                       new_inode->bi_dir_offset        = dir_offset;
-               }
+               new_inode->bi_dir               = dir_u->bi_inum;
+               new_inode->bi_dir_offset        = dir_offset;
        }
 
        inode_iter.flags &= ~BTREE_ITER_ALL_SNAPSHOTS;
@@ -228,10 +226,8 @@ int bch2_link_trans(struct btree_trans *trans,
        if (ret)
                goto err;
 
-       if (c->sb.version >= bcachefs_metadata_version_inode_backpointers) {
-               inode_u->bi_dir         = dir.inum;
-               inode_u->bi_dir_offset  = dir_offset;
-       }
+       inode_u->bi_dir         = dir.inum;
+       inode_u->bi_dir_offset  = dir_offset;
 
        ret =   bch2_inode_write(trans, &dir_iter, dir_u) ?:
                bch2_inode_write(trans, &inode_iter, inode_u);
@@ -414,21 +410,19 @@ int bch2_rename_trans(struct btree_trans *trans,
                        goto err;
        }
 
-       if (c->sb.version >= bcachefs_metadata_version_inode_backpointers) {
-               src_inode_u->bi_dir             = dst_dir_u->bi_inum;
-               src_inode_u->bi_dir_offset      = dst_offset;
+       src_inode_u->bi_dir             = dst_dir_u->bi_inum;
+       src_inode_u->bi_dir_offset      = dst_offset;
 
-               if (mode == BCH_RENAME_EXCHANGE) {
-                       dst_inode_u->bi_dir             = src_dir_u->bi_inum;
-                       dst_inode_u->bi_dir_offset      = src_offset;
-               }
+       if (mode == BCH_RENAME_EXCHANGE) {
+               dst_inode_u->bi_dir             = src_dir_u->bi_inum;
+               dst_inode_u->bi_dir_offset      = src_offset;
+       }
 
-               if (mode == BCH_RENAME_OVERWRITE &&
-                   dst_inode_u->bi_dir         == dst_dir_u->bi_inum &&
-                   dst_inode_u->bi_dir_offset  == src_offset) {
-                       dst_inode_u->bi_dir             = 0;
-                       dst_inode_u->bi_dir_offset      = 0;
-               }
+       if (mode == BCH_RENAME_OVERWRITE &&
+           dst_inode_u->bi_dir         == dst_dir_u->bi_inum &&
+           dst_inode_u->bi_dir_offset  == src_offset) {
+               dst_inode_u->bi_dir             = 0;
+               dst_inode_u->bi_dir_offset      = 0;
        }
 
        if (mode == BCH_RENAME_OVERWRITE) {
index de1617ec1b59cb86e5202521b8d169fe8932640a..4f0ecd60567570b7364cef517225ea0e3dfa5575 100644 (file)
@@ -870,8 +870,7 @@ static int check_inode(struct btree_trans *trans,
                return 0;
        }
 
-       if (u.bi_flags & BCH_INODE_unlinked &&
-           c->sb.version >= bcachefs_metadata_version_deleted_inodes) {
+       if (u.bi_flags & BCH_INODE_unlinked) {
                ret = check_inode_deleted_list(trans, k.k->p);
                if (ret < 0)
                        return ret;
@@ -1594,13 +1593,12 @@ static int check_dirent_target(struct btree_trans *trans,
                d = dirent_i_to_s_c(n);
        }
 
-       if (d.v->d_type == DT_SUBVOL &&
-           target->bi_parent_subvol != le32_to_cpu(d.v->d_parent_subvol) &&
-           (c->sb.version < bcachefs_metadata_version_subvol_dirent ||
-            fsck_err(c, dirent_d_parent_subvol_wrong,
-                     "dirent has wrong d_parent_subvol field: got %u, should be %u",
-                     le32_to_cpu(d.v->d_parent_subvol),
-                     target->bi_parent_subvol))) {
+       if (fsck_err_on(d.v->d_type == DT_SUBVOL &&
+                       target->bi_parent_subvol != le32_to_cpu(d.v->d_parent_subvol),
+                       c, dirent_d_parent_subvol_wrong,
+                       "dirent has wrong d_parent_subvol field: got %u, should be %u",
+                       le32_to_cpu(d.v->d_parent_subvol),
+                       target->bi_parent_subvol)) {
                n = bch2_trans_kmalloc(trans, bkey_bytes(d.k));
                ret = PTR_ERR_OR_ZERO(n);
                if (ret)
index e1d1bcb2a4757b13b9a43a9d2905dccf035d3b54..b24b71bc4e60956917a7a90008357899e4325469 100644 (file)
@@ -34,15 +34,14 @@ int bch2_reflink_p_invalid(struct bch_fs *c, struct bkey_s_c k,
                           struct printbuf *err)
 {
        struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
+       int ret = 0;
 
-       if (c->sb.version >= bcachefs_metadata_version_reflink_p_fix &&
-           le64_to_cpu(p.v->idx) < le32_to_cpu(p.v->front_pad)) {
-               prt_printf(err, "idx < front_pad (%llu < %u)",
-                      le64_to_cpu(p.v->idx), le32_to_cpu(p.v->front_pad));
-               return -EINVAL;
-       }
-
-       return 0;
+       bkey_fsck_err_on(le64_to_cpu(p.v->idx) < le32_to_cpu(p.v->front_pad),
+                        c, err, reflink_p_front_pad_bad,
+                        "idx < front_pad (%llu < %u)",
+                        le64_to_cpu(p.v->idx), le32_to_cpu(p.v->front_pad));
+fsck_err:
+       return ret;
 }
 
 void bch2_reflink_p_to_text(struct printbuf *out, struct bch_fs *c,
index b8e70108793a98d0f33c62955e8171194df4cf13..441dcb1bf160e917d531d1a5ea955cf0238f0844 100644 (file)
@@ -38,7 +38,9 @@
        x(snapshot_trees,                                       \
          RECOVERY_PASS_ALL_FSCK)                               \
        x(snapshot_skiplists,                                   \
-         BIT_ULL(BCH_RECOVERY_PASS_check_snapshots))           \
+         BIT_ULL(BCH_RECOVERY_PASS_check_snapshots),           \
+         BCH_FSCK_ERR_snapshot_bad_depth,                      \
+         BCH_FSCK_ERR_snapshot_bad_skiplist)                   \
        x(deleted_inodes,                                       \
          BIT_ULL(BCH_RECOVERY_PASS_check_inodes),              \
          BCH_FSCK_ERR_unlinked_inode_not_on_deleted_list)      \
index e7be1f9bdaabb39190e9d598683ae5fc171a14b6..c08aacdfd073c203e44a072363c94e89dd93eec8 100644 (file)
        x(dir_loop,                                             241)    \
        x(hash_table_key_duplicate,                             242)    \
        x(hash_table_key_wrong_offset,                          243)    \
-       x(unlinked_inode_not_on_deleted_list,                   244)
+       x(unlinked_inode_not_on_deleted_list,                   244)    \
+       x(reflink_p_front_pad_bad,                              245)
 
 enum bch_sb_error_id {
 #define x(t, n) BCH_FSCK_ERR_##t = n,
index b2306fabd1c9492acaa83e811a465adf8caf979c..56af937523ff2a8deda0a5168f45a67533a57da5 100644 (file)
@@ -814,11 +814,10 @@ static int check_snapshot(struct btree_trans *trans,
 
        real_depth = bch2_snapshot_depth(c, parent_id);
 
-       if (le32_to_cpu(s.depth) != real_depth &&
-           (c->sb.version_upgrade_complete < bcachefs_metadata_version_snapshot_skiplists ||
-            fsck_err(c, snapshot_bad_depth,
-                     "snapshot with incorrect depth field, should be %u:\n  %s",
-                     real_depth, (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))) {
+       if (fsck_err_on(le32_to_cpu(s.depth) != real_depth,
+                       c, snapshot_bad_depth,
+                       "snapshot with incorrect depth field, should be %u:\n  %s",
+                       real_depth, (bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
                u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
                ret = PTR_ERR_OR_ZERO(u);
                if (ret)
@@ -832,11 +831,9 @@ static int check_snapshot(struct btree_trans *trans,
        if (ret < 0)
                goto err;
 
-       if (!ret &&
-           (c->sb.version_upgrade_complete < bcachefs_metadata_version_snapshot_skiplists ||
-            fsck_err(c, snapshot_bad_skiplist,
-                     "snapshot with bad skiplist field:\n  %s",
-                     (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))) {
+       if (fsck_err_on(!ret, c, snapshot_bad_skiplist,
+                       "snapshot with bad skiplist field:\n  %s",
+                       (bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
                u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
                ret = PTR_ERR_OR_ZERO(u);
                if (ret)