diff mbox

[1/2] btrfs: print-tree: output enhancement

Message ID 20180411090813.19495-1-wqu@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Qu Wenruo April 11, 2018, 9:08 a.m. UTC
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.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
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(-)

Comments

David Sterba April 19, 2018, 12:49 p.m. UTC | #1
On Wed, Apr 11, 2018 at 05:08:12PM +0800, Qu Wenruo wrote:
> 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.

It will stay of course, code deletionists have no chance removing useful
debugging stuff.

Reviewed-by: David Sterba <dsterba@suse.com>

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.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo April 19, 2018, 12:57 p.m. UTC | #2
On 2018年04月19日 20:49, David Sterba wrote:
> On Wed, Apr 11, 2018 at 05:08:12PM +0800, Qu Wenruo wrote:
>> 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.
> 
> It will stay of course, code deletionists have no chance removing useful
> debugging stuff.
> 
> Reviewed-by: David Sterba <dsterba@suse.com>
> 
> 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

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
David Sterba April 19, 2018, 1:12 p.m. UTC | #3
On Thu, Apr 19, 2018 at 08:57:30PM +0800, Qu Wenruo wrote:
> 
> 
> On 2018年04月19日 20:49, David Sterba wrote:
> > On Wed, Apr 11, 2018 at 05:08:12PM +0800, Qu Wenruo wrote:
> >> 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.
> > 
> > It will stay of course, code deletionists have no chance removing useful
> > debugging stuff.
> > 
> > Reviewed-by: David Sterba <dsterba@suse.com>
> > 
> > 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.

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.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 4a8770485f77..9904cf741e1c 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -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);
 	}
 }
diff --git a/fs/btrfs/print-tree.h b/fs/btrfs/print-tree.h
index 3afd508ed8c5..834f3c187f0d 100644
--- a/fs/btrfs/print-tree.h
+++ b/fs/btrfs/print-tree.h
@@ -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