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


Groups > linux.kernel > #1657046 > unrolled thread

[PATCH v4 3/8] nvmet: implement namespace identify descriptor list

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2017-06-04 12:40 +0200
Last post2017-06-06 08:30 +0200
Articles 5 — 4 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 v4 3/8] nvmet: implement namespace identify descriptor list Johannes Thumshirn <jthumshirn@suse.de> - 2017-06-04 12:40 +0200
    Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor  list Sagi Grimberg <sagi@grimberg.me> - 2017-06-04 17:10 +0200
    Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor         list Christoph Hellwig <hch@lst.de> - 2017-06-05 07:40 +0200
      Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor  list Johannes Thumshirn <jthumshirn@suse.de> - 2017-06-06 14:10 +0200
    Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor  list Hannes Reinecke <hare@suse.de> - 2017-06-06 08:30 +0200

#1657046 — [PATCH v4 3/8] nvmet: implement namespace identify descriptor list

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-06-04 12:40 +0200
Subject[PATCH v4 3/8] nvmet: implement namespace identify descriptor list
Message-ID<tOB6W-3JJ-11@gated-at.bofh.it>
A NVMe Identify NS command with a CNS value of '3' is expecting a list
of Namespace Identification Descriptor structures to be returned to
the host for the namespace requested in the namespace identify
command.

This Namespace Identification Descriptor structure consists of the
type of the namespace identifier, the length of the identifier and the
actual identifier.

Valid types are NGUID and UUID which we have saved in our nvme_ns
structure if they have been configured via configfs. If no value has
been assigened to one of these we return an "invalid opcode" back to
the host to maintain backward compatibiliy with older implementations
without Namespace Identify Descriptor list support.

Also as the Namespace Identify Descriptor list is the only mandatory
feature change between 1.2.1 and 1.3.0 we can bump the advertised
version as well.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/nvme/target/admin-cmd.c | 53 +++++++++++++++++++++++++++++++++++++++++
 drivers/nvme/target/core.c      |  3 ++-
 drivers/nvme/target/nvmet.h     |  1 +
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index ff1f97006322..833b5ef935c3 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -367,6 +367,56 @@ static void nvmet_execute_identify_nslist(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
+static void nvmet_execute_identify_desclist(struct nvmet_req *req)
+{
+	struct nvmet_ns *ns;
+	struct nvme_ns_identifier_hdr hdr;
+	u16 status = 0;
+	off_t off = 0;
+
+	ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
+	if (!ns) {
+		status = NVME_SC_INVALID_NS | NVME_SC_DNR;
+		goto out;
+	}
+
+	if (memchr_inv(&ns->uuid, 0, sizeof(ns->uuid))) {
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.nidt = NVME_NIDT_UUID;
+		hdr.nidl = NVME_NIDT_UUID_LEN;
+		status = nvmet_copy_to_sgl(req, off, &hdr, sizeof(hdr));
+		if (status)
+			goto out_put_ns;
+		off += sizeof(hdr);
+
+		status = nvmet_copy_to_sgl(req, off, &ns->uuid,
+					   sizeof(ns->uuid));
+		if (status)
+			goto out_put_ns;
+		off += sizeof(ns->uuid);
+	}
+	if (memchr_inv(ns->nguid, 0, sizeof(ns->nguid))) {
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.nidt = NVME_NIDT_NGUID;
+		hdr.nidl = NVME_NIDT_NGUID_LEN;
+		status = nvmet_copy_to_sgl(req, off, &hdr, sizeof(hdr));
+		if (status)
+			goto out_put_ns;
+		off += sizeof(hdr);
+
+		status = nvmet_copy_to_sgl(req, off, &ns->nguid,
+					   sizeof(ns->nguid));
+		if (status)
+			goto out_put_ns;
+		off += sizeof(ns->nguid);
+	}
+
+out_put_ns:
+	nvmet_put_namespace(ns);
+out:
+	nvmet_req_complete(req, status);
+}
+
 /*
  * A "mimimum viable" abort implementation: the command is mandatory in the
  * spec, but we are not required to do any useful work.  We couldn't really
@@ -515,6 +565,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
 		case NVME_ID_CNS_NS_ACTIVE_LIST:
 			req->execute = nvmet_execute_identify_nslist;
 			return 0;
+		case NVME_ID_CNS_NS_DESC_LIST:
+			req->execute = nvmet_execute_identify_desclist;
+			return 0;
 		}
 		break;
 	case nvme_admin_abort_cmd:
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index eb9399ac97cf..1a9c17c7dc59 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -380,6 +380,7 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid)
 
 	ns->nsid = nsid;
 	ns->subsys = subsys;
+	uuid_be_gen(&ns->uuid);
 
 	return ns;
 }
@@ -926,7 +927,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 	if (!subsys)
 		return NULL;
 
-	subsys->ver = NVME_VS(1, 2, 1); /* NVMe 1.2.1 */
+	subsys->ver = NVME_VS(1, 3, 0); /* NVMe 1.3.0 */
 
 	switch (type) {
 	case NVME_NQN_NVME:
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index cfc5c7fb0ab7..4c6cb5ea1186 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -46,6 +46,7 @@ struct nvmet_ns {
 	u32			blksize_shift;
 	loff_t			size;
 	u8			nguid[16];
+	uuid_be			uuid;
 
 	bool			enabled;
 	struct nvmet_subsys	*subsys;
-- 
2.12.0

[toc] | [next] | [standalone]


#1657093 — Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list

FromSagi Grimberg <sagi@grimberg.me>
Date2017-06-04 17:10 +0200
SubjectRe: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list
Message-ID<tOFke-6N9-21@gated-at.bofh.it>
In reply to#1657046
> +static void nvmet_execute_identify_desclist(struct nvmet_req *req)
> +{
> +	struct nvmet_ns *ns;
> +	struct nvme_ns_identifier_hdr hdr;
> +	u16 status = 0;
> +	off_t off = 0;
> +
> +	ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
> +	if (!ns) {
> +		status = NVME_SC_INVALID_NS | NVME_SC_DNR;
> +		goto out;
> +	}
> +
> +	if (memchr_inv(&ns->uuid, 0, sizeof(ns->uuid))) {
> +		memset(&hdr, 0, sizeof(hdr));
> +		hdr.nidt = NVME_NIDT_UUID;
> +		hdr.nidl = NVME_NIDT_UUID_LEN;
> +		status = nvmet_copy_to_sgl(req, off, &hdr, sizeof(hdr));
> +		if (status)
> +			goto out_put_ns;
> +		off += sizeof(hdr);
> +
> +		status = nvmet_copy_to_sgl(req, off, &ns->uuid,
> +					   sizeof(ns->uuid));
> +		if (status)
> +			goto out_put_ns;
> +		off += sizeof(ns->uuid);
> +	}
> +	if (memchr_inv(ns->nguid, 0, sizeof(ns->nguid))) {

Plain override in case a namespace is fed with both uuid and nguid?

Perhaps we should try to help the user a bit here and either fail
the user trying to populate both in configfs or pick one here.

> +		memset(&hdr, 0, sizeof(hdr));
> +		hdr.nidt = NVME_NIDT_NGUID;
> +		hdr.nidl = NVME_NIDT_NGUID_LEN;
> +		status = nvmet_copy_to_sgl(req, off, &hdr, sizeof(hdr));
> +		if (status)
> +			goto out_put_ns;
> +		off += sizeof(hdr);
> +
> +		status = nvmet_copy_to_sgl(req, off, &ns->nguid,
> +					   sizeof(ns->nguid));
> +		if (status)
> +			goto out_put_ns;
> +		off += sizeof(ns->nguid);
> +	}

If none exist we return whatever the the stack contains in hdr...
Lets initialize hdr with {} at the declaration.

[toc] | [prev] | [next] | [standalone]


#1657282 — Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list

FromChristoph Hellwig <hch@lst.de>
Date2017-06-05 07:40 +0200
SubjectRe: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list
Message-ID<tOSUb-79A-25@gated-at.bofh.it>
In reply to#1657046
I think this needs to zero the remainder of the 4k
buffer, quoting the spec:

"The controller may return any number of variable length Namespace
Identification Descriptor structures that fit into the 4096 byte Identify
payload. All remaining bytes after the namespace identification descriptor
structures should be cleared to 0h, and the host shall interpret a
Namespace Identifier Descriptor Length (NIDL) value of 0h as the end of
the list. If the hosts sees an unknown descriptor type it should
continue parsing the structure."

It could be easily done by copying the zero page to userspace.
Eventually I want to add a helper to zero parts of a sglist to
lib/scatterlist.c, but I don't want to burden that on you.

[toc] | [prev] | [next] | [standalone]


#1658692 — Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-06-06 14:10 +0200
SubjectRe: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list
Message-ID<tPlt9-aF-27@gated-at.bofh.it>
In reply to#1657282
On 06/05/2017 07:35 AM, Christoph Hellwig wrote:
> I think this needs to zero the remainder of the 4k
> buffer, quoting the spec:

*gah* yeah, my initial version with the kzalloc() took care of it.

> It could be easily done by copying the zero page to userspace.
> Eventually I want to add a helper to zero parts of a sglist to
> lib/scatterlist.c, but I don't want to burden that on you.

I'll have a look.

-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

[toc] | [prev] | [next] | [standalone]


#1658383 — Re: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list

FromHannes Reinecke <hare@suse.de>
Date2017-06-06 08:30 +0200
SubjectRe: [PATCH v4 3/8] nvmet: implement namespace identify descriptor list
Message-ID<tPga5-55F-3@gated-at.bofh.it>
In reply to#1657046
On 06/04/2017 12:36 PM, Johannes Thumshirn wrote:
> A NVMe Identify NS command with a CNS value of '3' is expecting a list
> of Namespace Identification Descriptor structures to be returned to
> the host for the namespace requested in the namespace identify
> command.
> 
> This Namespace Identification Descriptor structure consists of the
> type of the namespace identifier, the length of the identifier and the
> actual identifier.
> 
> Valid types are NGUID and UUID which we have saved in our nvme_ns
> structure if they have been configured via configfs. If no value has
> been assigened to one of these we return an "invalid opcode" back to
> the host to maintain backward compatibiliy with older implementations
> without Namespace Identify Descriptor list support.
> 
> Also as the Namespace Identify Descriptor list is the only mandatory
> feature change between 1.2.1 and 1.3.0 we can bump the advertised
> version as well.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>  drivers/nvme/target/admin-cmd.c | 53 +++++++++++++++++++++++++++++++++++++++++
>  drivers/nvme/target/core.c      |  3 ++-
>  drivers/nvme/target/nvmet.h     |  1 +
>  3 files changed, 56 insertions(+), 1 deletion(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web