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