dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Brian Bunker <brian@purestorage.com>
To: device-mapper development <dm-devel@redhat.com>
Subject: [PATCH] libmultipath: Extract the LUN number for peripheral, flat, and logical unit address methods
Date: Mon, 28 Sep 2020 16:14:27 -0700	[thread overview]
Message-ID: <D7BC3D02-400E-4F70-9A61-6E959F5AE5A5@purestorage.com> (raw)

For LUNs between 0 and 255 peripheral addressing is used. For LUNs higher than 255 the LUN addressing
should switch to flat according to the specification. Instead of printing out the LUN number without regard to
the shifting of address method, display the LUN as it was intended to be the user connecting the LUN. The
current display leaves a non-obvious 16384 offset.

In short, a LUN connected as 258 will show up in multipath output as 16642. Instead display it as the
expected 258. This is for display only and doesn’t change the actual contents of the LUN variable.

Signed-off-by: Brian Bunker <brian@purestorage.com>
___
diff -Naur a/multipath-tools-0.8.3/libmultipath/print.c b/multipath-tools-0.8.3/libmultipath/print.c
--- a/libmultipath/print.c      2020-09-24 13:52:18.661828011 -0600
+++ b/libmultipath/print.c      2020-09-28 16:57:37.956222258 -0600
@@ -29,6 +29,7 @@
 #include "uevent.h"
 #include "debug.h"
 #include "discovery.h"
+#include "util.h"
 
 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
 #define MIN(x,y) (((x) > (y)) ? (y) : (x))
@@ -390,11 +391,12 @@
        if (!pp || pp->sg_id.host_no < 0)
                return snprintf(buff, len, "#:#:#:#");
 
+       int display_lun = extract_lun_number(pp->sg_id.lun);
        return snprintf(buff, len, "%i:%i:%i:%i",
                        pp->sg_id.host_no,
                        pp->sg_id.channel,
                        pp->sg_id.scsi_id,
-                       pp->sg_id.lun);
+                       display_lun);
 }
 
 static int
diff -Naur a/multipath-tools-0.8.3/libmultipath/util.c b/multipath-tools-0.8.3/libmultipath/util.c
--- a/multipath-tools-0.8.3/libmultipath/util.c 2019-10-02 01:15:03.000000000 -0600
+++ b/multipath-tools-0.8.3/libmultipath/util.c 2020-09-28 16:56:00.851169070 -0600
@@ -470,3 +470,25 @@
 {
        close((long)arg);
 }
+
+/* Extracts the LUN number from the addressing method for
+   peripheral, flat, and LUN addressing methods.
+ */
+int extract_lun_number(int lun)
+{
+       if (lun > UINT16_MAX)
+               return lun;
+
+       uint8_t address_method = ((lun >> 8) & 0xC0) >> 6; /* first two bits of the 16 byte LUN */
+       switch (address_method) {
+               case 1: /* Flat Addressing method (01b) */
+                       return lun - 0x4000;
+               case 2: /* Logical unit addressing (02b) */
+                       return lun & 0x001F;
+               case 0: /* Peripheral addressing method (00b) */
+                       if (lun > 255)
+                               condlog(3, "Peripheral addressing supports up to 256 LUNs");
+               default:
+                       return lun;
+       }
+}
diff -Naur a/multipath-tools-0.8.3/libmultipath/util.h b/multipath-tools-0.8.3/libmultipath/util.h
--- a/multipath-tools-0.8.3/libmultipath/util.h 2019-10-02 01:15:03.000000000 -0600
+++ b/multipath-tools-0.8.3/libmultipath/util.h 2020-09-28 16:43:32.632879763 -0600
@@ -22,6 +22,7 @@
 int parse_prkey_flags(char *ptr, uint64_t *prkey, uint8_t *flags);
 int safe_write(int fd, const void *buf, size_t count);
 void set_max_fds(int max_fds);
+int extract_lun_number(int lun);
 
 #define KERNEL_VERSION(maj, min, ptc) ((((maj) * 256) + (min)) * 256 + (ptc))
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))

Brian Bunker
SW Eng
brian@purestorage.com




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

             reply	other threads:[~2020-09-28 23:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 23:14 Brian Bunker [this message]
2020-09-30 11:09 ` [PATCH] libmultipath: Extract the LUN number for peripheral, flat, and logical unit address methods Steffen Maier
2020-09-30 12:08   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D7BC3D02-400E-4F70-9A61-6E959F5AE5A5@purestorage.com \
    --to=brian@purestorage.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).