linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs: print-tree: output enhancement
@ 2018-04-11  9:08 Qu Wenruo
  2018-04-11  9:08 ` [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
  2018-04-19 12:49 ` [PATCH 1/2] btrfs: print-tree: output enhancement David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Qu Wenruo @ 2018-04-11  9:08 UTC (permalink / raw)
  To: linux-btrfs

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(-)

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
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build
  2018-04-11  9:08 [PATCH 1/2] btrfs: print-tree: output enhancement Qu Wenruo
@ 2018-04-11  9:08 ` Qu Wenruo
  2018-04-19 13:01   ` David Sterba
  2018-04-19 12:49 ` [PATCH 1/2] btrfs: print-tree: output enhancement David Sterba
  1 sibling, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2018-04-11  9:08 UTC (permalink / raw)
  To: linux-btrfs

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

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/print-tree.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 9904cf741e1c..7f0ada51e5fe 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -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",
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] btrfs: print-tree: output enhancement
  2018-04-11  9:08 [PATCH 1/2] btrfs: print-tree: output enhancement Qu Wenruo
  2018-04-11  9:08 ` [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
@ 2018-04-19 12:49 ` David Sterba
  2018-04-19 12:57   ` Qu Wenruo
  1 sibling, 1 reply; 6+ messages in thread
From: David Sterba @ 2018-04-19 12:49 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] btrfs: print-tree: output enhancement
  2018-04-19 12:49 ` [PATCH 1/2] btrfs: print-tree: output enhancement David Sterba
@ 2018-04-19 12:57   ` Qu Wenruo
  2018-04-19 13:12     ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2018-04-19 12:57 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 1363 bytes --]



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
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build
  2018-04-11  9:08 ` [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
@ 2018-04-19 13:01   ` David Sterba
  0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-04-19 13:01 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Wed, Apr 11, 2018 at 05:08:13PM +0800, Qu Wenruo wrote:
> 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

Useful, but atomic is 'int' (%d), and pid_t is also int in disguise
(maybe there's a special printk specifier for that).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] btrfs: print-tree: output enhancement
  2018-04-19 12:57   ` Qu Wenruo
@ 2018-04-19 13:12     ` David Sterba
  0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-04-19 13:12 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: dsterba, Qu Wenruo, linux-btrfs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-19 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-11  9:08 [PATCH 1/2] btrfs: print-tree: output enhancement Qu Wenruo
2018-04-11  9:08 ` [PATCH 2/2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
2018-04-19 13:01   ` David Sterba
2018-04-19 12:49 ` [PATCH 1/2] btrfs: print-tree: output enhancement David Sterba
2018-04-19 12:57   ` Qu Wenruo
2018-04-19 13:12     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).