libmultipath: Fixes for NVME / NVMEoF
Subsystems (2)
v2 cover libmultipath: Fixes for NVME / NVMEoF
Current code fails to set up multipath maps for NVME devices in a Linux target/Linux host combination. This series enables at least basic operation.
Patch 1/4 fixes a crash that happens if over-long WWIDs are encountered, and is not specific to NVME as such. Patch 2/4 drops
the broken test uevent_can_discard_by_devpath(). Patch 3/4 compensates for the additional event processing required by 2/4. Patch 4/4 mangles overlong "nvme.*" WWIDs to make them usable for multipath (related discussion in [1]; WWID_SIZE can't be simply increased because it has to match device mapper's DM_NAME_LEN).
Changes wrt v1:
1/4: assure 0-termination by using strlcpy() (Bart van Assche) 4/4: drop extra length test (Ben Marzinski)
I kept the v1 Reviewed-by: and Acked-by tags because the changes are minor, I hope that's ok for the reviewers.
[1] http://lists.infradead.org/pipermail/linux-nvme/2017-July/011960.html
Martin Wilck (4):
libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
libmultipath: drop uevent_can_discard_by_devpath
libmultipath: only listen for uevents with DEVTYPE=disk
libmultipath: fix over-long NVME WWIDs
libmultipath/discovery.c | 85 +++++++++++++++++++++++++++++++++++++++++++++--- libmultipath/uevent.c | 27 +-------------- 2 files changed, 82 insertions(+), 30 deletions(-)
Signature · 1 line
2.13.2
PATCH v2 1/4 libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
If the first WWID_LEN bytes of the uuid_attribute do not contain a 0 byte, pp->wwid may end up not properly terminated. Fix it by using strlcpy() rather than strncpy().
--- libmultipath/discovery.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
libmultipath/discovery.c +2 -4
@@ -1608,13 +1608,11 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)if (!value ||strlen (value) ==0 ) value =getenv (uid_attribute);if (value &&strlen (value)) { -if (strlen (value) +1 >WWID_SIZE ) { + len =strlcpy (pp->wwid, value,WWID_SIZE ); +if (len >=WWID_SIZE ) {condlog (0 ,"%s: wwid overflow" , pp->dev); len =WWID_SIZE ; - }else { - len =strlen (value); } -strncpy (pp->wwid, value, len); }else {condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);
Signature · 1 line
2.13.2
PATCH v2 2/4 libmultipath: drop uevent_can_discard_by_devpath
In reply to Martin WilckThis function is broken. Not all devices that matter for multipathd follow the block/$DEVICE/$PARTITION convention (example: NVME)
--- libmultipath/uevent.c | 25 ------------------------- 1 file changed, 25 deletions(-)
libmultipath/uevent.c +0 -25
@@ -143,36 +143,11 @@ uevent_need_merge(void)return need_merge; } -static bool -uevent_can_discard_by_devpath (const char *devpath) -{ -static const char BLOCK [] ="/block/" ; -const char *tmp =strstr (devpath,BLOCK ); - -if (tmp ==NULL ) { -condlog (4 ,"no /block/ in '%s'" , devpath); -return true; - } - tmp +=sizeof (BLOCK ) -1 ; -if (*tmp =='\0' ) -/* just ".../block/" - discard */ -return true; -/* -* If there are more path elements after ".../block/xyz", -* it's a partition - discard it; but don't discard ".../block/sda/". -*/ - tmp =strchr (tmp,'/' ); -return tmp !=NULL && *(tmp +1 ) !='\0' ; -} -bool uevent_can_discard (struct uevent *uev) {struct config * conf; -if (uevent_can_discard_by_devpath (uev->devpath)) -return true; -/* * do not filter dm devices by devnode */
Signature · 1 line
2.13.2
PATCH v2 3/4 libmultipath: only listen for uevents with DEVTYPE=disk
In reply to Martin WilckWe are only interested in disks anyway. This saves us checking for devtype in the uevent processing queue, and is more powerful than the previous test in the dropped function uevent_can_discard_by_devpath().
--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/uevent.c +1 -1
@@ -770,7 +770,7 @@ int uevent_listen(struct udev *udev) goto out; } err =udev_monitor_filter_add_match_subsystem_devtype (monitor,"block" , -NULL ); +"disk" );if (err)condlog (2 ,"failed to create filter : %s" ,strerror (-err)); err =udev_monitor_enable_receiving (monitor);
Signature · 1 line
2.13.2
PATCH v2 4/4 libmultipath: fix over-long NVME WWIDs
In reply to Martin WilckFix for NVME wwids looking like this (line continuations inserted here for readability):
nvme.0000-3163653363666438366239656630386200-\
4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-\
00000002
which are encountered in some combinations of Linux NVME host and target, where the 2nd field represents the serial number (SN) and the 3rd the model number (MN).
The device mapper allows map names only up to 128 characters. Strip the "00" sequences at the end of the serial and model field, they are hex-encoded 0-bytes which are forbidden by the NVME spec anyway.
--- libmultipath/discovery.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
libmultipath/discovery.c +79 -0
@@ -1598,6 +1598,82 @@ get_prio (struct path * pp)return 0 ; } +/* +* Mangle string of length *len starting at start +* by removing character sequence "00" (hex for a 0 byte), +* starting at end, backwards. +* Changes the value of *len if characters were removed. +* Returns a pointer to the position where "end" was moved to. +*/ +static char +*skip_zeroes_backward (char * start,int *len,char *end) +{ +char *p = end; + +while (p >= start +2 && *(p -1 ) =='0' && *(p -2 ) =='0' ) + p -=2 ; + +if (p == end) +return p; + +memmove (p, end, start + *len +1 - end); + *len -= end - p; + +return p; +} + +/* +* Fix for NVME wwids looking like this: +* nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002 +* which are encountered in some combinations of Linux NVME host and target. +* The '00' are hex-encoded 0-bytes which are forbidden in the serial (SN) +* and model (MN) fields. Discard them. +* If a WWID of the above type is found, sets pp->wwid and returns a value > 0. +* Otherwise, returns 0. +*/ +static int +fix_broken_nvme_wwid (struct path *pp,const char *value,int size) +{ +static const char _nvme[] ="nvme." ; +int len, i; +char mangled[256 ]; +char *p; + + len =strlen (value); +if (len >=sizeof (mangled)) +return 0 ; + +/* Check that value starts with "nvme.%04x-" */ +if (memcmp (value, _nvme,sizeof (_nvme) -1 ) || value[9 ] !='-' ) +return 0 ; +for (i =5 ; i <9 ; i++) +if (!isxdigit (value[i])) +return 0 ; + +memcpy (mangled, value, len +1 ); + +/* search end of "model" part and strip trailing '00' */ + p =memrchr (mangled,'-' , len); +if (p ==NULL ) +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); + +/* search end of "serial" part */ + p =memrchr (mangled,'-' , p - mangled); +if (p ==NULL ||memrchr (mangled,'-' , p - mangled) != mangled +9 ) +/* We expect exactly 3 '-' in the value */ +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); +if (len >= size) +return 0 ; + +memcpy (pp->wwid, mangled, len +1 ); +condlog (2 ,"%s: over-long WWID shortened to %s" , pp->dev, pp->wwid); +return len; +} +static int get_udev_uid (struct path * pp,char *uid_attribute,struct udev_device *udev) {
@@ -1610,6 +1686,9 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)if (value &&strlen (value)) { len =strlcpy (pp->wwid, value,WWID_SIZE );if (len >=WWID_SIZE ) { + len =fix_broken_nvme_wwid (pp, value,WWID_SIZE ); +if (len >0 ) +return len;condlog (0 ,"%s: wwid overflow" , pp->dev); len =WWID_SIZE ; }
Signature · 1 line
2.13.2
Re: [PATCH v2 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
In reply to Martin WilckQuoted 3 lines · Martin Wilck
If the first
WWID_LENbytes of theuuid_attributedo not contain a 0 byte,pp->wwidmay end up not properly terminated. Fix it by usingstrlcpy()rather thanstrncpy().
This set is now merged.
Thanks.
Quoted 38 lines · Martin Wilck
Current code fails to set up multipath maps for NVME devices in a Linux target/Linux host combination. This series enables at least basic operation.
Patch 1/4 fixes a crash that happens if over-long WWIDs are encountered, and
is not specific to NVME as such. Patch 2/4 drops
the broken testuevent_can_discard_by_devpath(). Patch 3/4 compensates for the additional event processing required by 2/4. Patch 4/4 mangles overlong "nvme.*" WWIDs to make them usable for multipath (related discussion
in [1];WWID_SIZEcan't be simply increased because it has to match device mapper'sDM_NAME_LEN).Changes wrt v1:
1/4: assure 0-termination by usingstrlcpy()(Bart van Assche) 4/4: drop extra length test (Ben Marzinski)I kept the v1 Reviewed-by: and Acked-by tags because the changes are minor, I hope that's ok for the reviewers.
[1] http://lists.infradead.org/pipermail/linux-nvme/2017-July/011960.html
Martin Wilck (4):
libmultipath:get_udev_uid: make surepp->wwidis 0-terminated
libmultipath: dropuevent_can_discard_by_devpath
libmultipath: only listen for uevents with DEVTYPE=disk
libmultipath: fix over-long NVME WWIDslibmultipath/discovery.c | 85 ++++++++++++++++++++++++++++++ +++++++++++++++--- libmultipath/uevent.c | 27 +-------------- 2 files changed, 82 insertions(+), 30 deletions(-)--
2.13.2