conf: add Boolean value helper function

Change-Id: Ie86745fe397167416aee356dc773a1bf8387b492
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2017-03-30 11:08:32 -07:00 committed by Jim Harris
parent f390a2aad6
commit edbca2a676
7 changed files with 38 additions and 38 deletions

View File

@ -63,6 +63,7 @@ char *spdk_conf_section_get_nmval(struct spdk_conf_section *sp, const char *key,
char *spdk_conf_section_get_nval(struct spdk_conf_section *sp, const char *key, int idx);
char *spdk_conf_section_get_val(struct spdk_conf_section *sp, const char *key);
int spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key);
bool spdk_conf_section_get_boolval(struct spdk_conf_section *sp, const char *key, bool default_val);
void spdk_conf_set_as_default(struct spdk_conf *cp);

View File

@ -112,7 +112,7 @@ struct nvme_probe_ctx {
};
static int g_hot_insert_nvme_controller_index = 0;
static int g_reset_controller_on_timeout = 0;
static bool g_reset_controller_on_timeout = false;
static int g_timeout = 0;
static int g_nvme_adminq_poll_timeout_us = 0;
static int g_nvme_hotplug_poll_timeout_us = 0;
@ -768,12 +768,8 @@ bdev_nvme_library_init(void)
probe_ctx.count++;
}
val = spdk_conf_section_get_val(sp, "ResetControllerOnTimeout");
if (val != NULL) {
if (!strcmp(val, "Yes")) {
g_reset_controller_on_timeout = 1;
}
}
g_reset_controller_on_timeout =
spdk_conf_section_get_boolval(sp, "ResetControllerOnTimeout", false);
if ((g_timeout = spdk_conf_section_get_intval(sp, "NvmeTimeoutValue")) < 0) {
g_timeout = 0;

View File

@ -427,6 +427,27 @@ spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key)
return value;
}
bool
spdk_conf_section_get_boolval(struct spdk_conf_section *sp, const char *key, bool default_val)
{
const char *v;
v = spdk_conf_section_get_nval(sp, key, 0);
if (v == NULL) {
return default_val;
}
if (!strcasecmp(v, "Yes") || !strcasecmp(v, "Y") || !strcasecmp(v, "True")) {
return true;
}
if (!strcasecmp(v, "No") || !strcasecmp(v, "N") || !strcasecmp(v, "False")) {
return false;
}
return default_val;
}
static int
parse_line(struct spdk_conf *cp, char *lp)
{

View File

@ -277,18 +277,16 @@ static int
copy_engine_ioat_init(void)
{
struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "Ioat");
const char *val, *pci_bdf;
const char *pci_bdf;
int i;
struct ioat_probe_ctx probe_ctx = {};
if (sp != NULL) {
val = spdk_conf_section_get_val(sp, "Disable");
if (val != NULL) {
if (spdk_conf_section_get_boolval(sp, "Disable", false)) {
/* Disable Ioat */
if (!strcmp(val, "Yes")) {
return 0;
}
return 0;
}
/*Init the whitelist*/
for (i = 0; i < IOAT_MAX_CHANNELS; i++) {
pci_bdf = spdk_conf_section_get_nmval(sp, "Whitelist", i, 0);

View File

@ -83,23 +83,13 @@ static int
enable_rpc(void)
{
struct spdk_conf_section *sp;
char *val;
sp = spdk_conf_find_section(NULL, "Rpc");
if (sp == NULL) {
return 0;
}
val = spdk_conf_section_get_val(sp, "Enable");
if (val == NULL) {
return 0;
}
if (!strcmp(val, "Yes")) {
return 1;
}
return 0;
return spdk_conf_section_get_boolval(sp, "Enable", false);
}
static const char *

View File

@ -88,17 +88,7 @@ spdk_read_config_scsi_parameters(void)
g_spdk_scsi.scsi_params.unmap_granularity_alignment = (val == NULL) ?
DEFAULT_UNMAP_GRANULARITY_ALIGNMENT : strtoul(val, NULL, 10);
val = spdk_conf_section_get_val(sp, "Ugavalid");
if (val == NULL) {
g_spdk_scsi.scsi_params.ugavalid = DEFAULT_UGAVALID;
} else if (strcasecmp(val, "Yes") == 0) {
g_spdk_scsi.scsi_params.ugavalid = 1;
} else if (strcasecmp(val, "No") == 0) {
g_spdk_scsi.scsi_params.ugavalid = 0;
} else {
SPDK_ERRLOG("unknown value %s\n", val);
return -1;
}
g_spdk_scsi.scsi_params.ugavalid = spdk_conf_section_get_boolval(sp, "Ugavalid", DEFAULT_UGAVALID);
val = spdk_conf_section_get_val(sp, "MaxWriteSameLength");
g_spdk_scsi.scsi_params.max_write_same_length = (val == NULL) ?

View File

@ -274,6 +274,7 @@ scsi_init_ugavalid_no(void)
static void
scsi_init_ugavalid_unknown_value_failure(void)
{
struct spdk_scsi_parameters params;
int rc;
struct spdk_conf *config;
@ -282,10 +283,13 @@ scsi_init_ugavalid_unknown_value_failure(void)
config = spdk_config_init_scsi_params("Ugavalid", "unknown value");
spdk_conf_set_as_default(config);
rc = spdk_scsi_subsystem_init();
CU_ASSERT_EQUAL(rc, 0);
/* returns -1 since scsi_params.ugavalid is set to
* 'unknown value' */
CU_ASSERT_TRUE(rc < 0);
/* Assert the scsi_params.ugavalid == DEFAULT_UGAVALID and
* assert the rest of the params are set to their default values */
set_default_scsi_params(&params);
params.ugavalid = DEFAULT_UGAVALID;
CU_ASSERT(memcmp(&g_spdk_scsi.scsi_params, &params, sizeof(params)) == 0);
spdk_conf_free(config);
}