]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: allow defrag to be interruptible
authorFilipe Manana <fdmanana@suse.com>
Tue, 18 Jan 2022 13:43:31 +0000 (13:43 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 19 Jan 2022 17:16:38 +0000 (18:16 +0100)
commit629d3a03861d10669148e08749c954d438a72294
tree14f219d40b96f9f384a96e05c24c5cdba736c795
parent09b90e5e6d50ff21a3fed34a7416f4d8d6257811
btrfs: allow defrag to be interruptible

During defrag, at btrfs_defrag_file(), we have this loop that iterates
over a file range in steps no larger than 256K subranges. If the range
is too long, there's no way to interrupt it. So make the loop check in
each iteration if there's signal pending, and if there is, break and
return -AGAIN to userspace.

Before kernel 5.16, we used to allow defrag to be cancelled through a
signal, but that was lost with commit 2a747f5c2dad21 ("btrfs: defrag:
use defrag_one_cluster() to implement btrfs_defrag_file()").

This change adds back the possibility to cancel a defrag with a signal
and keeps the same semantics, returning -EAGAIN to user space (and not
the usually more expected -EINTR).

This is also motivated by a recent bug on 5.16 where defragging a 1 byte
file resulted in iterating from file range 0 to (u64)-1, as hitting the
bug triggered a too long loop, basically requiring one to reboot the
machine, as it was not possible to cancel defrag.

Fixes: 2a747f5c2dad21 ("btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file()")
CC: stable@vger.kernel.org # 5.16
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c