bdev/raid: Factor out removing base bdevs into a function

This is a preparation to add completion callback to the
destroy_raid_bdev RPC.

This patch doesn't change any behavior. This patch just factors out
code into a function and move it to raid_bdev.c.

Change-Id: Ia86741ec686ffd85e4d826caf4442292963922ec
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450567
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-04-09 08:19:41 +09:00 committed by Darek Stojaczyk
parent e1c9791225
commit 0839680db3
3 changed files with 35 additions and 14 deletions

View File

@ -64,11 +64,11 @@ struct raid_all_tailq g_raid_bdev_list;
struct raid_offline_tailq g_raid_bdev_offline_list;
/* Function declarations */
static void raid_bdev_examine(struct spdk_bdev *bdev);
static int raid_bdev_init(void);
static void raid_bdev_waitq_io_process(void *ctx);
static void raid_bdev_deconfigure(struct raid_bdev *raid_bdev);
static void raid_bdev_examine(struct spdk_bdev *bdev);
static int raid_bdev_init(void);
static void raid_bdev_waitq_io_process(void *ctx);
static void raid_bdev_deconfigure(struct raid_bdev *raid_bdev);
static void raid_bdev_remove_base_bdev(void *ctx);
/*
* brief:
@ -1778,7 +1778,7 @@ raid_bdev_find_by_base_bdev(struct spdk_bdev *base_bdev, struct raid_bdev **_rai
* returns:
* none
*/
void
static void
raid_bdev_remove_base_bdev(void *ctx)
{
struct spdk_bdev *base_bdev = ctx;
@ -1813,6 +1813,33 @@ raid_bdev_remove_base_bdev(void *ctx)
raid_bdev_deconfigure(raid_bdev);
}
/*
* brief:
* Remove base bdevs from the raid bdev one by one. Skip any base bdev which
* doesn't exist.
* params:
* raid_cfg - pointer to raid bdev config.
*/
void
raid_bdev_remove_base_devices(struct raid_bdev_config *raid_cfg)
{
struct spdk_bdev *base_bdev;
uint8_t i;
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_devices\n");
for (i = 0; i < raid_cfg->num_base_bdevs; i++) {
base_bdev = spdk_bdev_get_by_name(raid_cfg->base_bdev[i].name);
if (base_bdev == NULL) {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "base bdev %s doesn't exist now\n",
raid_cfg->base_bdev[i].name);
continue;
}
raid_bdev_remove_base_bdev(base_bdev);
}
}
/*
* brief:
* raid_bdev_add_base_device function is the actual function which either adds

View File

@ -215,8 +215,8 @@ extern struct raid_offline_tailq g_raid_bdev_offline_list;
extern struct raid_config g_raid_config;
int raid_bdev_create(struct raid_bdev_config *raid_cfg);
void raid_bdev_remove_base_bdev(void *ctx);
int raid_bdev_add_base_devices(struct raid_bdev_config *raid_cfg);
void raid_bdev_remove_base_devices(struct raid_bdev_config *raid_cfg);
int raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
int raid_level, struct raid_bdev_config **_raid_cfg);
int raid_bdev_config_add_base_bdev(struct raid_bdev_config *raid_cfg,

View File

@ -385,7 +385,6 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
struct rpc_destroy_raid_bdev req = {};
struct spdk_json_write_ctx *w;
struct raid_bdev_config *raid_cfg = NULL;
struct spdk_bdev *base_bdev;
if (spdk_json_decode_object(params, rpc_destroy_raid_bdev_decoders,
SPDK_COUNTOF(rpc_destroy_raid_bdev_decoders),
@ -405,12 +404,7 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
}
/* Remove all the base bdevs from this raid bdev before destroying the raid bdev */
for (uint32_t i = 0; i < raid_cfg->num_base_bdevs; i++) {
base_bdev = spdk_bdev_get_by_name(raid_cfg->base_bdev[i].name);
if (base_bdev != NULL) {
raid_bdev_remove_base_bdev(base_bdev);
}
}
raid_bdev_remove_base_devices(raid_cfg);
raid_bdev_config_destroy(raid_cfg);