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