xref: /openbmc/linux/include/trace/events/btrfs.h (revision 29c37341)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM btrfs
4 
5 #if !defined(_TRACE_BTRFS_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_BTRFS_H
7 
8 #include <linux/writeback.h>
9 #include <linux/tracepoint.h>
10 #include <trace/events/mmflags.h>
11 
12 struct btrfs_root;
13 struct btrfs_fs_info;
14 struct btrfs_inode;
15 struct extent_map;
16 struct btrfs_file_extent_item;
17 struct btrfs_ordered_extent;
18 struct btrfs_delayed_ref_node;
19 struct btrfs_delayed_tree_ref;
20 struct btrfs_delayed_data_ref;
21 struct btrfs_delayed_ref_head;
22 struct btrfs_block_group;
23 struct btrfs_free_cluster;
24 struct map_lookup;
25 struct extent_buffer;
26 struct btrfs_work;
27 struct __btrfs_workqueue;
28 struct btrfs_qgroup_extent_record;
29 struct btrfs_qgroup;
30 struct extent_io_tree;
31 struct prelim_ref;
32 struct btrfs_space_info;
33 
34 #define show_ref_type(type)						\
35 	__print_symbolic(type,						\
36 		{ BTRFS_TREE_BLOCK_REF_KEY, 	"TREE_BLOCK_REF" },	\
37 		{ BTRFS_EXTENT_DATA_REF_KEY, 	"EXTENT_DATA_REF" },	\
38 		{ BTRFS_EXTENT_REF_V0_KEY, 	"EXTENT_REF_V0" },	\
39 		{ BTRFS_SHARED_BLOCK_REF_KEY, 	"SHARED_BLOCK_REF" },	\
40 		{ BTRFS_SHARED_DATA_REF_KEY, 	"SHARED_DATA_REF" })
41 
42 #define __show_root_type(obj)						\
43 	__print_symbolic_u64(obj,					\
44 		{ BTRFS_ROOT_TREE_OBJECTID, 	"ROOT_TREE"	},	\
45 		{ BTRFS_EXTENT_TREE_OBJECTID, 	"EXTENT_TREE"	},	\
46 		{ BTRFS_CHUNK_TREE_OBJECTID, 	"CHUNK_TREE"	},	\
47 		{ BTRFS_DEV_TREE_OBJECTID, 	"DEV_TREE"	},	\
48 		{ BTRFS_FS_TREE_OBJECTID, 	"FS_TREE"	},	\
49 		{ BTRFS_ROOT_TREE_DIR_OBJECTID, "ROOT_TREE_DIR"	},	\
50 		{ BTRFS_CSUM_TREE_OBJECTID, 	"CSUM_TREE"	},	\
51 		{ BTRFS_TREE_LOG_OBJECTID,	"TREE_LOG"	},	\
52 		{ BTRFS_QUOTA_TREE_OBJECTID,	"QUOTA_TREE"	},	\
53 		{ BTRFS_TREE_RELOC_OBJECTID,	"TREE_RELOC"	},	\
54 		{ BTRFS_UUID_TREE_OBJECTID,	"UUID_TREE"	},	\
55 		{ BTRFS_FREE_SPACE_TREE_OBJECTID, "FREE_SPACE_TREE" },	\
56 		{ BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" })
57 
58 #define show_root_type(obj)						\
59 	obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) ||		\
60 	      (obj >= BTRFS_ROOT_TREE_OBJECTID &&			\
61 	       obj <= BTRFS_QUOTA_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
62 
63 #define FLUSH_ACTIONS								\
64 	EM( BTRFS_RESERVE_NO_FLUSH,		"BTRFS_RESERVE_NO_FLUSH")	\
65 	EM( BTRFS_RESERVE_FLUSH_LIMIT,		"BTRFS_RESERVE_FLUSH_LIMIT")	\
66 	EM( BTRFS_RESERVE_FLUSH_ALL,		"BTRFS_RESERVE_FLUSH_ALL")	\
67 	EMe(BTRFS_RESERVE_FLUSH_ALL_STEAL,	"BTRFS_RESERVE_FLUSH_ALL_STEAL")
68 
69 #define FI_TYPES							\
70 	EM( BTRFS_FILE_EXTENT_INLINE,		"INLINE")		\
71 	EM( BTRFS_FILE_EXTENT_REG,		"REG")			\
72 	EMe(BTRFS_FILE_EXTENT_PREALLOC,		"PREALLOC")
73 
74 #define QGROUP_RSV_TYPES						\
75 	EM( BTRFS_QGROUP_RSV_DATA,		"DATA")			\
76 	EM( BTRFS_QGROUP_RSV_META_PERTRANS,	"META_PERTRANS")	\
77 	EMe(BTRFS_QGROUP_RSV_META_PREALLOC,	"META_PREALLOC")
78 
79 #define IO_TREE_OWNER						    \
80 	EM( IO_TREE_FS_PINNED_EXTENTS, 	  "PINNED_EXTENTS")	    \
81 	EM( IO_TREE_FS_EXCLUDED_EXTENTS,  "EXCLUDED_EXTENTS")	    \
82 	EM( IO_TREE_INODE_IO,		  "INODE_IO")		    \
83 	EM( IO_TREE_INODE_IO_FAILURE,	  "INODE_IO_FAILURE")	    \
84 	EM( IO_TREE_RELOC_BLOCKS,	  "RELOC_BLOCKS")	    \
85 	EM( IO_TREE_TRANS_DIRTY_PAGES,	  "TRANS_DIRTY_PAGES")      \
86 	EM( IO_TREE_ROOT_DIRTY_LOG_PAGES, "ROOT_DIRTY_LOG_PAGES")   \
87 	EM( IO_TREE_INODE_FILE_EXTENT,	  "INODE_FILE_EXTENT")      \
88 	EM( IO_TREE_LOG_CSUM_RANGE,	  "LOG_CSUM_RANGE")         \
89 	EMe(IO_TREE_SELFTEST,		  "SELFTEST")
90 
91 #define FLUSH_STATES							\
92 	EM( FLUSH_DELAYED_ITEMS_NR,	"FLUSH_DELAYED_ITEMS_NR")	\
93 	EM( FLUSH_DELAYED_ITEMS,	"FLUSH_DELAYED_ITEMS")		\
94 	EM( FLUSH_DELALLOC,		"FLUSH_DELALLOC")		\
95 	EM( FLUSH_DELALLOC_WAIT,	"FLUSH_DELALLOC_WAIT")		\
96 	EM( FLUSH_DELAYED_REFS_NR,	"FLUSH_DELAYED_REFS_NR")	\
97 	EM( FLUSH_DELAYED_REFS,		"FLUSH_ELAYED_REFS")		\
98 	EM( ALLOC_CHUNK,		"ALLOC_CHUNK")			\
99 	EM( ALLOC_CHUNK_FORCE,		"ALLOC_CHUNK_FORCE")		\
100 	EM( RUN_DELAYED_IPUTS,		"RUN_DELAYED_IPUTS")		\
101 	EMe(COMMIT_TRANS,		"COMMIT_TRANS")
102 
103 /*
104  * First define the enums in the above macros to be exported to userspace via
105  * TRACE_DEFINE_ENUM().
106  */
107 
108 #undef EM
109 #undef EMe
110 #define EM(a, b)	TRACE_DEFINE_ENUM(a);
111 #define EMe(a, b)	TRACE_DEFINE_ENUM(a);
112 
113 FLUSH_ACTIONS
114 FI_TYPES
115 QGROUP_RSV_TYPES
116 IO_TREE_OWNER
117 FLUSH_STATES
118 
119 /*
120  * Now redefine the EM and EMe macros to map the enums to the strings that will
121  * be printed in the output
122  */
123 
124 #undef EM
125 #undef EMe
126 #define EM(a, b)        {a, b},
127 #define EMe(a, b)       {a, b}
128 
129 
130 #define BTRFS_GROUP_FLAGS	\
131 	{ BTRFS_BLOCK_GROUP_DATA,	"DATA"},	\
132 	{ BTRFS_BLOCK_GROUP_SYSTEM,	"SYSTEM"},	\
133 	{ BTRFS_BLOCK_GROUP_METADATA,	"METADATA"},	\
134 	{ BTRFS_BLOCK_GROUP_RAID0,	"RAID0"}, 	\
135 	{ BTRFS_BLOCK_GROUP_RAID1,	"RAID1"}, 	\
136 	{ BTRFS_BLOCK_GROUP_DUP,	"DUP"}, 	\
137 	{ BTRFS_BLOCK_GROUP_RAID10,	"RAID10"}, 	\
138 	{ BTRFS_BLOCK_GROUP_RAID5,	"RAID5"},	\
139 	{ BTRFS_BLOCK_GROUP_RAID6,	"RAID6"}
140 
141 #define EXTENT_FLAGS						\
142 	{ EXTENT_DIRTY,			"DIRTY"},		\
143 	{ EXTENT_UPTODATE,		"UPTODATE"},		\
144 	{ EXTENT_LOCKED,		"LOCKED"},		\
145 	{ EXTENT_NEW,			"NEW"},			\
146 	{ EXTENT_DELALLOC,		"DELALLOC"},		\
147 	{ EXTENT_DEFRAG,		"DEFRAG"},		\
148 	{ EXTENT_BOUNDARY,		"BOUNDARY"},		\
149 	{ EXTENT_NODATASUM,		"NODATASUM"},		\
150 	{ EXTENT_CLEAR_META_RESV,	"CLEAR_META_RESV"},	\
151 	{ EXTENT_NEED_WAIT,		"NEED_WAIT"},		\
152 	{ EXTENT_DAMAGED,		"DAMAGED"},		\
153 	{ EXTENT_NORESERVE,		"NORESERVE"},		\
154 	{ EXTENT_QGROUP_RESERVED,	"QGROUP_RESERVED"},	\
155 	{ EXTENT_CLEAR_DATA_RESV,	"CLEAR_DATA_RESV"},	\
156 	{ EXTENT_DELALLOC_NEW,		"DELALLOC_NEW"}
157 
158 #define BTRFS_FSID_SIZE 16
159 #define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_FSID_SIZE)
160 
161 #define TP_fast_assign_fsid(fs_info)					\
162 ({									\
163 	if (fs_info)							\
164 		memcpy(__entry->fsid, fs_info->fs_devices->fsid,	\
165 		       BTRFS_FSID_SIZE);				\
166 	else								\
167 		memset(__entry->fsid, 0, BTRFS_FSID_SIZE);		\
168 })
169 
170 #define TP_STRUCT__entry_btrfs(args...)					\
171 	TP_STRUCT__entry(						\
172 		TP_STRUCT__entry_fsid					\
173 		args)
174 #define TP_fast_assign_btrfs(fs_info, args...)				\
175 	TP_fast_assign(							\
176 		TP_fast_assign_fsid(fs_info);				\
177 		args)
178 #define TP_printk_btrfs(fmt, args...) \
179 	TP_printk("%pU: " fmt, __entry->fsid, args)
180 
181 TRACE_EVENT(btrfs_transaction_commit,
182 
183 	TP_PROTO(const struct btrfs_root *root),
184 
185 	TP_ARGS(root),
186 
187 	TP_STRUCT__entry_btrfs(
188 		__field(	u64,  generation		)
189 		__field(	u64,  root_objectid		)
190 	),
191 
192 	TP_fast_assign_btrfs(root->fs_info,
193 		__entry->generation	= root->fs_info->generation;
194 		__entry->root_objectid	= root->root_key.objectid;
195 	),
196 
197 	TP_printk_btrfs("root=%llu(%s) gen=%llu",
198 		  show_root_type(__entry->root_objectid),
199 		  __entry->generation)
200 );
201 
202 DECLARE_EVENT_CLASS(btrfs__inode,
203 
204 	TP_PROTO(const struct inode *inode),
205 
206 	TP_ARGS(inode),
207 
208 	TP_STRUCT__entry_btrfs(
209 		__field(	u64,  ino			)
210 		__field(	u64,  blocks			)
211 		__field(	u64,  disk_i_size		)
212 		__field(	u64,  generation		)
213 		__field(	u64,  last_trans		)
214 		__field(	u64,  logged_trans		)
215 		__field(	u64,  root_objectid		)
216 	),
217 
218 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
219 		__entry->ino	= btrfs_ino(BTRFS_I(inode));
220 		__entry->blocks	= inode->i_blocks;
221 		__entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
222 		__entry->generation = BTRFS_I(inode)->generation;
223 		__entry->last_trans = BTRFS_I(inode)->last_trans;
224 		__entry->logged_trans = BTRFS_I(inode)->logged_trans;
225 		__entry->root_objectid =
226 				BTRFS_I(inode)->root->root_key.objectid;
227 	),
228 
229 	TP_printk_btrfs("root=%llu(%s) gen=%llu ino=%llu blocks=%llu "
230 		  "disk_i_size=%llu last_trans=%llu logged_trans=%llu",
231 		  show_root_type(__entry->root_objectid),
232 		  __entry->generation,
233 		  __entry->ino,
234 		  __entry->blocks,
235 		  __entry->disk_i_size,
236 		  __entry->last_trans,
237 		  __entry->logged_trans)
238 );
239 
240 DEFINE_EVENT(btrfs__inode, btrfs_inode_new,
241 
242 	TP_PROTO(const struct inode *inode),
243 
244 	TP_ARGS(inode)
245 );
246 
247 DEFINE_EVENT(btrfs__inode, btrfs_inode_request,
248 
249 	TP_PROTO(const struct inode *inode),
250 
251 	TP_ARGS(inode)
252 );
253 
254 DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
255 
256 	TP_PROTO(const struct inode *inode),
257 
258 	TP_ARGS(inode)
259 );
260 
261 #define __show_map_type(type)						\
262 	__print_symbolic_u64(type,					\
263 		{ EXTENT_MAP_LAST_BYTE, "LAST_BYTE" 	},		\
264 		{ EXTENT_MAP_HOLE, 	"HOLE" 		},		\
265 		{ EXTENT_MAP_INLINE, 	"INLINE" 	},		\
266 		{ EXTENT_MAP_DELALLOC,	"DELALLOC" 	})
267 
268 #define show_map_type(type)			\
269 	type, (type >= EXTENT_MAP_LAST_BYTE) ? "-" :  __show_map_type(type)
270 
271 #define show_map_flags(flag)						\
272 	__print_flags(flag, "|",					\
273 		{ (1 << EXTENT_FLAG_PINNED), 		"PINNED" 	},\
274 		{ (1 << EXTENT_FLAG_COMPRESSED), 	"COMPRESSED" 	},\
275 		{ (1 << EXTENT_FLAG_PREALLOC), 		"PREALLOC" 	},\
276 		{ (1 << EXTENT_FLAG_LOGGING),	 	"LOGGING" 	},\
277 		{ (1 << EXTENT_FLAG_FILLING),	 	"FILLING" 	},\
278 		{ (1 << EXTENT_FLAG_FS_MAPPING),	"FS_MAPPING"	})
279 
280 TRACE_EVENT_CONDITION(btrfs_get_extent,
281 
282 	TP_PROTO(const struct btrfs_root *root, const struct btrfs_inode *inode,
283 		 const struct extent_map *map),
284 
285 	TP_ARGS(root, inode, map),
286 
287 	TP_CONDITION(map),
288 
289 	TP_STRUCT__entry_btrfs(
290 		__field(	u64,  root_objectid	)
291 		__field(	u64,  ino		)
292 		__field(	u64,  start		)
293 		__field(	u64,  len		)
294 		__field(	u64,  orig_start	)
295 		__field(	u64,  block_start	)
296 		__field(	u64,  block_len		)
297 		__field(	unsigned long,  flags	)
298 		__field(	int,  refs		)
299 		__field(	unsigned int,  compress_type	)
300 	),
301 
302 	TP_fast_assign_btrfs(root->fs_info,
303 		__entry->root_objectid	= root->root_key.objectid;
304 		__entry->ino		= btrfs_ino(inode);
305 		__entry->start		= map->start;
306 		__entry->len		= map->len;
307 		__entry->orig_start	= map->orig_start;
308 		__entry->block_start	= map->block_start;
309 		__entry->block_len	= map->block_len;
310 		__entry->flags		= map->flags;
311 		__entry->refs		= refcount_read(&map->refs);
312 		__entry->compress_type	= map->compress_type;
313 	),
314 
315 	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu "
316 		  "orig_start=%llu block_start=%llu(%s) "
317 		  "block_len=%llu flags=%s refs=%u "
318 		  "compress_type=%u",
319 		  show_root_type(__entry->root_objectid),
320 		  __entry->ino,
321 		  __entry->start,
322 		  __entry->len,
323 		  __entry->orig_start,
324 		  show_map_type(__entry->block_start),
325 		  __entry->block_len,
326 		  show_map_flags(__entry->flags),
327 		  __entry->refs, __entry->compress_type)
328 );
329 
330 TRACE_EVENT(btrfs_handle_em_exist,
331 
332 	TP_PROTO(const struct btrfs_fs_info *fs_info,
333 		const struct extent_map *existing, const struct extent_map *map,
334 		u64 start, u64 len),
335 
336 	TP_ARGS(fs_info, existing, map, start, len),
337 
338 	TP_STRUCT__entry_btrfs(
339 		__field(	u64,  e_start		)
340 		__field(	u64,  e_len		)
341 		__field(	u64,  map_start		)
342 		__field(	u64,  map_len		)
343 		__field(	u64,  start		)
344 		__field(	u64,  len		)
345 	),
346 
347 	TP_fast_assign_btrfs(fs_info,
348 		__entry->e_start	= existing->start;
349 		__entry->e_len		= existing->len;
350 		__entry->map_start	= map->start;
351 		__entry->map_len	= map->len;
352 		__entry->start		= start;
353 		__entry->len		= len;
354 	),
355 
356 	TP_printk_btrfs("start=%llu len=%llu "
357 		  "existing(start=%llu len=%llu) "
358 		  "em(start=%llu len=%llu)",
359 		  __entry->start,
360 		  __entry->len,
361 		  __entry->e_start,
362 		  __entry->e_len,
363 		  __entry->map_start,
364 		  __entry->map_len)
365 );
366 
367 /* file extent item */
368 DECLARE_EVENT_CLASS(btrfs__file_extent_item_regular,
369 
370 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
371 		 const struct btrfs_file_extent_item *fi, u64 start),
372 
373 	TP_ARGS(bi, l, fi, start),
374 
375 	TP_STRUCT__entry_btrfs(
376 		__field(	u64,	root_obj	)
377 		__field(	u64,	ino		)
378 		__field(	loff_t,	isize		)
379 		__field(	u64,	disk_isize	)
380 		__field(	u64,	num_bytes	)
381 		__field(	u64,	ram_bytes	)
382 		__field(	u64,	disk_bytenr	)
383 		__field(	u64,	disk_num_bytes	)
384 		__field(	u64,	extent_offset	)
385 		__field(	u8,	extent_type	)
386 		__field(	u8,	compression	)
387 		__field(	u64,	extent_start	)
388 		__field(	u64,	extent_end	)
389 	),
390 
391 	TP_fast_assign_btrfs(bi->root->fs_info,
392 		__entry->root_obj	= bi->root->root_key.objectid;
393 		__entry->ino		= btrfs_ino(bi);
394 		__entry->isize		= bi->vfs_inode.i_size;
395 		__entry->disk_isize	= bi->disk_i_size;
396 		__entry->num_bytes	= btrfs_file_extent_num_bytes(l, fi);
397 		__entry->ram_bytes	= btrfs_file_extent_ram_bytes(l, fi);
398 		__entry->disk_bytenr	= btrfs_file_extent_disk_bytenr(l, fi);
399 		__entry->disk_num_bytes	= btrfs_file_extent_disk_num_bytes(l, fi);
400 		__entry->extent_offset	= btrfs_file_extent_offset(l, fi);
401 		__entry->extent_type	= btrfs_file_extent_type(l, fi);
402 		__entry->compression	= btrfs_file_extent_compression(l, fi);
403 		__entry->extent_start	= start;
404 		__entry->extent_end	= (start + __entry->num_bytes);
405 	),
406 
407 	TP_printk_btrfs(
408 		"root=%llu(%s) inode=%llu size=%llu disk_isize=%llu "
409 		"file extent range=[%llu %llu] "
410 		"(num_bytes=%llu ram_bytes=%llu disk_bytenr=%llu "
411 		"disk_num_bytes=%llu extent_offset=%llu type=%s "
412 		"compression=%u",
413 		show_root_type(__entry->root_obj), __entry->ino,
414 		__entry->isize,
415 		__entry->disk_isize, __entry->extent_start,
416 		__entry->extent_end, __entry->num_bytes, __entry->ram_bytes,
417 		__entry->disk_bytenr, __entry->disk_num_bytes,
418 		__entry->extent_offset, __print_symbolic(__entry->extent_type, FI_TYPES),
419 		__entry->compression)
420 );
421 
422 DECLARE_EVENT_CLASS(
423 	btrfs__file_extent_item_inline,
424 
425 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
426 		 const struct btrfs_file_extent_item *fi, int slot, u64 start),
427 
428 	TP_ARGS(bi, l, fi, slot,  start),
429 
430 	TP_STRUCT__entry_btrfs(
431 		__field(	u64,	root_obj	)
432 		__field(	u64,	ino		)
433 		__field(	loff_t,	isize		)
434 		__field(	u64,	disk_isize	)
435 		__field(	u8,	extent_type	)
436 		__field(	u8,	compression	)
437 		__field(	u64,	extent_start	)
438 		__field(	u64,	extent_end	)
439 	),
440 
441 	TP_fast_assign_btrfs(
442 		bi->root->fs_info,
443 		__entry->root_obj	= bi->root->root_key.objectid;
444 		__entry->ino		= btrfs_ino(bi);
445 		__entry->isize		= bi->vfs_inode.i_size;
446 		__entry->disk_isize	= bi->disk_i_size;
447 		__entry->extent_type	= btrfs_file_extent_type(l, fi);
448 		__entry->compression	= btrfs_file_extent_compression(l, fi);
449 		__entry->extent_start	= start;
450 		__entry->extent_end	= (start + btrfs_file_extent_ram_bytes(l, fi));
451 	),
452 
453 	TP_printk_btrfs(
454 		"root=%llu(%s) inode=%llu size=%llu disk_isize=%llu "
455 		"file extent range=[%llu %llu] "
456 		"extent_type=%s compression=%u",
457 		show_root_type(__entry->root_obj), __entry->ino, __entry->isize,
458 		__entry->disk_isize, __entry->extent_start,
459 		__entry->extent_end, __print_symbolic(__entry->extent_type, FI_TYPES),
460 		__entry->compression)
461 );
462 
463 DEFINE_EVENT(
464 	btrfs__file_extent_item_regular, btrfs_get_extent_show_fi_regular,
465 
466 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
467 		 const struct btrfs_file_extent_item *fi, u64 start),
468 
469 	TP_ARGS(bi, l, fi, start)
470 );
471 
472 DEFINE_EVENT(
473 	btrfs__file_extent_item_regular, btrfs_truncate_show_fi_regular,
474 
475 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
476 		 const struct btrfs_file_extent_item *fi, u64 start),
477 
478 	TP_ARGS(bi, l, fi, start)
479 );
480 
481 DEFINE_EVENT(
482 	btrfs__file_extent_item_inline, btrfs_get_extent_show_fi_inline,
483 
484 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
485 		 const struct btrfs_file_extent_item *fi, int slot, u64 start),
486 
487 	TP_ARGS(bi, l, fi, slot, start)
488 );
489 
490 DEFINE_EVENT(
491 	btrfs__file_extent_item_inline, btrfs_truncate_show_fi_inline,
492 
493 	TP_PROTO(const struct btrfs_inode *bi, const struct extent_buffer *l,
494 		 const struct btrfs_file_extent_item *fi, int slot, u64 start),
495 
496 	TP_ARGS(bi, l, fi, slot, start)
497 );
498 
499 #define show_ordered_flags(flags)					   \
500 	__print_flags(flags, "|",					   \
501 		{ (1 << BTRFS_ORDERED_IO_DONE), 	"IO_DONE" 	}, \
502 		{ (1 << BTRFS_ORDERED_COMPLETE), 	"COMPLETE" 	}, \
503 		{ (1 << BTRFS_ORDERED_NOCOW), 		"NOCOW" 	}, \
504 		{ (1 << BTRFS_ORDERED_COMPRESSED), 	"COMPRESSED" 	}, \
505 		{ (1 << BTRFS_ORDERED_PREALLOC), 	"PREALLOC" 	}, \
506 		{ (1 << BTRFS_ORDERED_DIRECT),	 	"DIRECT" 	}, \
507 		{ (1 << BTRFS_ORDERED_IOERR), 		"IOERR" 	}, \
508 		{ (1 << BTRFS_ORDERED_TRUNCATED), 	"TRUNCATED"	})
509 
510 
511 DECLARE_EVENT_CLASS(btrfs__ordered_extent,
512 
513 	TP_PROTO(const struct inode *inode,
514 		 const struct btrfs_ordered_extent *ordered),
515 
516 	TP_ARGS(inode, ordered),
517 
518 	TP_STRUCT__entry_btrfs(
519 		__field(	u64,  ino		)
520 		__field(	u64,  file_offset	)
521 		__field(	u64,  start		)
522 		__field(	u64,  len		)
523 		__field(	u64,  disk_len		)
524 		__field(	u64,  bytes_left	)
525 		__field(	unsigned long,  flags	)
526 		__field(	int,  compress_type	)
527 		__field(	int,  refs		)
528 		__field(	u64,  root_objectid	)
529 		__field(	u64,  truncated_len	)
530 	),
531 
532 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
533 		__entry->ino 		= btrfs_ino(BTRFS_I(inode));
534 		__entry->file_offset	= ordered->file_offset;
535 		__entry->start		= ordered->disk_bytenr;
536 		__entry->len		= ordered->num_bytes;
537 		__entry->disk_len	= ordered->disk_num_bytes;
538 		__entry->bytes_left	= ordered->bytes_left;
539 		__entry->flags		= ordered->flags;
540 		__entry->compress_type	= ordered->compress_type;
541 		__entry->refs		= refcount_read(&ordered->refs);
542 		__entry->root_objectid	=
543 				BTRFS_I(inode)->root->root_key.objectid;
544 		__entry->truncated_len	= ordered->truncated_len;
545 	),
546 
547 	TP_printk_btrfs("root=%llu(%s) ino=%llu file_offset=%llu "
548 		  "start=%llu len=%llu disk_len=%llu "
549 		  "truncated_len=%llu "
550 		  "bytes_left=%llu flags=%s compress_type=%d "
551 		  "refs=%d",
552 		  show_root_type(__entry->root_objectid),
553 		  __entry->ino,
554 		  __entry->file_offset,
555 		  __entry->start,
556 		  __entry->len,
557 		  __entry->disk_len,
558 		  __entry->truncated_len,
559 		  __entry->bytes_left,
560 		  show_ordered_flags(__entry->flags),
561 		  __entry->compress_type, __entry->refs)
562 );
563 
564 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_add,
565 
566 	TP_PROTO(const struct inode *inode,
567 		 const struct btrfs_ordered_extent *ordered),
568 
569 	TP_ARGS(inode, ordered)
570 );
571 
572 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_remove,
573 
574 	TP_PROTO(const struct inode *inode,
575 		 const struct btrfs_ordered_extent *ordered),
576 
577 	TP_ARGS(inode, ordered)
578 );
579 
580 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_start,
581 
582 	TP_PROTO(const struct inode *inode,
583 		 const struct btrfs_ordered_extent *ordered),
584 
585 	TP_ARGS(inode, ordered)
586 );
587 
588 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_put,
589 
590 	TP_PROTO(const struct inode *inode,
591 		 const struct btrfs_ordered_extent *ordered),
592 
593 	TP_ARGS(inode, ordered)
594 );
595 
596 DECLARE_EVENT_CLASS(btrfs__writepage,
597 
598 	TP_PROTO(const struct page *page, const struct inode *inode,
599 		 const struct writeback_control *wbc),
600 
601 	TP_ARGS(page, inode, wbc),
602 
603 	TP_STRUCT__entry_btrfs(
604 		__field(	u64,	ino			)
605 		__field(	pgoff_t,  index			)
606 		__field(	long,   nr_to_write		)
607 		__field(	long,   pages_skipped		)
608 		__field(	loff_t, range_start		)
609 		__field(	loff_t, range_end		)
610 		__field(	char,   for_kupdate		)
611 		__field(	char,   for_reclaim		)
612 		__field(	char,   range_cyclic		)
613 		__field(	unsigned long,  writeback_index	)
614 		__field(	u64,    root_objectid		)
615 	),
616 
617 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
618 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
619 		__entry->index		= page->index;
620 		__entry->nr_to_write	= wbc->nr_to_write;
621 		__entry->pages_skipped	= wbc->pages_skipped;
622 		__entry->range_start	= wbc->range_start;
623 		__entry->range_end	= wbc->range_end;
624 		__entry->for_kupdate	= wbc->for_kupdate;
625 		__entry->for_reclaim	= wbc->for_reclaim;
626 		__entry->range_cyclic	= wbc->range_cyclic;
627 		__entry->writeback_index = inode->i_mapping->writeback_index;
628 		__entry->root_objectid	=
629 				 BTRFS_I(inode)->root->root_key.objectid;
630 	),
631 
632 	TP_printk_btrfs("root=%llu(%s) ino=%llu page_index=%lu "
633 		  "nr_to_write=%ld pages_skipped=%ld range_start=%llu "
634 		  "range_end=%llu for_kupdate=%d "
635 		  "for_reclaim=%d range_cyclic=%d writeback_index=%lu",
636 		  show_root_type(__entry->root_objectid),
637 		  __entry->ino, __entry->index,
638 		  __entry->nr_to_write, __entry->pages_skipped,
639 		  __entry->range_start, __entry->range_end,
640 		  __entry->for_kupdate,
641 		  __entry->for_reclaim, __entry->range_cyclic,
642 		  __entry->writeback_index)
643 );
644 
645 DEFINE_EVENT(btrfs__writepage, __extent_writepage,
646 
647 	TP_PROTO(const struct page *page, const struct inode *inode,
648 		 const struct writeback_control *wbc),
649 
650 	TP_ARGS(page, inode, wbc)
651 );
652 
653 TRACE_EVENT(btrfs_writepage_end_io_hook,
654 
655 	TP_PROTO(const struct page *page, u64 start, u64 end, int uptodate),
656 
657 	TP_ARGS(page, start, end, uptodate),
658 
659 	TP_STRUCT__entry_btrfs(
660 		__field(	u64,	 ino		)
661 		__field(	unsigned long, index	)
662 		__field(	u64,	 start		)
663 		__field(	u64,	 end		)
664 		__field(	int,	 uptodate	)
665 		__field(	u64,    root_objectid	)
666 	),
667 
668 	TP_fast_assign_btrfs(btrfs_sb(page->mapping->host->i_sb),
669 		__entry->ino	= btrfs_ino(BTRFS_I(page->mapping->host));
670 		__entry->index	= page->index;
671 		__entry->start	= start;
672 		__entry->end	= end;
673 		__entry->uptodate = uptodate;
674 		__entry->root_objectid	=
675 			 BTRFS_I(page->mapping->host)->root->root_key.objectid;
676 	),
677 
678 	TP_printk_btrfs("root=%llu(%s) ino=%llu page_index=%lu start=%llu "
679 		  "end=%llu uptodate=%d",
680 		  show_root_type(__entry->root_objectid),
681 		  __entry->ino, __entry->index,
682 		  __entry->start,
683 		  __entry->end, __entry->uptodate)
684 );
685 
686 TRACE_EVENT(btrfs_sync_file,
687 
688 	TP_PROTO(const struct file *file, int datasync),
689 
690 	TP_ARGS(file, datasync),
691 
692 	TP_STRUCT__entry_btrfs(
693 		__field(	u64,	ino		)
694 		__field(	u64,	parent		)
695 		__field(	int,    datasync	)
696 		__field(	u64,    root_objectid	)
697 	),
698 
699 	TP_fast_assign(
700 		const struct dentry *dentry = file->f_path.dentry;
701 		const struct inode *inode = d_inode(dentry);
702 
703 		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
704 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
705 		__entry->parent		= btrfs_ino(BTRFS_I(d_inode(dentry->d_parent)));
706 		__entry->datasync	= datasync;
707 		__entry->root_objectid	=
708 				 BTRFS_I(inode)->root->root_key.objectid;
709 	),
710 
711 	TP_printk_btrfs("root=%llu(%s) ino=%llu parent=%llu datasync=%d",
712 		  show_root_type(__entry->root_objectid),
713 		  __entry->ino,
714 		  __entry->parent,
715 		  __entry->datasync)
716 );
717 
718 TRACE_EVENT(btrfs_sync_fs,
719 
720 	TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),
721 
722 	TP_ARGS(fs_info, wait),
723 
724 	TP_STRUCT__entry_btrfs(
725 		__field(	int,  wait		)
726 	),
727 
728 	TP_fast_assign_btrfs(fs_info,
729 		__entry->wait	= wait;
730 	),
731 
732 	TP_printk_btrfs("wait=%d", __entry->wait)
733 );
734 
735 TRACE_EVENT(btrfs_add_block_group,
736 
737 	TP_PROTO(const struct btrfs_fs_info *fs_info,
738 		 const struct btrfs_block_group *block_group, int create),
739 
740 	TP_ARGS(fs_info, block_group, create),
741 
742 	TP_STRUCT__entry_btrfs(
743 		__field(	u64,	offset			)
744 		__field(	u64,	size			)
745 		__field(	u64,	flags			)
746 		__field(	u64,	bytes_used		)
747 		__field(	u64,	bytes_super		)
748 		__field(	int,	create			)
749 	),
750 
751 	TP_fast_assign_btrfs(fs_info,
752 		__entry->offset		= block_group->start;
753 		__entry->size		= block_group->length;
754 		__entry->flags		= block_group->flags;
755 		__entry->bytes_used	= block_group->used;
756 		__entry->bytes_super	= block_group->bytes_super;
757 		__entry->create		= create;
758 	),
759 
760 	TP_printk_btrfs("block_group offset=%llu size=%llu "
761 		  "flags=%llu(%s) bytes_used=%llu bytes_super=%llu "
762 		  "create=%d",
763 		  __entry->offset,
764 		  __entry->size,
765 		  __entry->flags,
766 		  __print_flags((unsigned long)__entry->flags, "|",
767 				BTRFS_GROUP_FLAGS),
768 		  __entry->bytes_used,
769 		  __entry->bytes_super, __entry->create)
770 );
771 
772 #define show_ref_action(action)						\
773 	__print_symbolic(action,					\
774 		{ BTRFS_ADD_DELAYED_REF,    "ADD_DELAYED_REF" },	\
775 		{ BTRFS_DROP_DELAYED_REF,   "DROP_DELAYED_REF" },	\
776 		{ BTRFS_ADD_DELAYED_EXTENT, "ADD_DELAYED_EXTENT" }, 	\
777 		{ BTRFS_UPDATE_DELAYED_HEAD, "UPDATE_DELAYED_HEAD" })
778 
779 
780 DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
781 
782 	TP_PROTO(const struct btrfs_fs_info *fs_info,
783 		 const struct btrfs_delayed_ref_node *ref,
784 		 const struct btrfs_delayed_tree_ref *full_ref,
785 		 int action),
786 
787 	TP_ARGS(fs_info, ref, full_ref, action),
788 
789 	TP_STRUCT__entry_btrfs(
790 		__field(	u64,  bytenr		)
791 		__field(	u64,  num_bytes		)
792 		__field(	int,  action		)
793 		__field(	u64,  parent		)
794 		__field(	u64,  ref_root		)
795 		__field(	int,  level		)
796 		__field(	int,  type		)
797 		__field(	u64,  seq		)
798 	),
799 
800 	TP_fast_assign_btrfs(fs_info,
801 		__entry->bytenr		= ref->bytenr;
802 		__entry->num_bytes	= ref->num_bytes;
803 		__entry->action		= action;
804 		__entry->parent		= full_ref->parent;
805 		__entry->ref_root	= full_ref->root;
806 		__entry->level		= full_ref->level;
807 		__entry->type		= ref->type;
808 		__entry->seq		= ref->seq;
809 	),
810 
811 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s "
812 		  "parent=%llu(%s) ref_root=%llu(%s) level=%d "
813 		  "type=%s seq=%llu",
814 		  __entry->bytenr,
815 		  __entry->num_bytes,
816 		  show_ref_action(__entry->action),
817 		  show_root_type(__entry->parent),
818 		  show_root_type(__entry->ref_root),
819 		  __entry->level, show_ref_type(__entry->type),
820 		  __entry->seq)
821 );
822 
823 DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
824 
825 	TP_PROTO(const struct btrfs_fs_info *fs_info,
826 		 const struct btrfs_delayed_ref_node *ref,
827 		 const struct btrfs_delayed_tree_ref *full_ref,
828 		 int action),
829 
830 	TP_ARGS(fs_info, ref, full_ref, action)
831 );
832 
833 DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
834 
835 	TP_PROTO(const struct btrfs_fs_info *fs_info,
836 		 const struct btrfs_delayed_ref_node *ref,
837 		 const struct btrfs_delayed_tree_ref *full_ref,
838 		 int action),
839 
840 	TP_ARGS(fs_info, ref, full_ref, action)
841 );
842 
843 DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
844 
845 	TP_PROTO(const struct btrfs_fs_info *fs_info,
846 		 const struct btrfs_delayed_ref_node *ref,
847 		 const struct btrfs_delayed_data_ref *full_ref,
848 		 int action),
849 
850 	TP_ARGS(fs_info, ref, full_ref, action),
851 
852 	TP_STRUCT__entry_btrfs(
853 		__field(	u64,  bytenr		)
854 		__field(	u64,  num_bytes		)
855 		__field(	int,  action		)
856 		__field(	u64,  parent		)
857 		__field(	u64,  ref_root		)
858 		__field(	u64,  owner		)
859 		__field(	u64,  offset		)
860 		__field(	int,  type		)
861 		__field(	u64,  seq		)
862 	),
863 
864 	TP_fast_assign_btrfs(fs_info,
865 		__entry->bytenr		= ref->bytenr;
866 		__entry->num_bytes	= ref->num_bytes;
867 		__entry->action		= action;
868 		__entry->parent		= full_ref->parent;
869 		__entry->ref_root	= full_ref->root;
870 		__entry->owner		= full_ref->objectid;
871 		__entry->offset		= full_ref->offset;
872 		__entry->type		= ref->type;
873 		__entry->seq		= ref->seq;
874 	),
875 
876 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s "
877 		  "parent=%llu(%s) ref_root=%llu(%s) owner=%llu "
878 		  "offset=%llu type=%s seq=%llu",
879 		  __entry->bytenr,
880 		  __entry->num_bytes,
881 		  show_ref_action(__entry->action),
882 		  show_root_type(__entry->parent),
883 		  show_root_type(__entry->ref_root),
884 		  __entry->owner,
885 		  __entry->offset,
886 		  show_ref_type(__entry->type),
887 		  __entry->seq)
888 );
889 
890 DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
891 
892 	TP_PROTO(const struct btrfs_fs_info *fs_info,
893 		 const struct btrfs_delayed_ref_node *ref,
894 		 const struct btrfs_delayed_data_ref *full_ref,
895 		 int action),
896 
897 	TP_ARGS(fs_info, ref, full_ref, action)
898 );
899 
900 DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
901 
902 	TP_PROTO(const struct btrfs_fs_info *fs_info,
903 		 const struct btrfs_delayed_ref_node *ref,
904 		 const struct btrfs_delayed_data_ref *full_ref,
905 		 int action),
906 
907 	TP_ARGS(fs_info, ref, full_ref, action)
908 );
909 
910 DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
911 
912 	TP_PROTO(const struct btrfs_fs_info *fs_info,
913 		 const struct btrfs_delayed_ref_head *head_ref,
914 		 int action),
915 
916 	TP_ARGS(fs_info, head_ref, action),
917 
918 	TP_STRUCT__entry_btrfs(
919 		__field(	u64,  bytenr		)
920 		__field(	u64,  num_bytes		)
921 		__field(	int,  action		)
922 		__field(	int,  is_data		)
923 	),
924 
925 	TP_fast_assign_btrfs(fs_info,
926 		__entry->bytenr		= head_ref->bytenr;
927 		__entry->num_bytes	= head_ref->num_bytes;
928 		__entry->action		= action;
929 		__entry->is_data	= head_ref->is_data;
930 	),
931 
932 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s is_data=%d",
933 		  __entry->bytenr,
934 		  __entry->num_bytes,
935 		  show_ref_action(__entry->action),
936 		  __entry->is_data)
937 );
938 
939 DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
940 
941 	TP_PROTO(const struct btrfs_fs_info *fs_info,
942 		 const struct btrfs_delayed_ref_head *head_ref,
943 		 int action),
944 
945 	TP_ARGS(fs_info, head_ref, action)
946 );
947 
948 DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
949 
950 	TP_PROTO(const struct btrfs_fs_info *fs_info,
951 		 const struct btrfs_delayed_ref_head *head_ref,
952 		 int action),
953 
954 	TP_ARGS(fs_info, head_ref, action)
955 );
956 
957 #define show_chunk_type(type)					\
958 	__print_flags(type, "|",				\
959 		{ BTRFS_BLOCK_GROUP_DATA, 	"DATA"	},	\
960 		{ BTRFS_BLOCK_GROUP_SYSTEM, 	"SYSTEM"},	\
961 		{ BTRFS_BLOCK_GROUP_METADATA, 	"METADATA"},	\
962 		{ BTRFS_BLOCK_GROUP_RAID0, 	"RAID0" },	\
963 		{ BTRFS_BLOCK_GROUP_RAID1, 	"RAID1" },	\
964 		{ BTRFS_BLOCK_GROUP_DUP, 	"DUP"	},	\
965 		{ BTRFS_BLOCK_GROUP_RAID10, 	"RAID10"},	\
966 		{ BTRFS_BLOCK_GROUP_RAID5, 	"RAID5"	},	\
967 		{ BTRFS_BLOCK_GROUP_RAID6, 	"RAID6"	})
968 
969 DECLARE_EVENT_CLASS(btrfs__chunk,
970 
971 	TP_PROTO(const struct btrfs_fs_info *fs_info,
972 		 const struct map_lookup *map, u64 offset, u64 size),
973 
974 	TP_ARGS(fs_info, map, offset, size),
975 
976 	TP_STRUCT__entry_btrfs(
977 		__field(	int,  num_stripes		)
978 		__field(	u64,  type			)
979 		__field(	int,  sub_stripes		)
980 		__field(	u64,  offset			)
981 		__field(	u64,  size			)
982 		__field(	u64,  root_objectid		)
983 	),
984 
985 	TP_fast_assign_btrfs(fs_info,
986 		__entry->num_stripes	= map->num_stripes;
987 		__entry->type		= map->type;
988 		__entry->sub_stripes	= map->sub_stripes;
989 		__entry->offset		= offset;
990 		__entry->size		= size;
991 		__entry->root_objectid	= fs_info->chunk_root->root_key.objectid;
992 	),
993 
994 	TP_printk_btrfs("root=%llu(%s) offset=%llu size=%llu "
995 		  "num_stripes=%d sub_stripes=%d type=%s",
996 		  show_root_type(__entry->root_objectid),
997 		  __entry->offset,
998 		  __entry->size,
999 		  __entry->num_stripes, __entry->sub_stripes,
1000 		  show_chunk_type(__entry->type))
1001 );
1002 
1003 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_alloc,
1004 
1005 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1006 		 const struct map_lookup *map, u64 offset, u64 size),
1007 
1008 	TP_ARGS(fs_info, map, offset, size)
1009 );
1010 
1011 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_free,
1012 
1013 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1014 		 const struct map_lookup *map, u64 offset, u64 size),
1015 
1016 	TP_ARGS(fs_info, map, offset, size)
1017 );
1018 
1019 TRACE_EVENT(btrfs_cow_block,
1020 
1021 	TP_PROTO(const struct btrfs_root *root, const struct extent_buffer *buf,
1022 		 const struct extent_buffer *cow),
1023 
1024 	TP_ARGS(root, buf, cow),
1025 
1026 	TP_STRUCT__entry_btrfs(
1027 		__field(	u64,  root_objectid		)
1028 		__field(	u64,  buf_start			)
1029 		__field(	int,  refs			)
1030 		__field(	u64,  cow_start			)
1031 		__field(	int,  buf_level			)
1032 		__field(	int,  cow_level			)
1033 	),
1034 
1035 	TP_fast_assign_btrfs(root->fs_info,
1036 		__entry->root_objectid	= root->root_key.objectid;
1037 		__entry->buf_start	= buf->start;
1038 		__entry->refs		= atomic_read(&buf->refs);
1039 		__entry->cow_start	= cow->start;
1040 		__entry->buf_level	= btrfs_header_level(buf);
1041 		__entry->cow_level	= btrfs_header_level(cow);
1042 	),
1043 
1044 	TP_printk_btrfs("root=%llu(%s) refs=%d orig_buf=%llu "
1045 		  "(orig_level=%d) cow_buf=%llu (cow_level=%d)",
1046 		  show_root_type(__entry->root_objectid),
1047 		  __entry->refs,
1048 		  __entry->buf_start,
1049 		  __entry->buf_level,
1050 		  __entry->cow_start,
1051 		  __entry->cow_level)
1052 );
1053 
1054 TRACE_EVENT(btrfs_space_reservation,
1055 
1056 	TP_PROTO(const struct btrfs_fs_info *fs_info, const char *type, u64 val,
1057 		 u64 bytes, int reserve),
1058 
1059 	TP_ARGS(fs_info, type, val, bytes, reserve),
1060 
1061 	TP_STRUCT__entry_btrfs(
1062 		__string(	type,	type			)
1063 		__field(	u64,	val			)
1064 		__field(	u64,	bytes			)
1065 		__field(	int,	reserve			)
1066 	),
1067 
1068 	TP_fast_assign_btrfs(fs_info,
1069 		__assign_str(type, type);
1070 		__entry->val		= val;
1071 		__entry->bytes		= bytes;
1072 		__entry->reserve	= reserve;
1073 	),
1074 
1075 	TP_printk_btrfs("%s: %llu %s %llu", __get_str(type), __entry->val,
1076 			__entry->reserve ? "reserve" : "release",
1077 			__entry->bytes)
1078 );
1079 
1080 TRACE_EVENT(btrfs_trigger_flush,
1081 
1082 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 bytes,
1083 		 int flush, const char *reason),
1084 
1085 	TP_ARGS(fs_info, flags, bytes, flush, reason),
1086 
1087 	TP_STRUCT__entry_btrfs(
1088 		__field(	u64,	flags			)
1089 		__field(	u64,	bytes			)
1090 		__field(	int,	flush			)
1091 		__string(	reason,	reason			)
1092 	),
1093 
1094 	TP_fast_assign_btrfs(fs_info,
1095 		__entry->flags	= flags;
1096 		__entry->bytes	= bytes;
1097 		__entry->flush	= flush;
1098 		__assign_str(reason, reason)
1099 	),
1100 
1101 	TP_printk_btrfs("%s: flush=%d(%s) flags=%llu(%s) bytes=%llu",
1102 		  __get_str(reason), __entry->flush,
1103 		  __print_symbolic(__entry->flush, FLUSH_ACTIONS),
1104 		  __entry->flags,
1105 		  __print_flags((unsigned long)__entry->flags, "|",
1106 				BTRFS_GROUP_FLAGS),
1107 		  __entry->bytes)
1108 );
1109 
1110 
1111 TRACE_EVENT(btrfs_flush_space,
1112 
1113 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 num_bytes,
1114 		 int state, int ret),
1115 
1116 	TP_ARGS(fs_info, flags, num_bytes, state, ret),
1117 
1118 	TP_STRUCT__entry_btrfs(
1119 		__field(	u64,	flags			)
1120 		__field(	u64,	num_bytes		)
1121 		__field(	int,	state			)
1122 		__field(	int,	ret			)
1123 	),
1124 
1125 	TP_fast_assign_btrfs(fs_info,
1126 		__entry->flags		=	flags;
1127 		__entry->num_bytes	=	num_bytes;
1128 		__entry->state		=	state;
1129 		__entry->ret		=	ret;
1130 	),
1131 
1132 	TP_printk_btrfs("state=%d(%s) flags=%llu(%s) num_bytes=%llu ret=%d",
1133 		  __entry->state,
1134 		  __print_symbolic(__entry->state, FLUSH_STATES),
1135 		  __entry->flags,
1136 		  __print_flags((unsigned long)__entry->flags, "|",
1137 				BTRFS_GROUP_FLAGS),
1138 		  __entry->num_bytes, __entry->ret)
1139 );
1140 
1141 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
1142 
1143 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1144 
1145 	TP_ARGS(fs_info, start, len),
1146 
1147 	TP_STRUCT__entry_btrfs(
1148 		__field(	u64,  start			)
1149 		__field(	u64,  len			)
1150 	),
1151 
1152 	TP_fast_assign_btrfs(fs_info,
1153 		__entry->start		= start;
1154 		__entry->len		= len;
1155 	),
1156 
1157 	TP_printk_btrfs("root=%llu(%s) start=%llu len=%llu",
1158 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1159 		  __entry->start,
1160 		  __entry->len)
1161 );
1162 
1163 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_alloc,
1164 
1165 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1166 
1167 	TP_ARGS(fs_info, start, len)
1168 );
1169 
1170 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_free,
1171 
1172 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1173 
1174 	TP_ARGS(fs_info, start, len)
1175 );
1176 
1177 TRACE_EVENT(find_free_extent,
1178 
1179 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 num_bytes,
1180 		 u64 empty_size, u64 data),
1181 
1182 	TP_ARGS(fs_info, num_bytes, empty_size, data),
1183 
1184 	TP_STRUCT__entry_btrfs(
1185 		__field(	u64,	num_bytes		)
1186 		__field(	u64,	empty_size		)
1187 		__field(	u64,	data			)
1188 	),
1189 
1190 	TP_fast_assign_btrfs(fs_info,
1191 		__entry->num_bytes	= num_bytes;
1192 		__entry->empty_size	= empty_size;
1193 		__entry->data		= data;
1194 	),
1195 
1196 	TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s)",
1197 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1198 		  __entry->num_bytes, __entry->empty_size, __entry->data,
1199 		  __print_flags((unsigned long)__entry->data, "|",
1200 				 BTRFS_GROUP_FLAGS))
1201 );
1202 
1203 DECLARE_EVENT_CLASS(btrfs__reserve_extent,
1204 
1205 	TP_PROTO(const struct btrfs_block_group *block_group, u64 start,
1206 		 u64 len),
1207 
1208 	TP_ARGS(block_group, start, len),
1209 
1210 	TP_STRUCT__entry_btrfs(
1211 		__field(	u64,	bg_objectid		)
1212 		__field(	u64,	flags			)
1213 		__field(	u64,	start			)
1214 		__field(	u64,	len			)
1215 	),
1216 
1217 	TP_fast_assign_btrfs(block_group->fs_info,
1218 		__entry->bg_objectid	= block_group->start;
1219 		__entry->flags		= block_group->flags;
1220 		__entry->start		= start;
1221 		__entry->len		= len;
1222 	),
1223 
1224 	TP_printk_btrfs("root=%llu(%s) block_group=%llu flags=%llu(%s) "
1225 		  "start=%llu len=%llu",
1226 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1227 		  __entry->bg_objectid,
1228 		  __entry->flags, __print_flags((unsigned long)__entry->flags,
1229 						"|", BTRFS_GROUP_FLAGS),
1230 		  __entry->start, __entry->len)
1231 );
1232 
1233 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
1234 
1235 	TP_PROTO(const struct btrfs_block_group *block_group, u64 start,
1236 		 u64 len),
1237 
1238 	TP_ARGS(block_group, start, len)
1239 );
1240 
1241 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
1242 
1243 	TP_PROTO(const struct btrfs_block_group *block_group, u64 start,
1244 		 u64 len),
1245 
1246 	TP_ARGS(block_group, start, len)
1247 );
1248 
1249 TRACE_EVENT(btrfs_find_cluster,
1250 
1251 	TP_PROTO(const struct btrfs_block_group *block_group, u64 start,
1252 		 u64 bytes, u64 empty_size, u64 min_bytes),
1253 
1254 	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
1255 
1256 	TP_STRUCT__entry_btrfs(
1257 		__field(	u64,	bg_objectid		)
1258 		__field(	u64,	flags			)
1259 		__field(	u64,	start			)
1260 		__field(	u64,	bytes			)
1261 		__field(	u64,	empty_size		)
1262 		__field(	u64,	min_bytes		)
1263 	),
1264 
1265 	TP_fast_assign_btrfs(block_group->fs_info,
1266 		__entry->bg_objectid	= block_group->start;
1267 		__entry->flags		= block_group->flags;
1268 		__entry->start		= start;
1269 		__entry->bytes		= bytes;
1270 		__entry->empty_size	= empty_size;
1271 		__entry->min_bytes	= min_bytes;
1272 	),
1273 
1274 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) start=%llu len=%llu "
1275 		  "empty_size=%llu min_bytes=%llu", __entry->bg_objectid,
1276 		  __entry->flags,
1277 		  __print_flags((unsigned long)__entry->flags, "|",
1278 				BTRFS_GROUP_FLAGS), __entry->start,
1279 		  __entry->bytes, __entry->empty_size,  __entry->min_bytes)
1280 );
1281 
1282 TRACE_EVENT(btrfs_failed_cluster_setup,
1283 
1284 	TP_PROTO(const struct btrfs_block_group *block_group),
1285 
1286 	TP_ARGS(block_group),
1287 
1288 	TP_STRUCT__entry_btrfs(
1289 		__field(	u64,	bg_objectid		)
1290 	),
1291 
1292 	TP_fast_assign_btrfs(block_group->fs_info,
1293 		__entry->bg_objectid	= block_group->start;
1294 	),
1295 
1296 	TP_printk_btrfs("block_group=%llu", __entry->bg_objectid)
1297 );
1298 
1299 TRACE_EVENT(btrfs_setup_cluster,
1300 
1301 	TP_PROTO(const struct btrfs_block_group *block_group,
1302 		 const struct btrfs_free_cluster *cluster,
1303 		 u64 size, int bitmap),
1304 
1305 	TP_ARGS(block_group, cluster, size, bitmap),
1306 
1307 	TP_STRUCT__entry_btrfs(
1308 		__field(	u64,	bg_objectid		)
1309 		__field(	u64,	flags			)
1310 		__field(	u64,	start			)
1311 		__field(	u64,	max_size		)
1312 		__field(	u64,	size			)
1313 		__field(	int,	bitmap			)
1314 	),
1315 
1316 	TP_fast_assign_btrfs(block_group->fs_info,
1317 		__entry->bg_objectid	= block_group->start;
1318 		__entry->flags		= block_group->flags;
1319 		__entry->start		= cluster->window_start;
1320 		__entry->max_size	= cluster->max_size;
1321 		__entry->size		= size;
1322 		__entry->bitmap		= bitmap;
1323 	),
1324 
1325 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) window_start=%llu "
1326 		  "size=%llu max_size=%llu bitmap=%d",
1327 		  __entry->bg_objectid,
1328 		  __entry->flags,
1329 		  __print_flags((unsigned long)__entry->flags, "|",
1330 				BTRFS_GROUP_FLAGS), __entry->start,
1331 		  __entry->size, __entry->max_size, __entry->bitmap)
1332 );
1333 
1334 struct extent_state;
1335 TRACE_EVENT(alloc_extent_state,
1336 
1337 	TP_PROTO(const struct extent_state *state,
1338 		 gfp_t mask, unsigned long IP),
1339 
1340 	TP_ARGS(state, mask, IP),
1341 
1342 	TP_STRUCT__entry(
1343 		__field(const struct extent_state *, state)
1344 		__field(gfp_t, mask)
1345 		__field(const void*, ip)
1346 	),
1347 
1348 	TP_fast_assign(
1349 		__entry->state	= state,
1350 		__entry->mask	= mask,
1351 		__entry->ip	= (const void *)IP
1352 	),
1353 
1354 	TP_printk("state=%p mask=%s caller=%pS", __entry->state,
1355 		  show_gfp_flags(__entry->mask), __entry->ip)
1356 );
1357 
1358 TRACE_EVENT(free_extent_state,
1359 
1360 	TP_PROTO(const struct extent_state *state, unsigned long IP),
1361 
1362 	TP_ARGS(state, IP),
1363 
1364 	TP_STRUCT__entry(
1365 		__field(const struct extent_state *, state)
1366 		__field(const void*, ip)
1367 	),
1368 
1369 	TP_fast_assign(
1370 		__entry->state	= state,
1371 		__entry->ip = (const void *)IP
1372 	),
1373 
1374 	TP_printk("state=%p caller=%pS", __entry->state, __entry->ip)
1375 );
1376 
1377 DECLARE_EVENT_CLASS(btrfs__work,
1378 
1379 	TP_PROTO(const struct btrfs_work *work),
1380 
1381 	TP_ARGS(work),
1382 
1383 	TP_STRUCT__entry_btrfs(
1384 		__field(	const void *,	work			)
1385 		__field(	const void *,	wq			)
1386 		__field(	const void *,	func			)
1387 		__field(	const void *,	ordered_func		)
1388 		__field(	const void *,	ordered_free		)
1389 		__field(	const void *,	normal_work		)
1390 	),
1391 
1392 	TP_fast_assign_btrfs(btrfs_work_owner(work),
1393 		__entry->work		= work;
1394 		__entry->wq		= work->wq;
1395 		__entry->func		= work->func;
1396 		__entry->ordered_func	= work->ordered_func;
1397 		__entry->ordered_free	= work->ordered_free;
1398 		__entry->normal_work	= &work->normal_work;
1399 	),
1400 
1401 	TP_printk_btrfs("work=%p (normal_work=%p) wq=%p func=%ps ordered_func=%p "
1402 		  "ordered_free=%p",
1403 		  __entry->work, __entry->normal_work, __entry->wq,
1404 		   __entry->func, __entry->ordered_func, __entry->ordered_free)
1405 );
1406 
1407 /*
1408  * For situations when the work is freed, we pass fs_info and a tag that matches
1409  * the address of the work structure so it can be paired with the scheduling
1410  * event. DO NOT add anything here that dereferences wtag.
1411  */
1412 DECLARE_EVENT_CLASS(btrfs__work__done,
1413 
1414 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1415 
1416 	TP_ARGS(fs_info, wtag),
1417 
1418 	TP_STRUCT__entry_btrfs(
1419 		__field(	const void *,	wtag			)
1420 	),
1421 
1422 	TP_fast_assign_btrfs(fs_info,
1423 		__entry->wtag		= wtag;
1424 	),
1425 
1426 	TP_printk_btrfs("work->%p", __entry->wtag)
1427 );
1428 
1429 DEFINE_EVENT(btrfs__work, btrfs_work_queued,
1430 
1431 	TP_PROTO(const struct btrfs_work *work),
1432 
1433 	TP_ARGS(work)
1434 );
1435 
1436 DEFINE_EVENT(btrfs__work, btrfs_work_sched,
1437 
1438 	TP_PROTO(const struct btrfs_work *work),
1439 
1440 	TP_ARGS(work)
1441 );
1442 
1443 DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
1444 
1445 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1446 
1447 	TP_ARGS(fs_info, wtag)
1448 );
1449 
1450 DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
1451 
1452 	TP_PROTO(const struct btrfs_work *work),
1453 
1454 	TP_ARGS(work)
1455 );
1456 
1457 DECLARE_EVENT_CLASS(btrfs__workqueue,
1458 
1459 	TP_PROTO(const struct __btrfs_workqueue *wq,
1460 		 const char *name, int high),
1461 
1462 	TP_ARGS(wq, name, high),
1463 
1464 	TP_STRUCT__entry_btrfs(
1465 		__field(	const void *,	wq			)
1466 		__string(	name,	name			)
1467 		__field(	int ,	high			)
1468 	),
1469 
1470 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1471 		__entry->wq		= wq;
1472 		__assign_str(name, name);
1473 		__entry->high		= high;
1474 	),
1475 
1476 	TP_printk_btrfs("name=%s%s wq=%p", __get_str(name),
1477 		  __print_flags(__entry->high, "",
1478 				{(WQ_HIGHPRI),	"-high"}),
1479 		  __entry->wq)
1480 );
1481 
1482 DEFINE_EVENT(btrfs__workqueue, btrfs_workqueue_alloc,
1483 
1484 	TP_PROTO(const struct __btrfs_workqueue *wq,
1485 		 const char *name, int high),
1486 
1487 	TP_ARGS(wq, name, high)
1488 );
1489 
1490 DECLARE_EVENT_CLASS(btrfs__workqueue_done,
1491 
1492 	TP_PROTO(const struct __btrfs_workqueue *wq),
1493 
1494 	TP_ARGS(wq),
1495 
1496 	TP_STRUCT__entry_btrfs(
1497 		__field(	const void *,	wq		)
1498 	),
1499 
1500 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1501 		__entry->wq		= wq;
1502 	),
1503 
1504 	TP_printk_btrfs("wq=%p", __entry->wq)
1505 );
1506 
1507 DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
1508 
1509 	TP_PROTO(const struct __btrfs_workqueue *wq),
1510 
1511 	TP_ARGS(wq)
1512 );
1513 
1514 #define BTRFS_QGROUP_OPERATIONS				\
1515 	{ QGROUP_RESERVE,	"reserve"	},	\
1516 	{ QGROUP_RELEASE,	"release"	},	\
1517 	{ QGROUP_FREE,		"free"		}
1518 
1519 DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
1520 
1521 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1522 		 u64 reserved, int op),
1523 
1524 	TP_ARGS(inode, start, len, reserved, op),
1525 
1526 	TP_STRUCT__entry_btrfs(
1527 		__field(	u64,		rootid		)
1528 		__field(	u64,		ino		)
1529 		__field(	u64,		start		)
1530 		__field(	u64,		len		)
1531 		__field(	u64,		reserved	)
1532 		__field(	int,		op		)
1533 	),
1534 
1535 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
1536 		__entry->rootid		=
1537 			BTRFS_I(inode)->root->root_key.objectid;
1538 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
1539 		__entry->start		= start;
1540 		__entry->len		= len;
1541 		__entry->reserved	= reserved;
1542 		__entry->op		= op;
1543 	),
1544 
1545 	TP_printk_btrfs("root=%llu ino=%llu start=%llu len=%llu reserved=%llu op=%s",
1546 		  __entry->rootid, __entry->ino, __entry->start, __entry->len,
1547 		  __entry->reserved,
1548 		  __print_flags((unsigned long)__entry->op, "",
1549 				BTRFS_QGROUP_OPERATIONS)
1550 	)
1551 );
1552 
1553 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_reserve_data,
1554 
1555 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1556 		 u64 reserved, int op),
1557 
1558 	TP_ARGS(inode, start, len, reserved, op)
1559 );
1560 
1561 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data,
1562 
1563 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1564 		 u64 reserved, int op),
1565 
1566 	TP_ARGS(inode, start, len, reserved, op)
1567 );
1568 
1569 DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
1570 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1571 		 const struct btrfs_qgroup_extent_record *rec),
1572 
1573 	TP_ARGS(fs_info, rec),
1574 
1575 	TP_STRUCT__entry_btrfs(
1576 		__field(	u64,  bytenr		)
1577 		__field(	u64,  num_bytes		)
1578 	),
1579 
1580 	TP_fast_assign_btrfs(fs_info,
1581 		__entry->bytenr		= rec->bytenr,
1582 		__entry->num_bytes	= rec->num_bytes;
1583 	),
1584 
1585 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu",
1586 		  __entry->bytenr, __entry->num_bytes)
1587 );
1588 
1589 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
1590 
1591 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1592 		 const struct btrfs_qgroup_extent_record *rec),
1593 
1594 	TP_ARGS(fs_info, rec)
1595 );
1596 
1597 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent,
1598 
1599 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1600 		 const struct btrfs_qgroup_extent_record *rec),
1601 
1602 	TP_ARGS(fs_info, rec)
1603 );
1604 
1605 TRACE_EVENT(qgroup_num_dirty_extents,
1606 
1607 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid,
1608 		 u64 num_dirty_extents),
1609 
1610 	TP_ARGS(fs_info, transid, num_dirty_extents),
1611 
1612 	TP_STRUCT__entry_btrfs(
1613 		__field(	u64, transid			)
1614 		__field(	u64, num_dirty_extents		)
1615 	),
1616 
1617 	TP_fast_assign_btrfs(fs_info,
1618 		__entry->transid	   = transid;
1619 		__entry->num_dirty_extents = num_dirty_extents;
1620 	),
1621 
1622 	TP_printk_btrfs("transid=%llu num_dirty_extents=%llu",
1623 		__entry->transid, __entry->num_dirty_extents)
1624 );
1625 
1626 TRACE_EVENT(btrfs_qgroup_account_extent,
1627 
1628 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid, u64 bytenr,
1629 		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
1630 
1631 	TP_ARGS(fs_info, transid, bytenr, num_bytes, nr_old_roots,
1632 		nr_new_roots),
1633 
1634 	TP_STRUCT__entry_btrfs(
1635 		__field(	u64,  transid			)
1636 		__field(	u64,  bytenr			)
1637 		__field(	u64,  num_bytes			)
1638 		__field(	u64,  nr_old_roots		)
1639 		__field(	u64,  nr_new_roots		)
1640 	),
1641 
1642 	TP_fast_assign_btrfs(fs_info,
1643 		__entry->transid	= transid;
1644 		__entry->bytenr		= bytenr;
1645 		__entry->num_bytes	= num_bytes;
1646 		__entry->nr_old_roots	= nr_old_roots;
1647 		__entry->nr_new_roots	= nr_new_roots;
1648 	),
1649 
1650 	TP_printk_btrfs(
1651 "transid=%llu bytenr=%llu num_bytes=%llu nr_old_roots=%llu nr_new_roots=%llu",
1652 		__entry->transid,
1653 		__entry->bytenr,
1654 		__entry->num_bytes,
1655 		__entry->nr_old_roots,
1656 		__entry->nr_new_roots)
1657 );
1658 
1659 TRACE_EVENT(qgroup_update_counters,
1660 
1661 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1662 		 const struct btrfs_qgroup *qgroup,
1663 		 u64 cur_old_count, u64 cur_new_count),
1664 
1665 	TP_ARGS(fs_info, qgroup, cur_old_count, cur_new_count),
1666 
1667 	TP_STRUCT__entry_btrfs(
1668 		__field(	u64,  qgid			)
1669 		__field(	u64,  old_rfer			)
1670 		__field(	u64,  old_excl			)
1671 		__field(	u64,  cur_old_count		)
1672 		__field(	u64,  cur_new_count		)
1673 	),
1674 
1675 	TP_fast_assign_btrfs(fs_info,
1676 		__entry->qgid		= qgroup->qgroupid;
1677 		__entry->old_rfer	= qgroup->rfer;
1678 		__entry->old_excl	= qgroup->excl;
1679 		__entry->cur_old_count	= cur_old_count;
1680 		__entry->cur_new_count	= cur_new_count;
1681 	),
1682 
1683 	TP_printk_btrfs("qgid=%llu old_rfer=%llu old_excl=%llu cur_old_count=%llu cur_new_count=%llu",
1684 		  __entry->qgid, __entry->old_rfer, __entry->old_excl,
1685 		  __entry->cur_old_count, __entry->cur_new_count)
1686 );
1687 
1688 TRACE_EVENT(qgroup_update_reserve,
1689 
1690 	TP_PROTO(struct btrfs_fs_info *fs_info, struct btrfs_qgroup *qgroup,
1691 		 s64 diff, int type),
1692 
1693 	TP_ARGS(fs_info, qgroup, diff, type),
1694 
1695 	TP_STRUCT__entry_btrfs(
1696 		__field(	u64,	qgid			)
1697 		__field(	u64,	cur_reserved		)
1698 		__field(	s64,	diff			)
1699 		__field(	int,	type			)
1700 	),
1701 
1702 	TP_fast_assign_btrfs(fs_info,
1703 		__entry->qgid		= qgroup->qgroupid;
1704 		__entry->cur_reserved	= qgroup->rsv.values[type];
1705 		__entry->diff		= diff;
1706 		__entry->type		= type;
1707 	),
1708 
1709 	TP_printk_btrfs("qgid=%llu type=%s cur_reserved=%llu diff=%lld",
1710 		__entry->qgid, __print_symbolic(__entry->type, QGROUP_RSV_TYPES),
1711 		__entry->cur_reserved, __entry->diff)
1712 );
1713 
1714 TRACE_EVENT(qgroup_meta_reserve,
1715 
1716 	TP_PROTO(struct btrfs_root *root, s64 diff, int type),
1717 
1718 	TP_ARGS(root, diff, type),
1719 
1720 	TP_STRUCT__entry_btrfs(
1721 		__field(	u64,	refroot			)
1722 		__field(	s64,	diff			)
1723 		__field(	int,	type			)
1724 	),
1725 
1726 	TP_fast_assign_btrfs(root->fs_info,
1727 		__entry->refroot	= root->root_key.objectid;
1728 		__entry->diff		= diff;
1729 		__entry->type		= type;
1730 	),
1731 
1732 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1733 		show_root_type(__entry->refroot),
1734 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1735 );
1736 
1737 TRACE_EVENT(qgroup_meta_convert,
1738 
1739 	TP_PROTO(struct btrfs_root *root, s64 diff),
1740 
1741 	TP_ARGS(root, diff),
1742 
1743 	TP_STRUCT__entry_btrfs(
1744 		__field(	u64,	refroot			)
1745 		__field(	s64,	diff			)
1746 	),
1747 
1748 	TP_fast_assign_btrfs(root->fs_info,
1749 		__entry->refroot	= root->root_key.objectid;
1750 		__entry->diff		= diff;
1751 	),
1752 
1753 	TP_printk_btrfs("refroot=%llu(%s) type=%s->%s diff=%lld",
1754 		show_root_type(__entry->refroot),
1755 		__print_symbolic(BTRFS_QGROUP_RSV_META_PREALLOC, QGROUP_RSV_TYPES),
1756 		__print_symbolic(BTRFS_QGROUP_RSV_META_PERTRANS, QGROUP_RSV_TYPES),
1757 		__entry->diff)
1758 );
1759 
1760 TRACE_EVENT(qgroup_meta_free_all_pertrans,
1761 
1762 	TP_PROTO(struct btrfs_root *root),
1763 
1764 	TP_ARGS(root),
1765 
1766 	TP_STRUCT__entry_btrfs(
1767 		__field(	u64,	refroot			)
1768 		__field(	s64,	diff			)
1769 		__field(	int,	type			)
1770 	),
1771 
1772 	TP_fast_assign_btrfs(root->fs_info,
1773 		__entry->refroot	= root->root_key.objectid;
1774 		spin_lock(&root->qgroup_meta_rsv_lock);
1775 		__entry->diff		= -(s64)root->qgroup_meta_rsv_pertrans;
1776 		spin_unlock(&root->qgroup_meta_rsv_lock);
1777 		__entry->type		= BTRFS_QGROUP_RSV_META_PERTRANS;
1778 	),
1779 
1780 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1781 		show_root_type(__entry->refroot),
1782 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1783 );
1784 
1785 DECLARE_EVENT_CLASS(btrfs__prelim_ref,
1786 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1787 		 const struct prelim_ref *oldref,
1788 		 const struct prelim_ref *newref, u64 tree_size),
1789 	TP_ARGS(fs_info, newref, oldref, tree_size),
1790 
1791 	TP_STRUCT__entry_btrfs(
1792 		__field(	u64,  root_id		)
1793 		__field(	u64,  objectid		)
1794 		__field(	 u8,  type		)
1795 		__field(	u64,  offset		)
1796 		__field(	int,  level		)
1797 		__field(	int,  old_count		)
1798 		__field(	u64,  parent		)
1799 		__field(	u64,  bytenr		)
1800 		__field(	int,  mod_count		)
1801 		__field(	u64,  tree_size		)
1802 	),
1803 
1804 	TP_fast_assign_btrfs(fs_info,
1805 		__entry->root_id	= oldref->root_id;
1806 		__entry->objectid	= oldref->key_for_search.objectid;
1807 		__entry->type		= oldref->key_for_search.type;
1808 		__entry->offset		= oldref->key_for_search.offset;
1809 		__entry->level		= oldref->level;
1810 		__entry->old_count	= oldref->count;
1811 		__entry->parent		= oldref->parent;
1812 		__entry->bytenr		= oldref->wanted_disk_byte;
1813 		__entry->mod_count	= newref ? newref->count : 0;
1814 		__entry->tree_size	= tree_size;
1815 	),
1816 
1817 	TP_printk_btrfs("root_id=%llu key=[%llu,%u,%llu] level=%d count=[%d+%d=%d] parent=%llu wanted_disk_byte=%llu nodes=%llu",
1818 			__entry->root_id,
1819 			__entry->objectid, __entry->type,
1820 			__entry->offset, __entry->level,
1821 			__entry->old_count, __entry->mod_count,
1822 			__entry->old_count + __entry->mod_count,
1823 			__entry->parent,
1824 			__entry->bytenr,
1825 			__entry->tree_size)
1826 );
1827 
1828 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_merge,
1829 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1830 		 const struct prelim_ref *oldref,
1831 		 const struct prelim_ref *newref, u64 tree_size),
1832 	TP_ARGS(fs_info, oldref, newref, tree_size)
1833 );
1834 
1835 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_insert,
1836 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1837 		 const struct prelim_ref *oldref,
1838 		 const struct prelim_ref *newref, u64 tree_size),
1839 	TP_ARGS(fs_info, oldref, newref, tree_size)
1840 );
1841 
1842 TRACE_EVENT(btrfs_inode_mod_outstanding_extents,
1843 	TP_PROTO(const struct btrfs_root *root, u64 ino, int mod),
1844 
1845 	TP_ARGS(root, ino, mod),
1846 
1847 	TP_STRUCT__entry_btrfs(
1848 		__field(	u64, root_objectid	)
1849 		__field(	u64, ino		)
1850 		__field(	int, mod		)
1851 	),
1852 
1853 	TP_fast_assign_btrfs(root->fs_info,
1854 		__entry->root_objectid	= root->root_key.objectid;
1855 		__entry->ino		= ino;
1856 		__entry->mod		= mod;
1857 	),
1858 
1859 	TP_printk_btrfs("root=%llu(%s) ino=%llu mod=%d",
1860 			show_root_type(__entry->root_objectid),
1861 			__entry->ino, __entry->mod)
1862 );
1863 
1864 DECLARE_EVENT_CLASS(btrfs__block_group,
1865 	TP_PROTO(const struct btrfs_block_group *bg_cache),
1866 
1867 	TP_ARGS(bg_cache),
1868 
1869 	TP_STRUCT__entry_btrfs(
1870 		__field(	u64,	bytenr		)
1871 		__field(	u64,	len		)
1872 		__field(	u64,	used		)
1873 		__field(	u64,	flags		)
1874 	),
1875 
1876 	TP_fast_assign_btrfs(bg_cache->fs_info,
1877 		__entry->bytenr = bg_cache->start,
1878 		__entry->len	= bg_cache->length,
1879 		__entry->used	= bg_cache->used;
1880 		__entry->flags	= bg_cache->flags;
1881 	),
1882 
1883 	TP_printk_btrfs("bg bytenr=%llu len=%llu used=%llu flags=%llu(%s)",
1884 		__entry->bytenr, __entry->len, __entry->used, __entry->flags,
1885 		__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS))
1886 );
1887 
1888 DEFINE_EVENT(btrfs__block_group, btrfs_remove_block_group,
1889 	TP_PROTO(const struct btrfs_block_group *bg_cache),
1890 
1891 	TP_ARGS(bg_cache)
1892 );
1893 
1894 DEFINE_EVENT(btrfs__block_group, btrfs_add_unused_block_group,
1895 	TP_PROTO(const struct btrfs_block_group *bg_cache),
1896 
1897 	TP_ARGS(bg_cache)
1898 );
1899 
1900 DEFINE_EVENT(btrfs__block_group, btrfs_skip_unused_block_group,
1901 	TP_PROTO(const struct btrfs_block_group *bg_cache),
1902 
1903 	TP_ARGS(bg_cache)
1904 );
1905 
1906 TRACE_EVENT(btrfs_set_extent_bit,
1907 	TP_PROTO(const struct extent_io_tree *tree,
1908 		 u64 start, u64 len, unsigned set_bits),
1909 
1910 	TP_ARGS(tree, start, len, set_bits),
1911 
1912 	TP_STRUCT__entry_btrfs(
1913 		__field(	unsigned,	owner	)
1914 		__field(	u64,		ino	)
1915 		__field(	u64,		rootid	)
1916 		__field(	u64,		start	)
1917 		__field(	u64,		len	)
1918 		__field(	unsigned,	set_bits)
1919 	),
1920 
1921 	TP_fast_assign_btrfs(tree->fs_info,
1922 		__entry->owner = tree->owner;
1923 		if (tree->private_data) {
1924 			const struct inode *inode = tree->private_data;
1925 
1926 			__entry->ino	= btrfs_ino(BTRFS_I(inode));
1927 			__entry->rootid	=
1928 				BTRFS_I(inode)->root->root_key.objectid;
1929 		} else {
1930 			__entry->ino	= 0;
1931 			__entry->rootid	= 0;
1932 		}
1933 		__entry->start		= start;
1934 		__entry->len		= len;
1935 		__entry->set_bits	= set_bits;
1936 	),
1937 
1938 	TP_printk_btrfs(
1939 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s",
1940 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
1941 		__entry->rootid, __entry->start, __entry->len,
1942 		__print_flags(__entry->set_bits, "|", EXTENT_FLAGS))
1943 );
1944 
1945 TRACE_EVENT(btrfs_clear_extent_bit,
1946 	TP_PROTO(const struct extent_io_tree *tree,
1947 		 u64 start, u64 len, unsigned clear_bits),
1948 
1949 	TP_ARGS(tree, start, len, clear_bits),
1950 
1951 	TP_STRUCT__entry_btrfs(
1952 		__field(	unsigned,	owner	)
1953 		__field(	u64,		ino	)
1954 		__field(	u64,		rootid	)
1955 		__field(	u64,		start	)
1956 		__field(	u64,		len	)
1957 		__field(	unsigned,	clear_bits)
1958 	),
1959 
1960 	TP_fast_assign_btrfs(tree->fs_info,
1961 		__entry->owner = tree->owner;
1962 		if (tree->private_data) {
1963 			const struct inode *inode = tree->private_data;
1964 
1965 			__entry->ino	= btrfs_ino(BTRFS_I(inode));
1966 			__entry->rootid	=
1967 				BTRFS_I(inode)->root->root_key.objectid;
1968 		} else {
1969 			__entry->ino	= 0;
1970 			__entry->rootid	= 0;
1971 		}
1972 		__entry->start		= start;
1973 		__entry->len		= len;
1974 		__entry->clear_bits	= clear_bits;
1975 	),
1976 
1977 	TP_printk_btrfs(
1978 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu clear_bits=%s",
1979 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
1980 		__entry->rootid, __entry->start, __entry->len,
1981 		__print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
1982 );
1983 
1984 TRACE_EVENT(btrfs_convert_extent_bit,
1985 	TP_PROTO(const struct extent_io_tree *tree,
1986 		 u64 start, u64 len, unsigned set_bits, unsigned clear_bits),
1987 
1988 	TP_ARGS(tree, start, len, set_bits, clear_bits),
1989 
1990 	TP_STRUCT__entry_btrfs(
1991 		__field(	unsigned,	owner	)
1992 		__field(	u64,		ino	)
1993 		__field(	u64,		rootid	)
1994 		__field(	u64,		start	)
1995 		__field(	u64,		len	)
1996 		__field(	unsigned,	set_bits)
1997 		__field(	unsigned,	clear_bits)
1998 	),
1999 
2000 	TP_fast_assign_btrfs(tree->fs_info,
2001 		__entry->owner = tree->owner;
2002 		if (tree->private_data) {
2003 			const struct inode *inode = tree->private_data;
2004 
2005 			__entry->ino	= btrfs_ino(BTRFS_I(inode));
2006 			__entry->rootid	=
2007 				BTRFS_I(inode)->root->root_key.objectid;
2008 		} else {
2009 			__entry->ino	= 0;
2010 			__entry->rootid	= 0;
2011 		}
2012 		__entry->start		= start;
2013 		__entry->len		= len;
2014 		__entry->set_bits	= set_bits;
2015 		__entry->clear_bits	= clear_bits;
2016 	),
2017 
2018 	TP_printk_btrfs(
2019 "io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s clear_bits=%s",
2020 		  __print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2021 		  __entry->rootid, __entry->start, __entry->len,
2022 		  __print_flags(__entry->set_bits , "|", EXTENT_FLAGS),
2023 		  __print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
2024 );
2025 
2026 DECLARE_EVENT_CLASS(btrfs_sleep_tree_lock,
2027 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2028 
2029 	TP_ARGS(eb, start_ns),
2030 
2031 	TP_STRUCT__entry_btrfs(
2032 		__field(	u64,	block		)
2033 		__field(	u64,	generation	)
2034 		__field(	u64,	start_ns	)
2035 		__field(	u64,	end_ns		)
2036 		__field(	u64,	diff_ns		)
2037 		__field(	u64,	owner		)
2038 		__field(	int,	is_log_tree	)
2039 	),
2040 
2041 	TP_fast_assign_btrfs(eb->fs_info,
2042 		__entry->block		= eb->start;
2043 		__entry->generation	= btrfs_header_generation(eb);
2044 		__entry->start_ns	= start_ns;
2045 		__entry->end_ns		= ktime_get_ns();
2046 		__entry->diff_ns	= __entry->end_ns - start_ns;
2047 		__entry->owner		= btrfs_header_owner(eb);
2048 		__entry->is_log_tree	= (eb->log_index >= 0);
2049 	),
2050 
2051 	TP_printk_btrfs(
2052 "block=%llu generation=%llu start_ns=%llu end_ns=%llu diff_ns=%llu owner=%llu is_log_tree=%d",
2053 		__entry->block, __entry->generation,
2054 		__entry->start_ns, __entry->end_ns, __entry->diff_ns,
2055 		__entry->owner, __entry->is_log_tree)
2056 );
2057 
2058 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_read_lock,
2059 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2060 
2061 	TP_ARGS(eb, start_ns)
2062 );
2063 
2064 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_lock,
2065 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2066 
2067 	TP_ARGS(eb, start_ns)
2068 );
2069 
2070 DECLARE_EVENT_CLASS(btrfs_locking_events,
2071 	TP_PROTO(const struct extent_buffer *eb),
2072 
2073 	TP_ARGS(eb),
2074 
2075 	TP_STRUCT__entry_btrfs(
2076 		__field(	u64,	block		)
2077 		__field(	u64,	generation	)
2078 		__field(	u64,	owner		)
2079 		__field(	int,	is_log_tree	)
2080 	),
2081 
2082 	TP_fast_assign_btrfs(eb->fs_info,
2083 		__entry->block		= eb->start;
2084 		__entry->generation	= btrfs_header_generation(eb);
2085 		__entry->owner		= btrfs_header_owner(eb);
2086 		__entry->is_log_tree	= (eb->log_index >= 0);
2087 	),
2088 
2089 	TP_printk_btrfs("block=%llu generation=%llu owner=%llu is_log_tree=%d",
2090 		__entry->block, __entry->generation,
2091 		__entry->owner, __entry->is_log_tree)
2092 );
2093 
2094 #define DEFINE_BTRFS_LOCK_EVENT(name)				\
2095 DEFINE_EVENT(btrfs_locking_events, name,			\
2096 		TP_PROTO(const struct extent_buffer *eb),	\
2097 								\
2098 		TP_ARGS(eb)					\
2099 )
2100 
2101 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_unlock);
2102 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock);
2103 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock_blocking);
2104 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_read);
2105 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_write);
2106 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_read_lock);
2107 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_write_lock);
2108 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_lock_atomic);
2109 
2110 DECLARE_EVENT_CLASS(btrfs__space_info_update,
2111 
2112 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2113 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2114 
2115 	TP_ARGS(fs_info, sinfo, old, diff),
2116 
2117 	TP_STRUCT__entry_btrfs(
2118 		__field(	u64,	type		)
2119 		__field(	u64,	old		)
2120 		__field(	s64,	diff		)
2121 	),
2122 
2123 	TP_fast_assign_btrfs(fs_info,
2124 		__entry->type	= sinfo->flags;
2125 		__entry->old	= old;
2126 		__entry->diff	= diff;
2127 	),
2128 	TP_printk_btrfs("type=%s old=%llu diff=%lld",
2129 		__print_flags(__entry->type, "|", BTRFS_GROUP_FLAGS),
2130 		__entry->old, __entry->diff)
2131 );
2132 
2133 DEFINE_EVENT(btrfs__space_info_update, update_bytes_may_use,
2134 
2135 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2136 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2137 
2138 	TP_ARGS(fs_info, sinfo, old, diff)
2139 );
2140 
2141 DEFINE_EVENT(btrfs__space_info_update, update_bytes_pinned,
2142 
2143 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2144 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2145 
2146 	TP_ARGS(fs_info, sinfo, old, diff)
2147 );
2148 
2149 #endif /* _TRACE_BTRFS_H */
2150 
2151 /* This part must be outside protection */
2152 #include <trace/define_trace.h>
2153