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