Re: [PATCH v6 02/20] nfsd: add protocol support for CB_NOTIFY
From: Chuck Lever
Date: Thu Jun 11 2026 - 17:34:29 EST
On Thu, Jun 11, 2026, at 1:50 PM, Jeff Layton wrote:
> diff --git a/Documentation/sunrpc/xdr/nfs4_1.x
> b/Documentation/sunrpc/xdr/nfs4_1.x
> index 5b45547b2ebc..632f5b579c39 100644
> --- a/Documentation/sunrpc/xdr/nfs4_1.x
> +++ b/Documentation/sunrpc/xdr/nfs4_1.x
> @@ -45,19 +45,165 @@ pragma header nfs4;
> /*
> * Basic typedefs for RFC 1832 data type definitions
> */
> -typedef hyper int64_t;
> -typedef unsigned int uint32_t;
> +typedef int int32_t;
> +typedef unsigned int uint32_t;
> +typedef hyper int64_t;
> +typedef unsigned hyper uint64_t;
> +
> +const NFS4_VERIFIER_SIZE = 8;
> +const NFS4_FHSIZE = 128;
> +
> +enum nfsstat4 {
> + NFS4_OK = 0, /* everything is okay */
> + NFS4ERR_PERM = 1, /* caller not privileged */
> + NFS4ERR_NOENT = 2, /* no such file/directory */
> + NFS4ERR_IO = 5, /* hard I/O error */
> + NFS4ERR_NXIO = 6, /* no such device */
> + NFS4ERR_ACCESS = 13, /* access denied */
> + NFS4ERR_EXIST = 17, /* file already exists */
> + NFS4ERR_XDEV = 18, /* different filesystems */
> +
> + /*
> + * Please do not allocate value 19; it was used in NFSv3
> + * and we do not want a value in NFSv3 to have a different
> + * meaning in NFSv4.x.
> + */
> +
> + NFS4ERR_NOTDIR = 20, /* should be a directory */
> + NFS4ERR_ISDIR = 21, /* should not be directory */
> + NFS4ERR_INVAL = 22, /* invalid argument */
> + NFS4ERR_FBIG = 27, /* file exceeds server max */
> + NFS4ERR_NOSPC = 28, /* no space on filesystem */
> + NFS4ERR_ROFS = 30, /* read-only filesystem */
> + NFS4ERR_MLINK = 31, /* too many hard links */
> + NFS4ERR_NAMETOOLONG = 63, /* name exceeds server max */
> + NFS4ERR_NOTEMPTY = 66, /* directory not empty */
> + NFS4ERR_DQUOT = 69, /* hard quota limit reached*/
> + NFS4ERR_STALE = 70, /* file no longer exists */
> + NFS4ERR_BADHANDLE = 10001,/* Illegal filehandle */
> + NFS4ERR_BAD_COOKIE = 10003,/* READDIR cookie is stale */
> + NFS4ERR_NOTSUPP = 10004,/* operation not supported */
> + NFS4ERR_TOOSMALL = 10005,/* response limit exceeded */
> + NFS4ERR_SERVERFAULT = 10006,/* undefined server error */
> + NFS4ERR_BADTYPE = 10007,/* type invalid for CREATE */
> + NFS4ERR_DELAY = 10008,/* file "busy" - retry */
> + NFS4ERR_SAME = 10009,/* nverify says attrs same */
> + NFS4ERR_DENIED = 10010,/* lock unavailable */
> + NFS4ERR_EXPIRED = 10011,/* lock lease expired */
> + NFS4ERR_LOCKED = 10012,/* I/O failed due to lock */
> + NFS4ERR_GRACE = 10013,/* in grace period */
> + NFS4ERR_FHEXPIRED = 10014,/* filehandle expired */
> + NFS4ERR_SHARE_DENIED = 10015,/* share reserve denied */
> + NFS4ERR_WRONGSEC = 10016,/* wrong security flavor */
> + NFS4ERR_CLID_INUSE = 10017,/* clientid in use */
> +
> + /* NFS4ERR_RESOURCE is not a valid error in NFSv4.1 */
> + NFS4ERR_RESOURCE = 10018,/* resource exhaustion */
> +
> + NFS4ERR_MOVED = 10019,/* filesystem relocated */
> + NFS4ERR_NOFILEHANDLE = 10020,/* current FH is not set */
> + NFS4ERR_MINOR_VERS_MISMATCH= 10021,/* minor vers not supp */
> + NFS4ERR_STALE_CLIENTID = 10022,/* server has rebooted */
> + NFS4ERR_STALE_STATEID = 10023,/* server has rebooted */
> + NFS4ERR_OLD_STATEID = 10024,/* state is out of sync */
> + NFS4ERR_BAD_STATEID = 10025,/* incorrect stateid */
> + NFS4ERR_BAD_SEQID = 10026,/* request is out of seq. */
> + NFS4ERR_NOT_SAME = 10027,/* verify - attrs not same */
> + NFS4ERR_LOCK_RANGE = 10028,/* overlapping lock range */
> + NFS4ERR_SYMLINK = 10029,/* should be file/directory*/
> + NFS4ERR_RESTOREFH = 10030,/* no saved filehandle */
> + NFS4ERR_LEASE_MOVED = 10031,/* some filesystem moved */
> + NFS4ERR_ATTRNOTSUPP = 10032,/* recommended attr not sup*/
> + NFS4ERR_NO_GRACE = 10033,/* reclaim outside of grace*/
> + NFS4ERR_RECLAIM_BAD = 10034,/* reclaim error at server */
> + NFS4ERR_RECLAIM_CONFLICT= 10035,/* conflict on reclaim */
> + NFS4ERR_BADXDR = 10036,/* XDR decode failed */
> + NFS4ERR_LOCKS_HELD = 10037,/* file locks held at CLOSE*/
> + NFS4ERR_OPENMODE = 10038,/* conflict in OPEN and I/O*/
> + NFS4ERR_BADOWNER = 10039,/* owner translation bad */
> + NFS4ERR_BADCHAR = 10040,/* utf-8 char not supported*/
> + NFS4ERR_BADNAME = 10041,/* name not supported */
> + NFS4ERR_BAD_RANGE = 10042,/* lock range not supported*/
> + NFS4ERR_LOCK_NOTSUPP = 10043,/* no atomic up/downgrade */
> + NFS4ERR_OP_ILLEGAL = 10044,/* undefined operation */
> + NFS4ERR_DEADLOCK = 10045,/* file locking deadlock */
> + NFS4ERR_FILE_OPEN = 10046,/* open file blocks op. */
> + NFS4ERR_ADMIN_REVOKED = 10047,/* lockowner state revoked */
> + NFS4ERR_CB_PATH_DOWN = 10048,/* callback path down */
> +
> + /* NFSv4.1 errors start here. */
> +
> + NFS4ERR_BADIOMODE = 10049,
> + NFS4ERR_BADLAYOUT = 10050,
> + NFS4ERR_BAD_SESSION_DIGEST = 10051,
> + NFS4ERR_BADSESSION = 10052,
> + NFS4ERR_BADSLOT = 10053,
> + NFS4ERR_COMPLETE_ALREADY = 10054,
> + NFS4ERR_CONN_NOT_BOUND_TO_SESSION = 10055,
> + NFS4ERR_DELEG_ALREADY_WANTED = 10056,
> + NFS4ERR_BACK_CHAN_BUSY = 10057,/*backchan reqs outstanding*/
> + NFS4ERR_LAYOUTTRYLATER = 10058,
> + NFS4ERR_LAYOUTUNAVAILABLE = 10059,
> + NFS4ERR_NOMATCHING_LAYOUT = 10060,
> + NFS4ERR_RECALLCONFLICT = 10061,
> + NFS4ERR_UNKNOWN_LAYOUTTYPE = 10062,
> + NFS4ERR_SEQ_MISORDERED = 10063,/* unexpected seq.ID in req*/
> + NFS4ERR_SEQUENCE_POS = 10064,/* [CB_]SEQ. op not 1st op */
> + NFS4ERR_REQ_TOO_BIG = 10065,/* request too big */
> + NFS4ERR_REP_TOO_BIG = 10066,/* reply too big */
> + NFS4ERR_REP_TOO_BIG_TO_CACHE =10067,/* rep. not all cached*/
> + NFS4ERR_RETRY_UNCACHED_REP =10068,/* retry & rep. uncached*/
> + NFS4ERR_UNSAFE_COMPOUND =10069,/* retry/recovery too hard */
> + NFS4ERR_TOO_MANY_OPS = 10070,/*too many ops in [CB_]COMP*/
> + NFS4ERR_OP_NOT_IN_SESSION =10071,/* op needs [CB_]SEQ. op */
> + NFS4ERR_HASH_ALG_UNSUPP = 10072, /* hash alg. not supp. */
> + /* Error 10073 is unused. */
> + NFS4ERR_CLIENTID_BUSY = 10074,/* clientid has state */
> + NFS4ERR_PNFS_IO_HOLE = 10075,/* IO to _SPARSE file hole */
> + NFS4ERR_SEQ_FALSE_RETRY= 10076,/* Retry != original req. */
> + NFS4ERR_BAD_HIGH_SLOT = 10077,/* req has bad highest_slot*/
> + NFS4ERR_DEADSESSION = 10078,/*new req sent to dead sess*/
> + NFS4ERR_ENCR_ALG_UNSUPP= 10079,/* encr alg. not supp. */
> + NFS4ERR_PNFS_NO_LAYOUT = 10080,/* I/O without a layout */
> + NFS4ERR_NOT_ONLY_OP = 10081,/* addl ops not allowed */
> + NFS4ERR_WRONG_CRED = 10082,/* op done by wrong cred */
> + NFS4ERR_WRONG_TYPE = 10083,/* op on wrong type object */
> + NFS4ERR_DIRDELEG_UNAVAIL=10084,/* delegation not avail. */
> + NFS4ERR_REJECT_DELEG = 10085,/* cb rejected delegation */
> + NFS4ERR_RETURNCONFLICT = 10086,/* layout get before return*/
> + NFS4ERR_DELEG_REVOKED = 10087, /* deleg./layout revoked */
> + NFS4ERR_PARTNER_NOTSUPP = 10088,
> + NFS4ERR_PARTNER_NO_AUTH = 10089,
> + NFS4ERR_UNION_NOTSUPP = 10090,
> + NFS4ERR_OFFLOAD_DENIED = 10091,
> + NFS4ERR_WRONG_LFS = 10092,
> + NFS4ERR_BADLABEL = 10093,
> + NFS4ERR_OFFLOAD_NO_REQS = 10094,
> + NFS4ERR_NOXATTR = 10095,
> + NFS4ERR_XATTR2BIG = 10096,
> +
> + /* always set this to one more than the last one in the enum */
> + NFS4ERR_FIRST_FREE = 10097
> +};
This value can be leaked onto the wire. The basic enum encoder
checks that these values are part of the .x before sticking
them on the wire.
Please keep the .x document aligned with the specification. If
you need a "maximum value" symbolic constant, please define it
in one of the hand-rolled headers. (I guess this one was copied
over from the existing hand-rolled NFS4ERR definitions).
I see that NFS4ERR_FIRST_FREE is used to determine the numeric
value for NFSERR_EOF.
fs/nfsd/nfs3xdr.c: if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0)
fs/nfsd/nfs4xdr.c: return nfsd4_encode_bool(xdr, readdir->common.err == nfserr_eof);
fs/nfsd/nfsd.h: __be32 err; /* 0, nfserr, or nfserr_eof */
fs/nfsd/nfsd.h:#define nfserr_eof cpu_to_be32(NFSERR_EOF)
fs/nfsd/nfsxdr.c: if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0)
fs/nfsd/vfs.c: cdp->err = nfserr_eof; /* will be cleared on successful read */
fs/nfsd/vfs.c: if (err == nfserr_eof || err == nfserr_toosmall)
A better interim approach might be to select an impossible value
for NFSERR_EOF, as is done for the internal NLM error status codes:
fs/lockd/lockd.h:#define nlm__int__drop_reply cpu_to_be32(30000)
fs/lockd/lockd.h:#define nlm__int__deadlock cpu_to_be32(30001)
fs/lockd/lockd.h:#define nlm__int__stale_fh cpu_to_be32(30002)
fs/lockd/lockd.h:#define nlm__int__failed cpu_to_be32(30003)
> @@ -245,3 +406,88 @@ const FATTR4_ACL_TRUEFORM = 89;
> const FATTR4_ACL_TRUEFORM_SCOPE = 90;
> const FATTR4_POSIX_DEFAULT_ACL = 91;
> const FATTR4_POSIX_ACCESS_ACL = 92;
> +
> +/*
> + * Directory notification types.
> + */
> +enum notify_type4 {
> + NOTIFY4_CHANGE_CHILD_ATTRS = 0,
> + NOTIFY4_CHANGE_DIR_ATTRS = 1,
> + NOTIFY4_REMOVE_ENTRY = 2,
> + NOTIFY4_ADD_ENTRY = 3,
> + NOTIFY4_RENAME_ENTRY = 4,
> + NOTIFY4_CHANGE_COOKIE_VERIFIER = 5
> +};
> +
> +/* Changed entry information. */
> +struct notify_entry4 {
> + component4 ne_file;
> + fattr4 ne_attrs;
> +};
> +
> +/* Previous entry information */
> +struct prev_entry4 {
> + notify_entry4 pe_prev_entry;
> + /* what READDIR returned for this entry */
> + nfs_cookie4 pe_prev_entry_cookie;
> +};
> +
> +struct notify_remove4 {
> + notify_entry4 nrm_old_entry;
> + nfs_cookie4 nrm_old_entry_cookie;
> +};
> +pragma public notify_remove4;
> +
> +struct notify_add4 {
> + /*
> + * Information on object
> + * possibly renamed over.
> + */
> + notify_remove4 nad_old_entry<1>;
> + notify_entry4 nad_new_entry;
> + /* what READDIR would have returned for this entry */
> + nfs_cookie4 nad_new_entry_cookie<1>;
> + prev_entry4 nad_prev_entry<1>;
> + bool nad_last_entry;
> +};
> +pragma public notify_add4;
> +
> +struct notify_attr4 {
> + notify_entry4 na_changed_entry;
> +};
> +pragma public notify_attr4;
> +
> +struct notify_rename4 {
> + notify_remove4 nrn_old_entry;
> + notify_add4 nrn_new_entry;
> +};
> +pragma public notify_rename4;
> +
> +struct notify_verifier4 {
> + verifier4 nv_old_cookieverf;
> + verifier4 nv_new_cookieverf;
> +};
> +
> +/*
> + * Objects of type notify_<>4 and
> + * notify_device_<>4 are encoded in this.
> + */
> +typedef opaque notifylist4<>;
> +
> +struct notify4 {
> + /* composed from notify_type4 or notify_deviceid_type4 */
> + bitmap4 notify_mask;
> + notifylist4 notify_vals;
> +};
> +
> +struct CB_NOTIFY4args {
> + stateid4 cna_stateid;
> + nfs_fh4 cna_fh;
> + notify4 cna_changes<>;
> +};
> +pragma public CB_NOTIFY4args;
> +
> +struct CB_NOTIFY4res {
> + nfsstat4 cnr_status;
> +};
> +pragma public CB_NOTIFY4res;
Let's add the "pragma public" directives in the patches where
they are first needed, instead of here. As subsequent patches
are modified, the need for these directives might vanish.
--
Chuck Lever