diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-11-15 23:02:13 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:17 +0300 |
commit | c714614bd06cc422f56c02475adf03dc618bf385 (patch) | |
tree | 82e12f009dd33d431d66dd19ee3195c8457d4e3e /fs | |
parent | 0a84a066f9a1455ce703850ac5918270d7a4019d (diff) | |
download | linux-c714614bd06cc422f56c02475adf03dc618bf385.tar.xz |
bcachefs: Disk space accounting fix on brand-new fs
The filesystem initialization path first marks superblock and journal
buckets non transactionally, since the btree isn't functional yet. That
path was updating the per-journal-buf percpu counters via
bch2_dev_usage_update(), and updating the wrong set of counters so those
updates didn't get written out until journal entry 4.
The relevant code is going to get significantly rewritten in the future
as we transition away from the in memory bucket array, so this just
hacks around it for now.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/bcachefs.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/buckets.c | 11 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 966e185201d1..077d366961ff 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -495,6 +495,7 @@ struct bch_dev { enum { /* startup: */ + BCH_FS_INITIALIZED, BCH_FS_ALLOC_READ_DONE, BCH_FS_ALLOC_CLEAN, BCH_FS_ALLOCATOR_RUNNING, diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index d4d41646b2e6..c3387689fbb6 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -117,6 +117,8 @@ static inline struct bch_dev_usage *dev_usage_ptr(struct bch_dev *ca, unsigned journal_seq, bool gc) { + BUG_ON(!gc && !journal_seq); + return this_cpu_ptr(gc ? ca->usage_gc : ca->usage[journal_seq & JOURNAL_BUF_MASK]); @@ -142,6 +144,8 @@ static inline struct bch_fs_usage *fs_usage_ptr(struct bch_fs *c, unsigned journal_seq, bool gc) { + BUG_ON(!gc && !journal_seq); + return this_cpu_ptr(gc ? c->usage_gc : c->usage[journal_seq & JOURNAL_BUF_MASK]); @@ -364,6 +368,13 @@ static void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca, struct bch_fs_usage *fs_usage; struct bch_dev_usage *u; + /* + * Hack for bch2_fs_initialize path, where we're first marking sb and + * journal non-transactionally: + */ + if (!journal_seq && !test_bit(BCH_FS_INITIALIZED, &c->flags)) + journal_seq = 1; + percpu_rwsem_assert_held(&c->mark_lock); preempt_disable(); diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 637408d76270..3cc5d8ea743f 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -447,8 +447,16 @@ int bch2_sb_to_fs(struct bch_fs *c, struct bch_sb *src) if (BCH_SB_HAS_ERRORS(c->disk_sb.sb)) set_bit(BCH_FS_ERROR, &c->flags); + else + clear_bit(BCH_FS_ERROR, &c->flags); + if (BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb)) set_bit(BCH_FS_TOPOLOGY_ERROR, &c->flags); + else + clear_bit(BCH_FS_TOPOLOGY_ERROR, &c->flags); + + if (BCH_SB_INITIALIZED(c->disk_sb.sb)) + set_bit(BCH_FS_INITIALIZED, &c->flags); ret = bch2_sb_replicas_to_cpu_replicas(c); if (ret) |