lib/conf: allow multiple sections with same name

Add disable_sections_merge() procedure that will allow
to have multiple sections with a same name.
This behaviour is how FIO treats such sections
and so will be used in bdevperf config file.

Change-Id: If221daeb7753d91b5d2608d25ccbb16f2d43ccce
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3433
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Vitaliy Mysak 2020-07-17 12:46:14 +02:00 committed by Tomasz Zawadzki
parent a7972f0a54
commit 800b18d028
4 changed files with 29 additions and 3 deletions

View File

@ -201,6 +201,13 @@ bool spdk_conf_section_get_boolval(struct spdk_conf_section *sp, const char *key
*/
void spdk_conf_set_as_default(struct spdk_conf *cp);
/**
* Disable sections merging during 'spdk_conf_read()'
*
* \param cp Configuration to be read
*/
void spdk_conf_disable_sections_merge(struct spdk_conf *cp);
#ifdef __cplusplus
}
#endif

View File

@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 2
SO_MINOR := 0
SO_MINOR := 1
C_SRCS = conf.c
LIBNAME = conf

View File

@ -60,6 +60,7 @@ struct spdk_conf {
char *file;
struct spdk_conf_section *current_section;
struct spdk_conf_section *section;
bool merge_sections;
};
#define CF_DELIM " \t"
@ -72,7 +73,13 @@ static struct spdk_conf *default_config = NULL;
struct spdk_conf *
spdk_conf_allocate(void)
{
return calloc(1, sizeof(struct spdk_conf));
struct spdk_conf *ret = calloc(1, sizeof(struct spdk_conf));
if (ret) {
ret->merge_sections = true;
}
return ret;
}
static void
@ -480,7 +487,12 @@ parse_line(struct spdk_conf *cp, char *lp)
num = 0;
}
sp = spdk_conf_find_section(cp, key);
if (cp->merge_sections) {
sp = spdk_conf_find_section(cp, key);
} else {
sp = NULL;
}
if (sp == NULL) {
sp = allocate_cf_section();
append_cf_section(cp, sp);
@ -684,3 +696,9 @@ spdk_conf_set_as_default(struct spdk_conf *cp)
{
default_config = cp;
}
void
spdk_conf_disable_sections_merge(struct spdk_conf *cp)
{
cp->merge_sections = false;
}

View File

@ -17,6 +17,7 @@
spdk_conf_section_get_intval;
spdk_conf_section_get_boolval;
spdk_conf_set_as_default;
spdk_conf_disable_sections_merge;
local: *;
};