1 /*
2    ctdb database library
3 
4    Copyright (C) Andrew Tridgell  2006
5 
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.
10 
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.
15 
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/>.
18 */
19 
20 #ifndef _CTDB_PRIVATE_H
21 #define _CTDB_PRIVATE_H
22 
23 #include "ctdb_client.h"
24 #include <sys/socket.h>
25 
26 #include "common/db_hash.h"
27 
28 /*
29   array of tcp connections
30  */
31 struct ctdb_tcp_array {
32 	uint32_t num;
33 	struct ctdb_connection *connections;
34 };
35 
36 /*
37   an installed ctdb remote call
38 */
39 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
40 
41 struct ctdb_registered_call {
42 	struct ctdb_registered_call *next, *prev;
43 	uint32_t id;
44 	ctdb_fn_t fn;
45 };
46 
47 /*
48   check that a pnn is valid
49  */
50 #define ctdb_validate_pnn(ctdb, pnn) (((uint32_t)(pnn)) < (ctdb)->num_nodes)
51 
52 /* used for callbacks in ctdb_control requests */
53 typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
54 					   int32_t status, TDB_DATA data,
55 					   const char *errormsg,
56 					   void *private_data);
57 /*
58   structure describing a connected client in the daemon
59  */
60 struct ctdb_client {
61 	struct ctdb_context *ctdb;
62 	int fd;
63 	struct ctdb_queue *queue;
64 	uint32_t client_id;
65 	pid_t pid;
66 	struct ctdb_tcp_list *tcp_list;
67 	uint32_t db_id;
68 	uint32_t num_persistent_updates;
69 	struct ctdb_client_notify_list *notify;
70 };
71 
72 /*
73   state associated with one node
74 */
75 struct ctdb_node {
76 	struct ctdb_context *ctdb;
77 	ctdb_sock_addr address;
78 	const char *name; /* for debug messages */
79 	void *transport_data; /* private to transport */
80 	uint32_t pnn;
81 	uint32_t flags;
82 
83 	/* used by the dead node monitoring */
84 	uint32_t dead_count;
85 	uint32_t rx_cnt;
86 	uint32_t tx_cnt;
87 
88 	/* a list of controls pending to this node, so we can time them out quickly
89 	   if the node becomes disconnected */
90 	struct daemon_control_state *pending_controls;
91 
92 	/* used by the recovery daemon to track when a node should be banned */
93 	struct ctdb_banning_state *ban_state;
94 };
95 
96 /*
97   transport specific methods
98 */
99 struct ctdb_methods {
100 	int (*initialise)(struct ctdb_context *); /* initialise transport structures */
101 	int (*start)(struct ctdb_context *); /* start the transport */
102 	int (*add_node)(struct ctdb_node *); /* setup a new node */
103 	int (*connect_node)(struct ctdb_node *); /* connect to node */
104 	int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
105 	void *(*allocate_pkt)(TALLOC_CTX *mem_ctx, size_t );
106 	void (*shutdown)(struct ctdb_context *); /* shutdown transport */
107 	void (*restart)(struct ctdb_node *); /* stop and restart the connection */
108 };
109 
110 /*
111   transport calls up to the ctdb layer
112 */
113 struct ctdb_upcalls {
114 	/* recv_pkt is called when a packet comes in */
115 	void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
116 
117 	/* node_dead is called when an attempt to send to a node fails */
118 	void (*node_dead)(struct ctdb_node *);
119 
120 	/* node_connected is called when a connection to a node is established */
121 	void (*node_connected)(struct ctdb_node *);
122 };
123 
124 /* additional data required for the daemon mode */
125 struct ctdb_daemon_data {
126 	int sd;
127 	char *name;
128 	struct ctdb_queue *queue;
129 };
130 
131 
132 #define CTDB_UPDATE_STAT(ctdb, counter, value) \
133 	{										\
134 		if (value > ctdb->statistics.counter) {					\
135 			ctdb->statistics.counter = value;				\
136 		}									\
137 		if (value > ctdb->statistics_current.counter) {				\
138 			ctdb->statistics_current.counter = value;			\
139 		}									\
140 	}
141 
142 #define CTDB_INCREMENT_STAT(ctdb, counter) \
143 	{										\
144 		ctdb->statistics.counter++;						\
145 		ctdb->statistics_current.counter++;					\
146 	}
147 
148 #define CTDB_DECREMENT_STAT(ctdb, counter) \
149 	{										\
150 		if (ctdb->statistics.counter > 0)					\
151 			ctdb->statistics.counter--;					\
152 		if (ctdb->statistics_current.counter > 0)				\
153 			ctdb->statistics_current.counter--;				\
154 	}
155 
156 #define CTDB_INCREMENT_DB_STAT(ctdb_db, counter) \
157 	{										\
158 		ctdb_db->statistics.counter++;						\
159 	}
160 
161 #define CTDB_DECREMENT_DB_STAT(ctdb_db, counter) \
162 	{										\
163 		if (ctdb_db->statistics.counter > 0)					\
164 			ctdb_db->statistics.counter--;					\
165 	}
166 
167 #define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
168 	{										\
169 		if (value > ctdb->statistics.counter.max)				\
170 			ctdb->statistics.counter.max = value;				\
171 		if (value > ctdb->statistics_current.counter.max)			\
172 			ctdb->statistics_current.counter.max = value;			\
173 											\
174 		if (ctdb->statistics.counter.num == 0 ||				\
175 		    value < ctdb->statistics.counter.min)				\
176 			ctdb->statistics.counter.min = value;				\
177 		if (ctdb->statistics_current.counter.num == 0 ||			\
178 		    value < ctdb->statistics_current.counter.min)			\
179 			ctdb->statistics_current.counter.min = value;			\
180 											\
181 		ctdb->statistics.counter.total += value;				\
182 		ctdb->statistics_current.counter.total += value;			\
183 											\
184 		ctdb->statistics.counter.num++;						\
185 		ctdb->statistics_current.counter.num++;					\
186 											\
187 		if (ctdb->tunable.reclock_latency_ms != 0) {				\
188 			if (value*1000 > ctdb->tunable.reclock_latency_ms) {		\
189 				DEBUG(DEBUG_ERR,					\
190 				      ("High RECLOCK latency %fs for operation %s\n",	\
191 				       value, name));					\
192 			}								\
193 		}									\
194 	}
195 
196 #define CTDB_UPDATE_DB_LATENCY(ctdb_db, operation, counter, value)			\
197 	{										\
198 		if (value > ctdb_db->statistics.counter.max)				\
199 			ctdb_db->statistics.counter.max = value;			\
200 		if (ctdb_db->statistics.counter.num == 0 || 				\
201 		    value < ctdb_db->statistics.counter.min)				\
202 			ctdb_db->statistics.counter.min = value;			\
203 											\
204 		ctdb_db->statistics.counter.total += value;				\
205 		ctdb_db->statistics.counter.num++;					\
206 											\
207 		if (ctdb_db->ctdb->tunable.log_latency_ms != 0) {			\
208 			if (value*1000 > ctdb_db->ctdb->tunable.log_latency_ms) {	\
209 				DEBUG(DEBUG_ERR,					\
210 				      ("High latency %.6fs for operation %s on database %s\n",\
211 				       value, operation, ctdb_db->db_name));		\
212 			}								\
213 		}									\
214 	}
215 
216 #define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
217 	{										\
218 		double l = timeval_elapsed(&t);						\
219 											\
220 		if (l > ctdb->statistics.counter.max)					\
221 			ctdb->statistics.counter.max = l;				\
222 		if (l > ctdb->statistics_current.counter.max)				\
223 			ctdb->statistics_current.counter.max = l;			\
224 											\
225 		if (ctdb->statistics.counter.num == 0 ||				\
226 		    l < ctdb->statistics.counter.min)					\
227 			ctdb->statistics.counter.min = l;				\
228 		if (ctdb->statistics_current.counter.num == 0 ||			\
229 		    l < ctdb->statistics_current.counter.min)				\
230 			ctdb->statistics_current.counter.min = l;			\
231 											\
232 		ctdb->statistics.counter.total += l;					\
233 		ctdb->statistics_current.counter.total += l;				\
234 											\
235 		ctdb->statistics.counter.num++;						\
236 		ctdb->statistics_current.counter.num++;					\
237 											\
238 		if (ctdb->tunable.log_latency_ms != 0) {				\
239 			if (l*1000 > ctdb->tunable.log_latency_ms) {			\
240 				DEBUG(DEBUG_WARNING,					\
241 				      ("High latency %.6fs for operation %s on database %s\n",\
242 				       l, operation, db->db_name));			\
243 			}								\
244 		}									\
245 	}
246 
247 
248 struct ctdb_cluster_mutex_handle;
249 struct eventd_context;
250 
251 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
252 
253 /* main state of the ctdb daemon */
254 struct ctdb_context {
255 	struct tevent_context *ev;
256 	struct timeval ctdbd_start_time;
257 	struct timeval last_recovery_started;
258 	struct timeval last_recovery_finished;
259 	uint32_t recovery_mode;
260 	TALLOC_CTX *tickle_update_context;
261 	TALLOC_CTX *keepalive_ctx;
262 	TALLOC_CTX *check_public_ifaces_ctx;
263 	struct ctdb_tunable_list tunable;
264 	enum ctdb_freeze_mode freeze_mode;
265 	struct ctdb_freeze_handle *freeze_handle;
266 	bool freeze_transaction_started;
267 	uint32_t freeze_transaction_id;
268 	ctdb_sock_addr *address;
269 	const char *name;
270 	const char *db_directory;
271 	const char *db_directory_persistent;
272 	const char *db_directory_state;
273 	struct tdb_wrap *db_persistent_health;
274 	uint32_t db_persistent_startup_generation;
275 	uint64_t db_persistent_check_errors;
276 	uint64_t max_persistent_check_errors;
277 	const char *transport;
278 	const char *recovery_lock;
279 	uint32_t pnn; /* our own pnn */
280 	uint32_t num_nodes;
281 	uint32_t num_connected;
282 	unsigned flags;
283 	uint32_t capabilities;
284 	struct reqid_context *idr;
285 	struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
286 	struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
287 	struct ctdb_interface *ifaces; /* list of local interfaces */
288 	char *err_msg;
289 	const struct ctdb_methods *methods; /* transport methods */
290 	const struct ctdb_upcalls *upcalls; /* transport upcalls */
291 	void *transport_data; /* private to transport */
292 	struct ctdb_db_context *db_list;
293 	struct srvid_context *srv;
294 	struct srvid_context *tunnels;
295 	struct ctdb_daemon_data daemon;
296 	struct ctdb_statistics statistics;
297 	struct ctdb_statistics statistics_current;
298 #define MAX_STAT_HISTORY 100
299 	struct ctdb_statistics statistics_history[MAX_STAT_HISTORY];
300 	struct ctdb_vnn_map *vnn_map;
301 	uint32_t num_clients;
302 	uint32_t recovery_master;
303 	struct ctdb_client_ip *client_ip_list;
304 	bool do_checkpublicip;
305 	bool do_setsched;
306 	const char *event_script_dir;
307 	const char *notification_script;
308 	pid_t ctdbd_pid;
309 	pid_t recoverd_pid;
310 	enum ctdb_runstate runstate;
311 	struct ctdb_monitor_state *monitor;
312 	int start_as_disabled;
313 	int start_as_stopped;
314 	bool valgrinding;
315 	uint32_t *recd_ping_count;
316 	TALLOC_CTX *recd_ctx; /* a context used to track recoverd monitoring events */
317 	TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
318 
319 	struct eventd_context *ectx;
320 
321 	TALLOC_CTX *banning_ctx;
322 
323 	struct ctdb_vacuum_child_context *vacuumer;
324 
325 	/* mapping from pid to ctdb_client * */
326 	struct ctdb_client_pid_list *client_pids;
327 
328 	/* Used to defer db attach requests while in recovery mode */
329 	struct ctdb_deferred_attach_context *deferred_attach;
330 
331 	/* if we are a child process, do we have a domain socket to send controls on */
332 	bool can_send_controls;
333 
334 	struct ctdb_reloadips_handle *reload_ips;
335 
336 	const char *nodes_file;
337 	const char *public_addresses_file;
338 	struct trbt_tree *child_processes;
339 
340 	/* Used for locking record/db/alldb */
341 	struct lock_context *lock_current;
342 	struct lock_context *lock_pending;
343 };
344 
345 struct ctdb_db_context {
346 	struct ctdb_db_context *next, *prev;
347 	struct ctdb_context *ctdb;
348 	uint32_t db_id;
349 	uint8_t db_flags;
350 	const char *db_name;
351 	const char *db_path;
352 	struct tdb_wrap *ltdb;
353 	struct tdb_context *rottdb; /* ReadOnly tracking TDB */
354 	struct ctdb_registered_call *calls; /* list of registered calls */
355 	uint32_t seqnum;
356 	struct tevent_timer *seqnum_update;
357 	struct ctdb_traverse_local_handle *traverse;
358 	struct ctdb_vacuum_handle *vacuum_handle;
359 	char *unhealthy_reason;
360 	int pending_requests;
361 	struct revokechild_handle *revokechild_active;
362 	struct ctdb_persistent_state *persistent_state;
363 	struct trbt_tree *delete_queue;
364 	struct trbt_tree *fetch_queue;
365 	struct trbt_tree *sticky_records;
366 	int (*ctdb_ltdb_store_fn)(struct ctdb_db_context *ctdb_db,
367 				  TDB_DATA key,
368 				  struct ctdb_ltdb_header *header,
369 				  TDB_DATA data);
370 
371 	/* used to track which records we are currently fetching
372 	   so we can avoid sending duplicate fetch requests
373 	*/
374 	struct trbt_tree *deferred_fetch;
375 	struct trbt_tree *defer_dmaster;
376 
377 	struct ctdb_db_statistics_old statistics;
378 
379 	struct lock_context *lock_current;
380 	struct lock_context *lock_pending;
381 	int lock_num_current;
382 	struct db_hash_context *lock_log;
383 
384 	struct ctdb_call_state *pending_calls;
385 
386 	enum ctdb_freeze_mode freeze_mode;
387 	struct ctdb_db_freeze_handle *freeze_handle;
388 	bool freeze_transaction_started;
389 	uint32_t freeze_transaction_id;
390 	uint32_t generation;
391 
392 	bool invalid_records;
393 	bool push_started;
394 	void *push_state;
395 
396 	struct hash_count_context *migratedb;
397 };
398 
399 
400 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
401           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
402           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
403 	  return -1; }} while (0)
404 
405 #define CTDB_NO_MEMORY_VOID(ctdb, p) do { if (!(p)) { \
406           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
407           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
408 	  return; }} while (0)
409 
410 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
411           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
412           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
413 	  return NULL; }} while (0)
414 
415 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
416           DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
417           ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
418 	  }} while (0)
419 
420 
421 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
422 
423 /*
424   state of a in-progress ctdb call
425 */
426 struct ctdb_call_state {
427 	struct ctdb_call_state *next, *prev;
428 	enum call_state state;
429 	uint32_t reqid;
430 	struct ctdb_req_call_old *c;
431 	struct ctdb_db_context *ctdb_db;
432 	const char *errmsg;
433 	struct ctdb_call *call;
434 	uint32_t generation;
435 	struct {
436 		void (*fn)(struct ctdb_call_state *);
437 		void *private_data;
438 	} async;
439 };
440 
441 /* internal prototypes */
442 
443 #define CHECK_CONTROL_DATA_SIZE(size) do { \
444  if (indata.dsize != size) { \
445 	 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
446 		  opcode, (unsigned)indata.dsize, (unsigned)size));	\
447 	 return -1; \
448  } \
449  } while (0)
450 
451 #define CHECK_CONTROL_MIN_DATA_SIZE(size) do { \
452  if (indata.dsize < size) { \
453 	 DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected >= %u\n", \
454 		  opcode, (unsigned)indata.dsize, (unsigned)size));	\
455 	 return -1; \
456  } \
457  } while (0)
458 
459 /*
460   state of a in-progress ctdb call in client
461 */
462 struct ctdb_client_call_state {
463 	enum call_state state;
464 	uint32_t reqid;
465 	struct ctdb_db_context *ctdb_db;
466 	struct ctdb_call *call;
467 	struct {
468 		void (*fn)(struct ctdb_client_call_state *);
469 		void *private_data;
470 	} async;
471 };
472 
473 extern int script_log_level;
474 extern bool fast_start;
475 extern const char *ctdbd_pidfile;
476 
477 typedef void (*deferred_requeue_fn)(void *call_context, struct ctdb_req_header *hdr);
478 
479 
480 /* from tcp/ and ib/ */
481 
482 int ctdb_tcp_init(struct ctdb_context *ctdb);
483 int ctdb_ibw_init(struct ctdb_context *ctdb);
484 
485 /* from ctdb_banning.c */
486 
487 int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
488 int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
489 void ctdb_ban_self(struct ctdb_context *ctdb);
490 
491 /* from ctdb_call.c */
492 
493 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
494 
495 void ctdb_request_dmaster(struct ctdb_context *ctdb,
496 			  struct ctdb_req_header *hdr);
497 void ctdb_reply_dmaster(struct ctdb_context *ctdb,
498 			struct ctdb_req_header *hdr);
499 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
500 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
501 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
502 
503 void ctdb_call_resend_db(struct ctdb_db_context *ctdb);
504 void ctdb_call_resend_all(struct ctdb_context *ctdb);
505 
506 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
507 					     struct ctdb_call *call,
508 					     struct ctdb_ltdb_header *header,
509 					     TDB_DATA *data);
510 
511 struct ctdb_call_state *ctdb_daemon_call_send_remote(
512 					struct ctdb_db_context *ctdb_db,
513 					struct ctdb_call *call,
514 					struct ctdb_ltdb_header *header);
515 int ctdb_daemon_call_recv(struct ctdb_call_state *state,
516 			  struct ctdb_call *call);
517 
518 int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb,
519 				struct ctdb_db_context *ctdb_db,
520 				TDB_DATA key, struct ctdb_ltdb_header *header,
521 				TDB_DATA data);
522 
523 int ctdb_add_revoke_deferred_call(struct ctdb_context *ctdb,
524 				  struct ctdb_db_context *ctdb_db,
525 				  TDB_DATA key, struct ctdb_req_header *hdr,
526 				  deferred_requeue_fn fn, void *call_context);
527 
528 int ctdb_migration_init(struct ctdb_db_context *ctdb_db);
529 
530 /* from server/ctdb_control.c */
531 
532 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata);
533 
534 void ctdb_request_control_reply(struct ctdb_context *ctdb,
535 				struct ctdb_req_control_old *c,
536 				TDB_DATA *outdata, int32_t status,
537 				const char *errormsg);
538 
539 void ctdb_request_control(struct ctdb_context *ctdb,
540 			  struct ctdb_req_header *hdr);
541 void ctdb_reply_control(struct ctdb_context *ctdb,
542 			struct ctdb_req_header *hdr);
543 
544 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
545 			     uint64_t srvid, uint32_t opcode,
546 			     uint32_t client_id, uint32_t flags,
547 			     TDB_DATA data,
548 			     ctdb_control_callback_fn_t callback,
549 			     void *private_data);
550 
551 /* from server/ctdb_daemon.c */
552 
553 int daemon_register_message_handler(struct ctdb_context *ctdb,
554 				    uint32_t client_id, uint64_t srvid);
555 int daemon_deregister_message_handler(struct ctdb_context *ctdb,
556 				      uint32_t client_id, uint64_t srvid);
557 
558 void daemon_tunnel_handler(uint64_t tunnel_id, TDB_DATA data,
559 			   void *private_data);
560 
561 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
562 
563 struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
564 						 TALLOC_CTX *mem_ctx,
565 						 enum ctdb_operation operation,
566 						 size_t length, size_t slength,
567 						 const char *type);
568 
569 #define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
570 	(type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, \
571 					 sizeof(type), #type)
572 
573 void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb,
574 				 struct ctdb_node *node);
575 
576 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
577 			 ctdb_fn_t fn, int id);
578 
579 int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
580 			     uint64_t srvid, TDB_DATA data);
581 
582 int32_t ctdb_control_register_notify(struct ctdb_context *ctdb,
583 				     uint32_t client_id, TDB_DATA indata);
584 int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb,
585 				       uint32_t client_id, TDB_DATA indata);
586 
587 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb,
588 					    pid_t pid);
589 
590 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
591 int32_t ctdb_control_check_pid_srvid(struct ctdb_context *ctdb,
592 				     TDB_DATA indata);
593 
594 int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode,
595 			      TDB_DATA indata, TDB_DATA *outdata);
596 
597 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code);
598 
599 int switch_from_server_to_client(struct ctdb_context *ctdb);
600 
601 /* From server/ctdb_fork.c */
602 
603 void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid);
604 
605 pid_t ctdb_fork(struct ctdb_context *ctdb);
606 pid_t ctdb_vfork_exec(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
607 		      const char *helper, int helper_argc,
608 		      const char **helper_argv);
609 
610 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
611 
612 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
613 
614 /* from server/ctdb_freeze.c */
615 
616 int32_t ctdb_control_db_freeze(struct ctdb_context *ctdb,
617 			       struct ctdb_req_control_old *c,
618 			       uint32_t db_id, bool *async_reply);
619 int32_t ctdb_control_db_thaw(struct ctdb_context *ctdb, uint32_t db_id);
620 
621 int32_t ctdb_control_freeze(struct ctdb_context *ctdb,
622 			    struct ctdb_req_control_old *c, bool *async_reply);
623 int32_t ctdb_control_thaw(struct ctdb_context *ctdb, bool check_recmode);
624 
625 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
626 
627 int32_t ctdb_control_db_transaction_start(struct ctdb_context *ctdb,
628 					  TDB_DATA indata);
629 int32_t ctdb_control_db_transaction_cancel(struct ctdb_context *ctdb,
630 					   TDB_DATA indata);
631 int32_t ctdb_control_db_transaction_commit(struct ctdb_context *ctdb,
632 					   TDB_DATA indata);
633 
634 int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
635 
636 bool ctdb_db_frozen(struct ctdb_db_context *ctdb_db);
637 bool ctdb_db_all_frozen(struct ctdb_context *ctdb);
638 bool ctdb_db_allow_access(struct ctdb_db_context *ctdb_db);
639 
640 /* from server/ctdb_keepalive.c */
641 
642 void ctdb_start_keepalive(struct ctdb_context *ctdb);
643 void ctdb_stop_keepalive(struct ctdb_context *ctdb);
644 
645 void ctdb_request_keepalive(struct ctdb_context *ctdb,
646 			    struct ctdb_req_header *hdr);
647 
648 /* from server/ctdb_lock.c */
649 
650 struct lock_request;
651 
652 typedef int (*ctdb_db_handler_t)(struct ctdb_db_context *ctdb_db,
653 				 void *private_data);
654 
655 int ctdb_db_iterator(struct ctdb_context *ctdb, ctdb_db_handler_t handler,
656 		     void *private_data);
657 
658 int ctdb_lockdb_mark(struct ctdb_db_context *ctdb_db);
659 
660 int ctdb_lockdb_unmark(struct ctdb_db_context *ctdb_db);
661 
662 struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx,
663 				      struct ctdb_db_context *ctdb_db,
664 				      TDB_DATA key,
665 				      bool auto_mark,
666 				      void (*callback)(void *, bool),
667 				      void *private_data);
668 
669 struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
670 				  struct ctdb_db_context *ctdb_db,
671 				  bool auto_mark,
672 				  void (*callback)(void *, bool),
673 				  void *private_data);
674 
675 /* from ctdb_logging.c */
676 
677 bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
678 		       const char *debug_level);
679 
680 int ctdb_set_child_logging(struct ctdb_context *ctdb);
681 
682 /* from ctdb_logging_file.c */
683 
684 void ctdb_log_init_file(void);
685 
686 /* from ctdb_logging_syslog.c */
687 
688 void ctdb_log_init_syslog(void);
689 
690 /* from ctdb_ltdb_server.c */
691 
692 int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db,
693 			   TDB_DATA key, struct ctdb_req_header *hdr,
694 			   void (*recv_pkt)(void *, struct ctdb_req_header *),
695 			   void *recv_context, bool ignore_generation);
696 
697 int ctdb_ltdb_lock_fetch_requeue(struct ctdb_db_context *ctdb_db,
698 				 TDB_DATA key, struct ctdb_ltdb_header *header,
699 				 struct ctdb_req_header *hdr, TDB_DATA *data,
700 				 void (*recv_pkt)(void *, struct ctdb_req_header *),
701 				 void *recv_context, bool ignore_generation);
702 
703 int ctdb_load_persistent_health(struct ctdb_context *ctdb,
704 				struct ctdb_db_context *ctdb_db);
705 int ctdb_update_persistent_health(struct ctdb_context *ctdb,
706 				  struct ctdb_db_context *ctdb_db,
707 				  const char *reason,/* NULL means healthy */
708 				  unsigned int num_healthy_nodes);
709 int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
710 
711 int32_t ctdb_control_db_set_healthy(struct ctdb_context *ctdb,
712 				    TDB_DATA indata);
713 int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb,
714 				   TDB_DATA indata, TDB_DATA *outdata);
715 
716 int ctdb_set_db_readonly(struct ctdb_context *ctdb,
717 			 struct ctdb_db_context *ctdb_db);
718 
719 int ctdb_process_deferred_attach(struct ctdb_context *ctdb);
720 
721 int32_t ctdb_control_db_attach(struct ctdb_context *ctdb,
722 			       TDB_DATA indata,
723 			       TDB_DATA *outdata,
724 			       uint8_t db_flags,
725 			       uint32_t srcnode,
726 			       uint32_t client_id,
727 			       struct ctdb_req_control_old *c,
728 			       bool *async_reply);
729 int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
730 			       uint32_t client_id);
731 
732 int ctdb_attach_databases(struct ctdb_context *ctdb);
733 
734 int32_t ctdb_ltdb_update_seqnum(struct ctdb_context *ctdb, uint32_t db_id,
735 				uint32_t srcnode);
736 int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id);
737 
738 int ctdb_set_db_sticky(struct ctdb_context *ctdb,
739 		       struct ctdb_db_context *ctdb_db);
740 
741 void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db);
742 
743 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
744 				       uint32_t db_id, TDB_DATA *outdata);
745 
746 /* from ctdb_monitor.c */
747 
748 void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
749 
750 void ctdb_stop_monitoring(struct ctdb_context *ctdb);
751 
752 void ctdb_wait_for_first_recovery(struct ctdb_context *ctdb);
753 
754 int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata);
755 
756 /* from ctdb_persistent.c */
757 
758 void ctdb_persistent_finish_trans3_commits(struct ctdb_context *ctdb);
759 
760 int32_t ctdb_control_trans3_commit(struct ctdb_context *ctdb,
761 				   struct ctdb_req_control_old *c,
762 				   TDB_DATA recdata, bool *async_reply);
763 
764 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb,
765 					     struct ctdb_req_control_old *c,
766 					     TDB_DATA recdata);
767 int32_t ctdb_control_cancel_persistent_update(struct ctdb_context *ctdb,
768 					      struct ctdb_req_control_old *c,
769 					      TDB_DATA recdata);
770 
771 int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
772 				   TDB_DATA indata, TDB_DATA *outdata);
773 
774 /* from ctdb_recover.c */
775 
776 int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
777 			   TDB_DATA indata, TDB_DATA *outdata);
778 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode,
779 			   TDB_DATA indata, TDB_DATA *outdata);
780 
781 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode,
782 			  TDB_DATA indata, TDB_DATA *outdata);
783 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode,
784 			    TDB_DATA indata, TDB_DATA *outdata);
785 
786 int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
787 
788 int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata,
789 			     TDB_DATA *outdata);
790 int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
791 
792 int32_t ctdb_control_db_pull(struct ctdb_context *ctdb,
793 			     struct ctdb_req_control_old *c,
794 			     TDB_DATA indata, TDB_DATA *outdata);
795 int32_t ctdb_control_db_push_start(struct ctdb_context *ctdb,
796 				   TDB_DATA indata);
797 int32_t ctdb_control_db_push_confirm(struct ctdb_context *ctdb,
798 				     TDB_DATA indata, TDB_DATA *outdata);
799 
800 int ctdb_deferred_drop_all_ips(struct ctdb_context *ctdb);
801 
802 int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
803 				 struct ctdb_req_control_old *c,
804 				 TDB_DATA indata, bool *async_reply,
805 				 const char **errormsg);
806 
807 int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
808 				 struct ctdb_req_control_old *c,
809 				 bool *async_reply);
810 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
811 				 struct ctdb_req_control_old *c,
812 				 bool *async_reply);
813 
814 int32_t ctdb_control_try_delete_records(struct ctdb_context *ctdb,
815 					TDB_DATA indata, TDB_DATA *outdata);
816 
817 int32_t ctdb_control_get_capabilities(struct ctdb_context *ctdb,
818 				      TDB_DATA *outdata);
819 
820 int32_t ctdb_control_recd_ping(struct ctdb_context *ctdb);
821 int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb,
822 				   uint32_t opcode, TDB_DATA indata);
823 
824 void ctdb_node_become_inactive(struct ctdb_context *ctdb);
825 
826 int32_t ctdb_control_stop_node(struct ctdb_context *ctdb);
827 int32_t ctdb_control_continue_node(struct ctdb_context *ctdb);
828 
829 /* from ctdb_recoverd.c */
830 
831 int ctdb_start_recoverd(struct ctdb_context *ctdb);
832 void ctdb_stop_recoverd(struct ctdb_context *ctdb);
833 
834 /* from ctdb_server.c */
835 
836 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
837 
838 struct ctdb_node *ctdb_ip_to_node(struct ctdb_context *ctdb,
839 				  const ctdb_sock_addr *nodeip);
840 uint32_t ctdb_ip_to_pnn(struct ctdb_context *ctdb,
841 			const ctdb_sock_addr *nodeip);
842 
843 void ctdb_load_nodes_file(struct ctdb_context *ctdb);
844 
845 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
846 
847 uint32_t ctdb_get_num_active_nodes(struct ctdb_context *ctdb);
848 
849 void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *);
850 
851 void ctdb_node_dead(struct ctdb_node *node);
852 void ctdb_node_connected(struct ctdb_node *node);
853 
854 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
855 void ctdb_queue_packet_opcode(struct ctdb_context *ctdb,
856 			      struct ctdb_req_header *hdr, unsigned opcode);
857 
858 /* from ctdb_serverids.c */
859 
860 int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
861 					uint32_t client_id, TDB_DATA indata);
862 int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
863 				     TDB_DATA indata);
864 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
865 					  TDB_DATA indata);
866 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
867 					TDB_DATA *outdata);
868 
869 /* from ctdb_statistics.c */
870 
871 int ctdb_statistics_init(struct ctdb_context *ctdb);
872 
873 int32_t ctdb_control_get_stat_history(struct ctdb_context *ctdb,
874 				      struct ctdb_req_control_old *c,
875 				      TDB_DATA *outdata);
876 
877 /* from ctdb_takeover.c */
878 
879 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
880 				 struct ctdb_req_control_old *c,
881 				 TDB_DATA indata,
882 				 bool *async_reply);
883 int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
884 				 struct ctdb_req_control_old *c,
885 				 TDB_DATA indata,
886 				 bool *async_reply);
887 int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
888 				 struct ctdb_req_control_old *c,
889 				 bool *async_reply);
890 
891 int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses);
892 
893 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
894 				TDB_DATA indata);
895 int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata,
896 			     bool tcp_update_needed);
897 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
898 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
899 
900 void ctdb_takeover_client_destructor_hook(struct ctdb_client *client);
901 
902 void ctdb_release_all_ips(struct ctdb_context *ctdb);
903 
904 int32_t ctdb_control_get_public_ips(struct ctdb_context *ctdb,
905 				    struct ctdb_req_control_old *c,
906 				    TDB_DATA *outdata);
907 int32_t ctdb_control_get_public_ip_info(struct ctdb_context *ctdb,
908 					struct ctdb_req_control_old *c,
909 					TDB_DATA indata, TDB_DATA *outdata);
910 
911 int32_t ctdb_control_get_ifaces(struct ctdb_context *ctdb,
912 				struct ctdb_req_control_old *c,
913 				TDB_DATA *outdata);
914 int32_t ctdb_control_set_iface_link(struct ctdb_context *ctdb,
915 				    struct ctdb_req_control_old *c,
916 				    TDB_DATA indata);
917 
918 int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb,
919 					 TDB_DATA indata);
920 int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb,
921 					 TDB_DATA indata, TDB_DATA *outdata);
922 
923 void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb);
924 
925 int32_t ctdb_control_send_gratious_arp(struct ctdb_context *ctdb,
926 				       TDB_DATA indata);
927 
928 int32_t ctdb_control_add_public_address(struct ctdb_context *ctdb,
929 					TDB_DATA indata);
930 int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb,
931 					TDB_DATA recdata);
932 
933 int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb,
934 				       struct ctdb_req_control_old *c,
935 				       bool *async_reply);
936 
937 /* from ctdb_traverse.c */
938 
939 int32_t ctdb_control_traverse_all_ext(struct ctdb_context *ctdb,
940 				      TDB_DATA data, TDB_DATA *outdata);
941 int32_t ctdb_control_traverse_all(struct ctdb_context *ctdb,
942 				  TDB_DATA data, TDB_DATA *outdata);
943 int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb,
944 				   TDB_DATA data, TDB_DATA *outdata);
945 int32_t ctdb_control_traverse_kill(struct ctdb_context *ctdb, TDB_DATA indata,
946 				    TDB_DATA *outdata, uint32_t srcnode);
947 
948 int32_t ctdb_control_traverse_start_ext(struct ctdb_context *ctdb,
949 					TDB_DATA indata, TDB_DATA *outdata,
950 					uint32_t srcnode, uint32_t client_id);
951 int32_t ctdb_control_traverse_start(struct ctdb_context *ctdb,
952 				    TDB_DATA indata, TDB_DATA *outdata,
953 				    uint32_t srcnode, uint32_t client_id);
954 
955 /* from ctdb_tunables.c */
956 
957 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
958 
959 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
960 				 TDB_DATA *outdata);
961 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata);
962 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb,
963 				   TDB_DATA *outdata);
964 
965 /* from ctdb_tunnel.c */
966 
967 int32_t ctdb_control_tunnel_register(struct ctdb_context *ctdb,
968 				     uint32_t client_id, uint64_t tunnel_id);
969 int32_t ctdb_control_tunnel_deregister(struct ctdb_context *ctdb,
970 				       uint32_t client_id, uint64_t tunnel_id);
971 
972 int ctdb_daemon_send_tunnel(struct ctdb_context *ctdb, uint32_t destnode,
973 			    uint64_t tunnel_id, uint32_t client_id,
974 			    TDB_DATA data);
975 
976 void ctdb_request_tunnel(struct ctdb_context *ctdb,
977 			 struct ctdb_req_header *hdr);
978 
979 /* from ctdb_update_record.c */
980 
981 int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
982 				   struct ctdb_req_control_old *c,
983 				   TDB_DATA recdata, bool *async_reply);
984 
985 /* from ctdb_uptime.c */
986 
987 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, TDB_DATA *outdata);
988 
989 /* from ctdb_vacuum.c */
990 
991 int32_t ctdb_control_db_vacuum(struct ctdb_context *ctdb,
992 			       struct ctdb_req_control_old *c,
993 			       TDB_DATA indata,
994 			       bool *async_reply);
995 
996 void ctdb_stop_vacuuming(struct ctdb_context *ctdb);
997 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
998 
999 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
1000 					   TDB_DATA indata);
1001 int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
1002 					 const struct ctdb_ltdb_header *hdr,
1003 					 TDB_DATA key);
1004 
1005 void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
1006 					 const struct ctdb_ltdb_header *hdr,
1007 					 const TDB_DATA key);
1008 
1009 int32_t ctdb_control_vacuum_fetch(struct ctdb_context *ctdb, TDB_DATA indata);
1010 
1011 /* from eventscript.c */
1012 
1013 int ctdb_start_eventd(struct ctdb_context *ctdb);
1014 void ctdb_stop_eventd(struct ctdb_context *ctdb);
1015 
1016 int ctdb_event_script_callback(struct ctdb_context *ctdb,
1017 			       TALLOC_CTX *mem_ctx,
1018 			       void (*callback)(struct ctdb_context *,
1019 						int, void *),
1020 			       void *private_data,
1021 			       enum ctdb_event call,
1022 			       const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
1023 
1024 int ctdb_event_script_args(struct ctdb_context *ctdb,
1025 			   enum ctdb_event call,
1026 			   const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
1027 
1028 int ctdb_event_script(struct ctdb_context *ctdb,
1029 		      enum ctdb_event call);
1030 
1031 #endif
1032