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;
164 uint32_t num_persistent_updates;
168 /* state associated with a public ip address */
170 struct ctdb_vnn *prev, *next;
173 struct sockaddr_in public_address;
174 uint8_t public_netmask_bits;
176 /* the node number that is serving this public address, if any.
177 If no node serves this ip it is set to -1 */
180 /* List of clients to tickle for this public address */
181 struct ctdb_tcp_array *tcp_array;
183 /* whether we need to update the other nodes with changes to our list
184 of connected clients */
185 bool tcp_update_needed;
187 /* a context to hang sending gratious arp events off */
188 TALLOC_CTX *takeover_ctx;
190 struct ctdb_kill_tcp *killtcp;
194 state associated with one node
197 struct ctdb_context *ctdb;
198 struct ctdb_address address;
199 const char *name; /* for debug messages */
200 void *private_data; /* private to transport */
202 #define NODE_FLAGS_DISCONNECTED 0x00000001 /* node isn't connected */
203 #define NODE_FLAGS_UNHEALTHY 0x00000002 /* monitoring says node is unhealthy */
204 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
205 #define NODE_FLAGS_BANNED 0x00000008 /* recovery daemon has banned the node */
206 #define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
207 #define NODE_FLAGS_INACTIVE (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
210 /* used by the dead node monitoring */
215 /* used to track node capabilities, is only valid/tracked inside the
218 uint32_t capabilities;
220 /* a list of controls pending to this node, so we can time them out quickly
221 if the node becomes disconnected */
222 struct daemon_control_state *pending_controls;
224 /* used by the recovery daemon when distributing ip addresses
225 across the nodes. it needs to know which public ip's can be handled
228 struct ctdb_all_public_ips *public_ips;
232 transport specific methods
234 struct ctdb_methods {
235 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
236 int (*start)(struct ctdb_context *); /* start protocol processing */
237 int (*add_node)(struct ctdb_node *); /* setup a new node */
238 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
239 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
240 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
241 void (*restart)(struct ctdb_node *); /* stop and restart the connection */
245 transport calls up to the ctdb layer
247 struct ctdb_upcalls {
248 /* recv_pkt is called when a packet comes in */
249 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
251 /* node_dead is called when an attempt to send to a node fails */
252 void (*node_dead)(struct ctdb_node *);
254 /* node_connected is called when a connection to a node is established */
255 void (*node_connected)(struct ctdb_node *);
258 /* list of message handlers - needs to be changed to a more efficient data
259 structure so we can find a message handler given a srvid quickly */
260 struct ctdb_message_list {
261 struct ctdb_context *ctdb;
262 struct ctdb_message_list *next, *prev;
264 ctdb_message_fn_t message_handler;
265 void *message_private;
268 /* additional data required for the daemon mode */
269 struct ctdb_daemon_data {
272 struct ctdb_queue *queue;
276 ctdb status information
278 struct ctdb_statistics {
279 uint32_t num_clients;
282 uint32_t client_packets_sent;
283 uint32_t client_packets_recv;
284 uint32_t node_packets_sent;
285 uint32_t node_packets_recv;
286 uint32_t keepalive_packets_sent;
287 uint32_t keepalive_packets_recv;
291 uint32_t req_dmaster;
292 uint32_t reply_dmaster;
293 uint32_t reply_error;
294 uint32_t req_message;
295 uint32_t req_control;
296 uint32_t reply_control;
300 uint32_t req_message;
301 uint32_t req_control;
308 uint32_t total_calls;
309 uint32_t pending_calls;
310 uint32_t lockwait_calls;
311 uint32_t pending_lockwait_calls;
312 uint32_t childwrite_calls;
313 uint32_t pending_childwrite_calls;
314 uint32_t memory_used;
315 uint32_t __last_counter; /* hack for control_statistics_all */
316 uint32_t max_hop_count;
317 double max_call_latency;
318 double max_lockwait_latency;
319 double max_childwrite_latency;
323 #define INVALID_GENERATION 1
324 /* table that contains the mapping between a hash value and lmaster
326 struct ctdb_vnn_map {
333 a wire representation of the vnn map
335 struct ctdb_vnn_map_wire {
341 /* a structure that contains the elements required for the write record
344 struct ctdb_write_record {
348 unsigned char blob[1];
351 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
353 #define CTDB_MONITORING_ACTIVE 0
354 #define CTDB_MONITORING_DISABLED 1
356 /* The different capabilities of the ctdb daemon. */
357 #define CTDB_CAP_RECMASTER 0x00000001
358 #define CTDB_CAP_LMASTER 0x00000002
359 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
360 #define CTDB_CAP_LVS 0x00000004
362 /* main state of the ctdb daemon */
363 struct ctdb_context {
364 struct event_context *ev;
365 struct timeval ctdbd_start_time;
366 struct timeval last_recovery_started;
367 struct timeval last_recovery_finished;
368 uint32_t recovery_mode;
369 TALLOC_CTX *tickle_update_context;
370 TALLOC_CTX *keepalive_ctx;
371 struct ctdb_tunable tunable;
372 enum ctdb_freeze_mode freeze_mode;
373 struct ctdb_freeze_handle *freeze_handle;
374 struct ctdb_address address;
376 const char *db_directory;
377 const char *db_directory_persistent;
378 const char *transport;
380 char *node_list_file;
381 char *recovery_lock_file;
382 int recovery_lock_fd;
383 uint32_t pnn; /* our own pnn */
385 uint32_t num_connected;
387 uint32_t capabilities;
388 struct idr_context *idr;
390 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
391 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
392 struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
394 const struct ctdb_methods *methods; /* transport methods */
395 const struct ctdb_upcalls *upcalls; /* transport upcalls */
396 void *private_data; /* private to transport */
397 struct ctdb_db_context *db_list;
398 struct ctdb_message_list *message_list;
399 struct ctdb_daemon_data daemon;
400 struct ctdb_statistics statistics;
401 struct ctdb_vnn_map *vnn_map;
402 uint32_t num_clients;
403 uint32_t recovery_master;
404 struct ctdb_call_state *pending_calls;
405 struct ctdb_client_ip *client_ip_list;
407 void *saved_scheduler_param;
408 struct _trbt_tree_t *server_ids;
409 const char *event_script_dir;
410 const char *default_public_interface;
415 struct ctdb_monitor_state *monitor;
416 struct ctdb_log_state *log;
417 int start_as_disabled;
418 uint32_t event_script_timeouts; /* counting how many consecutive times an eventscript has timedout */
419 TALLOC_CTX *eventscripts_ctx; /* a context to hold data for the RUN_EVENTSCRIPTS control */
422 struct ctdb_db_context {
423 struct ctdb_db_context *next, *prev;
424 struct ctdb_context *ctdb;
429 struct tdb_wrap *ltdb;
430 struct ctdb_registered_call *calls; /* list of registered calls */
432 struct timed_event *te;
433 uint32_t client_tdb_flags;
437 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
438 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
439 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
440 return -1; }} while (0)
442 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
443 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
444 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
447 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
448 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
449 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
450 return NULL; }} while (0)
452 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
453 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
454 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
458 the extended header for records in the ltdb
460 struct ctdb_ltdb_header {
467 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
468 CTDB_CONTROL_STATISTICS = 1,
470 CTDB_CONTROL_PING = 3,
471 CTDB_CONTROL_GETDBPATH = 4,
472 CTDB_CONTROL_GETVNNMAP = 5,
473 CTDB_CONTROL_SETVNNMAP = 6,
474 CTDB_CONTROL_GET_DEBUG = 7,
475 CTDB_CONTROL_SET_DEBUG = 8,
476 CTDB_CONTROL_GET_DBMAP = 9,
477 CTDB_CONTROL_GET_NODEMAP = 10,
478 CTDB_CONTROL_SET_DMASTER = 11,
480 CTDB_CONTROL_PULL_DB = 13,
481 CTDB_CONTROL_PUSH_DB = 14,
482 CTDB_CONTROL_GET_RECMODE = 15,
483 CTDB_CONTROL_SET_RECMODE = 16,
484 CTDB_CONTROL_STATISTICS_RESET = 17,
485 CTDB_CONTROL_DB_ATTACH = 18,
486 CTDB_CONTROL_SET_CALL = 19,
487 CTDB_CONTROL_TRAVERSE_START = 20,
488 CTDB_CONTROL_TRAVERSE_ALL = 21,
489 CTDB_CONTROL_TRAVERSE_DATA = 22,
490 CTDB_CONTROL_REGISTER_SRVID = 23,
491 CTDB_CONTROL_DEREGISTER_SRVID = 24,
492 CTDB_CONTROL_GET_DBNAME = 25,
493 CTDB_CONTROL_ENABLE_SEQNUM = 26,
494 CTDB_CONTROL_UPDATE_SEQNUM = 27,
496 CTDB_CONTROL_DUMP_MEMORY = 29,
497 CTDB_CONTROL_GET_PID = 30,
498 CTDB_CONTROL_GET_RECMASTER = 31,
499 CTDB_CONTROL_SET_RECMASTER = 32,
500 CTDB_CONTROL_FREEZE = 33,
501 CTDB_CONTROL_THAW = 34,
502 CTDB_CONTROL_GET_PNN = 35,
503 CTDB_CONTROL_SHUTDOWN = 36,
504 CTDB_CONTROL_GET_MONMODE = 37,
509 CTDB_CONTROL_TAKEOVER_IP = 42,
510 CTDB_CONTROL_RELEASE_IP = 43,
511 CTDB_CONTROL_TCP_CLIENT = 44,
512 CTDB_CONTROL_TCP_ADD = 45,
513 CTDB_CONTROL_TCP_REMOVE = 46,
514 CTDB_CONTROL_STARTUP = 47,
515 CTDB_CONTROL_SET_TUNABLE = 48,
516 CTDB_CONTROL_GET_TUNABLE = 49,
517 CTDB_CONTROL_LIST_TUNABLES = 50,
518 CTDB_CONTROL_GET_PUBLIC_IPS = 51,
519 CTDB_CONTROL_MODIFY_FLAGS = 52,
520 CTDB_CONTROL_GET_ALL_TUNABLES = 53,
521 CTDB_CONTROL_KILL_TCP = 54,
522 CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55,
523 CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56,
524 CTDB_CONTROL_REGISTER_SERVER_ID = 57,
525 CTDB_CONTROL_UNREGISTER_SERVER_ID = 58,
526 CTDB_CONTROL_CHECK_SERVER_ID = 59,
527 CTDB_CONTROL_GET_SERVER_ID_LIST = 60,
528 CTDB_CONTROL_DB_ATTACH_PERSISTENT = 61,
529 CTDB_CONTROL_PERSISTENT_STORE = 62,
530 CTDB_CONTROL_UPDATE_RECORD = 63,
531 CTDB_CONTROL_SEND_GRATIOUS_ARP = 64,
532 CTDB_CONTROL_TRANSACTION_START = 65,
533 CTDB_CONTROL_TRANSACTION_COMMIT = 66,
534 CTDB_CONTROL_WIPE_DATABASE = 67,
536 CTDB_CONTROL_UPTIME = 69,
537 CTDB_CONTROL_START_RECOVERY = 70,
538 CTDB_CONTROL_END_RECOVERY = 71,
539 CTDB_CONTROL_RELOAD_NODES_FILE = 72,
540 CTDB_CONTROL_GET_RECLOCK_FILE = 73,
541 CTDB_CONTROL_TRY_DELETE_RECORDS = 74,
542 CTDB_CONTROL_ENABLE_MONITOR = 75,
543 CTDB_CONTROL_DISABLE_MONITOR = 76,
544 CTDB_CONTROL_ADD_PUBLIC_IP = 77,
545 CTDB_CONTROL_DEL_PUBLIC_IP = 78,
546 CTDB_CONTROL_RUN_EVENTSCRIPTS = 79,
547 CTDB_CONTROL_GET_CAPABILITIES = 80,
548 CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
549 CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
553 structure passed in set_call control
555 struct ctdb_control_set_call {
562 struct for tcp_client control
564 struct ctdb_control_tcp {
565 struct sockaddr_in src;
566 struct sockaddr_in dest;
570 struct for kill_tcp control
572 struct ctdb_control_killtcp {
573 struct sockaddr_in src;
574 struct sockaddr_in dst;
578 struct holding a sockaddr_in and an interface name,
579 used to add/remove public addresses
581 struct ctdb_control_ip_iface {
582 struct sockaddr_in sin;
589 struct holding a ctdb_sock_addr and an interface name,
590 used for send_gratious_arp
592 struct ctdb_control_gratious_arp {
600 struct for tcp_add and tcp_remove controls
602 struct ctdb_control_tcp_vnn {
603 struct sockaddr_in src;
604 struct sockaddr_in dest;
608 persistent store control - update this record on all other nodes
610 struct ctdb_control_persistent_store {
617 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
619 struct ctdb_node_flag_change {
626 structure to change flags on a node
628 struct ctdb_node_modflags {
634 struct for admin setting a ban
636 struct ctdb_ban_info {
641 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
643 #define CTDB_LMASTER_ANY 0xffffffff
646 state of a in-progress ctdb call
648 struct ctdb_call_state {
649 struct ctdb_call_state *next, *prev;
650 enum call_state state;
652 struct ctdb_req_call *c;
653 struct ctdb_db_context *ctdb_db;
655 struct ctdb_call *call;
658 void (*fn)(struct ctdb_call_state *);
664 /* used for fetch_lock */
665 struct ctdb_fetch_handle {
666 struct ctdb_db_context *ctdb_db;
669 struct ctdb_ltdb_header header;
675 enum ctdb_operation {
678 CTDB_REQ_DMASTER = 2,
679 CTDB_REPLY_DMASTER = 3,
680 CTDB_REPLY_ERROR = 4,
681 CTDB_REQ_MESSAGE = 5,
683 CTDB_REQ_CONTROL = 7,
684 CTDB_REPLY_CONTROL = 8,
685 CTDB_REQ_KEEPALIVE = 9,
688 #define CTDB_MAGIC 0x43544442 /* CTDB */
689 #define CTDB_VERSION 1
694 struct ctdb_req_header {
697 uint32_t ctdb_version;
705 struct ctdb_req_call {
706 struct ctdb_req_header hdr;
712 uint32_t calldatalen;
713 uint8_t data[1]; /* key[] followed by calldata[] */
716 struct ctdb_reply_call {
717 struct ctdb_req_header hdr;
723 struct ctdb_reply_error {
724 struct ctdb_req_header hdr;
730 struct ctdb_req_dmaster {
731 struct ctdb_req_header hdr;
740 struct ctdb_reply_dmaster {
741 struct ctdb_req_header hdr;
749 struct ctdb_req_message {
750 struct ctdb_req_header hdr;
756 struct ctdb_req_getdbpath {
757 struct ctdb_req_header hdr;
761 struct ctdb_reply_getdbpath {
762 struct ctdb_req_header hdr;
767 struct ctdb_req_control {
768 struct ctdb_req_header hdr;
772 #define CTDB_CTRL_FLAG_NOREPLY 1
778 struct ctdb_reply_control {
779 struct ctdb_req_header hdr;
786 struct ctdb_req_keepalive {
787 struct ctdb_req_header hdr;
790 /* internal prototypes */
791 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
792 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
793 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
794 bool parse_ip_mask(const char *s, struct sockaddr_in *ip, unsigned *mask);
795 int ctdb_parse_address(struct ctdb_context *ctdb,
796 TALLOC_CTX *mem_ctx, const char *str,
797 struct ctdb_address *address);
798 bool ctdb_same_ipv4(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
799 bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2);
800 bool ctdb_same_sockaddr(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2);
801 uint32_t ctdb_hash(const TDB_DATA *key);
802 uint32_t ctdb_hash_string(const char *str);
803 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
804 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
805 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
806 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
807 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
808 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
810 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
811 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
812 TDB_DATA key, struct ctdb_ltdb_header *header,
813 TALLOC_CTX *mem_ctx, TDB_DATA *data);
814 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
815 struct ctdb_ltdb_header *header, TDB_DATA data);
816 int ctdb_ltdb_persistent_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
817 struct ctdb_ltdb_header *header, TDB_DATA data);
818 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
819 struct ctdb_req_control *c,
821 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
822 struct ctdb_req_control *c,
824 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
825 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb, struct ctdb_req_header *hdr, unsigned opcode);
826 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
827 TDB_DATA key, struct ctdb_req_header *hdr,
828 void (*recv_pkt)(void *, struct ctdb_req_header *),
829 void *recv_context, bool ignore_generation);
830 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
831 TDB_DATA key, struct ctdb_ltdb_header *header,
832 struct ctdb_req_header *hdr, TDB_DATA *data,
833 void (*recv_pkt)(void *, struct ctdb_req_header *),
834 void *recv_context, bool ignore_generation);
835 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
837 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
838 struct ctdb_call *call,
839 struct ctdb_ltdb_header *header,
843 int ctdbd_start(struct ctdb_context *ctdb);
844 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
845 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
848 queue a packet for sending
850 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
853 setup the fd used by the queue
855 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
858 setup a packet queue on a socket
860 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
861 TALLOC_CTX *mem_ctx, int fd, int alignment,
863 ctdb_queue_cb_fn_t callback,
867 allocate a packet for use in client<->daemon communication
869 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
871 enum ctdb_operation operation,
872 size_t length, size_t slength,
874 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
875 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
877 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
879 enum ctdb_operation operation,
880 size_t length, size_t slength,
882 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
883 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
887 lock a record in the ltdb, given a key
889 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
892 unlock a record in the ltdb, given a key
894 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
898 make a ctdb call to the local daemon - async send. Called from client context.
900 This constructs a ctdb_call request and queues it for processing.
901 This call never blocks.
903 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
904 struct ctdb_call *call);
907 make a recv call to the local ctdb daemon - called from client context
909 This is called when the program wants to wait for a ctdb_call to complete and get the
910 results. This call will block unless the call has already completed.
912 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
914 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
915 ctdb_message_fn_t handler,
918 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
919 uint64_t srvid, TDB_DATA data);
924 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
925 uint64_t srvid, TDB_DATA data);
928 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
930 void (*callback)(void *), void *private_data);
932 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
933 struct ctdb_call *call);
935 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
937 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
938 struct ctdb_call *call,
939 struct ctdb_ltdb_header *header);
941 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
942 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
945 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
947 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
949 int ctdb_socket_connect(struct ctdb_context *ctdb);
951 void ctdb_latency(double *latency, struct timeval t);
953 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
954 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
955 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
957 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
958 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
960 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
961 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
963 ctdb_control_callback_fn_t callback,
966 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
967 TDB_DATA *outdata, uint64_t tdb_flags, bool persistent);
969 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
970 ctdb_fn_t fn, int id);
972 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
973 uint32_t opcode, uint32_t flags, TDB_DATA data,
974 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
975 struct timeval *timeout, char **errormsg);
976 int ctdb_control_recv(struct ctdb_context *ctdb,
977 struct ctdb_client_control_state *state,
979 TDB_DATA *outdata, int32_t *status, char **errormsg);
981 struct ctdb_client_control_state *
982 ctdb_control_send(struct ctdb_context *ctdb,
983 uint32_t destnode, uint64_t srvid,
984 uint32_t opcode, uint32_t flags, TDB_DATA data,
986 struct timeval *timeout,
992 #define CHECK_CONTROL_DATA_SIZE(size) do { \
993 if (indata.dsize != size) { \
994 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
995 opcode, (unsigned)indata.dsize, (unsigned)size)); \
1000 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1001 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1002 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1003 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1004 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
1007 struct ctdb_traverse_start {
1014 structure used to pass record data between the child and parent
1016 struct ctdb_rec_data {
1025 /* structure used for pulldb control */
1026 struct ctdb_control_pulldb {
1031 /* structure used for pulldb control */
1032 struct ctdb_control_pulldb_reply {
1038 /* set dmaster control structure */
1039 struct ctdb_control_set_dmaster {
1045 structure for setting a tunable
1047 struct ctdb_control_set_tunable {
1054 structure for getting a tunable
1056 struct ctdb_control_get_tunable {
1062 structure for listing tunables
1064 struct ctdb_control_list_tunable {
1066 /* returns a : separated list of tunable names */
1071 /* table that contains a list of all nodes a ctdb knows about and their
1074 struct ctdb_node_and_flags {
1077 struct sockaddr_in sin;
1081 struct ctdb_node_map {
1083 struct ctdb_node_and_flags nodes[1];
1086 struct ctdb_control_wipe_database {
1088 uint32_t transaction_id;
1092 state of a in-progress ctdb call in client
1094 struct ctdb_client_call_state {
1095 enum call_state state;
1097 struct ctdb_db_context *ctdb_db;
1098 struct ctdb_call *call;
1100 void (*fn)(struct ctdb_client_call_state *);
1106 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
1107 TDB_DATA *outdata, uint32_t srcnode);
1108 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1109 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
1111 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
1113 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1114 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
1115 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
1117 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
1118 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
1119 int32_t ctdb_ltdb_set_seqnum_frequency(struct ctdb_context *ctdb, uint32_t frequency);
1121 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
1122 TDB_DATA key, struct ctdb_ltdb_header *, TDB_DATA data);
1124 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1125 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
1126 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
1128 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
1129 struct ctdb_req_control *c,
1130 TDB_DATA indata, bool *async_reply,
1131 const char **errormsg);
1132 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1133 TDB_DATA *outdata, int32_t status, const char *errormsg);
1135 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1136 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1138 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1139 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
1141 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1143 void ctdb_disable_monitoring(struct ctdb_context *ctdb);
1144 void ctdb_enable_monitoring(struct ctdb_context *ctdb);
1145 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1146 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1147 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1148 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1149 void ctdb_start_keepalive(struct ctdb_context *ctdb);
1150 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
1151 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA data, bool *async_reply);
1154 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1155 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1156 void ctdb_node_dead(struct ctdb_node *node);
1157 void ctdb_node_connected(struct ctdb_node *node);
1158 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1159 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1160 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1161 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1162 struct ctdb_req_control *c,
1165 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1166 struct ctdb_req_control *c,
1169 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
1170 struct ctdb_req_control *c,
1172 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
1173 struct ctdb_req_control *c,
1176 struct ctdb_public_ip {
1178 struct sockaddr_in sin;
1180 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1181 uint32_t destnode, struct ctdb_public_ip *ip);
1182 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1183 uint32_t destnode, struct ctdb_public_ip *ip);
1185 struct ctdb_all_public_ips {
1187 struct ctdb_public_ip ips[1];
1189 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1190 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1191 struct timeval timeout, uint32_t destnode,
1192 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1195 /* from takeover/system.c */
1196 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
1197 bool ctdb_sys_have_ip(struct sockaddr_in ip);
1198 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
1199 const ctdb_sock_addr *src,
1200 uint32_t seq, uint32_t ack, int rst);
1202 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1203 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1204 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1205 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1207 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1209 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1210 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1211 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1212 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1213 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb, TDB_DATA indata);
1214 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1215 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1217 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1218 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1219 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1220 struct timeval timeout,
1221 TALLOC_CTX *mem_ctx,
1222 void (*callback)(struct ctdb_context *, int, void *),
1224 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1225 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1227 void set_nonblocking(int fd);
1228 void set_close_on_exec(int fd);
1230 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1232 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1234 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1236 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1237 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1238 int32_t ctdb_control_get_reclock_file(struct ctdb_context *ctdb, TDB_DATA *outdata);
1239 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1240 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1241 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA indata);
1243 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1245 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1247 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1248 struct timeval timeout,
1250 struct ctdb_tunable *tunables);
1252 void ctdb_start_freeze(struct ctdb_context *ctdb);
1254 bool parse_ip_port(const char *s, ctdb_sock_addr *saddr);
1255 bool parse_ip(const char *s, ctdb_sock_addr *saddr);
1257 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1258 int ctdb_sys_close_capture_socket(void *private_data);
1259 int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst,
1260 uint32_t *ack_seq, uint32_t *seq);
1262 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1263 struct timeval timeout,
1265 struct ctdb_control_killtcp *killtcp);
1267 int ctdb_ctrl_add_public_ip(struct ctdb_context *ctdb,
1268 struct timeval timeout,
1270 struct ctdb_control_ip_iface *pub);
1272 int ctdb_ctrl_del_public_ip(struct ctdb_context *ctdb,
1273 struct timeval timeout,
1275 struct ctdb_control_ip_iface *pub);
1277 int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
1278 struct timeval timeout,
1280 ctdb_sock_addr *addr,
1281 const char *ifname);
1283 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1284 struct timeval timeout,
1286 TALLOC_CTX *mem_ctx,
1287 struct sockaddr_in *ip,
1288 struct ctdb_control_tcp_tickle_list **list);
1291 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1294 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1296 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1298 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
1300 int32_t ctdb_control_uptime(struct ctdb_context *ctdb,
1303 int ctdb_attach_persistent(struct ctdb_context *ctdb);
1305 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
1306 struct ctdb_req_control *c,
1307 TDB_DATA recdata, bool *async_reply);
1308 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
1309 struct ctdb_req_control *c, TDB_DATA recdata,
1312 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id);
1313 int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id);
1314 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
1317 int ctdb_vacuum(struct ctdb_context *ctdb, int argc, const char **argv);
1318 int ctdb_repack(struct ctdb_context *ctdb, int argc, const char **argv);
1320 void ctdb_block_signal(int signum);
1321 void ctdb_unblock_signal(int signum);
1322 int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
1323 int ctdb_set_child_logging(struct ctdb_context *ctdb);
1326 typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data);
1328 struct client_async_data {
1329 enum ctdb_controls opcode;
1330 bool dont_log_errors;
1332 uint32_t fail_count;
1333 client_async_callback callback;
1334 client_async_callback fail_callback;
1335 void *callback_data;
1337 void ctdb_client_async_add(struct client_async_data *data, struct ctdb_client_control_state *state);
1338 int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data);
1339 int ctdb_client_async_control(struct ctdb_context *ctdb,
1340 enum ctdb_controls opcode,
1342 struct timeval timeout,
1343 bool dont_log_errors,
1345 client_async_callback client_callback,
1346 client_async_callback fail_callback,
1347 void *callback_data);
1349 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
1351 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
1353 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
1354 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb, TDB_DATA *outdata);