s3: VFS: vfs_snapper: Make chflags return errno = EROFS on a shadow copy path.
[Samba.git] / ctdb / server / ctdb_tunables.c
blobae2778d6cdfb48a34a98eec735b27cbc0b1cffbb
1 /*
2 ctdb tunables code
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/>.
19 #include "replace.h"
20 #include "system/network.h"
22 #include <talloc.h>
23 #include <tdb.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/tunable.h"
34 set all tunables to defaults
36 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
38 ctdb_tunable_set_defaults(&ctdb->tunable);
43 get a tunable
45 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
46 TDB_DATA *outdata)
48 struct ctdb_control_get_tunable *t =
49 (struct ctdb_control_get_tunable *)indata.dptr;
50 char *name;
51 uint32_t val;
52 bool ret;
54 if (indata.dsize < sizeof(*t) ||
55 t->length > indata.dsize - offsetof(struct ctdb_control_get_tunable, name)) {
56 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_get_tunable\n"));
57 return -1;
60 name = talloc_strndup(ctdb, (char*)t->name, t->length);
61 CTDB_NO_MEMORY(ctdb, name);
63 ret = ctdb_tunable_get_value(&ctdb->tunable, name, &val);
64 talloc_free(name);
65 if (! ret) {
66 return -EINVAL;
69 outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
70 CTDB_NO_MEMORY(ctdb, outdata->dptr);
72 *(uint32_t *)outdata->dptr = val;
73 outdata->dsize = sizeof(uint32_t);
75 return 0;
80 set a tunable
82 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
84 struct ctdb_tunable_old *t =
85 (struct ctdb_tunable_old *)indata.dptr;
86 char *name;
87 int ret;
88 bool obsolete;
90 if (indata.dsize < sizeof(*t) ||
91 t->length > indata.dsize - offsetof(struct ctdb_tunable_old, name)) {
92 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_set_tunable\n"));
93 return -1;
96 name = talloc_strndup(ctdb, (char *)t->name, t->length);
97 CTDB_NO_MEMORY(ctdb, name);
99 ret = ctdb_tunable_set_value(&ctdb->tunable, name, t->value,
100 &obsolete);
101 if (! ret) {
102 talloc_free(name);
103 return -1;
106 if (obsolete) {
107 DEBUG(DEBUG_WARNING,
108 ("Setting obsolete tunable \"%s\"\n", name));
109 talloc_free(name);
110 return 1;
113 talloc_free(name);
114 return 0;
118 list tunables
120 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
122 char *list = NULL;
123 struct ctdb_control_list_tunable *t;
125 list = ctdb_tunable_names_to_string(outdata);
126 CTDB_NO_MEMORY(ctdb, list);
128 outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) +
129 strlen(list) + 1;
130 outdata->dptr = talloc_size(outdata, outdata->dsize);
131 CTDB_NO_MEMORY(ctdb, outdata->dptr);
133 t = (struct ctdb_control_list_tunable *)outdata->dptr;
134 t->length = strlen(list)+1;
136 memcpy(t->data, list, t->length);
137 talloc_free(list);
139 return 0;