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