Add debug-btrfs command to btrfs-progs
Subsystems (3)
RFC PATCH 1/1 Add debug-btrfs command to btrfs-progs
Hi,
The below set of patches add debug-btrfs command to btrfs-progs package. The new command depends on the libss.a library provided e2fsprogs. To build one have to set E2FSPRGS_BUILD_DIR to point to the e2fsprogs build directory. Once we get e2fsprogs to create a proper libss package we should be able to remove the above export.
Currently supported list of commands are listed below. It should be really easy to add new commands
debug-btrfs: ?
Available debug-btrfs requests:
show_debugfs_params, params
Show btrfs_debug parameters
open_filesys, open Open the file system dump_tree Show full btrfs tree dump_root_tree Show root tree dump_chunk_tree Show btrfs chunk tree print_inode Print inode details help Display info on command or topic. list_requests, lr, ? List available commands. quit, q Leave the subsystem.
You should be able to get the patches with --no-renames at
http://www.kernel.org/pub/linux/kernel/people/kvaneesh/debug-btrfs/
-aneesh
PATCH 1/4 btrfs-progs: Move files around
Build libbtrfs.a and link against that for the commands
--- Makefile | 72 +++---------------- lib/Makefile | 47 ++++++++++++ bit-radix.c => lib/bit-radix.c | 0 bit-radix.h => lib/bit-radix.h | 0 crc32c.c => lib/crc32c.c | 0 crc32c.h => lib/crc32c.h | 0 ctree.c => lib/ctree.c | 0 ctree.h => lib/ctree.h | 0 dir-item.c => lib/dir-item.c | 0 disk-io.c => lib/disk-io.c | 0 disk-io.h => lib/disk-io.h | 0 extent-cache.c => lib/extent-cache.c | 0 extent-cache.h => lib/extent-cache.h | 0 extent-tree.c => lib/extent-tree.c | 0 extent_io.c => lib/extent_io.c | 0 extent_io.h => lib/extent_io.h | 0 file-item.c => lib/file-item.c | 0 hash.h => lib/hash.h | 0 inode-item.c => lib/inode-item.c | 0 inode-map.c => lib/inode-map.c | 0 ioctl.h => lib/ioctl.h | 0 kerncompat.h => lib/kerncompat.h | 0 list.h => lib/list.h | 0 print-tree.c => lib/print-tree.c | 0 print-tree.h => lib/print-tree.h | 0 radix-tree.c => lib/radix-tree.c | 0 radix-tree.h => lib/radix-tree.h | 0 rbtree.c => lib/rbtree.c | 0 rbtree.h => lib/rbtree.h | 0 root-tree.c => lib/root-tree.c | 0 transaction.h => lib/transaction.h | 0 utils.c => lib/utils.c | 0 utils.h => lib/utils.h | 0 volumes.c => lib/volumes.c | 0 volumes.h => lib/volumes.h | 0 misc/Makefile | 79 ++++++++++++++++++++ bcp => misc/bcp | 0 btrfs-image.c => misc/btrfs-image.c | 0 btrfs-map-logical.c => misc/btrfs-map-logical.c | 0 btrfs-show.c => misc/btrfs-show.c | 0 btrfs-vol.c => misc/btrfs-vol.c | 0 btrfsck.c => misc/btrfsck.c | 0 btrfsctl.c => misc/btrfsctl.c | 0 btrfstune.c => misc/btrfstune.c | 0 convert.c => misc/convert.c | 0 debug-tree.c => misc/debug-tree.c | 0 mkfs.c => misc/mkfs.c | 0 version.sh => misc/version.sh | 0 tests/Makefile | 88 +++++++++++++++++++++++ dir-test.c => tests/dir-test.c | 0 hasher.c => tests/hasher.c | 0 quick-test.c => tests/quick-test.c | 0 random-test.c => tests/random-test.c | 0 show-blocks => tests/show-blocks | 0 54 files changed, 223 insertions(+), 63 deletions(-) create mode 100644 lib/Makefile rename bit-radix.c => lib/bit-radix.c (100%) rename bit-radix.h => lib/bit-radix.h (100%) rename crc32c.c => lib/crc32c.c (100%) rename crc32c.h => lib/crc32c.h (100%) rename ctree.c => lib/ctree.c (100%) rename ctree.h => lib/ctree.h (100%) rename dir-item.c => lib/dir-item.c (100%) rename disk-io.c => lib/disk-io.c (100%) rename disk-io.h => lib/disk-io.h (100%) rename extent-cache.c => lib/extent-cache.c (100%) rename extent-cache.h => lib/extent-cache.h (100%) rename extent-tree.c => lib/extent-tree.c (100%) rename extent_io.c => lib/extent_io.c (100%) rename extent_io.h => lib/extent_io.h (100%) rename file-item.c => lib/file-item.c (100%) rename hash.h => lib/hash.h (100%) rename inode-item.c => lib/inode-item.c (100%) rename inode-map.c => lib/inode-map.c (100%) rename ioctl.h => lib/ioctl.h (100%) rename kerncompat.h => lib/kerncompat.h (100%) rename list.h => lib/list.h (100%) rename print-tree.c => lib/print-tree.c (100%) rename print-tree.h => lib/print-tree.h (100%) rename radix-tree.c => lib/radix-tree.c (100%) rename radix-tree.h => lib/radix-tree.h (100%) rename rbtree.c => lib/rbtree.c (100%) rename rbtree.h => lib/rbtree.h (100%) rename root-tree.c => lib/root-tree.c (100%) rename transaction.h => lib/transaction.h (100%) rename utils.c => lib/utils.c (100%) rename utils.h => lib/utils.h (100%) rename volumes.c => lib/volumes.c (100%) rename volumes.h => lib/volumes.h (100%) create mode 100644 misc/Makefile rename bcp => misc/bcp (100%) mode change 100755 => 100644 rename btrfs-image.c => misc/btrfs-image.c (100%) rename btrfs-map-logical.c => misc/btrfs-map-logical.c (100%) rename btrfs-show.c => misc/btrfs-show.c (100%) rename btrfs-vol.c => misc/btrfs-vol.c (100%) rename btrfsck.c => misc/btrfsck.c (100%) rename btrfsctl.c => misc/btrfsctl.c (100%) rename btrfstune.c => misc/btrfstune.c (100%) rename convert.c => misc/convert.c (100%) rename debug-tree.c => misc/debug-tree.c (100%) rename mkfs.c => misc/mkfs.c (100%) rename version.sh => misc/version.sh (100%) create mode 100644 tests/Makefile rename dir-test.c => tests/dir-test.c (100%) rename hasher.c => tests/hasher.c (100%) rename quick-test.c => tests/quick-test.c (100%) rename random-test.c => tests/random-test.c (100%) rename show-blocks => tests/show-blocks (100%) mode change 100755 => 100644
Makefile +9 -63
@@ -1,11 +1,6 @@ CC=gcc AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 CFLAGS = -g -Werror -Os -objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ - root-tree.o dir-item.o file-item.o inode-item.o \ - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ - volumes.o utils.o - # CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef
@@ -16,8 +11,7 @@ prefix ?= /usr/local bindir = $(prefix)/bin LIBS=-luuid -progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ - btrfs-map-logical +SUBDIRS=lib misc man # make C=1 to enable sparse ifdef C
@@ -31,60 +25,12 @@ endif $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< -all: version $(progs) manpages - -version: - bash version.sh - -btrfsctl: $(objects) btrfsctl.o - gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-vol: $(objects) btrfs-vol.o - gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-show: $(objects) btrfs-show.o - gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS) - -btrfsck: $(objects) btrfsck.o - gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS) - -mkfs.btrfs: $(objects) mkfs.o - gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) - -btrfs-debug-tree: $(objects) debug-tree.o - gcc $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS) - -btrfstune: $(objects) btrfstune.o - gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS) - -btrfs-map-logical: $(objects) btrfs-map-logical.o - gcc $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS) - -btrfs-image: $(objects) btrfs-image.o - gcc $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS) - -dir-test: $(objects) dir-test.o - gcc $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS) - -quick-test: $(objects) quick-test.o - gcc $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS) - -convert: $(objects) convert.o - gcc $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs $(LDFLAGS) $(LIBS) - -manpages: - cd man; make - -install-man: - cd man; make install - -clean : - rm -f $(progs) cscope.out *.o .*.d btrfs-convert - cd man; make clean - -install: $(progs) install-man - $(INSTALL) -m755 -d $(DESTDIR)$(bindir) - $(INSTALL) $(progs) $(DESTDIR)$(bindir) - if [ -e btrfs-convert ]; then $(INSTALL) btrfs-convert $(DESTDIR)$(bindir); fi +all clean install: + @for subdir in $(SUBDIRS); do \ + if test -d $$subdir ; then \ + target=`echo $@`; \ + echo making $$target in $$subdir; \ + (cd $$subdir && $(MAKE) $$target) || exit 1; \ + fi ; \ + done --include .*.d
lib/Makefile new file +47 -0
47 lines not on this page · raw message
lib/bit-radix.c renamed from bit-radix.c +0 -0
lib/bit-radix.h renamed from bit-radix.h +0 -0
lib/crc32c.c renamed from crc32c.c +0 -0
lib/crc32c.h renamed from crc32c.h +0 -0
lib/ctree.c renamed from ctree.c +0 -0
lib/ctree.h renamed from ctree.h +0 -0
lib/dir-item.c renamed from dir-item.c +0 -0
lib/disk-io.c renamed from disk-io.c +0 -0
lib/disk-io.h renamed from disk-io.h +0 -0
lib/extent-cache.c renamed from extent-cache.c +0 -0
lib/extent-cache.h renamed from extent-cache.h +0 -0
lib/extent-tree.c renamed from extent-tree.c +0 -0
lib/extent_io.c renamed from extent_io.c +0 -0
lib/extent_io.h renamed from extent_io.h +0 -0
lib/file-item.c renamed from file-item.c +0 -0
lib/hash.h renamed from hash.h +0 -0
lib/inode-item.c renamed from inode-item.c +0 -0
lib/inode-map.c renamed from inode-map.c +0 -0
lib/ioctl.h renamed from ioctl.h +0 -0
lib/kerncompat.h renamed from kerncompat.h +0 -0
lib/list.h renamed from list.h +0 -0
lib/print-tree.c renamed from print-tree.c +0 -0
lib/print-tree.h renamed from print-tree.h +0 -0
lib/radix-tree.c renamed from radix-tree.c +0 -0
lib/radix-tree.h renamed from radix-tree.h +0 -0
lib/rbtree.c renamed from rbtree.c +0 -0
lib/rbtree.h renamed from rbtree.h +0 -0
lib/root-tree.c renamed from root-tree.c +0 -0
lib/transaction.h renamed from transaction.h +0 -0
lib/utils.c renamed from utils.c +0 -0
lib/utils.h renamed from utils.h +0 -0
lib/volumes.c renamed from volumes.c +0 -0
lib/volumes.h renamed from volumes.h +0 -0
misc/Makefile new file +79 -0
79 lines not on this page · raw message
misc/bcp renamed from bcp +0 -0
misc/btrfs-image.c renamed from btrfs-image.c +0 -0
misc/btrfs-map-logical.c renamed from btrfs-map-logical.c +0 -0
misc/btrfs-show.c renamed from btrfs-show.c +0 -0
misc/btrfs-vol.c renamed from btrfs-vol.c +0 -0
misc/btrfsck.c renamed from btrfsck.c +0 -0
misc/btrfsctl.c renamed from btrfsctl.c +0 -0
misc/btrfstune.c renamed from btrfstune.c +0 -0
misc/convert.c renamed from convert.c +0 -0
misc/debug-tree.c renamed from debug-tree.c +0 -0
misc/mkfs.c renamed from mkfs.c +0 -0
misc/version.sh renamed from version.sh +0 -0
tests/Makefile new file +88 -0
88 lines not on this page · raw message
tests/dir-test.c renamed from dir-test.c +0 -0
tests/hasher.c renamed from hasher.c +0 -0
tests/quick-test.c renamed from quick-test.c +0 -0
tests/random-test.c renamed from random-test.c +0 -0
tests/show-blocks renamed from show-blocks +0 -0
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 2/4 btrfs-progs: Add debug-btrfs command
In reply to Aneesh Kumar K.V--- Makefile | 3 + debugbtrfs/Makefile | 44 +++++++ debugbtrfs/cmds.c | 27 +++++ debugbtrfs/debug_btrfs.c | 59 ++++++++++ debugbtrfs/debug_btrfs.h | 29 +++++ debugbtrfs/debug_btrfs_cmds.ct | 33 ++++++ debugbtrfs/debug_tree.c | 243 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 438 insertions(+), 0 deletions(-) create mode 100644 debugbtrfs/Makefile create mode 100644 debugbtrfs/cmds.c create mode 100644 debugbtrfs/debug_btrfs.c create mode 100644 debugbtrfs/debug_btrfs.h create mode 100644 debugbtrfs/debug_btrfs_cmds.ct create mode 100644 debugbtrfs/debug_tree.c
Makefile +3 -0
@@ -12,6 +12,9 @@ bindir = $(prefix)/bin LIBS=-luuid SUBDIRS=lib misc man +ifneq ($(E2FSPRGS_BUILD_DIR),) + SUBDIRS += debugbtrfs +endif # make C=1 to enable sparse ifdef C
debugbtrfs/Makefile new file +44 -0
44 lines not on this page · raw message
debugbtrfs/cmds.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright IBM Corporation, 2010 +* Author Aneesh Kumar K.V <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ + +#include <stdio.h> +#include "debug_btrfs.h" + +void do_show_debugfs_params (int argc,char *argv[]) +{ +FILE *out = stdout; +fprintf (out,"Filesystem in use: %s\n" , current_device); +}
debugbtrfs/debug_btrfs.c new file +59 -0
59 lines not on this page · raw message
debugbtrfs/debug_btrfs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright IBM Corporation, 2010 +* Author Aneesh Kumar K.V <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ + +#ifndef DEBUG_BTRFS_H +#define DEBUG_BTRFS_H +#include <getopt.h> + +extern const char *current_device; +static inline void reset_getopt (void ) +{ + optind =0 ; +} +#endif
debugbtrfs/debug_btrfs_cmds.ct new file +33 -0
@@ -0,0 +1,33 @@ +# Copyright IBM Corporation, 2010 +# Author Aneesh Kumar K.V <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License v2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA. + +command_table btrfs_debug_cmds; + +request do_show_debugfs_params, "Show btrfs_debug parameters", + show_debugfs_params, params; + +request do_dump_tree, "Show full btrfs tree", + dump_tree; + +request do_dump_root_tree, "Show root tree", + dump_root_tree; + +request do_dump_chunk_tree, "Show btrfs chunk tree", + dump_chunk_tree; + +end; +
debugbtrfs/debug_tree.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 3/4 debug-btrfs: Add open file system command
In reply to Aneesh Kumar K.V--- debugbtrfs/cmds.c | 23 +++++++++++++++++ debugbtrfs/debug_btrfs.c | 16 +++++------ debugbtrfs/debug_btrfs.h | 1 + debugbtrfs/debug_btrfs_cmds.ct | 3 ++ debugbtrfs/debug_tree.c | 54 ++++++++++++++++----------------------- 5 files changed, 56 insertions(+), 41 deletions(-)
debugbtrfs/cmds.c +23 -0
@@ -18,6 +18,11 @@*/ #include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "ctree.h" +#include "disk-io.h" #include "debug_btrfs.h" void do_show_debugfs_params (int argc,char *argv[])
@@ -25,3 +30,21 @@ void do_show_debugfs_params(int argc, char *argv[])FILE *out = stdout;fprintf (out,"Filesystem in use: %s\n" , current_device); } + +void do_open_filesys (int argc,char *argv[]) +{ +if (argc !=1 ) { +free ((void *)current_device); + current_device =strdup (argv[1 ]); + } + +if (current_fs_root) +close_ctree (current_fs_root); + +radix_tree_init (); + current_fs_root =open_ctree (current_device,0 ,0 ); +if (!current_fs_root) { +fprintf (stderr,"unable to open %s\n" , current_device); +return ; + } +}
debugbtrfs/debug_btrfs.c +7 -9
@@ -19,27 +19,25 @@#include <stdio.h> #include <stdlib.h> +#include <string.h> #include <ss/ss.h> #include "debug_btrfs.h" extern ss_request_table btrfs_debug_cmds;const char *current_device; - -void usage (char *prg) -{ -fprintf (stderr,"Usage: %s device\n" , prg); -exit (1 ); -} +struct btrfs_root *current_fs_root; +extern void do_open_filesys (int argc,char *argv[]);int main (int argc,char *argv[]) {int sci_idx;int retval; -if (argc <2 ) -usage (argv[0 ]); +if (argc !=1 ) { +/* open the file system */ +do_open_filesys (argc, argv); + } - current_device = argv[1 ]; sci_idx =ss_create_invocation ("debug-btrfs" ,"0.0" ,NULL , &btrfs_debug_cmds, &retval);if (retval) {
debugbtrfs/debug_btrfs.h +1 -0
@@ -22,6 +22,7 @@#include <getopt.h> extern const char *current_device; +extern struct btrfs_root *current_fs_root;static inline void reset_getopt (void ) { optind =0 ;
debugbtrfs/debug_btrfs_cmds.ct +3 -0
@@ -20,6 +20,9 @@ command_table btrfs_debug_cmds; request do_show_debugfs_params, "Show btrfs_debug parameters", show_debugfs_params, params; +request do_open_filesys, "Open the file system", + open_filesys, open; + request do_dump_tree, "Show full btrfs tree", dump_tree;
debugbtrfs/debug_tree.c +22 -32
108 lines not on this page · raw message
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 4/4 debug-btrfs: Add print_inode command
In reply to Aneesh Kumar K.V--- debugbtrfs/cmds.c | 100 ++++++++++++++++++++++++++++++++++++++++ debugbtrfs/debug_btrfs_cmds.ct | 3 + 2 files changed, 103 insertions(+), 0 deletions(-)
debugbtrfs/cmds.c +100 -0
@@ -23,6 +23,8 @@#include "ctree.h" #include "disk-io.h" +#include "extent_io.h" +#include "transaction.h" #include "debug_btrfs.h" void do_show_debugfs_params (int argc,char *argv[])
@@ -48,3 +50,101 @@ void do_open_filesys(int argc, char *argv[])return ; } } + +void dump_inode_details (u64 ino,struct extent_buffer *leaf, +struct btrfs_inode_item *inode_item) +{ +char *format_space =" " ; +printf ("Inode: %10llu" , (unsigned long long )ino); +printf ("%sMode: %5o" , format_space, +btrfs_inode_mode (leaf, inode_item) &0777 ); +printf ("%sUser: %d\n" , format_space,btrfs_inode_uid (leaf, inode_item)); +printf ("Size: %llu\n" , (unsigned long long ) +btrfs_inode_size (leaf, inode_item)); +return ; +} + +void dump_file_extent (u64 offset,struct extent_buffer *leaf, +struct btrfs_file_extent_item *file_extent_item) +{ +printf ("[%15llu - %15llu (%15llu)]\t->\t" , (unsigned long long ) offset, + (unsigned long long ) + offset +btrfs_file_extent_num_bytes (leaf, file_extent_item), +btrfs_file_extent_num_bytes (leaf, file_extent_item)); + +printf ("%15llu (%15llu)\n" , (unsigned long long ) +btrfs_file_extent_disk_bytenr (leaf, file_extent_item), +btrfs_file_extent_disk_num_bytes (leaf, file_extent_item)); +return ; +} + +void dump_file_hole_extent (u64 offset,u64 end_offset) +{ +printf ("[%15llu - %15llu (%15llu)]\t->\t" , (unsigned long long ) offset, + (unsigned long long ) end_offset, end_offset - offset); +printf ("Hole\n" ); +} + +void do_print_inode (int argc,char *argv[]) +{ +int ret; +u64 offset, inode_i_size; +struct btrfs_path *path; +struct btrfs_key inode_key; +struct extent_buffer *leaf; +struct btrfs_trans_handle *trans; +struct btrfs_inode_item *inode_item; +struct btrfs_file_extent_item *file_extent_item; + + +if (argc !=2 ) { +fprintf (stderr,"Usage inode inode_num\n" ); +return ; + } + inode_key.objectid =atoll (argv[1 ]); + inode_key.type =BTRFS_INODE_ITEM_KEY ; + inode_key.offset =0 ; + + path =btrfs_alloc_path (); +btrfs_init_path (path); + trans =btrfs_start_transaction (current_fs_root,1 ); + + ret =btrfs_search_slot (trans, current_fs_root, &inode_key, path,0 ,0 ); +if (ret !=0 ) { +fprintf (stderr,"Failed get the inode details for %llu\n" , + (unsigned long long )inode_key.objectid); +return ; + } + leaf = path->nodes[0 ]; + inode_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item); +dump_inode_details (inode_key.objectid, leaf, inode_item); + inode_i_size =btrfs_inode_size (leaf, inode_item); +btrfs_release_path (current_fs_root, path); + +/* get the file extent details */ + offset =0 ; +/* Dump header */ +printf ("Extent details:\n" ); +printf ("[%15s - %15s (%15s)]\t->\t%15s (%15s)\n" , +"Logical offset" , +"End offset" , +"Extent Size" , +"Disk bytenr" , +"Actual disk size" ); +while (offset < inode_i_size) { +btrfs_init_path (path); + ret =btrfs_lookup_file_extent (trans, current_fs_root, path, + inode_key.objectid, offset,0 ); +if (ret !=0 ) { +fprintf (stderr,"Not able to retrive extent information\n" ); +break ; + } + leaf = path->nodes[0 ]; + file_extent_item =btrfs_item_ptr (leaf, path->slots[0 ], + struct btrfs_file_extent_item); +dump_file_extent (offset, leaf, file_extent_item); + offset +=btrfs_file_extent_num_bytes (leaf, file_extent_item); +btrfs_release_path (current_fs_root, path); + } +btrfs_commit_transaction (trans, current_fs_root); +}
debugbtrfs/debug_btrfs_cmds.ct +3 -0
@@ -32,5 +32,8 @@ request do_dump_root_tree, "Show root tree", request do_dump_chunk_tree, "Show btrfs chunk tree", dump_chunk_tree; +request do_print_inode, "Print inode details", + print_inode; + end;
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 5/6 debug-btrfs: Add command to dump each of the btrfs trees
--- debugbtrfs/debug_btrfs_cmds.ct | 19 ++++- debugbtrfs/debug_tree.c | 159 ++++++++++++++++++++------------------- 2 files changed, 99 insertions(+), 79 deletions(-)
debugbtrfs/debug_btrfs_cmds.ct +17 -2
@@ -23,17 +23,32 @@ request do_show_debugfs_params, "Show btrfs_debug parameters", request do_open_filesys, "Open the file system", open_filesys, open; +request do_print_inode, "Print inode details", + print_inode; + request do_dump_tree, "Show full btrfs tree", dump_tree; +request do_dump_extent_tree, "Show Extent tree", + dump_extent_tree; + request do_dump_root_tree, "Show root tree", dump_root_tree; request do_dump_chunk_tree, "Show btrfs chunk tree", dump_chunk_tree; -request do_print_inode, "Print inode details", - print_inode; +request do_dump_dev_tree, "Show btrfs dev tree", + dump_dev_tree; + +request do_dump_fs_tree, "Show btrfs fs tree", + dump_fs_tree; + +request do_dump_csum_tree, "Show btrfs checksum tree", + dump_csum_tree; + +request do_dump_log_tree, "Show btrfs log tree", + dump_log_tree; end;
debugbtrfs/debug_tree.c +82 -77
234 lines not on this page · raw message
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 6/6 debug-btrfs: Add pager support
In reply to Aneesh Kumar K.V--- debugbtrfs/Makefile | 5 +- debugbtrfs/debug_btrfs.h | 3 + debugbtrfs/debug_tree.c | 106 ++++++++++++-------- debugbtrfs/pager.c | 49 +++++++++ lib/ctree.c | 22 ++-- lib/extent-tree.c | 10 +- lib/print-tree.c | 256 +++++++++++++++++++++++----------------------- lib/print-tree.h | 8 +- lib/root-tree.c | 11 +- misc/debug-tree.c | 8 +- 10 files changed, 278 insertions(+), 200 deletions(-) create mode 100644 debugbtrfs/pager.c
debugbtrfs/Makefile +3 -2
@@ -33,8 +33,9 @@ all: $(progs) debug_btrfs_cmds.c: debug_btrfs_cmds.ct $(MK_CMDS) debug_btrfs_cmds.ct -debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o - $(CC) $(CFLAGS) -o debug-btrfs debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) +debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o pager.o + $(CC) $(CFLAGS) -o debug-btrfs debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o \ + pager.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) clean: rm -f *.o debug_btrfs_cmds.c
debugbtrfs/debug_btrfs.h +3 -0
@@ -19,6 +19,7 @@#ifndef DEBUG_BTRFS_H #define DEBUG_BTRFS_H +#include <stdio.h> #include <getopt.h> extern const char *current_device;
@@ -27,4 +28,6 @@ static inline void reset_getopt(void) { optind =0 ; } +extern FILE *open_pager (void ); +extern void close_pager (FILE *);#endif
debugbtrfs/debug_tree.c +65 -41
231 lines not on this page · raw message
debugbtrfs/pager.c new file +49 -0
49 lines not on this page · raw message
lib/ctree.c +11 -11
@@ -657,13 +657,13 @@ static int check_leaf(struct btrfs_root *root, struct btrfs_path *path,btrfs_item_key (leaf, &leaf_key, slot);btrfs_item_key_to_cpu (leaf, &cpukey, slot -1 );if (btrfs_comp_keys (&leaf_key, &cpukey) <=0 ) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("slot %d offset bad key\n" , slot);BUG_ON (1 ); }if (btrfs_item_offset_nr (leaf, slot -1 ) !=btrfs_item_end_nr (leaf, slot)) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("slot %d offset bad\n" , slot);BUG_ON (1 ); }
@@ -674,7 +674,7 @@ static int check_leaf(struct btrfs_root *root, struct btrfs_path *path,BUG_ON (btrfs_comp_keys (&leaf_key, &cpukey) >=0 );if (btrfs_item_offset_nr (leaf, slot) !=btrfs_item_end_nr (leaf, slot +1 )) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("slot %d offset bad\n" , slot);BUG_ON (1 ); }
@@ -2356,7 +2356,7 @@ split: ret =0 ;if (btrfs_leaf_free_space (root, leaf) <0 ) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);BUG (); }kfree (buf);
@@ -2456,7 +2456,7 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans, ret =0 ;if (btrfs_leaf_free_space (root, leaf) <0 ) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);BUG (); }return ret;
@@ -2484,7 +2484,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, data_end =leaf_data_end (root, leaf);if (btrfs_leaf_free_space (root, leaf) < data_size) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);BUG (); } slot = path->slots[0 ];
@@ -2492,7 +2492,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans,BUG_ON (slot <0 );if (slot >= nritems) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("slot %d too large, nritems %d\n" , slot, nritems);BUG_ON (1 ); }
@@ -2521,7 +2521,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, ret =0 ;if (btrfs_leaf_free_space (root, leaf) <0 ) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);BUG (); }return ret;
@@ -2572,7 +2572,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, data_end =leaf_data_end (root, leaf);if (btrfs_leaf_free_space (root, leaf) < total_size) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("not enough freespace need %u have %d\n" , total_size,btrfs_leaf_free_space (root, leaf));BUG ();
@@ -2586,7 +2586,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,unsigned int old_data =btrfs_item_end_nr (leaf, slot);if (old_data < data_end) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);printk ("slot %d old_data %d data_end %d\n" , slot, old_data, data_end);BUG_ON (1 );
@@ -2634,7 +2634,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, }if (btrfs_leaf_free_space (root, leaf) <0 ) { -btrfs_print_leaf (root, leaf); +btrfs_print_leaf (stdout, root, leaf);BUG (); }
lib/extent-tree.c +5 -5
@@ -1447,7 +1447,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,if (ret <0 ) goto out;if (ret !=0 ) { -btrfs_print_leaf (root, path->nodes[0 ]); +btrfs_print_leaf (stdout, root, path->nodes[0 ]);printk ("failed to find block number %Lu\n" , bytenr);BUG (); }
@@ -1505,7 +1505,7 @@ int btrfs_set_block_flags(struct btrfs_trans_handle *trans,if (ret <0 ) goto out;if (ret !=0 ) { -btrfs_print_leaf (root, path->nodes[0 ]); +btrfs_print_leaf (stdout, root, path->nodes[0 ]);printk ("failed to find block number %Lu\n" , (unsigned long long )bytenr);BUG ();
@@ -2126,13 +2126,13 @@ static int __free_extent(struct btrfs_trans_handle *trans,printk (KERN_ERR "umm, got %d back from search" ", was looking for %llu\n" , ret, (unsigned long long )bytenr); -btrfs_print_leaf (extent_root, path->nodes[0 ]); +btrfs_print_leaf (stdout, extent_root, path->nodes[0 ]); }BUG_ON (ret); extent_slot = path->slots[0 ]; } }else { -btrfs_print_leaf (extent_root, path->nodes[0 ]); +btrfs_print_leaf (stdout, extent_root, path->nodes[0 ]);WARN_ON (1 ); printk(KERN_ERR "btrfs unable to find ref byte nr %llu " "parent %llu root %llu owner %llu offset %llu\n",
@@ -2165,7 +2165,7 @@ static int __free_extent(struct btrfs_trans_handle *trans,printk (KERN_ERR "umm, got %d back from search" ", was looking for %llu\n" , ret, (unsigned long long )bytenr); -btrfs_print_leaf (extent_root, path->nodes[0 ]); +btrfs_print_leaf (stdout, extent_root, path->nodes[0 ]); }BUG_ON (ret); extent_slot = path->slots[0 ];
lib/print-tree.c +128 -128
652 lines not on this page · raw message
lib/print-tree.h +5 -3
@@ -18,7 +18,9 @@#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_key (struct btrfs_disk_key *disk_key); +#include <stdio.h> + +void btrfs_print_leaf (FILE *out,struct btrfs_root *root,struct extent_buffer *l); +void btrfs_print_tree (FILE *out,struct btrfs_root *root,struct extent_buffer *t); +void btrfs_print_key (FILE *out,struct btrfs_disk_key *disk_key);#endif
lib/root-tree.c +5 -6
@@ -182,12 +182,11 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,if (ret <0 ) goto out;if (ret) { -btrfs_print_leaf (root, path->nodes[0 ]); -printk ("failed to del %llu %u %llu\n" , - (unsigned long long )key->objectid, - key->type, - (unsigned long long )key->offset); - +btrfs_print_leaf (stdout, root, path->nodes[0 ]); +printk ("failed to del %llu %u %llu\n" , + (unsigned long long )key->objectid, + key->type, + (unsigned long long )key->offset); }BUG_ON (ret !=0 ); leaf = path->nodes[0 ];
misc/debug-tree.c +4 -4
@@ -144,11 +144,11 @@ int main(int ac, char **av) }if (!extent_only) {printf ("root tree\n" ); -btrfs_print_tree (root->fs_info->tree_root, +btrfs_print_tree (stdout, root->fs_info->tree_root, root->fs_info->tree_root->node);printf ("chunk tree\n" ); -btrfs_print_tree (root->fs_info->chunk_root, +btrfs_print_tree (stdout, root->fs_info->chunk_root, root->fs_info->chunk_root->node); } tree_root_scan = root->fs_info->tree_root;
@@ -258,9 +258,9 @@ again: }if (!skip && !extent_only) {printf (" tree " ); -btrfs_print_key (&disk_key); +btrfs_print_key (stdout, &disk_key);printf (" \n" ); -btrfs_print_tree (tree_root_scan, buf); +btrfs_print_tree (stdout, tree_root_scan, buf); }else if (extent_only && !skip) {print_extents (tree_root_scan, buf); }
Signature · 1 line
1.7.0.rc0.48.gdace5