smbstatus: add json items to traverse_struct
[Samba.git] / ctdb / cluster / cluster_conf.c
blobbdd64ba112f25c1b243ee9c999bc12d4284308e6
1 /*
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/>.
20 #include "replace.h"
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) {
42 goto done;
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 ||
50 new_value == NULL ||
51 strcmp(old_value, new_value) != 0) {
52 D_WARNING("Ignoring update of [%s] -> %s\n",
53 CLUSTER_CONF_SECTION,
54 key);
58 done:
59 return true;
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",
70 new_transport);
71 return false;
74 /* This sometimes warns but always returns true */
75 return check_static_string_change(key,
76 old_transport,
77 new_transport,
78 mode);
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)
86 struct in_addr addr4;
87 struct in6_addr addr6;
88 int ret;
90 if (new_node_address == NULL) {
91 goto good;
94 ret = inet_pton(AF_INET, new_node_address, &addr4);
95 if (ret == 1) {
96 goto good;
99 ret = inet_pton(AF_INET6, new_node_address, &addr6);
100 if (ret == 1) {
101 goto good;
104 D_ERR("Invalid value for [cluster] -> node address = %s\n",
105 new_node_address);
106 return false;
108 good:
109 /* This sometimes warns but always returns true */
110 return check_static_string_change(key,
111 old_node_address,
112 new_node_address,
113 mode);
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)
121 bool status;
123 if (new_reclock != NULL) {
124 D_WARNING("Configuration option [%s] -> %s is deprecated\n",
125 CLUSTER_CONF_SECTION,
126 key);
129 status = check_static_string_change(key, old_reclock, new_reclock, mode);
131 return status;
134 static bool validate_leader_timeout(const char *key,
135 int old_timeout,
136 int new_timeout,
137 enum conf_update_mode mode)
139 if (new_timeout <= 0) {
140 D_ERR("Invalid value for [cluster] -> leader timeout = %d\n",
141 new_timeout);
142 return false;
145 return true;
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,
156 validate_transport);
157 conf_define_string(conf,
158 CLUSTER_CONF_SECTION,
159 CLUSTER_CONF_NODE_ADDRESS,
160 NULL,
161 validate_node_address);
162 conf_define_string(conf,
163 CLUSTER_CONF_SECTION,
164 CLUSTER_CONF_CLUSTER_LOCK,
165 NULL,
166 check_static_string_change);
167 conf_define_string(conf,
168 CLUSTER_CONF_SECTION,
169 CLUSTER_CONF_RECOVERY_LOCK,
170 NULL,
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,
180 true,
181 NULL);