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
41 a tcp connection description
43 struct ctdb_tcp_connection {
44 struct sockaddr_in saddr;
45 struct sockaddr_in daddr;
48 /* the wire representation for a tcp tickle array */
49 struct ctdb_tcp_wire_array {
51 struct ctdb_tcp_connection connections[1];
54 /* the list of tcp tickles used by get/set tcp tickle list */
55 struct ctdb_control_tcp_tickle_list {
56 struct sockaddr_in ip;
57 struct ctdb_tcp_wire_array tickles;
61 array of tcp connections
63 struct ctdb_tcp_array {
65 struct ctdb_tcp_connection *connections;
69 /* all tunable variables go in here */
71 uint32_t max_redirect_count;
72 uint32_t seqnum_frequency;
73 uint32_t control_timeout;
74 uint32_t traverse_timeout;
75 uint32_t keepalive_interval;
76 uint32_t keepalive_limit;
78 uint32_t recover_timeout;
79 uint32_t recover_interval;
80 uint32_t election_timeout;
81 uint32_t takeover_timeout;
82 uint32_t monitor_interval;
83 uint32_t tickle_update_interval;
84 uint32_t script_timeout;
85 uint32_t recovery_grace_period;
86 uint32_t recovery_ban_period;
87 uint32_t database_hash_size;
88 uint32_t rerecovery_timeout;
92 an installed ctdb remote call
94 struct ctdb_registered_call {
95 struct ctdb_registered_call *next, *prev;
101 this address structure might need to be generalised later for some
104 struct ctdb_address {
110 check that a pnn is valid
112 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
115 /* called from the queue code when a packet comes in. Called with data==NULL
117 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
120 /* used for callbacks in ctdb_control requests */
121 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
122 int32_t status, TDB_DATA data,
123 const char *errormsg,
127 structure describing a connected client in the daemon
130 struct ctdb_context *ctdb;
132 struct ctdb_queue *queue;
135 struct ctdb_tcp_list *tcp_list;
139 /* state associated with a public ip address */
141 struct ctdb_vnn *prev, *next;
144 const char *public_address;
145 uint8_t public_netmask_bits;
147 /* the node number that is serving this public address, if any.
148 If no node serves this ip it is set to -1 */
151 /* List of clients to tickle for this public address */
152 struct ctdb_tcp_array *tcp_array;
154 /* whether we need to update the other nodes with changes to our list
155 of connected clients */
156 bool tcp_update_needed;
158 /* a context to hang sending gratious arp events off */
159 TALLOC_CTX *takeover_ctx;
161 struct ctdb_kill_tcp *killtcp;
165 state associated with one node
168 struct ctdb_context *ctdb;
169 struct ctdb_address address;
170 const char *name; /* for debug messages */
171 void *private_data; /* private to transport */
173 #define NODE_FLAGS_DISCONNECTED 0x00000001 /* node isn't connected */
174 #define NODE_FLAGS_UNHEALTHY 0x00000002 /* monitoring says node is unhealthy */
175 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
176 #define NODE_FLAGS_BANNED 0x00000008 /* recovery daemon has banned the node */
177 #define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
178 #define NODE_FLAGS_INACTIVE (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED)
181 /* used by the dead node monitoring */
186 /* a list of controls pending to this node, so we can time them out quickly
187 if the node becomes disconnected */
188 struct daemon_control_state *pending_controls;
190 /* used by the recovery daemon when distributing ip addresses
191 across the nodes. it needs to know which public ip's can be handled
194 struct ctdb_all_public_ips *public_ips;
198 transport specific methods
200 struct ctdb_methods {
201 int (*initialise)(struct ctdb_context *); /* initialise transport structures */
202 int (*start)(struct ctdb_context *); /* start protocol processing */
203 int (*add_node)(struct ctdb_node *); /* setup a new node */
204 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
205 void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
206 void (*shutdown)(struct ctdb_context *); /* shutdown transport */
210 transport calls up to the ctdb layer
212 struct ctdb_upcalls {
213 /* recv_pkt is called when a packet comes in */
214 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
216 /* node_dead is called when an attempt to send to a node fails */
217 void (*node_dead)(struct ctdb_node *);
219 /* node_connected is called when a connection to a node is established */
220 void (*node_connected)(struct ctdb_node *);
223 /* list of message handlers - needs to be changed to a more efficient data
224 structure so we can find a message handler given a srvid quickly */
225 struct ctdb_message_list {
226 struct ctdb_context *ctdb;
227 struct ctdb_message_list *next, *prev;
229 ctdb_message_fn_t message_handler;
230 void *message_private;
233 /* additional data required for the daemon mode */
234 struct ctdb_daemon_data {
237 struct ctdb_queue *queue;
241 ctdb status information
243 struct ctdb_statistics {
244 uint32_t num_clients;
247 uint32_t client_packets_sent;
248 uint32_t client_packets_recv;
249 uint32_t node_packets_sent;
250 uint32_t node_packets_recv;
251 uint32_t keepalive_packets_sent;
252 uint32_t keepalive_packets_recv;
256 uint32_t req_dmaster;
257 uint32_t reply_dmaster;
258 uint32_t reply_error;
259 uint32_t req_message;
260 uint32_t req_control;
261 uint32_t reply_control;
265 uint32_t req_message;
266 uint32_t req_control;
273 uint32_t total_calls;
274 uint32_t pending_calls;
275 uint32_t lockwait_calls;
276 uint32_t pending_lockwait_calls;
277 uint32_t memory_used;
278 uint32_t __last_counter; /* hack for control_statistics_all */
279 uint32_t max_hop_count;
280 double max_call_latency;
281 double max_lockwait_latency;
285 #define INVALID_GENERATION 1
286 /* table that contains the mapping between a hash value and lmaster
288 struct ctdb_vnn_map {
295 a wire representation of the vnn map
297 struct ctdb_vnn_map_wire {
303 /* a structure that contains the elements required for the write record
306 struct ctdb_write_record {
310 unsigned char blob[1];
313 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
315 #define CTDB_MONITORING_ACTIVE 0
316 #define CTDB_MONITORING_DISABLED 1
318 /* main state of the ctdb daemon */
319 struct ctdb_context {
320 struct event_context *ev;
321 uint32_t recovery_mode;
322 uint32_t monitoring_mode;
323 TALLOC_CTX *monitor_context;
324 TALLOC_CTX *tickle_update_context;
325 struct ctdb_tunable tunable;
326 enum ctdb_freeze_mode freeze_mode;
327 struct ctdb_freeze_handle *freeze_handle;
328 struct ctdb_address address;
330 const char *db_directory;
331 const char *transport;
333 char *node_list_file;
334 char *recovery_lock_file;
335 int recovery_lock_fd;
336 uint32_t pnn; /* our own pnn */
338 uint32_t num_connected;
340 struct idr_context *idr;
342 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
343 struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
345 const struct ctdb_methods *methods; /* transport methods */
346 const struct ctdb_upcalls *upcalls; /* transport upcalls */
347 void *private_data; /* private to transport */
348 struct ctdb_db_context *db_list;
349 struct ctdb_message_list *message_list;
350 struct ctdb_daemon_data daemon;
351 struct ctdb_statistics statistics;
352 struct ctdb_vnn_map *vnn_map;
353 uint32_t num_clients;
354 uint32_t recovery_master;
355 struct ctdb_call_state *pending_calls;
356 struct ctdb_client_ip *client_ip_list;
358 void *saved_scheduler_param;
359 struct _trbt_tree_t *server_ids;
360 const char *event_script_dir;
363 struct ctdb_db_context {
364 struct ctdb_db_context *next, *prev;
365 struct ctdb_context *ctdb;
369 struct tdb_wrap *ltdb;
370 struct ctdb_registered_call *calls; /* list of registered calls */
372 struct timed_event *te;
376 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
377 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
378 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
379 return -1; }} while (0)
381 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
382 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
383 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
386 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
387 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
388 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
389 return NULL; }} while (0)
391 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
392 DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
393 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
397 the extended header for records in the ltdb
399 struct ctdb_ltdb_header {
406 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
407 CTDB_CONTROL_STATISTICS = 1,
409 CTDB_CONTROL_PING = 3,
410 CTDB_CONTROL_GETDBPATH = 4,
411 CTDB_CONTROL_GETVNNMAP = 5,
412 CTDB_CONTROL_SETVNNMAP = 6,
413 CTDB_CONTROL_GET_DEBUG = 7,
414 CTDB_CONTROL_SET_DEBUG = 8,
415 CTDB_CONTROL_GET_DBMAP = 9,
416 CTDB_CONTROL_GET_NODEMAP = 10,
417 CTDB_CONTROL_SET_DMASTER = 11,
419 CTDB_CONTROL_PULL_DB = 13,
420 CTDB_CONTROL_PUSH_DB = 14,
421 CTDB_CONTROL_GET_RECMODE = 15,
422 CTDB_CONTROL_SET_RECMODE = 16,
423 CTDB_CONTROL_STATISTICS_RESET = 17,
424 CTDB_CONTROL_DB_ATTACH = 18,
425 CTDB_CONTROL_SET_CALL = 19,
426 CTDB_CONTROL_TRAVERSE_START = 20,
427 CTDB_CONTROL_TRAVERSE_ALL = 21,
428 CTDB_CONTROL_TRAVERSE_DATA = 22,
429 CTDB_CONTROL_REGISTER_SRVID = 23,
430 CTDB_CONTROL_DEREGISTER_SRVID = 24,
431 CTDB_CONTROL_GET_DBNAME = 25,
432 CTDB_CONTROL_ENABLE_SEQNUM = 26,
433 CTDB_CONTROL_UPDATE_SEQNUM = 27,
435 CTDB_CONTROL_DUMP_MEMORY = 29,
436 CTDB_CONTROL_GET_PID = 30,
437 CTDB_CONTROL_GET_RECMASTER = 31,
438 CTDB_CONTROL_SET_RECMASTER = 32,
439 CTDB_CONTROL_FREEZE = 33,
440 CTDB_CONTROL_THAW = 34,
441 CTDB_CONTROL_GET_PNN = 35,
442 CTDB_CONTROL_SHUTDOWN = 36,
443 CTDB_CONTROL_GET_MONMODE = 37,
444 CTDB_CONTROL_SET_MONMODE = 38,
445 CTDB_CONTROL_MAX_RSN = 39,
446 CTDB_CONTROL_SET_RSN_NONEMPTY = 40,
447 CTDB_CONTROL_DELETE_LOW_RSN = 41,
448 CTDB_CONTROL_TAKEOVER_IP = 42,
449 CTDB_CONTROL_RELEASE_IP = 43,
450 CTDB_CONTROL_TCP_CLIENT = 44,
451 CTDB_CONTROL_TCP_ADD = 45,
452 CTDB_CONTROL_TCP_REMOVE = 46,
453 CTDB_CONTROL_STARTUP = 47,
454 CTDB_CONTROL_SET_TUNABLE = 48,
455 CTDB_CONTROL_GET_TUNABLE = 49,
456 CTDB_CONTROL_LIST_TUNABLES = 50,
457 CTDB_CONTROL_GET_PUBLIC_IPS = 51,
458 CTDB_CONTROL_MODIFY_FLAGS = 52,
459 CTDB_CONTROL_GET_ALL_TUNABLES = 53,
460 CTDB_CONTROL_KILL_TCP = 54,
461 CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55,
462 CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56,
463 CTDB_CONTROL_REGISTER_SERVER_ID = 57,
464 CTDB_CONTROL_UNREGISTER_SERVER_ID = 58,
465 CTDB_CONTROL_CHECK_SERVER_ID = 59,
466 CTDB_CONTROL_GET_SERVER_ID_LIST = 60,
470 structure passed in ctdb_control_set_rsn_nonempty
472 struct ctdb_control_set_rsn_nonempty {
478 structure passed in ctdb_control_delete_low_rsn
480 struct ctdb_control_delete_low_rsn {
486 structure passed in set_call control
488 struct ctdb_control_set_call {
495 struct for tcp_client control
497 struct ctdb_control_tcp {
498 struct sockaddr_in src;
499 struct sockaddr_in dest;
503 struct for kill_tcp control
505 struct ctdb_control_killtcp {
506 struct sockaddr_in src;
507 struct sockaddr_in dst;
511 struct for tcp_add and tcp_remove controls
513 struct ctdb_control_tcp_vnn {
514 struct sockaddr_in src;
515 struct sockaddr_in dest;
519 structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
521 struct ctdb_node_flag_change {
528 structure to change flags on a node
530 struct ctdb_node_modflags {
536 struct for admin setting a ban
538 struct ctdb_ban_info {
543 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
545 #define CTDB_LMASTER_ANY 0xffffffff
548 state of a in-progress ctdb call
550 struct ctdb_call_state {
551 struct ctdb_call_state *next, *prev;
552 enum call_state state;
554 struct ctdb_req_call *c;
555 struct ctdb_db_context *ctdb_db;
557 struct ctdb_call call;
560 void (*fn)(struct ctdb_call_state *);
566 /* used for fetch_lock */
567 struct ctdb_fetch_handle {
568 struct ctdb_db_context *ctdb_db;
571 struct ctdb_ltdb_header header;
577 enum ctdb_operation {
580 CTDB_REQ_DMASTER = 2,
581 CTDB_REPLY_DMASTER = 3,
582 CTDB_REPLY_ERROR = 4,
583 CTDB_REQ_MESSAGE = 5,
585 CTDB_REQ_CONTROL = 7,
586 CTDB_REPLY_CONTROL = 8,
587 CTDB_REQ_KEEPALIVE = 9,
590 #define CTDB_MAGIC 0x43544442 /* CTDB */
591 #define CTDB_VERSION 1
596 struct ctdb_req_header {
599 uint32_t ctdb_version;
607 struct ctdb_req_call {
608 struct ctdb_req_header hdr;
614 uint32_t calldatalen;
615 uint8_t data[1]; /* key[] followed by calldata[] */
618 struct ctdb_reply_call {
619 struct ctdb_req_header hdr;
625 struct ctdb_reply_error {
626 struct ctdb_req_header hdr;
632 struct ctdb_req_dmaster {
633 struct ctdb_req_header hdr;
642 struct ctdb_reply_dmaster {
643 struct ctdb_req_header hdr;
651 struct ctdb_req_message {
652 struct ctdb_req_header hdr;
658 struct ctdb_req_getdbpath {
659 struct ctdb_req_header hdr;
663 struct ctdb_reply_getdbpath {
664 struct ctdb_req_header hdr;
669 struct ctdb_req_control {
670 struct ctdb_req_header hdr;
674 #define CTDB_CTRL_FLAG_NOREPLY 1
680 struct ctdb_reply_control {
681 struct ctdb_req_header hdr;
688 struct ctdb_req_keepalive {
689 struct ctdb_req_header hdr;
692 /* internal prototypes */
693 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
694 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
695 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
696 int ctdb_parse_address(struct ctdb_context *ctdb,
697 TALLOC_CTX *mem_ctx, const char *str,
698 struct ctdb_address *address);
699 uint32_t ctdb_hash(const TDB_DATA *key);
700 uint32_t ctdb_hash_string(const char *str);
701 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
702 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
703 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
704 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
705 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
706 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
708 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
709 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
710 TDB_DATA key, struct ctdb_ltdb_header *header,
711 TALLOC_CTX *mem_ctx, TDB_DATA *data);
712 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
713 struct ctdb_ltdb_header *header, TDB_DATA data);
714 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
715 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
716 TDB_DATA key, struct ctdb_req_header *hdr,
717 void (*recv_pkt)(void *, struct ctdb_req_header *),
718 void *recv_context, bool ignore_generation);
719 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
720 TDB_DATA key, struct ctdb_ltdb_header *header,
721 struct ctdb_req_header *hdr, TDB_DATA *data,
722 void (*recv_pkt)(void *, struct ctdb_req_header *),
723 void *recv_context, bool ignore_generation);
724 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
726 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
727 struct ctdb_call *call,
728 struct ctdb_ltdb_header *header,
732 int ctdbd_start(struct ctdb_context *ctdb);
733 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
734 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
737 queue a packet for sending
739 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
742 setup the fd used by the queue
744 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
747 setup a packet queue on a socket
749 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
750 TALLOC_CTX *mem_ctx, int fd, int alignment,
752 ctdb_queue_cb_fn_t callback,
756 allocate a packet for use in client<->daemon communication
758 struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
760 enum ctdb_operation operation,
761 size_t length, size_t slength,
763 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
764 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
766 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
768 enum ctdb_operation operation,
769 size_t length, size_t slength,
771 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
772 (type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
776 lock a record in the ltdb, given a key
778 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
781 unlock a record in the ltdb, given a key
783 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
787 make a ctdb call to the local daemon - async send. Called from client context.
789 This constructs a ctdb_call request and queues it for processing.
790 This call never blocks.
792 struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
793 struct ctdb_call *call);
796 make a recv call to the local ctdb daemon - called from client context
798 This is called when the program wants to wait for a ctdb_call to complete and get the
799 results. This call will block unless the call has already completed.
801 int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
803 int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
804 ctdb_message_fn_t handler,
807 int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
808 uint64_t srvid, TDB_DATA data);
813 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
814 uint64_t srvid, TDB_DATA data);
817 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
819 void (*callback)(void *), void *private_data);
821 struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
822 struct ctdb_call *call);
824 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
826 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
827 struct ctdb_call *call,
828 struct ctdb_ltdb_header *header);
830 int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
831 struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data,
834 #define ctdb_reqid_find(ctdb, reqid, type) (type *)_ctdb_reqid_find(ctdb, reqid, #type, __location__)
836 void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
838 int ctdb_socket_connect(struct ctdb_context *ctdb);
840 void ctdb_latency(double *latency, struct timeval t);
842 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
843 void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
844 void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
846 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
847 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
849 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
850 uint64_t srvid, uint32_t opcode, uint32_t client_id, uint32_t flags,
852 ctdb_control_callback_fn_t callback,
855 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
858 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
859 ctdb_fn_t fn, int id);
861 int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
862 uint32_t opcode, uint32_t flags, TDB_DATA data,
863 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
864 struct timeval *timeout, char **errormsg);
865 int ctdb_control_recv(struct ctdb_context *ctdb,
866 struct ctdb_client_control_state *state,
868 TDB_DATA *outdata, int32_t *status, char **errormsg);
870 struct ctdb_client_control_state *
871 ctdb_control_send(struct ctdb_context *ctdb,
872 uint32_t destnode, uint64_t srvid,
873 uint32_t opcode, uint32_t flags, TDB_DATA data,
874 TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
875 struct timeval *timeout,
881 #define CHECK_CONTROL_DATA_SIZE(size) do { \
882 if (indata.dsize != size) { \
883 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
884 opcode, (unsigned)indata.dsize, (unsigned)size)); \
889 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
890 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
891 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
892 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
893 int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
896 struct ctdb_traverse_start {
903 structure used to pass record data between the child and parent
905 struct ctdb_rec_data {
914 /* structure used for pulldb control */
915 struct ctdb_control_pulldb {
920 /* structure used for pulldb control */
921 struct ctdb_control_pulldb_reply {
927 /* set dmaster control structure */
928 struct ctdb_control_set_dmaster {
934 structure for setting a tunable
936 struct ctdb_control_set_tunable {
943 structure for getting a tunable
945 struct ctdb_control_get_tunable {
951 structure for listing tunables
953 struct ctdb_control_list_tunable {
955 /* returns a : separated list of tunable names */
960 /* table that contains a list of all nodes a ctdb knows about and their
963 struct ctdb_node_and_flags {
966 struct sockaddr_in sin;
970 struct ctdb_node_map {
972 struct ctdb_node_and_flags nodes[1];
975 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb, TDB_DATA indata,
976 TDB_DATA *outdata, uint32_t srcnode);
977 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
978 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB_DATA *outdata);
980 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data);
982 int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
983 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
984 int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid);
986 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
987 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id, uint32_t srcnode);
988 int32_t ctdb_ltdb_set_seqnum_frequency(struct ctdb_context *ctdb, uint32_t frequency);
990 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, TDB_DATA key, TDB_DATA data);
992 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
993 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
994 int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
996 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
997 struct ctdb_req_control *c,
998 TDB_DATA indata, bool *async_reply,
999 const char **errormsg);
1000 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
1001 TDB_DATA *outdata, int32_t status, const char *errormsg);
1003 int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
1004 int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
1006 int ctdb_start_recoverd(struct ctdb_context *ctdb);
1008 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
1010 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
1011 void ctdb_start_monitoring(struct ctdb_context *ctdb);
1012 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
1013 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode);
1015 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node);
1016 void ctdb_call_resend_all(struct ctdb_context *ctdb);
1017 void ctdb_node_dead(struct ctdb_node *node);
1018 void ctdb_node_connected(struct ctdb_node *node);
1019 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
1020 int32_t ctdb_control_max_rsn(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1021 int32_t ctdb_control_set_rsn_nonempty(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1022 int32_t ctdb_control_delete_low_rsn(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1023 int ctdb_ctrl_get_max_rsn(struct ctdb_context *ctdb, struct timeval timeout,
1024 uint32_t destnode, uint32_t db_id, uint64_t *max_rsn);
1025 int ctdb_ctrl_set_rsn_nonempty(struct ctdb_context *ctdb, struct timeval timeout,
1026 uint32_t destnode, uint32_t db_id, uint64_t rsn);
1027 int ctdb_ctrl_delete_low_rsn(struct ctdb_context *ctdb, struct timeval timeout,
1028 uint32_t destnode, uint32_t db_id, uint64_t rsn);
1029 void ctdb_set_scheduler(struct ctdb_context *ctdb);
1030 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
1031 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
1032 struct ctdb_req_control *c,
1035 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
1036 struct ctdb_req_control *c,
1040 struct ctdb_public_ip {
1042 struct sockaddr_in sin;
1044 int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
1045 uint32_t destnode, struct ctdb_public_ip *ip);
1046 int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
1047 uint32_t destnode, struct ctdb_public_ip *ip);
1049 struct ctdb_all_public_ips {
1051 struct ctdb_public_ip ips[1];
1053 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA *outdata);
1054 int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
1055 struct timeval timeout, uint32_t destnode,
1056 TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips);
1059 /* from takeover/system.c */
1060 int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface);
1061 bool ctdb_sys_have_ip(const char *ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname);
1062 int ctdb_sys_send_tcp(int fd,
1063 const struct sockaddr_in *dest,
1064 const struct sockaddr_in *src,
1065 uint32_t seq, uint32_t ack, int rst);
1067 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
1068 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
1069 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
1070 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
1072 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
1074 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
1075 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
1076 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
1077 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
1078 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata);
1079 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata);
1081 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
1082 int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1083 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1084 struct timeval timeout,
1085 TALLOC_CTX *mem_ctx,
1086 void (*callback)(struct ctdb_context *, int, void *),
1088 const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1089 void ctdb_release_all_ips(struct ctdb_context *ctdb);
1091 void set_nonblocking(int fd);
1092 void set_close_on_exec(int fd);
1094 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
1096 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
1098 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
1100 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
1101 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata);
1103 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
1105 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
1107 int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
1108 struct timeval timeout,
1110 struct ctdb_tunable *tunables);
1112 void ctdb_start_freeze(struct ctdb_context *ctdb);
1114 bool parse_ip_port(const char *s, struct sockaddr_in *ip);
1116 int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
1117 int ctdb_sys_close_capture_socket(void *private_data);
1118 int ctdb_sys_open_sending_socket(void);
1119 int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst,
1120 uint32_t *ack_seq, uint32_t *seq);
1122 int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
1123 struct timeval timeout,
1125 struct ctdb_control_killtcp *killtcp);
1127 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
1128 struct timeval timeout,
1130 TALLOC_CTX *mem_ctx,
1131 struct sockaddr_in *ip,
1132 struct ctdb_control_tcp_tickle_list **list);
1135 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
1138 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
1140 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
1142 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,