Commit f5b8911b authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: remove xfs_tosspages

It's a buggy, unnecessary wrapper that is duplicating
truncate_pagecache_range().

When replacing the call in xfs_change_file_space(), also ensure that
the length being allocated/freed is always positive before making
any changes. These checks are done in the lower extent manipulation
functions, too, but we need to do them before any page cache
operations.
Reported-by: default avatarAndrew Dahl <adahl@sgi.com>
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-By: default avatarAndrew Dahl <adahl@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent de497688
...@@ -315,8 +315,7 @@ xfs_swap_extents( ...@@ -315,8 +315,7 @@ xfs_swap_extents(
* are safe. We don't really care if non-io related * are safe. We don't really care if non-io related
* fields change. * fields change.
*/ */
truncate_pagecache_range(VFS_I(ip), 0, -1);
xfs_tosspages(ip, 0, -1, FI_REMAPF);
tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT); tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT);
if ((error = xfs_trans_reserve(tp, 0, if ((error = xfs_trans_reserve(tp, 0,
......
...@@ -25,18 +25,6 @@ ...@@ -25,18 +25,6 @@
* note: all filemap functions return negative error codes. These * note: all filemap functions return negative error codes. These
* need to be inverted before returning to the xfs core functions. * need to be inverted before returning to the xfs core functions.
*/ */
void
xfs_tosspages(
xfs_inode_t *ip,
xfs_off_t first,
xfs_off_t last,
int fiopt)
{
/* can't toss partial tail pages, so mask them out */
last &= ~(PAGE_SIZE - 1);
truncate_inode_pages_range(VFS_I(ip)->i_mapping, first, last - 1);
}
int int
xfs_flushinval_pages( xfs_flushinval_pages(
xfs_inode_t *ip, xfs_inode_t *ip,
......
...@@ -2118,7 +2118,7 @@ xfs_change_file_space( ...@@ -2118,7 +2118,7 @@ xfs_change_file_space(
xfs_fsize_t fsize; xfs_fsize_t fsize;
int setprealloc; int setprealloc;
xfs_off_t startoffset; xfs_off_t startoffset;
xfs_off_t llen; xfs_off_t end;
xfs_trans_t *tp; xfs_trans_t *tp;
struct iattr iattr; struct iattr iattr;
int prealloc_type; int prealloc_type;
...@@ -2139,12 +2139,30 @@ xfs_change_file_space( ...@@ -2139,12 +2139,30 @@ xfs_change_file_space(
return XFS_ERROR(EINVAL); return XFS_ERROR(EINVAL);
} }
llen = bf->l_len > 0 ? bf->l_len - 1 : bf->l_len; /*
* length of <= 0 for resv/unresv/zero is invalid. length for
* alloc/free is ignored completely and we have no idea what userspace
* might have set it to, so set it to zero to allow range
* checks to pass.
*/
switch (cmd) {
case XFS_IOC_ZERO_RANGE:
case XFS_IOC_RESVSP:
case XFS_IOC_RESVSP64:
case XFS_IOC_UNRESVSP:
case XFS_IOC_UNRESVSP64:
if (bf->l_len <= 0)
return XFS_ERROR(EINVAL);
break;
default:
bf->l_len = 0;
break;
}
if (bf->l_start < 0 || if (bf->l_start < 0 ||
bf->l_start > mp->m_super->s_maxbytes || bf->l_start > mp->m_super->s_maxbytes ||
bf->l_start + llen < 0 || bf->l_start + bf->l_len < 0 ||
bf->l_start + llen > mp->m_super->s_maxbytes) bf->l_start + bf->l_len >= mp->m_super->s_maxbytes)
return XFS_ERROR(EINVAL); return XFS_ERROR(EINVAL);
bf->l_whence = 0; bf->l_whence = 0;
...@@ -2169,7 +2187,9 @@ xfs_change_file_space( ...@@ -2169,7 +2187,9 @@ xfs_change_file_space(
switch (cmd) { switch (cmd) {
case XFS_IOC_ZERO_RANGE: case XFS_IOC_ZERO_RANGE:
prealloc_type |= XFS_BMAPI_CONVERT; prealloc_type |= XFS_BMAPI_CONVERT;
xfs_tosspages(ip, startoffset, startoffset + bf->l_len, 0); end = round_down(startoffset + bf->l_len, PAGE_SIZE) - 1;
if (startoffset > end)
truncate_pagecache_range(VFS_I(ip), startoffset, end);
/* FALLTHRU */ /* FALLTHRU */
case XFS_IOC_RESVSP: case XFS_IOC_RESVSP:
case XFS_IOC_RESVSP64: case XFS_IOC_RESVSP64:
......
...@@ -48,8 +48,6 @@ int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name, ...@@ -48,8 +48,6 @@ int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags); int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
int flags, struct attrlist_cursor_kern *cursor); int flags, struct attrlist_cursor_kern *cursor);
void xfs_tosspages(struct xfs_inode *inode, xfs_off_t first,
xfs_off_t last, int fiopt);
int xfs_flushinval_pages(struct xfs_inode *ip, xfs_off_t first, int xfs_flushinval_pages(struct xfs_inode *ip, xfs_off_t first,
xfs_off_t last, int fiopt); xfs_off_t last, int fiopt);
int xfs_flush_pages(struct xfs_inode *ip, xfs_off_t first, int xfs_flush_pages(struct xfs_inode *ip, xfs_off_t first,
......
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