linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] btrfs-progs: Add human readable flags output string for extent flags.
@ 2014-06-12  7:12 Qu Wenruo
  2014-06-12  7:12 ` [PATCH v2 2/2] btrfs-progs: Add human readable flags output for chunk/block group type Qu Wenruo
  0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2014-06-12  7:12 UTC (permalink / raw)
  To: linux-btrfs

Current btrfs-debug-tree outputs extent flags as numbers,
which makes it hard to understand and need to check the source to
understand the meaning.

This patch will convert numberic flags output to human readable strings.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
changlog:
v2: none
---
 print-tree.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/print-tree.c b/print-tree.c
index 7263b09..7f831ad 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -242,6 +242,25 @@ static void print_file_extent_item(struct extent_buffer *eb,
 	       btrfs_file_extent_compression(eb, fi));
 }
 
+/* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
+static void extent_flags_to_str(u64 flags, char *ret)
+{
+	int empty = 1;
+
+	if (flags & BTRFS_EXTENT_FLAG_DATA) {
+		empty = 0;
+		strcpy(ret, "DATA");
+	}
+	if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
+		if (!empty) {
+			empty = 0;
+			strcat(ret, "|");
+		}
+		strcat(ret, "TREE_BLOCK");
+	}
+	return;
+}
+
 static void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
 {
 	struct btrfs_extent_item *ei;
@@ -255,6 +274,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
 	u32 item_size = btrfs_item_size_nr(eb, slot);
 	u64 flags;
 	u64 offset;
+	char flags_str[32] = {0};
 
 	if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
@@ -271,11 +291,12 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
 
 	ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
 	flags = btrfs_extent_flags(eb, ei);
+	extent_flags_to_str(flags, flags_str);
 
-	printf("\t\textent refs %llu gen %llu flags %llu\n",
+	printf("\t\textent refs %llu gen %llu flags %s\n",
 	       (unsigned long long)btrfs_extent_refs(eb, ei),
 	       (unsigned long long)btrfs_extent_generation(eb, ei),
-	       (unsigned long long)flags);
+	       flags_str);
 
 	if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
 		struct btrfs_tree_block_info *info;
-- 
2.0.0


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

* [PATCH v2 2/2] btrfs-progs: Add human readable flags output for chunk/block group type.
  2014-06-12  7:12 [PATCH v2 1/2] btrfs-progs: Add human readable flags output string for extent flags Qu Wenruo
@ 2014-06-12  7:12 ` Qu Wenruo
  0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2014-06-12  7:12 UTC (permalink / raw)
  To: linux-btrfs

Current btrfs-debug-tree output chunk/block group type as numbers,
which makes it hard to understand and need to check the source to
understand the meaning.

This patch will convert numberic type output to human readable strings.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
changlog:
v2: allow mixed chunk.
---
 print-tree.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/print-tree.c b/print-tree.c
index 7f831ad..6cf59ca 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -160,15 +160,60 @@ static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *ite
 	return 0;
 }
 
+/* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
+static void bg_flags_to_str(u64 flags, char *ret)
+{
+	int empty = 1;
+
+	if (flags & BTRFS_BLOCK_GROUP_DATA) {
+		empty = 0;
+		strcpy(ret, "DATA");
+	}
+	if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+		if (!empty)
+			strcat(ret, "|");
+		strcat(ret, "METADATA");
+	}
+	if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+		if (!empty)
+			strcat(ret, "|");
+		strcat(ret, "SYSTEM");
+	}
+	switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+	case BTRFS_BLOCK_GROUP_RAID0:
+		strcat(ret, "|RAID0");
+		break;
+	case BTRFS_BLOCK_GROUP_RAID1:
+		strcat(ret, "|RAID1");
+		break;
+	case BTRFS_BLOCK_GROUP_DUP:
+		strcat(ret, "|DUP");
+		break;
+	case BTRFS_BLOCK_GROUP_RAID10:
+		strcat(ret, "|RAID10");
+		break;
+	case BTRFS_BLOCK_GROUP_RAID5:
+		strcat(ret, "|RAID5");
+		break;
+	case BTRFS_BLOCK_GROUP_RAID6:
+		strcat(ret, "|RAID6");
+		break;
+	default:
+		break;
+	}
+}
+
 static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
 {
 	int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
 	int i;
-	printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n",
+	char chunk_flags_str[32] = {0};
+
+	bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
+	printf("\t\tchunk length %llu owner %llu type %s num_stripes %d\n",
 	       (unsigned long long)btrfs_chunk_length(eb, chunk),
 	       (unsigned long long)btrfs_chunk_owner(eb, chunk),
-	       (unsigned long long)btrfs_chunk_type(eb, chunk),
-	       num_stripes);
+	       chunk_flags_str, num_stripes);
 	for (i = 0 ; i < num_stripes ; i++) {
 		printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
 		      (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
@@ -744,6 +789,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
 	u32 nr = btrfs_header_nritems(l);
 	u64 objectid;
 	u32 type;
+	char bg_flags_str[32];
 
 	printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
 		(unsigned long long)btrfs_header_bytenr(l), nr,
@@ -858,10 +904,13 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
 					    struct btrfs_block_group_item);
 			read_extent_buffer(l, &bg_item, (unsigned long)bi,
 					   sizeof(bg_item));
-			printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n",
+			memset(bg_flags_str, 0, sizeof(bg_flags_str));
+			bg_flags_to_str(btrfs_block_group_flags(&bg_item),
+					bg_flags_str);
+			printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
 			       (unsigned long long)btrfs_block_group_used(&bg_item),
 			       (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
-			       (unsigned long long)btrfs_block_group_flags(&bg_item));
+			       bg_flags_str);
 			break;
 		case BTRFS_CHUNK_ITEM_KEY:
 			print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
-- 
2.0.0


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

end of thread, other threads:[~2014-06-12  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12  7:12 [PATCH v2 1/2] btrfs-progs: Add human readable flags output string for extent flags Qu Wenruo
2014-06-12  7:12 ` [PATCH v2 2/2] btrfs-progs: Add human readable flags output for chunk/block group type Qu Wenruo

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