Skip to contentSkip to conversation

NFSD: Use vfs_iocb_iter_read()

RFC PATCH Superseded Chuck Lever 3 participants 3 messages Jun 13, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chuck Lever

author maintainer
#0 lore raw

RFC PATCH 1/1 NFSD: Use vfs_iocb_iter_read()

From: Chuck Lever <[email protected]>

Refactor: Enable the use of RWF_ flags to control individual I/O operations.

---
 fs/nfsd/vfs.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +11 -2
index cd689df2ca5d..f20bacd9b224 100644
@@ -1086,10 +1086,18 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 {
 	unsigned long v, total;
 	struct iov_iter iter;
-	loff_t ppos = offset;
+	struct kiocb kiocb;
 	ssize_t host_err;
 	size_t len;
 
+	init_sync_kiocb(&kiocb, file);
+	host_err = kiocb_set_rw_flags(&kiocb, 0, READ);
+	if (host_err) {
+		*count = 0;
+		goto out;
+	}
+	kiocb.ki_pos = offset;
+
 	v = 0;
 	total = *count;
 	while (total) {
@@ -1104,7 +1112,8 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 
 	trace_nfsd_read_vector(rqstp, fhp, offset, *count);
 	iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count);
-	host_err = vfs_iter_read(file, &iter, &ppos, 0);
+	host_err = vfs_iocb_iter_read(file, &kiocb, &iter);
+out:
 	return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
 }
 
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Chuck Lever

From: Chuck Lever <[email protected]>

Refactor: Enable the use of RWF_ flags to control individual I/O operations.

RWF_ flags such as .... ???

I'm guessing RWF_DIRECT and maybe RWF_NOWAIT based on the earlier conversation. Might be useful to provide this as explicit motivation.

But seeing they will be passed to kiocb_set_rw_flags(), shouldn't we be talking about the IOCB_ versions of the flags? The only caller of kiocb_set_rw_flags() I can find which doesn't pass zero is aio_prep_rw() and it uses the IOCB_ versions.

And should we be changing the vfs_iter_write() to vfs_iocb_iter_write() too, just for consistency?

Quoted 3 lines

3 more callers to go and vfs_iter_read() could be discarded.

NeilBrown

Quoted 42 lines
---
 fs/nfsd/vfs.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +11 -2
index cd689df2ca5d..f20bacd9b224 100644
@@ -1086,10 +1086,18 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 {
 	unsigned long v, total;
 	struct iov_iter iter;
-	loff_t ppos = offset;
+	struct kiocb kiocb;
 	ssize_t host_err;
 	size_t len;
 
+	init_sync_kiocb(&kiocb, file);
+	host_err = kiocb_set_rw_flags(&kiocb, 0, READ);
+	if (host_err) {
+		*count = 0;
+		goto out;
+	}
+	kiocb.ki_pos = offset;
+
 	v = 0;
 	total = *count;
 	while (total) {
@@ -1104,7 +1112,8 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 
 	trace_nfsd_read_vector(rqstp, fhp, offset, *count);
 	iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count);
-	host_err = vfs_iter_read(file, &iter, &ppos, 0);
+	host_err = vfs_iocb_iter_read(file, &kiocb, &iter);
+out:
 	return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
 }
 
Signature · 1 line
2.49.0
#2 lore raw
In reply to Chuck Lever
Quoted 4 lines · Chuck Lever

From: Chuck Lever <[email protected]>

Refactor: Enable the use of RWF_ flags to control individual I/O operations.

The IOCB_ ones, really.

fs/nfsd/vfs.c __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 1098

Quoted 5 lines
fs/nfsd/vfs.c +5 -0
+	host_err = kiocb_set_rw_flags(&kiocb, 0, READ);
+	if (host_err) {
+		*count = 0;
+		goto out;
+	}

And if you don't want to explicitly convert from RWF_* flags, this is pointless. Just drop it for now and explicitly set the IOCB_ flags we want once we add some.