From f045d924fc4e819fe2444ecc0d99dcf4e227ed5a Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Sun, 21 Jun 2020 08:55:31 +0900 Subject: [PATCH] lib/nvmf: Factor out abort operation on the specific qpair into a function Factor out abort operation on the specific qpair into a helper function nvmf_qpair_abort_request(). After this refactoring, nvmf_ctrlr_abort_done() calls _nvmf_request_complete() only if the passed status is zero. If the passed status is not zero, nvmf_qpair_abort() is responsible for calling _nvmf_request_complete() instead. Signed-off-by: Shuhei Matsumoto Change-Id: I4828c0e21cc7650210675661d6e1c0fd54c7a2cb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2991 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Michael Haeuptle Reviewed-by: Jim Harris --- lib/nvmf/ctrlr.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index 28380c524..5c0e48487 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -2089,12 +2089,37 @@ nvmf_qpair_abort_aer(struct spdk_nvmf_qpair *qpair, uint16_t cid) return false; } +static void +nvmf_qpair_abort_request(struct spdk_nvmf_qpair *qpair, struct spdk_nvmf_request *req) +{ + uint16_t cid = req->cmd->nvme_cmd.cdw10_bits.abort.cid; + + if (nvmf_qpair_abort_aer(qpair, cid)) { + SPDK_DEBUGLOG(SPDK_LOG_NVMF, "abort ctrlr=%p sqid=%u cid=%u successful\n", + qpair->ctrlr, qpair->qid, cid); + req->rsp->nvme_cpl.cdw0 &= ~1U; /* Command successfully aborted */ + + spdk_nvmf_request_complete(req); + return; + } + + /* TODO: track list of outstanding requests in qpair? */ + SPDK_DEBUGLOG(SPDK_LOG_NVMF, "cid %u not found\n", cid); + + spdk_nvmf_request_complete(req); +} + static void nvmf_ctrlr_abort_done(struct spdk_io_channel_iter *i, int status) { struct spdk_nvmf_request *req = spdk_io_channel_iter_get_ctx(i); - _nvmf_request_complete(req); + if (status == 0) { + /* There was no qpair whose ID matches SQID of the abort command. + * Hence call _nvmf_request_complete() here. + */ + _nvmf_request_complete(req); + } } static void @@ -2103,27 +2128,15 @@ nvmf_ctrlr_abort_on_pg(struct spdk_io_channel_iter *i) struct spdk_nvmf_request *req = spdk_io_channel_iter_get_ctx(i); struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i); struct spdk_nvmf_poll_group *group = spdk_io_channel_get_ctx(ch); - struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; - struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; - uint16_t sqid = cmd->cdw10_bits.abort.sqid; + uint16_t sqid = req->cmd->nvme_cmd.cdw10_bits.abort.sqid; struct spdk_nvmf_qpair *qpair; TAILQ_FOREACH(qpair, &group->qpairs, link) { if (qpair->ctrlr == req->qpair->ctrlr && qpair->qid == sqid) { - uint16_t cid = cmd->cdw10_bits.abort.cid; - /* Found the qpair */ - if (!nvmf_qpair_abort_aer(qpair, cid)) { - /* TODO: track list of outstanding requests in qpair? */ - SPDK_DEBUGLOG(SPDK_LOG_NVMF, "cid %u not found\n", cid); - spdk_for_each_channel_continue(i, -1); - return; - } + nvmf_qpair_abort_request(qpair, req); - SPDK_DEBUGLOG(SPDK_LOG_NVMF, "abort ctrlr=%p sqid=%u cid=%u successful\n", - qpair->ctrlr, sqid, cid); - rsp->cdw0 &= ~1U; /* Command successfully aborted */ /* Return -1 for the status so the iteration across threads stops. */ spdk_for_each_channel_continue(i, -1); return;