xref: /openbmc/linux/include/trace/events/btrfs.h (revision a2cce7a9)
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM btrfs
3 
4 #if !defined(_TRACE_BTRFS_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_BTRFS_H
6 
7 #include <linux/writeback.h>
8 #include <linux/tracepoint.h>
9 #include <trace/events/gfpflags.h>
10 
11 struct btrfs_root;
12 struct btrfs_fs_info;
13 struct btrfs_inode;
14 struct extent_map;
15 struct btrfs_ordered_extent;
16 struct btrfs_delayed_ref_node;
17 struct btrfs_delayed_tree_ref;
18 struct btrfs_delayed_data_ref;
19 struct btrfs_delayed_ref_head;
20 struct btrfs_block_group_cache;
21 struct btrfs_free_cluster;
22 struct map_lookup;
23 struct extent_buffer;
24 struct btrfs_work;
25 struct __btrfs_workqueue;
26 struct btrfs_qgroup_operation;
27 
28 #define show_ref_type(type)						\
29 	__print_symbolic(type,						\
30 		{ BTRFS_TREE_BLOCK_REF_KEY, 	"TREE_BLOCK_REF" },	\
31 		{ BTRFS_EXTENT_DATA_REF_KEY, 	"EXTENT_DATA_REF" },	\
32 		{ BTRFS_EXTENT_REF_V0_KEY, 	"EXTENT_REF_V0" },	\
33 		{ BTRFS_SHARED_BLOCK_REF_KEY, 	"SHARED_BLOCK_REF" },	\
34 		{ BTRFS_SHARED_DATA_REF_KEY, 	"SHARED_DATA_REF" })
35 
36 #define __show_root_type(obj)						\
37 	__print_symbolic_u64(obj,					\
38 		{ BTRFS_ROOT_TREE_OBJECTID, 	"ROOT_TREE"	},	\
39 		{ BTRFS_EXTENT_TREE_OBJECTID, 	"EXTENT_TREE"	},	\
40 		{ BTRFS_CHUNK_TREE_OBJECTID, 	"CHUNK_TREE"	},	\
41 		{ BTRFS_DEV_TREE_OBJECTID, 	"DEV_TREE"	},	\
42 		{ BTRFS_FS_TREE_OBJECTID, 	"FS_TREE"	},	\
43 		{ BTRFS_ROOT_TREE_DIR_OBJECTID, "ROOT_TREE_DIR"	},	\
44 		{ BTRFS_CSUM_TREE_OBJECTID, 	"CSUM_TREE"	},	\
45 		{ BTRFS_TREE_LOG_OBJECTID,	"TREE_LOG"	},	\
46 		{ BTRFS_QUOTA_TREE_OBJECTID,	"QUOTA_TREE"	},	\
47 		{ BTRFS_TREE_RELOC_OBJECTID,	"TREE_RELOC"	},	\
48 		{ BTRFS_UUID_TREE_OBJECTID,	"UUID_RELOC"	},	\
49 		{ BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" })
50 
51 #define show_root_type(obj)						\
52 	obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) ||		\
53 	      (obj >= BTRFS_ROOT_TREE_OBJECTID &&			\
54 	       obj <= BTRFS_QUOTA_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
55 
56 #define BTRFS_GROUP_FLAGS	\
57 	{ BTRFS_BLOCK_GROUP_DATA,	"DATA"},	\
58 	{ BTRFS_BLOCK_GROUP_SYSTEM,	"SYSTEM"},	\
59 	{ BTRFS_BLOCK_GROUP_METADATA,	"METADATA"},	\
60 	{ BTRFS_BLOCK_GROUP_RAID0,	"RAID0"}, 	\
61 	{ BTRFS_BLOCK_GROUP_RAID1,	"RAID1"}, 	\
62 	{ BTRFS_BLOCK_GROUP_DUP,	"DUP"}, 	\
63 	{ BTRFS_BLOCK_GROUP_RAID10,	"RAID10"}, 	\
64 	{ BTRFS_BLOCK_GROUP_RAID5,	"RAID5"},	\
65 	{ BTRFS_BLOCK_GROUP_RAID6,	"RAID6"}
66 
67 #define BTRFS_UUID_SIZE 16
68 
69 TRACE_EVENT(btrfs_transaction_commit,
70 
71 	TP_PROTO(struct btrfs_root *root),
72 
73 	TP_ARGS(root),
74 
75 	TP_STRUCT__entry(
76 		__field(	u64,  generation		)
77 		__field(	u64,  root_objectid		)
78 	),
79 
80 	TP_fast_assign(
81 		__entry->generation	= root->fs_info->generation;
82 		__entry->root_objectid	= root->root_key.objectid;
83 	),
84 
85 	TP_printk("root = %llu(%s), gen = %llu",
86 		  show_root_type(__entry->root_objectid),
87 		  (unsigned long long)__entry->generation)
88 );
89 
90 DECLARE_EVENT_CLASS(btrfs__inode,
91 
92 	TP_PROTO(struct inode *inode),
93 
94 	TP_ARGS(inode),
95 
96 	TP_STRUCT__entry(
97 		__field(	ino_t,  ino			)
98 		__field(	blkcnt_t,  blocks		)
99 		__field(	u64,  disk_i_size		)
100 		__field(	u64,  generation		)
101 		__field(	u64,  last_trans		)
102 		__field(	u64,  logged_trans		)
103 		__field(	u64,  root_objectid		)
104 	),
105 
106 	TP_fast_assign(
107 		__entry->ino	= inode->i_ino;
108 		__entry->blocks	= inode->i_blocks;
109 		__entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
110 		__entry->generation = BTRFS_I(inode)->generation;
111 		__entry->last_trans = BTRFS_I(inode)->last_trans;
112 		__entry->logged_trans = BTRFS_I(inode)->logged_trans;
113 		__entry->root_objectid =
114 				BTRFS_I(inode)->root->root_key.objectid;
115 	),
116 
117 	TP_printk("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
118 		  "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu",
119 		  show_root_type(__entry->root_objectid),
120 		  (unsigned long long)__entry->generation,
121 		  (unsigned long)__entry->ino,
122 		  (unsigned long long)__entry->blocks,
123 		  (unsigned long long)__entry->disk_i_size,
124 		  (unsigned long long)__entry->last_trans,
125 		  (unsigned long long)__entry->logged_trans)
126 );
127 
128 DEFINE_EVENT(btrfs__inode, btrfs_inode_new,
129 
130 	TP_PROTO(struct inode *inode),
131 
132 	TP_ARGS(inode)
133 );
134 
135 DEFINE_EVENT(btrfs__inode, btrfs_inode_request,
136 
137 	TP_PROTO(struct inode *inode),
138 
139 	TP_ARGS(inode)
140 );
141 
142 DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
143 
144 	TP_PROTO(struct inode *inode),
145 
146 	TP_ARGS(inode)
147 );
148 
149 #define __show_map_type(type)						\
150 	__print_symbolic_u64(type,					\
151 		{ EXTENT_MAP_LAST_BYTE, "LAST_BYTE" 	},		\
152 		{ EXTENT_MAP_HOLE, 	"HOLE" 		},		\
153 		{ EXTENT_MAP_INLINE, 	"INLINE" 	},		\
154 		{ EXTENT_MAP_DELALLOC,	"DELALLOC" 	})
155 
156 #define show_map_type(type)			\
157 	type, (type >= EXTENT_MAP_LAST_BYTE) ? "-" :  __show_map_type(type)
158 
159 #define show_map_flags(flag)						\
160 	__print_flags(flag, "|",					\
161 		{ (1 << EXTENT_FLAG_PINNED), 		"PINNED" 	},\
162 		{ (1 << EXTENT_FLAG_COMPRESSED), 	"COMPRESSED" 	},\
163 		{ (1 << EXTENT_FLAG_VACANCY), 		"VACANCY" 	},\
164 		{ (1 << EXTENT_FLAG_PREALLOC), 		"PREALLOC" 	},\
165 		{ (1 << EXTENT_FLAG_LOGGING),	 	"LOGGING" 	},\
166 		{ (1 << EXTENT_FLAG_FILLING),	 	"FILLING" 	},\
167 		{ (1 << EXTENT_FLAG_FS_MAPPING),	"FS_MAPPING"	})
168 
169 TRACE_EVENT_CONDITION(btrfs_get_extent,
170 
171 	TP_PROTO(struct btrfs_root *root, struct extent_map *map),
172 
173 	TP_ARGS(root, map),
174 
175 	TP_CONDITION(map),
176 
177 	TP_STRUCT__entry(
178 		__field(	u64,  root_objectid	)
179 		__field(	u64,  start		)
180 		__field(	u64,  len		)
181 		__field(	u64,  orig_start	)
182 		__field(	u64,  block_start	)
183 		__field(	u64,  block_len		)
184 		__field(	unsigned long,  flags	)
185 		__field(	int,  refs		)
186 		__field(	unsigned int,  compress_type	)
187 	),
188 
189 	TP_fast_assign(
190 		__entry->root_objectid	= root->root_key.objectid;
191 		__entry->start 		= map->start;
192 		__entry->len		= map->len;
193 		__entry->orig_start	= map->orig_start;
194 		__entry->block_start	= map->block_start;
195 		__entry->block_len	= map->block_len;
196 		__entry->flags		= map->flags;
197 		__entry->refs		= atomic_read(&map->refs);
198 		__entry->compress_type	= map->compress_type;
199 	),
200 
201 	TP_printk("root = %llu(%s), start = %llu, len = %llu, "
202 		  "orig_start = %llu, block_start = %llu(%s), "
203 		  "block_len = %llu, flags = %s, refs = %u, "
204 		  "compress_type = %u",
205 		  show_root_type(__entry->root_objectid),
206 		  (unsigned long long)__entry->start,
207 		  (unsigned long long)__entry->len,
208 		  (unsigned long long)__entry->orig_start,
209 		  show_map_type(__entry->block_start),
210 		  (unsigned long long)__entry->block_len,
211 		  show_map_flags(__entry->flags),
212 		  __entry->refs, __entry->compress_type)
213 );
214 
215 #define show_ordered_flags(flags)					   \
216 	__print_flags(flags, "|",					   \
217 		{ (1 << BTRFS_ORDERED_IO_DONE), 	"IO_DONE" 	}, \
218 		{ (1 << BTRFS_ORDERED_COMPLETE), 	"COMPLETE" 	}, \
219 		{ (1 << BTRFS_ORDERED_NOCOW), 		"NOCOW" 	}, \
220 		{ (1 << BTRFS_ORDERED_COMPRESSED), 	"COMPRESSED" 	}, \
221 		{ (1 << BTRFS_ORDERED_PREALLOC), 	"PREALLOC" 	}, \
222 		{ (1 << BTRFS_ORDERED_DIRECT),	 	"DIRECT" 	}, \
223 		{ (1 << BTRFS_ORDERED_IOERR), 		"IOERR" 	}, \
224 		{ (1 << BTRFS_ORDERED_UPDATED_ISIZE), 	"UPDATED_ISIZE"	}, \
225 		{ (1 << BTRFS_ORDERED_LOGGED_CSUM), 	"LOGGED_CSUM"	}, \
226 		{ (1 << BTRFS_ORDERED_TRUNCATED), 	"TRUNCATED"	})
227 
228 
229 DECLARE_EVENT_CLASS(btrfs__ordered_extent,
230 
231 	TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
232 
233 	TP_ARGS(inode, ordered),
234 
235 	TP_STRUCT__entry(
236 		__field(	ino_t,  ino		)
237 		__field(	u64,  file_offset	)
238 		__field(	u64,  start		)
239 		__field(	u64,  len		)
240 		__field(	u64,  disk_len		)
241 		__field(	u64,  bytes_left	)
242 		__field(	unsigned long,  flags	)
243 		__field(	int,  compress_type	)
244 		__field(	int,  refs		)
245 		__field(	u64,  root_objectid	)
246 	),
247 
248 	TP_fast_assign(
249 		__entry->ino 		= inode->i_ino;
250 		__entry->file_offset	= ordered->file_offset;
251 		__entry->start		= ordered->start;
252 		__entry->len		= ordered->len;
253 		__entry->disk_len	= ordered->disk_len;
254 		__entry->bytes_left	= ordered->bytes_left;
255 		__entry->flags		= ordered->flags;
256 		__entry->compress_type	= ordered->compress_type;
257 		__entry->refs		= atomic_read(&ordered->refs);
258 		__entry->root_objectid	=
259 				BTRFS_I(inode)->root->root_key.objectid;
260 	),
261 
262 	TP_printk("root = %llu(%s), ino = %llu, file_offset = %llu, "
263 		  "start = %llu, len = %llu, disk_len = %llu, "
264 		  "bytes_left = %llu, flags = %s, compress_type = %d, "
265 		  "refs = %d",
266 		  show_root_type(__entry->root_objectid),
267 		  (unsigned long long)__entry->ino,
268 		  (unsigned long long)__entry->file_offset,
269 		  (unsigned long long)__entry->start,
270 		  (unsigned long long)__entry->len,
271 		  (unsigned long long)__entry->disk_len,
272 		  (unsigned long long)__entry->bytes_left,
273 		  show_ordered_flags(__entry->flags),
274 		  __entry->compress_type, __entry->refs)
275 );
276 
277 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_add,
278 
279 	TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
280 
281 	TP_ARGS(inode, ordered)
282 );
283 
284 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_remove,
285 
286 	TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
287 
288 	TP_ARGS(inode, ordered)
289 );
290 
291 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_start,
292 
293 	TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
294 
295 	TP_ARGS(inode, ordered)
296 );
297 
298 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_put,
299 
300 	TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
301 
302 	TP_ARGS(inode, ordered)
303 );
304 
305 DECLARE_EVENT_CLASS(btrfs__writepage,
306 
307 	TP_PROTO(struct page *page, struct inode *inode,
308 		 struct writeback_control *wbc),
309 
310 	TP_ARGS(page, inode, wbc),
311 
312 	TP_STRUCT__entry(
313 		__field(	ino_t,  ino			)
314 		__field(	pgoff_t,  index			)
315 		__field(	long,   nr_to_write		)
316 		__field(	long,   pages_skipped		)
317 		__field(	loff_t, range_start		)
318 		__field(	loff_t, range_end		)
319 		__field(	char,   for_kupdate		)
320 		__field(	char,   for_reclaim		)
321 		__field(	char,   range_cyclic		)
322 		__field(	pgoff_t,  writeback_index	)
323 		__field(	u64,    root_objectid		)
324 	),
325 
326 	TP_fast_assign(
327 		__entry->ino		= inode->i_ino;
328 		__entry->index		= page->index;
329 		__entry->nr_to_write	= wbc->nr_to_write;
330 		__entry->pages_skipped	= wbc->pages_skipped;
331 		__entry->range_start	= wbc->range_start;
332 		__entry->range_end	= wbc->range_end;
333 		__entry->for_kupdate	= wbc->for_kupdate;
334 		__entry->for_reclaim	= wbc->for_reclaim;
335 		__entry->range_cyclic	= wbc->range_cyclic;
336 		__entry->writeback_index = inode->i_mapping->writeback_index;
337 		__entry->root_objectid	=
338 				 BTRFS_I(inode)->root->root_key.objectid;
339 	),
340 
341 	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, "
342 		  "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, "
343 		  "range_end = %llu, for_kupdate = %d, "
344 		  "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu",
345 		  show_root_type(__entry->root_objectid),
346 		  (unsigned long)__entry->ino, __entry->index,
347 		  __entry->nr_to_write, __entry->pages_skipped,
348 		  __entry->range_start, __entry->range_end,
349 		  __entry->for_kupdate,
350 		  __entry->for_reclaim, __entry->range_cyclic,
351 		  (unsigned long)__entry->writeback_index)
352 );
353 
354 DEFINE_EVENT(btrfs__writepage, __extent_writepage,
355 
356 	TP_PROTO(struct page *page, struct inode *inode,
357 		 struct writeback_control *wbc),
358 
359 	TP_ARGS(page, inode, wbc)
360 );
361 
362 TRACE_EVENT(btrfs_writepage_end_io_hook,
363 
364 	TP_PROTO(struct page *page, u64 start, u64 end, int uptodate),
365 
366 	TP_ARGS(page, start, end, uptodate),
367 
368 	TP_STRUCT__entry(
369 		__field(	ino_t,	 ino		)
370 		__field(	pgoff_t, index		)
371 		__field(	u64,	 start		)
372 		__field(	u64,	 end		)
373 		__field(	int,	 uptodate	)
374 		__field(	u64,    root_objectid	)
375 	),
376 
377 	TP_fast_assign(
378 		__entry->ino	= page->mapping->host->i_ino;
379 		__entry->index	= page->index;
380 		__entry->start	= start;
381 		__entry->end	= end;
382 		__entry->uptodate = uptodate;
383 		__entry->root_objectid	=
384 			 BTRFS_I(page->mapping->host)->root->root_key.objectid;
385 	),
386 
387 	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
388 		  "end = %llu, uptodate = %d",
389 		  show_root_type(__entry->root_objectid),
390 		  (unsigned long)__entry->ino, (unsigned long)__entry->index,
391 		  (unsigned long long)__entry->start,
392 		  (unsigned long long)__entry->end, __entry->uptodate)
393 );
394 
395 TRACE_EVENT(btrfs_sync_file,
396 
397 	TP_PROTO(struct file *file, int datasync),
398 
399 	TP_ARGS(file, datasync),
400 
401 	TP_STRUCT__entry(
402 		__field(	ino_t,  ino		)
403 		__field(	ino_t,  parent		)
404 		__field(	int,    datasync	)
405 		__field(	u64,    root_objectid	)
406 	),
407 
408 	TP_fast_assign(
409 		struct dentry *dentry = file->f_path.dentry;
410 		struct inode *inode = d_inode(dentry);
411 
412 		__entry->ino		= inode->i_ino;
413 		__entry->parent		= d_inode(dentry->d_parent)->i_ino;
414 		__entry->datasync	= datasync;
415 		__entry->root_objectid	=
416 				 BTRFS_I(inode)->root->root_key.objectid;
417 	),
418 
419 	TP_printk("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
420 		  show_root_type(__entry->root_objectid),
421 		  (unsigned long)__entry->ino, (unsigned long)__entry->parent,
422 		  __entry->datasync)
423 );
424 
425 TRACE_EVENT(btrfs_sync_fs,
426 
427 	TP_PROTO(int wait),
428 
429 	TP_ARGS(wait),
430 
431 	TP_STRUCT__entry(
432 		__field(	int,  wait		)
433 	),
434 
435 	TP_fast_assign(
436 		__entry->wait	= wait;
437 	),
438 
439 	TP_printk("wait = %d", __entry->wait)
440 );
441 
442 #define show_ref_action(action)						\
443 	__print_symbolic(action,					\
444 		{ BTRFS_ADD_DELAYED_REF,    "ADD_DELAYED_REF" },	\
445 		{ BTRFS_DROP_DELAYED_REF,   "DROP_DELAYED_REF" },	\
446 		{ BTRFS_ADD_DELAYED_EXTENT, "ADD_DELAYED_EXTENT" }, 	\
447 		{ BTRFS_UPDATE_DELAYED_HEAD, "UPDATE_DELAYED_HEAD" })
448 
449 
450 DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
451 
452 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
453 		 struct btrfs_delayed_tree_ref *full_ref,
454 		 int action),
455 
456 	TP_ARGS(ref, full_ref, action),
457 
458 	TP_STRUCT__entry(
459 		__field(	u64,  bytenr		)
460 		__field(	u64,  num_bytes		)
461 		__field(	int,  action		)
462 		__field(	u64,  parent		)
463 		__field(	u64,  ref_root		)
464 		__field(	int,  level		)
465 		__field(	int,  type		)
466 		__field(	u64,  seq		)
467 	),
468 
469 	TP_fast_assign(
470 		__entry->bytenr		= ref->bytenr;
471 		__entry->num_bytes	= ref->num_bytes;
472 		__entry->action		= action;
473 		__entry->parent		= full_ref->parent;
474 		__entry->ref_root	= full_ref->root;
475 		__entry->level		= full_ref->level;
476 		__entry->type		= ref->type;
477 		__entry->seq		= ref->seq;
478 	),
479 
480 	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
481 		  "parent = %llu(%s), ref_root = %llu(%s), level = %d, "
482 		  "type = %s, seq = %llu",
483 		  (unsigned long long)__entry->bytenr,
484 		  (unsigned long long)__entry->num_bytes,
485 		  show_ref_action(__entry->action),
486 		  show_root_type(__entry->parent),
487 		  show_root_type(__entry->ref_root),
488 		  __entry->level, show_ref_type(__entry->type),
489 		  (unsigned long long)__entry->seq)
490 );
491 
492 DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
493 
494 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
495 		 struct btrfs_delayed_tree_ref *full_ref,
496 		 int action),
497 
498 	TP_ARGS(ref, full_ref, action)
499 );
500 
501 DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
502 
503 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
504 		 struct btrfs_delayed_tree_ref *full_ref,
505 		 int action),
506 
507 	TP_ARGS(ref, full_ref, action)
508 );
509 
510 DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
511 
512 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
513 		 struct btrfs_delayed_data_ref *full_ref,
514 		 int action),
515 
516 	TP_ARGS(ref, full_ref, action),
517 
518 	TP_STRUCT__entry(
519 		__field(	u64,  bytenr		)
520 		__field(	u64,  num_bytes		)
521 		__field(	int,  action		)
522 		__field(	u64,  parent		)
523 		__field(	u64,  ref_root		)
524 		__field(	u64,  owner		)
525 		__field(	u64,  offset		)
526 		__field(	int,  type		)
527 		__field(	u64,  seq		)
528 	),
529 
530 	TP_fast_assign(
531 		__entry->bytenr		= ref->bytenr;
532 		__entry->num_bytes	= ref->num_bytes;
533 		__entry->action		= action;
534 		__entry->parent		= full_ref->parent;
535 		__entry->ref_root	= full_ref->root;
536 		__entry->owner		= full_ref->objectid;
537 		__entry->offset		= full_ref->offset;
538 		__entry->type		= ref->type;
539 		__entry->seq		= ref->seq;
540 	),
541 
542 	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
543 		  "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, "
544 		  "offset = %llu, type = %s, seq = %llu",
545 		  (unsigned long long)__entry->bytenr,
546 		  (unsigned long long)__entry->num_bytes,
547 		  show_ref_action(__entry->action),
548 		  show_root_type(__entry->parent),
549 		  show_root_type(__entry->ref_root),
550 		  (unsigned long long)__entry->owner,
551 		  (unsigned long long)__entry->offset,
552 		  show_ref_type(__entry->type),
553 		  (unsigned long long)__entry->seq)
554 );
555 
556 DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
557 
558 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
559 		 struct btrfs_delayed_data_ref *full_ref,
560 		 int action),
561 
562 	TP_ARGS(ref, full_ref, action)
563 );
564 
565 DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
566 
567 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
568 		 struct btrfs_delayed_data_ref *full_ref,
569 		 int action),
570 
571 	TP_ARGS(ref, full_ref, action)
572 );
573 
574 DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
575 
576 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
577 		 struct btrfs_delayed_ref_head *head_ref,
578 		 int action),
579 
580 	TP_ARGS(ref, head_ref, action),
581 
582 	TP_STRUCT__entry(
583 		__field(	u64,  bytenr		)
584 		__field(	u64,  num_bytes		)
585 		__field(	int,  action		)
586 		__field(	int,  is_data		)
587 	),
588 
589 	TP_fast_assign(
590 		__entry->bytenr		= ref->bytenr;
591 		__entry->num_bytes	= ref->num_bytes;
592 		__entry->action		= action;
593 		__entry->is_data	= head_ref->is_data;
594 	),
595 
596 	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
597 		  (unsigned long long)__entry->bytenr,
598 		  (unsigned long long)__entry->num_bytes,
599 		  show_ref_action(__entry->action),
600 		  __entry->is_data)
601 );
602 
603 DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
604 
605 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
606 		 struct btrfs_delayed_ref_head *head_ref,
607 		 int action),
608 
609 	TP_ARGS(ref, head_ref, action)
610 );
611 
612 DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
613 
614 	TP_PROTO(struct btrfs_delayed_ref_node *ref,
615 		 struct btrfs_delayed_ref_head *head_ref,
616 		 int action),
617 
618 	TP_ARGS(ref, head_ref, action)
619 );
620 
621 #define show_chunk_type(type)					\
622 	__print_flags(type, "|",				\
623 		{ BTRFS_BLOCK_GROUP_DATA, 	"DATA"	},	\
624 		{ BTRFS_BLOCK_GROUP_SYSTEM, 	"SYSTEM"},	\
625 		{ BTRFS_BLOCK_GROUP_METADATA, 	"METADATA"},	\
626 		{ BTRFS_BLOCK_GROUP_RAID0, 	"RAID0" },	\
627 		{ BTRFS_BLOCK_GROUP_RAID1, 	"RAID1" },	\
628 		{ BTRFS_BLOCK_GROUP_DUP, 	"DUP"	},	\
629 		{ BTRFS_BLOCK_GROUP_RAID10, 	"RAID10"},	\
630 		{ BTRFS_BLOCK_GROUP_RAID5, 	"RAID5"	},	\
631 		{ BTRFS_BLOCK_GROUP_RAID6, 	"RAID6"	})
632 
633 DECLARE_EVENT_CLASS(btrfs__chunk,
634 
635 	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
636 		 u64 offset, u64 size),
637 
638 	TP_ARGS(root, map, offset, size),
639 
640 	TP_STRUCT__entry(
641 		__field(	int,  num_stripes		)
642 		__field(	u64,  type			)
643 		__field(	int,  sub_stripes		)
644 		__field(	u64,  offset			)
645 		__field(	u64,  size			)
646 		__field(	u64,  root_objectid		)
647 	),
648 
649 	TP_fast_assign(
650 		__entry->num_stripes	= map->num_stripes;
651 		__entry->type		= map->type;
652 		__entry->sub_stripes	= map->sub_stripes;
653 		__entry->offset		= offset;
654 		__entry->size		= size;
655 		__entry->root_objectid	= root->root_key.objectid;
656 	),
657 
658 	TP_printk("root = %llu(%s), offset = %llu, size = %llu, "
659 		  "num_stripes = %d, sub_stripes = %d, type = %s",
660 		  show_root_type(__entry->root_objectid),
661 		  (unsigned long long)__entry->offset,
662 		  (unsigned long long)__entry->size,
663 		  __entry->num_stripes, __entry->sub_stripes,
664 		  show_chunk_type(__entry->type))
665 );
666 
667 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_alloc,
668 
669 	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
670 		 u64 offset, u64 size),
671 
672 	TP_ARGS(root, map, offset, size)
673 );
674 
675 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_free,
676 
677 	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
678 		 u64 offset, u64 size),
679 
680 	TP_ARGS(root, map, offset, size)
681 );
682 
683 TRACE_EVENT(btrfs_cow_block,
684 
685 	TP_PROTO(struct btrfs_root *root, struct extent_buffer *buf,
686 		 struct extent_buffer *cow),
687 
688 	TP_ARGS(root, buf, cow),
689 
690 	TP_STRUCT__entry(
691 		__field(	u64,  root_objectid		)
692 		__field(	u64,  buf_start			)
693 		__field(	int,  refs			)
694 		__field(	u64,  cow_start			)
695 		__field(	int,  buf_level			)
696 		__field(	int,  cow_level			)
697 	),
698 
699 	TP_fast_assign(
700 		__entry->root_objectid	= root->root_key.objectid;
701 		__entry->buf_start	= buf->start;
702 		__entry->refs		= atomic_read(&buf->refs);
703 		__entry->cow_start	= cow->start;
704 		__entry->buf_level	= btrfs_header_level(buf);
705 		__entry->cow_level	= btrfs_header_level(cow);
706 	),
707 
708 	TP_printk("root = %llu(%s), refs = %d, orig_buf = %llu "
709 		  "(orig_level = %d), cow_buf = %llu (cow_level = %d)",
710 		  show_root_type(__entry->root_objectid),
711 		  __entry->refs,
712 		  (unsigned long long)__entry->buf_start,
713 		  __entry->buf_level,
714 		  (unsigned long long)__entry->cow_start,
715 		  __entry->cow_level)
716 );
717 
718 TRACE_EVENT(btrfs_space_reservation,
719 
720 	TP_PROTO(struct btrfs_fs_info *fs_info, char *type, u64 val,
721 		 u64 bytes, int reserve),
722 
723 	TP_ARGS(fs_info, type, val, bytes, reserve),
724 
725 	TP_STRUCT__entry(
726 		__array(	u8,	fsid,	BTRFS_UUID_SIZE	)
727 		__string(	type,	type			)
728 		__field(	u64,	val			)
729 		__field(	u64,	bytes			)
730 		__field(	int,	reserve			)
731 	),
732 
733 	TP_fast_assign(
734 		memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE);
735 		__assign_str(type, type);
736 		__entry->val		= val;
737 		__entry->bytes		= bytes;
738 		__entry->reserve	= reserve;
739 	),
740 
741 	TP_printk("%pU: %s: %Lu %s %Lu", __entry->fsid, __get_str(type),
742 		  __entry->val, __entry->reserve ? "reserve" : "release",
743 		  __entry->bytes)
744 );
745 
746 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
747 
748 	TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
749 
750 	TP_ARGS(root, start, len),
751 
752 	TP_STRUCT__entry(
753 		__field(	u64,  root_objectid		)
754 		__field(	u64,  start			)
755 		__field(	u64,  len			)
756 	),
757 
758 	TP_fast_assign(
759 		__entry->root_objectid	= root->root_key.objectid;
760 		__entry->start		= start;
761 		__entry->len		= len;
762 	),
763 
764 	TP_printk("root = %llu(%s), start = %llu, len = %llu",
765 		  show_root_type(__entry->root_objectid),
766 		  (unsigned long long)__entry->start,
767 		  (unsigned long long)__entry->len)
768 );
769 
770 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_alloc,
771 
772 	TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
773 
774 	TP_ARGS(root, start, len)
775 );
776 
777 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_free,
778 
779 	TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
780 
781 	TP_ARGS(root, start, len)
782 );
783 
784 TRACE_EVENT(find_free_extent,
785 
786 	TP_PROTO(struct btrfs_root *root, u64 num_bytes, u64 empty_size,
787 		 u64 data),
788 
789 	TP_ARGS(root, num_bytes, empty_size, data),
790 
791 	TP_STRUCT__entry(
792 		__field(	u64,	root_objectid		)
793 		__field(	u64,	num_bytes		)
794 		__field(	u64,	empty_size		)
795 		__field(	u64,	data			)
796 	),
797 
798 	TP_fast_assign(
799 		__entry->root_objectid	= root->root_key.objectid;
800 		__entry->num_bytes	= num_bytes;
801 		__entry->empty_size	= empty_size;
802 		__entry->data		= data;
803 	),
804 
805 	TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
806 		  "flags = %Lu(%s)", show_root_type(__entry->root_objectid),
807 		  __entry->num_bytes, __entry->empty_size, __entry->data,
808 		  __print_flags((unsigned long)__entry->data, "|",
809 				 BTRFS_GROUP_FLAGS))
810 );
811 
812 DECLARE_EVENT_CLASS(btrfs__reserve_extent,
813 
814 	TP_PROTO(struct btrfs_root *root,
815 		 struct btrfs_block_group_cache *block_group, u64 start,
816 		 u64 len),
817 
818 	TP_ARGS(root, block_group, start, len),
819 
820 	TP_STRUCT__entry(
821 		__field(	u64,	root_objectid		)
822 		__field(	u64,	bg_objectid		)
823 		__field(	u64,	flags			)
824 		__field(	u64,	start			)
825 		__field(	u64,	len			)
826 	),
827 
828 	TP_fast_assign(
829 		__entry->root_objectid	= root->root_key.objectid;
830 		__entry->bg_objectid	= block_group->key.objectid;
831 		__entry->flags		= block_group->flags;
832 		__entry->start		= start;
833 		__entry->len		= len;
834 	),
835 
836 	TP_printk("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
837 		  "start = %Lu, len = %Lu",
838 		  show_root_type(__entry->root_objectid), __entry->bg_objectid,
839 		  __entry->flags, __print_flags((unsigned long)__entry->flags,
840 						"|", BTRFS_GROUP_FLAGS),
841 		  __entry->start, __entry->len)
842 );
843 
844 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
845 
846 	TP_PROTO(struct btrfs_root *root,
847 		 struct btrfs_block_group_cache *block_group, u64 start,
848 		 u64 len),
849 
850 	TP_ARGS(root, block_group, start, len)
851 );
852 
853 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
854 
855 	TP_PROTO(struct btrfs_root *root,
856 		 struct btrfs_block_group_cache *block_group, u64 start,
857 		 u64 len),
858 
859 	TP_ARGS(root, block_group, start, len)
860 );
861 
862 TRACE_EVENT(btrfs_find_cluster,
863 
864 	TP_PROTO(struct btrfs_block_group_cache *block_group, u64 start,
865 		 u64 bytes, u64 empty_size, u64 min_bytes),
866 
867 	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
868 
869 	TP_STRUCT__entry(
870 		__field(	u64,	bg_objectid		)
871 		__field(	u64,	flags			)
872 		__field(	u64,	start			)
873 		__field(	u64,	bytes			)
874 		__field(	u64,	empty_size		)
875 		__field(	u64,	min_bytes		)
876 	),
877 
878 	TP_fast_assign(
879 		__entry->bg_objectid	= block_group->key.objectid;
880 		__entry->flags		= block_group->flags;
881 		__entry->start		= start;
882 		__entry->bytes		= bytes;
883 		__entry->empty_size	= empty_size;
884 		__entry->min_bytes	= min_bytes;
885 	),
886 
887 	TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
888 		  " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid,
889 		  __entry->flags,
890 		  __print_flags((unsigned long)__entry->flags, "|",
891 				BTRFS_GROUP_FLAGS), __entry->start,
892 		  __entry->bytes, __entry->empty_size,  __entry->min_bytes)
893 );
894 
895 TRACE_EVENT(btrfs_failed_cluster_setup,
896 
897 	TP_PROTO(struct btrfs_block_group_cache *block_group),
898 
899 	TP_ARGS(block_group),
900 
901 	TP_STRUCT__entry(
902 		__field(	u64,	bg_objectid		)
903 	),
904 
905 	TP_fast_assign(
906 		__entry->bg_objectid	= block_group->key.objectid;
907 	),
908 
909 	TP_printk("block_group = %Lu", __entry->bg_objectid)
910 );
911 
912 TRACE_EVENT(btrfs_setup_cluster,
913 
914 	TP_PROTO(struct btrfs_block_group_cache *block_group,
915 		 struct btrfs_free_cluster *cluster, u64 size, int bitmap),
916 
917 	TP_ARGS(block_group, cluster, size, bitmap),
918 
919 	TP_STRUCT__entry(
920 		__field(	u64,	bg_objectid		)
921 		__field(	u64,	flags			)
922 		__field(	u64,	start			)
923 		__field(	u64,	max_size		)
924 		__field(	u64,	size			)
925 		__field(	int,	bitmap			)
926 	),
927 
928 	TP_fast_assign(
929 		__entry->bg_objectid	= block_group->key.objectid;
930 		__entry->flags		= block_group->flags;
931 		__entry->start		= cluster->window_start;
932 		__entry->max_size	= cluster->max_size;
933 		__entry->size		= size;
934 		__entry->bitmap		= bitmap;
935 	),
936 
937 	TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
938 		  "size = %Lu, max_size = %Lu, bitmap = %d",
939 		  __entry->bg_objectid,
940 		  __entry->flags,
941 		  __print_flags((unsigned long)__entry->flags, "|",
942 				BTRFS_GROUP_FLAGS), __entry->start,
943 		  __entry->size, __entry->max_size, __entry->bitmap)
944 );
945 
946 struct extent_state;
947 TRACE_EVENT(alloc_extent_state,
948 
949 	TP_PROTO(struct extent_state *state, gfp_t mask, unsigned long IP),
950 
951 	TP_ARGS(state, mask, IP),
952 
953 	TP_STRUCT__entry(
954 		__field(struct extent_state *, state)
955 		__field(gfp_t, mask)
956 		__field(unsigned long, ip)
957 	),
958 
959 	TP_fast_assign(
960 		__entry->state	= state,
961 		__entry->mask	= mask,
962 		__entry->ip	= IP
963 	),
964 
965 	TP_printk("state=%p; mask = %s; caller = %pS", __entry->state,
966 		  show_gfp_flags(__entry->mask), (void *)__entry->ip)
967 );
968 
969 TRACE_EVENT(free_extent_state,
970 
971 	TP_PROTO(struct extent_state *state, unsigned long IP),
972 
973 	TP_ARGS(state, IP),
974 
975 	TP_STRUCT__entry(
976 		__field(struct extent_state *, state)
977 		__field(unsigned long, ip)
978 	),
979 
980 	TP_fast_assign(
981 		__entry->state	= state,
982 		__entry->ip = IP
983 	),
984 
985 	TP_printk(" state=%p; caller = %pS", __entry->state,
986 		  (void *)__entry->ip)
987 );
988 
989 DECLARE_EVENT_CLASS(btrfs__work,
990 
991 	TP_PROTO(struct btrfs_work *work),
992 
993 	TP_ARGS(work),
994 
995 	TP_STRUCT__entry(
996 		__field(	void *,	work			)
997 		__field(	void *, wq			)
998 		__field(	void *,	func			)
999 		__field(	void *,	ordered_func		)
1000 		__field(	void *,	ordered_free		)
1001 		__field(	void *,	normal_work		)
1002 	),
1003 
1004 	TP_fast_assign(
1005 		__entry->work		= work;
1006 		__entry->wq		= work->wq;
1007 		__entry->func		= work->func;
1008 		__entry->ordered_func	= work->ordered_func;
1009 		__entry->ordered_free	= work->ordered_free;
1010 		__entry->normal_work	= &work->normal_work;
1011 	),
1012 
1013 	TP_printk("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p,"
1014 		  " ordered_free=%p",
1015 		  __entry->work, __entry->normal_work, __entry->wq,
1016 		   __entry->func, __entry->ordered_func, __entry->ordered_free)
1017 );
1018 
1019 /* For situiations that the work is freed */
1020 DECLARE_EVENT_CLASS(btrfs__work__done,
1021 
1022 	TP_PROTO(struct btrfs_work *work),
1023 
1024 	TP_ARGS(work),
1025 
1026 	TP_STRUCT__entry(
1027 		__field(	void *,	work			)
1028 	),
1029 
1030 	TP_fast_assign(
1031 		__entry->work		= work;
1032 	),
1033 
1034 	TP_printk("work->%p", __entry->work)
1035 );
1036 
1037 DEFINE_EVENT(btrfs__work, btrfs_work_queued,
1038 
1039 	TP_PROTO(struct btrfs_work *work),
1040 
1041 	TP_ARGS(work)
1042 );
1043 
1044 DEFINE_EVENT(btrfs__work, btrfs_work_sched,
1045 
1046 	TP_PROTO(struct btrfs_work *work),
1047 
1048 	TP_ARGS(work)
1049 );
1050 
1051 DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
1052 
1053 	TP_PROTO(struct btrfs_work *work),
1054 
1055 	TP_ARGS(work)
1056 );
1057 
1058 DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
1059 
1060 	TP_PROTO(struct btrfs_work *work),
1061 
1062 	TP_ARGS(work)
1063 );
1064 
1065 DECLARE_EVENT_CLASS(btrfs__workqueue,
1066 
1067 	TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
1068 
1069 	TP_ARGS(wq, name, high),
1070 
1071 	TP_STRUCT__entry(
1072 		__field(	void *,	wq			)
1073 		__string(	name,	name			)
1074 		__field(	int ,	high			)
1075 	),
1076 
1077 	TP_fast_assign(
1078 		__entry->wq		= wq;
1079 		__assign_str(name, name);
1080 		__entry->high		= high;
1081 	),
1082 
1083 	TP_printk("name=%s%s, wq=%p", __get_str(name),
1084 		  __print_flags(__entry->high, "",
1085 				{(WQ_HIGHPRI),	"-high"}),
1086 		  __entry->wq)
1087 );
1088 
1089 DEFINE_EVENT(btrfs__workqueue, btrfs_workqueue_alloc,
1090 
1091 	TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
1092 
1093 	TP_ARGS(wq, name, high)
1094 );
1095 
1096 DECLARE_EVENT_CLASS(btrfs__workqueue_done,
1097 
1098 	TP_PROTO(struct __btrfs_workqueue *wq),
1099 
1100 	TP_ARGS(wq),
1101 
1102 	TP_STRUCT__entry(
1103 		__field(	void *,	wq			)
1104 	),
1105 
1106 	TP_fast_assign(
1107 		__entry->wq		= wq;
1108 	),
1109 
1110 	TP_printk("wq=%p", __entry->wq)
1111 );
1112 
1113 DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
1114 
1115 	TP_PROTO(struct __btrfs_workqueue *wq),
1116 
1117 	TP_ARGS(wq)
1118 );
1119 
1120 #endif /* _TRACE_BTRFS_H */
1121 
1122 /* This part must be outside protection */
1123 #include <trace/define_trace.h>
1124