linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Curt Wohlgemuth <curtw@google.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] Print extent information in debugfs
Date: Thu, 23 Jul 2009 13:36:29 -0700	[thread overview]
Message-ID: <6601abe90907231336o64cdc786r634d29be822316af@mail.gmail.com> (raw)

Building on the email that Ricky Benitez sent out earlier this month ("Tool
to view extent metadata"), I really wanted to look at the extent descriptors
while working on the O_DIRECT/fallocate/page cache issue, so I created this
patch to debugfs; it adds to the 'stat' command, and only for extent-based
files.

The output pretty much mirrors the BLOCKS output; it shows each extent
simply as a range of logical blocks to the file, plus "[uninit]" if this bit
is set.

Here's some sample output from the 'stat' command for a ~100MB file (that's
been fallocate'd and written):

===========================================================
...
atime: 0x4a679eb7 -- Wed Jul 22 16:20:23 2009
mtime: 0x4a68b71f -- Thu Jul 23 12:16:47 2009
Extents (logical blocks):
(0-25599), (25600-30719 [uninit]), (30720-61439 [uninit]),
(61440-63487 [uninit]), (63488-94207 [uninit]), (94208-96255
[uninit]), (96256-124927 [uninit]), (124928-131071 [uninit])
BLOCKS:
(IND):133120, (0-63487):34816-98303, (63488-96255):100352-133119,
(96256-124927):135168-163839, (124928-131071):165888-172031
TOTAL: 131073
===========================================================

Does this seem reasonable?  Generally useful?

	Signed-off-by: Curt Wohlgemuth <curtw@google.com>

---
--- debugfs/debugfs.c.orig	2009-06-30 20:41:09.000000000 -0700
+++ debugfs/debugfs.c	2009-07-23 13:15:32.000000000 -0700
@@ -552,6 +552,45 @@
 }


+static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino)
+{
+	ext2_extent_handle_t	handle;
+	struct ext2fs_extent	extent;
+	int			op = EXT2_EXTENT_ROOT;
+	unsigned int		printed = 0;
+	errcode_t 		errcode;
+
+	errcode = ext2fs_extent_open(current_fs, ino, &handle);
+	if (errcode)
+		return;
+
+	fprintf(f, "%sExtents (logical blocks):\n%s", prefix, prefix);
+
+	while (1) {
+		errcode = ext2fs_extent_get(handle, op, &extent);
+
+		if (errcode)
+			break;
+
+		op = EXT2_EXTENT_NEXT;
+
+		if (!(extent.e_flags & EXT2_EXTENT_FLAGS_LEAF))
+			continue;
+
+		fprintf(f,
+			"%s(%lld-%lld%s)",
+			printed ? ", " : "",
+			extent.e_lblk,
+			extent.e_lblk + (extent.e_len - 1),
+			extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
+			         " [uninit]" : "");
+		printed = 1;
+	}
+	if (printed)
+		fprintf(f, "\n");
+}
+
+
 void internal_dump_inode(FILE *out, const char *prefix,
 			 ext2_ino_t inode_num, struct ext2_inode *inode,
 			 int do_dump_blocks)
@@ -649,6 +688,11 @@
 	if (inode->i_dtime)
 	  fprintf(out, "%sdtime: 0x%08x -- %s", prefix, inode->i_dtime,
 		  time_to_string(inode->i_dtime));
+
+	if (inode->i_flags & EXT4_EXTENTS_FL) {
+		dump_extents(out, prefix, inode_num);
+	}
+
 	if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
 		internal_dump_inode_extra(out, prefix, inode_num,
 					  (struct ext2_inode_large *) inode);

             reply	other threads:[~2009-07-23 20:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-23 20:36 Curt Wohlgemuth [this message]
2009-07-27  3:02 ` [PATCH] Print extent information in debugfs Theodore Tso
2009-07-27  3:18   ` Eric Sandeen
2009-07-27 14:34     ` Theodore Tso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6601abe90907231336o64cdc786r634d29be822316af@mail.gmail.com \
    --to=curtw@google.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).