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