Skip to contentSkip to conversation

nvme-cli: add ns-descs subcommand

PATCH New Johannes Thumshirn 2 participants 3 messages Jun 20, 2017 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 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>
---
 nvme-builtin.h |   1 +
 nvme-ioctl.c   |   6 +++
 nvme-ioctl.h   |   1 +
 nvme-print.c   | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 nvme-print.h   |   2 +
 nvme.c         |  63 ++++++++++++++++++++++++++++
 6 files changed, 201 insertions(+)
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..2f4c87719b8a 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, 0x3, 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 +128 -0

140 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
#1 lore raw

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

nvme-ioctl.c int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data) · line 371

Quoted 5 lines
nvme-ioctl.c +5 -0
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
+{
+
+	return nvme_identify(fd, nsid, 0x3, data);
+}

This should use NVME_ID_CNS_NS_DESC_LIST. nvme-cli doesn't currently have that, but that's just a sign it needs a resync with the kernel nvme.h.

Also personally I find the nvme_identify_* wrappers rather pointless, and thin kthey should be removed instead of adding more.

nvme-print.c line 6

Quoted 9 lines
nvme-print.c +1 -0
index 2da5acd5c9b8..582d15a7c5e8 100644
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <uuid/uuid.h>

libuuid usage in nvme-cli is conditional on LIBUUID. Not that I particularly agree on stubbing this depdency out..

nvme-print.c void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode) · line 608

Quoted 5 lines
nvme-print.c +5 -0
+enum {
+	NVME_NIDT_EUI64		= 0x1,
+	NVME_NIDT_NGUID		= 0x2,
+	NVME_NIDT_UUID		= 0x3,
+};

Should use values from the updated nvme.h:

nvme-print.c void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode) · line 626

Quoted 5 lines
nvme-print.c +5 -0
+	struct nvme_ns_id_desc {
+		__u8 nidt;
+		__u8 nidl;
+		__u16 reserved;
+	};

Same here.

nvme-print.c

Quoted 1 line
nvme-print.c +1 -0
+	for (pos = 0; pos < 0x1000; pos += len) {

Same here for the magic constant.

nvme-print.c void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode) · line 643

Quoted 4 lines
nvme-print.c +4 -0
+		switch (cur->nidt) {
+		case NVME_NIDT_EUI64:
+			memset(eui64, 0, sizeof(eui64_str));
+			memcpy(eui64_desc, data + off, sizeof(eui64_desc));

What's the point of this memcpy? Alignment?

#2 lore raw

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

Quoted 10 lines · Christoph Hellwig

nvme-ioctl.c int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data) · line 371

Quoted 5 lines
nvme-ioctl.c +5 -0
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
+{
+
+	return nvme_identify(fd, nsid, 0x3, data);
+}

This should use NVME_ID_CNS_NS_DESC_LIST. nvme-cli doesn't currently have that, but that's just a sign it needs a resync with the kernel nvme.h.

Quoted 2 lines

Also personally I find the nvme_identify_* wrappers rather pointless, and thin kthey should be removed instead of adding more.

I just wanted to align with the rest of the implementation.

Quoted 9 lines
Quoted 9 lines
nvme-print.c +0 -0
index 2da5acd5c9b8..582d15a7c5e8 100644
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <stdlib.h>
 
Quoted 4 lines

nvme-print.c line 6

Quoted 1 line
nvme-print.c +1 -0
+#include <uuid/uuid.h>

libuuid usage in nvme-cli is conditional on LIBUUID. Not that I particularly agree on stubbing this depdency out..

Sure, just forgot to do.

[...]

Quoted 6 lines

nvme-print.c void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode) · line 643

Quoted 4 lines
nvme-print.c +4 -0
+		switch (cur->nidt) {
+		case NVME_NIDT_EUI64:
+			memset(eui64, 0, sizeof(eui64_str));
+			memcpy(eui64_desc, data + off, sizeof(eui64_desc));

What's the point of this memcpy? Alignment?

Honestly, fighting against the compiler :-D

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at 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