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