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