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