bdev/raid: Factor out add base bdev to raid bdev config operation

Change-Id: I05cff0e0330ed34e92a9a16d7d2f14001d17fb2c
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/420328
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Kunal Sablok <kunal.sablok@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-07-25 11:12:39 +09:00 committed by Ben Walker
parent 372b0d4931
commit 6e320a7629
3 changed files with 53 additions and 25 deletions

View File

@ -873,6 +873,46 @@ raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
return 0;
}
/*
* brief:
* raid_bdev_config_add_base_bdev function add base bdev to raid bdev config.
*
* params:
* raid_cfg - pointer to raid bdev configuration
* base_bdev_name - name of base bdev
* slot - Position to add base bdev
*/
int
raid_bdev_config_add_base_bdev(struct raid_bdev_config *raid_cfg, const char *base_bdev_name,
uint32_t slot)
{
uint32_t i;
struct raid_bdev_config *tmp;
if (slot >= raid_cfg->num_base_bdevs) {
return -EINVAL;
}
TAILQ_FOREACH(tmp, &g_spdk_raid_config.raid_bdev_config_head, link) {
for (i = 0; i < tmp->num_base_bdevs; i++) {
if (tmp->base_bdev[i].bdev_name != NULL) {
if (!strcmp(tmp->base_bdev[i].bdev_name, base_bdev_name)) {
SPDK_ERRLOG("duplicate base bdev name %s mentioned\n",
base_bdev_name);
return -EEXIST;
}
}
}
}
raid_cfg->base_bdev[slot].bdev_name = strdup(base_bdev_name);
if (raid_cfg->base_bdev[slot].bdev_name == NULL) {
SPDK_ERRLOG("unable to allocate memory\n");
return -ENOMEM;
}
return 0;
}
/*
* brief:
* raid_bdev_parse_raid is used to parse the raid bdev from config file based on
@ -903,11 +943,10 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
{
const char *raid_name;
int strip_size;
int num_base_bdevs;
int i, num_base_bdevs;
int raid_level;
const char *base_bdev_name;
uint32_t i, j;
struct raid_bdev_config *raid_bdev_config, *tmp;
struct raid_bdev_config *raid_bdev_config;
int rc;
raid_name = spdk_conf_section_get_val(conf_section, "Name");
@ -946,30 +985,17 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
if (base_bdev_name == NULL) {
break;
}
if (i >= raid_bdev_config->num_base_bdevs) {
if (i >= num_base_bdevs) {
raid_bdev_config_cleanup(raid_bdev_config);
SPDK_ERRLOG("Number of devices mentioned is more than count\n");
return -1;
}
TAILQ_FOREACH(tmp, &g_spdk_raid_config.raid_bdev_config_head, link) {
for (j = 0; j < tmp->num_base_bdevs; j++) {
if (tmp->base_bdev[j].bdev_name != NULL) {
if (!strcmp(tmp->base_bdev[j].bdev_name, base_bdev_name)) {
raid_bdev_config_cleanup(raid_bdev_config);
SPDK_ERRLOG("duplicate base bdev name %s mentioned\n",
base_bdev_name);
return -EEXIST;
}
}
}
}
raid_bdev_config->base_bdev[i].bdev_name = strdup(base_bdev_name);
if (raid_bdev_config->base_bdev[i].bdev_name == NULL) {
rc = raid_bdev_config_add_base_bdev(raid_bdev_config, base_bdev_name, i);
if (rc != 0) {
raid_bdev_config_cleanup(raid_bdev_config);
SPDK_ERRLOG("unable to allocate memory\n");
return -ENOMEM;
SPDK_ERRLOG("Failed to add base bdev to raid bdev config\n");
return rc;
}
}

View File

@ -230,6 +230,8 @@ void raid_bdev_remove_base_bdev(void *ctx);
int raid_bdev_add_base_device(struct spdk_bdev *bdev);
int raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
int raid_level, struct raid_bdev_config **_raid_bdev_config);
int raid_bdev_config_add_base_bdev(struct raid_bdev_config *raid_cfg,
const char *base_bdev_name, uint32_t slot);
void raid_bdev_config_cleanup(struct raid_bdev_config *raid_cfg);
#endif // SPDK_BDEV_RAID_INTERNAL_H

View File

@ -353,11 +353,11 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
return;
}
for (size_t i = 0; i < raid_bdev_config->num_base_bdevs; i++) {
raid_bdev_config->base_bdev[i].bdev_name = strdup(req.base_bdevs.base_bdevs[i]);
if (raid_bdev_config->base_bdev[i].bdev_name == NULL) {
for (size_t i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
rc = raid_bdev_config_add_base_bdev(raid_bdev_config, req.base_bdevs.base_bdevs[i], i);
if (rc != 0) {
raid_bdev_config_cleanup(raid_bdev_config);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(ENOMEM));
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(-rc));
free_rpc_construct_raid_bdev(&req);
return;
}