From: Nikolay Borisov <nborisov@suse.com>
To: sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 3/4] fiemap: Simplify internals of fiemap_f.
Date: Wed, 23 Aug 2017 18:11:21 +0300 [thread overview]
Message-ID: <1503501082-16983-3-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1503501082-16983-1-git-send-email-nborisov@suse.com>
So far fiemap used some rather convoluted logic to terminate the iteration and
calculate the number of extents to pass to fm_extent_count. Simplify this by:
* Get the whole number of extents that this file has and keep iterating until
we've printed all extents
* Always use a hard-coded batch of 32 extents so we don't have to worry about
any extra calculations
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
io/fiemap.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/io/fiemap.c b/io/fiemap.c
index 30c49112e089..ef54b265ab91 100644
--- a/io/fiemap.c
+++ b/io/fiemap.c
@@ -23,6 +23,8 @@
#include "init.h"
#include "io.h"
+#define EXTENT_BATCH 32
+
static cmdinfo_t fiemap_cmd;
static const __u64 blocksize = 512;
static int max_extents = 0;
@@ -95,7 +97,7 @@ print_verbose(
memset(lbuf, 0, sizeof(lbuf));
}
- if ((*cur_extent + 1) == max_extents)
+ if (*cur_extent == max_extents)
return;
snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", lstart,
@@ -137,7 +139,7 @@ print_plain(
(*cur_extent)++;
}
- if ((*cur_extent + 1) == max_extents)
+ if (*cur_extent == max_extents)
return;
printf("\t%d: [%llu..%llu]: %llu..%llu", *cur_extent,
@@ -215,7 +217,7 @@ fiemap_f(
char **argv)
{
struct fiemap *fiemap;
- int num_extents = 32;
+ int num_extents;
int last = 0;
int lflag = 0;
int vflag = 0;
@@ -251,10 +253,15 @@ fiemap_f(
}
}
- if (max_extents)
- num_extents = min(num_extents, max_extents);
+ ret = get_extent_count(file->fd, last_logical, -1);
+ if (ret < 0) {
+ exitcode = 1;
+ return 0;
+ }
+ num_extents = ret;
+
map_size = sizeof(struct fiemap) +
- (num_extents * sizeof(struct fiemap_extent));
+ (EXTENT_BATCH * sizeof(struct fiemap_extent));
fiemap = malloc(map_size);
if (!fiemap) {
fprintf(stderr, _("%s: malloc of %d bytes failed.\n"),
@@ -265,16 +272,14 @@ fiemap_f(
printf("%s:\n", file->name);
- while (!last && ((cur_extent + 1) != max_extents)) {
- if (max_extents)
- num_extents = min(num_extents,
- max_extents - (cur_extent + 1));
+ while (!last && num_extents) {
+ /* Query a batch worth of extents */
memset(fiemap, 0, map_size);
fiemap->fm_flags = fiemap_flags;
fiemap->fm_start = last_logical;
fiemap->fm_length = -1LL;
- fiemap->fm_extent_count = num_extents;
+ fiemap->fm_extent_count = EXTENT_BATCH;
ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
if (ret < 0) {
@@ -307,17 +312,17 @@ fiemap_f(
print_plain(extent, lflag, blocksize,
&cur_extent, &last_logical);
- if (extent->fe_flags & FIEMAP_EXTENT_LAST) {
+ if (extent->fe_flags & FIEMAP_EXTENT_LAST ||
+ cur_extent == max_extents) {
last = 1;
break;
}
-
- if ((cur_extent + 1) == max_extents)
- break;
}
+
+ num_extents -= fiemap->fm_mapped_extents;
}
- if ((cur_extent + 1) == max_extents)
+ if (cur_extent == max_extents)
goto out;
memset(&st, 0, sizeof(st));
--
2.7.4
next prev parent reply other threads:[~2017-08-23 15:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-11 11:55 [PATCH] fiemap: Refactor fiemap + implement range parameters Nikolay Borisov
2017-08-22 6:41 ` Nikolay Borisov
2017-08-22 19:11 ` Eric Sandeen
2017-08-23 8:07 ` Nikolay Borisov
2017-08-23 15:11 ` [PATCH 1/4] fiemap: Move global variables out of function scope Nikolay Borisov
2017-08-23 15:11 ` [PATCH 2/4] fiemap: Introduce get_extent_count Nikolay Borisov
2017-08-23 17:05 ` Darrick J. Wong
2017-08-23 15:11 ` Nikolay Borisov [this message]
2017-08-23 15:51 ` [PATCH 3/4] fiemap: Simplify internals of fiemap_f Eric Sandeen
2017-08-23 17:17 ` Eric Sandeen
2017-08-23 15:11 ` [PATCH 4/4] fiemap: Add support for ranged query Nikolay Borisov
2017-08-23 19:12 ` Eric Sandeen
2017-08-23 15:49 ` [PATCH 1/4] fiemap: Move global variables out of function scope Eric Sandeen
2017-08-23 22:36 ` Eric Sandeen
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=1503501082-16983-3-git-send-email-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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