Commit 0e49d3ff authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix locking in __bch2_trans_mark_dev_sb()

We run this in full RW mode now, so we have to guard against the
superblock buffer being reallocated.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 99c87fe0
...@@ -741,12 +741,9 @@ static int bch2_gc_btrees(struct bch_fs *c) ...@@ -741,12 +741,9 @@ static int bch2_gc_btrees(struct bch_fs *c)
static int bch2_mark_superblocks(struct bch_fs *c) static int bch2_mark_superblocks(struct bch_fs *c)
{ {
mutex_lock(&c->sb_lock);
gc_pos_set(c, gc_phase(GC_PHASE_sb)); gc_pos_set(c, gc_phase(GC_PHASE_sb));
int ret = bch2_trans_mark_dev_sbs_flags(c, BTREE_TRIGGER_gc); return bch2_trans_mark_dev_sbs_flags(c, BTREE_TRIGGER_gc);
mutex_unlock(&c->sb_lock);
return ret;
} }
static void bch2_gc_free(struct bch_fs *c) static void bch2_gc_free(struct bch_fs *c)
......
...@@ -915,7 +915,6 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans, ...@@ -915,7 +915,6 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
enum bch_data_type type, enum bch_data_type type,
unsigned sectors) unsigned sectors)
{ {
struct bch_fs *c = trans->c;
struct btree_iter iter; struct btree_iter iter;
int ret = 0; int ret = 0;
...@@ -1046,13 +1045,18 @@ static int bch2_trans_mark_metadata_sectors(struct btree_trans *trans, ...@@ -1046,13 +1045,18 @@ static int bch2_trans_mark_metadata_sectors(struct btree_trans *trans,
static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, struct bch_dev *ca, static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, struct bch_dev *ca,
enum btree_iter_update_trigger_flags flags) enum btree_iter_update_trigger_flags flags)
{ {
struct bch_sb_layout *layout = &ca->disk_sb.sb->layout; struct bch_fs *c = trans->c;
mutex_lock(&c->sb_lock);
struct bch_sb_layout layout = ca->disk_sb.sb->layout;
mutex_unlock(&c->sb_lock);
u64 bucket = 0; u64 bucket = 0;
unsigned i, bucket_sectors = 0; unsigned i, bucket_sectors = 0;
int ret; int ret;
for (i = 0; i < layout->nr_superblocks; i++) { for (i = 0; i < layout.nr_superblocks; i++) {
u64 offset = le64_to_cpu(layout->sb_offset[i]); u64 offset = le64_to_cpu(layout.sb_offset[i]);
if (offset == BCH_SB_SECTOR) { if (offset == BCH_SB_SECTOR) {
ret = bch2_trans_mark_metadata_sectors(trans, ca, ret = bch2_trans_mark_metadata_sectors(trans, ca,
...@@ -1063,7 +1067,7 @@ static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, struct bch_dev *c ...@@ -1063,7 +1067,7 @@ static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, struct bch_dev *c
} }
ret = bch2_trans_mark_metadata_sectors(trans, ca, offset, ret = bch2_trans_mark_metadata_sectors(trans, ca, offset,
offset + (1 << layout->sb_max_size_bits), offset + (1 << layout.sb_max_size_bits),
BCH_DATA_sb, &bucket, &bucket_sectors, flags); BCH_DATA_sb, &bucket, &bucket_sectors, flags);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment