ctdb-daemon: Remove setting of debug_extra via ctdb_set_child_info()
[samba.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_track_child(struct ctdb_context *ctdb, pid_t pid);
608
609 pid_t ctdb_fork(struct ctdb_context *ctdb);
610
611 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
612
613 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
614
615 /* from server/ctdb_freeze.c */
616
617 int32_t ctdb_control_db_freeze(struct ctdb_context *ctdb,
618                                struct ctdb_req_control_old *c,
619                                uint32_t db_id, bool *async_reply);
620 int32_t ctdb_control_db_thaw(struct ctdb_context *ctdb, uint32_t db_id);
621
622 int32_t ctdb_control_freeze(struct ctdb_context *ctdb,
623                             struct ctdb_req_control_old *c, bool *async_reply);
624 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, bool check_recmode);
625
626 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
627
628 int32_t ctdb_control_db_transaction_start(struct ctdb_context *ctdb,
629                                           TDB_DATA indata);
630 int32_t ctdb_control_db_transaction_cancel(struct ctdb_context *ctdb,
631                                            TDB_DATA indata);
632 int32_t ctdb_control_db_transaction_commit(struct ctdb_context *ctdb,
633                                            TDB_DATA indata);
634
635 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
636
637 bool ctdb_db_frozen(struct ctdb_db_context *ctdb_db);
638 bool ctdb_db_all_frozen(struct ctdb_context *ctdb);
639
640 /* from server/ctdb_keepalive.c */
641
642 void ctdb_start_keepalive(struct ctdb_context *ctdb);
643 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
644
645 /* from server/ctdb_lock.c */
646
647 struct lock_request;
648
649 typedef int (*ctdb_db_handler_t)(struct ctdb_db_context *ctdb_db,
650                                  void *private_data);
651
652 int ctdb_db_iterator(struct ctdb_context *ctdb, ctdb_db_handler_t handler,
653                      void *private_data);
654
655 int ctdb_lockdb_mark(struct ctdb_db_context *ctdb_db);
656
657 int ctdb_lockdb_unmark(struct ctdb_db_context *ctdb_db);
658
659 struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx,
660                                       struct ctdb_db_context *ctdb_db,
661                                       TDB_DATA key,
662                                       bool auto_mark,
663                                       void (*callback)(void *, bool),
664                                       void *private_data);
665
666 struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
667                                   struct ctdb_db_context *ctdb_db,
668                                   bool auto_mark,
669                                   void (*callback)(void *, bool),
670                                   void *private_data);
671
672 /* from ctdb_logging.c */
673
674 extern const char *debug_extra;
675
676 bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
677                        const char *debug_level);
678
679 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
680                                                struct ctdb_context *ctdb,
681                                                const char *log_prefix,
682                                                const char *helper,
683                                                int helper_argc,
684                                                const char **helper_argv,
685                                                void (*logfn)(const char *,
686                                                              uint16_t, void *),
687                                                void *logfn_private, pid_t *pid);
688
689 int ctdb_set_child_logging(struct ctdb_context *ctdb);
690
691 /* from ctdb_logging_file.c */
692
693 void ctdb_log_init_file(void);
694
695 /* from ctdb_logging_syslog.c */
696
697 void ctdb_log_init_syslog(void);
698
699 /* from ctdb_ltdb_server.c */
700
701 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
702                            TDB_DATA key, struct ctdb_req_header *hdr,
703                            void (*recv_pkt)(void *, struct ctdb_req_header *),
704                            void *recv_context, bool ignore_generation);
705
706 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
707                                  TDB_DATA key, struct ctdb_ltdb_header *header,
708                                  struct ctdb_req_header *hdr, TDB_DATA *data,
709                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
710                                  void *recv_context, bool ignore_generation);
711
712 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
713                                 struct ctdb_db_context *ctdb_db);
714 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
715                                   struct ctdb_db_context *ctdb_db,
716                                   const char *reason,/* NULL means healthy */
717                                   int num_healthy_nodes);
718 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
719
720 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb,
721                                     TDB_DATA indata);
722 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
723                                    TDB_DATA indata, TDB_DATA *outdata);
724
725 int ctdb_set_db_readonly(struct ctdb_context *ctdb,
726                          struct ctdb_db_context *ctdb_db);
727
728 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
729
730 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
731                                TDB_DATA *outdata, uint64_t tdb_flags,
732                                bool persistent, uint32_t client_id,
733                                struct ctdb_req_control_old *c,
734                                bool *async_reply);
735 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
736                                uint32_t client_id);
737
738 int ctdb_attach_databases(struct ctdb_context *ctdb);
739
740 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id,
741                                 uint32_t srcnode);
742 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
743
744 int ctdb_set_db_sticky(struct ctdb_context *ctdb,
745                        struct ctdb_db_context *ctdb_db);
746
747 void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db);
748
749 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
750                                        uint32_t db_id, TDB_DATA *outdata);
751
752 /* from ctdb_monitor.c */
753
754 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
755 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
756
757 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
758 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
759 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
760
761 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
762
763 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
764
765 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
766 bool ctdb_stopped_monitoring(struct ctdb_context *ctdb);
767
768 /* from ctdb_persistent.c */
769
770 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
771
772 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
773                                    struct ctdb_req_control_old *c,
774                                    TDB_DATA recdata, bool *async_reply);
775
776 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
777                                              struct ctdb_req_control_old *c,
778                                              TDB_DATA recdata);
779 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
780                                               struct ctdb_req_control_old *c,
781                                               TDB_DATA recdata);
782
783 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
784                                    TDB_DATA indata, TDB_DATA *outdata);
785
786 /* from ctdb_recover.c */
787
788 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
789                            TDB_DATA indata, TDB_DATA *outdata);
790 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
791                            TDB_DATA indata, TDB_DATA *outdata);
792
793 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode,
794                           TDB_DATA indata, TDB_DATA *outdata);
795 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode,
796                             TDB_DATA indata, TDB_DATA *outdata);
797
798 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
799
800 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata,
801                              TDB_DATA *outdata);
802 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
803
804 int32_t ctdb_control_db_pull(struct ctdb_context *ctdb,
805                              struct ctdb_req_control_old *c,
806                              TDB_DATA indata, TDB_DATA *outdata);
807 int32_t ctdb_control_db_push_start(struct ctdb_context *ctdb,
808                                    TDB_DATA indata);
809 int32_t ctdb_control_db_push_confirm(struct ctdb_context *ctdb,
810                                      TDB_DATA indata, TDB_DATA *outdata);
811
812 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
813
814 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
815                                  struct ctdb_req_control_old *c,
816                                  TDB_DATA indata, bool *async_reply,
817                                  const char **errormsg);
818
819 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
820                                  struct ctdb_req_control_old *c,
821                                  bool *async_reply);
822 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
823                                  struct ctdb_req_control_old *c,
824                                  bool *async_reply);
825
826 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb,
827                                         TDB_DATA indata, TDB_DATA *outdata);
828 int32_t ctdb_control_receive_records(struct ctdb_context *ctdb,
829                                      TDB_DATA indata, TDB_DATA *outdata);
830
831 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb,
832                                       TDB_DATA *outdata);
833
834 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
835 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb,
836                                    uint32_t opcode, TDB_DATA indata);
837
838 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
839 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
840
841 /* from ctdb_recoverd.c */
842
843 int ctdb_start_recoverd(struct ctdb_context *ctdb);
844 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
845
846 /* from ctdb_server.c */
847
848 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
849
850 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const ctdb_sock_addr *nodeip);
851
852 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
853
854 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
855
856 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
857
858 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
859
860 void ctdb_node_dead(struct ctdb_node *node);
861 void ctdb_node_connected(struct ctdb_node *node);
862
863 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
864 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb,
865                               struct ctdb_req_header *hdr, unsigned opcode);
866
867 /* from ctdb_serverids.c */
868
869 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
870                                         uint32_t client_id, TDB_DATA indata);
871 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
872                                      TDB_DATA indata);
873 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
874                                           TDB_DATA indata);
875 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
876                                         TDB_DATA *outdata);
877
878 /* from ctdb_statistics.c */
879
880 int ctdb_statistics_init(struct ctdb_context *ctdb);
881
882 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
883                                       struct ctdb_req_control_old *c,
884                                       TDB_DATA *outdata);
885
886 /* from ctdb_takeover.c */
887
888 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
889                                  struct ctdb_req_control_old *c,
890                                  TDB_DATA indata,
891                                  bool *async_reply);
892 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
893                                  struct ctdb_req_control_old *c,
894                                  TDB_DATA indata,
895                                  bool *async_reply);
896 int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
897                                  struct ctdb_req_control_old *c,
898                                  bool *async_reply);
899
900 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
901
902 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodemap,
903                       uint32_t *force_rebalance_nodes);
904
905 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
906                                 TDB_DATA indata);
907 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata,
908                              bool tcp_update_needed);
909 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
910 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
911
912 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
913
914 void ctdb_release_all_ips(struct ctdb_context *ctdb);
915
916 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb,
917                                     struct ctdb_req_control_old *c,
918                                     TDB_DATA *outdata);
919 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
920                                         struct ctdb_req_control_old *c,
921                                         TDB_DATA indata, TDB_DATA *outdata);
922
923 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
924                                 struct ctdb_req_control_old *c,
925                                 TDB_DATA *outdata);
926 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
927                                     struct ctdb_req_control_old *c,
928                                     TDB_DATA indata);
929
930 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb,
931                                          TDB_DATA indata);
932 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb,
933                                          TDB_DATA indata, TDB_DATA *outdata);
934
935 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
936
937 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb,
938                                        TDB_DATA indata);
939
940 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb,
941                                         TDB_DATA indata);
942 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
943                                         TDB_DATA recdata);
944
945 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb,
946                                        struct ctdb_req_control_old *c,
947                                        bool *async_reply);
948
949 /* from ctdb_traverse.c */
950
951 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb,
952                                       TDB_DATA data, TDB_DATA *outdata);
953 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb,
954                                   TDB_DATA data, TDB_DATA *outdata);
955 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb,
956                                    TDB_DATA data, TDB_DATA *outdata);
957 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
958                                     TDB_DATA *outdata, uint32_t srcnode);
959
960 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
961                                         TDB_DATA indata, TDB_DATA *outdata,
962                                         uint32_t srcnode, uint32_t client_id);
963 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb,
964                                     TDB_DATA indata, TDB_DATA *outdata,
965                                     uint32_t srcnode, uint32_t client_id);
966
967 /* from ctdb_tunables.c */
968
969 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
970
971 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
972                                  TDB_DATA *outdata);
973 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
974 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb,
975                                    TDB_DATA *outdata);
976
977 /* from ctdb_update_record.c */
978
979 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
980                                    struct ctdb_req_control_old *c,
981                                    TDB_DATA recdata, bool *async_reply);
982
983 /* from ctdb_uptime.c */
984
985 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, TDB_DATA *outdata);
986
987 /* from ctdb_vacuum.c */
988
989 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
990 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
991
992 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
993                                            TDB_DATA indata);
994 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
995                                          const struct ctdb_ltdb_header *hdr,
996                                          TDB_DATA key);
997
998 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
999                                          const struct ctdb_ltdb_header *hdr,
1000                                          const TDB_DATA key);
1001
1002 /* from eventscript.c */
1003
1004 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1005                                              uint32_t call_type,
1006                                              TDB_DATA *outdata);
1007
1008 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1009                                TALLOC_CTX *mem_ctx,
1010                                void (*callback)(struct ctdb_context *,
1011                                                 int, void *),
1012                                void *private_data,
1013                                enum ctdb_event call,
1014                                const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1015
1016 int ctdb_event_script_args(struct ctdb_context *ctdb,
1017                            enum ctdb_event call,
1018                            const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1019
1020 int ctdb_event_script(struct ctdb_context *ctdb,
1021                       enum ctdb_event call);
1022
1023 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
1024                               struct ctdb_req_control_old *c,
1025                               TDB_DATA data, bool *async_reply);
1026
1027 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1028 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1029
1030 #endif