bdev: unregister all bdevs in spdk_bdev_finish()
Instead of requiring each bdev module to track its own bdevs and clean them up during its fini callback, we can walk the list of registered bdevs during spdk_bdev_finish() and call spdk_bdev_unregister() on each one of them before cleaning up the bdev modules. Change-Id: I01816707c9100f66f542bfd73b90bcb0e0fb0c0c Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/389878 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
450ffbc63a
commit
453f5ae9f6
@ -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,
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user