xref: /linux/fs/bcachefs/trace.h (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM bcachefs
4 
5 #if !defined(_TRACE_BCACHEFS_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_BCACHEFS_H
7 
8 #include <linux/tracepoint.h>
9 
10 #define TRACE_BPOS_entries(name)				\
11 	__field(u64,			name##_inode	)	\
12 	__field(u64,			name##_offset	)	\
13 	__field(u32,			name##_snapshot	)
14 
15 #define TRACE_BPOS_assign(dst, src)				\
16 	__entry->dst##_inode		= (src).inode;		\
17 	__entry->dst##_offset		= (src).offset;		\
18 	__entry->dst##_snapshot		= (src).snapshot
19 
20 DECLARE_EVENT_CLASS(bpos,
21 	TP_PROTO(const struct bpos *p),
22 	TP_ARGS(p),
23 
24 	TP_STRUCT__entry(
25 		TRACE_BPOS_entries(p)
26 	),
27 
28 	TP_fast_assign(
29 		TRACE_BPOS_assign(p, *p);
30 	),
31 
32 	TP_printk("%llu:%llu:%u", __entry->p_inode, __entry->p_offset, __entry->p_snapshot)
33 );
34 
35 DECLARE_EVENT_CLASS(fs_str,
36 	TP_PROTO(struct bch_fs *c, const char *str),
37 	TP_ARGS(c, str),
38 
39 	TP_STRUCT__entry(
40 		__field(dev_t,		dev			)
41 		__string(str,		str			)
42 	),
43 
44 	TP_fast_assign(
45 		__entry->dev		= c->dev;
46 		__assign_str(str);
47 	),
48 
49 	TP_printk("%d,%d\n%s", MAJOR(__entry->dev), MINOR(__entry->dev), __get_str(str))
50 );
51 
52 DECLARE_EVENT_CLASS(trans_str,
53 	TP_PROTO(struct btree_trans *trans, unsigned long caller_ip, const char *str),
54 	TP_ARGS(trans, caller_ip, str),
55 
56 	TP_STRUCT__entry(
57 		__field(dev_t,		dev			)
58 		__array(char,		trans_fn, 32		)
59 		__field(unsigned long,	caller_ip		)
60 		__string(str,		str			)
61 	),
62 
63 	TP_fast_assign(
64 		__entry->dev		= trans->c->dev;
65 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
66 		__entry->caller_ip		= caller_ip;
67 		__assign_str(str);
68 	),
69 
70 	TP_printk("%d,%d %s %pS %s",
71 		  MAJOR(__entry->dev), MINOR(__entry->dev),
72 		  __entry->trans_fn, (void *) __entry->caller_ip, __get_str(str))
73 );
74 
75 DECLARE_EVENT_CLASS(trans_str_nocaller,
76 	TP_PROTO(struct btree_trans *trans, const char *str),
77 	TP_ARGS(trans, str),
78 
79 	TP_STRUCT__entry(
80 		__field(dev_t,		dev			)
81 		__array(char,		trans_fn, 32		)
82 		__string(str,		str			)
83 	),
84 
85 	TP_fast_assign(
86 		__entry->dev		= trans->c->dev;
87 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
88 		__assign_str(str);
89 	),
90 
91 	TP_printk("%d,%d %s %s",
92 		  MAJOR(__entry->dev), MINOR(__entry->dev),
93 		  __entry->trans_fn, __get_str(str))
94 );
95 
96 DECLARE_EVENT_CLASS(btree_node_nofs,
97 	TP_PROTO(struct bch_fs *c, struct btree *b),
98 	TP_ARGS(c, b),
99 
100 	TP_STRUCT__entry(
101 		__field(dev_t,		dev			)
102 		__field(u8,		level			)
103 		__field(u8,		btree_id		)
104 		TRACE_BPOS_entries(pos)
105 	),
106 
107 	TP_fast_assign(
108 		__entry->dev		= c->dev;
109 		__entry->level		= b->c.level;
110 		__entry->btree_id	= b->c.btree_id;
111 		TRACE_BPOS_assign(pos, b->key.k.p);
112 	),
113 
114 	TP_printk("%d,%d %u %s %llu:%llu:%u",
115 		  MAJOR(__entry->dev), MINOR(__entry->dev),
116 		  __entry->level,
117 		  bch2_btree_id_str(__entry->btree_id),
118 		  __entry->pos_inode, __entry->pos_offset, __entry->pos_snapshot)
119 );
120 
121 DECLARE_EVENT_CLASS(btree_node,
122 	TP_PROTO(struct btree_trans *trans, struct btree *b),
123 	TP_ARGS(trans, b),
124 
125 	TP_STRUCT__entry(
126 		__field(dev_t,		dev			)
127 		__array(char,		trans_fn, 32		)
128 		__field(u8,		level			)
129 		__field(u8,		btree_id		)
130 		TRACE_BPOS_entries(pos)
131 	),
132 
133 	TP_fast_assign(
134 		__entry->dev		= trans->c->dev;
135 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
136 		__entry->level		= b->c.level;
137 		__entry->btree_id	= b->c.btree_id;
138 		TRACE_BPOS_assign(pos, b->key.k.p);
139 	),
140 
141 	TP_printk("%d,%d %s %u %s %llu:%llu:%u",
142 		  MAJOR(__entry->dev), MINOR(__entry->dev), __entry->trans_fn,
143 		  __entry->level,
144 		  bch2_btree_id_str(__entry->btree_id),
145 		  __entry->pos_inode, __entry->pos_offset, __entry->pos_snapshot)
146 );
147 
148 DECLARE_EVENT_CLASS(bch_fs,
149 	TP_PROTO(struct bch_fs *c),
150 	TP_ARGS(c),
151 
152 	TP_STRUCT__entry(
153 		__field(dev_t,		dev			)
154 	),
155 
156 	TP_fast_assign(
157 		__entry->dev		= c->dev;
158 	),
159 
160 	TP_printk("%d,%d", MAJOR(__entry->dev), MINOR(__entry->dev))
161 );
162 
163 DECLARE_EVENT_CLASS(btree_trans,
164 	TP_PROTO(struct btree_trans *trans),
165 	TP_ARGS(trans),
166 
167 	TP_STRUCT__entry(
168 		__field(dev_t,		dev			)
169 		__array(char,		trans_fn, 32		)
170 	),
171 
172 	TP_fast_assign(
173 		__entry->dev		= trans->c->dev;
174 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
175 	),
176 
177 	TP_printk("%d,%d %s", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->trans_fn)
178 );
179 
180 DECLARE_EVENT_CLASS(bio,
181 	TP_PROTO(struct bio *bio),
182 	TP_ARGS(bio),
183 
184 	TP_STRUCT__entry(
185 		__field(dev_t,		dev			)
186 		__field(sector_t,	sector			)
187 		__field(unsigned int,	nr_sector		)
188 		__array(char,		rwbs,	6		)
189 	),
190 
191 	TP_fast_assign(
192 		__entry->dev		= bio->bi_bdev ? bio_dev(bio) : 0;
193 		__entry->sector		= bio->bi_iter.bi_sector;
194 		__entry->nr_sector	= bio->bi_iter.bi_size >> 9;
195 		blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
196 	),
197 
198 	TP_printk("%d,%d  %s %llu + %u",
199 		  MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
200 		  (unsigned long long)__entry->sector, __entry->nr_sector)
201 );
202 
203 /* fs.c: */
204 TRACE_EVENT(bch2_sync_fs,
205 	TP_PROTO(struct super_block *sb, int wait),
206 
207 	TP_ARGS(sb, wait),
208 
209 	TP_STRUCT__entry(
210 		__field(	dev_t,	dev			)
211 		__field(	int,	wait			)
212 
213 	),
214 
215 	TP_fast_assign(
216 		__entry->dev	= sb->s_dev;
217 		__entry->wait	= wait;
218 	),
219 
220 	TP_printk("dev %d,%d wait %d",
221 		  MAJOR(__entry->dev), MINOR(__entry->dev),
222 		  __entry->wait)
223 );
224 
225 /* fs-io.c: */
226 TRACE_EVENT(bch2_fsync,
227 	TP_PROTO(struct file *file, int datasync),
228 
229 	TP_ARGS(file, datasync),
230 
231 	TP_STRUCT__entry(
232 		__field(	dev_t,	dev			)
233 		__field(	ino_t,	ino			)
234 		__field(	ino_t,	parent			)
235 		__field(	int,	datasync		)
236 	),
237 
238 	TP_fast_assign(
239 		struct dentry *dentry = file->f_path.dentry;
240 
241 		__entry->dev		= dentry->d_sb->s_dev;
242 		__entry->ino		= d_inode(dentry)->i_ino;
243 		__entry->parent		= d_inode(dentry->d_parent)->i_ino;
244 		__entry->datasync	= datasync;
245 	),
246 
247 	TP_printk("dev %d,%d ino %lu parent %lu datasync %d ",
248 		  MAJOR(__entry->dev), MINOR(__entry->dev),
249 		  (unsigned long) __entry->ino,
250 		  (unsigned long) __entry->parent, __entry->datasync)
251 );
252 
253 /* super-io.c: */
254 TRACE_EVENT(write_super,
255 	TP_PROTO(struct bch_fs *c, unsigned long ip),
256 	TP_ARGS(c, ip),
257 
258 	TP_STRUCT__entry(
259 		__field(dev_t,		dev	)
260 		__field(unsigned long,	ip	)
261 	),
262 
263 	TP_fast_assign(
264 		__entry->dev		= c->dev;
265 		__entry->ip		= ip;
266 	),
267 
268 	TP_printk("%d,%d for %pS",
269 		  MAJOR(__entry->dev), MINOR(__entry->dev),
270 		  (void *) __entry->ip)
271 );
272 
273 /* io.c: */
274 
275 DEFINE_EVENT(bio, read_promote,
276 	TP_PROTO(struct bio *bio),
277 	TP_ARGS(bio)
278 );
279 
280 TRACE_EVENT(read_nopromote,
281 	TP_PROTO(struct bch_fs *c, int ret),
282 	TP_ARGS(c, ret),
283 
284 	TP_STRUCT__entry(
285 		__field(dev_t,		dev		)
286 		__array(char,		ret, 32		)
287 	),
288 
289 	TP_fast_assign(
290 		__entry->dev		= c->dev;
291 		strscpy(__entry->ret, bch2_err_str(ret), sizeof(__entry->ret));
292 	),
293 
294 	TP_printk("%d,%d ret %s",
295 		  MAJOR(__entry->dev), MINOR(__entry->dev),
296 		  __entry->ret)
297 );
298 
299 DEFINE_EVENT(bio, read_bounce,
300 	TP_PROTO(struct bio *bio),
301 	TP_ARGS(bio)
302 );
303 
304 DEFINE_EVENT(bio, read_split,
305 	TP_PROTO(struct bio *bio),
306 	TP_ARGS(bio)
307 );
308 
309 DEFINE_EVENT(bio, read_retry,
310 	TP_PROTO(struct bio *bio),
311 	TP_ARGS(bio)
312 );
313 
314 DEFINE_EVENT(bio, read_reuse_race,
315 	TP_PROTO(struct bio *bio),
316 	TP_ARGS(bio)
317 );
318 
319 /* Journal */
320 
321 DEFINE_EVENT(bch_fs, journal_full,
322 	TP_PROTO(struct bch_fs *c),
323 	TP_ARGS(c)
324 );
325 
326 DEFINE_EVENT(fs_str, journal_entry_full,
327 	TP_PROTO(struct bch_fs *c, const char *str),
328 	TP_ARGS(c, str)
329 );
330 
331 DEFINE_EVENT(fs_str, journal_entry_close,
332 	TP_PROTO(struct bch_fs *c, const char *str),
333 	TP_ARGS(c, str)
334 );
335 
336 DEFINE_EVENT(bio, journal_write,
337 	TP_PROTO(struct bio *bio),
338 	TP_ARGS(bio)
339 );
340 
341 TRACE_EVENT(journal_reclaim_start,
342 	TP_PROTO(struct bch_fs *c, bool direct, bool kicked,
343 		 u64 min_nr, u64 min_key_cache,
344 		 u64 btree_cache_dirty, u64 btree_cache_total,
345 		 u64 btree_key_cache_dirty, u64 btree_key_cache_total),
346 	TP_ARGS(c, direct, kicked, min_nr, min_key_cache,
347 		btree_cache_dirty, btree_cache_total,
348 		btree_key_cache_dirty, btree_key_cache_total),
349 
350 	TP_STRUCT__entry(
351 		__field(dev_t,		dev			)
352 		__field(bool,		direct			)
353 		__field(bool,		kicked			)
354 		__field(u64,		min_nr			)
355 		__field(u64,		min_key_cache		)
356 		__field(u64,		btree_cache_dirty	)
357 		__field(u64,		btree_cache_total	)
358 		__field(u64,		btree_key_cache_dirty	)
359 		__field(u64,		btree_key_cache_total	)
360 	),
361 
362 	TP_fast_assign(
363 		__entry->dev			= c->dev;
364 		__entry->direct			= direct;
365 		__entry->kicked			= kicked;
366 		__entry->min_nr			= min_nr;
367 		__entry->min_key_cache		= min_key_cache;
368 		__entry->btree_cache_dirty	= btree_cache_dirty;
369 		__entry->btree_cache_total	= btree_cache_total;
370 		__entry->btree_key_cache_dirty	= btree_key_cache_dirty;
371 		__entry->btree_key_cache_total	= btree_key_cache_total;
372 	),
373 
374 	TP_printk("%d,%d direct %u kicked %u min %llu key cache %llu btree cache %llu/%llu key cache %llu/%llu",
375 		  MAJOR(__entry->dev), MINOR(__entry->dev),
376 		  __entry->direct,
377 		  __entry->kicked,
378 		  __entry->min_nr,
379 		  __entry->min_key_cache,
380 		  __entry->btree_cache_dirty,
381 		  __entry->btree_cache_total,
382 		  __entry->btree_key_cache_dirty,
383 		  __entry->btree_key_cache_total)
384 );
385 
386 TRACE_EVENT(journal_reclaim_finish,
387 	TP_PROTO(struct bch_fs *c, u64 nr_flushed),
388 	TP_ARGS(c, nr_flushed),
389 
390 	TP_STRUCT__entry(
391 		__field(dev_t,		dev			)
392 		__field(u64,		nr_flushed		)
393 	),
394 
395 	TP_fast_assign(
396 		__entry->dev		= c->dev;
397 		__entry->nr_flushed	= nr_flushed;
398 	),
399 
400 	TP_printk("%d,%d flushed %llu",
401 		  MAJOR(__entry->dev), MINOR(__entry->dev),
402 		  __entry->nr_flushed)
403 );
404 
405 /* bset.c: */
406 
407 DEFINE_EVENT(bpos, bkey_pack_pos_fail,
408 	TP_PROTO(const struct bpos *p),
409 	TP_ARGS(p)
410 );
411 
412 /* Btree cache: */
413 
414 TRACE_EVENT(btree_cache_scan,
415 	TP_PROTO(long nr_to_scan, long can_free, long ret),
416 	TP_ARGS(nr_to_scan, can_free, ret),
417 
418 	TP_STRUCT__entry(
419 		__field(long,	nr_to_scan		)
420 		__field(long,	can_free		)
421 		__field(long,	ret			)
422 	),
423 
424 	TP_fast_assign(
425 		__entry->nr_to_scan	= nr_to_scan;
426 		__entry->can_free	= can_free;
427 		__entry->ret		= ret;
428 	),
429 
430 	TP_printk("scanned for %li nodes, can free %li, ret %li",
431 		  __entry->nr_to_scan, __entry->can_free, __entry->ret)
432 );
433 
434 DEFINE_EVENT(btree_node_nofs, btree_cache_reap,
435 	TP_PROTO(struct bch_fs *c, struct btree *b),
436 	TP_ARGS(c, b)
437 );
438 
439 DEFINE_EVENT(btree_trans, btree_cache_cannibalize_lock_fail,
440 	TP_PROTO(struct btree_trans *trans),
441 	TP_ARGS(trans)
442 );
443 
444 DEFINE_EVENT(btree_trans, btree_cache_cannibalize_lock,
445 	TP_PROTO(struct btree_trans *trans),
446 	TP_ARGS(trans)
447 );
448 
449 DEFINE_EVENT(btree_trans, btree_cache_cannibalize,
450 	TP_PROTO(struct btree_trans *trans),
451 	TP_ARGS(trans)
452 );
453 
454 DEFINE_EVENT(btree_trans, btree_cache_cannibalize_unlock,
455 	TP_PROTO(struct btree_trans *trans),
456 	TP_ARGS(trans)
457 );
458 
459 /* Btree */
460 
461 DEFINE_EVENT(btree_node, btree_node_read,
462 	TP_PROTO(struct btree_trans *trans, struct btree *b),
463 	TP_ARGS(trans, b)
464 );
465 
466 TRACE_EVENT(btree_node_write,
467 	TP_PROTO(struct btree *b, unsigned bytes, unsigned sectors),
468 	TP_ARGS(b, bytes, sectors),
469 
470 	TP_STRUCT__entry(
471 		__field(enum btree_node_type,	type)
472 		__field(unsigned,	bytes			)
473 		__field(unsigned,	sectors			)
474 	),
475 
476 	TP_fast_assign(
477 		__entry->type	= btree_node_type(b);
478 		__entry->bytes	= bytes;
479 		__entry->sectors = sectors;
480 	),
481 
482 	TP_printk("bkey type %u bytes %u sectors %u",
483 		  __entry->type , __entry->bytes, __entry->sectors)
484 );
485 
486 DEFINE_EVENT(btree_node, btree_node_alloc,
487 	TP_PROTO(struct btree_trans *trans, struct btree *b),
488 	TP_ARGS(trans, b)
489 );
490 
491 DEFINE_EVENT(btree_node, btree_node_free,
492 	TP_PROTO(struct btree_trans *trans, struct btree *b),
493 	TP_ARGS(trans, b)
494 );
495 
496 TRACE_EVENT(btree_reserve_get_fail,
497 	TP_PROTO(const char *trans_fn,
498 		 unsigned long caller_ip,
499 		 size_t required,
500 		 int ret),
501 	TP_ARGS(trans_fn, caller_ip, required, ret),
502 
503 	TP_STRUCT__entry(
504 		__array(char,			trans_fn, 32	)
505 		__field(unsigned long,		caller_ip	)
506 		__field(size_t,			required	)
507 		__array(char,			ret, 32		)
508 	),
509 
510 	TP_fast_assign(
511 		strscpy(__entry->trans_fn, trans_fn, sizeof(__entry->trans_fn));
512 		__entry->caller_ip	= caller_ip;
513 		__entry->required	= required;
514 		strscpy(__entry->ret, bch2_err_str(ret), sizeof(__entry->ret));
515 	),
516 
517 	TP_printk("%s %pS required %zu ret %s",
518 		  __entry->trans_fn,
519 		  (void *) __entry->caller_ip,
520 		  __entry->required,
521 		  __entry->ret)
522 );
523 
524 DEFINE_EVENT(btree_node, btree_node_compact,
525 	TP_PROTO(struct btree_trans *trans, struct btree *b),
526 	TP_ARGS(trans, b)
527 );
528 
529 DEFINE_EVENT(btree_node, btree_node_merge,
530 	TP_PROTO(struct btree_trans *trans, struct btree *b),
531 	TP_ARGS(trans, b)
532 );
533 
534 DEFINE_EVENT(btree_node, btree_node_split,
535 	TP_PROTO(struct btree_trans *trans, struct btree *b),
536 	TP_ARGS(trans, b)
537 );
538 
539 DEFINE_EVENT(btree_node, btree_node_rewrite,
540 	TP_PROTO(struct btree_trans *trans, struct btree *b),
541 	TP_ARGS(trans, b)
542 );
543 
544 DEFINE_EVENT(btree_node, btree_node_set_root,
545 	TP_PROTO(struct btree_trans *trans, struct btree *b),
546 	TP_ARGS(trans, b)
547 );
548 
549 TRACE_EVENT(btree_path_relock_fail,
550 	TP_PROTO(struct btree_trans *trans,
551 		 unsigned long caller_ip,
552 		 struct btree_path *path,
553 		 unsigned level),
554 	TP_ARGS(trans, caller_ip, path, level),
555 
556 	TP_STRUCT__entry(
557 		__array(char,			trans_fn, 32	)
558 		__field(unsigned long,		caller_ip	)
559 		__field(u8,			btree_id	)
560 		__field(u8,			level		)
561 		TRACE_BPOS_entries(pos)
562 		__array(char,			node, 24	)
563 		__field(u8,			self_read_count	)
564 		__field(u8,			self_intent_count)
565 		__field(u8,			read_count	)
566 		__field(u8,			intent_count	)
567 		__field(u32,			iter_lock_seq	)
568 		__field(u32,			node_lock_seq	)
569 	),
570 
571 	TP_fast_assign(
572 		struct btree *b = btree_path_node(path, level);
573 		struct six_lock_count c;
574 
575 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
576 		__entry->caller_ip		= caller_ip;
577 		__entry->btree_id		= path->btree_id;
578 		__entry->level			= path->level;
579 		TRACE_BPOS_assign(pos, path->pos);
580 
581 		c = bch2_btree_node_lock_counts(trans, NULL, &path->l[level].b->c, level);
582 		__entry->self_read_count	= c.n[SIX_LOCK_read];
583 		__entry->self_intent_count	= c.n[SIX_LOCK_intent];
584 
585 		if (IS_ERR(b)) {
586 			strscpy(__entry->node, bch2_err_str(PTR_ERR(b)), sizeof(__entry->node));
587 		} else {
588 			c = six_lock_counts(&path->l[level].b->c.lock);
589 			__entry->read_count	= c.n[SIX_LOCK_read];
590 			__entry->intent_count	= c.n[SIX_LOCK_intent];
591 			scnprintf(__entry->node, sizeof(__entry->node), "%px", b);
592 		}
593 		__entry->iter_lock_seq		= path->l[level].lock_seq;
594 		__entry->node_lock_seq		= is_btree_node(path, level)
595 			? six_lock_seq(&path->l[level].b->c.lock)
596 			: 0;
597 	),
598 
599 	TP_printk("%s %pS btree %s pos %llu:%llu:%u level %u node %s held %u:%u lock count %u:%u iter seq %u lock seq %u",
600 		  __entry->trans_fn,
601 		  (void *) __entry->caller_ip,
602 		  bch2_btree_id_str(__entry->btree_id),
603 		  __entry->pos_inode,
604 		  __entry->pos_offset,
605 		  __entry->pos_snapshot,
606 		  __entry->level,
607 		  __entry->node,
608 		  __entry->self_read_count,
609 		  __entry->self_intent_count,
610 		  __entry->read_count,
611 		  __entry->intent_count,
612 		  __entry->iter_lock_seq,
613 		  __entry->node_lock_seq)
614 );
615 
616 TRACE_EVENT(btree_path_upgrade_fail,
617 	TP_PROTO(struct btree_trans *trans,
618 		 unsigned long caller_ip,
619 		 struct btree_path *path,
620 		 unsigned level),
621 	TP_ARGS(trans, caller_ip, path, level),
622 
623 	TP_STRUCT__entry(
624 		__array(char,			trans_fn, 32	)
625 		__field(unsigned long,		caller_ip	)
626 		__field(u8,			btree_id	)
627 		__field(u8,			level		)
628 		TRACE_BPOS_entries(pos)
629 		__field(u8,			locked		)
630 		__field(u8,			self_read_count	)
631 		__field(u8,			self_intent_count)
632 		__field(u8,			read_count	)
633 		__field(u8,			intent_count	)
634 		__field(u32,			iter_lock_seq	)
635 		__field(u32,			node_lock_seq	)
636 	),
637 
638 	TP_fast_assign(
639 		struct six_lock_count c;
640 
641 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
642 		__entry->caller_ip		= caller_ip;
643 		__entry->btree_id		= path->btree_id;
644 		__entry->level			= level;
645 		TRACE_BPOS_assign(pos, path->pos);
646 		__entry->locked			= btree_node_locked(path, level);
647 
648 		c = bch2_btree_node_lock_counts(trans, NULL, &path->l[level].b->c, level),
649 		__entry->self_read_count	= c.n[SIX_LOCK_read];
650 		__entry->self_intent_count	= c.n[SIX_LOCK_intent];
651 		c = six_lock_counts(&path->l[level].b->c.lock);
652 		__entry->read_count		= c.n[SIX_LOCK_read];
653 		__entry->intent_count		= c.n[SIX_LOCK_intent];
654 		__entry->iter_lock_seq		= path->l[level].lock_seq;
655 		__entry->node_lock_seq		= is_btree_node(path, level)
656 			? six_lock_seq(&path->l[level].b->c.lock)
657 			: 0;
658 	),
659 
660 	TP_printk("%s %pS btree %s pos %llu:%llu:%u level %u locked %u held %u:%u lock count %u:%u iter seq %u lock seq %u",
661 		  __entry->trans_fn,
662 		  (void *) __entry->caller_ip,
663 		  bch2_btree_id_str(__entry->btree_id),
664 		  __entry->pos_inode,
665 		  __entry->pos_offset,
666 		  __entry->pos_snapshot,
667 		  __entry->level,
668 		  __entry->locked,
669 		  __entry->self_read_count,
670 		  __entry->self_intent_count,
671 		  __entry->read_count,
672 		  __entry->intent_count,
673 		  __entry->iter_lock_seq,
674 		  __entry->node_lock_seq)
675 );
676 
677 /* Garbage collection */
678 
679 DEFINE_EVENT(bch_fs, gc_gens_start,
680 	TP_PROTO(struct bch_fs *c),
681 	TP_ARGS(c)
682 );
683 
684 DEFINE_EVENT(bch_fs, gc_gens_end,
685 	TP_PROTO(struct bch_fs *c),
686 	TP_ARGS(c)
687 );
688 
689 /* Allocator */
690 
691 DEFINE_EVENT(fs_str, bucket_alloc,
692 	TP_PROTO(struct bch_fs *c, const char *str),
693 	TP_ARGS(c, str)
694 );
695 
696 DEFINE_EVENT(fs_str, bucket_alloc_fail,
697 	TP_PROTO(struct bch_fs *c, const char *str),
698 	TP_ARGS(c, str)
699 );
700 
701 TRACE_EVENT(discard_buckets,
702 	TP_PROTO(struct bch_fs *c, u64 seen, u64 open,
703 		 u64 need_journal_commit, u64 discarded, const char *err),
704 	TP_ARGS(c, seen, open, need_journal_commit, discarded, err),
705 
706 	TP_STRUCT__entry(
707 		__field(dev_t,		dev			)
708 		__field(u64,		seen			)
709 		__field(u64,		open			)
710 		__field(u64,		need_journal_commit	)
711 		__field(u64,		discarded		)
712 		__array(char,		err,	16		)
713 	),
714 
715 	TP_fast_assign(
716 		__entry->dev			= c->dev;
717 		__entry->seen			= seen;
718 		__entry->open			= open;
719 		__entry->need_journal_commit	= need_journal_commit;
720 		__entry->discarded		= discarded;
721 		strscpy(__entry->err, err, sizeof(__entry->err));
722 	),
723 
724 	TP_printk("%d%d seen %llu open %llu need_journal_commit %llu discarded %llu err %s",
725 		  MAJOR(__entry->dev), MINOR(__entry->dev),
726 		  __entry->seen,
727 		  __entry->open,
728 		  __entry->need_journal_commit,
729 		  __entry->discarded,
730 		  __entry->err)
731 );
732 
733 TRACE_EVENT(bucket_invalidate,
734 	TP_PROTO(struct bch_fs *c, unsigned dev, u64 bucket, u32 sectors),
735 	TP_ARGS(c, dev, bucket, sectors),
736 
737 	TP_STRUCT__entry(
738 		__field(dev_t,		dev			)
739 		__field(u32,		dev_idx			)
740 		__field(u32,		sectors			)
741 		__field(u64,		bucket			)
742 	),
743 
744 	TP_fast_assign(
745 		__entry->dev		= c->dev;
746 		__entry->dev_idx	= dev;
747 		__entry->sectors	= sectors;
748 		__entry->bucket		= bucket;
749 	),
750 
751 	TP_printk("%d:%d invalidated %u:%llu cached sectors %u",
752 		  MAJOR(__entry->dev), MINOR(__entry->dev),
753 		  __entry->dev_idx, __entry->bucket,
754 		  __entry->sectors)
755 );
756 
757 /* Moving IO */
758 
759 TRACE_EVENT(bucket_evacuate,
760 	TP_PROTO(struct bch_fs *c, struct bpos *bucket),
761 	TP_ARGS(c, bucket),
762 
763 	TP_STRUCT__entry(
764 		__field(dev_t,		dev			)
765 		__field(u32,		dev_idx			)
766 		__field(u64,		bucket			)
767 	),
768 
769 	TP_fast_assign(
770 		__entry->dev		= c->dev;
771 		__entry->dev_idx	= bucket->inode;
772 		__entry->bucket		= bucket->offset;
773 	),
774 
775 	TP_printk("%d:%d %u:%llu",
776 		  MAJOR(__entry->dev), MINOR(__entry->dev),
777 		  __entry->dev_idx, __entry->bucket)
778 );
779 
780 DEFINE_EVENT(fs_str, move_extent,
781 	TP_PROTO(struct bch_fs *c, const char *str),
782 	TP_ARGS(c, str)
783 );
784 
785 DEFINE_EVENT(fs_str, move_extent_read,
786 	TP_PROTO(struct bch_fs *c, const char *str),
787 	TP_ARGS(c, str)
788 );
789 
790 DEFINE_EVENT(fs_str, move_extent_write,
791 	TP_PROTO(struct bch_fs *c, const char *str),
792 	TP_ARGS(c, str)
793 );
794 
795 DEFINE_EVENT(fs_str, move_extent_finish,
796 	TP_PROTO(struct bch_fs *c, const char *str),
797 	TP_ARGS(c, str)
798 );
799 
800 DEFINE_EVENT(fs_str, move_extent_fail,
801 	TP_PROTO(struct bch_fs *c, const char *str),
802 	TP_ARGS(c, str)
803 );
804 
805 DEFINE_EVENT(fs_str, move_extent_start_fail,
806 	TP_PROTO(struct bch_fs *c, const char *str),
807 	TP_ARGS(c, str)
808 );
809 
810 TRACE_EVENT(move_data,
811 	TP_PROTO(struct bch_fs *c,
812 		 struct bch_move_stats *stats),
813 	TP_ARGS(c, stats),
814 
815 	TP_STRUCT__entry(
816 		__field(dev_t,		dev		)
817 		__field(u64,		keys_moved	)
818 		__field(u64,		keys_raced	)
819 		__field(u64,		sectors_seen	)
820 		__field(u64,		sectors_moved	)
821 		__field(u64,		sectors_raced	)
822 	),
823 
824 	TP_fast_assign(
825 		__entry->dev		= c->dev;
826 		__entry->keys_moved	= atomic64_read(&stats->keys_moved);
827 		__entry->keys_raced	= atomic64_read(&stats->keys_raced);
828 		__entry->sectors_seen	= atomic64_read(&stats->sectors_seen);
829 		__entry->sectors_moved	= atomic64_read(&stats->sectors_moved);
830 		__entry->sectors_raced	= atomic64_read(&stats->sectors_raced);
831 	),
832 
833 	TP_printk("%d,%d keys moved %llu raced %llu"
834 		  "sectors seen %llu moved %llu raced %llu",
835 		  MAJOR(__entry->dev), MINOR(__entry->dev),
836 		  __entry->keys_moved,
837 		  __entry->keys_raced,
838 		  __entry->sectors_seen,
839 		  __entry->sectors_moved,
840 		  __entry->sectors_raced)
841 );
842 
843 TRACE_EVENT(evacuate_bucket,
844 	TP_PROTO(struct bch_fs *c, struct bpos *bucket,
845 		 unsigned sectors, unsigned bucket_size,
846 		 u64 fragmentation, int ret),
847 	TP_ARGS(c, bucket, sectors, bucket_size, fragmentation, ret),
848 
849 	TP_STRUCT__entry(
850 		__field(dev_t,		dev		)
851 		__field(u64,		member		)
852 		__field(u64,		bucket		)
853 		__field(u32,		sectors		)
854 		__field(u32,		bucket_size	)
855 		__field(u64,		fragmentation	)
856 		__field(int,		ret		)
857 	),
858 
859 	TP_fast_assign(
860 		__entry->dev			= c->dev;
861 		__entry->member			= bucket->inode;
862 		__entry->bucket			= bucket->offset;
863 		__entry->sectors		= sectors;
864 		__entry->bucket_size		= bucket_size;
865 		__entry->fragmentation		= fragmentation;
866 		__entry->ret			= ret;
867 	),
868 
869 	TP_printk("%d,%d %llu:%llu sectors %u/%u fragmentation %llu ret %i",
870 		  MAJOR(__entry->dev), MINOR(__entry->dev),
871 		  __entry->member, __entry->bucket,
872 		  __entry->sectors, __entry->bucket_size,
873 		  __entry->fragmentation, __entry->ret)
874 );
875 
876 TRACE_EVENT(copygc,
877 	TP_PROTO(struct bch_fs *c,
878 		 u64 sectors_moved, u64 sectors_not_moved,
879 		 u64 buckets_moved, u64 buckets_not_moved),
880 	TP_ARGS(c,
881 		sectors_moved, sectors_not_moved,
882 		buckets_moved, buckets_not_moved),
883 
884 	TP_STRUCT__entry(
885 		__field(dev_t,		dev			)
886 		__field(u64,		sectors_moved		)
887 		__field(u64,		sectors_not_moved	)
888 		__field(u64,		buckets_moved		)
889 		__field(u64,		buckets_not_moved	)
890 	),
891 
892 	TP_fast_assign(
893 		__entry->dev			= c->dev;
894 		__entry->sectors_moved		= sectors_moved;
895 		__entry->sectors_not_moved	= sectors_not_moved;
896 		__entry->buckets_moved		= buckets_moved;
897 		__entry->buckets_not_moved = buckets_moved;
898 	),
899 
900 	TP_printk("%d,%d sectors moved %llu remain %llu buckets moved %llu remain %llu",
901 		  MAJOR(__entry->dev), MINOR(__entry->dev),
902 		  __entry->sectors_moved, __entry->sectors_not_moved,
903 		  __entry->buckets_moved, __entry->buckets_not_moved)
904 );
905 
906 TRACE_EVENT(copygc_wait,
907 	TP_PROTO(struct bch_fs *c,
908 		 u64 wait_amount, u64 until),
909 	TP_ARGS(c, wait_amount, until),
910 
911 	TP_STRUCT__entry(
912 		__field(dev_t,		dev			)
913 		__field(u64,		wait_amount		)
914 		__field(u64,		until			)
915 	),
916 
917 	TP_fast_assign(
918 		__entry->dev		= c->dev;
919 		__entry->wait_amount	= wait_amount;
920 		__entry->until		= until;
921 	),
922 
923 	TP_printk("%d,%u waiting for %llu sectors until %llu",
924 		  MAJOR(__entry->dev), MINOR(__entry->dev),
925 		  __entry->wait_amount, __entry->until)
926 );
927 
928 /* btree transactions: */
929 
930 DECLARE_EVENT_CLASS(transaction_event,
931 	TP_PROTO(struct btree_trans *trans,
932 		 unsigned long caller_ip),
933 	TP_ARGS(trans, caller_ip),
934 
935 	TP_STRUCT__entry(
936 		__array(char,			trans_fn, 32	)
937 		__field(unsigned long,		caller_ip	)
938 	),
939 
940 	TP_fast_assign(
941 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
942 		__entry->caller_ip		= caller_ip;
943 	),
944 
945 	TP_printk("%s %pS", __entry->trans_fn, (void *) __entry->caller_ip)
946 );
947 
948 DEFINE_EVENT(transaction_event,	transaction_commit,
949 	TP_PROTO(struct btree_trans *trans,
950 		 unsigned long caller_ip),
951 	TP_ARGS(trans, caller_ip)
952 );
953 
954 DEFINE_EVENT(transaction_event,	trans_restart_injected,
955 	TP_PROTO(struct btree_trans *trans,
956 		 unsigned long caller_ip),
957 	TP_ARGS(trans, caller_ip)
958 );
959 
960 TRACE_EVENT(trans_restart_split_race,
961 	TP_PROTO(struct btree_trans *trans,
962 		 unsigned long caller_ip,
963 		 struct btree *b),
964 	TP_ARGS(trans, caller_ip, b),
965 
966 	TP_STRUCT__entry(
967 		__array(char,			trans_fn, 32	)
968 		__field(unsigned long,		caller_ip	)
969 		__field(u8,			level		)
970 		__field(u16,			written		)
971 		__field(u16,			blocks		)
972 		__field(u16,			u64s_remaining	)
973 	),
974 
975 	TP_fast_assign(
976 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
977 		__entry->caller_ip		= caller_ip;
978 		__entry->level		= b->c.level;
979 		__entry->written	= b->written;
980 		__entry->blocks		= btree_blocks(trans->c);
981 		__entry->u64s_remaining	= bch2_btree_keys_u64s_remaining(b);
982 	),
983 
984 	TP_printk("%s %pS l=%u written %u/%u u64s remaining %u",
985 		  __entry->trans_fn, (void *) __entry->caller_ip,
986 		  __entry->level,
987 		  __entry->written, __entry->blocks,
988 		  __entry->u64s_remaining)
989 );
990 
991 TRACE_EVENT(trans_blocked_journal_reclaim,
992 	TP_PROTO(struct btree_trans *trans,
993 		 unsigned long caller_ip),
994 	TP_ARGS(trans, caller_ip),
995 
996 	TP_STRUCT__entry(
997 		__array(char,			trans_fn, 32	)
998 		__field(unsigned long,		caller_ip	)
999 
1000 		__field(unsigned long,		key_cache_nr_keys	)
1001 		__field(unsigned long,		key_cache_nr_dirty	)
1002 		__field(long,			must_wait		)
1003 	),
1004 
1005 	TP_fast_assign(
1006 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1007 		__entry->caller_ip		= caller_ip;
1008 		__entry->key_cache_nr_keys	= atomic_long_read(&trans->c->btree_key_cache.nr_keys);
1009 		__entry->key_cache_nr_dirty	= atomic_long_read(&trans->c->btree_key_cache.nr_dirty);
1010 		__entry->must_wait		= __bch2_btree_key_cache_must_wait(trans->c);
1011 	),
1012 
1013 	TP_printk("%s %pS key cache keys %lu dirty %lu must_wait %li",
1014 		  __entry->trans_fn, (void *) __entry->caller_ip,
1015 		  __entry->key_cache_nr_keys,
1016 		  __entry->key_cache_nr_dirty,
1017 		  __entry->must_wait)
1018 );
1019 
1020 TRACE_EVENT(trans_restart_journal_preres_get,
1021 	TP_PROTO(struct btree_trans *trans,
1022 		 unsigned long caller_ip,
1023 		 unsigned flags),
1024 	TP_ARGS(trans, caller_ip, flags),
1025 
1026 	TP_STRUCT__entry(
1027 		__array(char,			trans_fn, 32	)
1028 		__field(unsigned long,		caller_ip	)
1029 		__field(unsigned,		flags		)
1030 	),
1031 
1032 	TP_fast_assign(
1033 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1034 		__entry->caller_ip		= caller_ip;
1035 		__entry->flags			= flags;
1036 	),
1037 
1038 	TP_printk("%s %pS %x", __entry->trans_fn,
1039 		  (void *) __entry->caller_ip,
1040 		  __entry->flags)
1041 );
1042 
1043 DEFINE_EVENT(transaction_event,	trans_restart_fault_inject,
1044 	TP_PROTO(struct btree_trans *trans,
1045 		 unsigned long caller_ip),
1046 	TP_ARGS(trans, caller_ip)
1047 );
1048 
1049 DEFINE_EVENT(transaction_event,	trans_traverse_all,
1050 	TP_PROTO(struct btree_trans *trans,
1051 		 unsigned long caller_ip),
1052 	TP_ARGS(trans, caller_ip)
1053 );
1054 
1055 DEFINE_EVENT(transaction_event,	trans_restart_key_cache_raced,
1056 	TP_PROTO(struct btree_trans *trans,
1057 		 unsigned long caller_ip),
1058 	TP_ARGS(trans, caller_ip)
1059 );
1060 
1061 DEFINE_EVENT(trans_str, trans_restart_too_many_iters,
1062 	TP_PROTO(struct btree_trans *trans,
1063 		 unsigned long caller_ip,
1064 		 const char *paths),
1065 	TP_ARGS(trans, caller_ip, paths)
1066 );
1067 
1068 DECLARE_EVENT_CLASS(transaction_restart_iter,
1069 	TP_PROTO(struct btree_trans *trans,
1070 		 unsigned long caller_ip,
1071 		 struct btree_path *path),
1072 	TP_ARGS(trans, caller_ip, path),
1073 
1074 	TP_STRUCT__entry(
1075 		__array(char,			trans_fn, 32	)
1076 		__field(unsigned long,		caller_ip	)
1077 		__field(u8,			btree_id	)
1078 		TRACE_BPOS_entries(pos)
1079 	),
1080 
1081 	TP_fast_assign(
1082 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1083 		__entry->caller_ip		= caller_ip;
1084 		__entry->btree_id		= path->btree_id;
1085 		TRACE_BPOS_assign(pos, path->pos)
1086 	),
1087 
1088 	TP_printk("%s %pS btree %s pos %llu:%llu:%u",
1089 		  __entry->trans_fn,
1090 		  (void *) __entry->caller_ip,
1091 		  bch2_btree_id_str(__entry->btree_id),
1092 		  __entry->pos_inode,
1093 		  __entry->pos_offset,
1094 		  __entry->pos_snapshot)
1095 );
1096 
1097 DEFINE_EVENT(transaction_restart_iter,	trans_restart_btree_node_reused,
1098 	TP_PROTO(struct btree_trans *trans,
1099 		 unsigned long caller_ip,
1100 		 struct btree_path *path),
1101 	TP_ARGS(trans, caller_ip, path)
1102 );
1103 
1104 DEFINE_EVENT(transaction_restart_iter,	trans_restart_btree_node_split,
1105 	TP_PROTO(struct btree_trans *trans,
1106 		 unsigned long caller_ip,
1107 		 struct btree_path *path),
1108 	TP_ARGS(trans, caller_ip, path)
1109 );
1110 
1111 TRACE_EVENT(trans_restart_upgrade,
1112 	TP_PROTO(struct btree_trans *trans,
1113 		 unsigned long caller_ip,
1114 		 struct btree_path *path,
1115 		 unsigned old_locks_want,
1116 		 unsigned new_locks_want,
1117 		 struct get_locks_fail *f),
1118 	TP_ARGS(trans, caller_ip, path, old_locks_want, new_locks_want, f),
1119 
1120 	TP_STRUCT__entry(
1121 		__array(char,			trans_fn, 32	)
1122 		__field(unsigned long,		caller_ip	)
1123 		__field(u8,			btree_id	)
1124 		__field(u8,			old_locks_want	)
1125 		__field(u8,			new_locks_want	)
1126 		__field(u8,			level		)
1127 		__field(u32,			path_seq	)
1128 		__field(u32,			node_seq	)
1129 		TRACE_BPOS_entries(pos)
1130 	),
1131 
1132 	TP_fast_assign(
1133 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1134 		__entry->caller_ip		= caller_ip;
1135 		__entry->btree_id		= path->btree_id;
1136 		__entry->old_locks_want		= old_locks_want;
1137 		__entry->new_locks_want		= new_locks_want;
1138 		__entry->level			= f->l;
1139 		__entry->path_seq		= path->l[f->l].lock_seq;
1140 		__entry->node_seq		= IS_ERR_OR_NULL(f->b) ? 0 : f->b->c.lock.seq;
1141 		TRACE_BPOS_assign(pos, path->pos)
1142 	),
1143 
1144 	TP_printk("%s %pS btree %s pos %llu:%llu:%u locks_want %u -> %u level %u path seq %u node seq %u",
1145 		  __entry->trans_fn,
1146 		  (void *) __entry->caller_ip,
1147 		  bch2_btree_id_str(__entry->btree_id),
1148 		  __entry->pos_inode,
1149 		  __entry->pos_offset,
1150 		  __entry->pos_snapshot,
1151 		  __entry->old_locks_want,
1152 		  __entry->new_locks_want,
1153 		  __entry->level,
1154 		  __entry->path_seq,
1155 		  __entry->node_seq)
1156 );
1157 
1158 DEFINE_EVENT(trans_str,	trans_restart_relock,
1159 	TP_PROTO(struct btree_trans *trans, unsigned long caller_ip, const char *str),
1160 	TP_ARGS(trans, caller_ip, str)
1161 );
1162 
1163 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_next_node,
1164 	TP_PROTO(struct btree_trans *trans,
1165 		 unsigned long caller_ip,
1166 		 struct btree_path *path),
1167 	TP_ARGS(trans, caller_ip, path)
1168 );
1169 
1170 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_parent_for_fill,
1171 	TP_PROTO(struct btree_trans *trans,
1172 		 unsigned long caller_ip,
1173 		 struct btree_path *path),
1174 	TP_ARGS(trans, caller_ip, path)
1175 );
1176 
1177 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_after_fill,
1178 	TP_PROTO(struct btree_trans *trans,
1179 		 unsigned long caller_ip,
1180 		 struct btree_path *path),
1181 	TP_ARGS(trans, caller_ip, path)
1182 );
1183 
1184 DEFINE_EVENT(transaction_event,	trans_restart_key_cache_upgrade,
1185 	TP_PROTO(struct btree_trans *trans,
1186 		 unsigned long caller_ip),
1187 	TP_ARGS(trans, caller_ip)
1188 );
1189 
1190 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_key_cache_fill,
1191 	TP_PROTO(struct btree_trans *trans,
1192 		 unsigned long caller_ip,
1193 		 struct btree_path *path),
1194 	TP_ARGS(trans, caller_ip, path)
1195 );
1196 
1197 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_path,
1198 	TP_PROTO(struct btree_trans *trans,
1199 		 unsigned long caller_ip,
1200 		 struct btree_path *path),
1201 	TP_ARGS(trans, caller_ip, path)
1202 );
1203 
1204 DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_path_intent,
1205 	TP_PROTO(struct btree_trans *trans,
1206 		 unsigned long caller_ip,
1207 		 struct btree_path *path),
1208 	TP_ARGS(trans, caller_ip, path)
1209 );
1210 
1211 DEFINE_EVENT(transaction_restart_iter,	trans_restart_traverse,
1212 	TP_PROTO(struct btree_trans *trans,
1213 		 unsigned long caller_ip,
1214 		 struct btree_path *path),
1215 	TP_ARGS(trans, caller_ip, path)
1216 );
1217 
1218 DEFINE_EVENT(transaction_restart_iter,	trans_restart_memory_allocation_failure,
1219 	TP_PROTO(struct btree_trans *trans,
1220 		 unsigned long caller_ip,
1221 		 struct btree_path *path),
1222 	TP_ARGS(trans, caller_ip, path)
1223 );
1224 
1225 DEFINE_EVENT(trans_str_nocaller, trans_restart_would_deadlock,
1226 	TP_PROTO(struct btree_trans *trans,
1227 		 const char *cycle),
1228 	TP_ARGS(trans, cycle)
1229 );
1230 
1231 DEFINE_EVENT(transaction_event,	trans_restart_would_deadlock_recursion_limit,
1232 	TP_PROTO(struct btree_trans *trans,
1233 		 unsigned long caller_ip),
1234 	TP_ARGS(trans, caller_ip)
1235 );
1236 
1237 TRACE_EVENT(trans_restart_would_deadlock_write,
1238 	TP_PROTO(struct btree_trans *trans),
1239 	TP_ARGS(trans),
1240 
1241 	TP_STRUCT__entry(
1242 		__array(char,			trans_fn, 32	)
1243 	),
1244 
1245 	TP_fast_assign(
1246 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1247 	),
1248 
1249 	TP_printk("%s", __entry->trans_fn)
1250 );
1251 
1252 TRACE_EVENT(trans_restart_mem_realloced,
1253 	TP_PROTO(struct btree_trans *trans,
1254 		 unsigned long caller_ip,
1255 		 unsigned long bytes),
1256 	TP_ARGS(trans, caller_ip, bytes),
1257 
1258 	TP_STRUCT__entry(
1259 		__array(char,			trans_fn, 32	)
1260 		__field(unsigned long,		caller_ip	)
1261 		__field(unsigned long,		bytes		)
1262 	),
1263 
1264 	TP_fast_assign(
1265 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1266 		__entry->caller_ip	= caller_ip;
1267 		__entry->bytes		= bytes;
1268 	),
1269 
1270 	TP_printk("%s %pS bytes %lu",
1271 		  __entry->trans_fn,
1272 		  (void *) __entry->caller_ip,
1273 		  __entry->bytes)
1274 );
1275 
1276 TRACE_EVENT(trans_restart_key_cache_key_realloced,
1277 	TP_PROTO(struct btree_trans *trans,
1278 		 unsigned long caller_ip,
1279 		 struct btree_path *path,
1280 		 unsigned old_u64s,
1281 		 unsigned new_u64s),
1282 	TP_ARGS(trans, caller_ip, path, old_u64s, new_u64s),
1283 
1284 	TP_STRUCT__entry(
1285 		__array(char,			trans_fn, 32	)
1286 		__field(unsigned long,		caller_ip	)
1287 		__field(enum btree_id,		btree_id	)
1288 		TRACE_BPOS_entries(pos)
1289 		__field(u32,			old_u64s	)
1290 		__field(u32,			new_u64s	)
1291 	),
1292 
1293 	TP_fast_assign(
1294 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1295 		__entry->caller_ip		= caller_ip;
1296 
1297 		__entry->btree_id	= path->btree_id;
1298 		TRACE_BPOS_assign(pos, path->pos);
1299 		__entry->old_u64s	= old_u64s;
1300 		__entry->new_u64s	= new_u64s;
1301 	),
1302 
1303 	TP_printk("%s %pS btree %s pos %llu:%llu:%u old_u64s %u new_u64s %u",
1304 		  __entry->trans_fn,
1305 		  (void *) __entry->caller_ip,
1306 		  bch2_btree_id_str(__entry->btree_id),
1307 		  __entry->pos_inode,
1308 		  __entry->pos_offset,
1309 		  __entry->pos_snapshot,
1310 		  __entry->old_u64s,
1311 		  __entry->new_u64s)
1312 );
1313 
1314 TRACE_EVENT(path_downgrade,
1315 	TP_PROTO(struct btree_trans *trans,
1316 		 unsigned long caller_ip,
1317 		 struct btree_path *path,
1318 		 unsigned old_locks_want),
1319 	TP_ARGS(trans, caller_ip, path, old_locks_want),
1320 
1321 	TP_STRUCT__entry(
1322 		__array(char,			trans_fn, 32	)
1323 		__field(unsigned long,		caller_ip	)
1324 		__field(unsigned,		old_locks_want	)
1325 		__field(unsigned,		new_locks_want	)
1326 		__field(unsigned,		btree		)
1327 		TRACE_BPOS_entries(pos)
1328 	),
1329 
1330 	TP_fast_assign(
1331 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1332 		__entry->caller_ip		= caller_ip;
1333 		__entry->old_locks_want		= old_locks_want;
1334 		__entry->new_locks_want		= path->locks_want;
1335 		__entry->btree			= path->btree_id;
1336 		TRACE_BPOS_assign(pos, path->pos);
1337 	),
1338 
1339 	TP_printk("%s %pS locks_want %u -> %u %s %llu:%llu:%u",
1340 		  __entry->trans_fn,
1341 		  (void *) __entry->caller_ip,
1342 		  __entry->old_locks_want,
1343 		  __entry->new_locks_want,
1344 		  bch2_btree_id_str(__entry->btree),
1345 		  __entry->pos_inode,
1346 		  __entry->pos_offset,
1347 		  __entry->pos_snapshot)
1348 );
1349 
1350 DEFINE_EVENT(transaction_event,	trans_restart_write_buffer_flush,
1351 	TP_PROTO(struct btree_trans *trans,
1352 		 unsigned long caller_ip),
1353 	TP_ARGS(trans, caller_ip)
1354 );
1355 
1356 TRACE_EVENT(write_buffer_flush,
1357 	TP_PROTO(struct btree_trans *trans, size_t nr, size_t skipped, size_t fast, size_t size),
1358 	TP_ARGS(trans, nr, skipped, fast, size),
1359 
1360 	TP_STRUCT__entry(
1361 		__field(size_t,		nr		)
1362 		__field(size_t,		skipped		)
1363 		__field(size_t,		fast		)
1364 		__field(size_t,		size		)
1365 	),
1366 
1367 	TP_fast_assign(
1368 		__entry->nr	= nr;
1369 		__entry->skipped = skipped;
1370 		__entry->fast	= fast;
1371 		__entry->size	= size;
1372 	),
1373 
1374 	TP_printk("%zu/%zu skipped %zu fast %zu",
1375 		  __entry->nr, __entry->size, __entry->skipped, __entry->fast)
1376 );
1377 
1378 TRACE_EVENT(write_buffer_flush_sync,
1379 	TP_PROTO(struct btree_trans *trans, unsigned long caller_ip),
1380 	TP_ARGS(trans, caller_ip),
1381 
1382 	TP_STRUCT__entry(
1383 		__array(char,			trans_fn, 32	)
1384 		__field(unsigned long,		caller_ip	)
1385 	),
1386 
1387 	TP_fast_assign(
1388 		strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
1389 		__entry->caller_ip		= caller_ip;
1390 	),
1391 
1392 	TP_printk("%s %pS", __entry->trans_fn, (void *) __entry->caller_ip)
1393 );
1394 
1395 TRACE_EVENT(write_buffer_flush_slowpath,
1396 	TP_PROTO(struct btree_trans *trans, size_t slowpath, size_t total),
1397 	TP_ARGS(trans, slowpath, total),
1398 
1399 	TP_STRUCT__entry(
1400 		__field(size_t,		slowpath	)
1401 		__field(size_t,		total		)
1402 	),
1403 
1404 	TP_fast_assign(
1405 		__entry->slowpath	= slowpath;
1406 		__entry->total		= total;
1407 	),
1408 
1409 	TP_printk("%zu/%zu", __entry->slowpath, __entry->total)
1410 );
1411 
1412 DEFINE_EVENT(fs_str, rebalance_extent,
1413 	TP_PROTO(struct bch_fs *c, const char *str),
1414 	TP_ARGS(c, str)
1415 );
1416 
1417 DEFINE_EVENT(fs_str, data_update,
1418 	TP_PROTO(struct bch_fs *c, const char *str),
1419 	TP_ARGS(c, str)
1420 );
1421 
1422 TRACE_EVENT(error_downcast,
1423 	TP_PROTO(int bch_err, int std_err, unsigned long ip),
1424 	TP_ARGS(bch_err, std_err, ip),
1425 
1426 	TP_STRUCT__entry(
1427 		__array(char,		bch_err, 32		)
1428 		__array(char,		std_err, 32		)
1429 		__array(char,		ip, 32			)
1430 	),
1431 
1432 	TP_fast_assign(
1433 		strscpy(__entry->bch_err, bch2_err_str(bch_err), sizeof(__entry->bch_err));
1434 		strscpy(__entry->std_err, bch2_err_str(std_err), sizeof(__entry->std_err));
1435 		snprintf(__entry->ip, sizeof(__entry->ip), "%ps", (void *) ip);
1436 	),
1437 
1438 	TP_printk("%s -> %s %s", __entry->bch_err, __entry->std_err, __entry->ip)
1439 );
1440 
1441 #endif /* _TRACE_BCACHEFS_H */
1442 
1443 /* This part must be outside protection */
1444 #undef TRACE_INCLUDE_PATH
1445 #define TRACE_INCLUDE_PATH ../../fs/bcachefs
1446 
1447 #undef TRACE_INCLUDE_FILE
1448 #define TRACE_INCLUDE_FILE trace
1449 
1450 #include <trace/define_trace.h>
1451