Re: [PATCH 2/3] btrfs: don't attempt to trim devices that don't support it

2018-09-14 Thread David Sterba
On Thu, Sep 06, 2018 at 05:18:15PM -0400, je...@suse.com wrote:
> From: Jeff Mahoney 
> 
> 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)
> Signed-off-by: Jeff Mahoney 

Reviewed-by: David Sterba 


[PATCH 2/3] btrfs: don't attempt to trim devices that don't support it

2018-09-06 Thread jeffm
From: Jeff Mahoney 

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)
Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/extent-tree.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a0e82589c3e8..92e5e9fd9bdd 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10887,6 +10887,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, >dev_state))
return 0;
-- 
2.12.3