1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Network filesystem support module tracepoints
3  *
4  * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7 #undef TRACE_SYSTEM
8 #define TRACE_SYSTEM netfs
9 
10 #if !defined(_TRACE_NETFS_H) || defined(TRACE_HEADER_MULTI_READ)
11 #define _TRACE_NETFS_H
12 
13 #include <linux/tracepoint.h>
14 
15 /*
16  * Define enums for tracing information.
17  */
18 #define netfs_read_traces					\
19 	EM(netfs_read_trace_expanded,		"EXPANDED ")	\
20 	EM(netfs_read_trace_readahead,		"READAHEAD")	\
21 	EM(netfs_read_trace_readpage,		"READPAGE ")	\
22 	E_(netfs_read_trace_write_begin,	"WRITEBEGN")
23 
24 #define netfs_rreq_origins					\
25 	EM(NETFS_READAHEAD,			"RA")		\
26 	EM(NETFS_READPAGE,			"RP")		\
27 	E_(NETFS_READ_FOR_WRITE,		"RW")
28 
29 #define netfs_rreq_traces					\
30 	EM(netfs_rreq_trace_assess,		"ASSESS ")	\
31 	EM(netfs_rreq_trace_copy,		"COPY   ")	\
32 	EM(netfs_rreq_trace_done,		"DONE   ")	\
33 	EM(netfs_rreq_trace_free,		"FREE   ")	\
34 	EM(netfs_rreq_trace_resubmit,		"RESUBMT")	\
35 	EM(netfs_rreq_trace_unlock,		"UNLOCK ")	\
36 	E_(netfs_rreq_trace_unmark,		"UNMARK ")
37 
38 #define netfs_sreq_sources					\
39 	EM(NETFS_FILL_WITH_ZEROES,		"ZERO")		\
40 	EM(NETFS_DOWNLOAD_FROM_SERVER,		"DOWN")		\
41 	EM(NETFS_READ_FROM_CACHE,		"READ")		\
42 	E_(NETFS_INVALID_READ,			"INVL")		\
43 
44 #define netfs_sreq_traces					\
45 	EM(netfs_sreq_trace_download_instead,	"RDOWN")	\
46 	EM(netfs_sreq_trace_free,		"FREE ")	\
47 	EM(netfs_sreq_trace_prepare,		"PREP ")	\
48 	EM(netfs_sreq_trace_resubmit_short,	"SHORT")	\
49 	EM(netfs_sreq_trace_submit,		"SUBMT")	\
50 	EM(netfs_sreq_trace_terminated,		"TERM ")	\
51 	EM(netfs_sreq_trace_write,		"WRITE")	\
52 	EM(netfs_sreq_trace_write_skip,		"SKIP ")	\
53 	E_(netfs_sreq_trace_write_term,		"WTERM")
54 
55 #define netfs_failures							\
56 	EM(netfs_fail_check_write_begin,	"check-write-begin")	\
57 	EM(netfs_fail_copy_to_cache,		"copy-to-cache")	\
58 	EM(netfs_fail_read,			"read")			\
59 	EM(netfs_fail_short_read,		"short-read")		\
60 	E_(netfs_fail_prepare_write,		"prep-write")
61 
62 #define netfs_rreq_ref_traces					\
63 	EM(netfs_rreq_trace_get_hold,		"GET HOLD   ")	\
64 	EM(netfs_rreq_trace_get_subreq,		"GET SUBREQ ")	\
65 	EM(netfs_rreq_trace_put_complete,	"PUT COMPLT ")	\
66 	EM(netfs_rreq_trace_put_discard,	"PUT DISCARD")	\
67 	EM(netfs_rreq_trace_put_failed,		"PUT FAILED ")	\
68 	EM(netfs_rreq_trace_put_hold,		"PUT HOLD   ")	\
69 	EM(netfs_rreq_trace_put_subreq,		"PUT SUBREQ ")	\
70 	EM(netfs_rreq_trace_put_zero_len,	"PUT ZEROLEN")	\
71 	E_(netfs_rreq_trace_new,		"NEW        ")
72 
73 #define netfs_sreq_ref_traces					\
74 	EM(netfs_sreq_trace_get_copy_to_cache,	"GET COPY2C ")	\
75 	EM(netfs_sreq_trace_get_resubmit,	"GET RESUBMIT")	\
76 	EM(netfs_sreq_trace_get_short_read,	"GET SHORTRD")	\
77 	EM(netfs_sreq_trace_new,		"NEW        ")	\
78 	EM(netfs_sreq_trace_put_clear,		"PUT CLEAR  ")	\
79 	EM(netfs_sreq_trace_put_failed,		"PUT FAILED ")	\
80 	EM(netfs_sreq_trace_put_merged,		"PUT MERGED ")	\
81 	EM(netfs_sreq_trace_put_no_copy,	"PUT NO COPY")	\
82 	E_(netfs_sreq_trace_put_terminated,	"PUT TERM   ")
83 
84 #ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
85 #define __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
86 
87 #undef EM
88 #undef E_
89 #define EM(a, b) a,
90 #define E_(a, b) a
91 
92 enum netfs_read_trace { netfs_read_traces } __mode(byte);
93 enum netfs_rreq_trace { netfs_rreq_traces } __mode(byte);
94 enum netfs_sreq_trace { netfs_sreq_traces } __mode(byte);
95 enum netfs_failure { netfs_failures } __mode(byte);
96 enum netfs_rreq_ref_trace { netfs_rreq_ref_traces } __mode(byte);
97 enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte);
98 
99 #endif
100 
101 /*
102  * Export enum symbols via userspace.
103  */
104 #undef EM
105 #undef E_
106 #define EM(a, b) TRACE_DEFINE_ENUM(a);
107 #define E_(a, b) TRACE_DEFINE_ENUM(a);
108 
109 netfs_read_traces;
110 netfs_rreq_origins;
111 netfs_rreq_traces;
112 netfs_sreq_sources;
113 netfs_sreq_traces;
114 netfs_failures;
115 netfs_rreq_ref_traces;
116 netfs_sreq_ref_traces;
117 
118 /*
119  * Now redefine the EM() and E_() macros to map the enums to the strings that
120  * will be printed in the output.
121  */
122 #undef EM
123 #undef E_
124 #define EM(a, b)	{ a, b },
125 #define E_(a, b)	{ a, b }
126 
127 TRACE_EVENT(netfs_read,
128 	    TP_PROTO(struct netfs_io_request *rreq,
129 		     loff_t start, size_t len,
130 		     enum netfs_read_trace what),
131 
132 	    TP_ARGS(rreq, start, len, what),
133 
134 	    TP_STRUCT__entry(
135 		    __field(unsigned int,		rreq		)
136 		    __field(unsigned int,		cookie		)
137 		    __field(loff_t,			start		)
138 		    __field(size_t,			len		)
139 		    __field(enum netfs_read_trace,	what		)
140 		    __field(unsigned int,		netfs_inode	)
141 			     ),
142 
143 	    TP_fast_assign(
144 		    __entry->rreq	= rreq->debug_id;
145 		    __entry->cookie	= rreq->cache_resources.debug_id;
146 		    __entry->start	= start;
147 		    __entry->len	= len;
148 		    __entry->what	= what;
149 		    __entry->netfs_inode = rreq->inode->i_ino;
150 			   ),
151 
152 	    TP_printk("R=%08x %s c=%08x ni=%x s=%llx %zx",
153 		      __entry->rreq,
154 		      __print_symbolic(__entry->what, netfs_read_traces),
155 		      __entry->cookie,
156 		      __entry->netfs_inode,
157 		      __entry->start, __entry->len)
158 	    );
159 
160 TRACE_EVENT(netfs_rreq,
161 	    TP_PROTO(struct netfs_io_request *rreq,
162 		     enum netfs_rreq_trace what),
163 
164 	    TP_ARGS(rreq, what),
165 
166 	    TP_STRUCT__entry(
167 		    __field(unsigned int,		rreq		)
168 		    __field(unsigned int,		flags		)
169 		    __field(enum netfs_io_origin,	origin		)
170 		    __field(enum netfs_rreq_trace,	what		)
171 			     ),
172 
173 	    TP_fast_assign(
174 		    __entry->rreq	= rreq->debug_id;
175 		    __entry->flags	= rreq->flags;
176 		    __entry->origin	= rreq->origin;
177 		    __entry->what	= what;
178 			   ),
179 
180 	    TP_printk("R=%08x %s %s f=%02x",
181 		      __entry->rreq,
182 		      __print_symbolic(__entry->origin, netfs_rreq_origins),
183 		      __print_symbolic(__entry->what, netfs_rreq_traces),
184 		      __entry->flags)
185 	    );
186 
187 TRACE_EVENT(netfs_sreq,
188 	    TP_PROTO(struct netfs_io_subrequest *sreq,
189 		     enum netfs_sreq_trace what),
190 
191 	    TP_ARGS(sreq, what),
192 
193 	    TP_STRUCT__entry(
194 		    __field(unsigned int,		rreq		)
195 		    __field(unsigned short,		index		)
196 		    __field(short,			error		)
197 		    __field(unsigned short,		flags		)
198 		    __field(enum netfs_io_source,	source		)
199 		    __field(enum netfs_sreq_trace,	what		)
200 		    __field(size_t,			len		)
201 		    __field(size_t,			transferred	)
202 		    __field(loff_t,			start		)
203 			     ),
204 
205 	    TP_fast_assign(
206 		    __entry->rreq	= sreq->rreq->debug_id;
207 		    __entry->index	= sreq->debug_index;
208 		    __entry->error	= sreq->error;
209 		    __entry->flags	= sreq->flags;
210 		    __entry->source	= sreq->source;
211 		    __entry->what	= what;
212 		    __entry->len	= sreq->len;
213 		    __entry->transferred = sreq->transferred;
214 		    __entry->start	= sreq->start;
215 			   ),
216 
217 	    TP_printk("R=%08x[%u] %s %s f=%02x s=%llx %zx/%zx e=%d",
218 		      __entry->rreq, __entry->index,
219 		      __print_symbolic(__entry->source, netfs_sreq_sources),
220 		      __print_symbolic(__entry->what, netfs_sreq_traces),
221 		      __entry->flags,
222 		      __entry->start, __entry->transferred, __entry->len,
223 		      __entry->error)
224 	    );
225 
226 TRACE_EVENT(netfs_failure,
227 	    TP_PROTO(struct netfs_io_request *rreq,
228 		     struct netfs_io_subrequest *sreq,
229 		     int error, enum netfs_failure what),
230 
231 	    TP_ARGS(rreq, sreq, error, what),
232 
233 	    TP_STRUCT__entry(
234 		    __field(unsigned int,		rreq		)
235 		    __field(short,			index		)
236 		    __field(short,			error		)
237 		    __field(unsigned short,		flags		)
238 		    __field(enum netfs_io_source,	source		)
239 		    __field(enum netfs_failure,		what		)
240 		    __field(size_t,			len		)
241 		    __field(size_t,			transferred	)
242 		    __field(loff_t,			start		)
243 			     ),
244 
245 	    TP_fast_assign(
246 		    __entry->rreq	= rreq->debug_id;
247 		    __entry->index	= sreq ? sreq->debug_index : -1;
248 		    __entry->error	= error;
249 		    __entry->flags	= sreq ? sreq->flags : 0;
250 		    __entry->source	= sreq ? sreq->source : NETFS_INVALID_READ;
251 		    __entry->what	= what;
252 		    __entry->len	= sreq ? sreq->len : rreq->len;
253 		    __entry->transferred = sreq ? sreq->transferred : 0;
254 		    __entry->start	= sreq ? sreq->start : 0;
255 			   ),
256 
257 	    TP_printk("R=%08x[%d] %s f=%02x s=%llx %zx/%zx %s e=%d",
258 		      __entry->rreq, __entry->index,
259 		      __print_symbolic(__entry->source, netfs_sreq_sources),
260 		      __entry->flags,
261 		      __entry->start, __entry->transferred, __entry->len,
262 		      __print_symbolic(__entry->what, netfs_failures),
263 		      __entry->error)
264 	    );
265 
266 TRACE_EVENT(netfs_rreq_ref,
267 	    TP_PROTO(unsigned int rreq_debug_id, int ref,
268 		     enum netfs_rreq_ref_trace what),
269 
270 	    TP_ARGS(rreq_debug_id, ref, what),
271 
272 	    TP_STRUCT__entry(
273 		    __field(unsigned int,		rreq		)
274 		    __field(int,			ref		)
275 		    __field(enum netfs_rreq_ref_trace,	what		)
276 			     ),
277 
278 	    TP_fast_assign(
279 		    __entry->rreq	= rreq_debug_id;
280 		    __entry->ref	= ref;
281 		    __entry->what	= what;
282 			   ),
283 
284 	    TP_printk("R=%08x %s r=%u",
285 		      __entry->rreq,
286 		      __print_symbolic(__entry->what, netfs_rreq_ref_traces),
287 		      __entry->ref)
288 	    );
289 
290 TRACE_EVENT(netfs_sreq_ref,
291 	    TP_PROTO(unsigned int rreq_debug_id, unsigned int subreq_debug_index,
292 		     int ref, enum netfs_sreq_ref_trace what),
293 
294 	    TP_ARGS(rreq_debug_id, subreq_debug_index, ref, what),
295 
296 	    TP_STRUCT__entry(
297 		    __field(unsigned int,		rreq		)
298 		    __field(unsigned int,		subreq		)
299 		    __field(int,			ref		)
300 		    __field(enum netfs_sreq_ref_trace,	what		)
301 			     ),
302 
303 	    TP_fast_assign(
304 		    __entry->rreq	= rreq_debug_id;
305 		    __entry->subreq	= subreq_debug_index;
306 		    __entry->ref	= ref;
307 		    __entry->what	= what;
308 			   ),
309 
310 	    TP_printk("R=%08x[%x] %s r=%u",
311 		      __entry->rreq,
312 		      __entry->subreq,
313 		      __print_symbolic(__entry->what, netfs_sreq_ref_traces),
314 		      __entry->ref)
315 	    );
316 
317 #undef EM
318 #undef E_
319 #endif /* _TRACE_NETFS_H */
320 
321 /* This part must be outside protection */
322 #include <trace/define_trace.h>
323