Documentation: Add the RPC language description of NFSv3
Subsystems (3)
Chuck Lever
maintainerPATCH v3 2/34 Documentation: Add the RPC language description of NFSv3
From: 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 v3 3/34 NFSD: Add infrastructure for generating NFSv3 XDR encoders and decoders
NFSD'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 v3 4/34 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 v3 5/34 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 v3 6/34 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 v3 7/34 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 v3 8/34 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 | 159 ++++++++++++++++++++++++----- 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, 185 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 +133 -26
212 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 v3 9/34 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 */
@@ -184,6 +193,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)
@@ -221,6 +238,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.
@@ -280,32 +412,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; }
@@ -1064,16 +1211,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,
@@ -1306,7 +1452,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