libmultipath: turn pp->vpd_data into a pointer
authorBenjamin Marzinski <bmarzins@redhat.com>
Wed, 19 Feb 2020 20:21:42 +0000 (14:21 -0600)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Mon, 2 Mar 2020 09:57:53 +0000 (10:57 +0100)
Instead of always allocating space in the path structure for vpd_data,
only allocte it when necessary.

Also, fix comments on vpd tests

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
libmultipath/discovery.c
libmultipath/print.c
libmultipath/structs.c
libmultipath/structs.h
tests/vpd.c

index 8e7f8fe..99c1a0f 100644 (file)
@@ -1629,8 +1629,21 @@ scsi_ioctl_pathinfo (struct path * pp, int mask)
        select_vpd_vendor_id(pp);
        vpd_id = pp->vpd_vendor_id;
 
-       if (vpd_id != VPD_VP_UNDEF && get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id, pp->vpd_data, sizeof(pp->vpd_data)) < 0)
-               condlog(3, "%s: failed to get extra vpd data", pp->dev);
+       if (vpd_id != VPD_VP_UNDEF) {
+               char vpd_data[VPD_DATA_SIZE] = {0};
+
+               if (get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id,
+                   vpd_data, sizeof(vpd_data)) < 0)
+                       condlog(3, "%s: failed to get extra vpd data", pp->dev);
+               else {
+                       vpd_data[VPD_DATA_SIZE - 1] = '\0';
+                       if (pp->vpd_data)
+                               free(pp->vpd_data);
+                       pp->vpd_data = strdup(vpd_data);
+                       if (!pp->vpd_data)
+                               condlog(0, "%s: failed to allocate space for vpd data", pp->dev);
+               }
+       }
 
        parent = pp->udev;
        while (parent) {
index 8d26c7e..77f732c 100644 (file)
@@ -370,7 +370,7 @@ snprint_multipath_vpd_data(char * buff, size_t len,
 
        vector_foreach_slot(mpp->pg, pgp, i)
                vector_foreach_slot(pgp->paths, pp, j)
-                       if (strlen(pp->vpd_data))
+                       if (pp->vpd_data)
                                return snprintf(buff, len, "%s", pp->vpd_data);
        return snprintf(buff, len, "[undef]");
 }
@@ -709,7 +709,7 @@ snprint_path_marginal(char * buff, size_t len, const struct path * pp)
 static int
 snprint_path_vpd_data(char * buff, size_t len, const struct path * pp)
 {
-       if (strlen(pp->vpd_data) > 0)
+       if (pp->vpd_data)
                return snprintf(buff, len, "%s", pp->vpd_data);
        return snprintf(buff, len, "[undef]");
 }
index f420ee5..85d1443 100644 (file)
@@ -131,6 +131,9 @@ free_path (struct path * pp)
                udev_device_unref(pp->udev);
                pp->udev = NULL;
        }
+       if (pp->vpd_data)
+               free(pp->vpd_data);
+
        vector_free(pp->hwe);
 
        FREE(pp);
index 5cf7f5b..58af7a0 100644 (file)
@@ -268,7 +268,7 @@ struct path {
        char rev[PATH_REV_SIZE];
        char serial[SERIAL_SIZE];
        char tgt_node_name[NODE_NAME_SIZE];
-       char vpd_data[VPD_DATA_SIZE];
+       char *vpd_data;
        unsigned long long size;
        unsigned int checkint;
        unsigned int tick;
index 0331c48..3cbad81 100644 (file)
@@ -520,8 +520,9 @@ static void test_vpd_eui_ ## len ## _ ## wlen ## _ ## sml(void **state)     \
        n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id,       \
                         2, 0, len);                                    \
        if (sml) {                                                      \
-               /* overwrite the page side to DEFAULT_SGIO_LEN + 1 */   \
+               /* overwrite the page size to DEFAULT_SGIO_LEN + 1 */   \
                put_unaligned_be16(255, vt->vpdbuf + 2);                \
+               /* this causes get_vpd_sgio to do a second ioctl */     \
                will_return(__wrap_ioctl, n);                           \
                will_return(__wrap_ioctl, vt->vpdbuf);                  \
        }                                                               \