diff mbox series

btrfs-progs: print the eb flags for nodes as well

Message ID 15066ba6ad8acaff53242f7cc4580874c42ce411.1605802617.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: print the eb flags for nodes as well | expand

Commit Message

Josef Bacik Nov. 19, 2020, 4:17 p.m. UTC
While debugging a corruption problem I realized we don't spit out the
flags for nodes, which is needed when debugging relocation problems so
we know which nodes are the RELOC root items and which are the actual fs
tree's items.  Fix this by unifying the header printing helper so both
leaf's and nodes get the same information printed out.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 kernel-shared/print-tree.c | 52 ++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 22 deletions(-)

Comments

David Sterba Dec. 11, 2020, 4:48 p.m. UTC | #1
On Thu, Nov 19, 2020 at 11:17:04AM -0500, Josef Bacik wrote:
> While debugging a corruption problem I realized we don't spit out the
> flags for nodes, which is needed when debugging relocation problems so
> we know which nodes are the RELOC root items and which are the actual fs
> tree's items.  Fix this by unifying the header printing helper so both
> leaf's and nodes get the same information printed out.

This newly prints one more line for node, like

node 41070940160 level 1 items 34 free space 87 generation 7709536 owner ROOT_TREE
node 41070940160 flags 0x1(WRITTEN) backref revision 1

the same already exists for leaves

leaf 41070944256 items 12 free space 515 generation 7709536 owner ROOT_TREE
leaf 41070944256 flags 0x1(WRITTEN) backref revision 1

I think this is ok though it would be better to have that on one line.
That the offset block address is duplicated should be enough for
grepping or matching against other data, the line would be overly long
otherwise.

> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Added to devel, thanks.
diff mbox series

Patch

diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index 7ab55e29..391c1139 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -1196,16 +1196,11 @@  static void header_flags_to_str(u64 flags, char *ret)
 	}
 }
 
-void btrfs_print_leaf(struct extent_buffer *eb)
+static void print_header_info(struct extent_buffer *eb)
 {
-	struct btrfs_fs_info *fs_info = eb->fs_info;
-	struct btrfs_item *item;
-	struct btrfs_disk_key disk_key;
 	char flags_str[128];
-	u32 leaf_data_size = __BTRFS_LEAF_DATA_SIZE(eb->len);
-	u32 i;
-	u32 nr;
 	u64 flags;
+	u32 nr;
 	u8 backref_rev;
 
 	flags = btrfs_header_flags(eb) & ~BTRFS_BACKREF_REV_MASK;
@@ -1213,17 +1208,38 @@  void btrfs_print_leaf(struct extent_buffer *eb)
 	header_flags_to_str(flags, flags_str);
 	nr = btrfs_header_nritems(eb);
 
-	printf("leaf %llu items %u free space %d generation %llu owner ",
-		(unsigned long long)btrfs_header_bytenr(eb), nr,
-		btrfs_leaf_free_space(eb),
-		(unsigned long long)btrfs_header_generation(eb));
+	if (btrfs_header_level(eb))
+		printf(
+	"node %llu level %d items %u free %u generation %llu owner ",
+		       (unsigned long long)eb->start, btrfs_header_level(eb),
+		       nr, (u32)BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb) - nr,
+		       (unsigned long long)btrfs_header_generation(eb));
+	else
+		printf(
+	"leaf %llu items %u free space %d generation %llu owner ",
+		       (unsigned long long)btrfs_header_bytenr(eb), nr,
+		       btrfs_leaf_free_space(eb),
+		       (unsigned long long)btrfs_header_generation(eb));
 	print_objectid(stdout, btrfs_header_owner(eb), 0);
 	printf("\n");
-	printf("leaf %llu flags 0x%llx(%s) backref revision %d\n",
-		btrfs_header_bytenr(eb), flags, flags_str, backref_rev);
+	printf("%s %llu flags 0x%llx(%s) backref revision %d\n",
+	       btrfs_header_level(eb) ? "node" : "leaf",
+	       btrfs_header_bytenr(eb), flags, flags_str, backref_rev);
 	print_uuids(eb);
 	fflush(stdout);
+}
+
+void btrfs_print_leaf(struct extent_buffer *eb)
+{
+	struct btrfs_fs_info *fs_info = eb->fs_info;
+	struct btrfs_item *item;
+	struct btrfs_disk_key disk_key;
+	u32 leaf_data_size = __BTRFS_LEAF_DATA_SIZE(eb->len);
+	u32 i;
+	u32 nr;
 
+	print_header_info(eb);
+	nr = btrfs_header_nritems(eb);
 	for (i = 0; i < nr; i++) {
 		u32 item_size;
 		void *ptr;
@@ -1517,15 +1533,7 @@  void btrfs_print_tree(struct extent_buffer *eb, bool follow, int traverse)
 		warning(
 		"node nr_items corrupted, has %u limit %u, continue anyway",
 			nr, BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb));
-	printf("node %llu level %d items %u free %u generation %llu owner ",
-	       (unsigned long long)eb->start,
-	        btrfs_header_level(eb), nr,
-		(u32)BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb) - nr,
-		(unsigned long long)btrfs_header_generation(eb));
-	print_objectid(stdout, btrfs_header_owner(eb), 0);
-	printf("\n");
-	print_uuids(eb);
-	fflush(stdout);
+	print_header_info(eb);
 	ptr_num = BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb);
 	for (i = 0; i < nr && i < ptr_num; i++) {
 		u64 blocknr = btrfs_node_blockptr(eb, i);