ctdb-daemon: Rename struct ctdb_control_set_tunable to ctdb_tunable_old
[obnox/samba/samba-obnox.git] / ctdb / server / ctdb_tunables.c
1 /* 
2    ctdb tunables code
3
4    Copyright (C) Andrew Tridgell  2007
5
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.
10    
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.
15    
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/>.
18 */
19 #include "replace.h"
20 #include "system/network.h"
21
22 #include <talloc.h>
23 #include <tdb.h>
24
25 #include "lib/util/debug.h"
26
27 #include "ctdb_private.h"
28 #include "ctdb_logging.h"
29
30 #include "common/common.h"
31
32 static const struct {
33         const char *name;
34         uint32_t default_v;
35         size_t offset;
36         bool obsolete;
37 } tunable_map[] = {
38         { "MaxRedirectCount",     3,  offsetof(struct ctdb_tunable_list, max_redirect_count), false },
39         { "SeqnumInterval",      1000,  offsetof(struct ctdb_tunable_list, seqnum_interval), false },
40         { "ControlTimeout",      60, offsetof(struct ctdb_tunable_list, control_timeout), false },
41         { "TraverseTimeout",     20, offsetof(struct ctdb_tunable_list, traverse_timeout), false },
42         { "KeepaliveInterval",    5,  offsetof(struct ctdb_tunable_list, keepalive_interval), false },
43         { "KeepaliveLimit",       5,  offsetof(struct ctdb_tunable_list, keepalive_limit), false },
44         { "RecoverTimeout",     120,  offsetof(struct ctdb_tunable_list, recover_timeout), false },
45         { "RecoverInterval",      1,  offsetof(struct ctdb_tunable_list, recover_interval), false },
46         { "ElectionTimeout",      3,  offsetof(struct ctdb_tunable_list, election_timeout), false },
47         { "TakeoverTimeout",      9,  offsetof(struct ctdb_tunable_list, takeover_timeout), false },
48         { "MonitorInterval",     15,  offsetof(struct ctdb_tunable_list, monitor_interval), false },
49         { "TickleUpdateInterval",20,  offsetof(struct ctdb_tunable_list, tickle_update_interval), false },
50         { "EventScriptTimeout",  30,  offsetof(struct ctdb_tunable_list, script_timeout), false },
51         { "EventScriptTimeoutCount", 20,  offsetof(struct ctdb_tunable_list, script_timeout_count), false },
52         { "EventScriptUnhealthyOnTimeout", 0, offsetof(struct ctdb_tunable_list, script_unhealthy_on_timeout), true },
53         { "RecoveryGracePeriod", 120,  offsetof(struct ctdb_tunable_list, recovery_grace_period), false },
54         { "RecoveryBanPeriod",  300,  offsetof(struct ctdb_tunable_list, recovery_ban_period), false },
55         { "DatabaseHashSize", 100001, offsetof(struct ctdb_tunable_list, database_hash_size), false },
56         { "DatabaseMaxDead",      5,  offsetof(struct ctdb_tunable_list, database_max_dead), false },
57         { "RerecoveryTimeout",   10,  offsetof(struct ctdb_tunable_list, rerecovery_timeout), false },
58         { "EnableBans",           1,  offsetof(struct ctdb_tunable_list, enable_bans), false },
59         { "DeterministicIPs",     0,  offsetof(struct ctdb_tunable_list, deterministic_public_ips), false },
60         { "LCP2PublicIPs",        1,  offsetof(struct ctdb_tunable_list, lcp2_public_ip_assignment), false },
61         { "ReclockPingPeriod",   60,  offsetof(struct ctdb_tunable_list,  reclock_ping_period), false },
62         { "NoIPFailback",         0,  offsetof(struct ctdb_tunable_list, no_ip_failback), false },
63         { "DisableIPFailover",    0,  offsetof(struct ctdb_tunable_list, disable_ip_failover), false },
64         { "VerboseMemoryNames",   0,  offsetof(struct ctdb_tunable_list, verbose_memory_names), false },
65         { "RecdPingTimeout",     60,  offsetof(struct ctdb_tunable_list, recd_ping_timeout), false },
66         { "RecdFailCount",       10,  offsetof(struct ctdb_tunable_list, recd_ping_failcount), false },
67         { "LogLatencyMs",         0,  offsetof(struct ctdb_tunable_list, log_latency_ms), false },
68         { "RecLockLatencyMs",  1000,  offsetof(struct ctdb_tunable_list, reclock_latency_ms), false },
69         { "RecoveryDropAllIPs", 120,  offsetof(struct ctdb_tunable_list, recovery_drop_all_ips), false },
70         { "VerifyRecoveryLock",   1,  offsetof(struct ctdb_tunable_list, verify_recovery_lock), true },
71         { "VacuumInterval",   10,  offsetof(struct ctdb_tunable_list, vacuum_interval), false },
72         { "VacuumMaxRunTime",     120,  offsetof(struct ctdb_tunable_list, vacuum_max_run_time), false },
73         { "RepackLimit",      10000,  offsetof(struct ctdb_tunable_list, repack_limit), false },
74         { "VacuumLimit",       5000,  offsetof(struct ctdb_tunable_list, vacuum_limit), false },
75         { "VacuumFastPathCount", 60, offsetof(struct ctdb_tunable_list, vacuum_fast_path_count), false },
76         { "MaxQueueDropMsg",  1000000, offsetof(struct ctdb_tunable_list, max_queue_depth_drop_msg), false },
77         { "AllowUnhealthyDBRead", 0,  offsetof(struct ctdb_tunable_list, allow_unhealthy_db_read), false },
78         { "StatHistoryInterval",  1,  offsetof(struct ctdb_tunable_list, stat_history_interval), false },
79         { "DeferredAttachTO",  120,  offsetof(struct ctdb_tunable_list, deferred_attach_timeout), false },
80         { "AllowClientDBAttach", 1, offsetof(struct ctdb_tunable_list, allow_client_db_attach), false },
81         { "RecoverPDBBySeqNum",  1, offsetof(struct ctdb_tunable_list, recover_pdb_by_seqnum), false },
82         { "DeferredRebalanceOnNodeAdd", 300, offsetof(struct ctdb_tunable_list, deferred_rebalance_on_node_add) },
83         { "FetchCollapse",       1, offsetof(struct ctdb_tunable_list, fetch_collapse) },
84         { "HopcountMakeSticky",   50,  offsetof(struct ctdb_tunable_list, hopcount_make_sticky) },
85         { "StickyDuration",      600,  offsetof(struct ctdb_tunable_list, sticky_duration) },
86         { "StickyPindown",       200,  offsetof(struct ctdb_tunable_list, sticky_pindown) },
87         { "NoIPTakeover",         0,  offsetof(struct ctdb_tunable_list, no_ip_takeover), false },
88         { "DBRecordCountWarn",    100000,  offsetof(struct ctdb_tunable_list, db_record_count_warn), false },
89         { "DBRecordSizeWarn",   10000000,  offsetof(struct ctdb_tunable_list, db_record_size_warn), false },
90         { "DBSizeWarn",        100000000,  offsetof(struct ctdb_tunable_list, db_size_warn), false },
91         { "PullDBPreallocation", 10*1024*1024,  offsetof(struct ctdb_tunable_list, pulldb_preallocation_size), false },
92         { "NoIPHostOnAllDisabled",    0,  offsetof(struct ctdb_tunable_list, no_ip_host_on_all_disabled), false },
93         { "Samba3AvoidDeadlocks", 0, offsetof(struct ctdb_tunable_list, samba3_hack), false },
94         { "TDBMutexEnabled", 0, offsetof(struct ctdb_tunable_list, mutex_enabled), false },
95         { "LockProcessesPerDB", 200, offsetof(struct ctdb_tunable_list, lock_processes_per_db), false },
96 };
97
98 /*
99   set all tunables to defaults
100  */
101 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
102 {
103         int i;
104         for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
105                 *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = tunable_map[i].default_v;
106         }
107 }
108
109
110 /*
111   get a tunable
112  */
113 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata, 
114                                  TDB_DATA *outdata)
115 {
116         struct ctdb_control_get_tunable *t = 
117                 (struct ctdb_control_get_tunable *)indata.dptr;
118         char *name;
119         uint32_t val;
120         int i;
121
122         if (indata.dsize < sizeof(*t) ||
123             t->length > indata.dsize - offsetof(struct ctdb_control_get_tunable, name)) {
124                 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_get_tunable\n"));
125                 return -1;
126         }
127
128         name = talloc_strndup(ctdb, (char*)t->name, t->length);
129         CTDB_NO_MEMORY(ctdb, name);
130
131         for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
132                 if (strcasecmp(name, tunable_map[i].name) == 0) break;
133         }
134         talloc_free(name);
135         
136         if (i == ARRAY_SIZE(tunable_map)) {
137                 return -EINVAL;
138         }
139
140         val = *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable);
141
142         outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
143         CTDB_NO_MEMORY(ctdb, outdata->dptr);
144
145         *(uint32_t *)outdata->dptr = val;
146         outdata->dsize = sizeof(uint32_t);
147
148         return 0;
149 }
150
151
152 /*
153   set a tunable
154  */
155 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
156 {
157         struct ctdb_tunable_old *t =
158                 (struct ctdb_tunable_old *)indata.dptr;
159         char *name;
160         int i;
161
162         if (indata.dsize < sizeof(*t) ||
163             t->length > indata.dsize - offsetof(struct ctdb_tunable_old, name)) {
164                 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_set_tunable\n"));
165                 return -1;
166         }
167
168         name = talloc_strndup(ctdb, (char *)t->name, t->length);
169         CTDB_NO_MEMORY(ctdb, name);
170
171         for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
172                 if (strcasecmp(name, tunable_map[i].name) == 0) break;
173         }
174
175         talloc_free(name);
176
177         if (i == ARRAY_SIZE(tunable_map)) {
178                 return -1;
179         }
180
181         *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = t->value;
182
183         if (tunable_map[i].obsolete) {
184                 DEBUG(DEBUG_WARNING,
185                       ("Setting obsolete tunable \"%s\"\n",
186                        tunable_map[i].name));
187                 return 1;
188         }
189
190         return 0;
191 }
192
193 /*
194   list tunables
195  */
196 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
197 {
198         char *list = NULL;
199         int i;
200         struct ctdb_control_list_tunable *t;
201
202         list = talloc_strdup(outdata, tunable_map[0].name);
203         CTDB_NO_MEMORY(ctdb, list);
204
205         for (i=1;i<ARRAY_SIZE(tunable_map);i++) {
206                 if (tunable_map[i].obsolete) {
207                         continue;
208                 }
209                 list = talloc_asprintf_append(list, ":%s", tunable_map[i].name);
210                 CTDB_NO_MEMORY(ctdb, list);             
211         }
212
213         outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) + 
214                 strlen(list) + 1;
215         outdata->dptr = talloc_size(outdata, outdata->dsize);
216         CTDB_NO_MEMORY(ctdb, outdata->dptr);
217
218         t = (struct ctdb_control_list_tunable *)outdata->dptr;
219         t->length = strlen(list)+1;
220
221         memcpy(t->data, list, t->length);
222         talloc_free(list);
223
224         return 0;       
225 }