Skip to contentSkip to conversation

xfs: fix IOCB_NOWAIT handling in xfs_file_dio_aio_read

PATCH In review Christoph Hellwig 3 participants 3 messages Jan 15, 2020 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix IOCB_NOWAIT handling in xfs_file_dio_aio_read

Direct I/O reads can also be used with RWF_NOWAIT & co. Fix the inode locking in xfs_file_dio_aio_read to take IOCB_NOWAIT into account.

---

Resending standalone to get a little more attention.

 fs/xfs/xfs_file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/xfs_file.c +6 -1
index c93250108952..b8a4a3f29b36 100644
@@ -187,7 +187,12 @@ xfs_file_dio_aio_read(
 
 	file_accessed(iocb->ki_filp);
 
-	xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED))
+			return -EAGAIN;
+	} else {
+		xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	}
 	ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL,
 			is_sync_kiocb(iocb));
 	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Christoph Hellwig

Direct I/O reads can also be used with RWF_NOWAIT & co. Fix the inode locking in xfs_file_dio_aio_read to take IOCB_NOWAIT into account.

---

Resending standalone to get a little more attention.

 fs/xfs/xfs_file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/xfs_file.c +0 -0
index c93250108952..b8a4a3f29b36 100644
@@ -187,7 +187,12 @@ xfs_file_dio_aio_read(
 
 	file_accessed(iocb->ki_filp);
 

fs/xfs/xfs_file.c xfs_file_dio_aio_read( · line 198

Quoted 10 lines
fs/xfs/xfs_file.c +6 -1
-	xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED))
+			return -EAGAIN;
+	} else {
+		xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	}
 	ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL,
 			is_sync_kiocb(iocb));
 	xfs_iunlock(ip, XFS_IOLOCK_SHARED);

Looks good to me.

Signature · 1 line
Carlos
Reviewed-by on v1 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 16 lines · Christoph Hellwig

Direct I/O reads can also be used with RWF_NOWAIT & co. Fix the inode locking in xfs_file_dio_aio_read to take IOCB_NOWAIT into account.

---

Resending standalone to get a little more attention.

 fs/xfs/xfs_file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/xfs_file.c +0 -0
index c93250108952..b8a4a3f29b36 100644

fs/xfs/xfs_file.c xfs_file_dio_aio_read( · line 195

Quoted 10 lines
fs/xfs/xfs_file.c +6 -1
@@ -187,7 +187,12 @@ xfs_file_dio_aio_read(
 
 	file_accessed(iocb->ki_filp);
 
-	xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED))
+			return -EAGAIN;
+	} else {
+		xfs_ilock(ip, XFS_IOLOCK_SHARED);
+	}

/me really wishes we had a better way to do this than to open-code this idiom over and over and over again in every fs. Unfortunately I know of no way to accomplish that without macros(!) so this will have to do:

--D

Quoted 6 lines
fs/xfs/xfs_file.c +0 -0
 	ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL,
 			is_sync_kiocb(iocb));
 	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
Signature · 1 line
2.24.1