Skip to contentSkip to conversation

nvme-cli: Implemented primary and secondary controller

PATCH New Revanth Rajashekar 3 participants 4 messages Jun 19, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-cli: Implemented primary and secondary controller

Signed-off-by Revanth Rajashekar <revanth.rajashekar at intel.com>
---
 linux/nvme.h   |  43 ++++++++++++++++++
 nvme-builtin.h |   2 +
 nvme-ioctl.c   |  22 +++++++++
 nvme-ioctl.h   |   3 ++
 nvme-print.c   | 120 +++++++++++++++++++++++++++++++++++++++++++++++++
 nvme-print.h   |   7 +++
 nvme.c         | 109 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 306 insertions(+)
linux/nvme.h +43 -0
index 8df7255..d6f99d9 100644
@@ -34,6 +34,8 @@
 
 #define NVME_NSID_ALL		0xffffffff
 
+#define NVME_SECONDARY_CONTROLLER_MAX	127
+
 enum nvme_subsys_type {
 	NVME_NQN_DISC	= 1,		/* Discovery type target subsystem */
 	NVME_NQN_NVME	= 2,		/* NVME type target subsystem */
@@ -270,6 +272,44 @@ struct nvme_id_ctrl {
 	__u8			vs[1024];
 };
 
+struct nvme_id_primary_ctrl {
+	__le16	cntlid;
+	__le16	portid;
+	__u8	crt;
+	__u8	rsvd5[27];
+	__le32	vqfrt;
+	__le32	vqrfa;
+	__le16	vqrfap;
+	__le16 	vqprt;
+	__le16	vqfrsm;
+	__le16 	vqgran;
+	__u8	rsvd48[16];
+	__le32	vifrt;
+	__le32	virfa;
+	__le16 	virfap;
+	__le16	viprt;
+	__le16	vifrsm;
+	__le16	vigran;
+	__u8	rsvd80[4016];
+};
+
+struct nvme_secondary_ctrl_entry {
+	__le16	scid;
+	__le16 	pcid;
+	__u8 	scs;
+	__u8 	rsvd5[3];
+	__le16 	vfn;
+	__le16 	nvq;
+	__le16 	nvi;
+	__u8 	rsvd14[18];
+};
+
+struct nvme_id_secondary_ctrl_list {
+	__u8 	num_of_identifiers;
+	__u8	rsvd1[31];
+	struct  nvme_secondary_ctrl_entry sc[NVME_SECONDARY_CONTROLLER_MAX];
+};
+
 enum {
 	NVME_CTRL_ONCS_COMPARE			= 1 << 0,
 	NVME_CTRL_ONCS_WRITE_UNCORRECTABLE	= 1 << 1,
@@ -337,6 +377,8 @@ enum {
 	NVME_ID_CNS_NS_PRESENT		= 0x11,
 	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
 	NVME_ID_CNS_CTRL_LIST		= 0x13,
+	NVME_ID_CNS_PIMARY_CTRL_CAP 		= 0x14,
+	NVME_ID_CNS_SECONDARY_CTRL_LIST 	= 0x15,
 };
 
 enum {
@@ -934,6 +976,7 @@ struct nvme_identify {
 };
 
 #define NVME_IDENTIFY_DATA_SIZE 4096
+#define NVME_VIRTUAL_CTRL_DATA_SIZE 4096
 
 struct nvme_features {
 	__u8			opcode;
nvme-builtin.h +2 -0
index 86b0fff..0b81193 100644
@@ -63,6 +63,8 @@ COMMAND_LIST(
 	ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd)
 	ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive)
 	ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)
+	ENTRY("id-primary-ctrl", "Obtain the primary controller capabilities structure", id_primary_ctrl)
+	ENTRY("id-secondary-ctrl", "Obtain a Secondary Controller list associated with the primary controller", id_secondary_ctrl)
 );
 
 #endif
nvme-ioctl.c +22 -0
index 63ff8fb..493f643 100644
@@ -393,6 +393,28 @@ int nvme_identify_nvmset(int fd, __u16 nvmset_id, void *data)
 	return nvme_identify13(fd, 0, NVME_ID_CNS_NVMSET_LIST, nvmset_id, data);
 }
 
+int nvme_ctrl(int fd, __u32 cdw10, void *data)
+{
+	struct nvme_admin_cmd cmd = {
+		.opcode 	= nvme_admin_virtual_mgmt,
+		.addr 		= (__u64)(uintptr_t) data,
+		.data_len	= NVME_VIRTUAL_CTRL_DATA_SIZE,
+		.cdw10 		= cdw10,
+	};
+
+	return nvme_submit_admin_passthru(fd, &cmd);
+}
+
+int nvme_id_primary_ctrl(int fd, void *data)
+{
+	return nvme_ctrl(fd, NVME_ID_CNS_PIMARY_CTRL_CAP, data);
+}
+
+int nvme_id_secondary_ctrl(int fd, void *data)
+{
+	return nvme_ctrl(fd, NVME_ID_CNS_SECONDARY_CTRL_LIST, data);
+}
+
 int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
                  __u16 lsi, __u32 data_len, void *data)
 {
nvme-ioctl.h +3 -0
index 6d4ac95..4919020 100644
@@ -138,4 +138,7 @@ int nvme_sanitize(int fd, __u8 sanact, __u8 ause, __u8 owpass, __u8 oipbp,
 		  __u8 no_dealloc, __u32 ovrpat);
 int nvme_self_test_start(int fd, __u32 nsid, __u32 cdw10);
 int nvme_self_test_log(int fd, struct nvme_self_test_log *self_test_log);
+int nvme_ctrl(int fd, __u32 cdw10, void *data);
+int nvme_id_primary_ctrl(int fd, void *data);
+int nvme_id_secondary_ctrl(int fd, void *data);
 #endif				/* _NVME_LIB_H */
nvme-print.c +120 -0

132 lines not on this page · raw message

nvme-print.h +7 -0
index 7dd5f34..2d5ab8c 100644
@@ -58,6 +58,13 @@ void json_nvme_id_ns_descs(void *data);
 void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n);
 void json_self_test_log(struct nvme_self_test_log *self_test, const char *devname);
 void json_nvme_id_nvmset(struct nvme_id_nvmset *nvmset, const char *devname);
+void show_nvme_id_primary_ctrl_crt(__u8 crt);
+void show_nvme_id_primary_ctrl(struct nvme_id_primary_ctrl *ctrl);
+void show_nvme_id_secondary_ctrl_entry_scs(__u8 scs);
+void show_nvme_id_secondary_ctrl_entry(struct nvme_secondary_ctrl_entry *ctrl);
+void show_nvme_id_secondary_ctrl_list(struct nvme_id_secondary_ctrl_list *ctrl);
+void json_nvme_id_primary_ctrl(struct nvme_id_primary_ctrl *ctrl);
+void json_nvme_id_secondary_ctrl(struct nvme_id_secondary_ctrl_list *ctrl);
 
 
 #endif
nvme.c +109 -0

115 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 nvme-cli: Implemented primary and secondary controller

nvme-ioctl.c int nvme_identify_nvmset(int fd, __u16 nvmset_id, void *data) · line 399

Quoted 4 lines · Revanth Rajashekar
nvme-ioctl.c +4 -0
+int nvme_ctrl(int fd, __u32 cdw10, void *data)
+{
+	struct nvme_admin_cmd cmd = {
+		.opcode 	= nvme_admin_virtual_mgmt,

A pitfall from not having a capable device to test with: I'm sure you don't possibly mean to use the nvme_admin_virtual_mgmt opcode here.

Just use nvme_identify().

#2 lore raw

PATCH 1/1 nvme-cli: Implemented primary and secondary controller

Quoted 10 lines · Keith Busch

nvme-ioctl.c int nvme_identify_nvmset(int fd, __u16 nvmset_id, void *data) · line 399

Quoted 4 lines · Revanth Rajashekar
nvme-ioctl.c +4 -0
+int nvme_ctrl(int fd, __u32 cdw10, void *data)
+{
+	struct nvme_admin_cmd cmd = {
+		.opcode 	= nvme_admin_virtual_mgmt,

A pitfall from not having a capable device to test with: I'm sure you don't possibly mean to use the nvme_admin_virtual_mgmt opcode here.

Just use nvme_identify().

Btw, I'm really unconfortable with having this code around if it hasn't actually been tested..

#3 lore raw

PATCH 1/1 nvme-cli: Implemented primary and secondary controller

Quoted 2 lines · Christoph Hellwig

Btw, I'm really unconfortable with having this code around if it hasn't actually been tested..

Agreed. If you can't test it, it probably doesn't work.