77d109266035830a15841d3de24285beb225d342
[rusty/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 "ctdb.h"
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26
27 /* location of daemon socket */
28 #define CTDB_PATH       "/tmp/ctdb.socket"
29
30 /* default ctdb port number */
31 #define CTDB_PORT 4379
32
33 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
34 #define CTDB_DS_ALIGNMENT 8
35
36
37 #define CTDB_NULL_FUNC      0xFF000001
38 #define CTDB_FETCH_FUNC     0xFF000002
39
40
41 /*
42   recovery daemon memdump reply address
43  */
44 struct rd_memdump_reply {
45         uint32_t pnn;
46         uint64_t srvid;
47 };
48
49 /*
50   definitions for different socket structures
51  */
52 typedef struct sockaddr_in ctdb_addr_in;
53 typedef struct sockaddr_in6 ctdb_addr_in6;
54 typedef union {
55         struct sockaddr sa;
56         ctdb_addr_in    ip;
57         ctdb_addr_in6   ip6;
58 } ctdb_sock_addr;
59
60 /*
61   a tcp connection description
62  */
63 struct ctdb_tcp_connection {
64         struct sockaddr_in saddr;
65         struct sockaddr_in daddr;
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         struct sockaddr_in ip;
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_frequency;
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_ban_count; /* ban after this many consec timeouts*/
106         uint32_t recovery_grace_period;
107         uint32_t recovery_ban_period;
108         uint32_t database_hash_size;
109         uint32_t database_max_dead;
110         uint32_t rerecovery_timeout;
111         uint32_t enable_bans;
112         uint32_t deterministic_public_ips;
113         uint32_t disable_when_unhealthy;
114         uint32_t reclock_ping_period;
115         uint32_t no_ip_failback;
116         uint32_t verbose_memory_names;
117 };
118
119 /*
120   an installed ctdb remote call
121 */
122 struct ctdb_registered_call {
123         struct ctdb_registered_call *next, *prev;
124         uint32_t id;
125         ctdb_fn_t fn;
126 };
127
128 /*
129   this address structure might need to be generalised later for some
130   transports
131 */
132 struct ctdb_address {
133         const char *address;
134         int port;
135 };
136
137 /*
138   check that a pnn is valid
139  */
140 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
141
142
143 /* called from the queue code when a packet comes in. Called with data==NULL
144    on error */
145 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
146                                    void *private_data);
147
148 /* used for callbacks in ctdb_control requests */
149 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
150                                            int32_t status, TDB_DATA data, 
151                                            const char *errormsg,
152                                            void *private_data);
153
154 /*
155   structure describing a connected client in the daemon
156  */
157 struct ctdb_client {
158         struct ctdb_context *ctdb;
159         int fd;
160         struct ctdb_queue *queue;
161         uint32_t client_id;
162         pid_t pid;
163         struct ctdb_tcp_list *tcp_list;
164         uint32_t num_persistent_updates;
165 };
166
167
168 /* state associated with a public ip address */
169 struct ctdb_vnn {
170         struct ctdb_vnn *prev, *next;
171
172         const char *iface;
173         struct sockaddr_in public_address;
174         uint8_t public_netmask_bits;
175
176         /* the node number that is serving this public address, if any. 
177            If no node serves this ip it is set to -1 */
178         int32_t pnn;
179
180         /* List of clients to tickle for this public address */
181         struct ctdb_tcp_array *tcp_array;
182
183         /* whether we need to update the other nodes with changes to our list
184            of connected clients */
185         bool tcp_update_needed;
186
187         /* a context to hang sending gratious arp events off */
188         TALLOC_CTX *takeover_ctx;
189
190         struct ctdb_kill_tcp *killtcp;
191 };
192
193 /*
194   state associated with one node
195 */
196 struct ctdb_node {
197         struct ctdb_context *ctdb;
198         struct ctdb_address address;
199         const char *name; /* for debug messages */
200         void *private_data; /* private to transport */
201         uint32_t pnn;
202 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
203 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
204 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
205 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
206 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
207 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
208         uint32_t flags;
209
210         /* used by the dead node monitoring */
211         uint32_t dead_count;
212         uint32_t rx_cnt;
213         uint32_t tx_cnt;
214
215         /* used to track node capabilities, is only valid/tracked inside the
216            recovery daemon.
217         */
218         uint32_t capabilities;
219
220         /* a list of controls pending to this node, so we can time them out quickly
221            if the node becomes disconnected */
222         struct daemon_control_state *pending_controls;
223
224         /* used by the recovery daemon when distributing ip addresses 
225            across the nodes.  it needs to know which public ip's can be handled
226            by each node.
227         */
228         struct ctdb_all_public_ips *public_ips;
229 };
230
231 /*
232   transport specific methods
233 */
234 struct ctdb_methods {
235         int (*initialise)(struct ctdb_context *); /* initialise transport structures */ 
236         int (*start)(struct ctdb_context *); /* start protocol processing */    
237         int (*add_node)(struct ctdb_node *); /* setup a new node */     
238         int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
239         void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
240         void (*shutdown)(struct ctdb_context *); /* shutdown transport */
241         void (*restart)(struct ctdb_node *); /* stop and restart the connection */
242 };
243
244 /*
245   transport calls up to the ctdb layer
246 */
247 struct ctdb_upcalls {
248         /* recv_pkt is called when a packet comes in */
249         void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
250
251         /* node_dead is called when an attempt to send to a node fails */
252         void (*node_dead)(struct ctdb_node *);
253
254         /* node_connected is called when a connection to a node is established */
255         void (*node_connected)(struct ctdb_node *);
256 };
257
258 /* list of message handlers - needs to be changed to a more efficient data
259    structure so we can find a message handler given a srvid quickly */
260 struct ctdb_message_list {
261         struct ctdb_context *ctdb;
262         struct ctdb_message_list *next, *prev;
263         uint64_t srvid;
264         ctdb_message_fn_t message_handler;
265         void *message_private;
266 };
267
268 /* additional data required for the daemon mode */
269 struct ctdb_daemon_data {
270         int sd;
271         char *name;
272         struct ctdb_queue *queue;
273 };
274
275 /*
276   ctdb status information
277  */
278 struct ctdb_statistics {
279         uint32_t num_clients;
280         uint32_t frozen;
281         uint32_t recovering;
282         uint32_t client_packets_sent;
283         uint32_t client_packets_recv;
284         uint32_t node_packets_sent;
285         uint32_t node_packets_recv;
286         uint32_t keepalive_packets_sent;
287         uint32_t keepalive_packets_recv;
288         struct {
289                 uint32_t req_call;
290                 uint32_t reply_call;
291                 uint32_t req_dmaster;
292                 uint32_t reply_dmaster;
293                 uint32_t reply_error;
294                 uint32_t req_message;
295                 uint32_t req_control;
296                 uint32_t reply_control;
297         } node;
298         struct {
299                 uint32_t req_call;
300                 uint32_t req_message;
301                 uint32_t req_control;
302         } client;
303         struct {
304                 uint32_t call;
305                 uint32_t control;
306                 uint32_t traverse;
307         } timeouts;
308         uint32_t total_calls;
309         uint32_t pending_calls;
310         uint32_t lockwait_calls;
311         uint32_t pending_lockwait_calls;
312         uint32_t childwrite_calls;
313         uint32_t pending_childwrite_calls;
314         uint32_t memory_used;
315         uint32_t __last_counter; /* hack for control_statistics_all */
316         uint32_t max_hop_count;
317         double max_call_latency;
318         double max_lockwait_latency;
319         double max_childwrite_latency;
320 };
321
322
323 #define INVALID_GENERATION 1
324 /* table that contains the mapping between a hash value and lmaster
325  */
326 struct ctdb_vnn_map {
327         uint32_t generation;
328         uint32_t size;
329         uint32_t *map;
330 };
331
332 /* 
333    a wire representation of the vnn map
334  */
335 struct ctdb_vnn_map_wire {
336         uint32_t generation;
337         uint32_t size;
338         uint32_t map[1];
339 };
340
341 /* a structure that contains the elements required for the write record
342    control
343 */
344 struct ctdb_write_record {
345         uint32_t dbid;
346         uint32_t keylen;
347         uint32_t datalen;
348         unsigned char blob[1];
349 };
350
351 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
352
353 #define CTDB_MONITORING_ACTIVE          0
354 #define CTDB_MONITORING_DISABLED        1
355
356 /* The different capabilities of the ctdb daemon. */
357 #define CTDB_CAP_RECMASTER              0x00000001
358 #define CTDB_CAP_LMASTER                0x00000002
359 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
360 #define CTDB_CAP_LVS                    0x00000004
361
362 /* main state of the ctdb daemon */
363 struct ctdb_context {
364         struct event_context *ev;
365         struct timeval ctdbd_start_time;
366         struct timeval last_recovery_started;
367         struct timeval last_recovery_finished;
368         uint32_t recovery_mode;
369         TALLOC_CTX *tickle_update_context;
370         TALLOC_CTX *keepalive_ctx;
371         struct ctdb_tunable tunable;
372         enum ctdb_freeze_mode freeze_mode;
373         struct ctdb_freeze_handle *freeze_handle;
374         struct ctdb_address address;
375         const char *name;
376         const char *db_directory;
377         const char *db_directory_persistent;
378         const char *transport;
379         const char *logfile;
380         char *node_list_file;
381         char *recovery_lock_file;
382         int recovery_lock_fd;
383         uint32_t pnn; /* our own pnn */
384         uint32_t num_nodes;
385         uint32_t num_connected;
386         unsigned flags;
387         uint32_t capabilities;
388         struct idr_context *idr;
389         uint16_t idr_cnt;
390         struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
391         struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
392         struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
393         char *err_msg;
394         const struct ctdb_methods *methods; /* transport methods */
395         const struct ctdb_upcalls *upcalls; /* transport upcalls */
396         void *private_data; /* private to transport */
397         struct ctdb_db_context *db_list;
398         struct ctdb_message_list *message_list;
399         struct ctdb_daemon_data daemon;
400         struct ctdb_statistics statistics;
401         struct ctdb_vnn_map *vnn_map;
402         uint32_t num_clients;
403         uint32_t recovery_master;
404         struct ctdb_call_state *pending_calls;
405         struct ctdb_client_ip *client_ip_list;
406         bool do_setsched;
407         void *saved_scheduler_param;
408         struct _trbt_tree_t *server_ids;        
409         const char *event_script_dir;
410         const char *default_public_interface;
411         pid_t ctdbd_pid;
412         pid_t recoverd_pid;
413         bool done_startup;
414         const char *node_ip;
415         struct ctdb_monitor_state *monitor;
416         struct ctdb_log_state *log;
417         int start_as_disabled;
418         uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
419         TALLOC_CTX *eventscripts_ctx; /* a context to hold data for the RUN_EVENTSCRIPTS control */
420 };
421
422 struct ctdb_db_context {
423         struct ctdb_db_context *next, *prev;
424         struct ctdb_context *ctdb;
425         uint32_t db_id;
426         bool persistent;
427         const char *db_name;
428         const char *db_path;
429         struct tdb_wrap *ltdb;
430         struct ctdb_registered_call *calls; /* list of registered calls */
431         uint32_t seqnum;
432         struct timed_event *te;
433         uint32_t client_tdb_flags;
434 };
435
436
437 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
438           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
439           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
440           return -1; }} while (0)
441
442 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
443           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
444           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
445           return; }} while (0)
446
447 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
448           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
449           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
450           return NULL; }} while (0)
451
452 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
453           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
454           ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
455           }} while (0)
456
457 /*
458   the extended header for records in the ltdb
459 */
460 struct ctdb_ltdb_header {
461         uint64_t rsn;
462         uint32_t dmaster;
463         uint32_t laccessor;
464         uint32_t lacount;
465 };
466
467 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0, 
468                     CTDB_CONTROL_STATISTICS              = 1, 
469                     /* #2 removed */
470                     CTDB_CONTROL_PING                    = 3,
471                     CTDB_CONTROL_GETDBPATH               = 4,
472                     CTDB_CONTROL_GETVNNMAP               = 5,
473                     CTDB_CONTROL_SETVNNMAP               = 6,
474                     CTDB_CONTROL_GET_DEBUG               = 7,
475                     CTDB_CONTROL_SET_DEBUG               = 8,
476                     CTDB_CONTROL_GET_DBMAP               = 9,
477                     CTDB_CONTROL_GET_NODEMAP             = 10,
478                     CTDB_CONTROL_SET_DMASTER             = 11,
479                     /* #12 removed */
480                     CTDB_CONTROL_PULL_DB                 = 13,
481                     CTDB_CONTROL_PUSH_DB                 = 14,
482                     CTDB_CONTROL_GET_RECMODE             = 15,
483                     CTDB_CONTROL_SET_RECMODE             = 16,
484                     CTDB_CONTROL_STATISTICS_RESET        = 17,
485                     CTDB_CONTROL_DB_ATTACH               = 18,
486                     CTDB_CONTROL_SET_CALL                = 19,
487                     CTDB_CONTROL_TRAVERSE_START          = 20,
488                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
489                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
490                     CTDB_CONTROL_REGISTER_SRVID          = 23,
491                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
492                     CTDB_CONTROL_GET_DBNAME              = 25,
493                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
494                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
495                     /* #28 removed */
496                     CTDB_CONTROL_DUMP_MEMORY             = 29,
497                     CTDB_CONTROL_GET_PID                 = 30,
498                     CTDB_CONTROL_GET_RECMASTER           = 31,
499                     CTDB_CONTROL_SET_RECMASTER           = 32,
500                     CTDB_CONTROL_FREEZE                  = 33,
501                     CTDB_CONTROL_THAW                    = 34,
502                     CTDB_CONTROL_GET_PNN                 = 35,
503                     CTDB_CONTROL_SHUTDOWN                = 36,
504                     CTDB_CONTROL_GET_MONMODE             = 37,
505                     /* #38 removed */
506                     /* #39 removed */
507                     /* #40 removed */
508                     /* #41 removed */
509                     CTDB_CONTROL_TAKEOVER_IP             = 42,
510                     CTDB_CONTROL_RELEASE_IP              = 43,
511                     CTDB_CONTROL_TCP_CLIENT              = 44,
512                     CTDB_CONTROL_TCP_ADD                 = 45,
513                     CTDB_CONTROL_TCP_REMOVE              = 46,
514                     CTDB_CONTROL_STARTUP                 = 47,
515                     CTDB_CONTROL_SET_TUNABLE             = 48,
516                     CTDB_CONTROL_GET_TUNABLE             = 49,
517                     CTDB_CONTROL_LIST_TUNABLES           = 50,
518                     CTDB_CONTROL_GET_PUBLIC_IPS          = 51,
519                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
520                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
521                     CTDB_CONTROL_KILL_TCP                = 54,
522                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
523                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
524                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
525                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
526                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
527                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
528                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
529                     CTDB_CONTROL_PERSISTENT_STORE        = 62,
530                     CTDB_CONTROL_UPDATE_RECORD           = 63,
531                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
532                     CTDB_CONTROL_TRANSACTION_START       = 65,
533                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
534                     CTDB_CONTROL_WIPE_DATABASE           = 67,
535                     /* #68 removed */
536                     CTDB_CONTROL_UPTIME                  = 69,
537                     CTDB_CONTROL_START_RECOVERY          = 70,
538                     CTDB_CONTROL_END_RECOVERY            = 71,
539                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
540                     CTDB_CONTROL_GET_RECLOCK_FILE        = 73,
541                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
542                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
543                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
544                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
545                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
546                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
547                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
548                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
549                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
550 };      
551
552 /*
553   structure passed in set_call control
554  */
555 struct ctdb_control_set_call {
556         uint32_t db_id;
557         ctdb_fn_t fn;
558         uint32_t id;
559 };
560
561 /*
562   struct for tcp_client control
563  */
564 struct ctdb_control_tcp {
565         struct sockaddr_in src;
566         struct sockaddr_in dest;
567 };
568
569 /*
570   struct for kill_tcp control
571  */
572 struct ctdb_control_killtcp {
573         struct sockaddr_in src;
574         struct sockaddr_in dst;
575 };
576
577 /*
578   struct holding a sockaddr_in and an interface name,
579   used to add/remove public addresses
580  */
581 struct ctdb_control_ip_iface {
582         struct sockaddr_in sin;
583         uint32_t mask;
584         uint32_t len;
585         char iface[1];
586 };
587
588 /*
589   struct holding a ctdb_sock_addr and an interface name,
590   used for send_gratious_arp
591  */
592 struct ctdb_control_gratious_arp {
593         ctdb_sock_addr addr;
594         uint32_t mask;
595         uint32_t len;
596         char iface[1];
597 };
598
599 /*
600   struct for tcp_add and tcp_remove controls
601  */
602 struct ctdb_control_tcp_vnn {
603         struct sockaddr_in src;
604         struct sockaddr_in dest;
605 };
606
607 /*
608   persistent store control - update this record on all other nodes
609  */
610 struct ctdb_control_persistent_store {
611         uint32_t db_id;
612         uint32_t len;
613         uint8_t  data[1];
614 };
615
616 /*
617   structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
618  */
619 struct ctdb_node_flag_change {
620         uint32_t pnn;
621         uint32_t new_flags;
622         uint32_t old_flags;
623 };
624
625 /*
626   structure to change flags on a node
627  */
628 struct ctdb_node_modflags {
629         uint32_t set;
630         uint32_t clear;
631 };
632
633 /*
634   struct for admin setting a ban
635  */
636 struct ctdb_ban_info {
637         uint32_t pnn;
638         uint32_t ban_time;
639 };
640
641 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
642
643 #define CTDB_LMASTER_ANY        0xffffffff
644
645 /*
646   state of a in-progress ctdb call
647 */
648 struct ctdb_call_state {
649         struct ctdb_call_state *next, *prev;
650         enum call_state state;
651         uint32_t reqid;
652         struct ctdb_req_call *c;
653         struct ctdb_db_context *ctdb_db;
654         const char *errmsg;
655         struct ctdb_call *call;
656         uint32_t generation;
657         struct {
658                 void (*fn)(struct ctdb_call_state *);
659                 void *private_data;
660         } async;
661 };
662
663
664 /* used for fetch_lock */
665 struct ctdb_fetch_handle {
666         struct ctdb_db_context *ctdb_db;
667         TDB_DATA key;
668         TDB_DATA *data;
669         struct ctdb_ltdb_header header;
670 };
671
672 /*
673   operation IDs
674 */
675 enum ctdb_operation {
676         CTDB_REQ_CALL           = 0,
677         CTDB_REPLY_CALL         = 1,
678         CTDB_REQ_DMASTER        = 2,
679         CTDB_REPLY_DMASTER      = 3,
680         CTDB_REPLY_ERROR        = 4,
681         CTDB_REQ_MESSAGE        = 5,
682         /* #6 removed */
683         CTDB_REQ_CONTROL        = 7,
684         CTDB_REPLY_CONTROL      = 8,
685         CTDB_REQ_KEEPALIVE      = 9,
686 };
687
688 #define CTDB_MAGIC 0x43544442 /* CTDB */
689 #define CTDB_VERSION 1
690
691 /*
692   packet structures
693 */
694 struct ctdb_req_header {
695         uint32_t length;
696         uint32_t ctdb_magic;
697         uint32_t ctdb_version;
698         uint32_t generation;
699         uint32_t operation;
700         uint32_t destnode;
701         uint32_t srcnode;
702         uint32_t reqid;
703 };
704
705 struct ctdb_req_call {
706         struct ctdb_req_header hdr;
707         uint32_t flags;
708         uint32_t db_id;
709         uint32_t callid;
710         uint32_t hopcount;
711         uint32_t keylen;
712         uint32_t calldatalen;
713         uint8_t data[1]; /* key[] followed by calldata[] */
714 };
715
716 struct ctdb_reply_call {
717         struct ctdb_req_header hdr;
718         uint32_t status;
719         uint32_t datalen;
720         uint8_t  data[1];
721 };
722
723 struct ctdb_reply_error {
724         struct ctdb_req_header hdr;
725         uint32_t status;
726         uint32_t msglen;
727         uint8_t  msg[1];
728 };
729
730 struct ctdb_req_dmaster {
731         struct ctdb_req_header hdr;
732         uint32_t db_id;
733         uint64_t rsn;
734         uint32_t dmaster;
735         uint32_t keylen;
736         uint32_t datalen;
737         uint8_t  data[1];
738 };
739
740 struct ctdb_reply_dmaster {
741         struct ctdb_req_header hdr;
742         uint32_t db_id;
743         uint64_t rsn;
744         uint32_t keylen;
745         uint32_t datalen;
746         uint8_t  data[1];
747 };
748
749 struct ctdb_req_message {
750         struct ctdb_req_header hdr;
751         uint64_t srvid;
752         uint32_t datalen;
753         uint8_t data[1];
754 };
755
756 struct ctdb_req_getdbpath {
757         struct ctdb_req_header hdr;
758         uint32_t db_id;
759 };
760
761 struct ctdb_reply_getdbpath {
762         struct ctdb_req_header hdr;
763         uint32_t datalen;
764         uint8_t data[1];
765 };
766
767 struct ctdb_req_control {
768         struct ctdb_req_header hdr;
769         uint32_t opcode;
770         uint64_t srvid;
771         uint32_t client_id;
772 #define CTDB_CTRL_FLAG_NOREPLY   1
773         uint32_t flags;
774         uint32_t datalen;
775         uint8_t data[1];
776 };
777
778 struct ctdb_reply_control {
779         struct ctdb_req_header hdr;
780         int32_t  status;
781         uint32_t datalen;
782         uint32_t errorlen;
783         uint8_t data[1];
784 };
785
786 struct ctdb_req_keepalive {
787         struct ctdb_req_header hdr;
788 };
789
790 /* internal prototypes */
791 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
792 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
793 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
794 bool parse_ip_mask(const char *s, struct sockaddr_in *ip, unsigned *mask);
795 int ctdb_parse_address(struct ctdb_context *ctdb,
796                        TALLOC_CTX *mem_ctx, const char *str,
797                        struct ctdb_address *address);
798 bool ctdb_same_ipv4(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
799 bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2);
800 bool ctdb_same_sockaddr(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
801 uint32_t ctdb_hash(const TDB_DATA *key);
802 uint32_t ctdb_hash_string(const char *str);
803 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
804 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
805 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
806 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
807 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
808 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
809
810 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
811 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, 
812                     TDB_DATA key, struct ctdb_ltdb_header *header, 
813                     TALLOC_CTX *mem_ctx, TDB_DATA *data);
814 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, 
815                     struct ctdb_ltdb_header *header, TDB_DATA data);
816 int ctdb_ltdb_persistent_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, 
817                     struct ctdb_ltdb_header *header, TDB_DATA data);
818 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb, 
819                         struct ctdb_req_control *c,
820                         TDB_DATA recdata);
821 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb, 
822                         struct ctdb_req_control *c,
823                         TDB_DATA recdata);
824 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
825 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
826 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db, 
827                            TDB_DATA key, struct ctdb_req_header *hdr,
828                            void (*recv_pkt)(void *, struct ctdb_req_header *),
829                            void *recv_context, bool ignore_generation);
830 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db, 
831                                  TDB_DATA key, struct ctdb_ltdb_header *header, 
832                                  struct ctdb_req_header *hdr, TDB_DATA *data,
833                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
834                                  void *recv_context, bool ignore_generation);
835 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
836
837 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db, 
838                                              struct ctdb_call *call,
839                                              struct ctdb_ltdb_header *header,
840                                              TDB_DATA *data);
841
842
843 int ctdbd_start(struct ctdb_context *ctdb);
844 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
845 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
846
847 /*
848   queue a packet for sending
849 */
850 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
851
852 /*
853   setup the fd used by the queue
854  */
855 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
856
857 /*
858   setup a packet queue on a socket
859  */
860 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
861                                     TALLOC_CTX *mem_ctx, int fd, int alignment,
862                                     
863                                     ctdb_queue_cb_fn_t callback,
864                                     void *private_data);
865
866 /*
867   allocate a packet for use in client<->daemon communication
868  */
869 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
870                                             TALLOC_CTX *mem_ctx, 
871                                             enum ctdb_operation operation, 
872                                             size_t length, size_t slength,
873                                             const char *type);
874 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
875         (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
876
877 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
878                                                  TALLOC_CTX *mem_ctx, 
879                                                  enum ctdb_operation operation, 
880                                                  size_t length, size_t slength,
881                                                  const char *type);
882 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
883         (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
884
885
886 /*
887   lock a record in the ltdb, given a key
888  */
889 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
890
891 /*
892   unlock a record in the ltdb, given a key
893  */
894 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
895
896
897 /*
898   make a ctdb call to the local daemon - async send. Called from client context.
899
900   This constructs a ctdb_call request and queues it for processing. 
901   This call never blocks.
902 */
903 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db, 
904                                               struct ctdb_call *call);
905
906 /*
907   make a recv call to the local ctdb daemon - called from client context
908
909   This is called when the program wants to wait for a ctdb_call to complete and get the 
910   results. This call will block unless the call has already completed.
911 */
912 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
913
914 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
915                              ctdb_message_fn_t handler,
916                              void *private_data);
917
918 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
919                              uint64_t srvid, TDB_DATA data);
920
921 /*
922   send a ctdb message
923 */
924 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
925                              uint64_t srvid, TDB_DATA data);
926
927
928 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
929                                       TDB_DATA key,
930                                       void (*callback)(void *), void *private_data);
931
932 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, 
933                                               struct ctdb_call *call);
934
935 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
936
937 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db, 
938                                                      struct ctdb_call *call, 
939                                                      struct ctdb_ltdb_header *header);
940
941 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
942                     struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
943                     uint32_t caller);
944
945 #define ctdb_reqid_find(ctdb, reqid, type)      (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
946
947 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
948
949 int ctdb_socket_connect(struct ctdb_context *ctdb);
950
951 void ctdb_latency(double *latency, struct timeval t);
952
953 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
954 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
955 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
956
957 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
958 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
959
960 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
961                              uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
962                              TDB_DATA data,
963                              ctdb_control_callback_fn_t callback,
964                              void *private_data);
965
966 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata, 
967                                TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
968
969 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
970                          ctdb_fn_t fn, int id);
971
972 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid, 
973                  uint32_t opcode, uint32_t flags, TDB_DATA data, 
974                  TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
975                  struct timeval *timeout, char **errormsg);
976 int ctdb_control_recv(struct ctdb_context *ctdb, 
977                 struct ctdb_client_control_state *state, 
978                 TALLOC_CTX *mem_ctx,
979                 TDB_DATA *outdata, int32_t *status, char **errormsg);
980
981 struct ctdb_client_control_state *
982 ctdb_control_send(struct ctdb_context *ctdb, 
983                 uint32_t destnode, uint64_t srvid, 
984                 uint32_t opcode, uint32_t flags, TDB_DATA data, 
985                 TALLOC_CTX *mem_ctx,
986                 struct timeval *timeout,
987                 char **errormsg);
988
989
990
991
992 #define CHECK_CONTROL_DATA_SIZE(size) do { \
993  if (indata.dsize != size) { \
994          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
995                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
996          return -1; \
997  } \
998  } while (0)
999
1000 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1001 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1002 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1003 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1004 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1005
1006
1007 struct ctdb_traverse_start {
1008         uint32_t db_id;
1009         uint32_t reqid;
1010         uint64_t srvid;
1011 };
1012
1013 /*
1014   structure used to pass record data between the child and parent
1015  */
1016 struct ctdb_rec_data {
1017         uint32_t length;
1018         uint32_t reqid;
1019         uint32_t keylen;
1020         uint32_t datalen;
1021         uint8_t  data[1];
1022 };
1023                                    
1024
1025 /* structure used for pulldb control */
1026 struct ctdb_control_pulldb {
1027         uint32_t db_id;
1028         uint32_t lmaster;
1029 };
1030
1031 /* structure used for pulldb control */
1032 struct ctdb_control_pulldb_reply {
1033         uint32_t db_id;
1034         uint32_t count;
1035         uint8_t data[1];
1036 };
1037
1038 /* set dmaster control structure */
1039 struct ctdb_control_set_dmaster {
1040         uint32_t db_id;
1041         uint32_t dmaster;
1042 };
1043
1044 /*
1045   structure for setting a tunable
1046  */
1047 struct ctdb_control_set_tunable {
1048         uint32_t value;
1049         uint32_t length;
1050         uint8_t  name[1];
1051 };
1052
1053 /*
1054   structure for getting a tunable
1055  */
1056 struct ctdb_control_get_tunable {
1057         uint32_t length;
1058         uint8_t  name[1];
1059 };
1060
1061 /*
1062   structure for listing tunables
1063  */
1064 struct ctdb_control_list_tunable {
1065         uint32_t length;
1066         /* returns a : separated list of tunable names */
1067         uint8_t  data[1];
1068 };
1069
1070
1071 /* table that contains a list of all nodes a ctdb knows about and their 
1072    status
1073  */
1074 struct ctdb_node_and_flags {
1075         uint32_t pnn;
1076         uint32_t flags;
1077         struct sockaddr_in sin;
1078
1079 };
1080
1081 struct ctdb_node_map {
1082         uint32_t num;
1083         struct ctdb_node_and_flags nodes[1];
1084 };
1085
1086 struct ctdb_control_wipe_database {
1087         uint32_t db_id;
1088         uint32_t transaction_id;
1089 };
1090
1091 /*
1092   state of a in-progress ctdb call in client
1093 */
1094 struct ctdb_client_call_state {
1095         enum call_state state;
1096         uint32_t reqid;
1097         struct ctdb_db_context *ctdb_db;
1098         struct ctdb_call *call;
1099         struct {
1100                 void (*fn)(struct ctdb_client_call_state *);
1101                 void *private_data;
1102         } async;
1103 };
1104
1105
1106 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata, 
1107                                     TDB_DATA *outdata, uint32_t srcnode);
1108 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1109 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1110
1111 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1112
1113 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1114 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1115 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1116
1117 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1118 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1119 int32_t ctdb_ltdb_set_seqnum_frequency(struct ctdb_context *ctdb, uint32_t frequency);
1120
1121 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, 
1122                                            TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1123
1124 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1125 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1126 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1127
1128 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, 
1129                                  struct ctdb_req_control *c,
1130                                  TDB_DATA indata, bool *async_reply,
1131                                  const char **errormsg);
1132 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1133                                 TDB_DATA *outdata, int32_t status, const char *errormsg);
1134
1135 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1136 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1137
1138 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1139 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1140
1141 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1142
1143 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1144 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1145 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1146 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1147 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1148 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1149 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1150 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1151 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1152
1153
1154 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1155 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1156 void ctdb_node_dead(struct ctdb_node *node);
1157 void ctdb_node_connected(struct ctdb_node *node);
1158 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1159 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1160 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1161 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
1162                                  struct ctdb_req_control *c,
1163                                  TDB_DATA indata, 
1164                                  bool *async_reply);
1165 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, 
1166                                  struct ctdb_req_control *c,
1167                                  TDB_DATA indata, 
1168                                  bool *async_reply);
1169 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb, 
1170                                  struct ctdb_req_control *c,
1171                                  bool *async_reply);
1172 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb, 
1173                                  struct ctdb_req_control *c,
1174                                  bool *async_reply);
1175
1176 struct ctdb_public_ip {
1177         uint32_t pnn;
1178         struct sockaddr_in sin;
1179 };
1180 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1181                           uint32_t destnode, struct ctdb_public_ip *ip);
1182 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1183                          uint32_t destnode, struct ctdb_public_ip *ip);
1184
1185 struct ctdb_all_public_ips {
1186         uint32_t num;
1187         struct ctdb_public_ip ips[1];
1188 };
1189 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1190 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, 
1191                         struct timeval timeout, uint32_t destnode, 
1192                         TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1193
1194
1195 /* from takeover/system.c */
1196 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1197 bool ctdb_sys_have_ip(struct sockaddr_in ip);
1198 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
1199                       const ctdb_sock_addr *src,
1200                       uint32_t seq, uint32_t ack, int rst);
1201
1202 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1203 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1204 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1205 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1206
1207 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, 
1208                                 TDB_DATA indata);
1209 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1210 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1211 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1212 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1213 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1214 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1215 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1216
1217 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1218 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1219 int ctdb_event_script_callback(struct ctdb_context *ctdb, 
1220                                struct timeval timeout,
1221                                TALLOC_CTX *mem_ctx,
1222                                void (*callback)(struct ctdb_context *, int, void *),
1223                                void *private_data,
1224                                const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1225 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1226
1227 void set_nonblocking(int fd);
1228 void set_close_on_exec(int fd);
1229
1230 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1231
1232 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1233
1234 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata, 
1235                                  TDB_DATA *outdata);
1236 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1237 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1238 int32_t ctdb_control_get_reclock_file(struct ctdb_context *ctdb, TDB_DATA *outdata);
1239 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1240 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1241 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1242
1243 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1244
1245 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1246
1247 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb, 
1248                                struct timeval timeout, 
1249                                uint32_t destnode,
1250                                struct ctdb_tunable *tunables);
1251
1252 void ctdb_start_freeze(struct ctdb_context *ctdb);
1253
1254 bool parse_ip_port(const char *s, ctdb_sock_addr *saddr);
1255 bool parse_ip(const char *s, ctdb_sock_addr *saddr);
1256
1257 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1258 int ctdb_sys_close_capture_socket(void *private_data);
1259 int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst,
1260                              uint32_t *ack_seq, uint32_t *seq);
1261
1262 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, 
1263                       struct timeval timeout, 
1264                       uint32_t destnode,
1265                       struct ctdb_control_killtcp *killtcp);
1266
1267 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb, 
1268                       struct timeval timeout, 
1269                       uint32_t destnode,
1270                       struct ctdb_control_ip_iface *pub);
1271
1272 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb, 
1273                       struct timeval timeout, 
1274                       uint32_t destnode,
1275                       struct ctdb_control_ip_iface *pub);
1276
1277 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb, 
1278                       struct timeval timeout, 
1279                       uint32_t destnode,
1280                       ctdb_sock_addr *addr,
1281                       const char *ifname);
1282
1283 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, 
1284                       struct timeval timeout, 
1285                       uint32_t destnode,
1286                       TALLOC_CTX *mem_ctx,
1287                       struct sockaddr_in *ip,
1288                       struct ctdb_control_tcp_tickle_list **list);
1289
1290
1291 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, 
1292                       uint32_t client_id,
1293                       TDB_DATA indata);
1294 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb, 
1295                       TDB_DATA indata);
1296 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, 
1297                       TDB_DATA indata);
1298 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, 
1299                       TDB_DATA *outdata);
1300 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, 
1301                       TDB_DATA *outdata);
1302
1303 int ctdb_attach_persistent(struct ctdb_context *ctdb);
1304
1305 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb, 
1306                                       struct ctdb_req_control *c, 
1307                                       TDB_DATA recdata, bool *async_reply);
1308 int32_t ctdb_control_update_record(struct ctdb_context *ctdb, 
1309                                    struct ctdb_req_control *c, TDB_DATA recdata, 
1310                                    bool *async_reply);
1311
1312 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1313 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1314 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1315
1316
1317 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1318 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1319
1320 void ctdb_block_signal(int signum);
1321 void ctdb_unblock_signal(int signum);
1322 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1323 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1324
1325
1326 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1327
1328 struct client_async_data {
1329         enum ctdb_controls opcode;
1330         bool dont_log_errors;
1331         uint32_t count;
1332         uint32_t fail_count;
1333         client_async_callback callback;
1334         client_async_callback fail_callback;
1335         void *callback_data;
1336 };
1337 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1338 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1339 int ctdb_client_async_control(struct ctdb_context *ctdb,
1340                                 enum ctdb_controls opcode,
1341                                 uint32_t *nodes,
1342                                 struct timeval timeout,
1343                                 bool dont_log_errors,
1344                                 TDB_DATA data,
1345                                 client_async_callback client_callback,
1346                                 client_async_callback fail_callback,
1347                                 void *callback_data);
1348
1349 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1350
1351 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1352
1353 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1354 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1355
1356 #endif