discovery: sanitize NVMe discovery
authorHannes Reinecke <hare@suse.de>
Fri, 15 Sep 2017 06:30:27 +0000 (08:30 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 20 Sep 2017 13:31:23 +0000 (15:31 +0200)
Bring the output of NVMe discovery inline with the other transports,
and set the sg_id mappings to avoid ugly '#' outputs.

Signed-off-by: Hannes Reinecke <hare@suse.com>
libmultipath/discovery.c

index 3a912d7..95c138b 100644 (file)
@@ -1194,28 +1194,37 @@ scsi_sysfs_pathinfo (struct path * pp, vector hwtable)
 static int
 nvme_sysfs_pathinfo (struct path * pp, vector hwtable)
 {
-       struct udev_device *parent, *nvme = NULL;
+       struct udev_device *parent;
+       const char *attr_path = NULL;
 
-       parent = pp->udev;
-       while (parent) {
-               const char *subsys = udev_device_get_subsystem(parent);
+       attr_path = udev_device_get_sysname(pp->udev);
+       if (!attr_path)
+               return 1;
 
-               if (subsys && !strncmp(subsys, "nvme", 4)) {
-                       nvme = parent;
-                       break;
-               }
-               parent = udev_device_get_parent(parent);
-       }
-       if (!nvme)
+       if (sscanf(attr_path, "nvme%dn%d",
+                  &pp->sg_id.host_no,
+                  &pp->sg_id.scsi_id) != 2)
+               return 1;
+       pp->sg_id.channel = 0;
+       pp->sg_id.lun = 0;
+
+       parent = udev_device_get_parent(pp->udev);
+       if (!parent)
                return 1;
 
        snprintf(pp->vendor_id, SCSI_VENDOR_SIZE, "NVME");
-       snprintf(pp->product_id, SCSI_PRODUCT_SIZE, "%s", udev_device_get_sysattr_value(nvme, "model"));
-       snprintf(pp->serial, SERIAL_SIZE, "%s", udev_device_get_sysattr_value(nvme, "serial"));
-       snprintf(pp->rev, SCSI_REV_SIZE, "%s", udev_device_get_sysattr_value(nvme, "firmware_rev"));
+       snprintf(pp->product_id, SCSI_PRODUCT_SIZE, "%s",
+                udev_device_get_sysattr_value(parent, "model"));
+       snprintf(pp->serial, SERIAL_SIZE, "%s",
+                udev_device_get_sysattr_value(parent, "serial"));
+       snprintf(pp->rev, SCSI_REV_SIZE, "%s",
+                udev_device_get_sysattr_value(parent, "firmware_rev"));
+
+       condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
+       condlog(3, "%s: product = %s", pp->dev, pp->product_id);
+       condlog(3, "%s: serial = %s", pp->dev, pp->serial);
+       condlog(3, "%s: rev = %s", pp->dev, pp->rev);
 
-       condlog(3, "%s: vendor:%s product:%s serial:%s rev:%s", pp->dev,
-               pp->vendor_id, pp->product_id, pp->serial, pp->rev);
        pp->hwe = find_hwe(hwtable, pp->vendor_id, pp->product_id, NULL);
 
        return 0;