Skip to contentSkip to conversation

nvme-cli: add ns-descs subcommand

PATCH New Johannes Thumshirn 4 participants 4 messages Jun 23, 2017 – Jan 2, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme-cli: add ns-descs subcommand

NVMe 1.3 defines the "Namespace Identification Descriptor" command in NVMe Identify NS. This command returns a list of so called Namespace Identificastion Descriptors which currently can either be a EUI-64, a NGUID or a UUID.

Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 linux/nvme.h   |  14 +++++++
 nvme-builtin.h |   1 +
 nvme-ioctl.c   |   6 +++
 nvme-ioctl.h   |   1 +
 nvme-print.c   | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 nvme-print.h   |   2 +
 nvme.c         |  63 +++++++++++++++++++++++++++++
 7 files changed, 209 insertions(+)
linux/nvme.h +14 -0
index b2c8dbb2244b..883b5eb8b710 100644
@@ -862,6 +862,20 @@ struct nvme_command {
 	};
 };
 
+#define NVME_IDENTIFY_CMD_LEN 4096
+#define NVME_ID_CNS_NS_DESC_LIST 0x3
+enum {
+	NVME_NIDT_EUI64		= 0x1,
+	NVME_NIDT_NGUID		= 0x2,
+	NVME_NIDT_UUID		= 0x3,
+};
+
+struct nvme_ns_id_desc {
+	__u8 nidt;
+	__u8 nidl;
+	__u16 reserved;
+};
+
 static inline bool nvme_is_write(struct nvme_command *cmd)
 {
 	/*
nvme-builtin.h +1 -0
index 087fc1986b2f..91f361df54a3 100644
@@ -11,6 +11,7 @@ COMMAND_LIST(
 	ENTRY("id-ctrl", "Send NVMe Identify Controller", id_ctrl)
 	ENTRY("id-ns", "Send NVMe Identify Namespace, display structure", id_ns)
 	ENTRY("list-ns", "Send NVMe Identify List, display structure", list_ns)
+	ENTRY("ns-descs", "Send NVMe Namespace Descriptor List, display structure", ns_descs)
 	ENTRY("create-ns", "Creates a namespace with the provided parameters", create_ns)
 	ENTRY("delete-ns", "Deletes a namespace from the controller", delete_ns)
 	ENTRY("attach-ns", "Attaches a namespace to requested controller(s)", attach_ns)
nvme-ioctl.c +6 -0
index a22399ab6169..e3e9af412168 100644
@@ -364,6 +364,12 @@ int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data)
 	return nvme_identify(fd, nsid, (cntid << 16) | cns, data);
 }
 
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
+{
+
+	return nvme_identify(fd, nsid, NVME_ID_CNS_CTRL_LIST, data);
+}
+
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data)
 {
 	struct nvme_admin_cmd cmd = {
nvme-ioctl.h +1 -0
index 3beddf8e2db2..8faf345dcf37 100644
@@ -77,6 +77,7 @@ int nvme_identify_ctrl(int fd, void *data);
 int nvme_identify_ns(int fd, __u32 nsid, bool present, void *data);
 int nvme_identify_ns_list(int fd, __u32 nsid, bool all, void *data);
 int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data);
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data);
 
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data);
 int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log);
nvme-print.c +122 -0

134 lines not on this page · raw message

nvme-print.h +2 -0
index 0502d0d48ee4..d39bc63dc665 100644
@@ -26,6 +26,7 @@ void show_error_log(struct nvme_error_log_page *err_log, int entries, const char
 void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
 void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
 void show_ctrl_registers(void *bar, unsigned int mode);
+void show_nvme_id_ns_descs(void *data);
 
 void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf);
 char *nvme_status_to_string(__u32 status);
@@ -39,6 +40,7 @@ void json_error_log(struct nvme_error_log_page *err_log, int entries, const char
 void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
 void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
 void json_print_list_items(struct list_item *items, unsigned amnt);
+void json_nvme_id_ns_descs(void *data);
 
 
 #endif
nvme.c +63 -0

69 lines not on this page · raw message

Signature · 1 line
2.12.3
Applied
#1 lore raw

PATCH v2 1/1 nvme-cli: add ns-descs subcommand

Quoted 6 lines · Johannes Thumshirn

NVMe 1.3 defines the "Namespace Identification Descriptor" command in NVMe Identify NS. This command returns a list of so called Namespace Identificastion Descriptors which currently can either be a EUI-64, a NGUID or a UUID.

Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>

Thanks! Applied.

#2 lore raw

PATCH v2 1/1 nvme-cli: add ns-descs subcommand

In reply to Johannes Thumshirn

Meh, this still didn't properly resync nvme.h.

Something like this is needed for the current tree:

---

Quoted 1 line

From 79afec638c7a0eb636065403615a78db64ecaec7 Mon Sep 17 00:00:00 2001

From: Christoph Hellwig <[email protected]>
Date: Sat, 24 Jun 2017 09:04:48 +0200
Subject: resync nvme.h with the kernel

Copy over the current nvme.h from the for-4.13 block tree, and adjust a few callers. The biggest tweak is that we can't use the kernel uuid.h and either need to use libuuid or our own definition.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 fabrics.c    |   2 +
 linux/nvme.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 nvme-print.c |   8 +---
 nvme.c       |   4 --
 nvme.h       |  19 ++++----
 5 files changed, 129 insertions(+), 44 deletions(-)
fabrics.c +2 -0
index 87cdba2..da4e04e 100644
@@ -44,6 +44,8 @@
 
 #include "common.h"
 
+#define NVMF_HOSTID_SIZE	36
+
 static struct config {
 	char *nqn;
 	char *transport;
linux/nvme.h +116 -24

260 lines not on this page · raw message

nvme-print.c +2 -6
index dca4a19..637c695 100644
@@ -3,10 +3,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "json.h"
 #include "nvme-models.h"
@@ -622,7 +618,7 @@ void json_nvme_id_ns_descs(void *data)
 
 	root = json_create_object();
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		off = pos + sizeof(*cur);
@@ -680,7 +676,7 @@ void show_nvme_id_ns_descs(void *data)
 	__u8 eui64[8];
 	__u8 nguid[16];
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		if (cur->nidl == 0)
nvme.c +0 -4
index f746b74..4cb7d63 100644
@@ -45,10 +45,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
 #include "nvme-lightnvm.h"
nvme.h +9 -10
index 397a1a5..b796961 100644
@@ -21,6 +21,15 @@
 #include "json.h"
 
 #define unlikely(x) x
+
+#ifdef LIBUUID
+#include <uuid/uuid.h>
+#else
+typedef struct {
+	__u8 b[16];
+} uuid_t;
+#endif
+
 #include "linux/nvme.h"
 
 struct nvme_error_log_page {
@@ -45,16 +54,6 @@ struct nvme_firmware_log_page {
 /* idle and active power scales occupy the last 2 bits of the field */
 #define POWER_SCALE(s) ((s) >> 6)
 
-enum {
-	NVME_ID_CNS_NS			= 0x00,
-	NVME_ID_CNS_CTRL		= 0x01,
-	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
-	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
-	NVME_ID_CNS_NS_PRESENT		= 0x11,
-	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
-	NVME_ID_CNS_CTRL_LIST		= 0x13,
-};
-
 struct nvme_host_mem_buffer {
 	__u32			hsize;
 	__u32			hmdlal;
Signature · 1 line
2.11.0
#3 lore raw

PATCH v2 1/1 nvme-cli: add ns-descs subcommand

Is the following line from the patch below really needed? +#include <linux/uuid.h>

It was causing the following compile error in SLES 11.4 In file included from nvme.h:34,
from nvme-print.h:4,
from nvme-print.c:6:
linux/nvme.h:19:24: error: linux/uuid.h: No such file or directory
make: *** [nvme-print.o] Error 1

When I comment out the #include <linux/uuid.h>, it compiles just fine. I also commented it out on SLES 12.2 and Redhat 7.4 and it compiled just fine without it there as well.

Jeff Lien

-----Original Message-----
From: Linux-nvme [mailto:[email protected]] On Behalf Of Christoph Hellwig
Sent: Saturday, June 24, 2017 2:13 AM
To: Johannes Thumshirn
Cc: Keith Busch; Sagi Grimberg; Linux NVMe Mailinglist; Christoph Hellwig
Subject: Re: [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand

Meh, this still didn't properly resync nvme.h.

Something like this is needed for the current tree:

---

Quoted 1 line

From 79afec638c7a0eb636065403615a78db64ecaec7 Mon Sep 17 00:00:00 2001

From: Christoph Hellwig <[email protected]>
Date: Sat, 24 Jun 2017 09:04:48 +0200
Subject: resync nvme.h with the kernel

Copy over the current nvme.h from the for-4.13 block tree, and adjust a few callers. The biggest tweak is that we can't use the kernel uuid.h and either need to use libuuid or our own definition.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 fabrics.c    |   2 +
 linux/nvme.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 nvme-print.c |   8 +---
 nvme.c       |   4 --
 nvme.h       |  19 ++++----
 5 files changed, 129 insertions(+), 44 deletions(-)
fabrics.c +2 -0
index 87cdba2..da4e04e 100644
@@ -44,6 +44,8 @@
 
 #include "common.h"
 
+#define NVMF_HOSTID_SIZE	36
+
 static struct config {
 	char *nqn;
 	char *transport;
linux/nvme.h +115 -24

256 lines not on this page · raw message

nvme-print.c +2 -6
@@ -3,10 +3,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "json.h"
 #include "nvme-models.h"
@@ -622,7 +618,7 @@ void json_nvme_id_ns_descs(void *data)
 
 	root = json_create_object();
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		off = pos + sizeof(*cur);
@@ -680,7 +676,7 @@ void show_nvme_id_ns_descs(void *data)
 	__u8 eui64[8];
 	__u8 nguid[16];
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		if (cur->nidl == 0)
nvme.c +0 -4
index f746b74..4cb7d63 100644
@@ -45,10 +45,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
 #include "nvme-lightnvm.h"
nvme.h +9 -11
index 397a1a5..b796961 100644
@@ -21,6 +21,15 @@
 #include "json.h"
 
 #define unlikely(x) x
+
+#ifdef LIBUUID
+#include <uuid/uuid.h>
+#else
+typedef struct {
+	__u8 b[16];
+} uuid_t;
+#endif
+
 #include "linux/nvme.h"
 
 struct nvme_error_log_page {
@@ -45,16 +54,6 @@ struct nvme_firmware_log_page {
 /* idle and active power scales occupy the last 2 bits of the field */  #define POWER_SCALE(s) ((s) >> 6)
 
-enum {
-	NVME_ID_CNS_NS			= 0x00,
-	NVME_ID_CNS_CTRL		= 0x01,
-	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
-	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
-	NVME_ID_CNS_NS_PRESENT		= 0x11,
-	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
-	NVME_ID_CNS_CTRL_LIST		= 0x13,
-};
-
 struct nvme_host_mem_buffer {
 	__u32			hsize;
 	__u32			hmdlal;
--

2.11.0

_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme