Convert server-side NFSv3 XDR to use xdrgen
Subsystems (3)
Chuck Lever
maintainerv2 cover Convert server-side NFSv3 XDR to use xdrgen
Replace NFSD's NFSv3 XDR encoders and decoders with code that is mechanically generated directly from the NFSv3 RPC language specification. Unlike NFSv2, where there are at least two incomplete language specifications and much lore, nfs3.x here is based closely on RFC 1813.
As we convert newer NFS versions to use xdrgen, I expect a reduction in human coding errors, improved spec compliance, and better memory safety for those more complex NFS programs.
Changes in v2:
- Include the generated NFSv3 header directly in nfsfh.c and nfsctl.c.
- Remove the unused struct nfsd3_createargs in the MKDIR patch.
- Regenerate the READDIR and READDIRPLUS result decoders.
- Drop the decode-hook stubs the regenerated decoders no longer call.
- Link to v1: https://lore.kernel.org/linux-nfs/[email protected]/
Chuck Lever (33):
NFSD: Report a first-batch readdir error in the reply status
Documentation: Add the RPC language description of NFSv3
NFSD: Add infrastructure for generating NFSv3 XDR encoders and
decoders
NFSD: Replace nfs3.h with nfs3xdr_gen.h
NFSD: Replace the nfsd3_createres macro
NFSD: Relocate the NFSv3 XDR storage union into nfs3proc.c
NFSD: Use xdrgen XDR functions for the NFSv3 NULL procedure
NFSD: Use xdrgen XDR functions for NFSv3 GETATTR procedure
NFSD: Use xdrgen XDR functions for NFSv3 SETATTR procedure
NFSD: Use xdrgen XDR functions for the NFSv3 LOOKUP procedure
NFSD: Use xdrgen XDR functions for NFSv3 ACCESS procedure
NFSD: Use xdrgen XDR functions for NFSv3 READLINK procedure
NFSD: Use xdrgen XDR functions for NFSv3 READ procedure
NFSD: Use xdrgen XDR functions for NFSv3 WRITE procedure
NFSD: Use xdrgen XDR functions for NFSv3 CREATE procedure
NFSD: Use xdrgen XDR functions for NFSv3 MKDIR procedure
NFSD: Use xdrgen XDR functions for NFSv3 SYMLINK procedure
NFSD: Use xdrgen XDR functions for NFSv3 MKNOD procedure
NFSD: Use xdrgen XDR functions for the NFSv3 REMOVE procedure
NFSD: Use xdrgen XDR functions for the NFSv3 RMDIR procedure
NFSD: Use xdrgen XDR functions for the NFSv3 RENAME procedure
NFSD: Use xdrgen XDR functions for the NFSv3 LINK procedure
NFSD: Use xdrgen XDR functions for the NFSv3 FSSTAT procedure
NFSD: Use xdrgen XDR functions for the NFSv3 FSINFO procedure
NFSD: Use xdrgen XDR functions for the NFSv3 PATHCONF procedure
NFSD: Use xdrgen XDR functions for the NFSv3 COMMIT procedure
NFSD: Use xdrgen XDR functions for NFSv3 READDIR arguments
NFSD: Use xdrgen XDR functions for NFSv3 READDIRPLUS arguments
NFSD: Refactor NFSv3 directory cookie encoding
NFSD: Refactor NFSv3 directory entry encoding
NFSD: Split struct nfsd3_readdirres
NFSD: Use xdrgen XDR functions for NFSv3 READDIR results
NFSD: Use xdrgen XDR functions for NFSv3 READDIRPLUS results
Documentation/sunrpc/xdr/nfs3.x | 839 ++++++ fs/nfsd/Makefile | 15 +- fs/nfsd/nfs2acl.c | 41 +- fs/nfsd/nfs3acl.c | 12 +- fs/nfsd/nfs3proc.c | 2545 +++++++++++++------ fs/nfsd/nfs3xdr.c | 1369 +++------- fs/nfsd/nfs3xdr_gen.c | 3808 ++++++++++++++++++++++++++++ fs/nfsd/nfs3xdr_gen.h | 82 + fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfserr.h | 2 +- fs/nfsd/nfsfh.c | 2 +- fs/nfsd/vfs.c | 76 +- fs/nfsd/xdr3.h | 300 +-- include/linux/nfs3.h | 3 - include/linux/sunrpc/xdrgen/nfs3.h | 1092 ++++++++ 15 files changed, 8021 insertions(+), 2167 deletions(-) create mode 100644 Documentation/sunrpc/xdr/nfs3.x create mode 100644 fs/nfsd/nfs3xdr_gen.c create mode 100644 fs/nfsd/nfs3xdr_gen.h create mode 100644 include/linux/sunrpc/xdrgen/nfs3.h
base-commit: 21c66e2ece97c0ac8139b44051d565b29574f821
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 1/33 NFSD: Report a first-batch readdir error in the reply status
The NFSv2 READDIR encoder pulls directory entries while the reply is encoded, after the status word is on the wire. 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.
--- fs/nfsd/vfs.c | 76 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 26 deletions(-)
fs/nfsd/vfs.c +50 -26
@@ -2376,6 +2376,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
@@ -2383,13 +2410,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)
@@ -2425,6 +2454,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:
@@ -2449,26 +2489,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;
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 2/33 Documentation: Add the RPC language description of NFSv3
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
In order to generate source code to encode and decode NFSv3 protocol elements, include a copy of the RPC language description of NFSv3 for xdrgen to process. The language description is copied from RFC 1813.
The goals of replacing hand-written XDR functions with ones that are tool-generated are to improve memory safety and make XDR encoding and decoding less brittle to maintain. Parts of the NFSv4 protocol are still being extended actively. Tool-generated XDR code reduces the time it takes to get a working implementation of new protocol elements.
The xdrgen utility derives both the type definitions and the encode/decode functions directly from protocol specifications, using names and symbols familiar to anyone who knows those specs. Unlike hand-written code that can inadvertently diverge from the specification, xdrgen guarantees that the generated code matches the specification exactly.
We would eventually like xdrgen to generate Rust code as well, making the conversion of the kernel's NFS stacks to use Rust just a little easier for us.
--- Documentation/sunrpc/xdr/nfs3.x | 812 ++++++++++++++++++++++++++++++++ 1 file changed, 812 insertions(+) create mode 100644 Documentation/sunrpc/xdr/nfs3.x
Documentation/sunrpc/xdr/nfs3.x new file +812 -0
@@ -0,0 +1,812 @@ +/* + * Copyright (c) 1995 IETF Trust and the persons identified + * as the document authors. All rights reserved. + * + * The document authors are identified in RFC 1813. + * + * Redistribution and use in source and binary forms, with + * or without modification, are permitted provided that the + * following conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * - Neither the name of Internet Society, IETF or IETF + * Trust, nor the names of specific contributors, may be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS + * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +const NFS3_FHSIZE = 64; +const NFS3_COOKIEVERFSIZE = 8; +const NFS3_CREATEVERFSIZE = 8; +const NFS3_WRITEVERFSIZE = 8; + +typedef unsigned hyper uint64; +typedef hyper int64; +typedef unsigned long uint32; +typedef long int32; +typedef string filename3<>; +typedef string nfspath3<>; +typedef uint64 fileid3; +typedef uint64 cookie3; +typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE]; +typedef opaque createverf3[NFS3_CREATEVERFSIZE]; +typedef opaque writeverf3[NFS3_WRITEVERFSIZE]; +typedef uint32 uid3; +typedef uint32 gid3; +typedef uint64 size3; +typedef uint64 offset3; +typedef uint32 mode3; +typedef uint32 count3; + +enum nfsstat3 { + NFS3_OK = 0, + NFS3ERR_PERM = 1, + NFS3ERR_NOENT = 2, + NFS3ERR_IO = 5, + NFS3ERR_NXIO = 6, + NFS3ERR_ACCES = 13, + NFS3ERR_EXIST = 17, + NFS3ERR_XDEV = 18, + NFS3ERR_NODEV = 19, + NFS3ERR_NOTDIR = 20, + NFS3ERR_ISDIR = 21, + NFS3ERR_INVAL = 22, + NFS3ERR_FBIG = 27, + NFS3ERR_NOSPC = 28, + NFS3ERR_ROFS = 30, + NFS3ERR_MLINK = 31, + NFS3ERR_NAMETOOLONG = 63, + NFS3ERR_NOTEMPTY = 66, + NFS3ERR_DQUOT = 69, + NFS3ERR_STALE = 70, + NFS3ERR_REMOTE = 71, + NFS3ERR_BADHANDLE = 10001, + NFS3ERR_NOT_SYNC = 10002, + NFS3ERR_BAD_COOKIE = 10003, + NFS3ERR_NOTSUPP = 10004, + NFS3ERR_TOOSMALL = 10005, + NFS3ERR_SERVERFAULT = 10006, + NFS3ERR_BADTYPE = 10007, + NFS3ERR_JUKEBOX = 10008 +}; + +enum ftype3 { + NF3REG = 1, + NF3DIR = 2, + NF3BLK = 3, + NF3CHR = 4, + NF3LNK = 5, + NF3SOCK = 6, + NF3FIFO = 7 +}; + +struct specdata3 { + uint32 specdata1; + uint32 specdata2; +}; + +struct nfs_fh3 { + opaque data<NFS3_FHSIZE>; +}; + +struct nfstime3 { + uint32 seconds; + uint32 nseconds; +}; + +struct fattr3 { + ftype3 type; + mode3 mode; + uint32 nlink; + uid3 uid; + gid3 gid; + size3 size; + size3 used; + specdata3 rdev; + uint64 fsid; + fileid3 fileid; + nfstime3 atime; + nfstime3 mtime; + nfstime3 ctime; +}; + +union post_op_attr switch (bool attributes_follow) { + case TRUE: + fattr3 attributes; + case FALSE: + void; +}; + +struct wcc_attr { + size3 size; + nfstime3 mtime; + nfstime3 ctime; +}; + +union pre_op_attr switch (bool attributes_follow) { + case TRUE: + wcc_attr attributes; + case FALSE: + void; +}; + +struct wcc_data { + pre_op_attr before; + post_op_attr after; +}; + +union post_op_fh3 switch (bool handle_follows) { + case TRUE: + nfs_fh3 handle; + case FALSE: + void; +}; + +enum time_how { + DONT_CHANGE = 0, + SET_TO_SERVER_TIME = 1, + SET_TO_CLIENT_TIME = 2 +}; + +union set_mode3 switch (bool set_it) { + case TRUE: + mode3 mode; + default: + void; +}; + +union set_uid3 switch (bool set_it) { + case TRUE: + uid3 uid; + default: + void; +}; + +union set_gid3 switch (bool set_it) { + case TRUE: + gid3 gid; + default: + void; +}; + +union set_size3 switch (bool set_it) { + case TRUE: + size3 size; + default: + void; +}; + +union set_atime switch (time_how set_it) { + case SET_TO_CLIENT_TIME: + nfstime3 atime; + default: + void; +}; + +union set_mtime switch (time_how set_it) { + case SET_TO_CLIENT_TIME: + nfstime3 mtime; + default: + void; +}; + +struct sattr3 { + set_mode3 mode; + set_uid3 uid; + set_gid3 gid; + set_size3 size; + set_atime atime; + set_mtime mtime; +}; + +struct diropargs3 { + nfs_fh3 dir; + filename3 name; +}; + +struct GETATTR3args { + nfs_fh3 object; +}; + +struct GETATTR3resok { + fattr3 obj_attributes; +}; + +union GETATTR3res switch (nfsstat3 status) { + case NFS3_OK: + GETATTR3resok resok; + default: + void; +}; + +union sattrguard3 switch (bool check) { + case TRUE: + nfstime3 obj_ctime; + case FALSE: + void; +}; + +struct SETATTR3args { + nfs_fh3 object; + sattr3 new_attributes; + sattrguard3 guard; +}; + +struct SETATTR3resok { + wcc_data obj_wcc; +}; + +struct SETATTR3resfail { + wcc_data obj_wcc; +}; + +union SETATTR3res switch (nfsstat3 status) { + case NFS3_OK: + SETATTR3resok resok; + default: + SETATTR3resfail resfail; +}; + +struct LOOKUP3args { + diropargs3 what; +}; + +struct LOOKUP3resok { + nfs_fh3 object; + post_op_attr obj_attributes; + post_op_attr dir_attributes; +}; + +struct LOOKUP3resfail { + post_op_attr dir_attributes; +}; + +union LOOKUP3res switch (nfsstat3 status) { + case NFS3_OK: + LOOKUP3resok resok; + default: + LOOKUP3resfail resfail; +}; + +const ACCESS3_READ = 0x0001; +const ACCESS3_LOOKUP = 0x0002; +const ACCESS3_MODIFY = 0x0004; +const ACCESS3_EXTEND = 0x0008; +const ACCESS3_DELETE = 0x0010; +const ACCESS3_EXECUTE = 0x0020; + +struct ACCESS3args { + nfs_fh3 object; + uint32 access; +}; + +struct ACCESS3resok { + post_op_attr obj_attributes; + uint32 access; +}; + +struct ACCESS3resfail { + post_op_attr obj_attributes; +}; + +union ACCESS3res switch (nfsstat3 status) { + case NFS3_OK: + ACCESS3resok resok; + default: + ACCESS3resfail resfail; +}; + +struct READLINK3args { + nfs_fh3 symlink; +}; + +struct READLINK3resok { + post_op_attr symlink_attributes; + nfspath3 data; +}; + +struct READLINK3resfail { + post_op_attr symlink_attributes; +}; + +union READLINK3res switch (nfsstat3 status) { + case NFS3_OK: + READLINK3resok resok; + default: + READLINK3resfail resfail; +}; + +struct READ3args { + nfs_fh3 file; + offset3 offset; + count3 count; +}; + +struct READ3resok { + post_op_attr file_attributes; + count3 count; + bool eof; + opaque data<>; +}; + +struct READ3resfail { + post_op_attr file_attributes; +}; + +union READ3res switch (nfsstat3 status) { + case NFS3_OK: + READ3resok resok; + default: + READ3resfail resfail; +}; + +enum stable_how { + UNSTABLE = 0, + DATA_SYNC = 1, + FILE_SYNC = 2 +}; + +struct WRITE3args { + nfs_fh3 file; + offset3 offset; + count3 count; + stable_how stable; + opaque data<>; +}; + +struct WRITE3resok { + wcc_data file_wcc; + count3 count; + stable_how committed; + writeverf3 verf; +}; + +struct WRITE3resfail { + wcc_data file_wcc; +}; + +union WRITE3res switch (nfsstat3 status) { + case NFS3_OK: + WRITE3resok resok; + default: + WRITE3resfail resfail; +}; + +enum createmode3 { + UNCHECKED = 0, + GUARDED = 1, + EXCLUSIVE = 2 +}; + +union createhow3 switch (createmode3 mode) { + case UNCHECKED: + case GUARDED: + sattr3 obj_attributes; + case EXCLUSIVE: + createverf3 verf; +}; + +struct CREATE3args { + diropargs3 where; + createhow3 how; +}; + +struct CREATE3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct CREATE3resfail { + wcc_data dir_wcc; +}; + +union CREATE3res switch (nfsstat3 status) { + case NFS3_OK: + CREATE3resok resok; + default: + CREATE3resfail resfail; +}; + +struct MKDIR3args { + diropargs3 where; + sattr3 attributes; +}; + +struct MKDIR3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct MKDIR3resfail { + wcc_data dir_wcc; +}; + +union MKDIR3res switch (nfsstat3 status) { + case NFS3_OK: + MKDIR3resok resok; + default: + MKDIR3resfail resfail; +}; + +struct symlinkdata3 { + sattr3 symlink_attributes; + nfspath3 symlink_data; +}; + +struct SYMLINK3args { + diropargs3 where; + symlinkdata3 symlink; +}; + +struct SYMLINK3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct SYMLINK3resfail { + wcc_data dir_wcc; +}; + +union SYMLINK3res switch (nfsstat3 status) { + case NFS3_OK: + SYMLINK3resok resok; + default: + SYMLINK3resfail resfail; +}; + +struct devicedata3 { + sattr3 dev_attributes; + specdata3 spec; +}; + +union mknoddata3 switch (ftype3 type) { + case NF3CHR: + case NF3BLK: + devicedata3 device; + case NF3SOCK: + case NF3FIFO: + sattr3 pipe_attributes; + default: + void; +}; + +struct MKNOD3args { + diropargs3 where; + mknoddata3 what; +}; + +struct MKNOD3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct MKNOD3resfail { + wcc_data dir_wcc; +}; + +union MKNOD3res switch (nfsstat3 status) { + case NFS3_OK: + MKNOD3resok resok; + default: + MKNOD3resfail resfail; +}; + +struct REMOVE3args { + diropargs3 object; +}; + +struct REMOVE3resok { + wcc_data dir_wcc; +}; + +struct REMOVE3resfail { + wcc_data dir_wcc; +}; + +union REMOVE3res switch (nfsstat3 status) { + case NFS3_OK: + REMOVE3resok resok; + default: + REMOVE3resfail resfail; +}; + +struct RMDIR3args { + diropargs3 object; +}; + +struct RMDIR3resok { + wcc_data dir_wcc; +}; + +struct RMDIR3resfail { + wcc_data dir_wcc; +}; + +union RMDIR3res switch (nfsstat3 status) { + case NFS3_OK: + RMDIR3resok resok; + default: + RMDIR3resfail resfail; +}; + +struct RENAME3args { + diropargs3 from; + diropargs3 to; +}; + +struct RENAME3resok { + wcc_data fromdir_wcc; + wcc_data todir_wcc; +}; + +struct RENAME3resfail { + wcc_data fromdir_wcc; + wcc_data todir_wcc; +}; + +union RENAME3res switch (nfsstat3 status) { + case NFS3_OK: + RENAME3resok resok; + default: + RENAME3resfail resfail; +}; + +struct LINK3args { + nfs_fh3 file; + diropargs3 link; +}; + +struct LINK3resok { + post_op_attr file_attributes; + wcc_data linkdir_wcc; +}; + +struct LINK3resfail { + post_op_attr file_attributes; + wcc_data linkdir_wcc; +}; + +union LINK3res switch (nfsstat3 status) { + case NFS3_OK: + LINK3resok resok; + default: + LINK3resfail resfail; +}; + +struct READDIR3args { + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 count; +}; + +struct entry3 { + fileid3 fileid; + filename3 name; + cookie3 cookie; + entry3 *nextentry; +}; + +struct dirlist3 { + entry3 *entries; + bool eof; +}; + +struct READDIR3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlist3 reply; +}; + +struct READDIR3resfail { + post_op_attr dir_attributes; +}; + +union READDIR3res switch (nfsstat3 status) { + case NFS3_OK: + READDIR3resok resok; + default: + READDIR3resfail resfail; +}; + +struct READDIRPLUS3args { + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 dircount; + count3 maxcount; +}; + +struct entryplus3 { + fileid3 fileid; + filename3 name; + cookie3 cookie; + post_op_attr name_attributes; + post_op_fh3 name_handle; + entryplus3 *nextentry; +}; + +struct dirlistplus3 { + entryplus3 *entries; + bool eof; +}; + +struct READDIRPLUS3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlistplus3 reply; +}; + +struct READDIRPLUS3resfail { + post_op_attr dir_attributes; +}; + +union READDIRPLUS3res switch (nfsstat3 status) { + case NFS3_OK: + READDIRPLUS3resok resok; + default: + READDIRPLUS3resfail resfail; +}; + + +struct FSSTAT3args { + nfs_fh3 fsroot; +}; + +struct FSSTAT3resok { + post_op_attr obj_attributes; + size3 tbytes; + size3 fbytes; + size3 abytes; + size3 tfiles; + size3 ffiles; + size3 afiles; + uint32 invarsec; +}; + +struct FSSTAT3resfail { + post_op_attr obj_attributes; +}; + +union FSSTAT3res switch (nfsstat3 status) { + case NFS3_OK: + FSSTAT3resok resok; + default: + FSSTAT3resfail resfail; +}; + +const FSF3_LINK = 0x0001; +const FSF3_SYMLINK = 0x0002; +const FSF3_HOMOGENEOUS = 0x0008; +const FSF3_CANSETTIME = 0x0010; + +struct FSINFO3args { + nfs_fh3 fsroot; +}; + +struct FSINFO3resok { + post_op_attr obj_attributes; + uint32 rtmax; + uint32 rtpref; + uint32 rtmult; + uint32 wtmax; + uint32 wtpref; + uint32 wtmult; + uint32 dtpref; + size3 maxfilesize; + nfstime3 time_delta; + uint32 properties; +}; + +struct FSINFO3resfail { + post_op_attr obj_attributes; +}; + +union FSINFO3res switch (nfsstat3 status) { + case NFS3_OK: + FSINFO3resok resok; + default: + FSINFO3resfail resfail; +}; + +struct PATHCONF3args { + nfs_fh3 object; +}; + +struct PATHCONF3resok { + post_op_attr obj_attributes; + uint32 linkmax; + uint32 name_max; + bool no_trunc; + bool chown_restricted; + bool case_insensitive; + bool case_preserving; +}; + +struct PATHCONF3resfail { + post_op_attr obj_attributes; +}; + +union PATHCONF3res switch (nfsstat3 status) { + case NFS3_OK: + PATHCONF3resok resok; + default: + PATHCONF3resfail resfail; +}; + +struct COMMIT3args { + nfs_fh3 file; + offset3 offset; + count3 count; +}; + +struct COMMIT3resok { + wcc_data file_wcc; + writeverf3 verf; +}; + +struct COMMIT3resfail { + wcc_data file_wcc; +}; + +union COMMIT3res switch (nfsstat3 status) { + case NFS3_OK: + COMMIT3resok resok; + default: + COMMIT3resfail resfail; +}; + +program NFS_PROGRAM { + version NFS_V3 { + void NFSPROC3_NULL(void) = 0; + GETATTR3res NFSPROC3_GETATTR(GETATTR3args) = 1; + SETATTR3res NFSPROC3_SETATTR(SETATTR3args) = 2; + LOOKUP3res NFSPROC3_LOOKUP(LOOKUP3args) = 3; + ACCESS3res NFSPROC3_ACCESS(ACCESS3args) = 4; + READLINK3res NFSPROC3_READLINK(READLINK3args) = 5; + READ3res NFSPROC3_READ(READ3args) = 6; + WRITE3res NFSPROC3_WRITE(WRITE3args) = 7; + CREATE3res NFSPROC3_CREATE(CREATE3args) = 8; + MKDIR3res NFSPROC3_MKDIR(MKDIR3args) = 9; + SYMLINK3res NFSPROC3_SYMLINK(SYMLINK3args) = 10; + MKNOD3res NFSPROC3_MKNOD(MKNOD3args) = 11; + REMOVE3res NFSPROC3_REMOVE(REMOVE3args) = 12; + RMDIR3res NFSPROC3_RMDIR(RMDIR3args) = 13; + RENAME3res NFSPROC3_RENAME(RENAME3args) = 14; + LINK3res NFSPROC3_LINK(LINK3args) = 15; + READDIR3res NFSPROC3_READDIR(READDIR3args) = 16; + READDIRPLUS3res NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17; + FSSTAT3res NFSPROC3_FSSTAT(FSSTAT3args) = 18; + FSINFO3res NFSPROC3_FSINFO(FSINFO3args) = 19; + PATHCONF3res NFSPROC3_PATHCONF(PATHCONF3args) = 20; + COMMIT3res NFSPROC3_COMMIT(COMMIT3args) = 21; + } = 3; +} = 100003;
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 3/33 NFSD: Add infrastructure for generating NFSv3 XDR encoders and decoders
In reply to Chuck LeverNFSD's NFSv3 XDR codecs are hand-maintained; they are being converted to xdrgen-generated code one RPC procedure at a time. The first step is to generate and commit the xdrgen C code based on nfs3.x. The generated code can be refreshed any time nfs3.x is modified by running "(cd fs/nfsd && make xdrgen)".
--- Documentation/sunrpc/xdr/nfs3.x | 2 + fs/nfsd/Makefile | 15 +- fs/nfsd/nfs3xdr_gen.c | 3768 ++++++++++++++++++++++++++++ fs/nfsd/nfs3xdr_gen.h | 60 + include/linux/sunrpc/xdrgen/nfs3.h | 1092 ++++++++ 5 files changed, 4933 insertions(+), 4 deletions(-) create mode 100644 fs/nfsd/nfs3xdr_gen.c create mode 100644 fs/nfsd/nfs3xdr_gen.h create mode 100644 include/linux/sunrpc/xdrgen/nfs3.h
Documentation/sunrpc/xdr/nfs3.x +2 -0
@@ -39,6 +39,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +pragma header nfs3; + const NFS3_FHSIZE = 64; const NFS3_COOKIEVERFSIZE = 8; const NFS3_CREATEVERFSIZE = 8;
fs/nfsd/Makefile +11 -4
@@ -12,8 +12,8 @@ nfsd-y += trace.o nfsd-y += nfssvc.o nfsctl.o nfsfh.o vfs.o \ export.o auth.o lockd.o nfscache.o \ - stats.o filecache.o nfs3proc.o nfs3xdr.o \ - netlink.o + stats.o filecache.o netlink.o \ + nfs3proc.o nfs3xdr.o nfs3xdr_gen.o nfsd-$(CONFIG_NFSD_V2) += nfsproc.o nfsxdr.o nfs2xdr_gen.o nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o
@@ -38,23 +38,30 @@ nfsd-$(CONFIG_DEBUG_FS) += debugfs.o .PHONY: xdrgen XDRGEN_DEFINITIONS = ../../include/linux/sunrpc/xdrgen/nfs2.h \ + ../../include/linux/sunrpc/xdrgen/nfs3.h \ ../../include/linux/sunrpc/xdrgen/nfs4_1.h -XDRGEN_DECLARATIONS = nfs2xdr_gen.h nfs4xdr_gen.h -XDRGEN_SOURCE = nfs2xdr_gen.c nfs4xdr_gen.c +XDRGEN_DECLARATIONS = nfs2xdr_gen.h nfs3xdr_gen.h nfs4xdr_gen.h +XDRGEN_SOURCE = nfs2xdr_gen.c nfs3xdr_gen.c nfs4xdr_gen.c xdrgen: $(XDRGEN_DEFINITIONS) $(XDRGEN_DECLARATIONS) $(XDRGEN_SOURCE) ../../include/linux/sunrpc/xdrgen/nfs2.h: ../../Documentation/sunrpc/xdr/nfs2.x ../../tools/net/sunrpc/xdrgen/xdrgen definitions $< > $@ +../../include/linux/sunrpc/xdrgen/nfs3.h: ../../Documentation/sunrpc/xdr/nfs3.x + ../../tools/net/sunrpc/xdrgen/xdrgen definitions $< > $@ ../../include/linux/sunrpc/xdrgen/nfs4_1.h: ../../Documentation/sunrpc/xdr/nfs4_1.x ../../tools/net/sunrpc/xdrgen/xdrgen definitions $< > $@ nfs2xdr_gen.h: ../../Documentation/sunrpc/xdr/nfs2.x ../../tools/net/sunrpc/xdrgen/xdrgen declarations $< > $@ +nfs3xdr_gen.h: ../../Documentation/sunrpc/xdr/nfs3.x + ../../tools/net/sunrpc/xdrgen/xdrgen declarations $< > $@ nfs4xdr_gen.h: ../../Documentation/sunrpc/xdr/nfs4_1.x ../../tools/net/sunrpc/xdrgen/xdrgen declarations $< > $@ nfs2xdr_gen.c: ../../Documentation/sunrpc/xdr/nfs2.x ../../tools/net/sunrpc/xdrgen/xdrgen source $< > $@ +nfs3xdr_gen.c: ../../Documentation/sunrpc/xdr/nfs3.x + ../../tools/net/sunrpc/xdrgen/xdrgen source $< > $@ nfs4xdr_gen.c: ../../Documentation/sunrpc/xdr/nfs4_1.x ../../tools/net/sunrpc/xdrgen/xdrgen source $< > $@
fs/nfsd/nfs3xdr_gen.c new file +3768 -0
2,950 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.h new file +60 -0
60 lines not on this page · raw message
include/linux/sunrpc/xdrgen/nfs3.h new file +1092 -0
1,092 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
Chuck Lever
maintainerPATCH v2 4/33 NFSD: Replace nfs3.h with nfs3xdr_gen.h
In reply to Chuck Levernfs3xdr_gen.h includes a set of header files that are tool-generated from the nfs3.x specification. The goal is to replace NFSD's XDR infrastructure with tool-generated files which are to have better memory safety and are less brittle to maintain.
The generated header names the NFSv3 wire constants as the specification spells them, so point NFSD's references at the new
names: NFS3_ACCESS_* becomes ACCESS3_*, NFS3PROC_* becomes NFSPROC3_*, and the createmode and write-stability constants shed their prefixes entirely. Move to xdr3.h the constants the generator does not emit: the NF3NON and NF3BAD ftype3 sentinels and the name and path length limits, none of which appear on the wire.
--- fs/nfsd/nfs2acl.c | 26 ++++++------ fs/nfsd/nfs3proc.c | 96 +++++++++++++++++++++++--------------------- fs/nfsd/nfs3xdr.c | 9 ++--- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfserr.h | 2 +- fs/nfsd/nfsfh.c | 2 +- fs/nfsd/xdr3.h | 6 +++ include/linux/nfs3.h | 3 -- 8 files changed, 76 insertions(+), 70 deletions(-)
fs/nfsd/nfs2acl.c +13 -13
@@ -22,19 +22,19 @@* the behavior of the two versions to diverge if needed. */ static const struct nfsd_access_map nfsd2_regaccess[] = { - {NFS3_ACCESS_READ ,NFSD_MAY_READ }, - {NFS3_ACCESS_EXECUTE ,NFSD_MAY_EXEC }, - {NFS3_ACCESS_MODIFY ,NFSD_MAY_WRITE |NFSD_MAY_TRUNC }, - {NFS3_ACCESS_EXTEND ,NFSD_MAY_WRITE }, + {ACCESS3_READ ,NFSD_MAY_READ }, + {ACCESS3_EXECUTE ,NFSD_MAY_EXEC }, + {ACCESS3_MODIFY ,NFSD_MAY_WRITE |NFSD_MAY_TRUNC }, + {ACCESS3_EXTEND ,NFSD_MAY_WRITE }, {0 ,0 } };static const struct nfsd_access_map nfsd2_diraccess[] = { - {NFS3_ACCESS_READ ,NFSD_MAY_READ }, - {NFS3_ACCESS_LOOKUP ,NFSD_MAY_EXEC }, - {NFS3_ACCESS_MODIFY ,NFSD_MAY_EXEC |NFSD_MAY_WRITE |NFSD_MAY_TRUNC }, - {NFS3_ACCESS_EXTEND ,NFSD_MAY_EXEC |NFSD_MAY_WRITE }, - {NFS3_ACCESS_DELETE ,NFSD_MAY_REMOVE }, + {ACCESS3_READ ,NFSD_MAY_READ }, + {ACCESS3_LOOKUP ,NFSD_MAY_EXEC }, + {ACCESS3_MODIFY ,NFSD_MAY_EXEC |NFSD_MAY_WRITE |NFSD_MAY_TRUNC }, + {ACCESS3_EXTEND ,NFSD_MAY_EXEC |NFSD_MAY_WRITE }, + {ACCESS3_DELETE ,NFSD_MAY_REMOVE }, {0 ,0 } };
@@ -46,10 +46,10 @@ static const struct nfsd_access_map nfsd2_diraccess[] = {* filesystem checks. */ static const struct nfsd_access_map nfsd2_otheraccess[] = { - {NFS3_ACCESS_READ ,NFSD_MAY_READ }, - {NFS3_ACCESS_EXECUTE ,NFSD_MAY_EXEC }, - {NFS3_ACCESS_MODIFY ,NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS }, - {NFS3_ACCESS_EXTEND ,NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS }, + {ACCESS3_READ ,NFSD_MAY_READ }, + {ACCESS3_EXECUTE ,NFSD_MAY_EXEC }, + {ACCESS3_MODIFY ,NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS }, + {ACCESS3_EXTEND ,NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS }, {0 ,0 } };
fs/nfsd/nfs3proc.c +50 -46
304 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +4 -5
@@ -8,7 +8,6 @@*/ #include <linux/namei.h> -#include <linux/nfs3.h> #include <linux/sunrpc/svc_xprt.h> #include "nfsd.h"
@@ -560,7 +559,7 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return false;if (xdr_stream_decode_u32 (xdr, &args->stable) <0 )return false; -if (args->stable >NFS_FILE_SYNC ) +if (args->stable >FILE_SYNC )return false;/* opaque data */
@@ -588,10 +587,10 @@ nfs3svc_decode_createargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)if (xdr_stream_decode_u32 (xdr, &args->createmode) <0 )return false;switch (args->createmode) { -case NFS3_CREATE_UNCHECKED : -case NFS3_CREATE_GUARDED : +case UNCHECKED : +case GUARDED :return svcxdr_decode_sattr3 (rqstp, xdr, &args->attrs); -case NFS3_CREATE_EXCLUSIVE : +case EXCLUSIVE : args->verf =xdr_inline_decode (xdr,NFS3_CREATEVERFSIZE );if (!args->verf)return false;
fs/nfsd/nfsctl.c +1 -1
@@ -20,7 +20,7 @@#include <linux/module.h> #include <linux/fsnotify.h> #include <linux/nfslocalio.h> -#include <linux/nfs3.h> +#include <linux/sunrpc/xdrgen/nfs3.h> #include "idmap.h" #include "nfsd.h"
fs/nfsd/nfserr.h +1 -1
@@ -11,7 +11,7 @@#define LINUX_NFSD_NFSERR_H #include <linux/sunrpc/xdrgen/nfs2.h> -#include <linux/nfs3.h> +#include <linux/sunrpc/xdrgen/nfs3.h> #include <linux/nfs4.h> /*
fs/nfsd/nfsfh.c +1 -1
@@ -9,7 +9,7 @@*/ #include <linux/exportfs.h> -#include <linux/nfs3.h> +#include <linux/sunrpc/xdrgen/nfs3.h> #include <linux/sunrpc/svcauth_gss.h> #include <crypto/utils.h>
fs/nfsd/xdr3.h +6 -0
@@ -12,6 +12,12 @@#include "vfs.h" +#define NF3NON (0) +#define NF3BAD (8) + +#define NFS3_MAXNAMLEN NAME_MAX +#define NFS3_MAXPATHLEN PATH_MAX +struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;
include/linux/nfs3.h +0 -3
@@ -51,7 +51,4 @@ enum nfs3_stable_how {NFS_INVALID_STABLE_HOW =-1 }; -/* Number of 32bit words in post_op_attr */ -#define NFS3_POST_OP_ATTR_WORDS 22 -#endif /* _LINUX_NFS3_H */
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 5/33 NFSD: Replace the nfsd3_createres macro
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I'm about to use the name "nfsd3_createres" for a C struct, so let's get rid of the macro to reduce confusion.
--- fs/nfsd/nfs3proc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/nfsd/nfs3proc.c +4 -5
@@ -916,7 +916,6 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)#define nfsd3_fhandleargs nfsd_fhandle#define nfsd3_attrstatres nfsd3_attrstat#define nfsd3_wccstatres nfsd3_attrstat -#define nfsd3_createres nfsd3_diropres#define ST 1/* status*/ #define FH 17/* filehandle with length */
@@ -1027,7 +1026,7 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_release = nfs3svc_release_fhandle2, .pc_argsize = sizeof(struct nfsd3_createargs), .pc_argzero = sizeof(struct nfsd3_createargs), - .pc_ressize = sizeof(struct nfsd3_createres), + .pc_ressize = sizeof(struct nfsd3_diropres), .pc_cachetype = RC_REPLBUFF, .pc_xdrressize = ST+(1+FH+pAT)+WC, .pc_name = "CREATE",
@@ -1039,7 +1038,7 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_release = nfs3svc_release_fhandle2, .pc_argsize = sizeof(struct nfsd3_mkdirargs), .pc_argzero = sizeof(struct nfsd3_mkdirargs), - .pc_ressize = sizeof(struct nfsd3_createres), + .pc_ressize = sizeof(struct nfsd3_diropres), .pc_cachetype = RC_REPLBUFF, .pc_xdrressize = ST+(1+FH+pAT)+WC, .pc_name = "MKDIR",
@@ -1051,7 +1050,7 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_release = nfs3svc_release_fhandle2, .pc_argsize = sizeof(struct nfsd3_symlinkargs), .pc_argzero = sizeof(struct nfsd3_symlinkargs), - .pc_ressize = sizeof(struct nfsd3_createres), + .pc_ressize = sizeof(struct nfsd3_diropres), .pc_cachetype = RC_REPLBUFF, .pc_xdrressize = ST+(1+FH+pAT)+WC, .pc_name = "SYMLINK",
@@ -1063,7 +1062,7 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_release = nfs3svc_release_fhandle2, .pc_argsize = sizeof(struct nfsd3_mknodargs), .pc_argzero = sizeof(struct nfsd3_mknodargs), - .pc_ressize = sizeof(struct nfsd3_createres), + .pc_ressize = sizeof(struct nfsd3_diropres), .pc_cachetype = RC_REPLBUFF, .pc_xdrressize = ST+(1+FH+pAT)+WC, .pc_name = "MKNOD",
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 6/33 NFSD: Relocate the NFSv3 XDR storage union into nfs3proc.c
In reply to Chuck Leverunion nfsd3_xdrstore and the NFS3_SVC_XDRSIZE macro it feeds exist only to size service result buffers, yet xdr3.h exposes them to every file that includes the header. This couples the NFSv3 XDR type layout to translation units that have no stake in a service's buffer size.
Three svc_version structures drew their vs_xdrsize from the shared
union: nfsd_version3 in nfs3proc.c and the two NFSACL programs, nfsd_acl_version2 and nfsd_acl_version3. Give each its own storage union next to the version structure it sizes, listing only that program's own argument and result types, and compute vs_xdrsize from sizeof of the local union. NFS3_SVC_XDRSIZE then has no users left and is removed from xdr3.h.
The svc layer allocates rqstp->rq_resp at sv_xdrsize -- the largest vs_xdrsize among a program's versions -- and clears it to the dispatched procedure's pc_ressize, so each union must bound the largest result its version encodes. The NFSACL programs previously borrowed the full NFSv3 union; sizing them from their own result types is both tighter and self-contained. This mirrors the recent lockd conversion, which confined each NLM version's storage union to the file that defines the version structure.
--- fs/nfsd/nfs2acl.c | 15 ++++++++++++++- fs/nfsd/nfs3acl.c | 12 +++++++++++- fs/nfsd/nfs3proc.c | 30 +++++++++++++++++++++++++++++- fs/nfsd/xdr3.h | 30 ------------------------------ 4 files changed, 54 insertions(+), 33 deletions(-)
fs/nfsd/nfs2acl.c +14 -1
@@ -452,10 +452,23 @@ static const struct svc_procedure nfsd_acl_procedures2[5] = { }, }; +/* +* Storage requirements for XDR arguments and results. +*/ +union nfsd_acl2_xdrstore { +struct nfsd3_getaclargs getaclargs; +struct nfsd3_setaclargs setaclargs; +struct nfsd3_accessargs accessargs; +struct nfsd_fhandle fhandle; +struct nfsd3_getaclres getaclres; +struct nfsd_attrstat attrstat; +struct nfsd3_accessres accessres; +}; +const struct svc_version nfsd_acl_version2 = { .vs_vers =2 , .vs_nproc =ARRAY_SIZE (nfsd_acl_procedures2), .vs_proc = nfsd_acl_procedures2, .vs_dispatch = nfsd_dispatch, - .vs_xdrsize =NFS3_SVC_XDRSIZE , + .vs_xdrsize =sizeof (union nfsd_acl2_xdrstore ), };
fs/nfsd/nfs3acl.c +11 -1
@@ -294,11 +294,21 @@ static const struct svc_procedure nfsd_acl_procedures3[3] = { }, }; +/* +* Storage requirements for XDR arguments and results. +*/ +union nfsd_acl3_xdrstore { +struct nfsd3_getaclargs getaclargs; +struct nfsd3_setaclargs setaclargs; +struct nfsd3_getaclres getaclres; +struct nfsd3_attrstat attrstat; +}; +const struct svc_version nfsd_acl_version3 = { .vs_vers =3 , .vs_nproc =ARRAY_SIZE (nfsd_acl_procedures3), .vs_proc = nfsd_acl_procedures3, .vs_dispatch = nfsd_dispatch, - .vs_xdrsize =NFS3_SVC_XDRSIZE , + .vs_xdrsize =sizeof (union nfsd_acl3_xdrstore ), };
fs/nfsd/nfs3proc.c +29 -1
@@ -1184,10 +1184,38 @@ static const struct svc_procedure nfsd_procedures3[22] = { }, }; +/* +* Storage requirements for XDR arguments and results. +*/ +union nfsd3_xdrstore { +struct nfsd3_sattrargs sattrargs; +struct nfsd3_diropargs diropargs; +struct nfsd3_readargs readargs; +struct nfsd3_writeargs writeargs; +struct nfsd3_createargs createargs; +struct nfsd3_renameargs renameargs; +struct nfsd3_linkargs linkargs; +struct nfsd3_symlinkargs symlinkargs; +struct nfsd3_readdirargs readdirargs; +struct nfsd3_diropres diropres; +struct nfsd3_accessres accessres; +struct nfsd3_readlinkres readlinkres; +struct nfsd3_readres readres; +struct nfsd3_writeres writeres; +struct nfsd3_renameres renameres; +struct nfsd3_linkres linkres; +struct nfsd3_readdirres readdirres; +struct nfsd3_fsstatres fsstatres; +struct nfsd3_fsinfores fsinfores; +struct nfsd3_pathconfres pathconfres; +struct nfsd3_commitres commitres; +struct nfsd3_getaclres getaclres; +}; +const struct svc_version nfsd_version3 = { .vs_vers =3 , .vs_nproc =ARRAY_SIZE (nfsd_procedures3), .vs_proc = nfsd_procedures3, .vs_dispatch = nfsd_dispatch, - .vs_xdrsize =NFS3_SVC_XDRSIZE , + .vs_xdrsize =sizeof (union nfsd3_xdrstore ), };
fs/nfsd/xdr3.h +0 -30
@@ -243,36 +243,6 @@ struct nfsd3_fhandle_pair {struct svc_fh fh2; }; -/* -* Storage requirements for XDR arguments and results. -*/ -union nfsd3_xdrstore { -struct nfsd3_sattrargs sattrargs; -struct nfsd3_diropargs diropargs; -struct nfsd3_readargs readargs; -struct nfsd3_writeargs writeargs; -struct nfsd3_createargs createargs; -struct nfsd3_renameargs renameargs; -struct nfsd3_linkargs linkargs; -struct nfsd3_symlinkargs symlinkargs; -struct nfsd3_readdirargs readdirargs; -struct nfsd3_diropres diropres; -struct nfsd3_accessres accessres; -struct nfsd3_readlinkres readlinkres; -struct nfsd3_readres readres; -struct nfsd3_writeres writeres; -struct nfsd3_renameres renameres; -struct nfsd3_linkres linkres; -struct nfsd3_readdirres readdirres; -struct nfsd3_fsstatres fsstatres; -struct nfsd3_fsinfores fsinfores; -struct nfsd3_pathconfres pathconfres; -struct nfsd3_commitres commitres; -struct nfsd3_getaclres getaclres; -}; - -#define NFS3_SVC_XDRSIZE sizeof(union nfsd3_xdrstore) -bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_sattrargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 7/33 NFSD: Use xdrgen XDR functions for the NFSv3 NULL procedure
In reply to Chuck LeverUpdate the NFSPROC3_NULL entry in the nfsd_procedures3 array to use the generated XDR encoder and decoder functions (xdrgen_svc_decode_void and xdrgen_svc_encode_void) instead of the hand-written nfssvc_decode_voidarg and nfssvc_encode_voidres.
Also update pc_xdrressize to 0 since the NULL procedure returns a void result with no XDR-encoded data.
--- fs/nfsd/nfs3proc.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
fs/nfsd/nfs3proc.c +23 -12
@@ -130,10 +130,21 @@ static __be32 nfsd3_map_status(__be32 status) }/* -* NULL call. +* A full specification of each of the following NFSv3 procedures is +* available in RFC 1813 Section 3.3. */ -static __be32 -nfsd3_proc_null (struct svc_rqst *rqstp) + +/** +* nfsd3_proc_null - NULL: Do nothing +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* void NFSPROC3_NULL(void) = 0; +*/ +static __be32 nfsd3_proc_null (struct svc_rqst *rqstp) {return rpc_success; }
@@ -925,15 +936,15 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)static const struct svc_procedure nfsd_procedures3[22 ] = { [NFSPROC3_NULL ] = { - .pc_func = nfsd3_proc_null, - .pc_decode = nfssvc_decode_voidarg, - .pc_encode = nfssvc_encode_voidres, - .pc_argsize =sizeof (struct nfsd_voidargs ), - .pc_argzero =sizeof (struct nfsd_voidargs ), - .pc_ressize =sizeof (struct nfsd_voidres ), - .pc_cachetype =RC_NOCACHE , - .pc_xdrressize =ST , - .pc_name ="NULL" , + .pc_func = nfsd3_proc_null, + .pc_decode = xdrgen_svc_decode_void, + .pc_encode = xdrgen_svc_encode_void, + .pc_argsize = XDR_void, + .pc_argzero =0 , + .pc_ressize =0 , + .pc_cachetype =RC_NOCACHE , + .pc_xdrressize = XDR_void, + .pc_name ="NULL" , }, [NFSPROC3_GETATTR ] = { .pc_func = nfsd3_proc_getattr,
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 8/33 NFSD: Use xdrgen XDR functions for NFSv3 GETATTR procedure
In reply to Chuck LeverReplace the NFSPROC3_GETATTR entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_GETATTR3args and nfs_svc_encode_GETATTR3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh and kstat representations the NFSD VFS layer still uses. A few helper functions are introduced which will be used here and in subsequent patches.
The pc_argzero field is now set to zero for the NFSv3 GETATTR procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
This refactor replaces the use of svcxdr_encode_fattr3(). Because nfsd3_proc_getattr() now fills in the response attributes, the fh_getattr() call is made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_getattr(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
Following the precedent of commit 40ee5dc6af35 ("knfsd: 64 bit ino support for NFS server"), lease_get_mtime() determines the file's mtime for GETATTR (and later when filling in post-op attributes), but is not used for WCC data. This seems odd to me; NFSv4 does not use lease_get_mtime() at all, and not using it for WCC data seems like an NFSv3 file's reported mtime values might vary depending on how the file metadata is queried.
nfs3svc_encode_getattrres() no longer has any callers, so it is removed.
--- Documentation/sunrpc/xdr/nfs3.x | 1 + fs/nfsd/nfs3proc.c | 161 ++++++++++++++++++++++++----- fs/nfsd/nfs3xdr.c | 19 ---- fs/nfsd/nfs3xdr_gen.c | 94 ++++++++--------- fs/nfsd/nfs3xdr_gen.h | 2 +- fs/nfsd/xdr3.h | 1 - include/linux/sunrpc/xdrgen/nfs3.h | 4 +- 7 files changed, 187 insertions(+), 95 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +1 -0
@@ -95,6 +95,7 @@ enum nfsstat3 { NFS3ERR_BADTYPE = 10007, NFS3ERR_JUKEBOX = 10008 }; +pragma big_endian nfsstat3; enum ftype3 { NF3REG = 1,
fs/nfsd/nfs3proc.c +135 -26
214 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +0 -19
@@ -738,25 +738,6 @@ nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)* XDR encode functions */ -/* GETATTR */ -bool -nfs3svc_encode_getattrres (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_attrstat *resp = rqstp->rq_resp; - -if (!svcxdr_encode_nfsstat3 (xdr, resp->status)) -return false; -switch (resp->status) { -case nfs_ok: -lease_get_mtime (d_inode (resp->fh.fh_dentry), &resp->stat.mtime); -if (!svcxdr_encode_fattr3 (rqstp, xdr, &resp->fh, &resp->stat)) -return false; -break ; - } - -return true; -} -/* SETATTR, REMOVE, RMDIR */ bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/nfs3xdr_gen.c +48 -46
373 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.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: Fri Jul 10 23:20:55 2026 */ +/* XDR specification modification time: Fri Jul 10 23:21:45 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
fs/nfsd/xdr3.h +0 -1
@@ -259,7 +259,6 @@ bool nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_getattrres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_lookupres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
include/linux/sunrpc/xdrgen/nfs3.h +2 -2
@@ -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: Fri Jul 10 23:20:55 2026 */ +/* XDR specification modification time: Fri Jul 10 23:21:45 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
@@ -83,7 +83,7 @@ enum nfsstat3 { NFS3ERR_JUKEBOX = 10008, }; -typedef enum nfsstat3 nfsstat3 ; +typedef __be32 nfsstat3 ;enum ftype3 {NF3REG =1 ,
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 9/33 NFSD: Use xdrgen XDR functions for NFSv3 SETATTR procedure
In reply to Chuck LeverReplace the NFSPROC3_SETATTR entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_SETATTR3args and nfs_svc_encode_SETATTR3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh and iattr representations the NFSD VFS layer still uses; the result uses the generated SETATTR3res type directly. The new nfsd3_sattr3_to_iattr() and nfsd3_nfstime3_to_timespec64() helpers translate the decoded sattr3 into the iattr that nfsd_setattr() consumes, and nfsd3_fill_wcc_data() assembles the weak cache consistency data that both the success and failure results carry.
When an operation leaves no post-op attributes saved, svcxdr_encode_wcc_data() omits the pre-op attributes and fetches fresh post-op attributes instead. nfsd3_fill_wcc_data() keeps that behavior through a new nfsd3_fill_post_op_attr() helper, which later procedures also use to fill in post-op attributes.
The pc_argzero field is now set to zero for the NFSv3 SETATTR procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_setattr() now assembles the WCC data, that work moves out of the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_setattr(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_sattrargs() no longer has any callers, so it and its svcxdr_decode_sattrguard3() helper are removed.
--- fs/nfsd/nfs3proc.c | 211 ++++++++++++++++++++++++++++++++++++++------- fs/nfsd/nfs3xdr.c | 27 ------ fs/nfsd/xdr3.h | 8 -- 3 files changed, 179 insertions(+), 67 deletions(-)
fs/nfsd/nfs3proc.c +179 -32
@@ -47,6 +47,15 @@ struct GETATTR3res_wrapper {static_assert (offsetof(struct GETATTR3res_wrapper , xdrgen) ==0 ); +struct SETATTR3args_wrapper { +struct SETATTR3args xdrgen; +struct svc_fh fh; +struct iattr iattrs; +struct timespec64 guard; +}; + +static_assert (offsetof(struct SETATTR3args_wrapper , xdrgen) ==0 ); +static int nfs3_ftypes[] = {0 ,/* NF3NON */ S_IFREG ,/* NF3REG */
@@ -186,6 +195,14 @@ nfsd3_mode_to_ftype3(umode_t mode)return NF3REG ; } +static __always_inline void +nfsd3_nfstime3_to_timespec64 (struct timespec64 *dst, +const struct nfstime3 *src) +{ + dst->tv_sec = src->seconds; + dst->tv_nsec = src->nseconds; +} +static void nfsd3_stat_to_fattr3 (struct svc_rqst *rqstp,struct fattr3 *fattr,const struct kstat *stat,const struct svc_fh *fhp)
@@ -223,6 +240,121 @@ nfsd3_stat_to_fattr3(struct svc_rqst *rqstp, struct fattr3 *fattr,nfsd3_timespec64_to_nfstime3 (&fattr->ctime, &stat->ctime); } +static void +nfsd3_fill_post_op_attr (struct svc_rqst *rqstp,struct post_op_attr *attr, +struct svc_fh *fhp); + +static void +nfsd3_fill_wcc_data (struct svc_rqst *rqstp,struct wcc_data *wcc, +struct svc_fh *fhp) +{ +/* Pre-op attributes are of no use to the client without post-op ones */ +if (!fhp->fh_post_saved) { + wcc->before.attributes_follow = false; +nfsd3_fill_post_op_attr (rqstp, &wcc->after, fhp); +return ; + } + + wcc->before.attributes_follow = fhp->fh_pre_saved; +if (fhp->fh_pre_saved) { +struct wcc_attr *wattr = &wcc->before.u.attributes; + + wattr->size = fhp->fh_pre_size; +nfsd3_timespec64_to_nfstime3 (&wattr->mtime, &fhp->fh_pre_mtime); +nfsd3_timespec64_to_nfstime3 (&wattr->ctime, &fhp->fh_pre_ctime); + } + + wcc->after.attributes_follow = true; +nfsd3_stat_to_fattr3 (rqstp, &wcc->after.u.attributes, + &fhp->fh_post_attr, fhp); +} + +static void +nfsd3_sattr3_to_iattr (struct svc_rqst *rqstp,struct iattr *iap, +const struct sattr3 *sattr) +{ +/* trace_nfsd_vfs_setattr() records fields ia_valid leaves unset */ +memset (iap,0 ,sizeof (*iap)); + +if (sattr->mode.set_it) { + iap->ia_valid |=ATTR_MODE ; + iap->ia_mode = sattr->mode.u.mode; + } +if (sattr->uid.set_it) { + iap->ia_uid =make_kuid (nfsd_user_namespace (rqstp), + sattr->uid.u.uid); +if (uid_valid (iap->ia_uid)) + iap->ia_valid |=ATTR_UID ; + } +if (sattr->gid.set_it) { + iap->ia_gid =make_kgid (nfsd_user_namespace (rqstp), + sattr->gid.u.gid); +if (gid_valid (iap->ia_gid)) + iap->ia_valid |=ATTR_GID ; + } +if (sattr->size.set_it) { + iap->ia_valid |=ATTR_SIZE ; + iap->ia_size = sattr->size.u.size; + } +switch (sattr->atime.set_it) { +case DONT_CHANGE : +break ; +case SET_TO_SERVER_TIME : + iap->ia_valid |=ATTR_ATIME ; +break ; +case SET_TO_CLIENT_TIME : +nfsd3_nfstime3_to_timespec64 (&iap->ia_atime, + &sattr->atime.u.atime); + iap->ia_valid |=ATTR_ATIME |ATTR_ATIME_SET ; +break ; + } +switch (sattr->mtime.set_it) { +case DONT_CHANGE : +break ; +case SET_TO_SERVER_TIME : + iap->ia_valid |=ATTR_MTIME ; +break ; +case SET_TO_CLIENT_TIME : +nfsd3_nfstime3_to_timespec64 (&iap->ia_mtime, + &sattr->mtime.u.mtime); + iap->ia_valid |=ATTR_MTIME |ATTR_MTIME_SET ; +break ; + } +} + +/* +* struct kstat is pretty huge. To reduce stack utilization, reuse @fhp's +* fh_post_attr field as the stat buffer passed to fh_getattr. +* +* This is safe to do as long as proc functions that need both WCC and +* post_op_attrs invoke nfsd3_fill_wcc_data() before invoking +* nfsd3_fill_post_op_attr() on the same fhp argument. +*/ +static void +nfsd3_fill_post_op_attr (struct svc_rqst *rqstp,struct post_op_attr *attr, +struct svc_fh *fhp) +{ +struct kstat *statp = &fhp->fh_post_attr; +struct dentry *dentry = fhp->fh_dentry; + +/* +* The inode may be NULL if the call failed because of a stale +* file handle. In this case, no attributes are returned. +*/ +if (fhp->fh_no_wcc || !dentry || !d_really_is_positive (dentry)) + goto no_post_op_attrs; +if (fh_getattr (fhp, statp) != nfs_ok) + goto no_post_op_attrs; + + attr->attributes_follow = true; +lease_get_mtime (d_inode (dentry), &statp->mtime); +nfsd3_stat_to_fattr3 (rqstp, &attr->u.attributes, statp, fhp); +return ; + +no_post_op_attrs: + attr->attributes_follow = false; +} +/* * A full specification of each of the following NFSv3 procedures is * available in RFC 1813 Section 3.3.
@@ -282,32 +414,47 @@ static __be32 nfsd3_proc_getattr(struct svc_rqst *rqstp)return rpc_success; } -/* -* Set a file's attributes +/** +* nfsd3_proc_setattr - SETATTR: Set file attributes +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* SETATTR3res NFSPROC3_SETATTR(SETATTR3args) = 2; */ -static __be32 -nfsd3_proc_setattr (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_setattr (struct svc_rqst *rqstp) { -struct nfsd3_sattrargs *argp = rqstp->rq_argp; -struct nfsd3_attrstat *resp = rqstp->rq_resp; -struct nfsd_attrs attrs = { - .na_iattr = &argp->attrs, - }; +struct SETATTR3args_wrapper *argp = rqstp->rq_argp; +struct SETATTR3res *resp = rqstp->rq_resp;const struct timespec64 *guardtime =NULL ; +struct svc_fh *fhp = &argp->fh; +struct nfsd_attrs nattrs = { + .na_iattr = &argp->iattrs, + }; -dprintk ("nfsd: SETATTR(3) %s\n" , -SVCFH_fmt (&argp->fh)); - -fh_copy (&resp->fh, &argp->fh); -if (!nfsd3_time_in_range (&argp->attrs)) { - resp->status = nfserr_inval; - goto out; +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.object); +nfsd3_sattr3_to_iattr (rqstp, &argp->iattrs, &argp->xdrgen.new_attributes); +if (argp->xdrgen.guard.check) { +nfsd3_nfstime3_to_timespec64 (&argp->guard, + &argp->xdrgen.guard.u.obj_ctime); + guardtime = &argp->guard; } -if (argp->check_guard) - guardtime = &argp->guardtime; - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime); -out: - resp->status =nfsd3_map_status (resp->status); + +if (nfsd3_time_in_range (&argp->iattrs)) + resp->status =nfsd_setattr (rqstp, fhp, &nattrs, guardtime); +else + resp->status = nfserr_inval; + +if (resp->status == nfs_ok) { +nfsd3_fill_wcc_data (rqstp, &resp->u.resok.obj_wcc, fhp); + }else { + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_wcc_data (rqstp, &resp->u.resfail.obj_wcc, fhp); + } + +fh_put (fhp);return rpc_success; }
@@ -1066,16 +1213,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "GETATTR", }, [NFSPROC3_SETATTR] = { - .pc_func = nfsd3_proc_setattr, - .pc_decode = nfs3svc_decode_sattrargs, - .pc_encode = nfs3svc_encode_wccstatres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_sattrargs), - .pc_argzero = sizeof(struct nfsd3_sattrargs), - .pc_ressize = sizeof(struct nfsd3_wccstatres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+WC, - .pc_name = "SETATTR", + .pc_func = nfsd3_proc_setattr, + .pc_decode = nfs_svc_decode_SETATTR3args, + .pc_encode = nfs_svc_encode_SETATTR3res, + .pc_argsize = sizeof(struct SETATTR3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct SETATTR3res), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_SETATTR3res_sz, + .pc_name = "SETATTR", }, [NFSPROC3_LOOKUP] = { .pc_func = nfsd3_proc_lookup,
@@ -1308,7 +1454,8 @@ static const struct svc_procedure nfsd_procedures3[22] = {union nfsd3_xdrstore {struct GETATTR3args_wrapper getattrargs;struct GETATTR3res_wrapper getattrres; -struct nfsd3_sattrargs sattrargs; +struct SETATTR3args_wrapper setattrargs; +struct SETATTR3res setattrres;struct nfsd3_diropargs diropargs;struct nfsd3_readargs readargs;struct nfsd3_writeargs writeargs;
fs/nfsd/nfs3xdr.c +0 -27
@@ -295,23 +295,6 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,return true; } -static bool -svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) -{ -u32 check; - -if (xdr_stream_decode_bool (xdr, &check) <0 ) -return false; -if (check) { -if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime)) -return false; - args->check_guard =1 ; - }else - args->check_guard =0 ; - -return true; -} -static bool svcxdr_decode_specdata3 (struct xdr_stream *xdr,struct nfsd3_mknodargs *args) {
@@ -499,16 +482,6 @@ nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_nfs_fh3 (xdr, &args->fh); } -bool -nfs3svc_decode_sattrargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_sattrargs *args = rqstp->rq_argp; - -return svcxdr_decode_nfs_fh3 (xdr, &args->fh) && -svcxdr_decode_sattr3 (rqstp, xdr, &args->attrs) && -svcxdr_decode_sattrguard3 (xdr, args); -} -bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
fs/nfsd/xdr3.h +0 -8
@@ -18,13 +18,6 @@#define NFS3_MAXNAMLEN NAME_MAX#define NFS3_MAXPATHLEN PATH_MAX -struct nfsd3_sattrargs { -struct svc_fh fh; -struct iattr attrs; -int check_guard; -struct timespec64 guardtime; -}; -struct nfsd3_diropargs {struct svc_fh fh;char * name;
@@ -244,7 +237,6 @@ struct nfsd3_fhandle_pair { };bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_sattrargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_accessargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 10/33 NFSD: Use xdrgen XDR functions for the NFSv3 LOOKUP procedure
In reply to Chuck LeverReplace the NFSPROC3_LOOKUP entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_LOOKUP3args and nfs_svc_encode_LOOKUP3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 LOOKUP procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfs3svc_decode_diropargs() rejects an empty name, a name longer than NFS3_MAXNAMLEN, and a name containing '/' or NUL. The generated filename3 decoder checks none of these. Introduce nfsd3_check_filename() so that nfsd3_proc_lookup() applies the same checks before it calls nfsd_lookup(). After the change, a name that fails them draws NFS3ERR_INVAL or NFS3ERR_NAMETOOLONG rather than GARBAGE_ARGS. Later procedures that take a filename share the helper.
Because nfsd3_proc_lookup() now fills in the post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_lookup(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
Following the precedent of commit 40ee5dc6af35 ("knfsd: 64 bit ino support for NFS server"), lease_get_mtime() determines the file's mtime when filling in post-op attributes, but is not used for WCC data. This seems odd to me; NFSv4 does not use lease_get_mtime() at all, and not using it for WCC data seems like an NFSv3 file's reported mtime values might vary depending on how the file metadata is queried.
nfs3svc_encode_lookupres() no longer has any callers, so it is removed.
--- fs/nfsd/nfs3proc.c | 116 +++++++++++++++++++++++++++++++++++---------- fs/nfsd/nfs3xdr.c | 25 ---------- fs/nfsd/xdr3.h | 1 - 3 files changed, 90 insertions(+), 52 deletions(-)
fs/nfsd/nfs3proc.c +90 -26
@@ -56,6 +56,21 @@ struct SETATTR3args_wrapper {static_assert (offsetof(struct SETATTR3args_wrapper , xdrgen) ==0 ); +struct LOOKUP3args_wrapper { +struct LOOKUP3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct LOOKUP3args_wrapper , xdrgen) ==0 ); + +struct LOOKUP3res_wrapper { +struct LOOKUP3res xdrgen; +struct svc_fh fh; +u8 fh_data[NFS3_FHSIZE ]; +}; + +static_assert (offsetof(struct LOOKUP3res_wrapper , xdrgen) ==0 ); +static int nfs3_ftypes[] = {0 ,/* NF3NON */ S_IFREG ,/* NF3REG */
@@ -170,6 +185,14 @@ nfsd3_fh3_to_svc_fh(struct svc_fh *fhp, const struct nfs_fh3 *fh3)memcpy (&fhp->fh_handle.fh_raw, fh3->data.data, fh3->data.len); } +static __always_inline void +nfsd3_svc_fh_to_fh3 (struct nfs_fh3 *fh3,const struct svc_fh *fhp,u8 *scratch) +{ +memcpy (scratch, fhp->fh_handle.fh_raw, fhp->fh_handle.fh_size); + fh3->data.data = scratch; + fh3->data.len = fhp->fh_handle.fh_size; +} + static __always_inline voidnfsd3_timespec64_to_nfstime3 (struct nfstime3 *dst,const struct timespec64 *src)
@@ -178,6 +201,22 @@ nfsd3_timespec64_to_nfstime3(struct nfstime3 *dst, dst->nseconds = src->tv_nsec; } +static __be32 +nfsd3_check_filename (const unsigned char *name,u32 len) +{ +u32 i; + +if (len ==0 ) +return nfserr_inval; +if (len >NFS3_MAXNAMLEN ) +return nfserr_nametoolong; +for (i =0 ; i < len; i++) { +if (name[i] =='\0' || name[i] =='/' ) +return nfserr_inval; + } +return nfs_ok; +} +static u32 nfsd3_mode_to_ftype3 (umode_t mode) {
@@ -458,27 +497,51 @@ static __be32 nfsd3_proc_setattr(struct svc_rqst *rqstp)return rpc_success; } -/* -* Look up a path name component +/** +* nfsd3_proc_lookup - LOOKUP: Look up file name +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* LOOKUP3res NFSPROC3_LOOKUP(LOOKUP3args) = 3; */ -static __be32 -nfsd3_proc_lookup (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_lookup (struct svc_rqst *rqstp) { -struct nfsd3_diropargs *argp = rqstp->rq_argp; -struct nfsd3_diropres *resp = rqstp->rq_resp; +struct LOOKUP3args_wrapper *argp = rqstp->rq_argp; +struct LOOKUP3res_wrapper *resp = rqstp->rq_resp; +struct diropargs3 *what = &argp->xdrgen.what; +struct svc_fh *dirfhp = &argp->fh; +struct svc_fh *fhp = &resp->fh; -dprintk ("nfsd: LOOKUP(3) %s %.*s\n" , -SVCFH_fmt (&argp->fh), - argp->len, - argp->name); +nfsd3_fh3_to_svc_fh (dirfhp, &what->dir); -fh_copy (&resp->dirfh, &argp->fh); -fh_init (&resp->fh,NFS3_FHSIZE ); +fh_init (fhp,NFS3_FHSIZE ); + resp->xdrgen.status =nfsd3_check_filename (what->name.data, + what->name.len); +if (resp->xdrgen.status != nfs_ok) + goto out; + resp->xdrgen.status =nfsd_lookup (rqstp, dirfhp, + (char *)what->name.data, + what->name.len, fhp); - resp->status =nfsd_lookup (rqstp, &resp->dirfh, - argp->name, argp->len, - &resp->fh); - resp->status =nfsd3_map_status (resp->status); +out: +if (resp->xdrgen.status == nfs_ok) { +struct LOOKUP3resok *resok = &resp->xdrgen.u.resok; + +nfsd3_svc_fh_to_fh3 (&resok->object, fhp, resp->fh_data); +nfsd3_fill_post_op_attr (rqstp, &resok->obj_attributes, fhp); +nfsd3_fill_post_op_attr (rqstp, &resok->dir_attributes, dirfhp); + }else { +struct LOOKUP3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); +nfsd3_fill_post_op_attr (rqstp, &resfail->dir_attributes, dirfhp); + } + +fh_put (fhp); +fh_put (dirfhp);return rpc_success; }
@@ -1224,16 +1287,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "SETATTR", }, [NFSPROC3_LOOKUP] = { - .pc_func = nfsd3_proc_lookup, - .pc_decode = nfs3svc_decode_diropargs, - .pc_encode = nfs3svc_encode_lookupres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_diropargs), - .pc_argzero = sizeof(struct nfsd3_diropargs), - .pc_ressize = sizeof(struct nfsd3_diropres), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+FH+pAT+pAT, - .pc_name = "LOOKUP", + .pc_func = nfsd3_proc_lookup, + .pc_decode = nfs_svc_decode_LOOKUP3args, + .pc_encode = nfs_svc_encode_LOOKUP3res, + .pc_argsize = sizeof(struct LOOKUP3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct LOOKUP3res_wrapper), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_LOOKUP3res_sz, + .pc_name = "LOOKUP", }, [NFSPROC3_ACCESS] = { .pc_func = nfsd3_proc_access,
@@ -1456,6 +1518,8 @@ union nfsd3_xdrstore {struct GETATTR3res_wrapper getattrres;struct SETATTR3args_wrapper setattrargs;struct SETATTR3res setattrres; +struct LOOKUP3args_wrapper lookupargs; +struct LOOKUP3res_wrapper lookupres;struct nfsd3_diropargs diropargs;struct nfsd3_readargs readargs;struct nfsd3_writeargs writeargs;
fs/nfsd/nfs3xdr.c +0 -25
@@ -721,31 +721,6 @@ nfs3svc_encode_wccstat(struct svc_rqst *rqstp, struct xdr_stream *xdr)svcxdr_encode_wcc_data (rqstp, xdr, &resp->fh); } -/* LOOKUP */ -bool -nfs3svc_encode_lookupres (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_diropres *resp = rqstp->rq_resp; - -if (!svcxdr_encode_nfsstat3 (xdr, resp->status)) -return false; -switch (resp->status) { -case nfs_ok: -if (!svcxdr_encode_nfs_fh3 (xdr, &resp->fh)) -return false; -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) -return false; -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->dirfh)) -return false; -break ; -default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->dirfh)) -return false; - } - -return true; -} -/* ACCESS */ bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/xdr3.h +0 -1
@@ -252,7 +252,6 @@ bool nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, struct xdr_stream *xbool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_lookupres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readlinkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 11/33 NFSD: Use xdrgen XDR functions for NFSv3 ACCESS procedure
In reply to Chuck LeverReplace the NFSPROC3_ACCESS entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_ACCESS3args and nfs_svc_encode_ACCESS3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 ACCESS procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_access() now fills in the post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_access(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_accessargs() and nfs3svc_encode_accessres() no longer have any callers, so they are removed.
--- fs/nfsd/nfs3proc.c | 73 ++++++++++++++++++++++++++++++---------------- fs/nfsd/nfs3xdr.c | 36 ----------------------- fs/nfsd/xdr3.h | 1 - 3 files changed, 48 insertions(+), 62 deletions(-)
fs/nfsd/nfs3proc.c +48 -25
@@ -71,6 +71,13 @@ struct LOOKUP3res_wrapper {static_assert (offsetof(struct LOOKUP3res_wrapper , xdrgen) ==0 ); +struct ACCESS3args_wrapper { +struct ACCESS3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct ACCESS3args_wrapper , xdrgen) ==0 ); +static int nfs3_ftypes[] = {0 ,/* NF3NON */ S_IFREG ,/* NF3REG */
@@ -545,24 +552,40 @@ static __be32 nfsd3_proc_lookup(struct svc_rqst *rqstp)return rpc_success; } -/* -* Check file access +/** +* nfsd3_proc_access - ACCESS: Check access permission +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* ACCESS3res NFSPROC3_ACCESS(ACCESS3args) = 4; */ -static __be32 -nfsd3_proc_access (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_access (struct svc_rqst *rqstp) { -struct nfsd3_accessargs *argp = rqstp->rq_argp; -struct nfsd3_accessres *resp = rqstp->rq_resp; +struct ACCESS3args_wrapper *argp = rqstp->rq_argp; +struct ACCESS3res *resp = rqstp->rq_resp; +struct svc_fh *fhp = &argp->fh; -dprintk ("nfsd: ACCESS(3) %s 0x%x\n" , -SVCFH_fmt (&argp->fh), - argp->access); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.object); -fh_copy (&resp->fh, &argp->fh); - resp->access = argp->access; - resp->status =nfsd_access (rqstp, &resp->fh, &nfsd3_access_maps, - &resp->access,NULL ); - resp->status =nfsd3_map_status (resp->status); + resp->status =nfsd_access (rqstp, fhp, &nfsd3_access_maps, + &argp->xdrgen.access,NULL ); + +if (resp->status == nfs_ok) { +struct ACCESS3resok *resok = &resp->u.resok; + + resok->access = argp->xdrgen.access; +nfsd3_fill_post_op_attr (rqstp, &resok->obj_attributes, fhp); + }else { +struct ACCESS3resfail *resfail = &resp->u.resfail; + + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_post_op_attr (rqstp, &resfail->obj_attributes, fhp); + } + +fh_put (fhp);return rpc_success; }
@@ -1298,16 +1321,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "LOOKUP", }, [NFSPROC3_ACCESS] = { - .pc_func = nfsd3_proc_access, - .pc_decode = nfs3svc_decode_accessargs, - .pc_encode = nfs3svc_encode_accessres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_accessargs), - .pc_argzero = sizeof(struct nfsd3_accessargs), - .pc_ressize = sizeof(struct nfsd3_accessres), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+pAT+1, - .pc_name = "ACCESS", + .pc_func = nfsd3_proc_access, + .pc_decode = nfs_svc_decode_ACCESS3args, + .pc_encode = nfs_svc_encode_ACCESS3res, + .pc_argsize = sizeof(struct ACCESS3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct ACCESS3res), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_ACCESS3res_sz, + .pc_name = "ACCESS", }, [NFSPROC3_READLINK] = { .pc_func = nfsd3_proc_readlink,
@@ -1520,6 +1542,8 @@ union nfsd3_xdrstore {struct SETATTR3res setattrres;struct LOOKUP3args_wrapper lookupargs;struct LOOKUP3res_wrapper lookupres; +struct ACCESS3args_wrapper accessargs; +struct ACCESS3res accessres;struct nfsd3_diropargs diropargs;struct nfsd3_readargs readargs;struct nfsd3_writeargs writeargs;
@@ -1529,7 +1553,6 @@ union nfsd3_xdrstore {struct nfsd3_symlinkargs symlinkargs;struct nfsd3_readdirargs readdirargs;struct nfsd3_diropres diropres; -struct nfsd3_accessres accessres;struct nfsd3_readlinkres readlinkres;struct nfsd3_readres readres;struct nfsd3_writeres writeres;
fs/nfsd/nfs3xdr.c +0 -36
@@ -490,19 +490,6 @@ nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len); } -bool -nfs3svc_decode_accessargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_accessargs *args = rqstp->rq_argp; - -if (!svcxdr_decode_nfs_fh3 (xdr, &args->fh)) -return false; -if (xdr_stream_decode_u32 (xdr, &args->access) <0 ) -return false; - -return true; -} -bool nfs3svc_decode_readargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
@@ -721,29 +708,6 @@ nfs3svc_encode_wccstat(struct svc_rqst *rqstp, struct xdr_stream *xdr)svcxdr_encode_wcc_data (rqstp, xdr, &resp->fh); } -/* ACCESS */ -bool -nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_accessres *resp = rqstp->rq_resp; - -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 (xdr_stream_encode_u32 (xdr, resp->access) <0 ) -return false; -break ; -default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) -return false; - } - -return true; -} -/* READLINK */ bool nfs3svc_encode_readlinkres (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/xdr3.h +0 -1
@@ -238,7 +238,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_accessargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_writeargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_createargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 12/33 NFSD: Use xdrgen XDR functions for NFSv3 READLINK procedure
In reply to Chuck LeverReplace the hand-written NFSv3 READLINK codec pair with the xdrgen-generated functions. The NFSPROC3_READLINK entry in the nfsd_procedures3 array now dispatches nfs_svc_decode_READLINK3args and nfs_svc_encode_READLINK3res. A wrapper structure bridges the generated xdrgen fhandle type and the legacy svc_fh representation the NFSD VFS layer still uses.
The link target does not reside at the data pointer of the READLINK3resok data member: nfsd_readlink() deposits it directly in a page of the Reply buffer, so the generic encoder that copies an opaque from the member's data pointer cannot encode it. Mark the data member with the "pragma pages" directive so the generated encoder calls svcxdr_encode_opaque_payload(), which encodes the length prefix and inserts the payload page into the stream by reference. The page anchor that the result structure carried duplicated rq_res.pages -- svc_process() points rq_res.pages at the first Reply page before dispatch, and the READLINK3args argument decoder consumes no pages -- so the helper locates the payload through the Reply buffer itself, and the wrapper collapses to the generated READLINK3res type.
The pc_argzero field is now set to zero for the NFSv3 READLINK procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_readlink() now fills in the post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_readlink(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
--- Documentation/sunrpc/xdr/nfs3.x | 1 + fs/nfsd/nfs3proc.c | 79 ++++++++++++++++++++---------- fs/nfsd/nfs3xdr.c | 28 ----------- fs/nfsd/nfs3xdr_gen.c | 4 +- fs/nfsd/nfs3xdr_gen.h | 2 +- fs/nfsd/xdr3.h | 9 +--- include/linux/sunrpc/xdrgen/nfs3.h | 2 +- 7 files changed, 60 insertions(+), 65 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +1 -0
@@ -331,6 +331,7 @@ struct READLINK3resok { post_op_attr symlink_attributes; nfspath3 data; }; +pragma pages READLINK3resok data; struct READLINK3resfail { post_op_attr symlink_attributes;
fs/nfsd/nfs3proc.c +54 -25
113 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +0 -28
@@ -708,34 +708,6 @@ nfs3svc_encode_wccstat(struct svc_rqst *rqstp, struct xdr_stream *xdr)svcxdr_encode_wcc_data (rqstp, xdr, &resp->fh); } -/* READLINK */ -bool -nfs3svc_encode_readlinkres (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_readlinkres *resp = rqstp->rq_resp; -struct kvec *head = rqstp->rq_res.head; - -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 (xdr_stream_encode_u32 (xdr, resp->len) <0 ) -return false; -svcxdr_encode_opaque_pages (rqstp, xdr, resp->pages,0 , - resp->len); -if (svc_encode_result_payload (rqstp, head->iov_len, resp->len) <0 ) -return false; -break ; -default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) -return false; - } - -return true; -} -/* READ */ bool nfs3svc_encode_readres (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/nfs3xdr_gen.c +2 -2
@@ -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: Fri Jul 10 23:21:45 2026 +// XDR specification modification time: Tue Jul 14 09:53:56 2026 #include <linux/sunrpc/svc.h>
@@ -2480,7 +2480,7 @@ xdrgen_encode_READLINK3resok(struct xdr_stream *xdr, const struct READLINK3resok {if (!xdrgen_encode_post_op_attr (xdr, &value->symlink_attributes))return false; -if (!xdrgen_encode_nfspath3 (xdr, value->data)) +if (!svcxdr_encode_opaque_payload (xdr, value->data.len))return false;return true; }
fs/nfsd/nfs3xdr_gen.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: Fri Jul 10 23:21:45 2026 */ +/* XDR specification modification time: Tue Jul 14 09:53:56 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
fs/nfsd/xdr3.h +1 -8
@@ -9,6 +9,7 @@#define _LINUX_NFSD_XDR3_H#include <linux/vfs.h> +#include <linux/sunrpc/xdrgen/nfs3.h> #include "vfs.h"
@@ -134,13 +135,6 @@ struct nfsd3_accessres {struct kstat stat; }; -struct nfsd3_readlinkres { -__be32 status; -struct svc_fh fh; -__u32 len; -struct page **pages; -}; -struct nfsd3_readres {__be32 status;struct svc_fh fh;
@@ -252,7 +246,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_readlinkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_writeres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_createres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
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: Fri Jul 10 23:21:45 2026 */ +/* XDR specification modification time: Tue Jul 14 09:53:56 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 13/33 NFSD: Use xdrgen XDR functions for NFSv3 READ procedure
In reply to Chuck LeverReplace the NFSPROC3_READ entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_READ3args and nfs_svc_encode_READ3res. A wrapper structure bridges the generated xdrgen READ3args type and the legacy svc_fh representation the NFSD VFS layer still uses.
The file's data does not reside at the data pointer of the READ3resok data member: nfsd_read() deposits it directly in the pages of the Reply buffer, so the generic encoder that copies an opaque from the member's data pointer cannot encode it. Mark the member with the "pragma pages" directive so the generated encoder calls svcxdr_encode_opaque_payload(), which encodes the length prefix and inserts the payload pages into the stream by reference. The page anchor that the result structure carried duplicated rq_res.pages -- svc_process() points rq_res.pages at the first Reply page before dispatch, and the READ3args decoder consumes no pages -- so the helper locates the payload through the Reply buffer itself, and the wrapper collapses to the generated READ3res type.
The pc_argzero field is now set to zero for the NFSv3 READ procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_read() now fills in the post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_read(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_readargs() no longer has any callers, so it is removed.
--- Documentation/sunrpc/xdr/nfs3.x | 1 + fs/nfsd/nfs3proc.c | 99 ++++++++++++++++++------------ fs/nfsd/nfs3xdr.c | 48 --------------- fs/nfsd/nfs3xdr_gen.c | 4 +- fs/nfsd/nfs3xdr_gen.h | 2 +- fs/nfsd/xdr3.h | 16 ----- include/linux/sunrpc/xdrgen/nfs3.h | 2 +- 7 files changed, 66 insertions(+), 106 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +1 -0
@@ -356,6 +356,7 @@ struct READ3resok { bool eof; opaque data<>; }; +pragma pages READ3resok data; struct READ3resfail { post_op_attr file_attributes;
fs/nfsd/nfs3proc.c +61 -38
139 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +0 -48
60 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.c +2 -2
@@ -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 09:53:56 2026 +// XDR specification modification time: Tue Jul 14 11:24:16 2026 #include <linux/sunrpc/svc.h>
@@ -2531,7 +2531,7 @@ xdrgen_encode_READ3resok(struct xdr_stream *xdr, const struct READ3resok *value)return false;if (!xdrgen_encode_bool (xdr, value->eof))return false; -if (xdr_stream_encode_opaque (xdr, value->data.data, value->data.len) <0 ) +if (!svcxdr_encode_opaque_payload (xdr, value->data.len))return false;return true; }
fs/nfsd/nfs3xdr_gen.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 09:53:56 2026 */ +/* XDR specification modification time: Tue Jul 14 11:24:16 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
fs/nfsd/xdr3.h +0 -16
@@ -30,12 +30,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_readargs { -struct svc_fh fh; -__u64 offset; -__u32 count; -}; -struct nfsd3_writeargs {svc_fh fh;__u64 offset;
@@ -135,14 +129,6 @@ struct nfsd3_accessres {struct kstat stat; }; -struct nfsd3_readres { -__be32 status; -struct svc_fh fh; -unsigned long count; -__u32 eof; -struct page **pages; -}; -struct nfsd3_writeres {__be32 status;struct svc_fh fh;
@@ -232,7 +218,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_readargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_writeargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_createargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
@@ -246,7 +231,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_readres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_writeres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_createres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
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 09:53:56 2026 */ +/* XDR specification modification time: Tue Jul 14 11:24:16 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 14/33 NFSD: Use xdrgen XDR functions for NFSv3 WRITE procedure
In reply to Chuck LeverReplace the NFSPROC3_WRITE entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_WRITE3args and nfs_svc_encode_WRITE3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh representation the NFSD VFS layer still uses.
The NFSv3 WRITE argument decoder could not be generated before because the write payload must be directed into the server's page cache and decoded in place; a materializing decoder would copy every write. The "pages" directive now expresses this: it represents the payload as a struct xdr_buf and decodes it with svcxdr_decode_opaque_payload(), which subsegments the source stream in place rather than copying it. Annotate the data member of WRITE3args with "pragma pages".
Clamping the payload size when decoding serves no functional purpose and is removed entirely. The transport layer has already guaranteed that the incoming message, including the WRITE payload, does not exceed svc_max_payload.
The WRITE count versus data length sanity check moves to the proc function: if those values are ever not equal, that does not count as GARBAGE_ARGS, since the server is able to decode these arguments. Rather, the arguments are invalid.
The pc_argzero field is now set to zero for the NFSv3 WRITE procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary.
Because nfsd3_proc_write() now fills in the WCC data, including both the pre-op and post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_write(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_writeargs() and nfs3svc_encode_writeres() no longer have any callers, so they are removed.
--- Documentation/sunrpc/xdr/nfs3.x | 1 + fs/nfsd/nfs3proc.c | 94 +++++++++++++++++++----------- fs/nfsd/nfs3xdr.c | 59 ------------------- fs/nfsd/nfs3xdr_gen.c | 8 +-- fs/nfsd/nfs3xdr_gen.h | 4 +- fs/nfsd/xdr3.h | 19 +----- include/linux/sunrpc/xdrgen/nfs3.h | 6 +- 7 files changed, 73 insertions(+), 118 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +1 -0
@@ -382,6 +382,7 @@ struct WRITE3args { stable_how stable; opaque data<>; }; +pragma pages WRITE3args data; struct WRITE3resok { wcc_data file_wcc;
fs/nfsd/nfs3proc.c +60 -34
124 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +0 -59
71 lines not on this page · raw message
fs/nfsd/nfs3xdr_gen.c +4 -4
@@ -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 11:24:16 2026 +// XDR specification file: Documentation/sunrpc/xdr/nfs3.x +// XDR specification modification time: Tue Jul 14 11:43:26 2026 #include <linux/sunrpc/svc.h>
@@ -731,7 +731,7 @@ xdrgen_decode_WRITE3args(struct xdr_stream *xdr, struct WRITE3args *ptr)return false;if (!xdrgen_decode_stable_how (xdr, &ptr->stable))return false; -if (!xdrgen_decode_opaque (xdr, &ptr->data,0 )) +if (!svcxdr_decode_opaque_payload (xdr, &ptr->data,0 ))return false;return true; }
@@ -2578,7 +2578,7 @@ xdrgen_encode_WRITE3args(struct xdr_stream *xdr, const struct WRITE3args *value)return false;if (!xdrgen_encode_stable_how (xdr, value->stable))return false; -if (xdr_stream_encode_opaque (xdr, value->data.data, value->data.len) <0 ) +if (!svcxdr_encode_opaque_payload (xdr, value->data.len))return false;return true; }
fs/nfsd/nfs3xdr_gen.h +2 -2
@@ -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 11:24:16 2026 */ +/* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ +/* XDR specification modification time: Tue Jul 14 11:43:26 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
fs/nfsd/xdr3.h +3 -16
@@ -30,15 +30,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_writeargs { -svc_fh fh; -__u64 offset; -__u32 count; -__u32 stable; -__u32 len; -struct xdr_buf payload; -}; -struct nfsd3_createargs {struct svc_fh fh;char * name;
@@ -130,13 +121,11 @@ struct nfsd3_accessres { };struct nfsd3_writeres { -__be32 status; -struct svc_fh fh; -unsigned long count; -int committed; -__be32 verf[2 ]; +struct WRITE3res xdrgen; }; +static_assert (offsetof(struct nfsd3_writeres , xdrgen) ==0 ); +struct nfsd3_renameres {__be32 status;struct svc_fh ffh;
@@ -218,7 +207,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_writeargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_createargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
@@ -231,7 +219,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_writeres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_createres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
include/linux/sunrpc/xdrgen/nfs3.h +3 -3
@@ -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 11:24:16 2026 */ +/* XDR specification file: Documentation/sunrpc/xdr/nfs3.x */ +/* XDR specification modification time: Tue Jul 14 11:43:26 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
@@ -382,7 +382,7 @@ struct WRITE3args {offset3 offset;count3 count;stable_how stable; -opaque data; +struct xdr_buf data; };struct WRITE3resok {
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 15/33 NFSD: Use xdrgen XDR functions for NFSv3 CREATE procedure
In reply to Chuck LeverReplace the NFSPROC3_CREATE entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_CREATE3args and nfs_svc_encode_CREATE3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh and iattr representations the NFSD VFS layer still uses.
Introduce nfsd3_fill_post_op_fh3() to fill a post_op_fh3. It is useful here and in subsequent patches.
Filename validity is now checked by nfsd3_create_file() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 CREATE procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_create() now fills in the post-op file handle, the post-op attributes, and the WCC data, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_create(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_createargs() no longer has any callers, so it is removed.
--- fs/nfsd/nfs3proc.c | 194 ++++++++++++++++++++++++++++++--------------- fs/nfsd/nfs3xdr.c | 24 ------ fs/nfsd/xdr3.h | 1 - 3 files changed, 130 insertions(+), 89 deletions(-)
fs/nfsd/nfs3proc.c +130 -64
@@ -99,6 +99,22 @@ struct WRITE3args_wrapper {static_assert (offsetof(struct WRITE3args_wrapper , xdrgen) ==0 ); +struct CREATE3args_wrapper { +struct CREATE3args xdrgen; +struct svc_fh fh; +struct iattr iattrs; +}; + +static_assert (offsetof(struct CREATE3args_wrapper , xdrgen) ==0 ); + +struct CREATE3res_wrapper { +struct CREATE3res xdrgen; +struct svc_fh fh; +u8 fh_data[NFS3_FHSIZE ]; +}; + +static_assert (offsetof(struct CREATE3res_wrapper , xdrgen) ==0 ); +static int nfs3_ftypes[] = {0 ,/* NF3NON */ S_IFREG ,/* NF3REG */
@@ -422,6 +438,18 @@ nfsd3_fill_post_op_attr(struct svc_rqst *rqstp, struct post_op_attr *attr, attr->attributes_follow = false; } +static void +nfsd3_fill_post_op_fh3 (struct post_op_fh3 *post_op_fh, +const struct svc_fh *fhp,u8 *data) +{ +if (fhp->fh_handle.fh_size !=0 ) { + post_op_fh->handle_follows = true; +nfsd3_svc_fh_to_fh3 (&post_op_fh->u.handle, fhp, data); + }else { + post_op_fh->handle_follows = false; + } +} +/* * A full specification of each of the following NFSv3 procedures is * available in RFC 1813 Section 3.3.
@@ -761,59 +789,72 @@ static __be32 nfsd3_proc_write(struct svc_rqst *rqstp)* Implement NFSv3's unchecked, guarded, and exclusive CREATE * semantics for regular files. Except for the created file, * this operation is stateless on the server. -* -* Upon return, caller must release @fhp and @resfhp. */ static __be32 -nfsd3_create_file (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct svc_fh *resfhp,struct nfsd3_createargs *argp) +nfsd3_create_file (struct svc_rqst *rqstp,struct svc_fh *dirfhp, +struct svc_fh *resfhp,struct CREATE3args_wrapper *argp) { -struct iattr *iap = &argp->attrs; +struct diropargs3 *where = &argp->xdrgen.where; +struct createhow3 *how = &argp->xdrgen.how; +struct iattr *iattrs = &argp->iattrs;struct dentry *parent, *child; -struct nfsd_attrs attrs = { - .na_iattr = iap, - };struct svc_export *exp;__u32 v_mtime, v_atime;struct inode *inode; +struct nfsd_attrs nattrs = { + .na_iattr = iattrs, + };__be32 status;int host_err; -trace_nfsd_vfs_create (rqstp, fhp,S_IFREG , argp->name, argp->len); - -if (!nfsd3_time_in_range (iap)) -return nfserr_inval; -if (name_is_dot_dotdot (argp->name, argp->len)) -return nfserr_exist; -if (!(iap->ia_valid &ATTR_MODE )) - iap->ia_mode =0 ; - - status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_EXEC ); + status =nfsd3_check_filename (where->name.data, where->name.len);if (status != nfs_ok)return status; - parent = fhp->fh_dentry; +trace_nfsd_vfs_create (rqstp, dirfhp,S_IFREG , (char *)where->name.data, + where->name.len); + +if (name_is_dot_dotdot (where->name.data, where->name.len)) +return nfserr_exist; + +if (how->mode !=EXCLUSIVE ) { +nfsd3_sattr3_to_iattr (rqstp, iattrs, + &how->u.obj_attributes); +if (!(iattrs->ia_valid &ATTR_MODE )) + iattrs->ia_mode =0 ; + }else { +memset (iattrs,0 ,sizeof (*iattrs)); + } + +if (!nfsd3_time_in_range (iattrs)) +return nfserr_inval; + + status =fh_verify (rqstp, dirfhp,S_IFDIR ,NFSD_MAY_EXEC ); +if (status != nfs_ok) +return status; + + parent = dirfhp->fh_dentry; inode =d_inode (parent); - host_err =fh_want_write (fhp); + host_err =fh_want_write (dirfhp);if (host_err)return nfserrno (host_err); child =start_creating (&nop_mnt_idmap, parent, - &QSTR_LEN (argp->name, argp->len)); + &QSTR_LEN (where->name.data, where->name.len));if (IS_ERR (child)) { status =nfserrno (PTR_ERR (child)); goto out_write; }if (d_really_is_negative (child)) { - status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); + status =fh_verify (rqstp, dirfhp,S_IFDIR ,NFSD_MAY_CREATE );if (status != nfs_ok) goto out; } - exp =exp_get (fhp->fh_export); -if (argp->createmode ==UNCHECKED ) { + exp =exp_get (dirfhp->fh_export); +if (how->mode ==UNCHECKED ) {/* * If name is already in dcache we need to check for mountpoints */
@@ -827,15 +868,15 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, } } - status =fh_compose (resfhp, exp, child, fhp); + status =fh_compose (resfhp, exp, child, dirfhp);exp_put (exp);if (status != nfs_ok) goto out; v_mtime =0 ; v_atime =0 ; -if (argp->createmode ==EXCLUSIVE ) { -u32 *verifier = (u32 *)argp->verf; +if (how->mode ==EXCLUSIVE ) { +u32 *verifier = (u32 *)how->u.verf;/* * Solaris 7 gets confused (bugid 4218508) if these have
@@ -849,11 +890,11 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (d_really_is_positive (child)) { status = nfs_ok; -switch (argp->createmode) { +switch (how->mode) {case UNCHECKED :if (!d_is_reg (child))break ; - iap->ia_valid &=ATTR_SIZE ; + iattrs->ia_valid &=ATTR_SIZE ; goto set_attr;case GUARDED : status = nfserr_exist;
@@ -870,52 +911,77 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, }if (!IS_POSIXACL (inode)) - iap->ia_mode &= ~current_umask (); + iattrs->ia_mode &= ~current_umask (); - status =fh_fill_pre_attrs (fhp); + status =fh_fill_pre_attrs (dirfhp);if (status != nfs_ok) goto out; - host_err =vfs_create (&nop_mnt_idmap, child, iap->ia_mode,NULL ); + host_err =vfs_create (&nop_mnt_idmap, child, iattrs->ia_mode,NULL );if (host_err <0 ) { status =nfserrno (host_err); goto out; } -fh_fill_post_attrs (fhp); +fh_fill_post_attrs (dirfhp);/* A newly created file already has a file size of zero. */ -if ((iap->ia_valid &ATTR_SIZE ) && (iap->ia_size ==0 )) - iap->ia_valid &= ~ATTR_SIZE ; -if (argp->createmode ==EXCLUSIVE ) { - iap->ia_valid =ATTR_MTIME |ATTR_ATIME | -ATTR_MTIME_SET |ATTR_ATIME_SET ; - iap->ia_mtime.tv_sec = v_mtime; - iap->ia_atime.tv_sec = v_atime; - iap->ia_mtime.tv_nsec =0 ; - iap->ia_atime.tv_nsec =0 ; +if ((iattrs->ia_valid &ATTR_SIZE ) && iattrs->ia_size ==0 ) + iattrs->ia_valid &= ~ATTR_SIZE ; +if (how->mode ==EXCLUSIVE ) { + iattrs->ia_valid =ATTR_MTIME |ATTR_ATIME | +ATTR_MTIME_SET |ATTR_ATIME_SET ; + iattrs->ia_mtime.tv_sec = v_mtime; + iattrs->ia_atime.tv_sec = v_atime; + iattrs->ia_mtime.tv_nsec =0 ; + iattrs->ia_atime.tv_nsec =0 ; } set_attr: - status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs); + status =nfsd_create_setattr (rqstp, dirfhp, resfhp, &nattrs); out:end_creating (child); out_write: -fh_drop_write (fhp); +fh_drop_write (dirfhp);return status; } -static __be32 -nfsd3_proc_create (struct svc_rqst *rqstp) +/** +* nfsd3_proc_create - CREATE: Create a file +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* CREATE3res NFSPROC3_CREATE(CREATE3args) = 8; +*/ +static __be32 nfsd3_proc_create (struct svc_rqst *rqstp) { -struct nfsd3_createargs *argp = rqstp->rq_argp; -struct nfsd3_diropres *resp = rqstp->rq_resp; -svc_fh *dirfhp, *newfhp; +struct CREATE3args_wrapper *argp = rqstp->rq_argp; +struct CREATE3res_wrapper *resp = rqstp->rq_resp; +struct svc_fh *dirfhp = &argp->fh; +struct svc_fh *fhp = &resp->fh; - dirfhp =fh_copy (&resp->dirfh, &argp->fh); - newfhp =fh_init (&resp->fh,NFS3_FHSIZE ); +nfsd3_fh3_to_svc_fh (dirfhp, &argp->xdrgen.where.dir); - resp->status =nfsd3_create_file (rqstp, dirfhp, newfhp, argp); - resp->status =nfsd3_map_status (resp->status); +fh_init (fhp,NFS3_FHSIZE ); + resp->xdrgen.status =nfsd3_create_file (rqstp, dirfhp, fhp, argp); + +if (resp->xdrgen.status == nfs_ok) { +struct CREATE3resok *resok = &resp->xdrgen.u.resok; + +nfsd3_fill_post_op_fh3 (&resok->obj, fhp, resp->fh_data); +nfsd3_fill_post_op_attr (rqstp, &resok->obj_attributes, fhp); +nfsd3_fill_wcc_data (rqstp, &resok->dir_wcc, dirfhp); + }else { +struct CREATE3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); +nfsd3_fill_wcc_data (rqstp, &resfail->dir_wcc, dirfhp); + } + +fh_put (fhp); +fh_put (dirfhp);return rpc_success; }
@@ -1445,16 +1511,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "WRITE", }, [NFSPROC3_CREATE] = { - .pc_func = nfsd3_proc_create, - .pc_decode = nfs3svc_decode_createargs, - .pc_encode = nfs3svc_encode_createres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_createargs), - .pc_argzero = sizeof(struct nfsd3_createargs), - .pc_ressize = sizeof(struct nfsd3_diropres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+(1+FH+pAT)+WC, - .pc_name = "CREATE", + .pc_func = nfsd3_proc_create, + .pc_decode = nfs_svc_decode_CREATE3args, + .pc_encode = nfs_svc_encode_CREATE3res, + .pc_argsize = sizeof(struct CREATE3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct CREATE3res_wrapper), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_CREATE3res_sz, + .pc_name = "CREATE", }, [NFSPROC3_MKDIR] = { .pc_func = nfsd3_proc_mkdir,
@@ -1625,7 +1690,8 @@ union nfsd3_xdrstore {struct READ3args_wrapper readargs;struct nfsd3_diropargs diropargs;struct WRITE3args_wrapper writeargs; -struct nfsd3_createargs createargs; +struct CREATE3args_wrapper createargs; +struct CREATE3res_wrapper createres;struct nfsd3_renameargs renameargs;struct nfsd3_linkargs linkargs;struct nfsd3_symlinkargs symlinkargs;
fs/nfsd/nfs3xdr.c +0 -24
@@ -490,30 +490,6 @@ nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len); } -bool -nfs3svc_decode_createargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_createargs *args = rqstp->rq_argp; - -if (!svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len)) -return false; -if (xdr_stream_decode_u32 (xdr, &args->createmode) <0 ) -return false; -switch (args->createmode) { -case UNCHECKED : -case GUARDED : -return svcxdr_decode_sattr3 (rqstp, xdr, &args->attrs); -case EXCLUSIVE : - args->verf =xdr_inline_decode (xdr,NFS3_CREATEVERFSIZE ); -if (!args->verf) -return false; -break ; -default : -return false; - } -return true; -} -bool nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
fs/nfsd/xdr3.h +0 -1
@@ -207,7 +207,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_createargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 16/33 NFSD: Use xdrgen XDR functions for NFSv3 MKDIR procedure
In reply to Chuck LeverReplace the NFSPROC3_MKDIR entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_MKDIR3args and nfs_svc_encode_MKDIR3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh and iattr representations the NFSD VFS layer still uses.
Filename validity is now checked by nfsd3_proc_mkdir() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 MKDIR procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_mkdir() now fills in the post-op file handle, the post-op attributes, and the WCC data, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_mkdir(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_mkdirargs() no longer has any callers, so it is removed.
--- fs/nfsd/nfs3proc.c | 102 +++++++++++++++++++++++++++++++++------------ fs/nfsd/nfs3xdr.c | 10 ----- fs/nfsd/xdr3.h | 10 ----- 3 files changed, 75 insertions(+), 47 deletions(-)
fs/nfsd/nfs3proc.c +75 -27
@@ -115,6 +115,22 @@ struct CREATE3res_wrapper {static_assert (offsetof(struct CREATE3res_wrapper , xdrgen) ==0 ); +struct MKDIR3args_wrapper { +struct MKDIR3args xdrgen; +struct svc_fh fh; +struct iattr iattrs; +}; + +static_assert (offsetof(struct MKDIR3args_wrapper , xdrgen) ==0 ); + +struct MKDIR3res_wrapper { +struct MKDIR3res xdrgen; +struct svc_fh fh; +u8 fh_data[NFS3_FHSIZE ]; +}; + +static_assert (offsetof(struct MKDIR3res_wrapper , xdrgen) ==0 ); +static int nfs3_ftypes[] = {0 ,/* NF3NON */ S_IFREG ,/* NF3REG */
@@ -985,29 +1001,61 @@ static __be32 nfsd3_proc_create(struct svc_rqst *rqstp)return rpc_success; } -/* -* Make directory. This operation is not idempotent. +/** +* nfsd3_proc_mkdir - MKDIR: Create a directory +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* MKDIR3res NFSPROC3_MKDIR(MKDIR3args) = 9; */ -static __be32 -nfsd3_proc_mkdir (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_mkdir (struct svc_rqst *rqstp) { -struct nfsd3_createargs *argp = rqstp->rq_argp; -struct nfsd3_diropres *resp = rqstp->rq_resp; -struct nfsd_attrs attrs = { - .na_iattr = &argp->attrs, +struct MKDIR3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *where = &argp->xdrgen.where; +struct MKDIR3res_wrapper *resp = rqstp->rq_resp; +struct iattr *iattrs = &argp->iattrs; +struct svc_fh *dirfhp = &argp->fh; +struct svc_fh *fhp = &resp->fh; +struct nfsd_attrs nattrs = { + .na_iattr = iattrs, }; - argp->attrs.ia_valid &= ~ATTR_SIZE ; -fh_copy (&resp->dirfh, &argp->fh); -fh_init (&resp->fh,NFS3_FHSIZE ); -if (!nfsd3_time_in_range (&argp->attrs)) { - resp->status = nfserr_inval; +nfsd3_fh3_to_svc_fh (dirfhp, &where->dir); + resp->xdrgen.status =nfsd3_check_filename (where->name.data, + where->name.len); +if (resp->xdrgen.status != nfs_ok) + goto out; +nfsd3_sattr3_to_iattr (rqstp, iattrs, &argp->xdrgen.attributes); +if (!nfsd3_time_in_range (iattrs)) { + resp->xdrgen.status = nfserr_inval; goto out; } - resp->status =nfsd_create (rqstp, &resp->dirfh, argp->name, argp->len, - &attrs,S_IFDIR ,0 , &resp->fh); + +fh_init (fhp,NFS3_FHSIZE ); + iattrs->ia_valid &= ~ATTR_SIZE ; + resp->xdrgen.status =nfsd_create (rqstp, dirfhp, (char *)where->name.data, + where->name.len, &nattrs,S_IFDIR , +0 , fhp); + out: - resp->status =nfsd3_map_status (resp->status); +if (resp->xdrgen.status == nfs_ok) { +struct MKDIR3resok *resok = &resp->xdrgen.u.resok; + +nfsd3_fill_post_op_fh3 (&resok->obj, fhp, resp->fh_data); +nfsd3_fill_post_op_attr (rqstp, &resok->obj_attributes, fhp); +nfsd3_fill_wcc_data (rqstp, &resok->dir_wcc, dirfhp); + }else { +struct MKDIR3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); +nfsd3_fill_wcc_data (rqstp, &resfail->dir_wcc, dirfhp); + } + +fh_put (fhp); +fh_put (dirfhp);return rpc_success; }
@@ -1407,7 +1455,6 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)* Only the results of non-idempotent operations are cached. */ #define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat -#define nfsd3_mkdirargs nfsd3_createargs#define nfsd3_readdirplusargs nfsd3_readdirargs#define nfsd3_fhandleargs nfsd_fhandle#define nfsd3_wccstatres nfsd3_attrstat
@@ -1522,16 +1569,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "CREATE", }, [NFSPROC3_MKDIR] = { - .pc_func = nfsd3_proc_mkdir, - .pc_decode = nfs3svc_decode_mkdirargs, - .pc_encode = nfs3svc_encode_createres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_mkdirargs), - .pc_argzero = sizeof(struct nfsd3_mkdirargs), - .pc_ressize = sizeof(struct nfsd3_diropres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+(1+FH+pAT)+WC, - .pc_name = "MKDIR", + .pc_func = nfsd3_proc_mkdir, + .pc_decode = nfs_svc_decode_MKDIR3args, + .pc_encode = nfs_svc_encode_MKDIR3res, + .pc_argsize = sizeof(struct MKDIR3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct MKDIR3res_wrapper), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_MKDIR3res_sz, + .pc_name = "MKDIR", }, [NFSPROC3_SYMLINK] = { .pc_func = nfsd3_proc_symlink,
@@ -1692,6 +1738,8 @@ union nfsd3_xdrstore {struct WRITE3args_wrapper writeargs;struct CREATE3args_wrapper createargs;struct CREATE3res_wrapper createres; +struct MKDIR3args_wrapper mkdirargs; +struct MKDIR3res_wrapper mkdirres;struct nfsd3_renameargs renameargs;struct nfsd3_linkargs linkargs;struct nfsd3_symlinkargs symlinkargs;
fs/nfsd/nfs3xdr.c +0 -10
@@ -490,16 +490,6 @@ nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len); } -bool -nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_createargs *args = rqstp->rq_argp; - -return svcxdr_decode_diropargs3 (xdr, &args->fh, - &args->name, &args->len) && -svcxdr_decode_sattr3 (rqstp, xdr, &args->attrs); -} -bool nfs3svc_decode_symlinkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
fs/nfsd/xdr3.h +0 -10
@@ -30,15 +30,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_createargs { -struct svc_fh fh; -char * name; -unsigned int len; -int createmode; -struct iattr attrs; -__be32 * verf; -}; -struct nfsd3_mknodargs {struct svc_fh fh;char * name;
@@ -207,7 +198,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_mkdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 17/33 NFSD: Use xdrgen XDR functions for NFSv3 SYMLINK procedure
In reply to Chuck LeverReplace the NFSPROC3_SYMLINK entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_SYMLINK3args and nfs_svc_encode_SYMLINK3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh and iattr representations the NFSD VFS layer still uses.
A SYMLINK request's target pathname can extend from the head of the receive buffer into its page data; nfsd3_proc_symlink() reassembles it from a head segment and a page via svc_fill_symlink_pathname(). Annotate the symlink_data member of symlinkdata3 with "pragma pages" so the generated decoder represents the pathname as a struct xdr_buf and decodes it with svcxdr_decode_opaque_payload(), which subsegments the receive stream instead of pulling the string inline through the bounded xdr scratch buffer.
Filename validity is now checked by nfsd3_proc_symlink() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 SYMLINK procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_symlink() now fills in the post-op file handle, the post-op attributes, and the WCC data, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_symlink(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_symlinkargs() no longer has any callers, so it is removed.
--- Documentation/sunrpc/xdr/nfs3.x | 1 + fs/nfsd/nfs3proc.c | 122 +++++++++++++++++++++-------- fs/nfsd/nfs3xdr.c | 19 ----- fs/nfsd/nfs3xdr_gen.c | 6 +- fs/nfsd/nfs3xdr_gen.h | 2 +- fs/nfsd/xdr3.h | 11 --- include/linux/sunrpc/xdrgen/nfs3.h | 4 +- 7 files changed, 95 insertions(+), 70 deletions(-)
Documentation/sunrpc/xdr/nfs3.x +1 -0
@@ -464,6 +464,7 @@ struct symlinkdata3 { sattr3 symlink_attributes; nfspath3 symlink_data; }; +pragma pages symlinkdata3 symlink_data; struct SYMLINK3args { diropargs3 where;
fs/nfsd/nfs3proc.c +88 -34
162 lines not on this page · raw message
fs/nfsd/nfs3xdr.c +0 -19
@@ -490,25 +490,6 @@ nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len); } -bool -nfs3svc_decode_symlinkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_symlinkargs *args = rqstp->rq_argp; -struct kvec *head = rqstp->rq_arg.head; - -if (!svcxdr_decode_diropargs3 (xdr, &args->ffh, &args->fname, &args->flen)) -return false; -if (!svcxdr_decode_sattr3 (rqstp, xdr, &args->attrs)) -return false; -if (xdr_stream_decode_u32 (xdr, &args->tlen) <0 ) -return false; - -/* symlink_data */ - args->first.iov_len = head->iov_len -xdr_stream_pos (xdr); - args->first.iov_base =xdr_inline_decode (xdr, args->tlen); -return args->first.iov_base !=NULL ; -} -bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
fs/nfsd/nfs3xdr_gen.c +3 -3
@@ -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 11:43:26 2026 +// XDR specification modification time: Tue Jul 14 12:13:57 2026 #include <linux/sunrpc/svc.h>
@@ -915,7 +915,7 @@ xdrgen_decode_symlinkdata3(struct xdr_stream *xdr, struct symlinkdata3 *ptr) {if (!xdrgen_decode_sattr3 (xdr, &ptr->symlink_attributes))return false; -if (!xdrgen_decode_nfspath3 (xdr, &ptr->symlink_data)) +if (!svcxdr_decode_opaque_payload (xdr, &ptr->symlink_data,0 ))return false;return true; }
@@ -2748,7 +2748,7 @@ xdrgen_encode_symlinkdata3(struct xdr_stream *xdr, const struct symlinkdata3 *va {if (!xdrgen_encode_sattr3 (xdr, &value->symlink_attributes))return false; -if (!xdrgen_encode_nfspath3 (xdr, value->symlink_data)) +if (!svcxdr_encode_opaque_payload (xdr, value->symlink_data.len))return false;return true; }
fs/nfsd/nfs3xdr_gen.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 11:43:26 2026 */ +/* XDR specification modification time: Tue Jul 14 12:13:57 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DECL_H#define _LINUX_XDRGEN_NFS3_DECL_H
fs/nfsd/xdr3.h +0 -11
@@ -55,16 +55,6 @@ struct nfsd3_linkargs {unsigned int tlen; }; -struct nfsd3_symlinkargs { -struct svc_fh ffh; -char * fname; -unsigned int flen; -char * tname; -unsigned int tlen; -struct iattr attrs; -struct kvec first; -}; -struct nfsd3_readdirargs {struct svc_fh fh;__u64 cookie;
@@ -201,7 +191,6 @@ bool nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_symlinkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
include/linux/sunrpc/xdrgen/nfs3.h +2 -2
@@ -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 11:43:26 2026 */ +/* XDR specification modification time: Tue Jul 14 12:13:57 2026 */ #ifndef _LINUX_XDRGEN_NFS3_DEF_H#define _LINUX_XDRGEN_NFS3_DEF_H
@@ -468,7 +468,7 @@ struct MKDIR3res {struct symlinkdata3 {struct sattr3 symlink_attributes; -nfspath3 symlink_data; +struct xdr_buf symlink_data; };struct SYMLINK3args {
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 18/33 NFSD: Use xdrgen XDR functions for NFSv3 MKNOD procedure
In reply to Chuck LeverReplace the NFSPROC3_MKNOD entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_MKNOD3args and nfs_svc_encode_MKNOD3res. Wrapper structures bridge the generated xdrgen types and the legacy svc_fh and iattr representations the NFSD VFS layer still uses.
Filename validity is now checked by nfsd3_proc_mknod() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 MKNOD procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_mknod() now fills in the post-op file handle, the post-op attributes, and the WCC data, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_mknod(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_mknodargs() and nfs3svc_encode_createres() no longer have any callers, so they are removed. MKNOD was the last consumer of the hand-coded sattr3 decoder, so svcxdr_decode_sattr3() and its helpers svcxdr_decode_nfstime3(), svcxdr_decode_specdata3(), and svcxdr_decode_devicedata3() are removed as well.
--- fs/nfsd/nfs3proc.c | 154 +++++++++++++++++++++++++++------------ fs/nfsd/nfs3xdr.c | 175 --------------------------------------------- fs/nfsd/xdr3.h | 18 ----- 3 files changed, 107 insertions(+), 240 deletions(-)
fs/nfsd/nfs3proc.c +107 -47
@@ -147,17 +147,37 @@ struct SYMLINK3res_wrapper {static_assert (offsetof(struct SYMLINK3res_wrapper , xdrgen) ==0 ); -static int nfs3_ftypes[] = { -0 ,/* NF3NON */ -S_IFREG ,/* NF3REG */ -S_IFDIR ,/* NF3DIR */ -S_IFBLK ,/* NF3BLK */ -S_IFCHR ,/* NF3CHR */ -S_IFLNK ,/* NF3LNK */ -S_IFSOCK ,/* NF3SOCK */ -S_IFIFO ,/* NF3FIFO */ +struct MKNOD3args_wrapper { +struct MKNOD3args xdrgen; +struct svc_fh fh; +struct iattr iattrs; }; +static_assert (offsetof(struct MKNOD3args_wrapper , xdrgen) ==0 ); + +struct MKNOD3res_wrapper { +struct MKNOD3res xdrgen; +struct svc_fh fh; +u8 fh_data[NFS3_FHSIZE ]; +}; + +static_assert (offsetof(struct MKNOD3res_wrapper , xdrgen) ==0 ); + +static int nfsd3_ftype3_to_mode (ftype3 ftype) +{ +switch (ftype) { +case NF3REG :return S_IFREG ; +case NF3DIR :return S_IFDIR ; +case NF3BLK :return S_IFBLK ; +case NF3CHR :return S_IFCHR ; +case NF3LNK :return S_IFLNK ; +case NF3SOCK :return S_IFSOCK ; +case NF3FIFO :return S_IFIFO ; +default : +return 0 ; + } +} +/* * Reject a client-supplied atime or mtime whose nanoseconds field is out * of range. Such a value is well-formed on the wire but is not a valid
@@ -1153,45 +1173,86 @@ static __be32 nfsd3_proc_symlink(struct svc_rqst *rqstp)return rpc_success; } -/* -* Make socket/fifo/device. +/** +* nfsd3_proc_mknod - MKNOD: Create a special file +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* MKNOD3res NFSPROC3_MKNOD(MKNOD3args) = 11; */ -static __be32 -nfsd3_proc_mknod (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_mknod (struct svc_rqst *rqstp) { -struct nfsd3_mknodargs *argp = rqstp->rq_argp; -struct nfsd3_diropres *resp = rqstp->rq_resp; -struct nfsd_attrs attrs = { - .na_iattr = &argp->attrs, +struct MKNOD3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *where = &argp->xdrgen.where; +struct mknoddata3 *what = &argp->xdrgen.what; +struct MKNOD3res_wrapper *resp = rqstp->rq_resp; +struct iattr *iattrs = &argp->iattrs; +struct svc_fh *dirfhp = &argp->fh; +struct svc_fh *fhp = &resp->fh; +struct nfsd_attrs nattrs = { + .na_iattr = iattrs, }; -int type; -dev_t rdev =0 ; +dev_t rdev =0 ; -fh_copy (&resp->dirfh, &argp->fh); -fh_init (&resp->fh,NFS3_FHSIZE ); - -if (argp->ftype ==NF3CHR || argp->ftype ==NF3BLK ) { - rdev =MKDEV (argp->major, argp->minor); -if (MAJOR (rdev) != argp->major || -MINOR (rdev) != argp->minor) { - resp->status = nfserr_inval; +nfsd3_fh3_to_svc_fh (dirfhp, &where->dir); + resp->xdrgen.status =nfsd3_check_filename (where->name.data, + where->name.len); +if (resp->xdrgen.status != nfs_ok) + goto out; +switch (what->type) { +case NF3CHR : +case NF3BLK : + rdev =MKDEV (what->u.device.spec.specdata1, + what->u.device.spec.specdata2); +if (MAJOR (rdev) != what->u.device.spec.specdata1 || +MINOR (rdev) != what->u.device.spec.specdata2) { + resp->xdrgen.status = nfserr_inval; goto out; } - }else if (argp->ftype !=NF3SOCK && argp->ftype !=NF3FIFO ) { - resp->status = nfserr_badtype; +nfsd3_sattr3_to_iattr (rqstp, iattrs, + &what->u.device.dev_attributes); +break ; +case NF3SOCK : +case NF3FIFO : +nfsd3_sattr3_to_iattr (rqstp, iattrs, + &what->u.pipe_attributes); +break ; +default : + resp->xdrgen.status = nfserr_badtype; goto out; } -if (!nfsd3_time_in_range (&argp->attrs)) { - resp->status = nfserr_inval; +if (!nfsd3_time_in_range (iattrs)) { + resp->xdrgen.status = nfserr_inval; goto out; } - type = nfs3_ftypes[argp->ftype]; - resp->status =nfsd_create (rqstp, &resp->dirfh, argp->name, argp->len, - &attrs, type, rdev, &resp->fh); +fh_init (fhp,NFS3_FHSIZE ); + resp->xdrgen.status =nfsd_create (rqstp, dirfhp, + (char *)where->name.data, + where->name.len, &nattrs, +nfsd3_ftype3_to_mode (what->type), + rdev, fhp); + out: - resp->status =nfsd3_map_status (resp->status); +if (resp->xdrgen.status == nfs_ok) { +struct MKNOD3resok *resok = &resp->xdrgen.u.resok; + +nfsd3_fill_post_op_fh3 (&resok->obj, fhp, resp->fh_data); +nfsd3_fill_post_op_attr (rqstp, &resok->obj_attributes, fhp); +nfsd3_fill_wcc_data (rqstp, &resok->dir_wcc, dirfhp); + }else { +struct MKNOD3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); +nfsd3_fill_wcc_data (rqstp, &resfail->dir_wcc, dirfhp); + } + +fh_put (fhp); +fh_put (dirfhp);return rpc_success; }
@@ -1514,7 +1575,6 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)#define nfsd3_wccstatres nfsd3_attrstat#define ST 1/* status*/ -#define FH 17/* filehandle with length */ #define AT 21/* attributes */ #define pAT (1+AT)/* post attributes - conditional */ #define WC (7+pAT)/* WCC attributes */
@@ -1645,16 +1705,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "SYMLINK", }, [NFSPROC3_MKNOD] = { - .pc_func = nfsd3_proc_mknod, - .pc_decode = nfs3svc_decode_mknodargs, - .pc_encode = nfs3svc_encode_createres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_mknodargs), - .pc_argzero = sizeof(struct nfsd3_mknodargs), - .pc_ressize = sizeof(struct nfsd3_diropres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+(1+FH+pAT)+WC, - .pc_name = "MKNOD", + .pc_func = nfsd3_proc_mknod, + .pc_decode = nfs_svc_decode_MKNOD3args, + .pc_encode = nfs_svc_encode_MKNOD3res, + .pc_argsize = sizeof(struct MKNOD3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct MKNOD3res_wrapper), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_MKNOD3res_sz, + .pc_name = "MKNOD", }, [NFSPROC3_REMOVE] = { .pc_func = nfsd3_proc_remove,
@@ -1795,10 +1854,11 @@ union nfsd3_xdrstore {struct MKDIR3res_wrapper mkdirres;struct SYMLINK3args_wrapper symlinkargs;struct SYMLINK3res_wrapper symlinkres; +struct MKNOD3args_wrapper mknodargs; +struct MKNOD3res_wrapper mknodres;struct nfsd3_renameargs renameargs;struct nfsd3_linkargs linkargs;struct nfsd3_readdirargs readdirargs; -struct nfsd3_diropres diropres;struct READLINK3res readlinkres;struct READ3res readres;struct nfsd3_writeres writeres;
fs/nfsd/nfs3xdr.c +0 -175
199 lines not on this page · raw message
fs/nfsd/xdr3.h +0 -18
@@ -30,15 +30,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_mknodargs { -struct svc_fh fh; -char * name; -unsigned int len; -__u32 ftype; -__u32 major, minor; -struct iattr attrs; -}; -struct nfsd3_renameargs {struct svc_fh ffh;char * fname;
@@ -87,13 +78,6 @@ struct nfsd3_attrstat {struct kstat stat; }; -/* LOOKUP, CREATE, MKDIR, SYMLINK, MKNOD */ -struct nfsd3_diropres { -__be32 status; -struct svc_fh dirfh; -struct svc_fh fh; -}; -struct nfsd3_accessres {__be32 status;struct svc_fh fh;
@@ -188,7 +172,6 @@ struct nfsd3_fhandle_pair {bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_mknodargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
@@ -197,7 +180,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_createres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 19/33 NFSD: Use xdrgen XDR functions for the NFSv3 REMOVE procedure
In reply to Chuck LeverReplace the NFSPROC3_REMOVE entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_REMOVE3args and nfs_svc_encode_REMOVE3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses; the result uses the generated REMOVE3res type directly.
Filename validity is now checked by nfsd3_proc_remove() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 REMOVE procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_remove() now assembles the WCC data, that work moves out of the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_remove(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
--- fs/nfsd/nfs3proc.c | 72 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-)
fs/nfsd/nfs3proc.c +51 -21
@@ -163,6 +163,13 @@ struct MKNOD3res_wrapper {static_assert (offsetof(struct MKNOD3res_wrapper , xdrgen) ==0 ); +struct REMOVE3args_wrapper { +struct REMOVE3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct REMOVE3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1256,20 +1263,42 @@ static __be32 nfsd3_proc_mknod(struct svc_rqst *rqstp)return rpc_success; } -/* -* Remove file/fifo/socket etc. +/** +* nfsd3_proc_remove - REMOVE: Remove a file +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* REMOVE3res NFSPROC3_REMOVE(REMOVE3args) = 12; */ -static __be32 -nfsd3_proc_remove (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_remove (struct svc_rqst *rqstp) { -struct nfsd3_diropargs *argp = rqstp->rq_argp; -struct nfsd3_attrstat *resp = rqstp->rq_resp; +struct REMOVE3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *object = &argp->xdrgen.object; +struct REMOVE3res *resp = rqstp->rq_resp; +struct svc_fh *fhp = &argp->fh; -/* Unlink. -S_IFDIR means file must not be a directory */ -fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_unlink (rqstp, &resp->fh, -S_IFDIR , - argp->name, argp->len); - resp->status =nfsd3_map_status (resp->status); +nfsd3_fh3_to_svc_fh (fhp, &object->dir); + resp->status =nfsd3_check_filename (object->name.data, + object->name.len); +if (resp->status != nfs_ok) + goto out; + + resp->status =nfsd_unlink (rqstp, fhp, -S_IFDIR , + (char *)object->name.data, + object->name.len); + +out: +if (resp->status == nfs_ok) { +nfsd3_fill_wcc_data (rqstp, &resp->u.resok.dir_wcc, fhp); + }else { + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_wcc_data (rqstp, &resp->u.resfail.dir_wcc, fhp); + } + +fh_put (fhp);return rpc_success; }
@@ -1716,16 +1745,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "MKNOD", }, [NFSPROC3_REMOVE] = { - .pc_func = nfsd3_proc_remove, - .pc_decode = nfs3svc_decode_diropargs, - .pc_encode = nfs3svc_encode_wccstatres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_diropargs), - .pc_argzero = sizeof(struct nfsd3_diropargs), - .pc_ressize = sizeof(struct nfsd3_wccstatres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+WC, - .pc_name = "REMOVE", + .pc_func = nfsd3_proc_remove, + .pc_decode = nfs_svc_decode_REMOVE3args, + .pc_encode = nfs_svc_encode_REMOVE3res, + .pc_argsize = sizeof(struct REMOVE3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct REMOVE3res), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_REMOVE3res_sz, + .pc_name = "REMOVE", }, [NFSPROC3_RMDIR] = { .pc_func = nfsd3_proc_rmdir,
@@ -1856,6 +1884,8 @@ union nfsd3_xdrstore {struct SYMLINK3res_wrapper symlinkres;struct MKNOD3args_wrapper mknodargs;struct MKNOD3res_wrapper mknodres; +struct REMOVE3args_wrapper removeargs; +struct REMOVE3res removeres;struct nfsd3_renameargs renameargs;struct nfsd3_linkargs linkargs;struct nfsd3_readdirargs readdirargs;
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 20/33 NFSD: Use xdrgen XDR functions for the NFSv3 RMDIR procedure
In reply to Chuck LeverReplace the NFSPROC3_RMDIR entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_RMDIR3args and nfs_svc_encode_RMDIR3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses; the result uses the generated RMDIR3res type directly.
Filename validity is now checked by nfsd3_proc_rmdir() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 RMDIR procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_rmdir() now assembles the WCC data, that work moves out of the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_rmdir(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_diropargs() and nfs3svc_encode_wccstat() no longer have any callers, so they are removed.
--- fs/nfsd/nfs3proc.c | 74 ++++++++++++++++++++++++++++++++-------------- fs/nfsd/nfs3xdr.c | 18 ----------- fs/nfsd/xdr3.h | 8 ----- 3 files changed, 51 insertions(+), 49 deletions(-)
fs/nfsd/nfs3proc.c +51 -23
@@ -170,6 +170,13 @@ struct REMOVE3args_wrapper {static_assert (offsetof(struct REMOVE3args_wrapper , xdrgen) ==0 ); +struct RMDIR3args_wrapper { +struct RMDIR3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct RMDIR3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1302,19 +1309,42 @@ static __be32 nfsd3_proc_remove(struct svc_rqst *rqstp)return rpc_success; } -/* -* Remove a directory +/** +* nfsd3_proc_rmdir - RMDIR: Remove a directory +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* RMDIR3res NFSPROC3_RMDIR(RMDIR3args) = 13; */ -static __be32 -nfsd3_proc_rmdir (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_rmdir (struct svc_rqst *rqstp) { -struct nfsd3_diropargs *argp = rqstp->rq_argp; -struct nfsd3_attrstat *resp = rqstp->rq_resp; +struct RMDIR3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *object = &argp->xdrgen.object; +struct RMDIR3res *resp = rqstp->rq_resp; +struct svc_fh *fhp = &argp->fh; -fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_unlink (rqstp, &resp->fh,S_IFDIR , - argp->name, argp->len); - resp->status =nfsd3_map_status (resp->status); +nfsd3_fh3_to_svc_fh (fhp, &object->dir); + resp->status =nfsd3_check_filename (object->name.data, + object->name.len); +if (resp->status != nfs_ok) + goto out; + + resp->status =nfsd_unlink (rqstp, fhp,S_IFDIR , + (char *)object->name.data, + object->name.len); + +out: +if (resp->status == nfs_ok) { +nfsd3_fill_wcc_data (rqstp, &resp->u.resok.dir_wcc, fhp); + }else { + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_wcc_data (rqstp, &resp->u.resfail.dir_wcc, fhp); + } + +fh_put (fhp);return rpc_success; }
@@ -1598,10 +1628,8 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)* NFSv3 Server procedures. * Only the results of non-idempotent operations are cached. */ -#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat#define nfsd3_readdirplusargs nfsd3_readdirargs#define nfsd3_fhandleargs nfsd_fhandle -#define nfsd3_wccstatres nfsd3_attrstat#define ST 1/* status*/ #define AT 21/* attributes */
@@ -1756,16 +1784,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "REMOVE", }, [NFSPROC3_RMDIR] = { - .pc_func = nfsd3_proc_rmdir, - .pc_decode = nfs3svc_decode_diropargs, - .pc_encode = nfs3svc_encode_wccstatres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_diropargs), - .pc_argzero = sizeof(struct nfsd3_diropargs), - .pc_ressize = sizeof(struct nfsd3_wccstatres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+WC, - .pc_name = "RMDIR", + .pc_func = nfsd3_proc_rmdir, + .pc_decode = nfs_svc_decode_RMDIR3args, + .pc_encode = nfs_svc_encode_RMDIR3res, + .pc_argsize = sizeof(struct RMDIR3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct RMDIR3res), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_RMDIR3res_sz, + .pc_name = "RMDIR", }, [NFSPROC3_RENAME] = { .pc_func = nfsd3_proc_rename,
@@ -1874,7 +1901,6 @@ union nfsd3_xdrstore {struct ACCESS3res accessres;struct READLINK3args_wrapper readlinkargs;struct READ3args_wrapper readargs; -struct nfsd3_diropargs diropargs;struct WRITE3args_wrapper writeargs;struct CREATE3args_wrapper createargs;struct CREATE3res_wrapper createres;
@@ -1886,6 +1912,8 @@ union nfsd3_xdrstore {struct MKNOD3res_wrapper mknodres;struct REMOVE3args_wrapper removeargs;struct REMOVE3res removeres; +struct RMDIR3args_wrapper rmdirargs; +struct RMDIR3res rmdirres;struct nfsd3_renameargs renameargs;struct nfsd3_linkargs linkargs;struct nfsd3_readdirargs readdirargs;
fs/nfsd/nfs3xdr.c +0 -18
@@ -360,14 +360,6 @@ nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_nfs_fh3 (xdr, &args->fh); } -bool -nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_diropargs *args = rqstp->rq_argp; - -return svcxdr_decode_diropargs3 (xdr, &args->fh, &args->name, &args->len); -} -bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
@@ -448,16 +440,6 @@ nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)* XDR encode functions */ -/* SETATTR, REMOVE, RMDIR */ -bool -nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_attrstat *resp = rqstp->rq_resp; - -return svcxdr_encode_nfsstat3 (xdr, resp->status) && -svcxdr_encode_wcc_data (rqstp, xdr, &resp->fh); -} -/* RENAME */ bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/xdr3.h +0 -8
@@ -19,12 +19,6 @@#define NFS3_MAXNAMLEN NAME_MAX#define NFS3_MAXPATHLEN PATH_MAX -struct nfsd3_diropargs { -struct svc_fh fh; -char * name; -unsigned int len; -}; -struct nfsd3_accessargs {struct svc_fh fh;__u32 access;
@@ -171,14 +165,12 @@ struct nfsd3_fhandle_pair { };bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_diropargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_wccstat (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 21/33 NFSD: Use xdrgen XDR functions for the NFSv3 RENAME procedure
In reply to Chuck LeverReplace the NFSPROC3_RENAME entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_RENAME3args and nfs_svc_encode_RENAME3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses; the result uses the generated RENAME3res type directly.
Filename validity is now checked by nfsd3_proc_rename() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 RENAME procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_rename() now assembles the WCC data, that work moves out of the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_rename(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_renameargs() and nfs3svc_encode_renameres() no longer have any callers, so they are removed.
--- fs/nfsd/nfs3proc.c | 89 +++++++++++++++++++++++++++++++++++----------- fs/nfsd/nfs3xdr.c | 22 ------------ fs/nfsd/xdr3.h | 17 --------- 3 files changed, 68 insertions(+), 60 deletions(-)
fs/nfsd/nfs3proc.c +68 -21
@@ -177,6 +177,14 @@ struct RMDIR3args_wrapper {static_assert (offsetof(struct RMDIR3args_wrapper , xdrgen) ==0 ); +struct RENAME3args_wrapper { +struct RENAME3args xdrgen; +struct svc_fh ffh; +struct svc_fh tfh; +}; + +static_assert (offsetof(struct RENAME3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1348,17 +1356,57 @@ static __be32 nfsd3_proc_rmdir(struct svc_rqst *rqstp)return rpc_success; } -static __be32 -nfsd3_proc_rename (struct svc_rqst *rqstp) +/** +* nfsd3_proc_rename - RENAME: Rename a file or directory +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* RENAME3res NFSPROC3_RENAME(RENAME3args) = 14; +*/ +static __be32 nfsd3_proc_rename (struct svc_rqst *rqstp) { -struct nfsd3_renameargs *argp = rqstp->rq_argp; -struct nfsd3_renameres *resp = rqstp->rq_resp; +struct RENAME3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *from = &argp->xdrgen.from; +struct diropargs3 *to = &argp->xdrgen.to; +struct RENAME3res *resp = rqstp->rq_resp; +struct svc_fh *ffhp = &argp->ffh; +struct svc_fh *tfhp = &argp->tfh; -fh_copy (&resp->ffh, &argp->ffh); -fh_copy (&resp->tfh, &argp->tfh); - resp->status =nfsd_rename (rqstp, &resp->ffh, argp->fname, argp->flen, - &resp->tfh, argp->tname, argp->tlen); - resp->status =nfsd3_map_status (resp->status); +nfsd3_fh3_to_svc_fh (ffhp, &from->dir); +nfsd3_fh3_to_svc_fh (tfhp, &to->dir); + resp->status =nfsd3_check_filename (from->name.data, + from->name.len); +if (resp->status != nfs_ok) + goto out; + resp->status =nfsd3_check_filename (to->name.data, + to->name.len); +if (resp->status != nfs_ok) + goto out; + + resp->status =nfsd_rename (rqstp, ffhp, (char *)from->name.data, + from->name.len, tfhp, + (char *)to->name.data, + to->name.len); + +out: +if (resp->status == nfs_ok) { +struct RENAME3resok *resok = &resp->u.resok; + +nfsd3_fill_wcc_data (rqstp, &resok->fromdir_wcc, ffhp); +nfsd3_fill_wcc_data (rqstp, &resok->todir_wcc, tfhp); + }else { +struct RENAME3resfail *resfail = &resp->u.resfail; + + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_wcc_data (rqstp, &resfail->fromdir_wcc, ffhp); +nfsd3_fill_wcc_data (rqstp, &resfail->todir_wcc, tfhp); + } + +fh_put (ffhp); +fh_put (tfhp);return rpc_success; }
@@ -1795,16 +1843,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "RMDIR", }, [NFSPROC3_RENAME] = { - .pc_func = nfsd3_proc_rename, - .pc_decode = nfs3svc_decode_renameargs, - .pc_encode = nfs3svc_encode_renameres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_renameargs), - .pc_argzero = sizeof(struct nfsd3_renameargs), - .pc_ressize = sizeof(struct nfsd3_renameres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+WC+WC, - .pc_name = "RENAME", + .pc_func = nfsd3_proc_rename, + .pc_decode = nfs_svc_decode_RENAME3args, + .pc_encode = nfs_svc_encode_RENAME3res, + .pc_argsize = sizeof(struct RENAME3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct RENAME3res), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_RENAME3res_sz, + .pc_name = "RENAME", }, [NFSPROC3_LINK] = { .pc_func = nfsd3_proc_link,
@@ -1914,13 +1961,13 @@ union nfsd3_xdrstore {struct REMOVE3res removeres;struct RMDIR3args_wrapper rmdirargs;struct RMDIR3res rmdirres; -struct nfsd3_renameargs renameargs; +struct RENAME3args_wrapper renameargs; +struct RENAME3res renameres;struct nfsd3_linkargs linkargs;struct nfsd3_readdirargs readdirargs;struct READLINK3res readlinkres;struct READ3res readres;struct nfsd3_writeres writeres; -struct nfsd3_renameres renameres;struct nfsd3_linkres linkres;struct nfsd3_readdirres readdirres;struct nfsd3_fsstatres fsstatres;
fs/nfsd/nfs3xdr.c +0 -22
@@ -360,17 +360,6 @@ nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)return svcxdr_decode_nfs_fh3 (xdr, &args->fh); } -bool -nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_renameargs *args = rqstp->rq_argp; - -return svcxdr_decode_diropargs3 (xdr, &args->ffh, - &args->fname, &args->flen) && -svcxdr_decode_diropargs3 (xdr, &args->tfh, - &args->tname, &args->tlen); -} -bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
@@ -440,17 +429,6 @@ nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)* XDR encode functions */ -/* RENAME */ -bool -nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_renameres *resp = rqstp->rq_resp; - -return svcxdr_encode_nfsstat3 (xdr, resp->status) && -svcxdr_encode_wcc_data (rqstp, xdr, &resp->ffh) && -svcxdr_encode_wcc_data (rqstp, xdr, &resp->tfh); -} -/* LINK */ bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr)
fs/nfsd/xdr3.h +0 -17
@@ -24,15 +24,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_renameargs { -struct svc_fh ffh; -char * fname; -unsigned int flen; -struct svc_fh tfh; -char * tname; -unsigned int tlen; -}; -struct nfsd3_linkargs {struct svc_fh ffh;struct svc_fh tfh;
@@ -85,12 +76,6 @@ struct nfsd3_writeres {static_assert (offsetof(struct nfsd3_writeres , xdrgen) ==0 ); -struct nfsd3_renameres { -__be32 status; -struct svc_fh ffh; -struct svc_fh tfh; -}; -struct nfsd3_linkres {__be32 status;struct svc_fh tfh;
@@ -165,14 +150,12 @@ struct nfsd3_fhandle_pair { };bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_renameargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_renameres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_fsstatres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 22/33 NFSD: Use xdrgen XDR functions for the NFSv3 LINK procedure
In reply to Chuck LeverReplace the NFSPROC3_LINK entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_LINK3args and nfs_svc_encode_LINK3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses; the result uses the generated LINK3res type directly.
Filename validity is now checked by nfsd3_proc_link() so that a proper NFS3ERR status code can be returned to the client rather than GARBAGE_ARGS.
The pc_argzero field is now set to zero for the NFSv3 LINK procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_link() now fills in the post-op attributes and assembles the WCC data, that work moves out of the XDR result encoder, and the references to the file handles can be released directly by nfsd3_proc_link(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handles are properly released during every error flow.
nfs3svc_decode_linkargs(), nfs3svc_encode_linkres(), and nfs3svc_release_fhandle2() no longer have any callers, so they are removed, and with them the now-orphaned svcxdr_decode_filename3() and svcxdr_decode_diropargs3() decode helpers and the struct nfsd3_fhandle_pair release type.
--- fs/nfsd/nfs3proc.c | 82 ++++++++++++++++++++++++++++++++++------------ fs/nfsd/nfs3xdr.c | 63 ----------------------------------- fs/nfsd/xdr3.h | 23 ------------- 3 files changed, 61 insertions(+), 107 deletions(-)
fs/nfsd/nfs3proc.c +61 -21
@@ -185,6 +185,14 @@ struct RENAME3args_wrapper {static_assert (offsetof(struct RENAME3args_wrapper , xdrgen) ==0 ); +struct LINK3args_wrapper { +struct LINK3args xdrgen; +struct svc_fh ffh; +struct svc_fh tfh; +}; + +static_assert (offsetof(struct LINK3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1410,17 +1418,50 @@ static __be32 nfsd3_proc_rename(struct svc_rqst *rqstp)return rpc_success; } -static __be32 -nfsd3_proc_link (struct svc_rqst *rqstp) +/** +* nfsd3_proc_link - LINK: Create Link to an object +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* LINK3res NFSPROC3_LINK(LINK3args) = 15; +*/ +static __be32 nfsd3_proc_link (struct svc_rqst *rqstp) { -struct nfsd3_linkargs *argp = rqstp->rq_argp; -struct nfsd3_linkres *resp = rqstp->rq_resp; +struct LINK3args_wrapper *argp = rqstp->rq_argp; +struct diropargs3 *link = &argp->xdrgen.link; +struct LINK3res *resp = rqstp->rq_resp; +struct svc_fh *ffhp = &argp->ffh; +struct svc_fh *tfhp = &argp->tfh; -fh_copy (&resp->fh, &argp->ffh); -fh_copy (&resp->tfh, &argp->tfh); - resp->status =nfsd_link (rqstp, &resp->tfh, argp->tname, argp->tlen, - &resp->fh); - resp->status =nfsd3_map_status (resp->status); +nfsd3_fh3_to_svc_fh (ffhp, &argp->xdrgen.file); +nfsd3_fh3_to_svc_fh (tfhp, &link->dir); + resp->status =nfsd3_check_filename (link->name.data, + link->name.len); +if (resp->status != nfs_ok) + goto out; + + resp->status =nfsd_link (rqstp, tfhp, (char *)link->name.data, + link->name.len, ffhp); + +out: +if (resp->status == nfs_ok) { +struct LINK3resok *resok = &resp->u.resok; + +nfsd3_fill_post_op_attr (rqstp, &resok->file_attributes, ffhp); +nfsd3_fill_wcc_data (rqstp, &resok->linkdir_wcc, tfhp); + }else { +struct LINK3resfail *resfail = &resp->u.resfail; + + resp->status =nfsd3_map_status (resp->status); +nfsd3_fill_post_op_attr (rqstp, &resfail->file_attributes, ffhp); +nfsd3_fill_wcc_data (rqstp, &resfail->linkdir_wcc, tfhp); + } + +fh_put (ffhp); +fh_put (tfhp);return rpc_success; }
@@ -1854,16 +1895,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "RENAME", }, [NFSPROC3_LINK] = { - .pc_func = nfsd3_proc_link, - .pc_decode = nfs3svc_decode_linkargs, - .pc_encode = nfs3svc_encode_linkres, - .pc_release = nfs3svc_release_fhandle2, - .pc_argsize = sizeof(struct nfsd3_linkargs), - .pc_argzero = sizeof(struct nfsd3_linkargs), - .pc_ressize = sizeof(struct nfsd3_linkres), - .pc_cachetype = RC_REPLBUFF, - .pc_xdrressize = ST+pAT+WC, - .pc_name = "LINK", + .pc_func = nfsd3_proc_link, + .pc_decode = nfs_svc_decode_LINK3args, + .pc_encode = nfs_svc_encode_LINK3res, + .pc_argsize = sizeof(struct LINK3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct LINK3res), + .pc_cachetype = RC_REPLBUFF, + .pc_xdrressize = NFS3_LINK3res_sz, + .pc_name = "LINK", }, [NFSPROC3_READDIR] = { .pc_func = nfsd3_proc_readdir,
@@ -1963,12 +2003,12 @@ union nfsd3_xdrstore {struct RMDIR3res rmdirres;struct RENAME3args_wrapper renameargs;struct RENAME3res renameres; -struct nfsd3_linkargs linkargs; +struct LINK3args_wrapper linkargs; +struct LINK3res linkres;struct nfsd3_readdirargs readdirargs;struct READLINK3res readlinkres;struct READ3res readres;struct nfsd3_writeres writeres; -struct nfsd3_linkres linkres;struct nfsd3_readdirres readdirres;struct nfsd3_fsstatres fsstatres;struct nfsd3_fsinfores fsinfores;
fs/nfsd/nfs3xdr.c +0 -63
84 lines not on this page · raw message
fs/nfsd/xdr3.h +0 -23
@@ -24,13 +24,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_linkargs { -struct svc_fh ffh; -struct svc_fh tfh; -char * tname; -unsigned int tlen; -}; -struct nfsd3_readdirargs {struct svc_fh fh;__u64 cookie;
@@ -76,12 +69,6 @@ struct nfsd3_writeres {static_assert (offsetof(struct nfsd3_writeres , xdrgen) ==0 ); -struct nfsd3_linkres { -__be32 status; -struct svc_fh tfh; -struct svc_fh fh; -}; -struct nfsd3_readdirres {/* Components of the reply */ __be32 status;
@@ -142,21 +129,12 @@ struct nfsd3_getaclres {struct kstat stat; }; -/* dummy type for release */ -struct nfsd3_fhandle_pair { -__u32 dummy; -struct svc_fh fh1; -struct svc_fh fh2; -}; -bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_linkargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_linkres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_fsstatres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_fsinfores (struct svc_rqst *rqstp,struct xdr_stream *xdr);
@@ -164,7 +142,6 @@ bool nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nfs3svc_encode_commitres (struct svc_rqst *rqstp,struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *); -void nfs3svc_release_fhandle2 (struct svc_rqst *);void nfs3svc_encode_cookie3 (struct nfsd3_readdirres *resp,u64 offset); int nfs3svc_encode_entry3(void *data, const char *name, int namlen,
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 23/33 NFSD: Use xdrgen XDR functions for the NFSv3 FSSTAT procedure
In reply to Chuck LeverReplace the NFSPROC3_FSSTAT entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_FSSTAT3args and nfs_svc_encode_FSSTAT3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses. The result wrapper carries a scratch kstatfs alongside the generated FSSTAT3res type, which nfsd_statfs() fills before nfsd3_proc_fsstat() copies the values into the encoded result.
The pc_argzero field is now set to zero for the NFSv3 FSSTAT procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfsd3_proc_fsstat() now sets the post-op attributes directly. This makes it straightforward to confirm that the file handle is released during every error flow.
nfs3svc_encode_fsstatres() no longer has any callers, so it is removed, and with it the now-orphaned svcxdr_encode_fsstat3resok() encode helper.
--- fs/nfsd/nfs3proc.c | 71 +++++++++++++++++++++++++++++++++++----------- fs/nfsd/nfs3xdr.c | 45 ----------------------------- fs/nfsd/xdr3.h | 6 ++-- 3 files changed, 57 insertions(+), 65 deletions(-)
fs/nfsd/nfs3proc.c +54 -17
@@ -193,6 +193,13 @@ struct LINK3args_wrapper {static_assert (offsetof(struct LINK3args_wrapper , xdrgen) ==0 ); +struct FSSTAT3args_wrapper { +struct FSSTAT3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct FSSTAT3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1559,18 +1566,47 @@ nfsd3_proc_readdirplus(struct svc_rqst *rqstp)return rpc_success; } -/* -* Get file system stats +/** +* nfsd3_proc_fsstat - FSSTAT: Get dynamic file system information +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* FSSTAT3res NFSPROC3_FSSTAT(FSSTAT3args) = 18; */ -static __be32 -nfsd3_proc_fsstat (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_fsstat (struct svc_rqst *rqstp) { -struct nfsd_fhandle *argp = rqstp->rq_argp; +struct FSSTAT3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_fsstatres *resp = rqstp->rq_resp; +struct kstatfs *statp = &resp->stats; +struct svc_fh *fhp = &argp->fh; - resp->status =nfsd_statfs (rqstp, &argp->fh, &resp->stats,0 ); -fh_put (&argp->fh); - resp->status =nfsd3_map_status (resp->status); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.fsroot); + + resp->xdrgen.status =nfsd_statfs (rqstp, fhp, statp,0 ); + +if (resp->xdrgen.status == nfs_ok) { +struct FSSTAT3resok *resok = &resp->xdrgen.u.resok; +u64 bs = statp->f_bsize; + + resok->obj_attributes.attributes_follow = false; + resok->tbytes = bs * statp->f_blocks; + resok->fbytes = bs * statp->f_bfree; + resok->abytes = bs * statp->f_bavail; + resok->tfiles = statp->f_files; + resok->ffiles = statp->f_ffree; + resok->afiles = statp->f_ffree; + resok->invarsec =0 ; + }else { +struct FSSTAT3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); + resfail->obj_attributes.attributes_follow = false; + } + +fh_put (fhp);return rpc_success; }
@@ -1928,15 +1964,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "READDIRPLUS", }, [NFSPROC3_FSSTAT] = { - .pc_func = nfsd3_proc_fsstat, - .pc_decode = nfs3svc_decode_fhandleargs, - .pc_encode = nfs3svc_encode_fsstatres, - .pc_argsize = sizeof(struct nfsd3_fhandleargs), - .pc_argzero = sizeof(struct nfsd3_fhandleargs), - .pc_ressize = sizeof(struct nfsd3_fsstatres), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+pAT+2*6+1, - .pc_name = "FSSTAT", + .pc_func = nfsd3_proc_fsstat, + .pc_decode = nfs_svc_decode_FSSTAT3args, + .pc_encode = nfs_svc_encode_FSSTAT3res, + .pc_argsize = sizeof(struct FSSTAT3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_fsstatres), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_FSSTAT3res_sz, + .pc_name = "FSSTAT", }, [NFSPROC3_FSINFO] = { .pc_func = nfsd3_proc_fsinfo,
@@ -2010,6 +2046,7 @@ union nfsd3_xdrstore {struct READ3res readres;struct nfsd3_writeres writeres;struct nfsd3_readdirres readdirres; +struct FSSTAT3args_wrapper fsstatargs;struct nfsd3_fsstatres fsstatres;struct nfsd3_fsinfores fsinfores;struct nfsd3_pathconfres pathconfres;
fs/nfsd/nfs3xdr.c +0 -45
51 lines not on this page · raw message
fs/nfsd/xdr3.h +3 -3
@@ -86,11 +86,12 @@ struct nfsd3_readdirres { };struct nfsd3_fsstatres { -__be32 status; +struct FSSTAT3res xdrgen;struct kstatfs stats; -__u32 invarsec; }; +static_assert (offsetof(struct nfsd3_fsstatres , xdrgen) ==0 ); +struct nfsd3_fsinfores {__be32 status;__u32 f_rtmax;
@@ -136,7 +137,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);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_fsstatres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_fsinfores (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_pathconfres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_commitres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 24/33 NFSD: Use xdrgen XDR functions for the NFSv3 FSINFO procedure
In reply to Chuck LeverReplace the NFSPROC3_FSINFO entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_FSINFO3args and nfs_svc_encode_FSINFO3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 FSINFO procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfsd3_proc_fsinfo() now sets the post-op attributes directly. This makes it straightforward to confirm that the file handle is released during every error flow.
nfs3svc_encode_fsinfores() no longer has any callers, so it is removed, and with it the now-orphaned svcxdr_encode_fsinfo3resok() encode helper and the nfs3svc_time_delta constant it referenced.
--- fs/nfsd/nfs3proc.c | 107 +++++++++++++++++++++++++++------------------ fs/nfsd/nfs3xdr.c | 55 ----------------------- fs/nfsd/xdr3.h | 14 ++---- 3 files changed, 67 insertions(+), 109 deletions(-)
fs/nfsd/nfs3proc.c +64 -43
@@ -24,9 +24,6 @@#define NFSDDBG_FACILITY NFSDDBG_PROC -#define NFS3_FSF_DEFAULT 0x001b -#define NFS3_FSF_BILLYBOY 0x0018 -/* * Wrapper structures combine xdrgen types with legacy structures. * The xdrgen field must be first so the structure can be cast
@@ -200,6 +197,13 @@ struct FSSTAT3args_wrapper {static_assert (offsetof(struct FSSTAT3args_wrapper , xdrgen) ==0 ); +struct FSINFO3args_wrapper { +struct FSINFO3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct FSINFO3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1610,47 +1614,63 @@ static __be32 nfsd3_proc_fsstat(struct svc_rqst *rqstp)return rpc_success; } -/* -* Get file system info +/** +* nfsd3_proc_fsinfo - FSINFO: Get static file system information +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* FSINFO3res NFSPROC3_FSINFO(FSINFO3args) = 19; */ -static __be32 -nfsd3_proc_fsinfo (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_fsinfo (struct svc_rqst *rqstp) { -struct nfsd_fhandle *argp = rqstp->rq_argp; +struct FSINFO3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_fsinfores *resp = rqstp->rq_resp; -u32 max_blocksize =svc_max_payload (rqstp); +struct svc_fh *fhp = &argp->fh; -dprintk ("nfsd: FSINFO(3) %s\n" , -SVCFH_fmt (&argp->fh)); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.fsroot); - resp->f_rtmax = max_blocksize; - resp->f_rtpref = max_blocksize; - resp->f_rtmult =PAGE_SIZE ; - resp->f_wtmax = max_blocksize; - resp->f_wtpref = max_blocksize; - resp->f_wtmult =PAGE_SIZE ; - resp->f_dtpref = max_blocksize; - resp->f_maxfilesize = ~(u32 )0 ; - resp->f_properties =NFS3_FSF_DEFAULT ; + resp->xdrgen.status =fh_verify (rqstp, fhp,0 ,NFSD_MAY_NOP | +NFSD_MAY_BYPASS_GSS_ON_ROOT ); - resp->status =fh_verify (rqstp, &argp->fh,0 , -NFSD_MAY_NOP |NFSD_MAY_BYPASS_GSS_ON_ROOT ); +if (resp->xdrgen.status == nfs_ok) { +struct FSINFO3resok *resok = &resp->xdrgen.u.resok; +struct super_block *sb = fhp->fh_dentry->d_sb; +u32 max_blocksize =svc_max_payload (rqstp); -/* Check special features of the file system. May request -* different read/write sizes for file systems known to have -* problems with large blocks */ -if (resp->status == nfs_ok) { -struct super_block *sb = argp->fh.fh_dentry->d_sb; + resok->obj_attributes.attributes_follow = false; + resok->rtmax = max_blocksize; + resok->rtpref = max_blocksize; + resok->rtmult =PAGE_SIZE ; + resok->wtmax = max_blocksize; + resok->wtpref = max_blocksize; + resok->wtmult =PAGE_SIZE ; + resok->dtpref = max_blocksize; + resok->maxfilesize = ~(u32 )0 ; +/* NFSD is accurate to the nearest second. */ + resok->time_delta.seconds =1 ; + resok->time_delta.nseconds =0 ; + resok->properties =FSF3_LINK |FSF3_SYMLINK | +FSF3_HOMOGENEOUS |FSF3_CANSETTIME ; -/* Note that we don't care for remote fs's here */ -if (sb->s_magic ==MSDOS_SUPER_MAGIC ) { - resp->f_properties =NFS3_FSF_BILLYBOY ; - } - resp->f_maxfilesize = sb->s_maxbytes; +/* +* Check special features of the file system. May +* request different read/write sizes for file systems +* known to have problems with large blocks. +*/ +if (sb->s_magic ==MSDOS_SUPER_MAGIC ) + resok->properties =FSF3_HOMOGENEOUS |FSF3_CANSETTIME ; + resok->maxfilesize = sb->s_maxbytes; + }else { +struct FSINFO3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); + resfail->obj_attributes.attributes_follow = false; } -fh_put (&argp->fh); - resp->status =nfsd3_map_status (resp->status); +fh_put (fhp);return rpc_success; }
@@ -1975,15 +1995,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "FSSTAT", }, [NFSPROC3_FSINFO] = { - .pc_func = nfsd3_proc_fsinfo, - .pc_decode = nfs3svc_decode_fhandleargs, - .pc_encode = nfs3svc_encode_fsinfores, - .pc_argsize = sizeof(struct nfsd3_fhandleargs), - .pc_argzero = sizeof(struct nfsd3_fhandleargs), - .pc_ressize = sizeof(struct nfsd3_fsinfores), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+pAT+12, - .pc_name = "FSINFO", + .pc_func = nfsd3_proc_fsinfo, + .pc_decode = nfs_svc_decode_FSINFO3args, + .pc_encode = nfs_svc_encode_FSINFO3res, + .pc_argsize = sizeof(struct FSINFO3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_fsinfores), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_FSINFO3res_sz, + .pc_name = "FSINFO", }, [NFSPROC3_PATHCONF] = { .pc_func = nfsd3_proc_pathconf,
@@ -2048,6 +2068,7 @@ union nfsd3_xdrstore {struct nfsd3_readdirres readdirres;struct FSSTAT3args_wrapper fsstatargs;struct nfsd3_fsstatres fsstatres; +struct FSINFO3args_wrapper fsinfoargs;struct nfsd3_fsinfores fsinfores;struct nfsd3_pathconfres pathconfres;struct nfsd3_commitres commitres;
fs/nfsd/nfs3xdr.c +0 -55
67 lines not on this page · raw message
fs/nfsd/xdr3.h +3 -11
@@ -93,18 +93,11 @@ struct nfsd3_fsstatres {static_assert (offsetof(struct nfsd3_fsstatres , xdrgen) ==0 );struct nfsd3_fsinfores { -__be32 status; -__u32 f_rtmax; -__u32 f_rtpref; -__u32 f_rtmult; -__u32 f_wtmax; -__u32 f_wtpref; -__u32 f_wtmult; -__u32 f_dtpref; -__u64 f_maxfilesize; -__u32 f_properties; +struct FSINFO3res xdrgen; }; +static_assert (offsetof(struct nfsd3_fsinfores , xdrgen) ==0 ); +struct nfsd3_pathconfres {__be32 status;__u32 p_link_max;
@@ -137,7 +130,6 @@ bool nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);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_fsinfores (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_pathconfres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_commitres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 25/33 NFSD: Use xdrgen XDR functions for the NFSv3 PATHCONF procedure
In reply to Chuck LeverReplace the NFSPROC3_PATHCONF entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_PATHCONF3args and nfs_svc_encode_PATHCONF3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 PATHCONF procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfsd3_proc_pathconf() now sets the post-op attributes directly. This makes it straightforward to confirm that the file handle is released during every error flow.
nfs3svc_encode_pathconfres() no longer has any callers, so it is removed, and with it the now-orphaned svcxdr_encode_pathconf3resok() encode helper and the nfs3svc_null_fh constant it referenced. This was also the last user of the shared nfs3svc_decode_fhandleargs() decoder, so that too is removed.
--- fs/nfsd/nfs3proc.c | 94 +++++++++++++++++++++++++++------------------- fs/nfsd/nfs3xdr.c | 57 ---------------------------- fs/nfsd/xdr3.h | 12 ++---- 3 files changed, 59 insertions(+), 104 deletions(-)
fs/nfsd/nfs3proc.c +56 -38
@@ -204,6 +204,13 @@ struct FSINFO3args_wrapper {static_assert (offsetof(struct FSINFO3args_wrapper , xdrgen) ==0 ); +struct PATHCONF3args_wrapper { +struct PATHCONF3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct PATHCONF3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1674,40 +1681,47 @@ static __be32 nfsd3_proc_fsinfo(struct svc_rqst *rqstp)return rpc_success; } -/* -* Get pathconf info for the specified file +/** +* nfsd3_proc_pathconf - PATHCONF: Retrieve POSIX information +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* PATHCONF3res NFSPROC3_PATHCONF(PATHCONF3args) = 20; */ -static __be32 -nfsd3_proc_pathconf (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_pathconf (struct svc_rqst *rqstp) { -struct nfsd_fhandle *argp = rqstp->rq_argp; +struct PATHCONF3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_pathconfres *resp = rqstp->rq_resp; +struct svc_fh *fhp = &argp->fh; -dprintk ("nfsd: PATHCONF(3) %s\n" , -SVCFH_fmt (&argp->fh)); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.object); -/* Set default pathconf */ - resp->p_link_max =255 ;/* at least */ - resp->p_name_max =255 ;/* at least */ - resp->p_no_trunc =0 ; - resp->p_chown_restricted =1 ; - resp->p_case_insensitive = false; - resp->p_case_preserving = true; + resp->xdrgen.status =fh_verify (rqstp, fhp,0 ,NFSD_MAY_NOP ); - resp->status =fh_verify (rqstp, &argp->fh,0 ,NFSD_MAY_NOP ); - -if (resp->status == nfs_ok) { -struct super_block *sb = argp->fh.fh_dentry->d_sb; +if (resp->xdrgen.status == nfs_ok) { +struct PATHCONF3resok *resok = &resp->xdrgen.u.resok; +struct super_block *sb = fhp->fh_dentry->d_sb;int err; + resok->obj_attributes.attributes_follow = false; + resok->linkmax =255 ; + resok->name_max =NAME_MAX ; + resok->no_trunc = false; + resok->chown_restricted = true; + resok->case_insensitive = false; + resok->case_preserving = true; +if (sb->s_magic ==EXT2_SUPER_MAGIC ) { - resp->p_link_max =EXT2_LINK_MAX ; - resp->p_name_max =EXT2_NAME_LEN ; + resok->linkmax =EXT2_LINK_MAX ; + resok->name_max =EXT2_NAME_LEN ; } - err =nfsd_get_case_info (argp->fh.fh_dentry, - &resp->p_case_insensitive, - &resp->p_case_preserving); + err =nfsd_get_case_info (fhp->fh_dentry, + &resok->case_insensitive, + &resok->case_preserving);/* * RFC 1813 lists NFS3ERR_STALE, NFS3ERR_BADHANDLE, and * NFS3ERR_SERVERFAULT as the only PATHCONF errors.
@@ -1724,19 +1738,23 @@ nfsd3_proc_pathconf(struct svc_rqst *rqstp)* handle is unusable without implying a server * malfunction. */ - resp->status = nfserr_stale; + resp->xdrgen.status = nfserr_stale;break ;case -ESTALE : - resp->status = nfserr_stale; + resp->xdrgen.status = nfserr_stale;break ;default : - resp->status = nfserr_serverfault; + resp->xdrgen.status = nfserr_serverfault;break ; } + }else { +struct PATHCONF3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); + resfail->obj_attributes.attributes_follow = false; } -fh_put (&argp->fh); - resp->status =nfsd3_map_status (resp->status); +fh_put (fhp);return rpc_success; }
@@ -1774,7 +1792,6 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)* Only the results of non-idempotent operations are cached. */ #define nfsd3_readdirplusargs nfsd3_readdirargs -#define nfsd3_fhandleargs nfsd_fhandle#define ST 1/* status*/ #define AT 21/* attributes */
@@ -2006,15 +2023,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "FSINFO", }, [NFSPROC3_PATHCONF] = { - .pc_func = nfsd3_proc_pathconf, - .pc_decode = nfs3svc_decode_fhandleargs, - .pc_encode = nfs3svc_encode_pathconfres, - .pc_argsize = sizeof(struct nfsd3_fhandleargs), - .pc_argzero = sizeof(struct nfsd3_fhandleargs), - .pc_ressize = sizeof(struct nfsd3_pathconfres), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+pAT+6, - .pc_name = "PATHCONF", + .pc_func = nfsd3_proc_pathconf, + .pc_decode = nfs_svc_decode_PATHCONF3args, + .pc_encode = nfs_svc_encode_PATHCONF3res, + .pc_argsize = sizeof(struct PATHCONF3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_pathconfres), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_PATHCONF3res_sz, + .pc_name = "PATHCONF", }, [NFSPROC3_COMMIT] = { .pc_func = nfsd3_proc_commit,
@@ -2070,6 +2087,7 @@ union nfsd3_xdrstore {struct nfsd3_fsstatres fsstatres;struct FSINFO3args_wrapper fsinfoargs;struct nfsd3_fsinfores fsinfores; +struct PATHCONF3args_wrapper pathconfargs;struct nfsd3_pathconfres pathconfres;struct nfsd3_commitres commitres;struct nfsd3_getaclres getaclres;
fs/nfsd/nfs3xdr.c +0 -57
75 lines not on this page · raw message
fs/nfsd/xdr3.h +3 -9
@@ -99,15 +99,11 @@ struct nfsd3_fsinfores {static_assert (offsetof(struct nfsd3_fsinfores , xdrgen) ==0 );struct nfsd3_pathconfres { -__be32 status; -__u32 p_link_max; -__u32 p_name_max; -__u32 p_no_trunc; -__u32 p_chown_restricted; -bool p_case_insensitive; -bool p_case_preserving; +struct PATHCONF3res xdrgen; }; +static_assert (offsetof(struct nfsd3_pathconfres , xdrgen) ==0 ); +struct nfsd3_commitres {__be32 status;struct svc_fh fh;
@@ -123,14 +119,12 @@ struct nfsd3_getaclres {struct kstat stat; }; -bool nfs3svc_decode_fhandleargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);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_pathconfres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_commitres (struct svc_rqst *rqstp,struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 26/33 NFSD: Use xdrgen XDR functions for the NFSv3 COMMIT procedure
In reply to Chuck LeverReplace the NFSPROC3_COMMIT entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_COMMIT3args and nfs_svc_encode_COMMIT3res. A wrapper structure bridges the generated xdrgen argument type and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 COMMIT procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
Because nfsd3_proc_commit() now fills in the WCC data, including both the pre-op and post-op attributes, the fh_getattr() calls are made in the proc function rather than in the XDR result encoder, and the reference to the file handle can be released directly by nfsd3_proc_commit(). A separate ->pc_release callback is thus no longer needed. This makes it straightforward to confirm that the file handle is properly released during every error flow.
nfs3svc_decode_commitargs() and nfs3svc_encode_commitres() no longer have any callers, so they are removed. COMMIT was the last caller of the hand-written WCC encoders, so svcxdr_encode_wcc_data() and its svcxdr_encode_pre_op_attr() and svcxdr_encode_wcc_attr() helpers are removed as well, along with the now-orphaned svcxdr_encode_writeverf3() encode helper.
--- fs/nfsd/nfs3proc.c | 80 +++++++++++++++++++------------- fs/nfsd/nfs3xdr.c | 113 --------------------------------------------- fs/nfsd/xdr3.h | 14 ++---- 3 files changed, 52 insertions(+), 155 deletions(-)
fs/nfsd/nfs3proc.c +49 -31
@@ -211,6 +211,13 @@ struct PATHCONF3args_wrapper {static_assert (offsetof(struct PATHCONF3args_wrapper , xdrgen) ==0 ); +struct COMMIT3args_wrapper { +struct COMMIT3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct COMMIT3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1758,31 +1765,47 @@ static __be32 nfsd3_proc_pathconf(struct svc_rqst *rqstp)return rpc_success; } -/* -* Commit a file (range) to stable storage. +/** +* nfsd3_proc_commit - COMMIT: Commit cached data on a server to stable storage +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* COMMIT3res NFSPROC3_COMMIT(COMMIT3args) = 21; */ -static __be32 -nfsd3_proc_commit (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_commit (struct svc_rqst *rqstp) { -struct nfsd3_commitargs *argp = rqstp->rq_argp; +struct COMMIT3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_commitres *resp = rqstp->rq_resp; +struct svc_fh *fhp = &argp->fh;struct nfsd_file *nf; -dprintk ("nfsd: COMMIT(3) %s %u@%Lu\n" , -SVCFH_fmt (&argp->fh), - argp->count, - (unsigned long long ) argp->offset); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.file); -fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_file_acquire_gc (rqstp, &resp->fh,NFSD_MAY_WRITE | -NFSD_MAY_NOT_BREAK_LEASE , &nf); -if (resp->status) + resp->xdrgen.status =nfsd_file_acquire_gc (rqstp, fhp,NFSD_MAY_WRITE | +NFSD_MAY_NOT_BREAK_LEASE , &nf); +if (resp->xdrgen.status) goto out; - resp->status =nfsd_commit (rqstp, &resp->fh, nf, argp->offset, - argp->count, resp->verf); + resp->xdrgen.status =nfsd_commit (rqstp, fhp, nf, + argp->xdrgen.offset, argp->xdrgen.count, + (__be32 *)resp->xdrgen.u.resok.verf);nfsd_file_put (nf); + out: - resp->status =nfsd3_map_status (resp->status); +if (resp->xdrgen.status == nfs_ok) { +struct COMMIT3resok *resok = &resp->xdrgen.u.resok; + +nfsd3_fill_wcc_data (rqstp, &resok->file_wcc, fhp); + }else { +struct COMMIT3resfail *resfail = &resp->xdrgen.u.resfail; + + resp->xdrgen.status =nfsd3_map_status (resp->xdrgen.status); +nfsd3_fill_wcc_data (rqstp, &resfail->file_wcc, fhp); + } + +fh_put (fhp);return rpc_success; }
@@ -1793,11 +1816,6 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)*/ #define nfsd3_readdirplusargs nfsd3_readdirargs -#define ST 1/* status*/ -#define AT 21/* attributes */ -#define pAT (1+AT)/* post attributes - conditional */ -#define WC (7+pAT)/* WCC attributes */ -static const struct svc_procedure nfsd_procedures3[22 ] = { [NFSPROC3_NULL ] = { .pc_func = nfsd3_proc_null,
@@ -2034,16 +2052,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "PATHCONF", }, [NFSPROC3_COMMIT] = { - .pc_func = nfsd3_proc_commit, - .pc_decode = nfs3svc_decode_commitargs, - .pc_encode = nfs3svc_encode_commitres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_commitargs), - .pc_argzero = sizeof(struct nfsd3_commitargs), - .pc_ressize = sizeof(struct nfsd3_commitres), - .pc_cachetype = RC_NOCACHE, - .pc_xdrressize = ST+WC+2, - .pc_name = "COMMIT", + .pc_func = nfsd3_proc_commit, + .pc_decode = nfs_svc_decode_COMMIT3args, + .pc_encode = nfs_svc_encode_COMMIT3res, + .pc_argsize = sizeof(struct COMMIT3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_commitres), + .pc_cachetype = RC_NOCACHE, + .pc_xdrressize = NFS3_COMMIT3res_sz, + .pc_name = "COMMIT", }, };
@@ -2089,6 +2106,7 @@ union nfsd3_xdrstore {struct nfsd3_fsinfores fsinfores;struct PATHCONF3args_wrapper pathconfargs;struct nfsd3_pathconfres pathconfres; +struct COMMIT3args_wrapper commitargs;struct nfsd3_commitres commitres;struct nfsd3_getaclres getaclres; };
fs/nfsd/nfs3xdr.c +0 -113
143 lines not on this page · raw message
fs/nfsd/xdr3.h +3 -11
@@ -31,12 +31,6 @@ struct nfsd3_readdirargs {__be32 * verf; }; -struct nfsd3_commitargs { -struct svc_fh fh; -__u64 offset; -__u32 count; -}; -struct nfsd3_getaclargs {struct svc_fh fh;__u32 mask;
@@ -105,11 +99,11 @@ struct nfsd3_pathconfres {static_assert (offsetof(struct nfsd3_pathconfres , xdrgen) ==0 );struct nfsd3_commitres { -__be32 status; -struct svc_fh fh; -__be32 verf[2 ]; +struct COMMIT3res xdrgen; }; +static_assert (offsetof(struct nfsd3_commitres , xdrgen) ==0 ); +struct nfsd3_getaclres {__be32 status;struct svc_fh fh;
@@ -121,11 +115,9 @@ struct nfsd3_getaclres {bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_decode_commitargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);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_commitres (struct svc_rqst *rqstp,struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 27/33 NFSD: Use xdrgen XDR functions for NFSv3 READDIR arguments
In reply to Chuck LeverReplace the NFSPROC3_READDIR entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_READDIR3args. A wrapper structure bridges the generated xdrgen READDIR3args type and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 READDIR procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfs3svc_decode_readdirargs() no longer has any callers, so it is removed.
--- fs/nfsd/nfs3proc.c | 59 +++++++++++++++++++++++++++++----------------- fs/nfsd/nfs3xdr.c | 18 -------------- fs/nfsd/xdr3.h | 1 - 3 files changed, 37 insertions(+), 41 deletions(-)
fs/nfsd/nfs3proc.c +37 -22
@@ -218,6 +218,13 @@ struct COMMIT3args_wrapper {static_assert (offsetof(struct COMMIT3args_wrapper , xdrgen) ==0 ); +struct READDIR3args_wrapper { +struct READDIR3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct READDIR3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1510,28 +1517,35 @@ static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,xdr_init_encode_pages (xdr, buf); } -/* -* Read a portion of a directory. +/** +* nfsd3_proc_readdir - READDIR: Read from directory +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* READDIR3res NFSPROC3_READDIR(READDIR3args) = 16; */ -static __be32 -nfsd3_proc_readdir (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_readdir (struct svc_rqst *rqstp) { -struct nfsd3_readdirargs *argp = rqstp->rq_argp; +struct READDIR3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_readdirres *resp = rqstp->rq_resp; -loff_t offset; +loff_t offset = argp->xdrgen.cookie; +struct svc_fh *fhp = &argp->fh; -trace_nfsd_vfs_readdir (rqstp, &argp->fh, argp->count, argp->cookie); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.dir); +trace_nfsd_vfs_readdir (rqstp, fhp, argp->xdrgen.count, + argp->xdrgen.cookie); -nfsd3_init_dirlist_pages (rqstp, resp, argp->count); - -fh_copy (&resp->fh, &argp->fh); +nfsd3_init_dirlist_pages (rqstp, resp, argp->xdrgen.count); +fh_copy (&resp->fh, fhp); resp->common.err = nfs_ok; resp->cookie_offset =0 ; resp->rqstp = rqstp; - offset = argp->cookie; resp->status =nfsd_readdir (rqstp, &resp->fh, &offset, &resp->common, nfs3svc_encode_entry3); -memcpy (resp->verf, argp->verf,8 ); +memcpy (resp->verf, argp->xdrgen.cookieverf,NFS3_COOKIEVERFSIZE );nfs3svc_encode_cookie3 (resp, offset);/* Recycle only pages that were part of the reply */
@@ -1997,15 +2011,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "LINK", }, [NFSPROC3_READDIR] = { - .pc_func = nfsd3_proc_readdir, - .pc_decode = nfs3svc_decode_readdirargs, - .pc_encode = nfs3svc_encode_readdirres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_readdirargs), - .pc_argzero = sizeof(struct nfsd3_readdirargs), - .pc_ressize = sizeof(struct nfsd3_readdirres), - .pc_cachetype = RC_NOCACHE, - .pc_name = "READDIR", + .pc_func = nfsd3_proc_readdir, + .pc_decode = nfs_svc_decode_READDIR3args, + .pc_encode = nfs3svc_encode_readdirres, + .pc_release = nfs3svc_release_fhandle, + .pc_argsize = sizeof(struct READDIR3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_readdirres), + .pc_cachetype = RC_NOCACHE, + .pc_name = "READDIR", }, [NFSPROC3_READDIRPLUS] = { .pc_func = nfsd3_proc_readdirplus,
@@ -2095,7 +2109,8 @@ union nfsd3_xdrstore {struct RENAME3res renameres;struct LINK3args_wrapper linkargs;struct LINK3res linkres; -struct nfsd3_readdirargs readdirargs; +struct READDIR3args_wrapper readdirargs; +struct nfsd3_readdirargs readdirplusargs;struct READLINK3res readlinkres;struct READ3res readres;struct nfsd3_writeres writeres;
fs/nfsd/nfs3xdr.c +0 -18
@@ -228,24 +228,6 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,* XDR decode functions */ -bool -nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_readdirargs *args = rqstp->rq_argp; - -if (!svcxdr_decode_nfs_fh3 (xdr, &args->fh)) -return false; -if (xdr_stream_decode_u64 (xdr, &args->cookie) <0 ) -return false; - args->verf =xdr_inline_decode (xdr,NFS3_COOKIEVERFSIZE ); -if (!args->verf) -return false; -if (xdr_stream_decode_u32 (xdr, &args->count) <0 ) -return false; - -return true; -} -bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) {
fs/nfsd/xdr3.h +0 -1
@@ -113,7 +113,6 @@ struct nfsd3_getaclres {struct kstat stat; }; -bool nfs3svc_decode_readdirargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 28/33 NFSD: Use xdrgen XDR functions for NFSv3 READDIRPLUS arguments
In reply to Chuck LeverReplace the NFSPROC3_READDIRPLUS entry in the nfsd_procedures3 array with an entry that dispatches the xdrgen-generated nfs_svc_decode_READDIRPLUS3args. A wrapper structure bridges the generated xdrgen READDIRPLUS3args type and the legacy svc_fh representation the NFSD VFS layer still uses.
The pc_argzero field is now set to zero for the NFSv3 READDIRPLUS procedure. The xdrgen decoders are trusted to initialize all arguments in the argp->xdrgen field, making the early defensive memset unnecessary. The remaining argp fields are cleared as needed.
nfs3svc_decode_readdirplusargs() no longer has any callers, so it is removed.
--- fs/nfsd/nfs3proc.c | 62 +++++++++++++++++++++++++++------------------- fs/nfsd/nfs3xdr.c | 26 ------------------- fs/nfsd/xdr3.h | 9 ------- 3 files changed, 36 insertions(+), 61 deletions(-)
fs/nfsd/nfs3proc.c +36 -26
@@ -225,6 +225,13 @@ struct READDIR3args_wrapper {static_assert (offsetof(struct READDIR3args_wrapper , xdrgen) ==0 ); +struct READDIRPLUS3args_wrapper { +struct READDIRPLUS3args xdrgen; +struct svc_fh fh; +}; + +static_assert (offsetof(struct READDIRPLUS3args_wrapper , xdrgen) ==0 ); +static int nfsd3_ftype3_to_mode (ftype3 ftype) {switch (ftype) {
@@ -1555,27 +1562,32 @@ static __be32 nfsd3_proc_readdir(struct svc_rqst *rqstp)return rpc_success; } -/* -* Read a portion of a directory, including file handles and attrs. -* For now, we choose to ignore the dircount parameter. +/** +* nfsd3_proc_readdirplus - READDIRPLUS: Extended read from directory +* @rqstp: RPC transaction context +* +* Return: +* %rpc_success: RPC executed successfully +* +* RPC synopsis: +* READDIRPLUS3res NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17; */ -static __be32 -nfsd3_proc_readdirplus (struct svc_rqst *rqstp) +static __be32 nfsd3_proc_readdirplus (struct svc_rqst *rqstp) { -struct nfsd3_readdirargs *argp = rqstp->rq_argp; +struct READDIRPLUS3args_wrapper *argp = rqstp->rq_argp;struct nfsd3_readdirres *resp = rqstp->rq_resp; -loff_t offset; +loff_t offset = argp->xdrgen.cookie; +struct svc_fh *fhp = &argp->fh; -trace_nfsd_vfs_readdir (rqstp, &argp->fh, argp->count, argp->cookie); +nfsd3_fh3_to_svc_fh (fhp, &argp->xdrgen.dir); +trace_nfsd_vfs_readdir (rqstp, fhp, argp->xdrgen.maxcount, + argp->xdrgen.cookie); -nfsd3_init_dirlist_pages (rqstp, resp, argp->count); - -fh_copy (&resp->fh, &argp->fh); +nfsd3_init_dirlist_pages (rqstp, resp, argp->xdrgen.maxcount); +fh_copy (&resp->fh, fhp); resp->common.err = nfs_ok; resp->cookie_offset =0 ; resp->rqstp = rqstp; - offset = argp->cookie; - resp->status =fh_verify (rqstp, &resp->fh,S_IFDIR ,NFSD_MAY_NOP );if (resp->status != nfs_ok) goto out;
@@ -1587,7 +1599,7 @@ nfsd3_proc_readdirplus(struct svc_rqst *rqstp) resp->status =nfsd_readdir (rqstp, &resp->fh, &offset, &resp->common, nfs3svc_encode_entryplus3); -memcpy (resp->verf, argp->verf,8 ); +memcpy (resp->verf, argp->xdrgen.cookieverf,NFS3_COOKIEVERFSIZE );nfs3svc_encode_cookie3 (resp, offset);/* Recycle only pages that were part of the reply */
@@ -1828,8 +1840,6 @@ static __be32 nfsd3_proc_commit(struct svc_rqst *rqstp)* NFSv3 Server procedures. * Only the results of non-idempotent operations are cached. */ -#define nfsd3_readdirplusargs nfsd3_readdirargs -static const struct svc_procedure nfsd_procedures3[22 ] = { [NFSPROC3_NULL ] = { .pc_func = nfsd3_proc_null,
@@ -2022,15 +2032,15 @@ static const struct svc_procedure nfsd_procedures3[22] = { .pc_name = "READDIR", }, [NFSPROC3_READDIRPLUS] = { - .pc_func = nfsd3_proc_readdirplus, - .pc_decode = nfs3svc_decode_readdirplusargs, - .pc_encode = nfs3svc_encode_readdirres, - .pc_release = nfs3svc_release_fhandle, - .pc_argsize = sizeof(struct nfsd3_readdirplusargs), - .pc_argzero = sizeof(struct nfsd3_readdirplusargs), - .pc_ressize = sizeof(struct nfsd3_readdirres), - .pc_cachetype = RC_NOCACHE, - .pc_name = "READDIRPLUS", + .pc_func = nfsd3_proc_readdirplus, + .pc_decode = nfs_svc_decode_READDIRPLUS3args, + .pc_encode = nfs3svc_encode_readdirres, + .pc_release = nfs3svc_release_fhandle, + .pc_argsize = sizeof(struct READDIRPLUS3args_wrapper), + .pc_argzero = 0, + .pc_ressize = sizeof(struct nfsd3_readdirres), + .pc_cachetype = RC_NOCACHE, + .pc_name = "READDIRPLUS", }, [NFSPROC3_FSSTAT] = { .pc_func = nfsd3_proc_fsstat,
@@ -2110,7 +2120,7 @@ union nfsd3_xdrstore {struct LINK3args_wrapper linkargs;struct LINK3res linkres;struct READDIR3args_wrapper readdirargs; -struct nfsd3_readdirargs readdirplusargs; +struct READDIRPLUS3args_wrapper readdirplusargs;struct READLINK3res readlinkres;struct READ3res readres;struct nfsd3_writeres writeres;
fs/nfsd/nfs3xdr.c +0 -26
@@ -224,32 +224,6 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,return xdr_stream_encode_item_absent (xdr) >0 ; } -/* -* XDR decode functions -*/ - -bool -nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr) -{ -struct nfsd3_readdirargs *args = rqstp->rq_argp; -u32 dircount; - -if (!svcxdr_decode_nfs_fh3 (xdr, &args->fh)) -return false; -if (xdr_stream_decode_u64 (xdr, &args->cookie) <0 ) -return false; - args->verf =xdr_inline_decode (xdr,NFS3_COOKIEVERFSIZE ); -if (!args->verf) -return false; -/* dircount is ignored */ -if (xdr_stream_decode_u32 (xdr, &dircount) <0 ) -return false; -if (xdr_stream_decode_u32 (xdr, &args->count) <0 ) -return false; - -return true; -} -/* * XDR encode functions */
fs/nfsd/xdr3.h +0 -9
@@ -24,13 +24,6 @@ struct nfsd3_accessargs {__u32 access; }; -struct nfsd3_readdirargs { -struct svc_fh fh; -__u64 cookie; -__u32 count; -__be32 * verf; -}; -struct nfsd3_getaclargs {struct svc_fh fh;__u32 mask;
@@ -113,8 +106,6 @@ struct nfsd3_getaclres {struct kstat stat; }; -bool nfs3svc_decode_readdirplusargs (struct svc_rqst *rqstp,struct xdr_stream *xdr); -bool nfs3svc_encode_accessres (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nfs3svc_encode_readdirres (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 29/33 NFSD: Refactor NFSv3 directory cookie encoding
In reply to Chuck LeverThe current synopsis of nfs3svc_encode_cookie3() takes a "struct nfsd3_readdirres" argument, which is common to the NFSv3 READDIR and READDIRPLUS procedures.
xdrgen defines two distinct argument structures for these procedures since they are actually two distinct procedures and have different arguments.
With a "struct READDIR3args" and a "struct READDIRPLUS3args," the cookie3 encoder will need generic parameter types in order to be callable from both.
Note that NFSD can't use the xdrgen-generated cookie3 encoder. This is because directory cookies need to point to the previous directory entry. Space for each cookie in the send buffer is reserved when each directory entry is encoded; when the /next/ entry is encoded, the encoder writes its offset into that reserved space.
As a clean-up, remove "resp->cookie_offset = 0;" :
- In nfs3svc_encode_entry3() and nfs3svc_encode_entryplus3(), immediately after calling nfs3svc_encode_cookie3(), the code calls svcxdr_encode_entry3_common() which sets a new resp->cookie_offset value. The cookie_offset value was immediately overwritten.
- In nfsd3_proc_readdir() and nfsd3_proc_readdirplus(), nfs3svc_encode_cookie3() is called as the last cookie encoding, and no further use of cookie_offset follows.
- The out_toosmall error paths in entry encoders continue to set resp->cookie_offset = 0
--- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs3xdr.c | 22 +++++++++++----------- fs/nfsd/xdr3.h | 3 ++- 3 files changed, 15 insertions(+), 14 deletions(-)
fs/nfsd/nfs3proc.c +2 -2
@@ -1553,7 +1553,7 @@ static __be32 nfsd3_proc_readdir(struct svc_rqst *rqstp) resp->status =nfsd_readdir (rqstp, &resp->fh, &offset, &resp->common, nfs3svc_encode_entry3);memcpy (resp->verf, argp->xdrgen.cookieverf,NFS3_COOKIEVERFSIZE ); -nfs3svc_encode_cookie3 (resp, offset); +nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset);/* Recycle only pages that were part of the reply */ rqstp->rq_next_page = resp->xdr.page_ptr +1 ;
@@ -1600,7 +1600,7 @@ static __be32 nfsd3_proc_readdirplus(struct svc_rqst *rqstp) resp->status =nfsd_readdir (rqstp, &resp->fh, &offset, &resp->common, nfs3svc_encode_entryplus3);memcpy (resp->verf, argp->xdrgen.cookieverf,NFS3_COOKIEVERFSIZE ); -nfs3svc_encode_cookie3 (resp, offset); +nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset);/* Recycle only pages that were part of the reply */ rqstp->rq_next_page = resp->xdr.page_ptr +1 ;
fs/nfsd/nfs3xdr.c +11 -11
@@ -300,22 +300,22 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp, }/** -* nfs3svc_encode_cookie3 - Encode a directory offset cookie -* @resp: readdir result context -* @offset: offset cookie to encode +* nfs3svc_encode_cookie3 - Encode a directory cookie +* @xdr: stream into which to encode the cookie +* @pos: byte position in the stream +* @cookie: cookie to be encoded * * The buffer space for the offset cookie has already been reserved * by svcxdr_encode_entry3_common(). */ -void nfs3svc_encode_cookie3 (struct nfsd3_readdirres *resp,u64 offset) +void nfs3svc_encode_cookie3 (struct xdr_stream *xdr,unsigned int pos, +u64 cookie) { -__be64 cookie =cpu_to_be64 (offset); +__be64 wire_cookie =cpu_to_be64 (cookie); -if (!resp->cookie_offset) +if (!pos)return ; -write_bytes_to_xdr_buf (&resp->dirlist, resp->cookie_offset, &cookie, -sizeof (cookie)); - resp->cookie_offset =0 ; +write_bytes_to_xdr_buf (xdr->buf, pos, &wire_cookie,XDR_UNIT *2 ); } static bool
@@ -369,7 +369,7 @@ int nfs3svc_encode_entry3(void *data, const char *name, int namlen,unsigned int starting_length = resp->dirlist.len;/* The offset cookie for the previous entry */ -nfs3svc_encode_cookie3 (resp, offset); +nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset);if (!svcxdr_encode_entry3_common (resp, name, namlen, offset, ino)) goto out_toosmall;
@@ -444,7 +444,7 @@ int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen,unsigned int starting_length = resp->dirlist.len;/* The offset cookie for the previous entry */ -nfs3svc_encode_cookie3 (resp, offset); +nfs3svc_encode_cookie3 (&resp->xdr, resp->cookie_offset, offset);if (!svcxdr_encode_entry3_common (resp, name, namlen, offset, ino)) goto out_toosmall;
fs/nfsd/xdr3.h +2 -1
@@ -111,7 +111,8 @@ bool nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr);void nfs3svc_release_fhandle (struct svc_rqst *); -void nfs3svc_encode_cookie3 (struct nfsd3_readdirres *resp,u64 offset); +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,
Signature · 1 line
2.55.0
Chuck Lever
maintainerPATCH v2 30/33 NFSD: Refactor NFSv3 directory entry encoding
In reply to Chuck LeverThe 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 v2 31/33 NFSD: Split struct nfsd3_readdirres
In reply to Chuck LeverCurrently 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
@@ -1242,6 +1242,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
@@ -1575,7 +1596,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;
@@ -1583,7 +1604,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 ;
@@ -2034,11 +2055,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", },
@@ -2125,6 +2146,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 v2 32/33 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 cannot retract entries already on the wire, so it ends the list as a truncated, non-eof reply rather than an error status; 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 v2 33/33 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 cannot retract entries already on the wire, so it ends the list as a truncated, non-eof reply rather than an error status; 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 | 308 ++++++++++++++--------------- 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, 263 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 +154 -154
367 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