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