1 /*
2 CTDB daemon config handling
3
4 Copyright (C) Martin Schwenke 2018
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "replace.h"
21
22 #include "lib/util/debug.h"
23
24 #include "common/conf.h"
25 #include "common/logging_conf.h"
26 #include "common/path.h"
27
28 #include "cluster/cluster_conf.h"
29 #include "database/database_conf.h"
30 #include "event/event_conf.h"
31 #include "failover/failover_conf.h"
32 #include "legacy_conf.h"
33
34 #include "ctdb_config.h"
35
36 struct ctdb_config ctdb_config;
37
setup_config_pointers(struct conf_context * conf)38 static void setup_config_pointers(struct conf_context *conf)
39 {
40 /*
41 * Cluster
42 */
43
44 conf_assign_string_pointer(conf,
45 CLUSTER_CONF_SECTION,
46 CLUSTER_CONF_TRANSPORT,
47 &ctdb_config.transport);
48 conf_assign_string_pointer(conf,
49 CLUSTER_CONF_SECTION,
50 CLUSTER_CONF_NODE_ADDRESS,
51 &ctdb_config.node_address);
52 conf_assign_string_pointer(conf,
53 CLUSTER_CONF_SECTION,
54 CLUSTER_CONF_RECOVERY_LOCK,
55 &ctdb_config.recovery_lock);
56
57 /*
58 * Database
59 */
60
61 conf_assign_string_pointer(conf,
62 DATABASE_CONF_SECTION,
63 DATABASE_CONF_VOLATILE_DB_DIR,
64 &ctdb_config.dbdir_volatile);
65 conf_assign_string_pointer(conf,
66 DATABASE_CONF_SECTION,
67 DATABASE_CONF_PERSISTENT_DB_DIR,
68 &ctdb_config.dbdir_persistent);
69 conf_assign_string_pointer(conf,
70 DATABASE_CONF_SECTION,
71 DATABASE_CONF_STATE_DB_DIR,
72 &ctdb_config.dbdir_state);
73 conf_assign_string_pointer(conf,
74 DATABASE_CONF_SECTION,
75 DATABASE_CONF_LOCK_DEBUG_SCRIPT,
76 &ctdb_config.lock_debug_script);
77 conf_assign_boolean_pointer(conf,
78 DATABASE_CONF_SECTION,
79 DATABASE_CONF_TDB_MUTEXES,
80 &ctdb_config.tdb_mutexes);
81
82 /*
83 * Event
84 */
85 conf_assign_string_pointer(conf,
86 EVENT_CONF_SECTION,
87 EVENT_CONF_DEBUG_SCRIPT,
88 &ctdb_config.event_debug_script);
89
90 /*
91 * Failover
92 */
93 conf_assign_boolean_pointer(conf,
94 FAILOVER_CONF_SECTION,
95 FAILOVER_CONF_DISABLED,
96 &ctdb_config.failover_disabled);
97
98 /*
99 * Legacy
100 */
101
102 conf_assign_boolean_pointer(conf,
103 LEGACY_CONF_SECTION,
104 LEGACY_CONF_REALTIME_SCHEDULING,
105 &ctdb_config.realtime_scheduling);
106 conf_assign_boolean_pointer(conf,
107 LEGACY_CONF_SECTION,
108 LEGACY_CONF_RECMASTER_CAPABILITY,
109 &ctdb_config.recmaster_capability);
110 conf_assign_boolean_pointer(conf,
111 LEGACY_CONF_SECTION,
112 LEGACY_CONF_LMASTER_CAPABILITY,
113 &ctdb_config.lmaster_capability);
114 conf_assign_boolean_pointer(conf,
115 LEGACY_CONF_SECTION,
116 LEGACY_CONF_START_AS_STOPPED,
117 &ctdb_config.start_as_stopped);
118 conf_assign_boolean_pointer(conf,
119 LEGACY_CONF_SECTION,
120 LEGACY_CONF_START_AS_DISABLED,
121 &ctdb_config.start_as_disabled);
122 conf_assign_string_pointer(conf,
123 LEGACY_CONF_SECTION,
124 LEGACY_CONF_SCRIPT_LOG_LEVEL,
125 &ctdb_config.script_log_level);
126 }
127
ctdbd_config_load(TALLOC_CTX * mem_ctx,struct conf_context ** result)128 int ctdbd_config_load(TALLOC_CTX *mem_ctx,
129 struct conf_context **result)
130 {
131 struct conf_context *conf = NULL;
132 int ret = 0;
133 char *conf_file = NULL;
134
135 ret = conf_init(mem_ctx, &conf);
136 if (ret != 0) {
137 return ret;
138 }
139
140 logging_conf_init(conf, "NOTICE");
141 cluster_conf_init(conf);
142 database_conf_init(conf);
143 event_conf_init(conf);
144 failover_conf_init(conf);
145 legacy_conf_init(conf);
146
147 setup_config_pointers(conf);
148
149 if (! conf_valid(conf)) {
150 ret = EINVAL;
151 goto fail;
152 }
153
154 conf_file = path_config(conf);
155 if (conf_file == NULL) {
156 D_ERR("Memory allocation error\n");
157 ret = ENOMEM;
158 goto fail;
159 }
160 ret = conf_load(conf, conf_file, true);
161 /* Configuration file does not need to exist */
162 if (ret != 0 && ret != ENOENT) {
163 D_ERR("Failed to load configuration file %s\n", conf_file);
164 goto fail;
165 }
166
167 talloc_free(conf_file);
168 *result = conf;
169
170 return 0;
171
172 fail:
173 talloc_free(conf);
174 return ret;
175 }
176