bcachefs: Fix a deadlock
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 11 Sep 2023 03:33:08 +0000 (23:33 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:05 +0000 (17:09 -0400)
commitee7570546e89ece9b56eaa22c94a6ec0941ec827
tree7e454dc52b3f955a76cf46e849ee010ee7dafa24
parent9f2772c45460e420de9a88980129bef135c6b76f
bcachefs: Fix a deadlock

Waiting on a btree node write with btree locks held can deadlock, if the
write errors: the write error path has to do do a btree update to drop
the pointer to the replica that errored.

The interior update path has to wait on in flight btree writes before
freeing nodes on disk. Previously, this was done in
bch2_btree_interior_update_will_free_node(), and could deadlock; now, we
just stash a pointer to the node and do it in
btree_update_nodes_written(), just prior to the transactional part of
the update.

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