[PATCH 4.18 325/350] btrfs: dont attempt to trim devices that dont support it

From: Greg Kroah-Hartman
Date: Sun Nov 11 2018 - 18:13:54 EST


4.18-stable review patch. If anyone has any objections, please let me know.

------------------

From: Jeff Mahoney <jeffm@xxxxxxxx>

commit 0be88e367fd8fbdb45257615d691f4675dda062f upstream.

We check whether any device the file system is using supports discard in
the ioctl call, but then we attempt to trim free extents on every device
regardless of whether discard is supported. Due to the way we mask off
EOPNOTSUPP, we can end up issuing the trim operations on each free range
on devices that don't support it, just wasting time.

Fixes: 499f377f49f08 ("btrfs: iterate over unused chunk space in FITRIM")
CC: stable@xxxxxxxxxxxxxxx # 4.4+
Signed-off-by: Jeff Mahoney <jeffm@xxxxxxxx>
Reviewed-by: David Sterba <dsterba@xxxxxxxx>
Signed-off-by: David Sterba <dsterba@xxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
fs/btrfs/extent-tree.c | 4 ++++
1 file changed, 4 insertions(+)

--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10905,6 +10905,10 @@ static int btrfs_trim_free_extents(struc

*trimmed = 0;

+ /* Discard not supported = nothing to do. */
+ if (!blk_queue_discard(bdev_get_queue(device->bdev)))
+ return 0;
+
/* Not writeable = nothing to do. */
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state))
return 0;