summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2010-04-06 09:30:17 -0400
committerChris Mason <chris.mason@oracle.com>2010-04-06 09:30:17 -0400
commit075587c96c2f39e227847d13ca0ef305b13cd7d3 (patch)
tree849aca32b8beb2349dbc2e697b460690eb47f67c
parent8f55b769c703c3f7cc8c94d165ea2587d4384ae9 (diff)
Btrfs: add btrfs-debug-tree -b <block number> to print a single block
-rw-r--r--debug-tree.c35
-rw-r--r--dir-test.c2
-rw-r--r--print-tree.c8
-rw-r--r--print-tree.h2
-rw-r--r--quick-test.c6
-rw-r--r--random-test.c2
6 files changed, 42 insertions, 13 deletions
diff --git a/debug-tree.c b/debug-tree.c
index 1d475190..40628e09 100644
--- a/debug-tree.c
+++ b/debug-tree.c
@@ -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);
}
diff --git a/dir-test.c b/dir-test.c
index 44f27587..3ae9c68b 100644
--- a/dir-test.c
+++ b/dir-test.c
@@ -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;
diff --git a/print-tree.c b/print-tree.c
index 59f43588..bd8af132 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -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);
}
}
-
diff --git a/print-tree.h b/print-tree.h
index 4d1a01ae..495b81a2 100644
--- a/print-tree.h
+++ b/print-tree.h
@@ -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
diff --git a/quick-test.c b/quick-test.c
index 351c7061..fa6fd838 100644
--- a/quick-test.c
+++ b/quick-test.c
@@ -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;
}
diff --git a/random-test.c b/random-test.c
index 571735dd..0003236a 100644
--- a/random-test.c
+++ b/random-test.c
@@ -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;