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