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