summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-05-16 23:46:08 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-03 22:51:23 -0400
commit64dc5809e9c38082ac353b1d2de941d33e1d6dbc (patch)
treed95a1851de48041fae9e514de280b23bfbf30489
parent2d652f11118d25ef70faa8dfa1e03c7750e31b61 (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>
-rw-r--r--fs/bcachefs/journal.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index 31c5d236d18e..70d37041180e 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -805,8 +805,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;
}
@@ -821,10 +824,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
@@ -851,15 +854,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,