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 * pid of the ctdbd daemon
43 extern pid_t ctdbd_pid
;
46 a tcp connection description
47 also used by tcp_add and tcp_remove controls
49 struct ctdb_tcp_connection
{
50 ctdb_sock_addr src_addr
;
51 ctdb_sock_addr dst_addr
;
54 /* the wire representation for a tcp tickle array */
55 struct ctdb_tcp_wire_array
{
57 struct ctdb_tcp_connection connections
[1];
60 /* the list of tcp tickles used by get/set tcp tickle list */
61 struct ctdb_control_tcp_tickle_list
{
63 struct ctdb_tcp_wire_array tickles
;
67 array of tcp connections
69 struct ctdb_tcp_array
{
71 struct ctdb_tcp_connection
*connections
;
75 /* all tunable variables go in here */
77 uint32_t max_redirect_count
;
78 uint32_t seqnum_interval
; /* unit is ms */
79 uint32_t control_timeout
;
80 uint32_t traverse_timeout
;
81 uint32_t keepalive_interval
;
82 uint32_t keepalive_limit
;
83 uint32_t recover_timeout
;
84 uint32_t recover_interval
;
85 uint32_t election_timeout
;
86 uint32_t takeover_timeout
;
87 uint32_t monitor_interval
;
88 uint32_t tickle_update_interval
;
89 uint32_t script_timeout
;
90 uint32_t script_timeout_count
; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
91 uint32_t script_unhealthy_on_timeout
; /* obsolete */
92 uint32_t recovery_grace_period
;
93 uint32_t recovery_ban_period
;
94 uint32_t database_hash_size
;
95 uint32_t database_max_dead
;
96 uint32_t rerecovery_timeout
;
98 uint32_t deterministic_public_ips
;
99 uint32_t reclock_ping_period
;
100 uint32_t no_ip_failback
;
101 uint32_t disable_ip_failover
;
102 uint32_t verbose_memory_names
;
103 uint32_t recd_ping_timeout
;
104 uint32_t recd_ping_failcount
;
105 uint32_t log_latency_ms
;
106 uint32_t reclock_latency_ms
;
107 uint32_t recovery_drop_all_ips
;
108 uint32_t verify_recovery_lock
;
109 uint32_t vacuum_interval
;
110 uint32_t vacuum_max_run_time
;
111 uint32_t repack_limit
;
112 uint32_t vacuum_limit
;
113 uint32_t max_queue_depth_drop_msg
;
114 uint32_t use_status_events_for_monitoring
;
115 uint32_t allow_unhealthy_db_read
;
116 uint32_t stat_history_interval
;
117 uint32_t deferred_attach_timeout
;
118 uint32_t vacuum_fast_path_count
;
119 uint32_t lcp2_public_ip_assignment
;
120 uint32_t allow_client_db_attach
;
121 uint32_t recover_pdb_by_seqnum
;
122 uint32_t deferred_rebalance_on_node_add
;
123 uint32_t fetch_collapse
;
124 uint32_t hopcount_make_sticky
;
125 uint32_t sticky_duration
;
126 uint32_t sticky_pindown
;
127 uint32_t no_ip_takeover
;
128 uint32_t db_record_count_warn
;
129 uint32_t db_record_size_warn
;
130 uint32_t db_size_warn
;
131 uint32_t pulldb_preallocation_size
;
132 uint32_t no_ip_host_on_all_disabled
;
133 uint32_t samba3_hack
;
137 an installed ctdb remote call
139 struct ctdb_registered_call
{
140 struct ctdb_registered_call
*next
, *prev
;
146 this address structure might need to be generalised later for some
149 struct ctdb_address
{
155 check that a pnn is valid
157 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
160 /* called from the queue code when a packet comes in. Called with data==NULL
162 typedef void (*ctdb_queue_cb_fn_t
)(uint8_t *data
, size_t length
,
165 /* used for callbacks in ctdb_control requests */
166 typedef void (*ctdb_control_callback_fn_t
)(struct ctdb_context
*,
167 int32_t status
, TDB_DATA data
,
168 const char *errormsg
,
171 structure describing a connected client in the daemon
174 struct ctdb_context
*ctdb
;
176 struct ctdb_queue
*queue
;
179 struct ctdb_tcp_list
*tcp_list
;
181 uint32_t num_persistent_updates
;
182 struct ctdb_client_notify_list
*notify
;
187 /* state associated with a public ip address */
189 struct ctdb_vnn
*prev
, *next
;
191 struct ctdb_iface
*iface
;
193 ctdb_sock_addr public_address
;
194 uint8_t public_netmask_bits
;
196 /* the node number that is serving this public address, if any.
197 If no node serves this ip it is set to -1 */
200 /* List of clients to tickle for this public address */
201 struct ctdb_tcp_array
*tcp_array
;
203 /* whether we need to update the other nodes with changes to our list
204 of connected clients */
205 bool tcp_update_needed
;
207 /* a context to hang sending gratious arp events off */
208 TALLOC_CTX
*takeover_ctx
;
210 struct ctdb_kill_tcp
*killtcp
;
212 /* Set to true any time an update to this VNN is in flight.
213 This helps to avoid races. */
214 bool update_in_flight
;
216 /* If CTDB_CONTROL_DEL_PUBLIC_IP is received for this IP
217 * address then this flag is set. It will be deleted in the
218 * release IP callback. */
223 state associated with one node
226 struct ctdb_context
*ctdb
;
227 struct ctdb_address address
;
228 const char *name
; /* for debug messages */
229 void *private_data
; /* private to transport */
233 /* used by the dead node monitoring */
238 /* used to track node capabilities, is only valid/tracked inside the
241 uint32_t capabilities
;
243 /* a list of controls pending to this node, so we can time them out quickly
244 if the node becomes disconnected */
245 struct daemon_control_state
*pending_controls
;
247 /* used by the recovery daemon when distributing ip addresses
248 across the nodes. it needs to know which public ip's can be handled
251 struct ctdb_all_public_ips
*known_public_ips
;
252 struct ctdb_all_public_ips
*available_public_ips
;
253 /* used by the recovery dameon to track when a node should be banned */
254 struct ctdb_banning_state
*ban_state
;
258 transport specific methods
260 struct ctdb_methods
{
261 int (*initialise
)(struct ctdb_context
*); /* initialise transport structures */
262 int (*start
)(struct ctdb_context
*); /* start the transport */
263 int (*add_node
)(struct ctdb_node
*); /* setup a new node */
264 int (*connect_node
)(struct ctdb_node
*); /* connect to node */
265 int (*queue_pkt
)(struct ctdb_node
*, uint8_t *data
, uint32_t length
);
266 void *(*allocate_pkt
)(TALLOC_CTX
*mem_ctx
, size_t );
267 void (*shutdown
)(struct ctdb_context
*); /* shutdown transport */
268 void (*restart
)(struct ctdb_node
*); /* stop and restart the connection */
272 transport calls up to the ctdb layer
274 struct ctdb_upcalls
{
275 /* recv_pkt is called when a packet comes in */
276 void (*recv_pkt
)(struct ctdb_context
*, uint8_t *data
, uint32_t length
);
278 /* node_dead is called when an attempt to send to a node fails */
279 void (*node_dead
)(struct ctdb_node
*);
281 /* node_connected is called when a connection to a node is established */
282 void (*node_connected
)(struct ctdb_node
*);
285 /* list of message handlers - needs to be changed to a more efficient data
286 structure so we can find a message handler given a srvid quickly */
287 struct ctdb_message_list_header
{
288 struct ctdb_message_list_header
*next
, *prev
;
289 struct ctdb_context
*ctdb
;
291 struct ctdb_message_list
*m
;
293 struct ctdb_message_list
{
294 struct ctdb_message_list
*next
, *prev
;
295 struct ctdb_message_list_header
*h
;
296 ctdb_msg_fn_t message_handler
;
297 void *message_private
;
300 /* additional data required for the daemon mode */
301 struct ctdb_daemon_data
{
304 struct ctdb_queue
*queue
;
308 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
310 if (value > ctdb->statistics.counter) { \
311 ctdb->statistics.counter = c->hopcount; \
313 if (value > ctdb->statistics_current.counter) { \
314 ctdb->statistics_current.counter = c->hopcount; \
318 #define CTDB_INCREMENT_STAT(ctdb, counter) \
320 ctdb->statistics.counter++; \
321 ctdb->statistics_current.counter++; \
324 #define CTDB_DECREMENT_STAT(ctdb, counter) \
326 if (ctdb->statistics.counter > 0) \
327 ctdb->statistics.counter--; \
328 if (ctdb->statistics_current.counter > 0) \
329 ctdb->statistics_current.counter--; \
332 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
334 ctdb_db->statistics.counter++; \
337 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
339 if (ctdb_db->statistics.counter > 0) \
340 ctdb_db->statistics.counter--; \
343 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
345 if (value > ctdb->statistics.counter.max) \
346 ctdb->statistics.counter.max = value; \
347 if (value > ctdb->statistics_current.counter.max) \
348 ctdb->statistics_current.counter.max = value; \
350 if (ctdb->statistics.counter.num == 0 || \
351 value < ctdb->statistics.counter.min) \
352 ctdb->statistics.counter.min = value; \
353 if (ctdb->statistics_current.counter.num == 0 || \
354 value < ctdb->statistics_current.counter.min) \
355 ctdb->statistics_current.counter.min = value; \
357 ctdb->statistics.counter.total += value; \
358 ctdb->statistics_current.counter.total += value; \
360 ctdb->statistics.counter.num++; \
361 ctdb->statistics_current.counter.num++; \
363 if (ctdb->tunable.reclock_latency_ms != 0) { \
364 if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
366 ("High RECLOCK latency %fs for operation %s\n", \
372 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value) \
374 if (value > ctdb_db->statistics.counter.max) \
375 ctdb_db->statistics.counter.max = value; \
376 if (ctdb_db->statistics.counter.num == 0 || \
377 value < ctdb_db->statistics.counter.min) \
378 ctdb_db->statistics.counter.min = value; \
380 ctdb_db->statistics.counter.total += value; \
381 ctdb_db->statistics.counter.num++; \
383 if (ctdb_db->ctdb->tunable.log_latency_ms != 0) { \
384 if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) { \
386 ("High latency %.6fs for operation %s on database %s\n",\
387 value, operation, ctdb_db->db_name)); \
392 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
394 double l = timeval_elapsed(&t); \
396 if (l > ctdb->statistics.counter.max) \
397 ctdb->statistics.counter.max = l; \
398 if (l > ctdb->statistics_current.counter.max) \
399 ctdb->statistics_current.counter.max = l; \
401 if (ctdb->statistics.counter.num == 0 || \
402 l < ctdb->statistics.counter.min) \
403 ctdb->statistics.counter.min = l; \
404 if (ctdb->statistics_current.counter.num == 0 || \
405 l < ctdb->statistics_current.counter.min) \
406 ctdb->statistics_current.counter.min = l; \
408 ctdb->statistics.counter.total += l; \
409 ctdb->statistics_current.counter.total += l; \
411 ctdb->statistics.counter.num++; \
412 ctdb->statistics_current.counter.num++; \
414 if (ctdb->tunable.log_latency_ms != 0) { \
415 if (l*1000 > ctdb->tunable.log_latency_ms) { \
416 DEBUG(DEBUG_WARNING, \
417 ("High latency %.6fs for operation %s on database %s\n",\
418 l, operation, db->db_name)); \
425 /* a structure that contains the elements required for the write record
428 struct ctdb_write_record
{
432 unsigned char blob
[1];
435 enum ctdb_freeze_mode
{CTDB_FREEZE_NONE
, CTDB_FREEZE_PENDING
, CTDB_FREEZE_FROZEN
};
438 CTDB_RUNSTATE_UNKNOWN
,
441 CTDB_RUNSTATE_FIRST_RECOVERY
,
442 CTDB_RUNSTATE_STARTUP
,
443 CTDB_RUNSTATE_RUNNING
,
444 CTDB_RUNSTATE_SHUTDOWN
,
447 const char *runstate_to_string(enum ctdb_runstate runstate
);
448 enum ctdb_runstate
runstate_from_string(const char *label
);
449 void ctdb_set_runstate(struct ctdb_context
*ctdb
, enum ctdb_runstate runstate
);
451 void ctdb_shutdown_sequence(struct ctdb_context
*ctdb
, int exit_code
);
453 #define CTDB_MONITORING_ACTIVE 0
454 #define CTDB_MONITORING_DISABLED 1
456 #define NUM_DB_PRIORITIES 3
457 /* main state of the ctdb daemon */
458 struct ctdb_context
{
459 struct tevent_context
*ev
;
460 struct timeval ctdbd_start_time
;
461 struct timeval last_recovery_started
;
462 struct timeval last_recovery_finished
;
463 uint32_t recovery_mode
;
464 TALLOC_CTX
*tickle_update_context
;
465 TALLOC_CTX
*keepalive_ctx
;
466 TALLOC_CTX
*check_public_ifaces_ctx
;
467 struct ctdb_tunable tunable
;
468 enum ctdb_freeze_mode freeze_mode
[NUM_DB_PRIORITIES
+1];
469 struct ctdb_freeze_handle
*freeze_handles
[NUM_DB_PRIORITIES
+1];
470 bool freeze_transaction_started
;
471 uint32_t freeze_transaction_id
;
472 struct ctdb_address address
;
474 const char *db_directory
;
475 const char *db_directory_persistent
;
476 const char *db_directory_state
;
477 struct tdb_wrap
*db_persistent_health
;
478 uint32_t db_persistent_startup_generation
;
479 uint64_t db_persistent_check_errors
;
480 uint64_t max_persistent_check_errors
;
481 const char *transport
;
482 char *recovery_lock_file
;
483 int recovery_lock_fd
;
484 uint32_t pnn
; /* our own pnn */
486 uint32_t num_connected
;
488 uint32_t capabilities
;
489 struct idr_context
*idr
;
491 struct ctdb_node
**nodes
; /* array of nodes in the cluster - indexed by vnn */
492 struct ctdb_vnn
*vnn
; /* list of public ip addresses and interfaces */
493 struct ctdb_vnn
*single_ip_vnn
; /* a structure for the single ip */
494 struct ctdb_iface
*ifaces
; /* list of local interfaces */
496 const struct ctdb_methods
*methods
; /* transport methods */
497 const struct ctdb_upcalls
*upcalls
; /* transport upcalls */
498 void *private_data
; /* private to transport */
499 struct ctdb_db_context
*db_list
;
500 struct ctdb_message_list_header
*message_list_header
;
501 struct tdb_context
*message_list_indexdb
;
502 struct ctdb_daemon_data daemon
;
503 struct ctdb_statistics statistics
;
504 struct ctdb_statistics statistics_current
;
505 #define MAX_STAT_HISTORY 100
506 struct ctdb_statistics statistics_history
[MAX_STAT_HISTORY
];
507 struct ctdb_vnn_map
*vnn_map
;
508 uint32_t num_clients
;
509 uint32_t recovery_master
;
510 struct ctdb_call_state
*pending_calls
;
511 struct ctdb_client_ip
*client_ip_list
;
512 bool do_checkpublicip
;
513 struct trbt_tree
*server_ids
;
515 const char *event_script_dir
;
516 const char *notification_script
;
517 const char *default_public_interface
;
521 enum ctdb_runstate runstate
;
522 struct ctdb_monitor_state
*monitor
;
523 struct ctdb_log_state
*log
;
524 int start_as_disabled
;
525 int start_as_stopped
;
527 uint32_t event_script_timeouts
; /* counting how many consecutive times an eventscript has timedout */
528 uint32_t *recd_ping_count
;
529 TALLOC_CTX
*recd_ctx
; /* a context used to track recoverd monitoring events */
530 TALLOC_CTX
*release_ips_ctx
; /* a context used to automatically drop all IPs if we fail to recover the node */
532 TALLOC_CTX
*event_script_ctx
;
535 struct ctdb_event_script_state
*current_monitor
;
536 struct ctdb_scripts_wire
*last_status
[CTDB_EVENT_MAX
];
538 TALLOC_CTX
*banning_ctx
;
540 struct ctdb_vacuum_child_context
*vacuumers
;
542 /* mapping from pid to ctdb_client * */
543 struct ctdb_client_pid_list
*client_pids
;
545 /* used in the recovery daemon to remember the ip allocation */
546 struct trbt_tree
*ip_tree
;
548 /* Used to defer db attach requests while in recovery mode */
549 struct ctdb_deferred_attach_context
*deferred_attach
;
551 /* if we are a child process, do we have a domain socket to send controls on */
552 bool can_send_controls
;
554 /* list of event script callback functions that are active */
555 struct event_script_callback
*script_callbacks
;
557 struct ctdb_reloadips_handle
*reload_ips
;
559 const char *nodes_file
;
560 const char *public_addresses_file
;
561 struct trbt_tree
*child_processes
;
563 /* Used for locking record/db/alldb */
564 int lock_num_pending
;
565 struct lock_context
*lock_current
;
566 struct lock_context
*lock_pending
;
569 struct ctdb_db_context
{
570 struct ctdb_db_context
*next
, *prev
;
571 struct ctdb_context
*ctdb
;
575 bool readonly
; /* Do we support read-only delegations ? */
576 bool sticky
; /* Do we support sticky records ? */
579 struct tdb_wrap
*ltdb
;
580 struct tdb_context
*rottdb
; /* ReadOnly tracking TDB */
581 struct ctdb_registered_call
*calls
; /* list of registered calls */
583 struct timed_event
*seqnum_update
;
584 struct ctdb_traverse_local_handle
*traverse
;
585 struct ctdb_vacuum_handle
*vacuum_handle
;
586 char *unhealthy_reason
;
587 int pending_requests
;
588 struct revokechild_handle
*revokechild_active
;
589 struct ctdb_persistent_state
*persistent_state
;
590 struct trbt_tree
*delete_queue
;
591 struct trbt_tree
*sticky_records
;
592 int (*ctdb_ltdb_store_fn
)(struct ctdb_db_context
*ctdb_db
,
594 struct ctdb_ltdb_header
*header
,
597 /* used to track which records we are currently fetching
598 so we can avoid sending duplicate fetch requests
600 struct trbt_tree
*deferred_fetch
;
602 struct ctdb_db_statistics statistics
;
604 int lock_num_current
;
608 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
609 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
610 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
611 return -1; }} while (0)
613 #define CTDB_NO_MEMORY_VOID(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__); \
618 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
619 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
620 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
621 return NULL; }} while (0)
623 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
624 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
625 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
629 structure passed in set_call control
631 struct ctdb_control_set_call
{
638 struct for kill_tcp control
640 struct ctdb_control_killtcp
{
641 ctdb_sock_addr src_addr
;
642 ctdb_sock_addr dst_addr
;
646 struct holding a ctdb_sock_addr and an interface name,
647 used to add/remove public addresses
649 struct ctdb_control_ip_iface
{
657 struct holding a ctdb_sock_addr and an interface name,
658 used for send_gratious_arp
660 struct ctdb_control_gratious_arp
{
668 persistent store control - update this record on all other nodes
670 struct ctdb_control_persistent_store
{
677 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
679 struct ctdb_node_flag_change
{
686 struct for admin setting a ban
688 struct ctdb_ban_info
{
693 enum call_state
{CTDB_CALL_WAIT
, CTDB_CALL_DONE
, CTDB_CALL_ERROR
};
695 #define CTDB_LMASTER_ANY 0xffffffff
698 state of a in-progress ctdb call
700 struct ctdb_call_state
{
701 struct ctdb_call_state
*next
, *prev
;
702 enum call_state state
;
704 struct ctdb_req_call
*c
;
705 struct ctdb_db_context
*ctdb_db
;
707 struct ctdb_call
*call
;
710 void (*fn
)(struct ctdb_call_state
*);
716 /* used for fetch_lock */
717 struct ctdb_fetch_handle
{
718 struct ctdb_db_context
*ctdb_db
;
721 struct ctdb_ltdb_header header
;
724 /* internal prototypes */
725 void ctdb_set_error(struct ctdb_context
*ctdb
, const char *fmt
, ...) PRINTF_ATTRIBUTE(2,3);
726 void ctdb_fatal(struct ctdb_context
*ctdb
, const char *msg
);
727 void ctdb_die(struct ctdb_context
*ctdb
, const char *msg
);
728 void ctdb_external_trace(void);
729 bool ctdb_same_address(struct ctdb_address
*a1
, struct ctdb_address
*a2
);
730 int ctdb_parse_address(struct ctdb_context
*ctdb
,
731 TALLOC_CTX
*mem_ctx
, const char *str
,
732 struct ctdb_address
*address
);
733 bool ctdb_same_ip(const ctdb_sock_addr
*ip1
, const ctdb_sock_addr
*ip2
);
734 bool ctdb_same_sockaddr(const ctdb_sock_addr
*ip1
, const ctdb_sock_addr
*ip2
);
735 uint32_t ctdb_hash(const TDB_DATA
*key
);
736 uint32_t ctdb_hash_string(const char *str
);
737 void ctdb_request_call(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
738 void ctdb_request_dmaster(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
739 void ctdb_request_message(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
740 void ctdb_reply_dmaster(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
741 void ctdb_reply_call(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
742 void ctdb_reply_error(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
744 uint32_t ctdb_lmaster(struct ctdb_context
*ctdb
, const TDB_DATA
*key
);
745 int ctdb_ltdb_fetch(struct ctdb_db_context
*ctdb_db
,
746 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
747 TALLOC_CTX
*mem_ctx
, TDB_DATA
*data
);
748 int ctdb_ltdb_store(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
,
749 struct ctdb_ltdb_header
*header
, TDB_DATA data
);
750 int ctdb_ltdb_delete(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
751 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context
*ctdb_db
,
752 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
753 TALLOC_CTX
*mem_ctx
, TDB_DATA
*data
);
754 int32_t ctdb_control_start_persistent_update(struct ctdb_context
*ctdb
,
755 struct ctdb_req_control
*c
,
757 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context
*ctdb
,
758 struct ctdb_req_control
*c
,
760 void ctdb_queue_packet(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
761 void ctdb_queue_packet_opcode(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
, unsigned opcode
);
762 int ctdb_ltdb_lock_requeue(struct ctdb_db_context
*ctdb_db
,
763 TDB_DATA key
, struct ctdb_req_header
*hdr
,
764 void (*recv_pkt
)(void *, struct ctdb_req_header
*),
765 void *recv_context
, bool ignore_generation
);
766 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context
*ctdb_db
,
767 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
768 struct ctdb_req_header
*hdr
, TDB_DATA
*data
,
769 void (*recv_pkt
)(void *, struct ctdb_req_header
*),
770 void *recv_context
, bool ignore_generation
);
771 void ctdb_input_pkt(struct ctdb_context
*ctdb
, struct ctdb_req_header
*);
773 struct ctdb_call_state
*ctdb_call_local_send(struct ctdb_db_context
*ctdb_db
,
774 struct ctdb_call
*call
,
775 struct ctdb_ltdb_header
*header
,
779 int ctdb_start_daemon(struct ctdb_context
*ctdb
, bool do_fork
,
781 struct ctdb_call_state
*ctdbd_call_send(struct ctdb_db_context
*ctdb_db
, struct ctdb_call
*call
);
782 int ctdbd_call_recv(struct ctdb_call_state
*state
, struct ctdb_call
*call
);
785 queue a packet for sending
787 int ctdb_queue_send(struct ctdb_queue
*queue
, uint8_t *data
, uint32_t length
);
790 setup the fd used by the queue
792 int ctdb_queue_set_fd(struct ctdb_queue
*queue
, int fd
);
795 setup a packet queue on a socket
797 struct ctdb_queue
*ctdb_queue_setup(struct ctdb_context
*ctdb
,
798 TALLOC_CTX
*mem_ctx
, int fd
, int alignment
,
800 ctdb_queue_cb_fn_t callback
,
801 void *private_data
, const char *fmt
, ...)
802 PRINTF_ATTRIBUTE(7,8);
805 allocate a packet for use in client<->daemon communication
807 struct ctdb_req_header
*_ctdbd_allocate_pkt(struct ctdb_context
*ctdb
,
809 enum ctdb_operation operation
,
810 size_t length
, size_t slength
,
812 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
813 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
815 struct ctdb_req_header
*_ctdb_transport_allocate(struct ctdb_context
*ctdb
,
817 enum ctdb_operation operation
,
818 size_t length
, size_t slength
,
820 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
821 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
823 int ctdb_queue_length(struct ctdb_queue
*queue
);
826 lock a record in the ltdb, given a key
828 int ctdb_ltdb_lock(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
831 unlock a record in the ltdb, given a key
833 int ctdb_ltdb_unlock(struct ctdb_db_context
*ctdb_db
, TDB_DATA key
);
837 make a ctdb call to the local daemon - async send. Called from client context.
839 This constructs a ctdb_call request and queues it for processing.
840 This call never blocks.
842 struct ctdb_call_state
*ctdb_client_call_send(struct ctdb_db_context
*ctdb_db
,
843 struct ctdb_call
*call
);
846 make a recv call to the local ctdb daemon - called from client context
848 This is called when the program wants to wait for a ctdb_call to complete and get the
849 results. This call will block unless the call has already completed.
851 int ctdb_client_call_recv(struct ctdb_call_state
*state
, struct ctdb_call
*call
);
853 int ctdb_client_send_message(struct ctdb_context
*ctdb
, uint32_t vnn
,
854 uint64_t srvid
, TDB_DATA data
);
859 int ctdb_daemon_send_message(struct ctdb_context
*ctdb
, uint32_t pnn
,
860 uint64_t srvid
, TDB_DATA data
);
863 struct ctdb_call_state
*ctdb_daemon_call_send(struct ctdb_db_context
*ctdb_db
,
864 struct ctdb_call
*call
);
866 int ctdb_daemon_call_recv(struct ctdb_call_state
*state
, struct ctdb_call
*call
);
868 struct ctdb_call_state
*ctdb_daemon_call_send_remote(struct ctdb_db_context
*ctdb_db
,
869 struct ctdb_call
*call
,
870 struct ctdb_ltdb_header
*header
);
872 int ctdb_call_local(struct ctdb_db_context
*ctdb_db
, struct ctdb_call
*call
,
873 struct ctdb_ltdb_header
*header
, TALLOC_CTX
*mem_ctx
,
874 TDB_DATA
*data
, bool updatetdb
);
876 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
878 void ctdb_recv_raw_pkt(void *p
, uint8_t *data
, uint32_t length
);
880 int ctdb_socket_connect(struct ctdb_context
*ctdb
);
881 void ctdb_client_read_cb(uint8_t *data
, size_t cnt
, void *args
);
883 #define CTDB_BAD_REQID ((uint32_t)-1)
884 uint32_t ctdb_reqid_new(struct ctdb_context
*ctdb
, void *state
);
885 void *_ctdb_reqid_find(struct ctdb_context
*ctdb
, uint32_t reqid
, const char *type
, const char *location
);
886 void ctdb_reqid_remove(struct ctdb_context
*ctdb
, uint32_t reqid
);
888 void ctdb_request_control(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
889 void ctdb_reply_control(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
);
891 int ctdb_daemon_send_control(struct ctdb_context
*ctdb
, uint32_t destnode
,
892 uint64_t srvid
, uint32_t opcode
, uint32_t client_id
, uint32_t flags
,
894 ctdb_control_callback_fn_t callback
,
897 int32_t ctdb_control_db_attach(struct ctdb_context
*ctdb
, TDB_DATA indata
,
898 TDB_DATA
*outdata
, uint64_t tdb_flags
,
899 bool persistent
, uint32_t client_id
,
900 struct ctdb_req_control
*c
,
902 int32_t ctdb_control_db_detach(struct ctdb_context
*ctdb
, TDB_DATA indata
,
905 int ctdb_daemon_set_call(struct ctdb_context
*ctdb
, uint32_t db_id
,
906 ctdb_fn_t fn
, int id
);
908 int ctdb_control(struct ctdb_context
*ctdb
, uint32_t destnode
, uint64_t srvid
,
909 uint32_t opcode
, uint32_t flags
, TDB_DATA data
,
910 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
, int32_t *status
,
911 struct timeval
*timeout
, char **errormsg
);
912 int ctdb_control_recv(struct ctdb_context
*ctdb
,
913 struct ctdb_client_control_state
*state
,
915 TDB_DATA
*outdata
, int32_t *status
, char **errormsg
);
917 struct ctdb_client_control_state
*
918 ctdb_control_send(struct ctdb_context
*ctdb
,
919 uint32_t destnode
, uint64_t srvid
,
920 uint32_t opcode
, uint32_t flags
, TDB_DATA data
,
922 struct timeval
*timeout
,
928 #define CHECK_CONTROL_DATA_SIZE(size) do { \
929 if (indata.dsize != size) { \
930 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
931 opcode, (unsigned)indata.dsize, (unsigned)size)); \
936 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
937 if (indata.dsize < size) { \
938 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
939 opcode, (unsigned)indata.dsize, (unsigned)size)); \
944 int ctdb_control_getvnnmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
945 int ctdb_control_setvnnmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
946 int ctdb_control_getdbmap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
947 int ctdb_control_getnodemapv4(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
948 int ctdb_control_getnodemap(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
949 int ctdb_control_writerecord(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
, TDB_DATA
*outdata
);
952 /* structure used for pulldb control */
953 struct ctdb_control_pulldb
{
958 /* structure used for sending lists of records */
959 struct ctdb_marshall_buffer
{
966 structure for setting a tunable
968 struct ctdb_control_set_tunable
{
975 structure for getting a tunable
977 struct ctdb_control_get_tunable
{
983 structure for listing tunables
985 struct ctdb_control_list_tunable
{
987 /* returns a : separated list of tunable names */
992 struct ctdb_node_and_flagsv4
{
995 struct sockaddr_in sin
;
998 struct ctdb_node_mapv4
{
1000 struct ctdb_node_and_flagsv4 nodes
[1];
1003 struct ctdb_control_wipe_database
{
1005 uint32_t transaction_id
;
1009 state of a in-progress ctdb call in client
1011 struct ctdb_client_call_state
{
1012 enum call_state state
;
1014 struct ctdb_db_context
*ctdb_db
;
1015 struct ctdb_call
*call
;
1017 void (*fn
)(struct ctdb_client_call_state
*);
1023 int32_t ctdb_control_traverse_start_ext(struct ctdb_context
*ctdb
,
1027 uint32_t client_id
);
1028 int32_t ctdb_control_traverse_start(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1029 TDB_DATA
*outdata
, uint32_t srcnode
, uint32_t client_id
);
1030 int32_t ctdb_control_traverse_all(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
1031 int32_t ctdb_control_traverse_all_ext(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
1032 int32_t ctdb_control_traverse_data(struct ctdb_context
*ctdb
, TDB_DATA data
, TDB_DATA
*outdata
);
1033 int32_t ctdb_control_traverse_kill(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1034 TDB_DATA
*outdata
, uint32_t srcnode
);
1036 int ctdb_dispatch_message(struct ctdb_context
*ctdb
, uint64_t srvid
, TDB_DATA data
);
1037 bool ctdb_check_message_handler(struct ctdb_context
*ctdb
, uint64_t srvid
);
1039 int daemon_register_message_handler(struct ctdb_context
*ctdb
, uint32_t client_id
, uint64_t srvid
);
1040 int ctdb_deregister_message_handler(struct ctdb_context
*ctdb
, uint64_t srvid
, void *private_data
);
1041 int daemon_deregister_message_handler(struct ctdb_context
*ctdb
, uint32_t client_id
, uint64_t srvid
);
1042 int daemon_check_srvids(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1045 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context
*ctdb
, uint32_t db_id
);
1046 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context
*ctdb
, uint32_t db_id
, uint32_t srcnode
);
1048 struct ctdb_rec_data
*ctdb_marshall_record(TALLOC_CTX
*mem_ctx
, uint32_t reqid
,
1049 TDB_DATA key
, struct ctdb_ltdb_header
*, TDB_DATA data
);
1051 struct ctdb_rec_data
*ctdb_marshall_loop_next(struct ctdb_marshall_buffer
*m
, struct ctdb_rec_data
*r
,
1053 struct ctdb_ltdb_header
*header
,
1054 TDB_DATA
*key
, TDB_DATA
*data
);
1056 int32_t ctdb_control_pull_db(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1057 int32_t ctdb_control_push_db(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1059 int32_t ctdb_control_set_recmode(struct ctdb_context
*ctdb
,
1060 struct ctdb_req_control
*c
,
1061 TDB_DATA indata
, bool *async_reply
,
1062 const char **errormsg
);
1063 void ctdb_request_control_reply(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
,
1064 TDB_DATA
*outdata
, int32_t status
, const char *errormsg
);
1066 int32_t ctdb_control_freeze(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, bool *async_reply
);
1067 int32_t ctdb_control_thaw(struct ctdb_context
*ctdb
, uint32_t priority
);
1069 int ctdb_start_recoverd(struct ctdb_context
*ctdb
);
1070 void ctdb_stop_recoverd(struct ctdb_context
*ctdb
);
1072 uint32_t ctdb_get_num_active_nodes(struct ctdb_context
*ctdb
);
1074 void ctdb_disable_monitoring(struct ctdb_context
*ctdb
);
1075 void ctdb_enable_monitoring(struct ctdb_context
*ctdb
);
1076 void ctdb_stop_monitoring(struct ctdb_context
*ctdb
);
1077 void ctdb_wait_for_first_recovery(struct ctdb_context
*ctdb
);
1078 void ctdb_start_tcp_tickle_update(struct ctdb_context
*ctdb
);
1079 void ctdb_send_keepalive(struct ctdb_context
*ctdb
, uint32_t destnode
);
1080 void ctdb_start_keepalive(struct ctdb_context
*ctdb
);
1081 void ctdb_stop_keepalive(struct ctdb_context
*ctdb
);
1082 int32_t ctdb_run_eventscripts(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, TDB_DATA data
, bool *async_reply
);
1085 void ctdb_daemon_cancel_controls(struct ctdb_context
*ctdb
, struct ctdb_node
*node
);
1086 void ctdb_call_resend_all(struct ctdb_context
*ctdb
);
1087 void ctdb_node_dead(struct ctdb_node
*node
);
1088 void ctdb_node_connected(struct ctdb_node
*node
);
1089 bool ctdb_blocking_freeze(struct ctdb_context
*ctdb
);
1090 void set_scheduler(void);
1091 void reset_scheduler(void);
1093 struct tevent_signal
*ctdb_init_sigchld(struct ctdb_context
*ctdb
);
1094 void ctdb_track_child(struct ctdb_context
*ctdb
, pid_t pid
);
1095 pid_t
ctdb_fork(struct ctdb_context
*ctdb
);
1096 pid_t
ctdb_fork_no_free_ringbuffer(struct ctdb_context
*ctdb
);
1097 void ctdb_set_child_info(TALLOC_CTX
*mem_ctx
, const char *child_name_fmt
, ...);
1098 bool ctdb_is_child_process(void);
1099 int ctdb_kill(struct ctdb_context
*ctdb
, pid_t pid
, int signum
);
1101 int32_t ctdb_control_takeover_ip(struct ctdb_context
*ctdb
,
1102 struct ctdb_req_control
*c
,
1105 int32_t ctdb_control_takeover_ipv4(struct ctdb_context
*ctdb
,
1106 struct ctdb_req_control
*c
,
1109 int32_t ctdb_control_release_ip(struct ctdb_context
*ctdb
,
1110 struct ctdb_req_control
*c
,
1113 int32_t ctdb_control_release_ipv4(struct ctdb_context
*ctdb
,
1114 struct ctdb_req_control
*c
,
1117 int32_t ctdb_control_ipreallocated(struct ctdb_context
*ctdb
,
1118 struct ctdb_req_control
*c
,
1120 int32_t ctdb_control_start_recovery(struct ctdb_context
*ctdb
,
1121 struct ctdb_req_control
*c
,
1123 int32_t ctdb_control_end_recovery(struct ctdb_context
*ctdb
,
1124 struct ctdb_req_control
*c
,
1127 struct ctdb_public_ipv4
{
1129 struct sockaddr_in sin
;
1132 int ctdb_ctrl_takeover_ip(struct ctdb_context
*ctdb
, struct timeval timeout
,
1133 uint32_t destnode
, struct ctdb_public_ip
*ip
);
1134 int ctdb_ctrl_release_ip(struct ctdb_context
*ctdb
, struct timeval timeout
,
1135 uint32_t destnode
, struct ctdb_public_ip
*ip
);
1137 struct ctdb_all_public_ipsv4
{
1139 struct ctdb_public_ipv4 ips
[1];
1142 int32_t ctdb_control_get_public_ipsv4(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, TDB_DATA
*outdata
);
1143 int32_t ctdb_control_get_public_ips(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, TDB_DATA
*outdata
);
1144 int ctdb_ctrl_get_public_ips(struct ctdb_context
*ctdb
,
1145 struct timeval timeout
,
1147 TALLOC_CTX
*mem_ctx
,
1148 struct ctdb_all_public_ips
**ips
);
1149 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1150 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context
*ctdb
,
1151 struct timeval timeout
, uint32_t destnode
,
1152 TALLOC_CTX
*mem_ctx
,
1154 struct ctdb_all_public_ips
**ips
);
1155 int ctdb_ctrl_get_public_ipsv4(struct ctdb_context
*ctdb
,
1156 struct timeval timeout
, uint32_t destnode
,
1157 TALLOC_CTX
*mem_ctx
, struct ctdb_all_public_ips
**ips
);
1159 struct ctdb_control_iface_info
{
1160 char name
[CTDB_IFACE_SIZE
+2];
1161 uint16_t link_state
;
1162 uint32_t references
;
1165 struct ctdb_control_public_ip_info
{
1166 struct ctdb_public_ip ip
;
1167 uint32_t active_idx
;
1169 struct ctdb_control_iface_info ifaces
[1];
1172 struct ctdb_control_get_ifaces
{
1174 struct ctdb_control_iface_info ifaces
[1];
1177 int32_t ctdb_control_get_public_ip_info(struct ctdb_context
*ctdb
,
1178 struct ctdb_req_control
*c
,
1181 int32_t ctdb_control_get_ifaces(struct ctdb_context
*ctdb
,
1182 struct ctdb_req_control
*c
,
1184 int32_t ctdb_control_set_iface_link(struct ctdb_context
*ctdb
,
1185 struct ctdb_req_control
*c
,
1187 int ctdb_ctrl_get_public_ip_info(struct ctdb_context
*ctdb
,
1188 struct timeval timeout
, uint32_t destnode
,
1189 TALLOC_CTX
*mem_ctx
,
1190 const ctdb_sock_addr
*addr
,
1191 struct ctdb_control_public_ip_info
**info
);
1192 int ctdb_ctrl_get_ifaces(struct ctdb_context
*ctdb
,
1193 struct timeval timeout
, uint32_t destnode
,
1194 TALLOC_CTX
*mem_ctx
,
1195 struct ctdb_control_get_ifaces
**ifaces
);
1196 int ctdb_ctrl_set_iface_link(struct ctdb_context
*ctdb
,
1197 struct timeval timeout
, uint32_t destnode
,
1198 TALLOC_CTX
*mem_ctx
,
1199 const struct ctdb_control_iface_info
*info
);
1201 /* from takeover/system.c */
1202 uint32_t uint16_checksum(uint16_t *data
, size_t n
);
1203 int ctdb_sys_send_arp(const ctdb_sock_addr
*addr
, const char *iface
);
1204 bool ctdb_sys_have_ip(ctdb_sock_addr
*addr
);
1205 char *ctdb_sys_find_ifname(ctdb_sock_addr
*addr
);
1206 bool ctdb_sys_check_iface_exists(const char *iface
);
1207 int ctdb_get_peer_pid(const int fd
, pid_t
*peer_pid
);
1208 int ctdb_sys_send_tcp(const ctdb_sock_addr
*dest
,
1209 const ctdb_sock_addr
*src
,
1210 uint32_t seq
, uint32_t ack
, int rst
);
1212 /* Details of a byte range lock */
1213 struct ctdb_lock_info
{
1220 char *ctdb_get_process_name(pid_t pid
);
1221 int ctdb_set_process_name(const char *name
);
1222 bool ctdb_get_lock_info(pid_t req_pid
, struct ctdb_lock_info
*lock_info
);
1223 bool ctdb_get_blocker_pid(struct ctdb_lock_info
*reqlock
, pid_t
*blocker_pid
);
1225 typedef void (*client_async_callback
)(struct ctdb_context
*ctdb
, uint32_t node_pnn
, int32_t res
, TDB_DATA outdata
, void *callback_data
);
1227 int ctdb_set_public_addresses(struct ctdb_context
*ctdb
, bool check_addresses
);
1228 int ctdb_set_single_public_ip(struct ctdb_context
*ctdb
,
1231 int ctdb_set_event_script(struct ctdb_context
*ctdb
, const char *script
);
1232 int ctdb_set_notification_script(struct ctdb_context
*ctdb
, const char *script
);
1233 int ctdb_takeover_run(struct ctdb_context
*ctdb
, struct ctdb_node_map
*nodemap
,
1234 uint32_t *force_rebalance_nodes
,
1235 client_async_callback fail_callback
, void *callback_data
);
1237 int32_t ctdb_control_tcp_client(struct ctdb_context
*ctdb
, uint32_t client_id
,
1239 int32_t ctdb_control_tcp_add(struct ctdb_context
*ctdb
, TDB_DATA indata
, bool tcp_update_needed
);
1240 int32_t ctdb_control_tcp_remove(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1241 int32_t ctdb_control_startup(struct ctdb_context
*ctdb
, uint32_t vnn
);
1242 int32_t ctdb_control_kill_tcp(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1243 int32_t ctdb_control_send_gratious_arp(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1244 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1245 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1247 void ctdb_takeover_client_destructor_hook(struct ctdb_client
*client
);
1248 int ctdb_event_script(struct ctdb_context
*ctdb
, enum ctdb_eventscript_call call
);
1249 int ctdb_event_script_args(struct ctdb_context
*ctdb
, enum ctdb_eventscript_call call
,
1250 const char *fmt
, ...) PRINTF_ATTRIBUTE(3,4);
1251 int ctdb_event_script_callback(struct ctdb_context
*ctdb
,
1252 TALLOC_CTX
*mem_ctx
,
1253 void (*callback
)(struct ctdb_context
*, int, void *),
1255 enum ctdb_eventscript_call call
,
1256 const char *fmt
, ...) PRINTF_ATTRIBUTE(6,7);
1257 void ctdb_release_all_ips(struct ctdb_context
*ctdb
);
1259 void set_nonblocking(int fd
);
1260 void set_close_on_exec(int fd
);
1262 bool ctdb_recovery_lock(struct ctdb_context
*ctdb
, bool keep
);
1264 int ctdb_set_recovery_lock_file(struct ctdb_context
*ctdb
, const char *file
);
1266 int32_t ctdb_control_get_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1268 int32_t ctdb_control_set_tunable(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1269 int32_t ctdb_control_list_tunables(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1270 int32_t ctdb_control_try_delete_records(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1271 int32_t ctdb_control_receive_records(struct ctdb_context
*ctdb
, TDB_DATA indata
, TDB_DATA
*outdata
);
1272 int32_t ctdb_control_add_public_address(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1273 int32_t ctdb_control_del_public_address(struct ctdb_context
*ctdb
,
1274 struct ctdb_req_control
*c
,
1275 TDB_DATA recdata
, bool *async_reply
);
1277 void ctdb_tunables_set_defaults(struct ctdb_context
*ctdb
);
1279 int32_t ctdb_control_modflags(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1281 int ctdb_ctrl_get_all_tunables(struct ctdb_context
*ctdb
,
1282 struct timeval timeout
,
1284 struct ctdb_tunable
*tunables
);
1286 void ctdb_start_freeze(struct ctdb_context
*ctdb
, uint32_t priority
);
1288 bool parse_ip_mask(const char *s
, const char *iface
, ctdb_sock_addr
*addr
, unsigned *mask
);
1289 bool parse_ip_port(const char *s
, ctdb_sock_addr
*addr
);
1290 bool parse_ip(const char *s
, const char *iface
, unsigned port
, ctdb_sock_addr
*addr
);
1291 bool parse_ipv4(const char *s
, unsigned port
, struct sockaddr_in
*sin
);
1294 int ctdb_sys_open_capture_socket(const char *iface
, void **private_data
);
1295 int ctdb_sys_close_capture_socket(void *private_data
);
1296 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
);
1298 int ctdb_ctrl_killtcp(struct ctdb_context
*ctdb
,
1299 struct timeval timeout
,
1301 struct ctdb_control_killtcp
*killtcp
);
1303 int ctdb_ctrl_add_public_ip(struct ctdb_context
*ctdb
,
1304 struct timeval timeout
,
1306 struct ctdb_control_ip_iface
*pub
);
1308 int ctdb_ctrl_del_public_ip(struct ctdb_context
*ctdb
,
1309 struct timeval timeout
,
1311 struct ctdb_control_ip_iface
*pub
);
1313 int ctdb_ctrl_gratious_arp(struct ctdb_context
*ctdb
,
1314 struct timeval timeout
,
1316 ctdb_sock_addr
*addr
,
1317 const char *ifname
);
1319 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context
*ctdb
,
1320 struct timeval timeout
,
1322 TALLOC_CTX
*mem_ctx
,
1323 ctdb_sock_addr
*addr
,
1324 struct ctdb_control_tcp_tickle_list
**list
);
1327 int32_t ctdb_control_register_server_id(struct ctdb_context
*ctdb
,
1330 int32_t ctdb_control_check_server_id(struct ctdb_context
*ctdb
,
1332 int32_t ctdb_control_unregister_server_id(struct ctdb_context
*ctdb
,
1334 int32_t ctdb_control_get_server_id_list(struct ctdb_context
*ctdb
,
1336 int32_t ctdb_control_uptime(struct ctdb_context
*ctdb
,
1339 int ctdb_attach_databases(struct ctdb_context
*ctdb
);
1341 int32_t ctdb_control_persistent_store(struct ctdb_context
*ctdb
,
1342 struct ctdb_req_control
*c
,
1343 TDB_DATA recdata
, bool *async_reply
);
1344 int32_t ctdb_control_update_record(struct ctdb_context
*ctdb
,
1345 struct ctdb_req_control
*c
, TDB_DATA recdata
,
1347 int32_t ctdb_control_trans2_commit(struct ctdb_context
*ctdb
,
1348 struct ctdb_req_control
*c
,
1349 TDB_DATA recdata
, bool *async_reply
);
1351 int32_t ctdb_control_trans3_commit(struct ctdb_context
*ctdb
,
1352 struct ctdb_req_control
*c
,
1353 TDB_DATA recdata
, bool *async_reply
);
1355 void ctdb_persistent_finish_trans3_commits(struct ctdb_context
*ctdb
);
1357 int32_t ctdb_control_transaction_start(struct ctdb_context
*ctdb
, uint32_t id
);
1358 int32_t ctdb_control_transaction_commit(struct ctdb_context
*ctdb
, uint32_t id
);
1359 int32_t ctdb_control_transaction_cancel(struct ctdb_context
*ctdb
);
1360 int32_t ctdb_control_wipe_database(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1361 int32_t ctdb_control_db_set_healthy(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1362 int32_t ctdb_control_db_get_health(struct ctdb_context
*ctdb
,
1367 int ctdb_vacuum(struct ctdb_context
*ctdb
, int argc
, const char **argv
);
1368 int ctdb_repack(struct ctdb_context
*ctdb
, int argc
, const char **argv
);
1370 int32_t ctdb_monitoring_mode(struct ctdb_context
*ctdb
);
1371 bool ctdb_stopped_monitoring(struct ctdb_context
*ctdb
);
1372 int ctdb_set_child_logging(struct ctdb_context
*ctdb
);
1373 void lockdown_memory(bool valgrinding
);
1375 struct client_async_data
{
1376 enum ctdb_controls opcode
;
1377 bool dont_log_errors
;
1379 uint32_t fail_count
;
1380 client_async_callback callback
;
1381 client_async_callback fail_callback
;
1382 void *callback_data
;
1384 void ctdb_client_async_add(struct client_async_data
*data
, struct ctdb_client_control_state
*state
);
1385 int ctdb_client_async_wait(struct ctdb_context
*ctdb
, struct client_async_data
*data
);
1386 int ctdb_client_async_control(struct ctdb_context
*ctdb
,
1387 enum ctdb_controls opcode
,
1390 struct timeval timeout
,
1391 bool dont_log_errors
,
1393 client_async_callback client_callback
,
1394 client_async_callback fail_callback
,
1395 void *callback_data
);
1397 void ctdb_load_nodes_file(struct ctdb_context
*ctdb
);
1399 int ctdb_control_reload_nodes_file(struct ctdb_context
*ctdb
, uint32_t opcode
);
1401 int32_t ctdb_dump_memory(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1402 int32_t ctdb_control_get_capabilities(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1404 int32_t ctdb_control_trans2_finished(struct ctdb_context
*ctdb
,
1405 struct ctdb_req_control
*c
);
1406 int32_t ctdb_control_trans2_error(struct ctdb_context
*ctdb
,
1407 struct ctdb_req_control
*c
);
1408 int32_t ctdb_control_trans2_active(struct ctdb_context
*ctdb
,
1409 struct ctdb_req_control
*c
,
1412 char *ctdb_addr_to_str(ctdb_sock_addr
*addr
);
1413 unsigned ctdb_addr_to_port(ctdb_sock_addr
*addr
);
1414 void ctdb_canonicalize_ip(const ctdb_sock_addr
*ip
, ctdb_sock_addr
*cip
);
1416 int32_t ctdb_control_recd_ping(struct ctdb_context
*ctdb
);
1417 int32_t ctdb_control_set_recmaster(struct ctdb_context
*ctdb
, uint32_t opcode
, TDB_DATA indata
);
1419 extern int script_log_level
;
1420 extern bool fast_start
;
1421 extern const char *ctdbd_pidfile
;
1423 int32_t ctdb_control_get_event_script_status(struct ctdb_context
*ctdb
,
1427 int ctdb_log_event_script_output(struct ctdb_context
*ctdb
, char *str
, uint16_t len
);
1428 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context
*ctdb
, struct timeval timeout
, double latency
);
1430 int32_t ctdb_control_stop_node(struct ctdb_context
*ctdb
);
1431 int32_t ctdb_control_continue_node(struct ctdb_context
*ctdb
);
1433 void ctdb_stop_vacuuming(struct ctdb_context
*ctdb
);
1434 int ctdb_vacuum_init(struct ctdb_db_context
*ctdb_db
);
1436 int32_t ctdb_control_enable_script(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1437 int32_t ctdb_control_disable_script(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1439 void ctdb_local_node_got_banned(struct ctdb_context
*ctdb
);
1440 int32_t ctdb_control_set_ban_state(struct ctdb_context
*ctdb
, TDB_DATA indata
);
1441 int32_t ctdb_control_get_ban_state(struct ctdb_context
*ctdb
, TDB_DATA
*outdata
);
1442 int32_t ctdb_control_set_db_priority(struct ctdb_context
*ctdb
, TDB_DATA indata
,
1443 uint32_t client_id
);
1444 void ctdb_ban_self(struct ctdb_context
*ctdb
);
1446 int32_t ctdb_control_register_notify(struct ctdb_context
*ctdb
, uint32_t client_id
, TDB_DATA indata
);
1448 int32_t ctdb_control_deregister_notify(struct ctdb_context
*ctdb
, uint32_t client_id
, TDB_DATA indata
);
1450 int start_syslog_daemon(struct ctdb_context
*ctdb
);
1452 /* Where to send the log messages back to */
1453 struct ctdb_get_log_addr
{
1459 extern int log_ringbuf_size
;
1461 TDB_DATA
ctdb_log_ringbuffer_collect_log(TALLOC_CTX
*mem_ctx
,
1462 enum debug_level max_level
);
1463 void ctdb_collect_log(struct ctdb_context
*ctdb
, struct ctdb_get_log_addr
*log_addr
);
1464 void ctdb_clear_log(struct ctdb_context
*ctdb
);
1465 int32_t ctdb_control_get_log(struct ctdb_context
*ctdb
, TDB_DATA addr
);
1466 int32_t ctdb_control_clear_log(struct ctdb_context
*ctdb
);
1467 void ctdb_log_ringbuffer_free(void);
1469 struct ctdb_log_state
*ctdb_vfork_with_logging(TALLOC_CTX
*mem_ctx
,
1470 struct ctdb_context
*ctdb
,
1471 const char *log_prefix
,
1474 const char **helper_argv
,
1475 void (*logfn
)(const char *, uint16_t, void *),
1476 void *logfn_private
, pid_t
*pid
);
1479 int32_t ctdb_control_process_exists(struct ctdb_context
*ctdb
, pid_t pid
);
1480 struct ctdb_client
*ctdb_find_client_by_pid(struct ctdb_context
*ctdb
, pid_t pid
);
1482 int32_t ctdb_control_get_db_seqnum(struct ctdb_context
*ctdb
,
1486 int ctdb_load_persistent_health(struct ctdb_context
*ctdb
,
1487 struct ctdb_db_context
*ctdb_db
);
1488 int ctdb_update_persistent_health(struct ctdb_context
*ctdb
,
1489 struct ctdb_db_context
*ctdb_db
,
1490 const char *reason
,/* NULL means healthy */
1491 int num_healthy_nodes
);
1492 int ctdb_recheck_persistent_health(struct ctdb_context
*ctdb
);
1494 void ctdb_run_notification_script(struct ctdb_context
*ctdb
, const char *event
);
1496 void ctdb_fault_setup(void);
1498 int verify_remote_ip_allocation(struct ctdb_context
*ctdb
,
1499 struct ctdb_all_public_ips
*ips
,
1501 int update_ip_assignment_tree(struct ctdb_context
*ctdb
,
1502 struct ctdb_public_ip
*ip
);
1504 int ctdb_init_tevent_logging(struct ctdb_context
*ctdb
);
1506 int ctdb_statistics_init(struct ctdb_context
*ctdb
);
1508 int32_t ctdb_control_get_stat_history(struct ctdb_context
*ctdb
,
1509 struct ctdb_req_control
*c
,
1512 int ctdb_deferred_drop_all_ips(struct ctdb_context
*ctdb
);
1514 int ctdb_process_deferred_attach(struct ctdb_context
*ctdb
);
1517 * structure to pass to a schedule_for_deletion_control
1519 struct ctdb_control_schedule_for_deletion
{
1521 struct ctdb_ltdb_header hdr
;
1523 uint8_t key
[1]; /* key[] */
1526 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context
*ctdb
,
1530 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context
*ctdb_db
,
1531 const struct ctdb_ltdb_header
*hdr
,
1534 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context
*ctdb_db
,
1535 const struct ctdb_ltdb_header
*hdr
,
1536 const TDB_DATA key
);
1538 struct ctdb_ltdb_header
*ctdb_header_from_record_handle(struct ctdb_record_handle
*h
);
1540 int ctdb_trackingdb_add_pnn(struct ctdb_context
*ctdb
, TDB_DATA
*data
, uint32_t pnn
);
1542 typedef void (*ctdb_trackingdb_cb
)(struct ctdb_context
*ctdb
, uint32_t pnn
, void *private_data
);
1544 void ctdb_trackingdb_traverse(struct ctdb_context
*ctdb
, TDB_DATA data
, ctdb_trackingdb_cb cb
, void *private_data
);
1546 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
);
1548 typedef void (*deferred_requeue_fn
)(void *call_context
, struct ctdb_req_header
*hdr
);
1550 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
);
1552 int ctdb_set_db_readonly(struct ctdb_context
*ctdb
, struct ctdb_db_context
*ctdb_db
);
1554 int ctdb_null_func(struct ctdb_call_info
*call
);
1556 int ctdb_fetch_func(struct ctdb_call_info
*call
);
1558 int ctdb_fetch_with_header_func(struct ctdb_call_info
*call
);
1560 int32_t ctdb_control_get_db_statistics(struct ctdb_context
*ctdb
,
1564 int ctdb_set_db_sticky(struct ctdb_context
*ctdb
, struct ctdb_db_context
*ctdb_db
);
1567 description for a message to reload all ips via recovery master/daemon
1569 struct reloadips_all_reply
{
1574 int32_t ctdb_control_reload_public_ips(struct ctdb_context
*ctdb
, struct ctdb_req_control
*c
, bool *async_reply
);
1576 int ctdb_start_monitoring_interfaces(struct ctdb_context
*ctdb
);
1578 /* from server/ctdb_lock.c */
1579 struct lock_request
;
1581 int ctdb_lockall_mark_prio(struct ctdb_context
*ctdb
, uint32_t priority
);
1582 int ctdb_lockall_unmark_prio(struct ctdb_context
*ctdb
, uint32_t priority
);
1584 void ctdb_lock_free_request_context(struct lock_request
*lock_req
);
1586 struct lock_request
*ctdb_lock_record(struct ctdb_db_context
*ctdb_db
,
1589 void (*callback
)(void *, bool),
1590 void *private_data
);
1592 struct lock_request
*ctdb_lock_db(struct ctdb_db_context
*ctdb_db
,
1594 void (*callback
)(void *, bool),
1595 void *private_data
);
1597 struct lock_request
*ctdb_lock_alldb_prio(struct ctdb_context
*ctdb
,
1600 void (*callback
)(void *, bool),
1601 void *private_data
);
1603 struct lock_request
*ctdb_lock_alldb(struct ctdb_context
*ctdb
,
1605 void (*callback
)(void *, bool),
1606 void *private_data
);
1608 int mkdir_p(const char *dir
, int mode
);
1609 void mkdir_p_or_die(const char *dir
, int mode
);