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