[PATCH] 9p: Fix O_NONBLOCK read behaviour in P9L_DIRECT mode

From: David Howells
Date: Thu Jul 11 2024 - 09:20:07 EST


With the 9p filesystem, in P9L_DIRECT mode, if O_NONBLOCK is set, a read
should terminate after doing one piece of I/O.

Fixes: 80105ed2fd27 ("9p: Use netfslib read/write_iter")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218916
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
cc: Eric Van Hensbergen <ericvh@xxxxxxxxxx>
cc: Latchesar Ionkov <lucho@xxxxxxxxxx>
cc: Dominique Martinet <asmadeus@xxxxxxxxxxxxx>
cc: Christian Schoenebeck <linux_oss@xxxxxxxxxxxxx>
cc: v9fs@xxxxxxxxxxxxxxx
cc: netfs@xxxxxxxxxxxxxxx
cc: linux-fsdevel@xxxxxxxxxxxxxxx
---
fs/9p/vfs_addr.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
index a97ceb105cd8..b443024bf715 100644
--- a/fs/9p/vfs_addr.c
+++ b/fs/9p/vfs_addr.c
@@ -77,6 +77,10 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq)
* cache won't be on server and is zeroes */
__set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);

+ if ((fid->mode & P9L_DIRECT) &&
+ test_bit(NETFS_RREQ_NONBLOCK, &rreq->flags))
+ set_bit(NETFS_RREQ_BLOCKED, &rreq->flags);
+
netfs_subreq_terminated(subreq, err ?: total, false);
}