NFS: Add directory delegation support for CB_NOTIFY
Subsystems (2)
Anna Schumaker
maintainerv2 cover NFS: Add directory delegation support for CB_NOTIFY
From: Anna Schumaker <[email protected]>
These patches add support for the CB_NOTIFY callback operation from NFS servers. Editing directory order or placement in our caches isn't easy or practical the way things are structured now. Instead, I use CB_NOTIFY as an indication that the client needs to refresh its view of the directory.
Changes in v2:
* Fix signed / unsigned type mixups
* Don't try to share lookup code between NOTIFY4_REMOVE and NOTIFY4_ADD
* Add handling for the NOTIFY4_ADD 'na_have_old_entry' case
Thoughts?
Anna
Anna Schumaker (4):
NFS: Add an outline for the CB_NOTIFY operation
NFS: Add support for CB_NOTIFY4_REMOVE_ENTRY
NFS: Add support for CB_NOTIFY4_ADD_ENTRY
NFS: Add support for CB_NOTIFY4_RENAME_ENTRY
fs/nfs/callback.h | 51 ++++++++++++ fs/nfs/callback_proc.c | 147 ++++++++++++++++++++++++++++++++++ fs/nfs/callback_xdr.c | 175 ++++++++++++++++++++++++++++++++++++++++- fs/nfs/nfs4_fs.h | 2 + fs/nfs/nfs4xdr.c | 33 +++++++- include/linux/nfs4.h | 6 ++ 6 files changed, 409 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0
Anna Schumaker
maintainerPATCH v2 1/4 NFS: Add an outline for the CB_NOTIFY operation
From: Anna Schumaker <[email protected]>
Support for individual notification types will be added over the next few patches.
---
v2: Change res to a ssize_t
--- fs/nfs/callback.h | 14 +++++++++++ fs/nfs/callback_proc.c | 9 +++++++ fs/nfs/callback_xdr.c | 54 +++++++++++++++++++++++++++++++++++++++++- fs/nfs/nfs4xdr.c | 2 +- include/linux/nfs4.h | 3 +++ 5 files changed, 80 insertions(+), 2 deletions(-)
fs/nfs/callback.h +14 -0
@@ -143,6 +143,20 @@ struct cb_layoutrecallargs {extern __be32 nfs4_callback_layoutrecall (void *argp,void *resp,struct cb_process_state *cps); +struct cb_notify_changes { +u32 notify_mask; +}; + +struct cb_notifyargs { +nfs4_stateid cna_stateid; +struct nfs_fh cna_fh; +uint32_t cna_n_changes; +struct cb_notify_changes *cna_changes; +}; + +extern __be32 nfs4_callback_notify (void *argp,void *resp, +struct cb_process_state *cps); +struct cb_devicenotifyitem {uint32_t cbd_notify_type;uint32_t cbd_layout_type;
fs/nfs/callback_proc.c +9 -0
@@ -369,6 +369,15 @@ static void pnfs_recall_all_layouts(struct nfs_client *clp,do_callback_layoutrecall (clp, &args, cps); } +__be32 nfs4_callback_notify (void *argp,void *resp, +struct cb_process_state *cps) +{ +struct cb_notifyargs *args = argp; + +kfree (args->cna_changes); +return 0 ; +} +__be32 nfs4_callback_devicenotify (void *argp,void *resp,struct cb_process_state *cps) {
fs/nfs/callback_xdr.c +53 -1
83 lines not on this page · raw message
fs/nfs/nfs4xdr.c +1 -1
@@ -2012,7 +2012,7 @@ static void encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) { struct timespec64 ts = { 0, 0 }; -u32 notifications[1 ] = {0 }; +u32 notifications[1 ] = {CB_NOTIFY4_GFLAG_EXTEND };u32 attributes[1 ] = {0 };__be32 *p;
include/linux/nfs4.h +3 -0
@@ -491,6 +491,9 @@ enum {#define THRESHOLD_RD_IO (1UL << 2)#define THRESHOLD_WR_IO (1UL << 3) +/* Directory Delegation / CB_NOTIFY bits */ +#define CB_NOTIFY4_GFLAG_EXTEND (1UL << 6) +#define NFSPROC4_NULL 0#define NFSPROC4_COMPOUND 1#define NFS4_VERSION 4
Signature · 1 line
2.55.0
Anna Schumaker
maintainerPATCH v2 2/4 NFS: Add support for CB_NOTIFY4_REMOVE_ENTRY
In reply to Anna SchumakerFrom: Anna Schumaker <[email protected]>
When the server tells us that a directory entry has been removed then we need to take that as an indication that our knowledge of the directory has changed and needs to be refreshed.
---
v2:
* Initialize 'res' to 0 in nfs4_callback_notify()
* Add missing error handling
* Remove nfs4_cb_notify_lookup()
--- fs/nfs/callback.h | 16 ++++++++++- fs/nfs/callback_proc.c | 63 +++++++++++++++++++++++++++++++++++++++++- fs/nfs/callback_xdr.c | 62 +++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4xdr.c | 3 +- include/linux/nfs4.h | 1 + 5 files changed, 142 insertions(+), 3 deletions(-)
fs/nfs/callback.h +15 -1
@@ -143,8 +143,22 @@ struct cb_layoutrecallargs {extern __be32 nfs4_callback_layoutrecall (void *argp,void *resp,struct cb_process_state *cps); +struct cb_notify_entry { +u32 ne_namelen; +const char *ne_name; +struct nfs_fattr ne_attrs; +}; + +struct cb_notify_remove { +struct cb_notify_entry nrm_old_entry; +u64 nrm_old_entry_cookie; +}; +struct cb_notify_changes { -u32 notify_mask; +u32 notify_mask; +union { +struct cb_notify_remove notify_remove; + }; };struct cb_notifyargs {
fs/nfs/callback_proc.c +62 -1
81 lines not on this page · raw message
fs/nfs/callback_xdr.c +62 -0
74 lines not on this page · raw message
fs/nfs/nfs4xdr.c +2 -1
@@ -2012,7 +2012,8 @@ static void encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) { struct timespec64 ts = { 0, 0 }; -u32 notifications[1 ] = {CB_NOTIFY4_GFLAG_EXTEND }; +u32 notifications[1 ] = {CB_NOTIFY4_REMOVE_ENTRY | +CB_NOTIFY4_GFLAG_EXTEND };u32 attributes[1 ] = {0 };__be32 *p;
include/linux/nfs4.h +1 -0
@@ -492,6 +492,7 @@ enum {#define THRESHOLD_WR_IO (1UL << 3)/* Directory Delegation / CB_NOTIFY bits */ +#define CB_NOTIFY4_REMOVE_ENTRY (1UL << 2)#define CB_NOTIFY4_GFLAG_EXTEND (1UL << 6)#define NFSPROC4_NULL 0
Signature · 1 line
2.55.0
Jeff Layton
maintainerRe: [PATCH v2 2/4] NFS: Add support for CB_NOTIFY4_REMOVE_ENTRY
Quoted 69 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
When the server tells us that a directory entry has been removed then we need to take that as an indication that our knowledge of the directory has changed and needs to be refreshed.
Signed-off-by Anna Schumaker <[email protected]>Signed-off-by Anna Schumaker <[email protected]>---
v2:
* Initialize 'res' to 0 innfs4_callback_notify()
* Add missing error handling
* Removenfs4_cb_notify_lookup()--- fs/nfs/callback.h | 16 ++++++++++- fs/nfs/callback_proc.c | 63 +++++++++++++++++++++++++++++++++++++++++- fs/nfs/callback_xdr.c | 62 +++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4xdr.c | 3 +- include/linux/nfs4.h | 1 + 5 files changed, 142 insertions(+), 3 deletions(-)fs/nfs/callback.h +15
-1@@ -143,8 +143,22 @@ struct cb_layoutrecallargs {extern __be32 nfs4_callback_layoutrecall (void *argp,void *resp,struct cb_process_state *cps); +struct cb_notify_entry { +u32 ne_namelen; +const char *ne_name; +struct nfs_fattr ne_attrs; +}; + +struct cb_notify_remove { +struct cb_notify_entry nrm_old_entry; +u64 nrm_old_entry_cookie; +}; +struct cb_notify_changes { -u32 notify_mask; +u32 notify_mask; +union { +struct cb_notify_remove notify_remove; + }; };struct cb_notifyargs {fs/nfs/callback_proc.c +5
-0@@ -9,6 +9,7 @@#include <linux/errno.h> #include <linux/math.h> +#include <linux/namei.h> #include <linux/nfs4.h> #include <linux/nfs_fs.h> #include <linux/slab.h> @@ -369,13 +370,73 @@ static void pnfs_recall_all_layouts(struct nfs_client *clp,do_callback_layoutrecall (clp, &args, cps); } +static __be32 nfs4_cb_notify_remove (struct cb_process_state *cps, +struct dentry *parent, +struct cb_notify_remove *cb_remove) +{
fs/nfs/callback_proc.c static void pnfs_recall_all_layouts(struct nfs_client *clp, · line 386
Quoted 10 lines
fs/nfs/callback_proc.c +10
-0+struct qstr filename =QSTR_INIT (cb_remove->nrm_old_entry.ne_name, + cb_remove->nrm_old_entry.ne_namelen); +struct dentry *child; + + filename.hash =full_name_hash (parent, filename.name, filename.len); + child =d_lookup (parent, &filename); +if (IS_ERR_OR_NULL (child)) +return htonl (NFS4ERR_BADHANDLE ); + +d_drop (child);
Should this instead make this a negative dentry?
I think this will just drop the existing dentry and it'll trigger a lookup next time we end up trying to hit it.
Quoted 163 lines
fs/nfs/callback_proc.c +47
-1+dput (child); + +nfs_set_cache_invalid (parent->d_inode,NFS_INO_INVALID_DATA ); +return 0 ; +} +__be32 nfs4_callback_notify (void *argp,void *resp,struct cb_process_state *cps) {struct cb_notifyargs *args = argp; +struct dentry *parent; +struct inode *inode; +unsigned int i; +__be32 res =0 ; +if (!cps->clp) { + res =htonl (NFS4ERR_OP_NOT_IN_SESSION ); + goto out; + } + + inode =nfs_delegation_find_inode (cps->clp, &args->cna_fh); +if (IS_ERR (inode)) { + res =htonl (NFS4ERR_BADHANDLE ); + goto out; + } + parent =d_find_alias (inode); +if (!parent) + goto out_iput; + +for (i =0 ; i < args->cna_n_changes; i++) { +struct cb_notify_changes *change = &args->cna_changes[i]; + +switch (change->notify_mask) { +case CB_NOTIFY4_REMOVE_ENTRY : + res =nfs4_cb_notify_remove (cps, parent, + &change->notify_remove); +break ; +default : + res =htonl (NFS4ERR_NOTSUPP ); + goto out_dput; + } + +if (unlikely (res !=0 )) +break ; + } + +out_dput: +dput (parent); +out_iput: +nfs_iput_and_deactive (inode); +out:kfree (args->cna_changes); -return 0 ; +return res; } __be32 nfs4_callback_devicenotify(void *argp, void *resp,fs/nfs/callback_xdr.c +62
-0@@ -252,6 +252,50 @@ static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp,return 0 ; } +static __be32 decode_notify_entry (struct xdr_stream *xdr, +struct cb_notify_entry *args) +{ +uint32_t bitmap[3 ] = {0 }; +__be32 status; +u32 attrlen; +__be32 *p; + + status =decode_string (xdr, &args->ne_namelen, &args->ne_name, +NFS4_OPAQUE_LIMIT ); +if (unlikely (status !=0 )) +return status; + + status =decode_bitmap (xdr, bitmap); +if (unlikely (status !=0 )) +return status; + + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) +return htonl (NFS4ERR_BADXDR ); + + attrlen =be32_to_cpup (p); +if (attrlen !=0 ) +return htonl (NFS4ERR_BADXDR ); +return 0 ; +} + +static __be32 decode_notify_remove (struct xdr_stream *xdr, +struct cb_notify_remove *args) +{ +__be32 status; +__be32 *p; + + status =decode_notify_entry (xdr, &args->nrm_old_entry); +if (unlikely (status !=0 )) +return status; + + p =xdr_inline_decode (xdr,8 ); +if (unlikely (!p)) +return htonl (NFS4ERR_BADXDR ); +xdr_decode_hyper (p, &args->nrm_old_entry_cookie); +return 0 ; +} + static __be32 decode_notify_args(struct svc_rqst *rqstp, struct xdr_stream *xdr,@@ -289,6 +333,24 @@ __be32 decode_notify_args(struct svc_rqst *rqstp, &change->notify_mask, 1);if (unlikely (res <0 )) goto err; + +/* Decode opaque size */ + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) + goto err; + res =ntohl (*p); + +switch (change->notify_mask) { +case CB_NOTIFY4_REMOVE_ENTRY : + status =decode_notify_remove (xdr, + &change->notify_remove); +break ; +default : + goto err; + } + +if (unlikely (status !=0 )) + goto err; }return 0 ;fs/nfs/nfs4xdr.c +2
-1@@ -2012,7 +2012,8 @@ static void encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) { struct timespec64 ts = { 0, 0 }; -u32 notifications[1 ] = {CB_NOTIFY4_GFLAG_EXTEND }; +u32 notifications[1 ] = {CB_NOTIFY4_REMOVE_ENTRY | +CB_NOTIFY4_GFLAG_EXTEND };u32 attributes[1 ] = {0 };__be32 *p;include/linux/nfs4.h +1
-0@@ -492,6 +492,7 @@ enum {#define THRESHOLD_WR_IO (1UL << 3)/* Directory Delegation / CB_NOTIFY bits */ +#define CB_NOTIFY4_REMOVE_ENTRY (1UL << 2)#define CB_NOTIFY4_GFLAG_EXTEND (1UL << 6)#define NFSPROC4_NULL 0
Signature · 1 line
Jeff Layton <[email protected]>
Anna Schumaker
maintainerPATCH v2 3/4 NFS: Add support for CB_NOTIFY4_ADD_ENTRY
In reply to Anna SchumakerFrom: Anna Schumaker <[email protected]>
When the server tells us that a directory entry has been created, we need to instantiate a new dentry and add it to the dcache on the client.
---
v2:
* Handle the na_have_old_entry case
* Initialize fattr->valid to 0 before decoding
* Properly check the return code from decode_fattr_cb()
* Rewrite nfs4_cb_notify_add() to closer resemble nfs_prime_dcache()
--- fs/nfs/callback.h | 17 +++++++++++ fs/nfs/callback_proc.c | 61 +++++++++++++++++++++++++++++++++++++ fs/nfs/callback_xdr.c | 69 ++++++++++++++++++++++++++++++++++-------- fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4xdr.c | 29 ++++++++++++++++-- include/linux/nfs4.h | 1 + 6 files changed, 164 insertions(+), 15 deletions(-)
fs/nfs/callback.h +17 -0
@@ -147,6 +147,12 @@ struct cb_notify_entry {u32 ne_namelen;const char *ne_name;struct nfs_fattr ne_attrs; +struct nfs_fh ne_fh; +}; + +struct cb_notify_prev_entry { +struct cb_notify_entry pe_prev_entry; +u64 pe_prev_entry_cookie; };struct cb_notify_remove {
@@ -154,10 +160,21 @@ struct cb_notify_remove {u64 nrm_old_entry_cookie; }; +struct cb_notify_add { +bool na_have_old_entry; +struct cb_notify_remove na_old_entry; +struct cb_notify_entry na_new_entry; +bool na_have_new_entry_cookie; +u64 na_new_entry_cookie; +bool na_have_prev_entry; +bool na_last_entry; +}; +struct cb_notify_changes {u32 notify_mask;union {struct cb_notify_remove notify_remove; +struct cb_notify_add notify_add; }; };
fs/nfs/callback_proc.c +61 -0
73 lines not on this page · raw message
fs/nfs/callback_xdr.c +57 -12
95 lines not on this page · raw message
fs/nfs/nfs4_fs.h +2 -0
@@ -586,6 +586,8 @@ extern const u32 nfs42_maxlistxattrs_overhead;#endif struct nfs4_mount_data ; +int decode_fattr_cb (struct xdr_stream *xdr,uint32_t *bitmap, +struct nfs_fattr *fattr,struct nfs_fh *fhandle);/* callback_xdr.c */ extern const struct svc_version nfs4_callback_version1;
fs/nfs/nfs4xdr.c +26 -3
@@ -2013,8 +2013,11 @@ encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) {struct timespec64 ts = {0 ,0 };u32 notifications[1 ] = {CB_NOTIFY4_REMOVE_ENTRY | +CB_NOTIFY4_ADD_ENTRY |CB_NOTIFY4_GFLAG_EXTEND }; -u32 attributes[1 ] = {0 }; +u32 child_attrs[1 ] = {FATTR4_WORD0_FSID |FATTR4_WORD0_FILEID | +FATTR4_WORD0_TYPE |FATTR4_WORD0_FILEHANDLE }; +u32 dir_attrs[1 ] = {0 };__be32 *p;encode_op_hdr (xdr,OP_GET_DIR_DELEGATION , decode_get_dir_deleg_maxsz, hdr);
@@ -2030,10 +2033,10 @@ encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr)xdr_encode_nfstime4 (p, &ts);/* Requested child attributes */ -xdr_encode_bitmap4 (xdr, attributes,ARRAY_SIZE (attributes)); +xdr_encode_bitmap4 (xdr, child_attrs,ARRAY_SIZE (child_attrs));/* Requested dir attributes */ -xdr_encode_bitmap4 (xdr, attributes,ARRAY_SIZE (attributes)); +xdr_encode_bitmap4 (xdr, dir_attrs,ARRAY_SIZE (dir_attrs)); } static void
@@ -4919,6 +4922,26 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,return decode_getfattr_generic (xdr, fattr,NULL ,NULL , server); } +int decode_fattr_cb (struct xdr_stream *xdr,uint32_t *bitmap, +struct nfs_fattr *fattr,struct nfs_fh *fhandle) +{ +unsigned int savep; +uint32_t attrlen; +int status; + + fattr->valid =0 ; + + status =decode_attr_length (xdr, &attrlen, &savep); +if (status <0 ) +return status; + + status =decode_getfattr_attrs (xdr, bitmap, fattr, fhandle,NULL ,NULL ); +if (status <0 ) +return status; + +return verify_attr_len (xdr, savep, attrlen); +} +/* * Decode potentially multiple layout types. */
include/linux/nfs4.h +1 -0
@@ -493,6 +493,7 @@ enum {/* Directory Delegation / CB_NOTIFY bits */ #define CB_NOTIFY4_REMOVE_ENTRY (1UL << 2) +#define CB_NOTIFY4_ADD_ENTRY (1UL << 3)#define CB_NOTIFY4_GFLAG_EXTEND (1UL << 6)#define NFSPROC4_NULL 0
Signature · 1 line
2.55.0
Anna Schumaker
maintainerPATCH v2 4/4 NFS: Add support for CB_NOTIFY4_RENAME_ENTRY
In reply to Anna SchumakerFrom: Anna Schumaker <[email protected]>
Renaming an entry essentially combines a remove with an add, allowing us to reuse most of the code from the previous patches to do the work for us.
--- fs/nfs/callback.h | 6 ++++++ fs/nfs/callback_proc.c | 16 ++++++++++++++++ fs/nfs/callback_xdr.c | 14 ++++++++++++++ fs/nfs/nfs4xdr.c | 1 + include/linux/nfs4.h | 1 + 5 files changed, 38 insertions(+)
fs/nfs/callback.h +6 -0
@@ -170,11 +170,17 @@ struct cb_notify_add {bool na_last_entry; }; +struct cb_notify_rename { +struct cb_notify_remove nrn_old_entry; +struct cb_notify_add nrn_new_entry; +}; +struct cb_notify_changes {u32 notify_mask;union {struct cb_notify_remove notify_remove;struct cb_notify_add notify_add; +struct cb_notify_rename notify_rename; }; };
fs/nfs/callback_proc.c +16 -0
@@ -447,6 +447,18 @@ static __be32 nfs4_cb_notify_add(struct cb_process_state *cps,return 0 ; } +static __be32 nfs4_cb_notify_rename (struct cb_process_state *cps, +struct dentry *parent, +struct cb_notify_rename *cb_rename) +{ +__be32 status; + + status =nfs4_cb_notify_remove (cps, parent, &cb_rename->nrn_old_entry); +if (status !=0 ) +return status; +return nfs4_cb_notify_add (cps, parent, &cb_rename->nrn_new_entry); +} +__be32 nfs4_callback_notify (void *argp,void *resp,struct cb_process_state *cps) {
@@ -482,6 +494,10 @@ __be32 nfs4_callback_notify(void *argp, void *resp, res =nfs4_cb_notify_add (cps, parent, &change->notify_add);break ; +case CB_NOTIFY4_RENAME_ENTRY : + res =nfs4_cb_notify_rename (cps, parent, + &change->notify_rename); +break ;default : res =htonl (NFS4ERR_NOTSUPP ); goto out_dput;
fs/nfs/callback_xdr.c +14 -0
@@ -338,6 +338,17 @@ static __be32 decode_notify_add(struct xdr_stream *xdr,return 0 ; } +static __be32 decode_notify_rename (struct xdr_stream *xdr, +struct cb_notify_rename *args) +{ +__be32 status; + + status =decode_notify_remove (xdr, &args->nrn_old_entry); +if (unlikely (status !=0 )) +return status; +return decode_notify_add (xdr, &args->nrn_new_entry); +} + static __be32 decode_notify_args(struct svc_rqst *rqstp, struct xdr_stream *xdr,
@@ -390,6 +401,9 @@ __be32 decode_notify_args(struct svc_rqst *rqstp,case CB_NOTIFY4_ADD_ENTRY : status =decode_notify_add (xdr, &change->notify_add);break ; +case CB_NOTIFY4_RENAME_ENTRY : + status =decode_notify_rename (xdr, &change->notify_rename); +break ;default : goto err; }
fs/nfs/nfs4xdr.c +1 -0
@@ -2014,6 +2014,7 @@ encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr)struct timespec64 ts = {0 ,0 };u32 notifications[1 ] = {CB_NOTIFY4_REMOVE_ENTRY |CB_NOTIFY4_ADD_ENTRY | +CB_NOTIFY4_RENAME_ENTRY |CB_NOTIFY4_GFLAG_EXTEND };u32 child_attrs[1 ] = {FATTR4_WORD0_FSID |FATTR4_WORD0_FILEID |FATTR4_WORD0_TYPE |FATTR4_WORD0_FILEHANDLE };
include/linux/nfs4.h +1 -0
@@ -494,6 +494,7 @@ enum {/* Directory Delegation / CB_NOTIFY bits */ #define CB_NOTIFY4_REMOVE_ENTRY (1UL << 2)#define CB_NOTIFY4_ADD_ENTRY (1UL << 3) +#define CB_NOTIFY4_RENAME_ENTRY (1UL << 4)#define CB_NOTIFY4_GFLAG_EXTEND (1UL << 6)#define NFSPROC4_NULL 0
Signature · 1 line
2.55.0