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 a tcp connection description
52 struct ctdb_tcp_connection {
53 struct sockaddr_in saddr;
54 struct sockaddr_in daddr;
57 /* the wire representation for a tcp tickle array */
58 struct ctdb_tcp_wire_array {
60 struct ctdb_tcp_connection connections[1];
63 /* the list of tcp tickles used by get/set tcp tickle list */
64 struct ctdb_control_tcp_tickle_list {
65 struct sockaddr_in ip;
66 struct ctdb_tcp_wire_array tickles;
70 array of tcp connections
72 struct ctdb_tcp_array {
74 struct ctdb_tcp_connection *connections;
78 /* all tunable variables go in here */
80 uint32_t max_redirect_count;
81 uint32_t seqnum_frequency;
82 uint32_t control_timeout;
83 uint32_t traverse_timeout;
84 uint32_t keepalive_interval;
85 uint32_t keepalive_limit;
87 uint32_t recover_timeout;
88 uint32_t recover_interval;
89 uint32_t election_timeout;
90 uint32_t takeover_timeout;
91 uint32_t monitor_interval;
92 uint32_t tickle_update_interval;
93 uint32_t script_timeout;
94 uint32_t recovery_grace_period;
95 uint32_t recovery_ban_period;
96 uint32_t database_hash_size;
97 uint32_t database_max_dead;
98 uint32_t rerecovery_timeout;
100 uint32_t deterministic_public_ips;
101 uint32_t disable_when_unhealthy;
102 uint32_t reclock_ping_period;
103 uint32_t no_ip_failback;
104 uint32_t verbose_memory_names;
108 an installed ctdb remote call
110 struct ctdb_registered_call {
111 struct ctdb_registered_call *next, *prev;
117 this address structure might need to be generalised later for some
120 struct ctdb_address {
126 check that a pnn is valid
128 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
131 /* called from the queue code when a packet comes in. Called with data==NULL
133 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
136 /* used for callbacks in ctdb_control requests */
137 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
138 int32_t status, TDB_DATA data,
139 const char *errormsg,
143 structure describing a connected client in the daemon
146 struct ctdb_context *ctdb;
148 struct ctdb_queue *queue;
151 struct ctdb_tcp_list *tcp_list;
155 /* state associated with a public ip address */
157 struct ctdb_vnn *prev, *next;
160 struct sockaddr_in public_address;
161 uint8_t public_netmask_bits;
163 /* the node number that is serving this public address, if any.
164 If no node serves this ip it is set to -1 */
167 /* List of clients to tickle for this public address */
168 struct ctdb_tcp_array *tcp_array;
170 /* whether we need to update the other nodes with changes to our list
171 of connected clients */
172 bool tcp_update_needed;
174 /* a context to hang sending gratious arp events off */
175 TALLOC_CTX *takeover_ctx;
177 struct ctdb_kill_tcp *killtcp;
181 state associated with one node
184 struct ctdb_context *ctdb;
185 struct ctdb_address address;
186 const char *name; /* for debug messages */
187 void *private_data; /* private to transport */
189 #define NODE_FLAGS_DISCONNECTED 0x00000001 /* node isn't connected */
190 #define NODE_FLAGS_UNHEALTHY 0x00000002 /* monitoring says node is unhealthy */
191 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
192 #define NODE_FLAGS_BANNED 0x00000008 /* recovery daemon has banned the node */
193 #define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
194 #define NODE_FLAGS_INACTIVE (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
197 /* used by the dead node monitoring */
202 /* a list of controls pending to this node, so we can time them out quickly
203 if the node becomes disconnected */
204 struct daemon_control_state *pending_controls;
206 /* used by the recovery daemon when distributing ip addresses
207 across the nodes. it needs to know which public ip's can be handled
210 struct ctdb_all_public_ips *public_ips;
214 transport specific methods
216 struct ctdb_methods {
217 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
218 int (*start)(struct ctdb_context *); /* start protocol processing */
219 int (*add_node)(struct ctdb_node *); /* setup a new node */
220 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
221 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
222 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
223 void (*restart)(struct ctdb_node *); /* stop and restart the connection */
227 transport calls up to the ctdb layer
229 struct ctdb_upcalls {
230 /* recv_pkt is called when a packet comes in */
231 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
233 /* node_dead is called when an attempt to send to a node fails */
234 void (*node_dead)(struct ctdb_node *);
236 /* node_connected is called when a connection to a node is established */
237 void (*node_connected)(struct ctdb_node *);
240 /* list of message handlers - needs to be changed to a more efficient data
241 structure so we can find a message handler given a srvid quickly */
242 struct ctdb_message_list {
243 struct ctdb_context *ctdb;
244 struct ctdb_message_list *next, *prev;
246 ctdb_message_fn_t message_handler;
247 void *message_private;
250 /* additional data required for the daemon mode */
251 struct ctdb_daemon_data {
254 struct ctdb_queue *queue;
258 ctdb status information
260 struct ctdb_statistics {
261 uint32_t num_clients;
264 uint32_t client_packets_sent;
265 uint32_t client_packets_recv;
266 uint32_t node_packets_sent;
267 uint32_t node_packets_recv;
268 uint32_t keepalive_packets_sent;
269 uint32_t keepalive_packets_recv;
273 uint32_t req_dmaster;
274 uint32_t reply_dmaster;
275 uint32_t reply_error;
276 uint32_t req_message;
277 uint32_t req_control;
278 uint32_t reply_control;
282 uint32_t req_message;
283 uint32_t req_control;
290 uint32_t total_calls;
291 uint32_t pending_calls;
292 uint32_t lockwait_calls;
293 uint32_t pending_lockwait_calls;
294 uint32_t memory_used;
295 uint32_t __last_counter; /* hack for control_statistics_all */
296 uint32_t max_hop_count;
297 double max_call_latency;
298 double max_lockwait_latency;
302 #define INVALID_GENERATION 1
303 /* table that contains the mapping between a hash value and lmaster
305 struct ctdb_vnn_map {
312 a wire representation of the vnn map
314 struct ctdb_vnn_map_wire {
320 /* a structure that contains the elements required for the write record
323 struct ctdb_write_record {
327 unsigned char blob[1];
330 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
332 #define CTDB_MONITORING_ACTIVE 0
333 #define CTDB_MONITORING_DISABLED 1
335 /* main state of the ctdb daemon */
336 struct ctdb_context {
337 struct event_context *ev;
338 struct timeval ctdbd_start_time;
339 struct timeval last_recovery_time;
340 uint32_t recovery_mode;
341 TALLOC_CTX *tickle_update_context;
342 TALLOC_CTX *keepalive_ctx;
343 struct ctdb_tunable tunable;
344 enum ctdb_freeze_mode freeze_mode;
345 struct ctdb_freeze_handle *freeze_handle;
346 struct ctdb_address address;
348 const char *db_directory;
349 const char *db_directory_persistent;
350 const char *transport;
352 char *node_list_file;
353 char *recovery_lock_file;
354 int recovery_lock_fd;
355 uint32_t pnn; /* our own pnn */
357 uint32_t num_connected;
359 struct idr_context *idr;
361 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
362 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
363 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
365 const struct ctdb_methods *methods; /* transport methods */
366 const struct ctdb_upcalls *upcalls; /* transport upcalls */
367 void *private_data; /* private to transport */
368 struct ctdb_db_context *db_list;
369 struct ctdb_message_list *message_list;
370 struct ctdb_daemon_data daemon;
371 struct ctdb_statistics statistics;
372 struct ctdb_vnn_map *vnn_map;
373 uint32_t num_clients;
374 uint32_t recovery_master;
375 struct ctdb_call_state *pending_calls;
376 struct ctdb_client_ip *client_ip_list;
378 void *saved_scheduler_param;
379 struct _trbt_tree_t *server_ids;
380 const char *event_script_dir;
381 const char *default_public_interface;
386 struct ctdb_monitor_state *monitor;
387 struct ctdb_log_state *log;
388 int start_as_disabled;
389 TALLOC_CTX *eventscripts_ctx; /* a context to hold data for the RUN_EVENTSCRIPTS control */
392 struct ctdb_db_context {
393 struct ctdb_db_context *next, *prev;
394 struct ctdb_context *ctdb;
399 struct tdb_wrap *ltdb;
400 struct ctdb_registered_call *calls; /* list of registered calls */
402 struct timed_event *te;
403 uint32_t client_tdb_flags;
407 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
408 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
409 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
410 return -1; }} while (0)
412 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
413 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
414 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
417 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
418 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
419 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
420 return NULL; }} while (0)
422 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
423 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
424 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
428 the extended header for records in the ltdb
430 struct ctdb_ltdb_header {
437 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
438 CTDB_CONTROL_STATISTICS = 1,
440 CTDB_CONTROL_PING = 3,
441 CTDB_CONTROL_GETDBPATH = 4,
442 CTDB_CONTROL_GETVNNMAP = 5,
443 CTDB_CONTROL_SETVNNMAP = 6,
444 CTDB_CONTROL_GET_DEBUG = 7,
445 CTDB_CONTROL_SET_DEBUG = 8,
446 CTDB_CONTROL_GET_DBMAP = 9,
447 CTDB_CONTROL_GET_NODEMAP = 10,
448 CTDB_CONTROL_SET_DMASTER = 11,
450 CTDB_CONTROL_PULL_DB = 13,
451 CTDB_CONTROL_PUSH_DB = 14,
452 CTDB_CONTROL_GET_RECMODE = 15,
453 CTDB_CONTROL_SET_RECMODE = 16,
454 CTDB_CONTROL_STATISTICS_RESET = 17,
455 CTDB_CONTROL_DB_ATTACH = 18,
456 CTDB_CONTROL_SET_CALL = 19,
457 CTDB_CONTROL_TRAVERSE_START = 20,
458 CTDB_CONTROL_TRAVERSE_ALL = 21,
459 CTDB_CONTROL_TRAVERSE_DATA = 22,
460 CTDB_CONTROL_REGISTER_SRVID = 23,
461 CTDB_CONTROL_DEREGISTER_SRVID = 24,
462 CTDB_CONTROL_GET_DBNAME = 25,
463 CTDB_CONTROL_ENABLE_SEQNUM = 26,
464 CTDB_CONTROL_UPDATE_SEQNUM = 27,
466 CTDB_CONTROL_DUMP_MEMORY = 29,
467 CTDB_CONTROL_GET_PID = 30,
468 CTDB_CONTROL_GET_RECMASTER = 31,
469 CTDB_CONTROL_SET_RECMASTER = 32,
470 CTDB_CONTROL_FREEZE = 33,
471 CTDB_CONTROL_THAW = 34,
472 CTDB_CONTROL_GET_PNN = 35,
473 CTDB_CONTROL_SHUTDOWN = 36,
474 CTDB_CONTROL_GET_MONMODE = 37,
479 CTDB_CONTROL_TAKEOVER_IP = 42,
480 CTDB_CONTROL_RELEASE_IP = 43,
481 CTDB_CONTROL_TCP_CLIENT = 44,
482 CTDB_CONTROL_TCP_ADD = 45,
483 CTDB_CONTROL_TCP_REMOVE = 46,
484 CTDB_CONTROL_STARTUP = 47,
485 CTDB_CONTROL_SET_TUNABLE = 48,
486 CTDB_CONTROL_GET_TUNABLE = 49,
487 CTDB_CONTROL_LIST_TUNABLES = 50,
488 CTDB_CONTROL_GET_PUBLIC_IPS = 51,
489 CTDB_CONTROL_MODIFY_FLAGS = 52,
490 CTDB_CONTROL_GET_ALL_TUNABLES = 53,
491 CTDB_CONTROL_KILL_TCP = 54,
492 CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55,
493 CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56,
494 CTDB_CONTROL_REGISTER_SERVER_ID = 57,
495 CTDB_CONTROL_UNREGISTER_SERVER_ID = 58,
496 CTDB_CONTROL_CHECK_SERVER_ID = 59,
497 CTDB_CONTROL_GET_SERVER_ID_LIST = 60,
498 CTDB_CONTROL_DB_ATTACH_PERSISTENT = 61,
499 CTDB_CONTROL_PERSISTENT_STORE = 62,
500 CTDB_CONTROL_UPDATE_RECORD = 63,
501 CTDB_CONTROL_SEND_GRATIOUS_ARP = 64,
502 CTDB_CONTROL_TRANSACTION_START = 65,
503 CTDB_CONTROL_TRANSACTION_COMMIT = 66,
504 CTDB_CONTROL_WIPE_DATABASE = 67,
506 CTDB_CONTROL_UPTIME = 69,
507 CTDB_CONTROL_START_RECOVERY = 70,
508 CTDB_CONTROL_END_RECOVERY = 71,
509 CTDB_CONTROL_RELOAD_NODES_FILE = 72,
510 CTDB_CONTROL_GET_RECLOCK_FILE = 73,
511 CTDB_CONTROL_TRY_DELETE_RECORDS = 74,
512 CTDB_CONTROL_ENABLE_MONITOR = 75,
513 CTDB_CONTROL_DISABLE_MONITOR = 76,
514 CTDB_CONTROL_ADD_PUBLIC_IP = 77,
515 CTDB_CONTROL_DEL_PUBLIC_IP = 78,
516 CTDB_CONTROL_RUN_EVENTSCRIPTS = 79,
520 structure passed in set_call control
522 struct ctdb_control_set_call {
529 struct for tcp_client control
531 struct ctdb_control_tcp {
532 struct sockaddr_in src;
533 struct sockaddr_in dest;
537 struct for kill_tcp control
539 struct ctdb_control_killtcp {
540 struct sockaddr_in src;
541 struct sockaddr_in dst;
545 struct holding a sockaddr_in and an interface name,
546 used for send_gratious_arp and also add/remove public addresses
548 //struct ctdb_control_gratious_arp {
549 struct ctdb_control_ip_iface {
550 struct sockaddr_in sin;
557 struct for tcp_add and tcp_remove controls
559 struct ctdb_control_tcp_vnn {
560 struct sockaddr_in src;
561 struct sockaddr_in dest;
565 persistent store control - update this record on all other nodes
567 struct ctdb_control_persistent_store {
574 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
576 struct ctdb_node_flag_change {
583 structure to change flags on a node
585 struct ctdb_node_modflags {
591 struct for admin setting a ban
593 struct ctdb_ban_info {
598 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
600 #define CTDB_LMASTER_ANY 0xffffffff
603 state of a in-progress ctdb call
605 struct ctdb_call_state {
606 struct ctdb_call_state *next, *prev;
607 enum call_state state;
609 struct ctdb_req_call *c;
610 struct ctdb_db_context *ctdb_db;
612 struct ctdb_call *call;
615 void (*fn)(struct ctdb_call_state *);
621 /* used for fetch_lock */
622 struct ctdb_fetch_handle {
623 struct ctdb_db_context *ctdb_db;
626 struct ctdb_ltdb_header header;
632 enum ctdb_operation {
635 CTDB_REQ_DMASTER = 2,
636 CTDB_REPLY_DMASTER = 3,
637 CTDB_REPLY_ERROR = 4,
638 CTDB_REQ_MESSAGE = 5,
640 CTDB_REQ_CONTROL = 7,
641 CTDB_REPLY_CONTROL = 8,
642 CTDB_REQ_KEEPALIVE = 9,
645 #define CTDB_MAGIC 0x43544442 /* CTDB */
646 #define CTDB_VERSION 1
651 struct ctdb_req_header {
654 uint32_t ctdb_version;
662 struct ctdb_req_call {
663 struct ctdb_req_header hdr;
669 uint32_t calldatalen;
670 uint8_t data[1]; /* key[] followed by calldata[] */
673 struct ctdb_reply_call {
674 struct ctdb_req_header hdr;
680 struct ctdb_reply_error {
681 struct ctdb_req_header hdr;
687 struct ctdb_req_dmaster {
688 struct ctdb_req_header hdr;
697 struct ctdb_reply_dmaster {
698 struct ctdb_req_header hdr;
706 struct ctdb_req_message {
707 struct ctdb_req_header hdr;
713 struct ctdb_req_getdbpath {
714 struct ctdb_req_header hdr;
718 struct ctdb_reply_getdbpath {
719 struct ctdb_req_header hdr;
724 struct ctdb_req_control {
725 struct ctdb_req_header hdr;
729 #define CTDB_CTRL_FLAG_NOREPLY 1
735 struct ctdb_reply_control {
736 struct ctdb_req_header hdr;
743 struct ctdb_req_keepalive {
744 struct ctdb_req_header hdr;
747 /* internal prototypes */
748 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
749 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
750 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
751 bool parse_ip_mask(const char *s, struct sockaddr_in *ip, unsigned *mask);
752 int ctdb_parse_address(struct ctdb_context *ctdb,
753 TALLOC_CTX *mem_ctx, const char *str,
754 struct ctdb_address *address);
755 bool ctdb_same_ip(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
756 bool ctdb_same_sockaddr(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
757 uint32_t ctdb_hash(const TDB_DATA *key);
758 uint32_t ctdb_hash_string(const char *str);
759 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
760 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
761 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
762 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
763 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
764 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
766 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
767 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
768 TDB_DATA key, struct ctdb_ltdb_header *header,
769 TALLOC_CTX *mem_ctx, TDB_DATA *data);
770 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
771 struct ctdb_ltdb_header *header, TDB_DATA data);
772 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
773 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
774 TDB_DATA key, struct ctdb_req_header *hdr,
775 void (*recv_pkt)(void *, struct ctdb_req_header *),
776 void *recv_context, bool ignore_generation);
777 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
778 TDB_DATA key, struct ctdb_ltdb_header *header,
779 struct ctdb_req_header *hdr, TDB_DATA *data,
780 void (*recv_pkt)(void *, struct ctdb_req_header *),
781 void *recv_context, bool ignore_generation);
782 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
784 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
785 struct ctdb_call *call,
786 struct ctdb_ltdb_header *header,
790 int ctdbd_start(struct ctdb_context *ctdb);
791 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
792 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
795 queue a packet for sending
797 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
800 setup the fd used by the queue
802 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
805 setup a packet queue on a socket
807 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
808 TALLOC_CTX *mem_ctx, int fd, int alignment,
810 ctdb_queue_cb_fn_t callback,
814 allocate a packet for use in client<->daemon communication
816 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
818 enum ctdb_operation operation,
819 size_t length, size_t slength,
821 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
822 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
824 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
826 enum ctdb_operation operation,
827 size_t length, size_t slength,
829 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
830 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
834 lock a record in the ltdb, given a key
836 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
839 unlock a record in the ltdb, given a key
841 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
845 make a ctdb call to the local daemon - async send. Called from client context.
847 This constructs a ctdb_call request and queues it for processing.
848 This call never blocks.
850 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
851 struct ctdb_call *call);
854 make a recv call to the local ctdb daemon - called from client context
856 This is called when the program wants to wait for a ctdb_call to complete and get the
857 results. This call will block unless the call has already completed.
859 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
861 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
862 ctdb_message_fn_t handler,
865 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
866 uint64_t srvid, TDB_DATA data);
871 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
872 uint64_t srvid, TDB_DATA data);
875 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
877 void (*callback)(void *), void *private_data);
879 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
880 struct ctdb_call *call);
882 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
884 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
885 struct ctdb_call *call,
886 struct ctdb_ltdb_header *header);
888 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
889 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
892 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
894 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
896 int ctdb_socket_connect(struct ctdb_context *ctdb);
898 void ctdb_latency(double *latency, struct timeval t);
900 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
901 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
902 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
904 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
905 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
907 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
908 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
910 ctdb_control_callback_fn_t callback,
913 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
914 TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
916 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
917 ctdb_fn_t fn, int id);
919 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
920 uint32_t opcode, uint32_t flags, TDB_DATA data,
921 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
922 struct timeval *timeout, char **errormsg);
923 int ctdb_control_recv(struct ctdb_context *ctdb,
924 struct ctdb_client_control_state *state,
926 TDB_DATA *outdata, int32_t *status, char **errormsg);
928 struct ctdb_client_control_state *
929 ctdb_control_send(struct ctdb_context *ctdb,
930 uint32_t destnode, uint64_t srvid,
931 uint32_t opcode, uint32_t flags, TDB_DATA data,
933 struct timeval *timeout,
939 #define CHECK_CONTROL_DATA_SIZE(size) do { \
940 if (indata.dsize != size) { \
941 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
942 opcode, (unsigned)indata.dsize, (unsigned)size)); \
947 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
948 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
949 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
950 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
951 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
954 struct ctdb_traverse_start {
961 structure used to pass record data between the child and parent
963 struct ctdb_rec_data {
972 /* structure used for pulldb control */
973 struct ctdb_control_pulldb {
978 /* structure used for pulldb control */
979 struct ctdb_control_pulldb_reply {
985 /* set dmaster control structure */
986 struct ctdb_control_set_dmaster {
992 structure for setting a tunable
994 struct ctdb_control_set_tunable {
1001 structure for getting a tunable
1003 struct ctdb_control_get_tunable {
1009 structure for listing tunables
1011 struct ctdb_control_list_tunable {
1013 /* returns a : separated list of tunable names */
1018 /* table that contains a list of all nodes a ctdb knows about and their
1021 struct ctdb_node_and_flags {
1024 struct sockaddr_in sin;
1028 struct ctdb_node_map {
1030 struct ctdb_node_and_flags nodes[1];
1033 struct ctdb_control_wipe_database {
1035 uint32_t transaction_id;
1039 state of a in-progress ctdb call in client
1041 struct ctdb_client_call_state {
1042 enum call_state state;
1044 struct ctdb_db_context *ctdb_db;
1045 struct ctdb_call *call;
1047 void (*fn)(struct ctdb_client_call_state *);
1053 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
1054 TDB_DATA *outdata, uint32_t srcnode);
1055 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1056 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1058 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1060 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1061 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1062 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1064 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1065 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1066 int32_t ctdb_ltdb_set_seqnum_frequency(struct ctdb_context *ctdb, uint32_t frequency);
1068 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
1069 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1071 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1072 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1073 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1075 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1076 struct ctdb_req_control *c,
1077 TDB_DATA indata, bool *async_reply,
1078 const char **errormsg);
1079 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1080 TDB_DATA *outdata, int32_t status, const char *errormsg);
1082 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1083 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1085 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1086 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1088 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1090 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1091 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1092 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1093 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1094 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1095 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1096 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1097 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1098 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1101 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1102 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1103 void ctdb_node_dead(struct ctdb_node *node);
1104 void ctdb_node_connected(struct ctdb_node *node);
1105 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1106 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1107 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1108 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1109 struct ctdb_req_control *c,
1112 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1113 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_ip {
1125 struct sockaddr_in sin;
1127 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1128 uint32_t destnode, struct ctdb_public_ip *ip);
1129 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1130 uint32_t destnode, struct ctdb_public_ip *ip);
1132 struct ctdb_all_public_ips {
1134 struct ctdb_public_ip ips[1];
1136 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1137 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1138 struct timeval timeout, uint32_t destnode,
1139 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1142 /* from takeover/system.c */
1143 int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface);
1144 bool ctdb_sys_have_ip(struct sockaddr_in ip);
1145 int ctdb_sys_send_tcp(int fd,
1146 const struct sockaddr_in *dest,
1147 const struct sockaddr_in *src,
1148 uint32_t seq, uint32_t ack, int rst);
1150 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1151 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1152 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1153 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1155 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1157 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1158 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1159 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1160 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1161 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1162 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1163 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1165 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1166 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1167 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1168 struct timeval timeout,
1169 TALLOC_CTX *mem_ctx,
1170 void (*callback)(struct ctdb_context *, int, void *),
1172 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1173 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1175 void set_nonblocking(int fd);
1176 void set_close_on_exec(int fd);
1178 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1180 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1182 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1184 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1185 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1186 int32_t ctdb_control_get_reclock_file(struct ctdb_context *ctdb, TDB_DATA *outdata);
1187 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1188 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1189 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1191 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1193 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1195 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1196 struct timeval timeout,
1198 struct ctdb_tunable *tunables);
1200 void ctdb_start_freeze(struct ctdb_context *ctdb);
1202 bool parse_ip_port(const char *s, struct sockaddr_in *ip);
1204 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1205 int ctdb_sys_close_capture_socket(void *private_data);
1206 int ctdb_sys_open_sending_socket(void);
1207 int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst,
1208 uint32_t *ack_seq, uint32_t *seq);
1210 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1211 struct timeval timeout,
1213 struct ctdb_control_killtcp *killtcp);
1215 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1216 struct timeval timeout,
1218 struct ctdb_control_ip_iface *pub);
1220 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1221 struct timeval timeout,
1223 struct ctdb_control_ip_iface *pub);
1225 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1226 struct timeval timeout,
1228 struct sockaddr_in *sin,
1229 const char *ifname);
1231 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1232 struct timeval timeout,
1234 TALLOC_CTX *mem_ctx,
1235 struct sockaddr_in *ip,
1236 struct ctdb_control_tcp_tickle_list **list);
1239 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1242 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1244 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1246 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1248 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1251 int ctdb_attach_persistent(struct ctdb_context *ctdb);
1253 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1254 struct ctdb_req_control *c,
1255 TDB_DATA recdata, bool *async_reply);
1256 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1257 struct ctdb_req_control *c, TDB_DATA recdata,
1260 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1261 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1262 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1265 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1266 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1268 void ctdb_block_signal(int signum);
1269 void ctdb_unblock_signal(int signum);
1270 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1271 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1274 struct client_async_data {
1275 bool dont_log_errors;
1277 uint32_t fail_count;
1279 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1280 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1281 int ctdb_client_async_control(struct ctdb_context *ctdb,
1282 enum ctdb_controls opcode,
1284 struct timeval timeout,
1285 bool dont_log_errors,
1288 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1290 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1292 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);