add a libctdb version of the control to create a database
[sahlberg/ctdb.git] / include / ctdb_protocol.h
1 /* 
2    ctdb database library
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_PROTOCOL_H
21 #define _CTDB_PROTOCOL_H
22
23 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
24 struct ctdb_call {
25         int call_id;
26         TDB_DATA key;
27         TDB_DATA call_data;
28         TDB_DATA reply_data;
29         uint32_t status;
30         uint32_t flags;
31 };
32
33 /*
34   structure passed to a ctdb call backend function
35 */
36 struct ctdb_call_info {
37         TDB_DATA key;          /* record key */
38         TDB_DATA record_data;  /* current data in the record */
39         TDB_DATA *new_data;    /* optionally updated record data */
40         TDB_DATA *call_data;   /* optionally passed from caller */
41         TDB_DATA *reply_data;  /* optionally returned by function */
42         uint32_t status;       /* optional reply status - defaults to zero */
43 };
44
45 #define CTDB_ERR_INVALID 1
46 #define CTDB_ERR_NOMEM 2
47
48 /*
49   ctdb flags
50 */
51 #define CTDB_FLAG_TORTURE      (1<<1)
52
53 /* 
54    a message handler ID meaning "give me all messages"
55  */
56 #define CTDB_SRVID_ALL (~(uint64_t)0)
57
58 /*
59   srvid type : RECOVERY
60 */
61 #define CTDB_SRVID_RECOVERY     0xF100000000000000LL
62
63 /* 
64    a message handler ID meaning that the cluster has been reconfigured
65  */
66 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
67
68 /* 
69    a message handler ID meaning that an IP address has been released
70  */
71 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
72
73 /* 
74    a message ID to set the node flags in the recovery daemon
75  */
76 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
77
78 /* 
79    a message ID to ask the recovery daemon to update the expected node
80    assignment for a public ip
81  */
82 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
83
84 /*
85   a message to tell the recovery daemon to fetch a set of records
86  */
87 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
88
89 /*
90   a message to tell the recovery daemon to write a talloc memdump
91   to the log
92  */
93 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
94
95 /* 
96    a message ID to get the recovery daemon to push the node flags out
97  */
98 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
99
100 /* 
101    a message ID to get the recovery daemon to reload the nodes file
102  */
103 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
104
105 /* 
106    a message ID to get the recovery daemon to perform a takeover run
107  */
108 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
109
110 /* A message id to ask the recovery daemon to temporarily disable the
111    public ip checks
112 */
113 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
114
115 /* A dummy port used for sending back ipreallocate resposnes to the main
116    daemon
117 */
118 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE  0xFD00000000000000LL
119
120 /* A port reserved for samba (top 32 bits)
121  */
122 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
123
124
125 /* the key used for transaction locking on persistent databases */
126 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
127
128 /* the key used to store persistent db sequence number */
129 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
130
131 enum control_state {CTDB_CONTROL_WAIT, CTDB_CONTROL_DONE, CTDB_CONTROL_ERROR, CTDB_CONTROL_TIMEOUT};
132
133 struct ctdb_client_control_state {
134         struct ctdb_context *ctdb;
135         uint32_t reqid;
136         int32_t status;
137         TDB_DATA outdata;
138         enum control_state state;
139         char *errormsg;
140         struct ctdb_req_control *c;
141
142         /* if we have a callback registered for the completion (or failure) of
143            this control
144            if a callback is used, it MUST talloc_free the cb_data passed to it
145         */
146         struct {
147                 void (*fn)(struct ctdb_client_control_state *);
148                 void *private_data;
149         } async;        
150 };
151
152 struct ctdb_client_notify_register {
153         uint64_t srvid;
154         uint32_t len;
155         uint8_t notify_data[1];
156 };
157
158 struct ctdb_client_notify_deregister {
159         uint64_t srvid;
160 };
161
162 struct event_context;
163
164 /*
165   initialise ctdb subsystem
166 */
167 struct ctdb_context *ctdb_init(struct event_context *ev);
168
169 /*
170   choose the transport
171 */
172 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
173
174 /*
175   set the directory for the local databases
176 */
177 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
178 int ctdb_set_tdb_dir_persistent(struct ctdb_context *ctdb, const char *dir);
179 int ctdb_set_tdb_dir_state(struct ctdb_context *ctdb, const char *dir);
180
181 /*
182   set some flags
183 */
184 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
185
186 /*
187   set max acess count before a dmaster migration
188 */
189 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
190
191 /*
192   tell ctdb what address to listen on, in transport specific format
193 */
194 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
195
196 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
197
198 /*
199   tell ctdb what nodes are available. This takes a filename, which will contain
200   1 node address per line, in a transport specific format
201 */
202 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
203
204 /*
205   Check that a specific ip address exists in the node list and returns
206   the id for the node or -1
207 */
208 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
209
210 /*
211   start the ctdb protocol
212 */
213 int ctdb_start(struct ctdb_context *ctdb);
214 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog);
215
216 /*
217   attach to a ctdb database
218 */
219 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
220
221 /*
222   find an attached ctdb_db handle given a name
223  */
224 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
225
226 /*
227   error string for last ctdb error
228 */
229 const char *ctdb_errstr(struct ctdb_context *);
230
231 /* a ctdb call function */
232 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
233
234 /*
235   setup a ctdb call function
236 */
237 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
238
239
240
241 /*
242   make a ctdb call. The associated ctdb call function will be called on the DMASTER
243   for the given record
244 */
245 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
246
247 /*
248   initiate an ordered ctdb cluster shutdown
249   this function will never return
250 */
251 void ctdb_shutdown(struct ctdb_context *ctdb);
252
253 /* return pnn of this node */
254 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
255
256 /*
257   return the number of nodes
258 */
259 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
260
261
262 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
263 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
264 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
265
266
267 /* 
268    Fetch a ctdb record from a remote node
269  . Underneath this will force the
270    dmaster for the record to be moved to the local node. 
271 */
272 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
273                                            TDB_DATA key, TDB_DATA *data);
274
275 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
276
277 int ctdb_fetch(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
278                TDB_DATA key, TDB_DATA *data);
279
280 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
281                                   TALLOC_CTX *mem_ctx,
282                                   uint64_t srvid,
283                                   ctdb_message_fn_t handler,
284                                   void *private_data);
285
286 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
287
288
289 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
290
291 struct ctdb_statistics;
292 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
293
294 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
295
296 struct ctdb_vnn_map;
297 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, 
298                 struct timeval timeout, uint32_t destnode, 
299                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
300 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
301                 struct timeval timeout, uint32_t destnode, 
302                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
303
304 /* table that contains a list of all dbids on a node
305  */
306 struct ctdb_dbid_map {
307         uint32_t num;
308         struct ctdb_dbid {
309                 uint32_t dbid;
310                 bool persistent;
311         } dbs[1];
312 };
313 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, 
314         struct timeval timeout, uint32_t destnode, 
315         TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
316
317
318 struct ctdb_node_map;
319
320 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, 
321                     struct timeval timeout, uint32_t destnode, 
322                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
323
324 int ctdb_ctrl_getnodemapv4(struct ctdb_context *ctdb, 
325                     struct timeval timeout, uint32_t destnode, 
326                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
327
328 int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb, 
329                     struct timeval timeout, uint32_t destnode);
330
331 struct ctdb_key_list {
332         uint32_t dbid;
333         uint32_t num;
334         TDB_DATA *keys;
335         struct ctdb_ltdb_header *headers;
336         TDB_DATA *data;
337 };
338
339 int ctdb_ctrl_pulldb(
340        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
341        uint32_t lmaster, TALLOC_CTX *mem_ctx,
342        struct timeval timeout, TDB_DATA *outdata);
343
344 struct ctdb_client_control_state *ctdb_ctrl_pulldb_send(
345        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
346        uint32_t lmaster, TALLOC_CTX *mem_ctx, struct timeval timeout);
347
348 int ctdb_ctrl_pulldb_recv(
349        struct ctdb_context *ctdb,
350        TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state,
351        TDB_DATA *outdata);
352
353 int ctdb_ctrl_pushdb(
354        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
355        TALLOC_CTX *mem_ctx,
356        struct timeval timeout, TDB_DATA indata);
357
358 struct ctdb_client_control_state *ctdb_ctrl_pushdb_send(
359        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
360        TALLOC_CTX *mem_ctx, struct timeval timeout,
361        TDB_DATA indata);
362
363 int ctdb_ctrl_pushdb_recv(
364        struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
365        struct ctdb_client_control_state *state);
366
367
368 int ctdb_ctrl_copydb(struct ctdb_context *ctdb, 
369         struct timeval timeout, uint32_t sourcenode, 
370         uint32_t destnode, uint32_t dbid, uint32_t lmaster, 
371         TALLOC_CTX *mem_ctx);
372
373 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
374 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
375 int ctdb_ctrl_getdbhealth(struct ctdb_context *ctdb,
376                           struct timeval timeout,
377                           uint32_t destnode,
378                           uint32_t dbid, TALLOC_CTX *mem_ctx,
379                           const char **reason);
380 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent);
381
382 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
383
384 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
385
386 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
387
388 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level);
389 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t level);
390
391 /*
392   change dmaster for all keys in the database to the new value
393  */
394 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, 
395         struct timeval timeout, uint32_t destnode, 
396         TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
397
398 /*
399   write a record on a specific db (this implicitely updates dmaster of the record to locally be the vnn of the node where the control is executed on)
400  */
401 int ctdb_ctrl_write_record(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, TDB_DATA key, TDB_DATA data);
402
403 #define CTDB_RECOVERY_NORMAL            0
404 #define CTDB_RECOVERY_ACTIVE            1
405
406 /*
407   get the recovery mode of a remote node
408  */
409 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
410
411 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
412
413 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmode);
414
415
416 /*
417   set the recovery mode of a remote node
418  */
419 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
420 /*
421   get the monitoring mode of a remote node
422  */
423 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
424
425 /*
426   set the monitoring mode of a remote node to active
427  */
428 int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
429
430 /*
431   set the monitoring mode of a remote node to disabled
432  */
433 int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
434
435
436 /*
437   get the recovery master of a remote node
438  */
439 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
440
441 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
442
443 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmaster);
444
445
446
447 /*
448   set the recovery master of a remote node
449  */
450 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
451
452 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, 
453                                    struct timeval timeout, 
454                                    TALLOC_CTX *mem_ctx,
455                                    uint32_t *num_nodes);
456
457 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
458
459 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
460
461 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
462 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
463
464 int ctdb_dumpdb_record(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *p);
465 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
466
467 /*
468   get the pid of a ctdb daemon
469  */
470 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
471
472 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, 
473                         uint32_t destnode);
474 int ctdb_ctrl_freeze_priority(struct ctdb_context *ctdb, struct timeval timeout, 
475                               uint32_t destnode, uint32_t priority);
476
477 struct ctdb_client_control_state *
478 ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, 
479                       struct timeval timeout, uint32_t destnode,
480                       uint32_t priority);
481
482 int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, 
483                         struct ctdb_client_control_state *state);
484
485 int ctdb_ctrl_thaw_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t priority);
486 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
487
488 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
489
490 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb, 
491                           struct timeval timeout, 
492                           uint32_t destnode,
493                           const char *name, uint32_t *value);
494
495 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb, 
496                           struct timeval timeout, 
497                           uint32_t destnode,
498                           const char *name, uint32_t value);
499
500 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, 
501                             struct timeval timeout, 
502                             uint32_t destnode,
503                             TALLOC_CTX *mem_ctx,
504                             const char ***list, uint32_t *count);
505
506 int ctdb_ctrl_modflags(struct ctdb_context *ctdb, 
507                        struct timeval timeout, 
508                        uint32_t destnode, 
509                        uint32_t set, uint32_t clear);
510
511 enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
512
513 struct ctdb_server_id {
514         enum ctdb_server_id_type type;
515         uint32_t pnn;
516         uint32_t server_id;
517 };
518
519 struct ctdb_server_id_list {
520         uint32_t num;
521         struct ctdb_server_id server_ids[1];
522 };
523
524
525 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
526                 struct timeval timeout,
527                 struct ctdb_server_id *id);
528 int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb, 
529                 struct timeval timeout, 
530                 struct ctdb_server_id *id);
531 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
532                 struct timeval timeout, uint32_t destnode, 
533                 struct ctdb_server_id *id, uint32_t *status);
534 int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
535                 TALLOC_CTX *mem_ctx,
536                 struct timeval timeout, uint32_t destnode, 
537                 struct ctdb_server_id_list **svid_list);
538
539 struct ctdb_uptime {
540         struct timeval current_time;
541         struct timeval ctdbd_start_time;
542         struct timeval last_recovery_started;
543         struct timeval last_recovery_finished;
544 };
545
546 /*
547   definitions for different socket structures
548  */
549 typedef struct sockaddr_in ctdb_addr_in;
550 typedef struct sockaddr_in6 ctdb_addr_in6;
551 typedef union {
552         struct sockaddr sa;
553         ctdb_addr_in    ip;
554         ctdb_addr_in6   ip6;
555 } ctdb_sock_addr;
556
557 /*
558   struct for tcp_client control
559   this is an ipv4 only version of this structure used by samba
560   samba will later be migrated over to use the 
561   ctdb_control_tcp_addr structure instead
562  */
563 struct ctdb_control_tcp {
564         struct sockaddr_in src; // samba uses this
565         struct sockaddr_in dest;// samba uses this
566 };
567 /* new style structure */
568 struct ctdb_control_tcp_addr {
569         ctdb_sock_addr src;
570         ctdb_sock_addr dest;
571 };
572
573 int ctdb_socket_connect(struct ctdb_context *ctdb);
574
575 /*
576   get the uptime of a remote node
577  */
578 int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
579
580 struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
581
582 int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
583
584 int ctdb_ctrl_end_recovery(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
585
586 int ctdb_ctrl_getreclock(struct ctdb_context *ctdb, 
587         struct timeval timeout, uint32_t destnode, 
588         TALLOC_CTX *mem_ctx, const char **reclock);
589 int ctdb_ctrl_setreclock(struct ctdb_context *ctdb, 
590         struct timeval timeout, uint32_t destnode, 
591         const char *reclock);
592
593
594 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
595                                 struct ctdb_node_map *node_map,
596                                 TALLOC_CTX *mem_ctx,
597                                 bool include_self);
598 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
599                                 struct ctdb_node_map *node_map,
600                                 TALLOC_CTX *mem_ctx,
601                                 bool include_self);
602 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
603                                 struct ctdb_vnn_map *vnn_map,
604                                 TALLOC_CTX *mem_ctx,
605                                 bool include_self);
606 uint32_t *list_of_active_nodes_except_pnn(struct ctdb_context *ctdb,
607                                 struct ctdb_node_map *node_map,
608                                 TALLOC_CTX *mem_ctx,
609                                 uint32_t pnn);
610
611 int ctdb_read_pnn_lock(int fd, int32_t pnn);
612
613 /*
614   get capabilities of a remote node
615  */
616 int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities);
617
618 struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
619
620 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities);
621
622
623 int32_t ctdb_ctrl_transaction_active(struct ctdb_context *ctdb,
624                                      uint32_t destnode,
625                                      uint32_t db_id);
626
627 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx, 
628                                                struct ctdb_marshall_buffer *m,
629                                                uint64_t db_id,
630                                                uint32_t reqid,
631                                                TDB_DATA key,
632                                                struct ctdb_ltdb_header *header,
633                                                TDB_DATA data);
634 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
635
636 struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *ctdb_db,
637                                                        TALLOC_CTX *mem_ctx);
638 int ctdb_transaction_fetch(struct ctdb_transaction_handle *h, 
639                            TALLOC_CTX *mem_ctx, 
640                            TDB_DATA key, TDB_DATA *data);
641 int ctdb_transaction_store(struct ctdb_transaction_handle *h, 
642                            TDB_DATA key, TDB_DATA data);
643 int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
644
645 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
646
647 int switch_from_server_to_client(struct ctdb_context *ctdb);
648
649 #define MONITOR_SCRIPT_OK      0
650 #define MONITOR_SCRIPT_TIMEOUT 1
651
652 #define MAX_SCRIPT_NAME 31
653 #define MAX_SCRIPT_OUTPUT 511
654 struct ctdb_script_wire {
655         char name[MAX_SCRIPT_NAME+1];
656         struct timeval start;
657         struct timeval finished;
658         int32_t status;
659         char output[MAX_SCRIPT_OUTPUT+1];
660 };
661
662 struct ctdb_scripts_wire {
663         uint32_t num_scripts;
664         struct ctdb_script_wire scripts[1];
665 };
666
667 /* different calls to event scripts. */
668 enum ctdb_eventscript_call {
669         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
670         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
671         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
672         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
673         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
674         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
675         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
676         CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
677         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
678         CTDB_EVENT_STATUS,              /* Report service status: no args. */
679         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
680         CTDB_EVENT_RELOAD,              /* magic */
681         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
682         CTDB_EVENT_MAX
683 };
684
685 /* Mapping from enum to names. */
686 extern const char *ctdb_eventscript_call_names[];
687
688 int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb, 
689                     struct timeval timeout, uint32_t destnode, 
690                     TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
691                     struct ctdb_scripts_wire **script_status);
692
693
694 struct debug_levels {
695         int32_t level;
696         const char *description;
697 };
698 extern struct debug_levels debug_levels[];
699
700 const char *get_debug_by_level(int32_t level);
701 int32_t get_debug_by_desc(const char *desc);
702
703 int ctdb_ctrl_stop_node(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
704 int ctdb_ctrl_continue_node(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
705
706 int ctdb_ctrl_setnatgwstate(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t natgwstate);
707 int ctdb_ctrl_setlmasterrole(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t lmasterrole);
708 int ctdb_ctrl_setrecmasterrole(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmasterrole);
709
710 int ctdb_ctrl_enablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script);
711 int ctdb_ctrl_disablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script);
712
713 struct ctdb_ban_time {
714         uint32_t pnn;
715         uint32_t time;
716 };
717
718 int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_ban_time *bantime);
719 int ctdb_ctrl_get_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_ban_time **bantime);
720
721 struct ctdb_db_priority {
722         uint32_t db_id;
723         uint32_t priority;
724 };
725
726 int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio);
727 int ctdb_ctrl_get_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint32_t *priority);
728
729 #endif