summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-01-24 20:25:40 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:15 -0400
commit3e0745e28363c1675a05775425312c049d5857b3 (patch)
treeafc9b3624a8c4ee3e168d9f9b70600a9b6459653
parent42b72e0ba226fa15dda0fb9e9f1646a1ae5d03fd (diff)
downloadlwn-3e0745e28363c1675a05775425312c049d5857b3.tar.gz
lwn-3e0745e28363c1675a05775425312c049d5857b3.zip
bcachefs: initialize fs usage summary in recovery
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/buckets.c27
-rw-r--r--fs/bcachefs/buckets.h1
-rw-r--r--fs/bcachefs/recovery.c8
-rw-r--r--fs/bcachefs/super.c9
4 files changed, 42 insertions, 3 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index d919c1cacee5..f65132a0ebf4 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -114,6 +114,33 @@ void bch2_bucket_seq_cleanup(struct bch_fs *c)
}
}
+void bch2_fs_usage_initialize(struct bch_fs *c)
+{
+ struct bch_fs_usage *usage;
+ unsigned i, nr;
+
+ percpu_down_write(&c->mark_lock);
+ nr = sizeof(struct bch_fs_usage) / sizeof(u64) + c->replicas.nr;
+ usage = (void *) bch2_acc_percpu_u64s((void *) c->usage[0], nr);
+
+ for (i = 0; i < c->replicas.nr; i++) {
+ struct bch_replicas_entry *e =
+ cpu_replicas_entry(&c->replicas, i);
+
+ switch (e->data_type) {
+ case BCH_DATA_BTREE:
+ case BCH_DATA_USER:
+ usage->s.data += usage->data[i];
+ break;
+ case BCH_DATA_CACHED:
+ usage->s.cached += usage->data[i];
+ break;
+ }
+ }
+
+ percpu_up_write(&c->mark_lock);
+}
+
#define bch2_usage_read_raw(_stats) \
({ \
typeof(*this_cpu_ptr(_stats)) _acc; \
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h
index ee8c9e9a1f23..e5b9d5cb1215 100644
--- a/fs/bcachefs/buckets.h
+++ b/fs/bcachefs/buckets.h
@@ -248,6 +248,7 @@ static inline u64 bch2_fs_sectors_free(struct bch_fs *c)
/* key/bucket marking: */
void bch2_bucket_seq_cleanup(struct bch_fs *);
+void bch2_fs_usage_initialize(struct bch_fs *);
void bch2_invalidate_bucket(struct bch_fs *, struct bch_dev *,
size_t, struct bucket_mark *);
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 6349c394be45..a9b8d565c82f 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -6,6 +6,7 @@
#include "btree_update.h"
#include "btree_update_interior.h"
#include "btree_io.h"
+#include "buckets.h"
#include "dirent.h"
#include "ec.h"
#include "error.h"
@@ -251,6 +252,8 @@ int bch2_fs_recovery(struct bch_fs *c)
}
}
+ bch2_fs_usage_initialize(c);
+
for (i = 0; i < BTREE_ID_NR; i++) {
struct btree_root *r = &c->btree_roots[i];
@@ -384,6 +387,11 @@ int bch2_fs_initialize(struct bch_fs *c)
bch_notice(c, "initializing new filesystem");
+ mutex_lock(&c->sb_lock);
+ for_each_online_member(ca, c, i)
+ bch2_mark_dev_superblock(c, ca, 0);
+ mutex_unlock(&c->sb_lock);
+
set_bit(BCH_FS_ALLOC_READ_DONE, &c->flags);
for (i = 0; i < BTREE_ID_NR; i++)
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index 8a5ee2835bbd..29cb12d841e7 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -1071,9 +1071,12 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
if (ret)
return ret;
- mutex_lock(&c->sb_lock);
- bch2_mark_dev_superblock(ca->fs, ca, 0);
- mutex_unlock(&c->sb_lock);
+ if (test_bit(BCH_FS_ALLOC_READ_DONE, &c->flags) &&
+ !percpu_u64_get(&ca->usage[0]->buckets[BCH_DATA_SB])) {
+ mutex_lock(&c->sb_lock);
+ bch2_mark_dev_superblock(ca->fs, ca, 0);
+ mutex_unlock(&c->sb_lock);
+ }
bch2_dev_sysfs_online(c, ca);