From 68e5f0ae00c3a399107cd7d93dab1d475ee72af6 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 25 Feb 2022 02:16:50 +0000 Subject: [PATCH] bdev/nvme: add detach step to discovery_poller If a discovery controller fails at some point, we will want to detach it. This can happen separately from detaching the controller because we are stopping the discovery service. So break out the ctrlr detach operation into a separate phase of the discovery_poller. Signed-off-by: Jim Harris Change-Id: Ia601b767d32bda1c8899d3a95029781c0aeee136 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11772 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto --- module/bdev/nvme/bdev_nvme.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 5bde7a5e2..cc05b6e21 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -4644,29 +4644,24 @@ discovery_poller(void *arg) struct spdk_nvme_transport_id *trid; int rc; - if (ctx->stop) { - bool detach_done = false; - - if (ctx->ctrlr == NULL) { - detach_done = true; - } else if (ctx->detach_ctx == NULL) { + if (ctx->detach_ctx) { + rc = spdk_nvme_detach_poll_async(ctx->detach_ctx); + if (rc != -EAGAIN) { + ctx->detach_ctx = NULL; + ctx->ctrlr = NULL; + } + } else if (ctx->stop) { + if (ctx->ctrlr != NULL) { rc = spdk_nvme_detach_async(ctx->ctrlr, &ctx->detach_ctx); - if (rc != 0) { - DISCOVERY_ERRLOG(ctx, "could not detach discovery ctrlr\n"); - detach_done = true; - } - } else { - rc = spdk_nvme_detach_poll_async(ctx->detach_ctx); - if (rc != -EAGAIN) { - detach_done = true; + if (rc == 0) { + return SPDK_POLLER_BUSY; } + DISCOVERY_ERRLOG(ctx, "could not detach discovery ctrlr\n"); } - if (detach_done) { - spdk_poller_unregister(&ctx->poller); - TAILQ_REMOVE(&g_discovery_ctxs, ctx, tailq); - ctx->stop_cb_fn(ctx->cb_ctx); - free_discovery_ctx(ctx); - } + spdk_poller_unregister(&ctx->poller); + TAILQ_REMOVE(&g_discovery_ctxs, ctx, tailq); + ctx->stop_cb_fn(ctx->cb_ctx); + free_discovery_ctx(ctx); } else if (ctx->probe_ctx == NULL && ctx->ctrlr == NULL) { assert(ctx->entry_ctx_in_use == NULL); ctx->entry_ctx_in_use = TAILQ_FIRST(&ctx->discovery_entry_ctxs);