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