540ca98a8d2efeaa8989528a65cb71eb495c56e6
[sahlberg/ctdb.git] / include / ctdb_protocol.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_H
21 #define _CTDB_H
22
23 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
24 struct ctdb_call {
25         int call_id;
26         TDB_DATA key;
27         TDB_DATA call_data;
28         TDB_DATA reply_data;
29         uint32_t status;
30         uint32_t flags;
31 };
32
33 /*
34   structure passed to a ctdb call backend function
35 */
36 struct ctdb_call_info {
37         TDB_DATA key;          /* record key */
38         TDB_DATA record_data;  /* current data in the record */
39         TDB_DATA *new_data;    /* optionally updated record data */
40         TDB_DATA *call_data;   /* optionally passed from caller */
41         TDB_DATA *reply_data;  /* optionally returned by function */
42         uint32_t status;       /* optional reply status - defaults to zero */
43 };
44
45 #define CTDB_ERR_INVALID 1
46 #define CTDB_ERR_NOMEM 2
47
48 /*
49   ctdb flags
50 */
51 #define CTDB_FLAG_TORTURE      (1<<1)
52
53 /* 
54    a message handler ID meaning "give me all messages"
55  */
56 #define CTDB_SRVID_ALL (~(uint64_t)0)
57
58 /*
59   srvid type : RECOVERY
60 */
61 #define CTDB_SRVID_RECOVERY     0xF100000000000000LL
62
63 /* 
64    a message handler ID meaning that the cluster has been reconfigured
65  */
66 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
67
68 /* 
69    a message handler ID meaning that an IP address has been released
70  */
71 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
72
73 /* 
74    a message ID to set the node flags in the recovery daemon
75  */
76 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
77
78 /* 
79    a message ID to ask the recovery daemon to update the expected node
80    assignment for a public ip
81  */
82 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
83
84 /*
85   a message to tell the recovery daemon to fetch a set of records
86  */
87 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
88
89 /*
90   a message to tell the recovery daemon to write a talloc memdump
91   to the log
92  */
93 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
94
95 /* 
96    a message ID to get the recovery daemon to push the node flags out
97  */
98 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
99
100 /* 
101    a message ID to get the recovery daemon to reload the nodes file
102  */
103 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
104
105 /* 
106    a message ID to get the recovery daemon to perform a takeover run
107  */
108 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
109
110 /* A message id to ask the recovery daemon to temporarily disable the
111    public ip checks
112 */
113 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
114
115 /* A dummy port used for sending back ipreallocate resposnes to the main
116    daemon
117 */
118 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE  0xFD00000000000000LL
119
120 /* A port reserved for samba (top 32 bits)
121  */
122 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
123
124 /* used on the domain socket, send a pdu to the local daemon */
125 #define CTDB_CURRENT_NODE     0xF0000001
126 /* send a broadcast to all nodes in the cluster, active or not */
127 #define CTDB_BROADCAST_ALL    0xF0000002
128 /* send a broadcast to all nodes in the current vnn map */
129 #define CTDB_BROADCAST_VNNMAP 0xF0000003
130 /* send a broadcast to all connected nodes */
131 #define CTDB_BROADCAST_CONNECTED 0xF0000004
132
133 /* the key used for transaction locking on persistent databases */
134 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
135
136 /* the key used to store persistent db sequence number */
137 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
138
139 enum control_state {CTDB_CONTROL_WAIT, CTDB_CONTROL_DONE, CTDB_CONTROL_ERROR, CTDB_CONTROL_TIMEOUT};
140
141 struct ctdb_client_control_state {
142         struct ctdb_context *ctdb;
143         uint32_t reqid;
144         int32_t status;
145         TDB_DATA outdata;
146         enum control_state state;
147         char *errormsg;
148         struct ctdb_req_control *c;
149
150         /* if we have a callback registered for the completion (or failure) of
151            this control
152            if a callback is used, it MUST talloc_free the cb_data passed to it
153         */
154         struct {
155                 void (*fn)(struct ctdb_client_control_state *);
156                 void *private_data;
157         } async;        
158 };
159
160 struct ctdb_client_notify_register {
161         uint64_t srvid;
162         uint32_t len;
163         uint8_t notify_data[1];
164 };
165
166 struct ctdb_client_notify_deregister {
167         uint64_t srvid;
168 };
169
170 struct event_context;
171
172 /*
173   initialise ctdb subsystem
174 */
175 struct ctdb_context *ctdb_init(struct event_context *ev);
176
177 /*
178   choose the transport
179 */
180 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
181
182 /*
183   set the directory for the local databases
184 */
185 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
186 int ctdb_set_tdb_dir_persistent(struct ctdb_context *ctdb, const char *dir);
187 int ctdb_set_tdb_dir_state(struct ctdb_context *ctdb, const char *dir);
188
189 /*
190   set some flags
191 */
192 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
193
194 /*
195   set max acess count before a dmaster migration
196 */
197 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
198
199 /*
200   tell ctdb what address to listen on, in transport specific format
201 */
202 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
203
204 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
205
206 /*
207   tell ctdb what nodes are available. This takes a filename, which will contain
208   1 node address per line, in a transport specific format
209 */
210 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
211
212 /*
213   Check that a specific ip address exists in the node list and returns
214   the id for the node or -1
215 */
216 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
217
218 /*
219   start the ctdb protocol
220 */
221 int ctdb_start(struct ctdb_context *ctdb);
222 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog);
223
224 /*
225   attach to a ctdb database
226 */
227 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
228
229 /*
230   find an attached ctdb_db handle given a name
231  */
232 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
233
234 /*
235   error string for last ctdb error
236 */
237 const char *ctdb_errstr(struct ctdb_context *);
238
239 /* a ctdb call function */
240 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
241
242 /*
243   setup a ctdb call function
244 */
245 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
246
247
248
249 /*
250   make a ctdb call. The associated ctdb call function will be called on the DMASTER
251   for the given record
252 */
253 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
254
255 /*
256   initiate an ordered ctdb cluster shutdown
257   this function will never return
258 */
259 void ctdb_shutdown(struct ctdb_context *ctdb);
260
261 /* return pnn of this node */
262 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
263
264 /*
265   return the number of nodes
266 */
267 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
268
269 /* setup a handler for ctdb messages */
270 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, 
271                                   TDB_DATA data, void *);
272 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
273                              ctdb_message_fn_t handler,
274                              void *private_data);
275
276
277 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
278 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
279 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
280
281 /* send a ctdb message */
282 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
283                       uint64_t srvid, TDB_DATA data);
284
285
286 /* 
287    Fetch a ctdb record from a remote node
288  . Underneath this will force the
289    dmaster for the record to be moved to the local node. 
290 */
291 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
292                                            TDB_DATA key, TDB_DATA *data);
293
294 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
295
296 int ctdb_fetch(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
297                TDB_DATA key, TDB_DATA *data);
298
299 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
300                                   TALLOC_CTX *mem_ctx,
301                                   uint64_t srvid,
302                                   ctdb_message_fn_t handler,
303                                   void *private_data);
304
305 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
306
307
308 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
309
310 struct ctdb_statistics;
311 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
312
313 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
314
315 struct ctdb_vnn_map;
316 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, 
317                 struct timeval timeout, uint32_t destnode, 
318                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
319 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
320                 struct timeval timeout, uint32_t destnode, 
321                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
322
323 /* table that contains a list of all dbids on a node
324  */
325 struct ctdb_dbid_map {
326         uint32_t num;
327         struct ctdb_dbid {
328                 uint32_t dbid;
329                 bool persistent;
330         } dbs[1];
331 };
332 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, 
333         struct timeval timeout, uint32_t destnode, 
334         TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
335
336
337 struct ctdb_node_map;
338
339 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, 
340                     struct timeval timeout, uint32_t destnode, 
341                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
342
343 int ctdb_ctrl_getnodemapv4(struct ctdb_context *ctdb, 
344                     struct timeval timeout, uint32_t destnode, 
345                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
346
347 int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb, 
348                     struct timeval timeout, uint32_t destnode);
349
350 struct ctdb_key_list {
351         uint32_t dbid;
352         uint32_t num;
353         TDB_DATA *keys;
354         struct ctdb_ltdb_header *headers;
355         TDB_DATA *data;
356 };
357
358 int ctdb_ctrl_pulldb(
359        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
360        uint32_t lmaster, TALLOC_CTX *mem_ctx,
361        struct timeval timeout, TDB_DATA *outdata);
362
363 struct ctdb_client_control_state *ctdb_ctrl_pulldb_send(
364        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
365        uint32_t lmaster, TALLOC_CTX *mem_ctx, struct timeval timeout);
366
367 int ctdb_ctrl_pulldb_recv(
368        struct ctdb_context *ctdb,
369        TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state,
370        TDB_DATA *outdata);
371
372 int ctdb_ctrl_pushdb(
373        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
374        TALLOC_CTX *mem_ctx,
375        struct timeval timeout, TDB_DATA indata);
376
377 struct ctdb_client_control_state *ctdb_ctrl_pushdb_send(
378        struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
379        TALLOC_CTX *mem_ctx, struct timeval timeout,
380        TDB_DATA indata);
381
382 int ctdb_ctrl_pushdb_recv(
383        struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
384        struct ctdb_client_control_state *state);
385
386
387 int ctdb_ctrl_copydb(struct ctdb_context *ctdb, 
388         struct timeval timeout, uint32_t sourcenode, 
389         uint32_t destnode, uint32_t dbid, uint32_t lmaster, 
390         TALLOC_CTX *mem_ctx);
391
392 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
393 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
394 int ctdb_ctrl_getdbhealth(struct ctdb_context *ctdb,
395                           struct timeval timeout,
396                           uint32_t destnode,
397                           uint32_t dbid, TALLOC_CTX *mem_ctx,
398                           const char **reason);
399 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent);
400
401 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
402
403 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
404
405 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
406
407 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level);
408 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t level);
409
410 /*
411   change dmaster for all keys in the database to the new value
412  */
413 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, 
414         struct timeval timeout, uint32_t destnode, 
415         TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
416
417 /*
418   write a record on a specific db (this implicitely updates dmaster of the record to locally be the vnn of the node where the control is executed on)
419  */
420 int ctdb_ctrl_write_record(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, TDB_DATA key, TDB_DATA data);
421
422 #define CTDB_RECOVERY_NORMAL            0
423 #define CTDB_RECOVERY_ACTIVE            1
424
425 /*
426   get the recovery mode of a remote node
427  */
428 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
429
430 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
431
432 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmode);
433
434
435 /*
436   set the recovery mode of a remote node
437  */
438 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
439 /*
440   get the monitoring mode of a remote node
441  */
442 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
443
444 /*
445   set the monitoring mode of a remote node to active
446  */
447 int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
448
449 /*
450   set the monitoring mode of a remote node to disabled
451  */
452 int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
453
454
455 /*
456   get the recovery master of a remote node
457  */
458 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
459
460 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
461
462 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmaster);
463
464
465
466 /*
467   set the recovery master of a remote node
468  */
469 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
470
471 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, 
472                                    struct timeval timeout, 
473                                    TALLOC_CTX *mem_ctx,
474                                    uint32_t *num_nodes);
475
476 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
477
478 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
479
480 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
481 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
482
483 int ctdb_dumpdb_record(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *p);
484 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
485
486 /*
487   get the pid of a ctdb daemon
488  */
489 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
490
491 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, 
492                         uint32_t destnode);
493 int ctdb_ctrl_freeze_priority(struct ctdb_context *ctdb, struct timeval timeout, 
494                               uint32_t destnode, uint32_t priority);
495
496 struct ctdb_client_control_state *
497 ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, 
498                       struct timeval timeout, uint32_t destnode,
499                       uint32_t priority);
500
501 int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, 
502                         struct ctdb_client_control_state *state);
503
504 int ctdb_ctrl_thaw_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t priority);
505 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
506
507 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
508
509 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb, 
510                           struct timeval timeout, 
511                           uint32_t destnode,
512                           const char *name, uint32_t *value);
513
514 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb, 
515                           struct timeval timeout, 
516                           uint32_t destnode,
517                           const char *name, uint32_t value);
518
519 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, 
520                             struct timeval timeout, 
521                             uint32_t destnode,
522                             TALLOC_CTX *mem_ctx,
523                             const char ***list, uint32_t *count);
524
525 int ctdb_ctrl_modflags(struct ctdb_context *ctdb, 
526                        struct timeval timeout, 
527                        uint32_t destnode, 
528                        uint32_t set, uint32_t clear);
529
530 enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
531
532 struct ctdb_server_id {
533         enum ctdb_server_id_type type;
534         uint32_t pnn;
535         uint32_t server_id;
536 };
537
538 struct ctdb_server_id_list {
539         uint32_t num;
540         struct ctdb_server_id server_ids[1];
541 };
542
543
544 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
545                 struct timeval timeout,
546                 struct ctdb_server_id *id);
547 int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb, 
548                 struct timeval timeout, 
549                 struct ctdb_server_id *id);
550 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
551                 struct timeval timeout, uint32_t destnode, 
552                 struct ctdb_server_id *id, uint32_t *status);
553 int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
554                 TALLOC_CTX *mem_ctx,
555                 struct timeval timeout, uint32_t destnode, 
556                 struct ctdb_server_id_list **svid_list);
557
558 struct ctdb_uptime {
559         struct timeval current_time;
560         struct timeval ctdbd_start_time;
561         struct timeval last_recovery_started;
562         struct timeval last_recovery_finished;
563 };
564
565 /*
566   definitions for different socket structures
567  */
568 typedef struct sockaddr_in ctdb_addr_in;
569 typedef struct sockaddr_in6 ctdb_addr_in6;
570 typedef union {
571         struct sockaddr sa;
572         ctdb_addr_in    ip;
573         ctdb_addr_in6   ip6;
574 } ctdb_sock_addr;
575
576 /*
577   struct for tcp_client control
578   this is an ipv4 only version of this structure used by samba
579   samba will later be migrated over to use the 
580   ctdb_control_tcp_addr structure instead
581  */
582 struct ctdb_control_tcp {
583         struct sockaddr_in src; // samba uses this
584         struct sockaddr_in dest;// samba uses this
585 };
586 /* new style structure */
587 struct ctdb_control_tcp_addr {
588         ctdb_sock_addr src;
589         ctdb_sock_addr dest;
590 };
591
592 int ctdb_socket_connect(struct ctdb_context *ctdb);
593
594 /*
595   get the uptime of a remote node
596  */
597 int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
598
599 struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
600
601 int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
602
603 int ctdb_ctrl_end_recovery(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
604
605 int ctdb_ctrl_getreclock(struct ctdb_context *ctdb, 
606         struct timeval timeout, uint32_t destnode, 
607         TALLOC_CTX *mem_ctx, const char **reclock);
608 int ctdb_ctrl_setreclock(struct ctdb_context *ctdb, 
609         struct timeval timeout, uint32_t destnode, 
610         const char *reclock);
611
612
613 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
614                                 struct ctdb_node_map *node_map,
615                                 TALLOC_CTX *mem_ctx,
616                                 bool include_self);
617 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
618                                 struct ctdb_node_map *node_map,
619                                 TALLOC_CTX *mem_ctx,
620                                 bool include_self);
621 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
622                                 struct ctdb_vnn_map *vnn_map,
623                                 TALLOC_CTX *mem_ctx,
624                                 bool include_self);
625 uint32_t *list_of_active_nodes_except_pnn(struct ctdb_context *ctdb,
626                                 struct ctdb_node_map *node_map,
627                                 TALLOC_CTX *mem_ctx,
628                                 uint32_t pnn);
629
630 int ctdb_read_pnn_lock(int fd, int32_t pnn);
631
632 /*
633   get capabilities of a remote node
634  */
635 int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities);
636
637 struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
638
639 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities);
640
641
642 int32_t ctdb_ctrl_transaction_active(struct ctdb_context *ctdb,
643                                      uint32_t destnode,
644                                      uint32_t db_id);
645
646 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx, 
647                                                struct ctdb_marshall_buffer *m,
648                                                uint64_t db_id,
649                                                uint32_t reqid,
650                                                TDB_DATA key,
651                                                struct ctdb_ltdb_header *header,
652                                                TDB_DATA data);
653 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
654
655 struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *ctdb_db,
656                                                        TALLOC_CTX *mem_ctx);
657 int ctdb_transaction_fetch(struct ctdb_transaction_handle *h, 
658                            TALLOC_CTX *mem_ctx, 
659                            TDB_DATA key, TDB_DATA *data);
660 int ctdb_transaction_store(struct ctdb_transaction_handle *h, 
661                            TDB_DATA key, TDB_DATA data);
662 int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
663
664 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
665
666 int switch_from_server_to_client(struct ctdb_context *ctdb);
667
668 #define MONITOR_SCRIPT_OK      0
669 #define MONITOR_SCRIPT_TIMEOUT 1
670
671 #define MAX_SCRIPT_NAME 31
672 #define MAX_SCRIPT_OUTPUT 511
673 struct ctdb_script_wire {
674         char name[MAX_SCRIPT_NAME+1];
675         struct timeval start;
676         struct timeval finished;
677         int32_t status;
678         char output[MAX_SCRIPT_OUTPUT+1];
679 };
680
681 struct ctdb_scripts_wire {
682         uint32_t num_scripts;
683         struct ctdb_script_wire scripts[1];
684 };
685
686 /* different calls to event scripts. */
687 enum ctdb_eventscript_call {
688         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
689         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
690         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
691         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
692         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
693         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
694         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
695         CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
696         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
697         CTDB_EVENT_STATUS,              /* Report service status: no args. */
698         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
699         CTDB_EVENT_RELOAD,              /* magic */
700         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
701         CTDB_EVENT_MAX
702 };
703
704 /* Mapping from enum to names. */
705 extern const char *ctdb_eventscript_call_names[];
706
707 int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb, 
708                     struct timeval timeout, uint32_t destnode, 
709                     TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
710                     struct ctdb_scripts_wire **script_status);
711
712
713 struct debug_levels {
714         int32_t level;
715         const char *description;
716 };
717 extern struct debug_levels debug_levels[];
718
719 const char *get_debug_by_level(int32_t level);
720 int32_t get_debug_by_desc(const char *desc);
721
722 int ctdb_ctrl_stop_node(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
723 int ctdb_ctrl_continue_node(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
724
725 int ctdb_ctrl_setnatgwstate(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t natgwstate);
726 int ctdb_ctrl_setlmasterrole(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t lmasterrole);
727 int ctdb_ctrl_setrecmasterrole(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmasterrole);
728
729 int ctdb_ctrl_enablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script);
730 int ctdb_ctrl_disablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script);
731
732 struct ctdb_ban_time {
733         uint32_t pnn;
734         uint32_t time;
735 };
736
737 int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_ban_time *bantime);
738 int ctdb_ctrl_get_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_ban_time **bantime);
739
740 struct ctdb_db_priority {
741         uint32_t db_id;
742         uint32_t priority;
743 };
744
745 int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio);
746 int ctdb_ctrl_get_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint32_t *priority);
747
748 #endif