Merge tag 'fcoe-3.13' into for-linus
[linux-drm-fsl-dcu.git] / include / trace / events / btrfs.h
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM btrfs
3
4 #if !defined(_TRACE_BTRFS_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_BTRFS_H
6
7 #include <linux/writeback.h>
8 #include <linux/tracepoint.h>
9 #include <trace/events/gfpflags.h>
10
11 struct btrfs_root;
12 struct btrfs_fs_info;
13 struct btrfs_inode;
14 struct extent_map;
15 struct btrfs_ordered_extent;
16 struct btrfs_delayed_ref_node;
17 struct btrfs_delayed_tree_ref;
18 struct btrfs_delayed_data_ref;
19 struct btrfs_delayed_ref_head;
20 struct btrfs_block_group_cache;
21 struct btrfs_free_cluster;
22 struct map_lookup;
23 struct extent_buffer;
24
25 #define show_ref_type(type)                                             \
26         __print_symbolic(type,                                          \
27                 { BTRFS_TREE_BLOCK_REF_KEY,     "TREE_BLOCK_REF" },     \
28                 { BTRFS_EXTENT_DATA_REF_KEY,    "EXTENT_DATA_REF" },    \
29                 { BTRFS_EXTENT_REF_V0_KEY,      "EXTENT_REF_V0" },      \
30                 { BTRFS_SHARED_BLOCK_REF_KEY,   "SHARED_BLOCK_REF" },   \
31                 { BTRFS_SHARED_DATA_REF_KEY,    "SHARED_DATA_REF" })
32
33 #define __show_root_type(obj)                                           \
34         __print_symbolic_u64(obj,                                       \
35                 { BTRFS_ROOT_TREE_OBJECTID,     "ROOT_TREE"     },      \
36                 { BTRFS_EXTENT_TREE_OBJECTID,   "EXTENT_TREE"   },      \
37                 { BTRFS_CHUNK_TREE_OBJECTID,    "CHUNK_TREE"    },      \
38                 { BTRFS_DEV_TREE_OBJECTID,      "DEV_TREE"      },      \
39                 { BTRFS_FS_TREE_OBJECTID,       "FS_TREE"       },      \
40                 { BTRFS_ROOT_TREE_DIR_OBJECTID, "ROOT_TREE_DIR" },      \
41                 { BTRFS_CSUM_TREE_OBJECTID,     "CSUM_TREE"     },      \
42                 { BTRFS_TREE_LOG_OBJECTID,      "TREE_LOG"      },      \
43                 { BTRFS_QUOTA_TREE_OBJECTID,    "QUOTA_TREE"    },      \
44                 { BTRFS_TREE_RELOC_OBJECTID,    "TREE_RELOC"    },      \
45                 { BTRFS_UUID_TREE_OBJECTID,     "UUID_RELOC"    },      \
46                 { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" })
47
48 #define show_root_type(obj)                                             \
49         obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) ||                \
50               (obj >= BTRFS_ROOT_TREE_OBJECTID &&                       \
51                obj <= BTRFS_QUOTA_TREE_OBJECTID)) ? __show_root_type(obj) : "-"
52
53 #define BTRFS_GROUP_FLAGS       \
54         { BTRFS_BLOCK_GROUP_DATA,       "DATA"},        \
55         { BTRFS_BLOCK_GROUP_SYSTEM,     "SYSTEM"},      \
56         { BTRFS_BLOCK_GROUP_METADATA,   "METADATA"},    \
57         { BTRFS_BLOCK_GROUP_RAID0,      "RAID0"},       \
58         { BTRFS_BLOCK_GROUP_RAID1,      "RAID1"},       \
59         { BTRFS_BLOCK_GROUP_DUP,        "DUP"},         \
60         { BTRFS_BLOCK_GROUP_RAID10,     "RAID10"},      \
61         { BTRFS_BLOCK_GROUP_RAID5,      "RAID5"},       \
62         { BTRFS_BLOCK_GROUP_RAID6,      "RAID6"}
63
64 #define BTRFS_UUID_SIZE 16
65
66 TRACE_EVENT(btrfs_transaction_commit,
67
68         TP_PROTO(struct btrfs_root *root),
69
70         TP_ARGS(root),
71
72         TP_STRUCT__entry(
73                 __field(        u64,  generation                )
74                 __field(        u64,  root_objectid             )
75         ),
76
77         TP_fast_assign(
78                 __entry->generation     = root->fs_info->generation;
79                 __entry->root_objectid  = root->root_key.objectid;
80         ),
81
82         TP_printk("root = %llu(%s), gen = %llu",
83                   show_root_type(__entry->root_objectid),
84                   (unsigned long long)__entry->generation)
85 );
86
87 DECLARE_EVENT_CLASS(btrfs__inode,
88
89         TP_PROTO(struct inode *inode),
90
91         TP_ARGS(inode),
92
93         TP_STRUCT__entry(
94                 __field(        ino_t,  ino                     )
95                 __field(        blkcnt_t,  blocks               )
96                 __field(        u64,  disk_i_size               )
97                 __field(        u64,  generation                )
98                 __field(        u64,  last_trans                )
99                 __field(        u64,  logged_trans              )
100                 __field(        u64,  root_objectid             )
101         ),
102
103         TP_fast_assign(
104                 __entry->ino    = inode->i_ino;
105                 __entry->blocks = inode->i_blocks;
106                 __entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
107                 __entry->generation = BTRFS_I(inode)->generation;
108                 __entry->last_trans = BTRFS_I(inode)->last_trans;
109                 __entry->logged_trans = BTRFS_I(inode)->logged_trans;
110                 __entry->root_objectid =
111                                 BTRFS_I(inode)->root->root_key.objectid;
112         ),
113
114         TP_printk("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
115                   "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu",
116                   show_root_type(__entry->root_objectid),
117                   (unsigned long long)__entry->generation,
118                   (unsigned long)__entry->ino,
119                   (unsigned long long)__entry->blocks,
120                   (unsigned long long)__entry->disk_i_size,
121                   (unsigned long long)__entry->last_trans,
122                   (unsigned long long)__entry->logged_trans)
123 );
124
125 DEFINE_EVENT(btrfs__inode, btrfs_inode_new,
126
127         TP_PROTO(struct inode *inode),
128
129         TP_ARGS(inode)
130 );
131
132 DEFINE_EVENT(btrfs__inode, btrfs_inode_request,
133
134         TP_PROTO(struct inode *inode),
135
136         TP_ARGS(inode)
137 );
138
139 DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
140
141         TP_PROTO(struct inode *inode),
142
143         TP_ARGS(inode)
144 );
145
146 #define __show_map_type(type)                                           \
147         __print_symbolic_u64(type,                                      \
148                 { EXTENT_MAP_LAST_BYTE, "LAST_BYTE"     },              \
149                 { EXTENT_MAP_HOLE,      "HOLE"          },              \
150                 { EXTENT_MAP_INLINE,    "INLINE"        },              \
151                 { EXTENT_MAP_DELALLOC,  "DELALLOC"      })
152
153 #define show_map_type(type)                     \
154         type, (type >= EXTENT_MAP_LAST_BYTE) ? "-" :  __show_map_type(type)
155
156 #define show_map_flags(flag)                                            \
157         __print_flags(flag, "|",                                        \
158                 { EXTENT_FLAG_PINNED,           "PINNED"        },      \
159                 { EXTENT_FLAG_COMPRESSED,       "COMPRESSED"    },      \
160                 { EXTENT_FLAG_VACANCY,          "VACANCY"       },      \
161                 { EXTENT_FLAG_PREALLOC,         "PREALLOC"      },      \
162                 { EXTENT_FLAG_LOGGING,          "LOGGING"       },      \
163                 { EXTENT_FLAG_FILLING,          "FILLING"       })
164
165 TRACE_EVENT(btrfs_get_extent,
166
167         TP_PROTO(struct btrfs_root *root, struct extent_map *map),
168
169         TP_ARGS(root, map),
170
171         TP_STRUCT__entry(
172                 __field(        u64,  root_objectid     )
173                 __field(        u64,  start             )
174                 __field(        u64,  len               )
175                 __field(        u64,  orig_start        )
176                 __field(        u64,  block_start       )
177                 __field(        u64,  block_len         )
178                 __field(        unsigned long,  flags   )
179                 __field(        int,  refs              )
180                 __field(        unsigned int,  compress_type    )
181         ),
182
183         TP_fast_assign(
184                 __entry->root_objectid  = root->root_key.objectid;
185                 __entry->start          = map->start;
186                 __entry->len            = map->len;
187                 __entry->orig_start     = map->orig_start;
188                 __entry->block_start    = map->block_start;
189                 __entry->block_len      = map->block_len;
190                 __entry->flags          = map->flags;
191                 __entry->refs           = atomic_read(&map->refs);
192                 __entry->compress_type  = map->compress_type;
193         ),
194
195         TP_printk("root = %llu(%s), start = %llu, len = %llu, "
196                   "orig_start = %llu, block_start = %llu(%s), "
197                   "block_len = %llu, flags = %s, refs = %u, "
198                   "compress_type = %u",
199                   show_root_type(__entry->root_objectid),
200                   (unsigned long long)__entry->start,
201                   (unsigned long long)__entry->len,
202                   (unsigned long long)__entry->orig_start,
203                   show_map_type(__entry->block_start),
204                   (unsigned long long)__entry->block_len,
205                   show_map_flags(__entry->flags),
206                   __entry->refs, __entry->compress_type)
207 );
208
209 #define show_ordered_flags(flags)                                       \
210         __print_symbolic(flags,                                         \
211                 { BTRFS_ORDERED_IO_DONE,        "IO_DONE"       },      \
212                 { BTRFS_ORDERED_COMPLETE,       "COMPLETE"      },      \
213                 { BTRFS_ORDERED_NOCOW,          "NOCOW"         },      \
214                 { BTRFS_ORDERED_COMPRESSED,     "COMPRESSED"    },      \
215                 { BTRFS_ORDERED_PREALLOC,       "PREALLOC"      },      \
216                 { BTRFS_ORDERED_DIRECT,         "DIRECT"        },      \
217                 { BTRFS_ORDERED_IOERR,          "IOERR"         },      \
218                 { BTRFS_ORDERED_UPDATED_ISIZE,  "UPDATED_ISIZE" },      \
219                 { BTRFS_ORDERED_LOGGED_CSUM,    "LOGGED_CSUM"   })
220
221
222 DECLARE_EVENT_CLASS(btrfs__ordered_extent,
223
224         TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
225
226         TP_ARGS(inode, ordered),
227
228         TP_STRUCT__entry(
229                 __field(        ino_t,  ino             )
230                 __field(        u64,  file_offset       )
231                 __field(        u64,  start             )
232                 __field(        u64,  len               )
233                 __field(        u64,  disk_len          )
234                 __field(        u64,  bytes_left        )
235                 __field(        unsigned long,  flags   )
236                 __field(        int,  compress_type     )
237                 __field(        int,  refs              )
238                 __field(        u64,  root_objectid     )
239         ),
240
241         TP_fast_assign(
242                 __entry->ino            = inode->i_ino;
243                 __entry->file_offset    = ordered->file_offset;
244                 __entry->start          = ordered->start;
245                 __entry->len            = ordered->len;
246                 __entry->disk_len       = ordered->disk_len;
247                 __entry->bytes_left     = ordered->bytes_left;
248                 __entry->flags          = ordered->flags;
249                 __entry->compress_type  = ordered->compress_type;
250                 __entry->refs           = atomic_read(&ordered->refs);
251                 __entry->root_objectid  =
252                                 BTRFS_I(inode)->root->root_key.objectid;
253         ),
254
255         TP_printk("root = %llu(%s), ino = %llu, file_offset = %llu, "
256                   "start = %llu, len = %llu, disk_len = %llu, "
257                   "bytes_left = %llu, flags = %s, compress_type = %d, "
258                   "refs = %d",
259                   show_root_type(__entry->root_objectid),
260                   (unsigned long long)__entry->ino,
261                   (unsigned long long)__entry->file_offset,
262                   (unsigned long long)__entry->start,
263                   (unsigned long long)__entry->len,
264                   (unsigned long long)__entry->disk_len,
265                   (unsigned long long)__entry->bytes_left,
266                   show_ordered_flags(__entry->flags),
267                   __entry->compress_type, __entry->refs)
268 );
269
270 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_add,
271
272         TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
273
274         TP_ARGS(inode, ordered)
275 );
276
277 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_remove,
278
279         TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
280
281         TP_ARGS(inode, ordered)
282 );
283
284 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_start,
285
286         TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
287
288         TP_ARGS(inode, ordered)
289 );
290
291 DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_put,
292
293         TP_PROTO(struct inode *inode, struct btrfs_ordered_extent *ordered),
294
295         TP_ARGS(inode, ordered)
296 );
297
298 DECLARE_EVENT_CLASS(btrfs__writepage,
299
300         TP_PROTO(struct page *page, struct inode *inode,
301                  struct writeback_control *wbc),
302
303         TP_ARGS(page, inode, wbc),
304
305         TP_STRUCT__entry(
306                 __field(        ino_t,  ino                     )
307                 __field(        pgoff_t,  index                 )
308                 __field(        long,   nr_to_write             )
309                 __field(        long,   pages_skipped           )
310                 __field(        loff_t, range_start             )
311                 __field(        loff_t, range_end               )
312                 __field(        char,   for_kupdate             )
313                 __field(        char,   for_reclaim             )
314                 __field(        char,   range_cyclic            )
315                 __field(        pgoff_t,  writeback_index       )
316                 __field(        u64,    root_objectid           )
317         ),
318
319         TP_fast_assign(
320                 __entry->ino            = inode->i_ino;
321                 __entry->index          = page->index;
322                 __entry->nr_to_write    = wbc->nr_to_write;
323                 __entry->pages_skipped  = wbc->pages_skipped;
324                 __entry->range_start    = wbc->range_start;
325                 __entry->range_end      = wbc->range_end;
326                 __entry->for_kupdate    = wbc->for_kupdate;
327                 __entry->for_reclaim    = wbc->for_reclaim;
328                 __entry->range_cyclic   = wbc->range_cyclic;
329                 __entry->writeback_index = inode->i_mapping->writeback_index;
330                 __entry->root_objectid  =
331                                  BTRFS_I(inode)->root->root_key.objectid;
332         ),
333
334         TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, "
335                   "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, "
336                   "range_end = %llu, for_kupdate = %d, "
337                   "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu",
338                   show_root_type(__entry->root_objectid),
339                   (unsigned long)__entry->ino, __entry->index,
340                   __entry->nr_to_write, __entry->pages_skipped,
341                   __entry->range_start, __entry->range_end,
342                   __entry->for_kupdate,
343                   __entry->for_reclaim, __entry->range_cyclic,
344                   (unsigned long)__entry->writeback_index)
345 );
346
347 DEFINE_EVENT(btrfs__writepage, __extent_writepage,
348
349         TP_PROTO(struct page *page, struct inode *inode,
350                  struct writeback_control *wbc),
351
352         TP_ARGS(page, inode, wbc)
353 );
354
355 TRACE_EVENT(btrfs_writepage_end_io_hook,
356
357         TP_PROTO(struct page *page, u64 start, u64 end, int uptodate),
358
359         TP_ARGS(page, start, end, uptodate),
360
361         TP_STRUCT__entry(
362                 __field(        ino_t,   ino            )
363                 __field(        pgoff_t, index          )
364                 __field(        u64,     start          )
365                 __field(        u64,     end            )
366                 __field(        int,     uptodate       )
367                 __field(        u64,    root_objectid   )
368         ),
369
370         TP_fast_assign(
371                 __entry->ino    = page->mapping->host->i_ino;
372                 __entry->index  = page->index;
373                 __entry->start  = start;
374                 __entry->end    = end;
375                 __entry->uptodate = uptodate;
376                 __entry->root_objectid  =
377                          BTRFS_I(page->mapping->host)->root->root_key.objectid;
378         ),
379
380         TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
381                   "end = %llu, uptodate = %d",
382                   show_root_type(__entry->root_objectid),
383                   (unsigned long)__entry->ino, (unsigned long)__entry->index,
384                   (unsigned long long)__entry->start,
385                   (unsigned long long)__entry->end, __entry->uptodate)
386 );
387
388 TRACE_EVENT(btrfs_sync_file,
389
390         TP_PROTO(struct file *file, int datasync),
391
392         TP_ARGS(file, datasync),
393
394         TP_STRUCT__entry(
395                 __field(        ino_t,  ino             )
396                 __field(        ino_t,  parent          )
397                 __field(        int,    datasync        )
398                 __field(        u64,    root_objectid   )
399         ),
400
401         TP_fast_assign(
402                 struct dentry *dentry = file->f_path.dentry;
403                 struct inode *inode = dentry->d_inode;
404
405                 __entry->ino            = inode->i_ino;
406                 __entry->parent         = dentry->d_parent->d_inode->i_ino;
407                 __entry->datasync       = datasync;
408                 __entry->root_objectid  =
409                                  BTRFS_I(inode)->root->root_key.objectid;
410         ),
411
412         TP_printk("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
413                   show_root_type(__entry->root_objectid),
414                   (unsigned long)__entry->ino, (unsigned long)__entry->parent,
415                   __entry->datasync)
416 );
417
418 TRACE_EVENT(btrfs_sync_fs,
419
420         TP_PROTO(int wait),
421
422         TP_ARGS(wait),
423
424         TP_STRUCT__entry(
425                 __field(        int,  wait              )
426         ),
427
428         TP_fast_assign(
429                 __entry->wait   = wait;
430         ),
431
432         TP_printk("wait = %d", __entry->wait)
433 );
434
435 #define show_ref_action(action)                                         \
436         __print_symbolic(action,                                        \
437                 { BTRFS_ADD_DELAYED_REF,    "ADD_DELAYED_REF" },        \
438                 { BTRFS_DROP_DELAYED_REF,   "DROP_DELAYED_REF" },       \
439                 { BTRFS_ADD_DELAYED_EXTENT, "ADD_DELAYED_EXTENT" },     \
440                 { BTRFS_UPDATE_DELAYED_HEAD, "UPDATE_DELAYED_HEAD" })
441                         
442
443 DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
444
445         TP_PROTO(struct btrfs_delayed_ref_node *ref,
446                  struct btrfs_delayed_tree_ref *full_ref,
447                  int action),
448
449         TP_ARGS(ref, full_ref, action),
450
451         TP_STRUCT__entry(
452                 __field(        u64,  bytenr            )
453                 __field(        u64,  num_bytes         )
454                 __field(        int,  action            ) 
455                 __field(        u64,  parent            )
456                 __field(        u64,  ref_root          )
457                 __field(        int,  level             )
458                 __field(        int,  type              )
459                 __field(        u64,  seq               )
460         ),
461
462         TP_fast_assign(
463                 __entry->bytenr         = ref->bytenr;
464                 __entry->num_bytes      = ref->num_bytes;
465                 __entry->action         = action;
466                 __entry->parent         = full_ref->parent;
467                 __entry->ref_root       = full_ref->root;
468                 __entry->level          = full_ref->level;
469                 __entry->type           = ref->type;
470                 __entry->seq            = ref->seq;
471         ),
472
473         TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
474                   "parent = %llu(%s), ref_root = %llu(%s), level = %d, "
475                   "type = %s, seq = %llu",
476                   (unsigned long long)__entry->bytenr,
477                   (unsigned long long)__entry->num_bytes,
478                   show_ref_action(__entry->action),
479                   show_root_type(__entry->parent),
480                   show_root_type(__entry->ref_root),
481                   __entry->level, show_ref_type(__entry->type),
482                   (unsigned long long)__entry->seq)
483 );
484
485 DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
486
487         TP_PROTO(struct btrfs_delayed_ref_node *ref,
488                  struct btrfs_delayed_tree_ref *full_ref,
489                  int action),
490
491         TP_ARGS(ref, full_ref, action)
492 );
493
494 DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
495
496         TP_PROTO(struct btrfs_delayed_ref_node *ref,
497                  struct btrfs_delayed_tree_ref *full_ref,
498                  int action),
499
500         TP_ARGS(ref, full_ref, action)
501 );
502
503 DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
504
505         TP_PROTO(struct btrfs_delayed_ref_node *ref,
506                  struct btrfs_delayed_data_ref *full_ref,
507                  int action),
508
509         TP_ARGS(ref, full_ref, action),
510
511         TP_STRUCT__entry(
512                 __field(        u64,  bytenr            )
513                 __field(        u64,  num_bytes         )
514                 __field(        int,  action            ) 
515                 __field(        u64,  parent            )
516                 __field(        u64,  ref_root          )
517                 __field(        u64,  owner             )
518                 __field(        u64,  offset            )
519                 __field(        int,  type              )
520                 __field(        u64,  seq               )
521         ),
522
523         TP_fast_assign(
524                 __entry->bytenr         = ref->bytenr;
525                 __entry->num_bytes      = ref->num_bytes;
526                 __entry->action         = action;
527                 __entry->parent         = full_ref->parent;
528                 __entry->ref_root       = full_ref->root;
529                 __entry->owner          = full_ref->objectid;
530                 __entry->offset         = full_ref->offset;
531                 __entry->type           = ref->type;
532                 __entry->seq            = ref->seq;
533         ),
534
535         TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
536                   "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, "
537                   "offset = %llu, type = %s, seq = %llu",
538                   (unsigned long long)__entry->bytenr,
539                   (unsigned long long)__entry->num_bytes,
540                   show_ref_action(__entry->action),
541                   show_root_type(__entry->parent),
542                   show_root_type(__entry->ref_root),
543                   (unsigned long long)__entry->owner,
544                   (unsigned long long)__entry->offset,
545                   show_ref_type(__entry->type),
546                   (unsigned long long)__entry->seq)
547 );
548
549 DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
550
551         TP_PROTO(struct btrfs_delayed_ref_node *ref,
552                  struct btrfs_delayed_data_ref *full_ref,
553                  int action),
554
555         TP_ARGS(ref, full_ref, action)
556 );
557
558 DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
559
560         TP_PROTO(struct btrfs_delayed_ref_node *ref,
561                  struct btrfs_delayed_data_ref *full_ref,
562                  int action),
563
564         TP_ARGS(ref, full_ref, action)
565 );
566
567 DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
568
569         TP_PROTO(struct btrfs_delayed_ref_node *ref,
570                  struct btrfs_delayed_ref_head *head_ref,
571                  int action),
572
573         TP_ARGS(ref, head_ref, action),
574
575         TP_STRUCT__entry(
576                 __field(        u64,  bytenr            )
577                 __field(        u64,  num_bytes         )
578                 __field(        int,  action            ) 
579                 __field(        int,  is_data           )
580         ),
581
582         TP_fast_assign(
583                 __entry->bytenr         = ref->bytenr;
584                 __entry->num_bytes      = ref->num_bytes;
585                 __entry->action         = action;
586                 __entry->is_data        = head_ref->is_data;
587         ),
588
589         TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
590                   (unsigned long long)__entry->bytenr,
591                   (unsigned long long)__entry->num_bytes,
592                   show_ref_action(__entry->action),
593                   __entry->is_data)
594 );
595
596 DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
597
598         TP_PROTO(struct btrfs_delayed_ref_node *ref,
599                  struct btrfs_delayed_ref_head *head_ref,
600                  int action),
601
602         TP_ARGS(ref, head_ref, action)
603 );
604
605 DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
606
607         TP_PROTO(struct btrfs_delayed_ref_node *ref,
608                  struct btrfs_delayed_ref_head *head_ref,
609                  int action),
610
611         TP_ARGS(ref, head_ref, action)
612 );
613
614 #define show_chunk_type(type)                                   \
615         __print_flags(type, "|",                                \
616                 { BTRFS_BLOCK_GROUP_DATA,       "DATA"  },      \
617                 { BTRFS_BLOCK_GROUP_SYSTEM,     "SYSTEM"},      \
618                 { BTRFS_BLOCK_GROUP_METADATA,   "METADATA"},    \
619                 { BTRFS_BLOCK_GROUP_RAID0,      "RAID0" },      \
620                 { BTRFS_BLOCK_GROUP_RAID1,      "RAID1" },      \
621                 { BTRFS_BLOCK_GROUP_DUP,        "DUP"   },      \
622                 { BTRFS_BLOCK_GROUP_RAID10,     "RAID10"},      \
623                 { BTRFS_BLOCK_GROUP_RAID5,      "RAID5" },      \
624                 { BTRFS_BLOCK_GROUP_RAID6,      "RAID6" })
625
626 DECLARE_EVENT_CLASS(btrfs__chunk,
627
628         TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
629                  u64 offset, u64 size),
630
631         TP_ARGS(root, map, offset, size),
632
633         TP_STRUCT__entry(
634                 __field(        int,  num_stripes               )
635                 __field(        u64,  type                      )
636                 __field(        int,  sub_stripes               )
637                 __field(        u64,  offset                    )
638                 __field(        u64,  size                      )
639                 __field(        u64,  root_objectid             )
640         ),
641
642         TP_fast_assign(
643                 __entry->num_stripes    = map->num_stripes;
644                 __entry->type           = map->type;
645                 __entry->sub_stripes    = map->sub_stripes;
646                 __entry->offset         = offset;
647                 __entry->size           = size;
648                 __entry->root_objectid  = root->root_key.objectid;
649         ),
650
651         TP_printk("root = %llu(%s), offset = %llu, size = %llu, "
652                   "num_stripes = %d, sub_stripes = %d, type = %s",
653                   show_root_type(__entry->root_objectid),
654                   (unsigned long long)__entry->offset,
655                   (unsigned long long)__entry->size,
656                   __entry->num_stripes, __entry->sub_stripes,
657                   show_chunk_type(__entry->type))
658 );
659
660 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_alloc,
661
662         TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
663                  u64 offset, u64 size),
664
665         TP_ARGS(root, map, offset, size)
666 );
667
668 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_free,
669
670         TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
671                  u64 offset, u64 size),
672
673         TP_ARGS(root, map, offset, size)
674 );
675
676 TRACE_EVENT(btrfs_cow_block,
677
678         TP_PROTO(struct btrfs_root *root, struct extent_buffer *buf,
679                  struct extent_buffer *cow),
680
681         TP_ARGS(root, buf, cow),
682
683         TP_STRUCT__entry(
684                 __field(        u64,  root_objectid             )
685                 __field(        u64,  buf_start                 )
686                 __field(        int,  refs                      )
687                 __field(        u64,  cow_start                 )
688                 __field(        int,  buf_level                 )
689                 __field(        int,  cow_level                 )
690         ),
691
692         TP_fast_assign(
693                 __entry->root_objectid  = root->root_key.objectid;
694                 __entry->buf_start      = buf->start;
695                 __entry->refs           = atomic_read(&buf->refs);
696                 __entry->cow_start      = cow->start;
697                 __entry->buf_level      = btrfs_header_level(buf);
698                 __entry->cow_level      = btrfs_header_level(cow);
699         ),
700
701         TP_printk("root = %llu(%s), refs = %d, orig_buf = %llu "
702                   "(orig_level = %d), cow_buf = %llu (cow_level = %d)",
703                   show_root_type(__entry->root_objectid),
704                   __entry->refs,
705                   (unsigned long long)__entry->buf_start,
706                   __entry->buf_level,
707                   (unsigned long long)__entry->cow_start,
708                   __entry->cow_level)
709 );
710
711 TRACE_EVENT(btrfs_space_reservation,
712
713         TP_PROTO(struct btrfs_fs_info *fs_info, char *type, u64 val,
714                  u64 bytes, int reserve),
715
716         TP_ARGS(fs_info, type, val, bytes, reserve),
717
718         TP_STRUCT__entry(
719                 __array(        u8,     fsid,   BTRFS_UUID_SIZE )
720                 __string(       type,   type                    )
721                 __field(        u64,    val                     )
722                 __field(        u64,    bytes                   )
723                 __field(        int,    reserve                 )
724         ),
725
726         TP_fast_assign(
727                 memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE);
728                 __assign_str(type, type);
729                 __entry->val            = val;
730                 __entry->bytes          = bytes;
731                 __entry->reserve        = reserve;
732         ),
733
734         TP_printk("%pU: %s: %Lu %s %Lu", __entry->fsid, __get_str(type),
735                   __entry->val, __entry->reserve ? "reserve" : "release",
736                   __entry->bytes)
737 );
738
739 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
740
741         TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
742
743         TP_ARGS(root, start, len),
744
745         TP_STRUCT__entry(
746                 __field(        u64,  root_objectid             )
747                 __field(        u64,  start                     )
748                 __field(        u64,  len                       )
749         ),
750
751         TP_fast_assign(
752                 __entry->root_objectid  = root->root_key.objectid;
753                 __entry->start          = start;
754                 __entry->len            = len;
755         ),
756
757         TP_printk("root = %llu(%s), start = %llu, len = %llu",
758                   show_root_type(__entry->root_objectid),
759                   (unsigned long long)__entry->start,
760                   (unsigned long long)__entry->len)
761 );
762
763 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_alloc,
764
765         TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
766
767         TP_ARGS(root, start, len)
768 );
769
770 DEFINE_EVENT(btrfs__reserved_extent,  btrfs_reserved_extent_free,
771
772         TP_PROTO(struct btrfs_root *root, u64 start, u64 len),
773
774         TP_ARGS(root, start, len)
775 );
776
777 TRACE_EVENT(find_free_extent,
778
779         TP_PROTO(struct btrfs_root *root, u64 num_bytes, u64 empty_size,
780                  u64 data),
781
782         TP_ARGS(root, num_bytes, empty_size, data),
783
784         TP_STRUCT__entry(
785                 __field(        u64,    root_objectid           )
786                 __field(        u64,    num_bytes               )
787                 __field(        u64,    empty_size              )
788                 __field(        u64,    data                    )
789         ),
790
791         TP_fast_assign(
792                 __entry->root_objectid  = root->root_key.objectid;
793                 __entry->num_bytes      = num_bytes;
794                 __entry->empty_size     = empty_size;
795                 __entry->data           = data;
796         ),
797
798         TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
799                   "flags = %Lu(%s)", show_root_type(__entry->root_objectid),
800                   __entry->num_bytes, __entry->empty_size, __entry->data,
801                   __print_flags((unsigned long)__entry->data, "|",
802                                  BTRFS_GROUP_FLAGS))
803 );
804
805 DECLARE_EVENT_CLASS(btrfs__reserve_extent,
806
807         TP_PROTO(struct btrfs_root *root,
808                  struct btrfs_block_group_cache *block_group, u64 start,
809                  u64 len),
810
811         TP_ARGS(root, block_group, start, len),
812
813         TP_STRUCT__entry(
814                 __field(        u64,    root_objectid           )
815                 __field(        u64,    bg_objectid             )
816                 __field(        u64,    flags                   )
817                 __field(        u64,    start                   )
818                 __field(        u64,    len                     )
819         ),
820
821         TP_fast_assign(
822                 __entry->root_objectid  = root->root_key.objectid;
823                 __entry->bg_objectid    = block_group->key.objectid;
824                 __entry->flags          = block_group->flags;
825                 __entry->start          = start;
826                 __entry->len            = len;
827         ),
828
829         TP_printk("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
830                   "start = %Lu, len = %Lu",
831                   show_root_type(__entry->root_objectid), __entry->bg_objectid,
832                   __entry->flags, __print_flags((unsigned long)__entry->flags,
833                                                 "|", BTRFS_GROUP_FLAGS),
834                   __entry->start, __entry->len)
835 );
836
837 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
838
839         TP_PROTO(struct btrfs_root *root,
840                  struct btrfs_block_group_cache *block_group, u64 start,
841                  u64 len),
842
843         TP_ARGS(root, block_group, start, len)
844 );
845
846 DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
847
848         TP_PROTO(struct btrfs_root *root,
849                  struct btrfs_block_group_cache *block_group, u64 start,
850                  u64 len),
851
852         TP_ARGS(root, block_group, start, len)
853 );
854
855 TRACE_EVENT(btrfs_find_cluster,
856
857         TP_PROTO(struct btrfs_block_group_cache *block_group, u64 start,
858                  u64 bytes, u64 empty_size, u64 min_bytes),
859
860         TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
861
862         TP_STRUCT__entry(
863                 __field(        u64,    bg_objectid             )
864                 __field(        u64,    flags                   )
865                 __field(        u64,    start                   )
866                 __field(        u64,    bytes                   )
867                 __field(        u64,    empty_size              )
868                 __field(        u64,    min_bytes               )
869         ),
870
871         TP_fast_assign(
872                 __entry->bg_objectid    = block_group->key.objectid;
873                 __entry->flags          = block_group->flags;
874                 __entry->start          = start;
875                 __entry->bytes          = bytes;
876                 __entry->empty_size     = empty_size;
877                 __entry->min_bytes      = min_bytes;
878         ),
879
880         TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
881                   " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid,
882                   __entry->flags,
883                   __print_flags((unsigned long)__entry->flags, "|",
884                                 BTRFS_GROUP_FLAGS), __entry->start,
885                   __entry->bytes, __entry->empty_size,  __entry->min_bytes)
886 );
887
888 TRACE_EVENT(btrfs_failed_cluster_setup,
889
890         TP_PROTO(struct btrfs_block_group_cache *block_group),
891
892         TP_ARGS(block_group),
893
894         TP_STRUCT__entry(
895                 __field(        u64,    bg_objectid             )
896         ),
897
898         TP_fast_assign(
899                 __entry->bg_objectid    = block_group->key.objectid;
900         ),
901
902         TP_printk("block_group = %Lu", __entry->bg_objectid)
903 );
904
905 TRACE_EVENT(btrfs_setup_cluster,
906
907         TP_PROTO(struct btrfs_block_group_cache *block_group,
908                  struct btrfs_free_cluster *cluster, u64 size, int bitmap),
909
910         TP_ARGS(block_group, cluster, size, bitmap),
911
912         TP_STRUCT__entry(
913                 __field(        u64,    bg_objectid             )
914                 __field(        u64,    flags                   )
915                 __field(        u64,    start                   )
916                 __field(        u64,    max_size                )
917                 __field(        u64,    size                    )
918                 __field(        int,    bitmap                  )
919         ),
920
921         TP_fast_assign(
922                 __entry->bg_objectid    = block_group->key.objectid;
923                 __entry->flags          = block_group->flags;
924                 __entry->start          = cluster->window_start;
925                 __entry->max_size       = cluster->max_size;
926                 __entry->size           = size;
927                 __entry->bitmap         = bitmap;
928         ),
929
930         TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
931                   "size = %Lu, max_size = %Lu, bitmap = %d",
932                   __entry->bg_objectid,
933                   __entry->flags,
934                   __print_flags((unsigned long)__entry->flags, "|",
935                                 BTRFS_GROUP_FLAGS), __entry->start,
936                   __entry->size, __entry->max_size, __entry->bitmap)
937 );
938
939 struct extent_state;
940 TRACE_EVENT(alloc_extent_state,
941
942         TP_PROTO(struct extent_state *state, gfp_t mask, unsigned long IP),
943
944         TP_ARGS(state, mask, IP),
945
946         TP_STRUCT__entry(
947                 __field(struct extent_state *, state)
948                 __field(gfp_t, mask)
949                 __field(unsigned long, ip)
950         ),
951
952         TP_fast_assign(
953                 __entry->state  = state,
954                 __entry->mask   = mask,
955                 __entry->ip     = IP
956         ),
957
958         TP_printk("state=%p; mask = %s; caller = %pF", __entry->state,
959                   show_gfp_flags(__entry->mask), (void *)__entry->ip)
960 );
961
962 TRACE_EVENT(free_extent_state,
963
964         TP_PROTO(struct extent_state *state, unsigned long IP),
965
966         TP_ARGS(state, IP),
967
968         TP_STRUCT__entry(
969                 __field(struct extent_state *, state)
970                 __field(unsigned long, ip)
971         ),
972
973         TP_fast_assign(
974                 __entry->state  = state,
975                 __entry->ip = IP
976         ),
977
978         TP_printk(" state=%p; caller = %pF", __entry->state,
979                   (void *)__entry->ip)
980 );
981
982 #endif /* _TRACE_BTRFS_H */
983
984 /* This part must be outside protection */
985 #include <trace/define_trace.h>