Skip to content

Commit 467f789

Browse files
Christoph HellwigBen Myers
authored andcommitted
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: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Mark Tinguely <[email protected]> Signed-off-by: Ben Myers <[email protected]>
1 parent b4d05e3 commit 467f789

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

fs/xfs/xfs_file.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -593,35 +593,31 @@ xfs_file_aio_write_checks(
593593
struct xfs_inode *ip = XFS_I(inode);
594594
int error = 0;
595595

596-
xfs_rw_ilock(ip, XFS_ILOCK_EXCL);
597596
restart:
598597
error = generic_write_checks(file, pos, count, S_ISBLK(inode->i_mode));
599-
if (error) {
600-
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
598+
if (error)
601599
return error;
602-
}
603600

604601
/*
605602
* If the offset is beyond the size of the file, we need to zero any
606603
* blocks that fall between the existing EOF and the start of this
607604
* write. If zeroing is needed and we are currently holding the
608-
* iolock shared, we need to update it to exclusive which involves
609-
* dropping all locks and relocking to maintain correct locking order.
610-
* If we do this, restart the function to ensure all checks and values
611-
* are still valid.
605+
* iolock shared, we need to update it to exclusive which implies
606+
* having to redo all checks before.
612607
*/
613608
if (*pos > i_size_read(inode)) {
614609
if (*iolock == XFS_IOLOCK_SHARED) {
615-
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL | *iolock);
610+
xfs_rw_iunlock(ip, *iolock);
616611
*iolock = XFS_IOLOCK_EXCL;
617-
xfs_rw_ilock(ip, XFS_ILOCK_EXCL | *iolock);
612+
xfs_rw_ilock(ip, *iolock);
618613
goto restart;
619614
}
615+
xfs_rw_ilock(ip, XFS_ILOCK_EXCL);
620616
error = -xfs_zero_eof(ip, *pos, i_size_read(inode));
617+
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
618+
if (error)
619+
return error;
621620
}
622-
xfs_rw_iunlock(ip, XFS_ILOCK_EXCL);
623-
if (error)
624-
return error;
625621

626622
/*
627623
* Updating the timestamps will grab the ilock again from
@@ -638,7 +634,6 @@ xfs_file_aio_write_checks(
638634
* people from modifying setuid and setgid binaries.
639635
*/
640636
return file_remove_suid(file);
641-
642637
}
643638

644639
/*

0 commit comments

Comments
 (0)