linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-xfs@vger.kernel.org
Cc: sandeen@redhat.com, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 6/6] fiemap: Fix semantics of max_extents (-n arguments)
Date: Thu, 24 Aug 2017 14:47:52 +0300	[thread overview]
Message-ID: <1503575272-28263-7-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1503575272-28263-1-git-send-email-nborisov@suse.com>

Currently the semantics of the -n argument are a bit idiosyncratic. We want the
argument to be the limit of extents that are going to be output by the tool. This
is clearly broken now as evident from the following example on a fragmented file:

xfs_io -c "fiemap -v -n 5" test-dir/fragmented-file
test-dir/fragmented-file:
 EXT: FILE-OFFSET      BLOCK-RANGE          TOTAL FLAGS
   0: [0..15]:         hole                    16
   1: [16..23]:        897847296..897847303     8   0x0
   2: [24..31]:        hole                     8
   3: [32..39]:        897851392..897851399     8   0x0

So we want at most 5 extents printed, yet we get 4. So we always print n - 1
extents.

With this modification the output looks like:

xfs_io -c "fiemap -v -n 5" test-dir/fragmented-file
test-dir/fragmented-file:
 EXT: FILE-OFFSET      BLOCK-RANGE          TOTAL FLAGS
   0: [0..15]:         hole                    16
   1: [16..23]:        897847296..897847303     8   0x0
   2: [24..31]:        hole                     8
   3: [32..39]:        897851392..897851399     8   0x0
   4: [40..47]:        hole                     8

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 io/fiemap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/io/fiemap.c b/io/fiemap.c
index 44a64870d711..7b275275465d 100644
--- a/io/fiemap.c
+++ b/io/fiemap.c
@@ -122,7 +122,7 @@ print_verbose(
 		cur_extent++;
 	}
 
-	if ((cur_extent + 1) == max_extents)
+	if (cur_extent == max_extents)
 		return 1;
 
 	snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", lstart,
@@ -157,7 +157,7 @@ print_plain(
 		cur_extent++;
 	}
 
-	if ((cur_extent + 1) == max_extents)
+	if (cur_extent == max_extents)
 		return 1;
 
 	printf("\t%d: [%llu..%llu]: %llu..%llu", cur_extent,
@@ -264,7 +264,7 @@ fiemap_f(
 
 	printf("%s:\n", file->name);
 
-	while (!last && ((cur_extent + 1) != max_extents)) {
+	while (!last && (cur_extent != max_extents)) {
 
 		memset(fiemap, 0, map_size);
 		fiemap->fm_flags = fiemap_flags;
@@ -314,12 +314,12 @@ fiemap_f(
 				break;
 			}
 
-			if ((cur_extent + 1) == max_extents)
+			if (cur_extent == max_extents)
 				break;
 		}
 	}
 
-	if ((cur_extent + 1) == max_extents)
+	if (cur_extent  == max_extents)
 		goto out;
 
 	memset(&st, 0, sizeof(st));
-- 
2.7.4


  parent reply	other threads:[~2017-08-24 11:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 11:47 [PATCH 0/6] Fiemap refactoring Nikolay Borisov
2017-08-24 11:47 ` [PATCH 1/6] fiemap: Remove blocksize variable Nikolay Borisov
2017-08-24 11:47 ` [PATCH 2/6] fiemap: Make max_extents a global var Nikolay Borisov
2017-08-24 11:47 ` [PATCH 3/6] fiemap: Eliminate num_extents Nikolay Borisov
2017-08-24 11:47 ` [PATCH 4/6] fiemap: De-obfuscate last_logical and cur_extent manipulation Nikolay Borisov
2017-08-24 11:47 ` [PATCH 5/6] fiemap: Factor out common code used for printing holes Nikolay Borisov
2017-08-24 11:47 ` Nikolay Borisov [this message]
2017-08-24 16:03   ` [PATCH 6/6] fiemap: Fix semantics of max_extents (-n arguments) Eric Sandeen
2017-08-24 16:06     ` Nikolay Borisov
2017-08-24 16:07       ` Eric Sandeen
2017-08-24 17:51   ` Darrick J. Wong
2017-08-24 18:43     ` Eric Sandeen
2017-08-24 20:09 ` [PATCH 7/6] xfs_bmap: fix -n documentation in manpage Eric Sandeen
2017-08-24 20:56   ` Darrick J. Wong

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=1503575272-28263-7-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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).