bdev: track number of outstanding examinations

Add a new spdk_vbdev_module_examine_done() API which
vbdev modules can use to notify the generic bdev layer
once a base bdev examination is complete.

This is especially required for asynchronous vbdevs
like GPT which must issue I/O to the base bdev.

As part of this patch, add examine callbacks
for both split and error, which for now only call
this new functions.  Later patches will move code from
the init callback to the examine callback for these
modules.  examine callbacks are now required for all
vbdev modules.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I49f2d012d1675b878bcd23afff427c740c6502c7

Reviewed-on: https://review.gerrithub.io/368831
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-07-10 16:02:27 -07:00
parent 7abb7cb83e
commit e075a3dc7a
6 changed files with 49 additions and 7 deletions

View File

@ -119,6 +119,12 @@ struct spdk_bdev_module_if {
*/
void (*examine)(struct spdk_bdev *bdev);
/**
* Count of bdev examinations in progress. Used by generic bdev layer and must
* not be modified by bdev modules.
*/
uint32_t examine_in_progress;
TAILQ_ENTRY(spdk_bdev_module_if) tailq;
};
@ -377,6 +383,8 @@ void spdk_vbdev_register(struct spdk_bdev *vbdev, struct spdk_bdev **base_bdevs,
int base_bdev_count);
void spdk_vbdev_unregister(struct spdk_bdev *vbdev);
void spdk_vbdev_module_examine_done(struct spdk_bdev_module_if *module);
void spdk_bdev_poller_start(struct spdk_bdev_poller **ppoller,
spdk_bdev_poller_fn fn,
void *arg,

View File

@ -74,7 +74,6 @@ struct spdk_bdev_mgr {
#ifdef SPDK_CONFIG_VTUNE
__itt_domain *domain;
#endif
};
static struct spdk_bdev_mgr g_bdev_mgr = {
@ -1384,9 +1383,8 @@ _spdk_bdev_register(struct spdk_bdev *bdev)
TAILQ_INSERT_TAIL(&g_bdev_mgr.bdevs, bdev, link);
TAILQ_FOREACH(vbdev_module, &g_bdev_mgr.vbdev_modules, tailq) {
if (vbdev_module->examine) {
vbdev_module->examine(bdev);
}
vbdev_module->examine_in_progress++;
vbdev_module->examine(bdev);
}
}
@ -1459,6 +1457,13 @@ spdk_vbdev_unregister(struct spdk_bdev *vbdev)
spdk_bdev_unregister(vbdev);
}
void
spdk_vbdev_module_examine_done(struct spdk_bdev_module_if *module)
{
assert(module->examine_in_progress > 0);
module->examine_in_progress--;
}
static bool
__is_bdev_opened_for_write(struct spdk_bdev *bdev)
{
@ -1595,5 +1600,6 @@ spdk_bdev_module_list_add(struct spdk_bdev_module_if *bdev_module)
void
spdk_vbdev_module_list_add(struct spdk_bdev_module_if *vbdev_module)
{
assert(vbdev_module->examine != NULL);
TAILQ_INSERT_TAIL(&g_bdev_mgr.vbdev_modules, vbdev_module, tailq);
}

View File

@ -333,4 +333,11 @@ vbdev_error_fini(void)
}
}
SPDK_VBDEV_MODULE_REGISTER(error, vbdev_error_init, vbdev_error_fini, NULL, NULL, NULL)
static void
vbdev_error_examine(struct spdk_bdev *bdev)
{
spdk_vbdev_module_examine_done(SPDK_GET_BDEV_MODULE(error));
}
SPDK_VBDEV_MODULE_REGISTER(error, vbdev_error_init, vbdev_error_fini, NULL, NULL,
vbdev_error_examine)

View File

@ -522,6 +522,13 @@ vbdev_gpt_fini(void)
static void
vbdev_gpt_examine(struct spdk_bdev *bdev)
{
/*
* TODO: this will get fixed in a later patch which refactors
* the GPT init/register code. For now, nothing is operating
* on the examination counts so just immediately indicate
* that the examination is done.
*/
spdk_vbdev_module_examine_done(SPDK_GET_BDEV_MODULE(gpt));
if (g_gpt_disabled) {
return;
}

View File

@ -425,6 +425,12 @@ vbdev_split_get_ctx_size(void)
return sizeof(struct spdk_io_channel *);
}
static void
vbdev_split_examine(struct spdk_bdev *bdev)
{
spdk_vbdev_module_examine_done(SPDK_GET_BDEV_MODULE(split));
}
SPDK_VBDEV_MODULE_REGISTER(split, vbdev_split_init, vbdev_split_fini, NULL,
vbdev_split_get_ctx_size, NULL)
vbdev_split_get_ctx_size, vbdev_split_examine)
SPDK_LOG_REGISTER_TRACE_FLAG("vbdev_split", SPDK_TRACE_VBDEV_SPLIT)

View File

@ -36,6 +36,8 @@
#include "lib/test_env.c"
#include "bdev.c"
SPDK_DECLARE_BDEV_MODULE(vbdev_ut);
void *
spdk_io_channel_get_ctx(struct spdk_io_channel *ch)
{
@ -109,8 +111,14 @@ static struct spdk_bdev_fn_table fn_table = {
.destruct = stub_destruct,
};
static void
vbdev_ut_examine(struct spdk_bdev *bdev)
{
spdk_vbdev_module_examine_done(SPDK_GET_BDEV_MODULE(vbdev_ut));
}
SPDK_BDEV_MODULE_REGISTER(bdev_ut, NULL, NULL, NULL, NULL)
SPDK_VBDEV_MODULE_REGISTER(vbdev_ut, NULL, NULL, NULL, NULL, NULL)
SPDK_VBDEV_MODULE_REGISTER(vbdev_ut, NULL, NULL, NULL, NULL, vbdev_ut_examine)
static struct spdk_bdev *
allocate_bdev(char *name)