From ac926a506d5d3d0cfb8caeb135fe496b284ef5f6 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 1 Aug 2024 14:25:38 -0400 Subject: [PATCH] ctdb-conf: add boolean arg for verbosity when loading config In a future commit we will add support for loading the config file from the `ctdb` command line tool. Prior to this change the config file load func always called D_NOTICE that causes the command to emit new text and thus break all the tests that rely on the specific test output (not to mention something users could notice). This change plumbs a new `verbose` argument into some of the config file loading functions. Generally, all existing functions will have verbose set to true to match the existing behavior. Future callers of this function can set it to false in order to avoid emitting the extra text. Signed-off-by: John Mulligan Reviewed-by: Martin Schwenke --- ctdb/conf/conf.c | 7 +++++-- ctdb/conf/conf.h | 3 ++- ctdb/conf/conf_tool.c | 6 +++--- ctdb/conf/ctdb_config.c | 5 +++-- ctdb/conf/ctdb_config.h | 3 ++- ctdb/event/event_config.c | 2 +- ctdb/server/ctdbd.c | 2 +- ctdb/tests/src/conf_test.c | 6 +++--- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ctdb/conf/conf.c b/ctdb/conf/conf.c index 67046c715e2..2eb619765ad 100644 --- a/ctdb/conf/conf.c +++ b/ctdb/conf/conf.c @@ -1176,7 +1176,8 @@ done: int conf_load(struct conf_context *conf, const char *filename, - bool ignore_unknown) + bool ignore_unknown, + bool verbose) { conf->filename = talloc_strdup(conf, filename); if (conf->filename == NULL) { @@ -1185,7 +1186,9 @@ int conf_load(struct conf_context *conf, conf->ignore_unknown = ignore_unknown; - D_NOTICE("Reading config file %s\n", filename); + if (verbose) { + D_NOTICE("Reading config file %s\n", filename); + } return conf_load_internal(conf); } diff --git a/ctdb/conf/conf.h b/ctdb/conf/conf.h index 4dbf9c33723..29f36bd55e8 100644 --- a/ctdb/conf/conf.h +++ b/ctdb/conf/conf.h @@ -306,7 +306,8 @@ void conf_set_defaults(struct conf_context *conf); */ int conf_load(struct conf_context *conf, const char *filename, - bool ignore_unknown); + bool ignore_unknown, + bool verbose); /** * @brief Reload the values for configuration options diff --git a/ctdb/conf/conf_tool.c b/ctdb/conf/conf_tool.c index 28f6c1090d0..be4f06f57f6 100644 --- a/ctdb/conf/conf_tool.c +++ b/ctdb/conf/conf_tool.c @@ -57,7 +57,7 @@ static int conf_tool_dump(TALLOC_CTX *mem_ctx, return EINVAL; } - ret = conf_load(ctx->conf, ctx->conf_file, true); + ret = conf_load(ctx->conf, ctx->conf_file, true, true); if (ret != 0 && ret != ENOENT) { D_ERR("Failed to load config file %s\n", ctx->conf_file); return ret; @@ -97,7 +97,7 @@ static int conf_tool_get(TALLOC_CTX *mem_ctx, return ENOENT; } - ret = conf_load(ctx->conf, ctx->conf_file, true); + ret = conf_load(ctx->conf, ctx->conf_file, true, true); if (ret != 0 && ret != ENOENT) { D_ERR("Failed to load config file %s\n", ctx->conf_file); return ret; @@ -169,7 +169,7 @@ static int conf_tool_validate(TALLOC_CTX *mem_ctx, return EINVAL; } - ret = conf_load(ctx->conf, ctx->conf_file, false); + ret = conf_load(ctx->conf, ctx->conf_file, false, true); if (ret != 0) { D_ERR("Failed to load config file %s\n", ctx->conf_file); return ret; diff --git a/ctdb/conf/ctdb_config.c b/ctdb/conf/ctdb_config.c index f1f9ec020f0..f75bf374a80 100644 --- a/ctdb/conf/ctdb_config.c +++ b/ctdb/conf/ctdb_config.c @@ -138,7 +138,8 @@ static void setup_config_pointers(struct conf_context *conf) } int ctdb_config_load(TALLOC_CTX *mem_ctx, - struct conf_context **result) + struct conf_context **result, + bool verbose) { struct conf_context *conf = NULL; int ret = 0; @@ -169,7 +170,7 @@ int ctdb_config_load(TALLOC_CTX *mem_ctx, ret = ENOMEM; goto fail; } - ret = conf_load(conf, conf_file, true); + ret = conf_load(conf, conf_file, true, verbose); /* Configuration file does not need to exist */ if (ret != 0 && ret != ENOENT) { D_ERR("Failed to load configuration file %s\n", conf_file); diff --git a/ctdb/conf/ctdb_config.h b/ctdb/conf/ctdb_config.h index 2cf6a16f1cb..575e3045fa4 100644 --- a/ctdb/conf/ctdb_config.h +++ b/ctdb/conf/ctdb_config.h @@ -55,6 +55,7 @@ struct ctdb_config { extern struct ctdb_config ctdb_config; -int ctdb_config_load(TALLOC_CTX *mem_ctx, struct conf_context **conf); +int ctdb_config_load(TALLOC_CTX *mem_ctx, struct conf_context **conf, + bool verbose); #endif /* __CTDB_CONFIG_H__ */ diff --git a/ctdb/event/event_config.c b/ctdb/event/event_config.c index 8617ebaad30..616b5284d52 100644 --- a/ctdb/event/event_config.c +++ b/ctdb/event/event_config.c @@ -85,7 +85,7 @@ int event_config_init(TALLOC_CTX *mem_ctx, struct event_config **result) return EINVAL; } - ret = conf_load(config->conf, config->config_file, true); + ret = conf_load(config->conf, config->config_file, true, true); if (ret != 0 && ret != ENOENT) { talloc_free(config); return ret; diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index 73c4372f70d..524c51b91e5 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -233,7 +233,7 @@ int main(int argc, const char *argv[]) * Configuration file handling */ - ret = ctdb_config_load(ctdb, &conf); + ret = ctdb_config_load(ctdb, &conf, true); if (ret != 0) { /* ctdb_config_load() logs the failure */ goto fail; diff --git a/ctdb/tests/src/conf_test.c b/ctdb/tests/src/conf_test.c index a38a51bf37e..3ca0c1482c4 100644 --- a/ctdb/tests/src/conf_test.c +++ b/ctdb/tests/src/conf_test.c @@ -373,7 +373,7 @@ static void test8(const char *filename) status = conf_valid(conf); assert(status == true); - ret = conf_load(conf, filename, true); + ret = conf_load(conf, filename, true, true); conf_dump(conf, stdout); talloc_free(mem_ctx); @@ -402,7 +402,7 @@ static void test9(const char *filename, bool ignore_unknown) conf_set_boolean(conf, "section1", "key3", false); - ret = conf_load(conf, filename, ignore_unknown); + ret = conf_load(conf, filename, ignore_unknown, true); conf_dump(conf, stdout); talloc_free(mem_ctx); @@ -433,7 +433,7 @@ static void test11(const char *filename) status = conf_valid(conf); assert(status == true); - ret = conf_load(conf, filename, false); + ret = conf_load(conf, filename, false, true); assert(ret == 0); ret = rename(reload, filename); -- 2.47.3