xref: /linux/include/trace/events/btrfs.h (revision 8e07e0e3964ca4e23ce7b68e2096fe660a888942)
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 *,	normal_work		)
1565 	),
1566 
1567 	TP_fast_assign_btrfs(btrfs_work_owner(work),
1568 		__entry->work		= work;
1569 		__entry->wq		= work->wq;
1570 		__entry->func		= work->func;
1571 		__entry->ordered_func	= work->ordered_func;
1572 		__entry->normal_work	= &work->normal_work;
1573 	),
1574 
1575 	TP_printk_btrfs("work=%p (normal_work=%p) wq=%p func=%ps ordered_func=%p",
1576 		  __entry->work, __entry->normal_work, __entry->wq,
1577 		   __entry->func, __entry->ordered_func)
1578 );
1579 
1580 /*
1581  * For situations when the work is freed, we pass fs_info and a tag that matches
1582  * the address of the work structure so it can be paired with the scheduling
1583  * event. DO NOT add anything here that dereferences wtag.
1584  */
1585 DECLARE_EVENT_CLASS(btrfs__work__done,
1586 
1587 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1588 
1589 	TP_ARGS(fs_info, wtag),
1590 
1591 	TP_STRUCT__entry_btrfs(
1592 		__field(	const void *,	wtag			)
1593 	),
1594 
1595 	TP_fast_assign_btrfs(fs_info,
1596 		__entry->wtag		= wtag;
1597 	),
1598 
1599 	TP_printk_btrfs("work->%p", __entry->wtag)
1600 );
1601 
1602 DEFINE_EVENT(btrfs__work, btrfs_work_queued,
1603 
1604 	TP_PROTO(const struct btrfs_work *work),
1605 
1606 	TP_ARGS(work)
1607 );
1608 
1609 DEFINE_EVENT(btrfs__work, btrfs_work_sched,
1610 
1611 	TP_PROTO(const struct btrfs_work *work),
1612 
1613 	TP_ARGS(work)
1614 );
1615 
1616 DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
1617 
1618 	TP_PROTO(const struct btrfs_fs_info *fs_info, const void *wtag),
1619 
1620 	TP_ARGS(fs_info, wtag)
1621 );
1622 
1623 DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
1624 
1625 	TP_PROTO(const struct btrfs_work *work),
1626 
1627 	TP_ARGS(work)
1628 );
1629 
1630 DECLARE_EVENT_CLASS(btrfs_workqueue,
1631 
1632 	TP_PROTO(const struct btrfs_workqueue *wq, const char *name),
1633 
1634 	TP_ARGS(wq, name),
1635 
1636 	TP_STRUCT__entry_btrfs(
1637 		__field(	const void *,	wq			)
1638 		__string(	name,	name			)
1639 	),
1640 
1641 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1642 		__entry->wq		= wq;
1643 		__assign_str(name, name);
1644 	),
1645 
1646 	TP_printk_btrfs("name=%s wq=%p", __get_str(name),
1647 		  __entry->wq)
1648 );
1649 
1650 DEFINE_EVENT(btrfs_workqueue, btrfs_workqueue_alloc,
1651 
1652 	TP_PROTO(const struct btrfs_workqueue *wq, const char *name),
1653 
1654 	TP_ARGS(wq, name)
1655 );
1656 
1657 DECLARE_EVENT_CLASS(btrfs_workqueue_done,
1658 
1659 	TP_PROTO(const struct btrfs_workqueue *wq),
1660 
1661 	TP_ARGS(wq),
1662 
1663 	TP_STRUCT__entry_btrfs(
1664 		__field(	const void *,	wq		)
1665 	),
1666 
1667 	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
1668 		__entry->wq		= wq;
1669 	),
1670 
1671 	TP_printk_btrfs("wq=%p", __entry->wq)
1672 );
1673 
1674 DEFINE_EVENT(btrfs_workqueue_done, btrfs_workqueue_destroy,
1675 
1676 	TP_PROTO(const struct btrfs_workqueue *wq),
1677 
1678 	TP_ARGS(wq)
1679 );
1680 
1681 #define BTRFS_QGROUP_OPERATIONS				\
1682 	{ QGROUP_RESERVE,	"reserve"	},	\
1683 	{ QGROUP_RELEASE,	"release"	},	\
1684 	{ QGROUP_FREE,		"free"		}
1685 
1686 DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
1687 
1688 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1689 		 u64 reserved, int op),
1690 
1691 	TP_ARGS(inode, start, len, reserved, op),
1692 
1693 	TP_STRUCT__entry_btrfs(
1694 		__field(	u64,		rootid		)
1695 		__field(	u64,		ino		)
1696 		__field(	u64,		start		)
1697 		__field(	u64,		len		)
1698 		__field(	u64,		reserved	)
1699 		__field(	int,		op		)
1700 	),
1701 
1702 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
1703 		__entry->rootid		=
1704 			BTRFS_I(inode)->root->root_key.objectid;
1705 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
1706 		__entry->start		= start;
1707 		__entry->len		= len;
1708 		__entry->reserved	= reserved;
1709 		__entry->op		= op;
1710 	),
1711 
1712 	TP_printk_btrfs("root=%llu ino=%llu start=%llu len=%llu reserved=%llu op=%s",
1713 		  __entry->rootid, __entry->ino, __entry->start, __entry->len,
1714 		  __entry->reserved,
1715 		  __print_flags((unsigned long)__entry->op, "",
1716 				BTRFS_QGROUP_OPERATIONS)
1717 	)
1718 );
1719 
1720 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_reserve_data,
1721 
1722 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1723 		 u64 reserved, int op),
1724 
1725 	TP_ARGS(inode, start, len, reserved, op)
1726 );
1727 
1728 DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data,
1729 
1730 	TP_PROTO(const struct inode *inode, u64 start, u64 len,
1731 		 u64 reserved, int op),
1732 
1733 	TP_ARGS(inode, start, len, reserved, op)
1734 );
1735 
1736 DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
1737 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1738 		 const struct btrfs_qgroup_extent_record *rec),
1739 
1740 	TP_ARGS(fs_info, rec),
1741 
1742 	TP_STRUCT__entry_btrfs(
1743 		__field(	u64,  bytenr		)
1744 		__field(	u64,  num_bytes		)
1745 	),
1746 
1747 	TP_fast_assign_btrfs(fs_info,
1748 		__entry->bytenr		= rec->bytenr,
1749 		__entry->num_bytes	= rec->num_bytes;
1750 	),
1751 
1752 	TP_printk_btrfs("bytenr=%llu num_bytes=%llu",
1753 		  __entry->bytenr, __entry->num_bytes)
1754 );
1755 
1756 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
1757 
1758 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1759 		 const struct btrfs_qgroup_extent_record *rec),
1760 
1761 	TP_ARGS(fs_info, rec)
1762 );
1763 
1764 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent,
1765 
1766 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1767 		 const struct btrfs_qgroup_extent_record *rec),
1768 
1769 	TP_ARGS(fs_info, rec)
1770 );
1771 
1772 TRACE_EVENT(qgroup_num_dirty_extents,
1773 
1774 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid,
1775 		 u64 num_dirty_extents),
1776 
1777 	TP_ARGS(fs_info, transid, num_dirty_extents),
1778 
1779 	TP_STRUCT__entry_btrfs(
1780 		__field(	u64, transid			)
1781 		__field(	u64, num_dirty_extents		)
1782 	),
1783 
1784 	TP_fast_assign_btrfs(fs_info,
1785 		__entry->transid	   = transid;
1786 		__entry->num_dirty_extents = num_dirty_extents;
1787 	),
1788 
1789 	TP_printk_btrfs("transid=%llu num_dirty_extents=%llu",
1790 		__entry->transid, __entry->num_dirty_extents)
1791 );
1792 
1793 TRACE_EVENT(btrfs_qgroup_account_extent,
1794 
1795 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid, u64 bytenr,
1796 		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
1797 
1798 	TP_ARGS(fs_info, transid, bytenr, num_bytes, nr_old_roots,
1799 		nr_new_roots),
1800 
1801 	TP_STRUCT__entry_btrfs(
1802 		__field(	u64,  transid			)
1803 		__field(	u64,  bytenr			)
1804 		__field(	u64,  num_bytes			)
1805 		__field(	u64,  nr_old_roots		)
1806 		__field(	u64,  nr_new_roots		)
1807 	),
1808 
1809 	TP_fast_assign_btrfs(fs_info,
1810 		__entry->transid	= transid;
1811 		__entry->bytenr		= bytenr;
1812 		__entry->num_bytes	= num_bytes;
1813 		__entry->nr_old_roots	= nr_old_roots;
1814 		__entry->nr_new_roots	= nr_new_roots;
1815 	),
1816 
1817 	TP_printk_btrfs(
1818 "transid=%llu bytenr=%llu num_bytes=%llu nr_old_roots=%llu nr_new_roots=%llu",
1819 		__entry->transid,
1820 		__entry->bytenr,
1821 		__entry->num_bytes,
1822 		__entry->nr_old_roots,
1823 		__entry->nr_new_roots)
1824 );
1825 
1826 TRACE_EVENT(qgroup_update_counters,
1827 
1828 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1829 		 const struct btrfs_qgroup *qgroup,
1830 		 u64 cur_old_count, u64 cur_new_count),
1831 
1832 	TP_ARGS(fs_info, qgroup, cur_old_count, cur_new_count),
1833 
1834 	TP_STRUCT__entry_btrfs(
1835 		__field(	u64,  qgid			)
1836 		__field(	u64,  old_rfer			)
1837 		__field(	u64,  old_excl			)
1838 		__field(	u64,  cur_old_count		)
1839 		__field(	u64,  cur_new_count		)
1840 	),
1841 
1842 	TP_fast_assign_btrfs(fs_info,
1843 		__entry->qgid		= qgroup->qgroupid;
1844 		__entry->old_rfer	= qgroup->rfer;
1845 		__entry->old_excl	= qgroup->excl;
1846 		__entry->cur_old_count	= cur_old_count;
1847 		__entry->cur_new_count	= cur_new_count;
1848 	),
1849 
1850 	TP_printk_btrfs("qgid=%llu old_rfer=%llu old_excl=%llu cur_old_count=%llu cur_new_count=%llu",
1851 		  __entry->qgid, __entry->old_rfer, __entry->old_excl,
1852 		  __entry->cur_old_count, __entry->cur_new_count)
1853 );
1854 
1855 TRACE_EVENT(qgroup_update_reserve,
1856 
1857 	TP_PROTO(struct btrfs_fs_info *fs_info, struct btrfs_qgroup *qgroup,
1858 		 s64 diff, int type),
1859 
1860 	TP_ARGS(fs_info, qgroup, diff, type),
1861 
1862 	TP_STRUCT__entry_btrfs(
1863 		__field(	u64,	qgid			)
1864 		__field(	u64,	cur_reserved		)
1865 		__field(	s64,	diff			)
1866 		__field(	int,	type			)
1867 	),
1868 
1869 	TP_fast_assign_btrfs(fs_info,
1870 		__entry->qgid		= qgroup->qgroupid;
1871 		__entry->cur_reserved	= qgroup->rsv.values[type];
1872 		__entry->diff		= diff;
1873 		__entry->type		= type;
1874 	),
1875 
1876 	TP_printk_btrfs("qgid=%llu type=%s cur_reserved=%llu diff=%lld",
1877 		__entry->qgid, __print_symbolic(__entry->type, QGROUP_RSV_TYPES),
1878 		__entry->cur_reserved, __entry->diff)
1879 );
1880 
1881 TRACE_EVENT(qgroup_meta_reserve,
1882 
1883 	TP_PROTO(struct btrfs_root *root, s64 diff, int type),
1884 
1885 	TP_ARGS(root, diff, type),
1886 
1887 	TP_STRUCT__entry_btrfs(
1888 		__field(	u64,	refroot			)
1889 		__field(	s64,	diff			)
1890 		__field(	int,	type			)
1891 	),
1892 
1893 	TP_fast_assign_btrfs(root->fs_info,
1894 		__entry->refroot	= root->root_key.objectid;
1895 		__entry->diff		= diff;
1896 		__entry->type		= type;
1897 	),
1898 
1899 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1900 		show_root_type(__entry->refroot),
1901 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1902 );
1903 
1904 TRACE_EVENT(qgroup_meta_convert,
1905 
1906 	TP_PROTO(struct btrfs_root *root, s64 diff),
1907 
1908 	TP_ARGS(root, diff),
1909 
1910 	TP_STRUCT__entry_btrfs(
1911 		__field(	u64,	refroot			)
1912 		__field(	s64,	diff			)
1913 	),
1914 
1915 	TP_fast_assign_btrfs(root->fs_info,
1916 		__entry->refroot	= root->root_key.objectid;
1917 		__entry->diff		= diff;
1918 	),
1919 
1920 	TP_printk_btrfs("refroot=%llu(%s) type=%s->%s diff=%lld",
1921 		show_root_type(__entry->refroot),
1922 		__print_symbolic(BTRFS_QGROUP_RSV_META_PREALLOC, QGROUP_RSV_TYPES),
1923 		__print_symbolic(BTRFS_QGROUP_RSV_META_PERTRANS, QGROUP_RSV_TYPES),
1924 		__entry->diff)
1925 );
1926 
1927 TRACE_EVENT(qgroup_meta_free_all_pertrans,
1928 
1929 	TP_PROTO(struct btrfs_root *root),
1930 
1931 	TP_ARGS(root),
1932 
1933 	TP_STRUCT__entry_btrfs(
1934 		__field(	u64,	refroot			)
1935 		__field(	s64,	diff			)
1936 		__field(	int,	type			)
1937 	),
1938 
1939 	TP_fast_assign_btrfs(root->fs_info,
1940 		__entry->refroot	= root->root_key.objectid;
1941 		spin_lock(&root->qgroup_meta_rsv_lock);
1942 		__entry->diff		= -(s64)root->qgroup_meta_rsv_pertrans;
1943 		spin_unlock(&root->qgroup_meta_rsv_lock);
1944 		__entry->type		= BTRFS_QGROUP_RSV_META_PERTRANS;
1945 	),
1946 
1947 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1948 		show_root_type(__entry->refroot),
1949 		__print_symbolic(__entry->type, QGROUP_RSV_TYPES), __entry->diff)
1950 );
1951 
1952 DECLARE_EVENT_CLASS(btrfs__prelim_ref,
1953 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1954 		 const struct prelim_ref *oldref,
1955 		 const struct prelim_ref *newref, u64 tree_size),
1956 	TP_ARGS(fs_info, newref, oldref, tree_size),
1957 
1958 	TP_STRUCT__entry_btrfs(
1959 		__field(	u64,  root_id		)
1960 		__field(	u64,  objectid		)
1961 		__field(	 u8,  type		)
1962 		__field(	u64,  offset		)
1963 		__field(	int,  level		)
1964 		__field(	int,  old_count		)
1965 		__field(	u64,  parent		)
1966 		__field(	u64,  bytenr		)
1967 		__field(	int,  mod_count		)
1968 		__field(	u64,  tree_size		)
1969 	),
1970 
1971 	TP_fast_assign_btrfs(fs_info,
1972 		__entry->root_id	= oldref->root_id;
1973 		__entry->objectid	= oldref->key_for_search.objectid;
1974 		__entry->type		= oldref->key_for_search.type;
1975 		__entry->offset		= oldref->key_for_search.offset;
1976 		__entry->level		= oldref->level;
1977 		__entry->old_count	= oldref->count;
1978 		__entry->parent		= oldref->parent;
1979 		__entry->bytenr		= oldref->wanted_disk_byte;
1980 		__entry->mod_count	= newref ? newref->count : 0;
1981 		__entry->tree_size	= tree_size;
1982 	),
1983 
1984 	TP_printk_btrfs("root_id=%llu key=[%llu,%u,%llu] level=%d count=[%d+%d=%d] parent=%llu wanted_disk_byte=%llu nodes=%llu",
1985 			__entry->root_id,
1986 			__entry->objectid, __entry->type,
1987 			__entry->offset, __entry->level,
1988 			__entry->old_count, __entry->mod_count,
1989 			__entry->old_count + __entry->mod_count,
1990 			__entry->parent,
1991 			__entry->bytenr,
1992 			__entry->tree_size)
1993 );
1994 
1995 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_merge,
1996 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1997 		 const struct prelim_ref *oldref,
1998 		 const struct prelim_ref *newref, u64 tree_size),
1999 	TP_ARGS(fs_info, oldref, newref, tree_size)
2000 );
2001 
2002 DEFINE_EVENT(btrfs__prelim_ref, btrfs_prelim_ref_insert,
2003 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2004 		 const struct prelim_ref *oldref,
2005 		 const struct prelim_ref *newref, u64 tree_size),
2006 	TP_ARGS(fs_info, oldref, newref, tree_size)
2007 );
2008 
2009 TRACE_EVENT(btrfs_inode_mod_outstanding_extents,
2010 	TP_PROTO(const struct btrfs_root *root, u64 ino, int mod, unsigned outstanding),
2011 
2012 	TP_ARGS(root, ino, mod, outstanding),
2013 
2014 	TP_STRUCT__entry_btrfs(
2015 		__field(	u64, root_objectid	)
2016 		__field(	u64, ino		)
2017 		__field(	int, mod		)
2018 		__field(	unsigned, outstanding	)
2019 	),
2020 
2021 	TP_fast_assign_btrfs(root->fs_info,
2022 		__entry->root_objectid	= root->root_key.objectid;
2023 		__entry->ino		= ino;
2024 		__entry->mod		= mod;
2025 		__entry->outstanding    = outstanding;
2026 	),
2027 
2028 	TP_printk_btrfs("root=%llu(%s) ino=%llu mod=%d outstanding=%u",
2029 			show_root_type(__entry->root_objectid),
2030 			__entry->ino, __entry->mod, __entry->outstanding)
2031 );
2032 
2033 DECLARE_EVENT_CLASS(btrfs__block_group,
2034 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2035 
2036 	TP_ARGS(bg_cache),
2037 
2038 	TP_STRUCT__entry_btrfs(
2039 		__field(	u64,	bytenr		)
2040 		__field(	u64,	len		)
2041 		__field(	u64,	used		)
2042 		__field(	u64,	flags		)
2043 	),
2044 
2045 	TP_fast_assign_btrfs(bg_cache->fs_info,
2046 		__entry->bytenr = bg_cache->start,
2047 		__entry->len	= bg_cache->length,
2048 		__entry->used	= bg_cache->used;
2049 		__entry->flags	= bg_cache->flags;
2050 	),
2051 
2052 	TP_printk_btrfs("bg bytenr=%llu len=%llu used=%llu flags=%llu(%s)",
2053 		__entry->bytenr, __entry->len, __entry->used, __entry->flags,
2054 		__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS))
2055 );
2056 
2057 DEFINE_EVENT(btrfs__block_group, btrfs_remove_block_group,
2058 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2059 
2060 	TP_ARGS(bg_cache)
2061 );
2062 
2063 DEFINE_EVENT(btrfs__block_group, btrfs_add_unused_block_group,
2064 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2065 
2066 	TP_ARGS(bg_cache)
2067 );
2068 
2069 DEFINE_EVENT(btrfs__block_group, btrfs_add_reclaim_block_group,
2070 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2071 
2072 	TP_ARGS(bg_cache)
2073 );
2074 
2075 DEFINE_EVENT(btrfs__block_group, btrfs_reclaim_block_group,
2076 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2077 
2078 	TP_ARGS(bg_cache)
2079 );
2080 
2081 DEFINE_EVENT(btrfs__block_group, btrfs_skip_unused_block_group,
2082 	TP_PROTO(const struct btrfs_block_group *bg_cache),
2083 
2084 	TP_ARGS(bg_cache)
2085 );
2086 
2087 TRACE_EVENT(btrfs_set_extent_bit,
2088 	TP_PROTO(const struct extent_io_tree *tree,
2089 		 u64 start, u64 len, unsigned set_bits),
2090 
2091 	TP_ARGS(tree, start, len, set_bits),
2092 
2093 	TP_STRUCT__entry_btrfs(
2094 		__field(	unsigned,	owner	)
2095 		__field(	u64,		ino	)
2096 		__field(	u64,		rootid	)
2097 		__field(	u64,		start	)
2098 		__field(	u64,		len	)
2099 		__field(	unsigned,	set_bits)
2100 	),
2101 
2102 	TP_fast_assign_btrfs(tree->fs_info,
2103 		__entry->owner = tree->owner;
2104 		if (tree->inode) {
2105 			const struct btrfs_inode *inode = tree->inode;
2106 
2107 			__entry->ino	= btrfs_ino(inode);
2108 			__entry->rootid	= inode->root->root_key.objectid;
2109 		} else {
2110 			__entry->ino	= 0;
2111 			__entry->rootid	= 0;
2112 		}
2113 		__entry->start		= start;
2114 		__entry->len		= len;
2115 		__entry->set_bits	= set_bits;
2116 	),
2117 
2118 	TP_printk_btrfs(
2119 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s",
2120 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2121 		__entry->rootid, __entry->start, __entry->len,
2122 		__print_flags(__entry->set_bits, "|", EXTENT_FLAGS))
2123 );
2124 
2125 TRACE_EVENT(btrfs_clear_extent_bit,
2126 	TP_PROTO(const struct extent_io_tree *tree,
2127 		 u64 start, u64 len, unsigned clear_bits),
2128 
2129 	TP_ARGS(tree, start, len, clear_bits),
2130 
2131 	TP_STRUCT__entry_btrfs(
2132 		__field(	unsigned,	owner	)
2133 		__field(	u64,		ino	)
2134 		__field(	u64,		rootid	)
2135 		__field(	u64,		start	)
2136 		__field(	u64,		len	)
2137 		__field(	unsigned,	clear_bits)
2138 	),
2139 
2140 	TP_fast_assign_btrfs(tree->fs_info,
2141 		__entry->owner = tree->owner;
2142 		if (tree->inode) {
2143 			const struct btrfs_inode *inode = tree->inode;
2144 
2145 			__entry->ino	= btrfs_ino(inode);
2146 			__entry->rootid	= inode->root->root_key.objectid;
2147 		} else {
2148 			__entry->ino	= 0;
2149 			__entry->rootid	= 0;
2150 		}
2151 		__entry->start		= start;
2152 		__entry->len		= len;
2153 		__entry->clear_bits	= clear_bits;
2154 	),
2155 
2156 	TP_printk_btrfs(
2157 		"io_tree=%s ino=%llu root=%llu start=%llu len=%llu clear_bits=%s",
2158 		__print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2159 		__entry->rootid, __entry->start, __entry->len,
2160 		__print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
2161 );
2162 
2163 TRACE_EVENT(btrfs_convert_extent_bit,
2164 	TP_PROTO(const struct extent_io_tree *tree,
2165 		 u64 start, u64 len, unsigned set_bits, unsigned clear_bits),
2166 
2167 	TP_ARGS(tree, start, len, set_bits, clear_bits),
2168 
2169 	TP_STRUCT__entry_btrfs(
2170 		__field(	unsigned,	owner	)
2171 		__field(	u64,		ino	)
2172 		__field(	u64,		rootid	)
2173 		__field(	u64,		start	)
2174 		__field(	u64,		len	)
2175 		__field(	unsigned,	set_bits)
2176 		__field(	unsigned,	clear_bits)
2177 	),
2178 
2179 	TP_fast_assign_btrfs(tree->fs_info,
2180 		__entry->owner = tree->owner;
2181 		if (tree->inode) {
2182 			const struct btrfs_inode *inode = tree->inode;
2183 
2184 			__entry->ino	= btrfs_ino(inode);
2185 			__entry->rootid	= inode->root->root_key.objectid;
2186 		} else {
2187 			__entry->ino	= 0;
2188 			__entry->rootid	= 0;
2189 		}
2190 		__entry->start		= start;
2191 		__entry->len		= len;
2192 		__entry->set_bits	= set_bits;
2193 		__entry->clear_bits	= clear_bits;
2194 	),
2195 
2196 	TP_printk_btrfs(
2197 "io_tree=%s ino=%llu root=%llu start=%llu len=%llu set_bits=%s clear_bits=%s",
2198 		  __print_symbolic(__entry->owner, IO_TREE_OWNER), __entry->ino,
2199 		  __entry->rootid, __entry->start, __entry->len,
2200 		  __print_flags(__entry->set_bits , "|", EXTENT_FLAGS),
2201 		  __print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
2202 );
2203 
2204 DECLARE_EVENT_CLASS(btrfs_dump_space_info,
2205 	TP_PROTO(struct btrfs_fs_info *fs_info,
2206 		 const struct btrfs_space_info *sinfo),
2207 
2208 	TP_ARGS(fs_info, sinfo),
2209 
2210 	TP_STRUCT__entry_btrfs(
2211 		__field(	u64,	flags			)
2212 		__field(	u64,	total_bytes		)
2213 		__field(	u64,	bytes_used		)
2214 		__field(	u64,	bytes_pinned		)
2215 		__field(	u64,	bytes_reserved		)
2216 		__field(	u64,	bytes_may_use		)
2217 		__field(	u64,	bytes_readonly		)
2218 		__field(	u64,	reclaim_size		)
2219 		__field(	int,	clamp			)
2220 		__field(	u64,	global_reserved		)
2221 		__field(	u64,	trans_reserved		)
2222 		__field(	u64,	delayed_refs_reserved	)
2223 		__field(	u64,	delayed_reserved	)
2224 		__field(	u64,	free_chunk_space	)
2225 		__field(	u64,	delalloc_bytes		)
2226 		__field(	u64,	ordered_bytes		)
2227 	),
2228 
2229 	TP_fast_assign_btrfs(fs_info,
2230 		__entry->flags			=	sinfo->flags;
2231 		__entry->total_bytes		=	sinfo->total_bytes;
2232 		__entry->bytes_used		=	sinfo->bytes_used;
2233 		__entry->bytes_pinned		=	sinfo->bytes_pinned;
2234 		__entry->bytes_reserved		=	sinfo->bytes_reserved;
2235 		__entry->bytes_may_use		=	sinfo->bytes_may_use;
2236 		__entry->bytes_readonly		=	sinfo->bytes_readonly;
2237 		__entry->reclaim_size		=	sinfo->reclaim_size;
2238 		__entry->clamp			=	sinfo->clamp;
2239 		__entry->global_reserved	=	fs_info->global_block_rsv.reserved;
2240 		__entry->trans_reserved		=	fs_info->trans_block_rsv.reserved;
2241 		__entry->delayed_refs_reserved	=	fs_info->delayed_refs_rsv.reserved;
2242 		__entry->delayed_reserved	=	fs_info->delayed_block_rsv.reserved;
2243 		__entry->free_chunk_space	=	atomic64_read(&fs_info->free_chunk_space);
2244 		__entry->delalloc_bytes		=	percpu_counter_sum_positive(&fs_info->delalloc_bytes);
2245 		__entry->ordered_bytes		=	percpu_counter_sum_positive(&fs_info->ordered_bytes);
2246 	),
2247 
2248 	TP_printk_btrfs("flags=%s total_bytes=%llu bytes_used=%llu "
2249 			"bytes_pinned=%llu bytes_reserved=%llu "
2250 			"bytes_may_use=%llu bytes_readonly=%llu "
2251 			"reclaim_size=%llu clamp=%d global_reserved=%llu "
2252 			"trans_reserved=%llu delayed_refs_reserved=%llu "
2253 			"delayed_reserved=%llu chunk_free_space=%llu "
2254 			"delalloc_bytes=%llu ordered_bytes=%llu",
2255 			__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS),
2256 			__entry->total_bytes, __entry->bytes_used,
2257 			__entry->bytes_pinned, __entry->bytes_reserved,
2258 			__entry->bytes_may_use, __entry->bytes_readonly,
2259 			__entry->reclaim_size, __entry->clamp,
2260 			__entry->global_reserved, __entry->trans_reserved,
2261 			__entry->delayed_refs_reserved,
2262 			__entry->delayed_reserved, __entry->free_chunk_space,
2263 			__entry->delalloc_bytes, __entry->ordered_bytes)
2264 );
2265 
2266 DEFINE_EVENT(btrfs_dump_space_info, btrfs_done_preemptive_reclaim,
2267 	TP_PROTO(struct btrfs_fs_info *fs_info,
2268 		 const struct btrfs_space_info *sinfo),
2269 	TP_ARGS(fs_info, sinfo)
2270 );
2271 
2272 DEFINE_EVENT(btrfs_dump_space_info, btrfs_fail_all_tickets,
2273 	TP_PROTO(struct btrfs_fs_info *fs_info,
2274 		 const struct btrfs_space_info *sinfo),
2275 	TP_ARGS(fs_info, sinfo)
2276 );
2277 
2278 TRACE_EVENT(btrfs_reserve_ticket,
2279 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 bytes,
2280 		 u64 start_ns, int flush, int error),
2281 
2282 	TP_ARGS(fs_info, flags, bytes, start_ns, flush, error),
2283 
2284 	TP_STRUCT__entry_btrfs(
2285 		__field(	u64,	flags		)
2286 		__field(	u64,	bytes		)
2287 		__field(	u64,	start_ns	)
2288 		__field(	int,	flush		)
2289 		__field(	int,	error		)
2290 	),
2291 
2292 	TP_fast_assign_btrfs(fs_info,
2293 		__entry->flags		= flags;
2294 		__entry->bytes		= bytes;
2295 		__entry->start_ns	= start_ns;
2296 		__entry->flush		= flush;
2297 		__entry->error		= error;
2298 	),
2299 
2300 	TP_printk_btrfs("flags=%s bytes=%llu start_ns=%llu flush=%s error=%d",
2301 			__print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS),
2302 			__entry->bytes, __entry->start_ns,
2303 			__print_symbolic(__entry->flush, FLUSH_ACTIONS),
2304 			__entry->error)
2305 );
2306 
2307 DECLARE_EVENT_CLASS(btrfs_sleep_tree_lock,
2308 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2309 
2310 	TP_ARGS(eb, start_ns),
2311 
2312 	TP_STRUCT__entry_btrfs(
2313 		__field(	u64,	block		)
2314 		__field(	u64,	generation	)
2315 		__field(	u64,	start_ns	)
2316 		__field(	u64,	end_ns		)
2317 		__field(	u64,	diff_ns		)
2318 		__field(	u64,	owner		)
2319 		__field(	int,	is_log_tree	)
2320 	),
2321 
2322 	TP_fast_assign_btrfs(eb->fs_info,
2323 		__entry->block		= eb->start;
2324 		__entry->generation	= btrfs_header_generation(eb);
2325 		__entry->start_ns	= start_ns;
2326 		__entry->end_ns		= ktime_get_ns();
2327 		__entry->diff_ns	= __entry->end_ns - start_ns;
2328 		__entry->owner		= btrfs_header_owner(eb);
2329 		__entry->is_log_tree	= (eb->log_index >= 0);
2330 	),
2331 
2332 	TP_printk_btrfs(
2333 "block=%llu generation=%llu start_ns=%llu end_ns=%llu diff_ns=%llu owner=%llu is_log_tree=%d",
2334 		__entry->block, __entry->generation,
2335 		__entry->start_ns, __entry->end_ns, __entry->diff_ns,
2336 		__entry->owner, __entry->is_log_tree)
2337 );
2338 
2339 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_read_lock,
2340 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2341 
2342 	TP_ARGS(eb, start_ns)
2343 );
2344 
2345 DEFINE_EVENT(btrfs_sleep_tree_lock, btrfs_tree_lock,
2346 	TP_PROTO(const struct extent_buffer *eb, u64 start_ns),
2347 
2348 	TP_ARGS(eb, start_ns)
2349 );
2350 
2351 DECLARE_EVENT_CLASS(btrfs_locking_events,
2352 	TP_PROTO(const struct extent_buffer *eb),
2353 
2354 	TP_ARGS(eb),
2355 
2356 	TP_STRUCT__entry_btrfs(
2357 		__field(	u64,	block		)
2358 		__field(	u64,	generation	)
2359 		__field(	u64,	owner		)
2360 		__field(	int,	is_log_tree	)
2361 	),
2362 
2363 	TP_fast_assign_btrfs(eb->fs_info,
2364 		__entry->block		= eb->start;
2365 		__entry->generation	= btrfs_header_generation(eb);
2366 		__entry->owner		= btrfs_header_owner(eb);
2367 		__entry->is_log_tree	= (eb->log_index >= 0);
2368 	),
2369 
2370 	TP_printk_btrfs("block=%llu generation=%llu owner=%llu is_log_tree=%d",
2371 		__entry->block, __entry->generation,
2372 		__entry->owner, __entry->is_log_tree)
2373 );
2374 
2375 #define DEFINE_BTRFS_LOCK_EVENT(name)				\
2376 DEFINE_EVENT(btrfs_locking_events, name,			\
2377 		TP_PROTO(const struct extent_buffer *eb),	\
2378 								\
2379 		TP_ARGS(eb)					\
2380 )
2381 
2382 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_unlock);
2383 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock);
2384 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_unlock_blocking);
2385 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_read);
2386 DEFINE_BTRFS_LOCK_EVENT(btrfs_set_lock_blocking_write);
2387 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_read_lock);
2388 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_write_lock);
2389 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_lock_atomic);
2390 
2391 DECLARE_EVENT_CLASS(btrfs__space_info_update,
2392 
2393 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2394 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2395 
2396 	TP_ARGS(fs_info, sinfo, old, diff),
2397 
2398 	TP_STRUCT__entry_btrfs(
2399 		__field(	u64,	type		)
2400 		__field(	u64,	old		)
2401 		__field(	s64,	diff		)
2402 	),
2403 
2404 	TP_fast_assign_btrfs(fs_info,
2405 		__entry->type	= sinfo->flags;
2406 		__entry->old	= old;
2407 		__entry->diff	= diff;
2408 	),
2409 	TP_printk_btrfs("type=%s old=%llu diff=%lld",
2410 		__print_flags(__entry->type, "|", BTRFS_GROUP_FLAGS),
2411 		__entry->old, __entry->diff)
2412 );
2413 
2414 DEFINE_EVENT(btrfs__space_info_update, update_bytes_may_use,
2415 
2416 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2417 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2418 
2419 	TP_ARGS(fs_info, sinfo, old, diff)
2420 );
2421 
2422 DEFINE_EVENT(btrfs__space_info_update, update_bytes_pinned,
2423 
2424 	TP_PROTO(const struct btrfs_fs_info *fs_info,
2425 		 const struct btrfs_space_info *sinfo, u64 old, s64 diff),
2426 
2427 	TP_ARGS(fs_info, sinfo, old, diff)
2428 );
2429 
2430 DECLARE_EVENT_CLASS(btrfs_raid56_bio,
2431 
2432 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2433 		 const struct bio *bio,
2434 		 const struct raid56_bio_trace_info *trace_info),
2435 
2436 	TP_ARGS(rbio, bio, trace_info),
2437 
2438 	TP_STRUCT__entry_btrfs(
2439 		__field(	u64,	full_stripe	)
2440 		__field(	u64,	physical	)
2441 		__field(	u64,	devid		)
2442 		__field(	u32,	offset		)
2443 		__field(	u32,	len		)
2444 		__field(	u8,	opf		)
2445 		__field(	u8,	total_stripes	)
2446 		__field(	u8,	real_stripes	)
2447 		__field(	u8,	nr_data		)
2448 		__field(	u8,	stripe_nr	)
2449 	),
2450 
2451 	TP_fast_assign_btrfs(rbio->bioc->fs_info,
2452 		__entry->full_stripe	= rbio->bioc->full_stripe_logical;
2453 		__entry->physical	= bio->bi_iter.bi_sector << SECTOR_SHIFT;
2454 		__entry->len		= bio->bi_iter.bi_size;
2455 		__entry->opf		= bio_op(bio);
2456 		__entry->devid		= trace_info->devid;
2457 		__entry->offset		= trace_info->offset;
2458 		__entry->stripe_nr	= trace_info->stripe_nr;
2459 		__entry->total_stripes	= rbio->bioc->num_stripes;
2460 		__entry->real_stripes	= rbio->real_stripes;
2461 		__entry->nr_data	= rbio->nr_data;
2462 	),
2463 	/*
2464 	 * For type output, we need to output things like "DATA1"
2465 	 * (the first data stripe), "DATA2" (the second data stripe),
2466 	 * "PQ1" (P stripe),"PQ2" (Q stripe), "REPLACE0" (replace target device).
2467 	 */
2468 	TP_printk_btrfs(
2469 "full_stripe=%llu devid=%lld type=%s%d offset=%d opf=0x%x physical=%llu len=%u",
2470 		__entry->full_stripe, __entry->devid,
2471 		(__entry->stripe_nr < __entry->nr_data) ? "DATA" :
2472 			((__entry->stripe_nr < __entry->real_stripes) ? "PQ" :
2473 			 "REPLACE"),
2474 		(__entry->stripe_nr < __entry->nr_data) ?
2475 			(__entry->stripe_nr + 1) :
2476 			((__entry->stripe_nr < __entry->real_stripes) ?
2477 			 (__entry->stripe_nr - __entry->nr_data + 1) : 0),
2478 		__entry->offset, __entry->opf, __entry->physical, __entry->len)
2479 );
2480 
2481 DEFINE_EVENT(btrfs_raid56_bio, raid56_read,
2482 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2483 		 const struct bio *bio,
2484 		 const struct raid56_bio_trace_info *trace_info),
2485 
2486 	TP_ARGS(rbio, bio, trace_info)
2487 );
2488 
2489 DEFINE_EVENT(btrfs_raid56_bio, raid56_write,
2490 	TP_PROTO(const struct btrfs_raid_bio *rbio,
2491 		 const struct bio *bio,
2492 		 const struct raid56_bio_trace_info *trace_info),
2493 
2494 	TP_ARGS(rbio, bio, trace_info)
2495 );
2496 
2497 TRACE_EVENT(btrfs_insert_one_raid_extent,
2498 
2499 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 logical, u64 length,
2500 		 int num_stripes),
2501 
2502 	TP_ARGS(fs_info, logical, length, num_stripes),
2503 
2504 	TP_STRUCT__entry_btrfs(
2505 		__field(	u64,	logical		)
2506 		__field(	u64,	length		)
2507 		__field(	int,	num_stripes	)
2508 	),
2509 
2510 	TP_fast_assign_btrfs(fs_info,
2511 		__entry->logical	= logical;
2512 		__entry->length		= length;
2513 		__entry->num_stripes	= num_stripes;
2514 	),
2515 
2516 	TP_printk_btrfs("logical=%llu length=%llu num_stripes=%d",
2517 			__entry->logical, __entry->length,
2518 			__entry->num_stripes)
2519 );
2520 
2521 TRACE_EVENT(btrfs_raid_extent_delete,
2522 
2523 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 end,
2524 		 u64 found_start, u64 found_end),
2525 
2526 	TP_ARGS(fs_info, start, end, found_start, found_end),
2527 
2528 	TP_STRUCT__entry_btrfs(
2529 		__field(	u64,	start		)
2530 		__field(	u64,	end		)
2531 		__field(	u64,	found_start	)
2532 		__field(	u64,	found_end	)
2533 	),
2534 
2535 	TP_fast_assign_btrfs(fs_info,
2536 		__entry->start		= start;
2537 		__entry->end		= end;
2538 		__entry->found_start	= found_start;
2539 		__entry->found_end	= found_end;
2540 	),
2541 
2542 	TP_printk_btrfs("start=%llu end=%llu found_start=%llu found_end=%llu",
2543 			__entry->start, __entry->end, __entry->found_start,
2544 			__entry->found_end)
2545 );
2546 
2547 TRACE_EVENT(btrfs_get_raid_extent_offset,
2548 
2549 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 logical, u64 length,
2550 		 u64 physical, u64 devid),
2551 
2552 	TP_ARGS(fs_info, logical, length, physical, devid),
2553 
2554 	TP_STRUCT__entry_btrfs(
2555 		__field(	u64,	logical		)
2556 		__field(	u64,	length		)
2557 		__field(	u64,	physical	)
2558 		__field(	u64,	devid		)
2559 	),
2560 
2561 	TP_fast_assign_btrfs(fs_info,
2562 		__entry->logical	= logical;
2563 		__entry->length		= length;
2564 		__entry->physical	= physical;
2565 		__entry->devid		= devid;
2566 	),
2567 
2568 	TP_printk_btrfs("logical=%llu length=%llu physical=%llu devid=%llu",
2569 			__entry->logical, __entry->length, __entry->physical,
2570 			__entry->devid)
2571 );
2572 
2573 #endif /* _TRACE_BTRFS_H */
2574 
2575 /* This part must be outside protection */
2576 #include <trace/define_trace.h>
2577