btrfs: don't attempt to trim devices that don't support it
authorJeff Mahoney <jeffm@suse.com>
Thu, 6 Sep 2018 21:18:15 +0000 (17:18 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2018 19:17:04 +0000 (11:17 -0800)
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 <jeffm@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/extent-tree.c

index 1624746b4c3f33a7b3f62b0c6b1f79e58855cc34..804073a8734e2b0604456abfc5721a4c0d7a86db 100644 (file)
@@ -11071,6 +11071,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 (!device->writeable)
                return 0;