* [PATCH] xfs: don't perform discard if the given range length is less than block size
@ 2013-11-20 8:08 Jeff Liu
2013-11-20 17:31 ` Christoph Hellwig
2013-12-04 21:55 ` Ben Myers
0 siblings, 2 replies; 3+ messages in thread
From: Jeff Liu @ 2013-11-20 8:08 UTC (permalink / raw)
To: xfs@oss.sgi.com
From: Jie Liu <jeff.liu@oracle.com>
For discard operation, we should return EINVAL if the given range length
is less than a block size, otherwise it will go through the file system
to discard data blocks as the end range might be evaluated to -1, e.g,
# fstrim -v -o 0 -l 100 /xfs7
/xfs7: 9811378176 bytes were trimmed
This issue can be triggered via xfstests/generic/288.
Also, it seems to get the request queue pointer via bdev_get_queue()
instead of the hard code pointer dereference is not a bad thing.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/xfs/xfs_discard.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 8367d6d..4f11ef0 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -157,7 +157,7 @@ xfs_ioc_trim(
struct xfs_mount *mp,
struct fstrim_range __user *urange)
{
- struct request_queue *q = mp->m_ddev_targp->bt_bdev->bd_disk->queue;
+ struct request_queue *q = bdev_get_queue(mp->m_ddev_targp->bt_bdev);
unsigned int granularity = q->limits.discard_granularity;
struct fstrim_range range;
xfs_daddr_t start, end, minlen;
@@ -180,7 +180,8 @@ xfs_ioc_trim(
* matter as trimming blocks is an advisory interface.
*/
if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
- range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
+ range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)) ||
+ range.len < mp->m_sb.sb_blocksize)
return -XFS_ERROR(EINVAL);
start = BTOBB(range.start);
--
1.8.3.2
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfs: don't perform discard if the given range length is less than block size
2013-11-20 8:08 [PATCH] xfs: don't perform discard if the given range length is less than block size Jeff Liu
@ 2013-11-20 17:31 ` Christoph Hellwig
2013-12-04 21:55 ` Ben Myers
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2013-11-20 17:31 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs@oss.sgi.com
On Wed, Nov 20, 2013 at 04:08:53PM +0800, Jeff Liu wrote:
> From: Jie Liu <jeff.liu@oracle.com>
>
> For discard operation, we should return EINVAL if the given range length
> is less than a block size, otherwise it will go through the file system
> to discard data blocks as the end range might be evaluated to -1, e.g,
> # fstrim -v -o 0 -l 100 /xfs7
> /xfs7: 9811378176 bytes were trimmed
>
> This issue can be triggered via xfstests/generic/288.
Thanks for catching this.
> Also, it seems to get the request queue pointer via bdev_get_queue()
> instead of the hard code pointer dereference is not a bad thing.
I don't think bdev_get_queue is overly useful, but if there's not
other comments on that patch feel free to change it.
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: don't perform discard if the given range length is less than block size
2013-11-20 8:08 [PATCH] xfs: don't perform discard if the given range length is less than block size Jeff Liu
2013-11-20 17:31 ` Christoph Hellwig
@ 2013-12-04 21:55 ` Ben Myers
1 sibling, 0 replies; 3+ messages in thread
From: Ben Myers @ 2013-12-04 21:55 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs@oss.sgi.com
On Wed, Nov 20, 2013 at 04:08:53PM +0800, Jeff Liu wrote:
> From: Jie Liu <jeff.liu@oracle.com>
>
> For discard operation, we should return EINVAL if the given range length
> is less than a block size, otherwise it will go through the file system
> to discard data blocks as the end range might be evaluated to -1, e.g,
> # fstrim -v -o 0 -l 100 /xfs7
> /xfs7: 9811378176 bytes were trimmed
>
> This issue can be triggered via xfstests/generic/288.
>
> Also, it seems to get the request queue pointer via bdev_get_queue()
> instead of the hard code pointer dereference is not a bad thing.
>
> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Applied this.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-04 21:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-20 8:08 [PATCH] xfs: don't perform discard if the given range length is less than block size Jeff Liu
2013-11-20 17:31 ` Christoph Hellwig
2013-12-04 21:55 ` Ben Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox