move some timed event calls out from libctdb and put it back in client/ctdb_client.c
[sahlberg/ctdb.git] / include / ctdb_private.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_PRIVATE_H
21 #define _CTDB_PRIVATE_H
22
23 #include <sys/socket.h>
24
25 /* location of daemon socket */
26 #define CTDB_PATH       "/tmp/ctdb.socket"
27
28 /* default ctdb port number */
29 #define CTDB_PORT 4379
30
31 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
32 #define CTDB_DS_ALIGNMENT 8
33
34
35 #define CTDB_NULL_FUNC      0xFF000001
36 #define CTDB_FETCH_FUNC     0xFF000002
37
38
39 /*
40   recovery daemon memdump reply address
41  */
42 struct rd_memdump_reply {
43         uint32_t pnn;
44         uint64_t srvid;
45 };
46
47 /*
48   description for a TAKEOVER_RUN message reply address
49  */
50 struct takeover_run_reply {
51         uint32_t pnn;
52         uint64_t srvid;
53 };
54
55 /*
56  * pid of the ctdbd daemon
57  */
58 extern pid_t ctdbd_pid;
59
60 /*
61   a tcp connection description
62  */
63 struct ctdb_tcp_connection {
64         ctdb_sock_addr src_addr;
65         ctdb_sock_addr dst_addr;
66 };
67
68 /* the wire representation for a tcp tickle array */
69 struct ctdb_tcp_wire_array {
70         uint32_t num;
71         struct ctdb_tcp_connection connections[1];
72 };      
73
74 /* the list of tcp tickles used by get/set tcp tickle list */
75 struct ctdb_control_tcp_tickle_list {
76         ctdb_sock_addr addr;
77         struct ctdb_tcp_wire_array tickles;
78 };
79
80 /*
81   array of tcp connections
82  */
83 struct ctdb_tcp_array {
84         uint32_t num;
85         struct ctdb_tcp_connection *connections;
86 };      
87
88
89 /* all tunable variables go in here */
90 struct ctdb_tunable {
91         uint32_t max_redirect_count;
92         uint32_t seqnum_interval; /* unit is ms */
93         uint32_t control_timeout;
94         uint32_t traverse_timeout;
95         uint32_t keepalive_interval;
96         uint32_t keepalive_limit;
97         uint32_t max_lacount;
98         uint32_t recover_timeout;
99         uint32_t recover_interval;
100         uint32_t election_timeout;
101         uint32_t takeover_timeout;
102         uint32_t monitor_interval;
103         uint32_t tickle_update_interval;
104         uint32_t script_timeout;
105         uint32_t script_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
106         uint32_t script_unhealthy_on_timeout; /* obsolete */
107         uint32_t recovery_grace_period;
108         uint32_t recovery_ban_period;
109         uint32_t database_hash_size;
110         uint32_t database_max_dead;
111         uint32_t rerecovery_timeout;
112         uint32_t enable_bans;
113         uint32_t deterministic_public_ips;
114         uint32_t reclock_ping_period;
115         uint32_t no_ip_failback;
116         uint32_t verbose_memory_names;
117         uint32_t recd_ping_timeout;
118         uint32_t recd_ping_failcount;
119         uint32_t log_latency_ms;
120         uint32_t reclock_latency_ms;
121         uint32_t recovery_drop_all_ips;
122         uint32_t verify_recovery_lock;
123         uint32_t vacuum_default_interval;
124         uint32_t vacuum_max_run_time;
125         uint32_t repack_limit;
126         uint32_t vacuum_limit;
127         uint32_t vacuum_min_interval;
128         uint32_t vacuum_max_interval;
129         uint32_t max_queue_depth_drop_msg;
130         uint32_t use_status_events_for_monitoring;
131         uint32_t allow_unhealthy_db_read;
132 };
133
134 /*
135   an installed ctdb remote call
136 */
137 struct ctdb_registered_call {
138         struct ctdb_registered_call *next, *prev;
139         uint32_t id;
140         ctdb_fn_t fn;
141 };
142
143 /*
144   this address structure might need to be generalised later for some
145   transports
146 */
147 struct ctdb_address {
148         const char *address;
149         int port;
150 };
151
152 /*
153   check that a pnn is valid
154  */
155 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
156
157
158 /* called from the queue code when a packet comes in. Called with data==NULL
159    on error */
160 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
161                                    void *private_data);
162
163 /* used for callbacks in ctdb_control requests */
164 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
165                                            int32_t status, TDB_DATA data, 
166                                            const char *errormsg,
167                                            void *private_data);
168 /*
169   structure describing a connected client in the daemon
170  */
171 struct ctdb_client {
172         struct ctdb_context *ctdb;
173         int fd;
174         struct ctdb_queue *queue;
175         uint32_t client_id;
176         pid_t pid;
177         struct ctdb_tcp_list *tcp_list;
178         uint32_t db_id;
179         uint32_t num_persistent_updates;
180         struct ctdb_client_notify_list *notify;
181 };
182
183 struct ctdb_iface;
184
185 /* state associated with a public ip address */
186 struct ctdb_vnn {
187         struct ctdb_vnn *prev, *next;
188
189         struct ctdb_iface *iface;
190         const char **ifaces;
191         ctdb_sock_addr public_address;
192         uint8_t public_netmask_bits;
193
194         /* the node number that is serving this public address, if any. 
195            If no node serves this ip it is set to -1 */
196         int32_t pnn;
197
198         /* List of clients to tickle for this public address */
199         struct ctdb_tcp_array *tcp_array;
200
201         /* whether we need to update the other nodes with changes to our list
202            of connected clients */
203         bool tcp_update_needed;
204
205         /* a context to hang sending gratious arp events off */
206         TALLOC_CTX *takeover_ctx;
207
208         struct ctdb_kill_tcp *killtcp;
209 };
210
211 /*
212   state associated with one node
213 */
214 struct ctdb_node {
215         struct ctdb_context *ctdb;
216         struct ctdb_address address;
217         const char *name; /* for debug messages */
218         void *private_data; /* private to transport */
219         uint32_t pnn;
220 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
221 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
222 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
223 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
224 #define NODE_FLAGS_DELETED              0x00000010 /* this node has been deleted */
225 #define NODE_FLAGS_STOPPED              0x00000020 /* this node has been stopped */
226 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
227 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
228         uint32_t flags;
229
230         /* used by the dead node monitoring */
231         uint32_t dead_count;
232         uint32_t rx_cnt;
233         uint32_t tx_cnt;
234
235         /* used to track node capabilities, is only valid/tracked inside the
236            recovery daemon.
237         */
238         uint32_t capabilities;
239
240         /* a list of controls pending to this node, so we can time them out quickly
241            if the node becomes disconnected */
242         struct daemon_control_state *pending_controls;
243
244         /* used by the recovery daemon when distributing ip addresses 
245            across the nodes.  it needs to know which public ip's can be handled
246            by each node.
247         */
248         struct ctdb_all_public_ips *known_public_ips;
249         struct ctdb_all_public_ips *available_public_ips;
250         /* used by the recovery dameon to track when a node should be banned */
251         struct ctdb_banning_state *ban_state; 
252 };
253
254 /*
255   transport specific methods
256 */
257 struct ctdb_methods {
258         int (*initialise)(struct ctdb_context *); /* initialise transport structures */ 
259         int (*start)(struct ctdb_context *); /* start the transport */
260         int (*add_node)(struct ctdb_node *); /* setup a new node */     
261         int (*connect_node)(struct ctdb_node *); /* connect to node */
262         int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
263         void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
264         void (*shutdown)(struct ctdb_context *); /* shutdown transport */
265         void (*restart)(struct ctdb_node *); /* stop and restart the connection */
266 };
267
268 /*
269   transport calls up to the ctdb layer
270 */
271 struct ctdb_upcalls {
272         /* recv_pkt is called when a packet comes in */
273         void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
274
275         /* node_dead is called when an attempt to send to a node fails */
276         void (*node_dead)(struct ctdb_node *);
277
278         /* node_connected is called when a connection to a node is established */
279         void (*node_connected)(struct ctdb_node *);
280 };
281
282 /* list of message handlers - needs to be changed to a more efficient data
283    structure so we can find a message handler given a srvid quickly */
284 struct ctdb_message_list {
285         struct ctdb_context *ctdb;
286         struct ctdb_message_list *next, *prev;
287         uint64_t srvid;
288         ctdb_message_fn_t message_handler;
289         void *message_private;
290 };
291
292 /* additional data required for the daemon mode */
293 struct ctdb_daemon_data {
294         int sd;
295         char *name;
296         struct ctdb_queue *queue;
297 };
298
299 /*
300   ctdb status information
301  */
302 struct ctdb_statistics {
303         uint32_t num_clients;
304         uint32_t frozen;
305         uint32_t recovering;
306         uint32_t client_packets_sent;
307         uint32_t client_packets_recv;
308         uint32_t node_packets_sent;
309         uint32_t node_packets_recv;
310         uint32_t keepalive_packets_sent;
311         uint32_t keepalive_packets_recv;
312         struct {
313                 uint32_t req_call;
314                 uint32_t reply_call;
315                 uint32_t req_dmaster;
316                 uint32_t reply_dmaster;
317                 uint32_t reply_error;
318                 uint32_t req_message;
319                 uint32_t req_control;
320                 uint32_t reply_control;
321         } node;
322         struct {
323                 uint32_t req_call;
324                 uint32_t req_message;
325                 uint32_t req_control;
326         } client;
327         struct {
328                 uint32_t call;
329                 uint32_t control;
330                 uint32_t traverse;
331         } timeouts;
332         struct {
333                 double ctdbd;
334                 double recd;
335         } reclock;
336         uint32_t total_calls;
337         uint32_t pending_calls;
338         uint32_t lockwait_calls;
339         uint32_t pending_lockwait_calls;
340         uint32_t childwrite_calls;
341         uint32_t pending_childwrite_calls;
342         uint32_t memory_used;
343         uint32_t __last_counter; /* hack for control_statistics_all */
344         uint32_t max_hop_count;
345         double max_call_latency;
346         double max_lockwait_latency;
347         double max_childwrite_latency;
348 };
349
350
351 #define INVALID_GENERATION 1
352 /* table that contains the mapping between a hash value and lmaster
353  */
354 struct ctdb_vnn_map {
355         uint32_t generation;
356         uint32_t size;
357         uint32_t *map;
358 };
359
360 /* 
361    a wire representation of the vnn map
362  */
363 struct ctdb_vnn_map_wire {
364         uint32_t generation;
365         uint32_t size;
366         uint32_t map[1];
367 };
368
369 /* a structure that contains the elements required for the write record
370    control
371 */
372 struct ctdb_write_record {
373         uint32_t dbid;
374         uint32_t keylen;
375         uint32_t datalen;
376         unsigned char blob[1];
377 };
378
379 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
380
381 #define CTDB_MONITORING_ACTIVE          0
382 #define CTDB_MONITORING_DISABLED        1
383
384 /* The different capabilities of the ctdb daemon. */
385 #define CTDB_CAP_RECMASTER              0x00000001
386 #define CTDB_CAP_LMASTER                0x00000002
387 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
388 #define CTDB_CAP_LVS                    0x00000004
389 /* This capability is set if NATGW is enabled */
390 #define CTDB_CAP_NATGW                  0x00000008
391
392 #define NUM_DB_PRIORITIES 3
393 /* main state of the ctdb daemon */
394 struct ctdb_context {
395         struct event_context *ev;
396         struct timeval ctdbd_start_time;
397         struct timeval last_recovery_started;
398         struct timeval last_recovery_finished;
399         uint32_t recovery_mode;
400         TALLOC_CTX *tickle_update_context;
401         TALLOC_CTX *keepalive_ctx;
402         struct ctdb_tunable tunable;
403         enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
404         struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
405         bool freeze_transaction_started;
406         uint32_t freeze_transaction_id;
407         struct ctdb_address address;
408         const char *name;
409         const char *db_directory;
410         const char *db_directory_persistent;
411         const char *db_directory_state;
412         struct tdb_wrap *db_persistent_health;
413         uint32_t db_persistent_startup_generation;
414         uint64_t db_persistent_check_errors;
415         uint64_t max_persistent_check_errors;
416         const char *transport;
417         char *recovery_lock_file;
418         int recovery_lock_fd;
419         uint32_t pnn; /* our own pnn */
420         uint32_t num_nodes;
421         uint32_t num_connected;
422         unsigned flags;
423         uint32_t capabilities;
424         struct idr_context *idr;
425         uint16_t idr_cnt;
426         struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
427         struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
428         struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
429         struct ctdb_iface *ifaces; /* list of local interfaces */
430         char *err_msg;
431         const struct ctdb_methods *methods; /* transport methods */
432         const struct ctdb_upcalls *upcalls; /* transport upcalls */
433         void *private_data; /* private to transport */
434         struct ctdb_db_context *db_list;
435         struct ctdb_message_list *message_list;
436         struct ctdb_daemon_data daemon;
437         struct ctdb_statistics statistics;
438         struct ctdb_vnn_map *vnn_map;
439         uint32_t num_clients;
440         uint32_t recovery_master;
441         struct ctdb_call_state *pending_calls;
442         struct ctdb_client_ip *client_ip_list;
443         bool do_checkpublicip;
444         struct trbt_tree *server_ids;   
445         const char *event_script_dir;
446         const char *notification_script;
447         const char *default_public_interface;
448         pid_t ctdbd_pid;
449         pid_t recoverd_pid;
450         pid_t syslogd_pid;
451         bool done_startup;
452         const char *node_ip;
453         struct ctdb_monitor_state *monitor;
454         struct ctdb_log_state *log;
455         int start_as_disabled;
456         int start_as_stopped;
457         bool valgrinding;
458         uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
459         uint32_t *recd_ping_count;
460         TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
461
462         TALLOC_CTX *event_script_ctx;
463
464         struct ctdb_event_script_state *current_monitor;
465         struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX];
466
467         TALLOC_CTX *banning_ctx;
468
469         /* mapping from pid to ctdb_client * */
470         struct ctdb_client_pid_list *client_pids;
471
472         /* used in the recovery daemon to remember the ip allocation */
473         struct trbt_tree *ip_tree;
474 };
475
476 struct ctdb_db_context {
477         struct ctdb_db_context *next, *prev;
478         struct ctdb_context *ctdb;
479         uint32_t db_id;
480         uint32_t priority;
481         bool persistent;
482         const char *db_name;
483         const char *db_path;
484         struct tdb_wrap *ltdb;
485         struct ctdb_registered_call *calls; /* list of registered calls */
486         uint32_t seqnum;
487         struct timed_event *seqnum_update;
488         struct ctdb_traverse_local_handle *traverse;
489         bool transaction_active;
490         struct ctdb_vacuum_handle *vacuum_handle;
491         char *unhealthy_reason;
492 };
493
494
495 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
496           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
497           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
498           return -1; }} while (0)
499
500 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
501           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
502           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
503           return; }} while (0)
504
505 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
506           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
507           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
508           return NULL; }} while (0)
509
510 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
511           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
512           ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
513           }} while (0)
514
515 /*
516   the extended header for records in the ltdb
517 */
518 struct ctdb_ltdb_header {
519         uint64_t rsn;
520         uint32_t dmaster;
521         uint32_t laccessor;
522         uint32_t lacount;
523 };
524
525 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0, 
526                     CTDB_CONTROL_STATISTICS              = 1, 
527                     /* #2 removed */
528                     CTDB_CONTROL_PING                    = 3,
529                     CTDB_CONTROL_GETDBPATH               = 4,
530                     CTDB_CONTROL_GETVNNMAP               = 5,
531                     CTDB_CONTROL_SETVNNMAP               = 6,
532                     CTDB_CONTROL_GET_DEBUG               = 7,
533                     CTDB_CONTROL_SET_DEBUG               = 8,
534                     CTDB_CONTROL_GET_DBMAP               = 9,
535                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
536                     CTDB_CONTROL_SET_DMASTER             = 11,
537                     /* #12 removed */
538                     CTDB_CONTROL_PULL_DB                 = 13,
539                     CTDB_CONTROL_PUSH_DB                 = 14,
540                     CTDB_CONTROL_GET_RECMODE             = 15,
541                     CTDB_CONTROL_SET_RECMODE             = 16,
542                     CTDB_CONTROL_STATISTICS_RESET        = 17,
543                     CTDB_CONTROL_DB_ATTACH               = 18,
544                     CTDB_CONTROL_SET_CALL                = 19,
545                     CTDB_CONTROL_TRAVERSE_START          = 20,
546                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
547                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
548                     CTDB_CONTROL_REGISTER_SRVID          = 23,
549                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
550                     CTDB_CONTROL_GET_DBNAME              = 25,
551                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
552                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
553                     /* #28 removed */
554                     CTDB_CONTROL_DUMP_MEMORY             = 29,
555                     CTDB_CONTROL_GET_PID                 = 30,
556                     CTDB_CONTROL_GET_RECMASTER           = 31,
557                     CTDB_CONTROL_SET_RECMASTER           = 32,
558                     CTDB_CONTROL_FREEZE                  = 33,
559                     CTDB_CONTROL_THAW                    = 34,
560                     CTDB_CONTROL_GET_PNN                 = 35,
561                     CTDB_CONTROL_SHUTDOWN                = 36,
562                     CTDB_CONTROL_GET_MONMODE             = 37,
563                     /* #38 removed */
564                     /* #39 removed */
565                     /* #40 removed */
566                     /* #41 removed */
567                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
568                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
569                     CTDB_CONTROL_TCP_CLIENT              = 44,
570                     CTDB_CONTROL_TCP_ADD                 = 45,
571                     CTDB_CONTROL_TCP_REMOVE              = 46,
572                     CTDB_CONTROL_STARTUP                 = 47,
573                     CTDB_CONTROL_SET_TUNABLE             = 48,
574                     CTDB_CONTROL_GET_TUNABLE             = 49,
575                     CTDB_CONTROL_LIST_TUNABLES           = 50,
576                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
577                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
578                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
579                     CTDB_CONTROL_KILL_TCP                = 54,
580                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
581                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
582                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
583                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
584                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
585                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
586                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
587                     CTDB_CONTROL_PERSISTENT_STORE        = 62,
588                     CTDB_CONTROL_UPDATE_RECORD           = 63,
589                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
590                     CTDB_CONTROL_TRANSACTION_START       = 65,
591                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
592                     CTDB_CONTROL_WIPE_DATABASE           = 67,
593                     /* #68 removed */
594                     CTDB_CONTROL_UPTIME                  = 69,
595                     CTDB_CONTROL_START_RECOVERY          = 70,
596                     CTDB_CONTROL_END_RECOVERY            = 71,
597                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
598                     /* #73 removed */
599                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
600                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
601                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
602                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
603                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
604                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
605                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
606                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
607                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
608                     CTDB_CONTROL_TRANS2_COMMIT           = 83,
609                     CTDB_CONTROL_TRANS2_FINISHED         = 84,
610                     CTDB_CONTROL_TRANS2_ERROR            = 85,
611                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86,
612                     CTDB_CONTROL_RECD_PING               = 87,
613                     CTDB_CONTROL_RELEASE_IP              = 88,
614                     CTDB_CONTROL_TAKEOVER_IP             = 89,
615                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
616                     CTDB_CONTROL_GET_NODEMAP             = 91,
617                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
618                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
619                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
620                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
621                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100,
622                     CTDB_CONTROL_STOP_NODE               = 101,
623                     CTDB_CONTROL_CONTINUE_NODE           = 102,
624                     CTDB_CONTROL_SET_NATGWSTATE          = 103,
625                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
626                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
627                     CTDB_CONTROL_ENABLE_SCRIPT           = 107,
628                     CTDB_CONTROL_DISABLE_SCRIPT          = 108,
629                     CTDB_CONTROL_SET_BAN_STATE           = 109,
630                     CTDB_CONTROL_GET_BAN_STATE           = 110,
631                     CTDB_CONTROL_SET_DB_PRIORITY         = 111,
632                     CTDB_CONTROL_GET_DB_PRIORITY         = 112,
633                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113,
634                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
635                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
636                     CTDB_CONTROL_TRANS2_ACTIVE           = 116,
637                     CTDB_CONTROL_GET_LOG                 = 117,
638                     CTDB_CONTROL_CLEAR_LOG               = 118,
639                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
640                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
641                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
642                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
643                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
644                     CTDB_CONTROL_GET_IFACES              = 124,
645                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
646 };      
647
648 /*
649   structure passed in set_call control
650  */
651 struct ctdb_control_set_call {
652         uint32_t db_id;
653         ctdb_fn_t fn;
654         uint32_t id;
655 };
656
657 /*
658   struct for kill_tcp control
659  */
660 struct ctdb_control_killtcp {
661         ctdb_sock_addr src_addr;
662         ctdb_sock_addr dst_addr;
663 };
664
665 /*
666   struct holding a ctdb_sock_addr and an interface name,
667   used to add/remove public addresses
668  */
669 struct ctdb_control_ip_iface {
670         ctdb_sock_addr addr;
671         uint32_t mask;
672         uint32_t len;
673         char iface[1];
674 };
675
676 /*
677   struct holding a ctdb_sock_addr and an interface name,
678   used for send_gratious_arp
679  */
680 struct ctdb_control_gratious_arp {
681         ctdb_sock_addr addr;
682         uint32_t mask;
683         uint32_t len;
684         char iface[1];
685 };
686
687 /*
688   struct for tcp_add and tcp_remove controls
689  */
690 struct ctdb_control_tcp_vnn {
691         ctdb_sock_addr src;
692         ctdb_sock_addr dest;
693 };
694
695 /*
696   persistent store control - update this record on all other nodes
697  */
698 struct ctdb_control_persistent_store {
699         uint32_t db_id;
700         uint32_t len;
701         uint8_t  data[1];
702 };
703
704 /*
705   structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
706  */
707 struct ctdb_node_flag_change {
708         uint32_t pnn;
709         uint32_t new_flags;
710         uint32_t old_flags;
711 };
712
713 /*
714   struct for admin setting a ban
715  */
716 struct ctdb_ban_info {
717         uint32_t pnn;
718         uint32_t ban_time;
719 };
720
721 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
722
723 #define CTDB_LMASTER_ANY        0xffffffff
724
725 /*
726   state of a in-progress ctdb call
727 */
728 struct ctdb_call_state {
729         struct ctdb_call_state *next, *prev;
730         enum call_state state;
731         uint32_t reqid;
732         struct ctdb_req_call *c;
733         struct ctdb_db_context *ctdb_db;
734         const char *errmsg;
735         struct ctdb_call *call;
736         uint32_t generation;
737         struct {
738                 void (*fn)(struct ctdb_call_state *);
739                 void *private_data;
740         } async;
741 };
742
743
744 /* used for fetch_lock */
745 struct ctdb_fetch_handle {
746         struct ctdb_db_context *ctdb_db;
747         TDB_DATA key;
748         TDB_DATA *data;
749         struct ctdb_ltdb_header header;
750 };
751
752 /*
753   operation IDs
754 */
755 enum ctdb_operation {
756         CTDB_REQ_CALL           = 0,
757         CTDB_REPLY_CALL         = 1,
758         CTDB_REQ_DMASTER        = 2,
759         CTDB_REPLY_DMASTER      = 3,
760         CTDB_REPLY_ERROR        = 4,
761         CTDB_REQ_MESSAGE        = 5,
762         /* #6 removed */
763         CTDB_REQ_CONTROL        = 7,
764         CTDB_REPLY_CONTROL      = 8,
765         CTDB_REQ_KEEPALIVE      = 9,
766 };
767
768 #define CTDB_MAGIC 0x43544442 /* CTDB */
769 #define CTDB_VERSION 1
770
771 /*
772   packet structures
773 */
774 struct ctdb_req_header {
775         uint32_t length;
776         uint32_t ctdb_magic;
777         uint32_t ctdb_version;
778         uint32_t generation;
779         uint32_t operation;
780         uint32_t destnode;
781         uint32_t srcnode;
782         uint32_t reqid;
783 };
784
785 struct ctdb_req_call {
786         struct ctdb_req_header hdr;
787         uint32_t flags;
788         uint32_t db_id;
789         uint32_t callid;
790         uint32_t hopcount;
791         uint32_t keylen;
792         uint32_t calldatalen;
793         uint8_t data[1]; /* key[] followed by calldata[] */
794 };
795
796 struct ctdb_reply_call {
797         struct ctdb_req_header hdr;
798         uint32_t status;
799         uint32_t datalen;
800         uint8_t  data[1];
801 };
802
803 struct ctdb_reply_error {
804         struct ctdb_req_header hdr;
805         uint32_t status;
806         uint32_t msglen;
807         uint8_t  msg[1];
808 };
809
810 struct ctdb_req_dmaster {
811         struct ctdb_req_header hdr;
812         uint32_t db_id;
813         uint64_t rsn;
814         uint32_t dmaster;
815         uint32_t keylen;
816         uint32_t datalen;
817         uint8_t  data[1];
818 };
819
820 struct ctdb_reply_dmaster {
821         struct ctdb_req_header hdr;
822         uint32_t db_id;
823         uint64_t rsn;
824         uint32_t keylen;
825         uint32_t datalen;
826         uint8_t  data[1];
827 };
828
829 struct ctdb_req_message {
830         struct ctdb_req_header hdr;
831         uint64_t srvid;
832         uint32_t datalen;
833         uint8_t data[1];
834 };
835
836 struct ctdb_req_getdbpath {
837         struct ctdb_req_header hdr;
838         uint32_t db_id;
839 };
840
841 struct ctdb_reply_getdbpath {
842         struct ctdb_req_header hdr;
843         uint32_t datalen;
844         uint8_t data[1];
845 };
846
847 struct ctdb_req_control {
848         struct ctdb_req_header hdr;
849         uint32_t opcode;
850         uint64_t srvid;
851         uint32_t client_id;
852 #define CTDB_CTRL_FLAG_NOREPLY   1
853 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
854         uint32_t flags;
855         uint32_t datalen;
856         uint8_t data[1];
857 };
858
859 struct ctdb_reply_control {
860         struct ctdb_req_header hdr;
861         int32_t  status;
862         uint32_t datalen;
863         uint32_t errorlen;
864         uint8_t data[1];
865 };
866
867 struct ctdb_req_keepalive {
868         struct ctdb_req_header hdr;
869 };
870
871
872 /* types of failures possible from TRANS2_COMMIT */
873 enum ctdb_trans2_commit_error {
874         CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
875         CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
876         CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
877         CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
878 };
879
880 /* internal prototypes */
881 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
882 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
883 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
884 int ctdb_parse_address(struct ctdb_context *ctdb,
885                        TALLOC_CTX *mem_ctx, const char *str,
886                        struct ctdb_address *address);
887 bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
888 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
889 uint32_t ctdb_hash(const TDB_DATA *key);
890 uint32_t ctdb_hash_string(const char *str);
891 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
892 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
893 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
894 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
895 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
896 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
897
898 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
899 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, 
900                     TDB_DATA key, struct ctdb_ltdb_header *header, 
901                     TALLOC_CTX *mem_ctx, TDB_DATA *data);
902 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, 
903                     struct ctdb_ltdb_header *header, TDB_DATA data);
904 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb, 
905                         struct ctdb_req_control *c,
906                         TDB_DATA recdata);
907 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb, 
908                         struct ctdb_req_control *c,
909                         TDB_DATA recdata);
910 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
911 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
912 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db, 
913                            TDB_DATA key, struct ctdb_req_header *hdr,
914                            void (*recv_pkt)(void *, struct ctdb_req_header *),
915                            void *recv_context, bool ignore_generation);
916 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db, 
917                                  TDB_DATA key, struct ctdb_ltdb_header *header, 
918                                  struct ctdb_req_header *hdr, TDB_DATA *data,
919                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
920                                  void *recv_context, bool ignore_generation);
921 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
922
923 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db, 
924                                              struct ctdb_call *call,
925                                              struct ctdb_ltdb_header *header,
926                                              TDB_DATA *data);
927
928
929 int ctdbd_start(struct ctdb_context *ctdb);
930 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
931 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
932
933 /*
934   queue a packet for sending
935 */
936 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
937
938 /*
939   setup the fd used by the queue
940  */
941 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
942
943 /*
944   setup a packet queue on a socket
945  */
946 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
947                                     TALLOC_CTX *mem_ctx, int fd, int alignment,
948                                     
949                                     ctdb_queue_cb_fn_t callback,
950                                     void *private_data);
951
952 /*
953   allocate a packet for use in client<->daemon communication
954  */
955 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
956                                             TALLOC_CTX *mem_ctx, 
957                                             enum ctdb_operation operation, 
958                                             size_t length, size_t slength,
959                                             const char *type);
960 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
961         (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
962
963 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
964                                                  TALLOC_CTX *mem_ctx, 
965                                                  enum ctdb_operation operation, 
966                                                  size_t length, size_t slength,
967                                                  const char *type);
968 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
969         (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
970
971
972 /*
973  * Get the number of PDUs currently queued for this ctdb_queue
974  */
975 int ctdb_queue_length(struct ctdb_queue *queue);
976
977 /*
978   lock a record in the ltdb, given a key
979  */
980 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
981
982 /*
983   unlock a record in the ltdb, given a key
984  */
985 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
986
987
988 /*
989   make a ctdb call to the local daemon - async send. Called from client context.
990
991   This constructs a ctdb_call request and queues it for processing. 
992   This call never blocks.
993 */
994 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db, 
995                                               struct ctdb_call *call);
996
997 /*
998   make a recv call to the local ctdb daemon - called from client context
999
1000   This is called when the program wants to wait for a ctdb_call to complete and get the 
1001   results. This call will block unless the call has already completed.
1002 */
1003 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
1004
1005 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
1006                              ctdb_message_fn_t handler,
1007                              void *private_data);
1008
1009 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
1010                              uint64_t srvid, TDB_DATA data);
1011
1012 /*
1013   send a ctdb message
1014 */
1015 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
1016                              uint64_t srvid, TDB_DATA data);
1017
1018
1019 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
1020                                       TDB_DATA key,
1021                                       void (*callback)(void *), void *private_data);
1022
1023 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, 
1024                                               struct ctdb_call *call);
1025
1026 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
1027
1028 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db, 
1029                                                      struct ctdb_call *call, 
1030                                                      struct ctdb_ltdb_header *header);
1031
1032 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
1033                     struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
1034                     uint32_t caller);
1035
1036 #define ctdb_reqid_find(ctdb, reqid, type)      (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
1037
1038 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
1039
1040 int ctdb_socket_connect(struct ctdb_context *ctdb);
1041
1042 void ctdb_latency(struct ctdb_db_context *ctdb_db, const char *name, double *latency, struct timeval t);
1043 void ctdb_reclock_latency(struct ctdb_context *ctdb, const char *name, double *latency, double l);
1044
1045 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
1046 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
1047 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
1048
1049 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
1050 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
1051
1052 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
1053                              uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
1054                              TDB_DATA data,
1055                              ctdb_control_callback_fn_t callback,
1056                              void *private_data);
1057
1058 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata, 
1059                                TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
1060
1061 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
1062                          ctdb_fn_t fn, int id);
1063
1064 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid, 
1065                  uint32_t opcode, uint32_t flags, TDB_DATA data, 
1066                  TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
1067                  struct timeval *timeout, char **errormsg);
1068 int ctdb_control_recv(struct ctdb_context *ctdb, 
1069                 struct ctdb_client_control_state *state, 
1070                 TALLOC_CTX *mem_ctx,
1071                 TDB_DATA *outdata, int32_t *status, char **errormsg);
1072
1073 struct ctdb_client_control_state *
1074 ctdb_control_send(struct ctdb_context *ctdb, 
1075                 uint32_t destnode, uint64_t srvid, 
1076                 uint32_t opcode, uint32_t flags, TDB_DATA data, 
1077                 TALLOC_CTX *mem_ctx,
1078                 struct timeval *timeout,
1079                 char **errormsg);
1080
1081
1082
1083
1084 #define CHECK_CONTROL_DATA_SIZE(size) do { \
1085  if (indata.dsize != size) { \
1086          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
1087                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
1088          return -1; \
1089  } \
1090  } while (0)
1091
1092 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1093 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1094 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1095 int ctdb_control_getnodemapv4(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1096 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1097 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1098
1099
1100 struct ctdb_traverse_start {
1101         uint32_t db_id;
1102         uint32_t reqid;
1103         uint64_t srvid;
1104 };
1105
1106 /*
1107   structure used to pass record data between the child and parent
1108  */
1109 struct ctdb_rec_data {
1110         uint32_t length;
1111         uint32_t reqid;
1112         uint32_t keylen;
1113         uint32_t datalen;
1114         uint8_t  data[1];
1115 };
1116                                    
1117
1118 /* structure used for pulldb control */
1119 struct ctdb_control_pulldb {
1120         uint32_t db_id;
1121         uint32_t lmaster;
1122 };
1123
1124 /* structure used for sending lists of records */
1125 struct ctdb_marshall_buffer {
1126         uint32_t db_id;
1127         uint32_t count;
1128         uint8_t data[1];
1129 };
1130
1131 /* set dmaster control structure */
1132 struct ctdb_control_set_dmaster {
1133         uint32_t db_id;
1134         uint32_t dmaster;
1135 };
1136
1137 /*
1138   structure for setting a tunable
1139  */
1140 struct ctdb_control_set_tunable {
1141         uint32_t value;
1142         uint32_t length;
1143         uint8_t  name[1];
1144 };
1145
1146 /*
1147   structure for getting a tunable
1148  */
1149 struct ctdb_control_get_tunable {
1150         uint32_t length;
1151         uint8_t  name[1];
1152 };
1153
1154 /*
1155   structure for listing tunables
1156  */
1157 struct ctdb_control_list_tunable {
1158         uint32_t length;
1159         /* returns a : separated list of tunable names */
1160         uint8_t  data[1];
1161 };
1162
1163
1164 /* table that contains a list of all nodes a ctdb knows about and their 
1165    status
1166  */
1167 struct ctdb_node_and_flags {
1168         uint32_t pnn;
1169         uint32_t flags;
1170         ctdb_sock_addr addr;
1171 };
1172
1173 struct ctdb_node_map {
1174         uint32_t num;
1175         struct ctdb_node_and_flags nodes[1];
1176 };
1177
1178 struct ctdb_node_and_flagsv4 {
1179         uint32_t pnn;
1180         uint32_t flags;
1181         struct sockaddr_in sin;
1182 };
1183
1184 struct ctdb_node_mapv4 {
1185         uint32_t num;
1186         struct ctdb_node_and_flagsv4 nodes[1];
1187 };
1188
1189 struct ctdb_control_wipe_database {
1190         uint32_t db_id;
1191         uint32_t transaction_id;
1192 };
1193
1194 /*
1195   state of a in-progress ctdb call in client
1196 */
1197 struct ctdb_client_call_state {
1198         enum call_state state;
1199         uint32_t reqid;
1200         struct ctdb_db_context *ctdb_db;
1201         struct ctdb_call *call;
1202         struct {
1203                 void (*fn)(struct ctdb_client_call_state *);
1204                 void *private_data;
1205         } async;
1206 };
1207
1208
1209 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata, 
1210                                     TDB_DATA *outdata, uint32_t srcnode, uint32_t client_id);
1211 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1212 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1213 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata, 
1214                                     TDB_DATA *outdata, uint32_t srcnode);
1215
1216 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1217
1218 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1219 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1220 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1221
1222 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1223 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1224
1225 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, 
1226                                            TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1227
1228 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
1229                                               uint32_t *reqid,
1230                                               struct ctdb_ltdb_header *header,
1231                                               TDB_DATA *key, TDB_DATA *data);
1232
1233 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1234 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1235 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1236
1237 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, 
1238                                  struct ctdb_req_control *c,
1239                                  TDB_DATA indata, bool *async_reply,
1240                                  const char **errormsg);
1241 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1242                                 TDB_DATA *outdata, int32_t status, const char *errormsg);
1243
1244 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1245 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority);
1246
1247 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1248 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1249
1250 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1251
1252 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1253 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1254 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1255 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1256 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1257 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1258 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1259 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1260 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1261
1262
1263 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1264 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1265 void ctdb_node_dead(struct ctdb_node *node);
1266 void ctdb_node_connected(struct ctdb_node *node);
1267 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1268 void ctdb_high_priority(struct ctdb_context *ctdb);
1269 void ctdb_reduce_priority(struct ctdb_context *ctdb);
1270 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
1271                                  struct ctdb_req_control *c,
1272                                  TDB_DATA indata, 
1273                                  bool *async_reply);
1274 int32_t ctdb_control_takeover_ipv4(struct ctdb_context *ctdb, 
1275                                  struct ctdb_req_control *c,
1276                                  TDB_DATA indata, 
1277                                  bool *async_reply);
1278 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, 
1279                                  struct ctdb_req_control *c,
1280                                  TDB_DATA indata, 
1281                                  bool *async_reply);
1282 int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb, 
1283                                  struct ctdb_req_control *c,
1284                                  TDB_DATA indata, 
1285                                  bool *async_reply);
1286 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb, 
1287                                  struct ctdb_req_control *c,
1288                                  bool *async_reply);
1289 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb, 
1290                                  struct ctdb_req_control *c,
1291                                  bool *async_reply);
1292
1293 struct ctdb_public_ipv4 {
1294         uint32_t pnn;
1295         struct sockaddr_in sin;
1296 };
1297
1298 struct ctdb_public_ip {
1299         uint32_t pnn;
1300         ctdb_sock_addr addr;
1301 };
1302 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1303                           uint32_t destnode, struct ctdb_public_ip *ip);
1304 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1305                          uint32_t destnode, struct ctdb_public_ip *ip);
1306
1307 struct ctdb_all_public_ipsv4 {
1308         uint32_t num;
1309         struct ctdb_public_ipv4 ips[1];
1310 };
1311
1312 struct ctdb_all_public_ips {
1313         uint32_t num;
1314         struct ctdb_public_ip ips[1];
1315 };
1316 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1317 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1318 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, 
1319                              struct timeval timeout,
1320                              uint32_t destnode,
1321                              TALLOC_CTX *mem_ctx,
1322                              struct ctdb_all_public_ips **ips);
1323 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1324 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
1325                                    struct timeval timeout, uint32_t destnode,
1326                                    TALLOC_CTX *mem_ctx,
1327                                    uint32_t flags,
1328                                    struct ctdb_all_public_ips **ips);
1329 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb, 
1330                         struct timeval timeout, uint32_t destnode, 
1331                         TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1332
1333 #ifdef IFNAMSIZ
1334 #define CTDB_IFACE_SIZE IFNAMSIZ
1335 #else
1336 #define CTDB_IFACE_SIZE 16
1337 #endif
1338
1339 struct ctdb_control_iface_info {
1340         char name[CTDB_IFACE_SIZE+2];
1341         uint16_t link_state;
1342         uint32_t references;
1343 };
1344
1345 struct ctdb_control_public_ip_info {
1346         struct ctdb_public_ip ip;
1347         uint32_t active_idx;
1348         uint32_t num;
1349         struct ctdb_control_iface_info ifaces[1];
1350 };
1351
1352 struct ctdb_control_get_ifaces {
1353         uint32_t num;
1354         struct ctdb_control_iface_info ifaces[1];
1355 };
1356
1357 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
1358                                         struct ctdb_req_control *c,
1359                                         TDB_DATA indata,
1360                                         TDB_DATA *outdata);
1361 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
1362                                 struct ctdb_req_control *c,
1363                                 TDB_DATA *outdata);
1364 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
1365                                     struct ctdb_req_control *c,
1366                                     TDB_DATA indata);
1367 int ctdb_ctrl_get_public_ip_info(struct ctdb_context *ctdb,
1368                                  struct timeval timeout, uint32_t destnode,
1369                                  TALLOC_CTX *mem_ctx,
1370                                  const ctdb_sock_addr *addr,
1371                                  struct ctdb_control_public_ip_info **info);
1372 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
1373                          struct timeval timeout, uint32_t destnode,
1374                          TALLOC_CTX *mem_ctx,
1375                          struct ctdb_control_get_ifaces **ifaces);
1376 int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb,
1377                              struct timeval timeout, uint32_t destnode,
1378                              TALLOC_CTX *mem_ctx,
1379                              const struct ctdb_control_iface_info *info);
1380
1381 /* from takeover/system.c */
1382 uint32_t uint16_checksum(uint16_t *data, size_t n);
1383 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1384 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
1385 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
1386                       const ctdb_sock_addr *src,
1387                       uint32_t seq, uint32_t ack, int rst);
1388
1389 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1390 int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
1391                               const char *iface,
1392                               const char *ip);
1393 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1394 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1395 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
1396 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1397
1398 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, 
1399                                 TDB_DATA indata);
1400 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1401 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1402 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1403 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1404 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1405 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1406 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1407
1408 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1409 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call);
1410 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
1411                            const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1412 int ctdb_event_script_callback(struct ctdb_context *ctdb, 
1413                                TALLOC_CTX *mem_ctx,
1414                                void (*callback)(struct ctdb_context *, int, void *),
1415                                void *private_data,
1416                                bool from_user,
1417                                enum ctdb_eventscript_call call,
1418                                const char *fmt, ...) PRINTF_ATTRIBUTE(7,8);
1419 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1420
1421 void set_nonblocking(int fd);
1422 void set_close_on_exec(int fd);
1423
1424 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1425
1426 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1427
1428 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata, 
1429                                  TDB_DATA *outdata);
1430 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1431 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1432 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1433 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1434 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1435
1436 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1437
1438 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1439
1440 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb, 
1441                                struct timeval timeout, 
1442                                uint32_t destnode,
1443                                struct ctdb_tunable *tunables);
1444
1445 int ctdb_start_freeze(struct ctdb_context *ctdb, uint32_t priority);
1446
1447 bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask);
1448 bool parse_ip_port(const char *s, ctdb_sock_addr *addr);
1449 bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr);
1450 bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin);
1451  
1452
1453 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1454 int ctdb_sys_close_capture_socket(void *private_data);
1455 int ctdb_sys_read_tcp_packet(int s, void *private_data, ctdb_sock_addr *src, ctdb_sock_addr *dst, uint32_t *ack_seq, uint32_t *seq);
1456
1457 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, 
1458                       struct timeval timeout, 
1459                       uint32_t destnode,
1460                       struct ctdb_control_killtcp *killtcp);
1461
1462 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb, 
1463                       struct timeval timeout, 
1464                       uint32_t destnode,
1465                       struct ctdb_control_ip_iface *pub);
1466
1467 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb, 
1468                       struct timeval timeout, 
1469                       uint32_t destnode,
1470                       struct ctdb_control_ip_iface *pub);
1471
1472 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb, 
1473                       struct timeval timeout, 
1474                       uint32_t destnode,
1475                       ctdb_sock_addr *addr,
1476                       const char *ifname);
1477
1478 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, 
1479                       struct timeval timeout, 
1480                       uint32_t destnode,
1481                       TALLOC_CTX *mem_ctx,
1482                       ctdb_sock_addr *addr,
1483                       struct ctdb_control_tcp_tickle_list **list);
1484
1485
1486 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, 
1487                       uint32_t client_id,
1488                       TDB_DATA indata);
1489 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb, 
1490                       TDB_DATA indata);
1491 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, 
1492                       TDB_DATA indata);
1493 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, 
1494                       TDB_DATA *outdata);
1495 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, 
1496                       TDB_DATA *outdata);
1497
1498 int ctdb_attach_databases(struct ctdb_context *ctdb);
1499
1500 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb, 
1501                                       struct ctdb_req_control *c, 
1502                                       TDB_DATA recdata, bool *async_reply);
1503 int32_t ctdb_control_update_record(struct ctdb_context *ctdb, 
1504                                    struct ctdb_req_control *c, TDB_DATA recdata, 
1505                                    bool *async_reply);
1506 int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb, 
1507                                    struct ctdb_req_control *c, 
1508                                    TDB_DATA recdata, bool *async_reply);
1509
1510 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
1511                                    struct ctdb_req_control *c,
1512                                    TDB_DATA recdata, bool *async_reply);
1513
1514 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1515 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1516 int32_t ctdb_control_transaction_cancel(struct ctdb_context *ctdb);
1517 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1518 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb, TDB_DATA indata);
1519 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
1520                                    TDB_DATA indata,
1521                                    TDB_DATA *outdata);
1522
1523
1524 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1525 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1526
1527 void ctdb_block_signal(int signum);
1528 void ctdb_unblock_signal(int signum);
1529 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1530 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1531 void ctdb_lockdown_memory(struct ctdb_context *ctdb);
1532
1533 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1534
1535 struct client_async_data {
1536         enum ctdb_controls opcode;
1537         bool dont_log_errors;
1538         uint32_t count;
1539         uint32_t fail_count;
1540         client_async_callback callback;
1541         client_async_callback fail_callback;
1542         void *callback_data;
1543 };
1544 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1545 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1546 int ctdb_client_async_control(struct ctdb_context *ctdb,
1547                                 enum ctdb_controls opcode,
1548                                 uint32_t *nodes,
1549                                 uint64_t srvid,
1550                                 struct timeval timeout,
1551                                 bool dont_log_errors,
1552                                 TDB_DATA data,
1553                                 client_async_callback client_callback,
1554                                 client_async_callback fail_callback,
1555                                 void *callback_data);
1556
1557 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1558
1559 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1560
1561 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1562 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1563
1564 int32_t ctdb_control_trans2_finished(struct ctdb_context *ctdb, 
1565                                      struct ctdb_req_control *c);
1566 int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb, 
1567                                   struct ctdb_req_control *c);
1568 int32_t ctdb_control_trans2_active(struct ctdb_context *ctdb,
1569                                    struct ctdb_req_control *c,
1570                                    uint32_t db_id);
1571
1572 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
1573 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
1574 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
1575
1576 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
1577 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata);
1578
1579 extern int script_log_level;
1580
1581 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1582                                              uint32_t call_type,
1583                                              TDB_DATA *outdata);
1584
1585 int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
1586 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
1587
1588 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1589 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
1590
1591 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1592
1593 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1594 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1595
1596 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
1597 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
1598 int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata);
1599 void ctdb_ban_self(struct ctdb_context *ctdb);
1600
1601 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1602
1603 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1604
1605 int start_syslog_daemon(struct ctdb_context *ctdb);
1606
1607 /* Where to send the log messages back to */
1608 struct ctdb_get_log_addr {
1609         uint32_t pnn;
1610         uint64_t srvid;
1611         int32_t level;
1612 };
1613
1614 extern int log_ringbuf_size;
1615 int ctdb_init_log(void);
1616
1617 int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
1618 int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
1619
1620
1621 struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
1622                                               struct ctdb_context *ctdb,
1623                                               void (*logfn)(const char *, uint16_t, void *),
1624                                               void *logfn_private, pid_t *pid);
1625
1626 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
1627 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
1628
1629 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
1630                                    TDB_DATA indata,
1631                                    TDB_DATA *outdata);
1632
1633 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
1634                                 struct ctdb_db_context *ctdb_db);
1635 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
1636                                   struct ctdb_db_context *ctdb_db,
1637                                   const char *reason,/* NULL means healthy */
1638                                   int num_healthy_nodes);
1639 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
1640
1641 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
1642
1643 void ctdb_fault_setup(void);
1644
1645 int verify_remote_ip_allocation(struct ctdb_context *ctdb, 
1646                                 struct ctdb_all_public_ips *ips);
1647 int update_ip_assignment_tree(struct ctdb_context *ctdb,
1648                                 struct ctdb_public_ip *ip);
1649
1650 void ctdb_control_timeout_func(struct event_context *ev,
1651                                struct timed_event *te, 
1652                                struct timeval t, void *private_data);
1653
1654 void ctdb_invoke_control_callback(struct event_context *ev, struct timed_event *te, struct timeval t, void *private_data);
1655
1656 #endif