xref: /openbmc/linux/fs/nfsd/trace.h (revision 3dc4b6fb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2014 Christoph Hellwig.
4  */
5 #undef TRACE_SYSTEM
6 #define TRACE_SYSTEM nfsd
7 
8 #if !defined(_NFSD_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
9 #define _NFSD_TRACE_H
10 
11 #include <linux/tracepoint.h>
12 #include "nfsfh.h"
13 
14 TRACE_EVENT(nfsd_compound,
15 	TP_PROTO(const struct svc_rqst *rqst,
16 		 u32 args_opcnt),
17 	TP_ARGS(rqst, args_opcnt),
18 	TP_STRUCT__entry(
19 		__field(u32, xid)
20 		__field(u32, args_opcnt)
21 	),
22 	TP_fast_assign(
23 		__entry->xid = be32_to_cpu(rqst->rq_xid);
24 		__entry->args_opcnt = args_opcnt;
25 	),
26 	TP_printk("xid=0x%08x opcnt=%u",
27 		__entry->xid, __entry->args_opcnt)
28 )
29 
30 TRACE_EVENT(nfsd_compound_status,
31 	TP_PROTO(u32 args_opcnt,
32 		 u32 resp_opcnt,
33 		 __be32 status,
34 		 const char *name),
35 	TP_ARGS(args_opcnt, resp_opcnt, status, name),
36 	TP_STRUCT__entry(
37 		__field(u32, args_opcnt)
38 		__field(u32, resp_opcnt)
39 		__field(int, status)
40 		__string(name, name)
41 	),
42 	TP_fast_assign(
43 		__entry->args_opcnt = args_opcnt;
44 		__entry->resp_opcnt = resp_opcnt;
45 		__entry->status = be32_to_cpu(status);
46 		__assign_str(name, name);
47 	),
48 	TP_printk("op=%u/%u %s status=%d",
49 		__entry->resp_opcnt, __entry->args_opcnt,
50 		__get_str(name), __entry->status)
51 )
52 
53 DECLARE_EVENT_CLASS(nfsd_io_class,
54 	TP_PROTO(struct svc_rqst *rqstp,
55 		 struct svc_fh	*fhp,
56 		 loff_t		offset,
57 		 unsigned long	len),
58 	TP_ARGS(rqstp, fhp, offset, len),
59 	TP_STRUCT__entry(
60 		__field(u32, xid)
61 		__field(u32, fh_hash)
62 		__field(loff_t, offset)
63 		__field(unsigned long, len)
64 	),
65 	TP_fast_assign(
66 		__entry->xid = be32_to_cpu(rqstp->rq_xid);
67 		__entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
68 		__entry->offset = offset;
69 		__entry->len = len;
70 	),
71 	TP_printk("xid=0x%08x fh_hash=0x%08x offset=%lld len=%lu",
72 		  __entry->xid, __entry->fh_hash,
73 		  __entry->offset, __entry->len)
74 )
75 
76 #define DEFINE_NFSD_IO_EVENT(name)		\
77 DEFINE_EVENT(nfsd_io_class, nfsd_##name,	\
78 	TP_PROTO(struct svc_rqst *rqstp,	\
79 		 struct svc_fh	*fhp,		\
80 		 loff_t		offset,		\
81 		 unsigned long	len),		\
82 	TP_ARGS(rqstp, fhp, offset, len))
83 
84 DEFINE_NFSD_IO_EVENT(read_start);
85 DEFINE_NFSD_IO_EVENT(read_splice);
86 DEFINE_NFSD_IO_EVENT(read_vector);
87 DEFINE_NFSD_IO_EVENT(read_io_done);
88 DEFINE_NFSD_IO_EVENT(read_done);
89 DEFINE_NFSD_IO_EVENT(write_start);
90 DEFINE_NFSD_IO_EVENT(write_opened);
91 DEFINE_NFSD_IO_EVENT(write_io_done);
92 DEFINE_NFSD_IO_EVENT(write_done);
93 
94 DECLARE_EVENT_CLASS(nfsd_err_class,
95 	TP_PROTO(struct svc_rqst *rqstp,
96 		 struct svc_fh	*fhp,
97 		 loff_t		offset,
98 		 int		status),
99 	TP_ARGS(rqstp, fhp, offset, status),
100 	TP_STRUCT__entry(
101 		__field(u32, xid)
102 		__field(u32, fh_hash)
103 		__field(loff_t, offset)
104 		__field(int, status)
105 	),
106 	TP_fast_assign(
107 		__entry->xid = be32_to_cpu(rqstp->rq_xid);
108 		__entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
109 		__entry->offset = offset;
110 		__entry->status = status;
111 	),
112 	TP_printk("xid=0x%08x fh_hash=0x%08x offset=%lld status=%d",
113 		  __entry->xid, __entry->fh_hash,
114 		  __entry->offset, __entry->status)
115 )
116 
117 #define DEFINE_NFSD_ERR_EVENT(name)		\
118 DEFINE_EVENT(nfsd_err_class, nfsd_##name,	\
119 	TP_PROTO(struct svc_rqst *rqstp,	\
120 		 struct svc_fh	*fhp,		\
121 		 loff_t		offset,		\
122 		 int		len),		\
123 	TP_ARGS(rqstp, fhp, offset, len))
124 
125 DEFINE_NFSD_ERR_EVENT(read_err);
126 DEFINE_NFSD_ERR_EVENT(write_err);
127 
128 #include "state.h"
129 #include "filecache.h"
130 #include "vfs.h"
131 
132 DECLARE_EVENT_CLASS(nfsd_stateid_class,
133 	TP_PROTO(stateid_t *stp),
134 	TP_ARGS(stp),
135 	TP_STRUCT__entry(
136 		__field(u32, cl_boot)
137 		__field(u32, cl_id)
138 		__field(u32, si_id)
139 		__field(u32, si_generation)
140 	),
141 	TP_fast_assign(
142 		__entry->cl_boot = stp->si_opaque.so_clid.cl_boot;
143 		__entry->cl_id = stp->si_opaque.so_clid.cl_id;
144 		__entry->si_id = stp->si_opaque.so_id;
145 		__entry->si_generation = stp->si_generation;
146 	),
147 	TP_printk("client %08x:%08x stateid %08x:%08x",
148 		__entry->cl_boot,
149 		__entry->cl_id,
150 		__entry->si_id,
151 		__entry->si_generation)
152 )
153 
154 #define DEFINE_STATEID_EVENT(name) \
155 DEFINE_EVENT(nfsd_stateid_class, nfsd_##name, \
156 	TP_PROTO(stateid_t *stp), \
157 	TP_ARGS(stp))
158 DEFINE_STATEID_EVENT(layoutstate_alloc);
159 DEFINE_STATEID_EVENT(layoutstate_unhash);
160 DEFINE_STATEID_EVENT(layoutstate_free);
161 DEFINE_STATEID_EVENT(layout_get_lookup_fail);
162 DEFINE_STATEID_EVENT(layout_commit_lookup_fail);
163 DEFINE_STATEID_EVENT(layout_return_lookup_fail);
164 DEFINE_STATEID_EVENT(layout_recall);
165 DEFINE_STATEID_EVENT(layout_recall_done);
166 DEFINE_STATEID_EVENT(layout_recall_fail);
167 DEFINE_STATEID_EVENT(layout_recall_release);
168 
169 #define show_nf_flags(val)						\
170 	__print_flags(val, "|",						\
171 		{ 1 << NFSD_FILE_HASHED,	"HASHED" },		\
172 		{ 1 << NFSD_FILE_PENDING,	"PENDING" },		\
173 		{ 1 << NFSD_FILE_BREAK_READ,	"BREAK_READ" },		\
174 		{ 1 << NFSD_FILE_BREAK_WRITE,	"BREAK_WRITE" },	\
175 		{ 1 << NFSD_FILE_REFERENCED,	"REFERENCED"})
176 
177 /* FIXME: This should probably be fleshed out in the future. */
178 #define show_nf_may(val)						\
179 	__print_flags(val, "|",						\
180 		{ NFSD_MAY_READ,		"READ" },		\
181 		{ NFSD_MAY_WRITE,		"WRITE" },		\
182 		{ NFSD_MAY_NOT_BREAK_LEASE,	"NOT_BREAK_LEASE" })
183 
184 DECLARE_EVENT_CLASS(nfsd_file_class,
185 	TP_PROTO(struct nfsd_file *nf),
186 	TP_ARGS(nf),
187 	TP_STRUCT__entry(
188 		__field(unsigned int, nf_hashval)
189 		__field(void *, nf_inode)
190 		__field(int, nf_ref)
191 		__field(unsigned long, nf_flags)
192 		__field(unsigned char, nf_may)
193 		__field(struct file *, nf_file)
194 	),
195 	TP_fast_assign(
196 		__entry->nf_hashval = nf->nf_hashval;
197 		__entry->nf_inode = nf->nf_inode;
198 		__entry->nf_ref = atomic_read(&nf->nf_ref);
199 		__entry->nf_flags = nf->nf_flags;
200 		__entry->nf_may = nf->nf_may;
201 		__entry->nf_file = nf->nf_file;
202 	),
203 	TP_printk("hash=0x%x inode=0x%p ref=%d flags=%s may=%s file=%p",
204 		__entry->nf_hashval,
205 		__entry->nf_inode,
206 		__entry->nf_ref,
207 		show_nf_flags(__entry->nf_flags),
208 		show_nf_may(__entry->nf_may),
209 		__entry->nf_file)
210 )
211 
212 #define DEFINE_NFSD_FILE_EVENT(name) \
213 DEFINE_EVENT(nfsd_file_class, name, \
214 	TP_PROTO(struct nfsd_file *nf), \
215 	TP_ARGS(nf))
216 
217 DEFINE_NFSD_FILE_EVENT(nfsd_file_alloc);
218 DEFINE_NFSD_FILE_EVENT(nfsd_file_put_final);
219 DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash);
220 DEFINE_NFSD_FILE_EVENT(nfsd_file_put);
221 DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_release_locked);
222 
223 TRACE_EVENT(nfsd_file_acquire,
224 	TP_PROTO(struct svc_rqst *rqstp, unsigned int hash,
225 		 struct inode *inode, unsigned int may_flags,
226 		 struct nfsd_file *nf, __be32 status),
227 
228 	TP_ARGS(rqstp, hash, inode, may_flags, nf, status),
229 
230 	TP_STRUCT__entry(
231 		__field(__be32, xid)
232 		__field(unsigned int, hash)
233 		__field(void *, inode)
234 		__field(unsigned int, may_flags)
235 		__field(int, nf_ref)
236 		__field(unsigned long, nf_flags)
237 		__field(unsigned char, nf_may)
238 		__field(struct file *, nf_file)
239 		__field(__be32, status)
240 	),
241 
242 	TP_fast_assign(
243 		__entry->xid = rqstp->rq_xid;
244 		__entry->hash = hash;
245 		__entry->inode = inode;
246 		__entry->may_flags = may_flags;
247 		__entry->nf_ref = nf ? atomic_read(&nf->nf_ref) : 0;
248 		__entry->nf_flags = nf ? nf->nf_flags : 0;
249 		__entry->nf_may = nf ? nf->nf_may : 0;
250 		__entry->nf_file = nf ? nf->nf_file : NULL;
251 		__entry->status = status;
252 	),
253 
254 	TP_printk("xid=0x%x hash=0x%x inode=0x%p may_flags=%s ref=%d nf_flags=%s nf_may=%s nf_file=0x%p status=%u",
255 			be32_to_cpu(__entry->xid), __entry->hash, __entry->inode,
256 			show_nf_may(__entry->may_flags), __entry->nf_ref,
257 			show_nf_flags(__entry->nf_flags),
258 			show_nf_may(__entry->nf_may), __entry->nf_file,
259 			be32_to_cpu(__entry->status))
260 );
261 
262 DECLARE_EVENT_CLASS(nfsd_file_search_class,
263 	TP_PROTO(struct inode *inode, unsigned int hash, int found),
264 	TP_ARGS(inode, hash, found),
265 	TP_STRUCT__entry(
266 		__field(struct inode *, inode)
267 		__field(unsigned int, hash)
268 		__field(int, found)
269 	),
270 	TP_fast_assign(
271 		__entry->inode = inode;
272 		__entry->hash = hash;
273 		__entry->found = found;
274 	),
275 	TP_printk("hash=0x%x inode=0x%p found=%d", __entry->hash,
276 			__entry->inode, __entry->found)
277 );
278 
279 #define DEFINE_NFSD_FILE_SEARCH_EVENT(name)				\
280 DEFINE_EVENT(nfsd_file_search_class, name,				\
281 	TP_PROTO(struct inode *inode, unsigned int hash, int found),	\
282 	TP_ARGS(inode, hash, found))
283 
284 DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode_sync);
285 DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode);
286 DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_is_cached);
287 
288 TRACE_EVENT(nfsd_file_fsnotify_handle_event,
289 	TP_PROTO(struct inode *inode, u32 mask),
290 	TP_ARGS(inode, mask),
291 	TP_STRUCT__entry(
292 		__field(struct inode *, inode)
293 		__field(unsigned int, nlink)
294 		__field(umode_t, mode)
295 		__field(u32, mask)
296 	),
297 	TP_fast_assign(
298 		__entry->inode = inode;
299 		__entry->nlink = inode->i_nlink;
300 		__entry->mode = inode->i_mode;
301 		__entry->mask = mask;
302 	),
303 	TP_printk("inode=0x%p nlink=%u mode=0%ho mask=0x%x", __entry->inode,
304 			__entry->nlink, __entry->mode, __entry->mask)
305 );
306 
307 #endif /* _NFSD_TRACE_H */
308 
309 #undef TRACE_INCLUDE_PATH
310 #define TRACE_INCLUDE_PATH .
311 #define TRACE_INCLUDE_FILE trace
312 #include <trace/define_trace.h>
313