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