From 315890e845bcf4c0d404622ec813ef4eb265ba56 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 6 Jun 2024 10:00:09 -0400 Subject: [PATCH] ctdb-conf: add "nodes list" configuration option Add a "nodes list" configuration option to the [cluster] section of the ctdb server config. This option will be used similarly to the `cluster lock` parameter works. When unset it defaults to the same value as before (/etc/ctdb/nodes). If given a path that is not prefixed by `!` it instead loads the nodes file from the given path If given a path prefixed by `!` then it executes the path as a command and reads the standard output as if it were the content of the nodes file. Signed-off-by: John Mulligan Reviewed-by: Martin Schwenke --- ctdb/conf/cluster_conf.c | 21 +++++++++++++++++++++ ctdb/conf/cluster_conf.h | 17 +++++++++++++++++ ctdb/conf/ctdb_config.c | 4 ++++ ctdb/conf/ctdb_config.h | 1 + ctdb/tests/UNIT/cunit/config_test_001.sh | 1 + 5 files changed, 44 insertions(+) diff --git a/ctdb/conf/cluster_conf.c b/ctdb/conf/cluster_conf.c index b49a2440026..fd1c9230906 100644 --- a/ctdb/conf/cluster_conf.c +++ b/ctdb/conf/cluster_conf.c @@ -22,6 +22,8 @@ #include "lib/util/debug.h" +#include "common/path.h" + #include "conf/conf.h" #include "conf/cluster_conf.h" @@ -169,6 +171,11 @@ void cluster_conf_init(struct conf_context *conf) CLUSTER_CONF_RECOVERY_LOCK, NULL, validate_recovery_lock); + conf_define_string(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_NODES_LIST, + NULL, + check_static_string_change); conf_define_integer(conf, CLUSTER_CONF_SECTION, CLUSTER_CONF_LEADER_TIMEOUT, @@ -180,3 +187,17 @@ void cluster_conf_init(struct conf_context *conf) true, NULL); } + +char *cluster_conf_nodes_list(TALLOC_CTX *mem_ctx, struct conf_context *conf) +{ + const char *out = NULL; + int ret = conf_get_string(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_NODES_LIST, + &out, + NULL); + if (ret == 0 && out != NULL) { + return talloc_strdup(mem_ctx, out); + } + return path_etcdir_append(mem_ctx, "nodes"); +} diff --git a/ctdb/conf/cluster_conf.h b/ctdb/conf/cluster_conf.h index 9775b6fc080..584732b39ff 100644 --- a/ctdb/conf/cluster_conf.h +++ b/ctdb/conf/cluster_conf.h @@ -20,6 +20,8 @@ #ifndef __CTDB_CLUSTER_CONF_H__ #define __CTDB_CLUSTER_CONF_H__ +#include + #include "conf/conf.h" #define CLUSTER_CONF_SECTION "cluster" @@ -28,9 +30,24 @@ #define CLUSTER_CONF_NODE_ADDRESS "node address" #define CLUSTER_CONF_CLUSTER_LOCK "cluster lock" #define CLUSTER_CONF_RECOVERY_LOCK "recovery lock" +#define CLUSTER_CONF_NODES_LIST "nodes list" #define CLUSTER_CONF_LEADER_TIMEOUT "leader timeout" #define CLUSTER_CONF_LEADER_CAPABILITY "leader capability" void cluster_conf_init(struct conf_context *conf); +/** + * @brief Return the value of the nodes list configuration parameter. + * + * This function is used to fetch the value set in the ctdb.conf (or equivalent) + * for 'nodes list' a value that is then used to fetch the actual nodes list + * of private node addresses. If a value is not present in the configuration + * file a backwards compatible default value will be returned. + * + * @param[in] mem_ctx TALLOC memory context + * @param[in] conf A configuration context + * @return string or NULL on memory allocation error + */ +char *cluster_conf_nodes_list(TALLOC_CTX *mem_ctx, struct conf_context *conf); + #endif /* __CTDB_CLUSTER_CONF_H__ */ diff --git a/ctdb/conf/ctdb_config.c b/ctdb/conf/ctdb_config.c index e3e8cce8d6b..f1f9ec020f0 100644 --- a/ctdb/conf/ctdb_config.c +++ b/ctdb/conf/ctdb_config.c @@ -57,6 +57,10 @@ static void setup_config_pointers(struct conf_context *conf) CLUSTER_CONF_SECTION, CLUSTER_CONF_RECOVERY_LOCK, &ctdb_config.recovery_lock); + conf_assign_string_pointer(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_NODES_LIST, + &ctdb_config.nodes_list); conf_assign_integer_pointer(conf, CLUSTER_CONF_SECTION, CLUSTER_CONF_LEADER_TIMEOUT, diff --git a/ctdb/conf/ctdb_config.h b/ctdb/conf/ctdb_config.h index 7b588c3cd59..2cf6a16f1cb 100644 --- a/ctdb/conf/ctdb_config.h +++ b/ctdb/conf/ctdb_config.h @@ -28,6 +28,7 @@ struct ctdb_config { const char *node_address; const char *cluster_lock; const char *recovery_lock; + const char *nodes_list; int leader_timeout; bool leader_capability; diff --git a/ctdb/tests/UNIT/cunit/config_test_001.sh b/ctdb/tests/UNIT/cunit/config_test_001.sh index 70bf77f7939..9e7ac462618 100755 --- a/ctdb/tests/UNIT/cunit/config_test_001.sh +++ b/ctdb/tests/UNIT/cunit/config_test_001.sh @@ -36,6 +36,7 @@ ok <