From 114eea75c73dfd95ae529eb841aad0330793f446 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 24 Oct 2021 11:57:47 -0400 Subject: [PATCH] bcachefs: Fix dev accounting after device add 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 Signed-off-by: Kent Overstreet --- fs/bcachefs/super.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index db38d6b0f2ade..d17e4f005b3f1 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -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) -- 2.30.2