diff mbox series

[2/4] nfsd: add a tracepoint for nfsd_setattr

Message ID 20250306-nfsd-tracepoints-v1-2-4405bf41b95f@kernel.org (mailing list archive)
State Not Applicable
Headers show
Series nfsd: observability improvements | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch warning CHECK: Alignment should match open parenthesis CHECK: Lines should not end with a '(' WARNING: line length of 87 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 14 this patch: 14
netdev/source_inline success Was 0 now: 0

Commit Message

Jeff Layton March 6, 2025, 12:38 p.m. UTC
Turn Sargun's internal kprobe based implementation of this into a normal
static tracepoint.

Cc: Sargun Dillon <sargun@meta.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/trace.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/vfs.c   |  2 ++
 2 files changed, 56 insertions(+)

Comments

Chuck Lever March 6, 2025, 2:19 p.m. UTC | #1
On 3/6/25 7:38 AM, Jeff Layton wrote:
> Turn Sargun's internal kprobe based implementation of this into a normal
> static tracepoint.
> 
> Cc: Sargun Dillon <sargun@meta.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  fs/nfsd/trace.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  fs/nfsd/vfs.c   |  2 ++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
> index 0d49fc064f7273f32c93732a993fd77bc0783f5d..117f7e1fd66a4838a048cc44bd5bf4dd8c6db958 100644
> --- a/fs/nfsd/trace.h
> +++ b/fs/nfsd/trace.h
> @@ -2337,6 +2337,60 @@ DEFINE_EVENT(nfsd_copy_async_done_class,		\
>  DEFINE_COPY_ASYNC_DONE_EVENT(done);
>  DEFINE_COPY_ASYNC_DONE_EVENT(cancel);
>  
> +#define show_ia_valid_flags(x)					\
> +	__print_flags(x, "|",					\
> +			{ ATTR_MODE, "MODE" },			\
> +			{ ATTR_UID, "UID" },			\
> +			{ ATTR_GID, "GID" },			\
> +			{ ATTR_SIZE, "SIZE" },			\
> +			{ ATTR_ATIME, "ATIME" },		\
> +			{ ATTR_MTIME, "MTIME" },		\
> +			{ ATTR_CTIME, "CTIME" },		\
> +			{ ATTR_ATIME_SET, "ATIME_SET" },	\
> +			{ ATTR_MTIME_SET, "MTIME_SET" },	\
> +			{ ATTR_FORCE, "FORCE" },		\
> +			{ ATTR_KILL_SUID, "KILL_SUID" },	\
> +			{ ATTR_KILL_SGID, "KILL_SGID" },	\
> +			{ ATTR_FILE, "FILE" },			\
> +			{ ATTR_KILL_PRIV, "KILL_PRIV" },	\
> +			{ ATTR_OPEN, "OPEN" },			\
> +			{ ATTR_TIMES_SET, "TIMES_SET" },	\
> +			{ ATTR_TOUCH, "TOUCH"})

Let's add the above helper in include/trace/misc/fs.h instead.


> +
> +TRACE_EVENT(nfsd_setattr,
> +	TP_PROTO(const struct svc_rqst *rqstp, const struct svc_fh *fhp,
> +		 const struct iattr *iap, const struct timespec64 *guardtime),
> +	TP_ARGS(rqstp, fhp, iap, guardtime),
> +	TP_STRUCT__entry(
> +		__field(u32, xid)
> +		__field(u32, fh_hash)
> +		__field(s64, gtime_tv_sec)
> +		__field(u32, gtime_tv_nsec)
> +		__field(unsigned int, ia_valid)
> +		__field(umode_t, ia_mode)
> +		__field(uid_t, ia_uid)
> +		__field(gid_t, ia_gid)
> +		__field(loff_t, ia_size)
> +	),
> +	TP_fast_assign(__entry->xid = be32_to_cpu(rqstp->rq_xid);
> +	       __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
> +	       __entry->gtime_tv_sec = guardtime ? guardtime->tv_sec : 0;
> +	       __entry->gtime_tv_nsec = guardtime ? guardtime->tv_nsec : 0;
> +	       __entry->ia_valid = iap->ia_valid;
> +	       __entry->ia_mode = iap->ia_mode;
> +	       __entry->ia_uid = __kuid_val(iap->ia_uid);
> +	       __entry->ia_gid = __kgid_val(iap->ia_gid);
> +	       __entry->ia_size = iap->ia_size;
> +
> +	),
> +	TP_printk(
> +		"xid=0x%08x fh_hash=0x%08x ia_valid=%s ia_mode=%o ia_uid=%u ia_gid=%u guard_time=%lld.%u",
> +		__entry->xid, __entry->fh_hash, show_ia_valid_flags(__entry->ia_valid),
> +		__entry->ia_mode, __entry->ia_uid, __entry->ia_gid,
> +		__entry->gtime_tv_sec, __entry->gtime_tv_nsec
> +	)
> +)
> +
>  #endif /* _NFSD_TRACE_H */
>  
>  #undef TRACE_INCLUDE_PATH
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 390ddfb169083535faa3a2413389e247bdbf4a73..d755cc87a8670c491e55194de266d999ba1b337d 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -499,6 +499,8 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  	bool		size_change = (iap->ia_valid & ATTR_SIZE);
>  	int		retries;
>  
> +	trace_nfsd_setattr(rqstp, fhp, iap, guardtime);
> +
>  	if (iap->ia_valid & ATTR_SIZE) {
>  		accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
>  		ftype = S_IFREG;
>
diff mbox series

Patch

diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index 0d49fc064f7273f32c93732a993fd77bc0783f5d..117f7e1fd66a4838a048cc44bd5bf4dd8c6db958 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -2337,6 +2337,60 @@  DEFINE_EVENT(nfsd_copy_async_done_class,		\
 DEFINE_COPY_ASYNC_DONE_EVENT(done);
 DEFINE_COPY_ASYNC_DONE_EVENT(cancel);
 
+#define show_ia_valid_flags(x)					\
+	__print_flags(x, "|",					\
+			{ ATTR_MODE, "MODE" },			\
+			{ ATTR_UID, "UID" },			\
+			{ ATTR_GID, "GID" },			\
+			{ ATTR_SIZE, "SIZE" },			\
+			{ ATTR_ATIME, "ATIME" },		\
+			{ ATTR_MTIME, "MTIME" },		\
+			{ ATTR_CTIME, "CTIME" },		\
+			{ ATTR_ATIME_SET, "ATIME_SET" },	\
+			{ ATTR_MTIME_SET, "MTIME_SET" },	\
+			{ ATTR_FORCE, "FORCE" },		\
+			{ ATTR_KILL_SUID, "KILL_SUID" },	\
+			{ ATTR_KILL_SGID, "KILL_SGID" },	\
+			{ ATTR_FILE, "FILE" },			\
+			{ ATTR_KILL_PRIV, "KILL_PRIV" },	\
+			{ ATTR_OPEN, "OPEN" },			\
+			{ ATTR_TIMES_SET, "TIMES_SET" },	\
+			{ ATTR_TOUCH, "TOUCH"})
+
+TRACE_EVENT(nfsd_setattr,
+	TP_PROTO(const struct svc_rqst *rqstp, const struct svc_fh *fhp,
+		 const struct iattr *iap, const struct timespec64 *guardtime),
+	TP_ARGS(rqstp, fhp, iap, guardtime),
+	TP_STRUCT__entry(
+		__field(u32, xid)
+		__field(u32, fh_hash)
+		__field(s64, gtime_tv_sec)
+		__field(u32, gtime_tv_nsec)
+		__field(unsigned int, ia_valid)
+		__field(umode_t, ia_mode)
+		__field(uid_t, ia_uid)
+		__field(gid_t, ia_gid)
+		__field(loff_t, ia_size)
+	),
+	TP_fast_assign(__entry->xid = be32_to_cpu(rqstp->rq_xid);
+	       __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
+	       __entry->gtime_tv_sec = guardtime ? guardtime->tv_sec : 0;
+	       __entry->gtime_tv_nsec = guardtime ? guardtime->tv_nsec : 0;
+	       __entry->ia_valid = iap->ia_valid;
+	       __entry->ia_mode = iap->ia_mode;
+	       __entry->ia_uid = __kuid_val(iap->ia_uid);
+	       __entry->ia_gid = __kgid_val(iap->ia_gid);
+	       __entry->ia_size = iap->ia_size;
+
+	),
+	TP_printk(
+		"xid=0x%08x fh_hash=0x%08x ia_valid=%s ia_mode=%o ia_uid=%u ia_gid=%u guard_time=%lld.%u",
+		__entry->xid, __entry->fh_hash, show_ia_valid_flags(__entry->ia_valid),
+		__entry->ia_mode, __entry->ia_uid, __entry->ia_gid,
+		__entry->gtime_tv_sec, __entry->gtime_tv_nsec
+	)
+)
+
 #endif /* _NFSD_TRACE_H */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 390ddfb169083535faa3a2413389e247bdbf4a73..d755cc87a8670c491e55194de266d999ba1b337d 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -499,6 +499,8 @@  nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	bool		size_change = (iap->ia_valid & ATTR_SIZE);
 	int		retries;
 
+	trace_nfsd_setattr(rqstp, fhp, iap, guardtime);
+
 	if (iap->ia_valid & ATTR_SIZE) {
 		accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
 		ftype = S_IFREG;