diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index d8669fbb4e..b306500eac 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -1957,3 +1957,61 @@ spdk_nvmf_ctrlr_abort_aer(struct spdk_nvmf_ctrlr *ctrlr) spdk_nvmf_request_complete(ctrlr->aer_req); ctrlr->aer_req = NULL; } + +int +spdk_nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req) +{ + uint32_t nsid; + struct spdk_nvmf_ns *ns; + struct spdk_bdev *bdev; + struct spdk_bdev_desc *desc; + struct spdk_io_channel *ch; + struct spdk_nvmf_poll_group *group = req->qpair->group; + struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr; + struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; + struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; + + /* pre-set response details for this command */ + response->status.sc = SPDK_NVME_SC_SUCCESS; + nsid = cmd->nsid; + + if (spdk_unlikely(ctrlr == NULL)) { + SPDK_ERRLOG("I/O command sent before CONNECT\n"); + response->status.sct = SPDK_NVME_SCT_GENERIC; + response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR; + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; + } + + if (spdk_unlikely(ctrlr->vcprop.cc.bits.en != 1)) { + SPDK_ERRLOG("I/O command sent to disabled controller\n"); + response->status.sct = SPDK_NVME_SCT_GENERIC; + response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR; + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; + } + + ns = _spdk_nvmf_subsystem_get_ns(ctrlr->subsys, nsid); + if (ns == NULL || ns->bdev == NULL) { + SPDK_ERRLOG("Unsuccessful query for nsid %u\n", cmd->nsid); + response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT; + response->status.dnr = 1; + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; + } + + bdev = ns->bdev; + desc = ns->desc; + ch = group->sgroups[ctrlr->subsys->id].channels[nsid - 1]; + switch (cmd->opc) { + case SPDK_NVME_OPC_READ: + return spdk_nvmf_bdev_ctrlr_read_cmd(bdev, desc, ch, req); + case SPDK_NVME_OPC_WRITE: + return spdk_nvmf_bdev_ctrlr_write_cmd(bdev, desc, ch, req); + case SPDK_NVME_OPC_WRITE_ZEROES: + return spdk_nvmf_bdev_ctrlr_write_zeroes_cmd(bdev, desc, ch, req); + case SPDK_NVME_OPC_FLUSH: + return spdk_nvmf_bdev_ctrlr_flush_cmd(bdev, desc, ch, req); + case SPDK_NVME_OPC_DATASET_MANAGEMENT: + return spdk_nvmf_bdev_ctrlr_dsm_cmd(bdev, desc, ch, req); + default: + return spdk_nvmf_bdev_ctrlr_nvme_passthru_io(bdev, desc, ch, req); + } +} diff --git a/lib/nvmf/ctrlr_bdev.c b/lib/nvmf/ctrlr_bdev.c index 9caccbad10..cf1eccf790 100644 --- a/lib/nvmf/ctrlr_bdev.c +++ b/lib/nvmf/ctrlr_bdev.c @@ -173,9 +173,9 @@ nvmf_bdev_ctrl_queue_io(struct spdk_nvmf_request *req, struct spdk_bdev *bdev, } } -static int -nvmf_bdev_ctrlr_read_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_read_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { uint64_t bdev_num_blocks = spdk_bdev_get_num_blocks(bdev); uint32_t block_size = spdk_bdev_get_block_size(bdev); @@ -217,9 +217,9 @@ nvmf_bdev_ctrlr_read_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; } -static int -nvmf_bdev_ctrlr_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { uint64_t bdev_num_blocks = spdk_bdev_get_num_blocks(bdev); uint32_t block_size = spdk_bdev_get_block_size(bdev); @@ -261,9 +261,9 @@ nvmf_bdev_ctrlr_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; } -static int -nvmf_bdev_ctrlr_write_zeroes_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_write_zeroes_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { uint64_t bdev_num_blocks = spdk_bdev_get_num_blocks(bdev); struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; @@ -296,9 +296,9 @@ nvmf_bdev_ctrlr_write_zeroes_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc * return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; } -static int -nvmf_bdev_ctrlr_flush_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_flush_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; int rc; @@ -442,9 +442,9 @@ nvmf_bdev_ctrlr_unmap(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; } -static int -nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { uint32_t attribute; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; @@ -460,9 +460,9 @@ nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } -static int -nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, - struct spdk_io_channel *ch, struct spdk_nvmf_request *req) +int +spdk_nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { int rc; @@ -480,61 +480,3 @@ nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc * return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; } - -int -spdk_nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req) -{ - uint32_t nsid; - struct spdk_nvmf_ns *ns; - struct spdk_bdev *bdev; - struct spdk_bdev_desc *desc; - struct spdk_io_channel *ch; - struct spdk_nvmf_poll_group *group = req->qpair->group; - struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr; - struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; - struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; - - /* pre-set response details for this command */ - response->status.sc = SPDK_NVME_SC_SUCCESS; - nsid = cmd->nsid; - - if (spdk_unlikely(ctrlr == NULL)) { - SPDK_ERRLOG("I/O command sent before CONNECT\n"); - response->status.sct = SPDK_NVME_SCT_GENERIC; - response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR; - return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; - } - - if (spdk_unlikely(ctrlr->vcprop.cc.bits.en != 1)) { - SPDK_ERRLOG("I/O command sent to disabled controller\n"); - response->status.sct = SPDK_NVME_SCT_GENERIC; - response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR; - return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; - } - - ns = _spdk_nvmf_subsystem_get_ns(ctrlr->subsys, nsid); - if (ns == NULL || ns->bdev == NULL) { - SPDK_ERRLOG("Unsuccessful query for nsid %u\n", cmd->nsid); - response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT; - response->status.dnr = 1; - return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; - } - - bdev = ns->bdev; - desc = ns->desc; - ch = group->sgroups[ctrlr->subsys->id].channels[nsid - 1]; - switch (cmd->opc) { - case SPDK_NVME_OPC_READ: - return nvmf_bdev_ctrlr_read_cmd(bdev, desc, ch, req); - case SPDK_NVME_OPC_WRITE: - return nvmf_bdev_ctrlr_write_cmd(bdev, desc, ch, req); - case SPDK_NVME_OPC_WRITE_ZEROES: - return nvmf_bdev_ctrlr_write_zeroes_cmd(bdev, desc, ch, req); - case SPDK_NVME_OPC_FLUSH: - return nvmf_bdev_ctrlr_flush_cmd(bdev, desc, ch, req); - case SPDK_NVME_OPC_DATASET_MANAGEMENT: - return nvmf_bdev_ctrlr_dsm_cmd(bdev, desc, ch, req); - default: - return nvmf_bdev_ctrlr_nvme_passthru_io(bdev, desc, ch, req); - } -} diff --git a/lib/nvmf/nvmf_internal.h b/lib/nvmf/nvmf_internal.h index 893feedee6..e279d6d29a 100644 --- a/lib/nvmf/nvmf_internal.h +++ b/lib/nvmf/nvmf_internal.h @@ -306,6 +306,18 @@ bool spdk_nvmf_ctrlr_write_zeroes_supported(struct spdk_nvmf_ctrlr *ctrlr); void spdk_nvmf_ctrlr_ns_changed(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid); void spdk_nvmf_bdev_ctrlr_identify_ns(struct spdk_nvmf_ns *ns, struct spdk_nvme_ns_data *nsdata); +int spdk_nvmf_bdev_ctrlr_read_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); +int spdk_nvmf_bdev_ctrlr_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); +int spdk_nvmf_bdev_ctrlr_write_zeroes_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); +int spdk_nvmf_bdev_ctrlr_flush_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); +int spdk_nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); +int spdk_nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, + struct spdk_io_channel *ch, struct spdk_nvmf_request *req); int spdk_nvmf_subsystem_add_ctrlr(struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_ctrlr *ctrlr); diff --git a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c index cc504d14ad..62a7a47167 100644 --- a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c +++ b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c @@ -120,6 +120,42 @@ DEFINE_STUB(spdk_nvmf_transport_qpair_set_sqsize, (struct spdk_nvmf_qpair *qpair), 0); +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_read_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_write_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_write_zeroes_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_flush_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_dsm_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_nvme_passthru_io, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + int spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_cb cb_fn, void *ctx) { diff --git a/test/unit/lib/nvmf/tcp.c/tcp_ut.c b/test/unit/lib/nvmf/tcp.c/tcp_ut.c index 59e7cf6557..1bc87d59b4 100644 --- a/test/unit/lib/nvmf/tcp.c/tcp_ut.c +++ b/test/unit/lib/nvmf/tcp.c/tcp_ut.c @@ -127,6 +127,42 @@ DEFINE_STUB(spdk_nvmf_request_free, (struct spdk_nvmf_request *req), -1); +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_read_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_write_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_write_zeroes_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_flush_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_dsm_cmd, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + +DEFINE_STUB(spdk_nvmf_bdev_ctrlr_nvme_passthru_io, + int, + (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, + struct spdk_nvmf_request *req), + 0); + struct spdk_trace_histories *g_trace_histories; struct spdk_bdev {