nfsd: add support for CB_NOTIFY callbacks in directory delegations
Subsystems (3)
Jeff Layton
maintainerv6 cover nfsd: add support for CB_NOTIFY callbacks in directory delegations
This version of the patchset fixes up yet more problems that Sashiko and Chuck flagged during review. Progress!
Please consider for v7.3. Original cover letter follows:
---------------------------------8<------------------------------------
This patchset builds on the directory delegation work we did a few months ago to add support for CB_NOTIFY callbacks for some events. In particular, creates, unlinks and renames. The server also sends updated directory attributes in the notifications. With this support, the client can register interest in a directory and get notifications about changes within it without losing its lease.
The series starts with patches to allow the vfs to ignore certain types of events on directories. nfsd can then request these sorts of delegations on directories, and then set up inotify watches on the directory to trigger sending CB_NOTIFY events.
This has mainly been tested with pynfs, with some new testcases that I'll be posting soon. They seem to work fine with those tests, but I don't think we'll want to merge these until we have a complete client-side implementation to test against.
---
Changes in v6:
- fold earlier fix series into their respective patches
- tighten up RCU handling on fi_deleg_file
- move nfsd_fsnotify_recalc_mask() to filecache.c
- encoding failure now triggers deleg recall
- take snapshot of new dentry name when creating event
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- properly free dir delegation when alloc_pages_bulk() fails
- handle nfsd_file with no mark in nfsd_fsnotify_recalc_mask()
- nfsd_get_dir_deleg() should use stable nf pointer instead of
depending on fi_deleg_file
- use GFP_NOFS in alloc_nfsd_notify_event() since it's called with locks held
- nfsd_handle_dir_event() tracepoint now handles NULL pointers safely
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Rebase onto Chuck's nfsd-testing branch. Minor contextual fixups.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Fix error handling in alloc_init_dir_deleg()
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Fix __break_lease handling with different lease types on flc_lease list
- Add FSNOTIFY_EVENT_RENAME data type to properly handle cross-directory rename events
- Display fsnotify mask symbolically in tracepoints
- New tracepoint in fsnotify()
- Recalc fsnotify mask after unlocking lease instead of before
- Don't notify client that is making the changes
- After sending CB_NOTIFY, requeue if new events came in while running
- Document removal of NFS4_VERIFIER_SIZE/NFS4_FHSIZE from UAPI headers
- Properly release nfsd_dir_fsnotify_group on server shutdown
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (20):
nfsd: check fl_lmops in nfsd_breaker_owns_lease()
nfsd: add protocol support for CB_NOTIFY
nfs_common: add new NOTIFY4_* flags proposed in RFC8881bis
nfsd: allow nfsd to get a dir lease with an ignore mask
nfsd: update the fsnotify mark when setting or removing a dir delegation
nfsd: make nfsd4_callback_ops->prepare operation bool return
nfsd: add callback encoding and decoding linkages for CB_NOTIFY
nfsd: use RCU to protect fi_deleg_file
nfsd: add data structures for handling CB_NOTIFY
nfsd: add notification handlers for dir events
nfsd: apply the notify mask to the delegation when requested
nfsd: add helper to marshal a fattr4 from completed args
nfsd: allow nfsd4_encode_fattr4_change() to work with no export
nfsd: send basic file attributes in CB_NOTIFY
nfsd: allow encoding a filehandle into fattr4 without a svc_fh
nfsd: add a fi_connectable flag to struct nfs4_file
nfsd: add the filehandle to returned attributes in CB_NOTIFY
nfsd: properly track requested child attributes
nfsd: track requested dir attributes
nfsd: add support to CB_NOTIFY for dir attribute changes
Documentation/sunrpc/xdr/nfs4_1.x | 262 ++++++++++++++- fs/nfsd/filecache.c | 122 ++++++- fs/nfsd/filecache.h | 3 + fs/nfsd/nfs4callback.c | 97 +++++- fs/nfsd/nfs4layouts.c | 10 +- fs/nfsd/nfs4proc.c | 17 + fs/nfsd/nfs4state.c | 590 ++++++++++++++++++++++++++++++---- fs/nfsd/nfs4xdr.c | 330 +++++++++++++++++-- fs/nfsd/nfs4xdr_gen.c | 601 ++++++++++++++++++++++++++++++++++- fs/nfsd/nfs4xdr_gen.h | 20 +- fs/nfsd/nfsfh.c | 10 +- fs/nfsd/nfsfh.h | 1 + fs/nfsd/state.h | 85 ++++- fs/nfsd/trace.h | 24 ++ fs/nfsd/xdr4.h | 5 + fs/nfsd/xdr4cb.h | 12 + include/linux/nfs4.h | 127 -------- include/linux/sunrpc/xdrgen/nfs4_1.h | 291 ++++++++++++++++- include/uapi/linux/nfs4.h | 2 - 19 files changed, 2339 insertions(+), 270 deletions(-)
---
base-commit: 8defc3ed26a2b4c8677ce2106c2c92cd26ef1316
change-id: 20260325-dir-deleg-339066dd1017
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v6 1/20 nfsd: check fl_lmops in nfsd_breaker_owns_lease()
Any lease created by nfsd will have its fl_lmops set to nfsd_lease_mng_ops. Do a quick check for that first when testing whether the lease breaker owns the lease.
--- fs/nfsd/nfs4state.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/nfsd/nfs4state.c +6 -0
@@ -91,6 +91,8 @@ static void _free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_statstatic void nfsd4_file_hash_remove (struct nfs4_file *fi);static void deleg_reaper (struct nfsd_net *nn); +static const struct lease_manager_operations nfsd_lease_mng_ops; +/* Locking: */ enum nfsd4_st_mutex_lock_subclass {
@@ -5734,6 +5736,10 @@ static bool nfsd_breaker_owns_lease(struct file_lease *fl)struct svc_rqst *rqst;struct nfs4_client *clp; +/* Only nfsd leases */ +if (fl->fl_lmops != &nfsd_lease_mng_ops) +return false; + rqst =nfsd_current_rqst ();if (!nfsd_v4client (rqst))return false;
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 2/20 nfsd: add protocol support for CB_NOTIFY
In reply to Jeff LaytonAdd the necessary bits to nfs4_1.x and remove the duplicate definitions from nfs4.h and the uapi nfs4 header. Regenerate the xdr files.
Note that regenerating these files caused conflicts with the definitions of NFS4_VERIFIER_SIZE and NFS4_FHSIZE in include/uapi/linux/nfs4.h. These constants are defined by the RFC, and are not part of the kernel API. They have been removed. Userspace consumers who require those constants should plan to get them from more authoritative sources.
--- Documentation/sunrpc/xdr/nfs4_1.x | 250 ++++++++++++++- fs/nfsd/nfs4xdr_gen.c | 590 ++++++++++++++++++++++++++++++++++- fs/nfsd/nfs4xdr_gen.h | 20 +- fs/nfsd/trace.h | 1 + include/linux/nfs4.h | 127 -------- include/linux/sunrpc/xdrgen/nfs4_1.h | 280 ++++++++++++++++- include/uapi/linux/nfs4.h | 2 - 7 files changed, 1129 insertions(+), 141 deletions(-)
Documentation/sunrpc/xdr/nfs4_1.x +248 -2
@@ -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 +}; /* * Basic data types */ +typedef opaque attrlist4<>; typedef uint32_t bitmap4<>; +typedef opaque verifier4[NFS4_VERIFIER_SIZE]; +typedef uint64_t nfs_cookie4; +typedef opaque nfs_fh4<NFS4_FHSIZE>; typedef opaque utf8string<>; typedef utf8string utf8str_cis; typedef utf8string utf8str_cs; typedef utf8string utf8str_mixed; +typedef utf8str_cs component4; +typedef utf8str_cs linktext4; +typedef component4 pathname4<>; + /* * Timeval */
@@ -66,6 +212,21 @@ struct nfstime4 { uint32_t nseconds; }; +/* + * File attribute container + */ +struct fattr4 { + bitmap4 attrmask; + attrlist4 attr_vals; +}; + +/* + * Stateid + */ +struct stateid4 { + uint32_t seqid; + opaque other[12]; +}; /* * The following content was extracted from draft-ietf-nfsv4-delstid
@@ -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;
fs/nfsd/nfs4xdr_gen.c +585 -5
661 lines not on this page · raw message
fs/nfsd/nfs4xdr_gen.h +19 -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/nfs4_1.x */ -/* XDR specification modification time: Thu Jan 8 23:12:07 2026 */ +/* XDR specification modification time: Wed Mar 25 11:39:22 2026 */ #ifndef _LINUX_XDRGEN_NFS4_1_DECL_H#define _LINUX_XDRGEN_NFS4_1_DECL_H
@@ -32,4 +32,22 @@ bool xdrgen_decode_posixaceperm4(struct xdr_stream *xdr, posixaceperm4 *ptr);bool xdrgen_encode_posixaceperm4 (struct xdr_stream *xdr,const posixaceperm4 value); +bool xdrgen_decode_notify_remove4 (struct xdr_stream *xdr,struct notify_remove4 *ptr); +bool xdrgen_encode_notify_remove4 (struct xdr_stream *xdr,const struct notify_remove4 *value); + +bool xdrgen_decode_notify_add4 (struct xdr_stream *xdr,struct notify_add4 *ptr); +bool xdrgen_encode_notify_add4 (struct xdr_stream *xdr,const struct notify_add4 *value); + +bool xdrgen_decode_notify_attr4 (struct xdr_stream *xdr,struct notify_attr4 *ptr); +bool xdrgen_encode_notify_attr4 (struct xdr_stream *xdr,const struct notify_attr4 *value); + +bool xdrgen_decode_notify_rename4 (struct xdr_stream *xdr,struct notify_rename4 *ptr); +bool xdrgen_encode_notify_rename4 (struct xdr_stream *xdr,const struct notify_rename4 *value); + +bool xdrgen_decode_CB_NOTIFY4args (struct xdr_stream *xdr,struct CB_NOTIFY4args *ptr); +bool xdrgen_encode_CB_NOTIFY4args (struct xdr_stream *xdr,const struct CB_NOTIFY4args *value); + +bool xdrgen_decode_CB_NOTIFY4res (struct xdr_stream *xdr,struct CB_NOTIFY4res *ptr); +bool xdrgen_encode_CB_NOTIFY4res (struct xdr_stream *xdr,const struct CB_NOTIFY4res *value); +#endif /* _LINUX_XDRGEN_NFS4_1_DECL_H */
fs/nfsd/trace.h +1 -0
@@ -1677,6 +1677,7 @@ TRACE_EVENT(nfsd_cb_setup_err, { OP_CB_RECALL, "CB_RECALL" }, \ { OP_CB_LAYOUTRECALL, "CB_LAYOUTRECALL" }, \ { OP_CB_RECALL_ANY, "CB_RECALL_ANY" }, \ + { OP_CB_NOTIFY, "CB_NOTIFY" }, \ { OP_CB_NOTIFY_LOCK, "CB_NOTIFY_LOCK" }, \ { OP_CB_OFFLOAD, "CB_OFFLOAD" })
include/linux/nfs4.h +0 -127
133 lines not on this page · raw message
include/linux/sunrpc/xdrgen/nfs4_1.h +276 -4
333 lines not on this page · raw message
include/uapi/linux/nfs4.h +0 -2
@@ -17,11 +17,9 @@#include <linux/types.h> #define NFS4_BITMAP_SIZE 3 -#define NFS4_VERIFIER_SIZE 8#define NFS4_STATEID_SEQID_SIZE 4#define NFS4_STATEID_OTHER_SIZE 12#define NFS4_STATEID_SIZE (NFS4_STATEID_SEQID_SIZE + NFS4_STATEID_OTHER_SIZE) -#define NFS4_FHSIZE 128#define NFS4_MAXPATHLEN PATH_MAX#define NFS4_MAXNAMLEN NAME_MAX#define NFS4_OPAQUE_LIMIT 1024
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 02/20] nfsd: add protocol support for CB_NOTIFY
Quoted 141 lines · Jeff Layton
Documentation/sunrpc/xdr/nfs4_1.x +130
-2@@ -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,
Documentation/sunrpc/xdr/nfs4_1.x pragma header nfs4; · line 187
Quoted 10 lines
Documentation/sunrpc/xdr/nfs4_1.x +10
-0+ 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)
Quoted 79 lines
Documentation/sunrpc/xdr/nfs4_1.x +75
-0@@ -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 {
Documentation/sunrpc/xdr/nfs4_1.x const FATTR4_ACL_TRUEFORM = 89; · line 493
Quoted 10 lines
Documentation/sunrpc/xdr/nfs4_1.x +10
-0+ 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.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 3/20 nfs_common: add new NOTIFY4_* flags proposed in RFC8881bis
In reply to Jeff LaytonRFC8881bis adds some new flags to GET_DIR_DELEGATION that later patches will consume. In particular, Linux nfsd can't easily provide info about directory cookies and ordering. The new flags allow it to omit that information.
There is some risk here -- RFC8881bis is still a working group document, and has been for years. The changes to directory delegations have been stable for the last year or so however, so the hope is that those parts won't change (much).
--- Documentation/sunrpc/xdr/nfs4_1.x | 14 +++++++++++++- fs/nfsd/nfs4xdr_gen.c | 13 ++++++++++++- fs/nfsd/nfs4xdr_gen.h | 2 +- include/linux/sunrpc/xdrgen/nfs4_1.h | 13 ++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-)
Documentation/sunrpc/xdr/nfs4_1.x +13 -1
@@ -416,7 +416,19 @@ enum notify_type4 { NOTIFY4_REMOVE_ENTRY = 2, NOTIFY4_ADD_ENTRY = 3, NOTIFY4_RENAME_ENTRY = 4, - NOTIFY4_CHANGE_COOKIE_VERIFIER = 5 + NOTIFY4_CHANGE_COOKIE_VERIFIER = 5, + /* Proposed in RFC8881bis */ + NOTIFY4_GFLAG_EXTEND = 6, + NOTIFY4_AUFLAG_VALID = 7, + NOTIFY4_AUFLAG_USER = 8, + NOTIFY4_AUFLAG_GROUP = 9, + NOTIFY4_AUFLAG_OTHER = 10, + NOTIFY4_CHANGE_AUTH = 11, + NOTIFY4_CFLAG_ORDER = 12, + NOTIFY4_AUFLAG_GANOW = 13, + NOTIFY4_AUFLAG_GALATER = 14, + NOTIFY4_CHANGE_GA = 15, + NOTIFY4_CHANGE_AMASK = 16 }; /* Changed entry information. */
fs/nfsd/nfs4xdr_gen.c +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/nfs4_1.x -// XDR specification modification time: Wed Mar 25 11:39:22 2026 +// XDR specification modification time: Wed Mar 25 11:40:02 2026 #include <linux/sunrpc/svc.h>
@@ -590,6 +590,17 @@ xdrgen_decode_notify_type4(struct xdr_stream *xdr, notify_type4 *ptr)case NOTIFY4_ADD_ENTRY :case NOTIFY4_RENAME_ENTRY :case NOTIFY4_CHANGE_COOKIE_VERIFIER : +case NOTIFY4_GFLAG_EXTEND : +case NOTIFY4_AUFLAG_VALID : +case NOTIFY4_AUFLAG_USER : +case NOTIFY4_AUFLAG_GROUP : +case NOTIFY4_AUFLAG_OTHER : +case NOTIFY4_CHANGE_AUTH : +case NOTIFY4_CFLAG_ORDER : +case NOTIFY4_AUFLAG_GANOW : +case NOTIFY4_AUFLAG_GALATER : +case NOTIFY4_CHANGE_GA : +case NOTIFY4_CHANGE_AMASK :break ;default :return false;
fs/nfsd/nfs4xdr_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/nfs4_1.x */ -/* XDR specification modification time: Wed Mar 25 11:39:22 2026 */ +/* XDR specification modification time: Wed Mar 25 11:40:02 2026 */ #ifndef _LINUX_XDRGEN_NFS4_1_DECL_H#define _LINUX_XDRGEN_NFS4_1_DECL_H
include/linux/sunrpc/xdrgen/nfs4_1.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/nfs4_1.x */ -/* XDR specification modification time: Wed Mar 25 11:39:22 2026 */ +/* XDR specification modification time: Wed Mar 25 11:40:02 2026 */ #ifndef _LINUX_XDRGEN_NFS4_1_DEF_H#define _LINUX_XDRGEN_NFS4_1_DEF_H
@@ -377,6 +377,17 @@ enum notify_type4 {NOTIFY4_ADD_ENTRY =3 ,NOTIFY4_RENAME_ENTRY =4 ,NOTIFY4_CHANGE_COOKIE_VERIFIER =5 , +NOTIFY4_GFLAG_EXTEND =6 , +NOTIFY4_AUFLAG_VALID =7 , +NOTIFY4_AUFLAG_USER =8 , +NOTIFY4_AUFLAG_GROUP =9 , +NOTIFY4_AUFLAG_OTHER =10 , +NOTIFY4_CHANGE_AUTH =11 , +NOTIFY4_CFLAG_ORDER =12 , +NOTIFY4_AUFLAG_GANOW =13 , +NOTIFY4_AUFLAG_GALATER =14 , +NOTIFY4_CHANGE_GA =15 , + NOTIFY4_CHANGE_AMASK = 16, };typedef enum notify_type4 notify_type4 ;
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 4/20 nfsd: allow nfsd to get a dir lease with an ignore mask
In reply to Jeff LaytonWhen requesting a directory lease, enable the FL_IGN_DIR_* bits that correspond to the requested notification types.
In nfsd_get_dir_deleg(), gddr_notification[0] will ultimately represent the notifications that will be provided to the client. For now, that field is always set to 0. That will change once the upper layers are ready to start ignoring certain events.
--- fs/nfsd/nfs4state.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +23 -4
@@ -6119,7 +6119,22 @@ static bool nfsd4_cb_channel_good(struct nfs4_client *clp)return clp->cl_minorversion && clp->cl_cb_state ==NFSD4_CB_UNKNOWN ; } -static struct file_lease *nfs4_alloc_init_lease (struct nfs4_delegation *dp) +static unsigned int +nfsd_notify_to_ignore (u32 notify) +{ +unsigned int mask =0 ; + +if (notify &BIT (NOTIFY4_REMOVE_ENTRY )) + mask |=FL_IGN_DIR_DELETE ; +if (notify &BIT (NOTIFY4_ADD_ENTRY )) + mask |=FL_IGN_DIR_CREATE ; +if (notify &BIT (NOTIFY4_RENAME_ENTRY )) + mask |=FL_IGN_DIR_RENAME ; + +return mask; +} + +static struct file_lease *nfs4_alloc_init_lease (struct nfs4_delegation *dp,u32 notify) {struct file_lease *fl;
@@ -6127,7 +6142,7 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp)if (!fl)return NULL ; fl->fl_lmops = &nfsd_lease_mng_ops; - fl->c.flc_flags =FL_DELEG ; + fl->c.flc_flags =FL_DELEG |nfsd_notify_to_ignore (notify); fl->c.flc_type =deleg_is_read (dp->dl_type) ?F_RDLCK :F_WRLCK ; fl->c.flc_owner = (fl_owner_t )dp; fl->c.flc_pid = current->tgid;
@@ -6344,7 +6359,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,if (stp->st_stid.sc_export) dp->dl_stid.sc_export =exp_get (stp->st_stid.sc_export); - fl =nfs4_alloc_init_lease (dp); + fl =nfs4_alloc_init_lease (dp,0 );if (!fl) goto out_clnt_odstate;
@@ -9771,7 +9786,11 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, dp->dl_stid.sc_export =exp_get (cstate->current_fh.fh_export); - fl =nfs4_alloc_init_lease (dp); +/* +* NB: gddr_notification[0] represents the notifications that +* will be granted to the client +*/ + fl =nfs4_alloc_init_lease (dp, gdd->gddr_notification[0 ]);if (!fl) goto out_put_stid;
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 5/20 nfsd: update the fsnotify mark when setting or removing a dir delegation
In reply to Jeff LaytonAdd a new helper function that will update the mask on the nfsd_file's fsnotify_mark to be a union of all current directory delegations on an inode.
Call that when directory delegations are added or removed, since that can change what fsnotify events nfsd requires from the VFS layer.
The fsnotify_mark is shared by every nfsd_file open on the inode, so concurrent delegation adds and removes on the same directory can run nfsd_fsnotify_recalc_mask() in parallel. Because it reads the lease state and updates the mark in two separate locked sections, a recalc working from a stale snapshot of the lease list could clobber a concurrent update and leave the mark missing required events. Add an nfm_recalc_mutex to the nfsd_file_mark and hold it across the recalc to serialize callers.
--- fs/nfsd/filecache.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/filecache.h | 3 +++ fs/nfsd/nfs4state.c | 5 +++-- 3 files changed, 58 insertions(+), 2 deletions(-)
fs/nfsd/filecache.c +52 -0
@@ -192,6 +192,7 @@ nfsd_file_mark_find_or_create(struct inode *inode)fsnotify_init_mark (&new->nfm_mark, nfsd_file_fsnotify_group); new->nfm_mark.mask =FS_ATTRIB |FS_DELETE_SELF ;refcount_set (&new->nfm_ref,1 ); +mutex_init (&new->nfm_recalc_mutex); err =fsnotify_add_inode_mark (&new->nfm_mark, inode,0 );
@@ -1473,3 +1474,54 @@ int nfsd_file_cache_stats_show(struct seq_file *m, void *v)seq_printf (m,"mean age (ms): -\n" );return 0 ; } + +/** +* nfsd_fsnotify_recalc_mask - recalculate the fsnotify mask for a nfsd_file +* @nf: nfsd_file to recalculate the mask on +* +* When a directory nfsd_file has a delegation added or removed, that may +* change the events that nfsd requires from the VFS layer. This function +* recalculates the fsnotify mask based on the leases present. +*/ +void nfsd_fsnotify_recalc_mask (struct nfsd_file *nf) +{ +struct inode *inode =file_inode (nf->nf_file); +u32 lease_mask, set =0 , clear =0 ; +struct fsnotify_mark *mark; + +/* This is only needed when adding or removing dir delegs */ +if (!S_ISDIR (inode->i_mode) || !nf->nf_mark) +return ; + + mark = &nf->nf_mark->nfm_mark; + +/* +* The mark is shared by every nfsd_file on this inode, so concurrent +* delegation add/remove on the same directory can recalc it in +* parallel. Serialize the read of the lease state and the update of +* the mark so that a recalc working from a stale snapshot of the +* lease list can't clobber a concurrent recalc's update. +*/ +mutex_lock (&nf->nf_mark->nfm_recalc_mutex); + +/* Set up notifications for any ignored delegation events */ + lease_mask =inode_lease_ignore_mask (inode); + +if (lease_mask &FL_IGN_DIR_CREATE ) + set |=FS_CREATE |FS_MOVED_TO ; +else + clear |=FS_CREATE |FS_MOVED_TO ; + +if (lease_mask &FL_IGN_DIR_DELETE ) + set |=FS_DELETE |FS_MOVED_FROM ; +else + clear |=FS_DELETE |FS_MOVED_FROM ; + +if (lease_mask &FL_IGN_DIR_RENAME ) + set |=FS_RENAME ; +else + clear |=FS_RENAME ; + +fsnotify_modify_mark_mask (mark, set, clear); +mutex_unlock (&nf->nf_mark->nfm_recalc_mutex); +}
fs/nfsd/filecache.h +3 -0
@@ -26,6 +26,8 @@struct nfsd_file_mark {struct fsnotify_mark nfm_mark;refcount_t nfm_ref; +/* serializes nfsd_fsnotify_recalc_mask() against itself */ +struct mutex nfm_recalc_mutex; };/*
@@ -86,4 +88,5 @@ __be32 nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,__be32 nfsd_file_acquire_dir (struct svc_rqst *rqstp,struct svc_fh *fhp,struct nfsd_file **pnf);int nfsd_file_cache_stats_show (struct seq_file *m,void *v); +void nfsd_fsnotify_recalc_mask (struct nfsd_file *nf);#endif /* _FS_NFSD_FILECACHE_H */
fs/nfsd/nfs4state.c +3 -2
@@ -1255,6 +1255,7 @@ static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)nfsd4_finalize_deleg_timestamps (dp, nf->nf_file);kernel_setlease (nf->nf_file,F_UNLCK ,NULL , (void **)&dp); +nfsd_fsnotify_recalc_mask (nf);put_deleg_file (fp); }
@@ -9725,8 +9726,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,* @nf: nfsd_file opened on the directory * * Given a GET_DIR_DELEGATION request @gdd, attempt to acquire a delegation -* on the directory to which @nf refers. Note that this does not set up any -* sort of async notifications for the delegation. +* on the directory to which @nf refers. */ struct nfs4_delegation * nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,
@@ -9816,6 +9816,7 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,if (!status) {put_nfs4_file (fp); +nfsd_fsnotify_recalc_mask (nf);return dp; }
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 6/20 nfsd: make nfsd4_callback_ops->prepare operation bool return
In reply to Jeff LaytonFor a CB_NOTIFY operation, we need to stop processing the callback if an allocation fails. Change the ->prepare callback operation to return true if processing should continue, and false otherwise.
--- fs/nfsd/nfs4callback.c | 5 ++++- fs/nfsd/nfs4layouts.c | 3 ++- fs/nfsd/nfs4state.c | 6 ++++-- fs/nfsd/state.h | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-)
fs/nfsd/nfs4callback.c +4 -1
@@ -1786,7 +1786,10 @@ nfsd4_run_cb_work(struct work_struct *work)if (!test_and_clear_bit (NFSD4_CALLBACK_REQUEUE , &cb->cb_flags)) {if (cb->cb_ops && cb->cb_ops->prepare) - cb->cb_ops->prepare (cb); +if (!cb->cb_ops->prepare (cb)) { +nfsd41_destroy_cb (cb); +return ; + } } cb->cb_msg.rpc_cred = clp->cl_cb_cred;
fs/nfsd/nfs4layouts.c +2 -1
@@ -659,7 +659,7 @@ nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls, struct nfsd_file *file) } } -static void +static bool nfsd4_cb_layout_prepare (struct nfsd4_callback *cb) { struct nfs4_layout_stateid *ls =
@@ -668,6 +668,7 @@ nfsd4_cb_layout_prepare(struct nfsd4_callback *cb)mutex_lock (&ls->ls_mutex);nfs4_inc_and_copy_stateid (&ls->ls_recall_sid, &ls->ls_stid);mutex_unlock (&ls->ls_mutex); +return true; } static int
fs/nfsd/nfs4state.c +4 -2
@@ -357,12 +357,13 @@ remove_blocked_locks(struct nfs4_lockowner *lo) } } -static void +static bool nfsd4_cb_notify_lock_prepare (struct nfsd4_callback *cb) {struct nfsd4_blocked_lock *nbl =container_of (cb, struct nfsd4_blocked_lock, nbl_cb);locks_delete_block (&nbl->nbl_lock); +return true; } static int
@@ -5599,7 +5600,7 @@ bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, struct inode *inode)return timeo >0 ; } -static void nfsd4_cb_recall_prepare (struct nfsd4_callback *cb) +static bool nfsd4_cb_recall_prepare (struct nfsd4_callback *cb) {struct nfs4_delegation *dp =cb_to_delegation (cb); struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net,
@@ -5620,6 +5621,7 @@ static void nfsd4_cb_recall_prepare(struct nfsd4_callback *cb)list_add_tail (&dp->dl_recall_lru, &nn->del_recall_lru); }spin_unlock (&nn->deleg_lock); +return true; } static int nfsd4_cb_recall_done(struct nfsd4_callback *cb,
fs/nfsd/state.h +3 -3
@@ -98,9 +98,9 @@ struct nfsd4_callback { };struct nfsd4_callback_ops { -void (*prepare)(struct nfsd4_callback *); -int (*done)(struct nfsd4_callback *,struct rpc_task *); -void (*release)(struct nfsd4_callback *); +bool (*prepare)(struct nfsd4_callback *cb); +int (*done)(struct nfsd4_callback *cb,struct rpc_task *task); +void (*release)(struct nfsd4_callback *cb);uint32_t opcode; };
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 7/20 nfsd: add callback encoding and decoding linkages for CB_NOTIFY
In reply to Jeff LaytonAdd routines for encoding and decoding CB_NOTIFY messages. These call into the code generated by xdrgen to do the actual encoding and decoding.
For now, the encoder is a stub. Later patches will flesh out the payload encoding.
--- fs/nfsd/nfs4callback.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/state.h | 8 ++++++++ fs/nfsd/xdr4cb.h | 12 ++++++++++++ 3 files changed, 66 insertions(+)
fs/nfsd/nfs4callback.c +46 -0
@@ -887,6 +887,51 @@ static void encode_stateowner(struct xdr_stream *xdr, struct nfs4_stateowner *soxdr_encode_opaque (p, so->so_owner.data, so->so_owner.len); } +static void nfs4_xdr_enc_cb_notify (struct rpc_rqst *req, +struct xdr_stream *xdr, +const void *data) +{ +const struct nfsd4_callback *cb = data; +struct nfs4_cb_compound_hdr hdr = { + .ident =0 , + .minorversion = cb->cb_clp->cl_minorversion, + }; +struct CB_NOTIFY4args args = { }; + +WARN_ON_ONCE (hdr.minorversion ==0 ); + +encode_cb_compound4args (xdr, &hdr); +encode_cb_sequence4args (xdr, cb, &hdr); + +/* +* FIXME: get stateid and fh from delegation. Inline the cna_changes +* buffer, and zero it. +*/ +xdrgen_encode_CB_NOTIFY4args (xdr, &args); + + hdr.nops++; +encode_cb_nops (&hdr); +} + +static int nfs4_xdr_dec_cb_notify (struct rpc_rqst *rqstp, +struct xdr_stream *xdr, +void *data) +{ +struct nfsd4_callback *cb = data; +struct nfs4_cb_compound_hdr hdr; +int status; + + status =decode_cb_compound4res (xdr, &hdr); +if (unlikely (status)) +return status; + + status =decode_cb_sequence4res (xdr, cb); +if (unlikely (status || cb->cb_seq_status)) +return status; + +return decode_cb_op_status (xdr,OP_CB_NOTIFY , &cb->cb_status); +} +static void nfs4_xdr_enc_cb_notify_lock (struct rpc_rqst *req,struct xdr_stream *xdr,const void *data)
@@ -1048,6 +1093,7 @@ static const struct rpc_procinfo nfs4_cb_procedures[] = {#ifdef CONFIG_NFSD_PNFS PROC (CB_LAYOUT ,COMPOUND , cb_layout, cb_layout), #endif +PROC (CB_NOTIFY ,COMPOUND , cb_notify, cb_notify),PROC (CB_NOTIFY_LOCK ,COMPOUND , cb_notify_lock, cb_notify_lock),PROC (CB_OFFLOAD ,COMPOUND , cb_offload, cb_offload), PROC(CB_RECALL_ANY, COMPOUND, cb_recall_any, cb_recall_any),
fs/nfsd/state.h +8 -0
@@ -190,6 +190,13 @@ struct nfs4_cb_fattr {u64 ncf_cur_fsize; }; +/* +* FIXME: the current backchannel encoder can't handle a send buffer longer +* than a single page (see bc_malloc/bc_free). +*/ +#define NOTIFY4_EVENT_QUEUE_SIZE 3 +#define NOTIFY4_PAGE_ARRAY_SIZE 1 +/* * Represents a delegation stateid. The nfs4_client holds references to these * and they are put when it is being destroyed or when the delegation is
@@ -776,6 +783,7 @@ enum nfsd4_cb_op {NFSPROC4_CLNT_CB_NOTIFY_LOCK ,NFSPROC4_CLNT_CB_RECALL_ANY ,NFSPROC4_CLNT_CB_GETATTR , + NFSPROC4_CLNT_CB_NOTIFY, };/* Returns true iff a is later than b: */
fs/nfsd/xdr4cb.h +12 -0
@@ -33,6 +33,18 @@ cb_sequence_dec_sz + \ op_dec_sz) +#define NFS4_enc_cb_notify_sz (cb_compound_enc_hdr_sz + \ + cb_sequence_enc_sz + \ + 1 + enc_stateid_sz + \ + enc_nfs4_fh_sz + \ + 1 + \ + NOTIFY4_EVENT_QUEUE_SIZE * \ + (2 + (NFS4_OPAQUE_LIMIT >> 2))) + +#define NFS4_dec_cb_notify_sz (cb_compound_dec_hdr_sz + \ + cb_sequence_dec_sz + \ + op_dec_sz) +#define NFS4_enc_cb_notify_lock_sz (cb_compound_enc_hdr_sz + \ cb_sequence_enc_sz + \ 2 + 1 + \
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 8/20 nfsd: use RCU to protect fi_deleg_file
In reply to Jeff Laytonfi_deleg_file can be NULLed by put_deleg_file() when fi_delegees drops to zero during delegation teardown (e.g. DELEGRETURN). Concurrent accesses from workqueue callbacks -- such as CB_NOTIFY -- can dereference a NULL pointer if they race with this teardown.
Annotate fi_deleg_file with __rcu and convert all accessors to use proper RCU primitives:
- rcu_assign_pointer() / RCU_INIT_POINTER() for stores
- rcu_dereference_protected() for reads under fi_lock or where fi_delegees > 0 guarantees stability
This prepares for a subsequent patch that will use rcu_read_lock + rcu_dereference + nfsd_file_get to safely acquire a reference from the CB_NOTIFY callback path without holding fi_lock.
The error-path lease teardown in nfsd_get_dir_deleg() is one of these accessors, and it must drop the lease against fi_deleg_file->nf_file rather than this client's nf->nf_file. The lease's flc_file is fi_deleg_file (set in nfs4_alloc_init_lease()), which differs from nf when an earlier client already holds a delegation on the same directory. generic_delete_lease() matches on flc_file, so unlocking the wrong file would fail to remove the lease, leaking it on the inode and then freeing its owning stid underneath it -- a use-after-free once the leaked lease is later broken. Read fi_deleg_file there with rcu_dereference_protected() like the other accessors, and recalculate the fsnotify mask after dropping the lease to match the success path.
--- fs/nfsd/nfs4layouts.c | 7 ++++--- fs/nfsd/nfs4state.c | 51 ++++++++++++++++++++++++++++++++++----------------- fs/nfsd/state.h | 2 +- 3 files changed, 39 insertions(+), 21 deletions(-)
fs/nfsd/nfs4layouts.c +4 -3
@@ -248,12 +248,13 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate, NFSPROC4_CLNT_CB_LAYOUT);if (parent->sc_type ==SC_TYPE_DELEG ) { -spin_lock (&fp->fi_lock); - ls->ls_file =nfsd_file_get (fp->fi_deleg_file); -spin_unlock (&fp->fi_lock); +rcu_read_lock (); + ls->ls_file =nfsd_file_get (rcu_dereference (fp->fi_deleg_file)); +rcu_read_unlock (); }else { ls->ls_file =find_any_file (fp); } +if (!ls->ls_file) {nfs4_put_stid (stp);return NULL ;
fs/nfsd/nfs4state.c +34 -17
136 lines not on this page · raw message
fs/nfsd/state.h +1 -1
@@ -699,7 +699,7 @@ struct nfs4_file {*/ atomic_t fi_access[2 ];u32 fi_share_deny; -struct nfsd_file *fi_deleg_file; +struct nfsd_file __rcu *fi_deleg_file;struct nfsd_file *fi_rdeleg_file;int fi_delegees;struct knfsd_fh fi_fhandle;
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 9/20 nfsd: add data structures for handling CB_NOTIFY
In reply to Jeff LaytonAdd the data structures, allocation helpers, and callback operations needed for directory delegation CB_NOTIFY support:
- struct nfsd_notify_event: carries fsnotify events for CB_NOTIFY
- struct nfsd4_cb_notify: per-delegation state for notification handling
- Union dl_cb_fattr with dl_cb_notify in nfs4_delegation since a delegation is either a regular file delegation or a directory delegation, never both
Refactor alloc_init_deleg() into a common __alloc_init_deleg() base with a pluggable sc_free callback, and add alloc_init_dir_deleg() which allocates the page array and notify4 buffer needed for CB_NOTIFY encoding.
Add skeleton nfsd4_cb_notify_ops with done/release handlers that will be filled in when the notification path is wired up.
--- fs/nfsd/nfs4state.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++------ fs/nfsd/state.h | 47 +++++++++++++++++++- 2 files changed, 152 insertions(+), 16 deletions(-)
fs/nfsd/nfs4state.c +107 -14
@@ -126,6 +126,7 @@ static void free_session(struct nfsd4_session *);static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;static const struct nfsd4_callback_ops nfsd4_cb_getattr_ops; +static const struct nfsd4_callback_ops nfsd4_cb_notify_ops;static struct workqueue_struct *laundry_wq;
@@ -1123,29 +1124,31 @@ static void block_delegations(struct knfsd_fh *fh) }static struct nfs4_delegation * -alloc_init_deleg (struct nfs4_client *clp,struct nfs4_file *fp, -struct nfs4_clnt_odstate *odstate,u32 dl_type) +__alloc_init_deleg (struct nfs4_client *clp,struct nfs4_file *fp, +struct nfs4_clnt_odstate *odstate,u32 dl_type, +void (*sc_free)(struct nfs4_stid *)) {struct nfs4_delegation *dp;struct nfs4_stid *stid;long n; -dprintk ("NFSD alloc_init_deleg\n" ); +if (delegation_blocked (&fp->fi_fhandle)) +return NULL ; + n =atomic_long_inc_return (&num_delegations);if (n <0 || n > max_delegations) goto out_dec; -if (delegation_blocked (&fp->fi_fhandle)) - goto out_dec; - stid =nfs4_alloc_stid (clp, deleg_slab, nfs4_free_deleg); + + stid =nfs4_alloc_stid (clp, deleg_slab, sc_free);if (stid ==NULL ) goto out_dec; - dp =delegstateid (stid);/* * delegation seqid's are never incremented. The 4.1 special * meaning of seqid 0 isn't meaningful, really, but let's avoid -* 0 anyway just for consistency and use 1: +* 0 anyway just for consistency and use 1. */ + dp =delegstateid (stid); dp->dl_stid.sc_stateid.si_generation =1 ;INIT_LIST_HEAD (&dp->dl_perfile);INIT_LIST_HEAD (&dp->dl_perclnt);
@@ -1155,19 +1158,79 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp, dp->dl_type = dl_type; dp->dl_retries =1 ; dp->dl_recalled = false; -nfsd4_init_cb (&dp->dl_recall, dp->dl_stid.sc_client, - &nfsd4_cb_recall_ops,NFSPROC4_CLNT_CB_RECALL ); -nfsd4_init_cb (&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client, - &nfsd4_cb_getattr_ops,NFSPROC4_CLNT_CB_GETATTR ); - dp->dl_cb_fattr.ncf_file_modified = false;get_nfs4_file (fp); dp->dl_stid.sc_file = fp; +nfsd4_init_cb (&dp->dl_recall, dp->dl_stid.sc_client, + &nfsd4_cb_recall_ops,NFSPROC4_CLNT_CB_RECALL );return dp; out_dec:atomic_long_dec (&num_delegations);return NULL ; } +static struct nfs4_delegation * +alloc_init_deleg (struct nfs4_client *clp,struct nfs4_file *fp, +struct nfs4_clnt_odstate *odstate,u32 dl_type) +{ +struct nfs4_delegation *dp; + + dp =__alloc_init_deleg (clp, fp, odstate, dl_type, nfs4_free_deleg); +if (!dp) +return NULL ; + +nfsd4_init_cb (&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client, + &nfsd4_cb_getattr_ops,NFSPROC4_CLNT_CB_GETATTR ); + dp->dl_cb_fattr.ncf_file_modified = false; +return dp; +} + +static void nfs4_free_dir_deleg (struct nfs4_stid *stid) +{ +struct nfs4_delegation *dp =delegstateid (stid); +struct nfsd4_cb_notify *ncn = &dp->dl_cb_notify; +int i; + +for (i =0 ; i < ncn->ncn_evt_cnt; ++i) +nfsd_notify_event_put (ncn->ncn_evt[i]); +kfree (ncn->ncn_nf); +for (i =0 ; i <NOTIFY4_PAGE_ARRAY_SIZE ; i++) { +if (!ncn->ncn_pages[i]) +break ; +put_page (ncn->ncn_pages[i]); + } +nfs4_free_deleg (stid); +} + +static struct nfs4_delegation * +alloc_init_dir_deleg (struct nfs4_client *clp,struct nfs4_file *fp) +{ +struct nfs4_delegation *dp; +struct nfsd4_cb_notify *ncn; +int npages; + + dp =__alloc_init_deleg (clp, fp,NULL ,NFS4_OPEN_DELEGATE_READ , nfs4_free_dir_deleg); +if (!dp) +return NULL ; + + ncn = &dp->dl_cb_notify; + + npages =alloc_pages_bulk (GFP_KERNEL ,NOTIFY4_PAGE_ARRAY_SIZE , ncn->ncn_pages); +if (npages !=NOTIFY4_PAGE_ARRAY_SIZE ) { +nfs4_put_stid (&dp->dl_stid); +return NULL ; + } + + ncn->ncn_nf =kcalloc (NOTIFY4_EVENT_QUEUE_SIZE ,sizeof (*ncn->ncn_nf),GFP_KERNEL ); +if (!ncn->ncn_nf) { +nfs4_put_stid (&dp->dl_stid); +return NULL ; + } +spin_lock_init (&ncn->ncn_lock); +nfsd4_init_cb (&ncn->ncn_cb, dp->dl_stid.sc_client, + &nfsd4_cb_notify_ops,NFSPROC4_CLNT_CB_NOTIFY ); +return dp; +} +void nfs4_put_stid (struct nfs4_stid *s) {
@@ -3408,6 +3471,30 @@ nfsd4_cb_getattr_release(struct nfsd4_callback *cb)nfs4_put_stid (&dp->dl_stid); } +static int +nfsd4_cb_notify_done (struct nfsd4_callback *cb, +struct rpc_task *task) +{ +switch (task->tk_status) { +case -NFS4ERR_DELAY : +rpc_delay (task,2 *HZ ); +return 0 ; +default : +return 1 ; + } +} + +static void +nfsd4_cb_notify_release (struct nfsd4_callback *cb) +{ +struct nfsd4_cb_notify *ncn = + container_of(cb, struct nfsd4_cb_notify, ncn_cb); +struct nfs4_delegation *dp = + container_of(ncn, struct nfs4_delegation, dl_cb_notify); + +nfs4_put_stid (&dp->dl_stid); +} +static const struct nfsd4_callback_ops nfsd4_cb_recall_any_ops = { .done = nfsd4_cb_recall_any_done, .release = nfsd4_cb_recall_any_release,
@@ -3420,6 +3507,12 @@ static const struct nfsd4_callback_ops nfsd4_cb_getattr_ops = { .opcode = OP_CB_GETATTR, }; +static const struct nfsd4_callback_ops nfsd4_cb_notify_ops = { + .done = nfsd4_cb_notify_done, + .release = nfsd4_cb_notify_release, + .opcode =OP_CB_NOTIFY , +}; +static void nfs4_cb_getattr (struct nfs4_cb_fattr *ncf) { struct nfs4_delegation *dp =
@@ -9788,7 +9881,7 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,/* Try to set up the lease */ status = -ENOMEM ; - dp =alloc_init_deleg (clp, fp,NULL ,NFS4_OPEN_DELEGATE_READ ); + dp =alloc_init_dir_deleg (clp, fp);if (!dp) goto out_delegees;if (cstate->current_fh.fh_export)
fs/nfsd/state.h +45 -2
59 lines not on this page · raw message
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 10/20 nfsd: add notification handlers for dir events
In reply to Jeff LaytonAdd the necessary parts to accept a fsnotify callback for directory change event and create a CB_NOTIFY request for it. When a dir nfsd_file is created set a handle_event callback to handle the notification.
Use that to allocate a nfsd_notify_event object and then hand off a reference to each delegation's CB_NOTIFY. If anything fails along the way, recall any affected delegations.
--- fs/nfsd/filecache.c | 70 ++++++++--- fs/nfsd/nfs4callback.c | 54 ++++++++- fs/nfsd/nfs4state.c | 322 +++++++++++++++++++++++++++++++++++++++++++++---- fs/nfsd/nfs4xdr.c | 117 ++++++++++++++++++ fs/nfsd/state.h | 20 ++- fs/nfsd/trace.h | 23 ++++ fs/nfsd/xdr4.h | 3 + 7 files changed, 564 insertions(+), 45 deletions(-)
fs/nfsd/filecache.c +54 -16
@@ -78,6 +78,7 @@ static struct kmem_cache *nfsd_file_mark_slab;static struct list_lru nfsd_file_lru;static unsigned long nfsd_file_flags;static struct fsnotify_group *nfsd_file_fsnotify_group; +static struct fsnotify_group *nfsd_dir_fsnotify_group;static struct delayed_work nfsd_filecache_laundrette;static struct rhltable nfsd_file_rhltable____cacheline_aligned_in_smp ;
@@ -153,7 +154,7 @@ static void nfsd_file_mark_put(struct nfsd_file_mark *nfm) {if (refcount_dec_and_test (&nfm->nfm_ref)) { -fsnotify_destroy_mark (&nfm->nfm_mark, nfsd_file_fsnotify_group); +fsnotify_destroy_mark (&nfm->nfm_mark, nfm->nfm_mark.group);fsnotify_put_mark (&nfm->nfm_mark); } }
@@ -161,35 +162,37 @@ nfsd_file_mark_put(struct nfsd_file_mark *nfm)static struct nfsd_file_mark *nfsd_file_mark_find_or_create (struct inode *inode) { -int err; -struct fsnotify_mark *mark;struct nfsd_file_mark *nfm =NULL , *new; +struct fsnotify_group *group; +struct fsnotify_mark *mark; +int err; + + group =S_ISDIR (inode->i_mode) ? nfsd_dir_fsnotify_group : nfsd_file_fsnotify_group; do { - fsnotify_group_lock(nfsd_file_fsnotify_group); - mark = fsnotify_find_inode_mark(inode, - nfsd_file_fsnotify_group); + fsnotify_group_lock(group); + mark = fsnotify_find_inode_mark(inode, group); if (mark) { nfm = nfsd_file_mark_get(container_of(mark, struct nfsd_file_mark, nfm_mark)); - fsnotify_group_unlock(nfsd_file_fsnotify_group); + fsnotify_group_unlock(group); if (nfm) { fsnotify_put_mark(mark); break; } /* Avoid soft lockup race with nfsd_file_mark_put() */ - fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group); + fsnotify_destroy_mark(mark, group); fsnotify_put_mark(mark); } else { - fsnotify_group_unlock(nfsd_file_fsnotify_group); + fsnotify_group_unlock(group); } /* allocate a new nfm */ new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL); if (!new) return NULL; - fsnotify_init_mark(&new->nfm_mark, nfsd_file_fsnotify_group); + fsnotify_init_mark(&new->nfm_mark, group); new->nfm_mark.mask = FS_ATTRIB|FS_DELETE_SELF; refcount_set(&new->nfm_ref, 1); mutex_init(&new->nfm_recalc_mutex);
@@ -830,12 +833,36 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask,return 0 ; } +#ifdef CONFIG_NFSD_V4 +static int +nfsd_dir_fsnotify_handle_event (struct fsnotify_group *group,u32 mask, +const void *data,int data_type,struct inode *dir, +const struct qstr *name,u32 cookie, +struct fsnotify_iter_info *iter_info) +{ +return nfsd_handle_dir_event (mask, dir, data, data_type, name); +} +#else +static int +nfsd_dir_fsnotify_handle_event (struct fsnotify_group *group,u32 mask, +const void *data,int data_type,struct inode *dir, +const struct qstr *name,u32 cookie, +struct fsnotify_iter_info *iter_info) +{ +return 0 ; +} +#endif static const struct fsnotify_ops nfsd_file_fsnotify_ops = { .handle_inode_event = nfsd_file_fsnotify_handle_event, .free_mark = nfsd_file_mark_free, }; +static const struct fsnotify_ops nfsd_dir_fsnotify_ops = { + .handle_event = nfsd_dir_fsnotify_handle_event, + .free_mark = nfsd_file_mark_free, +}; +int nfsd_file_cache_init (void ) {
@@ -887,8 +914,7 @@ nfsd_file_cache_init(void) goto out_shrinker; } - nfsd_file_fsnotify_group =fsnotify_alloc_group (&nfsd_file_fsnotify_ops, -0 ); + nfsd_file_fsnotify_group =fsnotify_alloc_group (&nfsd_file_fsnotify_ops,0 );if (IS_ERR (nfsd_file_fsnotify_group)) {pr_err ("nfsd: unable to create fsnotify group: %ld\n" ,PTR_ERR (nfsd_file_fsnotify_group));
@@ -897,11 +923,23 @@ nfsd_file_cache_init(void) goto out_notifier; } + nfsd_dir_fsnotify_group =fsnotify_alloc_group (&nfsd_dir_fsnotify_ops,0 ); +if (IS_ERR (nfsd_dir_fsnotify_group)) { +pr_err ("nfsd: unable to create fsnotify group: %ld\n" , +PTR_ERR (nfsd_dir_fsnotify_group)); + ret =PTR_ERR (nfsd_dir_fsnotify_group); + nfsd_dir_fsnotify_group =NULL ; + goto out_notify_group; + } +INIT_DELAYED_WORK (&nfsd_filecache_laundrette, nfsd_file_gc_worker); out:if (ret)clear_bit (NFSD_FILE_CACHE_UP , &nfsd_file_flags);return ret; +out_notify_group: +fsnotify_put_group (nfsd_file_fsnotify_group); + nfsd_file_fsnotify_group =NULL ; out_notifier:lease_unregister_notifier (&nfsd_file_lease_notifier); out_shrinker:
@@ -1019,6 +1057,8 @@ nfsd_file_cache_shutdown(void)rcu_barrier ();fsnotify_put_group (nfsd_file_fsnotify_group); nfsd_file_fsnotify_group =NULL ; +fsnotify_put_group (nfsd_dir_fsnotify_group); + nfsd_dir_fsnotify_group =NULL ;kmem_cache_destroy (nfsd_file_slab); nfsd_file_slab =NULL ;fsnotify_wait_marks_destroyed ();
@@ -1223,10 +1263,8 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct net *net, open_file:trace_nfsd_file_alloc (nf); -if (type ==S_IFREG ) - nf->nf_mark =nfsd_file_mark_find_or_create (inode); - -if (type !=S_IFREG || nf->nf_mark) { + nf->nf_mark =nfsd_file_mark_find_or_create (inode); +if (nf->nf_mark) {if (file && (file->f_mode &FMODE_OPENED )) {get_file (file); nf->nf_file = file;
fs/nfsd/nfs4callback.c +50 -4
80 lines not on this page · raw message
fs/nfsd/nfs4state.c +299 -23
368 lines not on this page · raw message
fs/nfsd/nfs4xdr.c +117 -0
123 lines not on this page · raw message
fs/nfsd/state.h +18 -2
@@ -201,10 +201,23 @@ struct nfsd_notify_event {refcount_t ne_ref;// refcount u32 ne_mask;// FS_* mask from fsnotify callback struct dentry *ne_dentry;// dentry reference to target -u32 ne_namelen;// length of ne_name -char ne_name[];// name of dentry being changed +struct inode *ne_target;// inode overwritten by rename, or NULL +u32 ne_namelen;// length of ne_name (old name for a rename) +u32 ne_newnamelen;// length of new name (rename only), else 0 +char ne_name[];// entry name, then new name (rename only) }; +/* +* For a rename, the new name is snapshotted at event-alloc time and stored +* immediately after the (NUL-terminated) old name in ne_name[]. ne_dentry can +* be renamed again before the CB_NOTIFY work runs, so the new name must not be +* read from the live dentry at encode time. +*/ +static inline char *nfsd_notify_event_newname (struct nfsd_notify_event *ne) +{ +return ne->ne_name + ne->ne_namelen +1 ; +} +static inline struct nfsd_notify_event *nfsd_notify_event_get (struct nfsd_notify_event *ne) {refcount_inc (&ne->ne_ref);
@@ -214,6 +227,7 @@ static inline struct nfsd_notify_event *nfsd_notify_event_get(struct nfsd_notifystatic inline void nfsd_notify_event_put (struct nfsd_notify_event *ne) {if (refcount_dec_and_test (&ne->ne_ref)) { +iput (ne->ne_target);dput (ne->ne_dentry);kfree (ne); }
@@ -901,6 +915,8 @@ void nfsd_update_cmtime_attr(struct file *f, unsigned int flags);extern struct nfs4_client_reclaim *nfs4_client_to_reclaim (struct xdr_netobj name,struct xdr_netobj princhash,struct nfsd_net *nn);extern bool nfs4_has_reclaimed_state (struct xdr_netobj name,struct nfsd_net *nn); +int nfsd_handle_dir_event (u32 mask,const struct inode *dir,const void *data, +int data_type,const struct qstr *name);void put_nfs4_file (struct nfs4_file *fi); extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
fs/nfsd/trace.h +23 -0
@@ -12,6 +12,7 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/xprt.h> #include <trace/misc/fs.h> +#include <trace/misc/fsnotify.h> #include <trace/misc/nfs.h> #include <trace/misc/sunrpc.h>
@@ -1377,6 +1378,28 @@ TRACE_EVENT(nfsd_file_fsnotify_handle_event, __entry->nlink, __entry->mode, __entry->mask) ); +TRACE_EVENT (nfsd_handle_dir_event, + TP_PROTO(u32 mask, const struct inode *dir, const struct qstr *name), +TP_ARGS (mask, dir, name), +TP_STRUCT__entry ( + __field(u32, mask) + __field(dev_t, s_dev) + __field(u64, i_ino) +__string_len (name, name ? name->name :NULL , + name ? name->len :0 ) + ), +TP_fast_assign ( + __entry->mask = mask; + __entry->s_dev = dir ? dir->i_sb->s_dev : 0; + __entry->i_ino = dir ? dir->i_ino : 0; + __assign_str(name); + ), +TP_printk ("inode=0x%x:0x%x:0x%llx mask=%s name=%s" , +MAJOR (__entry->s_dev),MINOR (__entry->s_dev), + __entry->i_ino,show_fsnotify_mask (__entry->mask), +__get_str (name)) +); + DECLARE_EVENT_CLASS(nfsd_file_gc_class, TP_PROTO( const struct nfsd_file *nf
fs/nfsd/xdr4.h +3 -0
@@ -970,6 +970,9 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, u32 *bmval, struct svc_rqst *, int ignore_crossmnt); +u8 *nfsd4_encode_notify_event (struct xdr_stream *xdr,struct nfsd_notify_event *nne, +struct nfs4_delegation *dd,struct nfsd_file *nf, +u32 *notify_mask);extern __be32 nfsd4_setclientid (struct svc_rqst *rqstp,struct nfsd4_compound_state *,union nfsd4_op_u *u); extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 10/20] nfsd: add notification handlers for dir events
Quoted 25 lines · Jeff Layton
Add the necessary parts to accept a fsnotify callback for directory change event and create a
CB_NOTIFYrequest for it. When a dirnfsd_fileis created set ahandle_eventcallback to handle the notification.Use that to allocate a
nfsd_notify_eventobject and then hand off a reference to each delegation'sCB_NOTIFY. If anything fails along the way, recall any affected delegations.Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/nfs4callback.c +3
-2@@ -904,13 +908,45 @@ static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req,encode_cb_sequence4args (xdr, cb, &hdr);/* -* FIXME: get stateid and fh from delegation. Inline the cna_changes -* buffer, and zero it. +* nfsd4_cb_notify_prepare() sized the payload against a single page, +* but did not account for the compound, sequence, stateid, and +* filehandle encoded here. If the variable-length encode overflows the
fs/nfsd/nfs4callback.c static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req, · line 922
Quoted 10 lines
fs/nfsd/nfs4callback.c +8
-1+* backchannel send buffer, roll back to before the operation so that a +* truncated CB_NOTIFY is never placed on the wire. */ -xdrgen_encode_CB_NOTIFY4args (xdr, &args); + start =xdr_stream_pos (xdr); + + p =xdr_reserve_space (xdr,4 ); +if (!p) + goto out_err; + *p =cpu_to_be32 (OP_CB_NOTIFY );
Please use xdr_stream_encode_u32 for this purpose.
Quoted 15 lines
fs/nfsd/nfs4callback.c +12
-0+ + args.cna_stateid.seqid = dp->dl_stid.sc_stateid.si_generation; +memcpy (&args.cna_stateid.other, &dp->dl_stid.sc_stateid.si_opaque, +ARRAY_SIZE (args.cna_stateid.other)); + args.cna_fh.len = dp->dl_stid.sc_file->fi_fhandle.fh_size; + args.cna_fh.data = dp->dl_stid.sc_file->fi_fhandle.fh_raw; + args.cna_changes.count = ncn->ncn_nf_cnt; + args.cna_changes.element = ncn->ncn_nf; +if (!xdrgen_encode_CB_NOTIFY4args (xdr, &args)) + goto out_err; hdr.nops++;encode_cb_nops (&hdr); +return ; +
fs/nfsd/nfs4callback.c static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req, · line 947
Quoted 10 lines
fs/nfsd/nfs4callback.c +10
-0+out_err: +/* +* Drop the CB_NOTIFY op and emit a valid CB_SEQUENCE-only compound so +* the client still advances its slot. Flag the failure so the done +* handler recalls the delegation and the missed notification is not +* silently lost. The flag is written here in the transmit path and read +* in the done handler; the two are serialized phases of the same +* rpc_task, so no additional barrier is needed. +*/ + ncn->ncn_encode_err = true;
This flag is zeroed only once, at allocation time in alloc_init_dir_deleg(). It is never cleared in nfsd4_cb_notify_prepare().
Since nfsd4_cb_notify_release() can requeue the callback (via nfsd4_run_cb_notify) when events arrive while a callback is in flight, ->prepare may encode cleanly and return true, but nfsd4_cb_notify_done() still observes the stale ncn_encode_err == true and calls nfsd_break_one_deleg() -- discarding a good notification and recalling the delegation unnecessarily.
Quoted 27 lines
fs/nfsd/nfs4callback.c +2
-0+xdr_truncate_encode (xdr, start); +encode_cb_nops (&hdr); } static int nfs4_xdr_dec_cb_notify(struct rpc_rqst *rqstp,fs/nfsd/nfs4state.c +12
-0@@ -3471,19 +3472,146 @@ nfsd4_cb_getattr_release(struct nfsd4_callback *cb)nfs4_put_stid (&dp->dl_stid); } +static void nfsd_break_one_deleg (struct nfs4_delegation *dp) +{ +bool queued; + +if (test_and_set_bit (NFSD4_CALLBACK_RUNNING , &dp->dl_recall.cb_flags)) +return ; + +/* +* We're assuming the state code never drops its reference +* without first removing the lease. Since we're in this lease +* callback (and since the lease code is serialized by the +* flc_lock) we know the server hasn't removed the lease yet, and
fs/nfsd/nfs4state.c nfsd4_cb_getattr_release(struct nfsd4_callback *cb) · line 3496
Quoted 10 lines
fs/nfsd/nfs4state.c +10
-0+* we know it's safe to take a reference. +*/ +refcount_inc (&dp->dl_stid.sc_count); + queued =nfsd4_run_cb (&dp->dl_recall); +WARN_ON_ONCE (!queued); +if (!queued) { +refcount_dec (&dp->dl_stid.sc_count); +clear_bit (NFSD4_CALLBACK_RUNNING , &dp->dl_recall.cb_flags); + } +}
nfsd_break_one_deleg() does an unconditional refcount_inc(&dp->dl_stid.sc_count), and its comment justifies this with "the lease code is serialized by the flc_lock." That invariant holds when called from nfsd_break_deleg_cb() under flc_lock, but nfsd4_cb_notify_prepare() runs on a workqueue WITHOUT flc_lock. Itsout_recall: path calls nfsd_break_one_deleg(dp)
directly. The delegation can be concurrently destroyed with sc_count already at zero, making this an inc-from-zero.
The dispatch path nfsd4_run_cb_notify already does this correctly with refcount_inc_not_zero. The out_recall path needs the same guard (skip the recall / bail if the refcount is already zero).
I notice that the last unapplied patch ("nfsd: add
support to CB_NOTIFY for dir attribute changes") rewrites the guard "if (count > NOTIFY4_EVENT_QUEUE_SIZE)" into "if (count > limit)" with limit = NOTIFY4_EVENT_QUEUE_SIZE - 1 when NOTIFY4_CHANGE_DIR_ATTRS is requested. That turns the previously-dead overflow branch into a live, routine path to out_recall, which adds another normal-operation route into this unlocked recall.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerRe: [PATCH v6 10/20] nfsd: add notification handlers for dir events
Quoted 30 lines · Chuck Lever
Quoted 29 lines · Jeff Layton
Add the necessary parts to accept a fsnotify callback for directory change event and create a
CB_NOTIFYrequest for it. When a dirnfsd_fileis created set ahandle_eventcallback to handle the notification.Use that to allocate a
nfsd_notify_eventobject and then hand off a reference to each delegation'sCB_NOTIFY. If anything fails along the way, recall any affected delegations.Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/nfs4callback.c +5
-3@@ -904,13 +908,45 @@ static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req,encode_cb_sequence4args (xdr, cb, &hdr);/* -* FIXME: get stateid and fh from delegation. Inline the cna_changes -* buffer, and zero it. +* nfsd4_cb_notify_prepare() sized the payload against a single page, +* but did not account for the compound, sequence, stateid, and +* filehandle encoded here. If the variable-length encode overflows the +* backchannel send buffer, roll back to before the operation so that a +* truncated CB_NOTIFY is never placed on the wire. */ -xdrgen_encode_CB_NOTIFY4args (xdr, &args);
Quoted 9 lines
fs/nfsd/nfs4callback.c static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req, · line 922
Quoted 6 lines
fs/nfsd/nfs4callback.c +6
-0+ start =xdr_stream_pos (xdr); + + p =xdr_reserve_space (xdr,4 ); +if (!p) + goto out_err; + *p =cpu_to_be32 (OP_CB_NOTIFY );Please use
xdr_stream_encode_u32for this purpose.
Ok
Quoted 30 lines
Quoted 16 lines
fs/nfsd/nfs4callback.c +12
-0+ + args.cna_stateid.seqid = dp->dl_stid.sc_stateid.si_generation; +memcpy (&args.cna_stateid.other, &dp->dl_stid.sc_stateid.si_opaque, +ARRAY_SIZE (args.cna_stateid.other)); + args.cna_fh.len = dp->dl_stid.sc_file->fi_fhandle.fh_size; + args.cna_fh.data = dp->dl_stid.sc_file->fi_fhandle.fh_raw; + args.cna_changes.count = ncn->ncn_nf_cnt; + args.cna_changes.element = ncn->ncn_nf; +if (!xdrgen_encode_CB_NOTIFY4args (xdr, &args)) + goto out_err; hdr.nops++;encode_cb_nops (&hdr); +return ; +fs/nfsd/nfs4callback.c static void nfs4_xdr_enc_cb_notify(struct rpc_rqst *req, · line 947
Quoted 10 lines
fs/nfsd/nfs4callback.c +10
-0+out_err: +/* +* Drop the CB_NOTIFY op and emit a valid CB_SEQUENCE-only compound so +* the client still advances its slot. Flag the failure so the done +* handler recalls the delegation and the missed notification is not +* silently lost. The flag is written here in the transmit path and read +* in the done handler; the two are serialized phases of the same +* rpc_task, so no additional barrier is needed. +*/ + ncn->ncn_encode_err = true;This flag is zeroed only once, at allocation time in
alloc_init_dir_deleg(). It is never cleared innfsd4_cb_notify_prepare().
Quoted 7 lines
Since
nfsd4_cb_notify_release()can requeue the callback (vianfsd4_run_cb_notify) when events arrive while a callback is in flight, ->prepare may encode cleanly and return true, butnfsd4_cb_notify_done()still observes the stalencn_encode_err== true and callsnfsd_break_one_deleg()-- discarding a good notification and recalling the delegation unnecessarily.
Ok, so we need to reset this in ->prepare.
Quoted 52 lines
Quoted 28 lines
fs/nfsd/nfs4callback.c +2
-0+xdr_truncate_encode (xdr, start); +encode_cb_nops (&hdr); } static int nfs4_xdr_dec_cb_notify(struct rpc_rqst *rqstp,fs/nfsd/nfs4state.c +12
-0@@ -3471,19 +3472,146 @@ nfsd4_cb_getattr_release(struct nfsd4_callback *cb)nfs4_put_stid (&dp->dl_stid); } +static void nfsd_break_one_deleg (struct nfs4_delegation *dp) +{ +bool queued; + +if (test_and_set_bit (NFSD4_CALLBACK_RUNNING , &dp->dl_recall.cb_flags)) +return ; + +/* +* We're assuming the state code never drops its reference +* without first removing the lease. Since we're in this lease +* callback (and since the lease code is serialized by the +* flc_lock) we know the server hasn't removed the lease yet, and fs/nfsd/nfs4state.c nfsd4_cb_getattr_release(struct nfsd4_callback *cb) · line 3496
Quoted 10 lines
fs/nfsd/nfs4state.c +10
-0+* we know it's safe to take a reference. +*/ +refcount_inc (&dp->dl_stid.sc_count); + queued =nfsd4_run_cb (&dp->dl_recall); +WARN_ON_ONCE (!queued); +if (!queued) { +refcount_dec (&dp->dl_stid.sc_count); +clear_bit (NFSD4_CALLBACK_RUNNING , &dp->dl_recall.cb_flags); + } +}
nfsd_break_one_deleg()does an unconditionalrefcount_inc(&dp->dl_stid.sc_count), and its comment justifies this with "the lease code is serialized by theflc_lock." That invariant holds when called fromnfsd_break_deleg_cb()underflc_lock, butnfsd4_cb_notify_prepare()runs on a workqueue WITHOUTflc_lock. Itsout_recall: path callsnfsd_break_one_deleg(dp)
directly. The delegation can be concurrently destroyed withsc_countalready at zero, making this an inc-from-zero.The dispatch path
nfsd4_run_cb_notifyalready does this correctly withrefcount_inc_not_zero. Theout_recallpath needs the same guard (skip the recall / bail if the refcount is already zero).
Quoted 8 lines
I notice that the last unapplied patch ("nfsd: add
support toCB_NOTIFYfor dir attribute changes") rewrites the guard "if (count >NOTIFY4_EVENT_QUEUE_SIZE)" into "if (count > limit)" with limit =NOTIFY4_EVENT_QUEUE_SIZE- 1 whenNOTIFY4_CHANGE_DIR_ATTRSis requested. That turns the previously-dead overflow branch into a live, routine path toout_recall, which adds another normal-operation route into this unlocked recall.
This wart has been there a long time, and we just papered over it with the lock.
I think we need to do a refcount_inc_not_zero() in nfsd_break_one_deleg() and just return without queuing the callback if it's already at 0. That means that the recall is racing with the lease teardown, so I think the right thing to do is to not send the recall in that case.
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v6 11/20 nfsd: apply the notify mask to the delegation when requested
In reply to Jeff LaytonIf the client requests a directory delegation with notifications enabled, set the appropriate return mask in gddr_notification[0]. This will ensure the lease acquisition sets the appropriate ignore mask.
If the client doesn't set NOTIFY4_GFLAG_EXTEND, then don't offer any notifications, as nfsd won't provide directory offset information, and "classic" notifications require them.
--- fs/nfsd/nfs4proc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/nfsd/nfs4proc.c +12 -0
@@ -2530,12 +2530,18 @@ nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return status == nfserr_same ? nfs_ok : status; } +#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_REMOVE_ENTRY) | \ + BIT(NOTIFY4_ADD_ENTRY) | \ + BIT(NOTIFY4_RENAME_ENTRY) | \ + BIT(NOTIFY4_GFLAG_EXTEND)) +static __be32 nfsd4_get_dir_delegation (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u) {struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; +u32 requested = gdd->gdda_notification_types[0 ];struct nfs4_delegation *dd;struct nfsd_file *nf;__be32 status;
@@ -2544,6 +2550,12 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp,if (status != nfs_ok)return status; +/* No notifications if you don't set NOTIFY4_GFLAG_EXTEND! */ +if (!(requested &BIT (NOTIFY4_GFLAG_EXTEND ))) + requested =0 ; + + gdd->gddr_notification[0 ] = requested &SUPPORTED_NOTIFY_MASK ; +/* * RFC 8881, section 18.39.3 says: *
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 11/20] nfsd: apply the notify mask to the delegation when requested
Quoted 41 lines · Jeff Layton
If the client requests a directory delegation with notifications enabled, set the appropriate return mask in gddr_notification[0]. This will ensure the lease acquisition sets the appropriate ignore mask.
If the client doesn't set
NOTIFY4_GFLAG_EXTEND, then don't offer any notifications, as nfsd won't provide directory offset information, and "classic" notifications require them.Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4proc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)fs/nfsd/nfs4proc.c +6
-0@@ -2530,12 +2530,18 @@ nfsd4_verify(struct svc_rqst *rqstp, structnfsd4_compound_state *cstate, return status == nfserr_same ? nfs_ok : status; } +#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_REMOVE_ENTRY) | \ + BIT(NOTIFY4_ADD_ENTRY) | \ + BIT(NOTIFY4_RENAME_ENTRY) | \ + BIT(NOTIFY4_GFLAG_EXTEND)) +static __be32 nfsd4_get_dir_delegation (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u) {struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; +u32 requested = gdd->gdda_notification_types[0 ];struct nfs4_delegation *dd;struct nfsd_file *nf;fs/nfsd/nfs4proc.c +0
-0__be32 status;@@ -2544,6 +2550,12 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp,if (status != nfs_ok)return status;
fs/nfsd/nfs4proc.c nfsd4_get_dir_delegation(struct svc_rqst *rqstp, · line 2561
Quoted 10 lines
fs/nfsd/nfs4proc.c +6
-0+/* No notifications if you don't set NOTIFY4_GFLAG_EXTEND! */ +if (!(requested &BIT (NOTIFY4_GFLAG_EXTEND ))) + requested =0 ; + + gdd->gddr_notification[0 ] = requested &SUPPORTED_NOTIFY_MASK ; +/* * RFC 8881, section 18.39.3 says: *
When a client requests NOTIFY4_GFLAG_EXTEND | NOTIFY4_CFLAG_ORDER plus ADD/REMOVE/RENAME, the assignment still grants the content notification bits because it only requires GFLAG_EXTEND. The rest of NFSD's CB_NOTIFY encoder does not store that order-aware request and emits zero/absent cookie and previous-entry information, which is only safe for order-unaware clients.
An order-aware client can then keep an ordered directory cache from unusable notifications instead of having the delegation recalled.
The bis draft requires order info for order-aware clients, or recall:
- 27.4.5 (REMOVE): "If the client is order-aware, the server will send the cookie value as part of this."
- 16.2.13: order-aware == NOTIFY4_CFLAG_ORDER set OR NOTIFY4_GFLAG_EXTEND reset.
- 16.2.11.3: "If the client is concerned with entry order and these notifications ... cannot be sent for any other reason, then the delegation is recalled."
This patch's own first rule (drop everything when GFLAG_EXTEND is reset) is exactly the order-aware -> no-notifications principle for legacy RFC8881 clients. It misses the parallel case:GFLAG_EXTEND set PLUS CFLAG_ORDER set is also order-aware.
This finding is latent when this patch is first applied, but the NFSD's negotiation is incorrect for any future order-aware client.
I don't see this issue addressed by a subsequent patch in this series.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 12/20 nfsd: add helper to marshal a fattr4 from completed args
In reply to Jeff LaytonBreak the loop that encodes the actual attr_vals field into a separate function.
--- fs/nfsd/nfs4xdr.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-)
fs/nfsd/nfs4xdr.c +25 -19
@@ -3895,6 +3895,22 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {#endif }; +static __be32 +nfsd4_encode_attr_vals (struct xdr_stream *xdr,u32 *attrmask,struct nfsd4_fattr_args *args) +{ +DECLARE_BITMAP (attr_bitmap,ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops)); +unsigned long bit; +__be32 status; + +bitmap_from_arr32 (attr_bitmap, attrmask,ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops)); +for_each_set_bit (bit, attr_bitmap,ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops)) { + status = nfsd4_enc_fattr4_encode_ops[bit](xdr, args); +if (status != nfs_ok) +return status; + } +return nfs_ok; +} +/* * Note: @fhp can be NULL; in this case, we might have to compose the filehandle * ourselves. @case_cache is NULL for callers that encode a single dentry
@@ -3908,7 +3924,6 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,int ignore_crossmnt, struct nfsd_case_attrs_cache *case_cache) { -DECLARE_BITMAP (attr_bitmap ,ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops )); struct nfs4_delegation *dp = NULL;struct nfsd4_fattr_args args;struct svc_fh *tempfh =NULL ;
@@ -3923,7 +3938,6 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, .mnt = exp->ex_path.mnt, .dentry = dentry, }; -unsigned long bit;WARN_ON_ONCE (bmval[1 ] &NFSD_WRITEONLY_ATTRS_WORD1 );WARN_ON_ONCE (!nfsd_attrs_supported (minorversion, bmval));
@@ -4137,27 +4151,22 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ /* attrmask */ - status =nfsd4_encode_bitmap4 (xdr, attrmask[0 ], attrmask[1 ], - attrmask[2 ]); + status =nfsd4_encode_bitmap4 (xdr, attrmask[0 ], attrmask[1 ], attrmask[2 ]);if (status) goto out;/* attr_vals */ attrlen_offset = xdr->buf->len; -if (unlikely (!xdr_reserve_space (xdr,XDR_UNIT ))) - goto out_resource; -bitmap_from_arr32 (attr_bitmap, attrmask, -ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops)); -for_each_set_bit (bit, attr_bitmap, -ARRAY_SIZE (nfsd4_enc_fattr4_encode_ops)) { - status = nfsd4_enc_fattr4_encode_ops[bit](xdr, &args); -if (status != nfs_ok) - goto out; +if (unlikely (!xdr_reserve_space (xdr,XDR_UNIT ))) { + status = nfserr_resource; + goto out; } - attrlen =cpu_to_be32 (xdr->buf->len - attrlen_offset -XDR_UNIT ); -write_bytes_to_xdr_buf (xdr->buf, attrlen_offset, &attrlen,XDR_UNIT ); - status = nfs_ok; + status =nfsd4_encode_attr_vals (xdr, attrmask, &args); +if (status == nfs_ok) { + attrlen =cpu_to_be32 (xdr->buf->len - attrlen_offset -XDR_UNIT ); +write_bytes_to_xdr_buf (xdr->buf, attrlen_offset, &attrlen,XDR_UNIT ); + } out:#ifdef CONFIG_NFSD_V4_POSIX_ACLS if (args.dpacl)
@@ -4180,9 +4189,6 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, out_nfserr: status =nfserrno (err); goto out; -out_resource: - status = nfserr_resource; - goto out; } static bool
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 13/20 nfsd: allow nfsd4_encode_fattr4_change() to work with no export
In reply to Jeff LaytonIn the context of a CB_NOTIFY callback, we may not have easy access to a svc_export. nfsd will not currently grant a delegation on a the V4 root however, so this should be safe.
--- fs/nfsd/nfs4xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +1 -1
@@ -3273,7 +3273,7 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr, {const struct svc_export *exp = args->exp; -if (unlikely (exp->ex_flags &NFSEXP_V4ROOT )) { +if (exp &&unlikely (exp->ex_flags &NFSEXP_V4ROOT )) {u32 flush_time =convert_to_wallclock (exp->cd->flush_time);if (xdr_stream_encode_u32 (xdr, flush_time) !=XDR_UNIT )
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 14/20 nfsd: send basic file attributes in CB_NOTIFY
In reply to Jeff LaytonIn addition to the filename, send attributes about the inode in a CB_NOTIFY event. This patch just adds a the basic inode information that can be acquired via GETATTR.
--- fs/nfsd/nfs4xdr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
fs/nfsd/nfs4xdr.c +44 -0
@@ -4191,12 +4191,21 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, goto out; } +#define CB_NOTIFY_STATX_REQUEST_MASK (STATX_BASIC_STATS | \ + STATX_BTIME | \ + STATX_CHANGE_COOKIE) +static bool nfsd4_setup_notify_entry4 (struct notify_entry4 *ne,struct xdr_stream *xdr,struct dentry *dentry,struct nfs4_delegation *dp,struct nfsd_file *nf,char *name,u32 namelen) { +struct path path = { .mnt = nf->nf_file->f_path.mnt, + .dentry = dentry }; +struct nfsd4_fattr_args args = { };uint32_t *attrmask; +__be32 status; +int ret;/* Reserve space for attrmask */ attrmask =xdr_reserve_space (xdr,3 *sizeof (uint32_t ));
@@ -4207,6 +4216,41 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, ne->ne_file.len = namelen; ne->ne_attrs.attrmask.element = attrmask; +/* FIXME: d_find_alias for inode ? */ +if (!path.dentry || !d_inode (path.dentry)) + goto noattrs; + +/* +* It is possible that the client was granted a delegation when a file +* was created. Note that we don't issue a CB_GETATTR here since stale +* attributes are presumably ok. +*/ + ret =vfs_getattr (&path, &args.stat,CB_NOTIFY_STATX_REQUEST_MASK ,AT_STATX_SYNC_AS_STAT ); +if (ret) + goto noattrs; + + args.change_attr =nfsd4_change_attribute (&args.stat); + + attrmask[0 ] =FATTR4_WORD0_TYPE |FATTR4_WORD0_CHANGE | +FATTR4_WORD0_SIZE |FATTR4_WORD0_FILEID ; + attrmask[1 ] =FATTR4_WORD1_MODE |FATTR4_WORD1_NUMLINKS |FATTR4_WORD1_RAWDEV | +FATTR4_WORD1_SPACE_USED |FATTR4_WORD1_TIME_ACCESS | +FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; + attrmask[2 ] =0 ; + +if (args.stat.result_mask &STATX_BTIME ) + attrmask[1 ] |=FATTR4_WORD1_TIME_CREATE ; + + ne->ne_attrs.attrmask.count =2 ; + ne->ne_attrs.attr_vals.data = (u8 *)xdr->p; + + status =nfsd4_encode_attr_vals (xdr, attrmask, &args); +if (status != nfs_ok) + goto noattrs; + + ne->ne_attrs.attr_vals.len = (u8 *)xdr->p - ne->ne_attrs.attr_vals.data; +return true; +noattrs: attrmask[0 ] =0 ; attrmask[1 ] =0 ; attrmask[2 ] =0 ;
Signature · 1 line
2.54.0
Jeff Layton
maintainerPATCH v6 15/20 nfsd: allow encoding a filehandle into fattr4 without a svc_fh
In reply to Jeff LaytonThe current fattr4 encoder requires a svc_fh in order to encode the filehandle. This is not available in a CB_NOTIFY callback. Add a a new "fhandle" field to struct nfsd4_fattr_args and copy the filehandle into there from the svc_fh. CB_NOTIFY will populate it via other means.
A filehandle composed this way may still need a MAC appended on signed exports, so generalize fh_append_mac() to operate on a bare knfsd_fh (plus its maximum size and net) rather than a svc_fh.
--- fs/nfsd/nfs4xdr.c | 36 +++++++++++++++++++++--------------- fs/nfsd/nfsfh.c | 10 +++++----- fs/nfsd/nfsfh.h | 1 + 3 files changed, 27 insertions(+), 20 deletions(-)
fs/nfsd/nfs4xdr.c +21 -15
@@ -2715,7 +2715,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp) }static __be32 nfsd4_encode_nfs_fh4 (struct xdr_stream *xdr, -struct knfsd_fh *fh_handle) +const struct knfsd_fh *fh_handle) {return nfsd4_encode_opaque (xdr, fh_handle->fh_raw, fh_handle->fh_size); }
@@ -3158,6 +3158,7 @@ struct nfsd4_fattr_args {struct svc_fh *fhp;struct svc_export *exp;struct dentry *dentry; +struct knfsd_fh fhandle;struct kstat stat;struct kstatfs statfs;struct nfs4_acl *acl;
@@ -3402,7 +3403,7 @@ static __be32 nfsd4_encode_fattr4_homogeneous(struct xdr_stream *xdr,static __be32 nfsd4_encode_fattr4_filehandle (struct xdr_stream *xdr,const struct nfsd4_fattr_args *args) { -return nfsd4_encode_nfs_fh4 (xdr, &args->fhp->fh_handle); +return nfsd4_encode_nfs_fh4 (xdr, &args->fhandle); } static __be32 nfsd4_encode_fattr4_fileid(struct xdr_stream *xdr,
@@ -4015,19 +4016,24 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,if (err) goto out_nfserr; } -if ((attrmask[0 ] & (FATTR4_WORD0_FILEHANDLE |FATTR4_WORD0_FSID )) && - !fhp) { - tempfh = kmalloc_obj(struct svc_fh); - status = nfserr_jukebox; -if (!tempfh) - goto out; -fh_init (tempfh,NFS4_FHSIZE ); - status =fh_compose (tempfh, exp, dentry,NULL ); -if (status) - goto out; - args.fhp = tempfh; - }else - args.fhp = fhp; + + args.fhp = fhp; +if ((attrmask[0 ] & (FATTR4_WORD0_FILEHANDLE |FATTR4_WORD0_FSID ))) { +if (!args.fhp) { + tempfh = kmalloc_obj(struct svc_fh); + status = nfserr_jukebox; +if (!tempfh) + goto out; +fh_init (tempfh,NFS4_FHSIZE ); + status =fh_compose (tempfh, exp, dentry,NULL ); +if (status) + goto out; + args.fhp = tempfh; + } +if (args.fhp) +fh_copy_shallow (&args.fhandle, &args.fhp->fh_handle); + } +if (attrmask[0 ] & (FATTR4_WORD0_CASE_INSENSITIVE |FATTR4_WORD0_CASE_PRESERVING )) {/*
fs/nfsd/nfsfh.c +5 -5
@@ -144,16 +144,15 @@ static inline __be32 check_pseudo_root(struct dentry *dentry,/* Size of a file handle MAC, in 4-octet words */ #define FH_MAC_WORDS (sizeof(__le64) / 4) -static bool fh_append_mac (struct svc_fh *fhp,struct net *net) +bool fh_append_mac (struct knfsd_fh *fh,int fh_maxsize,struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -struct knfsd_fh *fh = &fhp->fh_handle;siphash_key_t *fh_key = nn->fh_key;__le64 hash;if (!fh_key) goto out_no_key; -if (fh->fh_size +sizeof (hash) > fhp->fh_maxsize) +if (fh->fh_size +sizeof (hash) > fh_maxsize) goto out_no_space; hash =cpu_to_le64 (siphash (&fh->fh_raw, fh->fh_size, fh_key));
@@ -167,7 +166,7 @@ static bool fh_append_mac(struct svc_fh *fhp, struct net *net) out_no_space:pr_warn_ratelimited ("NFSD: unable to sign filehandles, fh_size %zu would be greater than fh_maxsize %d.\n" , - fh->fh_size +sizeof (hash), fhp->fh_maxsize); + fh->fh_size +sizeof (hash), fh_maxsize);return false; }
@@ -566,7 +565,8 @@ static void _fh_update(struct svc_fh *fhp, struct svc_export *exp, fhp->fh_handle.fh_size += maxsize *4 ;if (exp->ex_flags &NFSEXP_SIGN_FH ) -if (!fh_append_mac (fhp, exp->cd->net)) +if (!fh_append_mac (&fhp->fh_handle, fhp->fh_maxsize, + exp->cd->net)) fhp->fh_handle.fh_fileid_type =FILEID_INVALID ; }else { fhp->fh_handle.fh_fileid_type =FILEID_ROOT ;
fs/nfsd/nfsfh.h +1 -0
@@ -226,6 +226,7 @@ __be32 fh_getattr(const struct svc_fh *fhp, struct kstat *stat);__be32 fh_compose (struct svc_fh *,struct svc_export *,struct dentry *,struct svc_fh *);__be32 fh_update (struct svc_fh *);void fh_put (struct svc_fh *); +bool fh_append_mac (struct knfsd_fh *fh,int fh_maxsize,struct net *net);static __inline__struct svc_fh *fh_copy (struct svc_fh *dst,const struct svc_fh *src)
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 15/20] nfsd: allow encoding a filehandle into fattr4 without a svc_fh
Quoted 44 lines · Jeff Layton
The current fattr4 encoder requires a
svc_fhin order to encode the filehandle. This is not available in aCB_NOTIFYcallback. Add a a new "fhandle" field to structnfsd4_fattr_argsand copy the filehandle into there from thesvc_fh.CB_NOTIFYwill populate it via other means.A filehandle composed this way may still need a MAC appended on signed exports, so generalize
fh_append_mac()to operate on a bareknfsd_fh(plus its maximum size and net) rather than asvc_fh.Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4xdr.c | 36 +++++++++++++++++++++--------------- fs/nfsd/nfsfh.c | 10 +++++----- fs/nfsd/nfsfh.h | 1 + 3 files changed, 27 insertions(+), 20 deletions(-)fs/nfsd/nfs4xdr.c +5
-13@@ -4015,19 +4016,24 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (err) goto out_nfserr; } -if ((attrmask[0 ] & (FATTR4_WORD0_FILEHANDLE |FATTR4_WORD0_FSID )) && - !fhp) { - tempfh = kmalloc_obj(struct svc_fh); - status = nfserr_jukebox; -if (!tempfh) - goto out; -fh_init (tempfh,NFS4_FHSIZE ); - status =fh_compose (tempfh, exp, dentry,NULL ); -if (status) - goto out; - args.fhp = tempfh; - }else - args.fhp = fhp; + + args.fhp = fhp; +if ((attrmask[0 ] & (FATTR4_WORD0_FILEHANDLE |FATTR4_WORD0_FSID ))) { +if (!args.fhp) { + tempfh = kmalloc_obj(struct svc_fh);
fs/nfsd/nfs4xdr.c nfsd4_encode_fattr4(struct svc_rqst *rqstp, · line 4034
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+ status = nfserr_jukebox; +if (!tempfh) + goto out; +fh_init (tempfh,NFS4_FHSIZE ); + status =fh_compose (tempfh, exp, dentry,NULL ); +if (status) + goto out; + args.fhp = tempfh; + } +if (args.fhp)
Nit: here, "args.fhp" is never false.
Note that nfsd4_encode_fattr4_fsid() calls fsid_source(args->fhp) without a NULL check. After this patch is applied, filehandle encoding is svc_fh-free but FSID encoding is not, and the two share the same attrmask gate:
(FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID).
No current caller trips it: the CB_NOTIFY path does not request FSID. But a future CB_NOTIFY attrset that adds FSID would dereference a NULL fhp.
Quoted 6 lines
fs/nfsd/nfs4xdr.c +3
-0+fh_copy_shallow (&args.fhandle, &args.fhp->fh_handle); + } +if (attrmask[0 ] & (FATTR4_WORD0_CASE_INSENSITIVE |FATTR4_WORD0_CASE_PRESERVING )) {/*
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 16/20 nfsd: add a fi_connectable flag to struct nfs4_file
In reply to Jeff LaytonWhen encoding a filehandle for a CB_NOTIFY, there is no svc_export available, but the server needs to know whether to encode a connectable filehandle. Add a flag to the nfs4_file that tells whether the svc_export under which a directory delegation was acquired has subtree checking enabled, in which case it needs connectable filehandles.
--- fs/nfsd/nfs4state.c | 1 + fs/nfsd/state.h | 1 + 2 files changed, 2 insertions(+)
fs/nfsd/nfs4state.c +1 -0
@@ -5231,6 +5231,7 @@ static void nfsd4_file_init(const struct svc_fh *fh, struct nfs4_file *fp)memset (fp->fi_access,0 ,sizeof (fp->fi_access)); fp->fi_aliased = false; fp->fi_inode =d_inode (fh->fh_dentry); + fp->fi_connectable = !(fh->fh_export->ex_flags &NFSEXP_NOSUBTREECHECK );#ifdef CONFIG_NFSD_PNFS INIT_LIST_HEAD (&fp->fi_lo_states);atomic_set (&fp->fi_lo_recalls,0 );
fs/nfsd/state.h +1 -0
@@ -761,6 +761,7 @@ struct nfs4_file {int fi_delegees;struct knfsd_fh fi_fhandle;bool fi_had_conflict; +bool fi_connectable;#ifdef CONFIG_NFSD_PNFS struct list_head fi_lo_states;atomic_t fi_lo_recalls;
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 16/20] nfsd: add a fi_connectable flag to struct nfs4_file
Quoted 32 lines · Jeff Layton
When encoding a filehandle for a
CB_NOTIFY, there is nosvc_exportavailable, but the server needs to know whether to encode a connectable filehandle. Add a flag to thenfs4_filethat tells whether thesvc_exportunder which a directory delegation was acquired has subtree checking enabled, in which case it needs connectable filehandles.Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 1 + fs/nfsd/state.h | 1 + 2 files changed, 2 insertions(+)fs/nfsd/nfs4state.c +1
-0@@ -5231,6 +5231,7 @@ static void nfsd4_file_init(const struct svc_fh *fh, struct nfs4_file *fp)memset (fp->fi_access,0 ,sizeof (fp->fi_access)); fp->fi_aliased = false; fp->fi_inode =d_inode (fh->fh_dentry); + fp->fi_connectable = !(fh->fh_export->ex_flags &NFSEXP_NOSUBTREECHECK );#ifdef CONFIG_NFSD_PNFS fs/nfsd/nfs4state.c +0
-0INIT_LIST_HEAD (&fp->fi_lo_states);atomic_set (&fp->fi_lo_recalls,0 );fs/nfsd/state.h +0
-0
fs/nfsd/state.h struct nfs4_file { · line 767
Quoted 7 lines
fs/nfsd/state.h +1
-0@@ -761,6 +761,7 @@ struct nfs4_file {int fi_delegees;struct knfsd_fh fi_fhandle;bool fi_had_conflict; +bool fi_connectable;#ifdef CONFIG_NFSD_PNFS struct list_head fi_lo_states;atomic_t fi_lo_recalls;
When two clients use exports of the same directory root that differ only in subtree_check/no_subtree_check, the root filehandle is the same and nfsd4_file_hash_insert() can reuse the same nfs4_file. This makes fi_connectable depend on whichever export first initialized the shared object, so a later directory delegation acquired under the other export can encode CB_NOTIFY child filehandles with the wrong connectability.
Therefore, the delegation's sc_export is the per-export state to derive connectability from, and the export is already available via dp->dl_stid.sc_export.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 17/20 nfsd: add the filehandle to returned attributes in CB_NOTIFY
In reply to Jeff Laytonnfsd's usual fh_compose routine requires a svc_export and fills out a svc_fh. In the context of a CB_NOTIFY there is no such export to consult.
Add a new routine that composes a filehandle with only a parent filehandle and nfs4_file. Use that to fill out the fhandle field in the nfsd4_fattr_args.
--- fs/nfsd/nfs4xdr.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
fs/nfsd/nfs4xdr.c +37 -0
@@ -4197,6 +4197,39 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, goto out; } +static bool +setup_notify_fhandle (struct dentry *dentry,struct nfs4_file *fi, +struct nfsd_file *nf,struct nfsd4_fattr_args *args) +{ +int fileid_type, fsid_len, maxsize, flags =0 ; +struct knfsd_fh *fhp = &args->fhandle; +struct inode *inode =d_inode (dentry); +struct inode *parent =NULL ; +struct fid *fid; + + fsid_len =key_len (fi->fi_fhandle.fh_fsid_type); + fhp->fh_size =4 + fsid_len; + +/* Copy first 4 bytes + fsid */ +memcpy (&fhp->fh_raw, &fi->fi_fhandle.fh_raw, fhp->fh_size); + + fid = (struct fid *)(fh_fsid (fhp) + fsid_len/4 ); + maxsize = (NFS4_FHSIZE - fhp->fh_size)/4 ; + +if (fi->fi_connectable && !S_ISDIR (inode->i_mode)) { + parent =d_inode (nf->nf_file->f_path.dentry); + flags =EXPORT_FH_CONNECTABLE ; + } + + fileid_type =exportfs_encode_inode_fh (inode, fid, &maxsize, parent, flags); +if (fileid_type <0 || fileid_type ==FILEID_INVALID ) +return false; + + fhp->fh_fileid_type = fileid_type; + fhp->fh_size += maxsize *4 ; +return true; +} +#define CB_NOTIFY_STATX_REQUEST_MASK (STATX_BASIC_STATS | \ STATX_BTIME | \ STATX_CHANGE_COOKIE)
@@ -4206,6 +4239,7 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, struct dentry *dentry, struct nfs4_delegation *dp, struct nfsd_file *nf, char *name, u32 namelen) { + struct nfs4_file *fi = dp->dl_stid.sc_file;struct path path = { .mnt = nf->nf_file->f_path.mnt, .dentry = dentry };struct nfsd4_fattr_args args = { };
@@ -4244,6 +4278,9 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr,FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; attrmask[2 ] =0 ; +if (setup_notify_fhandle (dentry, fi, nf, &args)) + attrmask[0 ] |=FATTR4_WORD0_FILEHANDLE ; +if (args.stat.result_mask &STATX_BTIME ) attrmask[1 ] |=FATTR4_WORD1_TIME_CREATE ;
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 17/20] nfsd: add the filehandle to returned attributes in CB_NOTIFY
Quoted 70 lines · Jeff Layton
nfsd's usual
fh_composeroutine requires asvc_exportand fills out asvc_fh. In the context of aCB_NOTIFYthere is no such export to consult.Add a new routine that composes a filehandle with only a parent filehandle and
nfs4_file. Use that to fill out the fhandle field in thenfsd4_fattr_args.Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4xdr.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)fs/nfsd/nfs4xdr.c +33
-0@@ -4197,6 +4197,39 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp,struct xdr_stream *xdr, goto out; } +static bool +setup_notify_fhandle (struct dentry *dentry,struct nfs4_file *fi, +struct nfsd_file *nf,struct nfsd4_fattr_args *args) +{ +int fileid_type, fsid_len, maxsize, flags =0 ; +struct knfsd_fh *fhp = &args->fhandle; +struct inode *inode =d_inode (dentry); +struct inode *parent =NULL ; +struct fid *fid; + + fsid_len =key_len (fi->fi_fhandle.fh_fsid_type); + fhp->fh_size =4 + fsid_len; + +/* Copy first 4 bytes + fsid */ +memcpy (&fhp->fh_raw, &fi->fi_fhandle.fh_raw, fhp->fh_size); + + fid = (struct fid *)(fh_fsid (fhp) + fsid_len/4 ); + maxsize = (NFS4_FHSIZE - fhp->fh_size)/4 ; + +if (fi->fi_connectable && !S_ISDIR (inode->i_mode)) { + parent =d_inode (nf->nf_file->f_path.dentry); + flags =EXPORT_FH_CONNECTABLE ; + } + + fileid_type =exportfs_encode_inode_fh (inode, fid, &maxsize, parent, flags); +if (fileid_type <0 || fileid_type ==FILEID_INVALID ) +return false; + + fhp->fh_fileid_type = fileid_type; + fhp->fh_size += maxsize *4 ; +return true; +} +#define CB_NOTIFY_STATX_REQUEST_MASK (STATX_BASIC_STATS | \fs/nfsd/nfs4xdr.c +1
-0STATX_BTIME | \ STATX_CHANGE_COOKIE)@@ -4206,6 +4239,7 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, struct dentry *dentry, struct nfs4_delegation *dp, struct nfsd_file *nf, char *name, u32 namelen) { +struct nfs4_file *fi = dp->dl_stid.sc_file;struct path path = { .mnt = nf->nf_file->f_path.mnt, .dentry = dentry };fs/nfsd/nfs4xdr.c +0
-0struct nfsd4_fattr_args args = { };
fs/nfsd/nfs4xdr.c nfsd4_setup_notify_entry4(struct notify_entry4 · line 4286
Quoted 9 lines
fs/nfsd/nfs4xdr.c +3
-0@@ -4244,6 +4278,9 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr,FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; attrmask[2 ] =0 ; +if (setup_notify_fhandle (dentry, fi, nf, &args)) + attrmask[0 ] |=FATTR4_WORD0_FILEHANDLE ; +if (args.stat.result_mask &STATX_BTIME ) attrmask[1 ] |=FATTR4_WORD1_TIME_CREATE ;
Codex flagged setup_notify_fhandle() for constructing a child FILEHANDLE attribute without calling fh_append_mac(): for exports with sign_fh, fh_compose() appends a MAC, and nfsd_set_fh_dentry() rejects every non-root signed-export handle whose MAC is absent or mismatched, so a client using the CB_NOTIFY filehandle gets a stale/bad handle. It recommends signing the constructed handle or suppressing the attribute when the export requires signed filehandles.
A client that does not receive the FH falls back to a LOOKUP, so suppression degrades gracefully.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 18/20 nfsd: properly track requested child attributes
In reply to Jeff LaytonTrack the union of requested and supported child attributes in the delegation, and only encode the attributes in that union when sending add/remove/rename updates.
--- fs/nfsd/nfs4proc.c | 2 ++ fs/nfsd/nfs4state.c | 18 ++++++++++++++++++ fs/nfsd/nfs4xdr.c | 15 ++++++--------- fs/nfsd/state.h | 3 +++ 4 files changed, 29 insertions(+), 9 deletions(-)
fs/nfsd/nfs4proc.c +2 -0
@@ -2577,6 +2577,8 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp, gdd->gddrnf_status =GDD4_OK ;memcpy (&gdd->gddr_stateid, &dd->dl_stid.sc_stateid,sizeof (gdd->gddr_stateid)); + gdd->gddr_child_attributes[0 ] = dd->dl_child_attrs[0 ]; + gdd->gddr_child_attributes[1 ] = dd->dl_child_attrs[1 ];nfs4_put_stid (&dd->dl_stid);return nfs_ok; }
fs/nfsd/nfs4state.c +18 -0
@@ -9930,6 +9930,21 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,return status; } +#define GDD_WORD0_CHILD_ATTRS (FATTR4_WORD0_TYPE | \ + FATTR4_WORD0_CHANGE | \ + FATTR4_WORD0_SIZE | \ + FATTR4_WORD0_FILEID | \ + FATTR4_WORD0_FILEHANDLE) + +#define GDD_WORD1_CHILD_ATTRS (FATTR4_WORD1_MODE | \ + FATTR4_WORD1_NUMLINKS | \ + FATTR4_WORD1_RAWDEV | \ + FATTR4_WORD1_SPACE_USED | \ + FATTR4_WORD1_TIME_ACCESS | \ + FATTR4_WORD1_TIME_METADATA | \ + FATTR4_WORD1_TIME_MODIFY | \ + FATTR4_WORD1_TIME_CREATE) +/** * nfsd_get_dir_deleg - attempt to get a directory delegation * @cstate: compound state
@@ -9998,6 +10013,9 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, dp->dl_stid.sc_export =exp_get (cstate->current_fh.fh_export); + dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; + dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; +/* * NB: gddr_notification[0] represents the notifications that * will be granted to the client
fs/nfsd/nfs4xdr.c +6 -9
@@ -4271,18 +4271,15 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, args.change_attr =nfsd4_change_attribute (&args.stat); - attrmask[0 ] =FATTR4_WORD0_TYPE |FATTR4_WORD0_CHANGE | -FATTR4_WORD0_SIZE |FATTR4_WORD0_FILEID ; - attrmask[1 ] =FATTR4_WORD1_MODE |FATTR4_WORD1_NUMLINKS |FATTR4_WORD1_RAWDEV | -FATTR4_WORD1_SPACE_USED |FATTR4_WORD1_TIME_ACCESS | -FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; + attrmask[0 ] = dp->dl_child_attrs[0 ]; + attrmask[1 ] = dp->dl_child_attrs[1 ]; attrmask[2 ] =0 ; -if (setup_notify_fhandle (dentry, fi, nf, &args)) - attrmask[0 ] |=FATTR4_WORD0_FILEHANDLE ; +if (!setup_notify_fhandle (dentry, fi, nf, &args)) + attrmask[0 ] &= ~FATTR4_WORD0_FILEHANDLE ; -if (args.stat.result_mask &STATX_BTIME ) - attrmask[1 ] |=FATTR4_WORD1_TIME_CREATE ; +if (!(args.stat.result_mask &STATX_BTIME )) + attrmask[1 ] &= ~FATTR4_WORD1_TIME_CREATE ; ne->ne_attrs.attrmask.count =2 ; ne->ne_attrs.attr_vals.data = (u8 *)xdr->p;
fs/nfsd/state.h +3 -0
@@ -297,6 +297,9 @@ struct nfs4_delegation {struct timespec64 dl_atime;struct timespec64 dl_mtime;struct timespec64 dl_ctime; + +/* For dir delegations */ +uint32_t dl_child_attrs[2 ]; };static inline bool deleg_is_read (u32 dl_type)
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 18/20] nfsd: properly track requested child attributes
Quoted 102 lines · Jeff Layton
Track the union of requested and supported child attributes in the delegation, and only encode the attributes in that union when sending add/remove/rename updates.
Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4proc.c | 2 ++ fs/nfsd/nfs4state.c | 18 ++++++++++++++++++ fs/nfsd/nfs4xdr.c | 15 ++++++--------- fs/nfsd/state.h | 3 +++ 4 files changed, 29 insertions(+), 9 deletions(-)fs/nfsd/nfs4proc.c +2
-0@@ -2577,6 +2577,8 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp, gdd->gddrnf_status =GDD4_OK ;memcpy (&gdd->gddr_stateid, &dd->dl_stid.sc_stateid,sizeof (gdd->gddr_stateid)); + gdd->gddr_child_attributes[0 ] = dd->dl_child_attrs[0 ]; + gdd->gddr_child_attributes[1 ] = dd->dl_child_attrs[1 ];nfs4_put_stid (&dd->dl_stid);return nfs_ok;}
fs/nfsd/nfs4state.c +15
-0@@ -9930,6 +9930,21 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, return status; } +#define GDD_WORD0_CHILD_ATTRS (FATTR4_WORD0_TYPE | \ + FATTR4_WORD0_CHANGE | \ + FATTR4_WORD0_SIZE | \ + FATTR4_WORD0_FILEID | \ + FATTR4_WORD0_FILEHANDLE) + +#define GDD_WORD1_CHILD_ATTRS (FATTR4_WORD1_MODE | \ + FATTR4_WORD1_NUMLINKS | \ + FATTR4_WORD1_RAWDEV | \ + FATTR4_WORD1_SPACE_USED | \ + FATTR4_WORD1_TIME_ACCESS | \ + FATTR4_WORD1_TIME_METADATA | \ + FATTR4_WORD1_TIME_MODIFY | \ + FATTR4_WORD1_TIME_CREATE) +/** * nfsd_get_dir_deleg - attempt to get a directory delegation * @cstate: compound state
fs/nfsd/nfs4state.c +3
-0@@ -9998,6 +10013,9 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, dp->dl_stid.sc_export =exp_get (cstate->current_fh.fh_export); + dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; + dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; +/* fs/nfsd/nfs4state.c +0
-0* NB: gddr_notification[0] represents the notifications that * will be granted to the client fs/nfsd/nfs4xdr.c +0
-3@@ -4271,18 +4271,15 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, args.change_attr =nfsd4_change_attribute (&args.stat); - attrmask[0 ] =FATTR4_WORD0_TYPE |FATTR4_WORD0_CHANGE | -FATTR4_WORD0_SIZE |FATTR4_WORD0_FILEID ; - attrmask[1] = FATTR4_WORD1_MODE | FATTR4_WORD1_NUMLINKS |
FATTR4_WORD1_RAWDEV|fs/nfsd/nfs4xdr.c +6
-6-FATTR4_WORD1_SPACE_USED |FATTR4_WORD1_TIME_ACCESS | -FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; + attrmask[0 ] = dp->dl_child_attrs[0 ]; + attrmask[1 ] = dp->dl_child_attrs[1 ]; attrmask[2 ] =0 ; -if (setup_notify_fhandle (dentry, fi, nf, &args)) - attrmask[0 ] |=FATTR4_WORD0_FILEHANDLE ; +if (!setup_notify_fhandle (dentry, fi, nf, &args)) + attrmask[0 ] &= ~FATTR4_WORD0_FILEHANDLE ; -if (args.stat.result_mask &STATX_BTIME ) - attrmask[1 ] |=FATTR4_WORD1_TIME_CREATE ; +if (!(args.stat.result_mask &STATX_BTIME )) + attrmask[1 ] &= ~FATTR4_WORD1_TIME_CREATE ; ne->ne_attrs.attrmask.count =2 ; ne->ne_attrs.attr_vals.data = (u8 *)xdr->p;fs/nfsd/state.h +0
-0
fs/nfsd/state.h struct nfs4_delegation { · line 305
Quoted 9 lines
fs/nfsd/state.h +3
-0@@ -297,6 +297,9 @@ struct nfs4_delegation {struct timespec64 dl_atime;struct timespec64 dl_mtime;struct timespec64 dl_ctime; + +/* For dir delegations */ +uint32_t dl_child_attrs[2 ]; };static inline bool deleg_is_read (u32 dl_type)
When a client requests any supported child attribute in word 1, this can make gddr_child_attributes[1] non-zero, so nfsd4_encode_bitmap4() emits a two-word bitmap. nfsd4_get_dir_delegation_rsize() still budgets only the old one-word child-attribute bitmap before executing this non-idempotent op, so a compound near the reply/slot limit can grant a directory delegation and then fail encoding with NFS4ERR_RESOURCE/REP_TOO_BIG, leaving the client without the returned stateid.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 19/20 nfsd: track requested dir attributes
In reply to Jeff LaytonTrack the union of requested and supported dir attributes in the delegation. In a later patch this will be used to ensure that we only encode the attributes in that union when sending add/remove/rename updates.
--- fs/nfsd/nfs4proc.c | 9 ++++++--- fs/nfsd/nfs4state.c | 20 ++++++++++++++++---- fs/nfsd/state.h | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-)
fs/nfsd/nfs4proc.c +6 -3
@@ -2530,9 +2530,10 @@ nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return status == nfserr_same ? nfs_ok : status; } -#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_REMOVE_ENTRY) | \ - BIT(NOTIFY4_ADD_ENTRY) | \ - BIT(NOTIFY4_RENAME_ENTRY) | \ +#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_CHANGE_DIR_ATTRS) | \ + BIT(NOTIFY4_REMOVE_ENTRY) | \ + BIT(NOTIFY4_ADD_ENTRY) | \ + BIT(NOTIFY4_RENAME_ENTRY) | \ BIT(NOTIFY4_GFLAG_EXTEND)) static __be32
@@ -2579,6 +2580,8 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp,memcpy (&gdd->gddr_stateid, &dd->dl_stid.sc_stateid,sizeof (gdd->gddr_stateid)); gdd->gddr_child_attributes[0 ] = dd->dl_child_attrs[0 ]; gdd->gddr_child_attributes[1 ] = dd->dl_child_attrs[1 ]; + gdd->gddr_dir_attributes[0 ] = dd->dl_dir_attrs[0 ]; + gdd->gddr_dir_attributes[1 ] = dd->dl_dir_attrs[1 ];nfs4_put_stid (&dd->dl_stid);return nfs_ok; }
fs/nfsd/nfs4state.c +16 -4
@@ -9945,6 +9945,15 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, FATTR4_WORD1_TIME_MODIFY | \ FATTR4_WORD1_TIME_CREATE) +#define GDD_WORD0_DIR_ATTRS (FATTR4_WORD0_CHANGE | \ + FATTR4_WORD0_SIZE) + +#define GDD_WORD1_DIR_ATTRS (FATTR4_WORD1_NUMLINKS | \ + FATTR4_WORD1_SPACE_USED | \ + FATTR4_WORD1_TIME_ACCESS | \ + FATTR4_WORD1_TIME_METADATA | \ + FATTR4_WORD1_TIME_MODIFY) +/** * nfsd_get_dir_deleg - attempt to get a directory delegation * @cstate: compound state
@@ -10013,14 +10022,17 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, dp->dl_stid.sc_export =exp_get (cstate->current_fh.fh_export); - dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; - dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; -/* * NB: gddr_notification[0] represents the notifications that * will be granted to the client */ - fl =nfs4_alloc_init_lease (dp, gdd->gddr_notification[0 ]); + dp->dl_notify_mask = gdd->gddr_notification[0 ]; + dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; + dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; + dp->dl_dir_attrs[0 ] = gdd->gdda_dir_attributes[0 ] &GDD_WORD0_DIR_ATTRS ; + dp->dl_dir_attrs[1 ] = gdd->gdda_dir_attributes[1 ] &GDD_WORD1_DIR_ATTRS ; + + fl =nfs4_alloc_init_lease (dp, dp->dl_notify_mask);if (!fl) goto out_put_stid;
fs/nfsd/state.h +2 -0
@@ -299,7 +299,9 @@ struct nfs4_delegation {struct timespec64 dl_ctime;/* For dir delegations */ +uint32_t dl_notify_mask;uint32_t dl_child_attrs[2 ]; +uint32_t dl_dir_attrs[2 ]; };static inline bool deleg_is_read (u32 dl_type)
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 19/20] nfsd: track requested dir attributes
Quoted 90 lines · Jeff Layton
Track the union of requested and supported dir attributes in the delegation. In a later patch this will be used to ensure that we only encode the attributes in that union when sending add/remove/rename updates.
Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4proc.c | 9 ++++++--- fs/nfsd/nfs4state.c | 20 ++++++++++++++++---- fs/nfsd/state.h | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-)fs/nfsd/nfs4proc.c +4
-3@@ -2530,9 +2530,10 @@ nfsd4_verify(struct svc_rqst *rqstp, structnfsd4_compound_state *cstate, return status == nfserr_same ? nfs_ok : status; } -#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_REMOVE_ENTRY) | \ - BIT(NOTIFY4_ADD_ENTRY) | \ - BIT(NOTIFY4_RENAME_ENTRY) | \ +#define SUPPORTED_NOTIFY_MASK (BIT(NOTIFY4_CHANGE_DIR_ATTRS) | \ + BIT(NOTIFY4_REMOVE_ENTRY) | \ + BIT(NOTIFY4_ADD_ENTRY) | \ + BIT(NOTIFY4_RENAME_ENTRY) | \ BIT(NOTIFY4_GFLAG_EXTEND))static
__be32fs/nfsd/nfs4proc.c +2
-0@@ -2579,6 +2580,8 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp,memcpy (&gdd->gddr_stateid, &dd->dl_stid.sc_stateid,sizeof (gdd->gddr_stateid)); gdd->gddr_child_attributes[0 ] = dd->dl_child_attrs[0 ]; gdd->gddr_child_attributes[1 ] = dd->dl_child_attrs[1 ]; + gdd->gddr_dir_attributes[0 ] = dd->dl_dir_attrs[0 ]; + gdd->gddr_dir_attributes[1 ] = dd->dl_dir_attrs[1 ];nfs4_put_stid (&dd->dl_stid);return nfs_ok;}
fs/nfsd/nfs4state.c +9
-0@@ -9945,6 +9945,15 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, FATTR4_WORD1_TIME_MODIFY | \ FATTR4_WORD1_TIME_CREATE) +#define GDD_WORD0_DIR_ATTRS (FATTR4_WORD0_CHANGE | \ + FATTR4_WORD0_SIZE) + +#define GDD_WORD1_DIR_ATTRS (FATTR4_WORD1_NUMLINKS | \ + FATTR4_WORD1_SPACE_USED | \ + FATTR4_WORD1_TIME_ACCESS | \ + FATTR4_WORD1_TIME_METADATA | \ + FATTR4_WORD1_TIME_MODIFY) +/** * nfsd_get_dir_deleg - attempt to get a directory delegation * @cstate: compound state
fs/nfsd/nfs4state.c +7
-4@@ -10013,14 +10022,17 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, dp->dl_stid.sc_export =exp_get (cstate->current_fh.fh_export); - dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; - dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; -/* * NB: gddr_notification[0] represents the notifications that * will be granted to the client */ - fl =nfs4_alloc_init_lease (dp, gdd->gddr_notification[0 ]); + dp->dl_notify_mask = gdd->gddr_notification[0 ]; + dp->dl_child_attrs[0 ] = gdd->gdda_child_attributes[0 ] &GDD_WORD0_CHILD_ATTRS ; + dp->dl_child_attrs[1 ] = gdd->gdda_child_attributes[1 ] &GDD_WORD1_CHILD_ATTRS ; + dp->dl_dir_attrs[0 ] = gdd->gdda_dir_attributes[0 ] &GDD_WORD0_DIR_ATTRS ; + dp->dl_dir_attrs[1 ] = gdd->gdda_dir_attributes[1 ] &GDD_WORD1_DIR_ATTRS ; + + fl =nfs4_alloc_init_lease (dp, dp->dl_notify_mask);if (!fl) goto out_put_stid;fs/nfsd/state.h +0
-0
fs/nfsd/state.h struct nfs4_delegation { · line 304
Quoted 6 lines
fs/nfsd/state.h +2
-0@@ -299,7 +299,9 @@ struct nfs4_delegation {struct timespec64 dl_ctime;/* For dir delegations */ +uint32_t dl_notify_mask;uint32_t dl_child_attrs[2 ]; +uint32_t dl_dir_attrs[2 ];
Nit: Maybe these should be u32. uint32_t is a user space type.
fs/nfsd/state.h struct nfs4_delegation { · line 307
Quoted 4 lines
fs/nfsd/state.h +0
-0};static inline bool deleg_is_read (u32 dl_type)
Bisectability: After this patch is applied, a client that requests NOTIFY4_CHANGE_DIR_ATTRS now gets that bit echoed in gddr_notification, but the callback path still only maps/encodes add, remove, and rename notifications (nfsd_notify_to_ignore(), nfsd_fsnotify_recalc_mask(), and nfsd4_encode_notify_event() have no dir-attr case). That lets the server grant a directory delegation while promising dir-attribute CB_NOTIFYs it cannot send until the follow-up support lands, so this bit should not be advertised in this patch.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v6 20/20 nfsd: add support to CB_NOTIFY for dir attribute changes
In reply to Jeff LaytonIf the client requested dir attribute change notifications, send those alongside any set of add/remove/rename events. Note that the server will still recall the delegation on a SETATTR, so these are only sent for changes to child dirents.
The child filehandle returned in these notifications is composed by setup_notify_fhandle() without going through fh_compose(), so it does not get a MAC appended. On exports configured with NFSEXP_SIGN_FH the client would then get back an unsigned filehandle that fh_verify() rejects as stale. Pass the delegation's export down to setup_notify_fhandle() and append the MAC with fh_append_mac() when the export requires signed filehandles; if signing fails, drop the filehandle attribute rather than handing out an unusable one.
--- fs/nfsd/nfs4state.c | 25 ++++++++++++++++-- fs/nfsd/nfs4xdr.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-------- fs/nfsd/xdr4.h | 2 ++ 3 files changed, 88 insertions(+), 12 deletions(-)
fs/nfsd/nfs4state.c +23 -2
@@ -3503,10 +3503,15 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb)struct nfsd_notify_event *events[NOTIFY4_EVENT_QUEUE_SIZE ];struct xdr_buf xdr = { .buflen =PAGE_SIZE *NOTIFY4_PAGE_ARRAY_SIZE , .pages = ncn->ncn_pages }; +int limit =NOTIFY4_EVENT_QUEUE_SIZE ;struct xdr_stream stream;struct nfsd_file *nf; -int count, i;bool error = false; +int count, i; + +/* Save a slot for dir attr update if requested */ +if (dp->dl_notify_mask &BIT (NOTIFY4_CHANGE_DIR_ATTRS )) + --limit;xdr_init_encode_pages (&stream, &xdr);
@@ -3520,7 +3525,7 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb) }/* we can't keep up! */ -if (count >NOTIFY4_EVENT_QUEUE_SIZE ) { +if (count > limit) {spin_unlock (&ncn->ncn_lock); goto out_recall; }
@@ -3567,6 +3572,22 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb)nfsd_notify_event_put (nne); }if (!error) { +if (dp->dl_notify_mask &BIT (NOTIFY4_CHANGE_DIR_ATTRS )) { +u32 *maskp = (u32 *)xdr_reserve_space (&stream,sizeof (*maskp)); + +if (maskp) { +u8 *p =nfsd4_encode_dir_attr_change (&stream, dp, nf); + +if (p) { + *maskp =BIT (NOTIFY4_CHANGE_DIR_ATTRS ); + ncn->ncn_nf[count].notify_mask.count =1 ; + ncn->ncn_nf[count].notify_mask.element = maskp; + ncn->ncn_nf[count].notify_vals.data = p; + ncn->ncn_nf[count].notify_vals.len = (u8 *)stream.p - p; + ++count; + } + } + } ncn->ncn_nf_cnt = count;nfsd_file_put (nf);return true;
fs/nfsd/nfs4xdr.c +63 -10
114 lines not on this page · raw message
fs/nfsd/xdr4.h +2 -0
@@ -973,6 +973,8 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,u8 *nfsd4_encode_notify_event (struct xdr_stream *xdr,struct nfsd_notify_event *nne,struct nfs4_delegation *dd,struct nfsd_file *nf,u32 *notify_mask); +u8 *nfsd4_encode_dir_attr_change (struct xdr_stream *xdr,struct nfs4_delegation *dp, +struct nfsd_file *nf);extern __be32 nfsd4_setclientid (struct svc_rqst *rqstp,struct nfsd4_compound_state *,union nfsd4_op_u *u); extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
Signature · 1 line
2.54.0
Chuck Lever
maintainerRe: [PATCH v6 20/20] nfsd: add support to CB_NOTIFY for dir attribute changes
Quoted 26 lines · Jeff Layton
If the client requested dir attribute change notifications, send those alongside any set of add/remove/rename events. Note that the server will still recall the delegation on a SETATTR, so these are only sent for changes to child dirents.
The child filehandle returned in these notifications is composed by
setup_notify_fhandle()without going throughfh_compose(), so it does not get a MAC appended. On exports configured withNFSEXP_SIGN_FHthe client would then get back an unsigned filehandle thatfh_verify()rejects as stale. Pass the delegation's export down tosetup_notify_fhandle()and append the MAC withfh_append_mac()when the export requires signed filehandles; if signing fails, drop the filehandle attribute rather than handing out an unusable one.Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 25 ++++++++++++++++-- fs/nfsd/nfs4xdr.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-------- fs/nfsd/xdr4.h | 2 ++ 3 files changed, 88 insertions(+), 12 deletions(-)fs/nfsd/nfs4state.c +0
-0
fs/nfsd/nfs4state.c nfsd4_cb_notify_prepare(struct nfsd4_callback *cb) · line 3506
Quoted 4 lines
fs/nfsd/nfs4state.c +1
-0@@ -3503,10 +3503,15 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb)struct nfsd_notify_event *events[NOTIFY4_EVENT_QUEUE_SIZE ];struct xdr_buf xdr = { .buflen =PAGE_SIZE *NOTIFY4_PAGE_ARRAY_SIZE , .pages = ncn->ncn_pages }; +int limit =NOTIFY4_EVENT_QUEUE_SIZE ;
When a client requests NOTIFY4_CHANGE_DIR_ATTRS, the CB_NOTIFY event queue can fill to NOTIFY4_EVENT_QUEUE_SIZE (3) events while the consumer only accepts 2 (it reserves a slot for the dir-attr-change entry). The resulting overflow path in nfsd4_cb_notify_prepare() recalls the delegation without draining the queue, and nfsd4_cb_notify_release() then requeues the same callback indefinitely.
Quoted 32 lines
fs/nfsd/nfs4state.c +12
-2struct xdr_stream stream;struct nfsd_file *nf; -int count, i;bool error = false; +int count, i; + +/* Save a slot for dir attr update if requested */ +if (dp->dl_notify_mask &BIT (NOTIFY4_CHANGE_DIR_ATTRS )) + --limit;xdr_init_encode_pages (&stream, &xdr);@@ -3520,7 +3525,7 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb) }/* we can't keep up! */ -if (count >NOTIFY4_EVENT_QUEUE_SIZE ) { +if (count > limit) {spin_unlock (&ncn->ncn_lock); goto out_recall; }@@ -3567,6 +3572,22 @@ nfsd4_cb_notify_prepare(struct nfsd4_callback *cb)nfsd_notify_event_put (nne); }if (!error) { +if (dp->dl_notify_mask &BIT (NOTIFY4_CHANGE_DIR_ATTRS )) { +u32 *maskp = (u32 *)xdr_reserve_space (&stream,sizeof (*maskp)); + +if (maskp) { +u8 *p =nfsd4_encode_dir_attr_change (&stream, dp, nf); +
fs/nfsd/nfs4state.c nfsd4_cb_notify_prepare(struct nfsd4_callback · line 3591
Quoted 10 lines
fs/nfsd/nfs4state.c +10
-0+if (p) { + *maskp =BIT (NOTIFY4_CHANGE_DIR_ATTRS ); + ncn->ncn_nf[count].notify_mask.count =1 ; + ncn->ncn_nf[count].notify_mask.element = maskp; + ncn->ncn_nf[count].notify_vals.data = p; + ncn->ncn_nf[count].notify_vals.len = (u8 *)stream.p - p; + ++count; + } + } + }
Nit:
When xdr_reserve_space() for maskp succeeds but nfsd4_encode_dir_attr_change() returns NULL, the 4-byte reservation is never rolled back and *maskp is never written, yet the function still takes the success path (return true). Unlike the child-event loop, this branch does not escalate to error = true.
This is probably benign only because nfs4_xdr_enc_cb_notify re-encodes from the ncn_nf[] array (and count was not incremented), so the garbage hole is never transmitted.
Quoted 17 lines
fs/nfsd/nfs4state.c +0
-0ncn->ncn_nf_cnt = count;nfsd_file_put (nf);fs/nfsd/nfs4state.c +0
-0return true;fs/nfsd/nfs4xdr.c +2
-1@@ -4199,7 +4199,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp,struct xdr_stream *xdr, static bool setup_notify_fhandle(struct dentry *dentry, struct nfs4_file *fi, - struct nfsd_file *nf, struct nfsd4_fattr_args *args) + struct nfsd_file *nf, struct svc_export *exp, + struct nfsd4_fattr_args *args) { int fileid_type, fsid_len, maxsize, flags = 0;
Quoted 1 line
struct
knfsd_fh*fhp =&args->fhandle;
The function dereferences the new exp parameter unconditionally.
The argument is dp->dl_stid.sc_export, read unlocked at nfs4xdr.c:4297 and handed down. An in-flight CB_NOTIFY callback holds a sc_count reference but NOT an export reference. drop_stid_export() can run concurrently (admin revoke / unexport), NULL sc_export, and drop what may be the last export reference, freeing the svc_export while the callback dereferences it.
Quoted 89 lines
fs/nfsd/nfs4xdr.c +13
-2@@ -4227,6 +4228,17 @@ setup_notify_fhandle(struct dentry *dentry,struct nfs4_file *fi, fhp->fh_fileid_type = fileid_type; fhp->fh_size += maxsize *4 ; + +/* +* fh_compose() appends a MAC to filehandles on signed exports; this +* hand-rolled filehandle must do the same or the client will get back +* an unsigned filehandle that fh_verify() later rejects as stale. +* If we can't sign it, don't hand it out at all. +*/ +if (exp && (exp->ex_flags &NFSEXP_SIGN_FH )) +if (!fh_append_mac (fhp,NFS4_FHSIZE , exp->cd->net)) +return false; +return true; }@@ -4240,11 +4252,11 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, struct nfsd_file *nf, char *name, u32 namelen) {struct nfs4_file *fi = dp->dl_stid.sc_file; -struct path path = { .mnt = nf->nf_file->f_path.mnt, - .dentry = dentry }; +struct path path = nf->nf_file->f_path;struct nfsd4_fattr_args args = { };uint32_t *attrmask;__be32 status; +bool parent;int ret;fs/nfsd/nfs4xdr.c +3
-0/* Reserve space for attrmask */ @@ -4256,6 +4268,9 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, ne->ne_file.len = namelen; ne->ne_attrs.attrmask.element = attrmask; + parent = (dentry == path.dentry); + path.dentry = dentry; +/* FIXME: d_find_alias for inode ? */ if (!path.dentry || !d_inode (path.dentry))fs/nfsd/nfs4xdr.c +13
-7goto noattrs;@@ -4271,15 +4286,21 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr, args.change_attr =nfsd4_change_attribute (&args.stat); - attrmask[0 ] = dp->dl_child_attrs[0 ]; - attrmask[1 ] = dp->dl_child_attrs[1 ]; - attrmask[2 ] =0 ; +if (parent) { + attrmask[0 ] = dp->dl_dir_attrs[0 ]; + attrmask[1 ] = dp->dl_dir_attrs[1 ]; + }else { + attrmask[0 ] = dp->dl_child_attrs[0 ]; + attrmask[1 ] = dp->dl_child_attrs[1 ]; -if (!setup_notify_fhandle (dentry, fi, nf, &args)) - attrmask[0 ] &= ~FATTR4_WORD0_FILEHANDLE ; +if (!setup_notify_fhandle (dentry, fi, nf, + dp->dl_stid.sc_export, &args)) + attrmask[0 ] &= ~FATTR4_WORD0_FILEHANDLE ; -if (!(args.stat.result_mask &STATX_BTIME )) - attrmask[1 ] &= ~FATTR4_WORD1_TIME_CREATE ; +if (!(args.stat.result_mask &STATX_BTIME )) + attrmask[1 ] &= ~FATTR4_WORD1_TIME_CREATE ; + } + attrmask[2 ] =0 ; ne->ne_attrs.attrmask.count =2 ;fs/nfsd/nfs4xdr.c +9
-0ne->ne_attrs.attr_vals.data = (u8 *)xdr->p;@@ -4392,6 +4413,38 @@ u8 *nfsd4_encode_notify_event(struct xdr_stream *xdr, struct nfsd_notify_event * return NULL; } +/** +* nfsd4_encode_dir_attr_change +* @xdr: stream to which to encode the fattr4 +* @dp: delegation where the event occurred +* @nf: nfsd_file opened on the directory +* +* Encode a dir attr change event. +*/ +u8 *nfsd4_encode_dir_attr_change(struct xdr_stream *xdr, struct
fs/nfsd/nfs4xdr.c u8 *nfsd4_encode_notify_event(struct xdr_stream · line 4435
Quoted 10 lines
fs/nfsd/nfs4xdr.c +9
-0nfs4_delegation *dp, + struct nfsd_file *nf) +{ + struct dentry *dentry = nf->nf_file->f_path.dentry; +struct notify_attr4 na = { }; +bool ret; +u8 *p =NULL ; + +if (!(dp->dl_notify_mask &BIT (NOTIFY4_CHANGE_DIR_ATTRS ))) +return NULL ;
It looks like this if() re-checks dl_notify_mask even though its sole caller already gated on the identical check.
nfsd4_encode_notify_event() does not repeat its caller's check. The guard is unreachable from current callers.
Quoted 37 lines
fs/nfsd/nfs4xdr.c +2
-0+ +/* RFC 8881 s10.4.3: ne_file must be a zero-length string for dir attrs */
fs/nfsd/nfs4xdr.c +12
-0+ ret =nfsd4_setup_notify_entry4 (&na.na_changed_entry, xdr, + dentry, dp, nf,"" ,0 ); + +/* Don't bother with the event if we're not encoding attrs */ +if (ret && na.na_changed_entry.ne_attrs.attr_vals.len) { + p = (u8 *)xdr->p; +if (!xdrgen_encode_notify_attr4 (xdr, &na)) + p =NULL ; + } +return p; +} +static void svcxdr_init_encode_from_buffer (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p,int bytes) {fs/nfsd/xdr4.h +2
-0@@ -973,6 +973,8 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, u8 *nfsd4_encode_notify_event(struct xdr_stream *xdr, struct nfsd_notify_event *nne, struct nfs4_delegation *dd, struct nfsd_file *nf, u32 *notify_mask); +u8 *nfsd4_encode_dir_attr_change (struct xdr_stream *xdr,struct nfs4_delegation *dp, +struct nfsd_file *nf);extern
__be32nfsd4_setclientid(structsvc_rqst*rqstp,
structnfsd4_compound_state*, unionnfsd4_op_u*u);
extern__be32nfsd4_setclientid_confirm(structsvc_rqst*rqstp,Signature · 1 line
2.54.0
Signature · 1 line
Chuck Lever