From 3c61b8ca6d8c3196a42bdf97eafb31f490b477a5 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 11 May 2022 17:37:23 +0200 Subject: [PATCH] bdev/nvme: extract stopping discovery to a function For now, it's only called from a single location, bdev_nvme_stop_discovery, but it'll make it possible to stop the discovery from other places. Signed-off-by: Konrad Sztyber Change-Id: I3ba447f30fd8ed23c392d008b3d03cdad30cdb33 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12681 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Tomasz Zawadzki --- module/bdev/nvme/bdev_nvme.c | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 60701fc64..c769497f4 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -4858,6 +4858,33 @@ build_trid_from_log_page_entry(struct spdk_nvme_transport_id *trid, } } +static void +stop_discovery(struct discovery_ctx *ctx, spdk_bdev_nvme_stop_discovery_fn cb_fn, void *cb_ctx) +{ + ctx->stop = true; + ctx->stop_cb_fn = cb_fn; + ctx->cb_ctx = cb_ctx; + + while (!TAILQ_EMPTY(&ctx->nvm_entry_ctxs)) { + struct discovery_entry_ctx *entry_ctx; + struct nvme_path_id path = {}; + + entry_ctx = TAILQ_FIRST(&ctx->nvm_entry_ctxs); + path.trid = entry_ctx->trid; + bdev_nvme_delete(entry_ctx->name, &path); + TAILQ_REMOVE(&ctx->nvm_entry_ctxs, entry_ctx, tailq); + free(entry_ctx); + } + + while (!TAILQ_EMPTY(&ctx->discovery_entry_ctxs)) { + struct discovery_entry_ctx *entry_ctx; + + entry_ctx = TAILQ_FIRST(&ctx->discovery_entry_ctxs); + TAILQ_REMOVE(&ctx->discovery_entry_ctxs, entry_ctx, tailq); + free(entry_ctx); + } +} + static void discovery_remove_controllers(struct discovery_ctx *ctx) { @@ -5242,26 +5269,7 @@ bdev_nvme_stop_discovery(const char *name, spdk_bdev_nvme_stop_discovery_fn cb_f if (ctx->stop) { return -EALREADY; } - ctx->stop = true; - ctx->stop_cb_fn = cb_fn; - ctx->cb_ctx = cb_ctx; - while (!TAILQ_EMPTY(&ctx->nvm_entry_ctxs)) { - struct discovery_entry_ctx *entry_ctx; - struct nvme_path_id path = {}; - - entry_ctx = TAILQ_FIRST(&ctx->nvm_entry_ctxs); - path.trid = entry_ctx->trid; - bdev_nvme_delete(entry_ctx->name, &path); - TAILQ_REMOVE(&ctx->nvm_entry_ctxs, entry_ctx, tailq); - free(entry_ctx); - } - while (!TAILQ_EMPTY(&ctx->discovery_entry_ctxs)) { - struct discovery_entry_ctx *entry_ctx; - - entry_ctx = TAILQ_FIRST(&ctx->discovery_entry_ctxs); - TAILQ_REMOVE(&ctx->discovery_entry_ctxs, entry_ctx, tailq); - free(entry_ctx); - } + stop_discovery(ctx, cb_fn, cb_ctx); return 0; } }