From b8fbb070f8c7b8ccdd19af21470265542fd6cf4e Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 24 Sep 2020 23:57:04 +0900 Subject: [PATCH] lib/nvme: nvme_ctrlr_probe() fails if the controller is being destructed When we support spdk_nvme_detach_async(), any controller may be destructed asynchronously. We will be able to know the case by ctrlr->is_destructed is true and ctrlr is queued in the attached list. nvme_ctrlr_probe() should fail if the found ctrlr satisfies these conditions. Signed-off-by: Shuhei Matsumoto Change-Id: I299c2e5ea3c16cc1239899c163bb9e0eb921ade5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4413 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index bd6a0c39b..43ea4efe8 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -491,8 +491,16 @@ nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid, if (!probe_ctx->probe_cb || probe_ctx->probe_cb(probe_ctx->cb_ctx, trid, &opts)) { ctrlr = nvme_get_ctrlr_by_trid_unsafe(trid); if (ctrlr) { - /* This ctrlr already exists. - * Increase the ref count before calling attach_cb() as the user may + /* This ctrlr already exists. */ + + if (ctrlr->is_destructed) { + /* This ctrlr is being destructed asynchronously. */ + SPDK_ERRLOG("NVMe controller for SSD: %s is being destructed\n", + trid->traddr); + return -EBUSY; + } + + /* Increase the ref count before calling attach_cb() as the user may * call nvme_detach() immediately. */ nvme_ctrlr_proc_get_ref(ctrlr);