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