diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index b39899a5d4..2b49819aaa 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -490,7 +490,6 @@ typedef TAILQ_HEAD(bdev_part_tailq, spdk_bdev_part) SPDK_BDEV_PART_TAILQ; void spdk_bdev_part_base_free(struct spdk_bdev_part_base *base); void spdk_bdev_part_free(struct spdk_bdev_part *part); -void spdk_bdev_part_tailq_fini(struct bdev_part_tailq *tailq); void spdk_bdev_part_base_hotremove(struct spdk_bdev *base_bdev, struct bdev_part_tailq *tailq); int spdk_bdev_part_base_construct(struct spdk_bdev_part_base *base, struct spdk_bdev *bdev, spdk_bdev_remove_cb_t remove_cb, diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index d8fe42b6c0..4c4379dc78 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -645,6 +645,50 @@ spdk_bdev_module_finish_done(void) } } +static void +_spdk_bdev_finish_unregister_bdevs_iter(void *cb_arg, int bdeverrno) +{ + struct spdk_bdev *bdev = cb_arg; + + if (bdeverrno && bdev) { + SPDK_WARNLOG("Unable to unregister bdev '%s' during spdk_bdev_finish()\n", + bdev->name); + + /* + * Since the call to spdk_bdev_unregister() failed, we have no way to free this + * bdev; try to continue by manually removing this bdev from the list and continue + * with the next bdev in the list. + */ + TAILQ_REMOVE(&g_bdev_mgr.bdevs, bdev, link); + } + + if (TAILQ_EMPTY(&g_bdev_mgr.bdevs)) { + SPDK_DEBUGLOG(SPDK_LOG_BDEV, "Done unregistering bdevs\n"); + spdk_bdev_module_finish_iter(NULL); + return; + } + + /* + * Unregister the first bdev in the list. + * + * spdk_bdev_unregister() will handle the case where the bdev has open descriptors by + * calling the remove_cb of the descriptors first. + * + * Once this bdev and all of its open descriptors have been cleaned up, this function + * will be called again via the unregister completion callback to continue the cleanup + * process with the next bdev. + */ + bdev = TAILQ_FIRST(&g_bdev_mgr.bdevs); + SPDK_DEBUGLOG(SPDK_LOG_BDEV, "Unregistering bdev '%s'\n", bdev->name); + spdk_bdev_unregister(bdev, _spdk_bdev_finish_unregister_bdevs_iter, bdev); +} + +static void +_spdk_bdev_finish_unregister_bdevs(void) +{ + _spdk_bdev_finish_unregister_bdevs_iter(NULL, 0); +} + void spdk_bdev_finish(spdk_bdev_fini_cb cb_fn, void *cb_arg) { @@ -655,7 +699,7 @@ spdk_bdev_finish(spdk_bdev_fini_cb cb_fn, void *cb_arg) g_fini_cb_fn = cb_fn; g_fini_cb_arg = cb_arg; - spdk_bdev_module_finish_iter(NULL); + _spdk_bdev_finish_unregister_bdevs(); } static struct spdk_bdev_io * @@ -2107,16 +2151,6 @@ spdk_bdev_part_free(struct spdk_bdev_part *part) } } -void -spdk_bdev_part_tailq_fini(struct bdev_part_tailq *tailq) -{ - struct spdk_bdev_part *part, *tmp; - - TAILQ_FOREACH_SAFE(part, tailq, tailq, tmp) { - spdk_bdev_part_free(part); - } -} - void spdk_bdev_part_base_hotremove(struct spdk_bdev *base_bdev, struct bdev_part_tailq *tailq) { diff --git a/lib/bdev/error/vbdev_error.c b/lib/bdev/error/vbdev_error.c index 6a39ae3d28..de5d35b6af 100644 --- a/lib/bdev/error/vbdev_error.c +++ b/lib/bdev/error/vbdev_error.c @@ -309,11 +309,5 @@ vbdev_error_examine(struct spdk_bdev *bdev) spdk_bdev_module_examine_done(SPDK_GET_BDEV_MODULE(error)); } -static void -vbdev_error_fini(void) -{ - spdk_bdev_part_tailq_fini(&g_error_disks); -} - -SPDK_BDEV_MODULE_REGISTER(error, vbdev_error_init, vbdev_error_fini, NULL, NULL, +SPDK_BDEV_MODULE_REGISTER(error, vbdev_error_init, NULL, NULL, NULL, vbdev_error_examine) diff --git a/lib/bdev/gpt/vbdev_gpt.c b/lib/bdev/gpt/vbdev_gpt.c index 8a05de3b65..7488d13c7b 100644 --- a/lib/bdev/gpt/vbdev_gpt.c +++ b/lib/bdev/gpt/vbdev_gpt.c @@ -358,12 +358,6 @@ vbdev_gpt_init(void) return 0; } -static void -vbdev_gpt_fini(void) -{ - spdk_bdev_part_tailq_fini(&g_gpt_disks); -} - static void vbdev_gpt_examine(struct spdk_bdev *bdev) { @@ -381,6 +375,6 @@ vbdev_gpt_examine(struct spdk_bdev *bdev) } } -SPDK_BDEV_MODULE_REGISTER(gpt, vbdev_gpt_init, vbdev_gpt_fini, NULL, +SPDK_BDEV_MODULE_REGISTER(gpt, vbdev_gpt_init, NULL, NULL, NULL, vbdev_gpt_examine) SPDK_LOG_REGISTER_COMPONENT("vbdev_gpt", SPDK_LOG_VBDEV_GPT) diff --git a/lib/bdev/lvol/vbdev_lvol.c b/lib/bdev/lvol/vbdev_lvol.c index 65ee6e0cdc..f7e34c5447 100644 --- a/lib/bdev/lvol/vbdev_lvol.c +++ b/lib/bdev/lvol/vbdev_lvol.c @@ -794,26 +794,6 @@ vbdev_lvs_init(void) return 0; } -static void -vbdev_lvs_fini_next(void *cb_arg, int lvserrno) -{ - struct lvol_store_bdev *lvs_bdev; - - lvs_bdev = TAILQ_FIRST(&g_spdk_lvol_pairs); - if (lvs_bdev == NULL) { - spdk_bdev_module_finish_done(); - return; - } - - vbdev_lvs_unload(lvs_bdev->lvs, vbdev_lvs_fini_next, cb_arg); -} - -static void -vbdev_lvs_fini(void) -{ - vbdev_lvs_fini_next(NULL, 0); -} - static int vbdev_lvs_get_ctx_size(void) { @@ -942,7 +922,6 @@ vbdev_lvs_examine(struct spdk_bdev *bdev) spdk_lvs_load(bs_dev, _vbdev_lvs_examine_cb, req); } -SPDK_BDEV_MODULE_REGISTER(lvol, vbdev_lvs_init, vbdev_lvs_fini, NULL, vbdev_lvs_get_ctx_size, +SPDK_BDEV_MODULE_REGISTER(lvol, vbdev_lvs_init, NULL, NULL, vbdev_lvs_get_ctx_size, vbdev_lvs_examine) -SPDK_BDEV_MODULE_ASYNC_FINI(lvol); SPDK_LOG_REGISTER_COMPONENT("vbdev_lvol", SPDK_LOG_VBDEV_LVOL); diff --git a/lib/bdev/malloc/bdev_malloc.c b/lib/bdev/malloc/bdev_malloc.c index 47e16a6ae6..a460dc5ae9 100644 --- a/lib/bdev/malloc/bdev_malloc.c +++ b/lib/bdev/malloc/bdev_malloc.c @@ -93,7 +93,6 @@ static TAILQ_HEAD(, malloc_disk) g_malloc_disks = TAILQ_HEAD_INITIALIZER(g_mallo int malloc_disk_count = 0; static int bdev_malloc_initialize(void); -static void bdev_malloc_finish(void); static void bdev_malloc_get_spdk_running_config(FILE *fp); static int @@ -102,7 +101,7 @@ bdev_malloc_get_ctx_size(void) return sizeof(struct malloc_task) + spdk_copy_task_size(); } -SPDK_BDEV_MODULE_REGISTER(malloc, bdev_malloc_initialize, bdev_malloc_finish, +SPDK_BDEV_MODULE_REGISTER(malloc, bdev_malloc_initialize, NULL, bdev_malloc_get_spdk_running_config, bdev_malloc_get_ctx_size, NULL) static void @@ -448,15 +447,6 @@ end: return rc; } -static void bdev_malloc_finish(void) -{ - struct malloc_disk *mdisk, *tmp; - - TAILQ_FOREACH_SAFE(mdisk, &g_malloc_disks, link, tmp) { - spdk_bdev_unregister(&mdisk->disk, NULL, NULL); - } -} - static void bdev_malloc_get_spdk_running_config(FILE *fp) { diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index f20798cca7..7792aea03b 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -1110,15 +1110,9 @@ end: static void bdev_nvme_library_fini(void) { - struct nvme_bdev *nvme_bdev, *btmp; - if (g_nvme_hotplug_enabled) { spdk_poller_unregister(&g_hotplug_poller); } - - TAILQ_FOREACH_SAFE(nvme_bdev, &g_nvme_bdevs, link, btmp) { - spdk_bdev_unregister(&nvme_bdev->disk, NULL, NULL); - } } static int diff --git a/lib/bdev/pmem/bdev_pmem.c b/lib/bdev/pmem/bdev_pmem.c index 734fcc37c1..8494025447 100644 --- a/lib/bdev/pmem/bdev_pmem.c +++ b/lib/bdev/pmem/bdev_pmem.c @@ -388,13 +388,6 @@ bdev_pmem_finish_done(void *io_device) static void bdev_pmem_finish(void) { - struct pmem_disk *pdisk, *tmp; - - TAILQ_FOREACH_SAFE(pdisk, &g_pmem_disks, tailq, tmp) { - bdev_pmem_destruct(pdisk); - spdk_bdev_unregister(&pdisk->disk, NULL, NULL); - } - spdk_io_device_unregister(&g_pmem_disks, bdev_pmem_finish_done); } diff --git a/lib/bdev/rbd/bdev_rbd.c b/lib/bdev/rbd/bdev_rbd.c index 79f0504fd2..ec872b2b53 100644 --- a/lib/bdev/rbd/bdev_rbd.c +++ b/lib/bdev/rbd/bdev_rbd.c @@ -51,7 +51,6 @@ #define SPDK_RBD_QUEUE_DEPTH 128 -static TAILQ_HEAD(, bdev_rbd) g_rbds = TAILQ_HEAD_INITIALIZER(g_rbds); static int bdev_rbd_count = 0; struct bdev_rbd { @@ -199,9 +198,8 @@ bdev_rbd_start_aio(rbd_image_t image, struct spdk_bdev_io *bdev_io, } static int bdev_rbd_library_init(void); -static void bdev_rbd_library_fini(void); -SPDK_BDEV_MODULE_REGISTER(rbd, bdev_rbd_library_init, bdev_rbd_library_fini, NULL, +SPDK_BDEV_MODULE_REGISTER(rbd, bdev_rbd_library_init, NULL, NULL, NULL, NULL) static int64_t @@ -232,7 +230,6 @@ bdev_rbd_destruct(void *ctx) { struct bdev_rbd *rbd = ctx; - TAILQ_REMOVE(&g_rbds, rbd, tailq); bdev_rbd_free(rbd); return 0; } @@ -470,16 +467,6 @@ static const struct spdk_bdev_fn_table rbd_fn_table = { .dump_config_json = bdev_rbd_dump_config_json, }; -static void -bdev_rbd_library_fini(void) -{ - struct bdev_rbd *rbd, *btmp; - - TAILQ_FOREACH_SAFE(rbd, &g_rbds, tailq, btmp) { - spdk_bdev_unregister(&rbd->disk, NULL, NULL); - } -} - struct spdk_bdev * spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block_size) { @@ -542,7 +529,6 @@ spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block return NULL; } - TAILQ_INSERT_TAIL(&g_rbds, rbd, tailq); return &rbd->disk; } diff --git a/lib/bdev/split/vbdev_split.c b/lib/bdev/split/vbdev_split.c index 047391d7f8..158b4a5aee 100644 --- a/lib/bdev/split/vbdev_split.c +++ b/lib/bdev/split/vbdev_split.c @@ -264,12 +264,7 @@ vbdev_split_examine(struct spdk_bdev *bdev) spdk_bdev_module_examine_done(SPDK_GET_BDEV_MODULE(split)); } -static void -vbdev_split_fini(void) -{ - spdk_bdev_part_tailq_fini(&g_split_disks); -} -SPDK_BDEV_MODULE_REGISTER(split, vbdev_split_init, vbdev_split_fini, NULL, +SPDK_BDEV_MODULE_REGISTER(split, vbdev_split_init, NULL, NULL, NULL, vbdev_split_examine) SPDK_LOG_REGISTER_COMPONENT("vbdev_split", SPDK_LOG_VBDEV_SPLIT)