more pretty printing - owners

This commit is contained in:
David Sterba 2012-10-03 01:21:19 +02:00
parent 33a4d17155
commit d1744f1275

View File

@ -25,6 +25,24 @@
#include "disk-io.h" #include "disk-io.h"
#include "print-tree.h" #include "print-tree.h"
static const char* pretty_owner(u64 owner)
{
static buf[32];
switch (owner) {
case BTRFS_ROOT_TREE_OBJECTID: return "ROOT_TREE(1)";
case BTRFS_EXTENT_TREE_OBJECTID: return "EXTENT_TREE(2)";
case BTRFS_CHUNK_TREE_OBJECTID: return "CHUNK_TREE(3)";
case BTRFS_DEV_TREE_OBJECTID: return "DEV_TREE(4)";
case BTRFS_FS_TREE_OBJECTID: return "FS_TREE(5)";
case BTRFS_CSUM_TREE_OBJECTID: return "CSUM_TREE(7)";
case BTRFS_QUOTA_TREE_OBJECTID: return "QUOTA_TREE(8)";
case BTRFS_TREE_RELOC_OBJECTID: return "TREE_RELOC(-8)";
case BTRFS_DATA_RELOC_TREE_OBJECTID: return "DATA_RELOC_TREE(-9)";
default: snprintf(buf, sizeof(buf), "%llu", (unsigned long long)owner); return buf;
}
}
static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item, static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
struct btrfs_dir_item *di) struct btrfs_dir_item *di)
{ {
@ -89,9 +107,9 @@ static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
{ {
int num_stripes = btrfs_chunk_num_stripes(eb, chunk); int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
int i; int i;
printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n", printf("\t\tchunk length %llu owner %s type %llu num_stripes %d\n",
(unsigned long long)btrfs_chunk_length(eb, chunk), (unsigned long long)btrfs_chunk_length(eb, chunk),
(unsigned long long)btrfs_chunk_owner(eb, chunk), pretty_owner(btrfs_chunk_owner(eb, chunk)),
(unsigned long long)btrfs_chunk_type(eb, chunk), (unsigned long long)btrfs_chunk_type(eb, chunk),
num_stripes); num_stripes);
for (i = 0 ; i < num_stripes ; i++) { for (i = 0 ; i < num_stripes ; i++) {
@ -221,8 +239,8 @@ static void print_extent_item(struct extent_buffer *eb, int slot)
offset = btrfs_extent_inline_ref_offset(eb, iref); offset = btrfs_extent_inline_ref_offset(eb, iref);
switch (type) { switch (type) {
case BTRFS_TREE_BLOCK_REF_KEY: case BTRFS_TREE_BLOCK_REF_KEY:
printf("\t\ttree block backref root %llu\n", printf("\t\ttree block backref root %s\n",
(unsigned long long)offset); pretty_owner(offset));
break; break;
case BTRFS_SHARED_BLOCK_REF_KEY: case BTRFS_SHARED_BLOCK_REF_KEY:
printf("\t\tshared block backref parent %llu\n", printf("\t\tshared block backref parent %llu\n",
@ -230,9 +248,9 @@ static void print_extent_item(struct extent_buffer *eb, int slot)
break; break;
case BTRFS_EXTENT_DATA_REF_KEY: case BTRFS_EXTENT_DATA_REF_KEY:
dref = (struct btrfs_extent_data_ref *)(&iref->offset); dref = (struct btrfs_extent_data_ref *)(&iref->offset);
printf("\t\textent data backref root %llu " printf("\t\textent data backref root %s "
"objectid %llu offset %llu count %u\n", "objectid %llu offset %llu count %u\n",
(unsigned long long)btrfs_extent_data_ref_root(eb, dref), pretty_owner(btrfs_extent_data_ref_root(eb, dref)),
(unsigned long long)btrfs_extent_data_ref_objectid(eb, dref), (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
(unsigned long long)btrfs_extent_data_ref_offset(eb, dref), (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
btrfs_extent_data_ref_count(eb, dref)); btrfs_extent_data_ref_count(eb, dref));
@ -559,7 +577,10 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key)
(unsigned long long)(offset & ((1ll << 48) - 1))); (unsigned long long)(offset & ((1ll << 48) - 1)));
break; break;
default: default:
printf(" %llu)", (unsigned long long)offset); if (offset == (u64)-1)
printf(" (u64)-1)");
else
printf(" %llu)", (unsigned long long)offset);
break; break;
} }
} }
@ -587,11 +608,11 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
u64 objectid; u64 objectid;
u32 type; u32 type;
printf("leaf %llu items %d free space %d generation %llu owner %llu\n", printf("leaf %llu items %d free space %d generation %llu owner %s\n",
(unsigned long long)btrfs_header_bytenr(l), nr, (unsigned long long)btrfs_header_bytenr(l), nr,
btrfs_leaf_free_space(root, l), btrfs_leaf_free_space(root, l),
(unsigned long long)btrfs_header_generation(l), (unsigned long long)btrfs_header_generation(l),
(unsigned long long)btrfs_header_owner(l)); pretty_owner(btrfs_header_owner(l)));
print_uuids(l); print_uuids(l);
fflush(stdout); fflush(stdout);
for (i = 0 ; i < nr ; i++) { for (i = 0 ; i < nr ; i++) {
@ -658,9 +679,9 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
break; break;
case BTRFS_EXTENT_DATA_REF_KEY: case BTRFS_EXTENT_DATA_REF_KEY:
dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref); dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
printf("\t\textent data backref root %llu " printf("\t\textent data backref root %s "
"objectid %llu offset %llu count %u\n", "objectid %llu offset %llu count %u\n",
(unsigned long long)btrfs_extent_data_ref_root(l, dref), pretty_owner(btrfs_extent_data_ref_root(l, dref)),
(unsigned long long)btrfs_extent_data_ref_objectid(l, dref), (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
(unsigned long long)btrfs_extent_data_ref_offset(l, dref), (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
btrfs_extent_data_ref_count(l, dref)); btrfs_extent_data_ref_count(l, dref));
@ -797,12 +818,12 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
btrfs_print_leaf(root, eb); btrfs_print_leaf(root, eb);
return; return;
} }
printf("node %llu level %d items %d free %u generation %llu owner %llu\n", printf("node %llu level %d items %d free %u generation %llu owner %s\n",
(unsigned long long)eb->start, (unsigned long long)eb->start,
btrfs_header_level(eb), nr, btrfs_header_level(eb), nr,
(u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr, (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
(unsigned long long)btrfs_header_generation(eb), (unsigned long long)btrfs_header_generation(eb),
(unsigned long long)btrfs_header_owner(eb)); pretty_owner(btrfs_header_owner(eb)));
print_uuids(eb); print_uuids(eb);
fflush(stdout); fflush(stdout);
size = btrfs_level_size(root, btrfs_header_level(eb) - 1); size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
@ -827,9 +848,9 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
size, size,
btrfs_node_ptr_generation(eb, i)); btrfs_node_ptr_generation(eb, i));
if (!next) { if (!next) {
fprintf(stderr, "failed to read %llu in tree %llu\n", fprintf(stderr, "failed to read %llu in tree %s\n",
(unsigned long long)btrfs_node_blockptr(eb, i), (unsigned long long)btrfs_node_blockptr(eb, i),
(unsigned long long)btrfs_header_owner(eb)); pretty_owner(btrfs_header_owner(eb)));
continue; continue;
} }
if (btrfs_is_leaf(next) && if (btrfs_is_leaf(next) &&