bcachefs: Fix race in bch2_write_super()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 7 May 2024 00:49:24 +0000 (20:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 7 May 2024 15:02:36 +0000 (11:02 -0400)
commit54541c1f78e12a78487ae63e2e199a7d4f6dbd26
tree735f198e33988225c60f206014d4860df540644f
parent71dac2482ad3c8d4a8b8998a96751f009bad895f
bcachefs: Fix race in bch2_write_super()

bch2_write_super() was looping over online devices multiple times -
dropping and retaking io_ref each time.

This meant it could race with device removal; it could increment the
sequence number on a device but fail to write it - and then if the
device was re-added, it would get confused the next time around thinking
a superblock write was silently dropped.

Fix this by taking io_ref once, and stashing pointers to online devices
in a darray.

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