From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] filefrag: count optimize non-verbose mode; count 0 extents properly when verbose
Date: Tue, 23 Nov 2010 17:21:42 -0600 [thread overview]
Message-ID: <4CEC4C86.1030806@redhat.com> (raw)
# rm -f a; touch a; filefrag -v a
yields 1 extent when it should be 0. Without -v, 0 is returned.
Fix this up by special-casing no extents returned in verbose
mode; skip printing the header for the columns too, since there
are no columns to print.
Also, in nonverbose mode we can set fm_extent_count to 0
so that FIEMAP will just query the extent count without gathering
details; as it is today I think a non-verbose query may under-report
the extent count once "count" extents have been filled in.
Addresses-redhat-bugzilla: 653234
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/misc/filefrag.c b/misc/filefrag.c
index bd4486d..a48b9b0 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -194,7 +194,14 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
do {
fiemap->fm_length = ~0ULL;
fiemap->fm_flags = flags;
- fiemap->fm_extent_count = count;
+ /*
+ * If fm_extent_count == 0, FIEMAP returns count of
+ * extents found without filling in details.
+ */
+ if (!verbose)
+ fiemap->fm_extent_count = 0;
+ else
+ fiemap->fm_extent_count = count;
rc = ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap);
if (rc < 0) {
if (errno == EBADR && fiemap_incompat_printed == 0) {
@@ -206,6 +213,14 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
}
if (verbose && !fiemap_header_printed) {
+ /*
+ * No extents on first call?
+ * Skip header and show 0 extents.
+ */
+ if (fiemap->fm_mapped_extents == 0) {
+ *num_extents = 0;
+ goto out;
+ }
printf(" ext %*s %*s %*s length flags\n", logical_width,
"logical", physical_width, "physical",
physical_width, "expected");
next reply other threads:[~2010-11-23 23:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-23 23:21 Eric Sandeen [this message]
2010-12-09 17:19 ` [PATCH] filefrag: count optimize non-verbose mode; count 0 extents properly when verbose Eric Sandeen
2011-03-11 15:01 ` Eric Sandeen
2011-04-08 16:44 ` Eric Sandeen
2011-04-08 23:40 ` Andreas Dilger
2011-05-05 18:21 ` [PATCH V2] filefrag: " Eric Sandeen
2011-05-07 22:45 ` Ted Ts'o
2011-05-08 3:35 ` Andreas Dilger
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=4CEC4C86.1030806@redhat.com \
--to=sandeen@redhat.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).