* [PATCH] e2fsprogs: Dump extent/sindices using debugfs
@ 2008-06-11 10:11 Girish Shilamkar
2008-06-11 10:43 ` Aneesh Kumar K.V
0 siblings, 1 reply; 4+ messages in thread
From: Girish Shilamkar @ 2008-06-11 10:11 UTC (permalink / raw)
To: Theodore Tso; +Cc: Ext4 Mailing List
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
Hi Ted,
The attached patch adds a command to debugfs to display all the
extents/indices contained in an inode or the block specified.
The options to the command includes tranversing and dumping the entire
extent tree (if inode specified) or the branch (in case of block) and
can display only the headers if required.
Would you please let me know your comments/suggestions ?
Thanks,
Girish
[-- Attachment #2: disp-ext-map.patch --]
[-- Type: text/x-patch, Size: 5983 bytes --]
Index: e2fsprogs-1.40.7/debugfs/debug_cmds.ct
===================================================================
--- e2fsprogs-1.40.7.orig/debugfs/debug_cmds.ct
+++ e2fsprogs-1.40.7/debugfs/debug_cmds.ct
@@ -157,5 +157,8 @@ request do_set_current_time, "Set curren
request do_supported_features, "Print features supported by this version of e2fsprogs",
supported_features;
+request do_dump_extent_map, "Dump extent map",
+ dump_extent_map, ext_map;
+
end;
Index: e2fsprogs-1.40.7/debugfs/debugfs.c
===================================================================
--- e2fsprogs-1.40.7.orig/debugfs/debugfs.c
+++ e2fsprogs-1.40.7/debugfs/debugfs.c
@@ -42,6 +42,9 @@ extern char *optarg;
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
+#define DUMP_EXT_MAP_HEADER_ONLY 1
+#define DUMP_EXT_MAP_TRAVERSE 2
+
extern ss_request_table debug_cmds;
ext2_filsys current_fs = NULL;
@@ -1858,6 +1861,177 @@ void do_supported_features(int argc, cha
}
}
+void dump_ext_header(struct ext3_extent_header *eh)
+{
+ fprintf(stdout, "HEADER: magic=%x entries=%u max=%u depth=%u "
+ "generation=%u\n", eh->eh_magic, eh->eh_entries, eh->eh_max,
+ eh->eh_depth, eh->eh_generation);
+}
+
+void dump_ext_index(struct ext3_extent_idx *ix)
+{
+ fprintf(stdout, "INDEX: block=%u leaf=%u leaf_hi=%u unused=%u\n",
+ ix->ei_block, ix->ei_leaf, ix->ei_leaf_hi, ix->ei_unused);
+}
+
+void dump_ext_extent(struct ext3_extent *ex)
+{
+ fprintf(stdout, "EXTENT: block=%u-%u len=%u start=%u start_hi=%u\n",
+ ex->ee_block, ex->ee_block + ex->ee_len - 1,
+ ex->ee_len, ex->ee_start, ex->ee_start_hi);
+}
+
+void dump_extent_map(void *eh_buf, int size, int flag, blk_t blk)
+{
+ int i;
+ errcode_t err;
+ struct ext3_extent_header *eh = eh_buf;
+ void *block_buf;
+
+ if (blk == 0)
+ fprintf(stdout, "IN INODE:\n");
+ else
+ fprintf(stdout, "BLOCK NO. = %u:\n", blk);
+
+ err = ext2fs_extent_header_verify(eh, size);
+ if (err) {
+ com_err("ext_map", err, "");
+ dump_ext_header(eh);
+ return;
+ }
+
+ dump_ext_header(eh);
+
+ if (eh->eh_depth == 0) {
+ struct ext3_extent *ex = EXT_FIRST_EXTENT(eh);
+
+ if (!(flag & DUMP_EXT_MAP_HEADER_ONLY)) {
+ for (i = 0; i < eh->eh_entries; i++, ex++)
+ dump_ext_extent(ex);
+ printf("\n");
+ }
+ } else {
+ struct ext3_extent_idx *ix = EXT_FIRST_INDEX(eh);
+
+ if (!(flag & DUMP_EXT_MAP_HEADER_ONLY)) {
+ for (i = 0; i < eh->eh_entries; i++, ix++)
+ dump_ext_index(ix);
+ printf("\n");
+ }
+
+ if (flag & DUMP_EXT_MAP_TRAVERSE) {
+ if (ext2fs_get_mem(current_fs->blocksize, &block_buf))
+ return;
+
+ ix = EXT_FIRST_INDEX(eh);
+ for (i = 0; i < eh->eh_entries; i++, ix++) {
+ err = ext2fs_read_ext_block(current_fs,
+ ix->ei_leaf,
+ block_buf);
+ if (err) {
+ com_err("ext_map", 0,
+ "while reading block %u\n",
+ ix->ei_leaf);
+ return;
+ }
+ dump_extent_map(block_buf,
+ current_fs->blocksize, flag,
+ ix->ei_leaf);
+ }
+ ext2fs_free_mem(&block_buf);
+ }
+ }
+}
+
+void do_dump_extent_map(int argc, char *argv[])
+{
+ errcode_t err;
+ blk_t blknum;
+ int is_block = 0, c, flag = 0;
+ char *buf = NULL;
+ struct ext3_extent_header *eh;
+ ext2_ino_t ino;
+
+ if (common_args_process(argc, argv, 2, 5, argv[0],
+ " [-h] [-t] [-i <file>] [-b blocknr]", 0))
+ return;
+
+ reset_getopt();
+ while ((c = getopt(argc, argv, "b:hi:t")) != EOF) {
+ switch (c) {
+ case 'b':
+ is_block++;
+ if (strtoblk(argv[0], optarg, &blknum))
+ goto out;
+ if (blknum < 0 || blknum >=
+ current_fs->super->s_blocks_count) {
+ com_err(argv[0], 0, "Invalid block number %u",
+ blknum);
+ goto out;
+ }
+ break;
+ case 'h':
+ flag |= DUMP_EXT_MAP_HEADER_ONLY;
+ break;
+ case 'i':
+ is_block = 0;
+ ino = string_to_inode(optarg);
+ if (!ino)
+ return;
+ break;
+ case 't':
+ flag |= DUMP_EXT_MAP_TRAVERSE;
+ break;
+ default:
+ com_err(argv[0], 0, "Usage: [-h] [-t] [-i <file>] "
+ "[-b blocknr]");
+ return;
+ }
+ }
+
+ if (is_block == 0) {
+ struct ext2_inode *inode;
+
+ inode = (struct ext2_inode *)
+ malloc(EXT2_INODE_SIZE(current_fs->super));
+
+ if (debugfs_read_inode_full(ino, inode, argv[0],
+ EXT2_INODE_SIZE(current_fs->super))) {
+ free(inode);
+ return;
+ }
+
+ if (inode->i_flags & EXT4_EXTENTS_FL) {
+ eh = (struct ext3_extent_header *)&inode->i_block;
+ dump_extent_map(eh, sizeof(inode->i_block), flag, 0);
+ } else {
+ com_err(argv[0], 0, "Inode doesn't use extent map\n");
+ }
+
+ free(inode);
+ } else {
+ buf = malloc(current_fs->blocksize);
+ if (!buf) {
+ com_err(argv[0], 0, "Error allocating memory.\n");
+ return;
+ }
+
+ err = ext2fs_read_ext_block(current_fs, blknum, buf);
+ if (err) {
+ com_err(argv[0], err, "while reading block %u\n",
+ blknum);
+ goto out;
+ }
+
+ eh = (struct ext3_extent_header *)buf;
+
+ dump_extent_map(buf, current_fs->blocksize, flag, blknum);
+ }
+out:
+ if (buf)
+ free(buf);
+}
+
static int source_file(const char *cmd_file, int sci_idx)
{
FILE *f;
Index: e2fsprogs-1.40.7/debugfs/debugfs.8.in
===================================================================
--- e2fsprogs-1.40.7.orig/debugfs/debugfs.8.in
+++ e2fsprogs-1.40.7/debugfs/debugfs.8.in
@@ -191,6 +191,22 @@ to match
Expand the directory
.IR filespec .
.TP
+.I ext_map [-h] [-t] [-i <filespec>] [-b block]
+Dump the extent map contained in inode/block.
+.IR -h
+option can be used to display only the extent headers.
+.IR -t
+option can be used to dump entire extent tree, in case inode
+is specified, or branch if block is specified.
+If
+.IR -i
+option is set, dump the extent map contained in the inode
+.IR filespec .
+If
+.IR -b
+option is set, dump the extent map contained in block
+.IR block .
+.TP
.I feature [fs_feature] [-fs_feature] ...
Set or clear various filesystem features in the superblock. After setting
or clearing any filesystem features that were requested, print the current
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] e2fsprogs: Dump extent/sindices using debugfs
2008-06-11 10:11 [PATCH] e2fsprogs: Dump extent/sindices using debugfs Girish Shilamkar
@ 2008-06-11 10:43 ` Aneesh Kumar K.V
2008-06-12 8:32 ` Andreas Dilger
0 siblings, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2008-06-11 10:43 UTC (permalink / raw)
To: Girish Shilamkar; +Cc: Theodore Tso, Ext4 Mailing List
On Wed, Jun 11, 2008 at 03:41:28PM +0530, Girish Shilamkar wrote:
> Hi Ted,
> The attached patch adds a command to debugfs to display all the
> extents/indices contained in an inode or the block specified.
> The options to the command includes tranversing and dumping the entire
> extent tree (if inode specified) or the branch (in case of block) and
> can display only the headers if required.
>
> Would you please let me know your comments/suggestions ?
lib/ext2fs/tst_extents (I don't know why we don't install this by
default) have inode, root and ns/n command which help to iterate the
extent format inode
-aneesh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] e2fsprogs: Dump extent/sindices using debugfs
2008-06-11 10:43 ` Aneesh Kumar K.V
@ 2008-06-12 8:32 ` Andreas Dilger
2008-06-12 13:46 ` Theodore Tso
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Dilger @ 2008-06-12 8:32 UTC (permalink / raw)
To: Aneesh Kumar K.V; +Cc: Girish Shilamkar, Theodore Tso, Ext4 Mailing List
On Jun 11, 2008 16:13 +0530, Aneesh Kumar K.V wrote:
> On Wed, Jun 11, 2008 at 03:41:28PM +0530, Girish Shilamkar wrote:
> > The attached patch adds a command to debugfs to display all the
> > extents/indices contained in an inode or the block specified.
> > The options to the command includes tranversing and dumping the entire
> > extent tree (if inode specified) or the branch (in case of block) and
> > can display only the headers if required.
> >
> > Would you please let me know your comments/suggestions ?
>
> lib/ext2fs/tst_extents (I don't know why we don't install this by
> default) have inode, root and ns/n command which help to iterate the
> extent format inode
The "tst_*" programs are purely for regression testing. Having this
functionality built into a proper tool like debugfs is needed.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] e2fsprogs: Dump extent/sindices using debugfs
2008-06-12 8:32 ` Andreas Dilger
@ 2008-06-12 13:46 ` Theodore Tso
0 siblings, 0 replies; 4+ messages in thread
From: Theodore Tso @ 2008-06-12 13:46 UTC (permalink / raw)
To: Andreas Dilger; +Cc: Aneesh Kumar K.V, Girish Shilamkar, Ext4 Mailing List
On Thu, Jun 12, 2008 at 02:32:04AM -0600, Andreas Dilger wrote:
> >
> > lib/ext2fs/tst_extents (I don't know why we don't install this by
> > default) have inode, root and ns/n command which help to iterate the
> > extent format inode
Some of the reasons why tst_extents was created to extend debugfs,
instead of simply adding these commands to debugfs are:
1) To demonstrate the technique for creating programs for doing
per-module testing various new bits of the libext2 library, without
having to replicate a lot of infrastructure already provided by
debugfs. (Code reuse is good; lots of testing of *any* code before
you submit it, in either e2fsprogs or the ext4 kernel code is a very
good thing; one of the thing that disturbs me a little is when I trip
over bugs that indicate that obviously the code was obviously NOT
tested before submission, such as the on-line resizing code or patches
to the on-line resizing code, when online resizing was clearly and
obviously busted.)
2) The command names, "inode", "root", "next_sibling", etc. are
clearly inappropriate for debugfs.
> The "tst_*" programs are purely for regression testing. Having this
> functionality built into a proper tool like debugfs is needed.
Agreed. That being siad, Girish's patch doesn't apply against the
latest e2fsprogs git repository. It uses ext2fs_read_ext_block(), and
one of the reasons why I objected to Clusterfs's extent support in
e2fsprogs is that it exposed the low-level extent format to userspace
(and meant that the swapfs.c also needed extreme intimate knowledge of
the extent tree format), and that's a bad idea if we ever want to
change the extent format in the future. So the extents abstraction in
the latest e2fsprogs git tree does not have ext2fs_read_ext_block().
So to properly add the desired features to debugfs would require
taking some of the code from tst_extents (really, lib/ext2fs/extents.c
in the #ifdef DEBUG section), and moving it into debugfs.
I doubt we would want to move all of the tst_extents functionality
into debugfs, though. Probably just enough to dump the extent tree
and the set_bmap functionality --- and the latter should be done by
extending debugfs.c:do_bmap() so that it can take an optional 3rd
argument which utilizes ext2fs_bmap() to set a logical block mapping;
that way do_bmap() will work with normal and extent-based files, since
ext2fs_bmap/ext2fs_bmap2 have been wired to use Eric's
ext2fs_extent_set_bmap() function automatically for extents-based
files.
Regards,
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-06-12 13:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-11 10:11 [PATCH] e2fsprogs: Dump extent/sindices using debugfs Girish Shilamkar
2008-06-11 10:43 ` Aneesh Kumar K.V
2008-06-12 8:32 ` Andreas Dilger
2008-06-12 13:46 ` Theodore Tso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).