]> git.proxmox.com Git - mirror_zfs.git/commitdiff
libzutil: don't read extraneous data in zpool_read_label
authorAlan Somers <asomers@FreeBSD.org>
Wed, 13 Jan 2021 16:30:48 +0000 (09:30 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 21 Jan 2021 19:18:32 +0000 (11:18 -0800)
zpool_read_label doesn't need the full labels including uberblocks.  It
only needs the vdev_phys_t.  This reduces by half the amount of data
read to check for a label, speeding up "zpool import", "zpool
labelclear", etc.

Originally committed as
https://cgit.freebsd.org/src/commit/?id=63f8025d6acab1b334373ddd33f940a69b3b54cc

Obtained from: FreeBSD
Sponsored by: Spectra Logic Corp, Axcient
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alek Pinchuk <apinchuk@axcient.com>
Signed-off-by: Alan Somers <asomers@gmail.com>
Closes #11467

lib/libzutil/zutil_import.c

index 3a1827294502e533b1c26e6422cec4bc4fdd483a..bf914d37c8b2280ffe7b91399ecc402b46d03806 100644 (file)
@@ -888,7 +888,7 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
 {
        struct stat64 statbuf;
        int l, count = 0;
-       vdev_label_t *label;
+       vdev_phys_t *label;
        nvlist_t *expected_config = NULL;
        uint64_t expected_guid = 0, size;
        int error;
@@ -905,13 +905,14 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
 
        for (l = 0; l < VDEV_LABELS; l++) {
                uint64_t state, guid, txg;
+               off_t offset = label_offset(size, l) + VDEV_SKIP_SIZE;
 
-               if (pread64(fd, label, sizeof (vdev_label_t),
-                   label_offset(size, l)) != sizeof (vdev_label_t))
+               if (pread64(fd, label, sizeof (vdev_phys_t),
+                   offset) != sizeof (vdev_phys_t))
                        continue;
 
-               if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
-                   sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0)
+               if (nvlist_unpack(label->vp_nvlist,
+                   sizeof (label->vp_nvlist), config, 0) != 0)
                        continue;
 
                if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_GUID,