2 CTDB cluster config handling
4 Copyright (C) Martin Schwenke 2018
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.
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.
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/>.
21 #include "system/network.h"
23 #include "lib/util/debug.h"
25 #include "common/conf.h"
27 #include "cluster_conf.h"
29 #define CLUSTER_TRANSPORT_DEFAULT "tcp"
32 * Ideally this wants to be a void function but it also used directly
33 * as a validation function
35 static bool check_static_string_change(const char *key
,
36 const char *old_value
,
37 const char *new_value
,
38 enum conf_update_mode mode
)
40 if (mode
== CONF_MODE_RELOAD
) {
41 if (old_value
== new_value
) {
46 * At this point old_value or new_value can not both
47 * NULL, so if one is NULL then they are different
49 if (old_value
== NULL
||
51 strcmp(old_value
, new_value
) != 0) {
52 D_WARNING("Ignoring update of [%s] -> %s\n",
62 static bool validate_transport(const char *key
,
63 const char *old_transport
,
64 const char *new_transport
,
65 enum conf_update_mode mode
)
67 /* Don't allow "ib" for now. It is broken! */
68 if (strcmp(new_transport
, CLUSTER_TRANSPORT_DEFAULT
) != 0) {
69 D_ERR("Invalid value for [cluster] -> transport = %s\n",
74 /* This sometimes warns but always returns true */
75 return check_static_string_change(key
,
81 static bool validate_node_address(const char *key
,
82 const char *old_node_address
,
83 const char *new_node_address
,
84 enum conf_update_mode mode
)
87 struct in6_addr addr6
;
90 if (new_node_address
== NULL
) {
94 ret
= inet_pton(AF_INET
, new_node_address
, &addr4
);
99 ret
= inet_pton(AF_INET6
, new_node_address
, &addr6
);
104 D_ERR("Invalid value for [cluster] -> node address = %s\n",
109 /* This sometimes warns but always returns true */
110 return check_static_string_change(key
,
116 static bool validate_recovery_lock(const char *key
,
117 const char *old_reclock
,
118 const char *new_reclock
,
119 enum conf_update_mode mode
)
123 if (new_reclock
!= NULL
) {
124 D_WARNING("Configuration option [%s] -> %s is deprecated\n",
125 CLUSTER_CONF_SECTION
,
129 status
= check_static_string_change(key
, old_reclock
, new_reclock
, mode
);
134 static bool validate_leader_timeout(const char *key
,
137 enum conf_update_mode mode
)
139 if (new_timeout
<= 0) {
140 D_ERR("Invalid value for [cluster] -> leader timeout = %d\n",
148 void cluster_conf_init(struct conf_context
*conf
)
150 conf_define_section(conf
, CLUSTER_CONF_SECTION
, NULL
);
152 conf_define_string(conf
,
153 CLUSTER_CONF_SECTION
,
154 CLUSTER_CONF_TRANSPORT
,
155 CLUSTER_TRANSPORT_DEFAULT
,
157 conf_define_string(conf
,
158 CLUSTER_CONF_SECTION
,
159 CLUSTER_CONF_NODE_ADDRESS
,
161 validate_node_address
);
162 conf_define_string(conf
,
163 CLUSTER_CONF_SECTION
,
164 CLUSTER_CONF_CLUSTER_LOCK
,
166 check_static_string_change
);
167 conf_define_string(conf
,
168 CLUSTER_CONF_SECTION
,
169 CLUSTER_CONF_RECOVERY_LOCK
,
171 validate_recovery_lock
);
172 conf_define_integer(conf
,
173 CLUSTER_CONF_SECTION
,
174 CLUSTER_CONF_LEADER_TIMEOUT
,
176 validate_leader_timeout
);
177 conf_define_boolean(conf
,
178 CLUSTER_CONF_SECTION
,
179 CLUSTER_CONF_LEADER_CAPABILITY
,