summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-05-16 23:46:08 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2021-05-19 15:33:47 -0400
commit3a6925a22b73ce28f3a69e263b575ece829625d9 (patch)
tree8151c786e72759c0495b700fd4ac7328af6ec1ef /fs
parent6642826e23b5ef37c93fd3de080f57499d18e5ec (diff)
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/journal.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index 1400774e4c01..52efa463d9f7 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -805,8 +805,10 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
long b;
if (new_fs) {
+ 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;
}
@@ -821,11 +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);
- spin_lock(&c->journal.lock);
}
+ spin_lock(&c->journal.lock);
+
/*
* XXX
* For resize at runtime, we should be writing the new
@@ -851,15 +852,15 @@ 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;
+ 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);
- } else {
- spin_unlock(&c->journal.lock);
percpu_up_read(&c->mark_lock);
-
+ } else {
ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_NOFAIL,
bch2_trans_mark_metadata_bucket(&trans, ca,
b, BCH_DATA_journal,