OSDN Git Service

btrfs: Always trim all unallocated space in btrfs_trim_free_extents
authorNikolay Borisov <nborisov@suse.com>
Mon, 3 Jun 2019 10:06:00 +0000 (13:06 +0300)
committerDavid Sterba <dsterba@suse.com>
Fri, 7 Jun 2019 12:52:05 +0000 (14:52 +0200)
commit8103d10b71610aa65a65d6611cd3ad3f3bd7beeb
tree11af4b39c6e5589054d62fbbd23a5ea231d62266
parent06989c799f04810f6876900d4760c0edda369cf7
btrfs: Always trim all unallocated space in btrfs_trim_free_extents

This patch removes support for range parameters of FITRIM ioctl when
trimming unallocated space on devices. This is necessary since ranges
passed from user space are generally interpreted as logical addresses,
whereas btrfs_trim_free_extents used to interpret them as device
physical extents. This could result in counter-intuitive behavior for
users so it's best to remove that support altogether.

Additionally, the existing range support had a bug where if an offset
was passed to FITRIM which overflows u64 e.g. -1 (parsed as u64
18446744073709551615) then wrong data was fed into btrfs_issue_discard,
which in turn leads to wrap-around when aligning the passed range and
results in wrong regions being discarded which leads to data corruption.

Fixes: c2d1b3aae336 ("btrfs: Honour FITRIM range constraints during free space trim")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c