Skip to contentSkip to conversation

debugfs: add the ability to manipulate the extent tree directly

PATCH New Theodore Ts'o 1 participant 1 message Dec 24, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: add the ability to manipulate the extent tree directly

This commit adds the functionality which had previously only been in the tst_extents command to debugfs. The debugfs command extent_open will open extent tree of a particular inode, and enables a series of commands which will allow the user to interact with the extent tree directly. Once the extent tree is closed via extent_open(), these additional commands will be disabled again.

This commit exports two new functions from lib/ext2fs/extent.c which had previously been statically defined: ext2fs_extent_node_split() and ext2fs_extent_goto2().

---
 debugfs/Makefile.in                                |  12 +-
 debugfs/debug_cmds.ct                              |   3 +
 debugfs/debugfs.c                                  |   5 +-
 debugfs/debugfs.h                                  |   3 +
 lib/ext2fs/extent_dbg.ct => debugfs/extent_cmds.ct |   6 +-
 debugfs/extent_inode.c                             | 547 +++++++++++++++++++++
 debugfs/ro_debug_cmds.ct                           |   3 +
 lib/ext2fs/Makefile.in                             |  18 +-
 lib/ext2fs/ext2fs.h                                |   3 +
 lib/ext2fs/extent.c                                | 489 +-----------------
 10 files changed, 595 insertions(+), 494 deletions(-)
 rename lib/ext2fs/extent_dbg.ct => debugfs/extent_cmds.ct (95%)
 create mode 100644 debugfs/extent_inode.c
debugfs/Makefile.in +8 -4
index 7e71c3f..42868a3 100644
@@ -18,16 +18,16 @@ MK_CMDS=	_SS_DIR_OVERRIDE=../lib/ss ../lib/ss/mk_cmds
 
 DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \
 	lsdel.o dump.o set_fields.o logdump.o htree.o unused.o e2freefrag.o \
-	filefrag.o
+	filefrag.o extent_cmds.o extent_inode.o
 
 RO_DEBUG_OBJS= ro_debug_cmds.o ro_debugfs.o util.o ncheck.o icheck.o ls.o \
-	lsdel.o logdump.o htree.o e2freefrag.o filefrag.o
+	lsdel.o logdump.o htree.o e2freefrag.o filefrag.o extent_inode.o
 
 SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \
 	$(srcdir)/ncheck.c $(srcdir)/icheck.c $(srcdir)/lsdel.c \
 	$(srcdir)/dump.c $(srcdir)/set_fields.c ${srcdir}/logdump.c \
 	$(srcdir)/htree.c $(srcdir)/unused.c ${srcdir}/../misc/e2freefrag.c \
-	$(srcdir)/filefrag.c
+	$(srcdir)/filefrag.c $(srcdir)/extent_inode.c
 
 LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
 	$(LIBUUID)
@@ -52,6 +52,10 @@ debug_cmds.c debug_cmds.h: debug_cmds.ct
 	$(E) "	MK_CMDS $@"
 	$(Q) $(MK_CMDS) $(srcdir)/debug_cmds.ct
 
+extent_cmds.c extent_cmds.h: extent_cmds.ct
+	$(E) "	MK_CMDS $@"
+	$(Q) $(MK_CMDS) $(srcdir)/extent_cmds.ct
+
 ro_debug_cmds.c ro_debug_cmds.h: ro_debug_cmds.ct
 	$(E) "	MK_CMDS $@"
 	$(Q) $(MK_CMDS) $(srcdir)/ro_debug_cmds.ct
@@ -102,7 +106,7 @@ uninstall:
 
 clean:
 	$(RM) -f $(PROGS) debugfs.8 \#* *.s *.o *.a *~ debug_cmds.c \
-		ro_debug_cmds.c core rdebugfs
+		extent_cmds.c ro_debug_cmds.c core rdebugfs
 
 mostlyclean: clean
 distclean: clean
debugfs/debug_cmds.ct +3 -0
index a799dd7..7767f8f 100644
@@ -178,5 +178,8 @@ request do_dump_mmp, "Dump MMP information",
 request do_set_mmp_value, "Set MMP value",
 	set_mmp_value, smmp;
 
+request do_extent_open, "Open inode for extent manipulation",
+	extent_open, eo;
+
 end;
 
debugfs/debugfs.c +1 -4
index cf80bd0..9bcfd52 100644
@@ -28,8 +28,6 @@ extern char *optarg;
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "et/com_err.h"
-#include "ss/ss.h"
 #include "debugfs.h"
 #include "uuid/uuid.h"
 #include "e2p/e2p.h"
@@ -39,9 +37,9 @@ extern char *optarg;
 #include "../version.h"
 #include "jfs_user.h"
 
-extern ss_request_table debug_cmds;
 ss_request_table *extra_cmds;
 const char *debug_prog_name;
+int sci_idx;
 
 ext2_filsys	current_fs = NULL;
 ext2_ino_t	root, cwd;
@@ -2284,7 +2282,6 @@ static int source_file(const char *cmd_file, int sci_idx)
 int main(int argc, char **argv)
 {
 	int		retval;
-	int		sci_idx;
 	const char	*usage = 
 		"Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] "
 		"[-R request] [-V] ["
debugfs/debugfs.h +3 -0
index 994577c..efd8d12 100644
@@ -2,6 +2,7 @@
  * debugfs.h --- header file for the debugfs program
  */
 
+#include "ss/ss.h"
 #include "ext2fs/ext2_fs.h"
 #include "ext2fs/ext2fs.h"
 
@@ -21,6 +22,8 @@
 
 extern ext2_filsys current_fs;
 extern ext2_ino_t	root, cwd;
+extern int sci_idx;
+extern ss_request_table debug_cmds, extent_cmds;
 
 extern void reset_getopt(void);
 extern FILE *open_pager(void);
debugfs/extent_cmds.ct renamed from lib/ext2fs/extent_dbg.ct +3 -3
similarity index 95%
rename from lib/ext2fs/extent_dbg.ct
rename to debugfs/extent_cmds.ct
index c1d8033..e1c4395 100644
@@ -4,9 +4,6 @@
 #
 command_table extent_cmds;
 
-request do_inode, "Open an inode",
-	inode;
-
 request do_current_node, "Current extent node",
 	current_node, current;
 
@@ -73,5 +70,8 @@ request do_goto_block, "Goto extent containing specified block",
 request do_info, "Print extent info",
 	info;
 
+request do_extent_close, "Close extent handle",
+	extent_close, ec;
+
 end;
 
debugfs/extent_inode.c new file +547 -0

547 lines not on this page · raw message

debugfs/ro_debug_cmds.ct +3 -0
index 4feb621..8226d1a 100644
@@ -87,5 +87,8 @@ request do_supported_features, "Print features supported by this version of e2fs
 request do_dump_mmp, "Dump MMP information",
 	dump_mmp;
 
+request do_extent_open, "Open inode for extent manipulation",
+	extent_open, eo;
+
 end;
 
lib/ext2fs/Makefile.in +13 -5
index 0aaa6d6..8eb2f7c 100644
@@ -292,17 +292,25 @@ extent_dbg.c: $(srcdir)/extent_dbg.ct
 	$(Q) $(MK_CMDS) $(srcdir)/extent_dbg.ct
 
 debug_cmds.c debug_cmds.h: $(top_srcdir)/debugfs/debug_cmds.ct
-	$(E) "	MK_CMDS $<@"
+	$(E) "	MK_CMDS $<"
 	$(Q) $(MK_CMDS) $(top_srcdir)/debugfs/debug_cmds.ct
 
+extent_cmds.c extent_cmds.h: $(top_srcdir)/debugfs/extent_cmds.ct
+	$(E) "	MK_CMDS $<"
+	$(Q) $(MK_CMDS) $(top_srcdir)/debugfs/extent_cmds.ct
+
 DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \
 	lsdel.o dump.o set_fields.o logdump.o htree.o unused.o \
-	e2freefrag.o filefrag.o
+	e2freefrag.o filefrag.o extent_inode.o extent_cmds.o
 
 debugfs.o: $(top_srcdir)/debugfs/debugfs.c
 	$(E) "	CC $<"
 	$(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@
 
+extent_inode.o: $(top_srcdir)/debugfs/extent_inode.c
+	$(E) "	CC $<"
+	$(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@
+
 util.o: $(top_srcdir)/debugfs/util.c
 	$(E) "	CC $<"
 	$(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@
@@ -361,10 +369,10 @@ tst_bitmaps: tst_bitmaps.o tst_bitmaps_cmd.o $(STATIC_LIBEXT2FS) $(DEPLIBSS) \
 	$(Q) $(CC) -o $@ tst_bitmaps.o tst_bitmaps_cmd.o $(ALL_CFLAGS) \
 		$(STATIC_LIBEXT2FS) $(LIBSS) $(STATIC_LIBCOM_ERR)
 
-tst_extents: $(srcdir)/extent.c extent_dbg.c $(DEBUG_OBJS) $(DEPLIBSS) \
+tst_extents: $(srcdir)/extent.c $(DEBUG_OBJS) $(DEPLIBSS) \
 	$(LIBE2P) $(DEPLIBUUID) $(DEPLIBBLKID) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
-	$(Q) $(CC) -o tst_extents $(srcdir)/extent.c extent_dbg.c \
+	$(Q) $(CC) -o tst_extents $(srcdir)/extent.c \
 		$(ALL_CFLAGS) -DDEBUG $(DEBUG_OBJS) $(LIBSS) $(LIBE2P) \
 		$(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) $(STATIC_LIBCOM_ERR) \
 		-I $(top_srcdir)/debugfs
@@ -446,7 +454,7 @@ clean::
 		tst_byteswap tst_ismounted tst_getsize tst_sectgetsize \
 		tst_bitops tst_types tst_icount tst_super_size tst_csum \
 		tst_bitmaps tst_bitmaps_out tst_bitmaps_cmd.c \
-		ext2_tdbtool mkjournal debug_cmds.c \
+		ext2_tdbtool mkjournal debug_cmds.c extent_cmds.c \
 		../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a \
 		crc32c_table.h gen_crc32ctable tst_crc32c
 
lib/ext2fs/ext2fs.h +3 -0
index 1b35ff7..a06f57e 100644
@@ -1070,6 +1070,7 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
 				   int flags, struct ext2fs_extent *extent);
+extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
 				       struct ext2fs_extent *extent);
 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
@@ -1082,6 +1083,8 @@ extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
 					struct ext2_extent_info *info);
 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
 				    blk64_t blk);
+extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
+				     int leaf_level, blk64_t blk);
 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
 
 /* fileio.c */
lib/ext2fs/extent.c +11 -475

545 lines not on this page · raw message