From eef0619865d8ffa174546dfdb4fd0e5a62d5cc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 6 Jan 2017 08:59:25 +0200 Subject: [PATCH] Add default parameters to created monitors When a monitor is created at runtime, it also needs to have the default parameters. Ideally, this would be done when the monitor is allocated but because of the way the configuration is processed, we need to do it after user defined parameters are added. --- include/maxscale/config.h | 13 +++++++++++++ server/core/config.c | 2 +- server/core/config_runtime.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/maxscale/config.h b/include/maxscale/config.h index c5f685ba3..7a5b02918 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -265,6 +265,19 @@ const char* config_get_string(const CONFIG_PARAMETER *params, const char *key); */ int config_get_enum(const CONFIG_PARAMETER *params, const char *key, const MXS_ENUM_VALUE *values); +/** + * @brief Generate default module parameters + * + * Adds any default parameters to @c ctx that aren't already in it. + * + * @param ctx Configuration context where the parameters are added + * @param module Module name + * @param type Module type + * + * TODO: Move this to a header internal to the MaxScale core + */ +void config_add_defaults(CONFIG_CONTEXT *ctx, const char *module, const char *type); + char* config_clean_string_list(const char* str); CONFIG_PARAMETER* config_clone_param(const CONFIG_PARAMETER* param); void config_enable_feedback_task(void); diff --git a/server/core/config.c b/server/core/config.c index 1f2fb9a8c..3fcb650c2 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -2384,7 +2384,7 @@ static int validate_ssl_parameters(CONFIG_CONTEXT* obj, char *ssl_cert, char *ss * @param ctx Configuration context where the default parameters are added * @param module Name of the module */ -static void config_add_defaults(CONFIG_CONTEXT *ctx, const char *module, const char *type) +void config_add_defaults(CONFIG_CONTEXT *ctx, const char *module, const char *type) { const MXS_MODULE *mod = get_module(module, type); diff --git a/server/core/config_runtime.c b/server/core/config_runtime.c index 3bd33f156..3a1631c1e 100644 --- a/server/core/config_runtime.c +++ b/server/core/config_runtime.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "maxscale/service.h" @@ -336,6 +337,21 @@ static long get_positive_int(const char *value) return 0; } +/** + * @brief Add default parameters to a monitor + * + * @param monitor Monitor to modify + */ +static void add_monitor_defaults(MONITOR *monitor) +{ + /** Inject the default module parameters in case we only deleted + * a parameter */ + CONFIG_CONTEXT ctx = {.object = ""}; + config_add_defaults(&ctx, monitor->module_name, MODULE_MONITOR); + monitorAddParameters(monitor, ctx.parameters); + config_parameter_free(ctx.parameters); +} + bool runtime_alter_monitor(MONITOR *monitor, char *key, char *value) { spinlock_acquire(&crt_lock); @@ -402,6 +418,8 @@ bool runtime_alter_monitor(MONITOR *monitor, char *key, char *value) CONFIG_PARAMETER p = {.name = key, .value = value}; monitorAddParameters(monitor, &p); } + + add_monitor_defaults(monitor); } monitorStart(monitor, monitor->parameters); @@ -560,6 +578,7 @@ bool runtime_create_monitor(const char *name, const char *module) { /** Mark that this monitor was created after MaxScale was started */ monitor->created_online = true; + add_monitor_defaults(monitor); if (monitor_serialize(monitor)) {