bcachefs: Fix dev accounting after device add
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 24 Oct 2021 15:57:47 +0000 (11:57 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:14 +0000 (17:09 -0400)
This is a hacky but effective fix to device usage stats for superblock
and journal being wrong on a newly added device (following the comment
that already told us how it needed to be done!)

Reported-by: Chris Webb <chris@arachsys.com>
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/super.c

index db38d6b0f2adeda7c00b2e821a52216cf1a015df..d17e4f005b3f1dbabcb74f673fd20c42fb9b6b94 100644 (file)
@@ -1591,6 +1591,8 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
        struct bch_dev *ca = NULL;
        struct bch_sb_field_members *mi;
        struct bch_member dev_mi;
+       struct bucket_array *buckets;
+       struct bucket *g;
        unsigned dev_idx, nr_devices, u64s;
        int ret;
 
@@ -1694,6 +1696,16 @@ have_slot:
 
        bch2_dev_usage_journal_reserve(c);
 
+       /*
+        * Clear marks before marking transactionally in the btree, so that
+        * per-device accounting gets done correctly:
+        */
+       down_read(&ca->bucket_lock);
+       buckets = bucket_array(ca);
+       for_each_bucket(g, buckets)
+               atomic64_set(&g->_mark.v, 0);
+       up_read(&ca->bucket_lock);
+
        err = "error marking superblock";
        ret = bch2_trans_mark_dev_sb(c, ca);
        if (ret)