ctdb-daemon: Rename enum ctdb_eventscript_call to ctdb_event
[kai/samba-autobuild/.git] / ctdb / include / ctdb_private.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _CTDB_PRIVATE_H
21 #define _CTDB_PRIVATE_H
22
23 #include "ctdb_client.h"
24 #include <sys/socket.h>
25
26 /*
27   array of tcp connections
28  */
29 struct ctdb_tcp_array {
30         uint32_t num;
31         struct ctdb_tcp_connection *connections;
32 };
33
34 /*
35   an installed ctdb remote call
36 */
37 struct ctdb_registered_call {
38         struct ctdb_registered_call *next, *prev;
39         uint32_t id;
40         ctdb_fn_t fn;
41 };
42
43 /*
44   check that a pnn is valid
45  */
46 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
47
48
49 /* called from the queue code when a packet comes in. Called with data==NULL
50    on error */
51 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
52                                    void *private_data);
53
54 /* used for callbacks in ctdb_control requests */
55 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
56                                            int32_t status, TDB_DATA data, 
57                                            const char *errormsg,
58                                            void *private_data);
59 /*
60   structure describing a connected client in the daemon
61  */
62 struct ctdb_client {
63         struct ctdb_context *ctdb;
64         int fd;
65         struct ctdb_queue *queue;
66         uint32_t client_id;
67         pid_t pid;
68         struct ctdb_tcp_list *tcp_list;
69         uint32_t db_id;
70         uint32_t num_persistent_updates;
71         struct ctdb_client_notify_list *notify;
72 };
73
74 /* state associated with a public ip address */
75 struct ctdb_vnn {
76         struct ctdb_vnn *prev, *next;
77
78         struct ctdb_iface *iface;
79         const char **ifaces;
80         ctdb_sock_addr public_address;
81         uint8_t public_netmask_bits;
82
83         /* the node number that is serving this public address, if any. 
84            If no node serves this ip it is set to -1 */
85         int32_t pnn;
86
87         /* List of clients to tickle for this public address */
88         struct ctdb_tcp_array *tcp_array;
89
90         /* whether we need to update the other nodes with changes to our list
91            of connected clients */
92         bool tcp_update_needed;
93
94         /* a context to hang sending gratious arp events off */
95         TALLOC_CTX *takeover_ctx;
96
97         struct ctdb_kill_tcp *killtcp;
98
99         /* Set to true any time an update to this VNN is in flight.
100            This helps to avoid races. */
101         bool update_in_flight;
102
103         /* If CTDB_CONTROL_DEL_PUBLIC_IP is received for this IP
104          * address then this flag is set.  It will be deleted in the
105          * release IP callback. */
106         bool delete_pending;
107 };
108
109 /*
110   state associated with one node
111 */
112 struct ctdb_node {
113         struct ctdb_context *ctdb;
114         ctdb_sock_addr address;
115         const char *name; /* for debug messages */
116         void *private_data; /* private to transport */
117         uint32_t pnn;
118         uint32_t flags;
119
120         /* used by the dead node monitoring */
121         uint32_t dead_count;
122         uint32_t rx_cnt;
123         uint32_t tx_cnt;
124
125         /* a list of controls pending to this node, so we can time them out quickly
126            if the node becomes disconnected */
127         struct daemon_control_state *pending_controls;
128
129         /* used by the recovery daemon when distributing ip addresses 
130            across the nodes.  it needs to know which public ip's can be handled
131            by each node.
132         */
133         struct ctdb_all_public_ips *known_public_ips;
134         struct ctdb_all_public_ips *available_public_ips;
135         /* used by the recovery dameon to track when a node should be banned */
136         struct ctdb_banning_state *ban_state; 
137 };
138
139 /*
140   transport specific methods
141 */
142 struct ctdb_methods {
143         int (*initialise)(struct ctdb_context *); /* initialise transport structures */ 
144         int (*start)(struct ctdb_context *); /* start the transport */
145         int (*add_node)(struct ctdb_node *); /* setup a new node */     
146         int (*connect_node)(struct ctdb_node *); /* connect to node */
147         int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
148         void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
149         void (*shutdown)(struct ctdb_context *); /* shutdown transport */
150         void (*restart)(struct ctdb_node *); /* stop and restart the connection */
151 };
152
153 /*
154   transport calls up to the ctdb layer
155 */
156 struct ctdb_upcalls {
157         /* recv_pkt is called when a packet comes in */
158         void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
159
160         /* node_dead is called when an attempt to send to a node fails */
161         void (*node_dead)(struct ctdb_node *);
162
163         /* node_connected is called when a connection to a node is established */
164         void (*node_connected)(struct ctdb_node *);
165 };
166
167 /* additional data required for the daemon mode */
168 struct ctdb_daemon_data {
169         int sd;
170         char *name;
171         struct ctdb_queue *queue;
172 };
173
174
175 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
176         {                                                                               \
177                 if (value > ctdb->statistics.counter) {                                 \
178                         ctdb->statistics.counter = c->hopcount;                         \
179                 }                                                                       \
180                 if (value > ctdb->statistics_current.counter) {                         \
181                         ctdb->statistics_current.counter = c->hopcount;                 \
182                 }                                                                       \
183         }
184
185 #define CTDB_INCREMENT_STAT(ctdb, counter) \
186         {                                                                               \
187                 ctdb->statistics.counter++;                                             \
188                 ctdb->statistics_current.counter++;                                     \
189         }
190
191 #define CTDB_DECREMENT_STAT(ctdb, counter) \
192         {                                                                               \
193                 if (ctdb->statistics.counter > 0)                                       \
194                         ctdb->statistics.counter--;                                     \
195                 if (ctdb->statistics_current.counter > 0)                               \
196                         ctdb->statistics_current.counter--;                             \
197         }
198
199 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
200         {                                                                               \
201                 ctdb_db->statistics.counter++;                                          \
202         }
203
204 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
205         {                                                                               \
206                 if (ctdb_db->statistics.counter > 0)                                    \
207                         ctdb_db->statistics.counter--;                                  \
208         }
209
210 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
211         {                                                                               \
212                 if (value > ctdb->statistics.counter.max)                               \
213                         ctdb->statistics.counter.max = value;                           \
214                 if (value > ctdb->statistics_current.counter.max)                       \
215                         ctdb->statistics_current.counter.max = value;                   \
216                                                                                         \
217                 if (ctdb->statistics.counter.num == 0 ||                                \
218                     value < ctdb->statistics.counter.min)                               \
219                         ctdb->statistics.counter.min = value;                           \
220                 if (ctdb->statistics_current.counter.num == 0 ||                        \
221                     value < ctdb->statistics_current.counter.min)                       \
222                         ctdb->statistics_current.counter.min = value;                   \
223                                                                                         \
224                 ctdb->statistics.counter.total += value;                                \
225                 ctdb->statistics_current.counter.total += value;                        \
226                                                                                         \
227                 ctdb->statistics.counter.num++;                                         \
228                 ctdb->statistics_current.counter.num++;                                 \
229                                                                                         \
230                 if (ctdb->tunable.reclock_latency_ms != 0) {                            \
231                         if (value*1000 > ctdb->tunable.reclock_latency_ms) {            \
232                                 DEBUG(DEBUG_ERR,                                        \
233                                       ("High RECLOCK latency %fs for operation %s\n",   \
234                                        value, name));                                   \
235                         }                                                               \
236                 }                                                                       \
237         }
238
239 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value)                      \
240         {                                                                               \
241                 if (value > ctdb_db->statistics.counter.max)                            \
242                         ctdb_db->statistics.counter.max = value;                        \
243                 if (ctdb_db->statistics.counter.num == 0 ||                             \
244                     value < ctdb_db->statistics.counter.min)                            \
245                         ctdb_db->statistics.counter.min = value;                        \
246                                                                                         \
247                 ctdb_db->statistics.counter.total += value;                             \
248                 ctdb_db->statistics.counter.num++;                                      \
249                                                                                         \
250                 if (ctdb_db->ctdb->tunable.log_latency_ms != 0) {                       \
251                         if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) {       \
252                                 DEBUG(DEBUG_ERR,                                        \
253                                       ("High latency %.6fs for operation %s on database %s\n",\
254                                        value, operation, ctdb_db->db_name));            \
255                         }                                                               \
256                 }                                                                       \
257         }
258
259 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
260         {                                                                               \
261                 double l = timeval_elapsed(&t);                                         \
262                                                                                         \
263                 if (l > ctdb->statistics.counter.max)                                   \
264                         ctdb->statistics.counter.max = l;                               \
265                 if (l > ctdb->statistics_current.counter.max)                           \
266                         ctdb->statistics_current.counter.max = l;                       \
267                                                                                         \
268                 if (ctdb->statistics.counter.num == 0 ||                                \
269                     l < ctdb->statistics.counter.min)                                   \
270                         ctdb->statistics.counter.min = l;                               \
271                 if (ctdb->statistics_current.counter.num == 0 ||                        \
272                     l < ctdb->statistics_current.counter.min)                           \
273                         ctdb->statistics_current.counter.min = l;                       \
274                                                                                         \
275                 ctdb->statistics.counter.total += l;                                    \
276                 ctdb->statistics_current.counter.total += l;                            \
277                                                                                         \
278                 ctdb->statistics.counter.num++;                                         \
279                 ctdb->statistics_current.counter.num++;                                 \
280                                                                                         \
281                 if (ctdb->tunable.log_latency_ms != 0) {                                \
282                         if (l*1000 > ctdb->tunable.log_latency_ms) {                    \
283                                 DEBUG(DEBUG_WARNING,                                    \
284                                       ("High latency %.6fs for operation %s on database %s\n",\
285                                        l, operation, db->db_name));                     \
286                         }                                                               \
287                 }                                                                       \
288         }
289
290
291 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
292
293 #define NUM_DB_PRIORITIES 3
294 /* main state of the ctdb daemon */
295 struct ctdb_context {
296         struct tevent_context *ev;
297         struct timeval ctdbd_start_time;
298         struct timeval last_recovery_started;
299         struct timeval last_recovery_finished;
300         uint32_t recovery_mode;
301         TALLOC_CTX *tickle_update_context;
302         TALLOC_CTX *keepalive_ctx;
303         TALLOC_CTX *check_public_ifaces_ctx;
304         struct ctdb_tunable tunable;
305         enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
306         struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
307         bool freeze_transaction_started;
308         uint32_t freeze_transaction_id;
309         ctdb_sock_addr *address;
310         const char *name;
311         const char *db_directory;
312         const char *db_directory_persistent;
313         const char *db_directory_state;
314         struct tdb_wrap *db_persistent_health;
315         uint32_t db_persistent_startup_generation;
316         uint64_t db_persistent_check_errors;
317         uint64_t max_persistent_check_errors;
318         const char *transport;
319         char *recovery_lock_file;
320         int recovery_lock_fd;
321         uint32_t pnn; /* our own pnn */
322         uint32_t num_nodes;
323         uint32_t num_connected;
324         unsigned flags;
325         uint32_t capabilities;
326         struct reqid_context *idr;
327         struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
328         struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
329         struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
330         struct ctdb_iface *ifaces; /* list of local interfaces */
331         char *err_msg;
332         const struct ctdb_methods *methods; /* transport methods */
333         const struct ctdb_upcalls *upcalls; /* transport upcalls */
334         void *private_data; /* private to transport */
335         struct ctdb_db_context *db_list;
336         struct srvid_context *srv;
337         struct ctdb_daemon_data daemon;
338         struct ctdb_statistics statistics;
339         struct ctdb_statistics statistics_current;
340 #define MAX_STAT_HISTORY 100
341         struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
342         struct ctdb_vnn_map *vnn_map;
343         uint32_t num_clients;
344         uint32_t recovery_master;
345         struct ctdb_client_ip *client_ip_list;
346         bool do_checkpublicip;
347         struct trbt_tree *server_ids; 
348         bool do_setsched;
349         const char *event_script_dir;
350         const char *notification_script;
351         const char *default_public_interface;
352         pid_t ctdbd_pid;
353         pid_t recoverd_pid;
354         enum ctdb_runstate runstate;
355         struct ctdb_monitor_state *monitor;
356         int start_as_disabled;
357         int start_as_stopped;
358         bool valgrinding;
359         uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
360         uint32_t *recd_ping_count;
361         TALLOC_CTX *recd_ctx; /* a context used to track recoverd monitoring events */
362         TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
363
364         TALLOC_CTX *event_script_ctx;
365         int active_events;
366
367         struct ctdb_event_script_state *current_monitor;
368         struct ctdb_script_list_old *last_status[CTDB_EVENT_MAX];
369
370         TALLOC_CTX *banning_ctx;
371
372         struct ctdb_vacuum_child_context *vacuumers;
373
374         /* mapping from pid to ctdb_client * */
375         struct ctdb_client_pid_list *client_pids;
376
377         /* used in the recovery daemon to remember the ip allocation */
378         struct trbt_tree *ip_tree;
379
380         /* Used to defer db attach requests while in recovery mode */
381         struct ctdb_deferred_attach_context *deferred_attach;
382
383         /* if we are a child process, do we have a domain socket to send controls on */
384         bool can_send_controls;
385
386         /* list of event script callback functions that are active */
387         struct event_script_callback *script_callbacks;
388
389         struct ctdb_reloadips_handle *reload_ips;
390
391         const char *nodes_file;
392         const char *public_addresses_file;
393         struct trbt_tree *child_processes; 
394
395         /* Used for locking record/db/alldb */
396         struct lock_context *lock_current;
397         struct lock_context *lock_pending;
398 };
399
400 struct ctdb_db_context {
401         struct ctdb_db_context *next, *prev;
402         struct ctdb_context *ctdb;
403         uint32_t db_id;
404         uint32_t priority;
405         bool persistent;
406         bool readonly; /* Do we support read-only delegations ? */
407         bool sticky; /* Do we support sticky records ? */
408         const char *db_name;
409         const char *db_path;
410         struct tdb_wrap *ltdb;
411         struct tdb_context *rottdb; /* ReadOnly tracking TDB */
412         struct ctdb_registered_call *calls; /* list of registered calls */
413         uint32_t seqnum;
414         struct tevent_timer *seqnum_update;
415         struct ctdb_traverse_local_handle *traverse;
416         struct ctdb_vacuum_handle *vacuum_handle;
417         char *unhealthy_reason;
418         int pending_requests;
419         struct revokechild_handle *revokechild_active;
420         struct ctdb_persistent_state *persistent_state;
421         struct trbt_tree *delete_queue;
422         struct trbt_tree *sticky_records; 
423         int (*ctdb_ltdb_store_fn)(struct ctdb_db_context *ctdb_db,
424                                   TDB_DATA key,
425                                   struct ctdb_ltdb_header *header,
426                                   TDB_DATA data);
427
428         /* used to track which records we are currently fetching
429            so we can avoid sending duplicate fetch requests
430         */
431         struct trbt_tree *deferred_fetch;
432         struct trbt_tree *defer_dmaster;
433
434         struct ctdb_db_statistics statistics;
435
436         struct lock_context *lock_current;
437         struct lock_context *lock_pending;
438         int lock_num_current;
439
440         struct ctdb_call_state *pending_calls;
441
442         enum ctdb_freeze_mode freeze_mode;
443         struct ctdb_db_freeze_handle *freeze_handle;
444         bool freeze_transaction_started;
445         uint32_t freeze_transaction_id;
446         uint32_t generation;
447 };
448
449
450 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
451           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
452           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
453           return -1; }} while (0)
454
455 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
456           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
457           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
458           return; }} while (0)
459
460 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
461           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
462           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
463           return NULL; }} while (0)
464
465 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
466           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
467           ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
468           }} while (0)
469
470
471 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
472
473 /*
474   state of a in-progress ctdb call
475 */
476 struct ctdb_call_state {
477         struct ctdb_call_state *next, *prev;
478         enum call_state state;
479         uint32_t reqid;
480         struct ctdb_req_call *c;
481         struct ctdb_db_context *ctdb_db;
482         const char *errmsg;
483         struct ctdb_call *call;
484         uint32_t generation;
485         struct {
486                 void (*fn)(struct ctdb_call_state *);
487                 void *private_data;
488         } async;
489 };
490
491 /* internal prototypes */
492
493 #define CHECK_CONTROL_DATA_SIZE(size) do { \
494  if (indata.dsize != size) { \
495          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
496                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
497          return -1; \
498  } \
499  } while (0)
500
501 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
502  if (indata.dsize < size) { \
503          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
504                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
505          return -1; \
506  } \
507  } while (0)
508
509 /*
510   state of a in-progress ctdb call in client
511 */
512 struct ctdb_client_call_state {
513         enum call_state state;
514         uint32_t reqid;
515         struct ctdb_db_context *ctdb_db;
516         struct ctdb_call *call;
517         struct {
518                 void (*fn)(struct ctdb_client_call_state *);
519                 void *private_data;
520         } async;
521 };
522
523 extern int script_log_level;
524 extern bool fast_start;
525 extern const char *ctdbd_pidfile;
526
527 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
528
529
530 /* from tcp/ and ib/ */
531
532 int ctdb_tcp_init(struct ctdb_context *ctdb);
533 int ctdb_ibw_init(struct ctdb_context *ctdb);
534
535 /* from ctdb_banning.c */
536
537 void ctdb_local_node_got_banned(struct ctdb_context *ctdb);
538 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
539 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
540 void ctdb_ban_self(struct ctdb_context *ctdb);
541
542 /* from ctdb_call.c */
543
544 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
545
546 void ctdb_request_dmaster(struct ctdb_context *ctdb,
547                           struct ctdb_req_header *hdr);
548 void ctdb_reply_dmaster(struct ctdb_context *ctdb,
549                         struct ctdb_req_header *hdr);
550 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
551 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
552 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
553
554 void ctdb_call_resend_db(struct ctdb_db_context *ctdb);
555 void ctdb_call_resend_all(struct ctdb_context *ctdb);
556
557 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
558                                              struct ctdb_call *call,
559                                              struct ctdb_ltdb_header *header,
560                                              TDB_DATA *data);
561
562 struct ctdb_call_state *ctdb_daemon_call_send_remote(
563                                         struct ctdb_db_context *ctdb_db,
564                                         struct ctdb_call *call,
565                                         struct ctdb_ltdb_header *header);
566 int ctdb_daemon_call_recv(struct ctdb_call_state *state,
567                           struct ctdb_call *call);
568
569 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
570
571 int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb,
572                                 struct ctdb_db_context *ctdb_db,
573                                 TDB_DATA key, struct ctdb_ltdb_header *header,
574                                 TDB_DATA data);
575
576 int ctdb_add_revoke_deferred_call(struct ctdb_context *ctdb,
577                                   struct ctdb_db_context *ctdb_db,
578                                   TDB_DATA key, struct ctdb_req_header *hdr,
579                                   deferred_requeue_fn fn, void *call_context);
580
581 /* from server/ctdb_control.c */
582
583 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
584
585 void ctdb_request_control_reply(struct ctdb_context *ctdb,
586                                 struct ctdb_req_control *c,
587                                 TDB_DATA *outdata, int32_t status,
588                                 const char *errormsg);
589
590 void ctdb_request_control(struct ctdb_context *ctdb,
591                           struct ctdb_req_header *hdr);
592 void ctdb_reply_control(struct ctdb_context *ctdb,
593                         struct ctdb_req_header *hdr);
594
595 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
596                              uint64_t srvid, uint32_t opcode,
597                              uint32_t client_id, uint32_t flags,
598                              TDB_DATA data,
599                              ctdb_control_callback_fn_t callback,
600                              void *private_data);
601
602 /* from server/ctdb_daemon.c */
603
604 int daemon_register_message_handler(struct ctdb_context *ctdb,
605                                     uint32_t client_id, uint64_t srvid);
606 int daemon_deregister_message_handler(struct ctdb_context *ctdb,
607                                       uint32_t client_id, uint64_t srvid);
608 int daemon_check_srvids(struct ctdb_context *ctdb, TDB_DATA indata,
609                         TDB_DATA *outdata);
610
611 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
612
613 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
614                                                  TALLOC_CTX *mem_ctx,
615                                                  enum ctdb_operation operation,
616                                                  size_t length, size_t slength,
617                                                  const char *type);
618
619 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
620         (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, \
621                                          sizeof(type), #type)
622
623 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb,
624                                  struct ctdb_node *node);
625
626 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
627                          ctdb_fn_t fn, int id);
628
629 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
630                              uint64_t srvid, TDB_DATA data);
631
632 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb,
633                                      uint32_t client_id, TDB_DATA indata);
634 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb,
635                                        uint32_t client_id, TDB_DATA indata);
636
637 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb,
638                                             pid_t pid);
639
640 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
641
642 int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode,
643                               TDB_DATA indata, TDB_DATA *outdata);
644
645 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code);
646
647 /* from server/ctdb_freeze.c */
648
649 int32_t ctdb_control_db_freeze(struct ctdb_context *ctdb,
650                                struct ctdb_req_control *c,
651                                uint32_t db_id, bool *async_reply);
652 int32_t ctdb_control_db_thaw(struct ctdb_context *ctdb, uint32_t db_id);
653
654 int32_t ctdb_control_freeze(struct ctdb_context *ctdb,
655                             struct ctdb_req_control *c, bool *async_reply);
656 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority,
657                           bool check_recmode);
658
659 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
660
661 int32_t ctdb_control_db_transaction_start(struct ctdb_context *ctdb,
662                                           TDB_DATA indata);
663 int32_t ctdb_control_db_transaction_cancel(struct ctdb_context *ctdb,
664                                            TDB_DATA indata);
665 int32_t ctdb_control_db_transaction_commit(struct ctdb_context *ctdb,
666                                            TDB_DATA indata);
667
668 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
669 int32_t ctdb_control_transaction_cancel(struct ctdb_context *ctdb);
670 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
671
672 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
673
674 bool ctdb_db_frozen(struct ctdb_db_context *ctdb_db);
675 bool ctdb_db_prio_frozen(struct ctdb_context *ctdb, uint32_t priority);
676 bool ctdb_db_all_frozen(struct ctdb_context *ctdb);
677
678 /* from server/ctdb_keepalive.c */
679
680 void ctdb_start_keepalive(struct ctdb_context *ctdb);
681 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
682
683 /* from server/ctdb_lock.c */
684
685 struct lock_request;
686
687 typedef int (*ctdb_db_handler_t)(struct ctdb_db_context *ctdb_db,
688                                  void *private_data);
689
690 int ctdb_db_prio_iterator(struct ctdb_context *ctdb, uint32_t priority,
691                           ctdb_db_handler_t handler, void *private_data);
692 int ctdb_db_iterator(struct ctdb_context *ctdb, ctdb_db_handler_t handler,
693                      void *private_data);
694
695 int ctdb_lockdb_mark(struct ctdb_db_context *ctdb_db);
696 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority);
697
698 int ctdb_lockdb_unmark(struct ctdb_db_context *ctdb_db);
699 int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority);
700
701 struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx,
702                                       struct ctdb_db_context *ctdb_db,
703                                       TDB_DATA key,
704                                       bool auto_mark,
705                                       void (*callback)(void *, bool),
706                                       void *private_data);
707
708 struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
709                                   struct ctdb_db_context *ctdb_db,
710                                   bool auto_mark,
711                                   void (*callback)(void *, bool),
712                                   void *private_data);
713
714 struct lock_request *ctdb_lock_alldb_prio(TALLOC_CTX *mem_ctx,
715                                           struct ctdb_context *ctdb,
716                                           uint32_t priority,
717                                           bool auto_mark,
718                                           void (*callback)(void *, bool),
719                                           void *private_data);
720
721 struct lock_request *ctdb_lock_alldb(TALLOC_CTX *mem_ctx,
722                                      struct ctdb_context *ctdb,
723                                      bool auto_mark,
724                                      void (*callback)(void *, bool),
725                                      void *private_data);
726
727 /* from ctdb_logging.c */
728
729 typedef int (*ctdb_log_setup_fn_t)(TALLOC_CTX *mem_ctx,
730                                    const char *logging,
731                                    const char *app_name);
732
733 void ctdb_log_register_backend(const char *prefix, ctdb_log_setup_fn_t init);
734
735 bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging);
736
737 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
738                                                struct ctdb_context *ctdb,
739                                                const char *log_prefix,
740                                                const char *helper,
741                                                int helper_argc,
742                                                const char **helper_argv,
743                                                void (*logfn)(const char *,
744                                                              uint16_t, void *),
745                                                void *logfn_private, pid_t *pid);
746
747 int ctdb_set_child_logging(struct ctdb_context *ctdb);
748 int ctdb_init_tevent_logging(struct ctdb_context *ctdb);
749
750 /* from ctdb_logging_file.c */
751
752 void ctdb_log_init_file(void);
753
754 /* from ctdb_logging_syslog.c */
755
756 void ctdb_log_init_syslog(void);
757
758 /* from ctdb_ltdb_server.c */
759
760 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
761                            TDB_DATA key, struct ctdb_req_header *hdr,
762                            void (*recv_pkt)(void *, struct ctdb_req_header *),
763                            void *recv_context, bool ignore_generation);
764
765 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
766                                  TDB_DATA key, struct ctdb_ltdb_header *header,
767                                  struct ctdb_req_header *hdr, TDB_DATA *data,
768                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
769                                  void *recv_context, bool ignore_generation);
770
771 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
772                                 struct ctdb_db_context *ctdb_db);
773 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
774                                   struct ctdb_db_context *ctdb_db,
775                                   const char *reason,/* NULL means healthy */
776                                   int num_healthy_nodes);
777 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
778
779 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb,
780                                     TDB_DATA indata);
781 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
782                                    TDB_DATA indata, TDB_DATA *outdata);
783
784 int ctdb_set_db_readonly(struct ctdb_context *ctdb,
785                          struct ctdb_db_context *ctdb_db);
786
787 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
788
789 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
790                                TDB_DATA *outdata, uint64_t tdb_flags,
791                                bool persistent, uint32_t client_id,
792                                struct ctdb_req_control *c,
793                                bool *async_reply);
794 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
795                                uint32_t client_id);
796
797 int ctdb_attach_databases(struct ctdb_context *ctdb);
798
799 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id,
800                                 uint32_t srcnode);
801 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
802
803 int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata,
804                                      uint32_t client_id);
805
806 int ctdb_set_db_sticky(struct ctdb_context *ctdb,
807                        struct ctdb_db_context *ctdb_db);
808
809 void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db);
810
811 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
812                                        uint32_t db_id, TDB_DATA *outdata);
813
814 /* from ctdb_monitor.c */
815
816 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
817 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
818
819 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
820 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
821 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
822
823 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
824
825 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
826
827 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
828 bool ctdb_stopped_monitoring(struct ctdb_context *ctdb);
829
830 /* from ctdb_persistent.c */
831
832 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
833
834 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
835                                    struct ctdb_req_control *c,
836                                    TDB_DATA recdata, bool *async_reply);
837
838 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
839                                              struct ctdb_req_control *c,
840                                              TDB_DATA recdata);
841 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
842                                               struct ctdb_req_control *c,
843                                               TDB_DATA recdata);
844
845 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
846                                    TDB_DATA indata, TDB_DATA *outdata);
847
848 /* from ctdb_recover.c */
849
850 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
851                            TDB_DATA indata, TDB_DATA *outdata);
852 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
853                            TDB_DATA indata, TDB_DATA *outdata);
854
855 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode,
856                           TDB_DATA indata, TDB_DATA *outdata);
857 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode,
858                             TDB_DATA indata, TDB_DATA *outdata);
859
860 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
861
862 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata,
863                              TDB_DATA *outdata);
864 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
865
866 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
867
868 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
869                                  struct ctdb_req_control *c,
870                                  TDB_DATA indata, bool *async_reply,
871                                  const char **errormsg);
872
873 bool ctdb_recovery_have_lock(struct ctdb_context *ctdb);
874 bool ctdb_recovery_lock(struct ctdb_context *ctdb);
875 void ctdb_recovery_unlock(struct ctdb_context *ctdb);
876
877 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
878                                  struct ctdb_req_control *c,
879                                  bool *async_reply);
880 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
881                                  struct ctdb_req_control *c,
882                                  bool *async_reply);
883
884 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb,
885                                         TDB_DATA indata, TDB_DATA *outdata);
886 int32_t ctdb_control_receive_records(struct ctdb_context *ctdb,
887                                      TDB_DATA indata, TDB_DATA *outdata);
888
889 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb,
890                                       TDB_DATA *outdata);
891
892 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
893 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb,
894                                    uint32_t opcode, TDB_DATA indata);
895
896 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
897 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
898
899 /* from ctdb_recoverd.c */
900
901 int ctdb_start_recoverd(struct ctdb_context *ctdb);
902 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
903
904 /* from ctdb_server.c */
905
906 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
907
908 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const ctdb_sock_addr *nodeip);
909
910 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
911
912 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
913
914 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
915
916 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
917
918 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
919
920 void ctdb_node_dead(struct ctdb_node *node);
921 void ctdb_node_connected(struct ctdb_node *node);
922
923 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
924 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb,
925                               struct ctdb_req_header *hdr, unsigned opcode);
926
927 /* from ctdb_serverids.c */
928
929 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
930                                         uint32_t client_id, TDB_DATA indata);
931 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
932                                      TDB_DATA indata);
933 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
934                                           TDB_DATA indata);
935 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
936                                         TDB_DATA *outdata);
937
938 /* from ctdb_statistics.c */
939
940 int ctdb_statistics_init(struct ctdb_context *ctdb);
941
942 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
943                                       struct ctdb_req_control *c,
944                                       TDB_DATA *outdata);
945
946 /* from ctdb_takeover.c */
947
948 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
949                                  struct ctdb_req_control *c,
950                                  TDB_DATA indata,
951                                  bool *async_reply);
952 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
953                                  struct ctdb_req_control *c,
954                                  TDB_DATA indata,
955                                  bool *async_reply);
956 int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
957                                  struct ctdb_req_control *c,
958                                  bool *async_reply);
959
960 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
961 int ctdb_set_single_public_ip(struct ctdb_context *ctdb, const char *iface,
962                               const char *ip);
963
964 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap,
965                       uint32_t *force_rebalance_nodes,
966                       client_async_callback fail_callback, void *callback_data);
967
968 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
969                                 TDB_DATA indata);
970 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata,
971                              bool tcp_update_needed);
972 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
973 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
974
975 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
976
977 void ctdb_release_all_ips(struct ctdb_context *ctdb);
978
979 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb,
980                                     struct ctdb_req_control *c,
981                                     TDB_DATA *outdata);
982 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
983                                         struct ctdb_req_control *c,
984                                         TDB_DATA indata, TDB_DATA *outdata);
985
986 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
987                                 struct ctdb_req_control *c,
988                                 TDB_DATA *outdata);
989 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
990                                     struct ctdb_req_control *c,
991                                     TDB_DATA indata);
992
993 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
994 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb,
995                                          TDB_DATA indata);
996 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb,
997                                          TDB_DATA indata, TDB_DATA *outdata);
998
999 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1000
1001 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb,
1002                                        TDB_DATA indata);
1003
1004 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb,
1005                                         TDB_DATA indata);
1006 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
1007                                         struct ctdb_req_control *c,
1008                                         TDB_DATA recdata, bool *async_reply);
1009
1010 int verify_remote_ip_allocation(struct ctdb_context *ctdb,
1011                                 struct ctdb_all_public_ips *ips,
1012                                 uint32_t pnn);
1013 int update_ip_assignment_tree(struct ctdb_context *ctdb,
1014                                 struct ctdb_public_ip *ip);
1015 void clear_ip_assignment_tree(struct ctdb_context *ctdb);
1016
1017 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb,
1018                                        struct ctdb_req_control *c,
1019                                        bool *async_reply);
1020
1021 /* from ctdb_traverse.c */
1022
1023 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb,
1024                                       TDB_DATA data, TDB_DATA *outdata);
1025 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb,
1026                                   TDB_DATA data, TDB_DATA *outdata);
1027 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb,
1028                                    TDB_DATA data, TDB_DATA *outdata);
1029 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
1030                                     TDB_DATA *outdata, uint32_t srcnode);
1031
1032 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
1033                                         TDB_DATA indata, TDB_DATA *outdata,
1034                                         uint32_t srcnode, uint32_t client_id);
1035 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb,
1036                                     TDB_DATA indata, TDB_DATA *outdata,
1037                                     uint32_t srcnode, uint32_t client_id);
1038
1039 /* from ctdb_tunables.c */
1040
1041 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1042
1043 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1044                                  TDB_DATA *outdata);
1045 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1046 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb,
1047                                    TDB_DATA *outdata);
1048
1049 /* from ctdb_update_record.c */
1050
1051 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1052                                    struct ctdb_req_control *c,
1053                                    TDB_DATA recdata, bool *async_reply);
1054
1055 /* from ctdb_uptime.c */
1056
1057 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, TDB_DATA *outdata);
1058
1059 /* from ctdb_vacuum.c */
1060
1061 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
1062 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1063
1064 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
1065                                            TDB_DATA indata);
1066 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
1067                                          const struct ctdb_ltdb_header *hdr,
1068                                          TDB_DATA key);
1069
1070 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
1071                                          const struct ctdb_ltdb_header *hdr,
1072                                          const TDB_DATA key);
1073
1074 /* from eventscript.c */
1075
1076 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1077                                              uint32_t call_type,
1078                                              TDB_DATA *outdata);
1079
1080 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1081                                TALLOC_CTX *mem_ctx,
1082                                void (*callback)(struct ctdb_context *,
1083                                                 int, void *),
1084                                void *private_data,
1085                                enum ctdb_event call,
1086                                const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1087
1088 int ctdb_event_script_args(struct ctdb_context *ctdb,
1089                            enum ctdb_event call,
1090                            const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1091
1092 int ctdb_event_script(struct ctdb_context *ctdb,
1093                       enum ctdb_event call);
1094
1095 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
1096                               struct ctdb_req_control *c,
1097                               TDB_DATA data, bool *async_reply);
1098
1099 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1100 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1101
1102 #endif