[PATCH RFC v2 28/28] nfsd: add support for NOTIFY4_RENAME_ENTRY events

Jeff Layton
2025-06-02T14:03:21Z

Add support for RENAME events. Marshal the event into the notifylist4
buffer and kick the callback handler.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4proc.c | 2 +-
fs/nfsd/nfs4state.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index a2996343fa0db33e014731f62aaa4e7c72506a76..4573c0651aa49df6089bcc4e5d40f45d46b1c499 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -2292,7 +2292,7 @@ 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|NOTIFY4_ADD_ENTRY)
+#define SUPPORTED_NOTIFY_MASK BIT(NOTIFY4_REMOVE_ENTRY|NOTIFY4_ADD_ENTRY|NOTIFY4_RENAME_ENTRY)

static __be32
nfsd4_get_dir_delegation(struct svc_rqst *rqstp,
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9dc607e355d5839d80946d4983205c15ece6a71e..6333e95c075259af0c160eb130149c776e55f5a8 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -9722,6 +9722,45 @@ nfsd_handle_dir_event(u32 mask, const struct inode *dir, const void *data,
ent->notify_vals.data = p;
++nns->nns_idx;
}
+ if (mask & FS_RENAME) {
+ struct dentry *new_dentry = fsnotify_data_dentry(data, data_type);
+ static uint32_t notify_rename_bitmap = BIT(NOTIFY4_RENAME_ENTRY);
+ struct notify4 *ent = &nns->nns_ent[nns->nns_idx];
+ struct notify_rename4 nr = { };
+ u8 *p = (u8 *)(stream->p);
+ struct name_snapshot n;
+ bool ret;
+
+ if (!(flc->flc_flags & FL_IGN_DIR_RENAME))
+ continue;
+
+ /* FIXME: warn? */
+ if (!new_dentry)
+ continue;
+
+ nr.nrn_old_entry.nrm_old_entry.ne_file.len = name->len;
+ nr.nrn_old_entry.nrm_old_entry.ne_file.data = (char *)name->name;
+ nr.nrn_old_entry.nrm_old_entry.ne_attrs.attrmask.count = 1;
+ nr.nrn_old_entry.nrm_old_entry.ne_attrs.attrmask.element = &zerobm;
+ take_dentry_name_snapshot(&n, new_dentry);
+ nr.nrn_new_entry.nad_new_entry.ne_file.len = n.name.len;
+ nr.nrn_new_entry.nad_new_entry.ne_file.data = (char *)n.name.name;
+ nr.nrn_new_entry.nad_new_entry.ne_attrs.attrmask.count = 1;
+ nr.nrn_new_entry.nad_new_entry.ne_attrs.attrmask.element = &zerobm;
+ ret = xdrgen_encode_notify_rename4(stream, &nr);
+ release_dentry_name_snapshot(&n);
+ if (!ret) {
+ pr_warn("nfsd: unable to marshal notify_rename4 to xdr stream\n");
+ continue;
+ }
+
+ /* grab a notify4 in the buffer and set it up */
+ ent->notify_mask.count = 1;
+ ent->notify_mask.element = &notify_rename_bitmap;
+ ent->notify_vals.len = (u8 *)stream->p - p;
+ ent->notify_vals.data = p;
+ ++nns->nns_idx;
+ }

if (nns->nns_idx)
nfsd4_run_cb_notify(ncn);

--
2.49.0