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