uwrap: Add mutex in uwrap_destructor().
[Samba.git] / ctdb / include / ctdb_private.h
blobe94d2c84f67b01a5013786f68c9427a67a7fe51f
1 /*
2 ctdb database library
4 Copyright (C) Andrew Tridgell 2006
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.
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.
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/>.
20 #ifndef _CTDB_PRIVATE_H
21 #define _CTDB_PRIVATE_H
23 #include "ctdb_client.h"
24 #include <sys/socket.h>
27 * Structures to support SRVID requests and replies
29 struct srvid_request {
30 uint32_t pnn;
31 uint64_t srvid;
34 struct srvid_request_data {
35 uint32_t pnn;
36 uint64_t srvid;
37 uint32_t data;
41 a tcp connection description
42 also used by tcp_add and tcp_remove controls
44 struct ctdb_tcp_connection {
45 ctdb_sock_addr src_addr;
46 ctdb_sock_addr dst_addr;
49 /* the wire representation for a tcp tickle array */
50 struct ctdb_tcp_wire_array {
51 uint32_t num;
52 struct ctdb_tcp_connection connections[1];
53 };
55 /* the list of tcp tickles used by get/set tcp tickle list */
56 struct ctdb_control_tcp_tickle_list {
57 ctdb_sock_addr addr;
58 struct ctdb_tcp_wire_array tickles;
62 array of tcp connections
64 struct ctdb_tcp_array {
65 uint32_t num;
66 struct ctdb_tcp_connection *connections;
67 };
70 /* all tunable variables go in here */
71 struct ctdb_tunable {
72 uint32_t max_redirect_count;
73 uint32_t seqnum_interval; /* unit is ms */
74 uint32_t control_timeout;
75 uint32_t traverse_timeout;
76 uint32_t keepalive_interval;
77 uint32_t keepalive_limit;
78 uint32_t recover_timeout;
79 uint32_t recover_interval;
80 uint32_t election_timeout;
81 uint32_t takeover_timeout;
82 uint32_t monitor_interval;
83 uint32_t tickle_update_interval;
84 uint32_t script_timeout;
85 uint32_t script_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
86 uint32_t script_unhealthy_on_timeout; /* obsolete */
87 uint32_t recovery_grace_period;
88 uint32_t recovery_ban_period;
89 uint32_t database_hash_size;
90 uint32_t database_max_dead;
91 uint32_t rerecovery_timeout;
92 uint32_t enable_bans;
93 uint32_t deterministic_public_ips;
94 uint32_t reclock_ping_period;
95 uint32_t no_ip_failback;
96 uint32_t disable_ip_failover;
97 uint32_t verbose_memory_names;
98 uint32_t recd_ping_timeout;
99 uint32_t recd_ping_failcount;
100 uint32_t log_latency_ms;
101 uint32_t reclock_latency_ms;
102 uint32_t recovery_drop_all_ips;
103 uint32_t verify_recovery_lock;
104 uint32_t vacuum_interval;
105 uint32_t vacuum_max_run_time;
106 uint32_t repack_limit;
107 uint32_t vacuum_limit;
108 uint32_t max_queue_depth_drop_msg;
109 uint32_t use_status_events_for_monitoring;
110 uint32_t allow_unhealthy_db_read;
111 uint32_t stat_history_interval;
112 uint32_t deferred_attach_timeout;
113 uint32_t vacuum_fast_path_count;
114 uint32_t lcp2_public_ip_assignment;
115 uint32_t allow_client_db_attach;
116 uint32_t recover_pdb_by_seqnum;
117 uint32_t deferred_rebalance_on_node_add;
118 uint32_t fetch_collapse;
119 uint32_t hopcount_make_sticky;
120 uint32_t sticky_duration;
121 uint32_t sticky_pindown;
122 uint32_t no_ip_takeover;
123 uint32_t db_record_count_warn;
124 uint32_t db_record_size_warn;
125 uint32_t db_size_warn;
126 uint32_t pulldb_preallocation_size;
127 uint32_t no_ip_host_on_all_disabled;
128 uint32_t samba3_hack;
129 uint32_t mutex_enabled;
133 an installed ctdb remote call
135 struct ctdb_registered_call {
136 struct ctdb_registered_call *next, *prev;
137 uint32_t id;
138 ctdb_fn_t fn;
142 this address structure might need to be generalised later for some
143 transports
145 struct ctdb_address {
146 const char *address;
147 int port;
151 check that a pnn is valid
153 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
156 /* called from the queue code when a packet comes in. Called with data==NULL
157 on error */
158 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
159 void *private_data);
161 /* used for callbacks in ctdb_control requests */
162 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
163 int32_t status, TDB_DATA data,
164 const char *errormsg,
165 void *private_data);
167 structure describing a connected client in the daemon
169 struct ctdb_client {
170 struct ctdb_context *ctdb;
171 int fd;
172 struct ctdb_queue *queue;
173 uint32_t client_id;
174 pid_t pid;
175 struct ctdb_tcp_list *tcp_list;
176 uint32_t db_id;
177 uint32_t num_persistent_updates;
178 struct ctdb_client_notify_list *notify;
181 struct ctdb_iface;
183 /* state associated with a public ip address */
184 struct ctdb_vnn {
185 struct ctdb_vnn *prev, *next;
187 struct ctdb_iface *iface;
188 const char **ifaces;
189 ctdb_sock_addr public_address;
190 uint8_t public_netmask_bits;
192 /* the node number that is serving this public address, if any.
193 If no node serves this ip it is set to -1 */
194 int32_t pnn;
196 /* List of clients to tickle for this public address */
197 struct ctdb_tcp_array *tcp_array;
199 /* whether we need to update the other nodes with changes to our list
200 of connected clients */
201 bool tcp_update_needed;
203 /* a context to hang sending gratious arp events off */
204 TALLOC_CTX *takeover_ctx;
206 struct ctdb_kill_tcp *killtcp;
208 /* Set to true any time an update to this VNN is in flight.
209 This helps to avoid races. */
210 bool update_in_flight;
212 /* If CTDB_CONTROL_DEL_PUBLIC_IP is received for this IP
213 * address then this flag is set. It will be deleted in the
214 * release IP callback. */
215 bool delete_pending;
219 state associated with one node
221 struct ctdb_node {
222 struct ctdb_context *ctdb;
223 struct ctdb_address address;
224 const char *name; /* for debug messages */
225 void *private_data; /* private to transport */
226 uint32_t pnn;
227 uint32_t flags;
229 /* used by the dead node monitoring */
230 uint32_t dead_count;
231 uint32_t rx_cnt;
232 uint32_t tx_cnt;
234 /* used to track node capabilities, is only valid/tracked inside the
235 recovery daemon.
237 uint32_t capabilities;
239 /* a list of controls pending to this node, so we can time them out quickly
240 if the node becomes disconnected */
241 struct daemon_control_state *pending_controls;
243 /* used by the recovery daemon when distributing ip addresses
244 across the nodes. it needs to know which public ip's can be handled
245 by each node.
247 struct ctdb_all_public_ips *known_public_ips;
248 struct ctdb_all_public_ips *available_public_ips;
249 /* used by the recovery dameon to track when a node should be banned */
250 struct ctdb_banning_state *ban_state;
254 transport specific methods
256 struct ctdb_methods {
257 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
258 int (*start)(struct ctdb_context *); /* start the transport */
259 int (*add_node)(struct ctdb_node *); /* setup a new node */
260 int (*connect_node)(struct ctdb_node *); /* connect to node */
261 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
262 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
263 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
264 void (*restart)(struct ctdb_node *); /* stop and restart the connection */
268 transport calls up to the ctdb layer
270 struct ctdb_upcalls {
271 /* recv_pkt is called when a packet comes in */
272 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
274 /* node_dead is called when an attempt to send to a node fails */
275 void (*node_dead)(struct ctdb_node *);
277 /* node_connected is called when a connection to a node is established */
278 void (*node_connected)(struct ctdb_node *);
281 /* list of message handlers - needs to be changed to a more efficient data
282 structure so we can find a message handler given a srvid quickly */
283 struct ctdb_message_list_header {
284 struct ctdb_message_list_header *next, *prev;
285 struct ctdb_context *ctdb;
286 uint64_t srvid;
287 struct ctdb_message_list *m;
289 struct ctdb_message_list {
290 struct ctdb_message_list *next, *prev;
291 struct ctdb_message_list_header *h;
292 ctdb_msg_fn_t message_handler;
293 void *message_private;
296 /* additional data required for the daemon mode */
297 struct ctdb_daemon_data {
298 int sd;
299 char *name;
300 struct ctdb_queue *queue;
304 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
306 if (value > ctdb->statistics.counter) { \
307 ctdb->statistics.counter = c->hopcount; \
309 if (value > ctdb->statistics_current.counter) { \
310 ctdb->statistics_current.counter = c->hopcount; \
314 #define CTDB_INCREMENT_STAT(ctdb, counter) \
316 ctdb->statistics.counter++; \
317 ctdb->statistics_current.counter++; \
320 #define CTDB_DECREMENT_STAT(ctdb, counter) \
322 if (ctdb->statistics.counter > 0) \
323 ctdb->statistics.counter--; \
324 if (ctdb->statistics_current.counter > 0) \
325 ctdb->statistics_current.counter--; \
328 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
330 ctdb_db->statistics.counter++; \
333 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
335 if (ctdb_db->statistics.counter > 0) \
336 ctdb_db->statistics.counter--; \
339 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
341 if (value > ctdb->statistics.counter.max) \
342 ctdb->statistics.counter.max = value; \
343 if (value > ctdb->statistics_current.counter.max) \
344 ctdb->statistics_current.counter.max = value; \
346 if (ctdb->statistics.counter.num == 0 || \
347 value < ctdb->statistics.counter.min) \
348 ctdb->statistics.counter.min = value; \
349 if (ctdb->statistics_current.counter.num == 0 || \
350 value < ctdb->statistics_current.counter.min) \
351 ctdb->statistics_current.counter.min = value; \
353 ctdb->statistics.counter.total += value; \
354 ctdb->statistics_current.counter.total += value; \
356 ctdb->statistics.counter.num++; \
357 ctdb->statistics_current.counter.num++; \
359 if (ctdb->tunable.reclock_latency_ms != 0) { \
360 if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
361 DEBUG(DEBUG_ERR, \
362 ("High RECLOCK latency %fs for operation %s\n", \
363 value, name)); \
368 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value) \
370 if (value > ctdb_db->statistics.counter.max) \
371 ctdb_db->statistics.counter.max = value; \
372 if (ctdb_db->statistics.counter.num == 0 || \
373 value < ctdb_db->statistics.counter.min) \
374 ctdb_db->statistics.counter.min = value; \
376 ctdb_db->statistics.counter.total += value; \
377 ctdb_db->statistics.counter.num++; \
379 if (ctdb_db->ctdb->tunable.log_latency_ms != 0) { \
380 if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) { \
381 DEBUG(DEBUG_ERR, \
382 ("High latency %.6fs for operation %s on database %s\n",\
383 value, operation, ctdb_db->db_name)); \
388 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
390 double l = timeval_elapsed(&t); \
392 if (l > ctdb->statistics.counter.max) \
393 ctdb->statistics.counter.max = l; \
394 if (l > ctdb->statistics_current.counter.max) \
395 ctdb->statistics_current.counter.max = l; \
397 if (ctdb->statistics.counter.num == 0 || \
398 l < ctdb->statistics.counter.min) \
399 ctdb->statistics.counter.min = l; \
400 if (ctdb->statistics_current.counter.num == 0 || \
401 l < ctdb->statistics_current.counter.min) \
402 ctdb->statistics_current.counter.min = l; \
404 ctdb->statistics.counter.total += l; \
405 ctdb->statistics_current.counter.total += l; \
407 ctdb->statistics.counter.num++; \
408 ctdb->statistics_current.counter.num++; \
410 if (ctdb->tunable.log_latency_ms != 0) { \
411 if (l*1000 > ctdb->tunable.log_latency_ms) { \
412 DEBUG(DEBUG_WARNING, \
413 ("High latency %.6fs for operation %s on database %s\n",\
414 l, operation, db->db_name)); \
421 /* a structure that contains the elements required for the write record
422 control
424 struct ctdb_write_record {
425 uint32_t dbid;
426 uint32_t keylen;
427 uint32_t datalen;
428 unsigned char blob[1];
431 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
433 enum ctdb_runstate {
434 CTDB_RUNSTATE_UNKNOWN,
435 CTDB_RUNSTATE_INIT,
436 CTDB_RUNSTATE_SETUP,
437 CTDB_RUNSTATE_FIRST_RECOVERY,
438 CTDB_RUNSTATE_STARTUP,
439 CTDB_RUNSTATE_RUNNING,
440 CTDB_RUNSTATE_SHUTDOWN,
443 const char *runstate_to_string(enum ctdb_runstate runstate);
444 enum ctdb_runstate runstate_from_string(const char *label);
445 void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate);
447 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code);
449 #define CTDB_MONITORING_ACTIVE 0
450 #define CTDB_MONITORING_DISABLED 1
452 #define NUM_DB_PRIORITIES 3
453 /* main state of the ctdb daemon */
454 struct ctdb_context {
455 struct tevent_context *ev;
456 struct timeval ctdbd_start_time;
457 struct timeval last_recovery_started;
458 struct timeval last_recovery_finished;
459 uint32_t recovery_mode;
460 TALLOC_CTX *tickle_update_context;
461 TALLOC_CTX *keepalive_ctx;
462 TALLOC_CTX *check_public_ifaces_ctx;
463 struct ctdb_tunable tunable;
464 enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
465 struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
466 bool freeze_transaction_started;
467 uint32_t freeze_transaction_id;
468 struct ctdb_address address;
469 const char *name;
470 const char *db_directory;
471 const char *db_directory_persistent;
472 const char *db_directory_state;
473 struct tdb_wrap *db_persistent_health;
474 uint32_t db_persistent_startup_generation;
475 uint64_t db_persistent_check_errors;
476 uint64_t max_persistent_check_errors;
477 const char *transport;
478 char *recovery_lock_file;
479 int recovery_lock_fd;
480 uint32_t pnn; /* our own pnn */
481 uint32_t num_nodes;
482 uint32_t num_connected;
483 unsigned flags;
484 uint32_t capabilities;
485 struct idr_context *idr;
486 int lastid;
487 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
488 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
489 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
490 struct ctdb_iface *ifaces; /* list of local interfaces */
491 char *err_msg;
492 const struct ctdb_methods *methods; /* transport methods */
493 const struct ctdb_upcalls *upcalls; /* transport upcalls */
494 void *private_data; /* private to transport */
495 struct ctdb_db_context *db_list;
496 struct ctdb_message_list_header *message_list_header;
497 struct tdb_context *message_list_indexdb;
498 struct ctdb_daemon_data daemon;
499 struct ctdb_statistics statistics;
500 struct ctdb_statistics statistics_current;
501 #define MAX_STAT_HISTORY 100
502 struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
503 struct ctdb_vnn_map *vnn_map;
504 uint32_t num_clients;
505 uint32_t recovery_master;
506 struct ctdb_call_state *pending_calls;
507 struct ctdb_client_ip *client_ip_list;
508 bool do_checkpublicip;
509 struct trbt_tree *server_ids;
510 bool do_setsched;
511 const char *event_script_dir;
512 const char *notification_script;
513 const char *default_public_interface;
514 pid_t ctdbd_pid;
515 pid_t recoverd_pid;
516 pid_t syslogd_pid;
517 enum ctdb_runstate runstate;
518 struct ctdb_monitor_state *monitor;
519 struct ctdb_log_state *log;
520 int start_as_disabled;
521 int start_as_stopped;
522 bool valgrinding;
523 uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
524 uint32_t *recd_ping_count;
525 TALLOC_CTX *recd_ctx; /* a context used to track recoverd monitoring events */
526 TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
528 TALLOC_CTX *event_script_ctx;
529 int active_events;
531 struct ctdb_event_script_state *current_monitor;
532 struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX];
534 TALLOC_CTX *banning_ctx;
536 struct ctdb_vacuum_child_context *vacuumers;
538 /* mapping from pid to ctdb_client * */
539 struct ctdb_client_pid_list *client_pids;
541 /* used in the recovery daemon to remember the ip allocation */
542 struct trbt_tree *ip_tree;
544 /* Used to defer db attach requests while in recovery mode */
545 struct ctdb_deferred_attach_context *deferred_attach;
547 /* if we are a child process, do we have a domain socket to send controls on */
548 bool can_send_controls;
550 /* list of event script callback functions that are active */
551 struct event_script_callback *script_callbacks;
553 struct ctdb_reloadips_handle *reload_ips;
555 const char *nodes_file;
556 const char *public_addresses_file;
557 struct trbt_tree *child_processes;
559 /* Used for locking record/db/alldb */
560 int lock_num_pending;
561 struct lock_context *lock_current;
562 struct lock_context *lock_pending;
565 struct ctdb_db_context {
566 struct ctdb_db_context *next, *prev;
567 struct ctdb_context *ctdb;
568 uint32_t db_id;
569 uint32_t priority;
570 bool persistent;
571 bool readonly; /* Do we support read-only delegations ? */
572 bool sticky; /* Do we support sticky records ? */
573 const char *db_name;
574 const char *db_path;
575 struct tdb_wrap *ltdb;
576 struct tdb_context *rottdb; /* ReadOnly tracking TDB */
577 struct ctdb_registered_call *calls; /* list of registered calls */
578 uint32_t seqnum;
579 struct timed_event *seqnum_update;
580 struct ctdb_traverse_local_handle *traverse;
581 struct ctdb_vacuum_handle *vacuum_handle;
582 char *unhealthy_reason;
583 int pending_requests;
584 struct revokechild_handle *revokechild_active;
585 struct ctdb_persistent_state *persistent_state;
586 struct trbt_tree *delete_queue;
587 struct trbt_tree *sticky_records;
588 int (*ctdb_ltdb_store_fn)(struct ctdb_db_context *ctdb_db,
589 TDB_DATA key,
590 struct ctdb_ltdb_header *header,
591 TDB_DATA data);
593 /* used to track which records we are currently fetching
594 so we can avoid sending duplicate fetch requests
596 struct trbt_tree *deferred_fetch;
598 struct ctdb_db_statistics statistics;
600 int lock_num_current;
604 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
605 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
606 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
607 return -1; }} while (0)
609 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
610 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
611 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
612 return; }} while (0)
614 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
615 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
616 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
617 return NULL; }} while (0)
619 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
620 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
621 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
622 }} while (0)
625 structure passed in set_call control
627 struct ctdb_control_set_call {
628 uint32_t db_id;
629 ctdb_fn_t fn;
630 uint32_t id;
634 struct for kill_tcp control
636 struct ctdb_control_killtcp {
637 ctdb_sock_addr src_addr;
638 ctdb_sock_addr dst_addr;
642 struct holding a ctdb_sock_addr and an interface name,
643 used to add/remove public addresses
645 struct ctdb_control_ip_iface {
646 ctdb_sock_addr addr;
647 uint32_t mask;
648 uint32_t len;
649 char iface[1];
653 struct holding a ctdb_sock_addr and an interface name,
654 used for send_gratious_arp
656 struct ctdb_control_gratious_arp {
657 ctdb_sock_addr addr;
658 uint32_t mask;
659 uint32_t len;
660 char iface[1];
664 persistent store control - update this record on all other nodes
666 struct ctdb_control_persistent_store {
667 uint32_t db_id;
668 uint32_t len;
669 uint8_t data[1];
673 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
675 struct ctdb_node_flag_change {
676 uint32_t pnn;
677 uint32_t new_flags;
678 uint32_t old_flags;
682 struct for admin setting a ban
684 struct ctdb_ban_info {
685 uint32_t pnn;
686 uint32_t ban_time;
689 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
691 #define CTDB_LMASTER_ANY 0xffffffff
694 state of a in-progress ctdb call
696 struct ctdb_call_state {
697 struct ctdb_call_state *next, *prev;
698 enum call_state state;
699 uint32_t reqid;
700 struct ctdb_req_call *c;
701 struct ctdb_db_context *ctdb_db;
702 const char *errmsg;
703 struct ctdb_call *call;
704 uint32_t generation;
705 struct {
706 void (*fn)(struct ctdb_call_state *);
707 void *private_data;
708 } async;
712 /* used for fetch_lock */
713 struct ctdb_fetch_handle {
714 struct ctdb_db_context *ctdb_db;
715 TDB_DATA key;
716 TDB_DATA *data;
717 struct ctdb_ltdb_header header;
720 /* internal prototypes */
721 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
722 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
723 void ctdb_die(struct ctdb_context *ctdb, const char *msg);
724 void ctdb_external_trace(void);
725 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
726 int ctdb_parse_address(struct ctdb_context *ctdb,
727 TALLOC_CTX *mem_ctx, const char *str,
728 struct ctdb_address *address);
729 bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
730 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
731 uint32_t ctdb_hash(const TDB_DATA *key);
732 uint32_t ctdb_hash_string(const char *str);
733 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
734 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
735 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
736 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
737 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
738 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
740 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
741 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
742 TDB_DATA key, struct ctdb_ltdb_header *header,
743 TALLOC_CTX *mem_ctx, TDB_DATA *data);
744 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
745 struct ctdb_ltdb_header *header, TDB_DATA data);
746 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
747 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context *ctdb_db,
748 TDB_DATA key, struct ctdb_ltdb_header *header,
749 TALLOC_CTX *mem_ctx, TDB_DATA *data);
750 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
751 struct ctdb_req_control *c,
752 TDB_DATA recdata);
753 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
754 struct ctdb_req_control *c,
755 TDB_DATA recdata);
756 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
757 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
758 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
759 TDB_DATA key, struct ctdb_req_header *hdr,
760 void (*recv_pkt)(void *, struct ctdb_req_header *),
761 void *recv_context, bool ignore_generation);
762 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
763 TDB_DATA key, struct ctdb_ltdb_header *header,
764 struct ctdb_req_header *hdr, TDB_DATA *data,
765 void (*recv_pkt)(void *, struct ctdb_req_header *),
766 void *recv_context, bool ignore_generation);
767 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
769 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
770 struct ctdb_call *call,
771 struct ctdb_ltdb_header *header,
772 TDB_DATA *data);
775 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork,
776 bool use_syslog);
777 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
778 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
781 queue a packet for sending
783 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
786 setup the fd used by the queue
788 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
791 setup a packet queue on a socket
793 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
794 TALLOC_CTX *mem_ctx, int fd, int alignment,
796 ctdb_queue_cb_fn_t callback,
797 void *private_data, const char *fmt, ...)
798 PRINTF_ATTRIBUTE(7,8);
801 allocate a packet for use in client<->daemon communication
803 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
804 TALLOC_CTX *mem_ctx,
805 enum ctdb_operation operation,
806 size_t length, size_t slength,
807 const char *type);
808 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
809 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
811 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
812 TALLOC_CTX *mem_ctx,
813 enum ctdb_operation operation,
814 size_t length, size_t slength,
815 const char *type);
816 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
817 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
819 int ctdb_queue_length(struct ctdb_queue *queue);
822 lock a record in the ltdb, given a key
824 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
827 unlock a record in the ltdb, given a key
829 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
833 make a ctdb call to the local daemon - async send. Called from client context.
835 This constructs a ctdb_call request and queues it for processing.
836 This call never blocks.
838 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
839 struct ctdb_call *call);
842 make a recv call to the local ctdb daemon - called from client context
844 This is called when the program wants to wait for a ctdb_call to complete and get the
845 results. This call will block unless the call has already completed.
847 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
849 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
850 uint64_t srvid, TDB_DATA data);
853 send a ctdb message
855 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
856 uint64_t srvid, TDB_DATA data);
859 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
860 struct ctdb_call *call);
862 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
864 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
865 struct ctdb_call *call,
866 struct ctdb_ltdb_header *header);
868 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
869 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx,
870 TDB_DATA *data, bool updatetdb);
872 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
874 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
876 int ctdb_socket_connect(struct ctdb_context *ctdb);
877 void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
879 #define CTDB_BAD_REQID ((uint32_t)-1)
880 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
881 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
882 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
884 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
885 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
887 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
888 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
889 TDB_DATA data,
890 ctdb_control_callback_fn_t callback,
891 void *private_data);
893 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
894 TDB_DATA *outdata, uint64_t tdb_flags,
895 bool persistent, uint32_t client_id,
896 struct ctdb_req_control *c,
897 bool *async_reply);
898 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
899 uint32_t client_id);
901 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
902 ctdb_fn_t fn, int id);
904 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
905 uint32_t opcode, uint32_t flags, TDB_DATA data,
906 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
907 struct timeval *timeout, char **errormsg);
908 int ctdb_control_recv(struct ctdb_context *ctdb,
909 struct ctdb_client_control_state *state,
910 TALLOC_CTX *mem_ctx,
911 TDB_DATA *outdata, int32_t *status, char **errormsg);
913 struct ctdb_client_control_state *
914 ctdb_control_send(struct ctdb_context *ctdb,
915 uint32_t destnode, uint64_t srvid,
916 uint32_t opcode, uint32_t flags, TDB_DATA data,
917 TALLOC_CTX *mem_ctx,
918 struct timeval *timeout,
919 char **errormsg);
924 #define CHECK_CONTROL_DATA_SIZE(size) do { \
925 if (indata.dsize != size) { \
926 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
927 opcode, (unsigned)indata.dsize, (unsigned)size)); \
928 return -1; \
930 } while (0)
932 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
933 if (indata.dsize < size) { \
934 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
935 opcode, (unsigned)indata.dsize, (unsigned)size)); \
936 return -1; \
938 } while (0)
940 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
941 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
942 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
943 int ctdb_control_getnodemapv4(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
944 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
945 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
948 /* structure used for pulldb control */
949 struct ctdb_control_pulldb {
950 uint32_t db_id;
951 uint32_t lmaster;
954 /* structure used for sending lists of records */
955 struct ctdb_marshall_buffer {
956 uint32_t db_id;
957 uint32_t count;
958 uint8_t data[1];
962 structure for setting a tunable
964 struct ctdb_control_set_tunable {
965 uint32_t value;
966 uint32_t length;
967 uint8_t name[1];
971 structure for getting a tunable
973 struct ctdb_control_get_tunable {
974 uint32_t length;
975 uint8_t name[1];
979 structure for listing tunables
981 struct ctdb_control_list_tunable {
982 uint32_t length;
983 /* returns a : separated list of tunable names */
984 uint8_t data[1];
988 struct ctdb_node_and_flagsv4 {
989 uint32_t pnn;
990 uint32_t flags;
991 struct sockaddr_in sin;
994 struct ctdb_node_mapv4 {
995 uint32_t num;
996 struct ctdb_node_and_flagsv4 nodes[1];
999 struct ctdb_control_wipe_database {
1000 uint32_t db_id;
1001 uint32_t transaction_id;
1005 state of a in-progress ctdb call in client
1007 struct ctdb_client_call_state {
1008 enum call_state state;
1009 uint32_t reqid;
1010 struct ctdb_db_context *ctdb_db;
1011 struct ctdb_call *call;
1012 struct {
1013 void (*fn)(struct ctdb_client_call_state *);
1014 void *private_data;
1015 } async;
1019 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
1020 TDB_DATA indata,
1021 TDB_DATA *outdata,
1022 uint32_t srcnode,
1023 uint32_t client_id);
1024 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
1025 TDB_DATA *outdata, uint32_t srcnode, uint32_t client_id);
1026 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1027 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1028 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1029 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
1030 TDB_DATA *outdata, uint32_t srcnode);
1032 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1033 bool ctdb_check_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
1035 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1036 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1037 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1038 int daemon_check_srvids(struct ctdb_context *ctdb, TDB_DATA indata,
1039 TDB_DATA *outdata);
1041 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1042 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1044 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
1045 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1047 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
1048 uint32_t *reqid,
1049 struct ctdb_ltdb_header *header,
1050 TDB_DATA *key, TDB_DATA *data);
1052 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1053 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1055 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1056 struct ctdb_req_control *c,
1057 TDB_DATA indata, bool *async_reply,
1058 const char **errormsg);
1059 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1060 TDB_DATA *outdata, int32_t status, const char *errormsg);
1062 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1063 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority,
1064 bool check_recmode);
1066 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1067 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1069 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1071 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1072 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1073 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1074 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
1075 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1076 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1077 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1078 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1079 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1082 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1083 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1084 void ctdb_node_dead(struct ctdb_node *node);
1085 void ctdb_node_connected(struct ctdb_node *node);
1086 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1087 void set_scheduler(void);
1088 void reset_scheduler(void);
1090 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
1091 void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid);
1092 pid_t ctdb_fork(struct ctdb_context *ctdb);
1093 pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb);
1094 void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...);
1095 bool ctdb_is_child_process(void);
1096 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
1098 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1099 struct ctdb_req_control *c,
1100 TDB_DATA indata,
1101 bool *async_reply);
1102 int32_t ctdb_control_takeover_ipv4(struct ctdb_context *ctdb,
1103 struct ctdb_req_control *c,
1104 TDB_DATA indata,
1105 bool *async_reply);
1106 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1107 struct ctdb_req_control *c,
1108 TDB_DATA indata,
1109 bool *async_reply);
1110 int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb,
1111 struct ctdb_req_control *c,
1112 TDB_DATA indata,
1113 bool *async_reply);
1114 int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
1115 struct ctdb_req_control *c,
1116 bool *async_reply);
1117 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
1118 struct ctdb_req_control *c,
1119 bool *async_reply);
1120 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
1121 struct ctdb_req_control *c,
1122 bool *async_reply);
1124 struct ctdb_public_ipv4 {
1125 uint32_t pnn;
1126 struct sockaddr_in sin;
1129 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1130 uint32_t destnode, struct ctdb_public_ip *ip);
1131 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1132 uint32_t destnode, struct ctdb_public_ip *ip);
1134 struct ctdb_all_public_ipsv4 {
1135 uint32_t num;
1136 struct ctdb_public_ipv4 ips[1];
1139 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1140 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1141 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1142 struct timeval timeout,
1143 uint32_t destnode,
1144 TALLOC_CTX *mem_ctx,
1145 struct ctdb_all_public_ips **ips);
1146 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1147 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
1148 struct timeval timeout, uint32_t destnode,
1149 TALLOC_CTX *mem_ctx,
1150 uint32_t flags,
1151 struct ctdb_all_public_ips **ips);
1152 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb,
1153 struct timeval timeout, uint32_t destnode,
1154 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1156 struct ctdb_control_iface_info {
1157 char name[CTDB_IFACE_SIZE+2];
1158 uint16_t link_state;
1159 uint32_t references;
1162 struct ctdb_control_public_ip_info {
1163 struct ctdb_public_ip ip;
1164 uint32_t active_idx;
1165 uint32_t num;
1166 struct ctdb_control_iface_info ifaces[1];
1169 struct ctdb_control_get_ifaces {
1170 uint32_t num;
1171 struct ctdb_control_iface_info ifaces[1];
1174 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
1175 struct ctdb_req_control *c,
1176 TDB_DATA indata,
1177 TDB_DATA *outdata);
1178 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
1179 struct ctdb_req_control *c,
1180 TDB_DATA *outdata);
1181 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
1182 struct ctdb_req_control *c,
1183 TDB_DATA indata);
1184 int ctdb_ctrl_get_public_ip_info(struct ctdb_context *ctdb,
1185 struct timeval timeout, uint32_t destnode,
1186 TALLOC_CTX *mem_ctx,
1187 const ctdb_sock_addr *addr,
1188 struct ctdb_control_public_ip_info **info);
1189 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
1190 struct timeval timeout, uint32_t destnode,
1191 TALLOC_CTX *mem_ctx,
1192 struct ctdb_control_get_ifaces **ifaces);
1193 int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb,
1194 struct timeval timeout, uint32_t destnode,
1195 TALLOC_CTX *mem_ctx,
1196 const struct ctdb_control_iface_info *info);
1198 /* from takeover/system.c */
1199 uint32_t uint16_checksum(uint16_t *data, size_t n);
1200 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1201 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
1202 char *ctdb_sys_find_ifname(ctdb_sock_addr *addr);
1203 bool ctdb_sys_check_iface_exists(const char *iface);
1204 int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
1205 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
1206 const ctdb_sock_addr *src,
1207 uint32_t seq, uint32_t ack, int rst);
1209 /* Details of a byte range lock */
1210 struct ctdb_lock_info {
1211 ino_t inode;
1212 off_t start, end;
1213 bool waiting;
1214 bool read_only;
1217 char *ctdb_get_process_name(pid_t pid);
1218 int ctdb_set_process_name(const char *name);
1219 bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info);
1220 bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid);
1222 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1224 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
1225 int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
1226 const char *iface,
1227 const char *ip);
1228 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1229 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
1230 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap,
1231 uint32_t *force_rebalance_nodes,
1232 client_async_callback fail_callback, void *callback_data);
1234 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1235 TDB_DATA indata);
1236 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata, bool tcp_update_needed);
1237 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1238 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1239 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1240 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1241 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1242 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1244 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1245 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call);
1246 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
1247 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1248 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1249 TALLOC_CTX *mem_ctx,
1250 void (*callback)(struct ctdb_context *, int, void *),
1251 void *private_data,
1252 enum ctdb_eventscript_call call,
1253 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1254 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1256 void set_nonblocking(int fd);
1257 void set_close_on_exec(int fd);
1259 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1261 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1263 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1264 TDB_DATA *outdata);
1265 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1266 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1267 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1268 int32_t ctdb_control_receive_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1269 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1270 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
1271 struct ctdb_req_control *c,
1272 TDB_DATA recdata, bool *async_reply);
1274 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1276 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1278 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1279 struct timeval timeout,
1280 uint32_t destnode,
1281 struct ctdb_tunable *tunables);
1283 void ctdb_start_freeze(struct ctdb_context *ctdb, uint32_t priority);
1285 bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask);
1286 bool parse_ip_port(const char *s, ctdb_sock_addr *addr);
1287 bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr);
1288 bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin);
1291 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1292 int ctdb_sys_close_capture_socket(void *private_data);
1293 int ctdb_sys_read_tcp_packet(int s, void *private_data, ctdb_sock_addr *src, ctdb_sock_addr *dst, uint32_t *ack_seq, uint32_t *seq);
1295 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1296 struct timeval timeout,
1297 uint32_t destnode,
1298 struct ctdb_control_killtcp *killtcp);
1300 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1301 struct timeval timeout,
1302 uint32_t destnode,
1303 struct ctdb_control_ip_iface *pub);
1305 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1306 struct timeval timeout,
1307 uint32_t destnode,
1308 struct ctdb_control_ip_iface *pub);
1310 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1311 struct timeval timeout,
1312 uint32_t destnode,
1313 ctdb_sock_addr *addr,
1314 const char *ifname);
1316 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1317 struct timeval timeout,
1318 uint32_t destnode,
1319 TALLOC_CTX *mem_ctx,
1320 ctdb_sock_addr *addr,
1321 struct ctdb_control_tcp_tickle_list **list);
1324 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1325 uint32_t client_id,
1326 TDB_DATA indata);
1327 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1328 TDB_DATA indata);
1329 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1330 TDB_DATA indata);
1331 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1332 TDB_DATA *outdata);
1333 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1334 TDB_DATA *outdata);
1336 int ctdb_attach_databases(struct ctdb_context *ctdb);
1338 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1339 struct ctdb_req_control *c,
1340 TDB_DATA recdata, bool *async_reply);
1341 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1342 struct ctdb_req_control *c, TDB_DATA recdata,
1343 bool *async_reply);
1344 int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb,
1345 struct ctdb_req_control *c,
1346 TDB_DATA recdata, bool *async_reply);
1348 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
1349 struct ctdb_req_control *c,
1350 TDB_DATA recdata, bool *async_reply);
1352 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
1354 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1355 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1356 int32_t ctdb_control_transaction_cancel(struct ctdb_context *ctdb);
1357 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1358 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb, TDB_DATA indata);
1359 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
1360 TDB_DATA indata,
1361 TDB_DATA *outdata);
1364 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1365 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1367 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1368 bool ctdb_stopped_monitoring(struct ctdb_context *ctdb);
1369 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1370 void lockdown_memory(bool valgrinding);
1372 struct client_async_data {
1373 enum ctdb_controls opcode;
1374 bool dont_log_errors;
1375 uint32_t count;
1376 uint32_t fail_count;
1377 client_async_callback callback;
1378 client_async_callback fail_callback;
1379 void *callback_data;
1381 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1382 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1383 int ctdb_client_async_control(struct ctdb_context *ctdb,
1384 enum ctdb_controls opcode,
1385 uint32_t *nodes,
1386 uint64_t srvid,
1387 struct timeval timeout,
1388 bool dont_log_errors,
1389 TDB_DATA data,
1390 client_async_callback client_callback,
1391 client_async_callback fail_callback,
1392 void *callback_data);
1394 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1396 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1398 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1399 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1401 int32_t ctdb_control_trans2_finished(struct ctdb_context *ctdb,
1402 struct ctdb_req_control *c);
1403 int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb,
1404 struct ctdb_req_control *c);
1405 int32_t ctdb_control_trans2_active(struct ctdb_context *ctdb,
1406 struct ctdb_req_control *c,
1407 uint32_t db_id);
1409 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
1410 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
1411 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
1413 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
1414 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata);
1416 extern int script_log_level;
1417 extern bool fast_start;
1418 extern const char *ctdbd_pidfile;
1420 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1421 uint32_t call_type,
1422 TDB_DATA *outdata);
1424 int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
1425 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
1427 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
1428 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
1430 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
1431 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1433 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1434 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1436 void ctdb_local_node_got_banned(struct ctdb_context *ctdb);
1437 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
1438 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
1439 int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata,
1440 uint32_t client_id);
1441 void ctdb_ban_self(struct ctdb_context *ctdb);
1443 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1445 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1447 int start_syslog_daemon(struct ctdb_context *ctdb);
1449 /* Where to send the log messages back to */
1450 struct ctdb_get_log_addr {
1451 uint32_t pnn;
1452 uint64_t srvid;
1453 int32_t level;
1456 extern int log_ringbuf_size;
1458 TDB_DATA ctdb_log_ringbuffer_collect_log(TALLOC_CTX *mem_ctx,
1459 enum debug_level max_level);
1460 void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr);
1461 void ctdb_clear_log(struct ctdb_context *ctdb);
1462 int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
1463 int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
1464 void ctdb_log_ringbuffer_free(void);
1466 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
1467 struct ctdb_context *ctdb,
1468 const char *log_prefix,
1469 const char *helper,
1470 int helper_argc,
1471 const char **helper_argv,
1472 void (*logfn)(const char *, uint16_t, void *),
1473 void *logfn_private, pid_t *pid);
1476 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
1477 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
1479 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
1480 TDB_DATA indata,
1481 TDB_DATA *outdata);
1483 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
1484 struct ctdb_db_context *ctdb_db);
1485 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
1486 struct ctdb_db_context *ctdb_db,
1487 const char *reason,/* NULL means healthy */
1488 int num_healthy_nodes);
1489 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
1491 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
1493 void ctdb_fault_setup(void);
1495 int verify_remote_ip_allocation(struct ctdb_context *ctdb,
1496 struct ctdb_all_public_ips *ips,
1497 uint32_t pnn);
1498 int update_ip_assignment_tree(struct ctdb_context *ctdb,
1499 struct ctdb_public_ip *ip);
1501 int ctdb_init_tevent_logging(struct ctdb_context *ctdb);
1503 int ctdb_statistics_init(struct ctdb_context *ctdb);
1505 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
1506 struct ctdb_req_control *c,
1507 TDB_DATA *outdata);
1509 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
1511 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
1514 * structure to pass to a schedule_for_deletion_control
1516 struct ctdb_control_schedule_for_deletion {
1517 uint32_t db_id;
1518 struct ctdb_ltdb_header hdr;
1519 uint32_t keylen;
1520 uint8_t key[1]; /* key[] */
1523 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
1524 TDB_DATA indata);
1527 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
1528 const struct ctdb_ltdb_header *hdr,
1529 TDB_DATA key);
1531 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
1532 const struct ctdb_ltdb_header *hdr,
1533 const TDB_DATA key);
1535 struct ctdb_ltdb_header *ctdb_header_from_record_handle(struct ctdb_record_handle *h);
1537 int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
1539 typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn, void *private_data);
1541 void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_trackingdb_cb cb, void *private_data);
1543 int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA data);
1545 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
1547 int ctdb_add_revoke_deferred_call(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key, struct ctdb_req_header *hdr, deferred_requeue_fn fn, void *call_context);
1549 int ctdb_set_db_readonly(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1551 int ctdb_null_func(struct ctdb_call_info *call);
1553 int ctdb_fetch_func(struct ctdb_call_info *call);
1555 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
1557 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
1558 uint32_t db_id,
1559 TDB_DATA *outdata);
1561 int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1564 description for a message to reload all ips via recovery master/daemon
1566 struct reloadips_all_reply {
1567 uint32_t pnn;
1568 uint64_t srvid;
1571 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1573 int ctdb_start_monitoring_interfaces(struct ctdb_context *ctdb);
1575 /* from server/ctdb_lock.c */
1576 struct lock_request;
1578 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority);
1579 int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority);
1581 void ctdb_lock_free_request_context(struct lock_request *lock_req);
1583 struct lock_request *ctdb_lock_record(struct ctdb_db_context *ctdb_db,
1584 TDB_DATA key,
1585 bool auto_mark,
1586 void (*callback)(void *, bool),
1587 void *private_data);
1589 struct lock_request *ctdb_lock_db(struct ctdb_db_context *ctdb_db,
1590 bool auto_mark,
1591 void (*callback)(void *, bool),
1592 void *private_data);
1594 struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb,
1595 uint32_t priority,
1596 bool auto_mark,
1597 void (*callback)(void *, bool),
1598 void *private_data);
1600 struct lock_request *ctdb_lock_alldb(struct ctdb_context *ctdb,
1601 bool auto_mark,
1602 void (*callback)(void *, bool),
1603 void *private_data);
1605 int mkdir_p(const char *dir, int mode);
1606 void mkdir_p_or_die(const char *dir, int mode);
1608 #endif