From 662c0200bea95d4f99db10e1cf6f98cefd791147 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 24 Aug 2021 14:20:56 +0200 Subject: [PATCH] nvme/pcie: make sure qpair connection is finished in delete When deleting an IO qpair, make sure that it's connection process is finished (i.e. create CQ/SQ commands are completed) before freeing it. Signed-off-by: Konrad Sztyber Change-Id: I487dcef390d73ff4a7264ff97d965c9030916840 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9279 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Ben Walker --- lib/nvme/nvme_pcie_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/nvme/nvme_pcie_common.c b/lib/nvme/nvme_pcie_common.c index aac8c9b32..f4ff10574 100644 --- a/lib/nvme/nvme_pcie_common.c +++ b/lib/nvme/nvme_pcie_common.c @@ -1047,6 +1047,16 @@ nvme_pcie_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ goto free; } + /* If attempting to delete a qpair that's still being connected, we have to wait until it's + * finished, so that we don't free it while it's waiting for the create cq/sq callbacks. + */ + while (nvme_qpair_get_state(qpair) == NVME_QPAIR_CONNECTING) { + rc = spdk_nvme_qpair_process_completions(ctrlr->adminq, 0); + if (rc < 0) { + break; + } + } + status = calloc(1, sizeof(*status)); if (!status) { SPDK_ERRLOG("Failed to allocate status tracker\n");