diff options
author | Jie Liu <jeff.liu@oracle.com> | 2013-11-20 03:08:53 -0500 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2013-12-10 11:00:33 -0500 |
commit | 2f42d612e7d4c4fb1819ea7b2b6e18938714ae7a (patch) | |
tree | 4c09011b252a333c6fbaa17d00737a2605a53409 /fs/xfs | |
parent | 31978b5cc66b8ba8a7e8eef60b12395d41b7b890 (diff) |
xfs: don't perform discard if the given range length is less than block size
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ben Myers <bpm@sgi.com>
(cherry picked from commit f9fd0135610084abef6867d984e9951c3099950d)
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/xfs_discard.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 8367d6dc18c9..4f11ef011139 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c | |||
@@ -157,7 +157,7 @@ xfs_ioc_trim( | |||
157 | struct xfs_mount *mp, | 157 | struct xfs_mount *mp, |
158 | struct fstrim_range __user *urange) | 158 | struct fstrim_range __user *urange) |
159 | { | 159 | { |
160 | struct request_queue *q = mp->m_ddev_targp->bt_bdev->bd_disk->queue; | 160 | struct request_queue *q = bdev_get_queue(mp->m_ddev_targp->bt_bdev); |
161 | unsigned int granularity = q->limits.discard_granularity; | 161 | unsigned int granularity = q->limits.discard_granularity; |
162 | struct fstrim_range range; | 162 | struct fstrim_range range; |
163 | xfs_daddr_t start, end, minlen; | 163 | xfs_daddr_t start, end, minlen; |
@@ -180,7 +180,8 @@ xfs_ioc_trim( | |||
180 | * matter as trimming blocks is an advisory interface. | 180 | * matter as trimming blocks is an advisory interface. |
181 | */ | 181 | */ |
182 | if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) || | 182 | if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) || |
183 | range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp))) | 183 | range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)) || |
184 | range.len < mp->m_sb.sb_blocksize) | ||
184 | return -XFS_ERROR(EINVAL); | 185 | return -XFS_ERROR(EINVAL); |
185 | 186 | ||
186 | start = BTOBB(range.start); | 187 | start = BTOBB(range.start); |