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>
Subject: [PATCH v3 01/34] NFSD: Report a first-batch readdir error in the reply status
Date: Mon, 12 Oct 2026 18:02:56 -0400 [thread overview]
Message-ID: <20261012220329.309998-2-cel@kernel.org> (raw)
In-Reply-To: <20261012220329.309998-1-cel@kernel.org>
The NFSv2 READDIR encoder pulls directory entries while the reply
is encoded, after the status word is committed. nfsd_readdir_open()
does not read from the directory, so an iterate_dir() failure on the
first batch surfaces only in nfsd_readdir_next(), where nothing can
turn it into a status. The reply carries NFS_OK, no entries, and eof
false. The client resends the same cookie and receives the same reply,
so a directory that fails with -EIO or -ENOENT traps it in a loop.
Read the first batch in nfsd_readdir_open() so the error selects the
reply status before any of it is committed. An error on a later batch
still cuts the list short with eof false. The client's follow-up
request then starts from that cookie and gets the error in its status.
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/vfs.c | 76 +++++++++++++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 26 deletions(-)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index c7dd94697f2f..c753d3257f1e 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -2397,6 +2397,33 @@ static bool nfsd_buffered_filldir(struct dir_context *ctx, const char *name,
return true;
}
+/*
+ * Read the next batch of entries. Returns false at end of directory
+ * (@iter->eof set) or on a filesystem error (@iter->host_err set).
+ */
+static bool nfsd_readdir_fill(struct nfsd_readdir_iter *iter)
+{
+ /* Between batches the resume cookie advances past the last. */
+ if (iter->batched)
+ iter->offset = vfs_llseek(iter->file, 0, SEEK_CUR);
+
+ iter->used = 0;
+ iter->full = 0;
+ iter->host_err = iterate_dir(iter->file, &iter->ctx);
+ if (iter->full)
+ iter->host_err = 0;
+ if (iter->host_err < 0)
+ return false;
+ if (!iter->used) {
+ iter->eof = true;
+ return false;
+ }
+ iter->batched = true;
+ iter->pos = iter->page;
+ iter->remaining = iter->used;
+ return true;
+}
+
/**
* nfsd_readdir_open - open a directory for streaming readdir
* @rqstp: RPC transaction context
@@ -2404,13 +2431,15 @@ static bool nfsd_buffered_filldir(struct dir_context *ctx, const char *name,
* @offsetp: seek offset at which to resume reading
* @iter: OUT: directory reader to initialize
*
- * On success the directory is open and positioned at @offsetp, and
- * @iter is ready for nfsd_readdir_next(). The caller must release
- * @iter with nfsd_readdir_close() once done, including on error paths
- * that follow a successful open.
+ * On success the directory is open and positioned at @offsetp, the
+ * first batch of entries has been read, and @iter is ready for
+ * nfsd_readdir_next(). The caller must release @iter with
+ * nfsd_readdir_close() once done, including on error paths that
+ * follow a successful open.
*
- * Return: nfs_ok on success, otherwise an nfsstat code. On error @iter
- * is left safe to pass to nfsd_readdir_close().
+ * Return: nfs_ok on success, otherwise an nfsstat code, including the
+ * error from reading the first batch. On error @iter is left safe to
+ * pass to nfsd_readdir_close().
*/
__be32 nfsd_readdir_open(struct svc_rqst *rqstp, struct svc_fh *fhp,
loff_t *offsetp, struct nfsd_readdir_iter *iter)
@@ -2446,6 +2475,17 @@ __be32 nfsd_readdir_open(struct svc_rqst *rqstp, struct svc_fh *fhp,
iter->file = file;
iter->fhp = fhp;
iter->offset = offset;
+
+ /*
+ * The first batch is read here so a filesystem error surfaces
+ * in the reply status. Once the encoder has committed nfs_ok,
+ * an error can only be reported as a short list.
+ */
+ if (!nfsd_readdir_fill(iter) && iter->host_err) {
+ err = nfserrno(iter->host_err);
+ nfsd_readdir_close(iter);
+ return err;
+ }
return nfs_ok;
out_close:
@@ -2470,26 +2510,10 @@ struct buffered_dirent *nfsd_readdir_next(struct nfsd_readdir_iter *iter)
struct buffered_dirent *de;
unsigned int reclen;
- while (iter->remaining <= 0) {
- /* Between batches the resume cookie advances past the last. */
- if (iter->batched)
- iter->offset = vfs_llseek(iter->file, 0, SEEK_CUR);
-
- iter->used = 0;
- iter->full = 0;
- iter->host_err = iterate_dir(iter->file, &iter->ctx);
- if (iter->full)
- iter->host_err = 0;
- if (iter->host_err < 0)
- return NULL;
- if (!iter->used) {
- iter->eof = true;
- return NULL;
- }
- iter->batched = true;
- iter->pos = iter->page;
- iter->remaining = iter->used;
- }
+ if (iter->eof || iter->host_err)
+ return NULL;
+ if (iter->remaining <= 0 && !nfsd_readdir_fill(iter))
+ return NULL;
de = (struct buffered_dirent *)iter->pos;
iter->offset = de->offset;
--
2.55.0
prev parent reply other threads:[~2026-10-12 22:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 22:02 [PATCH v3 00/34] Convert server-side NFSv3 XDR to use xdrgen Chuck Lever
2026-10-12 22:02 ` Chuck Lever [this message]
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=20261012220329.309998-2-cel@kernel.org \
--to=cel@kernel.org \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--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