From: Johannes Thumshirn <jthumshirn@suse.de>
To: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Keith Busch <keith.busch@intel.com>
Cc: Hannes Reinecke <hare@suse.de>,
maxg@mellanox.com,
Linux NVMe Mailinglist <linux-nvme@lists.infradead.org>,
Linux Kernel Mailinglist <linux-kernel@vger.kernel.org>,
Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH v5 7/9] nvme: get list of namespace descriptors
Date: Tue, 6 Jun 2017 16:36:15 +0200 [thread overview]
Message-ID: <20170606143617.32143-8-jthumshirn@suse.de> (raw)
In-Reply-To: <20170606143617.32143-1-jthumshirn@suse.de>
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>
Reviewed-by: Hannes Reinecke <hare@suse.com>
---
drivers/nvme/host/core.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
drivers/nvme/host/nvme.h | 1 +
2 files changed, 80 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7b254be16887..b0c7689427da 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -643,6 +643,77 @@ int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
return error;
}
+static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
+{
+ struct nvme_command c = { };
+ int status;
+ void *data;
+ int pos;
+ int len;
+
+ c.identify.opcode = nvme_admin_identify;
+ c.identify.nsid = cpu_to_le32(nsid);
+ c.identify.cns = NVME_ID_CNS_NS_DESC_LIST;
+
+ data = kzalloc(NVME_IDENTIFY_DATA_SIZE, GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ status = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, data,
+ NVME_IDENTIFY_DATA_SIZE);
+ if (status)
+ goto free_data;
+
+ for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
+ struct nvme_ns_identifier_hdr *cur = data + pos;
+
+ if (cur->nidl == 0)
+ break;
+
+ switch (cur->nidt) {
+ case NVME_NIDT_EUI64:
+ if (cur->nidl != NVME_NIDT_EUI64_LEN) {
+ dev_warn(ns->ctrl->device,
+ "ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
+ cur->nidl);
+ goto free_data;
+ }
+ len = NVME_NIDT_EUI64_LEN;
+ memcpy(ns->eui, data + pos + sizeof(*cur), len);
+ break;
+ case NVME_NIDT_NGUID:
+ if (cur->nidl != NVME_NIDT_NGUID_LEN) {
+ dev_warn(ns->ctrl->device,
+ "ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
+ cur->nidl);
+ goto free_data;
+ }
+ len = NVME_NIDT_NGUID_LEN;
+ memcpy(ns->nguid, data + pos + sizeof(*cur), len);
+ break;
+ case NVME_NIDT_UUID:
+ if (cur->nidl != NVME_NIDT_UUID_LEN) {
+ dev_warn(ns->ctrl->device,
+ "ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
+ cur->nidl);
+ goto free_data;
+ }
+ len = NVME_NIDT_UUID_LEN;
+ memcpy(ns->uuid, data + pos + sizeof(*cur), len);
+ break;
+ default:
+ /* Skip unnkown types */
+ len = cur->nidl;
+ break;
+ }
+
+ len += sizeof(*cur);
+ }
+free_data:
+ kfree(data);
+ return status;
+}
+
static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *ns_list)
{
struct nvme_command c = { };
@@ -1017,6 +1088,14 @@ 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)) {
+ /* Don't treat error as fatal we potentially
+ * already have a NGUID or EUI-64
+ */
+ if (nvme_identify_ns_descs(ns, ns->ns_id))
+ dev_warn(ns->ctrl->dev,
+ "%s: Identify Descriptors failed\n", __func__);
+ }
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.3
next prev parent reply other threads:[~2017-06-06 14:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 14:36 [PATCH v5 0/9] Implement NVMe Namespace Descriptor Identification Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 1/9] scatterlist: add sg_zeroout_area() helper Johannes Thumshirn
2017-06-06 18:26 ` Sagi Grimberg
2017-06-07 7:00 ` Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 2/9] nvmet: use NVME_IDENTIFY_DATA_SIZE Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 3/9] nvme: introduce NVMe Namespace Identification Descriptor structures Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 4/9] nvme: rename uuid to nguid in nvme_ns Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 5/9] nvmet: implement namespace identify descriptor list Johannes Thumshirn
2017-06-07 8:55 ` Max Gurtovoy
2017-06-06 14:36 ` [PATCH v5 6/9] nvmet: add uuid field to nvme_ns and populate via configfs Johannes Thumshirn
2017-06-06 14:36 ` Johannes Thumshirn [this message]
2017-06-06 18:30 ` [PATCH v5 7/9] nvme: get list of namespace descriptors Sagi Grimberg
2017-06-07 6:57 ` Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 8/9] nvme: provide UUID value to userspace Johannes Thumshirn
2017-06-06 14:36 ` [PATCH v5 9/9] nvmet: allow overriding the NVMe VS via configfs Johannes Thumshirn
2017-06-07 4:47 ` Guan Junxiong
2017-06-06 18:27 ` [PATCH v5 0/9] Implement NVMe Namespace Descriptor Identification Sagi Grimberg
2017-06-07 6:59 ` Johannes Thumshirn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170606143617.32143-8-jthumshirn@suse.de \
--to=jthumshirn@suse.de \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=keith.busch@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=maxg@mellanox.com \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®