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