]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Silence some fsck errors when reconstructing alloc info
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 12 Jul 2022 01:06:52 +0000 (21:06 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:35 +0000 (17:09 -0400)
There's no need to print fsck errors for errors that are expected, and
the user has already opted to repair.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_background.c
fs/bcachefs/btree_gc.c

index f4457d62d75e1f7ab5c57c8393b399ab55a63372..a511ab9e4e7c9fe9c7cbd2639b83ecb21c631bca 100644 (file)
@@ -652,12 +652,13 @@ static int bch2_check_alloc_key(struct btree_trans *trans,
        if (ret)
                goto err;
 
-       if (fsck_err_on(k.k->type != discard_key_type, c,
-                       "incorrect key in need_discard btree (got %s should be %s)\n"
-                       "  %s",
-                       bch2_bkey_types[k.k->type],
-                       bch2_bkey_types[discard_key_type],
-                       (bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
+       if (k.k->type != discard_key_type &&
+           (c->opts.reconstruct_alloc ||
+            fsck_err(c, "incorrect key in need_discard btree (got %s should be %s)\n"
+                     "  %s",
+                     bch2_bkey_types[k.k->type],
+                     bch2_bkey_types[discard_key_type],
+                     (bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf)))) {
                struct bkey_i *update =
                        bch2_trans_kmalloc(trans, sizeof(*update));
 
@@ -679,13 +680,14 @@ static int bch2_check_alloc_key(struct btree_trans *trans,
        if (ret)
                goto err;
 
-       if (fsck_err_on(k.k->type != freespace_key_type, c,
-                       "incorrect key in freespace btree (got %s should be %s)\n"
-                       "  %s",
-                       bch2_bkey_types[k.k->type],
-                       bch2_bkey_types[freespace_key_type],
-                       (printbuf_reset(&buf),
-                        bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
+       if (k.k->type != freespace_key_type &&
+           (c->opts.reconstruct_alloc ||
+            fsck_err(c, "incorrect key in freespace btree (got %s should be %s)\n"
+                     "  %s",
+                     bch2_bkey_types[k.k->type],
+                     bch2_bkey_types[freespace_key_type],
+                     (printbuf_reset(&buf),
+                      bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf)))) {
                struct bkey_i *update =
                        bch2_trans_kmalloc(trans, sizeof(*update));
 
index 1499885d899f33e6cf589d162df743ccf681686f..8be1c9f2664d71779ce78736c0ba6a8ad2823183 100644 (file)
@@ -564,7 +564,8 @@ static int bch2_check_fix_ptrs(struct bch_fs *c, enum btree_id btree_id,
                struct bucket *g = PTR_GC_BUCKET(ca, &p.ptr);
                enum bch_data_type data_type = bch2_bkey_ptr_data_type(*k, &entry->ptr);
 
-               if (fsck_err_on(!g->gen_valid, c,
+               if (c->opts.reconstruct_alloc ||
+                   fsck_err_on(!g->gen_valid, c,
                                "bucket %u:%zu data type %s ptr gen %u missing in alloc btree\n"
                                "while marking %s",
                                p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
@@ -1176,29 +1177,28 @@ static int bch2_gc_done(struct bch_fs *c,
 {
        struct bch_dev *ca = NULL;
        struct printbuf buf = PRINTBUF;
-       bool verify = !metadata_only && (!initial ||
-                      (c->sb.compat & (1ULL << BCH_COMPAT_alloc_info)));
+       bool verify = !metadata_only &&
+               !c->opts.reconstruct_alloc &&
+               (!initial || (c->sb.compat & (1ULL << BCH_COMPAT_alloc_info)));
        unsigned i, dev;
        int ret = 0;
 
        percpu_down_write(&c->mark_lock);
 
 #define copy_field(_f, _msg, ...)                                      \
-       if (dst->_f != src->_f) {                                       \
-               if (verify)                                             \
-                       fsck_err(c, _msg ": got %llu, should be %llu"   \
-                               , ##__VA_ARGS__, dst->_f, src->_f);     \
-               dst->_f = src->_f;                                      \
-       }
+       if (dst->_f != src->_f &&                                       \
+           (!verify ||                                                 \
+            fsck_err(c, _msg ": got %llu, should be %llu"              \
+                     , ##__VA_ARGS__, dst->_f, src->_f)))              \
+               dst->_f = src->_f
 #define copy_stripe_field(_f, _msg, ...)                               \
-       if (dst->_f != src->_f) {                                       \
-               if (verify)                                             \
-                       fsck_err(c, "stripe %zu has wrong "_msg         \
-                               ": got %u, should be %u",               \
-                               iter.pos, ##__VA_ARGS__,                \
-                               dst->_f, src->_f);                      \
-               dst->_f = src->_f;                                      \
-       }
+       if (dst->_f != src->_f &&                                       \
+           (!verify ||                                                 \
+            fsck_err(c, "stripe %zu has wrong "_msg                    \
+                     ": got %u, should be %u",                         \
+                     iter.pos, ##__VA_ARGS__,                          \
+                     dst->_f, src->_f)))                               \
+               dst->_f = src->_f
 #define copy_dev_field(_f, _msg, ...)                                  \
        copy_field(_f, "dev %u has wrong " _msg, dev, ##__VA_ARGS__)
 #define copy_fs_field(_f, _msg, ...)                                   \
@@ -1376,7 +1376,8 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
                return 0;
 
 #define copy_bucket_field(_f)                                          \
-       if (fsck_err_on(new._f != gc._f, c,                             \
+       if (c->opts.reconstruct_alloc ||                                \
+           fsck_err_on(new._f != gc._f, c,                             \
                        "bucket %llu:%llu gen %u data type %s has wrong " #_f   \
                        ": got %u, should be %u",                       \
                        iter->pos.inode, iter->pos.offset,              \