From 800b18d028b95f92738315af634b8101a4c84031 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Fri, 17 Jul 2020 12:46:14 +0200 Subject: [PATCH] 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 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3433 Reviewed-by: Tomasz Zawadzki Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- include/spdk/conf.h | 7 +++++++ lib/conf/Makefile | 2 +- lib/conf/conf.c | 22 ++++++++++++++++++++-- lib/conf/spdk_conf.map | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/spdk/conf.h b/include/spdk/conf.h index 51cbd8d694..4a5292d32b 100644 --- a/include/spdk/conf.h +++ b/include/spdk/conf.h @@ -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 diff --git a/lib/conf/Makefile b/lib/conf/Makefile index 667f72a13b..09966ea120 100644 --- a/lib/conf/Makefile +++ b/lib/conf/Makefile @@ -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 diff --git a/lib/conf/conf.c b/lib/conf/conf.c index 4897072524..287e157a5e 100644 --- a/lib/conf/conf.c +++ b/lib/conf/conf.c @@ -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; +} diff --git a/lib/conf/spdk_conf.map b/lib/conf/spdk_conf.map index 094b9d67b2..0fc01c8aa2 100644 --- a/lib/conf/spdk_conf.map +++ b/lib/conf/spdk_conf.map @@ -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: *; };