bcachefs: Don't mark superblocks past end of usable space
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 9 Jun 2021 02:50:30 +0000 (22:50 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:05 +0000 (17:09 -0400)
bcachefs-tools recently started putting a backup superblock at the end
of the device. This causes a problem if the bucket size doesn't divide
the device size - but we can fix it by just skipping marking that part.

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

index c9e2997..db8c3b7 100644 (file)
@@ -635,6 +635,12 @@ void bch2_mark_metadata_bucket(struct bch_fs *c, struct bch_dev *ca,
        BUG_ON(type != BCH_DATA_sb &&
               type != BCH_DATA_journal);
 
+       /*
+        * Backup superblock might be past the end of our normal usable space:
+        */
+       if (b >= ca->mi.nbuckets)
+               return;
+
        preempt_disable();
 
        if (likely(c)) {
@@ -2088,6 +2094,12 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
        };
        int ret = 0;
 
+       /*
+        * Backup superblock might be past the end of our normal usable space:
+        */
+       if (b >= ca->mi.nbuckets)
+               return 0;
+
        a = bch2_trans_start_alloc_update(trans, &iter, &ptr, &u);
        if (IS_ERR(a))
                return PTR_ERR(a);
index ef7322a..619cfdc 100644 (file)
@@ -1826,6 +1826,11 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
                goto err;
        }
 
+       ret = bch2_trans_mark_dev_sb(c, ca);
+       if (ret) {
+               goto err;
+       }
+
        mutex_lock(&c->sb_lock);
        mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
        mi->nbuckets = cpu_to_le64(nbuckets);