Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1654229 > unrolled thread

[PATCH v1 4/7] nvme: get list of namespace descriptors

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2017-05-31 15:40 +0200
Last post2017-06-01 08:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v1 4/7] nvme: get list of namespace descriptors Johannes Thumshirn <jthumshirn@suse.de> - 2017-05-31 15:40 +0200
    Re: [PATCH v1 4/7] nvme: get list of namespace descriptors Christoph Hellwig <hch@lst.de> - 2017-06-01 08:50 +0200

#1654229 — [PATCH v1 4/7] nvme: get list of namespace descriptors

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-05-31 15:40 +0200
Subject[PATCH v1 4/7] nvme: get list of namespace descriptors
Message-ID<tNc0W-5nk-1@gated-at.bofh.it>
If a target identifies itself as NVMe 1.3 compliant, try to get the
list of Namespace Identification Descriptors and populate the UUID,
NGUID and EUI64 fileds in the NVMe namespace structure with these
values.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/nvme/host/core.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 89 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7b254be16887..9acbf56c8796 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -643,6 +643,71 @@ int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
 	return error;
 }
 
+static void nvme_parse_ns_descs(struct nvme_ns *ns, void *ns_nid)
+{
+	struct nvme_ns_nid *cur;
+	const u8 *p;
+	int pos = 0;
+	int len;
+
+	p = (u8 *)ns_nid;
+
+	for (;;) {
+		cur = (struct nvme_ns_nid *)p;
+
+		switch (cur->nidl) {
+		case 0:
+			return;
+		case 8:
+		case 16:
+			break;
+		default:
+			dev_warn(ns->ctrl->dev,
+				 "Target returned bogus Namespace Identification Descriptor length: %d\n",
+				 cur->nidl);
+			return;
+
+		}
+
+		switch (cur->nidt) {
+		case NVME_NIDT_EUI64:
+			len = NVME_NIDT_EUI64_LEN;
+			memcpy(ns->eui, cur->nid, len);
+			break;
+		case NVME_NIDT_NGUID:
+			len = NVME_NIDT_NGUID_LEN;
+			memcpy(ns->nguid, cur->nid, len);
+			break;
+		case NVME_NIDT_UUID:
+			len = NVME_NIDT_UUID_LEN;
+			memcpy(ns->uuid, cur->nid, len);
+			break;
+		default:
+			dev_warn(ns->ctrl->dev,
+				 "Invalid Namespace Identification Descriptor Type: %d\n",
+				 cur->nidt);
+			return;
+		}
+
+		pos += sizeof(struct nvme_ns_nid) + len;
+		if (pos >= SZ_4K)
+			return;
+		p += pos;
+	}
+}
+
+static int nvme_identify_ns_descs(struct nvme_ctrl *dev, unsigned nsid,
+				  void *ns_nid)
+{
+	struct nvme_command c = { };
+
+	c.identify.opcode = nvme_admin_identify;
+	c.identify.nsid = cpu_to_le32(nsid);
+	c.identify.cns = NVME_ID_CNS_NS_DESC_LIST;
+
+	return nvme_submit_sync_cmd(dev->admin_q, &c, ns_nid, SZ_4K);
+}
+
 static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *ns_list)
 {
 	struct nvme_command c = { };
@@ -1017,6 +1082,29 @@ static int nvme_revalidate_ns(struct nvme_ns *ns, struct nvme_id_ns **id)
 		memcpy(ns->eui, (*id)->eui64, sizeof(ns->eui));
 	if (ns->ctrl->vs >= NVME_VS(1, 2, 0))
 		memcpy(ns->nguid, (*id)->nguid, sizeof(ns->nguid));
+	if (ns->ctrl->vs >= NVME_VS(1, 3, 0)) {
+		void *ns_nid;
+		int ret;
+
+
+		ns_nid = kzalloc(SZ_4K, GFP_KERNEL);
+		if (!ns_nid) {
+			dev_warn(ns->ctrl->dev,
+				 "%s: Identify Descriptors failed\n", __func__);
+			return 0;
+		}
+
+		ret = nvme_identify_ns_descs(ns->ctrl, ns->ns_id, ns_nid);
+		if (ret) {
+			dev_warn(ns->ctrl->dev,
+				 "%s: Identify Descriptors failed\n", __func__);
+			 /* Don't treat error as fatal we potentially
+			  * already have a NGUID or EUI-64 */
+			return 0;
+		}
+		nvme_parse_ns_descs(ns, ns_nid);
+		kfree(ns_nid);
+	}
 
 	return 0;
 }
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 5004f0c41397..7007521e8194 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -190,6 +190,7 @@ struct nvme_ns {
 
 	u8 eui[8];
 	u8 nguid[16];
+	u8 uuid[16];
 
 	unsigned ns_id;
 	int lba_shift;
-- 
2.12.0

[toc] | [next] | [standalone]


#1654851

FromChristoph Hellwig <hch@lst.de>
Date2017-06-01 08:50 +0200
Message-ID<tNs5I-7t1-5@gated-at.bofh.it>
In reply to#1654229
> +static void nvme_parse_ns_descs(struct nvme_ns *ns, void *ns_nid)
> +{
> +	struct nvme_ns_nid *cur;
> +	const u8 *p;
> +	int pos = 0;
> +	int len;
> +
> +	p = (u8 *)ns_nid;

No need for the cast.  But we can do void pointer arithmetics in the
kernel anyway, so possible we could just declare this void.

And maybe just call the argument data and operate on that.

> +
> +	for (;;) {
> +		cur = (struct nvme_ns_nid *)p;

	for (pos = 0; pos < NVME_ID_DATA_SIZE; pos += len) {
		struct nvme_ns_nid *cur = data + pos;

> +
> +		switch (cur->nidl) {
> +		case 0:
> +			return;
> +		case 8:
> +		case 16:
> +			break;
> +		default:
> +			dev_warn(ns->ctrl->dev,
> +				 "Target returned bogus Namespace Identification Descriptor length: %d\n",
> +				 cur->nidl);
> +			return;
> +
> +		}

This needs to be verified based on the type.

> +	if (ns->ctrl->vs >= NVME_VS(1, 3, 0)) {
> +		void *ns_nid;
> +		int ret;
> +
> +
> +		ns_nid = kzalloc(SZ_4K, GFP_KERNEL);
> +		if (!ns_nid) {
> +			dev_warn(ns->ctrl->dev,
> +				 "%s: Identify Descriptors failed\n", __func__);
> +			return 0;
> +		}
> +
> +		ret = nvme_identify_ns_descs(ns->ctrl, ns->ns_id, ns_nid);
> +		if (ret) {
> +			dev_warn(ns->ctrl->dev,
> +				 "%s: Identify Descriptors failed\n", __func__);
> +			 /* Don't treat error as fatal we potentially
> +			  * already have a NGUID or EUI-64 */
> +			return 0;
> +		}
> +		nvme_parse_ns_descs(ns, ns_nid);
> +		kfree(ns_nid);

Please move all this code into nvme_identify_ns_descs().

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web