4 Copyright (C) Andrew Tridgell 2007
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "../include/ctdb_private.h"
28 { "MaxRedirectCount", 3, offsetof(struct ctdb_tunable, max_redirect_count) },
29 { "SeqnumFrequency", 1, offsetof(struct ctdb_tunable, seqnum_frequency) },
30 { "ControlTimeout", 60, offsetof(struct ctdb_tunable, control_timeout) },
31 { "TraverseTimeout", 20, offsetof(struct ctdb_tunable, traverse_timeout) },
32 { "KeepaliveInterval", 2, offsetof(struct ctdb_tunable, keepalive_interval) },
33 { "KeepaliveLimit", 5, offsetof(struct ctdb_tunable, keepalive_limit) },
34 { "MaxLACount", 7, offsetof(struct ctdb_tunable, max_lacount) },
35 { "RecoverTimeout", 5, offsetof(struct ctdb_tunable, recover_timeout) },
36 { "RecoverInterval", 1, offsetof(struct ctdb_tunable, recover_interval) },
37 { "ElectionTimeout", 3, offsetof(struct ctdb_tunable, election_timeout) },
38 { "TakeoverTimeout", 5, offsetof(struct ctdb_tunable, takeover_timeout) },
39 { "MonitorInterval", 15, offsetof(struct ctdb_tunable, monitor_interval) },
40 { "EventScriptTimeout", 20, offsetof(struct ctdb_tunable, script_timeout) },
41 { "RecoveryGracePeriod", 60, offsetof(struct ctdb_tunable, recovery_grace_period) },
42 { "RecoveryBanPeriod", 300, offsetof(struct ctdb_tunable, recovery_ban_period) },
46 set all tunables to defaults
48 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
51 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
52 *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = tunable_map[i].default_v;
60 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
63 struct ctdb_control_get_tunable *t =
64 (struct ctdb_control_get_tunable *)indata.dptr;
69 if (indata.dsize < sizeof(*t) ||
70 t->length > indata.dsize - offsetof(struct ctdb_control_get_tunable, name)) {
71 DEBUG(0,("Bad indata in ctdb_control_get_tunable\n"));
75 name = talloc_strndup(ctdb, (char*)t->name, t->length);
76 CTDB_NO_MEMORY(ctdb, name);
78 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
79 if (strcasecmp(name, tunable_map[i].name) == 0) break;
83 if (i == ARRAY_SIZE(tunable_map)) {
87 val = *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable);
89 outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
90 CTDB_NO_MEMORY(ctdb, outdata->dptr);
92 *(uint32_t *)outdata->dptr = val;
93 outdata->dsize = sizeof(uint32_t);
102 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
104 struct ctdb_control_set_tunable *t =
105 (struct ctdb_control_set_tunable *)indata.dptr;
109 if (indata.dsize < sizeof(*t) ||
110 t->length > indata.dsize - offsetof(struct ctdb_control_set_tunable, name)) {
111 DEBUG(0,("Bad indata in ctdb_control_set_tunable\n"));
115 name = talloc_strndup(ctdb, (char *)t->name, t->length);
116 CTDB_NO_MEMORY(ctdb, name);
118 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
119 if (strcasecmp(name, tunable_map[i].name) == 0) break;
124 if (i == ARRAY_SIZE(tunable_map)) {
128 *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = t->value;
136 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
140 struct ctdb_control_list_tunable *t;
142 list = talloc_strdup(outdata, tunable_map[0].name);
143 CTDB_NO_MEMORY(ctdb, list);
145 for (i=1;i<ARRAY_SIZE(tunable_map);i++) {
146 list = talloc_asprintf_append(list, ":%s", tunable_map[i].name);
147 CTDB_NO_MEMORY(ctdb, list);
150 outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) +
152 outdata->dptr = talloc_size(outdata, outdata->dsize);
153 CTDB_NO_MEMORY(ctdb, outdata->dptr);
155 t = (struct ctdb_control_list_tunable *)outdata->dptr;
156 t->length = strlen(list)+1;
158 memcpy(t->data, list, t->length);