From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>, Christoph Hellwig <hch@lst.de>,
Chuck Lever <chuck.lever@oracle.com>,
Mike Snitzer <snitzer@kernel.org>
Subject: [PATCH v8 06/12] NFSD: Clean up struct nfsd_write_dio
Date: Mon, 27 Oct 2025 11:46:24 -0400 [thread overview]
Message-ID: <20251027154630.1774-7-cel@kernel.org> (raw)
In-Reply-To: <20251027154630.1774-1-cel@kernel.org>
From: Chuck Lever <chuck.lever@oracle.com>
Prepare for moving more common arguments into the shared per-request
structure.
First step is to move the target nfsd_file into that structure, as
it needs to be available in several functions.
As a clean-up, adopt the conventional naming of a structure that
carries the same arguments for a number of functions.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/vfs.c | 67 +++++++++++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 31 deletions(-)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 80bc105eb0b6..326c60eada65 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1254,7 +1254,9 @@ static int wait_for_concurrent_writes(struct file *file)
return err;
}
-struct nfsd_write_dio {
+struct nfsd_write_dio_args {
+ struct nfsd_file *nf;
+
ssize_t start_len; /* Length for misaligned first extent */
ssize_t middle_len; /* Length for DIO-aligned middle extent */
ssize_t end_len; /* Length for misaligned last extent */
@@ -1262,12 +1264,12 @@ struct nfsd_write_dio {
static bool
nfsd_is_write_dio_possible(loff_t offset, unsigned long len,
- struct nfsd_file *nf, struct nfsd_write_dio *write_dio)
+ struct nfsd_write_dio_args *args)
{
- const u32 dio_blocksize = nf->nf_dio_offset_align;
+ u32 dio_blocksize = args->nf->nf_dio_offset_align;
loff_t start_end, orig_end, middle_end;
- if (unlikely(!nf->nf_dio_mem_align || !dio_blocksize))
+ if (unlikely(!args->nf->nf_dio_mem_align || !dio_blocksize))
return false;
if (unlikely(len < dio_blocksize))
return false;
@@ -1276,16 +1278,18 @@ nfsd_is_write_dio_possible(loff_t offset, unsigned long len,
orig_end = offset + len;
middle_end = round_down(orig_end, dio_blocksize);
- write_dio->start_len = start_end - offset;
- write_dio->middle_len = middle_end - start_end;
- write_dio->end_len = orig_end - middle_end;
+ args->start_len = start_end - offset;
+ args->middle_len = middle_end - start_end;
+ args->end_len = orig_end - middle_end;
return true;
}
-static bool nfsd_iov_iter_aligned_bvec(const struct iov_iter *i,
- unsigned int addr_mask, unsigned int len_mask)
+static bool
+nfsd_iov_iter_aligned_bvec(const struct nfsd_file *nf, const struct iov_iter *i)
{
+ unsigned int len_mask = nf->nf_dio_offset_align - 1;
+ unsigned int addr_mask = nf->nf_dio_mem_align - 1;
const struct bio_vec *bvec = i->bvec;
size_t skip = i->iov_offset;
size_t size = i->count;
@@ -1314,37 +1318,35 @@ static bool nfsd_iov_iter_aligned_bvec(const struct iov_iter *i,
static int
nfsd_setup_write_dio_iters(struct iov_iter **iterp, bool *iter_is_dio_aligned,
struct bio_vec *rq_bvec, unsigned int nvecs,
- unsigned long cnt, struct nfsd_write_dio *write_dio,
- struct nfsd_file *nf)
+ unsigned long cnt, struct nfsd_write_dio_args *args)
{
int n_iters = 0;
struct iov_iter *iters = *iterp;
/* Setup misaligned start? */
- if (write_dio->start_len) {
+ if (args->start_len) {
iov_iter_bvec(&iters[n_iters], ITER_SOURCE, rq_bvec, nvecs, cnt);
- iters[n_iters].count = write_dio->start_len;
+ iters[n_iters].count = args->start_len;
iter_is_dio_aligned[n_iters] = false;
++n_iters;
}
/* Setup DIO-aligned middle */
iov_iter_bvec(&iters[n_iters], ITER_SOURCE, rq_bvec, nvecs, cnt);
- if (write_dio->start_len)
- iov_iter_advance(&iters[n_iters], write_dio->start_len);
- iters[n_iters].count -= write_dio->end_len;
+ if (args->start_len)
+ iov_iter_advance(&iters[n_iters], args->start_len);
+ iters[n_iters].count -= args->end_len;
iter_is_dio_aligned[n_iters] =
- nfsd_iov_iter_aligned_bvec(&iters[n_iters],
- nf->nf_dio_mem_align-1, nf->nf_dio_offset_align-1);
+ nfsd_iov_iter_aligned_bvec(args->nf, &iters[n_iters]);
if (unlikely(!iter_is_dio_aligned[n_iters]))
return 0; /* no DIO-aligned IO possible */
++n_iters;
/* Setup misaligned end? */
- if (write_dio->end_len) {
+ if (args->end_len) {
iov_iter_bvec(&iters[n_iters], ITER_SOURCE, rq_bvec, nvecs, cnt);
iov_iter_advance(&iters[n_iters],
- write_dio->start_len + write_dio->middle_len);
+ args->start_len + args->middle_len);
iter_is_dio_aligned[n_iters] = false;
++n_iters;
}
@@ -1370,11 +1372,11 @@ nfsd_buffered_write(struct svc_rqst *rqstp, struct file *file,
}
static int
-nfsd_issue_write_dio(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,
- u32 *stable_how, unsigned int nvecs, unsigned long *cnt,
- struct kiocb *kiocb, struct nfsd_write_dio *write_dio)
+nfsd_issue_write_dio(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *stable_how,
+ struct kiocb *kiocb, unsigned int nvecs, unsigned long *cnt,
+ struct nfsd_write_dio_args *args)
{
- struct file *file = nf->nf_file;
+ struct file *file = args->nf->nf_file;
bool iter_is_dio_aligned[3];
struct iov_iter iter_stack[3];
struct iov_iter *iter = iter_stack;
@@ -1384,7 +1386,8 @@ nfsd_issue_write_dio(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_fil
ssize_t host_err;
n_iters = nfsd_setup_write_dio_iters(&iter, iter_is_dio_aligned,
- rqstp->rq_bvec, nvecs, *cnt, write_dio, nf);
+ rqstp->rq_bvec, nvecs, *cnt,
+ args);
if (unlikely(!n_iters))
return nfsd_buffered_write(rqstp, file, nvecs, cnt, kiocb);
@@ -1421,21 +1424,23 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
struct nfsd_file *nf, u32 *stable_how, unsigned int nvecs,
unsigned long *cnt, struct kiocb *kiocb)
{
- struct nfsd_write_dio write_dio;
+ struct nfsd_write_dio_args args;
+
+ args.nf = nf;
/*
* Check if IOCB_DONTCACHE can be used when issuing buffered IO;
* if so, set it to preserve intent of NFSD_IO_DIRECT (it will
* be ignored for any DIO issued here).
*/
- if (nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
+ if (args.nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
kiocb->ki_flags |= IOCB_DONTCACHE;
- if (nfsd_is_write_dio_possible(kiocb->ki_pos, *cnt, nf, &write_dio))
- return nfsd_issue_write_dio(rqstp, fhp, nf, stable_how, nvecs,
- cnt, kiocb, &write_dio);
+ if (nfsd_is_write_dio_possible(kiocb->ki_pos, *cnt, &args))
+ return nfsd_issue_write_dio(rqstp, fhp, stable_how, kiocb,
+ nvecs, cnt, &args);
- return nfsd_buffered_write(rqstp, nf->nf_file, nvecs, cnt, kiocb);
+ return nfsd_buffered_write(rqstp, args.nf->nf_file, nvecs, cnt, kiocb);
}
/**
--
2.51.0
next prev parent reply other threads:[~2025-10-27 15:46 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 15:46 [PATCH v8 00/12] NFSD: Implement NFSD_IO_DIRECT for NFS WRITE Chuck Lever
2025-10-27 15:46 ` [PATCH v8 01/12] NFSD: Make FILE_SYNC WRITEs comply with spec Chuck Lever
2025-10-27 15:46 ` [PATCH v8 02/12] NFSD: Enable return of an updated stable_how to NFS clients Chuck Lever
2025-10-27 15:46 ` [PATCH v8 03/12] NFSD: Implement NFSD_IO_DIRECT for NFS WRITE Chuck Lever
2025-10-27 15:46 ` [PATCH v8 04/12] NFSD: Remove specific error handling Chuck Lever
2025-10-27 15:46 ` [PATCH v8 05/12] NFSD: Remove alignment size checking Chuck Lever
2025-10-27 15:46 ` Chuck Lever [this message]
2025-10-27 15:46 ` [PATCH v8 07/12] NFSD: Introduce struct nfsd_write_dio_seg Chuck Lever
2025-10-27 15:46 ` [PATCH v8 08/12] NFSD: Simplify nfsd_iov_iter_aligned_bvec() Chuck Lever
2025-10-30 15:00 ` Jeff Layton
2025-10-31 13:16 ` Christoph Hellwig
2025-10-27 15:46 ` [PATCH v8 09/12] NFSD: Handle both offset and memory alignment for direct I/O Chuck Lever
2025-10-30 19:52 ` Jeff Layton
2025-10-30 19:55 ` Chuck Lever
2025-10-31 9:13 ` Christoph Hellwig
2025-10-31 13:19 ` Christoph Hellwig
2025-10-31 13:21 ` Chuck Lever
2025-10-31 13:23 ` Christoph Hellwig
2025-10-31 16:07 ` Mike Snitzer
2025-10-27 15:46 ` [PATCH v8 10/12] NFSD: Combine direct I/O feasibility check with iterator setup Chuck Lever
2025-10-30 19:59 ` Jeff Layton
2025-10-31 13:20 ` Christoph Hellwig
2025-10-27 15:46 ` [PATCH v8 11/12] NFSD: Handle kiocb->ki_flags correctly Chuck Lever
2025-10-30 20:01 ` Jeff Layton
2025-10-31 13:21 ` Christoph Hellwig
2025-10-27 15:46 ` [PATCH v8 12/12] NFSD: Refactor nfsd_vfs_write Chuck Lever
2025-10-30 20:02 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251027154630.1774-7-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=hch@lst.de \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=snitzer@kernel.org \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox