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