s4-dsdb when setting DSDB_CONTROL_PASSWORD_BYPASS_LAST_SET_OID make it non-critical
[Samba/gbeck.git] / ctdb / include / ctdb_private.h
blob0f9da360c61c5c1144e0c1d291b661308f682bbb
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 recovery daemon memdump reply address
29 struct rd_memdump_reply {
30 uint32_t pnn;
31 uint64_t srvid;
35 description for a TAKEOVER_RUN message reply address
37 struct takeover_run_reply {
38 uint32_t pnn;
39 uint64_t srvid;
43 * pid of the ctdbd daemon
45 extern pid_t ctdbd_pid;
48 a tcp connection description
49 also used by tcp_add and tcp_remove controls
51 struct ctdb_tcp_connection {
52 ctdb_sock_addr src_addr;
53 ctdb_sock_addr dst_addr;
56 /* the wire representation for a tcp tickle array */
57 struct ctdb_tcp_wire_array {
58 uint32_t num;
59 struct ctdb_tcp_connection connections[1];
60 };
62 /* the list of tcp tickles used by get/set tcp tickle list */
63 struct ctdb_control_tcp_tickle_list {
64 ctdb_sock_addr addr;
65 struct ctdb_tcp_wire_array tickles;
69 array of tcp connections
71 struct ctdb_tcp_array {
72 uint32_t num;
73 struct ctdb_tcp_connection *connections;
74 };
77 /* all tunable variables go in here */
78 struct ctdb_tunable {
79 uint32_t max_redirect_count;
80 uint32_t seqnum_interval; /* unit is ms */
81 uint32_t control_timeout;
82 uint32_t traverse_timeout;
83 uint32_t keepalive_interval;
84 uint32_t keepalive_limit;
85 uint32_t recover_timeout;
86 uint32_t recover_interval;
87 uint32_t election_timeout;
88 uint32_t takeover_timeout;
89 uint32_t monitor_interval;
90 uint32_t tickle_update_interval;
91 uint32_t script_timeout;
92 uint32_t script_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
93 uint32_t script_unhealthy_on_timeout; /* obsolete */
94 uint32_t recovery_grace_period;
95 uint32_t recovery_ban_period;
96 uint32_t database_hash_size;
97 uint32_t database_max_dead;
98 uint32_t rerecovery_timeout;
99 uint32_t enable_bans;
100 uint32_t deterministic_public_ips;
101 uint32_t reclock_ping_period;
102 uint32_t no_ip_failback;
103 uint32_t disable_ip_failover;
104 uint32_t verbose_memory_names;
105 uint32_t recd_ping_timeout;
106 uint32_t recd_ping_failcount;
107 uint32_t log_latency_ms;
108 uint32_t reclock_latency_ms;
109 uint32_t recovery_drop_all_ips;
110 uint32_t verify_recovery_lock;
111 uint32_t vacuum_interval;
112 uint32_t vacuum_default_interval;
113 uint32_t vacuum_max_run_time;
114 uint32_t repack_limit;
115 uint32_t vacuum_limit;
116 uint32_t vacuum_min_interval;
117 uint32_t vacuum_max_interval;
118 uint32_t max_queue_depth_drop_msg;
119 uint32_t use_status_events_for_monitoring;
120 uint32_t allow_unhealthy_db_read;
121 uint32_t stat_history_interval;
122 uint32_t deferred_attach_timeout;
123 uint32_t vacuum_fast_path_count;
124 uint32_t lcp2_public_ip_assignment;
125 uint32_t allow_client_db_attach;
126 uint32_t recover_pdb_by_seqnum;
127 uint32_t deferred_rebalance_on_node_add;
128 uint32_t fetch_collapse;
129 uint32_t max_lacount;
130 uint32_t hopcount_make_sticky;
131 uint32_t sticky_duration;
132 uint32_t sticky_pindown;
133 uint32_t no_ip_takeover;
134 uint32_t db_record_count_warn;
135 uint32_t db_record_size_warn;
136 uint32_t db_size_warn;
137 uint32_t pulldb_preallocation_size;
141 an installed ctdb remote call
143 struct ctdb_registered_call {
144 struct ctdb_registered_call *next, *prev;
145 uint32_t id;
146 ctdb_fn_t fn;
150 this address structure might need to be generalised later for some
151 transports
153 struct ctdb_address {
154 const char *address;
155 int port;
159 check that a pnn is valid
161 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
164 /* called from the queue code when a packet comes in. Called with data==NULL
165 on error */
166 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
167 void *private_data);
169 /* used for callbacks in ctdb_control requests */
170 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
171 int32_t status, TDB_DATA data,
172 const char *errormsg,
173 void *private_data);
175 structure describing a connected client in the daemon
177 struct ctdb_client {
178 struct ctdb_context *ctdb;
179 int fd;
180 struct ctdb_queue *queue;
181 uint32_t client_id;
182 pid_t pid;
183 struct ctdb_tcp_list *tcp_list;
184 uint32_t db_id;
185 uint32_t num_persistent_updates;
186 struct ctdb_client_notify_list *notify;
189 struct ctdb_iface;
191 /* state associated with a public ip address */
192 struct ctdb_vnn {
193 struct ctdb_vnn *prev, *next;
195 struct ctdb_iface *iface;
196 const char **ifaces;
197 ctdb_sock_addr public_address;
198 uint8_t public_netmask_bits;
200 /* the node number that is serving this public address, if any.
201 If no node serves this ip it is set to -1 */
202 int32_t pnn;
204 /* List of clients to tickle for this public address */
205 struct ctdb_tcp_array *tcp_array;
207 /* whether we need to update the other nodes with changes to our list
208 of connected clients */
209 bool tcp_update_needed;
211 /* a context to hang sending gratious arp events off */
212 TALLOC_CTX *takeover_ctx;
214 struct ctdb_kill_tcp *killtcp;
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 {
283 struct ctdb_context *ctdb;
284 struct ctdb_message_list *next, *prev;
285 uint64_t srvid;
286 ctdb_msg_fn_t message_handler;
287 void *message_private;
290 /* additional data required for the daemon mode */
291 struct ctdb_daemon_data {
292 int sd;
293 char *name;
294 struct ctdb_queue *queue;
298 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
300 if (value > ctdb->statistics.counter) { \
301 ctdb->statistics.counter = c->hopcount; \
303 if (value > ctdb->statistics_current.counter) { \
304 ctdb->statistics_current.counter = c->hopcount; \
308 #define CTDB_INCREMENT_STAT(ctdb, counter) \
310 ctdb->statistics.counter++; \
311 ctdb->statistics_current.counter++; \
314 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
316 ctdb_db->statistics.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_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
329 if (value > ctdb->statistics.counter.max) \
330 ctdb->statistics.counter.max = value; \
331 if (value > ctdb->statistics_current.counter.max) \
332 ctdb->statistics_current.counter.max = value; \
334 if (ctdb->statistics.counter.num == 0 || value < ctdb->statistics.counter.min) \
335 ctdb->statistics.counter.min = value; \
336 if (ctdb->statistics_current.counter.num == 0 || value < ctdb->statistics_current.counter.min) \
337 ctdb->statistics_current.counter.min = value; \
339 ctdb->statistics.counter.total += value; \
340 ctdb->statistics_current.counter.total += value; \
342 ctdb->statistics.counter.num++; \
343 ctdb->statistics_current.counter.num++; \
345 if (ctdb->tunable.reclock_latency_ms != 0) { \
346 if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
347 DEBUG(DEBUG_ERR, ("High RECLOCK latency %fs for operation %s\n", value, name)); \
353 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
355 double l = timeval_elapsed(&t); \
357 if (l > ctdb->statistics.counter.max) \
358 ctdb->statistics.counter.max = l; \
359 if (l > ctdb->statistics_current.counter.max) \
360 ctdb->statistics_current.counter.max = l; \
362 if (ctdb->statistics.counter.num == 0 || l < ctdb->statistics.counter.min) \
363 ctdb->statistics.counter.min = l; \
364 if (ctdb->statistics_current.counter.num == 0 || l < ctdb->statistics_current.counter.min) \
365 ctdb->statistics_current.counter.min = l; \
367 ctdb->statistics.counter.total += l; \
368 ctdb->statistics_current.counter.total += l; \
370 ctdb->statistics.counter.num++; \
371 ctdb->statistics_current.counter.num++; \
373 if (ctdb->tunable.log_latency_ms !=0) { \
374 if (l*1000 > ctdb->tunable.log_latency_ms) { \
375 DEBUG(DEBUG_WARNING, ("High latency %.6fs for operation %s on database %s\n", l, operation, db->db_name));\
382 /* a structure that contains the elements required for the write record
383 control
385 struct ctdb_write_record {
386 uint32_t dbid;
387 uint32_t keylen;
388 uint32_t datalen;
389 unsigned char blob[1];
392 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
394 #define CTDB_MONITORING_ACTIVE 0
395 #define CTDB_MONITORING_DISABLED 1
397 /* The different capabilities of the ctdb daemon. */
398 #define CTDB_CAP_RECMASTER 0x00000001
399 #define CTDB_CAP_LMASTER 0x00000002
400 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
401 #define CTDB_CAP_LVS 0x00000004
402 /* This capability is set if NATGW is enabled */
403 #define CTDB_CAP_NATGW 0x00000008
405 #define NUM_DB_PRIORITIES 3
406 /* main state of the ctdb daemon */
407 struct ctdb_context {
408 struct tevent_context *ev;
409 struct timeval ctdbd_start_time;
410 struct timeval last_recovery_started;
411 struct timeval last_recovery_finished;
412 uint32_t recovery_mode;
413 TALLOC_CTX *tickle_update_context;
414 TALLOC_CTX *keepalive_ctx;
415 TALLOC_CTX *check_public_ifaces_ctx;
416 struct ctdb_tunable tunable;
417 enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
418 struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
419 bool freeze_transaction_started;
420 uint32_t freeze_transaction_id;
421 struct ctdb_address address;
422 const char *name;
423 const char *db_directory;
424 const char *db_directory_persistent;
425 const char *db_directory_state;
426 struct tdb_wrap *db_persistent_health;
427 uint32_t db_persistent_startup_generation;
428 uint64_t db_persistent_check_errors;
429 uint64_t max_persistent_check_errors;
430 const char *transport;
431 char *recovery_lock_file;
432 int recovery_lock_fd;
433 uint32_t pnn; /* our own pnn */
434 uint32_t num_nodes;
435 uint32_t num_connected;
436 unsigned flags;
437 uint32_t capabilities;
438 struct idr_context *idr;
439 int lastid;
440 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
441 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
442 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
443 struct ctdb_iface *ifaces; /* list of local interfaces */
444 char *err_msg;
445 const struct ctdb_methods *methods; /* transport methods */
446 const struct ctdb_upcalls *upcalls; /* transport upcalls */
447 void *private_data; /* private to transport */
448 struct ctdb_db_context *db_list;
449 struct ctdb_message_list *message_list;
450 struct ctdb_daemon_data daemon;
451 struct ctdb_statistics statistics;
452 struct ctdb_statistics statistics_current;
453 #define MAX_STAT_HISTORY 100
454 struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
455 struct ctdb_vnn_map *vnn_map;
456 uint32_t num_clients;
457 uint32_t recovery_master;
458 struct ctdb_call_state *pending_calls;
459 struct ctdb_client_ip *client_ip_list;
460 bool do_checkpublicip;
461 struct trbt_tree *server_ids;
462 bool do_setsched;
463 void *saved_scheduler_param;
464 const char *event_script_dir;
465 const char *debug_hung_script;
466 const char *notification_script;
467 const char *default_public_interface;
468 pid_t ctdbd_pid;
469 pid_t recoverd_pid;
470 pid_t syslogd_pid;
471 bool done_startup;
472 const char *node_ip;
473 struct ctdb_monitor_state *monitor;
474 struct ctdb_log_state *log;
475 int start_as_disabled;
476 int start_as_stopped;
477 bool valgrinding;
478 uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
479 uint32_t *recd_ping_count;
480 TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
482 TALLOC_CTX *event_script_ctx;
484 struct ctdb_event_script_state *current_monitor;
485 struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX];
487 TALLOC_CTX *banning_ctx;
489 struct ctdb_vacuum_child_context *vacuumers;
491 /* mapping from pid to ctdb_client * */
492 struct ctdb_client_pid_list *client_pids;
494 /* used in the recovery daemon to remember the ip allocation */
495 struct trbt_tree *ip_tree;
497 /* Used to defer db attach requests while in recovery mode */
498 struct ctdb_deferred_attach_context *deferred_attach;
500 /* if we are a child process, do we have a domain socket to send controls on */
501 bool can_send_controls;
503 /* list of event script callback functions that are active */
504 struct event_script_callback *script_callbacks;
506 struct ctdb_reloadips_handle *reload_ips;
508 const char *public_addresses_file;
509 struct trbt_tree *child_processes;
510 TALLOC_CTX *debug_hung_script_ctx;
513 struct ctdb_db_context {
514 struct ctdb_db_context *next, *prev;
515 struct ctdb_context *ctdb;
516 uint32_t db_id;
517 uint32_t priority;
518 bool persistent;
519 bool readonly; /* Do we support read-only delegations ? */
520 bool sticky; /* Do we support sticky records ? */
521 const char *db_name;
522 const char *db_path;
523 struct tdb_wrap *ltdb;
524 struct tdb_context *rottdb; /* ReadOnly tracking TDB */
525 struct ctdb_registered_call *calls; /* list of registered calls */
526 uint32_t seqnum;
527 struct timed_event *seqnum_update;
528 struct ctdb_traverse_local_handle *traverse;
529 bool transaction_active;
530 struct ctdb_vacuum_handle *vacuum_handle;
531 char *unhealthy_reason;
532 int pending_requests;
533 struct lockwait_handle *lockwait_active;
534 struct lockwait_handle *lockwait_overflow;
535 struct revokechild_handle *revokechild_active;
536 struct ctdb_persistent_state *persistent_state;
537 struct trbt_tree *delete_queue;
538 struct trbt_tree *sticky_records;
539 int (*ctdb_ltdb_store_fn)(struct ctdb_db_context *ctdb_db,
540 TDB_DATA key,
541 struct ctdb_ltdb_header *header,
542 TDB_DATA data);
544 /* used to track which records we are currently fetching
545 so we can avoid sending duplicate fetch requests
547 struct trbt_tree *deferred_fetch;
549 struct ctdb_db_statistics statistics;
553 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
554 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
555 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
556 return -1; }} while (0)
558 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
559 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
560 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
561 return; }} while (0)
563 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
564 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
565 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
566 return NULL; }} while (0)
568 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
569 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
570 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
571 }} while (0)
574 structure passed in set_call control
576 struct ctdb_control_set_call {
577 uint32_t db_id;
578 ctdb_fn_t fn;
579 uint32_t id;
583 struct for kill_tcp control
585 struct ctdb_control_killtcp {
586 ctdb_sock_addr src_addr;
587 ctdb_sock_addr dst_addr;
591 struct holding a ctdb_sock_addr and an interface name,
592 used to add/remove public addresses
594 struct ctdb_control_ip_iface {
595 ctdb_sock_addr addr;
596 uint32_t mask;
597 uint32_t len;
598 char iface[1];
602 struct holding a ctdb_sock_addr and an interface name,
603 used for send_gratious_arp
605 struct ctdb_control_gratious_arp {
606 ctdb_sock_addr addr;
607 uint32_t mask;
608 uint32_t len;
609 char iface[1];
613 persistent store control - update this record on all other nodes
615 struct ctdb_control_persistent_store {
616 uint32_t db_id;
617 uint32_t len;
618 uint8_t data[1];
622 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
624 struct ctdb_node_flag_change {
625 uint32_t pnn;
626 uint32_t new_flags;
627 uint32_t old_flags;
631 struct for admin setting a ban
633 struct ctdb_ban_info {
634 uint32_t pnn;
635 uint32_t ban_time;
638 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
640 #define CTDB_LMASTER_ANY 0xffffffff
643 state of a in-progress ctdb call
645 struct ctdb_call_state {
646 struct ctdb_call_state *next, *prev;
647 enum call_state state;
648 uint32_t reqid;
649 struct ctdb_req_call *c;
650 struct ctdb_db_context *ctdb_db;
651 const char *errmsg;
652 struct ctdb_call *call;
653 uint32_t generation;
654 struct {
655 void (*fn)(struct ctdb_call_state *);
656 void *private_data;
657 } async;
661 /* used for fetch_lock */
662 struct ctdb_fetch_handle {
663 struct ctdb_db_context *ctdb_db;
664 TDB_DATA key;
665 TDB_DATA *data;
666 struct ctdb_ltdb_header header;
669 /* internal prototypes */
670 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
671 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
672 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
673 int ctdb_parse_address(struct ctdb_context *ctdb,
674 TALLOC_CTX *mem_ctx, const char *str,
675 struct ctdb_address *address);
676 bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
677 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
678 uint32_t ctdb_hash(const TDB_DATA *key);
679 uint32_t ctdb_hash_string(const char *str);
680 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
681 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
682 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
683 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
684 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
685 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
687 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
688 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
689 TDB_DATA key, struct ctdb_ltdb_header *header,
690 TALLOC_CTX *mem_ctx, TDB_DATA *data);
691 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
692 struct ctdb_ltdb_header *header, TDB_DATA data);
693 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
694 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context *ctdb_db,
695 TDB_DATA key, struct ctdb_ltdb_header *header,
696 TALLOC_CTX *mem_ctx, TDB_DATA *data);
697 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
698 struct ctdb_req_control *c,
699 TDB_DATA recdata);
700 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
701 struct ctdb_req_control *c,
702 TDB_DATA recdata);
703 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
704 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
705 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
706 TDB_DATA key, struct ctdb_req_header *hdr,
707 void (*recv_pkt)(void *, struct ctdb_req_header *),
708 void *recv_context, bool ignore_generation);
709 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
710 TDB_DATA key, struct ctdb_ltdb_header *header,
711 struct ctdb_req_header *hdr, TDB_DATA *data,
712 void (*recv_pkt)(void *, struct ctdb_req_header *),
713 void *recv_context, bool ignore_generation);
714 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
716 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
717 struct ctdb_call *call,
718 struct ctdb_ltdb_header *header,
719 TDB_DATA *data);
722 int ctdbd_start(struct ctdb_context *ctdb);
723 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
724 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
727 queue a packet for sending
729 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
732 setup the fd used by the queue
734 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
737 setup a packet queue on a socket
739 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
740 TALLOC_CTX *mem_ctx, int fd, int alignment,
742 ctdb_queue_cb_fn_t callback,
743 void *private_data, const char *fmt, ...)
744 PRINTF_ATTRIBUTE(7,8);
747 allocate a packet for use in client<->daemon communication
749 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
750 TALLOC_CTX *mem_ctx,
751 enum ctdb_operation operation,
752 size_t length, size_t slength,
753 const char *type);
754 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
755 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
757 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
758 TALLOC_CTX *mem_ctx,
759 enum ctdb_operation operation,
760 size_t length, size_t slength,
761 const char *type);
762 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
763 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
765 int ctdb_queue_length(struct ctdb_queue *queue);
768 lock a record in the ltdb, given a key
770 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
773 unlock a record in the ltdb, given a key
775 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
779 make a ctdb call to the local daemon - async send. Called from client context.
781 This constructs a ctdb_call request and queues it for processing.
782 This call never blocks.
784 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
785 struct ctdb_call *call);
788 make a recv call to the local ctdb daemon - called from client context
790 This is called when the program wants to wait for a ctdb_call to complete and get the
791 results. This call will block unless the call has already completed.
793 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
795 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
796 uint64_t srvid, TDB_DATA data);
799 send a ctdb message
801 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
802 uint64_t srvid, TDB_DATA data);
805 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
806 TDB_DATA key,
807 void (*callback)(void *), void *private_data);
809 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
810 struct ctdb_call *call);
812 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
814 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
815 struct ctdb_call *call,
816 struct ctdb_ltdb_header *header);
818 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
819 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx,
820 TDB_DATA *data, bool updatetdb, uint32_t caller);
822 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
824 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
826 int ctdb_socket_connect(struct ctdb_context *ctdb);
827 void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
829 #define CTDB_BAD_REQID ((uint32_t)-1)
830 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
831 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
832 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
834 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
835 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
837 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
838 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
839 TDB_DATA data,
840 ctdb_control_callback_fn_t callback,
841 void *private_data);
843 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
844 TDB_DATA *outdata, uint64_t tdb_flags,
845 bool persistent, uint32_t client_id,
846 struct ctdb_req_control *c,
847 bool *async_reply);
849 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
850 ctdb_fn_t fn, int id);
852 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
853 uint32_t opcode, uint32_t flags, TDB_DATA data,
854 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
855 struct timeval *timeout, char **errormsg);
856 int ctdb_control_recv(struct ctdb_context *ctdb,
857 struct ctdb_client_control_state *state,
858 TALLOC_CTX *mem_ctx,
859 TDB_DATA *outdata, int32_t *status, char **errormsg);
861 struct ctdb_client_control_state *
862 ctdb_control_send(struct ctdb_context *ctdb,
863 uint32_t destnode, uint64_t srvid,
864 uint32_t opcode, uint32_t flags, TDB_DATA data,
865 TALLOC_CTX *mem_ctx,
866 struct timeval *timeout,
867 char **errormsg);
872 #define CHECK_CONTROL_DATA_SIZE(size) do { \
873 if (indata.dsize != size) { \
874 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
875 opcode, (unsigned)indata.dsize, (unsigned)size)); \
876 return -1; \
878 } while (0)
880 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
881 if (indata.dsize < size) { \
882 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
883 opcode, (unsigned)indata.dsize, (unsigned)size)); \
884 return -1; \
886 } while (0)
888 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
889 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
890 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
891 int ctdb_control_getnodemapv4(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
892 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
893 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
896 /* structure used for pulldb control */
897 struct ctdb_control_pulldb {
898 uint32_t db_id;
899 uint32_t lmaster;
902 /* structure used for sending lists of records */
903 struct ctdb_marshall_buffer {
904 uint32_t db_id;
905 uint32_t count;
906 uint8_t data[1];
909 /* set dmaster control structure */
910 struct ctdb_control_set_dmaster {
911 uint32_t db_id;
912 uint32_t dmaster;
916 structure for setting a tunable
918 struct ctdb_control_set_tunable {
919 uint32_t value;
920 uint32_t length;
921 uint8_t name[1];
925 structure for getting a tunable
927 struct ctdb_control_get_tunable {
928 uint32_t length;
929 uint8_t name[1];
933 structure for listing tunables
935 struct ctdb_control_list_tunable {
936 uint32_t length;
937 /* returns a : separated list of tunable names */
938 uint8_t data[1];
942 struct ctdb_node_and_flagsv4 {
943 uint32_t pnn;
944 uint32_t flags;
945 struct sockaddr_in sin;
948 struct ctdb_node_mapv4 {
949 uint32_t num;
950 struct ctdb_node_and_flagsv4 nodes[1];
953 struct ctdb_control_wipe_database {
954 uint32_t db_id;
955 uint32_t transaction_id;
959 state of a in-progress ctdb call in client
961 struct ctdb_client_call_state {
962 enum call_state state;
963 uint32_t reqid;
964 struct ctdb_db_context *ctdb_db;
965 struct ctdb_call *call;
966 struct {
967 void (*fn)(struct ctdb_client_call_state *);
968 void *private_data;
969 } async;
973 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
974 TDB_DATA indata,
975 TDB_DATA *outdata,
976 uint32_t srcnode,
977 uint32_t client_id);
978 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
979 TDB_DATA *outdata, uint32_t srcnode, uint32_t client_id);
980 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
981 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
982 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
983 TDB_DATA *outdata, uint32_t srcnode);
985 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
987 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
988 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
989 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
990 int daemon_check_srvids(struct ctdb_context *ctdb, TDB_DATA indata,
991 TDB_DATA *outdata);
993 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
994 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
996 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
997 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
999 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
1000 uint32_t *reqid,
1001 struct ctdb_ltdb_header *header,
1002 TDB_DATA *key, TDB_DATA *data);
1004 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1005 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1006 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1008 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1009 struct ctdb_req_control *c,
1010 TDB_DATA indata, bool *async_reply,
1011 const char **errormsg);
1012 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1013 TDB_DATA *outdata, int32_t status, const char *errormsg);
1015 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1016 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority);
1018 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1019 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1021 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1023 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1024 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1025 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1026 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1027 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1028 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1029 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1030 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1031 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1034 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1035 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1036 void ctdb_node_dead(struct ctdb_node *node);
1037 void ctdb_node_connected(struct ctdb_node *node);
1038 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1039 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1040 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1042 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
1043 pid_t ctdb_fork(struct ctdb_context *ctdb);
1044 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
1046 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1047 struct ctdb_req_control *c,
1048 TDB_DATA indata,
1049 bool *async_reply);
1050 int32_t ctdb_control_takeover_ipv4(struct ctdb_context *ctdb,
1051 struct ctdb_req_control *c,
1052 TDB_DATA indata,
1053 bool *async_reply);
1054 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1055 struct ctdb_req_control *c,
1056 TDB_DATA indata,
1057 bool *async_reply);
1058 int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb,
1059 struct ctdb_req_control *c,
1060 TDB_DATA indata,
1061 bool *async_reply);
1062 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
1063 struct ctdb_req_control *c,
1064 bool *async_reply);
1065 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
1066 struct ctdb_req_control *c,
1067 bool *async_reply);
1069 struct ctdb_public_ipv4 {
1070 uint32_t pnn;
1071 struct sockaddr_in sin;
1074 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1075 uint32_t destnode, struct ctdb_public_ip *ip);
1076 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1077 uint32_t destnode, struct ctdb_public_ip *ip);
1079 struct ctdb_all_public_ipsv4 {
1080 uint32_t num;
1081 struct ctdb_public_ipv4 ips[1];
1084 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1085 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1086 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1087 struct timeval timeout,
1088 uint32_t destnode,
1089 TALLOC_CTX *mem_ctx,
1090 struct ctdb_all_public_ips **ips);
1091 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1092 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
1093 struct timeval timeout, uint32_t destnode,
1094 TALLOC_CTX *mem_ctx,
1095 uint32_t flags,
1096 struct ctdb_all_public_ips **ips);
1097 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb,
1098 struct timeval timeout, uint32_t destnode,
1099 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1101 struct ctdb_control_iface_info {
1102 char name[CTDB_IFACE_SIZE+2];
1103 uint16_t link_state;
1104 uint32_t references;
1107 struct ctdb_control_public_ip_info {
1108 struct ctdb_public_ip ip;
1109 uint32_t active_idx;
1110 uint32_t num;
1111 struct ctdb_control_iface_info ifaces[1];
1114 struct ctdb_control_get_ifaces {
1115 uint32_t num;
1116 struct ctdb_control_iface_info ifaces[1];
1119 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
1120 struct ctdb_req_control *c,
1121 TDB_DATA indata,
1122 TDB_DATA *outdata);
1123 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
1124 struct ctdb_req_control *c,
1125 TDB_DATA *outdata);
1126 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
1127 struct ctdb_req_control *c,
1128 TDB_DATA indata);
1129 int ctdb_ctrl_get_public_ip_info(struct ctdb_context *ctdb,
1130 struct timeval timeout, uint32_t destnode,
1131 TALLOC_CTX *mem_ctx,
1132 const ctdb_sock_addr *addr,
1133 struct ctdb_control_public_ip_info **info);
1134 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
1135 struct timeval timeout, uint32_t destnode,
1136 TALLOC_CTX *mem_ctx,
1137 struct ctdb_control_get_ifaces **ifaces);
1138 int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb,
1139 struct timeval timeout, uint32_t destnode,
1140 TALLOC_CTX *mem_ctx,
1141 const struct ctdb_control_iface_info *info);
1143 /* from takeover/system.c */
1144 uint32_t uint16_checksum(uint16_t *data, size_t n);
1145 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1146 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
1147 char *ctdb_sys_find_ifname(ctdb_sock_addr *addr);
1148 bool ctdb_sys_check_iface_exists(const char *iface);
1149 int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
1150 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
1151 const ctdb_sock_addr *src,
1152 uint32_t seq, uint32_t ack, int rst);
1154 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
1155 int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
1156 const char *iface,
1157 const char *ip);
1158 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1159 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1160 int ctdb_set_debug_hung_script(struct ctdb_context *ctdb, const char *script);
1161 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
1162 void lcp2_forcerebalance(struct ctdb_context *ctdb, uint32_t pnn);
1163 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1165 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1166 TDB_DATA indata);
1167 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata, bool tcp_update_needed);
1168 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1169 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1170 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1171 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1172 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1173 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1175 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1176 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call);
1177 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
1178 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1179 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1180 TALLOC_CTX *mem_ctx,
1181 void (*callback)(struct ctdb_context *, int, void *),
1182 void *private_data,
1183 bool from_user,
1184 enum ctdb_eventscript_call call,
1185 const char *fmt, ...) PRINTF_ATTRIBUTE(7,8);
1186 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1188 void set_nonblocking(int fd);
1189 void set_close_on_exec(int fd);
1191 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1193 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1195 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1196 TDB_DATA *outdata);
1197 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1198 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1199 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1200 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1201 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1203 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1205 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1207 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1208 struct timeval timeout,
1209 uint32_t destnode,
1210 struct ctdb_tunable *tunables);
1212 int ctdb_start_freeze(struct ctdb_context *ctdb, uint32_t priority);
1214 bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask);
1215 bool parse_ip_port(const char *s, ctdb_sock_addr *addr);
1216 bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr);
1217 bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin);
1220 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1221 int ctdb_sys_close_capture_socket(void *private_data);
1222 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);
1224 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1225 struct timeval timeout,
1226 uint32_t destnode,
1227 struct ctdb_control_killtcp *killtcp);
1229 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1230 struct timeval timeout,
1231 uint32_t destnode,
1232 struct ctdb_control_ip_iface *pub);
1234 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1235 struct timeval timeout,
1236 uint32_t destnode,
1237 struct ctdb_control_ip_iface *pub);
1239 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1240 struct timeval timeout,
1241 uint32_t destnode,
1242 ctdb_sock_addr *addr,
1243 const char *ifname);
1245 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1246 struct timeval timeout,
1247 uint32_t destnode,
1248 TALLOC_CTX *mem_ctx,
1249 ctdb_sock_addr *addr,
1250 struct ctdb_control_tcp_tickle_list **list);
1253 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1254 uint32_t client_id,
1255 TDB_DATA indata);
1256 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1257 TDB_DATA indata);
1258 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1259 TDB_DATA indata);
1260 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1261 TDB_DATA *outdata);
1262 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1263 TDB_DATA *outdata);
1265 int ctdb_attach_databases(struct ctdb_context *ctdb);
1267 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1268 struct ctdb_req_control *c,
1269 TDB_DATA recdata, bool *async_reply);
1270 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1271 struct ctdb_req_control *c, TDB_DATA recdata,
1272 bool *async_reply);
1273 int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb,
1274 struct ctdb_req_control *c,
1275 TDB_DATA recdata, bool *async_reply);
1277 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
1278 struct ctdb_req_control *c,
1279 TDB_DATA recdata, bool *async_reply);
1281 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
1283 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1284 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1285 int32_t ctdb_control_transaction_cancel(struct ctdb_context *ctdb);
1286 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1287 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb, TDB_DATA indata);
1288 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
1289 TDB_DATA indata,
1290 TDB_DATA *outdata);
1293 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1294 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1296 void ctdb_block_signal(int signum);
1297 void ctdb_unblock_signal(int signum);
1298 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1299 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1300 void ctdb_lockdown_memory(struct ctdb_context *ctdb);
1302 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1304 struct client_async_data {
1305 enum ctdb_controls opcode;
1306 bool dont_log_errors;
1307 uint32_t count;
1308 uint32_t fail_count;
1309 client_async_callback callback;
1310 client_async_callback fail_callback;
1311 void *callback_data;
1313 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1314 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1315 int ctdb_client_async_control(struct ctdb_context *ctdb,
1316 enum ctdb_controls opcode,
1317 uint32_t *nodes,
1318 uint64_t srvid,
1319 struct timeval timeout,
1320 bool dont_log_errors,
1321 TDB_DATA data,
1322 client_async_callback client_callback,
1323 client_async_callback fail_callback,
1324 void *callback_data);
1326 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1328 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1330 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1331 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);
1333 int32_t ctdb_control_trans2_finished(struct ctdb_context *ctdb,
1334 struct ctdb_req_control *c);
1335 int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb,
1336 struct ctdb_req_control *c);
1337 int32_t ctdb_control_trans2_active(struct ctdb_context *ctdb,
1338 struct ctdb_req_control *c,
1339 uint32_t db_id);
1341 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
1342 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
1343 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
1345 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
1346 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata);
1348 extern int script_log_level;
1349 extern bool fast_start;
1351 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
1352 uint32_t call_type,
1353 TDB_DATA *outdata);
1355 int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
1356 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
1358 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1359 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
1361 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
1362 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
1364 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1365 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
1367 int32_t ctdb_local_node_got_banned(struct ctdb_context *ctdb);
1368 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
1369 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
1370 int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata);
1371 void ctdb_ban_self(struct ctdb_context *ctdb);
1373 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1375 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
1377 int start_syslog_daemon(struct ctdb_context *ctdb);
1379 /* Where to send the log messages back to */
1380 struct ctdb_get_log_addr {
1381 uint32_t pnn;
1382 uint64_t srvid;
1383 int32_t level;
1386 extern int log_ringbuf_size;
1388 int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
1389 int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
1392 struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
1393 struct ctdb_context *ctdb,
1394 const char *log_prefix,
1395 void (*logfn)(const char *, uint16_t, void *),
1396 void *logfn_private, pid_t *pid);
1398 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
1399 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
1401 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
1402 TDB_DATA indata,
1403 TDB_DATA *outdata);
1405 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
1406 struct ctdb_db_context *ctdb_db);
1407 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
1408 struct ctdb_db_context *ctdb_db,
1409 const char *reason,/* NULL means healthy */
1410 int num_healthy_nodes);
1411 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
1413 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
1415 void ctdb_fault_setup(void);
1417 int verify_remote_ip_allocation(struct ctdb_context *ctdb,
1418 struct ctdb_all_public_ips *ips);
1419 int update_ip_assignment_tree(struct ctdb_context *ctdb,
1420 struct ctdb_public_ip *ip);
1422 int ctdb_init_tevent_logging(struct ctdb_context *ctdb);
1424 int ctdb_statistics_init(struct ctdb_context *ctdb);
1426 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
1427 struct ctdb_req_control *c,
1428 TDB_DATA *outdata);
1430 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
1432 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
1435 * structure to pass to a schedule_for_deletion_control
1437 struct ctdb_control_schedule_for_deletion {
1438 uint32_t db_id;
1439 struct ctdb_ltdb_header hdr;
1440 uint32_t keylen;
1441 uint8_t key[1]; /* key[] */
1444 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
1445 TDB_DATA indata);
1448 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
1449 const struct ctdb_ltdb_header *hdr,
1450 TDB_DATA key);
1452 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
1453 const struct ctdb_ltdb_header *hdr,
1454 const TDB_DATA key);
1456 struct ctdb_ltdb_header *ctdb_header_from_record_handle(struct ctdb_record_handle *h);
1458 /* For unit testing ctdb_transaction.c. */
1459 struct ctdb_public_ip_list {
1460 struct ctdb_public_ip_list *next;
1461 uint32_t pnn;
1462 ctdb_sock_addr addr;
1464 int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
1466 typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn, void *private_data);
1468 void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_trackingdb_cb cb, void *private_data);
1470 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);
1472 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
1474 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);
1476 int ctdb_set_db_readonly(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1478 int ctdb_null_func(struct ctdb_call_info *call);
1480 int ctdb_fetch_func(struct ctdb_call_info *call);
1482 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
1484 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
1485 uint32_t db_id,
1486 TDB_DATA *outdata);
1488 int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
1491 description for a message to reload all ips via recovery master/daemon
1493 struct reloadips_all_reply {
1494 uint32_t pnn;
1495 uint64_t srvid;
1498 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1500 int ctdb_start_monitoring_interfaces(struct ctdb_context *ctdb);
1502 #endif