From: Jeff Mahoney Date: Thu, 6 Sep 2018 21:18:15 +0000 (-0400) Subject: btrfs: don't attempt to trim devices that don't support it X-Git-Tag: rel_imx_4.19.35_1.1.0~8740 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=4d0dfd8fc83395ac06a0ba34b6f77151f2ea173d;p=linux.git btrfs: don't attempt to trim devices that don't support it 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@vger.kernel.org # 4.4+ Signed-off-by: Jeff Mahoney Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a94948221c59..f042dc595d05 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -10789,6 +10789,10 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, *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;