Commit 2bf9d264 authored by Wang Shilong's avatar Wang Shilong Committed by Darrick J. Wong

xfs,fstrim: fix to return correct minlen

This patch tries to address two problems:

1) return @minlen we used to trim to
user space.

2) return EINVAL if granularity is larger than
avg size, even most of cases, granularity is small(4K),
but if devices return a lager granularity for some reaons
(testing, bugs etc), fstrim should return failure directly.
Signed-off-by: default avatarWang Shilong <wshilong@ddn.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 1ca89fbc
...@@ -172,6 +172,8 @@ xfs_ioc_trim( ...@@ -172,6 +172,8 @@ xfs_ioc_trim(
if (copy_from_user(&range, urange, sizeof(range))) if (copy_from_user(&range, urange, sizeof(range)))
return -EFAULT; return -EFAULT;
range.minlen = max_t(u64, granularity, range.minlen);
minlen = BTOBB(range.minlen);
/* /*
* Truncating down the len isn't actually quite correct, but using * Truncating down the len isn't actually quite correct, but using
* BBTOB would mean we trivially get overflows for values * BBTOB would mean we trivially get overflows for values
...@@ -186,7 +188,6 @@ xfs_ioc_trim( ...@@ -186,7 +188,6 @@ xfs_ioc_trim(
start = BTOBB(range.start); start = BTOBB(range.start);
end = start + BTOBBT(range.len) - 1; end = start + BTOBBT(range.len) - 1;
minlen = BTOBB(max_t(u64, granularity, range.minlen));
if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1) if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1; end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment