ctdb-daemon: Add implementation of control CHECK_PID_SRVID
[metze/samba/wip.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 ctdb_daemon_data daemon;
293         struct ctdb_statistics statistics;
294         struct ctdb_statistics statistics_current;
295 #define MAX_STAT_HISTORY 100
296         struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
297         struct ctdb_vnn_map *vnn_map;
298         uint32_t num_clients;
299         uint32_t recovery_master;
300         struct ctdb_client_ip *client_ip_list;
301         bool do_checkpublicip;
302         bool do_setsched;
303         const char *event_script_dir;
304         const char *notification_script;
305         const char *default_public_interface;
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 push_started;
390         void *push_state;
391
392         struct hash_count_context *migratedb;
393 };
394
395
396 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
397           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
398           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
399           return -1; }} while (0)
400
401 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
402           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
403           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
404           return; }} while (0)
405
406 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
407           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
408           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
409           return NULL; }} while (0)
410
411 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
412           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
413           ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
414           }} while (0)
415
416
417 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
418
419 /*
420   state of a in-progress ctdb call
421 */
422 struct ctdb_call_state {
423         struct ctdb_call_state *next, *prev;
424         enum call_state state;
425         uint32_t reqid;
426         struct ctdb_req_call_old *c;
427         struct ctdb_db_context *ctdb_db;
428         const char *errmsg;
429         struct ctdb_call *call;
430         uint32_t generation;
431         struct {
432                 void (*fn)(struct ctdb_call_state *);
433                 void *private_data;
434         } async;
435 };
436
437 /* internal prototypes */
438
439 #define CHECK_CONTROL_DATA_SIZE(size) do { \
440  if (indata.dsize != size) { \
441          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
442                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
443          return -1; \
444  } \
445  } while (0)
446
447 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
448  if (indata.dsize < size) { \
449          DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
450                   opcode, (unsigned)indata.dsize, (unsigned)size));     \
451          return -1; \
452  } \
453  } while (0)
454
455 /*
456   state of a in-progress ctdb call in client
457 */
458 struct ctdb_client_call_state {
459         enum call_state state;
460         uint32_t reqid;
461         struct ctdb_db_context *ctdb_db;
462         struct ctdb_call *call;
463         struct {
464                 void (*fn)(struct ctdb_client_call_state *);
465                 void *private_data;
466         } async;
467 };
468
469 extern int script_log_level;
470 extern bool fast_start;
471 extern const char *ctdbd_pidfile;
472
473 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
474
475
476 /* from tcp/ and ib/ */
477
478 int ctdb_tcp_init(struct ctdb_context *ctdb);
479 int ctdb_ibw_init(struct ctdb_context *ctdb);
480
481 /* from ctdb_banning.c */
482
483 void ctdb_local_node_got_banned(struct ctdb_context *ctdb);
484 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
485 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
486 void ctdb_ban_self(struct ctdb_context *ctdb);
487
488 /* from ctdb_call.c */
489
490 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
491
492 void ctdb_request_dmaster(struct ctdb_context *ctdb,
493                           struct ctdb_req_header *hdr);
494 void ctdb_reply_dmaster(struct ctdb_context *ctdb,
495                         struct ctdb_req_header *hdr);
496 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
497 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
498 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
499
500 void ctdb_call_resend_db(struct ctdb_db_context *ctdb);
501 void ctdb_call_resend_all(struct ctdb_context *ctdb);
502
503 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
504                                              struct ctdb_call *call,
505                                              struct ctdb_ltdb_header *header,
506                                              TDB_DATA *data);
507
508 struct ctdb_call_state *ctdb_daemon_call_send_remote(
509                                         struct ctdb_db_context *ctdb_db,
510                                         struct ctdb_call *call,
511                                         struct ctdb_ltdb_header *header);
512 int ctdb_daemon_call_recv(struct ctdb_call_state *state,
513                           struct ctdb_call *call);
514
515 int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb,
516                                 struct ctdb_db_context *ctdb_db,
517                                 TDB_DATA key, struct ctdb_ltdb_header *header,
518                                 TDB_DATA data);
519
520 int ctdb_add_revoke_deferred_call(struct ctdb_context *ctdb,
521                                   struct ctdb_db_context *ctdb_db,
522                                   TDB_DATA key, struct ctdb_req_header *hdr,
523                                   deferred_requeue_fn fn, void *call_context);
524
525 int ctdb_migration_init(struct ctdb_db_context *ctdb_db);
526
527 /* from server/ctdb_control.c */
528
529 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
530
531 void ctdb_request_control_reply(struct ctdb_context *ctdb,
532                                 struct ctdb_req_control_old *c,
533                                 TDB_DATA *outdata, int32_t status,
534                                 const char *errormsg);
535
536 void ctdb_request_control(struct ctdb_context *ctdb,
537                           struct ctdb_req_header *hdr);
538 void ctdb_reply_control(struct ctdb_context *ctdb,
539                         struct ctdb_req_header *hdr);
540
541 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
542                              uint64_t srvid, uint32_t opcode,
543                              uint32_t client_id, uint32_t flags,
544                              TDB_DATA data,
545                              ctdb_control_callback_fn_t callback,
546                              void *private_data);
547
548 /* from server/ctdb_daemon.c */
549
550 int daemon_register_message_handler(struct ctdb_context *ctdb,
551                                     uint32_t client_id, uint64_t srvid);
552 int daemon_deregister_message_handler(struct ctdb_context *ctdb,
553                                       uint32_t client_id, uint64_t srvid);
554
555 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
556
557 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
558                                                  TALLOC_CTX *mem_ctx,
559                                                  enum ctdb_operation operation,
560                                                  size_t length, size_t slength,
561                                                  const char *type);
562
563 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
564         (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, \
565                                          sizeof(type), #type)
566
567 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb,
568                                  struct ctdb_node *node);
569
570 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
571                          ctdb_fn_t fn, int id);
572
573 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
574                              uint64_t srvid, TDB_DATA data);
575
576 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb,
577                                      uint32_t client_id, TDB_DATA indata);
578 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb,
579                                        uint32_t client_id, TDB_DATA indata);
580
581 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb,
582                                             pid_t pid);
583
584 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
585 int32_t ctdb_control_check_pid_srvid(struct ctdb_context *ctdb,
586                                      TDB_DATA indata);
587
588 int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode,
589                               TDB_DATA indata, TDB_DATA *outdata);
590
591 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code);
592
593 int switch_from_server_to_client(struct ctdb_context *ctdb);
594
595 /* From server/ctdb_fork.c */
596
597 void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid);
598
599 pid_t ctdb_fork(struct ctdb_context *ctdb);
600 pid_t ctdb_vfork_exec(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
601                       const char *helper, int helper_argc,
602                       const char **helper_argv);
603
604 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
605
606 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
607
608 /* from server/ctdb_freeze.c */
609
610 int32_t ctdb_control_db_freeze(struct ctdb_context *ctdb,
611                                struct ctdb_req_control_old *c,
612                                uint32_t db_id, bool *async_reply);
613 int32_t ctdb_control_db_thaw(struct ctdb_context *ctdb, uint32_t db_id);
614
615 int32_t ctdb_control_freeze(struct ctdb_context *ctdb,
616                             struct ctdb_req_control_old *c, bool *async_reply);
617 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, bool check_recmode);
618
619 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
620
621 int32_t ctdb_control_db_transaction_start(struct ctdb_context *ctdb,
622                                           TDB_DATA indata);
623 int32_t ctdb_control_db_transaction_cancel(struct ctdb_context *ctdb,
624                                            TDB_DATA indata);
625 int32_t ctdb_control_db_transaction_commit(struct ctdb_context *ctdb,
626                                            TDB_DATA indata);
627
628 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
629
630 bool ctdb_db_frozen(struct ctdb_db_context *ctdb_db);
631 bool ctdb_db_all_frozen(struct ctdb_context *ctdb);
632 bool ctdb_db_allow_access(struct ctdb_db_context *ctdb_db);
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 void ctdb_request_keepalive(struct ctdb_context *ctdb,
640                             struct ctdb_req_header *hdr);
641
642 /* from server/ctdb_lock.c */
643
644 struct lock_request;
645
646 typedef int (*ctdb_db_handler_t)(struct ctdb_db_context *ctdb_db,
647                                  void *private_data);
648
649 int ctdb_db_iterator(struct ctdb_context *ctdb, ctdb_db_handler_t handler,
650                      void *private_data);
651
652 int ctdb_lockdb_mark(struct ctdb_db_context *ctdb_db);
653
654 int ctdb_lockdb_unmark(struct ctdb_db_context *ctdb_db);
655
656 struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx,
657                                       struct ctdb_db_context *ctdb_db,
658                                       TDB_DATA key,
659                                       bool auto_mark,
660                                       void (*callback)(void *, bool),
661                                       void *private_data);
662
663 struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
664                                   struct ctdb_db_context *ctdb_db,
665                                   bool auto_mark,
666                                   void (*callback)(void *, bool),
667                                   void *private_data);
668
669 /* from ctdb_logging.c */
670
671 bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
672                        const char *debug_level);
673
674 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
675                                                struct ctdb_context *ctdb,
676                                                const char *log_prefix,
677                                                const char *helper,
678                                                int helper_argc,
679                                                const char **helper_argv,
680                                                void (*logfn)(const char *,
681                                                              uint16_t, void *),
682                                                void *logfn_private, pid_t *pid);
683
684 int ctdb_set_child_logging(struct ctdb_context *ctdb);
685
686 /* from ctdb_logging_file.c */
687
688 void ctdb_log_init_file(void);
689
690 /* from ctdb_logging_syslog.c */
691
692 void ctdb_log_init_syslog(void);
693
694 /* from ctdb_ltdb_server.c */
695
696 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
697                            TDB_DATA key, struct ctdb_req_header *hdr,
698                            void (*recv_pkt)(void *, struct ctdb_req_header *),
699                            void *recv_context, bool ignore_generation);
700
701 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
702                                  TDB_DATA key, struct ctdb_ltdb_header *header,
703                                  struct ctdb_req_header *hdr, TDB_DATA *data,
704                                  void (*recv_pkt)(void *, struct ctdb_req_header *),
705                                  void *recv_context, bool ignore_generation);
706
707 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
708                                 struct ctdb_db_context *ctdb_db);
709 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
710                                   struct ctdb_db_context *ctdb_db,
711                                   const char *reason,/* NULL means healthy */
712                                   int num_healthy_nodes);
713 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
714
715 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb,
716                                     TDB_DATA indata);
717 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
718                                    TDB_DATA indata, TDB_DATA *outdata);
719
720 int ctdb_set_db_readonly(struct ctdb_context *ctdb,
721                          struct ctdb_db_context *ctdb_db);
722
723 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
724
725 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
726                                TDB_DATA *outdata,
727                                uint8_t db_flags, uint32_t client_id,
728                                struct ctdb_req_control_old *c,
729                                bool *async_reply);
730 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
731                                uint32_t client_id);
732
733 int ctdb_attach_databases(struct ctdb_context *ctdb);
734
735 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id,
736                                 uint32_t srcnode);
737 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
738
739 int ctdb_set_db_sticky(struct ctdb_context *ctdb,
740                        struct ctdb_db_context *ctdb_db);
741
742 void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db);
743
744 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
745                                        uint32_t db_id, TDB_DATA *outdata);
746
747 /* from ctdb_monitor.c */
748
749 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
750 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
751
752 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
753
754 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
755
756 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
757
758 /* from ctdb_persistent.c */
759
760 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
761
762 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
763                                    struct ctdb_req_control_old *c,
764                                    TDB_DATA recdata, bool *async_reply);
765
766 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
767                                              struct ctdb_req_control_old *c,
768                                              TDB_DATA recdata);
769 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
770                                               struct ctdb_req_control_old *c,
771                                               TDB_DATA recdata);
772
773 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
774                                    TDB_DATA indata, TDB_DATA *outdata);
775
776 /* from ctdb_recover.c */
777
778 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
779                            TDB_DATA indata, TDB_DATA *outdata);
780 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
781                            TDB_DATA indata, TDB_DATA *outdata);
782
783 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode,
784                           TDB_DATA indata, TDB_DATA *outdata);
785 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode,
786                             TDB_DATA indata, TDB_DATA *outdata);
787
788 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
789
790 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata,
791                              TDB_DATA *outdata);
792 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
793
794 int32_t ctdb_control_db_pull(struct ctdb_context *ctdb,
795                              struct ctdb_req_control_old *c,
796                              TDB_DATA indata, TDB_DATA *outdata);
797 int32_t ctdb_control_db_push_start(struct ctdb_context *ctdb,
798                                    TDB_DATA indata);
799 int32_t ctdb_control_db_push_confirm(struct ctdb_context *ctdb,
800                                      TDB_DATA indata, TDB_DATA *outdata);
801
802 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
803
804 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
805                                  struct ctdb_req_control_old *c,
806                                  TDB_DATA indata, bool *async_reply,
807                                  const char **errormsg);
808
809 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
810                                  struct ctdb_req_control_old *c,
811                                  bool *async_reply);
812 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
813                                  struct ctdb_req_control_old *c,
814                                  bool *async_reply);
815
816 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb,
817                                         TDB_DATA indata, TDB_DATA *outdata);
818 int32_t ctdb_control_receive_records(struct ctdb_context *ctdb,
819                                      TDB_DATA indata, TDB_DATA *outdata);
820
821 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb,
822                                       TDB_DATA *outdata);
823
824 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
825 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb,
826                                    uint32_t opcode, TDB_DATA indata);
827
828 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
829 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
830
831 /* from ctdb_recoverd.c */
832
833 int ctdb_start_recoverd(struct ctdb_context *ctdb);
834 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
835
836 /* from ctdb_server.c */
837
838 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
839
840 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const ctdb_sock_addr *nodeip);
841
842 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
843
844 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
845
846 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
847
848 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
849
850 void ctdb_node_dead(struct ctdb_node *node);
851 void ctdb_node_connected(struct ctdb_node *node);
852
853 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
854 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb,
855                               struct ctdb_req_header *hdr, unsigned opcode);
856
857 /* from ctdb_serverids.c */
858
859 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
860                                         uint32_t client_id, TDB_DATA indata);
861 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
862                                      TDB_DATA indata);
863 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
864                                           TDB_DATA indata);
865 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
866                                         TDB_DATA *outdata);
867
868 /* from ctdb_statistics.c */
869
870 int ctdb_statistics_init(struct ctdb_context *ctdb);
871
872 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
873                                       struct ctdb_req_control_old *c,
874                                       TDB_DATA *outdata);
875
876 /* from ctdb_takeover.c */
877
878 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
879                                  struct ctdb_req_control_old *c,
880                                  TDB_DATA indata,
881                                  bool *async_reply);
882 int32_t ctdb_control_release_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_ipreallocated(struct ctdb_context *ctdb,
887                                  struct ctdb_req_control_old *c,
888                                  bool *async_reply);
889
890 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
891
892 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
893                                 TDB_DATA indata);
894 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata,
895                              bool tcp_update_needed);
896 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
897 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
898
899 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
900
901 void ctdb_release_all_ips(struct ctdb_context *ctdb);
902
903 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb,
904                                     struct ctdb_req_control_old *c,
905                                     TDB_DATA *outdata);
906 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
907                                         struct ctdb_req_control_old *c,
908                                         TDB_DATA indata, TDB_DATA *outdata);
909
910 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
911                                 struct ctdb_req_control_old *c,
912                                 TDB_DATA *outdata);
913 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
914                                     struct ctdb_req_control_old *c,
915                                     TDB_DATA indata);
916
917 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb,
918                                          TDB_DATA indata);
919 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb,
920                                          TDB_DATA indata, TDB_DATA *outdata);
921
922 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
923
924 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb,
925                                        TDB_DATA indata);
926
927 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb,
928                                         TDB_DATA indata);
929 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
930                                         TDB_DATA recdata);
931
932 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb,
933                                        struct ctdb_req_control_old *c,
934                                        bool *async_reply);
935
936 /* from ctdb_traverse.c */
937
938 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb,
939                                       TDB_DATA data, TDB_DATA *outdata);
940 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb,
941                                   TDB_DATA data, TDB_DATA *outdata);
942 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb,
943                                    TDB_DATA data, TDB_DATA *outdata);
944 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
945                                     TDB_DATA *outdata, uint32_t srcnode);
946
947 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
948                                         TDB_DATA indata, TDB_DATA *outdata,
949                                         uint32_t srcnode, uint32_t client_id);
950 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb,
951                                     TDB_DATA indata, TDB_DATA *outdata,
952                                     uint32_t srcnode, uint32_t client_id);
953
954 /* from ctdb_tunables.c */
955
956 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
957
958 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
959                                  TDB_DATA *outdata);
960 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
961 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb,
962                                    TDB_DATA *outdata);
963
964 /* from ctdb_update_record.c */
965
966 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
967                                    struct ctdb_req_control_old *c,
968                                    TDB_DATA recdata, bool *async_reply);
969
970 /* from ctdb_uptime.c */
971
972 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, TDB_DATA *outdata);
973
974 /* from ctdb_vacuum.c */
975
976 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
977 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
978
979 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
980                                            TDB_DATA indata);
981 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
982                                          const struct ctdb_ltdb_header *hdr,
983                                          TDB_DATA key);
984
985 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
986                                          const struct ctdb_ltdb_header *hdr,
987                                          const TDB_DATA key);
988
989 /* from eventscript.c */
990
991 int ctdb_start_eventd(struct ctdb_context *ctdb);
992 void ctdb_stop_eventd(struct ctdb_context *ctdb);
993
994 int ctdb_event_script_callback(struct ctdb_context *ctdb,
995                                TALLOC_CTX *mem_ctx,
996                                void (*callback)(struct ctdb_context *,
997                                                 int, void *),
998                                void *private_data,
999                                enum ctdb_event call,
1000                                const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1001
1002 int ctdb_event_script_args(struct ctdb_context *ctdb,
1003                            enum ctdb_event call,
1004                            const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1005
1006 int ctdb_event_script(struct ctdb_context *ctdb,
1007                       enum ctdb_event call);
1008
1009 #endif