xref: /linux/include/trace/events/btrfs.h (revision 561add0da6d3d07c9bccb0832fb6ed5619167d26)
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 struct find_free_extent_ctl;
36 
37 #define show_ref_type(type)						\
38 	__print_symbolic(type,						\
39 		{ BTRFS_TREE_BLOCK_REF_KEY, 	"TREE_BLOCK_REF" },	\
40 		{ BTRFS_EXTENT_DATA_REF_KEY, 	"EXTENT_DATA_REF" },	\
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_DELAYED_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 TRACE_EVENT(btrfs_finish_ordered_extent,
664 
665 	TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 len,
666 		 bool uptodate),
667 
668 	TP_ARGS(inode, start, len, uptodate),
669 
670 	TP_STRUCT__entry_btrfs(
671 		__field(	u64,	 ino		)
672 		__field(	u64,	 start		)
673 		__field(	u64,	 len		)
674 		__field(	bool,	 uptodate	)
675 		__field(	u64,	 root_objectid	)
676 	),
677 
678 	TP_fast_assign_btrfs(inode->root->fs_info,
679 		__entry->ino	= btrfs_ino(inode);
680 		__entry->start	= start;
681 		__entry->len	= len;
682 		__entry->uptodate = uptodate;
683 		__entry->root_objectid = inode->root->root_key.objectid;
684 	),
685 
686 	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu uptodate=%d",
687 		  show_root_type(__entry->root_objectid),
688 		  __entry->ino, __entry->start,
689 		  __entry->len, !!__entry->uptodate)
690 );
691 
692 DECLARE_EVENT_CLASS(btrfs__writepage,
693 
694 	TP_PROTO(const struct page *page, const struct inode *inode,
695 		 const struct writeback_control *wbc),
696 
697 	TP_ARGS(page, inode, wbc),
698 
699 	TP_STRUCT__entry_btrfs(
700 		__field(	u64,	ino			)
701 		__field(	pgoff_t,  index			)
702 		__field(	long,   nr_to_write		)
703 		__field(	long,   pages_skipped		)
704 		__field(	loff_t, range_start		)
705 		__field(	loff_t, range_end		)
706 		__field(	char,   for_kupdate		)
707 		__field(	char,   for_reclaim		)
708 		__field(	char,   range_cyclic		)
709 		__field(	unsigned long,  writeback_index	)
710 		__field(	u64,    root_objectid		)
711 	),
712 
713 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
714 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
715 		__entry->index		= page->index;
716 		__entry->nr_to_write	= wbc->nr_to_write;
717 		__entry->pages_skipped	= wbc->pages_skipped;
718 		__entry->range_start	= wbc->range_start;
719 		__entry->range_end	= wbc->range_end;
720 		__entry->for_kupdate	= wbc->for_kupdate;
721 		__entry->for_reclaim	= wbc->for_reclaim;
722 		__entry->range_cyclic	= wbc->range_cyclic;
723 		__entry->writeback_index = inode->i_mapping->writeback_index;
724 		__entry->root_objectid	=
725 				 BTRFS_I(inode)->root->root_key.objectid;
726 	),
727 
728 	TP_printk_btrfs("root=%llu(%s) ino=%llu page_index=%lu "
729 		  "nr_to_write=%ld pages_skipped=%ld range_start=%llu "
730 		  "range_end=%llu for_kupdate=%d "
731 		  "for_reclaim=%d range_cyclic=%d writeback_index=%lu",
732 		  show_root_type(__entry->root_objectid),
733 		  __entry->ino, __entry->index,
734 		  __entry->nr_to_write, __entry->pages_skipped,
735 		  __entry->range_start, __entry->range_end,
736 		  __entry->for_kupdate,
737 		  __entry->for_reclaim, __entry->range_cyclic,
738 		  __entry->writeback_index)
739 );
740 
741 DEFINE_EVENT(btrfs__writepage, __extent_writepage,
742 
743 	TP_PROTO(const struct page *page, const struct inode *inode,
744 		 const struct writeback_control *wbc),
745 
746 	TP_ARGS(page, inode, wbc)
747 );
748 
749 TRACE_EVENT(btrfs_writepage_end_io_hook,
750 
751 	TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 end,
752 		 int uptodate),
753 
754 	TP_ARGS(inode, start, end, uptodate),
755 
756 	TP_STRUCT__entry_btrfs(
757 		__field(	u64,	 ino		)
758 		__field(	u64,	 start		)
759 		__field(	u64,	 end		)
760 		__field(	int,	 uptodate	)
761 		__field(	u64,    root_objectid	)
762 	),
763 
764 	TP_fast_assign_btrfs(inode->root->fs_info,
765 		__entry->ino	= btrfs_ino(inode);
766 		__entry->start	= start;
767 		__entry->end	= end;
768 		__entry->uptodate = uptodate;
769 		__entry->root_objectid = inode->root->root_key.objectid;
770 	),
771 
772 	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu end=%llu uptodate=%d",
773 		  show_root_type(__entry->root_objectid),
774 		  __entry->ino, __entry->start,
775 		  __entry->end, __entry->uptodate)
776 );
777 
778 TRACE_EVENT(btrfs_sync_file,
779 
780 	TP_PROTO(const struct file *file, int datasync),
781 
782 	TP_ARGS(file, datasync),
783 
784 	TP_STRUCT__entry_btrfs(
785 		__field(	u64,	ino		)
786 		__field(	u64,	parent		)
787 		__field(	int,    datasync	)
788 		__field(	u64,    root_objectid	)
789 	),
790 
791 	TP_fast_assign(
792 		const struct dentry *dentry = file->f_path.dentry;
793 		const struct inode *inode = d_inode(dentry);
794 
795 		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
796 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
797 		__entry->parent		= btrfs_ino(BTRFS_I(d_inode(dentry->d_parent)));
798 		__entry->datasync	= datasync;
799 		__entry->root_objectid	=
800 				 BTRFS_I(inode)->root->root_key.objectid;
801 	),
802 
803 	TP_printk_btrfs("root=%llu(%s) ino=%llu parent=%llu datasync=%d",
804 		  show_root_type(__entry->root_objectid),
805 		  __entry->ino,
806 		  __entry->parent,
807 		  __entry->datasync)
808 );
809 
810 TRACE_EVENT(btrfs_sync_fs,
811 
812 	TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),
813 
814 	TP_ARGS(fs_info, wait),
815 
816 	TP_STRUCT__entry_btrfs(
817 		__field(	int,  wait		)
818 	),
819 
820 	TP_fast_assign_btrfs(fs_info,
821 		__entry->wait	= wait;
822 	),
823 
824 	TP_printk_btrfs("wait=%d", __entry->wait)
825 );
826 
827 TRACE_EVENT(btrfs_add_block_group,
828 
829 	TP_PROTO(const struct btrfs_fs_info *fs_info,
830 		 const struct btrfs_block_group *block_group, int create),
831 
832 	TP_ARGS(fs_info, block_group, create),
833 
834 	TP_STRUCT__entry_btrfs(
835 		__field(	u64,	offset			)
836 		__field(	u64,	size			)
837 		__field(	u64,	flags			)
838 		__field(	u64,	bytes_used		)
839 		__field(	u64,	bytes_super		)
840 		__field(	int,	create			)
841 	),
842 
843 	TP_fast_assign_btrfs(fs_info,
844 		__entry->offset		= block_group->start;
845 		__entry->size		= block_group->length;
846 		__entry->flags		= block_group->flags;
847 		__entry->bytes_used	= block_group->used;
848 		__entry->bytes_super	= block_group->bytes_super;
849 		__entry->create		= create;
850 	),
851 
852 	TP_printk_btrfs("block_group offset=%llu size=%llu "
853 		  "flags=%llu(%s) bytes_used=%llu bytes_super=%llu "
854 		  "create=%d",
855 		  __entry->offset,
856 		  __entry->size,
857 		  __entry->flags,
858 		  __print_flags((unsigned long)__entry->flags, "|",
859 				BTRFS_GROUP_FLAGS),
860 		  __entry->bytes_used,
861 		  __entry->bytes_super, __entry->create)
862 );
863 
864 #define show_ref_action(action)						\
865 	__print_symbolic(action,					\
866 		{ BTRFS_ADD_DELAYED_REF,    "ADD_DELAYED_REF" },	\
867 		{ BTRFS_DROP_DELAYED_REF,   "DROP_DELAYED_REF" },	\
868 		{ BTRFS_ADD_DELAYED_EXTENT, "ADD_DELAYED_EXTENT" }, 	\
869 		{ BTRFS_UPDATE_DELAYED_HEAD, "UPDATE_DELAYED_HEAD" })
870 
871 
872 DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
873 
874 	TP_PROTO(const struct btrfs_fs_info *fs_info,
875 		 const struct btrfs_delayed_ref_node *ref,
876 		 const struct btrfs_delayed_tree_ref *full_ref,
877 		 int action),
878 
879 	TP_ARGS(fs_info, ref, full_ref, action),
880 
881 	TP_STRUCT__entry_btrfs(
882 		__field(	u64,  bytenr		)
883 		__field(	u64,  num_bytes		)
884 		__field(	int,  action		)
885 		__field(	u64,  parent		)
886 		__field(	u64,  ref_root		)
887 		__field(	int,  level		)
888 		__field(	int,  type		)
889 		__field(	u64,  seq		)
890 	),
891 
892 	TP_fast_assign_btrfs(fs_info,
893 		__entry->bytenr		= ref->bytenr;
894 		__entry->num_bytes	= ref->num_bytes;
895 		__entry->action		= action;
896 		__entry->parent		= full_ref->parent;
897 		__entry->ref_root	= full_ref->root;
898 		__entry->level		= full_ref->level;
899 		__entry->type		= ref->type;
900 		__entry->seq		= ref->seq;
901 	),
902 
903 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s "
904 		  "parent=%llu(%s) ref_root=%llu(%s) level=%d "
905 		  "type=%s seq=%llu",
906 		  __entry->bytenr,
907 		  __entry->num_bytes,
908 		  show_ref_action(__entry->action),
909 		  show_root_type(__entry->parent),
910 		  show_root_type(__entry->ref_root),
911 		  __entry->level, show_ref_type(__entry->type),
912 		  __entry->seq)
913 );
914 
915 DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
916 
917 	TP_PROTO(const struct btrfs_fs_info *fs_info,
918 		 const struct btrfs_delayed_ref_node *ref,
919 		 const struct btrfs_delayed_tree_ref *full_ref,
920 		 int action),
921 
922 	TP_ARGS(fs_info, ref, full_ref, action)
923 );
924 
925 DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
926 
927 	TP_PROTO(const struct btrfs_fs_info *fs_info,
928 		 const struct btrfs_delayed_ref_node *ref,
929 		 const struct btrfs_delayed_tree_ref *full_ref,
930 		 int action),
931 
932 	TP_ARGS(fs_info, ref, full_ref, action)
933 );
934 
935 DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
936 
937 	TP_PROTO(const struct btrfs_fs_info *fs_info,
938 		 const struct btrfs_delayed_ref_node *ref,
939 		 const struct btrfs_delayed_data_ref *full_ref,
940 		 int action),
941 
942 	TP_ARGS(fs_info, ref, full_ref, action),
943 
944 	TP_STRUCT__entry_btrfs(
945 		__field(	u64,  bytenr		)
946 		__field(	u64,  num_bytes		)
947 		__field(	int,  action		)
948 		__field(	u64,  parent		)
949 		__field(	u64,  ref_root		)
950 		__field(	u64,  owner		)
951 		__field(	u64,  offset		)
952 		__field(	int,  type		)
953 		__field(	u64,  seq		)
954 	),
955 
956 	TP_fast_assign_btrfs(fs_info,
957 		__entry->bytenr		= ref->bytenr;
958 		__entry->num_bytes	= ref->num_bytes;
959 		__entry->action		= action;
960 		__entry->parent		= full_ref->parent;
961 		__entry->ref_root	= full_ref->root;
962 		__entry->owner		= full_ref->objectid;
963 		__entry->offset		= full_ref->offset;
964 		__entry->type		= ref->type;
965 		__entry->seq		= ref->seq;
966 	),
967 
968 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s "
969 		  "parent=%llu(%s) ref_root=%llu(%s) owner=%llu "
970 		  "offset=%llu type=%s seq=%llu",
971 		  __entry->bytenr,
972 		  __entry->num_bytes,
973 		  show_ref_action(__entry->action),
974 		  show_root_type(__entry->parent),
975 		  show_root_type(__entry->ref_root),
976 		  __entry->owner,
977 		  __entry->offset,
978 		  show_ref_type(__entry->type),
979 		  __entry->seq)
980 );
981 
982 DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
983 
984 	TP_PROTO(const struct btrfs_fs_info *fs_info,
985 		 const struct btrfs_delayed_ref_node *ref,
986 		 const struct btrfs_delayed_data_ref *full_ref,
987 		 int action),
988 
989 	TP_ARGS(fs_info, ref, full_ref, action)
990 );
991 
992 DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
993 
994 	TP_PROTO(const struct btrfs_fs_info *fs_info,
995 		 const struct btrfs_delayed_ref_node *ref,
996 		 const struct btrfs_delayed_data_ref *full_ref,
997 		 int action),
998 
999 	TP_ARGS(fs_info, ref, full_ref, action)
1000 );
1001 
1002 DECLARE_EVENT_CLASS(btrfs_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 	TP_STRUCT__entry_btrfs(
1011 		__field(	u64,  bytenr		)
1012 		__field(	u64,  num_bytes		)
1013 		__field(	int,  action		)
1014 		__field(	int,  is_data		)
1015 	),
1016 
1017 	TP_fast_assign_btrfs(fs_info,
1018 		__entry->bytenr		= head_ref->bytenr;
1019 		__entry->num_bytes	= head_ref->num_bytes;
1020 		__entry->action		= action;
1021 		__entry->is_data	= head_ref->is_data;
1022 	),
1023 
1024 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu action=%s is_data=%d",
1025 		  __entry->bytenr,
1026 		  __entry->num_bytes,
1027 		  show_ref_action(__entry->action),
1028 		  __entry->is_data)
1029 );
1030 
1031 DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
1032 
1033 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1034 		 const struct btrfs_delayed_ref_head *head_ref,
1035 		 int action),
1036 
1037 	TP_ARGS(fs_info, head_ref, action)
1038 );
1039 
1040 DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
1041 
1042 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1043 		 const struct btrfs_delayed_ref_head *head_ref,
1044 		 int action),
1045 
1046 	TP_ARGS(fs_info, head_ref, action)
1047 );
1048 
1049 #define show_chunk_type(type)					\
1050 	__print_flags(type, "|",				\
1051 		{ BTRFS_BLOCK_GROUP_DATA, 	"DATA"	},	\
1052 		{ BTRFS_BLOCK_GROUP_SYSTEM, 	"SYSTEM"},	\
1053 		{ BTRFS_BLOCK_GROUP_METADATA, 	"METADATA"},	\
1054 		{ BTRFS_BLOCK_GROUP_RAID0, 	"RAID0" },	\
1055 		{ BTRFS_BLOCK_GROUP_RAID1, 	"RAID1" },	\
1056 		{ BTRFS_BLOCK_GROUP_DUP, 	"DUP"	},	\
1057 		{ BTRFS_BLOCK_GROUP_RAID10, 	"RAID10"},	\
1058 		{ BTRFS_BLOCK_GROUP_RAID5, 	"RAID5"	},	\
1059 		{ BTRFS_BLOCK_GROUP_RAID6, 	"RAID6"	})
1060 
1061 DECLARE_EVENT_CLASS(btrfs__chunk,
1062 
1063 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1064 		 const struct map_lookup *map, u64 offset, u64 size),
1065 
1066 	TP_ARGS(fs_info, map, offset, size),
1067 
1068 	TP_STRUCT__entry_btrfs(
1069 		__field(	int,  num_stripes		)
1070 		__field(	u64,  type			)
1071 		__field(	int,  sub_stripes		)
1072 		__field(	u64,  offset			)
1073 		__field(	u64,  size			)
1074 		__field(	u64,  root_objectid		)
1075 	),
1076 
1077 	TP_fast_assign_btrfs(fs_info,
1078 		__entry->num_stripes	= map->num_stripes;
1079 		__entry->type		= map->type;
1080 		__entry->sub_stripes	= map->sub_stripes;
1081 		__entry->offset		= offset;
1082 		__entry->size		= size;
1083 		__entry->root_objectid	= fs_info->chunk_root->root_key.objectid;
1084 	),
1085 
1086 	TP_printk_btrfs("root=%llu(%s) offset=%llu size=%llu "
1087 		  "num_stripes=%d sub_stripes=%d type=%s",
1088 		  show_root_type(__entry->root_objectid),
1089 		  __entry->offset,
1090 		  __entry->size,
1091 		  __entry->num_stripes, __entry->sub_stripes,
1092 		  show_chunk_type(__entry->type))
1093 );
1094 
1095 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_alloc,
1096 
1097 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1098 		 const struct map_lookup *map, u64 offset, u64 size),
1099 
1100 	TP_ARGS(fs_info, map, offset, size)
1101 );
1102 
1103 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_free,
1104 
1105 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1106 		 const struct map_lookup *map, u64 offset, u64 size),
1107 
1108 	TP_ARGS(fs_info, map, offset, size)
1109 );
1110 
1111 TRACE_EVENT(btrfs_cow_block,
1112 
1113 	TP_PROTO(const struct btrfs_root *root, const struct extent_buffer *buf,
1114 		 const struct extent_buffer *cow),
1115 
1116 	TP_ARGS(root, buf, cow),
1117 
1118 	TP_STRUCT__entry_btrfs(
1119 		__field(	u64,  root_objectid		)
1120 		__field(	u64,  buf_start			)
1121 		__field(	int,  refs			)
1122 		__field(	u64,  cow_start			)
1123 		__field(	int,  buf_level			)
1124 		__field(	int,  cow_level			)
1125 	),
1126 
1127 	TP_fast_assign_btrfs(root->fs_info,
1128 		__entry->root_objectid	= root->root_key.objectid;
1129 		__entry->buf_start	= buf->start;
1130 		__entry->refs		= atomic_read(&buf->refs);
1131 		__entry->cow_start	= cow->start;
1132 		__entry->buf_level	= btrfs_header_level(buf);
1133 		__entry->cow_level	= btrfs_header_level(cow);
1134 	),
1135 
1136 	TP_printk_btrfs("root=%llu(%s) refs=%d orig_buf=%llu "
1137 		  "(orig_level=%d) cow_buf=%llu (cow_level=%d)",
1138 		  show_root_type(__entry->root_objectid),
1139 		  __entry->refs,
1140 		  __entry->buf_start,
1141 		  __entry->buf_level,
1142 		  __entry->cow_start,
1143 		  __entry->cow_level)
1144 );
1145 
1146 TRACE_EVENT(btrfs_space_reservation,
1147 
1148 	TP_PROTO(const struct btrfs_fs_info *fs_info, const char *type, u64 val,
1149 		 u64 bytes, int reserve),
1150 
1151 	TP_ARGS(fs_info, type, val, bytes, reserve),
1152 
1153 	TP_STRUCT__entry_btrfs(
1154 		__string(	type,	type			)
1155 		__field(	u64,	val			)
1156 		__field(	u64,	bytes			)
1157 		__field(	int,	reserve			)
1158 	),
1159 
1160 	TP_fast_assign_btrfs(fs_info,
1161 		__assign_str(type, type);
1162 		__entry->val		= val;
1163 		__entry->bytes		= bytes;
1164 		__entry->reserve	= reserve;
1165 	),
1166 
1167 	TP_printk_btrfs("%s: %llu %s %llu", __get_str(type), __entry->val,
1168 			__entry->reserve ? "reserve" : "release",
1169 			__entry->bytes)
1170 );
1171 
1172 TRACE_EVENT(btrfs_trigger_flush,
1173 
1174 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 bytes,
1175 		 int flush, const char *reason),
1176 
1177 	TP_ARGS(fs_info, flags, bytes, flush, reason),
1178 
1179 	TP_STRUCT__entry_btrfs(
1180 		__field(	u64,	flags			)
1181 		__field(	u64,	bytes			)
1182 		__field(	int,	flush			)
1183 		__string(	reason,	reason			)
1184 	),
1185 
1186 	TP_fast_assign_btrfs(fs_info,
1187 		__entry->flags	= flags;
1188 		__entry->bytes	= bytes;
1189 		__entry->flush	= flush;
1190 		__assign_str(reason, reason);
1191 	),
1192 
1193 	TP_printk_btrfs("%s: flush=%d(%s) flags=%llu(%s) bytes=%llu",
1194 		  __get_str(reason), __entry->flush,
1195 		  __print_symbolic(__entry->flush, FLUSH_ACTIONS),
1196 		  __entry->flags,
1197 		  __print_flags((unsigned long)__entry->flags, "|",
1198 				BTRFS_GROUP_FLAGS),
1199 		  __entry->bytes)
1200 );
1201 
1202 
1203 TRACE_EVENT(btrfs_flush_space,
1204 
1205 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 num_bytes,
1206 		 int state, int ret, bool for_preempt),
1207 
1208 	TP_ARGS(fs_info, flags, num_bytes, state, ret, for_preempt),
1209 
1210 	TP_STRUCT__entry_btrfs(
1211 		__field(	u64,	flags			)
1212 		__field(	u64,	num_bytes		)
1213 		__field(	int,	state			)
1214 		__field(	int,	ret			)
1215 		__field(       bool,	for_preempt		)
1216 	),
1217 
1218 	TP_fast_assign_btrfs(fs_info,
1219 		__entry->flags		=	flags;
1220 		__entry->num_bytes	=	num_bytes;
1221 		__entry->state		=	state;
1222 		__entry->ret		=	ret;
1223 		__entry->for_preempt	=	for_preempt;
1224 	),
1225 
1226 	TP_printk_btrfs("state=%d(%s) flags=%llu(%s) num_bytes=%llu ret=%d for_preempt=%d",
1227 		  __entry->state,
1228 		  __print_symbolic(__entry->state, FLUSH_STATES),
1229 		  __entry->flags,
1230 		  __print_flags((unsigned long)__entry->flags, "|",
1231 				BTRFS_GROUP_FLAGS),
1232 		  __entry->num_bytes, __entry->ret, __entry->for_preempt)
1233 );
1234 
1235 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
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 	TP_STRUCT__entry_btrfs(
1242 		__field(	u64,  start			)
1243 		__field(	u64,  len			)
1244 	),
1245 
1246 	TP_fast_assign_btrfs(fs_info,
1247 		__entry->start		= start;
1248 		__entry->len		= len;
1249 	),
1250 
1251 	TP_printk_btrfs("root=%llu(%s) start=%llu len=%llu",
1252 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1253 		  __entry->start,
1254 		  __entry->len)
1255 );
1256 
1257 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_alloc,
1258 
1259 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1260 
1261 	TP_ARGS(fs_info, start, len)
1262 );
1263 
1264 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_free,
1265 
1266 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1267 
1268 	TP_ARGS(fs_info, start, len)
1269 );
1270 
1271 TRACE_EVENT(find_free_extent,
1272 
1273 	TP_PROTO(const struct btrfs_root *root,
1274 		 const struct find_free_extent_ctl *ffe_ctl),
1275 
1276 	TP_ARGS(root, ffe_ctl),
1277 
1278 	TP_STRUCT__entry_btrfs(
1279 		__field(	u64,	root_objectid		)
1280 		__field(	u64,	num_bytes		)
1281 		__field(	u64,	empty_size		)
1282 		__field(	u64,	flags			)
1283 	),
1284 
1285 	TP_fast_assign_btrfs(root->fs_info,
1286 		__entry->root_objectid	= root->root_key.objectid;
1287 		__entry->num_bytes	= ffe_ctl->num_bytes;
1288 		__entry->empty_size	= ffe_ctl->empty_size;
1289 		__entry->flags		= ffe_ctl->flags;
1290 	),
1291 
1292 	TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s)",
1293 		  show_root_type(__entry->root_objectid),
1294 		  __entry->num_bytes, __entry->empty_size, __entry->flags,
1295 		  __print_flags((unsigned long)__entry->flags, "|",
1296 				 BTRFS_GROUP_FLAGS))
1297 );
1298 
1299 TRACE_EVENT(find_free_extent_search_loop,
1300 
1301 	TP_PROTO(const struct btrfs_root *root,
1302 		 const struct find_free_extent_ctl *ffe_ctl),
1303 
1304 	TP_ARGS(root, ffe_ctl),
1305 
1306 	TP_STRUCT__entry_btrfs(
1307 		__field(	u64,	root_objectid		)
1308 		__field(	u64,	num_bytes		)
1309 		__field(	u64,	empty_size		)
1310 		__field(	u64,	flags			)
1311 		__field(	u64,	loop			)
1312 	),
1313 
1314 	TP_fast_assign_btrfs(root->fs_info,
1315 		__entry->root_objectid	= root->root_key.objectid;
1316 		__entry->num_bytes	= ffe_ctl->num_bytes;
1317 		__entry->empty_size	= ffe_ctl->empty_size;
1318 		__entry->flags		= ffe_ctl->flags;
1319 		__entry->loop		= ffe_ctl->loop;
1320 	),
1321 
1322 	TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s) loop=%llu",
1323 		  show_root_type(__entry->root_objectid),
1324 		  __entry->num_bytes, __entry->empty_size, __entry->flags,
1325 		  __print_flags((unsigned long)__entry->flags, "|", BTRFS_GROUP_FLAGS),
1326 		  __entry->loop)
1327 );
1328 
1329 TRACE_EVENT(find_free_extent_have_block_group,
1330 
1331 	TP_PROTO(const struct btrfs_root *root,
1332 		 const struct find_free_extent_ctl *ffe_ctl,
1333 		 const struct btrfs_block_group *block_group),
1334 
1335 	TP_ARGS(root, ffe_ctl, block_group),
1336 
1337 	TP_STRUCT__entry_btrfs(
1338 		__field(	u64,	root_objectid		)
1339 		__field(	u64,	num_bytes		)
1340 		__field(	u64,	empty_size		)
1341 		__field(	u64,	flags			)
1342 		__field(	u64,	loop			)
1343 		__field(	bool,	hinted			)
1344 		__field(	u64,	bg_start		)
1345 		__field(	u64,	bg_flags		)
1346 	),
1347 
1348 	TP_fast_assign_btrfs(root->fs_info,
1349 		__entry->root_objectid	= root->root_key.objectid;
1350 		__entry->num_bytes	= ffe_ctl->num_bytes;
1351 		__entry->empty_size	= ffe_ctl->empty_size;
1352 		__entry->flags		= ffe_ctl->flags;
1353 		__entry->loop		= ffe_ctl->loop;
1354 		__entry->hinted		= ffe_ctl->hinted;
1355 		__entry->bg_start	= block_group->start;
1356 		__entry->bg_flags	= block_group->flags;
1357 	),
1358 
1359 	TP_printk_btrfs(
1360 "root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s) loop=%llu hinted=%d block_group=%llu bg_flags=%llu(%s)",
1361 		  show_root_type(__entry->root_objectid),
1362 		  __entry->num_bytes, __entry->empty_size, __entry->flags,
1363 		  __print_flags((unsigned long)__entry->flags, "|", BTRFS_GROUP_FLAGS),
1364 		  __entry->loop, __entry->hinted,
1365 		  __entry->bg_start, __entry->bg_flags,
1366 		  __print_flags((unsigned long)__entry->bg_flags, "|",
1367 				 BTRFS_GROUP_FLAGS))
1368 );
1369 
1370 DECLARE_EVENT_CLASS(btrfs__reserve_extent,
1371 
1372 	TP_PROTO(const struct btrfs_block_group *block_group,
1373 		 const struct find_free_extent_ctl *ffe_ctl),
1374 
1375 	TP_ARGS(block_group, ffe_ctl),
1376 
1377 	TP_STRUCT__entry_btrfs(
1378 		__field(	u64,	bg_objectid		)
1379 		__field(	u64,	flags			)
1380 		__field(	int,	bg_size_class		)
1381 		__field(	u64,	start			)
1382 		__field(	u64,	len			)
1383 		__field(	u64,	loop			)
1384 		__field(	bool,	hinted			)
1385 		__field(	int,	size_class		)
1386 	),
1387 
1388 	TP_fast_assign_btrfs(block_group->fs_info,
1389 		__entry->bg_objectid	= block_group->start;
1390 		__entry->flags		= block_group->flags;
1391 		__entry->bg_size_class	= block_group->size_class;
1392 		__entry->start		= ffe_ctl->search_start;
1393 		__entry->len		= ffe_ctl->num_bytes;
1394 		__entry->loop		= ffe_ctl->loop;
1395 		__entry->hinted		= ffe_ctl->hinted;
1396 		__entry->size_class	= ffe_ctl->size_class;
1397 	),
1398 
1399 	TP_printk_btrfs(
1400 "root=%llu(%s) block_group=%llu flags=%llu(%s) bg_size_class=%d start=%llu len=%llu loop=%llu hinted=%d size_class=%d",
1401 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1402 		  __entry->bg_objectid,
1403 		  __entry->flags, __print_flags((unsigned long)__entry->flags,
1404 						"|", BTRFS_GROUP_FLAGS),
1405 		  __entry->bg_size_class, __entry->start, __entry->len,
1406 		  __entry->loop, __entry->hinted, __entry->size_class)
1407 );
1408 
1409 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
1410 
1411 	TP_PROTO(const struct btrfs_block_group *block_group,
1412 		 const struct find_free_extent_ctl *ffe_ctl),
1413 
1414 	TP_ARGS(block_group, ffe_ctl)
1415 );
1416 
1417 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
1418 
1419 	TP_PROTO(const struct btrfs_block_group *block_group,
1420 		 const struct find_free_extent_ctl *ffe_ctl),
1421 
1422 	TP_ARGS(block_group, ffe_ctl)
1423 );
1424 
1425 TRACE_EVENT(btrfs_find_cluster,
1426 
1427 	TP_PROTO(const struct btrfs_block_group *block_group, u64 start,
1428 		 u64 bytes, u64 empty_size, u64 min_bytes),
1429 
1430 	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
1431 
1432 	TP_STRUCT__entry_btrfs(
1433 		__field(	u64,	bg_objectid		)
1434 		__field(	u64,	flags			)
1435 		__field(	u64,	start			)
1436 		__field(	u64,	bytes			)
1437 		__field(	u64,	empty_size		)
1438 		__field(	u64,	min_bytes		)
1439 	),
1440 
1441 	TP_fast_assign_btrfs(block_group->fs_info,
1442 		__entry->bg_objectid	= block_group->start;
1443 		__entry->flags		= block_group->flags;
1444 		__entry->start		= start;
1445 		__entry->bytes		= bytes;
1446 		__entry->empty_size	= empty_size;
1447 		__entry->min_bytes	= min_bytes;
1448 	),
1449 
1450 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) start=%llu len=%llu "
1451 		  "empty_size=%llu min_bytes=%llu", __entry->bg_objectid,
1452 		  __entry->flags,
1453 		  __print_flags((unsigned long)__entry->flags, "|",
1454 				BTRFS_GROUP_FLAGS), __entry->start,
1455 		  __entry->bytes, __entry->empty_size,  __entry->min_bytes)
1456 );
1457 
1458 TRACE_EVENT(btrfs_failed_cluster_setup,
1459 
1460 	TP_PROTO(const struct btrfs_block_group *block_group),
1461 
1462 	TP_ARGS(block_group),
1463 
1464 	TP_STRUCT__entry_btrfs(
1465 		__field(	u64,	bg_objectid		)
1466 	),
1467 
1468 	TP_fast_assign_btrfs(block_group->fs_info,
1469 		__entry->bg_objectid	= block_group->start;
1470 	),
1471 
1472 	TP_printk_btrfs("block_group=%llu", __entry->bg_objectid)
1473 );
1474 
1475 TRACE_EVENT(btrfs_setup_cluster,
1476 
1477 	TP_PROTO(const struct btrfs_block_group *block_group,
1478 		 const struct btrfs_free_cluster *cluster,
1479 		 u64 size, int bitmap),
1480 
1481 	TP_ARGS(block_group, cluster, size, bitmap),
1482 
1483 	TP_STRUCT__entry_btrfs(
1484 		__field(	u64,	bg_objectid		)
1485 		__field(	u64,	flags			)
1486 		__field(	u64,	start			)
1487 		__field(	u64,	max_size		)
1488 		__field(	u64,	size			)
1489 		__field(	int,	bitmap			)
1490 	),
1491 
1492 	TP_fast_assign_btrfs(block_group->fs_info,
1493 		__entry->bg_objectid	= block_group->start;
1494 		__entry->flags		= block_group->flags;
1495 		__entry->start		= cluster->window_start;
1496 		__entry->max_size	= cluster->max_size;
1497 		__entry->size		= size;
1498 		__entry->bitmap		= bitmap;
1499 	),
1500 
1501 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) window_start=%llu "
1502 		  "size=%llu max_size=%llu bitmap=%d",
1503 		  __entry->bg_objectid,
1504 		  __entry->flags,
1505 		  __print_flags((unsigned long)__entry->flags, "|",
1506 				BTRFS_GROUP_FLAGS), __entry->start,
1507 		  __entry->size, __entry->max_size, __entry->bitmap)
1508 );
1509 
1510 struct extent_state;
1511 TRACE_EVENT(alloc_extent_state,
1512 
1513 	TP_PROTO(const struct extent_state *state,
1514 		 gfp_t mask, unsigned long IP),
1515 
1516 	TP_ARGS(state, mask, IP),
1517 
1518 	TP_STRUCT__entry(
1519 		__field(const struct extent_state *, state)
1520 		__field(unsigned long, mask)
1521 		__field(const void*, ip)
1522 	),
1523 
1524 	TP_fast_assign(
1525 		__entry->state	= state,
1526 		__entry->mask	= (__force unsigned long)mask,
1527 		__entry->ip	= (const void *)IP
1528 	),
1529 
1530 	TP_printk("state=%p mask=%s caller=%pS", __entry->state,
1531 		  show_gfp_flags(__entry->mask), __entry->ip)
1532 );
1533 
1534 TRACE_EVENT(free_extent_state,
1535 
1536 	TP_PROTO(const struct extent_state *state, unsigned long IP),
1537 
1538 	TP_ARGS(state, IP),
1539 
1540 	TP_STRUCT__entry(
1541 		__field(const struct extent_state *, state)
1542 		__field(const void*, ip)
1543 	),
1544 
1545 	TP_fast_assign(
1546 		__entry->state	= state,
1547 		__entry->ip = (const void *)IP
1548 	),
1549 
1550 	TP_printk("state=%p caller=%pS", __entry->state, __entry->ip)
1551 );
1552 
1553 DECLARE_EVENT_CLASS(btrfs__work,
1554 
1555 	TP_PROTO(const struct btrfs_work *work),
1556 
1557 	TP_ARGS(work),
1558 
1559 	TP_STRUCT__entry_btrfs(
1560 		__field(	const void *,	work			)
1561 		__field(	const void *,	wq			)
1562 		__field(	const void *,	func			)
1563 		__field(	const void *,	ordered_func		)
1564 		__field(	const void *,	ordered_free		)
1565 		__field(	const void *,	normal_work		)
1566 	),
1567 
1568 	TP_fast_assign_btrfs(btrfs_work_owner(work),
1569 		__entry->work		= work;
1570 		__entry->wq		= work->wq;
1571 		__entry->func		= work->func;
1572 		__entry->ordered_func	= work->ordered_func;
1573 		__entry->ordered_free	= work->ordered_free;
1574 		__entry->normal_work	= &work->normal_work;
1575 	),
1576 
1577 	TP_printk_btrfs("work=%p (normal_work=%p) wq=%p func=%ps ordered_func=%p "
1578 		  "ordered_free=%p",
1579 		  __entry->work, __entry->normal_work, __entry->wq,
1580 		   __entry->func, __entry->ordered_func, __entry->ordered_free)
1581 );
1582 
1583 /*
1584  * For situations when the work is freed, we pass fs_info and a tag that matches
1585  * the address of the work structure so it can be paired with the scheduling
1586  * event. DO NOT add anything here that dereferences wtag.
1587  */
1588 DECLARE_EVENT_CLASS(btrfs__work__done,
1589 
1590 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1591 
1592 	TP_ARGS(fs_info, wtag),
1593 
1594 	TP_STRUCT__entry_btrfs(
1595 		__field(	const void *,	wtag			)
1596 	),
1597 
1598 	TP_fast_assign_btrfs(fs_info,
1599 		__entry->wtag		= wtag;
1600 	),
1601 
1602 	TP_printk_btrfs("work->%p", __entry->wtag)
1603 );
1604 
1605 DEFINE_EVENT(btrfs__work, btrfs_work_queued,
1606 
1607 	TP_PROTO(const struct btrfs_work *work),
1608 
1609 	TP_ARGS(work)
1610 );
1611 
1612 DEFINE_EVENT(btrfs__work, btrfs_work_sched,
1613 
1614 	TP_PROTO(const struct btrfs_work *work),
1615 
1616 	TP_ARGS(work)
1617 );
1618 
1619 DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
1620 
1621 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1622 
1623 	TP_ARGS(fs_info, wtag)
1624 );
1625 
1626 DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
1627 
1628 	TP_PROTO(const struct btrfs_work *work),
1629 
1630 	TP_ARGS(work)
1631 );
1632 
1633 DECLARE_EVENT_CLASS(btrfs_workqueue,
1634 
1635 	TP_PROTO(const struct btrfs_workqueue *wq, const char *name),
1636 
1637 	TP_ARGS(wq, name),
1638 
1639 	TP_STRUCT__entry_btrfs(
1640 		__field(	const void *,	wq			)
1641 		__string(	name,	name			)
1642 	),
1643 
1644 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1645 		__entry->wq		= wq;
1646 		__assign_str(name, name);
1647 	),
1648 
1649 	TP_printk_btrfs("name=%s wq=%p", __get_str(name),
1650 		  __entry->wq)
1651 );
1652 
1653 DEFINE_EVENT(btrfs_workqueue, btrfs_workqueue_alloc,
1654 
1655 	TP_PROTO(const struct btrfs_workqueue *wq, const char *name),
1656 
1657 	TP_ARGS(wq, name)
1658 );
1659 
1660 DECLARE_EVENT_CLASS(btrfs_workqueue_done,
1661 
1662 	TP_PROTO(const struct btrfs_workqueue *wq),
1663 
1664 	TP_ARGS(wq),
1665 
1666 	TP_STRUCT__entry_btrfs(
1667 		__field(	const void *,	wq		)
1668 	),
1669 
1670 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1671 		__entry->wq		= wq;
1672 	),
1673 
1674 	TP_printk_btrfs("wq=%p", __entry->wq)
1675 );
1676 
1677 DEFINE_EVENT(btrfs_workqueue_done, btrfs_workqueue_destroy,
1678 
1679 	TP_PROTO(const struct btrfs_workqueue *wq),
1680 
1681 	TP_ARGS(wq)
1682 );
1683 
1684 #define BTRFS_QGROUP_OPERATIONS				\
1685 	{ QGROUP_RESERVE,	"reserve"	},	\
1686 	{ QGROUP_RELEASE,	"release"	},	\
1687 	{ QGROUP_FREE,		"free"		}
1688 
1689 DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
1690 
1691 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1692 		 u64 reserved, int op),
1693 
1694 	TP_ARGS(inode, start, len, reserved, op),
1695 
1696 	TP_STRUCT__entry_btrfs(
1697 		__field(	u64,		rootid		)
1698 		__field(	u64,		ino		)
1699 		__field(	u64,		start		)
1700 		__field(	u64,		len		)
1701 		__field(	u64,		reserved	)
1702 		__field(	int,		op		)
1703 	),
1704 
1705 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
1706 		__entry->rootid		=
1707 			BTRFS_I(inode)->root->root_key.objectid;
1708 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
1709 		__entry->start		= start;
1710 		__entry->len		= len;
1711 		__entry->reserved	= reserved;
1712 		__entry->op		= op;
1713 	),
1714 
1715 	TP_printk_btrfs("root=%llu ino=%llu start=%llu len=%llu reserved=%llu op=%s",
1716 		  __entry->rootid, __entry->ino, __entry->start, __entry->len,
1717 		  __entry->reserved,
1718 		  __print_flags((unsigned long)__entry->op, "",
1719 				BTRFS_QGROUP_OPERATIONS)
1720 	)
1721 );
1722 
1723 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_reserve_data,
1724 
1725 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1726 		 u64 reserved, int op),
1727 
1728 	TP_ARGS(inode, start, len, reserved, op)
1729 );
1730 
1731 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data,
1732 
1733 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1734 		 u64 reserved, int op),
1735 
1736 	TP_ARGS(inode, start, len, reserved, op)
1737 );
1738 
1739 DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
1740 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1741 		 const struct btrfs_qgroup_extent_record *rec),
1742 
1743 	TP_ARGS(fs_info, rec),
1744 
1745 	TP_STRUCT__entry_btrfs(
1746 		__field(	u64,  bytenr		)
1747 		__field(	u64,  num_bytes		)
1748 	),
1749 
1750 	TP_fast_assign_btrfs(fs_info,
1751 		__entry->bytenr		= rec->bytenr,
1752 		__entry->num_bytes	= rec->num_bytes;
1753 	),
1754 
1755 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu",
1756 		  __entry->bytenr, __entry->num_bytes)
1757 );
1758 
1759 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
1760 
1761 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1762 		 const struct btrfs_qgroup_extent_record *rec),
1763 
1764 	TP_ARGS(fs_info, rec)
1765 );
1766 
1767 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent,
1768 
1769 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1770 		 const struct btrfs_qgroup_extent_record *rec),
1771 
1772 	TP_ARGS(fs_info, rec)
1773 );
1774 
1775 TRACE_EVENT(qgroup_num_dirty_extents,
1776 
1777 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid,
1778 		 u64 num_dirty_extents),
1779 
1780 	TP_ARGS(fs_info, transid, num_dirty_extents),
1781 
1782 	TP_STRUCT__entry_btrfs(
1783 		__field(	u64, transid			)
1784 		__field(	u64, num_dirty_extents		)
1785 	),
1786 
1787 	TP_fast_assign_btrfs(fs_info,
1788 		__entry->transid	   = transid;
1789 		__entry->num_dirty_extents = num_dirty_extents;
1790 	),
1791 
1792 	TP_printk_btrfs("transid=%llu num_dirty_extents=%llu",
1793 		__entry->transid, __entry->num_dirty_extents)
1794 );
1795 
1796 TRACE_EVENT(btrfs_qgroup_account_extent,
1797 
1798 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid, u64 bytenr,
1799 		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
1800 
1801 	TP_ARGS(fs_info, transid, bytenr, num_bytes, nr_old_roots,
1802 		nr_new_roots),
1803 
1804 	TP_STRUCT__entry_btrfs(
1805 		__field(	u64,  transid			)
1806 		__field(	u64,  bytenr			)
1807 		__field(	u64,  num_bytes			)
1808 		__field(	u64,  nr_old_roots		)
1809 		__field(	u64,  nr_new_roots		)
1810 	),
1811 
1812 	TP_fast_assign_btrfs(fs_info,
1813 		__entry->transid	= transid;
1814 		__entry->bytenr		= bytenr;
1815 		__entry->num_bytes	= num_bytes;
1816 		__entry->nr_old_roots	= nr_old_roots;
1817 		__entry->nr_new_roots	= nr_new_roots;
1818 	),
1819 
1820 	TP_printk_btrfs(
1821 "transid=%llu bytenr=%llu num_bytes=%llu nr_old_roots=%llu nr_new_roots=%llu",
1822 		__entry->transid,
1823 		__entry->bytenr,
1824 		__entry->num_bytes,
1825 		__entry->nr_old_roots,
1826 		__entry->nr_new_roots)
1827 );
1828 
1829 TRACE_EVENT(qgroup_update_counters,
1830 
1831 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1832 		 const struct btrfs_qgroup *qgroup,
1833 		 u64 cur_old_count, u64 cur_new_count),
1834 
1835 	TP_ARGS(fs_info, qgroup, cur_old_count, cur_new_count),
1836 
1837 	TP_STRUCT__entry_btrfs(
1838 		__field(	u64,  qgid			)
1839 		__field(	u64,  old_rfer			)
1840 		__field(	u64,  old_excl			)
1841 		__field(	u64,  cur_old_count		)
1842 		__field(	u64,  cur_new_count		)
1843 	),
1844 
1845 	TP_fast_assign_btrfs(fs_info,
1846 		__entry->qgid		= qgroup->qgroupid;
1847 		__entry->old_rfer	= qgroup->rfer;
1848 		__entry->old_excl	= qgroup->excl;
1849 		__entry->cur_old_count	= cur_old_count;
1850 		__entry->cur_new_count	= cur_new_count;
1851 	),
1852 
1853 	TP_printk_btrfs("qgid=%llu old_rfer=%llu old_excl=%llu cur_old_count=%llu cur_new_count=%llu",
1854 		  __entry->qgid, __entry->old_rfer, __entry->old_excl,
1855 		  __entry->cur_old_count, __entry->cur_new_count)
1856 );
1857 
1858 TRACE_EVENT(qgroup_update_reserve,
1859 
1860 	TP_PROTO(struct btrfs_fs_info *fs_info, struct btrfs_qgroup *qgroup,
1861 		 s64 diff, int type),
1862 
1863 	TP_ARGS(fs_info, qgroup, diff, type),
1864 
1865 	TP_STRUCT__entry_btrfs(
1866 		__field(	u64,	qgid			)
1867 		__field(	u64,	cur_reserved		)
1868 		__field(	s64,	diff			)
1869 		__field(	int,	type			)
1870 	),
1871 
1872 	TP_fast_assign_btrfs(fs_info,
1873 		__entry->qgid		= qgroup->qgroupid;
1874 		__entry->cur_reserved	= qgroup->rsv.values[type];
1875 		__entry->diff		= diff;
1876 		__entry->type		= type;
1877 	),
1878 
1879 	TP_printk_btrfs("qgid=%llu type=%s cur_reserved=%llu diff=%lld",
1880 		__entry->qgid, __print_symbolic(__entry->type, QGROUP_RSV_TYPES),
1881 		__entry->cur_reserved, __entry->diff)
1882 );
1883 
1884 TRACE_EVENT(qgroup_meta_reserve,
1885 
1886 	TP_PROTO(struct btrfs_root *root, s64 diff, int type),
1887 
1888 	TP_ARGS(root, diff, type),
1889 
1890 	TP_STRUCT__entry_btrfs(
1891 		__field(	u64,	refroot			)
1892 		__field(	s64,	diff			)
1893 		__field(	int,	type			)
1894 	),
1895 
1896 	TP_fast_assign_btrfs(root->fs_info,
1897 		__entry->refroot	= root->root_key.objectid;
1898 		__entry->diff		= diff;
1899 		__entry->type		= type;
1900 	),
1901 
1902 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1903 		show_root_type(__entry->refroot),
1904 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1905 );
1906 
1907 TRACE_EVENT(qgroup_meta_convert,
1908 
1909 	TP_PROTO(struct btrfs_root *root, s64 diff),
1910 
1911 	TP_ARGS(root, diff),
1912 
1913 	TP_STRUCT__entry_btrfs(
1914 		__field(	u64,	refroot			)
1915 		__field(	s64,	diff			)
1916 	),
1917 
1918 	TP_fast_assign_btrfs(root->fs_info,
1919 		__entry->refroot	= root->root_key.objectid;
1920 		__entry->diff		= diff;
1921 	),
1922 
1923 	TP_printk_btrfs("refroot=%llu(%s) type=%s->%s diff=%lld",
1924 		show_root_type(__entry->refroot),
1925 		__print_symbolic(BTRFS_QGROUP_RSV_META_PREALLOC, QGROUP_RSV_TYPES),
1926 		__print_symbolic(BTRFS_QGROUP_RSV_META_PERTRANS, QGROUP_RSV_TYPES),
1927 		__entry->diff)
1928 );
1929 
1930 TRACE_EVENT(qgroup_meta_free_all_pertrans,
1931 
1932 	TP_PROTO(struct btrfs_root *root),
1933 
1934 	TP_ARGS(root),
1935 
1936 	TP_STRUCT__entry_btrfs(
1937 		__field(	u64,	refroot			)
1938 		__field(	s64,	diff			)
1939 		__field(	int,	type			)
1940 	),
1941 
1942 	TP_fast_assign_btrfs(root->fs_info,
1943 		__entry->refroot	= root->root_key.objectid;
1944 		spin_lock(&root->qgroup_meta_rsv_lock);
1945 		__entry->diff		= -(s64)root->qgroup_meta_rsv_pertrans;
1946 		spin_unlock(&root->qgroup_meta_rsv_lock);
1947 		__entry->type		= BTRFS_QGROUP_RSV_META_PERTRANS;
1948 	),
1949 
1950 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1951 		show_root_type(__entry->refroot),
1952 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1953 );
1954 
1955 DECLARE_EVENT_CLASS(btrfs__prelim_ref,
1956 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1957 		 const struct prelim_ref *oldref,
1958 		 const struct prelim_ref *newref, u64 tree_size),
1959 	TP_ARGS(fs_info, newref, oldref, tree_size),
1960 
1961 	TP_STRUCT__entry_btrfs(
1962 		__field(	u64,  root_id		)
1963 		__field(	u64,  objectid		)
1964 		__field(	 u8,  type		)
1965 		__field(	u64,  offset		)
1966 		__field(	int,  level		)
1967 		__field(	int,  old_count		)
1968 		__field(	u64,  parent		)
1969 		__field(	u64,  bytenr		)
1970 		__field(	int,  mod_count		)
1971 		__field(	u64,  tree_size		)
1972 	),
1973 
1974 	TP_fast_assign_btrfs(fs_info,
1975 		__entry->root_id	= oldref->root_id;
1976 		__entry->objectid	= oldref->key_for_search.objectid;
1977 		__entry->type		= oldref->key_for_search.type;
1978 		__entry->offset		= oldref->key_for_search.offset;
1979 		__entry->level		= oldref->level;
1980 		__entry->old_count	= oldref->count;
1981 		__entry->parent		= oldref->parent;
1982 		__entry->bytenr		= oldref->wanted_disk_byte;
1983 		__entry->mod_count	= newref ? newref->count : 0;
1984 		__entry->tree_size	= tree_size;
1985 	),
1986 
1987 	TP_printk_btrfs("root_id=%llu key=[%llu,%u,%llu] level=%d count=[%d+%d=%d] parent=%llu wanted_disk_byte=%llu nodes=%llu",
1988 			__entry->root_id,
1989 			__entry->objectid, __entry->type,
1990 			__entry->offset, __entry->level,
1991 			__entry->old_count, __entry->mod_count,
1992 			__entry->old_count + __entry->mod_count,
1993 			__entry->parent,
1994 			__entry->bytenr,
1995 			__entry->tree_size)
1996 );
1997 
1998 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_merge,
1999 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2000 		 const struct prelim_ref *oldref,
2001 		 const struct prelim_ref *newref, u64 tree_size),
2002 	TP_ARGS(fs_info, oldref, newref, tree_size)
2003 );
2004 
2005 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_insert,
2006 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2007 		 const struct prelim_ref *oldref,
2008 		 const struct prelim_ref *newref, u64 tree_size),
2009 	TP_ARGS(fs_info, oldref, newref, tree_size)
2010 );
2011 
2012 TRACE_EVENT(btrfs_inode_mod_outstanding_extents,
2013 	TP_PROTO(const struct btrfs_root *root, u64 ino, int mod, unsigned outstanding),
2014 
2015 	TP_ARGS(root, ino, mod, outstanding),
2016 
2017 	TP_STRUCT__entry_btrfs(
2018 		__field(	u64, root_objectid	)
2019 		__field(	u64, ino		)
2020 		__field(	int, mod		)
2021 		__field(	unsigned, outstanding	)
2022 	),
2023 
2024 	TP_fast_assign_btrfs(root->fs_info,
2025 		__entry->root_objectid	= root->root_key.objectid;
2026 		__entry->ino		= ino;
2027 		__entry->mod		= mod;
2028 		__entry->outstanding    = outstanding;
2029 	),
2030 
2031 	TP_printk_btrfs("root=%llu(%s) ino=%llu mod=%d outstanding=%u",
2032 			show_root_type(__entry->root_objectid),
2033 			__entry->ino, __entry->mod, __entry->outstanding)
2034 );
2035 
2036 DECLARE_EVENT_CLASS(btrfs__block_group,
2037 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2038 
2039 	TP_ARGS(bg_cache),
2040 
2041 	TP_STRUCT__entry_btrfs(
2042 		__field(	u64,	bytenr		)
2043 		__field(	u64,	len		)
2044 		__field(	u64,	used		)
2045 		__field(	u64,	flags		)
2046 	),
2047 
2048 	TP_fast_assign_btrfs(bg_cache->fs_info,
2049 		__entry->bytenr = bg_cache->start,
2050 		__entry->len	= bg_cache->length,
2051 		__entry->used	= bg_cache->used;
2052 		__entry->flags	= bg_cache->flags;
2053 	),
2054 
2055 	TP_printk_btrfs("bg bytenr=%llu len=%llu used=%llu flags=%llu(%s)",
2056 		__entry->bytenr, __entry->len, __entry->used, __entry->flags,
2057 		__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS))
2058 );
2059 
2060 DEFINE_EVENT(btrfs__block_group, btrfs_remove_block_group,
2061 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2062 
2063 	TP_ARGS(bg_cache)
2064 );
2065 
2066 DEFINE_EVENT(btrfs__block_group, btrfs_add_unused_block_group,
2067 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2068 
2069 	TP_ARGS(bg_cache)
2070 );
2071 
2072 DEFINE_EVENT(btrfs__block_group, btrfs_add_reclaim_block_group,
2073 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2074 
2075 	TP_ARGS(bg_cache)
2076 );
2077 
2078 DEFINE_EVENT(btrfs__block_group, btrfs_reclaim_block_group,
2079 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2080 
2081 	TP_ARGS(bg_cache)
2082 );
2083 
2084 DEFINE_EVENT(btrfs__block_group, btrfs_skip_unused_block_group,
2085 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2086 
2087 	TP_ARGS(bg_cache)
2088 );
2089 
2090 TRACE_EVENT(btrfs_set_extent_bit,
2091 	TP_PROTO(const struct extent_io_tree *tree,
2092 		 u64 start, u64 len, unsigned set_bits),
2093 
2094 	TP_ARGS(tree, start, len, set_bits),
2095 
2096 	TP_STRUCT__entry_btrfs(
2097 		__field(	unsigned,	owner	)
2098 		__field(	u64,		ino	)
2099 		__field(	u64,		rootid	)
2100 		__field(	u64,		start	)
2101 		__field(	u64,		len	)
2102 		__field(	unsigned,	set_bits)
2103 	),
2104 
2105 	TP_fast_assign_btrfs(tree->fs_info,
2106 		__entry->owner = tree->owner;
2107 		if (tree->inode) {
2108 			const struct btrfs_inode *inode = tree->inode;
2109 
2110 			__entry->ino	= btrfs_ino(inode);
2111 			__entry->rootid	= inode->root->root_key.objectid;
2112 		} else {
2113 			__entry->ino	= 0;
2114 			__entry->rootid	= 0;
2115 		}
2116 		__entry->start		= start;
2117 		__entry->len		= len;
2118 		__entry->set_bits	= set_bits;
2119 	),
2120 
2121 	TP_printk_btrfs(
2122 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s",
2123 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2124 		__entry->rootid, __entry->start, __entry->len,
2125 		__print_flags(__entry->set_bits, "|", EXTENT_FLAGS))
2126 );
2127 
2128 TRACE_EVENT(btrfs_clear_extent_bit,
2129 	TP_PROTO(const struct extent_io_tree *tree,
2130 		 u64 start, u64 len, unsigned clear_bits),
2131 
2132 	TP_ARGS(tree, start, len, clear_bits),
2133 
2134 	TP_STRUCT__entry_btrfs(
2135 		__field(	unsigned,	owner	)
2136 		__field(	u64,		ino	)
2137 		__field(	u64,		rootid	)
2138 		__field(	u64,		start	)
2139 		__field(	u64,		len	)
2140 		__field(	unsigned,	clear_bits)
2141 	),
2142 
2143 	TP_fast_assign_btrfs(tree->fs_info,
2144 		__entry->owner = tree->owner;
2145 		if (tree->inode) {
2146 			const struct btrfs_inode *inode = tree->inode;
2147 
2148 			__entry->ino	= btrfs_ino(inode);
2149 			__entry->rootid	= inode->root->root_key.objectid;
2150 		} else {
2151 			__entry->ino	= 0;
2152 			__entry->rootid	= 0;
2153 		}
2154 		__entry->start		= start;
2155 		__entry->len		= len;
2156 		__entry->clear_bits	= clear_bits;
2157 	),
2158 
2159 	TP_printk_btrfs(
2160 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu clear_bits=%s",
2161 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2162 		__entry->rootid, __entry->start, __entry->len,
2163 		__print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
2164 );
2165 
2166 TRACE_EVENT(btrfs_convert_extent_bit,
2167 	TP_PROTO(const struct extent_io_tree *tree,
2168 		 u64 start, u64 len, unsigned set_bits, unsigned clear_bits),
2169 
2170 	TP_ARGS(tree, start, len, set_bits, clear_bits),
2171 
2172 	TP_STRUCT__entry_btrfs(
2173 		__field(	unsigned,	owner	)
2174 		__field(	u64,		ino	)
2175 		__field(	u64,		rootid	)
2176 		__field(	u64,		start	)
2177 		__field(	u64,		len	)
2178 		__field(	unsigned,	set_bits)
2179 		__field(	unsigned,	clear_bits)
2180 	),
2181 
2182 	TP_fast_assign_btrfs(tree->fs_info,
2183 		__entry->owner = tree->owner;
2184 		if (tree->inode) {
2185 			const struct btrfs_inode *inode = tree->inode;
2186 
2187 			__entry->ino	= btrfs_ino(inode);
2188 			__entry->rootid	= inode->root->root_key.objectid;
2189 		} else {
2190 			__entry->ino	= 0;
2191 			__entry->rootid	= 0;
2192 		}
2193 		__entry->start		= start;
2194 		__entry->len		= len;
2195 		__entry->set_bits	= set_bits;
2196 		__entry->clear_bits	= clear_bits;
2197 	),
2198 
2199 	TP_printk_btrfs(
2200 "io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s clear_bits=%s",
2201 		  __print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2202 		  __entry->rootid, __entry->start, __entry->len,
2203 		  __print_flags(__entry->set_bits , "|", EXTENT_FLAGS),
2204 		  __print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
2205 );
2206 
2207 DECLARE_EVENT_CLASS(btrfs_dump_space_info,
2208 	TP_PROTO(struct btrfs_fs_info *fs_info,
2209 		 const struct btrfs_space_info *sinfo),
2210 
2211 	TP_ARGS(fs_info, sinfo),
2212 
2213 	TP_STRUCT__entry_btrfs(
2214 		__field(	u64,	flags			)
2215 		__field(	u64,	total_bytes		)
2216 		__field(	u64,	bytes_used		)
2217 		__field(	u64,	bytes_pinned		)
2218 		__field(	u64,	bytes_reserved		)
2219 		__field(	u64,	bytes_may_use		)
2220 		__field(	u64,	bytes_readonly		)
2221 		__field(	u64,	reclaim_size		)
2222 		__field(	int,	clamp			)
2223 		__field(	u64,	global_reserved		)
2224 		__field(	u64,	trans_reserved		)
2225 		__field(	u64,	delayed_refs_reserved	)
2226 		__field(	u64,	delayed_reserved	)
2227 		__field(	u64,	free_chunk_space	)
2228 		__field(	u64,	delalloc_bytes		)
2229 		__field(	u64,	ordered_bytes		)
2230 	),
2231 
2232 	TP_fast_assign_btrfs(fs_info,
2233 		__entry->flags			=	sinfo->flags;
2234 		__entry->total_bytes		=	sinfo->total_bytes;
2235 		__entry->bytes_used		=	sinfo->bytes_used;
2236 		__entry->bytes_pinned		=	sinfo->bytes_pinned;
2237 		__entry->bytes_reserved		=	sinfo->bytes_reserved;
2238 		__entry->bytes_may_use		=	sinfo->bytes_may_use;
2239 		__entry->bytes_readonly		=	sinfo->bytes_readonly;
2240 		__entry->reclaim_size		=	sinfo->reclaim_size;
2241 		__entry->clamp			=	sinfo->clamp;
2242 		__entry->global_reserved	=	fs_info->global_block_rsv.reserved;
2243 		__entry->trans_reserved		=	fs_info->trans_block_rsv.reserved;
2244 		__entry->delayed_refs_reserved	=	fs_info->delayed_refs_rsv.reserved;
2245 		__entry->delayed_reserved	=	fs_info->delayed_block_rsv.reserved;
2246 		__entry->free_chunk_space	=	atomic64_read(&fs_info->free_chunk_space);
2247 		__entry->delalloc_bytes		=	percpu_counter_sum_positive(&fs_info->delalloc_bytes);
2248 		__entry->ordered_bytes		=	percpu_counter_sum_positive(&fs_info->ordered_bytes);
2249 	),
2250 
2251 	TP_printk_btrfs("flags=%s total_bytes=%llu bytes_used=%llu "
2252 			"bytes_pinned=%llu bytes_reserved=%llu "
2253 			"bytes_may_use=%llu bytes_readonly=%llu "
2254 			"reclaim_size=%llu clamp=%d global_reserved=%llu "
2255 			"trans_reserved=%llu delayed_refs_reserved=%llu "
2256 			"delayed_reserved=%llu chunk_free_space=%llu "
2257 			"delalloc_bytes=%llu ordered_bytes=%llu",
2258 			__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS),
2259 			__entry->total_bytes, __entry->bytes_used,
2260 			__entry->bytes_pinned, __entry->bytes_reserved,
2261 			__entry->bytes_may_use, __entry->bytes_readonly,
2262 			__entry->reclaim_size, __entry->clamp,
2263 			__entry->global_reserved, __entry->trans_reserved,
2264 			__entry->delayed_refs_reserved,
2265 			__entry->delayed_reserved, __entry->free_chunk_space,
2266 			__entry->delalloc_bytes, __entry->ordered_bytes)
2267 );
2268 
2269 DEFINE_EVENT(btrfs_dump_space_info, btrfs_done_preemptive_reclaim,
2270 	TP_PROTO(struct btrfs_fs_info *fs_info,
2271 		 const struct btrfs_space_info *sinfo),
2272 	TP_ARGS(fs_info, sinfo)
2273 );
2274 
2275 DEFINE_EVENT(btrfs_dump_space_info, btrfs_fail_all_tickets,
2276 	TP_PROTO(struct btrfs_fs_info *fs_info,
2277 		 const struct btrfs_space_info *sinfo),
2278 	TP_ARGS(fs_info, sinfo)
2279 );
2280 
2281 TRACE_EVENT(btrfs_reserve_ticket,
2282 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 bytes,
2283 		 u64 start_ns, int flush, int error),
2284 
2285 	TP_ARGS(fs_info, flags, bytes, start_ns, flush, error),
2286 
2287 	TP_STRUCT__entry_btrfs(
2288 		__field(	u64,	flags		)
2289 		__field(	u64,	bytes		)
2290 		__field(	u64,	start_ns	)
2291 		__field(	int,	flush		)
2292 		__field(	int,	error		)
2293 	),
2294 
2295 	TP_fast_assign_btrfs(fs_info,
2296 		__entry->flags		= flags;
2297 		__entry->bytes		= bytes;
2298 		__entry->start_ns	= start_ns;
2299 		__entry->flush		= flush;
2300 		__entry->error		= error;
2301 	),
2302 
2303 	TP_printk_btrfs("flags=%s bytes=%llu start_ns=%llu flush=%s error=%d",
2304 			__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS),
2305 			__entry->bytes, __entry->start_ns,
2306 			__print_symbolic(__entry->flush, FLUSH_ACTIONS),
2307 			__entry->error)
2308 );
2309 
2310 DECLARE_EVENT_CLASS(btrfs_sleep_tree_lock,
2311 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2312 
2313 	TP_ARGS(eb, start_ns),
2314 
2315 	TP_STRUCT__entry_btrfs(
2316 		__field(	u64,	block		)
2317 		__field(	u64,	generation	)
2318 		__field(	u64,	start_ns	)
2319 		__field(	u64,	end_ns		)
2320 		__field(	u64,	diff_ns		)
2321 		__field(	u64,	owner		)
2322 		__field(	int,	is_log_tree	)
2323 	),
2324 
2325 	TP_fast_assign_btrfs(eb->fs_info,
2326 		__entry->block		= eb->start;
2327 		__entry->generation	= btrfs_header_generation(eb);
2328 		__entry->start_ns	= start_ns;
2329 		__entry->end_ns		= ktime_get_ns();
2330 		__entry->diff_ns	= __entry->end_ns - start_ns;
2331 		__entry->owner		= btrfs_header_owner(eb);
2332 		__entry->is_log_tree	= (eb->log_index >= 0);
2333 	),
2334 
2335 	TP_printk_btrfs(
2336 "block=%llu generation=%llu start_ns=%llu end_ns=%llu diff_ns=%llu owner=%llu is_log_tree=%d",
2337 		__entry->block, __entry->generation,
2338 		__entry->start_ns, __entry->end_ns, __entry->diff_ns,
2339 		__entry->owner, __entry->is_log_tree)
2340 );
2341 
2342 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_read_lock,
2343 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2344 
2345 	TP_ARGS(eb, start_ns)
2346 );
2347 
2348 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_lock,
2349 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2350 
2351 	TP_ARGS(eb, start_ns)
2352 );
2353 
2354 DECLARE_EVENT_CLASS(btrfs_locking_events,
2355 	TP_PROTO(const struct extent_buffer *eb),
2356 
2357 	TP_ARGS(eb),
2358 
2359 	TP_STRUCT__entry_btrfs(
2360 		__field(	u64,	block		)
2361 		__field(	u64,	generation	)
2362 		__field(	u64,	owner		)
2363 		__field(	int,	is_log_tree	)
2364 	),
2365 
2366 	TP_fast_assign_btrfs(eb->fs_info,
2367 		__entry->block		= eb->start;
2368 		__entry->generation	= btrfs_header_generation(eb);
2369 		__entry->owner		= btrfs_header_owner(eb);
2370 		__entry->is_log_tree	= (eb->log_index >= 0);
2371 	),
2372 
2373 	TP_printk_btrfs("block=%llu generation=%llu owner=%llu is_log_tree=%d",
2374 		__entry->block, __entry->generation,
2375 		__entry->owner, __entry->is_log_tree)
2376 );
2377 
2378 #define DEFINE_BTRFS_LOCK_EVENT(name)				\
2379 DEFINE_EVENT(btrfs_locking_events, name,			\
2380 		TP_PROTO(const struct extent_buffer *eb),	\
2381 								\
2382 		TP_ARGS(eb)					\
2383 )
2384 
2385 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_unlock);
2386 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock);
2387 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock_blocking);
2388 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_read);
2389 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_write);
2390 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_read_lock);
2391 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_write_lock);
2392 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_lock_atomic);
2393 
2394 DECLARE_EVENT_CLASS(btrfs__space_info_update,
2395 
2396 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2397 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2398 
2399 	TP_ARGS(fs_info, sinfo, old, diff),
2400 
2401 	TP_STRUCT__entry_btrfs(
2402 		__field(	u64,	type		)
2403 		__field(	u64,	old		)
2404 		__field(	s64,	diff		)
2405 	),
2406 
2407 	TP_fast_assign_btrfs(fs_info,
2408 		__entry->type	= sinfo->flags;
2409 		__entry->old	= old;
2410 		__entry->diff	= diff;
2411 	),
2412 	TP_printk_btrfs("type=%s old=%llu diff=%lld",
2413 		__print_flags(__entry->type, "|", BTRFS_GROUP_FLAGS),
2414 		__entry->old, __entry->diff)
2415 );
2416 
2417 DEFINE_EVENT(btrfs__space_info_update, update_bytes_may_use,
2418 
2419 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2420 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2421 
2422 	TP_ARGS(fs_info, sinfo, old, diff)
2423 );
2424 
2425 DEFINE_EVENT(btrfs__space_info_update, update_bytes_pinned,
2426 
2427 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2428 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2429 
2430 	TP_ARGS(fs_info, sinfo, old, diff)
2431 );
2432 
2433 DECLARE_EVENT_CLASS(btrfs_raid56_bio,
2434 
2435 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2436 		 const struct bio *bio,
2437 		 const struct raid56_bio_trace_info *trace_info),
2438 
2439 	TP_ARGS(rbio, bio, trace_info),
2440 
2441 	TP_STRUCT__entry_btrfs(
2442 		__field(	u64,	full_stripe	)
2443 		__field(	u64,	physical	)
2444 		__field(	u64,	devid		)
2445 		__field(	u32,	offset		)
2446 		__field(	u32,	len		)
2447 		__field(	u8,	opf		)
2448 		__field(	u8,	total_stripes	)
2449 		__field(	u8,	real_stripes	)
2450 		__field(	u8,	nr_data		)
2451 		__field(	u8,	stripe_nr	)
2452 	),
2453 
2454 	TP_fast_assign_btrfs(rbio->bioc->fs_info,
2455 		__entry->full_stripe	= rbio->bioc->full_stripe_logical;
2456 		__entry->physical	= bio->bi_iter.bi_sector << SECTOR_SHIFT;
2457 		__entry->len		= bio->bi_iter.bi_size;
2458 		__entry->opf		= bio_op(bio);
2459 		__entry->devid		= trace_info->devid;
2460 		__entry->offset		= trace_info->offset;
2461 		__entry->stripe_nr	= trace_info->stripe_nr;
2462 		__entry->total_stripes	= rbio->bioc->num_stripes;
2463 		__entry->real_stripes	= rbio->real_stripes;
2464 		__entry->nr_data	= rbio->nr_data;
2465 	),
2466 	/*
2467 	 * For type output, we need to output things like "DATA1"
2468 	 * (the first data stripe), "DATA2" (the second data stripe),
2469 	 * "PQ1" (P stripe),"PQ2" (Q stripe), "REPLACE0" (replace target device).
2470 	 */
2471 	TP_printk_btrfs(
2472 "full_stripe=%llu devid=%lld type=%s%d offset=%d opf=0x%x physical=%llu len=%u",
2473 		__entry->full_stripe, __entry->devid,
2474 		(__entry->stripe_nr < __entry->nr_data) ? "DATA" :
2475 			((__entry->stripe_nr < __entry->real_stripes) ? "PQ" :
2476 			 "REPLACE"),
2477 		(__entry->stripe_nr < __entry->nr_data) ?
2478 			(__entry->stripe_nr + 1) :
2479 			((__entry->stripe_nr < __entry->real_stripes) ?
2480 			 (__entry->stripe_nr - __entry->nr_data + 1) : 0),
2481 		__entry->offset, __entry->opf, __entry->physical, __entry->len)
2482 );
2483 
2484 DEFINE_EVENT(btrfs_raid56_bio, raid56_read,
2485 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2486 		 const struct bio *bio,
2487 		 const struct raid56_bio_trace_info *trace_info),
2488 
2489 	TP_ARGS(rbio, bio, trace_info)
2490 );
2491 
2492 DEFINE_EVENT(btrfs_raid56_bio, raid56_write,
2493 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2494 		 const struct bio *bio,
2495 		 const struct raid56_bio_trace_info *trace_info),
2496 
2497 	TP_ARGS(rbio, bio, trace_info)
2498 );
2499 
2500 #endif /* _TRACE_BTRFS_H */
2501 
2502 /* This part must be outside protection */
2503 #include <trace/define_trace.h>
2504