~ubuntu-branches/ubuntu/vivid/ctdb/vivid-proposed

« back to all changes in this revision

Viewing changes to server/ctdb_tunables.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Parent
  • Date: 2008-04-26 15:21:27 UTC
  • Revision ID: james.westby@ubuntu.com-20080426152127-58mv5ojv5q362ise
Tags: upstream-1.0.34+git200804242206
ImportĀ upstreamĀ versionĀ 1.0.34+git200804242206

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "includes.h"
 
20
#include "../include/ctdb_private.h"
 
21
 
 
22
static const struct {
 
23
        const char *name;
 
24
        uint32_t default_v;
 
25
        size_t offset;  
 
26
} tunable_map[] = {
 
27
        { "MaxRedirectCount",     3,  offsetof(struct ctdb_tunable, max_redirect_count) },
 
28
        { "SeqnumFrequency",      1,  offsetof(struct ctdb_tunable, seqnum_frequency) },
 
29
        { "ControlTimeout",      60, offsetof(struct ctdb_tunable, control_timeout) },
 
30
        { "TraverseTimeout",     20, offsetof(struct ctdb_tunable, traverse_timeout) },
 
31
        { "KeepaliveInterval",    5,  offsetof(struct ctdb_tunable, keepalive_interval) },
 
32
        { "KeepaliveLimit",       5,  offsetof(struct ctdb_tunable, keepalive_limit) },
 
33
        { "MaxLACount",           7,  offsetof(struct ctdb_tunable, max_lacount) },
 
34
        { "RecoverTimeout",      30,  offsetof(struct ctdb_tunable, recover_timeout) },
 
35
        { "RecoverInterval",      1,  offsetof(struct ctdb_tunable, recover_interval) },
 
36
        { "ElectionTimeout",      3,  offsetof(struct ctdb_tunable, election_timeout) },
 
37
        { "TakeoverTimeout",      5,  offsetof(struct ctdb_tunable, takeover_timeout) },
 
38
        { "MonitorInterval",     15,  offsetof(struct ctdb_tunable, monitor_interval) },
 
39
        { "TickleUpdateInterval",20,  offsetof(struct ctdb_tunable, tickle_update_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) },
 
43
        { "DatabaseHashSize", 10000,  offsetof(struct ctdb_tunable, database_hash_size) },
 
44
        { "DatabaseMaxDead",      5,  offsetof(struct ctdb_tunable, database_max_dead) },
 
45
        { "RerecoveryTimeout",   10,  offsetof(struct ctdb_tunable, rerecovery_timeout) },
 
46
        { "EnableBans",           1,  offsetof(struct ctdb_tunable, enable_bans) },
 
47
        { "DeterministicIPs",     1,  offsetof(struct ctdb_tunable, deterministic_public_ips) },
 
48
        { "DisableWhenUnhealthy", 0,  offsetof(struct ctdb_tunable, disable_when_unhealthy) },
 
49
        { "ReclockPingPeriod",   60,  offsetof(struct ctdb_tunable,  reclock_ping_period) },
 
50
        { "NoIPFailback",         0,  offsetof(struct ctdb_tunable, no_ip_failback) },
 
51
        { "VerboseMemoryNames",   0,  offsetof(struct ctdb_tunable, verbose_memory_names) },
 
52
};
 
53
 
 
54
/*
 
55
  set all tunables to defaults
 
56
 */
 
57
void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
 
58
{
 
59
        int i;
 
60
        for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
 
61
                *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = tunable_map[i].default_v;
 
62
        }
 
63
}
 
64
 
 
65
 
 
66
/*
 
67
  get a tunable
 
68
 */
 
69
int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata, 
 
70
                                 TDB_DATA *outdata)
 
71
{
 
72
        struct ctdb_control_get_tunable *t = 
 
73
                (struct ctdb_control_get_tunable *)indata.dptr;
 
74
        char *name;
 
75
        uint32_t val;
 
76
        int i;
 
77
 
 
78
        if (indata.dsize < sizeof(*t) ||
 
79
            t->length > indata.dsize - offsetof(struct ctdb_control_get_tunable, name)) {
 
80
                DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_get_tunable\n"));
 
81
                return -1;
 
82
        }
 
83
 
 
84
        name = talloc_strndup(ctdb, (char*)t->name, t->length);
 
85
        CTDB_NO_MEMORY(ctdb, name);
 
86
 
 
87
        for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
 
88
                if (strcasecmp(name, tunable_map[i].name) == 0) break;
 
89
        }
 
90
        talloc_free(name);
 
91
        
 
92
        if (i == ARRAY_SIZE(tunable_map)) {
 
93
                return -1;
 
94
        }
 
95
 
 
96
        val = *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable);
 
97
 
 
98
        outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
 
99
        CTDB_NO_MEMORY(ctdb, outdata->dptr);
 
100
 
 
101
        *(uint32_t *)outdata->dptr = val;
 
102
        outdata->dsize = sizeof(uint32_t);
 
103
 
 
104
        return 0;
 
105
}
 
106
 
 
107
 
 
108
/*
 
109
  set a tunable
 
110
 */
 
111
int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
 
112
{
 
113
        struct ctdb_control_set_tunable *t = 
 
114
                (struct ctdb_control_set_tunable *)indata.dptr;
 
115
        char *name;
 
116
        int i;
 
117
 
 
118
        if (indata.dsize < sizeof(*t) ||
 
119
            t->length > indata.dsize - offsetof(struct ctdb_control_set_tunable, name)) {
 
120
                DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_set_tunable\n"));
 
121
                return -1;
 
122
        }
 
123
 
 
124
        name = talloc_strndup(ctdb, (char *)t->name, t->length);
 
125
        CTDB_NO_MEMORY(ctdb, name);
 
126
 
 
127
        for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
 
128
                if (strcasecmp(name, tunable_map[i].name) == 0) break;
 
129
        }
 
130
 
 
131
        talloc_free(name);
 
132
        
 
133
        if (i == ARRAY_SIZE(tunable_map)) {
 
134
                return -1;
 
135
        }
 
136
        
 
137
        *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = t->value;
 
138
 
 
139
        return 0;
 
140
}
 
141
 
 
142
/*
 
143
  list tunables
 
144
 */
 
145
int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
 
146
{
 
147
        char *list = NULL;
 
148
        int i;
 
149
        struct ctdb_control_list_tunable *t;
 
150
 
 
151
        list = talloc_strdup(outdata, tunable_map[0].name);
 
152
        CTDB_NO_MEMORY(ctdb, list);
 
153
 
 
154
        for (i=1;i<ARRAY_SIZE(tunable_map);i++) {
 
155
                list = talloc_asprintf_append(list, ":%s", tunable_map[i].name);
 
156
                CTDB_NO_MEMORY(ctdb, list);             
 
157
        }
 
158
 
 
159
        outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) + 
 
160
                strlen(list) + 1;
 
161
        outdata->dptr = talloc_size(outdata, outdata->dsize);
 
162
        CTDB_NO_MEMORY(ctdb, outdata->dptr);
 
163
 
 
164
        t = (struct ctdb_control_list_tunable *)outdata->dptr;
 
165
        t->length = strlen(list)+1;
 
166
 
 
167
        memcpy(t->data, list, t->length);
 
168
        talloc_free(list);
 
169
 
 
170
        return 0;       
 
171
}