From 5b2e9b229c8c2845637e2cdf37f6a2289268104e Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 7 Jul 2021 13:55:06 +0200 Subject: [PATCH] nvme: move aborted requests to a separate queue before completion This avoids an infite loop when user sends and then immediately aborts all requests while the transport cannot submit them (returning -EAGAIN). It might happen in two cases: 1) if the transport doesn't have any free requests or 2) if the qpair is still in the NVME_QPAIR_CONNECTING state. Signed-off-by: Konrad Sztyber Change-Id: Ia1d0b7c93f387524be0ad39597ec49851e1d3af7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8711 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme_qpair.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/nvme/nvme_qpair.c b/lib/nvme/nvme_qpair.c index d922600c1d..1414b09914 100644 --- a/lib/nvme/nvme_qpair.c +++ b/lib/nvme/nvme_qpair.c @@ -572,10 +572,18 @@ static void _nvme_qpair_complete_abort_queued_reqs(struct spdk_nvme_qpair *qpair) { struct nvme_request *req; + STAILQ_HEAD(, nvme_request) tmp; - while (!STAILQ_EMPTY(&qpair->aborting_queued_req)) { - req = STAILQ_FIRST(&qpair->aborting_queued_req); - STAILQ_REMOVE_HEAD(&qpair->aborting_queued_req, stailq); + if (spdk_likely(STAILQ_EMPTY(&qpair->aborting_queued_req))) { + return; + } + + STAILQ_INIT(&tmp); + STAILQ_SWAP(&tmp, &qpair->aborting_queued_req, nvme_request); + + while (!STAILQ_EMPTY(&tmp)) { + req = STAILQ_FIRST(&tmp); + STAILQ_REMOVE_HEAD(&tmp, stailq); nvme_qpair_manual_complete_request(qpair, req, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SC_ABORTED_BY_REQUEST, 1, true); }