diff mbox series

[v2,2/2] libmultipath: add %L path wildcard for 64-bit hex LUN

Message ID 20220214185559.28363-3-maier@linux.ibm.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: FCP addressing display support (for s390x) | expand

Commit Message

Steffen Maier Feb. 14, 2022, 6:55 p.m. UTC
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 mbox series

Patch

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[] = {