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
24 #include <sys/socket.h>
25 #include <netinet/in.h>
27 /* location of daemon socket */
28 #define CTDB_PATH "/tmp/ctdb.socket"
30 /* default ctdb port number */
31 #define CTDB_PORT 4379
33 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
34 #define CTDB_DS_ALIGNMENT 8
37 #define CTDB_NULL_FUNC 0xFF000001
38 #define CTDB_FETCH_FUNC 0xFF000002
42 recovery daemon memdump reply address
44 struct rd_memdump_reply {
50 definitions for different socket structures
52 typedef struct sockaddr_in ctdb_addr_in;
53 typedef struct sockaddr_in6 ctdb_addr_in6;
61 a tcp connection description
63 struct ctdb_tcp_connection {
64 struct sockaddr_in saddr;
65 struct sockaddr_in daddr;
68 /* the wire representation for a tcp tickle array */
69 struct ctdb_tcp_wire_array {
71 struct ctdb_tcp_connection connections[1];
74 /* the list of tcp tickles used by get/set tcp tickle list */
75 struct ctdb_control_tcp_tickle_list {
76 struct sockaddr_in ip;
77 struct ctdb_tcp_wire_array tickles;
81 array of tcp connections
83 struct ctdb_tcp_array {
85 struct ctdb_tcp_connection *connections;
89 /* all tunable variables go in here */
91 uint32_t max_redirect_count;
92 uint32_t seqnum_frequency;
93 uint32_t control_timeout;
94 uint32_t traverse_timeout;
95 uint32_t keepalive_interval;
96 uint32_t keepalive_limit;
98 uint32_t recover_timeout;
99 uint32_t recover_interval;
100 uint32_t election_timeout;
101 uint32_t takeover_timeout;
102 uint32_t monitor_interval;
103 uint32_t tickle_update_interval;
104 uint32_t script_timeout;
105 uint32_t script_ban_count; /* ban after this many consec timeouts*/
106 uint32_t recovery_grace_period;
107 uint32_t recovery_ban_period;
108 uint32_t database_hash_size;
109 uint32_t database_max_dead;
110 uint32_t rerecovery_timeout;
111 uint32_t enable_bans;
112 uint32_t deterministic_public_ips;
113 uint32_t disable_when_unhealthy;
114 uint32_t reclock_ping_period;
115 uint32_t no_ip_failback;
116 uint32_t verbose_memory_names;
120 an installed ctdb remote call
122 struct ctdb_registered_call {
123 struct ctdb_registered_call *next, *prev;
129 this address structure might need to be generalised later for some
132 struct ctdb_address {
138 check that a pnn is valid
140 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
143 /* called from the queue code when a packet comes in. Called with data==NULL
145 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
148 /* used for callbacks in ctdb_control requests */
149 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
150 int32_t status, TDB_DATA data,
151 const char *errormsg,
155 structure describing a connected client in the daemon
158 struct ctdb_context *ctdb;
160 struct ctdb_queue *queue;
163 struct ctdb_tcp_list *tcp_list;
167 /* state associated with a public ip address */
169 struct ctdb_vnn *prev, *next;
172 struct sockaddr_in public_address;
173 uint8_t public_netmask_bits;
175 /* the node number that is serving this public address, if any.
176 If no node serves this ip it is set to -1 */
179 /* List of clients to tickle for this public address */
180 struct ctdb_tcp_array *tcp_array;
182 /* whether we need to update the other nodes with changes to our list
183 of connected clients */
184 bool tcp_update_needed;
186 /* a context to hang sending gratious arp events off */
187 TALLOC_CTX *takeover_ctx;
189 struct ctdb_kill_tcp *killtcp;
193 state associated with one node
196 struct ctdb_context *ctdb;
197 struct ctdb_address address;
198 const char *name; /* for debug messages */
199 void *private_data; /* private to transport */
201 #define NODE_FLAGS_DISCONNECTED 0x00000001 /* node isn't connected */
202 #define NODE_FLAGS_UNHEALTHY 0x00000002 /* monitoring says node is unhealthy */
203 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
204 #define NODE_FLAGS_BANNED 0x00000008 /* recovery daemon has banned the node */
205 #define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
206 #define NODE_FLAGS_INACTIVE (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
209 /* used by the dead node monitoring */
214 /* used to track node capabilities, is only valid/tracked inside the
217 uint32_t capabilities;
219 /* a list of controls pending to this node, so we can time them out quickly
220 if the node becomes disconnected */
221 struct daemon_control_state *pending_controls;
223 /* used by the recovery daemon when distributing ip addresses
224 across the nodes. it needs to know which public ip's can be handled
227 struct ctdb_all_public_ips *public_ips;
231 transport specific methods
233 struct ctdb_methods {
234 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
235 int (*start)(struct ctdb_context *); /* start protocol processing */
236 int (*add_node)(struct ctdb_node *); /* setup a new node */
237 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
238 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
239 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
240 void (*restart)(struct ctdb_node *); /* stop and restart the connection */
244 transport calls up to the ctdb layer
246 struct ctdb_upcalls {
247 /* recv_pkt is called when a packet comes in */
248 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
250 /* node_dead is called when an attempt to send to a node fails */
251 void (*node_dead)(struct ctdb_node *);
253 /* node_connected is called when a connection to a node is established */
254 void (*node_connected)(struct ctdb_node *);
257 /* list of message handlers - needs to be changed to a more efficient data
258 structure so we can find a message handler given a srvid quickly */
259 struct ctdb_message_list {
260 struct ctdb_context *ctdb;
261 struct ctdb_message_list *next, *prev;
263 ctdb_message_fn_t message_handler;
264 void *message_private;
267 /* additional data required for the daemon mode */
268 struct ctdb_daemon_data {
271 struct ctdb_queue *queue;
275 ctdb status information
277 struct ctdb_statistics {
278 uint32_t num_clients;
281 uint32_t client_packets_sent;
282 uint32_t client_packets_recv;
283 uint32_t node_packets_sent;
284 uint32_t node_packets_recv;
285 uint32_t keepalive_packets_sent;
286 uint32_t keepalive_packets_recv;
290 uint32_t req_dmaster;
291 uint32_t reply_dmaster;
292 uint32_t reply_error;
293 uint32_t req_message;
294 uint32_t req_control;
295 uint32_t reply_control;
299 uint32_t req_message;
300 uint32_t req_control;
307 uint32_t total_calls;
308 uint32_t pending_calls;
309 uint32_t lockwait_calls;
310 uint32_t pending_lockwait_calls;
311 uint32_t childwrite_calls;
312 uint32_t pending_childwrite_calls;
313 uint32_t memory_used;
314 uint32_t __last_counter; /* hack for control_statistics_all */
315 uint32_t max_hop_count;
316 double max_call_latency;
317 double max_lockwait_latency;
318 double max_childwrite_latency;
322 #define INVALID_GENERATION 1
323 /* table that contains the mapping between a hash value and lmaster
325 struct ctdb_vnn_map {
332 a wire representation of the vnn map
334 struct ctdb_vnn_map_wire {
340 /* a structure that contains the elements required for the write record
343 struct ctdb_write_record {
347 unsigned char blob[1];
350 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
352 #define CTDB_MONITORING_ACTIVE 0
353 #define CTDB_MONITORING_DISABLED 1
355 /* The different capabilities of the ctdb daemon. */
356 #define CTDB_CAP_RECMASTER 0x00000001
357 #define CTDB_CAP_LMASTER 0x00000002
359 /* main state of the ctdb daemon */
360 struct ctdb_context {
361 struct event_context *ev;
362 struct timeval ctdbd_start_time;
363 struct timeval last_recovery_started;
364 struct timeval last_recovery_finished;
365 uint32_t recovery_mode;
366 TALLOC_CTX *tickle_update_context;
367 TALLOC_CTX *keepalive_ctx;
368 struct ctdb_tunable tunable;
369 enum ctdb_freeze_mode freeze_mode;
370 struct ctdb_freeze_handle *freeze_handle;
371 struct ctdb_address address;
373 const char *db_directory;
374 const char *db_directory_persistent;
375 const char *transport;
377 char *node_list_file;
378 char *recovery_lock_file;
379 int recovery_lock_fd;
380 uint32_t pnn; /* our own pnn */
382 uint32_t num_connected;
384 uint32_t capabilities;
385 struct idr_context *idr;
387 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
388 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
389 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
391 const struct ctdb_methods *methods; /* transport methods */
392 const struct ctdb_upcalls *upcalls; /* transport upcalls */
393 void *private_data; /* private to transport */
394 struct ctdb_db_context *db_list;
395 struct ctdb_message_list *message_list;
396 struct ctdb_daemon_data daemon;
397 struct ctdb_statistics statistics;
398 struct ctdb_vnn_map *vnn_map;
399 uint32_t num_clients;
400 uint32_t recovery_master;
401 struct ctdb_call_state *pending_calls;
402 struct ctdb_client_ip *client_ip_list;
404 void *saved_scheduler_param;
405 struct _trbt_tree_t *server_ids;
406 const char *event_script_dir;
407 const char *default_public_interface;
412 struct ctdb_monitor_state *monitor;
413 struct ctdb_log_state *log;
414 int start_as_disabled;
415 uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
416 TALLOC_CTX *eventscripts_ctx; /* a context to hold data for the RUN_EVENTSCRIPTS control */
419 struct ctdb_db_context {
420 struct ctdb_db_context *next, *prev;
421 struct ctdb_context *ctdb;
426 struct tdb_wrap *ltdb;
427 struct ctdb_registered_call *calls; /* list of registered calls */
429 struct timed_event *te;
430 uint32_t client_tdb_flags;
434 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
435 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
436 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
437 return -1; }} while (0)
439 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
440 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
441 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
444 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
445 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
446 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
447 return NULL; }} while (0)
449 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
450 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
451 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
455 the extended header for records in the ltdb
457 struct ctdb_ltdb_header {
464 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
465 CTDB_CONTROL_STATISTICS = 1,
467 CTDB_CONTROL_PING = 3,
468 CTDB_CONTROL_GETDBPATH = 4,
469 CTDB_CONTROL_GETVNNMAP = 5,
470 CTDB_CONTROL_SETVNNMAP = 6,
471 CTDB_CONTROL_GET_DEBUG = 7,
472 CTDB_CONTROL_SET_DEBUG = 8,
473 CTDB_CONTROL_GET_DBMAP = 9,
474 CTDB_CONTROL_GET_NODEMAP = 10,
475 CTDB_CONTROL_SET_DMASTER = 11,
477 CTDB_CONTROL_PULL_DB = 13,
478 CTDB_CONTROL_PUSH_DB = 14,
479 CTDB_CONTROL_GET_RECMODE = 15,
480 CTDB_CONTROL_SET_RECMODE = 16,
481 CTDB_CONTROL_STATISTICS_RESET = 17,
482 CTDB_CONTROL_DB_ATTACH = 18,
483 CTDB_CONTROL_SET_CALL = 19,
484 CTDB_CONTROL_TRAVERSE_START = 20,
485 CTDB_CONTROL_TRAVERSE_ALL = 21,
486 CTDB_CONTROL_TRAVERSE_DATA = 22,
487 CTDB_CONTROL_REGISTER_SRVID = 23,
488 CTDB_CONTROL_DEREGISTER_SRVID = 24,
489 CTDB_CONTROL_GET_DBNAME = 25,
490 CTDB_CONTROL_ENABLE_SEQNUM = 26,
491 CTDB_CONTROL_UPDATE_SEQNUM = 27,
493 CTDB_CONTROL_DUMP_MEMORY = 29,
494 CTDB_CONTROL_GET_PID = 30,
495 CTDB_CONTROL_GET_RECMASTER = 31,
496 CTDB_CONTROL_SET_RECMASTER = 32,
497 CTDB_CONTROL_FREEZE = 33,
498 CTDB_CONTROL_THAW = 34,
499 CTDB_CONTROL_GET_PNN = 35,
500 CTDB_CONTROL_SHUTDOWN = 36,
501 CTDB_CONTROL_GET_MONMODE = 37,
506 CTDB_CONTROL_TAKEOVER_IP = 42,
507 CTDB_CONTROL_RELEASE_IP = 43,
508 CTDB_CONTROL_TCP_CLIENT = 44,
509 CTDB_CONTROL_TCP_ADD = 45,
510 CTDB_CONTROL_TCP_REMOVE = 46,
511 CTDB_CONTROL_STARTUP = 47,
512 CTDB_CONTROL_SET_TUNABLE = 48,
513 CTDB_CONTROL_GET_TUNABLE = 49,
514 CTDB_CONTROL_LIST_TUNABLES = 50,
515 CTDB_CONTROL_GET_PUBLIC_IPS = 51,
516 CTDB_CONTROL_MODIFY_FLAGS = 52,
517 CTDB_CONTROL_GET_ALL_TUNABLES = 53,
518 CTDB_CONTROL_KILL_TCP = 54,
519 CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55,
520 CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56,
521 CTDB_CONTROL_REGISTER_SERVER_ID = 57,
522 CTDB_CONTROL_UNREGISTER_SERVER_ID = 58,
523 CTDB_CONTROL_CHECK_SERVER_ID = 59,
524 CTDB_CONTROL_GET_SERVER_ID_LIST = 60,
525 CTDB_CONTROL_DB_ATTACH_PERSISTENT = 61,
526 CTDB_CONTROL_PERSISTENT_STORE = 62,
527 CTDB_CONTROL_UPDATE_RECORD = 63,
528 CTDB_CONTROL_SEND_GRATIOUS_ARP = 64,
529 CTDB_CONTROL_TRANSACTION_START = 65,
530 CTDB_CONTROL_TRANSACTION_COMMIT = 66,
531 CTDB_CONTROL_WIPE_DATABASE = 67,
533 CTDB_CONTROL_UPTIME = 69,
534 CTDB_CONTROL_START_RECOVERY = 70,
535 CTDB_CONTROL_END_RECOVERY = 71,
536 CTDB_CONTROL_RELOAD_NODES_FILE = 72,
537 CTDB_CONTROL_GET_RECLOCK_FILE = 73,
538 CTDB_CONTROL_TRY_DELETE_RECORDS = 74,
539 CTDB_CONTROL_ENABLE_MONITOR = 75,
540 CTDB_CONTROL_DISABLE_MONITOR = 76,
541 CTDB_CONTROL_ADD_PUBLIC_IP = 77,
542 CTDB_CONTROL_DEL_PUBLIC_IP = 78,
543 CTDB_CONTROL_RUN_EVENTSCRIPTS = 79,
544 CTDB_CONTROL_GET_CAPABILITIES = 80,
548 structure passed in set_call control
550 struct ctdb_control_set_call {
557 struct for tcp_client control
559 struct ctdb_control_tcp {
560 struct sockaddr_in src;
561 struct sockaddr_in dest;
565 struct for kill_tcp control
567 struct ctdb_control_killtcp {
568 struct sockaddr_in src;
569 struct sockaddr_in dst;
573 struct holding a sockaddr_in and an interface name,
574 used to add/remove public addresses
576 struct ctdb_control_ip_iface {
577 struct sockaddr_in sin;
584 struct holding a ctdb_sock_addr and an interface name,
585 used for send_gratious_arp
587 struct ctdb_control_gratious_arp {
595 struct for tcp_add and tcp_remove controls
597 struct ctdb_control_tcp_vnn {
598 struct sockaddr_in src;
599 struct sockaddr_in dest;
603 persistent store control - update this record on all other nodes
605 struct ctdb_control_persistent_store {
612 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
614 struct ctdb_node_flag_change {
621 structure to change flags on a node
623 struct ctdb_node_modflags {
629 struct for admin setting a ban
631 struct ctdb_ban_info {
636 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
638 #define CTDB_LMASTER_ANY 0xffffffff
641 state of a in-progress ctdb call
643 struct ctdb_call_state {
644 struct ctdb_call_state *next, *prev;
645 enum call_state state;
647 struct ctdb_req_call *c;
648 struct ctdb_db_context *ctdb_db;
650 struct ctdb_call *call;
653 void (*fn)(struct ctdb_call_state *);
659 /* used for fetch_lock */
660 struct ctdb_fetch_handle {
661 struct ctdb_db_context *ctdb_db;
664 struct ctdb_ltdb_header header;
670 enum ctdb_operation {
673 CTDB_REQ_DMASTER = 2,
674 CTDB_REPLY_DMASTER = 3,
675 CTDB_REPLY_ERROR = 4,
676 CTDB_REQ_MESSAGE = 5,
678 CTDB_REQ_CONTROL = 7,
679 CTDB_REPLY_CONTROL = 8,
680 CTDB_REQ_KEEPALIVE = 9,
683 #define CTDB_MAGIC 0x43544442 /* CTDB */
684 #define CTDB_VERSION 1
689 struct ctdb_req_header {
692 uint32_t ctdb_version;
700 struct ctdb_req_call {
701 struct ctdb_req_header hdr;
707 uint32_t calldatalen;
708 uint8_t data[1]; /* key[] followed by calldata[] */
711 struct ctdb_reply_call {
712 struct ctdb_req_header hdr;
718 struct ctdb_reply_error {
719 struct ctdb_req_header hdr;
725 struct ctdb_req_dmaster {
726 struct ctdb_req_header hdr;
735 struct ctdb_reply_dmaster {
736 struct ctdb_req_header hdr;
744 struct ctdb_req_message {
745 struct ctdb_req_header hdr;
751 struct ctdb_req_getdbpath {
752 struct ctdb_req_header hdr;
756 struct ctdb_reply_getdbpath {
757 struct ctdb_req_header hdr;
762 struct ctdb_req_control {
763 struct ctdb_req_header hdr;
767 #define CTDB_CTRL_FLAG_NOREPLY 1
773 struct ctdb_reply_control {
774 struct ctdb_req_header hdr;
781 struct ctdb_req_keepalive {
782 struct ctdb_req_header hdr;
785 /* internal prototypes */
786 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
787 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
788 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
789 bool parse_ip_mask(const char *s, struct sockaddr_in *ip, unsigned *mask);
790 int ctdb_parse_address(struct ctdb_context *ctdb,
791 TALLOC_CTX *mem_ctx, const char *str,
792 struct ctdb_address *address);
793 bool ctdb_same_ipv4(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
794 bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2);
795 bool ctdb_same_sockaddr(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
796 uint32_t ctdb_hash(const TDB_DATA *key);
797 uint32_t ctdb_hash_string(const char *str);
798 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
799 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
800 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
801 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
802 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
803 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
805 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
806 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
807 TDB_DATA key, struct ctdb_ltdb_header *header,
808 TALLOC_CTX *mem_ctx, TDB_DATA *data);
809 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
810 struct ctdb_ltdb_header *header, TDB_DATA data);
811 int ctdb_ltdb_persistent_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
812 struct ctdb_ltdb_header *header, TDB_DATA data);
813 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
814 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
815 TDB_DATA key, struct ctdb_req_header *hdr,
816 void (*recv_pkt)(void *, struct ctdb_req_header *),
817 void *recv_context, bool ignore_generation);
818 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
819 TDB_DATA key, struct ctdb_ltdb_header *header,
820 struct ctdb_req_header *hdr, TDB_DATA *data,
821 void (*recv_pkt)(void *, struct ctdb_req_header *),
822 void *recv_context, bool ignore_generation);
823 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
825 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
826 struct ctdb_call *call,
827 struct ctdb_ltdb_header *header,
831 int ctdbd_start(struct ctdb_context *ctdb);
832 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
833 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
836 queue a packet for sending
838 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
841 setup the fd used by the queue
843 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
846 setup a packet queue on a socket
848 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
849 TALLOC_CTX *mem_ctx, int fd, int alignment,
851 ctdb_queue_cb_fn_t callback,
855 allocate a packet for use in client<->daemon communication
857 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
859 enum ctdb_operation operation,
860 size_t length, size_t slength,
862 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
863 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
865 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
867 enum ctdb_operation operation,
868 size_t length, size_t slength,
870 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
871 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
875 lock a record in the ltdb, given a key
877 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
880 unlock a record in the ltdb, given a key
882 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
886 make a ctdb call to the local daemon - async send. Called from client context.
888 This constructs a ctdb_call request and queues it for processing.
889 This call never blocks.
891 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
892 struct ctdb_call *call);
895 make a recv call to the local ctdb daemon - called from client context
897 This is called when the program wants to wait for a ctdb_call to complete and get the
898 results. This call will block unless the call has already completed.
900 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
902 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
903 ctdb_message_fn_t handler,
906 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
907 uint64_t srvid, TDB_DATA data);
912 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
913 uint64_t srvid, TDB_DATA data);
916 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
918 void (*callback)(void *), void *private_data);
920 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
921 struct ctdb_call *call);
923 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
925 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
926 struct ctdb_call *call,
927 struct ctdb_ltdb_header *header);
929 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
930 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
933 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
935 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
937 int ctdb_socket_connect(struct ctdb_context *ctdb);
939 void ctdb_latency(double *latency, struct timeval t);
941 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
942 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
943 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
945 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
946 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
948 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
949 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
951 ctdb_control_callback_fn_t callback,
954 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
955 TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
957 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
958 ctdb_fn_t fn, int id);
960 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
961 uint32_t opcode, uint32_t flags, TDB_DATA data,
962 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
963 struct timeval *timeout, char **errormsg);
964 int ctdb_control_recv(struct ctdb_context *ctdb,
965 struct ctdb_client_control_state *state,
967 TDB_DATA *outdata, int32_t *status, char **errormsg);
969 struct ctdb_client_control_state *
970 ctdb_control_send(struct ctdb_context *ctdb,
971 uint32_t destnode, uint64_t srvid,
972 uint32_t opcode, uint32_t flags, TDB_DATA data,
974 struct timeval *timeout,
980 #define CHECK_CONTROL_DATA_SIZE(size) do { \
981 if (indata.dsize != size) { \
982 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
983 opcode, (unsigned)indata.dsize, (unsigned)size)); \
988 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
989 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
990 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
991 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
992 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
995 struct ctdb_traverse_start {
1002 structure used to pass record data between the child and parent
1004 struct ctdb_rec_data {
1013 /* structure used for pulldb control */
1014 struct ctdb_control_pulldb {
1019 /* structure used for pulldb control */
1020 struct ctdb_control_pulldb_reply {
1026 /* set dmaster control structure */
1027 struct ctdb_control_set_dmaster {
1033 structure for setting a tunable
1035 struct ctdb_control_set_tunable {
1042 structure for getting a tunable
1044 struct ctdb_control_get_tunable {
1050 structure for listing tunables
1052 struct ctdb_control_list_tunable {
1054 /* returns a : separated list of tunable names */
1059 /* table that contains a list of all nodes a ctdb knows about and their
1062 struct ctdb_node_and_flags {
1065 struct sockaddr_in sin;
1069 struct ctdb_node_map {
1071 struct ctdb_node_and_flags nodes[1];
1074 struct ctdb_control_wipe_database {
1076 uint32_t transaction_id;
1080 state of a in-progress ctdb call in client
1082 struct ctdb_client_call_state {
1083 enum call_state state;
1085 struct ctdb_db_context *ctdb_db;
1086 struct ctdb_call *call;
1088 void (*fn)(struct ctdb_client_call_state *);
1094 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
1095 TDB_DATA *outdata, uint32_t srcnode);
1096 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1097 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1099 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1101 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1102 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1103 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1105 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1106 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1107 int32_t ctdb_ltdb_set_seqnum_frequency(struct ctdb_context *ctdb, uint32_t frequency);
1109 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
1110 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1112 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1113 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1114 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1116 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1117 struct ctdb_req_control *c,
1118 TDB_DATA indata, bool *async_reply,
1119 const char **errormsg);
1120 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1121 TDB_DATA *outdata, int32_t status, const char *errormsg);
1123 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1124 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1126 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1127 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1129 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1131 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1132 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1133 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1134 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1135 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1136 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1137 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1138 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1139 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1142 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1143 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1144 void ctdb_node_dead(struct ctdb_node *node);
1145 void ctdb_node_connected(struct ctdb_node *node);
1146 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1147 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1148 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1149 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1150 struct ctdb_req_control *c,
1153 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1154 struct ctdb_req_control *c,
1157 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
1158 struct ctdb_req_control *c,
1160 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
1161 struct ctdb_req_control *c,
1164 struct ctdb_public_ip {
1166 struct sockaddr_in sin;
1168 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1169 uint32_t destnode, struct ctdb_public_ip *ip);
1170 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1171 uint32_t destnode, struct ctdb_public_ip *ip);
1173 struct ctdb_all_public_ips {
1175 struct ctdb_public_ip ips[1];
1177 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1178 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1179 struct timeval timeout, uint32_t destnode,
1180 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1183 /* from takeover/system.c */
1184 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1185 bool ctdb_sys_have_ip(struct sockaddr_in ip);
1186 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
1187 const ctdb_sock_addr *src,
1188 uint32_t seq, uint32_t ack, int rst);
1190 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1191 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1192 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1193 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1195 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1197 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1198 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1199 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1200 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1201 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1202 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1203 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1205 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1206 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1207 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1208 struct timeval timeout,
1209 TALLOC_CTX *mem_ctx,
1210 void (*callback)(struct ctdb_context *, int, void *),
1212 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1213 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1215 void set_nonblocking(int fd);
1216 void set_close_on_exec(int fd);
1218 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1220 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1222 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1224 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1225 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1226 int32_t ctdb_control_get_reclock_file(struct ctdb_context *ctdb, TDB_DATA *outdata);
1227 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1228 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1229 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1231 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1233 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1235 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1236 struct timeval timeout,
1238 struct ctdb_tunable *tunables);
1240 void ctdb_start_freeze(struct ctdb_context *ctdb);
1242 bool parse_ip_port(const char *s, ctdb_sock_addr *saddr);
1243 bool parse_ip(const char *s, ctdb_sock_addr *saddr);
1245 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1246 int ctdb_sys_close_capture_socket(void *private_data);
1247 int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst,
1248 uint32_t *ack_seq, uint32_t *seq);
1250 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1251 struct timeval timeout,
1253 struct ctdb_control_killtcp *killtcp);
1255 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1256 struct timeval timeout,
1258 struct ctdb_control_ip_iface *pub);
1260 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1261 struct timeval timeout,
1263 struct ctdb_control_ip_iface *pub);
1265 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1266 struct timeval timeout,
1268 ctdb_sock_addr *addr,
1269 const char *ifname);
1271 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1272 struct timeval timeout,
1274 TALLOC_CTX *mem_ctx,
1275 struct sockaddr_in *ip,
1276 struct ctdb_control_tcp_tickle_list **list);
1279 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1282 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1284 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1286 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1288 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1291 int ctdb_attach_persistent(struct ctdb_context *ctdb);
1293 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1294 struct ctdb_req_control *c,
1295 TDB_DATA recdata, bool *async_reply);
1296 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1297 struct ctdb_req_control *c, TDB_DATA recdata,
1300 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1301 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1302 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1305 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1306 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1308 void ctdb_block_signal(int signum);
1309 void ctdb_unblock_signal(int signum);
1310 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1311 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1314 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1316 struct client_async_data {
1317 enum ctdb_controls opcode;
1318 bool dont_log_errors;
1320 uint32_t fail_count;
1321 client_async_callback callback;
1322 client_async_callback fail_callback;
1323 void *callback_data;
1325 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1326 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1327 int ctdb_client_async_control(struct ctdb_context *ctdb,
1328 enum ctdb_controls opcode,
1330 struct timeval timeout,
1331 bool dont_log_errors,
1333 client_async_callback client_callback,
1334 client_async_callback fail_callback,
1335 void *callback_data);
1337 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1339 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1341 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1342 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);