All of lore.kernel.org
 help / color / mirror / Atom feed
* [dm-devel] [PATCH v3 0/2] multipath-tools: FCP addressing display support (for s390x)
@ 2022-02-15 19:45 Steffen Maier
  2022-02-15 19:45 ` [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus Steffen Maier
  2022-02-15 19:45 ` [dm-devel] [PATCH v3 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN Steffen Maier
  0 siblings, 2 replies; 4+ messages in thread
From: Steffen Maier @ 2022-02-15 19:45 UTC (permalink / raw)
  To: dm-devel, Christophe Varoqui; +Cc: Steffen Maier, Martin Wilck

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

For patch set version ChangeLog, see indidivual patches.

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 | 79 ++++++++++++++++++++--------------------
 libmultipath/discovery.h |  1 -
 libmultipath/print.c     | 20 ++++++++++
 3 files changed, 59 insertions(+), 41 deletions(-)


base-commit: 70602364987e27739b5521d94d684993d877157a
-- 
2.27.0

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus
  2022-02-15 19:45 [dm-devel] [PATCH v3 0/2] multipath-tools: FCP addressing display support (for s390x) Steffen Maier
@ 2022-02-15 19:45 ` Steffen Maier
  2022-02-15 20:43   ` Martin Wilck
  2022-02-15 19:45 ` [dm-devel] [PATCH v3 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN Steffen Maier
  1 sibling, 1 reply; 4+ messages in thread
From: Steffen Maier @ 2022-02-15 19:45 UTC (permalink / raw)
  To: dm-devel, Christophe Varoqui; +Cc: Steffen Maier, Martin Wilck

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]

Make helper function static and generalize it to also cover CCW bus
in addition to the already supported PCI bus. Had to move now static
helper in front of its only user.
While at it, use string functions that are safe against buffer overflows.

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").

Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
---

Notes:
    Changes since v2:
    - ensure we don't accidentally skip a potential ccw fcp device with an
      early continue due to driver_name being NULL (Martin):
      replace early continue by guarded string comparisons
    - turn while into for loop reducing calls of udev_device_get_parent() (Martin)
    - use string functions that are safe against buffer overflows (Martin)
    
    Changes since v1:
    - Make sysfs_get_host_pci_name() static and generalize for adapters
      on different bus types, in order to reduce code duplication (Ben).
      The ancestor walk is always the same based on kernel driver core
      with the only difference that PCI matches against driver name
      whereas CCW matches against subsystem name.
      Unfortunately, the diffstat increased because I had to move the
      new static sysfs_get_host_bus_id() in front of its only user
      sysfs_get_host_adapter_name() [or else a strange upfront prototype
      would have been necessary].

 libmultipath/discovery.c | 79 ++++++++++++++++++++--------------------
 libmultipath/discovery.h |  1 -
 2 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 7d939ae08004..875c80429969 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -475,60 +475,33 @@ sysfs_get_tgt_nodename(struct path *pp, char *node)
 	return 0;
 }
 
-int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
-{
-	int proto_id;
-
-	if (!pp || !adapter_name)
-		return 1;
-
-	proto_id = pp->sg_id.proto_id;
-
-	if (proto_id != SCSI_PROTOCOL_FCP &&
-	    proto_id != SCSI_PROTOCOL_SAS &&
-	    proto_id != SCSI_PROTOCOL_ISCSI &&
-	    proto_id != SCSI_PROTOCOL_SRP) {
-		return 1;
-	}
-	/* iscsi doesn't have adapter info in sysfs
-	 * get ip_address for grouping paths
-	 */
-	if (pp->sg_id.proto_id == SCSI_PROTOCOL_ISCSI)
-		return sysfs_get_iscsi_ip_address(pp, adapter_name);
-
-	/* fetch adapter pci name for other protocols
-	 */
-	return sysfs_get_host_pci_name(pp, adapter_name);
-}
-
-int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
+static int sysfs_get_host_bus_id(const struct path *pp, char *bus_id)
 {
 	struct udev_device *hostdev, *parent;
 	char host_name[HOST_NAME_LEN];
-	const char *driver_name, *value;
+	const char *driver_name, *subsystem_name, *value;
 
-	if (!pp || !pci_name)
+	if (!pp || !bus_id)
 		return 1;
 
-	sprintf(host_name, "host%d", pp->sg_id.host_no);
+	snprintf(host_name, sizeof(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(hostdev);
-	while (parent) {
+	for (parent = udev_device_get_parent(hostdev);
+	     parent;
+	     parent = udev_device_get_parent(parent)) {
 		driver_name = udev_device_get_driver(parent);
-		if (!driver_name) {
-			parent = udev_device_get_parent(parent);
-			continue;
-		}
-		if (!strcmp(driver_name, "pcieport"))
+		subsystem_name = udev_device_get_subsystem(parent);
+		if (driver_name && !strcmp(driver_name, "pcieport"))
+			break;
+		if (subsystem_name && !strcmp(subsystem_name, "ccw"))
 			break;
-		parent = udev_device_get_parent(parent);
 	}
 	if (parent) {
-		/* pci_device found
+		/* pci_device or ccw fcp device found
 		 */
 		value = udev_device_get_sysname(parent);
 
@@ -537,7 +510,7 @@ int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
 			return 1;
 		}
 
-		strncpy(pci_name, value, SLOT_NAME_SIZE);
+		strlcpy(bus_id, value, SLOT_NAME_SIZE);
 		udev_device_unref(hostdev);
 		return 0;
 	}
@@ -545,6 +518,32 @@ int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
 	return 1;
 }
 
+int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
+{
+	int proto_id;
+
+	if (!pp || !adapter_name)
+		return 1;
+
+	proto_id = pp->sg_id.proto_id;
+
+	if (proto_id != SCSI_PROTOCOL_FCP &&
+	    proto_id != SCSI_PROTOCOL_SAS &&
+	    proto_id != SCSI_PROTOCOL_ISCSI &&
+	    proto_id != SCSI_PROTOCOL_SRP) {
+		return 1;
+	}
+	/* iscsi doesn't have adapter info in sysfs
+	 * get ip_address for grouping paths
+	 */
+	if (pp->sg_id.proto_id == SCSI_PROTOCOL_ISCSI)
+		return sysfs_get_iscsi_ip_address(pp, adapter_name);
+
+	/* fetch adapter bus-ID for other protocols
+	 */
+	return sysfs_get_host_bus_id(pp, adapter_name);
+}
+
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address)
 {
 	struct udev_device *hostdev;
diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
index 095657bb9de4..466af34504de 100644
--- a/libmultipath/discovery.h
+++ b/libmultipath/discovery.h
@@ -44,7 +44,6 @@ 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_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,
 				char *adapter_name);
-- 
2.27.0

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [dm-devel] [PATCH v3 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN
  2022-02-15 19:45 [dm-devel] [PATCH v3 0/2] multipath-tools: FCP addressing display support (for s390x) Steffen Maier
  2022-02-15 19:45 ` [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus Steffen Maier
@ 2022-02-15 19:45 ` Steffen Maier
  1 sibling, 0 replies; 4+ messages in thread
From: Steffen Maier @ 2022-02-15 19:45 UTC (permalink / raw)
  To: dm-devel, Christophe Varoqui; +Cc: Steffen Maier, Martin Wilck

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.

Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
---

Notes:
    Changes since v1:
    - added 2 Reviewed-by (Ben, Martin)

 libmultipath/print.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 221b515f23d3..4f6146e85fc9 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -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[] = {
-- 
2.27.0

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus
  2022-02-15 19:45 ` [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus Steffen Maier
@ 2022-02-15 20:43   ` Martin Wilck
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Wilck @ 2022-02-15 20:43 UTC (permalink / raw)
  To: dm-devel, maier, christophe.varoqui

On Tue, 2022-02-15 at 20:45 +0100, Steffen Maier wrote:
> 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]
> 
> Make helper function static and generalize it to also cover CCW bus
> in addition to the already supported PCI bus. Had to move now static
> helper in front of its only user.
> While at it, use string functions that are safe against buffer
> overflows.
> 
> 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").
> 
> Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
> Signed-off-by: Steffen Maier <maier@linux.ibm.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-15 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 19:45 [dm-devel] [PATCH v3 0/2] multipath-tools: FCP addressing display support (for s390x) Steffen Maier
2022-02-15 19:45 ` [dm-devel] [PATCH v3 1/2] libmultipath: support host adapter name lookup for s390x ccw bus Steffen Maier
2022-02-15 20:43   ` Martin Wilck
2022-02-15 19:45 ` [dm-devel] [PATCH v3 2/2] libmultipath: add %L path wildcard for 64-bit hex LUN Steffen Maier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.