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