LIBCTDB: add support for traverse
[sahlberg/ctdb.git] / include / ctdb.h
1 /*
2    ctdb database library
3
4    Copyright (C) Ronnie sahlberg 2010
5    Copyright (C) Rusty Russell 2010
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _CTDB_H
22 #define _CTDB_H
23 #include <sys/types.h>
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <tdb.h>
29 #include <netinet/in.h>
30 #include <ctdb_protocol.h>
31
32 /**
33  * ctdb - a library for accessing tdbs controlled by ctdbd
34  *
35  * ctdbd (clustered tdb daemon) is a daemon designed to syncronize TDB
36  * databases across a cluster.  Using this library, you can communicate with
37  * the daemon to access the databases, pass messages across the cluster, and
38  * control the daemon itself.
39  *
40  * The general API is event-driven and asynchronous: you call the
41  * *_send functions, supplying callbacks, then when the ctdbd file
42  * descriptor is usable, call ctdb_service() to perform read from it
43  * and call your callbacks, which use the *_recv functions to unpack
44  * the replies from ctdbd.
45  *
46  * There is also a synchronous wrapper for each function for trivial
47  * programs; these can be found in the section marked "Synchronous API".
48  */
49
50 /**
51  * ctdb_log_fn_t - logging function for ctdbd
52  * @log_priv: private (typesafe) arg via ctdb_connect
53  * @severity: syslog-style severity
54  * @format: printf-style format string.
55  * @ap: arguments for formatting.
56  *
57  * The severity passed to log() are as per syslog(3).  In particular,
58  * LOG_DEBUG is used for tracing, LOG_WARNING is used for unusual
59  * conditions which don't necessarily return an error through the API,
60  * LOG_ERR is used for errors such as lost communication with ctdbd or
61  * out-of-memory, LOG_ALERT is used for library usage bugs, LOG_CRIT is
62  * used for libctdb internal consistency checks.
63  *
64  * The log() function can be typesafe: the @log_priv arg to
65  * ctdb_donnect and signature of log() should match.
66  */
67 typedef void (*ctdb_log_fn_t)(void *log_priv,
68                               int severity, const char *format, va_list ap);
69
70 /**
71  * ctdb_connect - connect to ctdb using the specified domain socket.
72  * @addr: the socket address, or NULL for default
73  * @log: the logging function
74  * @log_priv: the private argument to the logging function.
75  *
76  * Returns a ctdb context if successful or NULL.  Use ctdb_disconnect() to
77  * release the returned ctdb_connection when finished.
78  *
79  * See Also:
80  *      ctdb_log_fn_t, ctdb_log_file()
81  */
82 struct ctdb_connection *ctdb_connect(const char *addr,
83                                      ctdb_log_fn_t log_fn, void *log_priv);
84
85 /**
86  * ctdb_log_file - example logging function
87  *
88  * Logs everything at priority LOG_WARNING or above to the file given (via
89  * the log_priv argument, usually stderr).
90  */
91 void ctdb_log_file(FILE *, int, const char *, va_list);
92
93 /**
94  * ctdb_log_level - level at which to call logging function
95  *
96  * This variable globally controls filtering on the logging function.
97  * It is initialized to LOG_WARNING, meaning that strange but nonfatal
98  * events, as well as errors and API misuses are reported.
99  *
100  * Set it to LOG_DEBUG to receive all messages.
101  */
102 extern int ctdb_log_level;
103
104 /**
105  * ctdb_disconnect - close down a connection to ctdbd.
106  * @ctdb: the ctdb connectio returned from ctdb_connect.
107  *
108  * The @ctdb arg will be freed by this call, and must not be used again.
109  */
110 void ctdb_disconnect(struct ctdb_connection *ctdb);
111
112 /***
113  *
114  *  Asynchronous API
115  *
116  ***/
117
118 /**
119  * ctdb_get_fd - get the filedescriptor to select/poll on
120  * @ctdb: the ctdb_connection from ctdb_connect.
121  *
122  * By using poll or select on this file descriptor, you will know when to call
123  * ctdb_service().
124  *
125  * See Also:
126  *      ctdb_which_events(), ctdb_service()
127  */
128 int ctdb_get_fd(struct ctdb_connection *ctdb);
129
130 /**
131  * ctdb_which_events - determine which events ctdb_service wants to see
132  * @ctdb: the ctdb_connection from ctdb_connect.
133  *
134  * This returns POLLIN, possibly or'd with POLLOUT if there are writes
135  * pending.  You can set this straight into poll.events.
136  *
137  * See Also:
138  *      ctdb_service()
139  */
140 int ctdb_which_events(struct ctdb_connection *ctdb);
141
142 /**
143  * ctdb_service - service any I/O and callbacks from ctdbd communication
144  * @ctdb: the ctdb_connection from ctdb_connect.
145  * @revents: which events are available.
146  *
147  * This is the core of the library: it read and writes to the ctdbd
148  * socket.  It may call callbacks registered with the various _send
149  * functions.
150  *
151  * revents is a bitset: POLLIN and/or POLLOUT may be set to indicate
152  * it is worth attempting to read/write the (nonblocking)
153  * filedescriptor respectively.
154  *
155  * Note that the synchronous functions call this internally.
156  * Returns false on catastrophic failure.
157  */
158 bool ctdb_service(struct ctdb_connection *ctdb, int revents);
159
160 /**
161  * struct ctdb_request - handle for an outstanding request
162  *
163  * This opaque structure returned from various *_send functions gives
164  * you a handle by which you can cancel a request.  You can't do
165  * anything else with it until the request is completed and it is
166  * handed to your callback function.
167  */
168 struct ctdb_request;
169
170 /**
171  * ctdb_request_free - free a completed request
172  *
173  * This frees a request: you should only call it once it has been
174  * handed to your callback.  For incomplete requests, see ctdb_cancel().
175  */
176 void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req);
177
178 /**
179  * ctdb_callback_t - callback for completed requests.
180  *
181  * This would normally unpack the request using ctdb_*_recv().  You
182  * must free the request using ctdb_request_free().
183  *
184  * Note that due to macro magic, actual your callback can be typesafe:
185  * instead of taking a void *, it can take a type which matches the
186  * actual private parameter.
187  */
188 typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
189                                 struct ctdb_request *req, void *private_data);
190
191 /**
192  * struct ctdb_db - connection to a particular open TDB
193  *
194  * This represents a particular open database: you receive it from
195  * ctdb_attachdb or ctdb_attachdb_recv to manipulate a database.
196  *
197  * You have to free the handle with ctdb_detachdb() when finished with it.
198  */
199 struct ctdb_db;
200
201 /**
202  * ctdb_attachdb_send - open a clustered TDB
203  * @ctdb: the ctdb_connection from ctdb_connect.
204  * @name: the filename of the database (no /).
205  * @persistent: whether the database is persistent across ctdbd's life
206  * @tdb_flags: the flags to pass to tdb_open.
207  * @callback: the callback when we're attached or failed (typesafe)
208  * @cbdata: the argument to callback()
209  *
210  * This function connects to a TDB controlled by ctdbd.  It can create
211  * a new TDB if it does not exist, depending on tdb_flags.  Returns
212  * the pending request, or NULL on error.
213  */
214 struct ctdb_request *
215 ctdb_attachdb_send(struct ctdb_connection *ctdb,
216                    const char *name, bool persistent, uint32_t tdb_flags,
217                    ctdb_callback_t callback, void *cbdata);
218
219 /**
220  * ctdb_attachdb_recv - read an ctdb_attach reply from ctdbd
221  * @ctdb: the ctdb_connection from ctdb_connect.
222  * @req: the completed request.
223  *
224  * This returns NULL if something went wrong, or otherwise the open database.
225  */
226 struct ctdb_db *ctdb_attachdb_recv(struct ctdb_connection *ctdb,
227                                    struct ctdb_request *req);
228
229
230 /**
231  * struct ctdb_lock - a record lock on a clustered TDB database
232  *
233  * This locks a subset of the database across the entire cluster; it
234  * is the fundamental sychronization element for ctdb.  You cannot have
235  * more than one lock at once.
236  *
237  * You MUST NOT block during holding this lock and MUST release it
238  * quickly by performing ctdb_release_lock(lock).
239  * Do NOT make any system calls that may block while holding the lock.
240  *
241  * Try to release the lock as quickly as possible.
242  */
243 struct ctdb_lock;
244
245 /**
246  * ctdb_rrl_callback_t - callback for ctdb_readrecordlock_async
247  *
248  * This is not the standard ctdb_callback_t, because there is often no
249  * request required to access a database record (ie. if it is local already).
250  * So the callback is handed the lock directly: it might be NULL if there
251  * was an error obtaining the lock.
252  *
253  * See Also:
254  *      ctdb_readrecordlock_async(), ctdb_readrecordlock()
255  */
256 typedef void (*ctdb_rrl_callback_t)(struct ctdb_db *ctdb_db,
257                                     struct ctdb_lock *lock,
258                                     TDB_DATA data,
259                                     void *private_data);
260
261 /**
262  * ctdb_readrecordlock_async - read and lock a record
263  * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
264  * @key: the key of the record to lock.
265  * @callback: the callback once the record is locked (typesafe).
266  * @cbdata: the argument to callback()
267  *
268  * This returns true on success.  Commonly, we can obtain the record
269  * immediately and so the callback will be invoked.  Otherwise a request
270  * will be queued to ctdbd for the record.
271  *
272  * If failure is immediate, false is returned.  Otherwise, the callback
273  * may receive a NULL lock arg to indicate asynchronous failure.
274  */
275 bool ctdb_readrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
276                                ctdb_rrl_callback_t callback, void *cbdata);
277
278 /**
279  * ctdb_writerecord - write a locked record in a TDB
280  * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
281  * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_recv
282  * @data: the new data to place in the record.
283  */
284 bool ctdb_writerecord(struct ctdb_db *ctdb_db,
285                       struct ctdb_lock *lock, TDB_DATA data);
286
287 /**
288  * ctdb_release_lock - release a record lock on a TDB
289  * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
290  * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_async
291  */
292 void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock);
293
294
295
296 /**
297  * ctdb_traverse_callback_t - callback for ctdb_traverse_async.
298  * return 0 - to continue traverse
299  * return 1 - to abort the traverse
300  *
301  * See Also:
302  *      ctdb_traverse_async()
303  */
304 #define TRAVERSE_STATUS_RECORD          0
305 #define TRAVERSE_STATUS_FINISHED        1
306 #define TRAVERSE_STATUS_ERROR           2
307 typedef int (*ctdb_traverse_callback_t)(struct ctdb_connection *ctdb,
308                                     struct ctdb_db *ctdb_db,
309                                     int status,
310                                     TDB_DATA key,
311                                     TDB_DATA data,
312                                     void *private_data);
313
314 /**
315  * ctdb_traverse_async - traverse a database.
316  * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
317  * @callback: the callback once the record is locked (typesafe).
318  * @cbdata: the argument to callback()
319  *
320  * This returns true on success.
321  * when successfull, the callback will be invoked for each record
322  * until the traversal is finished.
323  *
324  * status == 
325  * TRAVERSE_STATUS_RECORD         key/data contains a record.
326  * TRAVERSE_STATUS_FINISHED       traverse is finished. key/data is undefined.
327  * TRAVERSE_STATUS_ERROR          an error occured during traverse.
328  *                                key/data is undefined.
329  *
330  * If failure is immediate, false is returned.
331  */
332 bool ctdb_traverse_async(struct ctdb_db *ctdb_db,
333                          ctdb_traverse_callback_t callback, void *cbdata);
334
335 /**
336  * ctdb_message_fn_t - messaging callback for ctdb messages
337  *
338  * ctdbd provides a simple messaging API; you can register for a particular
339  * 64-bit id on which you want to send messages, and send to other ids.
340  *
341  * See Also:
342  *      ctdb_set_message_handler_send()
343  */
344 typedef void (*ctdb_message_fn_t)(struct ctdb_connection *,
345                                   uint64_t srvid, TDB_DATA data, void *);
346
347 /**
348  * ctdb_set_message_handler_send - register for messages to a srvid
349  * @ctdb: the ctdb_connection from ctdb_connect.
350  * @srvid: the 64 bit identifier for our messages.
351  * @handler: the callback when we receive such a message (typesafe)
352  * @handler_data: the argument to handler()
353  * @callback: the callback when ctdb replies to our message (typesafe)
354  * @cbdata: the argument to callback()
355  *
356  * Note: our callback will always be called before handler.
357  *
358  * See Also:
359  *      ctdb_set_message_handler_recv(), ctdb_remove_message_handler_send()
360  */
361 struct ctdb_request *
362 ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
363                               ctdb_message_fn_t handler,
364                               void *handler_data,
365                               ctdb_callback_t callback,
366                               void *cbdata);
367
368 /**
369  * ctdb_set_message_handler_recv - read a set_message_handler result
370  * @ctdb: the ctdb_connection from ctdb_connect.
371  * @req: the completed request
372  *
373  * If this returns true, the registered handler may be called from the next
374  * ctdb_service().  If this returns false, the registration failed.
375  */
376 bool ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
377                                    struct ctdb_request *handle);
378
379 /**
380  * ctdb_remove_message_handler_send - unregister for messages to a srvid
381  * @ctdb: the ctdb_connection from ctdb_connect.
382  * @srvid: the 64 bit identifier for our messages.
383  * @handler: the callback when we receive such a message (typesafe)
384  * @handler_data: the argument to handler()
385  * @callback: the callback when ctdb replies to our message (typesafe)
386  * @cbdata: the argument to callback()
387  *
388  * This undoes a successful ctdb_set_message_handler or
389  * ctdb_set_message_handler_recv.
390  */
391 struct ctdb_request *
392 ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
393                                  ctdb_message_fn_t handler, void *handler_data,
394                                  ctdb_callback_t callback, void *cbdata);
395
396 /**
397  * ctdb_remove_message_handler_recv - read a remove_message_handler result
398  * @ctdb: the ctdb_connection from ctdb_connect.
399  * @req: the completed request
400  *
401  * After this returns true, the registered handler will no longer be called.
402  * If this returns false, the de-registration failed.
403  */
404 bool ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
405                                       struct ctdb_request *req);
406
407
408 /**
409  * ctdb_send_message - send a message via ctdbd
410  * @ctdb: the ctdb_connection from ctdb_connect.
411  * @pnn: the physical node number to send to
412  * @srvid: the 64 bit identifier for this message type.
413  * @data: the data to send
414  *
415  * This allows arbitrary messages to be sent across the cluster to those
416  * listening (via ctdb_set_message_handler et al).
417  *
418  * This queues a message to be sent: you will need to call
419  * ctdb_service() to actually send the message.  There is no callback
420  * because there is no acknowledgement.
421  *
422  * See Also:
423  *      ctdb_getpnn_send(), ctdb_getpnn()
424  */
425 bool ctdb_send_message(struct ctdb_connection *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
426
427 /**
428  * ctdb_getpnn_send - read the pnn number of a node.
429  * @ctdb: the ctdb_connection from ctdb_connect.
430  * @destnode: the destination node (see below)
431  * @callback: the callback when ctdb replies to our message (typesafe)
432  * @cbdata: the argument to callback()
433  *
434  * There are several special values for destnode, detailed in
435  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
436  * local ctdbd.
437  */
438 struct ctdb_request *
439 ctdb_getpnn_send(struct ctdb_connection *ctdb,
440                  uint32_t destnode,
441                  ctdb_callback_t callback,
442                  void *cbdata);
443 /**
444  * ctdb_getpnn_recv - read an ctdb_getpnn reply from ctdbd
445  * @ctdb: the ctdb_connection from ctdb_connect.
446  * @req: the completed request.
447  * @pnn: a pointer to the pnn to fill in
448  *
449  * This returns false if something went wrong, or otherwise fills in pnn.
450  */
451 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
452                       struct ctdb_request *req, uint32_t *pnn);
453
454
455 /**
456  * ctdb_getnodemap_send - read the nodemap number from a node.
457  * @ctdb: the ctdb_connection from ctdb_connect.
458  * @destnode: the destination node (see below)
459  * @callback: the callback when ctdb replies to our message (typesafe)
460  * @cbdata: the argument to callback()
461  *
462  * There are several special values for destnode, detailed in
463  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
464  * local ctdbd.
465  */
466 struct ctdb_request *
467 ctdb_getnodemap_send(struct ctdb_connection *ctdb,
468                  uint32_t destnode,
469                  ctdb_callback_t callback,
470                  void *cbdata);
471 /**
472  * ctdb_getnodemap_recv - read an ctdb_getnodemap reply from ctdbd
473  * @ctdb: the ctdb_connection from ctdb_connect.
474  * @req: the completed request.
475  * @nodemap: a pointer to the returned nodemap structure
476  *
477  * This returns false if something went wrong.
478  * If the command failed, it guarantees to set nodemap to NULL.
479  * A non-NULL value for nodemap means the command was successful.
480  *
481  * A non-NULL value of the nodemap must be release released/freed
482  * by ctdb_free_nodemap().
483  */
484 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
485                       struct ctdb_request *req, struct ctdb_node_map **nodemap);
486
487 /**
488  * ctdb_getpublicips_send - read the public ip list from a node.
489  * @ctdb: the ctdb_connection from ctdb_connect.
490  * @destnode: the destination node (see below)
491  * @callback: the callback when ctdb replies to our message (typesafe)
492  * @cbdata: the argument to callback()
493  *
494  * This control returns the list of public ips known to the local node.
495  * Deamons only know about those ips that are listed in the local
496  * public addresses file, which means the returned list of ips may
497  * be only a subset of all ips across the entire cluster.
498  *
499  * There are several special values for destnode, detailed in
500  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
501  * local ctdbd.
502  */
503 struct ctdb_request *
504 ctdb_getpublicips_send(struct ctdb_connection *ctdb,
505                  uint32_t destnode,
506                  ctdb_callback_t callback,
507                  void *cbdata);
508 /**
509  * ctdb_getpublicips_recv - read the public ip list from a node
510  * @ctdb: the ctdb_connection from ctdb_connect.
511  * @req: the completed request.
512  * @ips: a pointer to the returned public ip list
513  *
514  * This returns false if something went wrong.
515  * If the command failed, it guarantees to set ips to NULL.
516  * A non-NULL value for nodemap means the command was successful.
517  *
518  * A non-NULL value of the nodemap must be release released/freed
519  * by ctdb_free_publicips().
520  */
521 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
522                       struct ctdb_request *req, struct ctdb_all_public_ips **ips);
523
524
525 /**
526  * ctdb_getrecmaster_send - read the recovery master of a node
527  * @ctdb: the ctdb_connection from ctdb_connect.
528  * @destnode: the destination node (see below)
529  * @callback: the callback when ctdb replies to our message (typesafe)
530  * @cbdata: the argument to callback()
531  *
532  * There are several special values for destnode, detailed in
533  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
534  * local ctdbd.
535  */
536 struct ctdb_request *
537 ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
538                         uint32_t destnode,
539                         ctdb_callback_t callback, void *cbdata);
540
541 /**
542  * ctdb_getrecmaster_recv - read an ctdb_getrecmaster reply from ctdbd
543  * @ctdb: the ctdb_connection from ctdb_connect.
544  * @req: the completed request.
545  * @recmaster: a pointer to the recmaster to fill in
546  *
547  * This returns false if something went wrong, or otherwise fills in
548  * recmaster.
549  */
550 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
551                             struct ctdb_request *handle,
552                             uint32_t *recmaster);
553
554 /**
555  * ctdb_cancel - cancel an uncompleted request
556  * @ctdb: the ctdb_connection from ctdb_connect.
557  * @req: the uncompleted request.
558  *
559  * This cancels a request, returning true.  You may not cancel a
560  * request which has already been completed (ie. once its callback has
561  * been called); you should simply use ctdb_request_free() in that case.
562  */
563 void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req);
564
565 /***
566  *
567  *  Synchronous API
568  *
569  ***/
570
571 /**
572  * ctdb_attachdb - open a clustered TDB (synchronous)
573  * @ctdb: the ctdb_connection from ctdb_connect.
574  * @name: the filename of the database (no /).
575  * @persistent: whether the database is persistent across ctdbd's life
576  * @tdb_flags: the flags to pass to tdb_open.
577  *
578  * Do a ctdb_attachdb_send and wait for it to complete.
579  * Returns NULL on failure.
580  */
581 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
582                               const char *name, bool persistent,
583                               uint32_t tdb_flags);
584
585 /**
586  * ctdb_detachdb - close a clustered TDB.
587  * @ctdb: the ctdb_connection from ctdb_connect.
588  * @db: the database from ctdb_attachdb/ctdb_attachdb_send
589  *
590  * Closes a clustered tdb.
591  */
592 void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db);
593
594 /**
595  * ctdb_readrecordlock - read and lock a record (synchronous)
596  * @ctdb: the ctdb_connection from ctdb_connect.
597  * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
598  * @key: the key of the record to lock.
599  * @req: a pointer to the request, if one is needed.
600  *
601  * Do a ctdb_readrecordlock_send and wait for it to complete.
602  * Returns NULL on failure.
603  */
604 struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
605                                       struct ctdb_db *ctdb_db, TDB_DATA key,
606                                       TDB_DATA *data);
607
608
609 /**
610  * ctdb_set_message_handler - register for messages to a srvid (synchronous)
611  * @ctdb: the ctdb_connection from ctdb_connect.
612  * @srvid: the 64 bit identifier for our messages.
613  * @handler: the callback when we receive such a message (typesafe)
614  * @cbdata: the argument to handler()
615  *
616  * If this returns true, the message handler can be called from any
617  * ctdb_service() (which is also called indirectly by other
618  * synchronous functions).  If this returns false, the registration
619  * failed.
620  */
621 bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
622                               ctdb_message_fn_t handler, void *cbdata);
623
624
625 /**
626  * ctdb_remove_message_handler - deregister for messages (synchronous)
627  * @ctdb: the ctdb_connection from ctdb_connect.
628  * @srvid: the 64 bit identifier for our messages.
629  * @handler: the callback when we receive such a message (typesafe)
630  * @handler_data: the argument to handler()
631  *
632  * If this returns true, the message handler will no longer be called.
633  * If this returns false, the deregistration failed.
634  */
635 bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
636                                  ctdb_message_fn_t handler, void *handler_data);
637
638 /**
639  * ctdb_getpnn - read the pnn number of a node (synchronous)
640  * @ctdb: the ctdb_connection from ctdb_connect.
641  * @destnode: the destination node (see below)
642  * @pnn: a pointer to the pnn to fill in
643  *
644  * There are several special values for destnode, detailed in
645  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
646  * local ctdbd.
647  *
648  * Returns true and fills in *pnn on success.
649  */
650 bool ctdb_getpnn(struct ctdb_connection *ctdb,
651                  uint32_t destnode,
652                  uint32_t *pnn);
653
654 /**
655  * ctdb_getrecmaster - read the recovery master of a node (synchronous)
656  * @ctdb: the ctdb_connection from ctdb_connect.
657  * @destnode: the destination node (see below)
658  * @recmaster: a pointer to the recmaster to fill in
659  *
660  * There are several special values for destnode, detailed in
661  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
662  * local ctdbd.
663  *
664  * Returns true and fills in *recmaster on success.
665  */
666 bool ctdb_getrecmaster(struct ctdb_connection *ctdb,
667                        uint32_t destnode,
668                        uint32_t *recmaster);
669
670
671 /**
672  * ctdb_getnodemap - read the nodemap from a node (synchronous)
673  * @ctdb: the ctdb_connection from ctdb_connect.
674  * @destnode: the destination node (see below)
675  * @nodemap: a pointer to the nodemap to fill in
676  *
677  * There are several special values for destnode, detailed in
678  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
679  * local ctdbd.
680  *
681  * Returns true and fills in *nodemap on success.
682  * A non-NULL nodemap must be freed by calling ctdb_free_nodemap.
683  */
684 bool ctdb_getnodemap(struct ctdb_connection *ctdb,
685                      uint32_t destnode, struct ctdb_node_map **nodemap);
686
687 /*
688  * This function is used to release/free the nodemap structure returned
689  * by ctdb_getnodemap() and ctdb_getnodemap_recv()
690  */
691 void ctdb_free_nodemap(struct ctdb_node_map *nodemap);
692
693
694 /**
695  * ctdb_getpublicips - read the public ip list from a node.
696  * @ctdb: the ctdb_connection from ctdb_connect.
697  * @destnode: the destination node (see below)
698  * @ips: a pointer to the returned public ip list
699  *
700  * This control returns the list of public ips known to the local node.
701  * Deamons only know about those ips that are listed in the local
702  * public addresses file, which means the returned list of ips may
703  * be only a subset of all ips across the entire cluster.
704  *
705  * There are several special values for destnode, detailed in
706  * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
707  * local ctdbd.
708  *
709  * This returns false if something went wrong.
710  * If the command failed, it guarantees to set ips to NULL.
711  * A non-NULL value for nodemap means the command was successful.
712  *
713  * A non-NULL value of the nodemap must be release released/freed
714  * by ctdb_free_publicips().
715  */
716 bool ctdb_getpublicips(struct ctdb_connection *ctdb,
717                      uint32_t destnode, struct ctdb_all_public_ips **ips);
718
719 /*
720  * This function is used to release/free the public ip structure returned
721  * by ctdb_getpublicips() and ctdb_getpublicips_recv()
722  */
723 void ctdb_free_publicips(struct ctdb_all_public_ips *ips);
724
725
726 /* These ugly macro wrappers make the callbacks typesafe. */
727 #include <ctdb_typesafe_cb.h>
728 #define ctdb_sendcb(cb, cbdata)                                         \
729          typesafe_cb_preargs(void, (cb), (cbdata),                      \
730                              struct ctdb_connection *, struct ctdb_request *)
731
732 #define ctdb_msgcb(cb, cbdata)                                          \
733         typesafe_cb_preargs(void, (cb), (cbdata),                       \
734                             struct ctdb_connection *, uint64_t, TDB_DATA)
735
736 #define ctdb_connect(addr, log, logpriv)                                \
737         ctdb_connect((addr),                                            \
738                      typesafe_cb_postargs(void, (log), (logpriv),       \
739                                           int, const char *, va_list),  \
740                      (logpriv))
741
742 #define ctdb_set_message_handler(ctdb, srvid, handler, hdata)           \
743         ctdb_set_message_handler((ctdb), (srvid),                       \
744                                  ctdb_msgcb((handler), (hdata)), (hdata))
745
746 #define ctdb_remove_message_handler(ctdb, srvid, handler, hdata)        \
747         ctdb_remove_message_handler((ctdb), (srvid),                    \
748                                     ctdb_msgcb((handler), (hdata)), (hdata))
749
750 #define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
751         ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags),   \
752                            ctdb_sendcb((cb), (cbdata)), (cbdata))
753
754 #define ctdb_readrecordlock_async(_ctdb_db, key, cb, cbdata)            \
755         ctdb_readrecordlock_async((_ctdb_db), (key),                    \
756                 typesafe_cb_preargs(void, (cb), (cbdata),               \
757                                     struct ctdb_db *, struct ctdb_lock *, \
758                                     TDB_DATA), (cbdata))
759
760 #define ctdb_set_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
761         ctdb_set_message_handler_send((ctdb), (srvid),                  \
762                                       ctdb_msgcb((handler), (hdata)), (hdata), \
763                                       ctdb_sendcb((cb), (cbdata)), (cbdata))
764
765 #define ctdb_remove_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
766         ctdb_remove_message_handler_send((ctdb), (srvid),               \
767               ctdb_msgcb((handler), (hdata)), (hdata),                  \
768               ctdb_sendcb((cb), (cbdata)), (cbdata))
769
770 #define ctdb_getpnn_send(ctdb, destnode, cb, cbdata)                    \
771         ctdb_getpnn_send((ctdb), (destnode),                            \
772                          ctdb_sendcb((cb), (cbdata)), (cbdata))
773
774 #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata)              \
775         ctdb_getrecmaster_send((ctdb), (destnode),                      \
776                                ctdb_sendcb((cb), (cbdata)), (cbdata))
777
778 #define ctdb_getnodemap_send(ctdb, destnode, cb, cbdata)                \
779         ctdb_getnodemap_send((ctdb), (destnode),                        \
780                          ctdb_sendcb((cb), (cbdata)), (cbdata))
781
782 #define ctdb_getpublicips_send(ctdb, destnode, cb, cbdata)              \
783         ctdb_getpublicips_send((ctdb), (destnode),                      \
784                          ctdb_sendcb((cb), (cbdata)), (cbdata))
785
786 #endif