3226916a0fee512ac5a320f2d9f187c4e769f4d4
[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_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         uint32_t vacuum_default_interval;
112         uint32_t vacuum_max_run_time;
113 };
114
115 /*
116   an installed ctdb remote call
117 */
118 struct ctdb_registered_call {
119         struct ctdb_registered_call *next, *prev;
120         uint32_t id;
121         ctdb_fn_t fn;
122 };
123
124 /*
125   this address structure might need to be generalised later for some
126   transports
127 */
128 struct ctdb_address {
129         const char *address;
130         int port;
131 };
132
133 /*
134   check that a pnn is valid
135  */
136 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
137
138
139 /* called from the queue code when a packet comes in. Called with data==NULL
140    on error */
141 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
142                                    void *private_data);
143
144 /* used for callbacks in ctdb_control requests */
145 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
146                                            int32_t status, TDB_DATA data, 
147                                            const char *errormsg,
148                                            void *private_data);
149
150 /*
151   structure describing a connected client in the daemon
152  */
153 struct ctdb_client {
154         struct ctdb_context *ctdb;
155         int fd;
156         struct ctdb_queue *queue;
157         uint32_t client_id;
158         pid_t pid;
159         struct ctdb_tcp_list *tcp_list;
160         uint32_t num_persistent_updates;
161 };
162
163
164 /* state associated with a public ip address */
165 struct ctdb_vnn {
166         struct ctdb_vnn *prev, *next;
167
168         const char *iface;
169         ctdb_sock_addr public_address;
170         uint8_t public_netmask_bits;
171
172         /* the node number that is serving this public address, if any. 
173            If no node serves this ip it is set to -1 */
174         int32_t pnn;
175
176         /* List of clients to tickle for this public address */
177         struct ctdb_tcp_array *tcp_array;
178
179         /* whether we need to update the other nodes with changes to our list
180            of connected clients */
181         bool tcp_update_needed;
182
183         /* a context to hang sending gratious arp events off */
184         TALLOC_CTX *takeover_ctx;
185
186         struct ctdb_kill_tcp *killtcp;
187 };
188
189 /*
190   state associated with one node
191 */
192 struct ctdb_node {
193         struct ctdb_context *ctdb;
194         struct ctdb_address address;
195         const char *name; /* for debug messages */
196         void *private_data; /* private to transport */
197         uint32_t pnn;
198 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
199 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
200 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
201 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
202 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
203 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
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
363 /* main state of the ctdb daemon */
364 struct ctdb_context {
365         struct event_context *ev;
366         struct timeval ctdbd_start_time;
367         struct timeval last_recovery_started;
368         struct timeval last_recovery_finished;
369         uint32_t recovery_mode;
370         TALLOC_CTX *tickle_update_context;
371         TALLOC_CTX *keepalive_ctx;
372         struct ctdb_tunable tunable;
373         enum ctdb_freeze_mode freeze_mode;
374         struct ctdb_freeze_handle *freeze_handle;
375         struct ctdb_address address;
376         const char *name;
377         const char *db_directory;
378         const char *db_directory_persistent;
379         const char *transport;
380         const char *logfile;
381         char *node_list_file;
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         uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
422         TALLOC_CTX *eventscripts_ctx; /* a context to hold data for the RUN_EVENTSCRIPTS control */
423         uint32_t *recd_ping_count;
424         TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
425         TALLOC_CTX *script_monitoring_ctx; /* a context where we store results while running the monitor event */
426         TALLOC_CTX *last_monitoring_ctx; 
427 };
428
429 struct ctdb_db_context {
430         struct ctdb_db_context *next, *prev;
431         struct ctdb_context *ctdb;
432         uint32_t db_id;
433         bool persistent;
434         const char *db_name;
435         const char *db_path;
436         struct tdb_wrap *ltdb;
437         struct ctdb_registered_call *calls; /* list of registered calls */
438         uint32_t seqnum;
439         struct timed_event *te;
440         struct ctdb_traverse_local_handle *traverse;
441         struct ctdb_vacuum_handle *vacuum_handle;
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 };      
575
576 /*
577   structure passed in set_call control
578  */
579 struct ctdb_control_set_call {
580         uint32_t db_id;
581         ctdb_fn_t fn;
582         uint32_t id;
583 };
584
585 /*
586   struct for kill_tcp control
587  */
588 struct ctdb_control_killtcp {
589         ctdb_sock_addr src_addr;
590         ctdb_sock_addr dst_addr;
591 };
592
593 /*
594   struct holding a ctdb_sock_addr and an interface name,
595   used to add/remove public addresses
596  */
597 struct ctdb_control_ip_iface {
598         ctdb_sock_addr addr;
599         uint32_t mask;
600         uint32_t len;
601         char iface[1];
602 };
603
604 /*
605   struct holding a ctdb_sock_addr and an interface name,
606   used for send_gratious_arp
607  */
608 struct ctdb_control_gratious_arp {
609         ctdb_sock_addr addr;
610         uint32_t mask;
611         uint32_t len;
612         char iface[1];
613 };
614
615 /*
616   struct for tcp_add and tcp_remove controls
617  */
618 struct ctdb_control_tcp_vnn {
619         ctdb_sock_addr src;
620         ctdb_sock_addr dest;
621 };
622
623 /*
624   persistent store control - update this record on all other nodes
625  */
626 struct ctdb_control_persistent_store {
627         uint32_t db_id;
628         uint32_t len;
629         uint8_t  data[1];
630 };
631
632 /*
633   structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
634  */
635 struct ctdb_node_flag_change {
636         uint32_t pnn;
637         uint32_t new_flags;
638         uint32_t old_flags;
639 };
640
641 /*
642   struct for admin setting a ban
643  */
644 struct ctdb_ban_info {
645         uint32_t pnn;
646         uint32_t ban_time;
647 };
648
649 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
650
651 #define CTDB_LMASTER_ANY        0xffffffff
652
653 /*
654   state of a in-progress ctdb call
655 */
656 struct ctdb_call_state {
657         struct ctdb_call_state *next, *prev;
658         enum call_state state;
659         uint32_t reqid;
660         struct ctdb_req_call *c;
661         struct ctdb_db_context *ctdb_db;
662         const char *errmsg;
663         struct ctdb_call *call;
664         uint32_t generation;
665         struct {
666                 void (*fn)(struct ctdb_call_state *);
667                 void *private_data;
668         } async;
669 };
670
671
672 /* used for fetch_lock */
673 struct ctdb_fetch_handle {
674         struct ctdb_db_context *ctdb_db;
675         TDB_DATA key;
676         TDB_DATA *data;
677         struct ctdb_ltdb_header header;
678 };
679
680 /*
681   operation IDs
682 */
683 enum ctdb_operation {
684         CTDB_REQ_CALL           = 0,
685         CTDB_REPLY_CALL         = 1,
686         CTDB_REQ_DMASTER        = 2,
687         CTDB_REPLY_DMASTER      = 3,
688         CTDB_REPLY_ERROR        = 4,
689         CTDB_REQ_MESSAGE        = 5,
690         /* #6 removed */
691         CTDB_REQ_CONTROL        = 7,
692         CTDB_REPLY_CONTROL      = 8,
693         CTDB_REQ_KEEPALIVE      = 9,
694 };
695
696 #define CTDB_MAGIC 0x43544442 /* CTDB */
697 #define CTDB_VERSION 1
698
699 /*
700   packet structures
701 */
702 struct ctdb_req_header {
703         uint32_t length;
704         uint32_t ctdb_magic;
705         uint32_t ctdb_version;
706         uint32_t generation;
707         uint32_t operation;
708         uint32_t destnode;
709         uint32_t srcnode;
710         uint32_t reqid;
711 };
712
713 struct ctdb_req_call {
714         struct ctdb_req_header hdr;
715         uint32_t flags;
716         uint32_t db_id;
717         uint32_t callid;
718         uint32_t hopcount;
719         uint32_t keylen;
720         uint32_t calldatalen;
721         uint8_t data[1]; /* key[] followed by calldata[] */
722 };
723
724 struct ctdb_reply_call {
725         struct ctdb_req_header hdr;
726         uint32_t status;
727         uint32_t datalen;
728         uint8_t  data[1];
729 };
730
731 struct ctdb_reply_error {
732         struct ctdb_req_header hdr;
733         uint32_t status;
734         uint32_t msglen;
735         uint8_t  msg[1];
736 };
737
738 struct ctdb_req_dmaster {
739         struct ctdb_req_header hdr;
740         uint32_t db_id;
741         uint64_t rsn;
742         uint32_t dmaster;
743         uint32_t keylen;
744         uint32_t datalen;
745         uint8_t  data[1];
746 };
747
748 struct ctdb_reply_dmaster {
749         struct ctdb_req_header hdr;
750         uint32_t db_id;
751         uint64_t rsn;
752         uint32_t keylen;
753         uint32_t datalen;
754         uint8_t  data[1];
755 };
756
757 struct ctdb_req_message {
758         struct ctdb_req_header hdr;
759         uint64_t srvid;
760         uint32_t datalen;
761         uint8_t data[1];
762 };
763
764 struct ctdb_req_getdbpath {
765         struct ctdb_req_header hdr;
766         uint32_t db_id;
767 };
768
769 struct ctdb_reply_getdbpath {
770         struct ctdb_req_header hdr;
771         uint32_t datalen;
772         uint8_t data[1];
773 };
774
775 struct ctdb_req_control {
776         struct ctdb_req_header hdr;
777         uint32_t opcode;
778         uint64_t srvid;
779         uint32_t client_id;
780 #define CTDB_CTRL_FLAG_NOREPLY   1
781         uint32_t flags;
782         uint32_t datalen;
783         uint8_t data[1];
784 };
785
786 struct ctdb_reply_control {
787         struct ctdb_req_header hdr;
788         int32_t  status;
789         uint32_t datalen;
790         uint32_t errorlen;
791         uint8_t data[1];
792 };
793
794 struct ctdb_req_keepalive {
795         struct ctdb_req_header hdr;
796 };
797
798
799 /* types of failures possible from TRANS2_COMMIT */
800 enum ctdb_trans2_commit_error {
801         CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
802         CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
803         CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
804         CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
805 };
806
807
808 /* internal prototypes */
809 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
810 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
811 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
812 int ctdb_parse_address(struct ctdb_context *ctdb,
813                        TALLOC_CTX *mem_ctx, const char *str,
814                        struct ctdb_address *address);
815 bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
816 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
817 uint32_t ctdb_hash(const TDB_DATA *key);
818 uint32_t ctdb_hash_string(const char *str);
819 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
820 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
821 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
822 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
823 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
824 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
825
826 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
827 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, 
828                     TDB_DATA key, struct ctdb_ltdb_header *header, 
829                     TALLOC_CTX *mem_ctx, TDB_DATA *data);
830 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, 
831                     struct ctdb_ltdb_header *header, TDB_DATA data);
832 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb, 
833                         struct ctdb_req_control *c,
834                         TDB_DATA recdata);
835 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb, 
836                         struct ctdb_req_control *c,
837                         TDB_DATA recdata);
838 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
839 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
840 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db, 
841                            TDB_DATA key, struct ctdb_req_header *hdr,
842                            void (*recv_pkt)(void *, struct ctdb_req_header *),
843                            void *recv_context, bool ignore_generation);
844 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db, 
845                                  TDB_DATA key, struct ctdb_ltdb_header *header, 
846                                  struct ctdb_req_header *hdr, TDB_DATA *data,
847                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
848                                  void *recv_context, bool ignore_generation);
849 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
850
851 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db, 
852                                              struct ctdb_call *call,
853                                              struct ctdb_ltdb_header *header,
854                                              TDB_DATA *data);
855
856
857 int ctdbd_start(struct ctdb_context *ctdb);
858 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
859 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
860
861 /*
862   queue a packet for sending
863 */
864 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
865
866 /*
867   setup the fd used by the queue
868  */
869 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
870
871 /*
872   setup a packet queue on a socket
873  */
874 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
875                                     TALLOC_CTX *mem_ctx, int fd, int alignment,
876                                     
877                                     ctdb_queue_cb_fn_t callback,
878                                     void *private_data);
879
880 /*
881   allocate a packet for use in client<->daemon communication
882  */
883 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
884                                             TALLOC_CTX *mem_ctx, 
885                                             enum ctdb_operation operation, 
886                                             size_t length, size_t slength,
887                                             const char *type);
888 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
889         (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
890
891 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
892                                                  TALLOC_CTX *mem_ctx, 
893                                                  enum ctdb_operation operation, 
894                                                  size_t length, size_t slength,
895                                                  const char *type);
896 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
897         (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
898
899
900 /*
901   lock a record in the ltdb, given a key
902  */
903 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
904
905 /*
906   unlock a record in the ltdb, given a key
907  */
908 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
909
910
911 /*
912   make a ctdb call to the local daemon - async send. Called from client context.
913
914   This constructs a ctdb_call request and queues it for processing. 
915   This call never blocks.
916 */
917 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db, 
918                                               struct ctdb_call *call);
919
920 /*
921   make a recv call to the local ctdb daemon - called from client context
922
923   This is called when the program wants to wait for a ctdb_call to complete and get the 
924   results. This call will block unless the call has already completed.
925 */
926 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
927
928 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
929                              ctdb_message_fn_t handler,
930                              void *private_data);
931
932 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
933                              uint64_t srvid, TDB_DATA data);
934
935 /*
936   send a ctdb message
937 */
938 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
939                              uint64_t srvid, TDB_DATA data);
940
941
942 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
943                                       TDB_DATA key,
944                                       void (*callback)(void *), void *private_data);
945
946 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, 
947                                               struct ctdb_call *call);
948
949 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
950
951 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db, 
952                                                      struct ctdb_call *call, 
953                                                      struct ctdb_ltdb_header *header);
954
955 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
956                     struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
957                     uint32_t caller);
958
959 #define ctdb_reqid_find(ctdb, reqid, type)      (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
960
961 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
962
963 int ctdb_socket_connect(struct ctdb_context *ctdb);
964
965 void ctdb_latency(struct ctdb_db_context *ctdb_db, const char *name, double *latency, struct timeval t);
966 void ctdb_reclock_latency(struct ctdb_context *ctdb, const char *name, double *latency, double l);
967
968 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
969 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
970 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
971
972 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
973 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
974
975 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
976                              uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
977                              TDB_DATA data,
978                              ctdb_control_callback_fn_t callback,
979                              void *private_data);
980
981 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata, 
982                                TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
983
984 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
985                          ctdb_fn_t fn, int id);
986
987 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid, 
988                  uint32_t opcode, uint32_t flags, TDB_DATA data, 
989                  TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
990                  struct timeval *timeout, char **errormsg);
991 int ctdb_control_recv(struct ctdb_context *ctdb, 
992                 struct ctdb_client_control_state *state, 
993                 TALLOC_CTX *mem_ctx,
994                 TDB_DATA *outdata, int32_t *status, char **errormsg);
995
996 struct ctdb_client_control_state *
997 ctdb_control_send(struct ctdb_context *ctdb, 
998                 uint32_t destnode, uint64_t srvid, 
999                 uint32_t opcode, uint32_t flags, TDB_DATA data, 
1000                 TALLOC_CTX *mem_ctx,
1001                 struct timeval *timeout,
1002                 char **errormsg);
1003
1004
1005
1006
1007 #define CHECK_CONTROL_DATA_SIZE(size) do { \
1008  if (indata.dsize != size) { \
1009          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
1010                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
1011          return -1; \
1012  } \
1013  } while (0)
1014
1015 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1016 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1017 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1018 int ctdb_control_getnodemapv4(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1019 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1020 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1021
1022
1023 struct ctdb_traverse_start {
1024         uint32_t db_id;
1025         uint32_t reqid;
1026         uint64_t srvid;
1027 };
1028
1029 /*
1030   structure used to pass record data between the child and parent
1031  */
1032 struct ctdb_rec_data {
1033         uint32_t length;
1034         uint32_t reqid;
1035         uint32_t keylen;
1036         uint32_t datalen;
1037         uint8_t  data[1];
1038 };
1039                                    
1040
1041 /* structure used for pulldb control */
1042 struct ctdb_control_pulldb {
1043         uint32_t db_id;
1044         uint32_t lmaster;
1045 };
1046
1047 /* structure used for sending lists of records */
1048 struct ctdb_marshall_buffer {
1049         uint32_t db_id;
1050         uint32_t count;
1051         uint8_t data[1];
1052 };
1053
1054 /* set dmaster control structure */
1055 struct ctdb_control_set_dmaster {
1056         uint32_t db_id;
1057         uint32_t dmaster;
1058 };
1059
1060 /*
1061   structure for setting a tunable
1062  */
1063 struct ctdb_control_set_tunable {
1064         uint32_t value;
1065         uint32_t length;
1066         uint8_t  name[1];
1067 };
1068
1069 /*
1070   structure for getting a tunable
1071  */
1072 struct ctdb_control_get_tunable {
1073         uint32_t length;
1074         uint8_t  name[1];
1075 };
1076
1077 /*
1078   structure for listing tunables
1079  */
1080 struct ctdb_control_list_tunable {
1081         uint32_t length;
1082         /* returns a : separated list of tunable names */
1083         uint8_t  data[1];
1084 };
1085
1086
1087 /* table that contains a list of all nodes a ctdb knows about and their 
1088    status
1089  */
1090 struct ctdb_node_and_flags {
1091         uint32_t pnn;
1092         uint32_t flags;
1093         ctdb_sock_addr addr;
1094 };
1095
1096 struct ctdb_node_map {
1097         uint32_t num;
1098         struct ctdb_node_and_flags nodes[1];
1099 };
1100
1101 struct ctdb_node_and_flagsv4 {
1102         uint32_t pnn;
1103         uint32_t flags;
1104         struct sockaddr_in sin;
1105 };
1106
1107 struct ctdb_node_mapv4 {
1108         uint32_t num;
1109         struct ctdb_node_and_flagsv4 nodes[1];
1110 };
1111
1112 struct ctdb_control_wipe_database {
1113         uint32_t db_id;
1114         uint32_t transaction_id;
1115 };
1116
1117 /*
1118   state of a in-progress ctdb call in client
1119 */
1120 struct ctdb_client_call_state {
1121         enum call_state state;
1122         uint32_t reqid;
1123         struct ctdb_db_context *ctdb_db;
1124         struct ctdb_call *call;
1125         struct {
1126                 void (*fn)(struct ctdb_client_call_state *);
1127                 void *private_data;
1128         } async;
1129 };
1130
1131
1132 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata, 
1133                                     TDB_DATA *outdata, uint32_t srcnode, uint32_t client_id);
1134 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1135 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1136 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata, 
1137                                     TDB_DATA *outdata, uint32_t srcnode);
1138
1139 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1140
1141 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1142 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1143 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1144
1145 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1146 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1147
1148 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, 
1149                                            TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1150
1151 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
1152                                               uint32_t *reqid,
1153                                               struct ctdb_ltdb_header *header,
1154                                               TDB_DATA *key, TDB_DATA *data);
1155
1156 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1157 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1158 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1159
1160 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, 
1161                                  struct ctdb_req_control *c,
1162                                  TDB_DATA indata, bool *async_reply,
1163                                  const char **errormsg);
1164 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1165                                 TDB_DATA *outdata, int32_t status, const char *errormsg);
1166
1167 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1168 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1169
1170 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1171 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1172
1173 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1174
1175 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1176 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1177 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1178 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1179 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1180 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1181 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1182 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1183 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1184
1185
1186 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1187 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1188 void ctdb_node_dead(struct ctdb_node *node);
1189 void ctdb_node_connected(struct ctdb_node *node);
1190 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1191 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1192 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1193 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
1194                                  struct ctdb_req_control *c,
1195                                  TDB_DATA indata, 
1196                                  bool *async_reply);
1197 int32_t ctdb_control_takeover_ipv4(struct ctdb_context *ctdb, 
1198                                  struct ctdb_req_control *c,
1199                                  TDB_DATA indata, 
1200                                  bool *async_reply);
1201 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, 
1202                                  struct ctdb_req_control *c,
1203                                  TDB_DATA indata, 
1204                                  bool *async_reply);
1205 int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb, 
1206                                  struct ctdb_req_control *c,
1207                                  TDB_DATA indata, 
1208                                  bool *async_reply);
1209 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb, 
1210                                  struct ctdb_req_control *c,
1211                                  bool *async_reply);
1212 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb, 
1213                                  struct ctdb_req_control *c,
1214                                  bool *async_reply);
1215
1216 struct ctdb_public_ipv4 {
1217         uint32_t pnn;
1218         struct sockaddr_in sin;
1219 };
1220
1221 struct ctdb_public_ip {
1222         uint32_t pnn;
1223         ctdb_sock_addr addr;
1224 };
1225 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1226                           uint32_t destnode, struct ctdb_public_ip *ip);
1227 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout, 
1228                          uint32_t destnode, struct ctdb_public_ip *ip);
1229
1230 struct ctdb_all_public_ipsv4 {
1231         uint32_t num;
1232         struct ctdb_public_ipv4 ips[1];
1233 };
1234
1235 struct ctdb_all_public_ips {
1236         uint32_t num;
1237         struct ctdb_public_ip ips[1];
1238 };
1239 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1240 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1241 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, 
1242                         struct timeval timeout, uint32_t destnode, 
1243                         TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1244 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb, 
1245                         struct timeval timeout, uint32_t destnode, 
1246                         TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1247
1248
1249 /* from takeover/system.c */
1250 uint32_t uint16_checksum(uint16_t *data, size_t n);
1251 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1252 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
1253 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
1254                       const ctdb_sock_addr *src,
1255                       uint32_t seq, uint32_t ack, int rst);
1256
1257 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1258 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1259 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1260 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
1261 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1262
1263 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, 
1264                                 TDB_DATA indata);
1265 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1266 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1267 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1268 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1269 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1270 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1271 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1272
1273 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1274 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1275 int ctdb_event_script_callback(struct ctdb_context *ctdb, 
1276                                struct timeval timeout,
1277                                TALLOC_CTX *mem_ctx,
1278                                void (*callback)(struct ctdb_context *, int, void *),
1279                                void *private_data,
1280                                const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1281 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1282
1283 void set_nonblocking(int fd);
1284 void set_close_on_exec(int fd);
1285
1286 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1287
1288 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1289
1290 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata, 
1291                                  TDB_DATA *outdata);
1292 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1293 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1294 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1295 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1296 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1297
1298 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1299
1300 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1301
1302 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb, 
1303                                struct timeval timeout, 
1304                                uint32_t destnode,
1305                                struct ctdb_tunable *tunables);
1306
1307 void ctdb_start_freeze(struct ctdb_context *ctdb);
1308
1309 bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask);
1310 bool parse_ip_port(const char *s, ctdb_sock_addr *addr);
1311 bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr);
1312 bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin);
1313  
1314
1315 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1316 int ctdb_sys_close_capture_socket(void *private_data);
1317 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);
1318
1319 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, 
1320                       struct timeval timeout, 
1321                       uint32_t destnode,
1322                       struct ctdb_control_killtcp *killtcp);
1323
1324 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb, 
1325                       struct timeval timeout, 
1326                       uint32_t destnode,
1327                       struct ctdb_control_ip_iface *pub);
1328
1329 int ctdb_ctrl_del_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_gratious_arp(struct ctdb_context *ctdb, 
1335                       struct timeval timeout, 
1336                       uint32_t destnode,
1337                       ctdb_sock_addr *addr,
1338                       const char *ifname);
1339
1340 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, 
1341                       struct timeval timeout, 
1342                       uint32_t destnode,
1343                       TALLOC_CTX *mem_ctx,
1344                       ctdb_sock_addr *addr,
1345                       struct ctdb_control_tcp_tickle_list **list);
1346
1347
1348 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, 
1349                       uint32_t client_id,
1350                       TDB_DATA indata);
1351 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb, 
1352                       TDB_DATA indata);
1353 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, 
1354                       TDB_DATA indata);
1355 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, 
1356                       TDB_DATA *outdata);
1357 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, 
1358                       TDB_DATA *outdata);
1359
1360 int ctdb_attach_persistent(struct ctdb_context *ctdb);
1361
1362 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb, 
1363                                       struct ctdb_req_control *c, 
1364                                       TDB_DATA recdata, bool *async_reply);
1365 int32_t ctdb_control_update_record(struct ctdb_context *ctdb, 
1366                                    struct ctdb_req_control *c, TDB_DATA recdata, 
1367                                    bool *async_reply);
1368 int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb, 
1369                                    struct ctdb_req_control *c, 
1370                                    TDB_DATA recdata, bool *async_reply);
1371
1372 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1373 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1374 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1375
1376
1377 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1378 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1379
1380 void ctdb_block_signal(int signum);
1381 void ctdb_unblock_signal(int signum);
1382 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1383 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1384
1385
1386 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1387
1388 struct client_async_data {
1389         enum ctdb_controls opcode;
1390         bool dont_log_errors;
1391         uint32_t count;
1392         uint32_t fail_count;
1393         client_async_callback callback;
1394         client_async_callback fail_callback;
1395         void *callback_data;
1396 };
1397 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1398 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1399 int ctdb_client_async_control(struct ctdb_context *ctdb,
1400                                 enum ctdb_controls opcode,
1401                                 uint32_t *nodes,
1402                                 struct timeval timeout,
1403                                 bool dont_log_errors,
1404                                 TDB_DATA data,
1405                                 client_async_callback client_callback,
1406                                 client_async_callback fail_callback,
1407                                 void *callback_data);
1408
1409 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1410
1411 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1412
1413 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1414 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1415
1416 int32_t ctdb_control_trans2_finished(struct ctdb_context *ctdb, 
1417                                      struct ctdb_req_control *c);
1418 int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb, 
1419                                   struct ctdb_req_control *c);
1420
1421 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
1422 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
1423 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
1424
1425 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
1426 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata);
1427
1428 extern int script_log_level;
1429
1430 int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb);
1431 int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name);
1432 int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t res);
1433 int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb);
1434
1435 int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb);
1436 int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata);
1437 int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata);
1438 int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb);
1439
1440
1441 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata);
1442
1443 int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
1444 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
1445
1446 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1447
1448 #endif