]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: ensure relocation never runs while we have send operations running
authorFilipe Manana <fdmanana@suse.com>
Mon, 21 Jun 2021 10:10:38 +0000 (11:10 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 22 Jun 2021 12:11:58 +0000 (14:11 +0200)
commit8bc6cfd0423ddc9eebd24980e000c48747e2a4c3
treefa5549809528f500b2971565e3b5ec9efe8f48e9
parente5efe9580a2f621b8b4abf3dc5b985ae04de6f01
btrfs: ensure relocation never runs while we have send operations running

Relocation and send do not play well together because while send is
running a block group can be relocated, a transaction committed and
the respective disk extents get re-allocated and written to or discarded
while send is about to do something with the extents.

This was explained in commit 8d595b8e748700 ("Btrfs: prevent send failures
and crashes due to concurrent relocation"), which prevented balance and
send from running in parallel but it did not address one remaining case
where chunk relocation can happen: shrinking a device (and device deletion
which shrinks a device's size to 0 before deleting the device).

We also have now one more case where relocation is triggered: on zoned
filesystems partially used block groups get relocated by a background
thread, introduced in commit 9d8d2570b3afb2 ("btrfs: zoned: automatically
reclaim zones").

So make sure that instead of preventing balance from running when there
are ongoing send operations, we prevent relocation from happening.
This uses the infrastructure recently added by a patch that has the
subject: "btrfs: add cancellable chunk relocation support".

Also it adds a spinlock used exclusively for the exclusivity between
send and relocation, as before fs_info->balance_mutex was used, which
would make an attempt to run send to block waiting for balance to
finish, which can take a lot of time on large filesystems.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/relocation.c
fs/btrfs/send.c
fs/btrfs/volumes.c