ext4: check if device support discard in FITRIM ioctl
PATCH 1/2 ext4: check if device support discard in FITRIM ioctl
Right now we, are relying on the fact that when we attempt to actually do the discard, blkdev_issue_discar() returns -EOPNOTSUPP and the user is informed that the device does not support discard.
However, in the case where the we do not hit any suitable free extent to trim in FITRIM code, it will finish without any error. This is very confusing, because it seems that FITRIM was successful even though the device does not actually supports discard.
Solution: Check for the discard support before attempt to search for free extents.
--- fs/ext4/ioctl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/ext4/ioctl.c +4 -0
@@ -334,12 +334,16 @@ mext_out:case FITRIM : {struct super_block *sb = inode->i_sb; +struct request_queue *q =bdev_get_queue (sb->s_bdev);struct fstrim_range range;int ret =0 ;if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (!blk_queue_discard (q)) +return -EOPNOTSUPP ; +if (copy_from_user (&range, (struct fstrim_range *)arg,sizeof (range)))return -EFAULT ;
Signature · 1 line
1.7.4
PATCH 2/2 ext4: Adjust mineln with discard_granularity in FITRIM code
Discard granularity tells us the minimum size of extent to be discarded. Use that information to adjust minlen properly in FITRIM code. Smaller extents will be ignored anyway, so we can optimize by not even trying to discard them.
--- fs/ext4/ioctl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/ioctl.c +2 -0
@@ -348,6 +348,8 @@ mext_out: sizeof(range)))return -EFAULT ; + range.minlen =max ((unsigned int )range.minlen, + q->limits.discard_granularity); ret =ext4_trim_fs (sb, &range);if (ret <0 )return ret;
Signature · 1 line
1.7.4
Re: [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code
Quoted 6 lines · Lukas Czerner
Discard granularity tells us the minimum size of extent to be discarded. Use that information to adjust minlen properly in FITRIM code. Smaller extents will be ignored anyway, so we can optimize by not even trying to discard them.
Signed-off-by Lukas Czerner <[email protected]>
Applied to the ext4 patch queue, with a rewritten commit description.
"Always write with a deep sympathy for the reader"
- Ted
ext4: Adjust minlen with discard_granularity in the FITRIM ioctl
From: Lukas Czerner <[email protected]>
Discard granularity tells us the minimum size of extent that can be discard by the device. If the user supplies a minimum extent that should be discarded (range.minlen) which is smaller than the discard granularity, increase minlen to the discard granularity, since there's no point submitting trim requests that the device will reject anyway.
Re: [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code
Quoted 18 lines · Ted Ts'o
Quoted 6 lines · Lukas Czerner
Discard granularity tells us the minimum size of extent to be discarded. Use that information to adjust minlen properly in FITRIM code. Smaller extents will be ignored anyway, so we can optimize by not even trying to discard them.
Signed-off-by Lukas Czerner <[email protected]>Applied to the ext4 patch queue, with a rewritten commit description.
"Always write with a deep sympathy for the reader"
- Ted
ext4: Adjust minlen with
discard_granularityin the FITRIM ioctlFrom: Lukas Czerner <[email protected]>
Quoted 9 lines
Discard granularity tells us the minimum size of extent that can be discard by the device. If the user supplies a minimum extent that should be discarded (range.minlen) which is smaller than the discard granularity, increase minlen to the discard granularity, since there's no point submitting trim requests that the device will reject anyway.
Signed-off-by Lukas Czerner <[email protected]>Signed-off-by "Theodore Ts'o" <[email protected]>
Hi Ted,
thanks for merging and for the description. My English still needs a lot of practice :)
Thanks!
-Lukas
Ted Ts'o
maintainerQuoted 9 lines · Lukas Czerner
Right now we, are relying on the fact that when we attempt to actually do the discard,
blkdev_issue_discar()returns-EOPNOTSUPPand the user is informed that the device does not support discard.However, in the case where the we do not hit any suitable free extent to trim in FITRIM code, it will finish without any error. This is very confusing, because it seems that FITRIM was successful even though the device does not actually supports discard.
Quoted 4 lines
Solution: Check for the discard support before attempt to search for free extents.
Signed-off-by Lukas Czerner <[email protected]>
Added to the ext4 patch queue, but I rewrote the commit description to make it more understable.
- Ted
ext4: check if device support discard in FITRIM ioctl
From: Lukas Czerner <[email protected]>
For a device that does not support discard, the FITRIM ioctl returns -EOPNOTSUPP when blkdev_issue_discard() returns this error code, which is how the user is informed that the device does not support discard.
If there are no suitable free extents to be trimmed, then FITRIM will return success even though the device does not support discard, which could confuse the user. So check explicitly if the device supports discard and return an error code at the beginning of the FITRIM ioctl processing.