bdev/error: Remove config of an error vbdev at the removal of the vbdev

Remove configuration of an error vbdev at the removal of the vbdev.
This will lose the strict compatibility but the next patch will make
possible for us to add the removed config dynamically.

This patch will make the implementation cleaner and will not lose
any usability.

Change-Id: Idea7767ab5424427f912c82c66ff7d59d28108ab
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/403915
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-03-26 08:30:03 +09:00 committed by Daniel Verkamp
parent 2c7e3a05e3
commit 8d57caa11c

View File

@ -82,6 +82,8 @@ static void vbdev_error_fini(void);
static void vbdev_error_examine(struct spdk_bdev *bdev);
static int vbdev_error_config_json(struct spdk_json_write_ctx *w);
static int vbdev_error_config_remove(const char *base_bdev_name);
static struct spdk_bdev_module error_if = {
.name = "error",
.module_init = vbdev_error_init,
@ -209,9 +211,16 @@ static int
vbdev_error_destruct(void *ctx)
{
struct error_disk *error_disk = ctx;
struct spdk_bdev *base_bdev = error_disk->part.base->bdev;
int rc;
rc = vbdev_error_config_remove(base_bdev->name);
if (rc != 0) {
SPDK_ERRLOG("vbdev_error_config_remove() failed\n");
}
spdk_bdev_part_free(&error_disk->part);
return 0;
return rc;
}
static int
@ -316,6 +325,36 @@ vbdev_error_clear_config(void)
}
}
static struct spdk_vbdev_error_config *
vbdev_error_config_find_by_base_name(const char *base_bdev_name)
{
struct spdk_vbdev_error_config *cfg;
TAILQ_FOREACH(cfg, &g_error_config, tailq) {
if (strcmp(cfg->base_bdev, base_bdev_name) == 0) {
return cfg;
}
}
return NULL;
}
static int
vbdev_error_config_remove(const char *base_bdev_name)
{
struct spdk_vbdev_error_config *cfg;
cfg = vbdev_error_config_find_by_base_name(base_bdev_name);
if (!cfg) {
return -ENOENT;
}
TAILQ_REMOVE(&g_error_config, cfg, tailq);
free(cfg->base_bdev);
free(cfg);
return 0;
}
static int
vbdev_error_init(void)
{
@ -378,17 +417,12 @@ vbdev_error_examine(struct spdk_bdev *bdev)
struct spdk_vbdev_error_config *cfg;
int rc;
TAILQ_FOREACH(cfg, &g_error_config, tailq) {
if (strcmp(cfg->base_bdev, bdev->name) != 0) {
continue;
}
cfg = vbdev_error_config_find_by_base_name(bdev->name);
if (cfg != NULL) {
rc = spdk_vbdev_error_create(bdev);
if (rc != 0) {
SPDK_ERRLOG("could not create error vbdev for bdev %s\n", bdev->name);
}
break;
}
spdk_bdev_module_examine_done(&error_if);