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