aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2016-02-18 11:57:48 -0500
committerJens Axboe <axboe@fb.com>2016-03-16 10:46:25 -0400
commit118472ab8532e55f48395ef5764b354fe48b1d73 (patch)
treefd16dcee80675a6e96e043a8544696c4129bfefa
parent98347a7d8a93ef8a01c8d1946a2059f38f73b239 (diff)
NVMe: Expose ns wwid through single sysfs entry
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>
-rw-r--r--drivers/nvme/host/core.c26
-rw-r--r--drivers/nvme/host/nvme.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4304be00e556..266918b9bb84 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -915,6 +915,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
915 return -EIO; 915 return -EIO;
916 } 916 }
917 917
918 ctrl->vid = le16_to_cpu(id->vid);
918 ctrl->oncs = le16_to_cpup(&id->oncs); 919 ctrl->oncs = le16_to_cpup(&id->oncs);
919 atomic_set(&ctrl->abort_limit, id->acl + 1); 920 atomic_set(&ctrl->abort_limit, id->acl + 1);
920 ctrl->vwc = id->vwc; 921 ctrl->vwc = id->vwc;
@@ -1053,6 +1054,30 @@ static ssize_t nvme_sysfs_reset(struct device *dev,
1053} 1054}
1054static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset); 1055static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset);
1055 1056
1057static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,
1058 char *buf)
1059{
1060 struct nvme_ns *ns = dev_to_disk(dev)->private_data;
1061 struct nvme_ctrl *ctrl = ns->ctrl;
1062 int serial_len = sizeof(ctrl->serial);
1063 int model_len = sizeof(ctrl->model);
1064
1065 if (memchr_inv(ns->uuid, 0, sizeof(ns->uuid)))
1066 return sprintf(buf, "eui.%16phN\n", ns->uuid);
1067
1068 if (memchr_inv(ns->eui, 0, sizeof(ns->eui)))
1069 return sprintf(buf, "eui.%8phN\n", ns->eui);
1070
1071 while (ctrl->serial[serial_len - 1] == ' ')
1072 serial_len--;
1073 while (ctrl->model[model_len - 1] == ' ')
1074 model_len--;
1075
1076 return sprintf(buf, "nvme.%04x-%*phN-%*phN-%08x\n", ctrl->vid,
1077 serial_len, ctrl->serial, model_len, ctrl->model, ns->ns_id);
1078}
1079static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);
1080
1056static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, 1081static ssize_t uuid_show(struct device *dev, struct device_attribute *attr,
1057 char *buf) 1082 char *buf)
1058{ 1083{
@@ -1078,6 +1103,7 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr,
1078static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL); 1103static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL);
1079 1104
1080static struct attribute *nvme_ns_attrs[] = { 1105static struct attribute *nvme_ns_attrs[] = {
1106 &dev_attr_wwid.attr,
1081 &dev_attr_uuid.attr, 1107 &dev_attr_uuid.attr,
1082 &dev_attr_eui.attr, 1108 &dev_attr_eui.attr,
1083 &dev_attr_nsid.attr, 1109 &dev_attr_nsid.attr,
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index a402a0ebf471..bf3f143e975b 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -91,6 +91,7 @@ struct nvme_ctrl {
91 u32 max_hw_sectors; 91 u32 max_hw_sectors;
92 u32 stripe_size; 92 u32 stripe_size;
93 u16 oncs; 93 u16 oncs;
94 u16 vid;
94 atomic_t abort_limit; 95 atomic_t abort_limit;
95 u8 event_limit; 96 u8 event_limit;
96 u8 vwc; 97 u8 vwc;