Btrfs: add btrfs-debug-tree -b <block number> to print a single block

This commit is contained in:
Chris Mason 2010-04-06 09:30:17 -04:00
parent 8f55b769c7
commit 075587c96c
6 changed files with 42 additions and 13 deletions

View File

@ -116,19 +116,23 @@ int main(int ac, char **av)
int ret;
int slot;
int extent_only = 0;
u64 block_only = 0;
struct btrfs_root *tree_root_scan;
radix_tree_init();
while(1) {
int c;
c = getopt(ac, av, "e");
c = getopt(ac, av, "eb:");
if (c < 0)
break;
switch(c) {
case 'e':
extent_only = 1;
break;
case 'b':
block_only = atoll(optarg);
break;
default:
print_usage();
}
@ -142,14 +146,37 @@ int main(int ac, char **av)
fprintf(stderr, "unable to open %s\n", av[optind]);
exit(1);
}
if (block_only) {
leaf = read_tree_block(root,
block_only,
root->leafsize, 0);
if (leaf && btrfs_header_level(leaf) != 0) {
free_extent_buffer(leaf);
leaf = NULL;
}
if (!leaf) {
leaf = read_tree_block(root,
block_only,
root->nodesize, 0);
}
if (!leaf) {
fprintf(stderr, "failed to read %llu\n", block_only);
return 0;
}
btrfs_print_tree(root, leaf, 0);
return 0;
}
if (!extent_only) {
printf("root tree\n");
btrfs_print_tree(root->fs_info->tree_root,
root->fs_info->tree_root->node);
root->fs_info->tree_root->node, 1);
printf("chunk tree\n");
btrfs_print_tree(root->fs_info->chunk_root,
root->fs_info->chunk_root->node);
root->fs_info->chunk_root->node, 1);
}
tree_root_scan = root->fs_info->tree_root;
@ -260,7 +287,7 @@ again:
printf(" tree ");
btrfs_print_key(&disk_key);
printf(" \n");
btrfs_print_tree(tree_root_scan, buf);
btrfs_print_tree(tree_root_scan, buf, 1);
} else if (extent_only && !skip) {
print_extents(tree_root_scan, buf);
}

View File

@ -485,7 +485,7 @@ int main(int ac, char **av)
if (ret) {
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
btrfs_print_tree(root, root->node);
btrfs_print_tree(root, root->node, 1);
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
err = ret;

View File

@ -607,7 +607,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
}
}
void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb)
void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
{
int i;
u32 nr;
@ -643,6 +643,9 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb)
(unsigned long long)btrfs_node_ptr_generation(eb, i));
fflush(stdout);
}
if (!follow)
return;
for (i = 0; i < nr; i++) {
struct extent_buffer *next = read_tree_block(root,
btrfs_node_blockptr(eb, i),
@ -660,8 +663,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb)
if (btrfs_header_level(next) !=
btrfs_header_level(eb) - 1)
BUG();
btrfs_print_tree(root, next);
btrfs_print_tree(root, next, 1);
free_extent_buffer(next);
}
}

View File

@ -19,6 +19,6 @@
#ifndef __PRINT_TREE_
#define __PRINT_TREE_
void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l);
void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *t);
void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *t, int follow);
void btrfs_print_key(struct btrfs_disk_key *disk_key);
#endif

View File

@ -85,7 +85,7 @@ int main(int ac, char **av) {
fprintf(stderr, "search %d:%d\n", num, i);
ret = btrfs_search_slot(NULL, root, &ins, &path, 0, 0);
if (ret) {
btrfs_print_tree(root, root->node);
btrfs_print_tree(root, root->node, 1);
printf("unable to find %d\n", num);
exit(1);
}
@ -148,7 +148,7 @@ int main(int ac, char **av) {
fprintf(stderr, "search %d:%d\n", num, i);
ret = btrfs_search_slot(NULL, root, &ins, &path, 0, 0);
if (ret) {
btrfs_print_tree(root, root->node);
btrfs_print_tree(root, root->node, 1);
printf("unable to find %d\n", num);
exit(1);
}
@ -196,7 +196,7 @@ int main(int ac, char **av) {
btrfs_commit_transaction(trans, root);
printf("tree size is now %d\n", tree_size);
printf("root %p commit root %p\n", root->node, root->commit_root);
btrfs_print_tree(root, root->node);
btrfs_print_tree(root, root->node, 1);
close_ctree(root);
return 0;
}

View File

@ -404,7 +404,7 @@ int main(int ac, char **av)
if (ret) {
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
btrfs_print_tree(root, root->node);
btrfs_print_tree(root, root->node, 1);
fprintf(stderr, "op %d failed %d:%d\n",
op, i, iterations);
err = ret;