nvmf: add discovery controller ops
Simplify code that previously needed to check for subsystem type by factoring out the discovery controller operations into a new ops instance. Change-Id: Id87b498e4623451993fe779ffb765be5a6743fd9 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
d535f9b7bb
commit
790bad22c3
@ -153,8 +153,8 @@ nvmf_get_log_page_len(struct spdk_nvme_cmd *cmd)
|
||||
return ((numdu << 16) + numdl + 1) * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
spdk_nvmf_request_exec_status
|
||||
spdk_nvmf_process_discovery_cmd(struct spdk_nvmf_request *req)
|
||||
static int
|
||||
nvmf_discovery_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
||||
{
|
||||
struct spdk_nvmf_session *session = req->conn->sess;
|
||||
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
||||
@ -217,3 +217,34 @@ spdk_nvmf_process_discovery_cmd(struct spdk_nvmf_request *req)
|
||||
|
||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
static int
|
||||
nvmf_discovery_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
|
||||
{
|
||||
/* Discovery controllers do not support I/O queues, so this code should be unreachable. */
|
||||
abort();
|
||||
}
|
||||
|
||||
static void
|
||||
nvmf_discovery_ctrlr_get_data(struct spdk_nvmf_session *session)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nvmf_discovery_ctrlr_detach(struct spdk_nvmf_subsystem *subsystem)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
nvmf_discovery_ctrlr_attach(struct spdk_nvmf_subsystem *subsystem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct spdk_nvmf_ctrlr_ops spdk_nvmf_discovery_ctrlr_ops = {
|
||||
.attach = nvmf_discovery_ctrlr_attach,
|
||||
.ctrlr_get_data = nvmf_discovery_ctrlr_get_data,
|
||||
.process_admin_cmd = nvmf_discovery_ctrlr_process_admin_cmd,
|
||||
.process_io_cmd = nvmf_discovery_ctrlr_process_io_cmd,
|
||||
.detach = nvmf_discovery_ctrlr_detach,
|
||||
};
|
||||
|
@ -283,30 +283,19 @@ spdk_nvmf_request_exec(struct spdk_nvmf_request *req)
|
||||
SPDK_ERRLOG("Non-Fabric command sent to disabled controller\n");
|
||||
rsp->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
|
||||
status = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
} else if (req->conn->type == CONN_TYPE_AQ) {
|
||||
struct spdk_nvmf_subsystem *subsystem;
|
||||
|
||||
subsystem = session->subsys;
|
||||
assert(subsystem != NULL);
|
||||
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
||||
status = spdk_nvmf_process_discovery_cmd(req);
|
||||
} else {
|
||||
if (subsystem->is_removed) {
|
||||
rsp->status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST;
|
||||
status = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
} else {
|
||||
status = subsystem->ops->process_admin_cmd(req);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct spdk_nvmf_subsystem *subsystem;
|
||||
|
||||
subsystem = session->subsys;
|
||||
assert(subsystem != NULL);
|
||||
|
||||
if (subsystem->is_removed) {
|
||||
rsp->status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST;
|
||||
status = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
} else if (req->conn->type == CONN_TYPE_AQ) {
|
||||
status = subsystem->ops->process_admin_cmd(req);
|
||||
} else {
|
||||
status = session->subsys->ops->process_io_cmd(req);
|
||||
status = subsystem->ops->process_io_cmd(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,4 @@ spdk_nvmf_request_exec(struct spdk_nvmf_request *req);
|
||||
|
||||
int spdk_nvmf_request_complete(struct spdk_nvmf_request *req);
|
||||
|
||||
spdk_nvmf_request_exec_status spdk_nvmf_process_discovery_cmd(struct spdk_nvmf_request *req);
|
||||
|
||||
#endif
|
||||
|
@ -125,11 +125,7 @@ spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const ch
|
||||
int
|
||||
spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem)
|
||||
{
|
||||
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) {
|
||||
return subsystem->ops->attach(subsystem);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return subsystem->ops->attach(subsystem);
|
||||
}
|
||||
|
||||
void
|
||||
@ -137,8 +133,8 @@ spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem)
|
||||
{
|
||||
struct spdk_nvmf_session *session;
|
||||
|
||||
/* For NVMe subsystems, check the backing physical device for completions. */
|
||||
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) {
|
||||
/* Check the backing physical device for completions. */
|
||||
if (subsystem->ops->poll_for_completions) {
|
||||
subsystem->ops->poll_for_completions(subsystem);
|
||||
}
|
||||
|
||||
@ -206,7 +202,9 @@ spdk_nvmf_create_subsystem(const char *nqn,
|
||||
TAILQ_INIT(&subsystem->hosts);
|
||||
TAILQ_INIT(&subsystem->sessions);
|
||||
|
||||
if (mode == NVMF_SUBSYSTEM_MODE_DIRECT) {
|
||||
if (type == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
||||
subsystem->ops = &spdk_nvmf_discovery_ctrlr_ops;
|
||||
} else if (mode == NVMF_SUBSYSTEM_MODE_DIRECT) {
|
||||
subsystem->ops = &spdk_nvmf_direct_ctrlr_ops;
|
||||
subsystem->dev.direct.outstanding_admin_cmd_count = 0;
|
||||
} else {
|
||||
|
@ -45,4 +45,6 @@ void spdk_nvmf_get_discovery_log_page(void *buffer, uint64_t offset, uint32_t le
|
||||
|
||||
extern const struct spdk_nvmf_ctrlr_ops spdk_nvmf_direct_ctrlr_ops;
|
||||
extern const struct spdk_nvmf_ctrlr_ops spdk_nvmf_virtual_ctrlr_ops;
|
||||
extern const struct spdk_nvmf_ctrlr_ops spdk_nvmf_discovery_ctrlr_ops;
|
||||
|
||||
#endif /* SPDK_NVMF_SUBSYSTEM_H */
|
||||
|
@ -154,7 +154,7 @@ test_process_discovery_cmd(void)
|
||||
req.rsp = &req_rsp;
|
||||
|
||||
/* no request data check */
|
||||
ret = spdk_nvmf_process_discovery_cmd(&req);
|
||||
ret = nvmf_discovery_ctrlr_process_admin_cmd(&req);
|
||||
CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
|
||||
CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_INVALID_FIELD);
|
||||
|
||||
@ -163,7 +163,7 @@ test_process_discovery_cmd(void)
|
||||
req.cmd->nvme_cmd.cdw10 = SPDK_NVME_IDENTIFY_CTRLR;
|
||||
req.conn->sess = &req_sess;
|
||||
req.data = &req_data;
|
||||
ret = spdk_nvmf_process_discovery_cmd(&req);
|
||||
ret = nvmf_discovery_ctrlr_process_admin_cmd(&req);
|
||||
CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_SUCCESS);
|
||||
CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
|
||||
|
||||
@ -172,17 +172,17 @@ test_process_discovery_cmd(void)
|
||||
req.cmd->nvme_cmd.cdw10 = SPDK_NVME_LOG_DISCOVERY;
|
||||
req.data = &req_page;
|
||||
req.length = req_length;
|
||||
ret = spdk_nvmf_process_discovery_cmd(&req);
|
||||
ret = nvmf_discovery_ctrlr_process_admin_cmd(&req);
|
||||
CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_SUCCESS);
|
||||
CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
|
||||
req.cmd->nvme_cmd.cdw10 = 15;
|
||||
ret = spdk_nvmf_process_discovery_cmd(&req);
|
||||
ret = nvmf_discovery_ctrlr_process_admin_cmd(&req);
|
||||
CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_INVALID_FIELD);
|
||||
CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
|
||||
|
||||
/* Invalid opcode return value check */
|
||||
req.cmd->nvme_cmd.opc = 100;
|
||||
ret = spdk_nvmf_process_discovery_cmd(&req);
|
||||
ret = nvmf_discovery_ctrlr_process_admin_cmd(&req);
|
||||
CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_INVALID_OPCODE);
|
||||
CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
|
||||
}
|
||||
|
@ -135,12 +135,6 @@ spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const ch
|
||||
return false;
|
||||
}
|
||||
|
||||
spdk_nvmf_request_exec_status
|
||||
spdk_nvmf_process_discovery_cmd(struct spdk_nvmf_request *req)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_nvmf_process_fabrics_cmd(void)
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
const struct spdk_nvmf_ctrlr_ops spdk_nvmf_direct_ctrlr_ops;
|
||||
const struct spdk_nvmf_ctrlr_ops spdk_nvmf_virtual_ctrlr_ops;
|
||||
const struct spdk_nvmf_ctrlr_ops spdk_nvmf_discovery_ctrlr_ops;
|
||||
|
||||
#include "subsystem.c"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user