fiemap: Allow to specify range to fiemap
PATCH 1/1 fiemap: Allow to specify range to fiemap
Add 2 additional, optional, arguments to the embedded fiemap command, that way one can specify exact ranges to be fiemapped. This will be used for a btrfs test. Since the arguments are optional, omitting them just retains the old behavior.
--- io/fiemap.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
io/fiemap.c +32 -2
@@ -216,7 +216,11 @@ fiemap_f(int flg_w =5 ;__u64 blocksize =512 ;__u64 last_logical =0 ; +__u64 len =-1LL ;struct stat st; +size_t fsblocksize, fssectsize; + +init_cvtnum (&fsblocksize, &fssectsize);while ((c =getopt (argc, argv,"aln:v" )) !=EOF ) {switch (c) {
@@ -237,6 +241,32 @@ fiemap_f( } } +if (argc == optind +2 ) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (start_offset <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + last_logical =strtoull (argv[optind],NULL ,10 ); + + optind++; + +off64_t length =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (length <0 ) { +printf ("non-numeric len argument -- %s\n" , argv[optind]); +return 0 ; + } + len = length; + }else if (argc == optind +1 ) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (last_logical <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + } +if (max_extents) num_extents =min (num_extents, max_extents); map_size = sizeof(struct fiemap) +
@@ -259,7 +289,7 @@ fiemap_f(memset (fiemap,0 , map_size); fiemap->fm_flags = fiemap_flags; fiemap->fm_start = last_logical; - fiemap->fm_length =-1LL ; + fiemap->fm_length = len; fiemap->fm_extent_count = num_extents; ret =ioctl (file->fd,FS_IOC_FIEMAP , (unsigned long )fiemap);
@@ -350,7 +380,7 @@ fiemap_init(void) fiemap_cmd.argmin =0 ; fiemap_cmd.argmax =-1 ; fiemap_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - fiemap_cmd.args =_ ("[-alv] [-n nx]" ); + fiemap_cmd.args =_ ("[-alv] [-n nx] [start offset] [len]" ); fiemap_cmd.oneline =_ ("print block mapping for a file" ); fiemap_cmd.help = fiemap_help;
Signature · 1 line
2.7.4
io/fiemap.c
Quoted 14 lines · Nikolay Borisov
Add 2 additional, optional, arguments to the embedded fiemap command, that way one can specify exact ranges to be fiemapped. This will be used for a btrfs test. Since the arguments are optional, omitting them just retains the old behavior.
Signed-off-by Nikolay Borisov <[email protected]>--- io/fiemap.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)io/fiemap.c +0
-0
Need to update the fiemap_help() text.
And a man page update.
io/fiemap.c fiemap_f( · line 221
Quoted 7 lines
io/fiemap.c +2
-0@@ -216,7 +216,11 @@ fiemap_f(int flg_w =5 ;__u64 blocksize =512 ;__u64 last_logical =0 ; +__u64 len =-1LL ;struct stat st; +size_t fsblocksize, fssectsize;
^
Whitespace damage.
Quoted 7 lines
io/fiemap.c +2
-0+ +init_cvtnum (&fsblocksize, &fssectsize);while ((c =getopt (argc, argv,"aln:v" )) !=EOF ) {switch (c) {@@ -237,6 +241,32 @@ fiemap_f( }
io/fiemap.c fiemap_f( · line 251
Quoted 10 lines
io/fiemap.c +8
-0} +if (argc == optind +2 ) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (start_offset <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + last_logical =strtoull (argv[optind],NULL ,10 );
Ah, what?
Quoted 7 lines
io/fiemap.c +7
-0+ + optind++; + +off64_t length =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (length <0 ) { +printf ("non-numeric len argument -- %s\n" , argv[optind]); +return 0 ;
io/fiemap.c fiemap_f( · line 268
Quoted 10 lines
io/fiemap.c +10
-0+ } + len = length; + }else if (argc == optind +1 ) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (last_logical <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + }
Duplicate code to get start offset.
if (optind < argc) {
/* get start offset */
...
optind++
}
if (optind < argc) {
/* get length */
.....
}Cheers,
Dave.
Quoted 14 lines
io/fiemap.c +2
-1+if (max_extents) num_extents =min (num_extents, max_extents); map_size = sizeof(struct fiemap) +@@ -259,7 +289,7 @@ fiemap_f(memset (fiemap,0 , map_size); fiemap->fm_flags = fiemap_flags; fiemap->fm_start = last_logical; - fiemap->fm_length =-1LL ; + fiemap->fm_length = len; fiemap->fm_extent_count = num_extents; ret =ioctl (file->fd,FS_IOC_FIEMAP , (unsigned long )fiemap);
io/fiemap.c fiemap_init(void) · line 383
Quoted 5 lines
io/fiemap.c +1
-1@@ -350,7 +380,7 @@ fiemap_init(void) fiemap_cmd.argmin =0 ; fiemap_cmd.argmax =-1 ; fiemap_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - fiemap_cmd.args =_ ("[-alv] [-n nx]" ); + fiemap_cmd.args =_ ("[-alv] [-n nx] [start offset] [len]" );
Given that it's {offset, len} or just {offset}, you can't have length by itself as a parameter. i.e.
fiemap_cmd.args = _("[-alv] [-n nx] [start offset [len]]");Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v2 1/1 fiemap: Allow to specify range to fiemap
Add 2 additional, optional, arguments to the embedded fiemap command, that way one can specify exact ranges to be fiemapped. This will be used for a btrfs test. Since the arguments are optional, omitting them just retains the old behavior.
---
Changes since v1:
* Added help in man describing the new options
* Removed whitespace damage
* Simplified/dedup the code used to get the parameters in
* Updated one line help to indicate that len param can't exist on its own
io/fiemap.c | 28 ++++++++++++++++++++++++++-- man/man8/xfs_io.8 | 5 +++-- 2 files changed, 29 insertions(+), 4 deletions(-)
io/fiemap.c +26 -2
@@ -34,6 +34,7 @@ fiemap_help(void)"\n" " Example:\n" " 'fiemap -v' - tabular format verbose map\n" +" 'fiemap 0 4k' - print fiemap extents for 0-4k range\n" "\n" " fiemap prints the map of disk blocks used by the current file.\n" " The map lists each extent used by the file, as well as regions in the\n"
@@ -216,7 +217,11 @@ fiemap_f(int flg_w =5 ;__u64 blocksize =512 ;__u64 last_logical =0 ; +__u64 len =-1LL ;struct stat st; +size_t fsblocksize, fssectsize; + +init_cvtnum (&fsblocksize, &fssectsize);while ((c =getopt (argc, argv,"aln:v" )) !=EOF ) {switch (c) {
@@ -237,6 +242,25 @@ fiemap_f( } } +if (optind < argc) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (start_offset <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + optind++; + } + +if (optind < argc) { +off64_t length =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (length <0 ) { +printf ("non-numeric len argument -- %s\n" , argv[optind]); +return 0 ; + } + len = length; + } +if (max_extents) num_extents =min (num_extents, max_extents); map_size = sizeof(struct fiemap) +
@@ -259,7 +283,7 @@ fiemap_f(memset (fiemap,0 , map_size); fiemap->fm_flags = fiemap_flags; fiemap->fm_start = last_logical; - fiemap->fm_length =-1LL ; + fiemap->fm_length = len; fiemap->fm_extent_count = num_extents; ret =ioctl (file->fd,FS_IOC_FIEMAP , (unsigned long )fiemap);
@@ -350,7 +374,7 @@ fiemap_init(void) fiemap_cmd.argmin =0 ; fiemap_cmd.argmax =-1 ; fiemap_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - fiemap_cmd.args =_ ("[-alv] [-n nx]" ); + fiemap_cmd.args =_ ("[-alv] [-n nx] [start offset [len]]" ); fiemap_cmd.oneline =_ ("print block mapping for a file" ); fiemap_cmd.help = fiemap_help;
man/man8/xfs_io.8 +3 -2
@@ -295,11 +295,12 @@ Prints the block mapping for the current open file. Refer to the .BR xfs_bmap (8) manual page for complete documentation. .TP -.BI "fiemap [ \-alv ] [ \-n " nx " ]" +.BI "fiemap [ \-alv ] [ \-n " nx " ] [ " offset " [ " len " ]]" Prints the block mapping for the current open file using the fiemap ioctl. Options behave as described in the .BR xfs_bmap (8) -manual page. +manual page. Optionally, this command also supports passing the start offset +from where to begin the fiemap and the length of that region. .TP .BI "fsmap [ \-d | \-l | \-r ] [ \-m | \-v ] [ \-n " nx " ] [ " start " ] [ " end " ] Prints the mapping of disk blocks used by the filesystem hosting the current
Signature · 1 line
2.7.4
Quoted 69 lines · Nikolay Borisov
Add 2 additional, optional, arguments to the embedded fiemap command, that way one can specify exact ranges to be fiemapped. This will be used for a btrfs test. Since the arguments are optional, omitting them just retains the old behavior.
Signed-off-by Nikolay Borisov <[email protected]>---
Changes since v1:
* Added help in man describing the new options
* Removed whitespace damage
* Simplified/dedup the code used to get the parameters in
* Updated one line help to indicate that len param can't exist on its ownio/fiemap.c | 28 ++++++++++++++++++++++++++-- man/man8/xfs_io.8 | 5 +++-- 2 files changed, 29 insertions(+), 4 deletions(-)io/fiemap.c +24
-0@@ -34,6 +34,7 @@ fiemap_help(void)"\n" " Example:\n" " 'fiemap -v' - tabular format verbose map\n" +" 'fiemap 0 4k' - print fiemap extents for 0-4k range\n" "\n" " fiemap prints the map of disk blocks used by the current file.\n" " The map lists each extent used by the file, as well as regions in the\n" @@ -216,7 +217,11 @@ fiemap_f(int flg_w =5 ;__u64 blocksize =512 ;__u64 last_logical =0 ; +__u64 len =-1LL ;struct stat st; +size_t fsblocksize, fssectsize; + +init_cvtnum (&fsblocksize, &fssectsize);while ((c =getopt (argc, argv,"aln:v" )) !=EOF ) {switch (c) {@@ -237,6 +242,25 @@ fiemap_f( } } +if (optind < argc) { +off64_t start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (start_offset <0 ) { +printf ("non-numeric offset argument -- %s\n" , argv[optind]); +return 0 ; + } + last_logical = start_offset; + optind++; + } + +if (optind < argc) { +off64_t length =cvtnum (fsblocksize, fssectsize, argv[optind]); +if (length <0 ) { +printf ("non-numeric len argument -- %s\n" , argv[optind]); +return 0 ; + } + len = length; + } +if (max_extents) num_extents =min (num_extents, max_extents); map_size = sizeof(struct fiemap) +
io/fiemap.c fiemap_f( · line 286
Quoted 5 lines
io/fiemap.c +1
-1@@ -259,7 +283,7 @@ fiemap_f(memset (fiemap,0 , map_size); fiemap->fm_flags = fiemap_flags; fiemap->fm_start = last_logical; - fiemap->fm_length =-1LL ; + fiemap->fm_length = len;
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
--D
Quoted 38 lines
io/fiemap.c +1
-1fiemap->fm_extent_count = num_extents; ret =ioctl (file->fd,FS_IOC_FIEMAP , (unsigned long )fiemap);@@ -350,7 +374,7 @@ fiemap_init(void) fiemap_cmd.argmin =0 ; fiemap_cmd.argmax =-1 ; fiemap_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - fiemap_cmd.args =_ ("[-alv] [-n nx]" ); + fiemap_cmd.args =_ ("[-alv] [-n nx] [start offset [len]]" ); fiemap_cmd.oneline =_ ("print block mapping for a file" ); fiemap_cmd.help = fiemap_help;man/man8/xfs_io.8 +3
-2@@ -295,11 +295,12 @@ Prints the block mapping for the current open file. Refer to the .BR xfs_bmap (8) manual page for complete documentation. .TP -.BI "fiemap [ \-alv ] [ \-n " nx " ]" +.BI "fiemap [ \-alv ] [ \-n " nx " ] [ " offset " [ " len " ]]" Prints the block mapping for the current open file using the fiemap ioctl. Options behave as described in the .BR xfs_bmap (8) -manual page. +manual page. Optionally, this command also supports passing the start offset +from where to begin the fiemap and the length of that region. .TP .BI "fsmap [ \-d | \-l | \-r ] [ \-m | \-v ] [ \-n " nx " ] [ " start " ] [ " end " ] Prints the mapping of disk blocks used by the filesystem hosting the currentSignature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Darrick J. Wong
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
Hm, you are right, I believe on every iteration we should do:
len -= last_logical - start_offset
Quoted 9 lines · Nikolay Borisov
Quoted 2 lines · Darrick J. Wong
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
Hm, you are right, I believe on every iteration we should do:
len -=
last_logical-start_offset
start_offset doesn't change, right?
I would think len -= last_logical - fiemap->fm_start.
Or just calculate end_offset = start_offset + length and set fiemap->fm_length = end_offset - last_logical...
...though now that I look at that file even closer I wonder what is going on with that outer while loop counting extents? Does -n exist to let users cap the number of records to print, even if that means we don't make it to the end of the range requested?
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Darrick J. Wong
Quoted 9 lines · Nikolay Borisov
Quoted 2 lines · Darrick J. Wong
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
Hm, you are right, I believe on every iteration we should do:
len -=
last_logical-start_offset
start_offsetdoesn't change, right?I would think len -=
last_logical-fiemap->fm_start.
Quoted 7 lines
Or just calculate
end_offset=start_offset+ length and setfiemap->fm_length=end_offset-last_logical......though now that I look at that file even closer I wonder what is going on with that outer while loop counting extents? Does -n exist to let users cap the number of records to print, even if that means we don't make it to the end of the range requested?
-n should simply be the size of each fiemap request, i.e. how many to request and fill on each iteration. It should not affect how many get printed in the end.
At least that's how xfs_bmap is supposed to work, and therefore in theory how xfs_io's fiemap should work.
-Eric
Quoted 24 lines · Eric Sandeen
Quoted 15 lines · Darrick J. Wong
Quoted 9 lines · Nikolay Borisov
Quoted 2 lines · Darrick J. Wong
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
Hm, you are right, I believe on every iteration we should do:
len -=
last_logical-start_offset
start_offsetdoesn't change, right?I would think len -=
last_logical-fiemap->fm_start.Quoted 7 lines
Or just calculate
end_offset=start_offset+ length and setfiemap->fm_length=end_offset-last_logical......though now that I look at that file even closer I wonder what is going on with that outer while loop counting extents? Does -n exist to let users cap the number of records to print, even if that means we don't make it to the end of the range requested?
Quoted 6 lines
-n should simply be the size of each fiemap request, i.e. how many to request and fill on each iteration. It should not affect how many get printed in the end.
At least that's how
xfs_bmapis supposed to work, and therefore in theory how xfs_io's fiemap should work.
... except apparently that is not actually how it works :(
-Eric
Quoted 25 lines · Eric Sandeen
Quoted 24 lines · Eric Sandeen
Quoted 22 lines · Darrick J. Wong
Quoted 9 lines · Nikolay Borisov
Quoted 2 lines · Darrick J. Wong
We don't decrement len each time through the ioctl loop? Doesn't that cause us to request and retrieve rows for ranges we don't want?
Hm, you are right, I believe on every iteration we should do:
len -=
last_logical-start_offset
start_offsetdoesn't change, right?I would think len -=
last_logical-fiemap->fm_start.Or just calculate
end_offset=start_offset+ length and setfiemap->fm_length=end_offset-last_logical......though now that I look at that file even closer I wonder what is going on with that outer while loop counting extents? Does -n exist to let users cap the number of records to print, even if that means we don't make it to the end of the range requested?
Quoted 8 lines
Quoted 6 lines
-n should simply be the size of each fiemap request, i.e. how many to request and fill on each iteration. It should not affect how many get printed in the end.
At least that's how
xfs_bmapis supposed to work, and therefore in theory how xfs_io's fiemap should work.... except apparently that is not actually how it works :(
In my tests passing -n 1 doesn't print anything irrespective of whether I use the newly added args, it was strange. It's supposed to define the batch of extents to query at a time. However, that's definitely not what it's doing... Also the man pages states that if -n is not passed fiemap would query the number of extents required and use that, however the code currently just uses the default of 32 extents ...
Quoted 3 lines
-Eric