Skip to contentSkip to conversation

multipath-tools: FCP addressing display support (for s390x)

PATCH Superseded Steffen Maier 3 participants 6 messages Feb 10, 2022 Device mapper

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover multipath-tools: FCP addressing display support (for s390x)

It is quicker and easier than writing some script to correlate multipath output with other query tooling for FCP addressing.

Steffen Maier (2):
libmultipath: support host adapter name lookup for s390x ccw bus
libmultipath: add %L path wildcard for 64-bit hex LUN

 libmultipath/discovery.c | 41 +++++++++++++++++++++++++++++++++++++++-
 libmultipath/discovery.h |  1 +
 libmultipath/print.c     | 20 ++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

base-commit: d9d7ae9e2125116b465b4ff4d98ce65fe0eac3cc

Signature · 6 lines
2.27.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 1/2 libmultipath: support host adapter name lookup for s390x ccw bus

There are also (FCP) HBAs that appear on a bus different from PCI.

Complements v0.6.0 commit
01ab2a468ea2 ("libmultipath: Add additional path wildcards").

With that we can easily get the full FCP addressing triplet (HBA, WWPN, LUN) from multipath tools without additional tools and correlation:

$ multipathd -k'show paths format "%w|%i|%a|%r"'
uuid                             |hcil       |host adapter|target WWPN
36005076400820293e8000000000000a0|1:0:3:160  |0.0.5080    |0x500507680b25c449
36005076400820293e8000000000000a0|1:0:4:160  |0.0.5080    |0x500507680b25c448
36005076400820293e8000000000000a0|58:0:3:160 |0.0.50c0    |0x500507680b26c449
36005076400820293e8000000000000a0|58:0:4:160 |0.0.50c0    |0x500507680b26c448

^^^^^^^^
instead of [undef]

As a side effect this patch theoretically also enables group by host adapter for s390x based on v0.6.0 commit a28e61e5cc9a ("Crafted ordering of child paths for round robin path selector").

---
 libmultipath/discovery.c | 41 +++++++++++++++++++++++++++++++++++++++-
 libmultipath/discovery.h |  1 +
 2 files changed, 41 insertions(+), 1 deletion(-)
libmultipath/discovery.c +40 -1
index 7d939ae08004..bb4913d9b75f 100644
@@ -497,8 +497,12 @@ int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
 		return sysfs_get_iscsi_ip_address(pp, adapter_name);
 
 	/* fetch adapter pci name for other protocols
+	 * or try to get s390x channel subsystem FCP device bus-ID [zfcp]
 	 */
-	return sysfs_get_host_pci_name(pp, adapter_name);
+	if (sysfs_get_host_pci_name(pp, adapter_name))
+		return sysfs_get_host_ccw_name(pp, adapter_name);
+	else
+		return 0;
 }
 
 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
@@ -545,6 +549,41 @@ int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
 	return 1;
 }
 
+int sysfs_get_host_ccw_name(const struct path *pp, char *ccw_name)
+{
+	struct udev_device *hostdev, *parent;
+	char host_name[HOST_NAME_LEN];
+	const char *value;
+
+	if (!pp || !ccw_name)
+		return 1;
+
+	sprintf(host_name, "host%d", pp->sg_id.host_no);
+	hostdev = udev_device_new_from_subsystem_sysname(udev,
+			"scsi_host", host_name);
+	if (!hostdev)
+		return 1;
+
+	parent = udev_device_get_parent_with_subsystem_devtype(hostdev, "ccw",
+							       NULL);
+	if (parent) {
+		/* s390x ccw FCP device found
+		 */
+		value = udev_device_get_sysname(parent);
+
+		if (!value) {
+			udev_device_unref(hostdev);
+			return 1;
+		}
+
+		strncpy(ccw_name, value, SLOT_NAME_SIZE);
+		udev_device_unref(hostdev);
+		return 0;
+	}
+	udev_device_unref(hostdev);
+	return 1;
+}
+
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address)
 {
 	struct udev_device *hostdev;
libmultipath/discovery.h +1 -0
index 095657bb9de4..0a58c725d700 100644
@@ -44,6 +44,7 @@ int store_pathinfo (vector pathvec, struct config *conf,
 		    struct path **pp_ptr);
 int sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint);
 int sysfs_get_timeout(const struct path *pp, unsigned int *timeout);
+int sysfs_get_host_ccw_name(const struct path *pp, char *ccw_name);
 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name);
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address);
 int sysfs_get_host_adapter_name(const struct path *pp,

base-commit: d9d7ae9e2125116b465b4ff4d98ce65fe0eac3cc

Signature · 6 lines
2.27.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#2 lore raw

Re: [dm-devel] [PATCH 1/2] libmultipath: support host adapter name lookup for s390x ccw bus

Quoted 16 lines · Steffen Maier

There are also (FCP) HBAs that appear on a bus different from PCI.

Complements v0.6.0 commit
01ab2a468ea2 ("libmultipath: Add additional path wildcards").

With that we can easily get the full FCP addressing triplet (HBA, WWPN, LUN) from multipath tools without additional tools and correlation:

$ multipathd -k'show paths format "%w|%i|%a|%r"'
uuid                             |hcil       |host adapter|target WWPN
36005076400820293e8000000000000a0|1:0:3:160  |0.0.5080    |0x500507680b25c449
36005076400820293e8000000000000a0|1:0:4:160  |0.0.5080    |0x500507680b25c448
36005076400820293e8000000000000a0|58:0:3:160 |0.0.50c0    |0x500507680b26c449
36005076400820293e8000000000000a0|58:0:4:160 |0.0.50c0    |0x500507680b26c448
Quoted 6 lines

^^^^^^^^
instead of [undef]

As a side effect this patch theoretically also enables group by host adapter for s390x based on v0.6.0 commit a28e61e5cc9a ("Crafted ordering of child paths for round robin path selector").

This looks good in general, but I have some minor issues.

Quoted 26 lines
---
 libmultipath/discovery.c | 41 +++++++++++++++++++++++++++++++++++++++-
 libmultipath/discovery.h |  1 +
 2 files changed, 41 insertions(+), 1 deletion(-)
libmultipath/discovery.c +5 -1
index 7d939ae08004..bb4913d9b75f 100644
@@ -497,8 +497,12 @@ int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
 		return sysfs_get_iscsi_ip_address(pp, adapter_name);
 
 	/* fetch adapter pci name for other protocols
+	 * or try to get s390x channel subsystem FCP device bus-ID [zfcp]
 	 */
-	return sysfs_get_host_pci_name(pp, adapter_name);
+	if (sysfs_get_host_pci_name(pp, adapter_name))
+		return sysfs_get_host_ccw_name(pp, adapter_name);
+	else
+		return 0;
 }
 
 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)

libmultipath/discovery.c int sysfs_get_host_pci_name(const struct path *pp, char *pci_name) · line 551

Quoted 3 lines
libmultipath/discovery.c +0 -0
@@ -545,6 +549,41 @@ int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
 	return 1;
 }
 

I realize that sysfs_get_host_pci_name() isn't a global function, but there's no good reason for that, since nothing calls it outside of discovery.c. sysfs_get_host_ccw_name() should be static.

libmultipath/discovery.c int sysfs_get_host_pci_name(const struct path *pp, char *pci_name) · line 553

Quoted 2 lines
libmultipath/discovery.c +2 -0
+int sysfs_get_host_ccw_name(const struct path *pp, char *ccw_name)
+{

This looks very much like sysfs_get_host_pci_name(). The only difference is in grabbing the correct sysfs parent. It seems like they could be combined into one function that first attempts to grab the pci device, and failing that, grabs the ccw device.

Unless, or course, there is a good reason why we might want to call these functions outside of sysfs_get_host_adapter_name() that I'm missing. If so, you can ignore all this.

Thanks
-Ben

Quoted 49 lines
libmultipath/discovery.c +33 -0
+	struct udev_device *hostdev, *parent;
+	char host_name[HOST_NAME_LEN];
+	const char *value;
+
+	if (!pp || !ccw_name)
+		return 1;
+
+	sprintf(host_name, "host%d", pp->sg_id.host_no);
+	hostdev = udev_device_new_from_subsystem_sysname(udev,
+			"scsi_host", host_name);
+	if (!hostdev)
+		return 1;
+
+	parent = udev_device_get_parent_with_subsystem_devtype(hostdev, "ccw",
+							       NULL);
+	if (parent) {
+		/* s390x ccw FCP device found
+		 */
+		value = udev_device_get_sysname(parent);
+
+		if (!value) {
+			udev_device_unref(hostdev);
+			return 1;
+		}
+
+		strncpy(ccw_name, value, SLOT_NAME_SIZE);
+		udev_device_unref(hostdev);
+		return 0;
+	}
+	udev_device_unref(hostdev);
+	return 1;
+}
+
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address)
 {
 	struct udev_device *hostdev;
libmultipath/discovery.h +1 -0
index 095657bb9de4..0a58c725d700 100644
@@ -44,6 +44,7 @@ int store_pathinfo (vector pathvec, struct config *conf,
 		    struct path **pp_ptr);
 int sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint);
 int sysfs_get_timeout(const struct path *pp, unsigned int *timeout);
+int sysfs_get_host_ccw_name(const struct path *pp, char *ccw_name);
 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name);
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address);
 int sysfs_get_host_adapter_name(const struct path *pp,
Quoted 3 lines

base-commit: d9d7ae9e2125116b465b4ff4d98ce65fe0eac3cc

Signature · 1 line
2.27.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#3 lore raw

PATCH 2/2 libmultipath: add %L path wildcard for 64-bit hex LUN

In reply to Steffen Maier

Complements v0.6.0 commit
01ab2a468ea2 ("libmultipath: Add additional path wildcards") as well as ("libmultipath: support host adapter name lookup for s390x ccw bus").

With that we can easily get the full FCP addressing triplet (HBA, WWPN, FCPLUN) from multipath tools without additional tools and correlation:

$ multipathd -k'show paths format "%w|%a|%r|%L"'
uuid                             |host adapter|target WWPN       |LUN hex
36005076400820293e8000000000000a0|0.0.5080    |0x500507680b25c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.5080    |0x500507680b25c448|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0    |0x500507680b26c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0    |0x500507680b26c448|0x00a0000000000000

Likewise, add a field lun_hex for JSON path output.

---
 libmultipath/print.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
libmultipath/print.c +20 -0
index 221b515f23d3..4f6146e85fc9 100644
@@ -96,6 +96,7 @@
 			     "            \"host_wwpn\" : \"%R\",\n" \
 			     "            \"target_wwpn\" : \"%r\",\n" \
 			     "            \"host_adapter\" : \"%a\",\n" \
+			     "            \"lun_hex\" : \"%L\",\n" \
 			     "            \"marginal_st\" : \"%M\""
 
 #define PROGRESS_LEN  10
@@ -451,6 +452,24 @@ snprint_hcil (struct strbuf *buff, const struct path * pp)
 			pp->sg_id.lun);
 }
 
+
+static int
+snprint_path_lunhex (struct strbuf *buff, const struct path * pp)
+{
+	uint64_t lunhex = SCSI_INVALID_LUN, scsilun;
+
+	if (!pp || pp->sg_id.host_no < 0)
+		return print_strbuf(buff, "0x%016" PRIx64, lunhex);
+
+	scsilun = pp->sg_id.lun;
+	/* cf. Linux kernel function int_to_scsilun() */
+	lunhex = ((scsilun & 0x000000000000ffffULL) << 48) |
+		((scsilun & 0x00000000ffff0000ULL) << 16) |
+		((scsilun & 0x0000ffff00000000ULL) >> 16) |
+		((scsilun & 0xffff000000000000ULL) >> 48);
+	return print_strbuf(buff, "0x%016" PRIx64, lunhex);
+}
+
 static int
 snprint_dev (struct strbuf *buff, const struct path * pp)
 {
@@ -842,6 +861,7 @@ static const struct path_data pd[] = {
 	{'0', "failures",      snprint_path_failures},
 	{'P', "protocol",      snprint_path_protocol},
 	{'I', "init_st",       snprint_initialized},
+	{'L', "LUN hex",       snprint_path_lunhex},
 };
 
 static const struct pathgroup_data pgd[] = {
Signature · 6 lines
2.27.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [dm-devel] [PATCH 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN

Quoted 8 lines · Steffen Maier

Complements v0.6.0 commit
01ab2a468ea2 ("libmultipath: Add additional path wildcards") as well as ("libmultipath: support host adapter name lookup for s390x ccw bus").

With that we can easily get the full FCP addressing triplet (HBA, WWPN, FCPLUN) from multipath tools without additional tools and correlation:

Quoted 9 lines
$ multipathd -k'show paths format "%w|%a|%r|%L"'
uuid                             |host adapter|target WWPN       |LUN hex
36005076400820293e8000000000000a0|0.0.5080    |0x500507680b25c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.5080    |0x500507680b25c448|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0    |0x500507680b26c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0    |0x500507680b26c448|0x00a0000000000000

Likewise, add a field lun_hex for JSON path output.

Quoted 53 lines
---
 libmultipath/print.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
libmultipath/print.c +20 -0
index 221b515f23d3..4f6146e85fc9 100644
@@ -96,6 +96,7 @@
 			     "            \"host_wwpn\" : \"%R\",\n" \
 			     "            \"target_wwpn\" : \"%r\",\n" \
 			     "            \"host_adapter\" : \"%a\",\n" \
+			     "            \"lun_hex\" : \"%L\",\n" \
 			     "            \"marginal_st\" : \"%M\""
 
 #define PROGRESS_LEN  10
@@ -451,6 +452,24 @@ snprint_hcil (struct strbuf *buff, const struct path * pp)
 			pp->sg_id.lun);
 }
 
+
+static int
+snprint_path_lunhex (struct strbuf *buff, const struct path * pp)
+{
+	uint64_t lunhex = SCSI_INVALID_LUN, scsilun;
+
+	if (!pp || pp->sg_id.host_no < 0)
+		return print_strbuf(buff, "0x%016" PRIx64, lunhex);
+
+	scsilun = pp->sg_id.lun;
+	/* cf. Linux kernel function int_to_scsilun() */
+	lunhex = ((scsilun & 0x000000000000ffffULL) << 48) |
+		((scsilun & 0x00000000ffff0000ULL) << 16) |
+		((scsilun & 0x0000ffff00000000ULL) >> 16) |
+		((scsilun & 0xffff000000000000ULL) >> 48);
+	return print_strbuf(buff, "0x%016" PRIx64, lunhex);
+}
+
 static int
 snprint_dev (struct strbuf *buff, const struct path * pp)
 {
@@ -842,6 +861,7 @@ static const struct path_data pd[] = {
 	{'0', "failures",      snprint_path_failures},
 	{'P', "protocol",      snprint_path_protocol},
 	{'I', "init_st",       snprint_initialized},
+	{'L', "LUN hex",       snprint_path_lunhex},
 };
 
 static const struct pathgroup_data pgd[] = {
Signature · 1 line
2.27.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reviewed-by
#5 lore raw

Re: [dm-devel] [PATCH 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN

Quoted 23 lines · Benjamin Marzinski
Quoted 22 lines · Steffen Maier

Complements v0.6.0 commit
01ab2a468ea2 ("libmultipath: Add additional path wildcards") as well as
("libmultipath: support host adapter name lookup for s390x ccw bus").

With that we can easily get the full FCP addressing triplet (HBA, WWPN, FCPLUN) from multipath tools without additional tools and correlation:

$ multipathd -k'show paths format "%w|%a|%r|%L"'
uuid                             |host adapter|target WWPN      
|LUN hex
36005076400820293e8000000000000a0|0.0.5080   
|0x500507680b25c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.5080   
|0x500507680b25c448|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0   
|0x500507680b26c449|0x00a0000000000000
36005076400820293e8000000000000a0|0.0.50c0   
|0x500507680b26c448|0x00a0000000000000
Quoted 3 lines
Quoted 2 lines

Likewise, add a field lun_hex for JSON path output.

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel