All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl
@ 2011-02-15 17:06 Lukas Czerner
  2011-02-15 17:06 ` [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code Lukas Czerner
  2011-02-23 17:50 ` [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Ted Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Lukas Czerner @ 2011-02-15 17:06 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, lczerner

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.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ext4/ioctl.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index eb3bc2f..25ba7c7 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -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;
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code
  2011-02-15 17:06 [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Lukas Czerner
@ 2011-02-15 17:06 ` Lukas Czerner
  2011-02-23 17:58   ` Ted Ts'o
  2011-02-23 17:50 ` [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Ted Ts'o
  1 sibling, 1 reply; 5+ messages in thread
From: Lukas Czerner @ 2011-02-15 17:06 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, lczerner

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 <lczerner@redhat.com>
---
 fs/ext4/ioctl.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 25ba7c7..c052c9f 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -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;
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl
  2011-02-15 17:06 [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Lukas Czerner
  2011-02-15 17:06 ` [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code Lukas Czerner
@ 2011-02-23 17:50 ` Ted Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Ted Ts'o @ 2011-02-23 17:50 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4

On Tue, Feb 15, 2011 at 06:06:24PM +0100, Lukas Czerner wrote:
> 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.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

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 <lczerner@redhat.com>

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.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code
  2011-02-15 17:06 ` [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code Lukas Czerner
@ 2011-02-23 17:58   ` Ted Ts'o
  2011-02-23 18:19     ` Lukas Czerner
  0 siblings, 1 reply; 5+ messages in thread
From: Ted Ts'o @ 2011-02-23 17:58 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4

On Tue, Feb 15, 2011 at 06:06:25PM +0100, Lukas Czerner wrote:
> 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 <lczerner@redhat.com>

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 <lczerner@redhat.com>

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 <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code
  2011-02-23 17:58   ` Ted Ts'o
@ 2011-02-23 18:19     ` Lukas Czerner
  0 siblings, 0 replies; 5+ messages in thread
From: Lukas Czerner @ 2011-02-23 18:19 UTC (permalink / raw)
  To: Ted Ts'o; +Cc: Lukas Czerner, linux-ext4

On Wed, 23 Feb 2011, Ted Ts'o wrote:

> On Tue, Feb 15, 2011 at 06:06:25PM +0100, Lukas Czerner wrote:
> > 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 <lczerner@redhat.com>
> 
> 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 <lczerner@redhat.com>
> 
> 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 <lczerner@redhat.com>
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> 

Hi Ted,

thanks for merging and for the description. My English still needs a lot
of practice :)

Thanks!
-Lukas

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-23 18:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-15 17:06 [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Lukas Czerner
2011-02-15 17:06 ` [PATCH 2/2] ext4: Adjust mineln with discard_granularity in FITRIM code Lukas Czerner
2011-02-23 17:58   ` Ted Ts'o
2011-02-23 18:19     ` Lukas Czerner
2011-02-23 17:50 ` [PATCH 1/2] ext4: check if device support discard in FITRIM ioctl Ted Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.