]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
NVMe: Expose ns wwid through single sysfs entry
authorKeith Busch <keith.busch@intel.com>
Thu, 18 Feb 2016 16:57:48 +0000 (09:57 -0700)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 1 Jun 2017 20:41:10 +0000 (13:41 -0700)
The method to uniquely identify a namespace depends on the controller's
specification revision level and implemented capabilities. This patch
has the driver figure this out and exports the unique string through a
single 'wwid' attribute so the user doesn't have this burden.

The longest namespace unique identifier is used if available. If not
available, the driver will concat the controller's vendor, serial,
and model with the namespace ID. The specification provides this as a
unique indentifier.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
(cherry picked from commit 118472ab8532e55f48395ef5764b354fe48b1d73)

Orabug: 25130845

Signed-off-by: Ashok Vairavan <ashok.vairavan@oracle.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h

index c8c921e83a531364dda164b5c9d8c9af8863b251..9d4b05c6ccc5fd9fb8ed50535e052d467e83d090 100644 (file)
@@ -888,6 +888,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
                return -EIO;
        }
 
+       ctrl->vid = le16_to_cpu(id->vid);
        ctrl->oncs = le16_to_cpup(&id->oncs);
        atomic_set(&ctrl->abort_limit, id->acl + 1);
        ctrl->vwc = id->vwc;
@@ -1028,6 +1029,30 @@ static ssize_t nvme_sysfs_reset(struct device *dev,
 }
 static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset);
 
+static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,
+                                                               char *buf)
+{
+       struct nvme_ns *ns = dev_to_disk(dev)->private_data;
+       struct nvme_ctrl *ctrl = ns->ctrl;
+       int serial_len = sizeof(ctrl->serial);
+       int model_len = sizeof(ctrl->model);
+
+       if (memchr_inv(ns->uuid, 0, sizeof(ns->uuid)))
+               return sprintf(buf, "eui.%16phN\n", ns->uuid);
+
+       if (memchr_inv(ns->eui, 0, sizeof(ns->eui)))
+               return sprintf(buf, "eui.%8phN\n", ns->eui);
+
+       while (ctrl->serial[serial_len - 1] == ' ')
+               serial_len--;
+       while (ctrl->model[model_len - 1] == ' ')
+               model_len--;
+
+       return sprintf(buf, "nvme.%04x-%*phN-%*phN-%08x\n", ctrl->vid,
+               serial_len, ctrl->serial, model_len, ctrl->model, ns->ns_id);
+}
+static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);
+
 static ssize_t uuid_show(struct device *dev, struct device_attribute *attr,
                                                                char *buf)
 {
@@ -1053,6 +1078,7 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL);
 
 static struct attribute *nvme_ns_attrs[] = {
+       &dev_attr_wwid.attr,
        &dev_attr_uuid.attr,
        &dev_attr_eui.attr,
        &dev_attr_nsid.attr,
index 761b438d3fdc1de49d1f0075df646aa2146ba559..7f5a4dae1bcfdbca5d258753e6b5c398daf50c82 100644 (file)
@@ -80,6 +80,7 @@ struct nvme_ctrl {
        u32 max_hw_sectors;
        u32 stripe_size;
        u16 oncs;
+       u16 vid;
        atomic_t abort_limit;
        u8 event_limit;
        u8 vwc;