diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 22221047e7..ca2890333f 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -115,6 +115,13 @@ struct spdk_bdev_module_if { */ int (*get_ctx_size)(void); + /** + * Notification that a bdev has been registered. + * Virtual bdev modules may use this to inspect the newly-added bdev and automatically + * create their own vbdevs. + */ + void (*bdev_registered)(struct spdk_bdev *bdev); + TAILQ_ENTRY(spdk_bdev_module_if) tailq; }; @@ -394,12 +401,13 @@ spdk_bdev_io_from_ctx(void *ctx) spdk_bdev_module_list_add(&init_fn ## _if); \ } -#define SPDK_VBDEV_MODULE_REGISTER(init_fn, fini_fn, config_fn, ctx_size_fn) \ +#define SPDK_VBDEV_MODULE_REGISTER(init_fn, fini_fn, config_fn, ctx_size_fn, bdev_registered_fn)\ static struct spdk_bdev_module_if init_fn ## _if = { \ .module_init = init_fn, \ .module_fini = fini_fn, \ .config_text = config_fn, \ .get_ctx_size = ctx_size_fn, \ + .bdev_registered = bdev_registered_fn, \ }; \ __attribute__((constructor)) static void init_fn ## _init(void) \ { \ diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 4c720be692..9b165df1a5 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -1078,6 +1078,8 @@ spdk_bdev_io_get_nvme_status(const struct spdk_bdev_io *bdev_io, int *sct, int * void spdk_bdev_register(struct spdk_bdev *bdev) { + struct spdk_bdev_module_if *vbdev_module; + /* initialize the reset generation value to zero */ bdev->gencnt = 0; @@ -1088,6 +1090,12 @@ spdk_bdev_register(struct spdk_bdev *bdev) bdev->status = SPDK_BDEV_STATUS_UNCLAIMED; SPDK_TRACELOG(SPDK_TRACE_DEBUG, "Inserting bdev %s into list\n", bdev->name); TAILQ_INSERT_TAIL(&g_bdev_mgr.bdevs, bdev, link); + + TAILQ_FOREACH(vbdev_module, &g_bdev_mgr.vbdev_modules, tailq) { + if (vbdev_module->bdev_registered) { + vbdev_module->bdev_registered(bdev); + } + } } void diff --git a/lib/bdev/error/vbdev_error.c b/lib/bdev/error/vbdev_error.c index ca22a607eb..c6cfc6a09e 100644 --- a/lib/bdev/error/vbdev_error.c +++ b/lib/bdev/error/vbdev_error.c @@ -268,4 +268,4 @@ vbdev_error_fini(void) } } -SPDK_VBDEV_MODULE_REGISTER(vbdev_error_init, vbdev_error_fini, NULL, NULL) +SPDK_VBDEV_MODULE_REGISTER(vbdev_error_init, vbdev_error_fini, NULL, NULL, NULL) diff --git a/lib/bdev/split/vbdev_split.c b/lib/bdev/split/vbdev_split.c index 36a7972018..2982bd6000 100644 --- a/lib/bdev/split/vbdev_split.c +++ b/lib/bdev/split/vbdev_split.c @@ -404,5 +404,5 @@ vbdev_split_fini(void) } } -SPDK_VBDEV_MODULE_REGISTER(vbdev_split_init, vbdev_split_fini, NULL, NULL) +SPDK_VBDEV_MODULE_REGISTER(vbdev_split_init, vbdev_split_fini, NULL, NULL, NULL) SPDK_LOG_REGISTER_TRACE_FLAG("vbdev_split", SPDK_TRACE_VBDEV_SPLIT)