auth3: only use "sam_netlogon3 winbind:trustdomain" in make_auth3_context_for_netlogon
[Samba.git] / ctdb / common / tunable.c
blob5b640d9a902daf4cb8c8d7d31740e7c1ad8846b7
1 /*
2 Tunables utilities
4 Copyright (C) Amitay Isaacs 2016
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/locale.h"
22 #include "system/network.h"
24 #include <talloc.h>
26 #include "protocol/protocol.h"
28 #include "common/tunable.h"
30 static struct {
31 const char *label;
32 uint32_t value;
33 bool obsolete;
34 size_t offset;
35 } tunable_map[] = {
36 { "MaxRedirectCount", 3, true,
37 offsetof(struct ctdb_tunable_list, max_redirect_count) },
38 { "SeqnumInterval", 1000, false,
39 offsetof(struct ctdb_tunable_list, seqnum_interval) },
40 { "ControlTimeout", 60, false,
41 offsetof(struct ctdb_tunable_list, control_timeout) },
42 { "TraverseTimeout", 20, false,
43 offsetof(struct ctdb_tunable_list, traverse_timeout) },
44 { "KeepaliveInterval", 5, false,
45 offsetof(struct ctdb_tunable_list, keepalive_interval) },
46 { "KeepaliveLimit", 5, false,
47 offsetof(struct ctdb_tunable_list, keepalive_limit) },
48 { "RecoverTimeout", 30, false,
49 offsetof(struct ctdb_tunable_list, recover_timeout) },
50 { "RecoverInterval", 1, false,
51 offsetof(struct ctdb_tunable_list, recover_interval) },
52 { "ElectionTimeout", 3, false,
53 offsetof(struct ctdb_tunable_list, election_timeout) },
54 { "TakeoverTimeout", 9, false,
55 offsetof(struct ctdb_tunable_list, takeover_timeout) },
56 { "MonitorInterval", 15, false,
57 offsetof(struct ctdb_tunable_list, monitor_interval) },
58 { "TickleUpdateInterval", 20, false,
59 offsetof(struct ctdb_tunable_list, tickle_update_interval) },
60 { "EventScriptTimeout", 30, false,
61 offsetof(struct ctdb_tunable_list, script_timeout) },
62 { "MonitorTimeoutCount", 20, false,
63 offsetof(struct ctdb_tunable_list, monitor_timeout_count) },
64 { "EventScriptUnhealthyOnTimeout", 0, true,
65 offsetof(struct ctdb_tunable_list, script_unhealthy_on_timeout) },
66 { "RecoveryGracePeriod", 120, false,
67 offsetof(struct ctdb_tunable_list, recovery_grace_period) },
68 { "RecoveryBanPeriod", 300, false,
69 offsetof(struct ctdb_tunable_list, recovery_ban_period) },
70 { "DatabaseHashSize", 100001, false,
71 offsetof(struct ctdb_tunable_list, database_hash_size) },
72 { "DatabaseMaxDead", 5, false,
73 offsetof(struct ctdb_tunable_list, database_max_dead) },
74 { "RerecoveryTimeout", 10, false,
75 offsetof(struct ctdb_tunable_list, rerecovery_timeout) },
76 { "EnableBans", 1, false,
77 offsetof(struct ctdb_tunable_list, enable_bans) },
78 { "DeterministicIPs", 0, true,
79 offsetof(struct ctdb_tunable_list, deterministic_public_ips) },
80 { "LCP2PublicIPs", 1, true,
81 offsetof(struct ctdb_tunable_list, lcp2_public_ip_assignment) },
82 { "ReclockPingPeriod", 60, true,
83 offsetof(struct ctdb_tunable_list, reclock_ping_period) },
84 { "NoIPFailback", 0, false,
85 offsetof(struct ctdb_tunable_list, no_ip_failback) },
86 { "DisableIPFailover", 0, false,
87 offsetof(struct ctdb_tunable_list, disable_ip_failover) },
88 { "VerboseMemoryNames", 0, false,
89 offsetof(struct ctdb_tunable_list, verbose_memory_names) },
90 { "RecdPingTimeout", 60, false,
91 offsetof(struct ctdb_tunable_list, recd_ping_timeout) },
92 { "RecdFailCount", 10, false,
93 offsetof(struct ctdb_tunable_list, recd_ping_failcount) },
94 { "LogLatencyMs", 0, false,
95 offsetof(struct ctdb_tunable_list, log_latency_ms) },
96 { "RecLockLatencyMs", 1000, false,
97 offsetof(struct ctdb_tunable_list, reclock_latency_ms) },
98 { "RecoveryDropAllIPs", 120, false,
99 offsetof(struct ctdb_tunable_list, recovery_drop_all_ips) },
100 { "VerifyRecoveryLock", 1, true,
101 offsetof(struct ctdb_tunable_list, verify_recovery_lock) },
102 { "VacuumInterval", 10, false,
103 offsetof(struct ctdb_tunable_list, vacuum_interval) },
104 { "VacuumMaxRunTime", 120, false,
105 offsetof(struct ctdb_tunable_list, vacuum_max_run_time) },
106 { "RepackLimit", 10*1000, false,
107 offsetof(struct ctdb_tunable_list, repack_limit) },
108 { "VacuumLimit", 5*1000, false,
109 offsetof(struct ctdb_tunable_list, vacuum_limit) },
110 { "VacuumFastPathCount", 60, false,
111 offsetof(struct ctdb_tunable_list, vacuum_fast_path_count) },
112 { "MaxQueueDropMsg", 1000*1000, false,
113 offsetof(struct ctdb_tunable_list, max_queue_depth_drop_msg) },
114 { "AllowUnhealthyDBRead", 0, false,
115 offsetof(struct ctdb_tunable_list, allow_unhealthy_db_read) },
116 { "StatHistoryInterval", 1, false,
117 offsetof(struct ctdb_tunable_list, stat_history_interval) },
118 { "DeferredAttachTO", 120, false,
119 offsetof(struct ctdb_tunable_list, deferred_attach_timeout) },
120 { "AllowClientDBAttach", 1, false,
121 offsetof(struct ctdb_tunable_list, allow_client_db_attach) },
122 { "RecoverPDBBySeqNum", 1, true,
123 offsetof(struct ctdb_tunable_list, recover_pdb_by_seqnum) },
124 { "DeferredRebalanceOnNodeAdd", 300, true,
125 offsetof(struct ctdb_tunable_list, deferred_rebalance_on_node_add) },
126 { "FetchCollapse", 1, false,
127 offsetof(struct ctdb_tunable_list, fetch_collapse) },
128 { "HopcountMakeSticky", 50, false,
129 offsetof(struct ctdb_tunable_list, hopcount_make_sticky) },
130 { "StickyDuration", 600, false,
131 offsetof(struct ctdb_tunable_list, sticky_duration) },
132 { "StickyPindown", 200, false,
133 offsetof(struct ctdb_tunable_list, sticky_pindown) },
134 { "NoIPTakeover", 0, false,
135 offsetof(struct ctdb_tunable_list, no_ip_takeover) },
136 { "DBRecordCountWarn", 100*1000, false,
137 offsetof(struct ctdb_tunable_list, db_record_count_warn) },
138 { "DBRecordSizeWarn", 10*1000*1000, false,
139 offsetof(struct ctdb_tunable_list, db_record_size_warn) },
140 { "DBSizeWarn", 100*1000*1000, false,
141 offsetof(struct ctdb_tunable_list, db_size_warn) },
142 { "PullDBPreallocation", 10*1024*1024, false,
143 offsetof(struct ctdb_tunable_list, pulldb_preallocation_size) },
144 { "NoIPHostOnAllDisabled", 0, false,
145 offsetof(struct ctdb_tunable_list, no_ip_host_on_all_disabled) },
146 { "Samba3AvoidDeadlocks", 0, true,
147 offsetof(struct ctdb_tunable_list, samba3_hack) },
148 { "TDBMutexEnabled", 0, false,
149 offsetof(struct ctdb_tunable_list, mutex_enabled) },
150 { "LockProcessesPerDB", 200, false,
151 offsetof(struct ctdb_tunable_list, lock_processes_per_db) },
152 { "RecBufferSizeLimit", 1000*1000, false,
153 offsetof(struct ctdb_tunable_list, rec_buffer_size_limit) },
154 { "QueueBufferSize", 1024, false,
155 offsetof(struct ctdb_tunable_list, queue_buffer_size) },
156 { "IPAllocAlgorithm", 2, false,
157 offsetof(struct ctdb_tunable_list, ip_alloc_algorithm) },
158 { NULL, 0, true, }
161 void ctdb_tunable_set_defaults(struct ctdb_tunable_list *tun_list)
163 int i;
165 for (i=0; tunable_map[i].label != NULL; i++) {
166 size_t offset = tunable_map[i].offset;
167 uint32_t value = tunable_map[i].value;
168 uint32_t *value_ptr;
170 value_ptr = (uint32_t *)((uint8_t *)tun_list + offset);
171 *value_ptr = value;
175 bool ctdb_tunable_get_value(struct ctdb_tunable_list *tun_list,
176 const char *tunable_str, uint32_t *value)
178 int i;
180 for (i=0; tunable_map[i].label != NULL; i++) {
181 if (strcasecmp(tunable_map[i].label, tunable_str) == 0) {
182 uint32_t *value_ptr;
184 value_ptr = (uint32_t *)((uint8_t *)tun_list +
185 tunable_map[i].offset);
186 *value = *value_ptr;
187 return true;
191 return false;
194 bool ctdb_tunable_set_value(struct ctdb_tunable_list *tun_list,
195 const char *tunable_str, uint32_t value,
196 bool *obsolete)
198 int i;
200 for (i=0; tunable_map[i].label != NULL; i++) {
201 if (strcasecmp(tunable_map[i].label, tunable_str) == 0) {
202 uint32_t *value_ptr;
204 value_ptr = (uint32_t *)((uint8_t *)tun_list +
205 tunable_map[i].offset);
206 *value_ptr = value;
207 if (obsolete != NULL) {
208 *obsolete = tunable_map[i].obsolete;
210 return true;
214 return false;
217 struct ctdb_var_list *ctdb_tunable_names(TALLOC_CTX *mem_ctx)
219 struct ctdb_var_list *list;
220 int i;
222 list = talloc_zero(mem_ctx, struct ctdb_var_list);
223 if (list == NULL) {
224 return NULL;
227 for (i=0; tunable_map[i].label != NULL; i++) {
228 if (tunable_map[i].obsolete) {
229 continue;
232 list->var = talloc_realloc(list, list->var, const char *,
233 list->count + 1);
234 if (list->var == NULL) {
235 goto fail;
238 list->var[list->count] = talloc_strdup(list,
239 tunable_map[i].label);
240 if (list->var[list->count] == NULL) {
241 goto fail;
244 list->count += 1;
247 return list;
249 fail:
250 TALLOC_FREE(list);
251 return NULL;
254 char *ctdb_tunable_names_to_string(TALLOC_CTX *mem_ctx)
256 char *str = NULL;
257 int i;
259 str = talloc_strdup(mem_ctx, ":");
260 if (str == NULL) {
261 return NULL;
264 for (i=0; tunable_map[i].label != NULL; i++) {
265 if (tunable_map[i].obsolete) {
266 continue;
269 str = talloc_asprintf_append(str, "%s:",
270 tunable_map[i].label);
271 if (str == NULL) {
272 return NULL;
276 /* Remove the last ':' */
277 str[strlen(str)-1] = '\0';
279 return str;