Commit 07f1a4f5 authored by Dave Chinner's avatar Dave Chinner Committed by Alex Elder

xfs: Check new inode size is OK before preallocating

The new xfsqa test 228 tries to preallocate more space than the
filesystem contains. it should fail, but instead triggers an assert
about lock flags.  The failure is due to the size extension failing
in vmtruncate() due to rlimit being set. Check this before we start
the preallocation to avoid allocating space that will never be used.

Also the path through xfs_vn_allocate already holds the IO lock, so
it should not be present in the lock flags when the setattr fails.
Hence the assert needs to take this into account. This will prevent
other such callers from hitting this incorrect ASSERT.

(Fixed a reference to "newsize" to read "new_size". -Alex)
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAlex Elder <aelder@sgi.com>
parent fdc07f44
...@@ -585,11 +585,20 @@ xfs_vn_fallocate( ...@@ -585,11 +585,20 @@ xfs_vn_fallocate(
bf.l_len = len; bf.l_len = len;
xfs_ilock(ip, XFS_IOLOCK_EXCL); xfs_ilock(ip, XFS_IOLOCK_EXCL);
/* check the new inode size is valid before allocating */
if (!(mode & FALLOC_FL_KEEP_SIZE) &&
offset + len > i_size_read(inode)) {
new_size = offset + len;
error = inode_newsize_ok(inode, new_size);
if (error)
goto out_unlock;
}
error = -xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf, error = -xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
0, XFS_ATTR_NOLOCK); 0, XFS_ATTR_NOLOCK);
if (!error && !(mode & FALLOC_FL_KEEP_SIZE) && if (error)
offset + len > i_size_read(inode)) goto out_unlock;
new_size = offset + len;
/* Change file size if needed */ /* Change file size if needed */
if (new_size) { if (new_size) {
...@@ -600,6 +609,7 @@ xfs_vn_fallocate( ...@@ -600,6 +609,7 @@ xfs_vn_fallocate(
error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK); error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK);
} }
out_unlock:
xfs_iunlock(ip, XFS_IOLOCK_EXCL); xfs_iunlock(ip, XFS_IOLOCK_EXCL);
out_error: out_error:
return error; return error;
......
...@@ -267,7 +267,7 @@ xfs_setattr( ...@@ -267,7 +267,7 @@ xfs_setattr(
if (code) { if (code) {
ASSERT(tp == NULL); ASSERT(tp == NULL);
lock_flags &= ~XFS_ILOCK_EXCL; lock_flags &= ~XFS_ILOCK_EXCL;
ASSERT(lock_flags == XFS_IOLOCK_EXCL); ASSERT(lock_flags == XFS_IOLOCK_EXCL || !need_iolock);
goto error_return; goto error_return;
} }
tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE); tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE);
......
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