summaryrefslogtreecommitdiffstats
path: root/ctdb/cluster/cluster_conf.c
blob: bdd64ba112f25c1b243ee9c999bc12d4284308e6 (plain)
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
176
177
178
179
180
181
182
/*
   CTDB cluster 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 "system/network.h"

#include "lib/util/debug.h"

#include "common/conf.h"

#include "cluster_conf.h"

#define CLUSTER_TRANSPORT_DEFAULT "tcp"

/*
 * Ideally this wants to be a void function but it also used directly
 * as a validation function
 */
static bool check_static_string_change(const char *key,
				       const char *old_value,
				       const char *new_value,
				       enum conf_update_mode mode)
{
	if (mode == CONF_MODE_RELOAD) {
		if (old_value == new_value) {
			goto done;
		}

		/*
		 * At this point old_value or new_value can not both
		 * NULL, so if one is NULL then they are different
		 */
		if (old_value == NULL ||
		    new_value == NULL ||
		    strcmp(old_value, new_value) != 0) {
			D_WARNING("Ignoring update of [%s] -> %s\n",
				  CLUSTER_CONF_SECTION,
				  key);
		}
	}

done:
	return true;
}

static bool validate_transport(const char *key,
			       const char *old_transport,
			       const char *new_transport,
			       enum conf_update_mode mode)
{
	/* Don't allow "ib" for now.  It is broken! */
	if (strcmp(new_transport, CLUSTER_TRANSPORT_DEFAULT) != 0) {
		D_ERR("Invalid value for [cluster] -> transport = %s\n",
		      new_transport);
		return false;
	}

	/* This sometimes warns but always returns true */
	return check_static_string_change(key,
					  old_transport,
					  new_transport,
					  mode);
}

static bool validate_node_address(const char *key,
				  const char *old_node_address,
				  const char *new_node_address,
				  enum conf_update_mode mode)
{
	struct in_addr addr4;
	struct in6_addr addr6;
	int ret;

	if (new_node_address == NULL) {
		goto good;
	}

	ret = inet_pton(AF_INET, new_node_address, &addr4);
	if (ret == 1) {
		goto good;
	}

	ret = inet_pton(AF_INET6, new_node_address, &addr6);
	if (ret == 1) {
		goto good;
	}

	D_ERR("Invalid value for [cluster] -> node address = %s\n",
	      new_node_address);
	return false;

good:
	/* This sometimes warns but always returns true */
	return check_static_string_change(key,
					  old_node_address,
					  new_node_address,
					  mode);
}

static bool validate_recovery_lock(const char *key,
				   const char *old_reclock,
				   const char *new_reclock,
				   enum conf_update_mode mode)
{
	bool status;

	if (new_reclock != NULL) {
		D_WARNING("Configuration option [%s] -> %s is deprecated\n",
			  CLUSTER_CONF_SECTION,
			  key);
	}

	status = check_static_string_change(key, old_reclock, new_reclock, mode);

	return status;
}

static bool validate_leader_timeout(const char *key,
				    int old_timeout,
				    int new_timeout,
				    enum conf_update_mode mode)
{
	if (new_timeout <= 0) {
		D_ERR("Invalid value for [cluster] -> leader timeout = %d\n",
		      new_timeout);
		return false;
	}

	return true;
}

void cluster_conf_init(struct conf_context *conf)
{
	conf_define_section(conf, CLUSTER_CONF_SECTION, NULL);

	conf_define_string(conf,
			   CLUSTER_CONF_SECTION,
			   CLUSTER_CONF_TRANSPORT,
			   CLUSTER_TRANSPORT_DEFAULT,
			   validate_transport);
	conf_define_string(conf,
			   CLUSTER_CONF_SECTION,
			   CLUSTER_CONF_NODE_ADDRESS,
			   NULL,
			   validate_node_address);
	conf_define_string(conf,
			   CLUSTER_CONF_SECTION,
			   CLUSTER_CONF_CLUSTER_LOCK,
			   NULL,
			   check_static_string_change);
	conf_define_string(conf,
			   CLUSTER_CONF_SECTION,
			   CLUSTER_CONF_RECOVERY_LOCK,
			   NULL,
			   validate_recovery_lock);
	conf_define_integer(conf,
			    CLUSTER_CONF_SECTION,
			    CLUSTER_CONF_LEADER_TIMEOUT,
			    5,
			    validate_leader_timeout);
	conf_define_boolean(conf,
			    CLUSTER_CONF_SECTION,
			    CLUSTER_CONF_LEADER_CAPABILITY,
			    true,
			    NULL);
}