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