Btrfs: add btrfs-debug-tree -b <block number> to print a single block
authorChris Mason <chris.mason@oracle.com>
Tue, 6 Apr 2010 13:30:17 +0000 (09:30 -0400)
committerChris Mason <chris.mason@oracle.com>
Tue, 6 Apr 2010 13:30:17 +0000 (09:30 -0400)
debug-tree.c
dir-test.c
print-tree.c
print-tree.h
quick-test.c
random-test.c

index 1d47519..40628e0 100644 (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);
                        }
index 44f2758..3ae9c68 100644 (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;
index 59f4358..bd8af13 100644 (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);
        }
 }
-
index 4d1a01a..495b81a 100644 (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
index 351c706..fa6fd83 100644 (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;
 }
index 571735d..0003236 100644 (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;