aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2016-09-18 21:26:39 -0400
committerDave Chinner <david@fromorbit.com>2016-09-18 21:26:39 -0400
commit66642c5c1dea411dd2842159f9f297ce8e914994 (patch)
tree693c729488f40154f7fd6878afc9897209ec82cd
parent17879e8f865f4ed8b6f9041a2687ad40f13ae460 (diff)
xfs: take the ilock shared if possible in xfs_file_iomap_begin
We always just read the extent first, and will later lock exlusively after first dropping the lock in case we actually allocate blocks. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r--fs/xfs/xfs_iomap.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index ac677d032e3a..fe4a26d752d0 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -954,6 +954,7 @@ xfs_file_iomap_begin(
954 struct xfs_bmbt_irec imap; 954 struct xfs_bmbt_irec imap;
955 xfs_fileoff_t offset_fsb, end_fsb; 955 xfs_fileoff_t offset_fsb, end_fsb;
956 int nimaps = 1, error = 0; 956 int nimaps = 1, error = 0;
957 unsigned lockmode;
957 958
958 if (XFS_FORCED_SHUTDOWN(mp)) 959 if (XFS_FORCED_SHUTDOWN(mp))
959 return -EIO; 960 return -EIO;
@@ -963,7 +964,7 @@ xfs_file_iomap_begin(
963 iomap); 964 iomap);
964 } 965 }
965 966
966 xfs_ilock(ip, XFS_ILOCK_EXCL); 967 lockmode = xfs_ilock_data_map_shared(ip);
967 968
968 ASSERT(offset <= mp->m_super->s_maxbytes); 969 ASSERT(offset <= mp->m_super->s_maxbytes);
969 if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes) 970 if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes)
@@ -974,7 +975,7 @@ xfs_file_iomap_begin(
974 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap, 975 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
975 &nimaps, XFS_BMAPI_ENTIRE); 976 &nimaps, XFS_BMAPI_ENTIRE);
976 if (error) { 977 if (error) {
977 xfs_iunlock(ip, XFS_ILOCK_EXCL); 978 xfs_iunlock(ip, lockmode);
978 return error; 979 return error;
979 } 980 }
980 981
@@ -994,7 +995,8 @@ xfs_file_iomap_begin(
994 * xfs_iomap_write_direct() expects the shared lock. It 995 * xfs_iomap_write_direct() expects the shared lock. It
995 * is unlocked on return. 996 * is unlocked on return.
996 */ 997 */
997 xfs_ilock_demote(ip, XFS_ILOCK_EXCL); 998 if (lockmode == XFS_ILOCK_EXCL)
999 xfs_ilock_demote(ip, lockmode);
998 error = xfs_iomap_write_direct(ip, offset, length, &imap, 1000 error = xfs_iomap_write_direct(ip, offset, length, &imap,
999 nimaps); 1001 nimaps);
1000 if (error) 1002 if (error)
@@ -1005,7 +1007,7 @@ xfs_file_iomap_begin(
1005 } else { 1007 } else {
1006 ASSERT(nimaps); 1008 ASSERT(nimaps);
1007 1009
1008 xfs_iunlock(ip, XFS_ILOCK_EXCL); 1010 xfs_iunlock(ip, lockmode);
1009 trace_xfs_iomap_found(ip, offset, length, 0, &imap); 1011 trace_xfs_iomap_found(ip, offset, length, 0, &imap);
1010 } 1012 }
1011 1013