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@xxxxxxxxxxxxxxx> ___ 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@xxxxxxxxxxxxxxx -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel