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