]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: don't count fsmaps before querying fsmaps
authorDarrick J. Wong <djwong@kernel.org>
Wed, 28 Jul 2021 23:01:23 +0000 (19:01 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 28 Jul 2021 23:01:23 +0000 (19:01 -0400)
There's a bunch of code in fsmap.c that tries to count the GETFSMAP
records so that it can size the fsmap array appropriately for the
GETFSMAP call.  It's pointless to iterate the entire result set /twice/
(unlike the bmap command where the extent count is actually stored in
the fs metadata), so get rid of the duplicate walk.

In other words: Iterate over the records using the default chunk size
instead of doing one call to find the size and doing a giant allocation
and GETFSMAP call.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/fsmap.c

index 9f179fa808a2b0a4301c98ae1c0c0ed942c09f4c..f540a7c04409c0ba3a91f7631d88df1aee5842d7 100644 (file)
@@ -372,13 +372,11 @@ fsmap_f(
        char                    **argv)
 {
        struct fsmap            *p;
-       struct fsmap_head       *nhead;
        struct fsmap_head       *head;
        struct fsmap            *l, *h;
        struct xfs_fsop_geom    fsgeo;
        long long               start = 0;
        long long               end = -1;
-       int                     nmap_size;
        int                     map_size;
        int                     nflag = 0;
        int                     vflag = 0;
@@ -492,34 +490,6 @@ fsmap_f(
        h->fmr_flags = UINT_MAX;
        h->fmr_offset = ULLONG_MAX;
 
-       /* Count mappings */
-       if (!nflag) {
-               head->fmh_count = 0;
-               i = ioctl(file->fd, FS_IOC_GETFSMAP, head);
-               if (i < 0) {
-                       fprintf(stderr, _("%s: xfsctl(XFS_IOC_GETFSMAP)"
-                               " iflags=0x%x [\"%s\"]: %s\n"),
-                               progname, head->fmh_iflags, file->name,
-                               strerror(errno));
-                       exitcode = 1;
-                       free(head);
-                       return 0;
-               }
-               if (head->fmh_entries > map_size + 2) {
-                       map_size = 11ULL * head->fmh_entries / 10;
-                       nmap_size = map_size > (1 << 24) ? (1 << 24) : map_size;
-                       nhead = realloc(head, fsmap_sizeof(nmap_size));
-                       if (nhead == NULL) {
-                               fprintf(stderr,
-                                       _("%s: cannot realloc %zu bytes\n"),
-                                       progname, fsmap_sizeof(nmap_size));
-                       } else {
-                               head = nhead;
-                               map_size = nmap_size;
-                       }
-               }
-       }
-
        /*
         * If this is an XFS filesystem, remember the data device.
         * (We report AG number/block for data device extents on XFS).