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