param: move defaults_saved global out of dump_globals function
[Samba.git] / ctdb / include / ctdb_private.h
blobaeebed1b51679a271bb259d69e37bc2a57ff0420
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;
132 an installed ctdb remote call
134 struct ctdb_registered_call {
135 struct ctdb_registered_call *next, *prev;
136 uint32_t id;
137 ctdb_fn_t fn;
141 this address structure might need to be generalised later for some
142 transports
144 struct ctdb_address {
145 const char *address;
146 int port;
150 check that a pnn is valid
152 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
155 /* called from the queue code when a packet comes in. Called with data==NULL
156 on error */
157 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
158 void *private_data);
160 /* used for callbacks in ctdb_control requests */
161 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
162 int32_t status, TDB_DATA data,
163 const char *errormsg,
164 void *private_data);
166 structure describing a connected client in the daemon
168 struct ctdb_client {
169 struct ctdb_context *ctdb;
170 int fd;
171 struct ctdb_queue *queue;
172 uint32_t client_id;
173 pid_t pid;
174 struct ctdb_tcp_list *tcp_list;
175 uint32_t db_id;
176 uint32_t num_persistent_updates;
177 struct ctdb_client_notify_list *notify;
180 struct ctdb_iface;
182 /* state associated with a public ip address */
183 struct ctdb_vnn {
184 struct ctdb_vnn *prev, *next;
186 struct ctdb_iface *iface;
187 const char **ifaces;
188 ctdb_sock_addr public_address;
189 uint8_t public_netmask_bits;
191 /* the node number that is serving this public address, if any.
192 If no node serves this ip it is set to -1 */
193 int32_t pnn;
195 /* List of clients to tickle for this public address */
196 struct ctdb_tcp_array *tcp_array;
198 /* whether we need to update the other nodes with changes to our list
199 of connected clients */
200 bool tcp_update_needed;
202 /* a context to hang sending gratious arp events off */
203 TALLOC_CTX *takeover_ctx;
205 struct ctdb_kill_tcp *killtcp;
207 /* Set to true any time an update to this VNN is in flight.
208 This helps to avoid races. */
209 bool update_in_flight;
211 /* If CTDB_CONTROL_DEL_PUBLIC_IP is received for this IP
212 * address then this flag is set. It will be deleted in the
213 * release IP callback. */
214 bool delete_pending;
218 state associated with one node
220 struct ctdb_node {
221 struct ctdb_context *ctdb;
222 struct ctdb_address address;
223 const char *name; /* for debug messages */
224 void *private_data; /* private to transport */
225 uint32_t pnn;
226 uint32_t flags;
228 /* used by the dead node monitoring */
229 uint32_t dead_count;
230 uint32_t rx_cnt;
231 uint32_t tx_cnt;
233 /* used to track node capabilities, is only valid/tracked inside the
234 recovery daemon.
236 uint32_t capabilities;
238 /* a list of controls pending to this node, so we can time them out quickly
239 if the node becomes disconnected */
240 struct daemon_control_state *pending_controls;
242 /* used by the recovery daemon when distributing ip addresses
243 across the nodes. it needs to know which public ip's can be handled
244 by each node.
246 struct ctdb_all_public_ips *known_public_ips;
247 struct ctdb_all_public_ips *available_public_ips;
248 /* used by the recovery dameon to track when a node should be banned */
249 struct ctdb_banning_state *ban_state;
253 transport specific methods
255 struct ctdb_methods {
256 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
257 int (*start)(struct ctdb_context *); /* start the transport */
258 int (*add_node)(struct ctdb_node *); /* setup a new node */
259 int (*connect_node)(struct ctdb_node *); /* connect to node */
260 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
261 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
262 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
263 void (*restart)(struct ctdb_node *); /* stop and restart the connection */
267 transport calls up to the ctdb layer
269 struct ctdb_upcalls {
270 /* recv_pkt is called when a packet comes in */
271 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
273 /* node_dead is called when an attempt to send to a node fails */
274 void (*node_dead)(struct ctdb_node *);
276 /* node_connected is called when a connection to a node is established */
277 void (*node_connected)(struct ctdb_node *);
280 /* list of message handlers - needs to be changed to a more efficient data
281 structure so we can find a message handler given a srvid quickly */
282 struct ctdb_message_list_header {
283 struct ctdb_message_list_header *next, *prev;
284 struct ctdb_context *ctdb;
285 uint64_t srvid;
286 struct ctdb_message_list *m;
288 struct ctdb_message_list {
289 struct ctdb_message_list *next, *prev;
290 struct ctdb_message_list_header *h;
291 ctdb_msg_fn_t message_handler;
292 void *message_private;
295 /* additional data required for the daemon mode */
296 struct ctdb_daemon_data {
297 int sd;
298 char *name;
299 struct ctdb_queue *queue;
303 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
305 if (value > ctdb->statistics.counter) { \
306 ctdb->statistics.counter = c->hopcount; \
308 if (value > ctdb->statistics_current.counter) { \
309 ctdb->statistics_current.counter = c->hopcount; \
313 #define CTDB_INCREMENT_STAT(ctdb, counter) \
315 ctdb->statistics.counter++; \
316 ctdb->statistics_current.counter++; \
319 #define CTDB_DECREMENT_STAT(ctdb, counter) \
321 if (ctdb->statistics.counter > 0) \
322 ctdb->statistics.counter--; \
323 if (ctdb->statistics_current.counter > 0) \
324 ctdb->statistics_current.counter--; \
327 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
329 ctdb_db->statistics.counter++; \
332 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
334 if (ctdb_db->statistics.counter > 0) \
335 ctdb_db->statistics.counter--; \
338 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
340 if (value > ctdb->statistics.counter.max) \
341 ctdb->statistics.counter.max = value; \
342 if (value > ctdb->statistics_current.counter.max) \
343 ctdb->statistics_current.counter.max = value; \
345 if (ctdb->statistics.counter.num == 0 || \
346 value < ctdb->statistics.counter.min) \
347 ctdb->statistics.counter.min = value; \
348 if (ctdb->statistics_current.counter.num == 0 || \
349 value < ctdb->statistics_current.counter.min) \
350 ctdb->statistics_current.counter.min = value; \
352 ctdb->statistics.counter.total += value; \
353 ctdb->statistics_current.counter.total += value; \
355 ctdb->statistics.counter.num++; \
356 ctdb->statistics_current.counter.num++; \
358 if (ctdb->tunable.reclock_latency_ms != 0) { \
359 if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
360 DEBUG(DEBUG_ERR, \
361 ("High RECLOCK latency %fs for operation %s\n", \
362 value, name)); \
367 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value) \
369 if (value > ctdb_db->statistics.counter.max) \
370 ctdb_db->statistics.counter.max = value; \
371 if (ctdb_db->statistics.counter.num == 0 || \
372 value < ctdb_db->statistics.counter.min) \
373 ctdb_db->statistics.counter.min = value; \
375 ctdb_db->statistics.counter.total += value; \
376 ctdb_db->statistics.counter.num++; \
378 if (ctdb_db->ctdb->tunable.log_latency_ms != 0) { \
379 if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) { \
380 DEBUG(DEBUG_ERR, \
381 ("High latency %.6fs for operation %s on database %s\n",\
382 value, operation, ctdb_db->db_name)); \
387 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
389 double l = timeval_elapsed(&t); \
391 if (l > ctdb->statistics.counter.max) \
392 ctdb->statistics.counter.max = l; \
393 if (l > ctdb->statistics_current.counter.max) \
394 ctdb->statistics_current.counter.max = l; \
396 if (ctdb->statistics.counter.num == 0 || \
397 l < ctdb->statistics.counter.min) \
398 ctdb->statistics.counter.min = l; \
399 if (ctdb->statistics_current.counter.num == 0 || \
400 l < ctdb->statistics_current.counter.min) \
401 ctdb->statistics_current.counter.min = l; \
403 ctdb->statistics.counter.total += l; \
404 ctdb->statistics_current.counter.total += l; \
406 ctdb->statistics.counter.num++; \
407 ctdb->statistics_current.counter.num++; \
409 if (ctdb->tunable.log_latency_ms != 0) { \
410 if (l*1000 > ctdb->tunable.log_latency_ms) { \
411 DEBUG(DEBUG_WARNING, \
412 ("High latency %.6fs for operation %s on database %s\n",\
413 l, operation, db->db_name)); \
420 /* a structure that contains the elements required for the write record
421 control
423 struct ctdb_write_record {
424 uint32_t dbid;
425 uint32_t keylen;
426 uint32_t datalen;
427 unsigned char blob[1];
430 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
432 enum ctdb_runstate {
433 CTDB_RUNSTATE_UNKNOWN,
434 CTDB_RUNSTATE_INIT,
435 CTDB_RUNSTATE_SETUP,
436 CTDB_RUNSTATE_FIRST_RECOVERY,
437 CTDB_RUNSTATE_STARTUP,
438 CTDB_RUNSTATE_RUNNING,
439 CTDB_RUNSTATE_SHUTDOWN,
442 const char *runstate_to_string(enum ctdb_runstate runstate);
443 enum ctdb_runstate runstate_from_string(const char *label);
444 void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate);
446 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code);
448 #define CTDB_MONITORING_ACTIVE 0
449 #define CTDB_MONITORING_DISABLED 1
451 #define NUM_DB_PRIORITIES 3
452 /* main state of the ctdb daemon */
453 struct ctdb_context {
454 struct tevent_context *ev;
455 struct timeval ctdbd_start_time;
456 struct timeval last_recovery_started;
457 struct timeval last_recovery_finished;
458 uint32_t recovery_mode;
459 TALLOC_CTX *tickle_update_context;
460 TALLOC_CTX *keepalive_ctx;
461 TALLOC_CTX *check_public_ifaces_ctx;
462 struct ctdb_tunable tunable;
463 enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
464 struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
465 bool freeze_transaction_started;
466 uint32_t freeze_transaction_id;
467 struct ctdb_address address;
468 const char *name;
469 const char *db_directory;
470 const char *db_directory_persistent;
471 const char *db_directory_state;
472 struct tdb_wrap *db_persistent_health;
473 uint32_t db_persistent_startup_generation;
474 uint64_t db_persistent_check_errors;
475 uint64_t max_persistent_check_errors;
476 const char *transport;
477 char *recovery_lock_file;
478 int recovery_lock_fd;
479 uint32_t pnn; /* our own pnn */
480 uint32_t num_nodes;
481 uint32_t num_connected;
482 unsigned flags;
483 uint32_t capabilities;
484 struct idr_context *idr;
485 int lastid;
486 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
487 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
488 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
489 struct ctdb_iface *ifaces; /* list of local interfaces */
490 char *err_msg;
491 const struct ctdb_methods *methods; /* transport methods */
492 const struct ctdb_upcalls *upcalls; /* transport upcalls */
493 void *private_data; /* private to transport */
494 struct ctdb_db_context *db_list;
495 struct ctdb_message_list_header *message_list_header;
496 struct tdb_context *message_list_indexdb;
497 struct ctdb_daemon_data daemon;
498 struct ctdb_statistics statistics;
499 struct ctdb_statistics statistics_current;
500 #define MAX_STAT_HISTORY 100
501 struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
502 struct ctdb_vnn_map *vnn_map;
503 uint32_t num_clients;
504 uint32_t recovery_master;
505 struct ctdb_call_state *pending_calls;
506 struct ctdb_client_ip *client_ip_list;
507 bool do_checkpublicip;
508 struct trbt_tree *server_ids;
509 bool do_setsched;
510 const char *event_script_dir;
511 const char *notification_script;
512 const char *default_public_interface;
513 pid_t ctdbd_pid;
514 pid_t recoverd_pid;
515 pid_t syslogd_pid;
516 enum ctdb_runstate runstate;
517 struct ctdb_monitor_state *monitor;
518 struct ctdb_log_state *log;
519 int start_as_disabled;
520 int start_as_stopped;
521 bool valgrinding;
522 uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
523 uint32_t *recd_ping_count;
524 TALLOC_CTX *recd_ctx; /* a context used to track recoverd monitoring events */
525 TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
527 TALLOC_CTX *event_script_ctx;
528 int active_events;
530 struct ctdb_event_script_state *current_monitor;
531 struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX];
533 TALLOC_CTX *banning_ctx;
535 struct ctdb_vacuum_child_context *vacuumers;
537 /* mapping from pid to ctdb_client * */
538 struct ctdb_client_pid_list *client_pids;
540 /* used in the recovery daemon to remember the ip allocation */
541 struct trbt_tree *ip_tree;
543 /* Used to defer db attach requests while in recovery mode */
544 struct ctdb_deferred_attach_context *deferred_attach;
546 /* if we are a child process, do we have a domain socket to send controls on */
547 bool can_send_controls;
549 /* list of event script callback functions that are active */
550 struct event_script_callback *script_callbacks;
552 struct ctdb_reloadips_handle *reload_ips;
554 const char *nodes_file;
555 const char *public_addresses_file;
556 struct trbt_tree *child_processes;
558 /* Used for locking record/db/alldb */
559 int lock_num_pending;
560 struct lock_context *lock_current;
561 struct lock_context *lock_pending;
564 struct ctdb_db_context {
565 struct ctdb_db_context *next, *prev;
566 struct ctdb_context *ctdb;
567 uint32_t db_id;
568 uint32_t priority;
569 bool persistent;
570 bool readonly; /* Do we support read-only delegations ? */
571 bool sticky; /* Do we support sticky records ? */
572 const char *db_name;
573 const char *db_path;
574 struct tdb_wrap *ltdb;
575 struct tdb_context *rottdb; /* ReadOnly tracking TDB */
576 struct ctdb_registered_call *calls; /* list of registered calls */
577 uint32_t seqnum;
578 struct timed_event *seqnum_update;
579 struct ctdb_traverse_local_handle *traverse;
580 struct ctdb_vacuum_handle *vacuum_handle;
581 char *unhealthy_reason;
582 int pending_requests;
583 struct revokechild_handle *revokechild_active;
584 struct ctdb_persistent_state *persistent_state;
585 struct trbt_tree *delete_queue;
586 struct trbt_tree *sticky_records;
587 int (*ctdb_ltdb_store_fn)(struct ctdb_db_context *ctdb_db,
588 TDB_DATA key,
589 struct ctdb_ltdb_header *header,
590 TDB_DATA data);
592 /* used to track which records we are currently fetching
593 so we can avoid sending duplicate fetch requests
595 struct trbt_tree *deferred_fetch;
597 struct ctdb_db_statistics statistics;
599 int lock_num_current;
603 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
604 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
605 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
606 return -1; }} while (0)
608 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
609 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
610 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
611 return; }} while (0)
613 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
614 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
615 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
616 return NULL; }} while (0)
618 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
619 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
620 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
621 }} while (0)
624 structure passed in set_call control
626 struct ctdb_control_set_call {
627 uint32_t db_id;
628 ctdb_fn_t fn;
629 uint32_t id;
633 struct for kill_tcp control
635 struct ctdb_control_killtcp {
636 ctdb_sock_addr src_addr;
637 ctdb_sock_addr dst_addr;
641 struct holding a ctdb_sock_addr and an interface name,
642 used to add/remove public addresses
644 struct ctdb_control_ip_iface {
645 ctdb_sock_addr addr;
646 uint32_t mask;
647 uint32_t len;
648 char iface[1];
652 struct holding a ctdb_sock_addr and an interface name,
653 used for send_gratious_arp
655 struct ctdb_control_gratious_arp {
656 ctdb_sock_addr addr;
657 uint32_t mask;
658 uint32_t len;
659 char iface[1];
663 persistent store control - update this record on all other nodes
665 struct ctdb_control_persistent_store {
666 uint32_t db_id;
667 uint32_t len;
668 uint8_t data[1];
672 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
674 struct ctdb_node_flag_change {
675 uint32_t pnn;
676 uint32_t new_flags;
677 uint32_t old_flags;
681 struct for admin setting a ban
683 struct ctdb_ban_info {
684 uint32_t pnn;
685 uint32_t ban_time;
688 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
690 #define CTDB_LMASTER_ANY 0xffffffff
693 state of a in-progress ctdb call
695 struct ctdb_call_state {
696 struct ctdb_call_state *next, *prev;
697 enum call_state state;
698 uint32_t reqid;
699 struct ctdb_req_call *c;
700 struct ctdb_db_context *ctdb_db;
701 const char *errmsg;
702 struct ctdb_call *call;
703 uint32_t generation;
704 struct {
705 void (*fn)(struct ctdb_call_state *);
706 void *private_data;
707 } async;
711 /* used for fetch_lock */
712 struct ctdb_fetch_handle {
713 struct ctdb_db_context *ctdb_db;
714 TDB_DATA key;
715 TDB_DATA *data;
716 struct ctdb_ltdb_header header;
719 /* internal prototypes */
720 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
721 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
722 void ctdb_die(struct ctdb_context *ctdb, const char *msg);
723 void ctdb_external_trace(void);
724 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
725 int ctdb_parse_address(struct ctdb_context *ctdb,
726 TALLOC_CTX *mem_ctx, const char *str,
727 struct ctdb_address *address);
728 bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
729 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
730 uint32_t ctdb_hash(const TDB_DATA *key);
731 uint32_t ctdb_hash_string(const char *str);
732 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
733 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
734 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
735 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
736 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
737 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
739 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
740 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
741 TDB_DATA key, struct ctdb_ltdb_header *header,
742 TALLOC_CTX *mem_ctx, TDB_DATA *data);
743 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
744 struct ctdb_ltdb_header *header, TDB_DATA data);
745 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
746 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context *ctdb_db,
747 TDB_DATA key, struct ctdb_ltdb_header *header,
748 TALLOC_CTX *mem_ctx, TDB_DATA *data);
749 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
750 struct ctdb_req_control *c,
751 TDB_DATA recdata);
752 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
753 struct ctdb_req_control *c,
754 TDB_DATA recdata);
755 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
756 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
757 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
758 TDB_DATA key, struct ctdb_req_header *hdr,
759 void (*recv_pkt)(void *, struct ctdb_req_header *),
760 void *recv_context, bool ignore_generation);
761 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
762 TDB_DATA key, struct ctdb_ltdb_header *header,
763 struct ctdb_req_header *hdr, TDB_DATA *data,
764 void (*recv_pkt)(void *, struct ctdb_req_header *),
765 void *recv_context, bool ignore_generation);
766 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
768 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
769 struct ctdb_call *call,
770 struct ctdb_ltdb_header *header,
771 TDB_DATA *data);
774 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork,
775 bool use_syslog);
776 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
777 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
780 queue a packet for sending
782 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
785 setup the fd used by the queue
787 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
790 setup a packet queue on a socket
792 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
793 TALLOC_CTX *mem_ctx, int fd, int alignment,
795 ctdb_queue_cb_fn_t callback,
796 void *private_data, const char *fmt, ...)
797 PRINTF_ATTRIBUTE(7,8);
800 allocate a packet for use in client<->daemon communication
802 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
803 TALLOC_CTX *mem_ctx,
804 enum ctdb_operation operation,
805 size_t length, size_t slength,
806 const char *type);
807 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
808 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
810 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
811 TALLOC_CTX *mem_ctx,
812 enum ctdb_operation operation,
813 size_t length, size_t slength,
814 const char *type);
815 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
816 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
818 int ctdb_queue_length(struct ctdb_queue *queue);
821 lock a record in the ltdb, given a key
823 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
826 unlock a record in the ltdb, given a key
828 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
832 make a ctdb call to the local daemon - async send. Called from client context.
834 This constructs a ctdb_call request and queues it for processing.
835 This call never blocks.
837 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
838 struct ctdb_call *call);
841 make a recv call to the local ctdb daemon - called from client context
843 This is called when the program wants to wait for a ctdb_call to complete and get the
844 results. This call will block unless the call has already completed.
846 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
848 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
849 uint64_t srvid, TDB_DATA data);
852 send a ctdb message
854 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
855 uint64_t srvid, TDB_DATA data);
858 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
859 struct ctdb_call *call);
861 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
863 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
864 struct ctdb_call *call,
865 struct ctdb_ltdb_header *header);
867 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
868 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx,
869 TDB_DATA *data, bool updatetdb);
871 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
873 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
875 int ctdb_socket_connect(struct ctdb_context *ctdb);
876 void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
878 #define CTDB_BAD_REQID ((uint32_t)-1)
879 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
880 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
881 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
883 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
884 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
886 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
887 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
888 TDB_DATA data,
889 ctdb_control_callback_fn_t callback,
890 void *private_data);
892 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
893 TDB_DATA *outdata, uint64_t tdb_flags,
894 bool persistent, uint32_t client_id,
895 struct ctdb_req_control *c,
896 bool *async_reply);
897 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
898 uint32_t client_id);
900 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
901 ctdb_fn_t fn, int id);
903 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
904 uint32_t opcode, uint32_t flags, TDB_DATA data,
905 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
906 struct timeval *timeout, char **errormsg);
907 int ctdb_control_recv(struct ctdb_context *ctdb,
908 struct ctdb_client_control_state *state,
909 TALLOC_CTX *mem_ctx,
910 TDB_DATA *outdata, int32_t *status, char **errormsg);
912 struct ctdb_client_control_state *
913 ctdb_control_send(struct ctdb_context *ctdb,
914 uint32_t destnode, uint64_t srvid,
915 uint32_t opcode, uint32_t flags, TDB_DATA data,
916 TALLOC_CTX *mem_ctx,
917 struct timeval *timeout,
918 char **errormsg);
923 #define CHECK_CONTROL_DATA_SIZE(size) do { \
924 if (indata.dsize != size) { \
925 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
926 opcode, (unsigned)indata.dsize, (unsigned)size)); \
927 return -1; \
929 } while (0)
931 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
932 if (indata.dsize < size) { \
933 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
934 opcode, (unsigned)indata.dsize, (unsigned)size)); \
935 return -1; \
937 } while (0)
939 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
940 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
941 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
942 int ctdb_control_getnodemapv4(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
943 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
944 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
947 /* structure used for pulldb control */
948 struct ctdb_control_pulldb {
949 uint32_t db_id;
950 uint32_t lmaster;
953 /* structure used for sending lists of records */
954 struct ctdb_marshall_buffer {
955 uint32_t db_id;
956 uint32_t count;
957 uint8_t data[1];
961 structure for setting a tunable
963 struct ctdb_control_set_tunable {
964 uint32_t value;
965 uint32_t length;
966 uint8_t name[1];
970 structure for getting a tunable
972 struct ctdb_control_get_tunable {
973 uint32_t length;
974 uint8_t name[1];
978 structure for listing tunables
980 struct ctdb_control_list_tunable {
981 uint32_t length;
982 /* returns a : separated list of tunable names */
983 uint8_t data[1];
987 struct ctdb_node_and_flagsv4 {
988 uint32_t pnn;
989 uint32_t flags;
990 struct sockaddr_in sin;
993 struct ctdb_node_mapv4 {
994 uint32_t num;
995 struct ctdb_node_and_flagsv4 nodes[1];
998 struct ctdb_control_wipe_database {
999 uint32_t db_id;
1000 uint32_t transaction_id;
1004 state of a in-progress ctdb call in client
1006 struct ctdb_client_call_state {
1007 enum call_state state;
1008 uint32_t reqid;
1009 struct ctdb_db_context *ctdb_db;
1010 struct ctdb_call *call;
1011 struct {
1012 void (*fn)(struct ctdb_client_call_state *);
1013 void *private_data;
1014 } async;
1018 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
1019 TDB_DATA indata,
1020 TDB_DATA *outdata,
1021 uint32_t srcnode,
1022 uint32_t client_id);
1023 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
1024 TDB_DATA *outdata, uint32_t srcnode, uint32_t client_id);
1025 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1026 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1027 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1028 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
1029 TDB_DATA *outdata, uint32_t srcnode);
1031 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1032 bool ctdb_check_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
1034 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1035 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1036 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1037 int daemon_check_srvids(struct ctdb_context *ctdb, TDB_DATA indata,
1038 TDB_DATA *outdata);
1040 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1041 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1043 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
1044 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1046 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
1047 uint32_t *reqid,
1048 struct ctdb_ltdb_header *header,
1049 TDB_DATA *key, TDB_DATA *data);
1051 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1052 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1054 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1055 struct ctdb_req_control *c,
1056 TDB_DATA indata, bool *async_reply,
1057 const char **errormsg);
1058 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1059 TDB_DATA *outdata, int32_t status, const char *errormsg);
1061 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1062 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority,
1063 bool check_recmode);
1065 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1066 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1068 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1070 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1071 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1072 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1073 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
1074 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1075 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1076 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1077 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1078 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1081 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1082 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1083 void ctdb_node_dead(struct ctdb_node *node);
1084 void ctdb_node_connected(struct ctdb_node *node);
1085 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1086 void set_scheduler(void);
1087 void reset_scheduler(void);
1089 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
1090 void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid);
1091 pid_t ctdb_fork(struct ctdb_context *ctdb);
1092 pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb);
1093 void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...);
1094 bool ctdb_is_child_process(void);
1095 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
1097 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1098 struct ctdb_req_control *c,
1099 TDB_DATA indata,
1100 bool *async_reply);
1101 int32_t ctdb_control_takeover_ipv4(struct ctdb_context *ctdb,
1102 struct ctdb_req_control *c,
1103 TDB_DATA indata,
1104 bool *async_reply);
1105 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1106 struct ctdb_req_control *c,
1107 TDB_DATA indata,
1108 bool *async_reply);
1109 int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb,
1110 struct ctdb_req_control *c,
1111 TDB_DATA indata,
1112 bool *async_reply);
1113 int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
1114 struct ctdb_req_control *c,
1115 bool *async_reply);
1116 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
1117 struct ctdb_req_control *c,
1118 bool *async_reply);
1119 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
1120 struct ctdb_req_control *c,
1121 bool *async_reply);
1123 struct ctdb_public_ipv4 {
1124 uint32_t pnn;
1125 struct sockaddr_in sin;
1128 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1129 uint32_t destnode, struct ctdb_public_ip *ip);
1130 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1131 uint32_t destnode, struct ctdb_public_ip *ip);
1133 struct ctdb_all_public_ipsv4 {
1134 uint32_t num;
1135 struct ctdb_public_ipv4 ips[1];
1138 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1139 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1140 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1141 struct timeval timeout,
1142 uint32_t destnode,
1143 TALLOC_CTX *mem_ctx,
1144 struct ctdb_all_public_ips **ips);
1145 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1146 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
1147 struct timeval timeout, uint32_t destnode,
1148 TALLOC_CTX *mem_ctx,
1149 uint32_t flags,
1150 struct ctdb_all_public_ips **ips);
1151 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb,
1152 struct timeval timeout, uint32_t destnode,
1153 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1155 struct ctdb_control_iface_info {
1156 char name[CTDB_IFACE_SIZE+2];
1157 uint16_t link_state;
1158 uint32_t references;
1161 struct ctdb_control_public_ip_info {
1162 struct ctdb_public_ip ip;
1163 uint32_t active_idx;
1164 uint32_t num;
1165 struct ctdb_control_iface_info ifaces[1];
1168 struct ctdb_control_get_ifaces {
1169 uint32_t num;
1170 struct ctdb_control_iface_info ifaces[1];
1173 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
1174 struct ctdb_req_control *c,
1175 TDB_DATA indata,
1176 TDB_DATA *outdata);
1177 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
1178 struct ctdb_req_control *c,
1179 TDB_DATA *outdata);
1180 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
1181 struct ctdb_req_control *c,
1182 TDB_DATA indata);
1183 int ctdb_ctrl_get_public_ip_info(struct ctdb_context *ctdb,
1184 struct timeval timeout, uint32_t destnode,
1185 TALLOC_CTX *mem_ctx,
1186 const ctdb_sock_addr *addr,
1187 struct ctdb_control_public_ip_info **info);
1188 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
1189 struct timeval timeout, uint32_t destnode,
1190 TALLOC_CTX *mem_ctx,
1191 struct ctdb_control_get_ifaces **ifaces);
1192 int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb,
1193 struct timeval timeout, uint32_t destnode,
1194 TALLOC_CTX *mem_ctx,
1195 const struct ctdb_control_iface_info *info);
1197 /* from takeover/system.c */
1198 uint32_t uint16_checksum(uint16_t *data, size_t n);
1199 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1200 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
1201 char *ctdb_sys_find_ifname(ctdb_sock_addr *addr);
1202 bool ctdb_sys_check_iface_exists(const char *iface);
1203 int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
1204 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
1205 const ctdb_sock_addr *src,
1206 uint32_t seq, uint32_t ack, int rst);
1208 /* Details of a byte range lock */
1209 struct ctdb_lock_info {
1210 ino_t inode;
1211 off_t start, end;
1212 bool waiting;
1213 bool read_only;
1216 char *ctdb_get_process_name(pid_t pid);
1217 int ctdb_set_process_name(const char *name);
1218 bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info);
1219 bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid);
1221 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1223 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
1224 int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
1225 const char *iface,
1226 const char *ip);
1227 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1228 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
1229 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap,
1230 uint32_t *force_rebalance_nodes,
1231 client_async_callback fail_callback, void *callback_data);
1233 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1234 TDB_DATA indata);
1235 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata, bool tcp_update_needed);
1236 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1237 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1238 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1239 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1240 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1241 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1243 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1244 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call);
1245 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
1246 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1247 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1248 TALLOC_CTX *mem_ctx,
1249 void (*callback)(struct ctdb_context *, int, void *),
1250 void *private_data,
1251 enum ctdb_eventscript_call call,
1252 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1253 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1255 void set_nonblocking(int fd);
1256 void set_close_on_exec(int fd);
1258 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1260 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1262 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1263 TDB_DATA *outdata);
1264 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1265 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1266 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1267 int32_t ctdb_control_receive_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1268 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1269 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
1270 struct ctdb_req_control *c,
1271 TDB_DATA recdata, bool *async_reply);
1273 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1275 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1277 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1278 struct timeval timeout,
1279 uint32_t destnode,
1280 struct ctdb_tunable *tunables);
1282 void ctdb_start_freeze(struct ctdb_context *ctdb, uint32_t priority);
1284 bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask);
1285 bool parse_ip_port(const char *s, ctdb_sock_addr *addr);
1286 bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr);
1287 bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin);
1290 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1291 int ctdb_sys_close_capture_socket(void *private_data);
1292 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);
1294 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1295 struct timeval timeout,
1296 uint32_t destnode,
1297 struct ctdb_control_killtcp *killtcp);
1299 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1300 struct timeval timeout,
1301 uint32_t destnode,
1302 struct ctdb_control_ip_iface *pub);
1304 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1305 struct timeval timeout,
1306 uint32_t destnode,
1307 struct ctdb_control_ip_iface *pub);
1309 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1310 struct timeval timeout,
1311 uint32_t destnode,
1312 ctdb_sock_addr *addr,
1313 const char *ifname);
1315 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1316 struct timeval timeout,
1317 uint32_t destnode,
1318 TALLOC_CTX *mem_ctx,
1319 ctdb_sock_addr *addr,
1320 struct ctdb_control_tcp_tickle_list **list);
1323 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1324 uint32_t client_id,
1325 TDB_DATA indata);
1326 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1327 TDB_DATA indata);
1328 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1329 TDB_DATA indata);
1330 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1331 TDB_DATA *outdata);
1332 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1333 TDB_DATA *outdata);
1335 int ctdb_attach_databases(struct ctdb_context *ctdb);
1337 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1338 struct ctdb_req_control *c,
1339 TDB_DATA recdata, bool *async_reply);
1340 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1341 struct ctdb_req_control *c, TDB_DATA recdata,
1342 bool *async_reply);
1343 int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb,
1344 struct ctdb_req_control *c,
1345 TDB_DATA recdata, bool *async_reply);
1347 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
1348 struct ctdb_req_control *c,
1349 TDB_DATA recdata, bool *async_reply);
1351 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
1353 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1354 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1355 int32_t ctdb_control_transaction_cancel(struct ctdb_context *ctdb);
1356 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1357 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb, TDB_DATA indata);
1358 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
1359 TDB_DATA indata,
1360 TDB_DATA *outdata);
1363 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1364 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1366 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1367 bool ctdb_stopped_monitoring(struct ctdb_context *ctdb);
1368 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1369 void lockdown_memory(bool valgrinding);
1371 struct client_async_data {
1372 enum ctdb_controls opcode;
1373 bool dont_log_errors;
1374 uint32_t count;
1375 uint32_t fail_count;
1376 client_async_callback callback;
1377 client_async_callback fail_callback;
1378 void *callback_data;
1380 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1381 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1382 int ctdb_client_async_control(struct ctdb_context *ctdb,
1383 enum ctdb_controls opcode,
1384 uint32_t *nodes,
1385 uint64_t srvid,
1386 struct timeval timeout,
1387 bool dont_log_errors,
1388 TDB_DATA data,
1389 client_async_callback client_callback,
1390 client_async_callback fail_callback,
1391 void *callback_data);
1393 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1395 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1397 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1398 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1400 int32_t ctdb_control_trans2_finished(struct ctdb_context *ctdb,
1401 struct ctdb_req_control *c);
1402 int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb,
1403 struct ctdb_req_control *c);
1404 int32_t ctdb_control_trans2_active(struct ctdb_context *ctdb,
1405 struct ctdb_req_control *c,
1406 uint32_t db_id);
1408 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
1409 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
1410 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
1412 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
1413 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata);
1415 extern int script_log_level;
1416 extern bool fast_start;
1417 extern const char *ctdbd_pidfile;
1419 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1420 uint32_t call_type,
1421 TDB_DATA *outdata);
1423 int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
1424 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
1426 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
1427 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
1429 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
1430 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1432 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1433 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1435 void ctdb_local_node_got_banned(struct ctdb_context *ctdb);
1436 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
1437 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
1438 int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata,
1439 uint32_t client_id);
1440 void ctdb_ban_self(struct ctdb_context *ctdb);
1442 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1444 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1446 int start_syslog_daemon(struct ctdb_context *ctdb);
1448 /* Where to send the log messages back to */
1449 struct ctdb_get_log_addr {
1450 uint32_t pnn;
1451 uint64_t srvid;
1452 int32_t level;
1455 extern int log_ringbuf_size;
1457 TDB_DATA ctdb_log_ringbuffer_collect_log(TALLOC_CTX *mem_ctx,
1458 enum debug_level max_level);
1459 void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr);
1460 void ctdb_clear_log(struct ctdb_context *ctdb);
1461 int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
1462 int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
1463 void ctdb_log_ringbuffer_free(void);
1465 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
1466 struct ctdb_context *ctdb,
1467 const char *log_prefix,
1468 const char *helper,
1469 int helper_argc,
1470 const char **helper_argv,
1471 void (*logfn)(const char *, uint16_t, void *),
1472 void *logfn_private, pid_t *pid);
1475 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
1476 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
1478 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
1479 TDB_DATA indata,
1480 TDB_DATA *outdata);
1482 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
1483 struct ctdb_db_context *ctdb_db);
1484 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
1485 struct ctdb_db_context *ctdb_db,
1486 const char *reason,/* NULL means healthy */
1487 int num_healthy_nodes);
1488 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
1490 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
1492 void ctdb_fault_setup(void);
1494 int verify_remote_ip_allocation(struct ctdb_context *ctdb,
1495 struct ctdb_all_public_ips *ips,
1496 uint32_t pnn);
1497 int update_ip_assignment_tree(struct ctdb_context *ctdb,
1498 struct ctdb_public_ip *ip);
1500 int ctdb_init_tevent_logging(struct ctdb_context *ctdb);
1502 int ctdb_statistics_init(struct ctdb_context *ctdb);
1504 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
1505 struct ctdb_req_control *c,
1506 TDB_DATA *outdata);
1508 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
1510 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
1513 * structure to pass to a schedule_for_deletion_control
1515 struct ctdb_control_schedule_for_deletion {
1516 uint32_t db_id;
1517 struct ctdb_ltdb_header hdr;
1518 uint32_t keylen;
1519 uint8_t key[1]; /* key[] */
1522 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
1523 TDB_DATA indata);
1526 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
1527 const struct ctdb_ltdb_header *hdr,
1528 TDB_DATA key);
1530 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
1531 const struct ctdb_ltdb_header *hdr,
1532 const TDB_DATA key);
1534 struct ctdb_ltdb_header *ctdb_header_from_record_handle(struct ctdb_record_handle *h);
1536 int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
1538 typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn, void *private_data);
1540 void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_trackingdb_cb cb, void *private_data);
1542 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);
1544 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
1546 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);
1548 int ctdb_set_db_readonly(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1550 int ctdb_null_func(struct ctdb_call_info *call);
1552 int ctdb_fetch_func(struct ctdb_call_info *call);
1554 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
1556 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
1557 uint32_t db_id,
1558 TDB_DATA *outdata);
1560 int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1563 description for a message to reload all ips via recovery master/daemon
1565 struct reloadips_all_reply {
1566 uint32_t pnn;
1567 uint64_t srvid;
1570 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1572 int ctdb_start_monitoring_interfaces(struct ctdb_context *ctdb);
1574 /* from server/ctdb_lock.c */
1575 struct lock_request;
1577 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority);
1578 int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority);
1580 void ctdb_lock_free_request_context(struct lock_request *lock_req);
1582 struct lock_request *ctdb_lock_record(struct ctdb_db_context *ctdb_db,
1583 TDB_DATA key,
1584 bool auto_mark,
1585 void (*callback)(void *, bool),
1586 void *private_data);
1588 struct lock_request *ctdb_lock_db(struct ctdb_db_context *ctdb_db,
1589 bool auto_mark,
1590 void (*callback)(void *, bool),
1591 void *private_data);
1593 struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb,
1594 uint32_t priority,
1595 bool auto_mark,
1596 void (*callback)(void *, bool),
1597 void *private_data);
1599 struct lock_request *ctdb_lock_alldb(struct ctdb_context *ctdb,
1600 bool auto_mark,
1601 void (*callback)(void *, bool),
1602 void *private_data);
1604 int mkdir_p(const char *dir, int mode);
1605 void mkdir_p_or_die(const char *dir, int mode);
1607 #endif