Commit 8c96cfcc authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: fix more locking bugs

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 8777210b
...@@ -886,7 +886,8 @@ static int bch2_invalidate_buckets(struct bch_fs *c, struct bch_dev *ca) ...@@ -886,7 +886,8 @@ static int bch2_invalidate_buckets(struct bch_fs *c, struct bch_dev *ca)
ret = __bch2_alloc_write_key(c, ca, b, &iter, ret = __bch2_alloc_write_key(c, ca, b, &iter,
must_flush ? &journal_seq : NULL, must_flush ? &journal_seq : NULL,
BTREE_INSERT_GC_LOCK_HELD| BTREE_INSERT_GC_LOCK_HELD|
!fifo_empty(&ca->free_inc) ? BTREE_INSERT_NOWAIT : 0); (!fifo_empty(&ca->free_inc)
? BTREE_INSERT_NOWAIT : 0));
} }
bch2_btree_iter_unlock(&iter); bch2_btree_iter_unlock(&iter);
......
...@@ -1567,7 +1567,8 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter, ...@@ -1567,7 +1567,8 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter,
closure_init_stack(&cl); closure_init_stack(&cl);
/* Hack, because gc and splitting nodes doesn't mix yet: */ /* Hack, because gc and splitting nodes doesn't mix yet: */
if (!down_read_trylock(&c->gc_lock)) { if (!(flags & BTREE_INSERT_GC_LOCK_HELD) &&
!down_read_trylock(&c->gc_lock)) {
if (flags & BTREE_INSERT_NOUNLOCK) if (flags & BTREE_INSERT_NOUNLOCK)
return -EINTR; return -EINTR;
...@@ -1610,7 +1611,8 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter, ...@@ -1610,7 +1611,8 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter,
*/ */
__bch2_btree_iter_downgrade(iter, 1); __bch2_btree_iter_downgrade(iter, 1);
out: out:
up_read(&c->gc_lock); if (!(flags & BTREE_INSERT_GC_LOCK_HELD))
up_read(&c->gc_lock);
closure_sync(&cl); closure_sync(&cl);
return ret; return ret;
} }
...@@ -1688,7 +1690,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c, ...@@ -1688,7 +1690,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c,
} }
/* We're changing btree topology, doesn't mix with gc: */ /* We're changing btree topology, doesn't mix with gc: */
if (!down_read_trylock(&c->gc_lock)) if (!(flags & BTREE_INSERT_GC_LOCK_HELD) &&
!down_read_trylock(&c->gc_lock))
goto err_cycle_gc_lock; goto err_cycle_gc_lock;
if (!bch2_btree_iter_upgrade(iter, U8_MAX, if (!bch2_btree_iter_upgrade(iter, U8_MAX,
...@@ -1748,7 +1751,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c, ...@@ -1748,7 +1751,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c,
bch2_btree_update_done(as); bch2_btree_update_done(as);
up_read(&c->gc_lock); if (!(flags & BTREE_INSERT_GC_LOCK_HELD))
up_read(&c->gc_lock);
out: out:
bch2_btree_iter_verify_locks(iter); bch2_btree_iter_verify_locks(iter);
...@@ -1779,7 +1783,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c, ...@@ -1779,7 +1783,8 @@ void __bch2_foreground_maybe_merge(struct bch_fs *c,
err_unlock: err_unlock:
six_unlock_intent(&m->lock); six_unlock_intent(&m->lock);
up_read(&c->gc_lock); if (!(flags & BTREE_INSERT_GC_LOCK_HELD))
up_read(&c->gc_lock);
err: err:
BUG_ON(ret == -EAGAIN && (flags & BTREE_INSERT_NOUNLOCK)); BUG_ON(ret == -EAGAIN && (flags & BTREE_INSERT_NOUNLOCK));
......
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