Blame SOURCES/0009-libmultipath-add-code-to-get-vendor-specific-vpd-dat.patch

8444ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8444ee
From: Benjamin Marzinski <bmarzins@redhat.com>
8444ee
Date: Mon, 4 Nov 2019 15:38:25 -0600
8444ee
Subject: [PATCH] libmultipath: add code to get vendor specific vpd data
8444ee
8444ee
This adds the wildcard 'g' for multipath and path formatted printing,
8444ee
which returns extra data from a device's vendor specific vpd page.  The
8444ee
specific vendor vpd page to use, and the vendor/product id to decode it
8444ee
can be set in the hwentry with vpd_vendor_pg and vpd_vendor_id. It can
8444ee
be configured in the devices section of multipath.conf with the
8444ee
vpd_vendor parameter. Currently, the only devices that use this are HPE
8444ee
3PAR arrays, to return the Volume Name.
8444ee
8444ee
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
8444ee
---
8444ee
 libmultipath/config.c      |  4 ++++
8444ee
 libmultipath/config.h      |  2 ++
8444ee
 libmultipath/dict.c        | 34 ++++++++++++++++++++++++++++++++++
8444ee
 libmultipath/discovery.c   | 34 +++++++++++++++++++++++++++++++++-
8444ee
 libmultipath/hwtable.c     |  2 ++
8444ee
 libmultipath/print.c       | 27 +++++++++++++++++++++++++++
8444ee
 libmultipath/propsel.c     | 24 ++++++++++++++++++++++++
8444ee
 libmultipath/propsel.h     |  2 ++
8444ee
 libmultipath/structs.h     |  9 +++++++++
8444ee
 multipath/multipath.conf.5 |  8 ++++++++
8444ee
 10 files changed, 145 insertions(+), 1 deletion(-)
8444ee
8444ee
diff --git a/libmultipath/config.c b/libmultipath/config.c
8444ee
index 85626e96..72b8d37c 100644
8444ee
--- a/libmultipath/config.c
8444ee
+++ b/libmultipath/config.c
8444ee
@@ -369,6 +369,8 @@ merge_hwe (struct hwentry * dst, struct hwentry * src)
8444ee
 	merge_num(max_sectors_kb);
8444ee
 	merge_num(ghost_delay);
8444ee
 	merge_num(all_tg_pt);
8444ee
+	merge_num(vpd_vendor_pg);
8444ee
+	merge_num(vpd_vendor_id);
8444ee
 	merge_num(san_path_err_threshold);
8444ee
 	merge_num(san_path_err_forget_rate);
8444ee
 	merge_num(san_path_err_recovery_time);
8444ee
@@ -517,6 +519,8 @@ store_hwe (vector hwtable, struct hwentry * dhwe)
8444ee
 	hwe->detect_prio = dhwe->detect_prio;
8444ee
 	hwe->detect_checker = dhwe->detect_checker;
8444ee
 	hwe->ghost_delay = dhwe->ghost_delay;
8444ee
+	hwe->vpd_vendor_pg = dhwe->vpd_vendor_pg;
8444ee
+	hwe->vpd_vendor_id = dhwe->vpd_vendor_id;
8444ee
 
8444ee
 	if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
8444ee
 		goto out;
8444ee
diff --git a/libmultipath/config.h b/libmultipath/config.h
8444ee
index e69aa07c..589146de 100644
8444ee
--- a/libmultipath/config.h
8444ee
+++ b/libmultipath/config.h
8444ee
@@ -87,6 +87,8 @@ struct hwentry {
8444ee
 	int max_sectors_kb;
8444ee
 	int ghost_delay;
8444ee
 	int all_tg_pt;
8444ee
+	int vpd_vendor_pg;
8444ee
+	int vpd_vendor_id;
8444ee
 	char * bl_product;
8444ee
 };
8444ee
 
8444ee
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
8444ee
index 2b046e1d..d6d8b79b 100644
8444ee
--- a/libmultipath/dict.c
8444ee
+++ b/libmultipath/dict.c
8444ee
@@ -1366,6 +1366,39 @@ def_uxsock_timeout_handler(struct config *conf, vector strvec)
8444ee
 	return 0;
8444ee
 }
8444ee
 
8444ee
+static int
8444ee
+hw_vpd_vendor_handler(struct config *conf, vector strvec)
8444ee
+{
8444ee
+	int rc = 0;
8444ee
+	char *buff;
8444ee
+
8444ee
+	struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
8444ee
+	if (!hwe)
8444ee
+		return 1;
8444ee
+
8444ee
+	buff = set_value(strvec);
8444ee
+	if (!buff)
8444ee
+		return 1;
8444ee
+	if (strcmp(buff, "hp3par") == 0) {
8444ee
+		hwe->vpd_vendor_pg = 0xc0;
8444ee
+		hwe->vpd_vendor_id = VPD_VP_HP3PAR;
8444ee
+	} else
8444ee
+		rc = 1;
8444ee
+	FREE(buff);
8444ee
+	return rc;
8444ee
+}
8444ee
+
8444ee
+static int
8444ee
+snprint_hw_vpd_vendor(struct config *conf, char * buff, int len,
8444ee
+		      const void * data)
8444ee
+{
8444ee
+	const struct hwentry * hwe = (const struct hwentry *)data;
8444ee
+
8444ee
+	if (hwe->vpd_vendor_pg == 0xc0 && hwe->vpd_vendor_id == VPD_VP_HP3PAR)
8444ee
+		return snprintf(buff, len, "hp3par");
8444ee
+	return 0;
8444ee
+}
8444ee
+
8444ee
 /*
8444ee
  * blacklist block handlers
8444ee
  */
8444ee
@@ -1806,6 +1839,7 @@ init_keywords(vector keywords)
8444ee
 	install_keyword("max_sectors_kb", &hw_max_sectors_kb_handler, &snprint_hw_max_sectors_kb);
8444ee
 	install_keyword("ghost_delay", &hw_ghost_delay_handler, &snprint_hw_ghost_delay);
8444ee
 	install_keyword("all_tg_pt", &hw_all_tg_pt_handler, &snprint_hw_all_tg_pt);
8444ee
+	install_keyword("vpd_vendor", &hw_vpd_vendor_handler, &snprint_hw_vpd_vendor);
8444ee
 	install_sublevel_end();
8444ee
 
8444ee
 	install_keyword_root("overrides", &overrides_handler);
8444ee
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
8444ee
index 1d79cbae..d2773c3a 100644
8444ee
--- a/libmultipath/discovery.c
8444ee
+++ b/libmultipath/discovery.c
8444ee
@@ -1103,6 +1103,30 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
8444ee
 	return len;
8444ee
 }
8444ee
 
8444ee
+static int
8444ee
+parse_vpd_c0_hp3par(const unsigned char *in, size_t in_len,
8444ee
+		    char *out, size_t out_len)
8444ee
+{
8444ee
+	size_t len;
8444ee
+
8444ee
+	memset(out, 0x0, out_len);
8444ee
+	if (in_len <= 4 || (in[4] > 3 && in_len < 44)) {
8444ee
+		condlog(3, "HP/3PAR vendor specific VPD page length too short: %lu", in_len);
8444ee
+		return -EINVAL;
8444ee
+	}
8444ee
+	if (in[4] <= 3) /* revision must be > 3 to have Vomlume Name */
8444ee
+		return -ENODATA;
8444ee
+	len = get_unaligned_be32(&in[40]);
8444ee
+	if (len > out_len || len + 44 > in_len) {
8444ee
+		condlog(3, "HP/3PAR vendor specific Volume name too long: %lu",
8444ee
+			len);
8444ee
+		return -EINVAL;
8444ee
+	}
8444ee
+	memcpy(out, &in[44], len);
8444ee
+	out[out_len - 1] = '\0';
8444ee
+	return len;
8444ee
+}
8444ee
+
8444ee
 static int
8444ee
 get_vpd_sysfs (struct udev_device *parent, int pg, char * str, int maxlen)
8444ee
 {
8444ee
@@ -1170,7 +1194,9 @@ get_vpd_sgio (int fd, int pg, int vend_id, char * str, int maxlen)
8444ee
 			len = (buff_len <= maxlen)? buff_len : maxlen;
8444ee
 			memcpy (str, buff, len);
8444ee
 		}
8444ee
-	} else
8444ee
+	} else if (pg == 0xc0 && vend_id == VPD_VP_HP3PAR)
8444ee
+		len = parse_vpd_c0_hp3par(buff, buff_len, str, maxlen);
8444ee
+	else
8444ee
 		len = -ENOSYS;
8444ee
 
8444ee
 	return len;
8444ee
@@ -1544,6 +1570,12 @@ scsi_ioctl_pathinfo (struct path * pp, struct config *conf, int mask)
8444ee
 	if (!(mask & DI_SERIAL))
8444ee
 		return;
8444ee
 
8444ee
+	select_vpd_vendor_pg(conf, pp);
8444ee
+	select_vpd_vendor_id(conf, pp);
8444ee
+
8444ee
+	if (pp->vpd_vendor_pg != 0 && get_vpd_sgio(pp->fd, pp->vpd_vendor_pg, pp->vpd_vendor_id, pp->vpd_data, sizeof(pp->vpd_data)) < 0)
8444ee
+		condlog(3, "%s: failed to get extra vpd data", pp->dev);
8444ee
+
8444ee
 	parent = pp->udev;
8444ee
 	while (parent) {
8444ee
 		const char *subsys = udev_device_get_subsystem(parent);
8444ee
diff --git a/libmultipath/hwtable.c b/libmultipath/hwtable.c
8444ee
index 16627ec5..1f27450c 100644
8444ee
--- a/libmultipath/hwtable.c
8444ee
+++ b/libmultipath/hwtable.c
8444ee
@@ -117,6 +117,8 @@ static struct hwentry default_hw[] = {
8444ee
 		.no_path_retry = 18,
8444ee
 		.fast_io_fail  = 10,
8444ee
 		.dev_loss      = MAX_DEV_LOSS_TMO,
8444ee
+		.vpd_vendor_pg = 0xc0,
8444ee
+		.vpd_vendor_id = VPD_VP_HP3PAR,
8444ee
 	},
8444ee
 	{
8444ee
 		/* RA8000 / ESA12000 */
8444ee
diff --git a/libmultipath/print.c b/libmultipath/print.c
8444ee
index 907469ad..0aafe3cb 100644
8444ee
--- a/libmultipath/print.c
8444ee
+++ b/libmultipath/print.c
8444ee
@@ -358,6 +358,23 @@ snprint_action (char * buff, size_t len, const struct multipath * mpp)
8444ee
 	}
8444ee
 }
8444ee
 
8444ee
+static int
8444ee
+snprint_multipath_vpd_data(char * buff, size_t len,
8444ee
+			   const struct multipath * mpp)
8444ee
+{
8444ee
+	struct pathgroup * pgp;
8444ee
+	struct path * pp;
8444ee
+	int i, j;
8444ee
+
8444ee
+	vector_foreach_slot(mpp->pg, pgp, i) {
8444ee
+		vector_foreach_slot(pgp->paths, pp, j) {
8444ee
+			if (strlen(pp->vpd_data))
8444ee
+				return snprintf(buff, len, "%s", pp->vpd_data);
8444ee
+		}
8444ee
+	}
8444ee
+	return 0;
8444ee
+}
8444ee
+
8444ee
 /*
8444ee
  * path info printing functions
8444ee
  */
8444ee
@@ -688,6 +705,14 @@ snprint_path_marginal(char * buff, size_t len, const struct path * pp)
8444ee
 	return snprintf(buff, len, "normal");
8444ee
 }
8444ee
 
8444ee
+static int
8444ee
+snprint_path_vpd_data(char * buff, size_t len, const struct path * pp)
8444ee
+{
8444ee
+	if (strlen(pp->vpd_data) > 0)
8444ee
+		return snprintf(buff, len, "%s", pp->vpd_data);
8444ee
+	return 0;
8444ee
+}
8444ee
+
8444ee
 struct multipath_data mpd[] = {
8444ee
 	{'n', "name",          0, snprint_name},
8444ee
 	{'w', "uuid",          0, snprint_multipath_uuid},
8444ee
@@ -712,6 +737,7 @@ struct multipath_data mpd[] = {
8444ee
 	{'p', "prod",          0, snprint_multipath_prod},
8444ee
 	{'e', "rev",           0, snprint_multipath_rev},
8444ee
 	{'G', "foreign",       0, snprint_multipath_foreign},
8444ee
+	{'g', "vpd page data", 0, snprint_multipath_vpd_data},
8444ee
 	{0, NULL, 0 , NULL}
8444ee
 };
8444ee
 
8444ee
@@ -737,6 +763,7 @@ struct path_data pd[] = {
8444ee
 	{'r', "target WWPN",   0, snprint_tgt_wwpn},
8444ee
 	{'a', "host adapter",  0, snprint_host_adapter},
8444ee
 	{'G', "foreign",       0, snprint_path_foreign},
8444ee
+	{'g', "vpd page data", 0, snprint_path_vpd_data},
8444ee
 	{'0', "failures",      0, snprint_path_failures},
8444ee
 	{'P', "protocol",      0, snprint_path_protocol},
8444ee
 	{0, NULL, 0 , NULL}
8444ee
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
8444ee
index b5b5b89f..3c99f2d4 100644
8444ee
--- a/libmultipath/propsel.c
8444ee
+++ b/libmultipath/propsel.c
8444ee
@@ -1203,3 +1203,27 @@ out:
8444ee
 		origin);
8444ee
 	return 0;
8444ee
 }
8444ee
+
8444ee
+int select_vpd_vendor_pg (struct config *conf, struct path *pp)
8444ee
+{
8444ee
+	const char *origin;
8444ee
+
8444ee
+	pp_set_hwe(vpd_vendor_pg);
8444ee
+	pp_set_default(vpd_vendor_pg, 0);
8444ee
+out:
8444ee
+	condlog(3, "%s: vpd_vendor_pg = 0x%x %s", pp->dev, pp->vpd_vendor_pg,
8444ee
+		origin);
8444ee
+	return 0;
8444ee
+}
8444ee
+
8444ee
+int select_vpd_vendor_id (struct config *conf, struct path *pp)
8444ee
+{
8444ee
+	const char *origin;
8444ee
+
8444ee
+	pp_set_hwe(vpd_vendor_id);
8444ee
+	pp_set_default(vpd_vendor_id, 0);
8444ee
+out:
8444ee
+	condlog(3, "%s: vpd_vendor_id = 0x%x %s", pp->dev, pp->vpd_vendor_id,
8444ee
+		origin);
8444ee
+	return 0;
8444ee
+}
8444ee
diff --git a/libmultipath/propsel.h b/libmultipath/propsel.h
8444ee
index ddfd6262..3f6d319a 100644
8444ee
--- a/libmultipath/propsel.h
8444ee
+++ b/libmultipath/propsel.h
8444ee
@@ -37,3 +37,5 @@ void reconcile_features_with_options(const char *id, char **features,
8444ee
 				     int* no_path_retry,
8444ee
 				     int *retain_hwhandler);
8444ee
 int select_all_tg_pt (struct config *conf, struct multipath * mp);
8444ee
+int select_vpd_vendor_pg (struct config *conf, struct path *pp);
8444ee
+int select_vpd_vendor_id (struct config *conf, struct path *pp);
8444ee
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
8444ee
index 1c32a799..1ad5f64a 100644
8444ee
--- a/libmultipath/structs.h
8444ee
+++ b/libmultipath/structs.h
8444ee
@@ -21,6 +21,7 @@
8444ee
 #define HOST_NAME_LEN		16
8444ee
 #define SLOT_NAME_SIZE		40
8444ee
 #define PRKEY_SIZE		19
8444ee
+#define VPD_DATA_SIZE		128
8444ee
 
8444ee
 #define SCSI_VENDOR_SIZE	9
8444ee
 #define SCSI_PRODUCT_SIZE	17
8444ee
@@ -243,6 +244,11 @@ struct hd_geometry {
8444ee
 };
8444ee
 #endif
8444ee
 
8444ee
+/*
8444ee
+ * from sg_vpd_vendor.c
8444ee
+ */
8444ee
+#define VPD_VP_HP3PAR 4
8444ee
+
8444ee
 struct path {
8444ee
 	char dev[FILE_NAME_SIZE];
8444ee
 	char dev_t[BLK_DEV_SIZE];
8444ee
@@ -255,6 +261,7 @@ struct path {
8444ee
 	char rev[PATH_REV_SIZE];
8444ee
 	char serial[SERIAL_SIZE];
8444ee
 	char tgt_node_name[NODE_NAME_SIZE];
8444ee
+	char vpd_data[VPD_DATA_SIZE];
8444ee
 	unsigned long long size;
8444ee
 	unsigned int checkint;
8444ee
 	unsigned int tick;
8444ee
@@ -287,6 +294,8 @@ struct path {
8444ee
 	int io_err_pathfail_starttime;
8444ee
 	int find_multipaths_timeout;
8444ee
 	int marginal;
8444ee
+	int vpd_vendor_pg;
8444ee
+	int vpd_vendor_id;
8444ee
 	/* configlet pointers */
8444ee
 	vector hwe;
8444ee
 	struct gen_path generic_path;
8444ee
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
8444ee
index e866da23..dc103fd8 100644
8444ee
--- a/multipath/multipath.conf.5
8444ee
+++ b/multipath/multipath.conf.5
8444ee
@@ -1472,6 +1472,14 @@ the \fIproduct\fR attribute set to the value of \fIproduct_blacklist\fR.
8444ee
 The user_friendly_names prefix to use for this
8444ee
 device type, instead of the default "mpath".
8444ee
 .TP
8444ee
+.B vpd_vendor
8444ee
+The vendor specific vpd page information, using the vpd page abbreviation.
8444ee
+The vpd page abbreviation can be found by running \fIsg_vpd -e\fR. multipathd
8444ee
+will use this information to gather device specific information that can be
8444ee
+displayed with the \fI%g\fR wilcard for the \fImultipathd show maps format\fR
8444ee
+and \fImultipathd show paths format\fR commands. Currently only the
8444ee
+\fBhp3par\fR vpd page is supported.
8444ee
+.TP
8444ee
 .B hardware_handler
8444ee
 The hardware handler to use for this device type.
8444ee
 The following hardware handler are implemented:
8444ee
-- 
8444ee
2.17.2
8444ee