Commit edbca2a6 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

conf: add Boolean value helper function



Change-Id: Ie86745fe397167416aee356dc773a1bf8387b492
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent f390a2aa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);

+3 −7
Original line number Diff line number Diff line
@@ -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;
+21 −0
Original line number Diff line number Diff line
@@ -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)
{
+4 −6
Original line number Diff line number Diff line
@@ -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;
		}
		}

		/*Init the whitelist*/
		for (i = 0; i < IOAT_MAX_CHANNELS; i++) {
			pci_bdf = spdk_conf_section_get_nmval(sp, "Whitelist", i, 0);
+1 −11
Original line number Diff line number Diff line
@@ -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 *
Loading