diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-05-16 23:46:08 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:03 -0400 |
commit | 6ebe32b94c77f80aca235e476bad321ecc355035 (patch) | |
tree | 987e1292fe45b9c27ab901993ba1af0c12afbfdf /fs/bcachefs | |
parent | d125615a4e22194dff9cecd12ec5a608f8c0f920 (diff) | |
download | lwn-6ebe32b94c77f80aca235e476bad321ecc355035.tar.gz lwn-6ebe32b94c77f80aca235e476bad321ecc355035.zip |
bcachefs: Fix locking in __bch2_set_nr_journal_buckets()
We weren't holding mark_lock correctly - it's needed for the new_fs
path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs')
-rw-r--r-- | fs/bcachefs/journal.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index a7cc0b167072..7cbea06f57fd 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -804,8 +804,11 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr, long b; if (new_fs) { + if (c) + percpu_down_read(&c->mark_lock); b = bch2_bucket_alloc_new_fs(ca); if (b < 0) { + percpu_up_read(&c->mark_lock); ret = -ENOSPC; goto err; } @@ -820,10 +823,10 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr, } b = sector_to_bucket(ca, ob->ptr.offset); + } - percpu_down_read(&c->mark_lock); + if (c) spin_lock(&c->journal.lock); - } /* * XXX @@ -850,15 +853,17 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr, if (pos <= ja->cur_idx) ja->cur_idx = (ja->cur_idx + 1) % ja->nr; + if (c) + spin_unlock(&c->journal.lock); + if (new_fs) { bch2_mark_metadata_bucket(c, ca, b, BCH_DATA_journal, ca->mi.bucket_size, gc_phase(GC_PHASE_SB), 0); + if (c) + percpu_up_read(&c->mark_lock); } else { - spin_unlock(&c->journal.lock); - percpu_up_read(&c->mark_lock); - ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_NOFAIL, bch2_trans_mark_metadata_bucket(&trans, ca, b, BCH_DATA_journal, |