From fbbc8c4f8100d22482747246f816c61297f99cb3 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 2 Sep 2021 21:24:57 +0900 Subject: [PATCH] bdev/nvme: Restore the removed async callbacks for populating namespaces For multipath, when an new nvme_ns is added to an existing nvme_bdev, we need to add the corresponding qpair to all existing nvme_bdev_channels dynamically. The RPC bdev_nvme_attach_controller has to return after that. Hence populating namespace needs to be asynchronous. On the other hand, when an nvme_ns is removed from an existing nvme_bdev, we need to remove the corresponding qpair from all existing nvme_bdev_channels dynamically. Hence depopulating namespace needs to be asynchronous. By the recent refactoring, two callbacks, nvme_ctrlr_populate_namespace_done() and nvme_ctrlr_depopulate_namespace_done() were removed accidentally. We need to restore these. Signed-off-by: Shuhei Matsumoto Change-Id: I37ea2420588cef3a18648dec053f8bd2b884e86b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9392 Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins --- module/bdev/nvme/bdev_nvme.c | 61 +++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index b107f89b8..1d5dd0d0b 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1928,6 +1928,29 @@ timeout_cb(void *cb_arg, struct spdk_nvme_ctrlr *ctrlr, } } +static void +nvme_ctrlr_populate_namespace_done(struct nvme_async_probe_ctx *ctx, + struct nvme_ns *nvme_ns, int rc) +{ + struct nvme_ctrlr *nvme_ctrlr = nvme_ns->ctrlr; + + if (rc == 0) { + pthread_mutex_lock(&nvme_ctrlr->mutex); + nvme_ctrlr->ref++; + pthread_mutex_unlock(&nvme_ctrlr->mutex); + } else { + nvme_ctrlr->namespaces[nvme_ns->id - 1] = NULL; + free(nvme_ns); + } + + if (ctx) { + ctx->populates_in_progress--; + if (ctx->populates_in_progress == 0) { + nvme_ctrlr_populate_namespaces_done(nvme_ctrlr, ctx); + } + } +} + static void nvme_ctrlr_populate_namespace(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *nvme_ns, struct nvme_async_probe_ctx *ctx) @@ -1953,32 +1976,15 @@ nvme_ctrlr_populate_namespace(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *nvm rc = nvme_bdev_create(nvme_ctrlr, nvme_ns); done: - if (rc == 0) { - pthread_mutex_lock(&nvme_ctrlr->mutex); - nvme_ctrlr->ref++; - pthread_mutex_unlock(&nvme_ctrlr->mutex); - } else { - nvme_ctrlr->namespaces[nvme_ns->id - 1] = NULL; - free(nvme_ns); - } - - if (ctx) { - ctx->populates_in_progress--; - if (ctx->populates_in_progress == 0) { - nvme_ctrlr_populate_namespaces_done(nvme_ctrlr, ctx); - } - } + nvme_ctrlr_populate_namespace_done(ctx, nvme_ns, rc); } static void -nvme_ctrlr_depopulate_namespace(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *nvme_ns) +nvme_ctrlr_depopulate_namespace_done(struct nvme_ns *nvme_ns) { - struct nvme_bdev *bdev; + struct nvme_ctrlr *nvme_ctrlr = nvme_ns->ctrlr; - bdev = nvme_ns->bdev; - if (bdev != NULL) { - spdk_bdev_unregister(&bdev->disk, NULL, NULL); - } + assert(nvme_ctrlr != NULL); pthread_mutex_lock(&nvme_ctrlr->mutex); @@ -1995,6 +2001,19 @@ nvme_ctrlr_depopulate_namespace(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *n nvme_ctrlr_release(nvme_ctrlr); } +static void +nvme_ctrlr_depopulate_namespace(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *nvme_ns) +{ + struct nvme_bdev *bdev; + + bdev = nvme_ns->bdev; + if (bdev != NULL) { + spdk_bdev_unregister(&bdev->disk, NULL, NULL); + } + + nvme_ctrlr_depopulate_namespace_done(nvme_ns); +} + static void nvme_ctrlr_populate_namespaces(struct nvme_ctrlr *nvme_ctrlr, struct nvme_async_probe_ctx *ctx)