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 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 "system/network.h"
25 #include "lib/util/debug.h"
27 #include "ctdb_private.h"
29 #include "common/common.h"
30 #include "common/logging.h"
31 #include "common/path.h"
32 #include "common/tunable.h"
35 set all tunables to defaults
37 void ctdb_tunables_set_defaults(struct ctdb_context
*ctdb
)
39 ctdb_tunable_set_defaults(&ctdb
->tunable
);
46 int32_t ctdb_control_get_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
,
49 struct ctdb_control_get_tunable
*t
=
50 (struct ctdb_control_get_tunable
*)indata
.dptr
;
55 if (indata
.dsize
< sizeof(*t
) ||
56 t
->length
> indata
.dsize
- offsetof(struct ctdb_control_get_tunable
, name
)) {
57 DEBUG(DEBUG_ERR
,("Bad indata in ctdb_control_get_tunable\n"));
61 name
= talloc_strndup(ctdb
, (char*)t
->name
, t
->length
);
62 CTDB_NO_MEMORY(ctdb
, name
);
64 ret
= ctdb_tunable_get_value(&ctdb
->tunable
, name
, &val
);
70 outdata
->dptr
= (uint8_t *)talloc(outdata
, uint32_t);
71 CTDB_NO_MEMORY(ctdb
, outdata
->dptr
);
73 *(uint32_t *)outdata
->dptr
= val
;
74 outdata
->dsize
= sizeof(uint32_t);
83 int32_t ctdb_control_set_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
)
85 struct ctdb_tunable_old
*t
=
86 (struct ctdb_tunable_old
*)indata
.dptr
;
91 if (indata
.dsize
< sizeof(*t
) ||
92 t
->length
> indata
.dsize
- offsetof(struct ctdb_tunable_old
, name
)) {
93 DEBUG(DEBUG_ERR
,("Bad indata in ctdb_control_set_tunable\n"));
97 name
= talloc_strndup(ctdb
, (char *)t
->name
, t
->length
);
98 CTDB_NO_MEMORY(ctdb
, name
);
100 ret
= ctdb_tunable_set_value(&ctdb
->tunable
, name
, t
->value
,
109 ("Setting obsolete tunable \"%s\"\n", name
));
121 int32_t ctdb_control_list_tunables(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
)
124 struct ctdb_control_list_tunable
*t
;
126 list
= ctdb_tunable_names_to_string(outdata
);
127 CTDB_NO_MEMORY(ctdb
, list
);
129 outdata
->dsize
= offsetof(struct ctdb_control_list_tunable
, data
) +
131 outdata
->dptr
= talloc_size(outdata
, outdata
->dsize
);
132 CTDB_NO_MEMORY(ctdb
, outdata
->dptr
);
134 t
= (struct ctdb_control_list_tunable
*)outdata
->dptr
;
135 t
->length
= strlen(list
)+1;
137 memcpy(t
->data
, list
, t
->length
);
143 bool ctdb_tunables_load(struct ctdb_context
*ctdb
)
149 /* Fail by default */
152 tmp_ctx
= talloc_new(ctdb
);
153 if (tmp_ctx
== NULL
) {
154 DBG_ERR("Memory allocation error\n");
158 file
= path_etcdir_append(tmp_ctx
, "ctdb.tunables");
160 D_ERR("Failed to construct path for ctdb.tunables\n");
164 status
= ctdb_tunable_load_file(tmp_ctx
, &ctdb
->tunable
, file
);
165 /* No need to log error, already logged above */
168 talloc_free(tmp_ctx
);