diff mbox series

[v5,05/12] nvme: Add durable name for dev_printk

Message ID 20200925161929.1136806-6-tasleson@redhat.com
State New
Headers show
Series Add persistent durable identifier to storage log messages | expand

Commit Message

Tony Asleson Sept. 25, 2020, 4:19 p.m. UTC
Changed the comment from // to /* and re-worked buffer
space needed for formatting wwid as requested by
Keith Busch.

ref.
https://lore.kernel.org/linux-block/20200513230455.GA1503@redsun51.ssa.fujisawa.hgst.com/

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 drivers/nvme/host/core.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4ee2330c603e..2e3b808c7815 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2734,6 +2734,22 @@  static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
 	return true;
 }
 
+static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,
+			char *buf);
+
+static int dev_to_nvme_durable_name(const struct device *dev, char *buf, size_t len)
+{
+	/*
+	 * Max 141 needed for wwid_show, make sure we have the space available
+	 * in our buffer before we format the wwid directly into it.
+	 */
+	if (len >= 141) {
+		ssize_t wwid_len = wwid_show((struct device *)dev, NULL, buf);
+		return wwid_len > 0 ? wwid_len - 1 : 0;  /* remove '\n' */
+	}
+	return 0;
+}
+
 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 {
 	struct nvme_subsystem *subsys, *found;
@@ -3663,6 +3679,8 @@  static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	disk->queue = ns->queue;
 	disk->flags = flags;
 	memcpy(disk->disk_name, disk_name, DISK_NAME_LEN);
+	disk_to_dev(disk)->durable_name = dev_to_nvme_durable_name;
+
 	ns->disk = disk;
 
 	if (__nvme_revalidate_disk(disk, id))