From: Martin Schwenke Date: Wed, 18 Apr 2018 10:21:07 +0000 (+1000) Subject: ctdb-daemon: Implement ctdb configuration file loading X-Git-Tag: ldb-1.4.0~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=239f189b10160c0c176e6e0ebef089c8d544f213;p=thirdparty%2Fsamba.git ctdb-daemon: Implement ctdb configuration file loading Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/server/ctdb_config.c b/ctdb/server/ctdb_config.c new file mode 100644 index 00000000000..58bf975abfd --- /dev/null +++ b/ctdb/server/ctdb_config.c @@ -0,0 +1,161 @@ +/* + CTDB daemon config handling + + Copyright (C) Martin Schwenke 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include "replace.h" + +#include "lib/util/debug.h" + +#include "common/conf.h" +#include "common/logging_conf.h" +#include "common/path.h" + +#include "cluster/cluster_conf.h" +#include "database/database_conf.h" +#include "event/event_conf.h" +#include "legacy_conf.h" + +#include "ctdb_config.h" + +struct ctdb_config ctdb_config; + +static void setup_config_pointers(struct conf_context *conf) +{ + /* + * Cluster + */ + + conf_assign_string_pointer(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_TRANSPORT, + &ctdb_config.transport); + conf_assign_string_pointer(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_NODE_ADDRESS, + &ctdb_config.node_address); + conf_assign_string_pointer(conf, + CLUSTER_CONF_SECTION, + CLUSTER_CONF_RECOVERY_LOCK, + &ctdb_config.recovery_lock); + + /* + * Database + */ + + conf_assign_string_pointer(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_VOLATILE_DB_DIR, + &ctdb_config.dbdir_volatile); + conf_assign_string_pointer(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_PERSISTENT_DB_DIR, + &ctdb_config.dbdir_persistent); + conf_assign_string_pointer(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_STATE_DB_DIR, + &ctdb_config.dbdir_state); + conf_assign_string_pointer(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_LOCK_DEBUG_SCRIPT, + &ctdb_config.lock_debug_script); + + /* + * Event + */ + conf_assign_string_pointer(conf, + EVENT_CONF_SECTION, + EVENT_CONF_DEBUG_SCRIPT, + &ctdb_config.event_debug_script); + + /* + * Legacy + */ + + conf_assign_boolean_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_NO_REALTIME, + &ctdb_config.no_realtime); + conf_assign_boolean_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_RECMASTER_CAPABILITY, + &ctdb_config.recmaster_capability); + conf_assign_boolean_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_LMASTER_CAPABILITY, + &ctdb_config.lmaster_capability); + conf_assign_boolean_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_START_AS_STOPPED, + &ctdb_config.start_as_stopped); + conf_assign_boolean_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_START_AS_DISABLED, + &ctdb_config.start_as_disabled); + conf_assign_string_pointer(conf, + LEGACY_CONF_SECTION, + LEGACY_CONF_SCRIPT_LOG_LEVEL, + &ctdb_config.script_log_level); +} + +int ctdbd_config_load(TALLOC_CTX *mem_ctx, + struct conf_context **result) +{ + struct conf_context *conf = NULL; + int ret = 0; + char *conf_file = NULL; + + ret = conf_init(mem_ctx, &conf); + if (ret != 0) { + return ret; + } + + logging_conf_init(conf, "NOTICE"); + cluster_conf_init(conf); + database_conf_init(conf); + event_conf_init(conf); + legacy_conf_init(conf); + + setup_config_pointers(conf); + + if (! conf_valid(conf)) { + ret = EINVAL; + goto fail; + } + + conf_file = path_config(conf); + if (conf_file == NULL) { + D_ERR("Memory allocation error\n"); + ret = ENOMEM; + goto fail; + } + ret = conf_load(conf, conf_file, true); + /* Configuration file does not need to exist */ + if (ret != 0 && ret != ENOENT) { + D_ERR("Failed to load configuration file %s\n", conf_file); + goto fail; + } + + talloc_free(conf_file); + *result = conf; + + return 0; + +fail: + talloc_free(conf); + return ret; +} diff --git a/ctdb/server/ctdb_config.h b/ctdb/server/ctdb_config.h new file mode 100644 index 00000000000..51342a4a269 --- /dev/null +++ b/ctdb/server/ctdb_config.h @@ -0,0 +1,53 @@ +/* + CTDB daemon config handling + + Copyright (C) Martin Schwenke 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#ifndef __CTDB_CONFIG_H__ +#define __CTDB_CONFIG_H__ + +#include "common/conf.h" + +struct ctdb_config { + /* Cluster */ + const char *transport; + const char *node_address; + const char *recovery_lock; + + /* Database */ + const char *dbdir_volatile; + const char *dbdir_persistent; + const char *dbdir_state; + const char *lock_debug_script; + + /* Event */ + const char *event_debug_script; + + /* Legacy */ + bool no_realtime; + bool recmaster_capability; + bool lmaster_capability; + bool start_as_stopped; + bool start_as_disabled; + const char *script_log_level; +}; + +extern struct ctdb_config ctdb_config; + +int ctdbd_config_load(TALLOC_CTX *mem_ctx, struct conf_context **conf); + +#endif /* __CTDB_CONFIG_H__ */ diff --git a/ctdb/wscript b/ctdb/wscript index 7661cba5d20..ed1b2e7b25b 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -509,10 +509,17 @@ def build(bld): ctdb_statistics.c ctdb_update_record.c ctdb_lock.c ctdb_fork.c - ctdb_tunnel.c ctdb_client.c'''), + ctdb_tunnel.c ctdb_client.c + ctdb_config.c + '''), includes='include', deps='''ctdb-common ctdb-system ctdb-protocol ctdb-tcp ctdb-util replace sys_rw popt + ctdb-logging-conf + ctdb-cluster-conf + ctdb-database-conf + ctdb-event-conf + ctdb-legacy-conf talloc tevent tdb-wrap tdb talloc_report''' + ib_deps, install_path='${SBINDIR}',