bcachefs: initialize fs usage summary in recovery
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
42b72e0ba2
commit
3e0745e283
@ -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; \
|
||||
|
@ -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 *);
|
||||
|
@ -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++)
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user