Commit f045d924 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarMichael Haeuptle <michaelhaeuptle@gmail.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9975d4a1
Loading
Loading
Loading
Loading
+28 −15
Original line number Diff line number Diff line
@@ -2089,13 +2089,38 @@ 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);

	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
nvmf_ctrlr_abort_on_pg(struct spdk_io_channel_iter *i)
@@ -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;