bcachefs: Small check_fix_ptr fixes
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 23 May 2025 18:19:25 +0000 (14:19 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 23 May 2025 23:52:31 +0000 (19:52 -0400)
We don't want to change the bucket gen, on gen mismatch: it's possible
to have multiple btree nodes with different gens in the same bucket that
we want to keep, if we have to recover from btree node scan.

It's also not necessary to set g->gen_valid; add a comment to that
effect.

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

index 8bb6384190c53318db0ee811d832ee9d31a8af60..09eb5a543ae4393e46672eccab49a01f1a7fddb0 100644 (file)
@@ -156,10 +156,14 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
                        g->gen_valid            = true;
                        g->gen                  = p.ptr.gen;
                } else {
+                       /* this pointer will be dropped */
                        *do_update = true;
+                       goto out;
                }
        }
 
+       /* g->gen_valid == true */
+
        if (fsck_err_on(gen_cmp(p.ptr.gen, g->gen) > 0,
                        trans, ptr_gen_newer_than_bucket_gen,
                        "bucket %u:%zu data type %s ptr gen in the future: %u > %u\n"
@@ -172,15 +176,13 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
                if (!p.ptr.cached &&
                    (g->data_type != BCH_DATA_btree ||
                     data_type == BCH_DATA_btree)) {
-                       g->gen_valid            = true;
-                       g->gen                  = p.ptr.gen;
-                       g->data_type            = 0;
+                       g->data_type            = data_type;
                        g->stripe_sectors       = 0;
                        g->dirty_sectors        = 0;
                        g->cached_sectors       = 0;
-               } else {
-                       *do_update = true;
                }
+
+               *do_update = true;
        }
 
        if (fsck_err_on(gen_cmp(g->gen, p.ptr.gen) > BUCKET_GC_GEN_MAX,
@@ -217,9 +219,8 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
                        bch2_data_type_str(data_type),
                        (printbuf_reset(&buf),
                         bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
-               if (data_type == BCH_DATA_btree) {
-                       g->gen_valid            = true;
-                       g->gen                  = p.ptr.gen;
+               if (!p.ptr.cached &&
+                   data_type == BCH_DATA_btree) {
                        g->data_type            = data_type;
                        g->stripe_sectors       = 0;
                        g->dirty_sectors        = 0;