nvmf: simplify Identify command handling

Use the passthrough command for all Identify commands except Identify
Controller.

Also only check the CNS field of CDW10 and use the new enumerated names
instead of magic numbers.

Change-Id: Ia94f820ac85a2d6b2d0ae02659e73c53f1b1a4cd
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-07-20 09:16:35 -07:00
parent b8f95cbb1a
commit 03cd283e43

View File

@ -89,8 +89,7 @@ nvmf_process_discovery_cmd(struct spdk_nvmf_request *req)
switch (cmd->opc) { switch (cmd->opc) {
case SPDK_NVME_OPC_IDENTIFY: case SPDK_NVME_OPC_IDENTIFY:
/* Only identify controller can be supported */ /* Only identify controller can be supported */
if (cmd->cdw10 == 1) { if ((cmd->cdw10 & 0xFF) == SPDK_NVME_IDENTIFY_CTRLR) {
/* identify controller */
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Controller\n"); SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Controller\n");
memcpy(req->data, (char *)&session->vcdata, sizeof(struct spdk_nvme_ctrlr_data)); memcpy(req->data, (char *)&session->vcdata, sizeof(struct spdk_nvme_ctrlr_data));
return true; return true;
@ -156,38 +155,20 @@ nvmf_process_admin_cmd(struct spdk_nvmf_request *req)
switch (cmd->opc) { switch (cmd->opc) {
case SPDK_NVME_OPC_IDENTIFY: case SPDK_NVME_OPC_IDENTIFY:
if (req->data == NULL) { if ((cmd->cdw10 & 0xFF) == SPDK_NVME_IDENTIFY_CTRLR) {
if (req->data == NULL || req->length < sizeof(struct spdk_nvme_ctrlr_data)) {
SPDK_ERRLOG("identify command with no buffer\n"); SPDK_ERRLOG("identify command with no buffer\n");
response->status.sc = SPDK_NVME_SC_INVALID_FIELD; response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
return true; return true;
} }
if (cmd->cdw10 == 0) {
/* identify namespace */
struct spdk_nvme_ns *ns;
const struct spdk_nvme_ns_data *nsdata;
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Namespace\n");
ns = spdk_nvme_ctrlr_get_ns(subsystem->ctrlr, cmd->nsid);
if (ns == NULL) {
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Unsuccessful query for nsid %u\n", cmd->nsid);
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
return true;
}
nsdata = spdk_nvme_ns_get_data(ns);
memcpy(req->data, (char *)nsdata, sizeof(struct spdk_nvme_ns_data));
return true;
} else if (cmd->cdw10 == 1) {
/* identify controller */
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Controller\n"); SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Controller\n");
/* pull from virtual controller context */ /* pull from virtual controller context */
memcpy(req->data, (char *)&session->vcdata, sizeof(struct spdk_nvme_ctrlr_data)); memcpy(req->data, &session->vcdata, sizeof(struct spdk_nvme_ctrlr_data));
return true;
} else {
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Identify Namespace List\n");
response->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
return true; return true;
} }
break; goto passthrough;
case SPDK_NVME_OPC_GET_FEATURES: case SPDK_NVME_OPC_GET_FEATURES:
feature = cmd->cdw10 & 0xff; /* mask out the FID value */ feature = cmd->cdw10 & 0xff; /* mask out the FID value */
switch (feature) { switch (feature) {