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