Commit 467f7899 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Ben Myers

xfs: reduce ilock hold times in xfs_file_aio_write_checks

We do not need the ilock for generic_write_checks and the i_size_read,
which are protected by i_mutex and/or iolock, so reduce the ilock
critical section to just the call to xfs_zero_eof.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarMark Tinguely <tinguely@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent b4d05e30
...@@ -593,35 +593,31 @@ xfs_file_aio_write_checks( ...@@ -593,35 +593,31 @@ xfs_file_aio_write_checks(
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
int error = 0; int error = 0;
xfs_rw_ilock(ip, XFS_ILOCK_EXCL);
restart: restart:
error = generic_write_checks(file, pos, count, S_ISBLK(inode->i_mode)); error = generic_write_checks(file, pos, count, S_ISBLK(inode->i_mode));
if (error) { if (error)
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
return error; return error;
}
/* /*
* If the offset is beyond the size of the file, we need to zero any * If the offset is beyond the size of the file, we need to zero any
* blocks that fall between the existing EOF and the start of this * blocks that fall between the existing EOF and the start of this
* write. If zeroing is needed and we are currently holding the * write. If zeroing is needed and we are currently holding the
* iolock shared, we need to update it to exclusive which involves * iolock shared, we need to update it to exclusive which implies
* dropping all locks and relocking to maintain correct locking order. * having to redo all checks before.
* If we do this, restart the function to ensure all checks and values
* are still valid.
*/ */
if (*pos > i_size_read(inode)) { if (*pos > i_size_read(inode)) {
if (*iolock == XFS_IOLOCK_SHARED) { if (*iolock == XFS_IOLOCK_SHARED) {
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL | *iolock); xfs_rw_iunlock(ip, *iolock);
*iolock = XFS_IOLOCK_EXCL; *iolock = XFS_IOLOCK_EXCL;
xfs_rw_ilock(ip, XFS_ILOCK_EXCL | *iolock); xfs_rw_ilock(ip, *iolock);
goto restart; goto restart;
} }
xfs_rw_ilock(ip, XFS_ILOCK_EXCL);
error = -xfs_zero_eof(ip, *pos, i_size_read(inode)); error = -xfs_zero_eof(ip, *pos, i_size_read(inode));
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
if (error)
return error;
} }
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
if (error)
return error;
/* /*
* Updating the timestamps will grab the ilock again from * Updating the timestamps will grab the ilock again from
...@@ -638,7 +634,6 @@ xfs_file_aio_write_checks( ...@@ -638,7 +634,6 @@ xfs_file_aio_write_checks(
* people from modifying setuid and setgid binaries. * people from modifying setuid and setgid binaries.
*/ */
return file_remove_suid(file); return file_remove_suid(file);
} }
/* /*
......
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