public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs
@ 2025-06-13 20:08 Chuck Lever
  2025-06-13 20:08 ` [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read() Chuck Lever
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Chuck Lever @ 2025-06-13 20:08 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey
  Cc: linux-nfs, Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Mike has expressed interest in making NFSD perform direct, uncached,
or asynchronous I/O, independent of how the target file might have
been opened by the file cache. To do that, the idea is to pass in
RWF_ flags during each VFS read and write.

However, Christoph suggested APIs that already exist which
streamline the I/O operation a bit and expose the per-I/O flag
setting directly. The suggestion looks to me like a straightforward
and sensible general clean up of these code paths.

This series refactors nfsd_iter_read() and nfsd_vfs_write() to use
those APIs instead of vfs_iter_read() and vfs_iter_write(),
respectively, as a first baby step down this path. No behavior
change is expected.

Chuck Lever (2):
  NFSD: Use vfs_iocb_iter_read()
  NFSD: Use vfs_iocb_iter_write()

 fs/nfsd/vfs.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read()
  2025-06-13 20:08 [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Chuck Lever
@ 2025-06-13 20:08 ` Chuck Lever
  2025-06-16  5:00   ` Christoph Hellwig
  2025-06-13 20:08 ` [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write() Chuck Lever
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Chuck Lever @ 2025-06-13 20:08 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey
  Cc: linux-nfs, Chuck Lever, Christoph Hellwig

From: Chuck Lever <chuck.lever@oracle.com>

Refactor: Enable the use of IOCB flags to control NFSD's individual
read operations (when not using splice). This allows the eventual
use of atomic, uncached, direct, or asynchronous reads.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/vfs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index cd689df2ca5d..7b3bd141d54f 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1086,10 +1086,14 @@ __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);
+	kiocb.ki_pos = offset;
+	kiocb.ki_flags = 0;
+
 	v = 0;
 	total = *count;
 	while (total) {
@@ -1104,7 +1108,7 @@ __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);
 	return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
 }
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write()
  2025-06-13 20:08 [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Chuck Lever
  2025-06-13 20:08 ` [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read() Chuck Lever
@ 2025-06-13 20:08 ` Chuck Lever
  2025-06-16  5:00   ` Christoph Hellwig
  2025-06-13 21:01 ` [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Jeff Layton
  2025-06-15 22:38 ` NeilBrown
  3 siblings, 1 reply; 7+ messages in thread
From: Chuck Lever @ 2025-06-13 20:08 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey
  Cc: linux-nfs, Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor: Enable the use of IOCB flags to control NFSD's individual
write operations. This allows the eventual use of atomic, uncached,
direct, or asynchronous writes.

Suggested-by: NeilBrown <neil@brown.name>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/vfs.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 7b3bd141d54f..66adeb6ffff5 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1174,15 +1174,14 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	struct nfsd_net		*nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 	struct file		*file = nf->nf_file;
 	struct super_block	*sb = file_inode(file)->i_sb;
+	struct kiocb		kiocb;
 	struct svc_export	*exp;
 	struct iov_iter		iter;
 	errseq_t		since;
 	__be32			nfserr;
 	int			host_err;
-	loff_t			pos = offset;
 	unsigned long		exp_op_flags = 0;
 	unsigned int		pflags = current->flags;
-	rwf_t			flags = 0;
 	bool			restore_flags = false;
 	unsigned int		nvecs;
 
@@ -1208,16 +1207,18 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 
 	if (!EX_ISSYNC(exp))
 		stable = NFS_UNSTABLE;
-
+	init_sync_kiocb(&kiocb, file);
+	kiocb.ki_pos = offset;
+	kiocb.ki_flags = 0;
 	if (stable && !fhp->fh_use_wgather)
-		flags |= RWF_SYNC;
+		kiocb.ki_flags |= IOCB_DSYNC;
 
 	nvecs = xdr_buf_to_bvec(rqstp->rq_bvec, rqstp->rq_maxpages, payload);
 	iov_iter_bvec(&iter, ITER_SOURCE, rqstp->rq_bvec, nvecs, *cnt);
 	since = READ_ONCE(file->f_wb_err);
 	if (verf)
 		nfsd_copy_write_verifier(verf, nn);
-	host_err = vfs_iter_write(file, &iter, &pos, flags);
+	host_err = vfs_iocb_iter_write(file, &kiocb, &iter);
 	if (host_err < 0) {
 		commit_reset_write_verifier(nn, rqstp, host_err);
 		goto out_nfserr;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs
  2025-06-13 20:08 [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Chuck Lever
  2025-06-13 20:08 ` [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read() Chuck Lever
  2025-06-13 20:08 ` [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write() Chuck Lever
@ 2025-06-13 21:01 ` Jeff Layton
  2025-06-15 22:38 ` NeilBrown
  3 siblings, 0 replies; 7+ messages in thread
From: Jeff Layton @ 2025-06-13 21:01 UTC (permalink / raw)
  To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey
  Cc: linux-nfs, Chuck Lever

On Fri, 2025-06-13 at 16:08 -0400, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
> 
> Mike has expressed interest in making NFSD perform direct, uncached,
> or asynchronous I/O, independent of how the target file might have
> been opened by the file cache. To do that, the idea is to pass in
> RWF_ flags during each VFS read and write.
> 
> However, Christoph suggested APIs that already exist which
> streamline the I/O operation a bit and expose the per-I/O flag
> setting directly. The suggestion looks to me like a straightforward
> and sensible general clean up of these code paths.
> 
> This series refactors nfsd_iter_read() and nfsd_vfs_write() to use
> those APIs instead of vfs_iter_read() and vfs_iter_write(),
> respectively, as a first baby step down this path. No behavior
> change is expected.
> 
> Chuck Lever (2):
>   NFSD: Use vfs_iocb_iter_read()
>   NFSD: Use vfs_iocb_iter_write()
> 
>  fs/nfsd/vfs.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)

Looks like a straightforward change to me. Why the RFC? 

Reviewed-by: Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs
  2025-06-13 20:08 [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Chuck Lever
                   ` (2 preceding siblings ...)
  2025-06-13 21:01 ` [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Jeff Layton
@ 2025-06-15 22:38 ` NeilBrown
  3 siblings, 0 replies; 7+ messages in thread
From: NeilBrown @ 2025-06-15 22:38 UTC (permalink / raw)
  To: Chuck Lever
  Cc: Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
	Chuck Lever

On Sat, 14 Jun 2025, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
> 
> Mike has expressed interest in making NFSD perform direct, uncached,
> or asynchronous I/O, independent of how the target file might have
> been opened by the file cache. To do that, the idea is to pass in
> RWF_ flags during each VFS read and write.
> 
> However, Christoph suggested APIs that already exist which
> streamline the I/O operation a bit and expose the per-I/O flag
> setting directly. The suggestion looks to me like a straightforward
> and sensible general clean up of these code paths.
> 
> This series refactors nfsd_iter_read() and nfsd_vfs_write() to use
> those APIs instead of vfs_iter_read() and vfs_iter_write(),
> respectively, as a first baby step down this path. No behavior
> change is expected.
> 
> Chuck Lever (2):
>   NFSD: Use vfs_iocb_iter_read()
>   NFSD: Use vfs_iocb_iter_write()

It important part of this change (as I see it) is that we no longer have
to go through kiocb_set_rw_flags() (which vfs_iter_read/vfs_iter_write
do) but can set the IOCB_ flags directly. Eminently sensible.

Reviewed-by: NeilBrown <neil@brown.name>

Thanks,
NeilBrown

> 
>  fs/nfsd/vfs.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> -- 
> 2.49.0
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read()
  2025-06-13 20:08 ` [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read() Chuck Lever
@ 2025-06-16  5:00   ` Christoph Hellwig
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2025-06-16  5:00 UTC (permalink / raw)
  To: Chuck Lever
  Cc: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	linux-nfs, Chuck Lever, Christoph Hellwig

On Fri, Jun 13, 2025 at 04:08:46PM -0400, Chuck Lever wrote:
> +	init_sync_kiocb(&kiocb, file);
> +	kiocb.ki_pos = offset;
> +	kiocb.ki_flags = 0;

ki_flags is already cleared by init_sync_kiocb, so the line doing that
can be dropped.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write()
  2025-06-13 20:08 ` [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write() Chuck Lever
@ 2025-06-16  5:00   ` Christoph Hellwig
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2025-06-16  5:00 UTC (permalink / raw)
  To: Chuck Lever
  Cc: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	linux-nfs, Chuck Lever

On Fri, Jun 13, 2025 at 04:08:47PM -0400, Chuck Lever wrote:
> +	kiocb.ki_flags = 0;

Same thing here.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-06-16  5:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 20:08 [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Chuck Lever
2025-06-13 20:08 ` [RFC PATCH v2 1/2] NFSD: Use vfs_iocb_iter_read() Chuck Lever
2025-06-16  5:00   ` Christoph Hellwig
2025-06-13 20:08 ` [RFC PATCH v2 2/2] NFSD: Use vfs_iocb_iter_write() Chuck Lever
2025-06-16  5:00   ` Christoph Hellwig
2025-06-13 21:01 ` [RFC PATCH v2 0/2] Make NFSD use the vfs_iocb_iter APIs Jeff Layton
2025-06-15 22:38 ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox