Commit f50b8f47 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: factor out a xfs_ilock_iocb helper

Add a helper to factor out the nowait locking logical for the read/write
helpers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 213f6271
...@@ -197,6 +197,23 @@ xfs_file_fsync( ...@@ -197,6 +197,23 @@ xfs_file_fsync(
return error; return error;
} }
static int
xfs_ilock_iocb(
struct kiocb *iocb,
unsigned int lock_mode)
{
struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
if (iocb->ki_flags & IOCB_NOWAIT) {
if (!xfs_ilock_nowait(ip, lock_mode))
return -EAGAIN;
} else {
xfs_ilock(ip, lock_mode);
}
return 0;
}
STATIC ssize_t STATIC ssize_t
xfs_file_dio_aio_read( xfs_file_dio_aio_read(
struct kiocb *iocb, struct kiocb *iocb,
...@@ -213,12 +230,9 @@ xfs_file_dio_aio_read( ...@@ -213,12 +230,9 @@ xfs_file_dio_aio_read(
file_accessed(iocb->ki_filp); file_accessed(iocb->ki_filp);
if (iocb->ki_flags & IOCB_NOWAIT) { ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) if (ret)
return -EAGAIN; return ret;
} else {
xfs_ilock(ip, XFS_IOLOCK_SHARED);
}
ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL, 0); ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL, 0);
xfs_iunlock(ip, XFS_IOLOCK_SHARED); xfs_iunlock(ip, XFS_IOLOCK_SHARED);
...@@ -239,13 +253,9 @@ xfs_file_dax_read( ...@@ -239,13 +253,9 @@ xfs_file_dax_read(
if (!count) if (!count)
return 0; /* skip atime */ return 0; /* skip atime */
if (iocb->ki_flags & IOCB_NOWAIT) { ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) if (ret)
return -EAGAIN; return ret;
} else {
xfs_ilock(ip, XFS_IOLOCK_SHARED);
}
ret = dax_iomap_rw(iocb, to, &xfs_read_iomap_ops); ret = dax_iomap_rw(iocb, to, &xfs_read_iomap_ops);
xfs_iunlock(ip, XFS_IOLOCK_SHARED); xfs_iunlock(ip, XFS_IOLOCK_SHARED);
...@@ -263,12 +273,9 @@ xfs_file_buffered_aio_read( ...@@ -263,12 +273,9 @@ xfs_file_buffered_aio_read(
trace_xfs_file_buffered_read(ip, iov_iter_count(to), iocb->ki_pos); trace_xfs_file_buffered_read(ip, iov_iter_count(to), iocb->ki_pos);
if (iocb->ki_flags & IOCB_NOWAIT) { ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) if (ret)
return -EAGAIN; return ret;
} else {
xfs_ilock(ip, XFS_IOLOCK_SHARED);
}
ret = generic_file_read_iter(iocb, to); ret = generic_file_read_iter(iocb, to);
xfs_iunlock(ip, XFS_IOLOCK_SHARED); xfs_iunlock(ip, XFS_IOLOCK_SHARED);
...@@ -607,13 +614,9 @@ xfs_file_dax_write( ...@@ -607,13 +614,9 @@ xfs_file_dax_write(
size_t count; size_t count;
loff_t pos; loff_t pos;
if (iocb->ki_flags & IOCB_NOWAIT) { ret = xfs_ilock_iocb(iocb, iolock);
if (!xfs_ilock_nowait(ip, iolock)) if (ret)
return -EAGAIN; return ret;
} else {
xfs_ilock(ip, iolock);
}
ret = xfs_file_aio_write_checks(iocb, from, &iolock); ret = xfs_file_aio_write_checks(iocb, from, &iolock);
if (ret) if (ret)
goto out; goto out;
......
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