• Nikolay Borisov's avatar
    btrfs: Always trim all unallocated space in btrfs_trim_free_extents · 8103d10b
    Nikolay Borisov authored
    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: c2d1b3aa ("btrfs: Honour FITRIM range constraints during free space trim")
    Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    8103d10b
extent-tree.c 313 KB