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
{
34 struct srvid_request_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
{
52 struct ctdb_tcp_connection connections
[1];
55 /* the list of tcp tickles used by get/set tcp tickle list */
56 struct ctdb_control_tcp_tickle_list
{
58 struct ctdb_tcp_wire_array tickles
;
62 array of tcp connections
64 struct ctdb_tcp_array
{
66 struct ctdb_tcp_connection
*connections
;
70 /* all tunable variables go in here */
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
;
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 allow_unhealthy_db_read
;
110 uint32_t stat_history_interval
;
111 uint32_t deferred_attach_timeout
;
112 uint32_t vacuum_fast_path_count
;
113 uint32_t lcp2_public_ip_assignment
;
114 uint32_t allow_client_db_attach
;
115 uint32_t recover_pdb_by_seqnum
;
116 uint32_t deferred_rebalance_on_node_add
;
117 uint32_t fetch_collapse
;
118 uint32_t hopcount_make_sticky
;
119 uint32_t sticky_duration
;
120 uint32_t sticky_pindown
;
121 uint32_t no_ip_takeover
;
122 uint32_t db_record_count_warn
;
123 uint32_t db_record_size_warn
;
124 uint32_t db_size_warn
;
125 uint32_t pulldb_preallocation_size
;
126 uint32_t no_ip_host_on_all_disabled
;
127 uint32_t samba3_hack
;
128 uint32_t mutex_enabled
;
129 uint32_t lock_processes_per_db
;
133 an installed ctdb remote call
135 struct ctdb_registered_call
{
136 struct ctdb_registered_call
*next
, *prev
;
142 check that a pnn is valid
144 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
147 /* called from the queue code when a packet comes in. Called with data==NULL
149 typedef void (*ctdb_queue_cb_fn_t
)(uint8_t *data
, size_t length
,
152 /* used for callbacks in ctdb_control requests */
153 typedef void (*ctdb_control_callback_fn_t
)(struct ctdb_context
*,
154 int32_t status
, TDB_DATA data
,
155 const char *errormsg
,
158 structure describing a connected client in the daemon
161 struct ctdb_context
*ctdb
;
163 struct ctdb_queue
*queue
;
166 struct ctdb_tcp_list
*tcp_list
;
168 uint32_t num_persistent_updates
;
169 struct ctdb_client_notify_list
*notify
;
174 /* state associated with a public ip address */
176 struct ctdb_vnn
*prev
, *next
;
178 struct ctdb_iface
*iface
;
180 ctdb_sock_addr public_address
;
181 uint8_t public_netmask_bits
;
183 /* the node number that is serving this public address, if any.
184 If no node serves this ip it is set to -1 */
187 /* List of clients to tickle for this public address */
188 struct ctdb_tcp_array
*tcp_array
;
190 /* whether we need to update the other nodes with changes to our list
191 of connected clients */
192 bool tcp_update_needed
;
194 /* a context to hang sending gratious arp events off */
195 TALLOC_CTX
*takeover_ctx
;
197 struct ctdb_kill_tcp
*killtcp
;
199 /* Set to true any time an update to this VNN is in flight.
200 This helps to avoid races. */
201 bool update_in_flight
;
203 /* If CTDB_CONTROL_DEL_PUBLIC_IP is received for this IP
204 * address then this flag is set. It will be deleted in the
205 * release IP callback. */
210 state associated with one node
213 struct ctdb_context
*ctdb
;
214 ctdb_sock_addr address
;
215 const char *name
; /* for debug messages */
216 void *private_data
; /* private to transport */
220 /* used by the dead node monitoring */
225 /* a list of controls pending to this node, so we can time them out quickly
226 if the node becomes disconnected */
227 struct daemon_control_state
*pending_controls
;
229 /* used by the recovery daemon when distributing ip addresses
230 across the nodes. it needs to know which public ip's can be handled
233 struct ctdb_all_public_ips
*known_public_ips
;
234 struct ctdb_all_public_ips
*available_public_ips
;
235 /* used by the recovery dameon to track when a node should be banned */
236 struct ctdb_banning_state
*ban_state
;
240 transport specific methods
242 struct ctdb_methods
{
243 int (*initialise
)(struct ctdb_context
*); /* initialise transport structures */
244 int (*start
)(struct ctdb_context
*); /* start the transport */
245 int (*add_node
)(struct ctdb_node
*); /* setup a new node */
246 int (*connect_node
)(struct ctdb_node
*); /* connect to node */
247 int (*queue_pkt
)(struct ctdb_node
*, uint8_t *data
, uint32_t length
);
248 void *(*allocate_pkt
)(TALLOC_CTX
*mem_ctx
, size_t );
249 void (*shutdown
)(struct ctdb_context
*); /* shutdown transport */
250 void (*restart
)(struct ctdb_node
*); /* stop and restart the connection */
254 transport calls up to the ctdb layer
256 struct ctdb_upcalls
{
257 /* recv_pkt is called when a packet comes in */
258 void (*recv_pkt
)(struct ctdb_context
*, uint8_t *data
, uint32_t length
);
260 /* node_dead is called when an attempt to send to a node fails */
261 void (*node_dead
)(struct ctdb_node
*);
263 /* node_connected is called when a connection to a node is established */
264 void (*node_connected
)(struct ctdb_node
*);
267 /* additional data required for the daemon mode */
268 struct ctdb_daemon_data
{
271 struct ctdb_queue
*queue
;
275 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
277 if (value > ctdb->statistics.counter) { \
278 ctdb->statistics.counter = c->hopcount; \
280 if (value > ctdb->statistics_current.counter) { \
281 ctdb->statistics_current.counter = c->hopcount; \
285 #define CTDB_INCREMENT_STAT(ctdb, counter) \
287 ctdb->statistics.counter++; \
288 ctdb->statistics_current.counter++; \
291 #define CTDB_DECREMENT_STAT(ctdb, counter) \
293 if (ctdb->statistics.counter > 0) \
294 ctdb->statistics.counter--; \
295 if (ctdb->statistics_current.counter > 0) \
296 ctdb->statistics_current.counter--; \
299 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
301 ctdb_db->statistics.counter++; \
304 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
306 if (ctdb_db->statistics.counter > 0) \
307 ctdb_db->statistics.counter--; \
310 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
312 if (value > ctdb->statistics.counter.max) \
313 ctdb->statistics.counter.max = value; \
314 if (value > ctdb->statistics_current.counter.max) \
315 ctdb->statistics_current.counter.max = value; \
317 if (ctdb->statistics.counter.num == 0 || \
318 value < ctdb->statistics.counter.min) \
319 ctdb->statistics.counter.min = value; \
320 if (ctdb->statistics_current.counter.num == 0 || \
321 value < ctdb->statistics_current.counter.min) \
322 ctdb->statistics_current.counter.min = value; \
324 ctdb->statistics.counter.total += value; \
325 ctdb->statistics_current.counter.total += value; \
327 ctdb->statistics.counter.num++; \
328 ctdb->statistics_current.counter.num++; \
330 if (ctdb->tunable.reclock_latency_ms != 0) { \
331 if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
333 ("High RECLOCK latency %fs for operation %s\n", \
339 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value) \
341 if (value > ctdb_db->statistics.counter.max) \
342 ctdb_db->statistics.counter.max = value; \
343 if (ctdb_db->statistics.counter.num == 0 || \
344 value < ctdb_db->statistics.counter.min) \
345 ctdb_db->statistics.counter.min = value; \
347 ctdb_db->statistics.counter.total += value; \
348 ctdb_db->statistics.counter.num++; \
350 if (ctdb_db->ctdb->tunable.log_latency_ms != 0) { \
351 if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) { \
353 ("High latency %.6fs for operation %s on database %s\n",\
354 value, operation, ctdb_db->db_name)); \
359 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
361 double l = timeval_elapsed(&t); \
363 if (l > ctdb->statistics.counter.max) \
364 ctdb->statistics.counter.max = l; \
365 if (l > ctdb->statistics_current.counter.max) \
366 ctdb->statistics_current.counter.max = l; \
368 if (ctdb->statistics.counter.num == 0 || \
369 l < ctdb->statistics.counter.min) \
370 ctdb->statistics.counter.min = l; \
371 if (ctdb->statistics_current.counter.num == 0 || \
372 l < ctdb->statistics_current.counter.min) \
373 ctdb->statistics_current.counter.min = l; \
375 ctdb->statistics.counter.total += l; \
376 ctdb->statistics_current.counter.total += l; \
378 ctdb->statistics.counter.num++; \
379 ctdb->statistics_current.counter.num++; \
381 if (ctdb->tunable.log_latency_ms != 0) { \
382 if (l*1000 > ctdb->tunable.log_latency_ms) { \
383 DEBUG(DEBUG_WARNING, \
384 ("High latency %.6fs for operation %s on database %s\n",\
385 l, operation, db->db_name)); \
392 /* a structure that contains the elements required for the write record
395 struct ctdb_write_record
{
399 unsigned char blob
[1];
402 enum ctdb_freeze_mode
{CTDB_FREEZE_NONE
, CTDB_FREEZE_PENDING
, CTDB_FREEZE_FROZEN
};
405 CTDB_RUNSTATE_UNKNOWN
,
408 CTDB_RUNSTATE_FIRST_RECOVERY
,
409 CTDB_RUNSTATE_STARTUP
,
410 CTDB_RUNSTATE_RUNNING
,
411 CTDB_RUNSTATE_SHUTDOWN
,
414 const char *runstate_to_string(enum ctdb_runstate runstate
);
415 enum ctdb_runstate
runstate_from_string(const char *label
);
416 void ctdb_set_runstate(struct ctdb_context
*ctdb
, enum ctdb_runstate runstate
);
418 void ctdb_shutdown_sequence(struct ctdb_context
*ctdb
, int exit_code
);
420 #define CTDB_MONITORING_ACTIVE 0
421 #define CTDB_MONITORING_DISABLED 1
423 #define NUM_DB_PRIORITIES 3
424 /* main state of the ctdb daemon */
425 struct ctdb_context
{
426 struct tevent_context
*ev
;
427 struct timeval ctdbd_start_time
;
428 struct timeval last_recovery_started
;
429 struct timeval last_recovery_finished
;
430 uint32_t recovery_mode
;
431 TALLOC_CTX
*tickle_update_context
;
432 TALLOC_CTX
*keepalive_ctx
;
433 TALLOC_CTX
*check_public_ifaces_ctx
;
434 struct ctdb_tunable tunable
;
435 enum ctdb_freeze_mode freeze_mode
[NUM_DB_PRIORITIES
+1];
436 struct ctdb_freeze_handle
*freeze_handles
[NUM_DB_PRIORITIES
+1];
437 bool freeze_transaction_started
;
438 uint32_t freeze_transaction_id
;
439 ctdb_sock_addr
*address
;
441 const char *db_directory
;
442 const char *db_directory_persistent
;
443 const char *db_directory_state
;
444 struct tdb_wrap
*db_persistent_health
;
445 uint32_t db_persistent_startup_generation
;
446 uint64_t db_persistent_check_errors
;
447 uint64_t max_persistent_check_errors
;
448 const char *transport
;
449 char *recovery_lock_file
;
450 int recovery_lock_fd
;
451 uint32_t pnn
; /* our own pnn */
453 uint32_t num_connected
;
455 uint32_t capabilities
;
456 struct reqid_context
*idr
;
457 struct ctdb_node
**nodes
; /* array of nodes in the cluster - indexed by vnn */
458 struct ctdb_vnn
*vnn
; /* list of public ip addresses and interfaces */
459 struct ctdb_vnn
*single_ip_vnn
; /* a structure for the single ip */
460 struct ctdb_iface
*ifaces
; /* list of local interfaces */
462 const struct ctdb_methods
*methods
; /* transport methods */
463 const struct ctdb_upcalls
*upcalls
; /* transport upcalls */
464 void *private_data
; /* private to transport */
465 struct ctdb_db_context
*db_list
;
466 struct srvid_context
*srv
;
467 struct ctdb_daemon_data daemon
;
468 struct ctdb_statistics statistics
;
469 struct ctdb_statistics statistics_current
;
470 #define MAX_STAT_HISTORY 100
471 struct ctdb_statistics statistics_history
[MAX_STAT_HISTORY
];
472 struct ctdb_vnn_map
*vnn_map
;
473 uint32_t num_clients
;
474 uint32_t recovery_master
;
475 struct ctdb_client_ip
*client_ip_list
;
476 bool do_checkpublicip
;
477 struct trbt_tree
*server_ids
;
479 const char *event_script_dir
;
480 const char *notification_script
;
481 const char *default_public_interface
;
484 enum ctdb_runstate runstate
;
485 struct ctdb_monitor_state
*monitor
;
486 int start_as_disabled
;
487 int start_as_stopped
;
489 uint32_t event_script_timeouts
; /* counting how many consecutive times an eventscript has timedout */
490 uint32_t *recd_ping_count
;
491 TALLOC_CTX
*recd_ctx
; /* a context used to track recoverd monitoring events */
492 TALLOC_CTX
*release_ips_ctx
; /* a context used to automatically drop all IPs if we fail to recover the node */
494 TALLOC_CTX
*event_script_ctx
;
497 struct ctdb_event_script_state
*current_monitor
;
498 struct ctdb_scripts_wire
*last_status
[CTDB_EVENT_MAX
];
500 TALLOC_CTX
*banning_ctx
;
502 struct ctdb_vacuum_child_context
*vacuumers
;
504 /* mapping from pid to ctdb_client * */
505 struct ctdb_client_pid_list
*client_pids
;
507 /* used in the recovery daemon to remember the ip allocation */
508 struct trbt_tree
*ip_tree
;
510 /* Used to defer db attach requests while in recovery mode */
511 struct ctdb_deferred_attach_context
*deferred_attach
;
513 /* if we are a child process, do we have a domain socket to send controls on */
514 bool can_send_controls
;
516 /* list of event script callback functions that are active */
517 struct event_script_callback
*script_callbacks
;
519 struct ctdb_reloadips_handle
*reload_ips
;
521 const char *nodes_file
;
522 const char *public_addresses_file
;
523 struct trbt_tree
*child_processes
;
525 /* Used for locking record/db/alldb */
526 struct lock_context
*lock_current
;
527 struct lock_context
*lock_pending
;
530 struct ctdb_db_context
{
531 struct ctdb_db_context
*next
, *prev
;
532 struct ctdb_context
*ctdb
;
536 bool readonly
; /* Do we support read-only delegations ? */
537 bool sticky
; /* Do we support sticky records ? */
540 struct tdb_wrap
*ltdb
;
541 struct tdb_context
*rottdb
; /* ReadOnly tracking TDB */
542 struct ctdb_registered_call
*calls
; /* list of registered calls */
544 struct timed_event
*seqnum_update
;
545 struct ctdb_traverse_local_handle
*traverse
;
546 struct ctdb_vacuum_handle
*vacuum_handle
;
547 char *unhealthy_reason
;
548 int pending_requests
;
549 struct revokechild_handle
*revokechild_active
;
550 struct ctdb_persistent_state
*persistent_state
;
551 struct trbt_tree
*delete_queue
;
552 struct trbt_tree
*sticky_records
;
553 int (*ctdb_ltdb_store_fn
)(struct ctdb_db_context
*ctdb_db
,
555 struct ctdb_ltdb_header
*header
,
558 /* used to track which records we are currently fetching
559 so we can avoid sending duplicate fetch requests
561 struct trbt_tree
*deferred_fetch
;
562 struct trbt_tree
*defer_dmaster
;
564 struct ctdb_db_statistics statistics
;
566 struct lock_context
*lock_current
;
567 struct lock_context
*lock_pending
;
568 int lock_num_current
;
570 struct ctdb_call_state
*pending_calls
;
572 enum ctdb_freeze_mode freeze_mode
;
573 struct ctdb_db_freeze_handle
*freeze_handle
;
574 bool freeze_transaction_started
;
575 uint32_t freeze_transaction_id
;
580 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
581 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
582 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
583 return -1; }} while (0)
585 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
586 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
587 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
590 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
591 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
592 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
593 return NULL; }} while (0)
595 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
596 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
597 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
601 struct holding a ctdb_sock_addr and an interface name,
602 used to add/remove public addresses
604 struct ctdb_control_ip_iface
{
612 struct holding a ctdb_sock_addr and an interface name,
613 used for send_gratious_arp
615 struct ctdb_control_gratious_arp
{
623 persistent store control - update this record on all other nodes
625 struct ctdb_control_persistent_store
{
632 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
634 struct ctdb_node_flag_change
{
641 struct for admin setting a ban
643 struct ctdb_ban_info
{
648 enum call_state
{CTDB_CALL_WAIT
, CTDB_CALL_DONE
, CTDB_CALL_ERROR
};
650 #define CTDB_LMASTER_ANY 0xffffffff
653 state of a in-progress ctdb call
655 struct ctdb_call_state
{
656 struct ctdb_call_state
*next
, *prev
;
657 enum call_state state
;
659 struct ctdb_req_call
*c
;
660 struct ctdb_db_context
*ctdb_db
;
662 struct ctdb_call
*call
;
665 void (*fn
)(struct ctdb_call_state
*);
671 /* used for fetch_lock */
672 struct ctdb_fetch_handle
{
673 struct ctdb_db_context
*ctdb_db
;
676 struct ctdb_ltdb_header header
;
679 /* internal prototypes */
680 void ctdb_set_error(struct ctdb_context
*ctdb
, const char *fmt
, ...) PRINTF_ATTRIBUTE(2,3);
681 void ctdb_fatal(struct ctdb_context
*ctdb
, const char *msg
);
682 void ctdb_die(struct ctdb_context
*ctdb
, const char *msg
);
683 bool ctdb_set_helper(const char *type
, char *helper
, size_t size
,
684 const char *envvar
, const char *dir
, const char *file
);
685 void ctdb_external_trace(void);
686 bool ctdb_same_address(ctdb_sock_addr
*a1
, ctdb_sock_addr
*a2
);
687 int ctdb_parse_address(TALLOC_CTX
*mem_ctx
, const char *str
,
688 ctdb_sock_addr
*address
);
689 bool ctdb_same_ip(const ctdb_sock_addr
*ip1
, const ctdb_sock_addr
*ip2
);
690 bool ctdb_same_sockaddr(const ctdb_sock_addr
*ip1
, const ctdb_sock_addr
*ip2
);
691 uint32_t ctdb_hash(const TDB_DATA
*key
);
692 uint32_t *ctdb_key_to_idkey(TALLOC_CTX
*mem_ctx
, TDB_DATA key
);
694 void ctdb_request_call(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
695 void ctdb_request_dmaster(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
696 void ctdb_request_message(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
697 void ctdb_reply_dmaster(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
698 void ctdb_reply_call(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
699 void ctdb_reply_error(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
701 uint32_t ctdb_lmaster(struct ctdb_context
*ctdb
, const TDB_DATA
*key
);
702 int ctdb_ltdb_fetch(struct ctdb_db_context
*ctdb_db
,
703 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
704 TALLOC_CTX
*mem_ctx
, TDB_DATA
*data
);
705 int ctdb_ltdb_store(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
,
706 struct ctdb_ltdb_header
*header
, TDB_DATA data
);
707 int ctdb_ltdb_delete(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
708 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context
*ctdb_db
,
709 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
710 TALLOC_CTX
*mem_ctx
, TDB_DATA
*data
);
711 int32_t ctdb_control_start_persistent_update(struct ctdb_context
*ctdb
,
712 struct ctdb_req_control
*c
,
714 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context
*ctdb
,
715 struct ctdb_req_control
*c
,
717 void ctdb_queue_packet(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
718 void ctdb_queue_packet_opcode(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
, unsigned opcode
);
719 int ctdb_ltdb_lock_requeue(struct ctdb_db_context
*ctdb_db
,
720 TDB_DATA key
, struct ctdb_req_header
*hdr
,
721 void (*recv_pkt
)(void *, struct ctdb_req_header
*),
722 void *recv_context
, bool ignore_generation
);
723 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context
*ctdb_db
,
724 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
725 struct ctdb_req_header
*hdr
, TDB_DATA
*data
,
726 void (*recv_pkt
)(void *, struct ctdb_req_header
*),
727 void *recv_context
, bool ignore_generation
);
728 void ctdb_input_pkt(struct ctdb_context
*ctdb
, struct ctdb_req_header
*);
730 struct ctdb_call_state
*ctdb_call_local_send(struct ctdb_db_context
*ctdb_db
,
731 struct ctdb_call
*call
,
732 struct ctdb_ltdb_header
*header
,
736 int ctdb_start_daemon(struct ctdb_context
*ctdb
, bool do_fork
);
739 queue a packet for sending
741 int ctdb_queue_send(struct ctdb_queue
*queue
, uint8_t *data
, uint32_t length
);
744 setup the fd used by the queue
746 int ctdb_queue_set_fd(struct ctdb_queue
*queue
, int fd
);
749 setup a packet queue on a socket
751 struct ctdb_queue
*ctdb_queue_setup(struct ctdb_context
*ctdb
,
752 TALLOC_CTX
*mem_ctx
, int fd
, int alignment
,
754 ctdb_queue_cb_fn_t callback
,
755 void *private_data
, const char *fmt
, ...)
756 PRINTF_ATTRIBUTE(7,8);
759 allocate a packet for use in client<->daemon communication
761 struct ctdb_req_header
*_ctdbd_allocate_pkt(struct ctdb_context
*ctdb
,
763 enum ctdb_operation operation
,
764 size_t length
, size_t slength
,
766 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
767 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
769 struct ctdb_req_header
*_ctdb_transport_allocate(struct ctdb_context
*ctdb
,
771 enum ctdb_operation operation
,
772 size_t length
, size_t slength
,
774 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
775 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
777 int ctdb_queue_length(struct ctdb_queue
*queue
);
780 lock a record in the ltdb, given a key
782 int ctdb_ltdb_lock(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
785 unlock a record in the ltdb, given a key
787 int ctdb_ltdb_unlock(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
790 int ctdb_client_send_message(struct ctdb_context
*ctdb
, uint32_t vnn
,
791 uint64_t srvid
, TDB_DATA data
);
796 int ctdb_daemon_send_message(struct ctdb_context
*ctdb
, uint32_t pnn
,
797 uint64_t srvid
, TDB_DATA data
);
800 int ctdb_daemon_call_recv(struct ctdb_call_state
*state
, struct ctdb_call
*call
);
802 struct ctdb_call_state
*ctdb_daemon_call_send_remote(struct ctdb_db_context
*ctdb_db
,
803 struct ctdb_call
*call
,
804 struct ctdb_ltdb_header
*header
);
806 int ctdb_call_local(struct ctdb_db_context
*ctdb_db
, struct ctdb_call
*call
,
807 struct ctdb_ltdb_header
*header
, TALLOC_CTX
*mem_ctx
,
808 TDB_DATA
*data
, bool updatetdb
);
810 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
812 int ctdb_socket_connect(struct ctdb_context
*ctdb
);
813 void ctdb_client_read_cb(uint8_t *data
, size_t cnt
, void *args
);
815 void ctdb_request_control(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
816 void ctdb_reply_control(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
818 int ctdb_daemon_send_control(struct ctdb_context
*ctdb
, uint32_t destnode
,
819 uint64_t srvid
, uint32_t opcode
, uint32_t client_id
, uint32_t flags
,
821 ctdb_control_callback_fn_t callback
,
824 int32_t ctdb_control_db_attach(struct ctdb_context
*ctdb
, TDB_DATA indata
,
825 TDB_DATA
*outdata
, uint64_t tdb_flags
,
826 bool persistent
, uint32_t client_id
,
827 struct ctdb_req_control
*c
,
829 int32_t ctdb_control_db_detach(struct ctdb_context
*ctdb
, TDB_DATA indata
,
832 int ctdb_daemon_set_call(struct ctdb_context
*ctdb
, uint32_t db_id
,
833 ctdb_fn_t fn
, int id
);
835 int ctdb_control(struct ctdb_context
*ctdb
, uint32_t destnode
, uint64_t srvid
,
836 uint32_t opcode
, uint32_t flags
, TDB_DATA data
,
837 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
, int32_t *status
,
838 struct timeval
*timeout
, char **errormsg
);
839 int ctdb_control_recv(struct ctdb_context
*ctdb
,
840 struct ctdb_client_control_state
*state
,
842 TDB_DATA
*outdata
, int32_t *status
, char **errormsg
);
844 struct ctdb_client_control_state
*
845 ctdb_control_send(struct ctdb_context
*ctdb
,
846 uint32_t destnode
, uint64_t srvid
,
847 uint32_t opcode
, uint32_t flags
, TDB_DATA data
,
849 struct timeval
*timeout
,
855 #define CHECK_CONTROL_DATA_SIZE(size) do { \
856 if (indata.dsize != size) { \
857 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
858 opcode, (unsigned)indata.dsize, (unsigned)size)); \
863 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
864 if (indata.dsize < size) { \
865 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
866 opcode, (unsigned)indata.dsize, (unsigned)size)); \
871 int ctdb_control_getvnnmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
872 int ctdb_control_setvnnmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
873 int ctdb_control_getdbmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
874 int ctdb_control_getnodemap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
875 int ctdb_control_getnodesfile(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
878 /* structure used for pulldb control */
879 struct ctdb_control_pulldb
{
884 /* structure used for sending lists of records */
885 struct ctdb_marshall_buffer
{
892 structure for setting a tunable
894 struct ctdb_control_set_tunable
{
901 structure for getting a tunable
903 struct ctdb_control_get_tunable
{
909 structure for listing tunables
911 struct ctdb_control_list_tunable
{
913 /* returns a : separated list of tunable names */
918 struct ctdb_control_transdb
{
920 uint32_t transaction_id
;
924 state of a in-progress ctdb call in client
926 struct ctdb_client_call_state
{
927 enum call_state state
;
929 struct ctdb_db_context
*ctdb_db
;
930 struct ctdb_call
*call
;
932 void (*fn
)(struct ctdb_client_call_state
*);
938 int32_t ctdb_control_traverse_start_ext(struct ctdb_context
*ctdb
,
943 int32_t ctdb_control_traverse_start(struct ctdb_context
*ctdb
, TDB_DATA indata
,
944 TDB_DATA
*outdata
, uint32_t srcnode
, uint32_t client_id
);
945 int32_t ctdb_control_traverse_all(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
946 int32_t ctdb_control_traverse_all_ext(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
947 int32_t ctdb_control_traverse_data(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
948 int32_t ctdb_control_traverse_kill(struct ctdb_context
*ctdb
, TDB_DATA indata
,
949 TDB_DATA
*outdata
, uint32_t srcnode
);
951 int daemon_register_message_handler(struct ctdb_context
*ctdb
, uint32_t client_id
, uint64_t srvid
);
952 int daemon_deregister_message_handler(struct ctdb_context
*ctdb
, uint32_t client_id
, uint64_t srvid
);
953 int daemon_check_srvids(struct ctdb_context
*ctdb
, TDB_DATA indata
,
956 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context
*ctdb
, uint32_t db_id
);
957 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context
*ctdb
, uint32_t db_id
, uint32_t srcnode
);
959 struct ctdb_rec_data
*ctdb_marshall_record(TALLOC_CTX
*mem_ctx
, uint32_t reqid
,
960 TDB_DATA key
, struct ctdb_ltdb_header
*, TDB_DATA data
);
962 struct ctdb_rec_data
*ctdb_marshall_loop_next(struct ctdb_marshall_buffer
*m
, struct ctdb_rec_data
*r
,
964 struct ctdb_ltdb_header
*header
,
965 TDB_DATA
*key
, TDB_DATA
*data
);
967 int32_t ctdb_control_pull_db(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
968 int32_t ctdb_control_push_db(struct ctdb_context
*ctdb
, TDB_DATA indata
);
970 int32_t ctdb_control_set_recmode(struct ctdb_context
*ctdb
,
971 struct ctdb_req_control
*c
,
972 TDB_DATA indata
, bool *async_reply
,
973 const char **errormsg
);
974 void ctdb_request_control_reply(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
,
975 TDB_DATA
*outdata
, int32_t status
, const char *errormsg
);
977 int32_t ctdb_control_db_freeze(struct ctdb_context
*ctdb
,
978 struct ctdb_req_control
*c
,
979 uint32_t db_id
, bool *async_reply
);
980 int32_t ctdb_control_db_thaw(struct ctdb_context
*ctdb
, uint32_t db_id
);
982 int32_t ctdb_control_freeze(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, bool *async_reply
);
983 int32_t ctdb_control_thaw(struct ctdb_context
*ctdb
, uint32_t priority
,
985 bool ctdb_db_frozen(struct ctdb_db_context
*ctdb_db
);
986 bool ctdb_db_prio_frozen(struct ctdb_context
*ctdb
, uint32_t priority
);
987 bool ctdb_db_all_frozen(struct ctdb_context
*ctdb
);
989 int ctdb_start_recoverd(struct ctdb_context
*ctdb
);
990 void ctdb_stop_recoverd(struct ctdb_context
*ctdb
);
992 uint32_t ctdb_get_num_active_nodes(struct ctdb_context
*ctdb
);
994 void ctdb_disable_monitoring(struct ctdb_context
*ctdb
);
995 void ctdb_enable_monitoring(struct ctdb_context
*ctdb
);
996 void ctdb_stop_monitoring(struct ctdb_context
*ctdb
);
997 void ctdb_wait_for_first_recovery(struct ctdb_context
*ctdb
);
998 int ctdb_tcp_init(struct ctdb_context
*ctdb
);
999 int ctdb_ibw_init(struct ctdb_context
*ctdb
);
1000 void ctdb_start_tcp_tickle_update(struct ctdb_context
*ctdb
);
1001 void ctdb_send_keepalive(struct ctdb_context
*ctdb
, uint32_t destnode
);
1002 void ctdb_start_keepalive(struct ctdb_context
*ctdb
);
1003 void ctdb_stop_keepalive(struct ctdb_context
*ctdb
);
1004 int32_t ctdb_run_eventscripts(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, TDB_DATA data
, bool *async_reply
);
1007 void ctdb_daemon_cancel_controls(struct ctdb_context
*ctdb
, struct ctdb_node
*node
);
1008 void ctdb_call_resend_db(struct ctdb_db_context
*ctdb
);
1009 void ctdb_call_resend_all(struct ctdb_context
*ctdb
);
1010 void ctdb_node_dead(struct ctdb_node
*node
);
1011 void ctdb_node_connected(struct ctdb_node
*node
);
1012 bool ctdb_blocking_freeze(struct ctdb_context
*ctdb
);
1013 bool set_scheduler(void);
1014 void reset_scheduler(void);
1016 struct tevent_signal
*ctdb_init_sigchld(struct ctdb_context
*ctdb
);
1017 void ctdb_track_child(struct ctdb_context
*ctdb
, pid_t pid
);
1018 pid_t
ctdb_fork(struct ctdb_context
*ctdb
);
1019 void ctdb_set_child_info(TALLOC_CTX
*mem_ctx
, const char *child_name_fmt
, ...);
1020 int ctdb_kill(struct ctdb_context
*ctdb
, pid_t pid
, int signum
);
1022 int32_t ctdb_control_takeover_ip(struct ctdb_context
*ctdb
,
1023 struct ctdb_req_control
*c
,
1026 int32_t ctdb_control_release_ip(struct ctdb_context
*ctdb
,
1027 struct ctdb_req_control
*c
,
1030 int32_t ctdb_control_ipreallocated(struct ctdb_context
*ctdb
,
1031 struct ctdb_req_control
*c
,
1033 int32_t ctdb_control_start_recovery(struct ctdb_context
*ctdb
,
1034 struct ctdb_req_control
*c
,
1036 int32_t ctdb_control_end_recovery(struct ctdb_context
*ctdb
,
1037 struct ctdb_req_control
*c
,
1040 int ctdb_ctrl_takeover_ip(struct ctdb_context
*ctdb
, struct timeval timeout
,
1041 uint32_t destnode
, struct ctdb_public_ip
*ip
);
1042 int ctdb_ctrl_release_ip(struct ctdb_context
*ctdb
, struct timeval timeout
,
1043 uint32_t destnode
, struct ctdb_public_ip
*ip
);
1045 int32_t ctdb_control_get_public_ips(struct ctdb_context
*ctdb
,
1046 struct ctdb_req_control
*c
,
1048 int ctdb_ctrl_get_public_ips(struct ctdb_context
*ctdb
,
1049 struct timeval timeout
,
1051 TALLOC_CTX
*mem_ctx
,
1052 struct ctdb_all_public_ips
**ips
);
1053 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1054 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context
*ctdb
,
1055 struct timeval timeout
, uint32_t destnode
,
1056 TALLOC_CTX
*mem_ctx
,
1058 struct ctdb_all_public_ips
**ips
);
1060 struct ctdb_control_iface_info
{
1061 char name
[CTDB_IFACE_SIZE
+2];
1062 uint16_t link_state
;
1063 uint32_t references
;
1066 struct ctdb_control_public_ip_info
{
1067 struct ctdb_public_ip ip
;
1068 uint32_t active_idx
;
1070 struct ctdb_control_iface_info ifaces
[1];
1073 struct ctdb_control_get_ifaces
{
1075 struct ctdb_control_iface_info ifaces
[1];
1078 int32_t ctdb_control_get_public_ip_info(struct ctdb_context
*ctdb
,
1079 struct ctdb_req_control
*c
,
1082 int32_t ctdb_control_get_ifaces(struct ctdb_context
*ctdb
,
1083 struct ctdb_req_control
*c
,
1085 int32_t ctdb_control_set_iface_link(struct ctdb_context
*ctdb
,
1086 struct ctdb_req_control
*c
,
1088 int ctdb_ctrl_get_public_ip_info(struct ctdb_context
*ctdb
,
1089 struct timeval timeout
, uint32_t destnode
,
1090 TALLOC_CTX
*mem_ctx
,
1091 const ctdb_sock_addr
*addr
,
1092 struct ctdb_control_public_ip_info
**info
);
1093 int ctdb_ctrl_get_ifaces(struct ctdb_context
*ctdb
,
1094 struct timeval timeout
, uint32_t destnode
,
1095 TALLOC_CTX
*mem_ctx
,
1096 struct ctdb_control_get_ifaces
**ifaces
);
1097 int ctdb_ctrl_set_iface_link(struct ctdb_context
*ctdb
,
1098 struct timeval timeout
, uint32_t destnode
,
1099 TALLOC_CTX
*mem_ctx
,
1100 const struct ctdb_control_iface_info
*info
);
1102 /* from takeover/system.c */
1103 uint32_t uint16_checksum(uint16_t *data
, size_t n
);
1104 int ctdb_sys_send_arp(const ctdb_sock_addr
*addr
, const char *iface
);
1105 bool ctdb_sys_have_ip(ctdb_sock_addr
*addr
);
1106 char *ctdb_sys_find_ifname(ctdb_sock_addr
*addr
);
1107 bool ctdb_sys_check_iface_exists(const char *iface
);
1108 int ctdb_get_peer_pid(const int fd
, pid_t
*peer_pid
);
1109 int ctdb_sys_send_tcp(const ctdb_sock_addr
*dest
,
1110 const ctdb_sock_addr
*src
,
1111 uint32_t seq
, uint32_t ack
, int rst
);
1113 /* Details of a byte range lock */
1114 struct ctdb_lock_info
{
1121 int ctdb_set_process_name(const char *name
);
1123 typedef void (*client_async_callback
)(struct ctdb_context
*ctdb
, uint32_t node_pnn
, int32_t res
, TDB_DATA outdata
, void *callback_data
);
1125 int ctdb_set_public_addresses(struct ctdb_context
*ctdb
, bool check_addresses
);
1126 int ctdb_set_single_public_ip(struct ctdb_context
*ctdb
,
1129 int ctdb_set_notification_script(struct ctdb_context
*ctdb
, const char *script
);
1130 int ctdb_takeover_run(struct ctdb_context
*ctdb
, struct ctdb_node_map
*nodemap
,
1131 uint32_t *force_rebalance_nodes
,
1132 client_async_callback fail_callback
, void *callback_data
);
1134 int32_t ctdb_control_tcp_client(struct ctdb_context
*ctdb
, uint32_t client_id
,
1136 int32_t ctdb_control_tcp_add(struct ctdb_context
*ctdb
, TDB_DATA indata
, bool tcp_update_needed
);
1137 int32_t ctdb_control_tcp_remove(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1138 int32_t ctdb_control_startup(struct ctdb_context
*ctdb
, uint32_t vnn
);
1139 int32_t ctdb_control_kill_tcp(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1140 int32_t ctdb_control_send_gratious_arp(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1141 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1142 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1144 void ctdb_takeover_client_destructor_hook(struct ctdb_client
*client
);
1145 int ctdb_event_script(struct ctdb_context
*ctdb
, enum ctdb_eventscript_call call
);
1146 int ctdb_event_script_args(struct ctdb_context
*ctdb
, enum ctdb_eventscript_call call
,
1147 const char *fmt
, ...) PRINTF_ATTRIBUTE(3,4);
1148 int ctdb_event_script_callback(struct ctdb_context
*ctdb
,
1149 TALLOC_CTX
*mem_ctx
,
1150 void (*callback
)(struct ctdb_context
*, int, void *),
1152 enum ctdb_eventscript_call call
,
1153 const char *fmt
, ...) PRINTF_ATTRIBUTE(6,7);
1154 void ctdb_release_all_ips(struct ctdb_context
*ctdb
);
1156 void set_nonblocking(int fd
);
1157 void set_close_on_exec(int fd
);
1159 bool ctdb_recovery_have_lock(struct ctdb_context
*ctdb
);
1160 bool ctdb_recovery_lock(struct ctdb_context
*ctdb
);
1161 void ctdb_recovery_unlock(struct ctdb_context
*ctdb
);
1163 int ctdb_set_recovery_lock_file(struct ctdb_context
*ctdb
, const char *file
);
1165 int32_t ctdb_control_get_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1167 int32_t ctdb_control_set_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1168 int32_t ctdb_control_list_tunables(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1169 int32_t ctdb_control_try_delete_records(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1170 int32_t ctdb_control_receive_records(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1171 int32_t ctdb_control_add_public_address(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1172 int32_t ctdb_control_del_public_address(struct ctdb_context
*ctdb
,
1173 struct ctdb_req_control
*c
,
1174 TDB_DATA recdata
, bool *async_reply
);
1176 void ctdb_tunables_set_defaults(struct ctdb_context
*ctdb
);
1178 int32_t ctdb_control_modflags(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1180 int ctdb_ctrl_get_all_tunables(struct ctdb_context
*ctdb
,
1181 struct timeval timeout
,
1183 struct ctdb_tunable
*tunables
);
1185 bool parse_ip_mask(const char *s
, const char *iface
, ctdb_sock_addr
*addr
, unsigned *mask
);
1186 bool parse_ip_port(const char *s
, ctdb_sock_addr
*addr
);
1187 bool parse_ip(const char *s
, const char *iface
, unsigned port
, ctdb_sock_addr
*addr
);
1188 bool parse_ipv4(const char *s
, unsigned port
, struct sockaddr_in
*sin
);
1191 int ctdb_sys_open_capture_socket(const char *iface
, void **private_data
);
1192 int ctdb_sys_close_capture_socket(void *private_data
);
1193 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
);
1195 int ctdb_ctrl_killtcp(struct ctdb_context
*ctdb
,
1196 struct timeval timeout
,
1198 struct ctdb_tcp_connection
*killtcp
);
1200 int ctdb_ctrl_add_public_ip(struct ctdb_context
*ctdb
,
1201 struct timeval timeout
,
1203 struct ctdb_control_ip_iface
*pub
);
1205 int ctdb_ctrl_del_public_ip(struct ctdb_context
*ctdb
,
1206 struct timeval timeout
,
1208 struct ctdb_control_ip_iface
*pub
);
1210 int ctdb_ctrl_gratious_arp(struct ctdb_context
*ctdb
,
1211 struct timeval timeout
,
1213 ctdb_sock_addr
*addr
,
1214 const char *ifname
);
1216 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context
*ctdb
,
1217 struct timeval timeout
,
1219 TALLOC_CTX
*mem_ctx
,
1220 ctdb_sock_addr
*addr
,
1221 struct ctdb_control_tcp_tickle_list
**list
);
1224 int32_t ctdb_control_register_server_id(struct ctdb_context
*ctdb
,
1227 int32_t ctdb_control_check_server_id(struct ctdb_context
*ctdb
,
1229 int32_t ctdb_control_unregister_server_id(struct ctdb_context
*ctdb
,
1231 int32_t ctdb_control_get_server_id_list(struct ctdb_context
*ctdb
,
1233 int32_t ctdb_control_uptime(struct ctdb_context
*ctdb
,
1236 int ctdb_attach_databases(struct ctdb_context
*ctdb
);
1238 int32_t ctdb_control_persistent_store(struct ctdb_context
*ctdb
,
1239 struct ctdb_req_control
*c
,
1240 TDB_DATA recdata
, bool *async_reply
);
1241 int32_t ctdb_control_update_record(struct ctdb_context
*ctdb
,
1242 struct ctdb_req_control
*c
, TDB_DATA recdata
,
1245 int32_t ctdb_control_trans3_commit(struct ctdb_context
*ctdb
,
1246 struct ctdb_req_control
*c
,
1247 TDB_DATA recdata
, bool *async_reply
);
1249 void ctdb_persistent_finish_trans3_commits(struct ctdb_context
*ctdb
);
1251 int32_t ctdb_control_db_transaction_start(struct ctdb_context
*ctdb
,
1253 int32_t ctdb_control_db_transaction_commit(struct ctdb_context
*ctdb
,
1255 int32_t ctdb_control_db_transaction_cancel(struct ctdb_context
*ctdb
,
1258 int32_t ctdb_control_transaction_start(struct ctdb_context
*ctdb
, uint32_t id
);
1259 int32_t ctdb_control_transaction_commit(struct ctdb_context
*ctdb
, uint32_t id
);
1260 int32_t ctdb_control_transaction_cancel(struct ctdb_context
*ctdb
);
1261 int32_t ctdb_control_wipe_database(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1262 int32_t ctdb_control_db_set_healthy(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1263 int32_t ctdb_control_db_get_health(struct ctdb_context
*ctdb
,
1268 int ctdb_repack(struct ctdb_context
*ctdb
, int argc
, const char **argv
);
1270 int32_t ctdb_monitoring_mode(struct ctdb_context
*ctdb
);
1271 bool ctdb_stopped_monitoring(struct ctdb_context
*ctdb
);
1272 int ctdb_set_child_logging(struct ctdb_context
*ctdb
);
1273 void lockdown_memory(bool valgrinding
);
1275 struct client_async_data
{
1276 enum ctdb_controls opcode
;
1277 bool dont_log_errors
;
1279 uint32_t fail_count
;
1280 client_async_callback callback
;
1281 client_async_callback fail_callback
;
1282 void *callback_data
;
1284 void ctdb_client_async_add(struct client_async_data
*data
, struct ctdb_client_control_state
*state
);
1285 int ctdb_client_async_wait(struct ctdb_context
*ctdb
, struct client_async_data
*data
);
1286 int ctdb_client_async_control(struct ctdb_context
*ctdb
,
1287 enum ctdb_controls opcode
,
1290 struct timeval timeout
,
1291 bool dont_log_errors
,
1293 client_async_callback client_callback
,
1294 client_async_callback fail_callback
,
1295 void *callback_data
);
1297 struct ctdb_node_map
*
1298 ctdb_node_list_to_map(struct ctdb_node
**nodes
, uint32_t num_nodes
,
1299 TALLOC_CTX
*mem_ctx
);
1300 struct ctdb_node_map
*ctdb_read_nodes_file(TALLOC_CTX
*mem_ctx
,
1302 void ctdb_load_nodes_file(struct ctdb_context
*ctdb
);
1304 int ctdb_control_reload_nodes_file(struct ctdb_context
*ctdb
, uint32_t opcode
);
1306 int32_t ctdb_dump_memory(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1307 int32_t ctdb_control_get_capabilities(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1309 char *ctdb_addr_to_str(ctdb_sock_addr
*addr
);
1310 unsigned ctdb_addr_to_port(ctdb_sock_addr
*addr
);
1311 void ctdb_canonicalize_ip(const ctdb_sock_addr
*ip
, ctdb_sock_addr
*cip
);
1313 int32_t ctdb_control_recd_ping(struct ctdb_context
*ctdb
);
1314 int32_t ctdb_control_set_recmaster(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
);
1316 extern int script_log_level
;
1317 extern bool fast_start
;
1318 extern const char *ctdbd_pidfile
;
1320 int32_t ctdb_control_get_event_script_status(struct ctdb_context
*ctdb
,
1324 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context
*ctdb
, struct timeval timeout
, double latency
);
1326 int32_t ctdb_control_stop_node(struct ctdb_context
*ctdb
);
1327 int32_t ctdb_control_continue_node(struct ctdb_context
*ctdb
);
1329 void ctdb_stop_vacuuming(struct ctdb_context
*ctdb
);
1330 int ctdb_vacuum_init(struct ctdb_db_context
*ctdb_db
);
1332 int32_t ctdb_control_enable_script(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1333 int32_t ctdb_control_disable_script(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1335 void ctdb_local_node_got_banned(struct ctdb_context
*ctdb
);
1336 int32_t ctdb_control_set_ban_state(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1337 int32_t ctdb_control_get_ban_state(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1338 int32_t ctdb_control_set_db_priority(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1339 uint32_t client_id
);
1340 void ctdb_ban_self(struct ctdb_context
*ctdb
);
1342 int32_t ctdb_control_register_notify(struct ctdb_context
*ctdb
, uint32_t client_id
, TDB_DATA indata
);
1344 int32_t ctdb_control_deregister_notify(struct ctdb_context
*ctdb
, uint32_t client_id
, TDB_DATA indata
);
1346 struct ctdb_log_state
*ctdb_vfork_with_logging(TALLOC_CTX
*mem_ctx
,
1347 struct ctdb_context
*ctdb
,
1348 const char *log_prefix
,
1351 const char **helper_argv
,
1352 void (*logfn
)(const char *, uint16_t, void *),
1353 void *logfn_private
, pid_t
*pid
);
1356 int32_t ctdb_control_process_exists(struct ctdb_context
*ctdb
, pid_t pid
);
1357 struct ctdb_client
*ctdb_find_client_by_pid(struct ctdb_context
*ctdb
, pid_t pid
);
1359 int32_t ctdb_control_get_db_seqnum(struct ctdb_context
*ctdb
,
1363 int ctdb_load_persistent_health(struct ctdb_context
*ctdb
,
1364 struct ctdb_db_context
*ctdb_db
);
1365 int ctdb_update_persistent_health(struct ctdb_context
*ctdb
,
1366 struct ctdb_db_context
*ctdb_db
,
1367 const char *reason
,/* NULL means healthy */
1368 int num_healthy_nodes
);
1369 int ctdb_recheck_persistent_health(struct ctdb_context
*ctdb
);
1371 void ctdb_run_notification_script(struct ctdb_context
*ctdb
, const char *event
);
1373 int verify_remote_ip_allocation(struct ctdb_context
*ctdb
,
1374 struct ctdb_all_public_ips
*ips
,
1376 int update_ip_assignment_tree(struct ctdb_context
*ctdb
,
1377 struct ctdb_public_ip
*ip
);
1378 void clear_ip_assignment_tree(struct ctdb_context
*ctdb
);
1380 int ctdb_init_tevent_logging(struct ctdb_context
*ctdb
);
1382 int ctdb_statistics_init(struct ctdb_context
*ctdb
);
1384 int32_t ctdb_control_get_stat_history(struct ctdb_context
*ctdb
,
1385 struct ctdb_req_control
*c
,
1388 int ctdb_deferred_drop_all_ips(struct ctdb_context
*ctdb
);
1390 int ctdb_process_deferred_attach(struct ctdb_context
*ctdb
);
1393 * structure to pass to a schedule_for_deletion_control
1395 struct ctdb_control_schedule_for_deletion
{
1397 struct ctdb_ltdb_header hdr
;
1399 uint8_t key
[1]; /* key[] */
1402 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context
*ctdb
,
1406 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context
*ctdb_db
,
1407 const struct ctdb_ltdb_header
*hdr
,
1410 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context
*ctdb_db
,
1411 const struct ctdb_ltdb_header
*hdr
,
1412 const TDB_DATA key
);
1414 struct ctdb_ltdb_header
*ctdb_header_from_record_handle(struct ctdb_record_handle
*h
);
1416 int ctdb_trackingdb_add_pnn(struct ctdb_context
*ctdb
, TDB_DATA
*data
, uint32_t pnn
);
1418 typedef void (*ctdb_trackingdb_cb
)(struct ctdb_context
*ctdb
, uint32_t pnn
, void *private_data
);
1420 void ctdb_trackingdb_traverse(struct ctdb_context
*ctdb
, TDB_DATA data
, ctdb_trackingdb_cb cb
, void *private_data
);
1422 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
);
1424 typedef void (*deferred_requeue_fn
)(void *call_context
, struct ctdb_req_header
*hdr
);
1426 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
);
1428 int ctdb_set_db_readonly(struct ctdb_context
*ctdb
, struct ctdb_db_context
*ctdb_db
);
1430 int ctdb_null_func(struct ctdb_call_info
*call
);
1432 int ctdb_fetch_func(struct ctdb_call_info
*call
);
1434 int ctdb_fetch_with_header_func(struct ctdb_call_info
*call
);
1436 void ctdb_db_statistics_reset(struct ctdb_db_context
*ctdb_db
);
1438 int32_t ctdb_control_get_db_statistics(struct ctdb_context
*ctdb
,
1442 int ctdb_set_db_sticky(struct ctdb_context
*ctdb
, struct ctdb_db_context
*ctdb_db
);
1445 description for a message to reload all ips via recovery master/daemon
1447 struct reloadips_all_reply
{
1452 int32_t ctdb_control_reload_public_ips(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, bool *async_reply
);
1454 /* from server/ctdb_lock.c */
1455 struct lock_request
;
1457 typedef int (*ctdb_db_handler_t
)(struct ctdb_db_context
*ctdb_db
,
1458 void *private_data
);
1460 int ctdb_db_prio_iterator(struct ctdb_context
*ctdb
, uint32_t priority
,
1461 ctdb_db_handler_t handler
, void *private_data
);
1462 int ctdb_db_iterator(struct ctdb_context
*ctdb
, ctdb_db_handler_t handler
,
1463 void *private_data
);
1465 int ctdb_lockall_mark_prio(struct ctdb_context
*ctdb
, uint32_t priority
);
1466 int ctdb_lockall_unmark_prio(struct ctdb_context
*ctdb
, uint32_t priority
);
1468 int ctdb_lockdb_mark(struct ctdb_db_context
*ctdb_db
);
1469 int ctdb_lockdb_unmark(struct ctdb_db_context
*ctdb_db
);
1471 struct lock_request
*ctdb_lock_record(TALLOC_CTX
*mem_ctx
,
1472 struct ctdb_db_context
*ctdb_db
,
1475 void (*callback
)(void *, bool),
1476 void *private_data
);
1478 struct lock_request
*ctdb_lock_db(TALLOC_CTX
*mem_ctx
,
1479 struct ctdb_db_context
*ctdb_db
,
1481 void (*callback
)(void *, bool),
1482 void *private_data
);
1484 struct lock_request
*ctdb_lock_alldb_prio(TALLOC_CTX
*mem_ctx
,
1485 struct ctdb_context
*ctdb
,
1488 void (*callback
)(void *, bool),
1489 void *private_data
);
1491 struct lock_request
*ctdb_lock_alldb(TALLOC_CTX
*mem_ctx
,
1492 struct ctdb_context
*ctdb
,
1494 void (*callback
)(void *, bool),
1495 void *private_data
);
1497 int mkdir_p(const char *dir
, int mode
);
1498 void mkdir_p_or_die(const char *dir
, int mode
);
1500 ssize_t
sys_read(int fd
, void *buf
, size_t count
);
1501 ssize_t
sys_write(int fd
, const void *buf
, size_t count
);