[PATCH RFC v2 26/28] nfsd: add a tracepoint for nfsd_file_fsnotify_handle_dir_event()

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

Repurpose the existing nfsd_file_fsnotify_handle_event tracepoint() as a
class and call it from the dir notificaiton codepath. Add info about the
dir to it.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/filecache.c | 2 +-
fs/nfsd/nfs4state.c | 3 +++
fs/nfsd/trace.h | 25 ++++++++++++++++++-------
3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index 6cd4cfa0b46bf33c4134987a12e42c8455fc4879..ba72470b870cd0e266ba7fac8174a1a249a840e8 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -743,7 +743,7 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask,
if (WARN_ON_ONCE(!inode))
return 0;

- trace_nfsd_file_fsnotify_handle_event(inode, mask);
+ trace_nfsd_file_fsnotify_handle_event(inode, dir, mask);

/* Should be no marks on non-regular files */
if (!S_ISREG(inode->i_mode)) {
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a75179ffa6006868bae3931263830d7b7e1a8882..a610a90d119a771771cdb60ce3ee4ab3604cb8a3 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -9640,9 +9640,12 @@ int
nfsd_handle_dir_event(u32 mask, const struct inode *dir, const void *data,
int data_type, const struct qstr *name)
{
+ struct inode *inode = fsnotify_data_inode(data, data_type);
struct file_lock_context *ctx;
struct file_lock_core *flc;

+ trace_nfsd_file_fsnotify_handle_dir_event(inode, dir, mask);
+
ctx = locks_inode_context(dir);
if (!ctx || list_empty(&ctx->flc_lease))
return 0;
diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index 0c68df50eae248c7c9afe0437dfcf29837e09275..968e13a721942c051448f21af2f13849511b7c6a 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -1293,25 +1293,36 @@ TRACE_EVENT(nfsd_file_is_cached,
)
);

-TRACE_EVENT(nfsd_file_fsnotify_handle_event,
- TP_PROTO(struct inode *inode, u32 mask),
- TP_ARGS(inode, mask),
+DECLARE_EVENT_CLASS(nfsd_file_fsnotify_handle_event_class,
+ TP_PROTO(const struct inode *inode, const struct inode *dir, u32 mask),
+ TP_ARGS(inode, dir, mask),
TP_STRUCT__entry(
- __field(struct inode *, inode)
+ __field(ino_t, ino)
+ __field(ino_t, dir)
__field(unsigned int, nlink)
__field(umode_t, mode)
__field(u32, mask)
),
TP_fast_assign(
- __entry->inode = inode;
+ __entry->ino = inode->i_ino;
+ __entry->dir = dir ? dir->i_ino : 0;
__entry->nlink = inode->i_nlink;
__entry->mode = inode->i_mode;
__entry->mask = mask;
),
- TP_printk("inode=%p nlink=%u mode=0%ho mask=0x%x", __entry->inode,
- __entry->nlink, __entry->mode, __entry->mask)
+ TP_printk("dir=%lu inode=%lu nlink=%u mode=0%ho mask=0x%x",
+ __entry->dir, __entry->ino, __entry->nlink,
+ __entry->mode, __entry->mask)
);

+#define DEFINE_NFSD_FSNOTIFY_HANDLE_EVENT(name) \
+DEFINE_EVENT(nfsd_file_fsnotify_handle_event_class, name, \
+ TP_PROTO(const struct inode *inode, const struct inode *dir, u32 mask), \
+ TP_ARGS(inode, dir, mask))
+
+DEFINE_NFSD_FSNOTIFY_HANDLE_EVENT(nfsd_file_fsnotify_handle_event);
+DEFINE_NFSD_FSNOTIFY_HANDLE_EVENT(nfsd_file_fsnotify_handle_dir_event);
+
DECLARE_EVENT_CLASS(nfsd_file_gc_class,
TP_PROTO(
const struct nfsd_file *nf

--
2.49.0