1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM dlm
4 
5 #if !defined(_TRACE_DLM_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_DLM_H
7 
8 #include <linux/dlm.h>
9 #include <linux/dlmconstants.h>
10 #include <linux/tracepoint.h>
11 
12 #include "../../../fs/dlm/dlm_internal.h"
13 
14 #define show_lock_flags(flags) __print_flags(flags, "|",	\
15 	{ DLM_LKF_NOQUEUE,	"NOQUEUE" },			\
16 	{ DLM_LKF_CANCEL,	"CANCEL" },			\
17 	{ DLM_LKF_CONVERT,	"CONVERT" },			\
18 	{ DLM_LKF_VALBLK,	"VALBLK" },			\
19 	{ DLM_LKF_QUECVT,	"QUECVT" },			\
20 	{ DLM_LKF_IVVALBLK,	"IVVALBLK" },			\
21 	{ DLM_LKF_CONVDEADLK,	"CONVDEADLK" },			\
22 	{ DLM_LKF_PERSISTENT,	"PERSISTENT" },			\
23 	{ DLM_LKF_NODLCKWT,	"NODLCKWT" },			\
24 	{ DLM_LKF_NODLCKBLK,	"NODLCKBLK" },			\
25 	{ DLM_LKF_EXPEDITE,	"EXPEDITE" },			\
26 	{ DLM_LKF_NOQUEUEBAST,	"NOQUEUEBAST" },		\
27 	{ DLM_LKF_HEADQUE,	"HEADQUE" },			\
28 	{ DLM_LKF_NOORDER,	"NOORDER" },			\
29 	{ DLM_LKF_ORPHAN,	"ORPHAN" },			\
30 	{ DLM_LKF_ALTPR,	"ALTPR" },			\
31 	{ DLM_LKF_ALTCW,	"ALTCW" },			\
32 	{ DLM_LKF_FORCEUNLOCK,	"FORCEUNLOCK" },		\
33 	{ DLM_LKF_TIMEOUT,	"TIMEOUT" })
34 
35 #define show_lock_mode(mode) __print_symbolic(mode,		\
36 	{ DLM_LOCK_IV,		"IV"},				\
37 	{ DLM_LOCK_NL,		"NL"},				\
38 	{ DLM_LOCK_CR,		"CR"},				\
39 	{ DLM_LOCK_CW,		"CW"},				\
40 	{ DLM_LOCK_PR,		"PR"},				\
41 	{ DLM_LOCK_PW,		"PW"},				\
42 	{ DLM_LOCK_EX,		"EX"})
43 
44 #define show_dlm_sb_flags(flags) __print_flags(flags, "|",	\
45 	{ DLM_SBF_DEMOTED,	"DEMOTED" },			\
46 	{ DLM_SBF_VALNOTVALID,	"VALNOTVALID" },		\
47 	{ DLM_SBF_ALTMODE,	"ALTMODE" })
48 
49 /* note: we begin tracing dlm_lock_start() only if ls and lkb are found */
50 TRACE_EVENT(dlm_lock_start,
51 
52 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, const void *name,
53 		 unsigned int namelen, int mode, __u32 flags),
54 
55 	TP_ARGS(ls, lkb, name, namelen, mode, flags),
56 
57 	TP_STRUCT__entry(
58 		__field(__u32, ls_id)
59 		__field(__u32, lkb_id)
60 		__field(int, mode)
61 		__field(__u32, flags)
62 		__dynamic_array(unsigned char, res_name,
63 				lkb->lkb_resource ? lkb->lkb_resource->res_length : namelen)
64 	),
65 
66 	TP_fast_assign(
67 		struct dlm_rsb *r;
68 
69 		__entry->ls_id = ls->ls_global_id;
70 		__entry->lkb_id = lkb->lkb_id;
71 		__entry->mode = mode;
72 		__entry->flags = flags;
73 
74 		r = lkb->lkb_resource;
75 		if (r)
76 			memcpy(__get_dynamic_array(res_name), r->res_name,
77 			       __get_dynamic_array_len(res_name));
78 		else if (name)
79 			memcpy(__get_dynamic_array(res_name), name,
80 			       __get_dynamic_array_len(res_name));
81 	),
82 
83 	TP_printk("ls_id=%u lkb_id=%x mode=%s flags=%s res_name=%s",
84 		  __entry->ls_id, __entry->lkb_id,
85 		  show_lock_mode(__entry->mode),
86 		  show_lock_flags(__entry->flags),
87 		  __print_hex_str(__get_dynamic_array(res_name),
88 				  __get_dynamic_array_len(res_name)))
89 
90 );
91 
92 TRACE_EVENT(dlm_lock_end,
93 
94 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, const void *name,
95 		 unsigned int namelen, int mode, __u32 flags, int error,
96 		 bool kernel_lock),
97 
98 	TP_ARGS(ls, lkb, name, namelen, mode, flags, error, kernel_lock),
99 
100 	TP_STRUCT__entry(
101 		__field(__u32, ls_id)
102 		__field(__u32, lkb_id)
103 		__field(int, mode)
104 		__field(__u32, flags)
105 		__field(int, error)
106 		__dynamic_array(unsigned char, res_name,
107 				lkb->lkb_resource ? lkb->lkb_resource->res_length : namelen)
108 	),
109 
110 	TP_fast_assign(
111 		struct dlm_rsb *r;
112 
113 		__entry->ls_id = ls->ls_global_id;
114 		__entry->lkb_id = lkb->lkb_id;
115 		__entry->mode = mode;
116 		__entry->flags = flags;
117 		__entry->error = error;
118 
119 		r = lkb->lkb_resource;
120 		if (r)
121 			memcpy(__get_dynamic_array(res_name), r->res_name,
122 			       __get_dynamic_array_len(res_name));
123 		else if (name)
124 			memcpy(__get_dynamic_array(res_name), name,
125 			       __get_dynamic_array_len(res_name));
126 
127 		if (kernel_lock) {
128 			/* return value will be zeroed in those cases by dlm_lock()
129 			 * we do it here again to not introduce more overhead if
130 			 * trace isn't running and error reflects the return value.
131 			 */
132 			if (error == -EAGAIN || error == -EDEADLK)
133 				__entry->error = 0;
134 		}
135 
136 	),
137 
138 	TP_printk("ls_id=%u lkb_id=%x mode=%s flags=%s error=%d res_name=%s",
139 		  __entry->ls_id, __entry->lkb_id,
140 		  show_lock_mode(__entry->mode),
141 		  show_lock_flags(__entry->flags), __entry->error,
142 		  __print_hex_str(__get_dynamic_array(res_name),
143 				  __get_dynamic_array_len(res_name)))
144 
145 );
146 
147 TRACE_EVENT(dlm_bast,
148 
149 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, int mode),
150 
151 	TP_ARGS(ls, lkb, mode),
152 
153 	TP_STRUCT__entry(
154 		__field(__u32, ls_id)
155 		__field(__u32, lkb_id)
156 		__field(int, mode)
157 		__dynamic_array(unsigned char, res_name,
158 				lkb->lkb_resource ? lkb->lkb_resource->res_length : 0)
159 	),
160 
161 	TP_fast_assign(
162 		struct dlm_rsb *r;
163 
164 		__entry->ls_id = ls->ls_global_id;
165 		__entry->lkb_id = lkb->lkb_id;
166 		__entry->mode = mode;
167 
168 		r = lkb->lkb_resource;
169 		if (r)
170 			memcpy(__get_dynamic_array(res_name), r->res_name,
171 			       __get_dynamic_array_len(res_name));
172 	),
173 
174 	TP_printk("ls_id=%u lkb_id=%x mode=%s res_name=%s",
175 		  __entry->ls_id, __entry->lkb_id,
176 		  show_lock_mode(__entry->mode),
177 		  __print_hex_str(__get_dynamic_array(res_name),
178 				  __get_dynamic_array_len(res_name)))
179 
180 );
181 
182 TRACE_EVENT(dlm_ast,
183 
184 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb),
185 
186 	TP_ARGS(ls, lkb),
187 
188 	TP_STRUCT__entry(
189 		__field(__u32, ls_id)
190 		__field(__u32, lkb_id)
191 		__field(u8, sb_flags)
192 		__field(int, sb_status)
193 		__dynamic_array(unsigned char, res_name,
194 				lkb->lkb_resource ? lkb->lkb_resource->res_length : 0)
195 	),
196 
197 	TP_fast_assign(
198 		struct dlm_rsb *r;
199 
200 		__entry->ls_id = ls->ls_global_id;
201 		__entry->lkb_id = lkb->lkb_id;
202 		__entry->sb_flags = lkb->lkb_lksb->sb_flags;
203 		__entry->sb_status = lkb->lkb_lksb->sb_status;
204 
205 		r = lkb->lkb_resource;
206 		if (r)
207 			memcpy(__get_dynamic_array(res_name), r->res_name,
208 			       __get_dynamic_array_len(res_name));
209 	),
210 
211 	TP_printk("ls_id=%u lkb_id=%x sb_flags=%s sb_status=%d res_name=%s",
212 		  __entry->ls_id, __entry->lkb_id,
213 		  show_dlm_sb_flags(__entry->sb_flags), __entry->sb_status,
214 		  __print_hex_str(__get_dynamic_array(res_name),
215 				  __get_dynamic_array_len(res_name)))
216 
217 );
218 
219 /* note: we begin tracing dlm_unlock_start() only if ls and lkb are found */
220 TRACE_EVENT(dlm_unlock_start,
221 
222 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, __u32 flags),
223 
224 	TP_ARGS(ls, lkb, flags),
225 
226 	TP_STRUCT__entry(
227 		__field(__u32, ls_id)
228 		__field(__u32, lkb_id)
229 		__field(__u32, flags)
230 		__dynamic_array(unsigned char, res_name,
231 				lkb->lkb_resource ? lkb->lkb_resource->res_length : 0)
232 	),
233 
234 	TP_fast_assign(
235 		struct dlm_rsb *r;
236 
237 		__entry->ls_id = ls->ls_global_id;
238 		__entry->lkb_id = lkb->lkb_id;
239 		__entry->flags = flags;
240 
241 		r = lkb->lkb_resource;
242 		if (r)
243 			memcpy(__get_dynamic_array(res_name), r->res_name,
244 			       __get_dynamic_array_len(res_name));
245 	),
246 
247 	TP_printk("ls_id=%u lkb_id=%x flags=%s res_name=%s",
248 		  __entry->ls_id, __entry->lkb_id,
249 		  show_lock_flags(__entry->flags),
250 		  __print_hex_str(__get_dynamic_array(res_name),
251 				  __get_dynamic_array_len(res_name)))
252 
253 );
254 
255 TRACE_EVENT(dlm_unlock_end,
256 
257 	TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, __u32 flags,
258 		 int error),
259 
260 	TP_ARGS(ls, lkb, flags, error),
261 
262 	TP_STRUCT__entry(
263 		__field(__u32, ls_id)
264 		__field(__u32, lkb_id)
265 		__field(__u32, flags)
266 		__field(int, error)
267 		__dynamic_array(unsigned char, res_name,
268 				lkb->lkb_resource ? lkb->lkb_resource->res_length : 0)
269 	),
270 
271 	TP_fast_assign(
272 		struct dlm_rsb *r;
273 
274 		__entry->ls_id = ls->ls_global_id;
275 		__entry->lkb_id = lkb->lkb_id;
276 		__entry->flags = flags;
277 		__entry->error = error;
278 
279 		r = lkb->lkb_resource;
280 		if (r)
281 			memcpy(__get_dynamic_array(res_name), r->res_name,
282 			       __get_dynamic_array_len(res_name));
283 	),
284 
285 	TP_printk("ls_id=%u lkb_id=%x flags=%s error=%d res_name=%s",
286 		  __entry->ls_id, __entry->lkb_id,
287 		  show_lock_flags(__entry->flags), __entry->error,
288 		  __print_hex_str(__get_dynamic_array(res_name),
289 				  __get_dynamic_array_len(res_name)))
290 
291 );
292 
293 TRACE_EVENT(dlm_send,
294 
295 	TP_PROTO(int nodeid, int ret),
296 
297 	TP_ARGS(nodeid, ret),
298 
299 	TP_STRUCT__entry(
300 		__field(int, nodeid)
301 		__field(int, ret)
302 	),
303 
304 	TP_fast_assign(
305 		__entry->nodeid = nodeid;
306 		__entry->ret = ret;
307 	),
308 
309 	TP_printk("nodeid=%d ret=%d", __entry->nodeid, __entry->ret)
310 
311 );
312 
313 TRACE_EVENT(dlm_recv,
314 
315 	TP_PROTO(int nodeid, int ret),
316 
317 	TP_ARGS(nodeid, ret),
318 
319 	TP_STRUCT__entry(
320 		__field(int, nodeid)
321 		__field(int, ret)
322 	),
323 
324 	TP_fast_assign(
325 		__entry->nodeid = nodeid;
326 		__entry->ret = ret;
327 	),
328 
329 	TP_printk("nodeid=%d ret=%d", __entry->nodeid, __entry->ret)
330 
331 );
332 
333 #endif /* if !defined(_TRACE_DLM_H) || defined(TRACE_HEADER_MULTI_READ) */
334 
335 /* This part must be outside protection */
336 #include <trace/define_trace.h>
337