bdev: add hook for bdev registration

This allows virtual blockdevs to inspect newly-added bdevs and
potentially insert themselves automatically.

Change-Id: If567a950d753e5f08861a5de22a2e1350376e50f
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/362077
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Daniel Verkamp 2017-02-10 13:18:49 -07:00 committed by Ben Walker
parent f198553530
commit cd88c7c53b
4 changed files with 19 additions and 3 deletions

View File

@ -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) \
{ \

View File

@ -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

View File

@ -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)

View File

@ -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)