btrfs-progs: Move files around
Subsystems (3)
PATCH 1/6 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/6 btrfs-progs: Add debug-btrfs command
--- Makefile | 3 ++ debugbtrfs/Makefile | 44 +++++++++++++++++++++++++++++ debugbtrfs/cmds.c | 27 ++++++++++++++++++ debugbtrfs/debug_btrfs.c | 59 ++++++++++++++++++++++++++++++++++++++++ debugbtrfs/debug_btrfs.h | 29 +++++++++++++++++++ debugbtrfs/debug_btrfs_cmds.ct | 24 ++++++++++++++++ 6 files changed, 186 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
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 +24 -0
@@ -0,0 +1,24 @@ +# 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; + +end; +
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 3/6 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 +++ 4 files changed, 34 insertions(+), 9 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,5 +20,8 @@ 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; + end;
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 4/6 debug-btrfs: Add command to dump each of the btrfs trees
In reply to Aneesh Kumar K.V--- debugbtrfs/Makefile | 2 +- debugbtrfs/debug_btrfs_cmds.ct | 24 ++++ debugbtrfs/debug_tree.c | 238 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+), 1 deletions(-) create mode 100644 debugbtrfs/debug_tree.c
debugbtrfs/Makefile +1 -1
@@ -33,7 +33,7 @@ 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-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o $(CC) $(CFLAGS) -o debug-btrfs $^ $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) clean:
debugbtrfs/debug_btrfs_cmds.ct +24 -0
@@ -23,5 +23,29 @@ request do_show_debugfs_params, "Show btrfs_debug parameters", request do_open_filesys, "Open the file system", open_filesys, open; +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_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 new file +238 -0
238 lines not on this page · raw message
Signature · 1 line
1.7.0.rc0.48.gdace5
PATCH 5/6 debug-btrfs: Add pager support
In reply to Aneesh Kumar K.V--- debugbtrfs/Makefile | 2 +- debugbtrfs/debug_btrfs.h | 3 + debugbtrfs/debug_tree.c | 107 ++++++++++++-------- 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, 277 insertions(+), 199 deletions(-) create mode 100644 debugbtrfs/pager.c
debugbtrfs/Makefile +1 -1
@@ -33,7 +33,7 @@ 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 +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 $^ $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) clean:
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 +66 -41
232 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
PATCH 6/6 debug-btrfs: Add print_inode command
In reply to Aneesh Kumar K.V--- debugbtrfs/cmds.c | 191 ++++++++++++++++++++++++++++++++++++++++ debugbtrfs/debug_btrfs_cmds.ct | 3 + lib/volumes.c | 16 ---- lib/volumes.h | 12 +++ 4 files changed, 206 insertions(+), 16 deletions(-)
debugbtrfs/cmds.c +191 -0
@@ -20,10 +20,15 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <uuid/uuid.h> +#include <time.h> #include "ctree.h" #include "disk-io.h" +#include "extent_io.h" +#include "transaction.h" #include "debug_btrfs.h" +#include "volumes.h" void do_show_debugfs_params (int argc,char *argv[]) {
@@ -48,3 +53,189 @@ void do_open_filesys(int argc, char *argv[])return ; } } + +void dump_inode_details (FILE *out,u64 ino,struct extent_buffer *leaf, +struct btrfs_inode_item *inode_item) +{ +time_t t; +fprintf (out,"%-7s%-20llu" ,"Inode:" , (unsigned long long )ino); +fprintf (out,"Generation: %llu\n" , +btrfs_inode_generation (leaf, inode_item)); + +fprintf (out,"%-7s%-5o" ,"Mode:" , +btrfs_inode_mode (leaf, inode_item) &0777 ); + +fprintf (out,"%-7s%-10d" ,"User:" , +btrfs_inode_gid (leaf, inode_item)); +fprintf (out,"%-7s%-10d\n" ,"Group:" , +btrfs_inode_uid (leaf, inode_item)); + +fprintf (out,"%-7s%-20llu" ,"Size:" , (unsigned long long ) +btrfs_inode_size (leaf, inode_item)); +fprintf (out,"%-7s%u\n" ,"Link:" , + (unsigned int )btrfs_inode_nlink (leaf, inode_item)); + + t = (time_t )btrfs_timespec_sec (leaf, +btrfs_inode_atime (inode_item)); +fprintf (out,"atime: %s" ,ctime (&t)); + t = (time_t )btrfs_timespec_sec (leaf, +btrfs_inode_ctime (inode_item)); +fprintf (out,"ctime: %s" ,ctime (&t)); + t = (time_t )btrfs_timespec_sec (leaf, +btrfs_inode_mtime (inode_item)); +fprintf (out,"mtime: %s" ,ctime (&t)); + t = (time_t )btrfs_timespec_sec (leaf, +btrfs_inode_otime (inode_item)); +fprintf (out,"otime: %s" ,ctime (&t)); + +return ; +} + +void dump_map_type (FILE *out,struct map_lookup *map) +{ +u64 type = map->type; + +fprintf (out,"Raid type = " ); + +if (type &BTRFS_BLOCK_GROUP_RAID0 ) +fprintf (out,"Raid0" ); +else if (type &BTRFS_BLOCK_GROUP_RAID1 ) +fprintf (out,"Raid1" ); +else if (type &BTRFS_BLOCK_GROUP_RAID10 ) +fprintf (out,"Raid10" ); +else if (type &BTRFS_BLOCK_GROUP_DUP ) +fprintf (out,"Duplicated data" ); +else +fprintf (out,"None" ); + +fprintf (out,"\n" ); +} + +void dump_chunk_details (FILE *out,u64 logical,u64 length) +{ +int ret, i; +char fs_uuid[37 ]; +struct cache_extent *ce; +struct map_lookup *map; +struct btrfs_multi_bio *multi =NULL ; +struct btrfs_mapping_tree *map_tree = ¤t_fs_root->fs_info->mapping_tree; + + ret =btrfs_map_block (map_tree,WRITE , logical, &length, &multi,0 ); +if (ret) { +fprintf (stderr,"Error in finding the chunk details \n" ); +return ; + } +fprintf (out,"Number of devices = %d\n" , multi->num_stripes); + ce =find_first_cache_extent (&map_tree->cache_tree, logical); + map = container_of(ce, struct map_lookup, ce); +dump_map_type (out, map); +for (i =0 ; i < multi->num_stripes; i++) { +uuid_unparse (multi->stripes[i].dev->uuid , fs_uuid); +fprintf (out,"Device uuid = %s\n" , fs_uuid); +fprintf (out,"Device = %s Offset = %llu \n" , + multi->stripes[i].dev->name, + multi->stripes[i].physical); + + } +} + +void dump_file_extent (FILE *out,int count,u64 offset, +struct extent_buffer *leaf, +struct btrfs_file_extent_item *file_extent_item, +int print_chunk_details) +{ +fprintf (out,"\nExtent %d\n" , count); +fprintf (out,"Logical offset = %llu Extent size = %llu\n" , + (unsigned long long ) offset, +btrfs_file_extent_num_bytes (leaf, file_extent_item)); + +fprintf (out,"Disk bytenr = %llu Actual disk size = %llu" , + (unsigned long long ) +btrfs_file_extent_disk_bytenr (leaf, file_extent_item), +btrfs_file_extent_disk_num_bytes (leaf, file_extent_item)); + +if (!btrfs_file_extent_disk_bytenr (leaf, file_extent_item)) +fprintf (out," (Hole)" ); +fprintf (out,"\n" ); +if (print_chunk_details) +dump_chunk_details (out,btrfs_file_extent_disk_bytenr (leaf, file_extent_item), +btrfs_file_extent_disk_num_bytes (leaf, file_extent_item)); +return ; +} + +void do_print_inode (int argc,char *argv[]) +{ +FILE *out; +int c; +int print_chunk_details =0 ; +int ret, count =0 ; +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; + + +reset_getopt (); +while ((c =getopt (argc, argv,"ch" )) !=EOF ) { +switch (c) { +case 'c' : + print_chunk_details =1 ; +break ; +default : +fprintf (stderr,"Usage %s [-ch] inode number\n" , + argv[0 ]); +return ; + } + } +if (optind == argc) { +fprintf (stderr,"Usage %s [-ch] inode number\n" , + argv[0 ]); +return ; + } + out =open_pager (); + inode_key.objectid =atoll (argv[optind]); + 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); + goto err_out; + } + leaf = path->nodes[0 ]; + inode_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item); +dump_inode_details (out, 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 ; +while (offset < inode_i_size) { + 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 (out, count, offset, + leaf, file_extent_item, print_chunk_details); + offset +=btrfs_file_extent_num_bytes (leaf, file_extent_item); +btrfs_release_path (current_fs_root, path); + count++; + } +err_out: +btrfs_free_path (path); +btrfs_commit_transaction (trans, current_fs_root); +close_pager (out); +}
debugbtrfs/debug_btrfs_cmds.ct +3 -0
@@ -47,5 +47,8 @@ request do_dump_csum_tree, "Show btrfs checksum tree", request do_dump_log_tree, "Show btrfs log tree", dump_log_tree; +request do_print_inode, "Print inode details", + print_inode; + end;
lib/volumes.c +0 -16
@@ -30,22 +30,6 @@#include "print-tree.h" #include "volumes.h" -struct stripe { -struct btrfs_device *dev; -u64 physical; -}; - -struct map_lookup { -struct cache_extent ce; -u64 type; -int io_align; -int io_width; -int stripe_len; -int sector_size; -int num_stripes; -int sub_stripes; -struct btrfs_bio_stripe stripes[]; -};#define map_lookup_size (n) (sizeof(struct map_lookup) + \ (sizeof(struct btrfs_bio_stripe) * (n)))
lib/volumes.h +12 -0
@@ -88,6 +88,18 @@ struct btrfs_multi_bio {struct btrfs_bio_stripe stripes[]; }; +struct map_lookup { +struct cache_extent ce; +u64 type; +int io_align; +int io_width; +int stripe_len; +int sector_size; +int num_stripes; +int sub_stripes; +struct btrfs_bio_stripe stripes[]; +}; +#define btrfs_multi_bio_size (n) (sizeof(struct btrfs_multi_bio) + \ (sizeof(struct btrfs_bio_stripe) * (n)))
Signature · 1 line
1.7.0.rc0.48.gdace5
Add debug-btrfs (btrfs file system debugger)
In reply to Aneesh Kumar K.VHi Chris,
This is the -V2 version of the patch. I have cleaned up the patches and added -c option to print_inode to print the chunk mapping details. I guess they are ready to be merged
Patches can also be found at
http://www.kernel.org/pub/linux/kernel/people/kvaneesh/debug-btrfs/
-aneesh