Skip to content

Commit 118472a

Browse files
Keith Buschaxboe
authored andcommitted
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>
1 parent 98347a7 commit 118472a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/nvme/host/core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
915915
return -EIO;
916916
}
917917

918+
ctrl->vid = le16_to_cpu(id->vid);
918919
ctrl->oncs = le16_to_cpup(&id->oncs);
919920
atomic_set(&ctrl->abort_limit, id->acl + 1);
920921
ctrl->vwc = id->vwc;
@@ -1053,6 +1054,30 @@ static ssize_t nvme_sysfs_reset(struct device *dev,
10531054
}
10541055
static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset);
10551056

1057+
static 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+
}
1079+
static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);
1080+
10561081
static ssize_t uuid_show(struct device *dev, struct device_attribute *attr,
10571082
char *buf)
10581083
{
@@ -1078,6 +1103,7 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr,
10781103
static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL);
10791104

10801105
static struct attribute *nvme_ns_attrs[] = {
1106+
&dev_attr_wwid.attr,
10811107
&dev_attr_uuid.attr,
10821108
&dev_attr_eui.attr,
10831109
&dev_attr_nsid.attr,

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct nvme_ctrl {
9191
u32 max_hw_sectors;
9292
u32 stripe_size;
9393
u16 oncs;
94+
u16 vid;
9495
atomic_t abort_limit;
9596
u8 event_limit;
9697
u8 vwc;

0 commit comments

Comments
 (0)