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