bdev/raid: Check if required params are specified when parsing .INI config file

Checking if required parameters strip_size, num_base_bdevs, and
raid_level had been done in raid_bdev_config_add(). However, this
required us to use integer type.

If we do the check in raid_bdev_parse_raid(), we will be able to
use the same type between function parameters and variables of
struct, and hence do in this patch.

This will align with the next patch.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I10fd75f25ed9a5d40eb189b05c2a20c276fa3ad6
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464365
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: yidong0635 <dongx.yi@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-08-07 15:06:28 +09:00 committed by Changpeng Liu
parent 284aca9e36
commit 441ecc09ae
2 changed files with 30 additions and 17 deletions

View File

@ -1114,8 +1114,8 @@ raid_bdev_config_find_by_name(const char *raid_name)
* _raid_cfg - Pointer to newly added configuration
*/
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)
raid_bdev_config_add(const char *raid_name, uint32_t strip_size, uint8_t num_base_bdevs,
uint8_t raid_level, struct raid_bdev_config **_raid_cfg)
{
struct raid_bdev_config *raid_cfg;
@ -1127,17 +1127,17 @@ raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
}
if (spdk_u32_is_pow2(strip_size) == false) {
SPDK_ERRLOG("Invalid strip size %d\n", strip_size);
SPDK_ERRLOG("Invalid strip size %" PRIu32 "\n", strip_size);
return -EINVAL;
}
if (num_base_bdevs <= 0) {
SPDK_ERRLOG("Invalid base device count %d\n", num_base_bdevs);
if (num_base_bdevs == 0) {
SPDK_ERRLOG("Invalid base device count %u\n", num_base_bdevs);
return -EINVAL;
}
if (raid_level != 0) {
SPDK_ERRLOG("invalid raid level %d, only raid level 0 is supported\n",
SPDK_ERRLOG("invalid raid level %u, only raid level 0 is supported\n",
raid_level);
return -EINVAL;
}
@ -1242,12 +1242,11 @@ static int
raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
{
const char *raid_name;
int strip_size;
int i, num_base_bdevs;
int raid_level;
uint32_t strip_size;
uint8_t num_base_bdevs, raid_level;
const char *base_bdev_name;
struct raid_bdev_config *raid_cfg;
int rc;
int rc, i, val;
raid_name = spdk_conf_section_get_val(conf_section, "Name");
if (raid_name == NULL) {
@ -1255,12 +1254,26 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
return -EINVAL;
}
strip_size = spdk_conf_section_get_intval(conf_section, "StripSize");
num_base_bdevs = spdk_conf_section_get_intval(conf_section, "NumDevices");
raid_level = spdk_conf_section_get_intval(conf_section, "RaidLevel");
val = spdk_conf_section_get_intval(conf_section, "StripSize");
if (val < 0) {
return -EINVAL;
}
strip_size = val;
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "%s %d %d %d\n", raid_name, strip_size, num_base_bdevs,
raid_level);
val = spdk_conf_section_get_intval(conf_section, "NumDevices");
if (val < 0) {
return -EINVAL;
}
num_base_bdevs = val;
val = spdk_conf_section_get_intval(conf_section, "RaidLevel");
if (val < 0) {
return -EINVAL;
}
raid_level = val;
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "%s %" PRIu32 " %u %u\n",
raid_name, strip_size, num_base_bdevs, raid_level);
rc = raid_bdev_config_add(raid_name, strip_size, num_base_bdevs, raid_level,
&raid_cfg);

View File

@ -226,8 +226,8 @@ int raid_bdev_create(struct raid_bdev_config *raid_cfg);
int raid_bdev_add_base_devices(struct raid_bdev_config *raid_cfg);
void raid_bdev_remove_base_devices(struct raid_bdev_config *raid_cfg,
raid_bdev_destruct_cb cb_fn, void *cb_ctx);
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(const char *raid_name, uint32_t strip_size, uint8_t num_base_bdevs,
uint8_t raid_level, struct raid_bdev_config **_raid_cfg);
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);