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