diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b4b3627..45d16c271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## v18.04: (Upcoming Release) +### Bdev + +Add new optional bdev module interface function, init_complete, to notify bdev modules +when the bdev subsystem initialization is complete. Useful for virtual bdevs that require +notification that the set of initialization examine() calls is complete. + ### RPC The Rpc configuration file section, which was deprecated in v18.01, has been removed. diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 882e9b275..48e0ccd84 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -86,6 +86,14 @@ struct spdk_bdev_module { */ int (*module_init)(void); + /** + * Optional callback for modules that require notification of when + * the bdev subsystem has completed initialization. + * + * Modules are not required to define this function. + */ + void (*init_complete)(void); + /** * Finish function for the module. Called by the spdk application * before the spdk application exits to perform any necessary cleanup. diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index c19334e98..9d7c0fdf1 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -517,6 +517,16 @@ spdk_bdev_module_action_complete(void) } } + /* + * For modules that need to know when subsystem init is complete, + * inform them now. + */ + TAILQ_FOREACH(m, &g_bdev_mgr.bdev_modules, tailq) { + if (m->init_complete) { + m->init_complete(); + } + } + /* * Modules already finished initialization - now that all * the bdev modules have finished their asynchronous I/O diff --git a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c index f98e5b3a3..91d8fae9d 100644 --- a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c @@ -78,6 +78,7 @@ struct spdk_bdev_desc *g_desc; bool g_teardown_done = false; bool g_get_io_channel = true; bool g_create_ch = true; +bool g_init_complete_called = false; static int stub_create_ch(void *io_device, void *ctx_buf) @@ -191,10 +192,17 @@ module_fini(void) { } +static void +init_complete(void) +{ + g_init_complete_called = true; +} + struct spdk_bdev_module bdev_ut_if = { .name = "bdev_ut", .module_init = module_init, .module_fini = module_fini, + .init_complete = init_complete, }; SPDK_BDEV_MODULE_REGISTER(&bdev_ut_if) @@ -281,7 +289,9 @@ bdev_io_tailq_cnt(bdev_io_tailq_t *tailq) static void basic(void) { + g_init_complete_called = false; setup_test(); + CU_ASSERT(g_init_complete_called == true); set_thread(0);