Commit c0872323 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: print-tree: debugging output enhancement

This patch enhances the following things:

- tree block header
  * add generation and owner output for node and leaf
- node pointer generation output
- allow btrfs_print_tree() to not follow nodes
  * just like btrfs-progs

Please note that, although function btrfs_print_tree() is not called by
anyone right now, it's still a pretty useful function to debug kernel.
So that function is still kept for later use.
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarLu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 5e388e95
...@@ -189,9 +189,10 @@ void btrfs_print_leaf(struct extent_buffer *l) ...@@ -189,9 +189,10 @@ void btrfs_print_leaf(struct extent_buffer *l)
fs_info = l->fs_info; fs_info = l->fs_info;
nr = btrfs_header_nritems(l); nr = btrfs_header_nritems(l);
btrfs_info(fs_info, "leaf %llu total ptrs %d free space %d", btrfs_info(fs_info,
btrfs_header_bytenr(l), nr, "leaf %llu gen %llu total ptrs %d free space %d owner %llu",
btrfs_leaf_free_space(fs_info, l)); btrfs_header_bytenr(l), btrfs_header_generation(l), nr,
btrfs_leaf_free_space(fs_info, l), btrfs_header_owner(l));
for (i = 0 ; i < nr ; i++) { for (i = 0 ; i < nr ; i++) {
item = btrfs_item_nr(i); item = btrfs_item_nr(i);
btrfs_item_key_to_cpu(l, &key, i); btrfs_item_key_to_cpu(l, &key, i);
...@@ -325,7 +326,7 @@ void btrfs_print_leaf(struct extent_buffer *l) ...@@ -325,7 +326,7 @@ void btrfs_print_leaf(struct extent_buffer *l)
} }
} }
void btrfs_print_tree(struct extent_buffer *c) void btrfs_print_tree(struct extent_buffer *c, bool follow)
{ {
struct btrfs_fs_info *fs_info; struct btrfs_fs_info *fs_info;
int i; u32 nr; int i; u32 nr;
...@@ -342,15 +343,19 @@ void btrfs_print_tree(struct extent_buffer *c) ...@@ -342,15 +343,19 @@ void btrfs_print_tree(struct extent_buffer *c)
return; return;
} }
btrfs_info(fs_info, btrfs_info(fs_info,
"node %llu level %d total ptrs %d free spc %u", "node %llu level %d gen %llu total ptrs %d free spc %u owner %llu",
btrfs_header_bytenr(c), level, nr, btrfs_header_bytenr(c), level, btrfs_header_generation(c),
(u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr); nr, (u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr,
btrfs_header_owner(c));
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
btrfs_node_key_to_cpu(c, &key, i); btrfs_node_key_to_cpu(c, &key, i);
pr_info("\tkey %d (%llu %u %llu) block %llu\n", pr_info("\tkey %d (%llu %u %llu) block %llu gen %llu\n",
i, key.objectid, key.type, key.offset, i, key.objectid, key.type, key.offset,
btrfs_node_blockptr(c, i)); btrfs_node_blockptr(c, i),
btrfs_node_ptr_generation(c, i));
} }
if (!follow)
return;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct btrfs_key first_key; struct btrfs_key first_key;
struct extent_buffer *next; struct extent_buffer *next;
...@@ -372,7 +377,7 @@ void btrfs_print_tree(struct extent_buffer *c) ...@@ -372,7 +377,7 @@ void btrfs_print_tree(struct extent_buffer *c)
if (btrfs_header_level(next) != if (btrfs_header_level(next) !=
level - 1) level - 1)
BUG(); BUG();
btrfs_print_tree(next); btrfs_print_tree(next, follow);
free_extent_buffer(next); free_extent_buffer(next);
} }
} }
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
#define BTRFS_PRINT_TREE_H #define BTRFS_PRINT_TREE_H
void btrfs_print_leaf(struct extent_buffer *l); void btrfs_print_leaf(struct extent_buffer *l);
void btrfs_print_tree(struct extent_buffer *c); void btrfs_print_tree(struct extent_buffer *c, bool follow);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment