bcachefs: Fix deadlock on nocow locks in data move path
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 2 Jan 2023 22:53:02 +0000 (17:53 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:52 +0000 (17:09 -0400)
commit7ffb6a7ec6712eb1ba84a80137c2f712e67c4171
tree0d05e725b41817a28164f1ba6ee19747d010bbf6
parentdbe17f18838df6d0facf51b43cdc5efd372c28d6
bcachefs: Fix deadlock on nocow locks in data move path

The recent nocow locking rework introduced a deadlock in the data move
path: the new nocow locking scheme uses a hash table with a fixed size
array for chaining, meaning on hash collision we may have to wait for
other locks to be released before we can lock a bucket.

And since the data move path needs to submit writes from the same thread
that's taking nocow locks and submitting reads, this introduces a
deadlock.

This shouldn't happen often in practice, but since the data move path
can keep large numbers of IOs in flight simultaneously, it's something
we have to handle.

This patch makes move_ctxt_wait_event() available to
bch2_data_update_init() and uses it when appropriate, which is our
normal solution to this kind of thing.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/data_update.c
fs/bcachefs/data_update.h
fs/bcachefs/io.c
fs/bcachefs/move.c
fs/bcachefs/move.h