NFSD: Refactor NFSv3 directory entry encoding
Subsystems (4)
Chuck Lever
maintainerPATCH v3 30/34 NFSD: Refactor NFSv3 directory entry encoding
The current synopsis of svcxdr_encode_entry3_common() takes a "struct nfsd3_readdirres" argument, which is common to the NFSv3 READDIR and READDIRPLUS procedures.
However, xdrgen defines two distinct argument structures for these procedures, since they are actually two distinct RPC procedures and have different arguments.
With both a "struct READDIR3args" and a "struct READDIRPLUS3args," the directory entry encoders will need to incorporate the common entry encoding.
--- fs/nfsd/nfs3xdr.c | 70 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 36 deletions(-)
fs/nfsd/nfs3xdr.c +34 -36
@@ -306,7 +306,7 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,* @cookie: cookie to be encoded * * The buffer space for the offset cookie has already been reserved -* by svcxdr_encode_entry3_common(). +* by nfs3svc_encode_entry3() or nfs3svc_encode_entryplus3(). */ void nfs3svc_encode_cookie3 (struct xdr_stream *xdr,unsigned int pos,u64 cookie)
@@ -318,29 +318,6 @@ void nfs3svc_encode_cookie3(struct xdr_stream *xdr, unsigned int pos,write_bytes_to_xdr_buf (xdr->buf, pos, &wire_cookie,XDR_UNIT *2 ); } -static bool -svcxdr_encode_entry3_common (struct nfsd3_readdirres *resp,const char *name, -int namlen,loff_t offset,u64 ino) -{ -struct xdr_buf *dirlist = &resp->dirlist; -struct xdr_stream *xdr = &resp->xdr; - -if (xdr_stream_encode_item_present (xdr) <0 ) -return false; -/* fileid */ -if (xdr_stream_encode_u64 (xdr, ino) <0 ) -return false; -/* name */ -if (xdr_stream_encode_opaque (xdr, name,min (namlen,NFS3_MAXNAMLEN )) <0 ) -return false; -/* cookie */ - resp->cookie_offset = dirlist->len; -if (xdr_stream_encode_u64 (xdr,OFFSET_MAX ) <0 ) -return false; - -return true; -} -/** * nfs3svc_encode_entry3 - encode one NFSv3 READDIR entry * @data: directory context
@@ -363,18 +340,28 @@ int nfs3svc_encode_entry3(void *data, const char *name, int namlen, loff_t offset, u64 ino, unsigned int d_type) { struct readdir_cd *ccd = data; -struct nfsd3_readdirres *resp =container_of (ccd, - struct nfsd3_readdirres, - common); +struct nfsd3_readdirres *resp = + container_of(ccd, struct nfsd3_readdirres, common);unsigned int starting_length = resp->dirlist.len; +struct xdr_stream *xdr = &resp->xdr;/* The offset cookie for the previous entry */ -nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset); +nfs3svc_encode_cookie3 (xdr, resp->cookie_offset, offset); -if (!svcxdr_encode_entry3_common (resp, name, namlen, offset, ino)) +if (xdr_stream_encode_item_present (xdr) <0 ) + goto out_toosmall; +/* fileid */ +if (xdr_stream_encode_u64 (xdr, ino) <0 ) + goto out_toosmall; +/* name */ +if (xdr_stream_encode_opaque (xdr, name,min (namlen,NFS3_MAXNAMLEN )) <0 ) + goto out_toosmall; +/* cookie */ + resp->cookie_offset = resp->dirlist.len; +if (xdr_stream_encode_u64 (xdr,OFFSET_MAX ) <0 ) goto out_toosmall; -xdr_commit_encode (&resp->xdr); +xdr_commit_encode (xdr); resp->common.err = nfs_ok;return 0 ;
@@ -438,20 +425,31 @@ int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen, loff_t offset, u64 ino, unsigned int d_type) { struct readdir_cd *ccd = data; -struct nfsd3_readdirres *resp =container_of (ccd, - struct nfsd3_readdirres, - common); +struct nfsd3_readdirres *resp = + container_of(ccd, struct nfsd3_readdirres, common);unsigned int starting_length = resp->dirlist.len; +struct xdr_stream *xdr = &resp->xdr;/* The offset cookie for the previous entry */ -nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset); +nfs3svc_encode_cookie3 (xdr, resp->cookie_offset, offset); -if (!svcxdr_encode_entry3_common (resp, name, namlen, offset, ino)) +if (xdr_stream_encode_item_present (xdr) <0 ) goto out_toosmall; +/* fileid */ +if (xdr_stream_encode_u64 (xdr, ino) <0 ) + goto out_toosmall; +/* name */ +if (xdr_stream_encode_opaque (xdr, name,min (namlen,NFS3_MAXNAMLEN )) <0 ) + goto out_toosmall; +/* cookie */ + resp->cookie_offset = resp->dirlist.len; +if (xdr_stream_encode_u64 (xdr,OFFSET_MAX ) <0 ) + goto out_toosmall; +if (!svcxdr_encode_entry3_plus (resp, name, namlen, ino)) goto out_toosmall; -xdr_commit_encode (&resp->xdr); +xdr_commit_encode (xdr); resp->common.err = nfs_ok;return 0 ;
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v3 31/34 NFSD: Split struct nfsd3_readdirres
Currently NFSv3 READDIR and READDIRPLUS share the same C structure for encoding their results.
xdrgen defines two distinct result structures for the NFSv3 READDIR and READDIRPLUS procedures since they are actually two distinct procedures and have different result types.
Define a duplicate of struct nfsd3_readdirres to be used with READDIRPLUS. Then duplicate nfsd3_init_dirlist_pages() and nfs3svc_encode_readdirplusres() . These duplicates will use the new result type for NFSv3 READDIRPLUS.
--- fs/nfsd/nfs3proc.c | 30 ++++++++++++++++++++++++++---- fs/nfsd/nfs3xdr.c | 39 ++++++++++++++++++++++++++++++++++----- fs/nfsd/xdr3.h | 17 +++++++++++++++++ 3 files changed, 77 insertions(+), 9 deletions(-)
fs/nfsd/nfs3proc.c +26 -4
@@ -1238,6 +1238,27 @@ static __be32 nfsd3_proc_symlink(struct svc_rqst *rqstp)return rpc_success; } +static void +nfsd3_init_dirlistplus_pages (struct svc_rqst *rqstp, +struct nfsd3_readdirplusres *resp, +u32 count) +{ +struct xdr_buf *buf = &resp->dirlist; +struct xdr_stream *xdr = &resp->xdr; + unsigned int sendbuf = min_t(unsigned int, rqstp->rq_res.buflen, +svc_max_payload (rqstp)); + +memset (buf,0 ,sizeof (*buf)); + +/* Reserve room for the NULL ptr & eof flag (-2 words) */ + buf->buflen =clamp (count, (u32)(XDR_UNIT *2 ), sendbuf); + buf->buflen -=XDR_UNIT *2 ; + buf->pages = rqstp->rq_next_page; + rqstp->rq_next_page += (buf->buflen +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + +xdr_init_encode_pages (xdr, buf); +} +/** * nfsd3_proc_mknod - MKNOD: Create a special file * @rqstp: RPC transaction context
@@ -1571,7 +1592,7 @@ static __be32 nfsd3_proc_readdir(struct svc_rqst *rqstp)static __be32 nfsd3_proc_readdirplus (struct svc_rqst *rqstp) {struct READDIRPLUS3args_wrapper *argp = rqstp->rq_argp; -struct nfsd3_readdirres *resp = rqstp->rq_resp; +struct nfsd3_readdirplusres *resp = rqstp->rq_resp;loff_t offset = argp->xdrgen.cookie;struct svc_fh *fhp = &argp->fh;
@@ -1579,7 +1600,7 @@ static __be32 nfsd3_proc_readdirplus(struct svc_rqst *rqstp)trace_nfsd_vfs_readdir (rqstp, fhp, argp->xdrgen.maxcount, argp->xdrgen.cookie); -nfsd3_init_dirlist_pages (rqstp, resp, argp->xdrgen.maxcount); +nfsd3_init_dirlistplus_pages (rqstp, resp, argp->xdrgen.maxcount);fh_copy (&resp->fh, fhp); resp->common.err = nfs_ok; resp->cookie_offset =0 ;
@@ -2030,11 +2051,11 @@ static const struct svc_procedure nfsd_procedures3[22] = { [NFSPROC3_READDIRPLUS] = { .pc_func = nfsd3_proc_readdirplus, .pc_decode = nfs_svc_decode_READDIRPLUS3args, - .pc_encode = nfs3svc_encode_readdirres, + .pc_encode = nfs3svc_encode_readdirplusres, .pc_release = nfs3svc_release_fhandle, .pc_argsize = sizeof(struct READDIRPLUS3args_wrapper), .pc_argzero = 0, - .pc_ressize = sizeof(struct nfsd3_readdirres), + .pc_ressize = sizeof(struct nfsd3_readdirplusres), .pc_cachetype = RC_NOCACHE, .pc_name = "READDIRPLUS", },
@@ -2121,6 +2142,7 @@ union nfsd3_xdrstore {struct READ3res readres;struct nfsd3_writeres writeres;struct nfsd3_readdirres readdirres; +struct nfsd3_readdirplusres readdirplusres;struct FSSTAT3args_wrapper fsstatargs;struct nfsd3_fsstatres fsstatres;struct FSINFO3args_wrapper fsinfoargs;
fs/nfsd/nfs3xdr.c +34 -5
@@ -228,7 +228,6 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,* XDR encode functions */ -/* READDIR */ bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
@@ -259,8 +258,38 @@ nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr)return true; } +bool +nfs3svc_encode_readdirplusres (struct svc_rqst *rqstp,struct xdr_stream *xdr) +{ +struct nfsd3_readdirplusres *resp = rqstp->rq_resp; +struct xdr_buf *dirlist = &resp->dirlist; + +if (!svcxdr_encode_nfsstat3 (xdr, resp->status)) +return false; +switch (resp->status) { +case nfs_ok: +if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +return false; +if (!svcxdr_encode_cookieverf3 (xdr, resp->verf)) +return false; +svcxdr_encode_opaque_pages (rqstp, xdr, dirlist->pages,0 , + dirlist->len); +/* no more entries */ +if (xdr_stream_encode_item_absent (xdr) <0 ) +return false; +if (xdr_stream_encode_bool (xdr, resp->common.err == nfserr_eof) <0 ) +return false; +break ; +default : +if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +return false; + } + +return true; +} +static __be32 -compose_entry_fh (struct nfsd3_readdirres *cd,struct svc_fh *fhp, +compose_entry_fh (struct nfsd3_readdirplusres *cd,struct svc_fh *fhp,const char *name,int namlen,u64 ino) {struct svc_export *exp;
@@ -373,7 +402,7 @@ int nfs3svc_encode_entry3(void *data, const char *name, int namlen, }static bool -svcxdr_encode_entry3_plus (struct nfsd3_readdirres *resp,const char *name, +svcxdr_encode_entry3_plus (struct nfsd3_readdirplusres *resp,const char *name,int namlen,u64 ino) {struct xdr_stream *xdr = &resp->xdr;
@@ -425,8 +454,8 @@ int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen, loff_t offset, u64 ino, unsigned int d_type) { struct readdir_cd *ccd = data; -struct nfsd3_readdirres *resp = - container_of(ccd, struct nfsd3_readdirres, common); +struct nfsd3_readdirplusres *resp = + container_of(ccd, struct nfsd3_readdirplusres, common);unsigned int starting_length = resp->dirlist.len;struct xdr_stream *xdr = &resp->xdr;
fs/nfsd/xdr3.h +17 -0
@@ -72,6 +72,22 @@ struct nfsd3_readdirres { }; +struct nfsd3_readdirplusres { +/* Components of the reply */ +__be32 status; +struct svc_fh fh; +__be32 verf[2 ]; + +/* Used to encode the reply's entry list */ +struct xdr_stream xdr; +struct xdr_buf dirlist; +struct svc_fh scratch; +struct readdir_cd common; +unsigned int cookie_offset; +struct svc_rqst * rqstp; + +}; +struct nfsd3_fsstatres {struct FSSTAT3res xdrgen;struct kstatfs stats;
@@ -108,6 +124,7 @@ struct nfsd3_getaclres {bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr); +bool nfs3svc_encode_readdirplusres (struct svc_rqst *rqstp,struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v3 32/34 NFSD: Use xdrgen XDR functions for NFSv3 READDIR results
In reply to Chuck LeverNFSv3 READDIR's reply is still produced by a hand-written encoder. Its entry list is the value-follows form of RFC 1813's "entry3 *entries" -- each entry prefixed by TRUE, the sequence closed by FALSE -- streamed straight from the directory as it is read rather than from a materialized array. The generated encoder could not drive that: the union encoder writes the reply status word before the entry list, yet a streamed read does not learn the status until the directory has been opened, and the aggregate loop was bounded by a count the begin hook had to supply up front.
The preceding NFSv2 work removed both obstacles in shared code. The optional-data aggregate encoder pulls entries until the hook signals end, so no count is needed, and the streaming directory reader yields one entry at a time during encode. Mark dirlist3's entry list as an aggregate and regenerate; the struct definitions stay the verbatim RFC 1813 types, and the lone "pragma aggregate dirlist3 entries" selects the hook-driven codec.
Split the read across the two phases so the generated encoder owns the framing. nfsd3_proc_readdir() opens the directory, where an open error becomes the reply status the union encoder then writes, and fills the directory attributes and cookie verifier that precede the entry list. The encode hooks stream the entries: each pull reserves a placeholder cookie and back-patches the preceding entry's cookie once the following entry's resume offset is known; the end hook back-patches the final cookie and reports eof. The end hook also advances rq_next_page past the pages the entry list filled, because svcrdma and svc_rqst_release_pages() handle only the reply pages below it. nfs3svc_release_readdirres() closes the reader and releases the file handle. Set pc_argzero to clear the argument wrapper, because svc_release_rqst() calls that hook even when argument decoding fails and nfsd3_proc_readdir() never initializes the file handle.
struct nfsd3_readdirres now embeds struct READDIR3res so the RPC dispatch layer can cast the response to its xdrgen type, and holds the streaming reader in place of the old page-buffer state. READDIR3args_wrapper moves to xdr3.h so the encode and release paths can reach the directory file handle.
A host error during the streamed read ends the list as a truncated, non-eof reply rather than an error status. By then the generated union encoder has committed NFS3_OK and the resok fields ahead of the entry list, and the aggregate hooks cannot rewind the stream to re-encode the reply as resfail. The client resumes from the last cookie, so its follow-up READDIR starts at the failing batch, and nfsd_readdir_open() reports the error as the reply status there. An error opening the directory is still reported as the reply status. The bytes on the wire are otherwise unchanged.
nfs3svc_encode_readdirres() and nfs3svc_encode_entry3() no longer have any callers, so they are removed.
--- Documentation/sunrpc/xdr/nfs3.x | 10 ++ fs/nfsd/nfs3proc.c | 68 ++++----- fs/nfsd/nfs3xdr.c | 226 +++++++++++++++++++---------- fs/nfsd/nfs3xdr_gen.c | 35 ++++- fs/nfsd/nfs3xdr_gen.h | 13 +- fs/nfsd/xdr3.h | 39 +++-- include/linux/sunrpc/xdrgen/nfs3.h | 2 +- 7 files changed, 245 insertions(+), 148 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +10 -0
@@ -627,6 +627,16 @@ struct dirlist3 { bool eof; }; +/* + * The entry list encodes as the value-follows form of "entry3 + * *entries" -- each entry prefixed by TRUE, the sequence closed by + * FALSE -- and the encode hooks stream it straight from the directory + * during reply encoding rather than from a materialized array. The + * struct definitions above are the verbatim RFC 1813 types; only this + * pragma selects the hook-driven codec. + */ +pragma aggregate dirlist3 entries; + struct READDIR3resok { post_op_attr dir_attributes; cookieverf3 cookieverf;
fs/nfsd/nfs3proc.c +25 -43
106 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +147 -79
256 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.c +27 -8
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 // Generated by xdrgen. Manual edits will be lost. // XDR specification file: Documentation/sunrpc/xdr/nfs3.x -// XDR specification modification time: Tue Jul 14 12:13:57 2026 +// XDR specification modification time: Tue Jul 14 20:36:22 2026 #include <linux/sunrpc/svc.h>
@@ -1258,11 +1258,7 @@ xdrgen_decode_entry3(struct xdr_stream *xdr, struct entry3 *ptr)static bool __maybe_unused xdrgen_decode_dirlist3 (struct xdr_stream *xdr,struct dirlist3 *ptr) { -if (!xdrgen_decode_entry3 (xdr, ptr->entries)) -return false; -if (!xdrgen_decode_bool (xdr, &ptr->eof)) -return false; -return true; +return false; } static bool __maybe_unused
@@ -3089,8 +3085,31 @@ xdrgen_encode_entry3(struct xdr_stream *xdr, const struct entry3 *value)static bool __maybe_unused xdrgen_encode_dirlist3 (struct xdr_stream *xdr,const struct dirlist3 *value) { -if (!xdrgen_encode_entry3 (xdr, value->entries)) -return false; + { +struct xdrgen_aggregate_cursor cursor = { + .xdr = xdr, + .member_id =NFS3_DIRLIST3_ENTRIES , + .ctx = xdr->xdrgen_ctx, + }; +bool ok = true; + +if (!nfs3_dirlist3_encode_begin (&cursor)) +return false; +for (cursor.index =0 ; ; cursor.index++) { +struct entry3 element = {}; + +if (!nfs3_dirlist3_encode (&cursor, &element)) +break ; +if (!xdrgen_encode_entry3 (xdr, &element)) { + ok = false; +break ; + } + } +if (ok && !xdrgen_encode_entry3 (xdr,NULL )) + ok = false; +if (!nfs3_dirlist3_encode_end (&cursor, ok) || !ok) +return false; + }if (!xdrgen_encode_bool (xdr, value->eof))return false;return true;
fs/nfsd/nfs3xdr_gen.h +12 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ -/* XDR specification modification time: Tue Jul 14 12:13:57 2026 */ +/* XDR specification modification time: Tue Jul 14 20:36:22 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
@@ -13,6 +13,17 @@#include <linux/sunrpc/xdrgen/_builtins.h> #include <linux/sunrpc/xdrgen/nfs3.h> +enum { +NFS3_DIRLIST3_ENTRIES , +}; + +bool nfs3_dirlist3_encode_begin (struct xdrgen_aggregate_cursor *c); +bool nfs3_dirlist3_encode (struct xdrgen_aggregate_cursor *c,struct entry3 *out); +bool nfs3_dirlist3_encode_end (struct xdrgen_aggregate_cursor *c,bool ok); +bool nfs3_dirlist3_decode_begin (struct xdrgen_aggregate_cursor *c); +bool nfs3_dirlist3_decode (struct xdrgen_aggregate_cursor *c,const struct entry3 *in); +bool nfs3_dirlist3_decode_end (struct xdrgen_aggregate_cursor *c,bool ok); +bool nfs_svc_decode_GETATTR3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs_svc_decode_SETATTR3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs_svc_decode_LOOKUP3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);
fs/nfsd/xdr3.h +23 -16
@@ -56,22 +56,31 @@ struct nfsd3_writeres {static_assert (offsetof(struct nfsd3_writeres , xdrgen) ==0 ); -struct nfsd3_readdirres { -/* Components of the reply */ -__be32 status; +/* +* Declared here rather than in nfs3proc.c with the other proc wrappers +* because READDIR's encode path in nfs3xdr.c reads the file handle from +* it during encode and release. The xdrgen field must be first so the +* struct can be cast to its XDR type for the RPC dispatch layer. +*/ +struct READDIR3args_wrapper { +struct READDIR3args xdrgen;struct svc_fh fh; -__be32 verf[2 ]; - -/* Used to encode the reply's entry list */ -struct xdr_stream xdr; -struct xdr_buf dirlist; -struct svc_fh scratch; -struct readdir_cd common; -unsigned int cookie_offset; -struct svc_rqst * rqstp; - }; +static_assert (offsetof(struct READDIR3args_wrapper , xdrgen) ==0 ); + +struct nfsd3_readdirres { +struct READDIR3res xdrgen; + +/* Streaming state for encoding the reply's entry list */ +struct nfsd_readdir_iter iter;/* directory reader */ +u32 count;/* client's reply size hint */ +u32 space_left;/* remaining entry budget */ +unsigned int cookie_offset;/* prev entry's cookie slot */ +}; + +static_assert (offsetof(struct nfsd3_readdirres , xdrgen) ==0 ); +struct nfsd3_readdirplusres {/* Components of the reply */ __be32 status;
@@ -123,15 +132,13 @@ struct nfsd3_getaclres { };bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirplusres (struct svc_rqst *rqstp,struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *); +void nfs3svc_release_readdirres (struct svc_rqst *rqstp);void nfs3svc_encode_cookie3 (struct xdr_stream *xdr,unsigned int pos,u64 cookie); -int nfs3svc_encode_entry3 (void *data,const char *name,int namlen, -loff_t offset,u64 ino,unsigned int d_type);int nfs3svc_encode_entryplus3 (void *data,const char *name,int namlen,loff_t offset,u64 ino,unsigned int d_type);/* Helper functions for NFSv3 ACL code */
include/linux/sunrpc/xdrgen/nfs3.h +1 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ -/* XDR specification modification time: Tue Jul 14 12:13:57 2026 */ +/* XDR specification modification time: Tue Jul 14 20:36:22 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v3 33/34 NFSD: Use xdrgen XDR functions for NFSv3 READDIRPLUS results
In reply to Chuck LeverNFSv3 READDIRPLUS's reply is still produced by a hand-written encoder. Like READDIR, its entry list is the value-follows form of RFC 1813's "entryplus3 *entries" -- each entry prefixed by TRUE, the sequence closed by FALSE -- streamed from the directory as it is read. Each entry additionally carries the object's post-op attributes and file handle. The hand-written encoder materialized the whole list into page memory during nfsd_readdir(), then copied it into the reply as an opaque blob.
The preceding READDIR conversion built the streaming machinery in shared code: the optional-data aggregate encoder pulls entries until the hook signals end, and the streaming directory reader yields one entry at a time during encode. Mark dirlistplus3's entry list as an aggregate and regenerate; the struct definitions stay the verbatim RFC 1813 types, and the lone "pragma aggregate dirlistplus3 entries" selects the hook-driven codec.
Split the read across the two phases so the generated encoder owns the framing. nfsd3_proc_readdirplus() opens the directory, where an open error becomes the reply status the union encoder then writes, and fills the directory attributes and cookie verifier that precede the entry list. The encode hooks stream the entries: each pull composes the entry's post-op attributes and file handle with the same fill helpers the per-procedure encoders use, reserves a placeholder cookie, and back-patches the preceding entry's cookie once the following entry's resume offset is known. Because an entryplus3's cookie is not its final field, the hook records the cookie's slot from the entry's start position rather than from the tail of the stream. The end hook advances rq_next_page
past the pages the entry list filled, as the READDIR end hook does. nfs3svc_release_readdirplusres() closes the reader and releases the file handle. Set pc_argzero to clear the argument wrapper, because svc_release_rqst() calls that hook even when argument decoding fails and nfsd3_proc_readdirplus() never initializes the file handle.
struct nfsd3_readdirplusres now embeds struct READDIRPLUS3res so the RPC dispatch layer can cast the response to its xdrgen type, and holds the streaming reader in place of the old page-buffer state. READDIRPLUS3args_wrapper moves to xdr3.h so the encode and release paths can reach the directory file handle.
A host error during the streamed read ends the list as a truncated, non-eof reply rather than an error status. By then the generated union encoder has committed NFS3_OK and the resok fields ahead of the entry list, and the aggregate hooks cannot rewind the stream to re-encode the reply as resfail. The client resumes from the last cookie, so its follow-up READDIRPLUS starts at the failing batch, and nfsd_readdir_open() reports the error as the reply status there. An error opening the directory is still reported as the reply status. The bytes on the wire are otherwise unchanged.
The hand-written READDIRPLUS result encoder, its per-entry encoder, and the post-op file-handle encoders they relied on no longer have any callers, so they are removed. The declaration of nfs3svc_encode_accessres(), whose definition went away with the ACCESS conversion, is removed along with them.
--- Documentation/sunrpc/xdr/nfs3.x | 10 + fs/nfsd/nfs3proc.c | 88 +++----- fs/nfsd/nfs3xdr.c | 313 +++++++++++++++-------------- fs/nfsd/nfs3xdr_gen.c | 35 +++- fs/nfsd/nfs3xdr_gen.h | 13 +- fs/nfsd/xdr3.h | 48 +++-- include/linux/sunrpc/xdrgen/nfs3.h | 2 +- 7 files changed, 268 insertions(+), 241 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +10 -0
@@ -676,6 +676,16 @@ struct dirlistplus3 { bool eof; }; +/* + * The entry list encodes as the value-follows form of "entryplus3 + * *entries" -- each entry prefixed by TRUE, the sequence closed by + * FALSE -- and the encode hooks stream it straight from the directory + * during reply encoding rather than from a materialized array. The + * struct definitions above are the verbatim RFC 1813 types; only this + * pragma selects the hook-driven codec. + */ +pragma aggregate dirlistplus3 entries; + struct READDIRPLUS3resok { post_op_attr dir_attributes; cookieverf3 cookieverf;
fs/nfsd/nfs3proc.c +30 -58
145 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +159 -154
372 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.c +27 -8
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 // Generated by xdrgen. Manual edits will be lost. // XDR specification file: Documentation/sunrpc/xdr/nfs3.x -// XDR specification modification time: Tue Jul 14 20:36:22 2026 +// XDR specification modification time: Tue Jul 14 21:15:59 2026 #include <linux/sunrpc/svc.h>
@@ -1340,11 +1340,7 @@ xdrgen_decode_entryplus3(struct xdr_stream *xdr, struct entryplus3 *ptr)static bool __maybe_unused xdrgen_decode_dirlistplus3 (struct xdr_stream *xdr,struct dirlistplus3 *ptr) { -if (!xdrgen_decode_entryplus3 (xdr, ptr->entries)) -return false; -if (!xdrgen_decode_bool (xdr, &ptr->eof)) -return false; -return true; +return false; } static bool __maybe_unused
@@ -3192,8 +3188,31 @@ xdrgen_encode_entryplus3(struct xdr_stream *xdr, const struct entryplus3 *value)static bool __maybe_unused xdrgen_encode_dirlistplus3 (struct xdr_stream *xdr,const struct dirlistplus3 *value) { -if (!xdrgen_encode_entryplus3 (xdr, value->entries)) -return false; + { +struct xdrgen_aggregate_cursor cursor = { + .xdr = xdr, + .member_id =NFS3_DIRLISTPLUS3_ENTRIES , + .ctx = xdr->xdrgen_ctx, + }; +bool ok = true; + +if (!nfs3_dirlistplus3_encode_begin (&cursor)) +return false; +for (cursor.index =0 ; ; cursor.index++) { +struct entryplus3 element = {}; + +if (!nfs3_dirlistplus3_encode (&cursor, &element)) +break ; +if (!xdrgen_encode_entryplus3 (xdr, &element)) { + ok = false; +break ; + } + } +if (ok && !xdrgen_encode_entryplus3 (xdr,NULL )) + ok = false; +if (!nfs3_dirlistplus3_encode_end (&cursor, ok) || !ok) +return false; + }if (!xdrgen_encode_bool (xdr, value->eof))return false;return true;
fs/nfsd/nfs3xdr_gen.h +12 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ -/* XDR specification modification time: Tue Jul 14 20:36:22 2026 */ +/* XDR specification modification time: Tue Jul 14 21:15:59 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
@@ -24,6 +24,17 @@ bool nfs3_dirlist3_decode_begin(struct xdrgen_aggregate_cursor *c);bool nfs3_dirlist3_decode (struct xdrgen_aggregate_cursor *c,const struct entry3 *in);bool nfs3_dirlist3_decode_end (struct xdrgen_aggregate_cursor *c,bool ok); +enum { +NFS3_DIRLISTPLUS3_ENTRIES , +}; + +bool nfs3_dirlistplus3_encode_begin (struct xdrgen_aggregate_cursor *c); +bool nfs3_dirlistplus3_encode (struct xdrgen_aggregate_cursor *c,struct entryplus3 *out); +bool nfs3_dirlistplus3_encode_end (struct xdrgen_aggregate_cursor *c,bool ok); +bool nfs3_dirlistplus3_decode_begin (struct xdrgen_aggregate_cursor *c); +bool nfs3_dirlistplus3_decode (struct xdrgen_aggregate_cursor *c,const struct entryplus3 *in); +bool nfs3_dirlistplus3_decode_end (struct xdrgen_aggregate_cursor *c,bool ok); +bool nfs_svc_decode_GETATTR3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs_svc_decode_SETATTR3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs_svc_decode_LOOKUP3args (struct svc_rqst *rqstp,struct xdr_stream *xdr);
fs/nfsd/xdr3.h +29 -19
67 lines not on this page · raw message
include/linux/sunrpc/xdrgen/nfs3.h +1 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ -/* XDR specification modification time: Tue Jul 14 20:36:22 2026 */ +/* XDR specification modification time: Tue Jul 14 21:15:59 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v3 34/34 SUNRPC: Remove svc_fill_symlink_pathname()
In reply to Chuck LeverThe NFSv2 and NFSv3 SYMLINK procedures copy the target pathname out of a struct xdr_buf with nfsd_symlink_target(), so svc_fill_symlink_pathname() has no callers left. Remove it.
--- include/linux/sunrpc/svc.h | 3 --- net/sunrpc/svc.c | 50 -------------------------------------- 2 files changed, 53 deletions(-)
include/linux/sunrpc/svc.h +0 -3
@@ -492,9 +492,6 @@ const char * svc_proc_name(const struct svc_rqst *rqstp);int svc_encode_result_payload (struct svc_rqst *rqstp,unsigned int offset,unsigned int length); -char *svc_fill_symlink_pathname (struct svc_rqst *rqstp, -struct kvec *first,void *p, -size_t total);__be32 svc_generic_init_request (struct svc_rqst *rqstp,const struct svc_program *progp,struct svc_process_info *procinfo);
net/sunrpc/svc.c +0 -50
53 lines not on this page · raw message
Signature · 1 line
2.55.0