bcachefs: Fix double counting of stripe block counts by GC
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 17 Jan 2021 20:18:11 +0000 (15:18 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:51 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/buckets.c

index 11907ab..95368c9 100644 (file)
@@ -1273,9 +1273,15 @@ static int bch2_mark_stripe(struct bch_fs *c,
                m->blocks_nonempty = 0;
 
                for (i = 0; i < new_s->nr_blocks; i++) {
-                       m->block_sectors[i] =
-                               stripe_blockcount_get(new_s, i);
-                       m->blocks_nonempty += !!m->block_sectors[i];
+                       unsigned s = stripe_blockcount_get(new_s, i);
+
+                       /*
+                        * gc recalculates this field from stripe ptr
+                        * references:
+                        */
+                       if (!gc)
+                               m->block_sectors[i] = s;
+                       m->blocks_nonempty += !!s;
                }
 
                if (gc && old_s)