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