Skip to content

Commit 90af1e8

Browse files
snajpatonyhutter
andauthored
Linux 6.10 compat: Fix tracepoints definitions
__string field definition includes the source variable for a value of the string when the TP hits; in 6.10+ kernels, __assign_str() uses that to copy a value from src to the string, with older kernels, __assign_str still accepted src as a second parameter. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Pavel Snajdr <[email protected]> Co-authored-by: Tony Hutter <[email protected]> Closes #16475 Closes #16515
1 parent ac04407 commit 90af1e8

File tree

5 files changed

+82
-19
lines changed

5 files changed

+82
-19
lines changed

config/kernel-assign_str.m4

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
dnl #
2+
dnl # 6.10 kernel, check number of args of __assign_str() for trace:
3+
dnl
4+
dnl # 6.10+: one arg
5+
dnl # 6.9 and older: two args
6+
dnl #
7+
dnl # More specifically, this will test to see if __assign_str() takes one
8+
dnl # arg. If __assign_str() takes two args, or is not defined, then
9+
dnl # HAVE_1ARG_ASSIGN_STR will not be set.
10+
dnl #
11+
AC_DEFUN([ZFS_AC_KERNEL_1ARG_ASSIGN_STR], [
12+
AC_MSG_CHECKING([whether __assign_str() has one arg])
13+
ZFS_LINUX_TRY_COMPILE_HEADER([
14+
#include <linux/module.h>
15+
MODULE_LICENSE("$ZFS_META_LICENSE");
16+
17+
#define CREATE_TRACE_POINTS
18+
#include "conftest.h"
19+
],[
20+
trace_zfs_autoconf_event_one("1");
21+
trace_zfs_autoconf_event_two("2");
22+
],[
23+
AC_MSG_RESULT(yes)
24+
AC_DEFINE(HAVE_1ARG_ASSIGN_STR, 1,
25+
[__assign_str() has one arg])
26+
],[
27+
AC_MSG_RESULT(no)
28+
],[
29+
#if !defined(_CONFTEST_H) || defined(TRACE_HEADER_MULTI_READ)
30+
#define _CONFTEST_H
31+
32+
#undef TRACE_SYSTEM
33+
#define TRACE_SYSTEM zfs
34+
#include <linux/tracepoint.h>
35+
36+
DECLARE_EVENT_CLASS(zfs_autoconf_event_class,
37+
TP_PROTO(char *string),
38+
TP_ARGS(string),
39+
TP_STRUCT__entry(
40+
__string(str, string)
41+
),
42+
TP_fast_assign(
43+
__assign_str(str);
44+
),
45+
TP_printk("str = %s", __get_str(str))
46+
);
47+
48+
#define DEFINE_AUTOCONF_EVENT(name) \
49+
DEFINE_EVENT(zfs_autoconf_event_class, name, \
50+
TP_PROTO(char * str), \
51+
TP_ARGS(str))
52+
DEFINE_AUTOCONF_EVENT(zfs_autoconf_event_one);
53+
DEFINE_AUTOCONF_EVENT(zfs_autoconf_event_two);
54+
55+
#endif /* _CONFTEST_H */
56+
57+
#undef TRACE_INCLUDE_PATH
58+
#define TRACE_INCLUDE_PATH .
59+
#define TRACE_INCLUDE_FILE conftest
60+
#include <trace/define_trace.h>
61+
])
62+
])

config/kernel.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
332332
ZFS_AC_KERNEL_SYNC_BDEV
333333
ZFS_AC_KERNEL_MM_PAGE_SIZE
334334
ZFS_AC_KERNEL_MM_PAGE_MAPPING
335+
ZFS_AC_KERNEL_1ARG_ASSIGN_STR
335336
case "$host_cpu" in
336337
powerpc*)
337338
ZFS_AC_KERNEL_CPU_HAS_FEATURE

include/os/linux/spl/sys/types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ typedef struct user_namespace zidmap_t;
8383

8484
extern zidmap_t *zfs_init_idmap;
8585

86+
#ifdef HAVE_1ARG_ASSIGN_STR
87+
#define __assign_str_impl(a, b) __assign_str(a)
88+
#else
89+
#define __assign_str_impl(a, b) __assign_str(a, b)
90+
#endif
91+
8692
#endif /* _SPL_TYPES_H */

include/os/linux/zfs/sys/trace_dbgmsg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define _TRACE_DBGMSG_H
3333

3434
#include <linux/tracepoint.h>
35+
#include <sys/types.h>
3536

3637
/*
3738
* This file defines tracepoint events for use by the dbgmsg(),
@@ -59,7 +60,7 @@ DECLARE_EVENT_CLASS(zfs_dprintf_class,
5960
__string(msg, msg)
6061
),
6162
TP_fast_assign(
62-
__assign_str(msg, msg);
63+
__assign_str_impl(msg, msg);
6364
),
6465
TP_printk("%s", __get_str(msg))
6566
);

include/os/linux/zfs/sys/trace_dbuf.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,25 @@
4545
* dmu_buf_impl_t *, ...,
4646
* zio_t *, ...);
4747
*/
48+
#define DBUF_TP_STRUCT_ENTRY_OS_SPA \
49+
(db != NULL && \
50+
POINTER_IS_VALID(DB_DNODE(db)->dn_objset)) \
51+
? spa_name(DB_DNODE(db)->dn_objset->os_spa) : "NULL"
4852

4953
#define DBUF_TP_STRUCT_ENTRY \
50-
__dynamic_array(char, os_spa, TRACE_DBUF_MSG_MAX) \
54+
__string(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA) \
5155
__field(uint64_t, ds_object) \
5256
__field(uint64_t, db_object) \
5357
__field(uint64_t, db_level) \
5458
__field(uint64_t, db_blkid) \
5559
__field(uint64_t, db_offset) \
5660
__field(uint64_t, db_size) \
5761
__field(uint64_t, db_state) \
58-
__field(int64_t, db_holds) \
59-
__dynamic_array(char, msg, TRACE_DBUF_MSG_MAX)
62+
__field(int64_t, db_holds)
6063

6164
#define DBUF_TP_FAST_ASSIGN \
6265
if (db != NULL) { \
63-
if (POINTER_IS_VALID(DB_DNODE(db)->dn_objset)) { \
64-
__assign_str(os_spa, \
65-
spa_name(DB_DNODE(db)->dn_objset->os_spa)); \
66-
} else { \
67-
__assign_str(os_spa, "NULL"); \
68-
} \
69-
\
66+
__assign_str_impl(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA); \
7067
__entry->ds_object = db->db_objset->os_dsl_dataset ? \
7168
db->db_objset->os_dsl_dataset->ds_object : 0; \
7269
\
@@ -77,10 +74,8 @@
7774
__entry->db_size = db->db.db_size; \
7875
__entry->db_state = db->db_state; \
7976
__entry->db_holds = zfs_refcount_count(&db->db_holds); \
80-
snprintf(__get_str(msg), TRACE_DBUF_MSG_MAX, \
81-
DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS); \
8277
} else { \
83-
__assign_str(os_spa, "NULL"); \
78+
__assign_str_impl(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA); \
8479
__entry->ds_object = 0; \
8580
__entry->db_object = 0; \
8681
__entry->db_level = 0; \
@@ -89,8 +84,6 @@
8984
__entry->db_size = 0; \
9085
__entry->db_state = 0; \
9186
__entry->db_holds = 0; \
92-
snprintf(__get_str(msg), TRACE_DBUF_MSG_MAX, \
93-
"dbuf { NULL }"); \
9487
}
9588

9689
#define DBUF_TP_PRINTK_FMT \
@@ -109,15 +102,15 @@ DECLARE_EVENT_CLASS(zfs_dbuf_class,
109102
TP_ARGS(db, zio),
110103
TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
111104
TP_fast_assign(DBUF_TP_FAST_ASSIGN),
112-
TP_printk("%s", __get_str(msg))
105+
TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
113106
);
114107

115108
DECLARE_EVENT_CLASS(zfs_dbuf_state_class,
116109
TP_PROTO(dmu_buf_impl_t *db, const char *why),
117110
TP_ARGS(db, why),
118111
TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
119112
TP_fast_assign(DBUF_TP_FAST_ASSIGN),
120-
TP_printk("%s", __get_str(msg))
113+
TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
121114
);
122115
/* END CSTYLED */
123116

@@ -139,7 +132,7 @@ DECLARE_EVENT_CLASS(zfs_dbuf_evict_one_class,
139132
TP_ARGS(db, mls),
140133
TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
141134
TP_fast_assign(DBUF_TP_FAST_ASSIGN),
142-
TP_printk("%s", __get_str(msg))
135+
TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
143136
);
144137
/* END CSTYLED */
145138

0 commit comments

Comments
 (0)