btrfs: print-tree: output enhancement
PATCH 1/2 btrfs: print-tree: output enhancement
This patch enhance 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.
---
Fix title from "btrfs-progs" to "btrfs"
--- fs/btrfs/print-tree.c | 25 +++++++++++++++---------- fs/btrfs/print-tree.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-)
fs/btrfs/print-tree.c +15 -10
@@ -202,9 +202,10 @@ void btrfs_print_leaf(struct extent_buffer *l) fs_info = l->fs_info; nr =btrfs_header_nritems (l); -btrfs_info (fs_info,"leaf %llu total ptrs %d free space %d" , -btrfs_header_bytenr (l), nr, -btrfs_leaf_free_space (fs_info, l)); +btrfs_info (fs_info, +"leaf %llu gen %llu total ptrs %d free space %d owner %llu" , +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++) { item =btrfs_item_nr (i);btrfs_item_key_to_cpu (l, &key, i);
@@ -338,7 +339,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;int i;u32 nr;
@@ -355,15 +356,19 @@ void btrfs_print_tree(struct extent_buffer *c)return ; }btrfs_info (fs_info, -"node %llu level %d total ptrs %d free spc %u" , -btrfs_header_bytenr (c), level, nr, - (u32 )BTRFS_NODEPTRS_PER_BLOCK (fs_info) - nr); +"node %llu level %d gen %llu total ptrs %d free spc %u owner %llu" , +btrfs_header_bytenr (c), level,btrfs_header_generation (c), + nr, (u32 )BTRFS_NODEPTRS_PER_BLOCK (fs_info) - nr, +btrfs_header_owner (c));for (i =0 ; i < nr; 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, -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++) {struct btrfs_key first_key;struct extent_buffer *next;
@@ -385,7 +390,7 @@ void btrfs_print_tree(struct extent_buffer *c)if (btrfs_header_level (next) != level -1 )BUG (); -btrfs_print_tree (next); +btrfs_print_tree (next, follow);free_extent_buffer (next); } }
fs/btrfs/print-tree.h +1 -1
@@ -19,5 +19,5 @@#ifndef __PRINT_TREE_#define __PRINT_TREE_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
Signature · 1 line
2.17.0
PATCH 2/2 btrfs: print-tree: Add locking status output for debug build
It's pretty handy if we can get debug output for locking status of an extent buffer, specially for race related debugging.
So add the following output for btrfs_print_tree() and btrfs_print_leaf():
- refs
- write_locks (as w:%u)
- read_locks (as r:%u)
- blocking_writers (as bw:%u)
- blocking_readers (as br:%u)
- spinning_writers (as sw:%u)
- spinning_readers (as sr:%u)
- lock_owner
- current->pid
--- fs/btrfs/print-tree.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/btrfs/print-tree.c +22 -0
@@ -179,6 +179,26 @@ static void print_uuid_item(struct extent_buffer *l, unsigned long offset, } } +/* +* Helper to output refs and locking status. +* +* Useful to debug race related problem +*/ +static void print_eb_refs_lock (struct extent_buffer *eb) +{ +#ifdef CONFIG_BTRFS_DEBUG +btrfs_info (eb->fs_info, +"refs %u lock(w:%u r:%u bw:%u br:%u sw:%u sr:%u) lock_owner %u current %u" , +atomic_read (&eb->refs),atomic_read (&eb->write_locks), +atomic_read (&eb->read_locks), +atomic_read (&eb->blocking_writers), +atomic_read (&eb->blocking_readers), +atomic_read (&eb->spinning_writers), +atomic_read (&eb->spinning_readers), + eb->lock_owner, current->pid); +#endif +} +void btrfs_print_leaf (struct extent_buffer *l) {struct btrfs_fs_info *fs_info;
@@ -206,6 +226,7 @@ void btrfs_print_leaf(struct extent_buffer *l)"leaf %llu gen %llu total ptrs %d free space %d owner %llu" ,btrfs_header_bytenr (l),btrfs_header_generation (l), nr, btrfs_leaf_free_space(fs_info, l), btrfs_header_owner(l)); +print_eb_refs_lock (l);for (i =0 ; i < nr ; i++) { item =btrfs_item_nr (i);btrfs_item_key_to_cpu (l, &key, i);
@@ -360,6 +381,7 @@ void btrfs_print_tree(struct extent_buffer *c, bool follow)btrfs_header_bytenr (c), level,btrfs_header_generation (c), nr, (u32 )BTRFS_NODEPTRS_PER_BLOCK (fs_info) - nr, btrfs_header_owner(c)); +print_eb_refs_lock (c);for (i =0 ; i < nr; i++) {btrfs_node_key_to_cpu (c, &key, i); pr_info("\tkey %d (%llu %u %llu) block %llu gen %llu\n",
Signature · 1 line
2.17.0
Re: [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build
Quoted 14 lines · Qu Wenruo
It's pretty handy if we can get debug output for locking status of an extent buffer, specially for race related debugging.
So add the following output for
btrfs_print_tree()andbtrfs_print_leaf():
- refs
-write_locks(as w:%u)
-read_locks(as r:%u)
-blocking_writers(as bw:%u)
-blocking_readers(as br:%u)
-spinning_writers(as sw:%u)
-spinning_readers(as sr:%u)
-lock_owner
-current->pid
Useful, but atomic is 'int' (%d), and pid_t is also int in disguise (maybe there's a special printk specifier for that).
Quoted 11 lines · Qu Wenruo
This patch enhance the following things:
- tree block header
* add generation and owner output for node and leaf
- node pointer generation output
- allowbtrfs_print_tree()to not follow nodes
* just like btrfs-progsPlease 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.
It will stay of course, code deletionists have no chance removing useful debugging stuff.
Some time ago I improved the progs output of print-tree, this would be also good to port to kernel and we can then keep the files in 1:1.
Quoted 13 lines · David Sterba
Quoted 11 lines · Qu Wenruo
This patch enhance the following things:
- tree block header
* add generation and owner output for node and leaf
- node pointer generation output
- allowbtrfs_print_tree()to not follow nodes
* just like btrfs-progsPlease 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.
Quoted 7 lines
It will stay of course, code deletionists have no chance removing useful debugging stuff.
Reviewed-by David Sterba <[email protected]>Some time ago I improved the progs output of print-tree, this would be also good to port to kernel and we can then keep the files in 1:1.
Definitely!
The current kernel print-tree is just better than no output, far from human readable output.
I can't wait to port btrfs-progs print-tree to kernel, but that's over 1000 lines for debug facility.
If that's OK, I could start the port any time.
Thanks,
Qu
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 24 lines · Qu Wenruo
Quoted 13 lines · David Sterba
Quoted 11 lines · Qu Wenruo
This patch enhance the following things:
- tree block header
* add generation and owner output for node and leaf
- node pointer generation output
- allowbtrfs_print_tree()to not follow nodes
* just like btrfs-progsPlease 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.Quoted 7 lines
It will stay of course, code deletionists have no chance removing useful debugging stuff.
Reviewed-by David Sterba <[email protected]>Some time ago I improved the progs output of print-tree, this would be also good to port to kernel and we can then keep the files in 1:1.
Quoted 7 lines
Definitely!
The current kernel print-tree is just better than no output, far from human readable output.
I can't wait to port btrfs-progs print-tree to kernel, but that's over 1000 lines for debug facility.If that's OK, I could start the port any time.
As print-tree is independent, you can do that incrementally, similar to the progs patches that factor out the per-key cases into functions. Anything you'd have we can merge rightaway, these are easy patches that can serve as a "relaxation" and relief from the difficult ones.