xref: /openbmc/linux/include/trace/events/btrfs.h (revision b830f94f)
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 extent_io_tree;
31 struct prelim_ref;
32 struct btrfs_space_info;
33 
34 TRACE_DEFINE_ENUM(FLUSH_DELAYED_ITEMS_NR);
35 TRACE_DEFINE_ENUM(FLUSH_DELAYED_ITEMS);
36 TRACE_DEFINE_ENUM(FLUSH_DELALLOC);
37 TRACE_DEFINE_ENUM(FLUSH_DELALLOC_WAIT);
38 TRACE_DEFINE_ENUM(ALLOC_CHUNK);
39 TRACE_DEFINE_ENUM(COMMIT_TRANS);
40 
41 #define show_ref_type(type)						\
42 	__print_symbolic(type,						\
43 		{ BTRFS_TREE_BLOCK_REF_KEY, 	"TREE_BLOCK_REF" },	\
44 		{ BTRFS_EXTENT_DATA_REF_KEY, 	"EXTENT_DATA_REF" },	\
45 		{ BTRFS_EXTENT_REF_V0_KEY, 	"EXTENT_REF_V0" },	\
46 		{ BTRFS_SHARED_BLOCK_REF_KEY, 	"SHARED_BLOCK_REF" },	\
47 		{ BTRFS_SHARED_DATA_REF_KEY, 	"SHARED_DATA_REF" })
48 
49 #define __show_root_type(obj)						\
50 	__print_symbolic_u64(obj,					\
51 		{ BTRFS_ROOT_TREE_OBJECTID, 	"ROOT_TREE"	},	\
52 		{ BTRFS_EXTENT_TREE_OBJECTID, 	"EXTENT_TREE"	},	\
53 		{ BTRFS_CHUNK_TREE_OBJECTID, 	"CHUNK_TREE"	},	\
54 		{ BTRFS_DEV_TREE_OBJECTID, 	"DEV_TREE"	},	\
55 		{ BTRFS_FS_TREE_OBJECTID, 	"FS_TREE"	},	\
56 		{ BTRFS_ROOT_TREE_DIR_OBJECTID, "ROOT_TREE_DIR"	},	\
57 		{ BTRFS_CSUM_TREE_OBJECTID, 	"CSUM_TREE"	},	\
58 		{ BTRFS_TREE_LOG_OBJECTID,	"TREE_LOG"	},	\
59 		{ BTRFS_QUOTA_TREE_OBJECTID,	"QUOTA_TREE"	},	\
60 		{ BTRFS_TREE_RELOC_OBJECTID,	"TREE_RELOC"	},	\
61 		{ BTRFS_UUID_TREE_OBJECTID,	"UUID_TREE"	},	\
62 		{ BTRFS_FREE_SPACE_TREE_OBJECTID, "FREE_SPACE_TREE" },	\
63 		{ BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" })
64 
65 #define show_root_type(obj)						\
66 	obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) ||		\
67 	      (obj >= BTRFS_ROOT_TREE_OBJECTID &&			\
68 	       obj <= BTRFS_QUOTA_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
69 
70 #define show_fi_type(type)						\
71 	__print_symbolic(type,						\
72 		 { BTRFS_FILE_EXTENT_INLINE,	"INLINE" },		\
73 		 { BTRFS_FILE_EXTENT_REG,	"REG"	 },		\
74 		 { BTRFS_FILE_EXTENT_PREALLOC,	"PREALLOC"})
75 
76 #define show_qgroup_rsv_type(type)					\
77 	__print_symbolic(type,						\
78 		{ BTRFS_QGROUP_RSV_DATA,	  "DATA"	},	\
79 		{ BTRFS_QGROUP_RSV_META_PERTRANS, "META_PERTRANS" },	\
80 		{ BTRFS_QGROUP_RSV_META_PREALLOC, "META_PREALLOC" })
81 
82 #define show_extent_io_tree_owner(owner)				       \
83 	__print_symbolic(owner,						       \
84 		{ IO_TREE_FS_INFO_FREED_EXTENTS0, "FREED_EXTENTS0" },	       \
85 		{ IO_TREE_FS_INFO_FREED_EXTENTS1, "FREED_EXTENTS1" },	       \
86 		{ IO_TREE_INODE_IO,		  "INODE_IO" },		       \
87 		{ IO_TREE_INODE_IO_FAILURE,	  "INODE_IO_FAILURE" },	       \
88 		{ IO_TREE_RELOC_BLOCKS,		  "RELOC_BLOCKS" },	       \
89 		{ IO_TREE_TRANS_DIRTY_PAGES,	  "TRANS_DIRTY_PAGES" },       \
90 		{ IO_TREE_ROOT_DIRTY_LOG_PAGES,	  "ROOT_DIRTY_LOG_PAGES" },    \
91 		{ IO_TREE_SELFTEST,		  "SELFTEST" })
92 
93 #define BTRFS_GROUP_FLAGS	\
94 	{ BTRFS_BLOCK_GROUP_DATA,	"DATA"},	\
95 	{ BTRFS_BLOCK_GROUP_SYSTEM,	"SYSTEM"},	\
96 	{ BTRFS_BLOCK_GROUP_METADATA,	"METADATA"},	\
97 	{ BTRFS_BLOCK_GROUP_RAID0,	"RAID0"}, 	\
98 	{ BTRFS_BLOCK_GROUP_RAID1,	"RAID1"}, 	\
99 	{ BTRFS_BLOCK_GROUP_DUP,	"DUP"}, 	\
100 	{ BTRFS_BLOCK_GROUP_RAID10,	"RAID10"}, 	\
101 	{ BTRFS_BLOCK_GROUP_RAID5,	"RAID5"},	\
102 	{ BTRFS_BLOCK_GROUP_RAID6,	"RAID6"}
103 
104 #define EXTENT_FLAGS						\
105 	{ EXTENT_DIRTY,			"DIRTY"},		\
106 	{ EXTENT_UPTODATE,		"UPTODATE"},		\
107 	{ EXTENT_LOCKED,		"LOCKED"},		\
108 	{ EXTENT_NEW,			"NEW"},			\
109 	{ EXTENT_DELALLOC,		"DELALLOC"},		\
110 	{ EXTENT_DEFRAG,		"DEFRAG"},		\
111 	{ EXTENT_BOUNDARY,		"BOUNDARY"},		\
112 	{ EXTENT_NODATASUM,		"NODATASUM"},		\
113 	{ EXTENT_CLEAR_META_RESV,	"CLEAR_META_RESV"},	\
114 	{ EXTENT_NEED_WAIT,		"NEED_WAIT"},		\
115 	{ EXTENT_DAMAGED,		"DAMAGED"},		\
116 	{ EXTENT_NORESERVE,		"NORESERVE"},		\
117 	{ EXTENT_QGROUP_RESERVED,	"QGROUP_RESERVED"},	\
118 	{ EXTENT_CLEAR_DATA_RESV,	"CLEAR_DATA_RESV"},	\
119 	{ EXTENT_DELALLOC_NEW,		"DELALLOC_NEW"}
120 
121 #define BTRFS_FSID_SIZE 16
122 #define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_FSID_SIZE)
123 
124 #define TP_fast_assign_fsid(fs_info)					\
125 ({									\
126 	if (fs_info)							\
127 		memcpy(__entry->fsid, fs_info->fs_devices->fsid,	\
128 		       BTRFS_FSID_SIZE);				\
129 	else								\
130 		memset(__entry->fsid, 0, BTRFS_FSID_SIZE);		\
131 })
132 
133 #define TP_STRUCT__entry_btrfs(args...)					\
134 	TP_STRUCT__entry(						\
135 		TP_STRUCT__entry_fsid					\
136 		args)
137 #define TP_fast_assign_btrfs(fs_info, args...)				\
138 	TP_fast_assign(							\
139 		TP_fast_assign_fsid(fs_info);				\
140 		args)
141 #define TP_printk_btrfs(fmt, args...) \
142 	TP_printk("%pU: " fmt, __entry->fsid, args)
143 
144 TRACE_EVENT(btrfs_transaction_commit,
145 
146 	TP_PROTO(const struct btrfs_root *root),
147 
148 	TP_ARGS(root),
149 
150 	TP_STRUCT__entry_btrfs(
151 		__field(	u64,  generation		)
152 		__field(	u64,  root_objectid		)
153 	),
154 
155 	TP_fast_assign_btrfs(root->fs_info,
156 		__entry->generation	= root->fs_info->generation;
157 		__entry->root_objectid	= root->root_key.objectid;
158 	),
159 
160 	TP_printk_btrfs("root=%llu(%s) gen=%llu",
161 		  show_root_type(__entry->root_objectid),
162 		  __entry->generation)
163 );
164 
165 DECLARE_EVENT_CLASS(btrfs__inode,
166 
167 	TP_PROTO(const struct inode *inode),
168 
169 	TP_ARGS(inode),
170 
171 	TP_STRUCT__entry_btrfs(
172 		__field(	u64,  ino			)
173 		__field(	blkcnt_t,  blocks		)
174 		__field(	u64,  disk_i_size		)
175 		__field(	u64,  generation		)
176 		__field(	u64,  last_trans		)
177 		__field(	u64,  logged_trans		)
178 		__field(	u64,  root_objectid		)
179 	),
180 
181 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
182 		__entry->ino	= btrfs_ino(BTRFS_I(inode));
183 		__entry->blocks	= inode->i_blocks;
184 		__entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
185 		__entry->generation = BTRFS_I(inode)->generation;
186 		__entry->last_trans = BTRFS_I(inode)->last_trans;
187 		__entry->logged_trans = BTRFS_I(inode)->logged_trans;
188 		__entry->root_objectid =
189 				BTRFS_I(inode)->root->root_key.objectid;
190 	),
191 
192 	TP_printk_btrfs("root=%llu(%s) gen=%llu ino=%llu blocks=%llu "
193 		  "disk_i_size=%llu last_trans=%llu logged_trans=%llu",
194 		  show_root_type(__entry->root_objectid),
195 		  __entry->generation,
196 		  __entry->ino,
197 		  (unsigned long long)__entry->blocks,
198 		  __entry->disk_i_size,
199 		  __entry->last_trans,
200 		  __entry->logged_trans)
201 );
202 
203 DEFINE_EVENT(btrfs__inode, btrfs_inode_new,
204 
205 	TP_PROTO(const struct inode *inode),
206 
207 	TP_ARGS(inode)
208 );
209 
210 DEFINE_EVENT(btrfs__inode, btrfs_inode_request,
211 
212 	TP_PROTO(const struct inode *inode),
213 
214 	TP_ARGS(inode)
215 );
216 
217 DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
218 
219 	TP_PROTO(const struct inode *inode),
220 
221 	TP_ARGS(inode)
222 );
223 
224 #define __show_map_type(type)						\
225 	__print_symbolic_u64(type,					\
226 		{ EXTENT_MAP_LAST_BYTE, "LAST_BYTE" 	},		\
227 		{ EXTENT_MAP_HOLE, 	"HOLE" 		},		\
228 		{ EXTENT_MAP_INLINE, 	"INLINE" 	},		\
229 		{ EXTENT_MAP_DELALLOC,	"DELALLOC" 	})
230 
231 #define show_map_type(type)			\
232 	type, (type >= EXTENT_MAP_LAST_BYTE) ? "-" :  __show_map_type(type)
233 
234 #define show_map_flags(flag)						\
235 	__print_flags(flag, "|",					\
236 		{ (1 << EXTENT_FLAG_PINNED), 		"PINNED" 	},\
237 		{ (1 << EXTENT_FLAG_COMPRESSED), 	"COMPRESSED" 	},\
238 		{ (1 << EXTENT_FLAG_PREALLOC), 		"PREALLOC" 	},\
239 		{ (1 << EXTENT_FLAG_LOGGING),	 	"LOGGING" 	},\
240 		{ (1 << EXTENT_FLAG_FILLING),	 	"FILLING" 	},\
241 		{ (1 << EXTENT_FLAG_FS_MAPPING),	"FS_MAPPING"	})
242 
243 TRACE_EVENT_CONDITION(btrfs_get_extent,
244 
245 	TP_PROTO(const struct btrfs_root *root, const struct btrfs_inode *inode,
246 		 const struct extent_map *map),
247 
248 	TP_ARGS(root, inode, map),
249 
250 	TP_CONDITION(map),
251 
252 	TP_STRUCT__entry_btrfs(
253 		__field(	u64,  root_objectid	)
254 		__field(	u64,  ino		)
255 		__field(	u64,  start		)
256 		__field(	u64,  len		)
257 		__field(	u64,  orig_start	)
258 		__field(	u64,  block_start	)
259 		__field(	u64,  block_len		)
260 		__field(	unsigned long,  flags	)
261 		__field(	int,  refs		)
262 		__field(	unsigned int,  compress_type	)
263 	),
264 
265 	TP_fast_assign_btrfs(root->fs_info,
266 		__entry->root_objectid	= root->root_key.objectid;
267 		__entry->ino		= btrfs_ino(inode);
268 		__entry->start		= map->start;
269 		__entry->len		= map->len;
270 		__entry->orig_start	= map->orig_start;
271 		__entry->block_start	= map->block_start;
272 		__entry->block_len	= map->block_len;
273 		__entry->flags		= map->flags;
274 		__entry->refs		= refcount_read(&map->refs);
275 		__entry->compress_type	= map->compress_type;
276 	),
277 
278 	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu "
279 		  "orig_start=%llu block_start=%llu(%s) "
280 		  "block_len=%llu flags=%s refs=%u "
281 		  "compress_type=%u",
282 		  show_root_type(__entry->root_objectid),
283 		  __entry->ino,
284 		  __entry->start,
285 		  __entry->len,
286 		  __entry->orig_start,
287 		  show_map_type(__entry->block_start),
288 		  __entry->block_len,
289 		  show_map_flags(__entry->flags),
290 		  __entry->refs, __entry->compress_type)
291 );
292 
293 TRACE_EVENT(btrfs_handle_em_exist,
294 
295 	TP_PROTO(struct btrfs_fs_info *fs_info,
296 		const struct extent_map *existing, const struct extent_map *map,
297 		u64 start, u64 len),
298 
299 	TP_ARGS(fs_info, existing, map, start, len),
300 
301 	TP_STRUCT__entry_btrfs(
302 		__field(	u64,  e_start		)
303 		__field(	u64,  e_len		)
304 		__field(	u64,  map_start		)
305 		__field(	u64,  map_len		)
306 		__field(	u64,  start		)
307 		__field(	u64,  len		)
308 	),
309 
310 	TP_fast_assign_btrfs(fs_info,
311 		__entry->e_start	= existing->start;
312 		__entry->e_len		= existing->len;
313 		__entry->map_start	= map->start;
314 		__entry->map_len	= map->len;
315 		__entry->start		= start;
316 		__entry->len		= len;
317 	),
318 
319 	TP_printk_btrfs("start=%llu len=%llu "
320 		  "existing(start=%llu len=%llu) "
321 		  "em(start=%llu len=%llu)",
322 		  __entry->start,
323 		  __entry->len,
324 		  __entry->e_start,
325 		  __entry->e_len,
326 		  __entry->map_start,
327 		  __entry->map_len)
328 );
329 
330 /* file extent item */
331 DECLARE_EVENT_CLASS(btrfs__file_extent_item_regular,
332 
333 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
334 		 struct btrfs_file_extent_item *fi, u64 start),
335 
336 	TP_ARGS(bi, l, fi, start),
337 
338 	TP_STRUCT__entry_btrfs(
339 		__field(	u64,	root_obj	)
340 		__field(	u64,	ino		)
341 		__field(	loff_t,	isize		)
342 		__field(	u64,	disk_isize	)
343 		__field(	u64,	num_bytes	)
344 		__field(	u64,	ram_bytes	)
345 		__field(	u64,	disk_bytenr	)
346 		__field(	u64,	disk_num_bytes	)
347 		__field(	u64,	extent_offset	)
348 		__field(	u8,	extent_type	)
349 		__field(	u8,	compression	)
350 		__field(	u64,	extent_start	)
351 		__field(	u64,	extent_end	)
352 	),
353 
354 	TP_fast_assign_btrfs(bi->root->fs_info,
355 		__entry->root_obj	= bi->root->root_key.objectid;
356 		__entry->ino		= btrfs_ino(bi);
357 		__entry->isize		= bi->vfs_inode.i_size;
358 		__entry->disk_isize	= bi->disk_i_size;
359 		__entry->num_bytes	= btrfs_file_extent_num_bytes(l, fi);
360 		__entry->ram_bytes	= btrfs_file_extent_ram_bytes(l, fi);
361 		__entry->disk_bytenr	= btrfs_file_extent_disk_bytenr(l, fi);
362 		__entry->disk_num_bytes	= btrfs_file_extent_disk_num_bytes(l, fi);
363 		__entry->extent_offset	= btrfs_file_extent_offset(l, fi);
364 		__entry->extent_type	= btrfs_file_extent_type(l, fi);
365 		__entry->compression	= btrfs_file_extent_compression(l, fi);
366 		__entry->extent_start	= start;
367 		__entry->extent_end	= (start + __entry->num_bytes);
368 	),
369 
370 	TP_printk_btrfs(
371 		"root=%llu(%s) inode=%llu size=%llu disk_isize=%llu "
372 		"file extent range=[%llu %llu] "
373 		"(num_bytes=%llu ram_bytes=%llu disk_bytenr=%llu "
374 		"disk_num_bytes=%llu extent_offset=%llu type=%s "
375 		"compression=%u",
376 		show_root_type(__entry->root_obj), __entry->ino,
377 		__entry->isize,
378 		__entry->disk_isize, __entry->extent_start,
379 		__entry->extent_end, __entry->num_bytes, __entry->ram_bytes,
380 		__entry->disk_bytenr, __entry->disk_num_bytes,
381 		__entry->extent_offset, show_fi_type(__entry->extent_type),
382 		__entry->compression)
383 );
384 
385 DECLARE_EVENT_CLASS(
386 	btrfs__file_extent_item_inline,
387 
388 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
389 		 struct btrfs_file_extent_item *fi, int slot, u64 start),
390 
391 	TP_ARGS(bi, l, fi, slot,  start),
392 
393 	TP_STRUCT__entry_btrfs(
394 		__field(	u64,	root_obj	)
395 		__field(	u64,	ino		)
396 		__field(	loff_t,	isize		)
397 		__field(	u64,	disk_isize	)
398 		__field(	u8,	extent_type	)
399 		__field(	u8,	compression	)
400 		__field(	u64,	extent_start	)
401 		__field(	u64,	extent_end	)
402 	),
403 
404 	TP_fast_assign_btrfs(
405 		bi->root->fs_info,
406 		__entry->root_obj	= bi->root->root_key.objectid;
407 		__entry->ino		= btrfs_ino(bi);
408 		__entry->isize		= bi->vfs_inode.i_size;
409 		__entry->disk_isize	= bi->disk_i_size;
410 		__entry->extent_type	= btrfs_file_extent_type(l, fi);
411 		__entry->compression	= btrfs_file_extent_compression(l, fi);
412 		__entry->extent_start	= start;
413 		__entry->extent_end	= (start + btrfs_file_extent_ram_bytes(l, fi));
414 	),
415 
416 	TP_printk_btrfs(
417 		"root=%llu(%s) inode=%llu size=%llu disk_isize=%llu "
418 		"file extent range=[%llu %llu] "
419 		"extent_type=%s compression=%u",
420 		show_root_type(__entry->root_obj), __entry->ino, __entry->isize,
421 		__entry->disk_isize, __entry->extent_start,
422 		__entry->extent_end, show_fi_type(__entry->extent_type),
423 		__entry->compression)
424 );
425 
426 DEFINE_EVENT(
427 	btrfs__file_extent_item_regular, btrfs_get_extent_show_fi_regular,
428 
429 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
430 		 struct btrfs_file_extent_item *fi, u64 start),
431 
432 	TP_ARGS(bi, l, fi, start)
433 );
434 
435 DEFINE_EVENT(
436 	btrfs__file_extent_item_regular, btrfs_truncate_show_fi_regular,
437 
438 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
439 		 struct btrfs_file_extent_item *fi, u64 start),
440 
441 	TP_ARGS(bi, l, fi, start)
442 );
443 
444 DEFINE_EVENT(
445 	btrfs__file_extent_item_inline, btrfs_get_extent_show_fi_inline,
446 
447 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
448 		 struct btrfs_file_extent_item *fi, int slot, u64 start),
449 
450 	TP_ARGS(bi, l, fi, slot, start)
451 );
452 
453 DEFINE_EVENT(
454 	btrfs__file_extent_item_inline, btrfs_truncate_show_fi_inline,
455 
456 	TP_PROTO(struct btrfs_inode *bi, struct extent_buffer *l,
457 		 struct btrfs_file_extent_item *fi, int slot, u64 start),
458 
459 	TP_ARGS(bi, l, fi, slot, start)
460 );
461 
462 #define show_ordered_flags(flags)					   \
463 	__print_flags(flags, "|",					   \
464 		{ (1 << BTRFS_ORDERED_IO_DONE), 	"IO_DONE" 	}, \
465 		{ (1 << BTRFS_ORDERED_COMPLETE), 	"COMPLETE" 	}, \
466 		{ (1 << BTRFS_ORDERED_NOCOW), 		"NOCOW" 	}, \
467 		{ (1 << BTRFS_ORDERED_COMPRESSED), 	"COMPRESSED" 	}, \
468 		{ (1 << BTRFS_ORDERED_PREALLOC), 	"PREALLOC" 	}, \
469 		{ (1 << BTRFS_ORDERED_DIRECT),	 	"DIRECT" 	}, \
470 		{ (1 << BTRFS_ORDERED_IOERR), 		"IOERR" 	}, \
471 		{ (1 << BTRFS_ORDERED_UPDATED_ISIZE), 	"UPDATED_ISIZE"	}, \
472 		{ (1 << BTRFS_ORDERED_TRUNCATED), 	"TRUNCATED"	})
473 
474 
475 DECLARE_EVENT_CLASS(btrfs__ordered_extent,
476 
477 	TP_PROTO(const struct inode *inode,
478 		 const struct btrfs_ordered_extent *ordered),
479 
480 	TP_ARGS(inode, ordered),
481 
482 	TP_STRUCT__entry_btrfs(
483 		__field(	u64,  ino		)
484 		__field(	u64,  file_offset	)
485 		__field(	u64,  start		)
486 		__field(	u64,  len		)
487 		__field(	u64,  disk_len		)
488 		__field(	u64,  bytes_left	)
489 		__field(	unsigned long,  flags	)
490 		__field(	int,  compress_type	)
491 		__field(	int,  refs		)
492 		__field(	u64,  root_objectid	)
493 		__field(	u64,  truncated_len	)
494 	),
495 
496 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
497 		__entry->ino 		= btrfs_ino(BTRFS_I(inode));
498 		__entry->file_offset	= ordered->file_offset;
499 		__entry->start		= ordered->start;
500 		__entry->len		= ordered->len;
501 		__entry->disk_len	= ordered->disk_len;
502 		__entry->bytes_left	= ordered->bytes_left;
503 		__entry->flags		= ordered->flags;
504 		__entry->compress_type	= ordered->compress_type;
505 		__entry->refs		= refcount_read(&ordered->refs);
506 		__entry->root_objectid	=
507 				BTRFS_I(inode)->root->root_key.objectid;
508 		__entry->truncated_len	= ordered->truncated_len;
509 	),
510 
511 	TP_printk_btrfs("root=%llu(%s) ino=%llu file_offset=%llu "
512 		  "start=%llu len=%llu disk_len=%llu "
513 		  "truncated_len=%llu "
514 		  "bytes_left=%llu flags=%s compress_type=%d "
515 		  "refs=%d",
516 		  show_root_type(__entry->root_objectid),
517 		  __entry->ino,
518 		  __entry->file_offset,
519 		  __entry->start,
520 		  __entry->len,
521 		  __entry->disk_len,
522 		  __entry->truncated_len,
523 		  __entry->bytes_left,
524 		  show_ordered_flags(__entry->flags),
525 		  __entry->compress_type, __entry->refs)
526 );
527 
528 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_add,
529 
530 	TP_PROTO(const struct inode *inode,
531 		 const struct btrfs_ordered_extent *ordered),
532 
533 	TP_ARGS(inode, ordered)
534 );
535 
536 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_remove,
537 
538 	TP_PROTO(const struct inode *inode,
539 		 const struct btrfs_ordered_extent *ordered),
540 
541 	TP_ARGS(inode, ordered)
542 );
543 
544 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_start,
545 
546 	TP_PROTO(const struct inode *inode,
547 		 const struct btrfs_ordered_extent *ordered),
548 
549 	TP_ARGS(inode, ordered)
550 );
551 
552 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_put,
553 
554 	TP_PROTO(const struct inode *inode,
555 		 const struct btrfs_ordered_extent *ordered),
556 
557 	TP_ARGS(inode, ordered)
558 );
559 
560 DECLARE_EVENT_CLASS(btrfs__writepage,
561 
562 	TP_PROTO(const struct page *page, const struct inode *inode,
563 		 const struct writeback_control *wbc),
564 
565 	TP_ARGS(page, inode, wbc),
566 
567 	TP_STRUCT__entry_btrfs(
568 		__field(	u64,	ino			)
569 		__field(	pgoff_t,  index			)
570 		__field(	long,   nr_to_write		)
571 		__field(	long,   pages_skipped		)
572 		__field(	loff_t, range_start		)
573 		__field(	loff_t, range_end		)
574 		__field(	char,   for_kupdate		)
575 		__field(	char,   for_reclaim		)
576 		__field(	char,   range_cyclic		)
577 		__field(	pgoff_t,  writeback_index	)
578 		__field(	u64,    root_objectid		)
579 	),
580 
581 	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
582 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
583 		__entry->index		= page->index;
584 		__entry->nr_to_write	= wbc->nr_to_write;
585 		__entry->pages_skipped	= wbc->pages_skipped;
586 		__entry->range_start	= wbc->range_start;
587 		__entry->range_end	= wbc->range_end;
588 		__entry->for_kupdate	= wbc->for_kupdate;
589 		__entry->for_reclaim	= wbc->for_reclaim;
590 		__entry->range_cyclic	= wbc->range_cyclic;
591 		__entry->writeback_index = inode->i_mapping->writeback_index;
592 		__entry->root_objectid	=
593 				 BTRFS_I(inode)->root->root_key.objectid;
594 	),
595 
596 	TP_printk_btrfs("root=%llu(%s) ino=%llu page_index=%lu "
597 		  "nr_to_write=%ld pages_skipped=%ld range_start=%llu "
598 		  "range_end=%llu for_kupdate=%d "
599 		  "for_reclaim=%d range_cyclic=%d writeback_index=%lu",
600 		  show_root_type(__entry->root_objectid),
601 		  __entry->ino, __entry->index,
602 		  __entry->nr_to_write, __entry->pages_skipped,
603 		  __entry->range_start, __entry->range_end,
604 		  __entry->for_kupdate,
605 		  __entry->for_reclaim, __entry->range_cyclic,
606 		  (unsigned long)__entry->writeback_index)
607 );
608 
609 DEFINE_EVENT(btrfs__writepage, __extent_writepage,
610 
611 	TP_PROTO(const struct page *page, const struct inode *inode,
612 		 const struct writeback_control *wbc),
613 
614 	TP_ARGS(page, inode, wbc)
615 );
616 
617 TRACE_EVENT(btrfs_writepage_end_io_hook,
618 
619 	TP_PROTO(const struct page *page, u64 start, u64 end, int uptodate),
620 
621 	TP_ARGS(page, start, end, uptodate),
622 
623 	TP_STRUCT__entry_btrfs(
624 		__field(	u64,	 ino		)
625 		__field(	pgoff_t, index		)
626 		__field(	u64,	 start		)
627 		__field(	u64,	 end		)
628 		__field(	int,	 uptodate	)
629 		__field(	u64,    root_objectid	)
630 	),
631 
632 	TP_fast_assign_btrfs(btrfs_sb(page->mapping->host->i_sb),
633 		__entry->ino	= btrfs_ino(BTRFS_I(page->mapping->host));
634 		__entry->index	= page->index;
635 		__entry->start	= start;
636 		__entry->end	= end;
637 		__entry->uptodate = uptodate;
638 		__entry->root_objectid	=
639 			 BTRFS_I(page->mapping->host)->root->root_key.objectid;
640 	),
641 
642 	TP_printk_btrfs("root=%llu(%s) ino=%llu page_index=%lu start=%llu "
643 		  "end=%llu uptodate=%d",
644 		  show_root_type(__entry->root_objectid),
645 		  __entry->ino, (unsigned long)__entry->index,
646 		  __entry->start,
647 		  __entry->end, __entry->uptodate)
648 );
649 
650 TRACE_EVENT(btrfs_sync_file,
651 
652 	TP_PROTO(const struct file *file, int datasync),
653 
654 	TP_ARGS(file, datasync),
655 
656 	TP_STRUCT__entry_btrfs(
657 		__field(	u64,	ino		)
658 		__field(	u64,	parent		)
659 		__field(	int,    datasync	)
660 		__field(	u64,    root_objectid	)
661 	),
662 
663 	TP_fast_assign(
664 		const struct dentry *dentry = file->f_path.dentry;
665 		const struct inode *inode = d_inode(dentry);
666 
667 		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
668 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
669 		__entry->parent		= btrfs_ino(BTRFS_I(d_inode(dentry->d_parent)));
670 		__entry->datasync	= datasync;
671 		__entry->root_objectid	=
672 				 BTRFS_I(inode)->root->root_key.objectid;
673 	),
674 
675 	TP_printk_btrfs("root=%llu(%s) ino=%llu parent=%llu datasync=%d",
676 		  show_root_type(__entry->root_objectid),
677 		  __entry->ino,
678 		  __entry->parent,
679 		  __entry->datasync)
680 );
681 
682 TRACE_EVENT(btrfs_sync_fs,
683 
684 	TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),
685 
686 	TP_ARGS(fs_info, wait),
687 
688 	TP_STRUCT__entry_btrfs(
689 		__field(	int,  wait		)
690 	),
691 
692 	TP_fast_assign_btrfs(fs_info,
693 		__entry->wait	= wait;
694 	),
695 
696 	TP_printk_btrfs("wait=%d", __entry->wait)
697 );
698 
699 TRACE_EVENT(btrfs_add_block_group,
700 
701 	TP_PROTO(const struct btrfs_fs_info *fs_info,
702 		 const struct btrfs_block_group_cache *block_group, int create),
703 
704 	TP_ARGS(fs_info, block_group, create),
705 
706 	TP_STRUCT__entry_btrfs(
707 		__field(	u64,	offset			)
708 		__field(	u64,	size			)
709 		__field(	u64,	flags			)
710 		__field(	u64,	bytes_used		)
711 		__field(	u64,	bytes_super		)
712 		__field(	int,	create			)
713 	),
714 
715 	TP_fast_assign_btrfs(fs_info,
716 		__entry->offset		= block_group->key.objectid;
717 		__entry->size		= block_group->key.offset;
718 		__entry->flags		= block_group->flags;
719 		__entry->bytes_used	=
720 			btrfs_block_group_used(&block_group->item);
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, 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, 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 		{ COMMIT_TRANS,			"COMMIT_TRANS"})
1092 
1093 TRACE_EVENT(btrfs_flush_space,
1094 
1095 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 num_bytes,
1096 		 int state, int ret),
1097 
1098 	TP_ARGS(fs_info, flags, num_bytes, state, ret),
1099 
1100 	TP_STRUCT__entry_btrfs(
1101 		__field(	u64,	flags			)
1102 		__field(	u64,	num_bytes		)
1103 		__field(	int,	state			)
1104 		__field(	int,	ret			)
1105 	),
1106 
1107 	TP_fast_assign_btrfs(fs_info,
1108 		__entry->flags		=	flags;
1109 		__entry->num_bytes	=	num_bytes;
1110 		__entry->state		=	state;
1111 		__entry->ret		=	ret;
1112 	),
1113 
1114 	TP_printk_btrfs("state=%d(%s) flags=%llu(%s) num_bytes=%llu ret=%d",
1115 		  __entry->state,
1116 		  show_flush_state(__entry->state),
1117 		  __entry->flags,
1118 		  __print_flags((unsigned long)__entry->flags, "|",
1119 				BTRFS_GROUP_FLAGS),
1120 		  __entry->num_bytes, __entry->ret)
1121 );
1122 
1123 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
1124 
1125 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1126 
1127 	TP_ARGS(fs_info, start, len),
1128 
1129 	TP_STRUCT__entry_btrfs(
1130 		__field(	u64,  start			)
1131 		__field(	u64,  len			)
1132 	),
1133 
1134 	TP_fast_assign_btrfs(fs_info,
1135 		__entry->start		= start;
1136 		__entry->len		= len;
1137 	),
1138 
1139 	TP_printk_btrfs("root=%llu(%s) start=%llu len=%llu",
1140 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1141 		  __entry->start,
1142 		  __entry->len)
1143 );
1144 
1145 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_alloc,
1146 
1147 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1148 
1149 	TP_ARGS(fs_info, start, len)
1150 );
1151 
1152 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_free,
1153 
1154 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 start, u64 len),
1155 
1156 	TP_ARGS(fs_info, start, len)
1157 );
1158 
1159 TRACE_EVENT(find_free_extent,
1160 
1161 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 num_bytes,
1162 		 u64 empty_size, u64 data),
1163 
1164 	TP_ARGS(fs_info, num_bytes, empty_size, data),
1165 
1166 	TP_STRUCT__entry_btrfs(
1167 		__field(	u64,	num_bytes		)
1168 		__field(	u64,	empty_size		)
1169 		__field(	u64,	data			)
1170 	),
1171 
1172 	TP_fast_assign_btrfs(fs_info,
1173 		__entry->num_bytes	= num_bytes;
1174 		__entry->empty_size	= empty_size;
1175 		__entry->data		= data;
1176 	),
1177 
1178 	TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s)",
1179 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1180 		  __entry->num_bytes, __entry->empty_size, __entry->data,
1181 		  __print_flags((unsigned long)__entry->data, "|",
1182 				 BTRFS_GROUP_FLAGS))
1183 );
1184 
1185 DECLARE_EVENT_CLASS(btrfs__reserve_extent,
1186 
1187 	TP_PROTO(const struct btrfs_block_group_cache *block_group, u64 start,
1188 		 u64 len),
1189 
1190 	TP_ARGS(block_group, start, len),
1191 
1192 	TP_STRUCT__entry_btrfs(
1193 		__field(	u64,	bg_objectid		)
1194 		__field(	u64,	flags			)
1195 		__field(	u64,	start			)
1196 		__field(	u64,	len			)
1197 	),
1198 
1199 	TP_fast_assign_btrfs(block_group->fs_info,
1200 		__entry->bg_objectid	= block_group->key.objectid;
1201 		__entry->flags		= block_group->flags;
1202 		__entry->start		= start;
1203 		__entry->len		= len;
1204 	),
1205 
1206 	TP_printk_btrfs("root=%llu(%s) block_group=%llu flags=%llu(%s) "
1207 		  "start=%llu len=%llu",
1208 		  show_root_type(BTRFS_EXTENT_TREE_OBJECTID),
1209 		  __entry->bg_objectid,
1210 		  __entry->flags, __print_flags((unsigned long)__entry->flags,
1211 						"|", BTRFS_GROUP_FLAGS),
1212 		  __entry->start, __entry->len)
1213 );
1214 
1215 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
1216 
1217 	TP_PROTO(const struct btrfs_block_group_cache *block_group, u64 start,
1218 		 u64 len),
1219 
1220 	TP_ARGS(block_group, start, len)
1221 );
1222 
1223 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
1224 
1225 	TP_PROTO(const struct btrfs_block_group_cache *block_group, u64 start,
1226 		 u64 len),
1227 
1228 	TP_ARGS(block_group, start, len)
1229 );
1230 
1231 TRACE_EVENT(btrfs_find_cluster,
1232 
1233 	TP_PROTO(const struct btrfs_block_group_cache *block_group, u64 start,
1234 		 u64 bytes, u64 empty_size, u64 min_bytes),
1235 
1236 	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
1237 
1238 	TP_STRUCT__entry_btrfs(
1239 		__field(	u64,	bg_objectid		)
1240 		__field(	u64,	flags			)
1241 		__field(	u64,	start			)
1242 		__field(	u64,	bytes			)
1243 		__field(	u64,	empty_size		)
1244 		__field(	u64,	min_bytes		)
1245 	),
1246 
1247 	TP_fast_assign_btrfs(block_group->fs_info,
1248 		__entry->bg_objectid	= block_group->key.objectid;
1249 		__entry->flags		= block_group->flags;
1250 		__entry->start		= start;
1251 		__entry->bytes		= bytes;
1252 		__entry->empty_size	= empty_size;
1253 		__entry->min_bytes	= min_bytes;
1254 	),
1255 
1256 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) start=%llu len=%llu "
1257 		  "empty_size=%llu min_bytes=%llu", __entry->bg_objectid,
1258 		  __entry->flags,
1259 		  __print_flags((unsigned long)__entry->flags, "|",
1260 				BTRFS_GROUP_FLAGS), __entry->start,
1261 		  __entry->bytes, __entry->empty_size,  __entry->min_bytes)
1262 );
1263 
1264 TRACE_EVENT(btrfs_failed_cluster_setup,
1265 
1266 	TP_PROTO(const struct btrfs_block_group_cache *block_group),
1267 
1268 	TP_ARGS(block_group),
1269 
1270 	TP_STRUCT__entry_btrfs(
1271 		__field(	u64,	bg_objectid		)
1272 	),
1273 
1274 	TP_fast_assign_btrfs(block_group->fs_info,
1275 		__entry->bg_objectid	= block_group->key.objectid;
1276 	),
1277 
1278 	TP_printk_btrfs("block_group=%llu", __entry->bg_objectid)
1279 );
1280 
1281 TRACE_EVENT(btrfs_setup_cluster,
1282 
1283 	TP_PROTO(const struct btrfs_block_group_cache *block_group,
1284 		 const struct btrfs_free_cluster *cluster,
1285 		 u64 size, int bitmap),
1286 
1287 	TP_ARGS(block_group, cluster, size, bitmap),
1288 
1289 	TP_STRUCT__entry_btrfs(
1290 		__field(	u64,	bg_objectid		)
1291 		__field(	u64,	flags			)
1292 		__field(	u64,	start			)
1293 		__field(	u64,	max_size		)
1294 		__field(	u64,	size			)
1295 		__field(	int,	bitmap			)
1296 	),
1297 
1298 	TP_fast_assign_btrfs(block_group->fs_info,
1299 		__entry->bg_objectid	= block_group->key.objectid;
1300 		__entry->flags		= block_group->flags;
1301 		__entry->start		= cluster->window_start;
1302 		__entry->max_size	= cluster->max_size;
1303 		__entry->size		= size;
1304 		__entry->bitmap		= bitmap;
1305 	),
1306 
1307 	TP_printk_btrfs("block_group=%llu flags=%llu(%s) window_start=%llu "
1308 		  "size=%llu max_size=%llu bitmap=%d",
1309 		  __entry->bg_objectid,
1310 		  __entry->flags,
1311 		  __print_flags((unsigned long)__entry->flags, "|",
1312 				BTRFS_GROUP_FLAGS), __entry->start,
1313 		  __entry->size, __entry->max_size, __entry->bitmap)
1314 );
1315 
1316 struct extent_state;
1317 TRACE_EVENT(alloc_extent_state,
1318 
1319 	TP_PROTO(const struct extent_state *state,
1320 		 gfp_t mask, unsigned long IP),
1321 
1322 	TP_ARGS(state, mask, IP),
1323 
1324 	TP_STRUCT__entry(
1325 		__field(const struct extent_state *, state)
1326 		__field(gfp_t, mask)
1327 		__field(unsigned long, ip)
1328 	),
1329 
1330 	TP_fast_assign(
1331 		__entry->state	= state,
1332 		__entry->mask	= mask,
1333 		__entry->ip	= IP
1334 	),
1335 
1336 	TP_printk("state=%p mask=%s caller=%pS", __entry->state,
1337 		  show_gfp_flags(__entry->mask), (const void *)__entry->ip)
1338 );
1339 
1340 TRACE_EVENT(free_extent_state,
1341 
1342 	TP_PROTO(const struct extent_state *state, unsigned long IP),
1343 
1344 	TP_ARGS(state, IP),
1345 
1346 	TP_STRUCT__entry(
1347 		__field(const struct extent_state *, state)
1348 		__field(unsigned long, ip)
1349 	),
1350 
1351 	TP_fast_assign(
1352 		__entry->state	= state,
1353 		__entry->ip = IP
1354 	),
1355 
1356 	TP_printk("state=%p caller=%pS", __entry->state,
1357 		  (const void *)__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 situiations when the work is freed, we pass fs_info and a tag that that
1392  * matches address of the work structure so it can be paired with the
1393  * scheduling event.
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 		  (unsigned long long)__entry->bytenr,
1570 		  (unsigned long long)__entry->num_bytes)
1571 );
1572 
1573 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
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 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent,
1582 
1583 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1584 		 const struct btrfs_qgroup_extent_record *rec),
1585 
1586 	TP_ARGS(fs_info, rec)
1587 );
1588 
1589 TRACE_EVENT(qgroup_num_dirty_extents,
1590 
1591 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid,
1592 		 u64 num_dirty_extents),
1593 
1594 	TP_ARGS(fs_info, transid, num_dirty_extents),
1595 
1596 	TP_STRUCT__entry_btrfs(
1597 		__field(	u64, transid			)
1598 		__field(	u64, num_dirty_extents		)
1599 	),
1600 
1601 	TP_fast_assign_btrfs(fs_info,
1602 		__entry->transid	   = transid;
1603 		__entry->num_dirty_extents = num_dirty_extents;
1604 	),
1605 
1606 	TP_printk_btrfs("transid=%llu num_dirty_extents=%llu",
1607 		__entry->transid, __entry->num_dirty_extents)
1608 );
1609 
1610 TRACE_EVENT(btrfs_qgroup_account_extent,
1611 
1612 	TP_PROTO(const struct btrfs_fs_info *fs_info, u64 transid, u64 bytenr,
1613 		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
1614 
1615 	TP_ARGS(fs_info, transid, bytenr, num_bytes, nr_old_roots,
1616 		nr_new_roots),
1617 
1618 	TP_STRUCT__entry_btrfs(
1619 		__field(	u64,  transid			)
1620 		__field(	u64,  bytenr			)
1621 		__field(	u64,  num_bytes			)
1622 		__field(	u64,  nr_old_roots		)
1623 		__field(	u64,  nr_new_roots		)
1624 	),
1625 
1626 	TP_fast_assign_btrfs(fs_info,
1627 		__entry->transid	= transid;
1628 		__entry->bytenr		= bytenr;
1629 		__entry->num_bytes	= num_bytes;
1630 		__entry->nr_old_roots	= nr_old_roots;
1631 		__entry->nr_new_roots	= nr_new_roots;
1632 	),
1633 
1634 	TP_printk_btrfs(
1635 "transid=%llu bytenr=%llu num_bytes=%llu nr_old_roots=%llu nr_new_roots=%llu",
1636 		__entry->transid,
1637 		__entry->bytenr,
1638 		__entry->num_bytes,
1639 		__entry->nr_old_roots,
1640 		__entry->nr_new_roots)
1641 );
1642 
1643 TRACE_EVENT(qgroup_update_counters,
1644 
1645 	TP_PROTO(const struct btrfs_fs_info *fs_info,
1646 		 struct btrfs_qgroup *qgroup,
1647 		 u64 cur_old_count, u64 cur_new_count),
1648 
1649 	TP_ARGS(fs_info, qgroup, cur_old_count, cur_new_count),
1650 
1651 	TP_STRUCT__entry_btrfs(
1652 		__field(	u64,  qgid			)
1653 		__field(	u64,  old_rfer			)
1654 		__field(	u64,  old_excl			)
1655 		__field(	u64,  cur_old_count		)
1656 		__field(	u64,  cur_new_count		)
1657 	),
1658 
1659 	TP_fast_assign_btrfs(fs_info,
1660 		__entry->qgid		= qgroup->qgroupid;
1661 		__entry->old_rfer	= qgroup->rfer;
1662 		__entry->old_excl	= qgroup->excl;
1663 		__entry->cur_old_count	= cur_old_count;
1664 		__entry->cur_new_count	= cur_new_count;
1665 	),
1666 
1667 	TP_printk_btrfs("qgid=%llu old_rfer=%llu old_excl=%llu cur_old_count=%llu cur_new_count=%llu",
1668 		  __entry->qgid, __entry->old_rfer, __entry->old_excl,
1669 		  __entry->cur_old_count, __entry->cur_new_count)
1670 );
1671 
1672 TRACE_EVENT(qgroup_update_reserve,
1673 
1674 	TP_PROTO(struct btrfs_fs_info *fs_info, struct btrfs_qgroup *qgroup,
1675 		 s64 diff, int type),
1676 
1677 	TP_ARGS(fs_info, qgroup, diff, type),
1678 
1679 	TP_STRUCT__entry_btrfs(
1680 		__field(	u64,	qgid			)
1681 		__field(	u64,	cur_reserved		)
1682 		__field(	s64,	diff			)
1683 		__field(	int,	type			)
1684 	),
1685 
1686 	TP_fast_assign_btrfs(fs_info,
1687 		__entry->qgid		= qgroup->qgroupid;
1688 		__entry->cur_reserved	= qgroup->rsv.values[type];
1689 		__entry->diff		= diff;
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 	),
1713 
1714 	TP_printk_btrfs("refroot=%llu(%s) type=%s diff=%lld",
1715 		show_root_type(__entry->refroot),
1716 		show_qgroup_rsv_type(__entry->type), __entry->diff)
1717 );
1718 
1719 TRACE_EVENT(qgroup_meta_convert,
1720 
1721 	TP_PROTO(struct btrfs_root *root, s64 diff),
1722 
1723 	TP_ARGS(root, diff),
1724 
1725 	TP_STRUCT__entry_btrfs(
1726 		__field(	u64,	refroot			)
1727 		__field(	s64,	diff			)
1728 		__field(	int,	type			)
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(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_cache *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->key.objectid,
1861 		__entry->len	= bg_cache->key.offset,
1862 		__entry->used	= btrfs_block_group_used(&bg_cache->item);
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_cache *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_cache *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_cache *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 			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 			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 			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_clear_lock_blocking_read);
2090 DEFINE_BTRFS_LOCK_EVENT(btrfs_clear_lock_blocking_write);
2091 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_read_lock);
2092 DEFINE_BTRFS_LOCK_EVENT(btrfs_try_tree_write_lock);
2093 DEFINE_BTRFS_LOCK_EVENT(btrfs_tree_read_lock_atomic);
2094 
2095 DECLARE_EVENT_CLASS(btrfs__space_info_update,
2096 
2097 	TP_PROTO(struct btrfs_fs_info *fs_info,
2098 		 struct btrfs_space_info *sinfo, u64 old, s64 diff),
2099 
2100 	TP_ARGS(fs_info, sinfo, old, diff),
2101 
2102 	TP_STRUCT__entry_btrfs(
2103 		__field(	u64,	type		)
2104 		__field(	u64,	old		)
2105 		__field(	s64,	diff		)
2106 	),
2107 
2108 	TP_fast_assign_btrfs(fs_info,
2109 		__entry->type	= sinfo->flags;
2110 		__entry->old	= old;
2111 		__entry->diff	= diff;
2112 	),
2113 	TP_printk_btrfs("type=%s old=%llu diff=%lld",
2114 		__print_flags(__entry->type, "|", BTRFS_GROUP_FLAGS),
2115 		__entry->old, __entry->diff)
2116 );
2117 
2118 DEFINE_EVENT(btrfs__space_info_update, update_bytes_may_use,
2119 
2120 	TP_PROTO(struct btrfs_fs_info *fs_info,
2121 		 struct btrfs_space_info *sinfo, u64 old, s64 diff),
2122 
2123 	TP_ARGS(fs_info, sinfo, old, diff)
2124 );
2125 
2126 DEFINE_EVENT(btrfs__space_info_update, update_bytes_pinned,
2127 
2128 	TP_PROTO(struct btrfs_fs_info *fs_info,
2129 		 struct btrfs_space_info *sinfo, u64 old, s64 diff),
2130 
2131 	TP_ARGS(fs_info, sinfo, old, diff)
2132 );
2133 
2134 #endif /* _TRACE_BTRFS_H */
2135 
2136 /* This part must be outside protection */
2137 #include <trace/define_trace.h>
2138