From b56d8100b63dd13666ce93c76105414614aff7c5 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Fri, 4 Oct 2019 12:29:54 +0200 Subject: [PATCH] bdev/nvme: Move bdev_nvme_ctrlr_destruct function to common.c This is a part of changes required by upcoming patch. This will also require moving bdev_nvme_unregister_cb function to common.c. Signed-off-by: Maciej Szwed Change-Id: Icc14534db4aec903542a94588d22b0ea9d43f47a Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470439 Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- module/bdev/nvme/bdev_nvme.c | 36 ------------------------------------ module/bdev/nvme/common.c | 36 ++++++++++++++++++++++++++++++++++++ module/bdev/nvme/common.h | 2 ++ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 19c142b4a3..fd5c67014a 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -247,42 +247,6 @@ bdev_nvme_poll_adminq(void *arg) return rc; } -static void -bdev_nvme_unregister_cb(void *io_device) -{ - struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = io_device; - uint32_t i; - - pthread_mutex_lock(&g_bdev_nvme_mutex); - TAILQ_REMOVE(&g_nvme_bdev_ctrlrs, nvme_bdev_ctrlr, tailq); - pthread_mutex_unlock(&g_bdev_nvme_mutex); - spdk_nvme_detach(nvme_bdev_ctrlr->ctrlr); - spdk_poller_unregister(&nvme_bdev_ctrlr->adminq_timer_poller); - free(nvme_bdev_ctrlr->name); - for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { - free(nvme_bdev_ctrlr->namespaces[i]); - } - free(nvme_bdev_ctrlr->namespaces); - free(nvme_bdev_ctrlr); -} - -static void -bdev_nvme_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr) -{ - assert(nvme_bdev_ctrlr->destruct); - if (nvme_bdev_ctrlr->opal_dev) { - if (nvme_bdev_ctrlr->opal_poller != NULL) { - spdk_poller_unregister(&nvme_bdev_ctrlr->opal_poller); - /* wait until we get the result */ - while (spdk_opal_revert_poll(nvme_bdev_ctrlr->opal_dev) == -EAGAIN); - } - spdk_opal_close(nvme_bdev_ctrlr->opal_dev); - nvme_bdev_ctrlr->opal_dev = NULL; - } - - spdk_io_device_unregister(nvme_bdev_ctrlr, bdev_nvme_unregister_cb); -} - static int bdev_nvme_destruct(void *ctx) { diff --git a/module/bdev/nvme/common.c b/module/bdev/nvme/common.c index 53335c3a81..52834ae5e9 100644 --- a/module/bdev/nvme/common.c +++ b/module/bdev/nvme/common.c @@ -109,3 +109,39 @@ nvme_bdev_dump_trid_json(struct spdk_nvme_transport_id *trid, struct spdk_json_w spdk_json_write_named_string(w, "subnqn", trid->subnqn); } } + +static void +bdev_nvme_unregister_cb(void *io_device) +{ + struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = io_device; + uint32_t i; + + pthread_mutex_lock(&g_bdev_nvme_mutex); + TAILQ_REMOVE(&g_nvme_bdev_ctrlrs, nvme_bdev_ctrlr, tailq); + pthread_mutex_unlock(&g_bdev_nvme_mutex); + spdk_nvme_detach(nvme_bdev_ctrlr->ctrlr); + spdk_poller_unregister(&nvme_bdev_ctrlr->adminq_timer_poller); + free(nvme_bdev_ctrlr->name); + for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { + free(nvme_bdev_ctrlr->namespaces[i]); + } + free(nvme_bdev_ctrlr->namespaces); + free(nvme_bdev_ctrlr); +} + +void +bdev_nvme_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr) +{ + assert(nvme_bdev_ctrlr->destruct); + if (nvme_bdev_ctrlr->opal_dev) { + if (nvme_bdev_ctrlr->opal_poller != NULL) { + spdk_poller_unregister(&nvme_bdev_ctrlr->opal_poller); + /* wait until we get the result */ + while (spdk_opal_revert_poll(nvme_bdev_ctrlr->opal_dev) == -EAGAIN); + } + spdk_opal_close(nvme_bdev_ctrlr->opal_dev); + nvme_bdev_ctrlr->opal_dev = NULL; + } + + spdk_io_device_unregister(nvme_bdev_ctrlr, bdev_nvme_unregister_cb); +} diff --git a/module/bdev/nvme/common.h b/module/bdev/nvme/common.h index b4fb7771fb..89a65d288b 100644 --- a/module/bdev/nvme/common.h +++ b/module/bdev/nvme/common.h @@ -120,4 +120,6 @@ struct nvme_bdev_ctrlr *nvme_bdev_next_ctrlr(struct nvme_bdev_ctrlr *prev); void nvme_bdev_dump_trid_json(struct spdk_nvme_transport_id *trid, struct spdk_json_write_ctx *w); +void bdev_nvme_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr); + #endif /* SPDK_COMMON_BDEV_NVME_H */