]> granicus.if.org Git - zfs/commitdiff
Fix segfault in zpool iostat when adding VDEVs
authorTony Hutter <hutter2@llnl.gov>
Wed, 6 Dec 2017 19:43:07 +0000 (11:43 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 6 Dec 2017 19:43:07 +0000 (11:43 -0800)
Fix a segfault when running 'zpool iostat -v 1' while adding
a VDEV.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #6748
Closes #6872

cmd/zpool/zpool_main.c

index 440b2979960e85666a005c0cb8546cd7b99603e7..a44167a386f6d63761285ec70451137bda03a142 100644 (file)
@@ -3648,7 +3648,7 @@ print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
     nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
 {
        nvlist_t **oldchild, **newchild;
-       uint_t c, children;
+       uint_t c, children, oldchildren;
        vdev_stat_t *oldvs, *newvs, *calcvs;
        vdev_stat_t zerovs = { 0 };
        char *vname;
@@ -3760,9 +3760,13 @@ children:
            &newchild, &children) != 0)
                return (ret);
 
-       if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
-           &oldchild, &c) != 0)
-               return (ret);
+       if (oldnv) {
+               if (nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
+                   &oldchild, &oldchildren) != 0)
+                       return (ret);
+
+               children = MIN(oldchildren, children);
+       }
 
        for (c = 0; c < children; c++) {
                uint64_t ishole = B_FALSE, islog = B_FALSE;
@@ -3818,9 +3822,13 @@ children:
            &newchild, &children) != 0)
                return (ret);
 
-       if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
-           &oldchild, &c) != 0)
-               return (ret);
+       if (oldnv) {
+               if (nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
+                   &oldchild, &oldchildren) != 0)
+                       return (ret);
+
+               children = MIN(oldchildren, children);
+       }
 
        if (children > 0) {
                if ((!(cb->cb_flags & IOS_ANYHISTO_M)) && !cb->cb_scripted &&