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