Re: [PATCH 1/2] btrfs-progs: copy functionality of btrfs-debug-tree to inspect-internal subcommand

2016-02-10 Thread David Sterba
On Tue, Feb 09, 2016 at 05:12:08PM +0100, Alexander Fougner wrote:
> The long-term plan is to merge the features of standalone tools
> into the btrfs binary, reducing the number of shipped binaries.
> 
> Signed-off-by: Alexander Fougner 

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] btrfs-progs: copy functionality of btrfs-debug-tree to inspect-internal subcommand

2016-02-09 Thread Alexander Fougner
The long-term plan is to merge the features of standalone tools
into the btrfs binary, reducing the number of shipped binaries.

Signed-off-by: Alexander Fougner 
---
 Makefile.in  |   2 +-
 btrfs-debug-tree.c   | 424 +---
 cmds-inspect-dump-tree.c | 451 +++
 cmds-inspect-dump-tree.h |  15 ++
 cmds-inspect.c   |   8 +
 5 files changed, 481 insertions(+), 419 deletions(-)
 create mode 100644 cmds-inspect-dump-tree.c
 create mode 100644 cmds-inspect-dump-tree.h

diff --git a/Makefile.in b/Makefile.in
index 19697ff..14dab76 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -70,7 +70,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o 
print-tree.o \
  extent-cache.o extent_io.o volumes.o utils.o repair.o \
  qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
  ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
- inode.o file.o find-root.o free-space-tree.o help.o
+ inode.o file.o find-root.o free-space-tree.o help.o 
cmds-inspect-dump-tree.o
 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
   cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
   cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
index 266176f..057a715 100644
--- a/btrfs-debug-tree.c
+++ b/btrfs-debug-tree.c
@@ -30,433 +30,21 @@
 #include "transaction.h"
 #include "volumes.h"
 #include "utils.h"
-
-static int print_usage(int ret)
-{
-   fprintf(stderr, "usage: btrfs-debug-tree [-e] [-d] [-r] [-R] [-u]\n");
-   fprintf(stderr, "[-b block_num ] device\n");
-   fprintf(stderr, "\t-e : print detailed extents info\n");
-   fprintf(stderr, "\t-d : print info of btrfs device and root tree dirs"
-" only\n");
-   fprintf(stderr, "\t-r : print info of roots only\n");
-   fprintf(stderr, "\t-R : print info of roots and root backups\n");
-   fprintf(stderr, "\t-u : print info of uuid tree only\n");
-   fprintf(stderr, "\t-b block_num : print info of the specified block"
-" only\n");
-   fprintf(stderr,
-   "\t-t tree_id : print only the tree with the given id\n");
-   fprintf(stderr, "%s\n", PACKAGE_STRING);
-   exit(ret);
-}
-
-static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
-{
-   int i;
-   u32 nr;
-   u32 size;
-
-   if (!eb)
-   return;
-
-   if (btrfs_is_leaf(eb)) {
-   btrfs_print_leaf(root, eb);
-   return;
-   }
-
-   size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
-   nr = btrfs_header_nritems(eb);
-   for (i = 0; i < nr; i++) {
-   struct extent_buffer *next = read_tree_block(root,
-btrfs_node_blockptr(eb, i),
-size,
-btrfs_node_ptr_generation(eb, i));
-   if (!extent_buffer_uptodate(next))
-   continue;
-   if (btrfs_is_leaf(next) &&
-   btrfs_header_level(eb) != 1)
-   BUG();
-   if (btrfs_header_level(next) !=
-   btrfs_header_level(eb) - 1)
-   BUG();
-   print_extents(root, next);
-   free_extent_buffer(next);
-   }
-}
-
-static void print_old_roots(struct btrfs_super_block *super)
-{
-   struct btrfs_root_backup *backup;
-   int i;
-
-   for (i = 0; i < BTRFS_NUM_BACKUP_ROOTS; i++) {
-   backup = super->super_roots + i;
-   printf("btrfs root backup slot %d\n", i);
-   printf("\ttree root gen %llu block %llu\n",
-  (unsigned long long)btrfs_backup_tree_root_gen(backup),
-  (unsigned long long)btrfs_backup_tree_root(backup));
-
-   printf("\t\textent root gen %llu block %llu\n",
-  (unsigned long long)btrfs_backup_extent_root_gen(backup),
-  (unsigned long long)btrfs_backup_extent_root(backup));
-
-   printf("\t\tchunk root gen %llu block %llu\n",
-  (unsigned long long)btrfs_backup_chunk_root_gen(backup),
-  (unsigned long long)btrfs_backup_chunk_root(backup));
-
-   printf("\t\tdevice root gen %llu block %llu\n",
-  (unsigned long long)btrfs_backup_dev_root_gen(backup),
-  (unsigned long long)btrfs_backup_dev_root(backup));
-
-   printf("\t\tcsum root gen %llu block %llu\n",
-  (unsigned long long)btrfs_backup_csum_root_gen(backup),
-  (unsigned long long)btrfs_backup_csum_root(backup));
-
-