1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
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 <http://www.gnu.org/licenses/>.
*/
#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 "failover/failover_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);
conf_assign_boolean_pointer(conf,
DATABASE_CONF_SECTION,
DATABASE_CONF_TDB_MUTEXES,
&ctdb_config.tdb_mutexes);
/*
* Event
*/
conf_assign_string_pointer(conf,
EVENT_CONF_SECTION,
EVENT_CONF_DEBUG_SCRIPT,
&ctdb_config.event_debug_script);
/*
* Failover
*/
conf_assign_boolean_pointer(conf,
FAILOVER_CONF_SECTION,
FAILOVER_CONF_DISABLED,
&ctdb_config.failover_disabled);
/*
* Legacy
*/
conf_assign_boolean_pointer(conf,
LEGACY_CONF_SECTION,
LEGACY_CONF_REALTIME_SCHEDULING,
&ctdb_config.realtime_scheduling);
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);
failover_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;
}
|