All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] NFSD: Clean up tracepoint string handling
@ 2021-07-19 15:01 Chuck Lever
  2021-07-19 15:01 ` [PATCH 1/3] tracing: Add trace_event helper macros __string_len() and __assign_str_len() Chuck Lever
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chuck Lever @ 2021-07-19 15:01 UTC (permalink / raw)
  To: linux-kernel, linux-nfs; +Cc: rostedt

As discussed last week, here's what I've added to the for-next topic
branch at:

  git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git

See:

  https://lore.kernel.org/lkml/20210715215753.4a314e97@rorschach.local.home/T/#u

---

Chuck Lever (2):
      NFSD: Use new __string_len C macros for the nfs_dirent tracepoint
      NFSD: Use new __string_len C macros for nfsd_clid_class

Steven Rostedt (VMware) (1):
      tracing: Add trace_event helper macros __string_len() and __assign_str_len()


 fs/nfsd/trace.h                            | 17 ++++++--------
 include/trace/trace_events.h               | 22 ++++++++++++++++++
 samples/trace_events/trace-events-sample.h | 27 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 10 deletions(-)

--
Chuck Lever


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] tracing: Add trace_event helper macros __string_len() and __assign_str_len()
  2021-07-19 15:01 [PATCH 0/3] NFSD: Clean up tracepoint string handling Chuck Lever
@ 2021-07-19 15:01 ` Chuck Lever
  2021-07-19 15:01 ` [PATCH 2/3] NFSD: Use new __string_len C macros for the nfs_dirent tracepoint Chuck Lever
  2021-07-19 15:01 ` [PATCH 3/3] NFSD: Use new __string_len C macros for nfsd_clid_class Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2021-07-19 15:01 UTC (permalink / raw)
  To: linux-kernel, linux-nfs; +Cc: rostedt

From: Steven Rostedt (VMware) <rostedt@goodmis.org>

There's a few cases that a string that is to be recorded in a trace event,
does not have a terminating 'nul' character, and instead, the tracepoint
passes in the length of the string to record.

Add two helper macros to the trace event code that lets this work easier,
than tricks with "%.*s" logic.

  __string_len() which is similar to __string() for declaration, but takes a
                 length argument.

  __assign_str_len() which is similar to __assign_str() for assiging the
                 string, but it too takes a length argument.

Note, the TRACE_EVENT() macro will allocate the location on the ring
buffer to 'len + 1', that will be used to store the string into. It is a
requirement that the 'len' used for this is a most the length of the
string being recorded.

This string can still use __get_str() just like strings created with
__string() can use to retrieve the string.

Link: https://lore.kernel.org/linux-nfs/20210513105018.7539996a@gandalf.local.home/

Tested-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 include/trace/trace_events.h               |   22 ++++++++++++++++++++++
 samples/trace_events/trace-events-sample.h |   27 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index acc17194c160..08810a463880 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -102,6 +102,9 @@ TRACE_MAKE_SYSTEM_STR();
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
 
@@ -197,6 +200,9 @@ TRACE_MAKE_SYSTEM_STR();
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 
@@ -459,6 +465,9 @@ static struct trace_event_functions trace_event_type_funcs_##call = {	\
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 
@@ -507,6 +516,9 @@ static struct trace_event_fields trace_event_fields_##call[] = {	\
 #define __string(item, src) __dynamic_array(char, item,			\
 		    strlen((src) ? (const char *)(src) : "(null)") + 1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
+
 /*
  * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
  * num_possible_cpus().
@@ -670,10 +682,20 @@ static inline notrace int trace_event_get_offsets_##call(		\
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __assign_str
 #define __assign_str(dst, src)						\
 	strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
 
+#undef __assign_str_len
+#define __assign_str_len(dst, src, len)					\
+	do {								\
+		memcpy(__get_str(dst), (src), (len));			\
+		__get_str(dst)[len] = '\0';				\
+	} while(0)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 13a35f7cbe66..e61471ab7d14 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -141,6 +141,33 @@
  *         In most cases, the __assign_str() macro will take the same
  *         parameters as the __string() macro had to declare the string.
  *
+ *   __string_len: This is a helper to a __dynamic_array, but it understands
+ *	   that the array has characters in it, and with the combined
+ *         use of __assign_str_len(), it will allocate 'len' + 1 bytes
+ *         in the ring buffer and add a '\0' to the string. This is
+ *         useful if the string being saved has no terminating '\0' byte.
+ *         It requires that the length of the string is known as it acts
+ *         like a memcpy().
+ *
+ *         Declared with:
+ *
+ *         __string_len(foo, bar, len)
+ *
+ *         To assign this string, use the helper macro __assign_str_len().
+ *
+ *         __assign_str(foo, bar, len);
+ *
+ *         Then len + 1 is allocated to the ring buffer, and a nul terminating
+ *         byte is added. This is similar to:
+ *
+ *         memcpy(__get_str(foo), bar, len);
+ *         __get_str(foo)[len] = 0;
+ *
+ *        The advantage of using this over __dynamic_array, is that it
+ *        takes care of allocating the extra byte on the ring buffer
+ *        for the '\0' terminating byte, and __get_str(foo) can be used
+ *        in the TP_printk().
+ *
  *   __bitmask: This is another kind of __dynamic_array, but it expects
  *         an array of longs, and the number of bits to parse. It takes
  *         two parameters (name, nr_bits), where name is the name of the



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] NFSD: Use new __string_len C macros for the nfs_dirent tracepoint
  2021-07-19 15:01 [PATCH 0/3] NFSD: Clean up tracepoint string handling Chuck Lever
  2021-07-19 15:01 ` [PATCH 1/3] tracing: Add trace_event helper macros __string_len() and __assign_str_len() Chuck Lever
@ 2021-07-19 15:01 ` Chuck Lever
  2021-07-19 15:01 ` [PATCH 3/3] NFSD: Use new __string_len C macros for nfsd_clid_class Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2021-07-19 15:01 UTC (permalink / raw)
  To: linux-kernel, linux-nfs; +Cc: rostedt

Clean up.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/trace.h |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index adaec43548d1..52a43acd546c 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -400,18 +400,16 @@ TRACE_EVENT(nfsd_dirent,
 	TP_STRUCT__entry(
 		__field(u32, fh_hash)
 		__field(u64, ino)
-		__field(int, len)
-		__dynamic_array(unsigned char, name, namlen)
+		__string_len(name, name, namlen)
 	),
 	TP_fast_assign(
 		__entry->fh_hash = fhp ? knfsd_fh_hash(&fhp->fh_handle) : 0;
 		__entry->ino = ino;
-		__entry->len = namlen;
-		memcpy(__get_str(name), name, namlen);
+		__assign_str_len(name, name, namlen)
 	),
-	TP_printk("fh_hash=0x%08x ino=%llu name=%.*s",
-		__entry->fh_hash, __entry->ino,
-		__entry->len, __get_str(name))
+	TP_printk("fh_hash=0x%08x ino=%llu name=%s",
+		__entry->fh_hash, __entry->ino, __get_str(name)
+	)
 )
 
 #include "state.h"



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] NFSD: Use new __string_len C macros for nfsd_clid_class
  2021-07-19 15:01 [PATCH 0/3] NFSD: Clean up tracepoint string handling Chuck Lever
  2021-07-19 15:01 ` [PATCH 1/3] tracing: Add trace_event helper macros __string_len() and __assign_str_len() Chuck Lever
  2021-07-19 15:01 ` [PATCH 2/3] NFSD: Use new __string_len C macros for the nfs_dirent tracepoint Chuck Lever
@ 2021-07-19 15:01 ` Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2021-07-19 15:01 UTC (permalink / raw)
  To: linux-kernel, linux-nfs; +Cc: rostedt

Clean up.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/trace.h |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index 52a43acd546c..538520957a81 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -606,7 +606,7 @@ DECLARE_EVENT_CLASS(nfsd_clid_class,
 		__array(unsigned char, addr, sizeof(struct sockaddr_in6))
 		__field(unsigned long, flavor)
 		__array(unsigned char, verifier, NFS4_VERIFIER_SIZE)
-		__dynamic_array(char, name, clp->cl_name.len + 1)
+		__string_len(name, name, clp->cl_name.len)
 	),
 	TP_fast_assign(
 		__entry->cl_boot = clp->cl_clientid.cl_boot;
@@ -616,8 +616,7 @@ DECLARE_EVENT_CLASS(nfsd_clid_class,
 		__entry->flavor = clp->cl_cred.cr_flavor;
 		memcpy(__entry->verifier, (void *)&clp->cl_verifier,
 		       NFS4_VERIFIER_SIZE);
-		memcpy(__get_str(name), clp->cl_name.data, clp->cl_name.len);
-		__get_str(name)[clp->cl_name.len] = '\0';
+		__assign_str_len(name, clp->cl_name.data, clp->cl_name.len);
 	),
 	TP_printk("addr=%pISpc name='%s' verifier=0x%s flavor=%s client=%08x:%08x",
 		__entry->addr, __get_str(name),



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-19 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-19 15:01 [PATCH 0/3] NFSD: Clean up tracepoint string handling Chuck Lever
2021-07-19 15:01 ` [PATCH 1/3] tracing: Add trace_event helper macros __string_len() and __assign_str_len() Chuck Lever
2021-07-19 15:01 ` [PATCH 2/3] NFSD: Use new __string_len C macros for the nfs_dirent tracepoint Chuck Lever
2021-07-19 15:01 ` [PATCH 3/3] NFSD: Use new __string_len C macros for nfsd_clid_class Chuck Lever

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.