ctdb-client: Remove ununsed functions from old client code
[samba.git] / ctdb / include / ctdb_client.h
1 /*
2    ctdb database library: old client interface
3
4    Copyright (C) Andrew Tridgell  2006
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
20 #ifndef _CTDB_CLIENT_H
21 #define _CTDB_CLIENT_H
22
23 #include "common/srvid.h"
24 #include "ctdb_protocol.h"
25
26 enum control_state {
27         CTDB_CONTROL_WAIT,
28         CTDB_CONTROL_DONE,
29         CTDB_CONTROL_ERROR,
30         CTDB_CONTROL_TIMEOUT
31 };
32
33 struct ctdb_client_control_state {
34         struct ctdb_context *ctdb;
35         uint32_t reqid;
36         int32_t status;
37         TDB_DATA outdata;
38         enum control_state state;
39         char *errormsg;
40         struct ctdb_req_control_old *c;
41
42         /* if we have a callback registered for the completion (or failure) of
43            this control
44            if a callback is used, it MUST talloc_free the cb_data passed to it
45         */
46         struct {
47                 void (*fn)(struct ctdb_client_control_state *);
48                 void *private_data;
49         } async;
50 };
51
52 struct tevent_context;
53 struct ctdb_db_context;
54
55 /*
56   allocate a packet for use in client<->daemon communication
57  */
58 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
59                                             TALLOC_CTX *mem_ctx,
60                                             enum ctdb_operation operation,
61                                             size_t length, size_t slength,
62                                             const char *type);
63
64 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
65         (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, \
66                                     sizeof(type), #type)
67
68 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
69                     struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx,
70                     TDB_DATA *data, bool updatetdb);
71
72 void ctdb_request_message(struct ctdb_context *ctdb,
73                           struct ctdb_req_header *hdr);
74
75 void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
76
77 int ctdb_socket_connect(struct ctdb_context *ctdb);
78
79 /*
80   make a ctdb call. The associated ctdb call function will be called on the DMASTER
81   for the given record
82 */
83 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
84                                               struct ctdb_call *call);
85 int ctdb_call_recv(struct ctdb_client_call_state *state,
86                    struct ctdb_call *call);
87 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
88
89 /* setup a handler for ctdb messages */
90 typedef void (*ctdb_msg_fn_t)(struct ctdb_context *, uint64_t srvid,
91                               TDB_DATA data, void *);
92
93 int ctdb_client_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
94                                     srvid_handler_fn handler,
95                                     void *private_data);
96 int ctdb_client_remove_message_handler(struct ctdb_context *ctdb,
97                                        uint64_t srvid, void *private_data);
98
99 /* send a ctdb message */
100 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t pnn,
101                              uint64_t srvid, TDB_DATA data);
102
103 struct ctdb_client_control_state *ctdb_control_send(struct ctdb_context *ctdb,
104                                                     uint32_t destnode,
105                                                     uint64_t srvid,
106                                                     uint32_t opcode,
107                                                     uint32_t flags,
108                                                     TDB_DATA data,
109                                                     TALLOC_CTX *mem_ctx,
110                                                     struct timeval *timeout,
111                                                     char **errormsg);
112 int ctdb_control_recv(struct ctdb_context *ctdb,
113                       struct ctdb_client_control_state *state,
114                       TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
115                       int32_t *status, char **errormsg);
116 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
117                  uint32_t opcode, uint32_t flags, TDB_DATA data,
118                  TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
119                  struct timeval *timeout, char **errormsg);
120
121 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout,
122                         uint32_t destnode, TALLOC_CTX *mem_ctx,
123                         struct ctdb_vnn_map **vnnmap);
124
125 /*
126   get the recovery mode of a remote node
127  */
128 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(
129                                         struct ctdb_context *ctdb,
130                                         TALLOC_CTX *mem_ctx,
131                                         struct timeval timeout,
132                                         uint32_t destnode);
133 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
134                               struct ctdb_client_control_state *state,
135                               uint32_t *recmode);
136 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
137                          struct timeval timeout, uint32_t destnode,
138                          uint32_t *recmode);
139
140 /*
141   set the recovery mode of a remote node
142  */
143 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout,
144                          uint32_t destnode, uint32_t recmode);
145
146 /*
147   get the recovery master of a remote node
148  */
149 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(
150                                         struct ctdb_context *ctdb,
151                                         TALLOC_CTX *mem_ctx,
152                                         struct timeval timeout,
153                                         uint32_t destnode);
154 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb,
155                                 TALLOC_CTX *mem_ctx,
156                                 struct ctdb_client_control_state *state,
157                                 uint32_t *recmaster);
158 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
159                            struct timeval timeout, uint32_t destnode,
160                            uint32_t *recmaster);
161
162 /*
163   set the recovery master of a remote node
164  */
165 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout,
166                            uint32_t destnode, uint32_t recmaster);
167
168 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, struct timeval timeout,
169                        uint32_t destnode, TALLOC_CTX *mem_ctx,
170                        struct ctdb_dbid_map_old **dbmap);
171
172 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, struct timeval timeout,
173                          uint32_t destnode, TALLOC_CTX *mem_ctx,
174                          struct ctdb_node_map_old **nodemap);
175
176 int ctdb_ctrl_get_runstate(struct ctdb_context *ctdb, struct timeval timeout,
177                            uint32_t destnode, uint32_t *runstate);
178
179 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout,
180                         uint32_t destnode, uint32_t dbid,
181                         TALLOC_CTX *mem_ctx, const char **path);
182 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout,
183                         uint32_t destnode, uint32_t dbid,
184                         TALLOC_CTX *mem_ctx, const char **name);
185
186 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
187                        uint32_t destnode, TALLOC_CTX *mem_ctx,
188                        const char *name, uint8_t db_flags, uint32_t *db_id);
189
190 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode,
191                              int32_t *level);
192
193 /*
194   attach to a ctdb database
195 */
196 int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
197                             int *tdb_flags);
198
199 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
200                                     struct timeval timeout,
201                                     const char *name,
202                                     uint8_t db_flags);
203
204 /* a ctdb call function */
205 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
206
207 /*
208   setup a ctdb call function
209 */
210 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
211
212 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
213                      uint32_t destnode);
214
215 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout,
216                      uint32_t destnode);
217
218 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
219                                    struct timeval timeout, uint32_t destnode,
220                                    TALLOC_CTX *mem_ctx, uint32_t flags,
221                                    struct ctdb_public_ip_list_old **ips);
222 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
223                              struct timeval timeout, uint32_t destnode,
224                              TALLOC_CTX *mem_ctx,
225                              struct ctdb_public_ip_list_old **ips);
226
227 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
228                          struct timeval timeout, uint32_t destnode,
229                          TALLOC_CTX *mem_ctx,
230                          struct ctdb_iface_list_old **ifaces);
231
232 int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
233                        struct timeval timeout,
234                        uint32_t destnode,
235                        uint32_t set, uint32_t clear);
236
237 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
238                                struct timeval timeout, uint32_t destnode,
239                                struct ctdb_tunable_list *tunables);
240
241 /*
242   initialise ctdb subsystem
243 */
244 struct ctdb_context *ctdb_init(struct tevent_context *ev);
245
246 /*
247   set some flags
248 */
249 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
250
251 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
252 const char *ctdb_get_socketname(struct ctdb_context *ctdb);
253
254 /* return pnn of this node */
255 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
256
257 typedef void (*client_async_callback)(struct ctdb_context *ctdb,
258                                       uint32_t node_pnn, int32_t res,
259                                       TDB_DATA outdata, void *callback_data);
260
261 struct client_async_data {
262         enum ctdb_controls opcode;
263         bool dont_log_errors;
264         uint32_t count;
265         uint32_t fail_count;
266         client_async_callback callback;
267         client_async_callback fail_callback;
268         void *callback_data;
269 };
270
271 void ctdb_client_async_add(struct client_async_data *data,
272                            struct ctdb_client_control_state *state);
273 int ctdb_client_async_wait(struct ctdb_context *ctdb,
274                            struct client_async_data *data);
275 int ctdb_client_async_control(struct ctdb_context *ctdb,
276                               enum ctdb_controls opcode, uint32_t *nodes,
277                               uint64_t srvid, struct timeval timeout,
278                               bool dont_log_errors, TDB_DATA data,
279                               client_async_callback client_callback,
280                               client_async_callback fail_callback,
281                               void *callback_data);
282
283 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
284                                struct ctdb_vnn_map *vnn_map,
285                                TALLOC_CTX *mem_ctx, bool include_self);
286
287 uint32_t *list_of_nodes(struct ctdb_context *ctdb,
288                         struct ctdb_node_map_old *node_map,
289                         TALLOC_CTX *mem_ctx, uint32_t mask, int exclude_pnn);
290 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
291                                struct ctdb_node_map_old *node_map,
292                                TALLOC_CTX *mem_ctx, bool include_self);
293 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
294                                   struct ctdb_node_map_old *node_map,
295                                   TALLOC_CTX *mem_ctx, bool include_self);
296
297 /*
298   get capabilities of a remote node
299  */
300
301 struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(
302                                         struct ctdb_context *ctdb,
303                                         TALLOC_CTX *mem_ctx,
304                                         struct timeval timeout,
305                                         uint32_t destnode);
306 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb,
307                                    TALLOC_CTX *mem_ctx,
308                                    struct ctdb_client_control_state *state,
309                                    uint32_t *capabilities);
310 int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb,
311                               struct timeval timeout, uint32_t destnode,
312                               uint32_t *capabilities);
313
314 struct ctdb_node_capabilities {
315         bool retrieved;
316         uint32_t capabilities;
317 };
318
319 /* Retrieve capabilities for all connected nodes.  The length of the
320  * returned array can be calculated using talloc_array_length(). */
321 struct ctdb_node_capabilities *ctdb_get_capabilities(
322                                         struct ctdb_context *ctdb,
323                                         TALLOC_CTX *mem_ctx,
324                                         struct timeval timeout,
325                                         struct ctdb_node_map_old *nodemap);
326
327 /* Get capabilities for specified node, NULL if not found */
328 uint32_t *ctdb_get_node_capabilities(struct ctdb_node_capabilities *caps,
329                                      uint32_t pnn);
330
331 /* True if the given node has all of the required capabilities */
332 bool ctdb_node_has_capabilities(struct ctdb_node_capabilities *caps,
333                                 uint32_t pnn, uint32_t capabilities_required);
334
335 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
336
337 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb,
338                                        struct timeval timeout, double latency);
339
340 int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout,
341                       uint32_t destnode, struct ctdb_ban_state *bantime);
342
343 struct ctdb_client_control_state *ctdb_ctrl_updaterecord_send(
344                                         struct ctdb_context *ctdb,
345                                         TALLOC_CTX *mem_ctx,
346                                         struct timeval timeout,
347                                         uint32_t destnode,
348                                         struct ctdb_db_context *ctdb_db,
349                                         TDB_DATA key,
350                                         struct ctdb_ltdb_header *header,
351                                         TDB_DATA data);
352 int ctdb_ctrl_updaterecord_recv(struct ctdb_context *ctdb,
353                                 struct ctdb_client_control_state *state);
354 int ctdb_ctrl_updaterecord(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
355                            struct timeval timeout, uint32_t destnode,
356                            struct ctdb_db_context *ctdb_db, TDB_DATA key,
357                            struct ctdb_ltdb_header *header, TDB_DATA data);
358
359 #endif /* _CTDB_CLIENT_H */