4 Copyright (C) Ronnie sahlberg 2010
5 Copyright (C) Rusty Russell 2010
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.
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.
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/>.
23 #include <sys/types.h>
29 #include <netinet/in.h>
30 #include <ctdb_protocol.h>
33 * ctdb - a library for accessing tdbs controlled by ctdbd
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.
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.
46 * There is also a synchronous wrapper for each function for trivial
47 * programs; these can be found in the section marked "Synchronous API".
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.
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.
64 * The log() function can be typesafe: the @log_priv arg to
65 * ctdb_donnect and signature of log() should match.
67 typedef void (*ctdb_log_fn_t)(void *log_priv,
68 int severity, const char *format, va_list ap);
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.
76 * Returns a ctdb context if successful or NULL. Use ctdb_disconnect() to
77 * release the returned ctdb_connection when finished.
80 * ctdb_log_fn_t, ctdb_log_file()
82 struct ctdb_connection *ctdb_connect(const char *addr,
83 ctdb_log_fn_t log_fn, void *log_priv);
86 * ctdb_log_file - example logging function
88 * Logs everything at priority LOG_WARNING or above to the file given (via
89 * the log_priv argument, usually stderr).
91 void ctdb_log_file(FILE *, int, const char *, va_list);
94 * ctdb_log_level - level at which to call logging function
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.
100 * Set it to LOG_DEBUG to receive all messages.
102 extern int ctdb_log_level;
105 * ctdb_disconnect - close down a connection to ctdbd.
106 * @ctdb: the ctdb connectio returned from ctdb_connect.
108 * The @ctdb arg will be freed by this call, and must not be used again.
110 void ctdb_disconnect(struct ctdb_connection *ctdb);
119 * ctdb_get_fd - get the filedescriptor to select/poll on
120 * @ctdb: the ctdb_connection from ctdb_connect.
122 * By using poll or select on this file descriptor, you will know when to call
126 * ctdb_which_events(), ctdb_service()
128 int ctdb_get_fd(struct ctdb_connection *ctdb);
131 * ctdb_which_events - determine which events ctdb_service wants to see
132 * @ctdb: the ctdb_connection from ctdb_connect.
134 * This returns POLLIN, possibly or'd with POLLOUT if there are writes
135 * pending. You can set this straight into poll.events.
140 int ctdb_which_events(struct ctdb_connection *ctdb);
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.
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
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.
155 * Note that the synchronous functions call this internally.
156 * Returns false on catastrophic failure.
158 bool ctdb_service(struct ctdb_connection *ctdb, int revents);
161 * struct ctdb_request - handle for an outstanding request
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.
171 * ctdb_request_free - free a completed request
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().
176 void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req);
179 * ctdb_callback_t - callback for completed requests.
181 * This would normally unpack the request using ctdb_*_recv(). You
182 * must free the request using ctdb_request_free().
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.
188 typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
189 struct ctdb_request *req, void *private_data);
192 * struct ctdb_db - connection to a particular open TDB
194 * This represents a particular open database: you receive it from
195 * ctdb_attachdb or ctdb_attachdb_recv to manipulate a database.
197 * You have to free the handle with ctdb_detachdb() when finished with it.
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()
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.
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);
220 * ctdb_attachdb_recv - read an ctdb_attach reply from ctdbd
221 * @ctdb: the ctdb_connection from ctdb_connect.
222 * @req: the completed request.
224 * This returns NULL if something went wrong, or otherwise the open database.
226 struct ctdb_db *ctdb_attachdb_recv(struct ctdb_connection *ctdb,
227 struct ctdb_request *req);
231 * struct ctdb_lock - a record lock on a clustered TDB database
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.
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.
241 * Try to release the lock as quickly as possible.
246 * ctdb_rrl_callback_t - callback for ctdb_readrecordlock_async
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.
254 * ctdb_readrecordlock_async(), ctdb_readrecordlock()
256 typedef void (*ctdb_rrl_callback_t)(struct ctdb_db *ctdb_db,
257 struct ctdb_lock *lock,
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()
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.
272 * If failure is immediate, false is returned. Otherwise, the callback
273 * may receive a NULL lock arg to indicate asynchronous failure.
275 bool ctdb_readrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
276 ctdb_rrl_callback_t callback, void *cbdata);
279 * ctdb_readonlyrecordlock_async - read and lock a record for read-only access
280 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
281 * @key: the key of the record to lock.
282 * @callback: the callback once the record is locked (typesafe).
283 * @cbdata: the argument to callback()
285 * This returns true on success. Commonly, we can obtain the record
286 * immediately and so the callback will be invoked. Otherwise a request
287 * will be queued to ctdbd for the record.
289 * If failure is immediate, false is returned. Otherwise, the callback
290 * may receive a NULL lock arg to indicate asynchronous failure.
292 bool ctdb_readonlyrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
293 ctdb_rrl_callback_t callback, void *cbdata);
297 * ctdb_writerecord - write a locked record in a TDB
298 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
299 * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_recv
300 * @data: the new data to place in the record.
302 bool ctdb_writerecord(struct ctdb_db *ctdb_db,
303 struct ctdb_lock *lock, TDB_DATA data);
306 * ctdb_release_lock - release a record lock on a TDB
307 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
308 * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_async
310 void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock);
315 * ctdb_traverse_callback_t - callback for ctdb_traverse_async.
316 * return 0 - to continue traverse
317 * return 1 - to abort the traverse
320 * ctdb_traverse_async()
322 #define TRAVERSE_STATUS_RECORD 0
323 #define TRAVERSE_STATUS_FINISHED 1
324 #define TRAVERSE_STATUS_ERROR 2
325 typedef int (*ctdb_traverse_callback_t)(struct ctdb_connection *ctdb,
326 struct ctdb_db *ctdb_db,
333 * ctdb_traverse_async - traverse a database.
334 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
335 * @callback: the callback once the record is locked (typesafe).
336 * @cbdata: the argument to callback()
338 * This returns true on success.
339 * when successfull, the callback will be invoked for each record
340 * until the traversal is finished.
343 * TRAVERSE_STATUS_RECORD key/data contains a record.
344 * TRAVERSE_STATUS_FINISHED traverse is finished. key/data is undefined.
345 * TRAVERSE_STATUS_ERROR an error occured during traverse.
346 * key/data is undefined.
348 * If failure is immediate, false is returned.
350 bool ctdb_traverse_async(struct ctdb_db *ctdb_db,
351 ctdb_traverse_callback_t callback, void *cbdata);
354 * ctdb_message_fn_t - messaging callback for ctdb messages
356 * ctdbd provides a simple messaging API; you can register for a particular
357 * 64-bit id on which you want to send messages, and send to other ids.
360 * ctdb_set_message_handler_send()
362 typedef void (*ctdb_message_fn_t)(struct ctdb_connection *,
363 uint64_t srvid, TDB_DATA data, void *);
366 * ctdb_set_message_handler_send - register for messages to a srvid
367 * @ctdb: the ctdb_connection from ctdb_connect.
368 * @srvid: the 64 bit identifier for our messages.
369 * @handler: the callback when we receive such a message (typesafe)
370 * @handler_data: the argument to handler()
371 * @callback: the callback when ctdb replies to our message (typesafe)
372 * @cbdata: the argument to callback()
374 * Note: our callback will always be called before handler.
377 * ctdb_set_message_handler_recv(), ctdb_remove_message_handler_send()
379 struct ctdb_request *
380 ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
381 ctdb_message_fn_t handler,
383 ctdb_callback_t callback,
387 * ctdb_set_message_handler_recv - read a set_message_handler result
388 * @ctdb: the ctdb_connection from ctdb_connect.
389 * @req: the completed request
391 * If this returns true, the registered handler may be called from the next
392 * ctdb_service(). If this returns false, the registration failed.
394 bool ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
395 struct ctdb_request *handle);
398 * ctdb_remove_message_handler_send - unregister for messages to a srvid
399 * @ctdb: the ctdb_connection from ctdb_connect.
400 * @srvid: the 64 bit identifier for our messages.
401 * @handler: the callback when we receive such a message (typesafe)
402 * @handler_data: the argument to handler()
403 * @callback: the callback when ctdb replies to our message (typesafe)
404 * @cbdata: the argument to callback()
406 * This undoes a successful ctdb_set_message_handler or
407 * ctdb_set_message_handler_recv.
409 struct ctdb_request *
410 ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
411 ctdb_message_fn_t handler, void *handler_data,
412 ctdb_callback_t callback, void *cbdata);
415 * ctdb_remove_message_handler_recv - read a remove_message_handler result
416 * @ctdb: the ctdb_connection from ctdb_connect.
417 * @req: the completed request
419 * After this returns true, the registered handler will no longer be called.
420 * If this returns false, the de-registration failed.
422 bool ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
423 struct ctdb_request *req);
427 * ctdb_send_message - send a message via ctdbd
428 * @ctdb: the ctdb_connection from ctdb_connect.
429 * @pnn: the physical node number to send to
430 * @srvid: the 64 bit identifier for this message type.
431 * @data: the data to send
433 * This allows arbitrary messages to be sent across the cluster to those
434 * listening (via ctdb_set_message_handler et al).
436 * This queues a message to be sent: you will need to call
437 * ctdb_service() to actually send the message. There is no callback
438 * because there is no acknowledgement.
441 * ctdb_getpnn_send(), ctdb_getpnn()
443 bool ctdb_send_message(struct ctdb_connection *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
446 * ctdb_getpnn_send - read the pnn number of a node.
447 * @ctdb: the ctdb_connection from ctdb_connect.
448 * @destnode: the destination node (see below)
449 * @callback: the callback when ctdb replies to our message (typesafe)
450 * @cbdata: the argument to callback()
452 * There are several special values for destnode, detailed in
453 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
456 struct ctdb_request *
457 ctdb_getpnn_send(struct ctdb_connection *ctdb,
459 ctdb_callback_t callback,
462 * ctdb_getpnn_recv - read an ctdb_getpnn reply from ctdbd
463 * @ctdb: the ctdb_connection from ctdb_connect.
464 * @req: the completed request.
465 * @pnn: a pointer to the pnn to fill in
467 * This returns false if something went wrong, or otherwise fills in pnn.
469 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
470 struct ctdb_request *req, uint32_t *pnn);
474 * ctdb_getdbseqnum_send - read the sequence number off a db
475 * @ctdb: the ctdb_connection from ctdb_connect.
476 * @destnode: the destination node (see below)
478 * @callback: the callback when ctdb replies to our message (typesafe)
479 * @cbdata: the argument to callback()
481 * There are several special values for destnode, detailed in
482 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
485 struct ctdb_request *
486 ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
489 ctdb_callback_t callback,
492 * ctdb_getdbseqnum_recv - read the sequence number off a database
493 * @ctdb: the ctdb_connection from ctdb_connect.
494 * @req: the completed request.
495 * @seqnum: a pointer to the seqnum to fill in
497 * This returns false if something went wrong, or otherwise fills in pnn.
499 bool ctdb_getdbseqnum_recv(struct ctdb_connection *ctdb,
500 struct ctdb_request *req, uint64_t *seqnum);
503 * ctdb_getnodemap_send - read the nodemap number from a node.
504 * @ctdb: the ctdb_connection from ctdb_connect.
505 * @destnode: the destination node (see below)
506 * @callback: the callback when ctdb replies to our message (typesafe)
507 * @cbdata: the argument to callback()
509 * There are several special values for destnode, detailed in
510 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
513 struct ctdb_request *
514 ctdb_getnodemap_send(struct ctdb_connection *ctdb,
516 ctdb_callback_t callback,
519 * ctdb_getnodemap_recv - read an ctdb_getnodemap reply from ctdbd
520 * @ctdb: the ctdb_connection from ctdb_connect.
521 * @req: the completed request.
522 * @nodemap: a pointer to the returned nodemap structure
524 * This returns false if something went wrong.
525 * If the command failed, it guarantees to set nodemap to NULL.
526 * A non-NULL value for nodemap means the command was successful.
528 * A non-NULL value of the nodemap must be release released/freed
529 * by ctdb_free_nodemap().
531 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
532 struct ctdb_request *req, struct ctdb_node_map **nodemap);
535 * ctdb_getpublicips_send - read the public ip list from a node.
536 * @ctdb: the ctdb_connection from ctdb_connect.
537 * @destnode: the destination node (see below)
538 * @callback: the callback when ctdb replies to our message (typesafe)
539 * @cbdata: the argument to callback()
541 * This control returns the list of public ips known to the local node.
542 * Deamons only know about those ips that are listed in the local
543 * public addresses file, which means the returned list of ips may
544 * be only a subset of all ips across the entire cluster.
546 * There are several special values for destnode, detailed in
547 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
550 struct ctdb_request *
551 ctdb_getpublicips_send(struct ctdb_connection *ctdb,
553 ctdb_callback_t callback,
556 * ctdb_getpublicips_recv - read the public ip list from a node
557 * @ctdb: the ctdb_connection from ctdb_connect.
558 * @req: the completed request.
559 * @ips: a pointer to the returned public ip list
561 * This returns false if something went wrong.
562 * If the command failed, it guarantees to set ips to NULL.
563 * A non-NULL value for nodemap means the command was successful.
565 * A non-NULL value of the nodemap must be release released/freed
566 * by ctdb_free_publicips().
568 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
569 struct ctdb_request *req, struct ctdb_all_public_ips **ips);
573 * ctdb_getrecmaster_send - read the recovery master of a node
574 * @ctdb: the ctdb_connection from ctdb_connect.
575 * @destnode: the destination node (see below)
576 * @callback: the callback when ctdb replies to our message (typesafe)
577 * @cbdata: the argument to callback()
579 * There are several special values for destnode, detailed in
580 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
583 struct ctdb_request *
584 ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
586 ctdb_callback_t callback, void *cbdata);
589 * ctdb_getrecmaster_recv - read an ctdb_getrecmaster reply from ctdbd
590 * @ctdb: the ctdb_connection from ctdb_connect.
591 * @req: the completed request.
592 * @recmaster: a pointer to the recmaster to fill in
594 * This returns false if something went wrong, or otherwise fills in
597 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
598 struct ctdb_request *handle,
599 uint32_t *recmaster);
602 * ctdb_cancel - cancel an uncompleted request
603 * @ctdb: the ctdb_connection from ctdb_connect.
604 * @req: the uncompleted request.
606 * This cancels a request, returning true. You may not cancel a
607 * request which has already been completed (ie. once its callback has
608 * been called); you should simply use ctdb_request_free() in that case.
610 void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req);
619 * ctdb_attachdb - open a clustered TDB (synchronous)
620 * @ctdb: the ctdb_connection from ctdb_connect.
621 * @name: the filename of the database (no /).
622 * @persistent: whether the database is persistent across ctdbd's life
623 * @tdb_flags: the flags to pass to tdb_open.
625 * Do a ctdb_attachdb_send and wait for it to complete.
626 * Returns NULL on failure.
628 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
629 const char *name, bool persistent,
633 * ctdb_detachdb - close a clustered TDB.
634 * @ctdb: the ctdb_connection from ctdb_connect.
635 * @db: the database from ctdb_attachdb/ctdb_attachdb_send
637 * Closes a clustered tdb.
639 void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db);
642 * ctdb_readrecordlock - read and lock a record (synchronous)
643 * @ctdb: the ctdb_connection from ctdb_connect.
644 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
645 * @key: the key of the record to lock.
646 * @req: a pointer to the request, if one is needed.
648 * Do a ctdb_readrecordlock_send and wait for it to complete.
649 * Returns NULL on failure.
651 struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
652 struct ctdb_db *ctdb_db, TDB_DATA key,
657 * ctdb_set_message_handler - register for messages to a srvid (synchronous)
658 * @ctdb: the ctdb_connection from ctdb_connect.
659 * @srvid: the 64 bit identifier for our messages.
660 * @handler: the callback when we receive such a message (typesafe)
661 * @cbdata: the argument to handler()
663 * If this returns true, the message handler can be called from any
664 * ctdb_service() (which is also called indirectly by other
665 * synchronous functions). If this returns false, the registration
668 bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
669 ctdb_message_fn_t handler, void *cbdata);
673 * ctdb_remove_message_handler - deregister for messages (synchronous)
674 * @ctdb: the ctdb_connection from ctdb_connect.
675 * @srvid: the 64 bit identifier for our messages.
676 * @handler: the callback when we receive such a message (typesafe)
677 * @handler_data: the argument to handler()
679 * If this returns true, the message handler will no longer be called.
680 * If this returns false, the deregistration failed.
682 bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
683 ctdb_message_fn_t handler, void *handler_data);
686 * ctdb_getpnn - read the pnn number of a node (synchronous)
687 * @ctdb: the ctdb_connection from ctdb_connect.
688 * @destnode: the destination node (see below)
689 * @pnn: a pointer to the pnn to fill in
691 * There are several special values for destnode, detailed in
692 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
695 * Returns true and fills in *pnn on success.
697 bool ctdb_getpnn(struct ctdb_connection *ctdb,
702 * ctdb_getdbseqnum - read the seqnum of a database
703 * @ctdb: the ctdb_connection from ctdb_connect.
704 * @destnode: the destination node (see below)
706 * @seqnum: sequence number for the database
708 * There are several special values for destnode, detailed in
709 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
712 * Returns true and fills in *pnn on success.
715 ctdb_getdbseqnum(struct ctdb_connection *ctdb,
721 * ctdb_getrecmaster - read the recovery master of a node (synchronous)
722 * @ctdb: the ctdb_connection from ctdb_connect.
723 * @destnode: the destination node (see below)
724 * @recmaster: a pointer to the recmaster to fill in
726 * There are several special values for destnode, detailed in
727 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
730 * Returns true and fills in *recmaster on success.
732 bool ctdb_getrecmaster(struct ctdb_connection *ctdb,
734 uint32_t *recmaster);
738 * ctdb_getnodemap - read the nodemap from a node (synchronous)
739 * @ctdb: the ctdb_connection from ctdb_connect.
740 * @destnode: the destination node (see below)
741 * @nodemap: a pointer to the nodemap to fill in
743 * There are several special values for destnode, detailed in
744 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
747 * Returns true and fills in *nodemap on success.
748 * A non-NULL nodemap must be freed by calling ctdb_free_nodemap.
750 bool ctdb_getnodemap(struct ctdb_connection *ctdb,
751 uint32_t destnode, struct ctdb_node_map **nodemap);
754 * This function is used to release/free the nodemap structure returned
755 * by ctdb_getnodemap() and ctdb_getnodemap_recv()
757 void ctdb_free_nodemap(struct ctdb_node_map *nodemap);
761 * ctdb_getpublicips - read the public ip list from a node.
762 * @ctdb: the ctdb_connection from ctdb_connect.
763 * @destnode: the destination node (see below)
764 * @ips: a pointer to the returned public ip list
766 * This control returns the list of public ips known to the local node.
767 * Deamons only know about those ips that are listed in the local
768 * public addresses file, which means the returned list of ips may
769 * be only a subset of all ips across the entire cluster.
771 * There are several special values for destnode, detailed in
772 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
775 * This returns false if something went wrong.
776 * If the command failed, it guarantees to set ips to NULL.
777 * A non-NULL value for nodemap means the command was successful.
779 * A non-NULL value of the nodemap must be release released/freed
780 * by ctdb_free_publicips().
782 bool ctdb_getpublicips(struct ctdb_connection *ctdb,
783 uint32_t destnode, struct ctdb_all_public_ips **ips);
786 * This function is used to release/free the public ip structure returned
787 * by ctdb_getpublicips() and ctdb_getpublicips_recv()
789 void ctdb_free_publicips(struct ctdb_all_public_ips *ips);
792 /* These ugly macro wrappers make the callbacks typesafe. */
793 #include <ctdb_typesafe_cb.h>
794 #define ctdb_sendcb(cb, cbdata) \
795 typesafe_cb_preargs(void, (cb), (cbdata), \
796 struct ctdb_connection *, struct ctdb_request *)
798 #define ctdb_msgcb(cb, cbdata) \
799 typesafe_cb_preargs(void, (cb), (cbdata), \
800 struct ctdb_connection *, uint64_t, TDB_DATA)
802 #define ctdb_connect(addr, log, logpriv) \
803 ctdb_connect((addr), \
804 typesafe_cb_postargs(void, (log), (logpriv), \
805 int, const char *, va_list), \
808 #define ctdb_set_message_handler(ctdb, srvid, handler, hdata) \
809 ctdb_set_message_handler((ctdb), (srvid), \
810 ctdb_msgcb((handler), (hdata)), (hdata))
812 #define ctdb_remove_message_handler(ctdb, srvid, handler, hdata) \
813 ctdb_remove_message_handler((ctdb), (srvid), \
814 ctdb_msgcb((handler), (hdata)), (hdata))
816 #define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
817 ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags), \
818 ctdb_sendcb((cb), (cbdata)), (cbdata))
820 #define ctdb_readrecordlock_async(_ctdb_db, key, cb, cbdata) \
821 ctdb_readrecordlock_async((_ctdb_db), (key), \
822 typesafe_cb_preargs(void, (cb), (cbdata), \
823 struct ctdb_db *, struct ctdb_lock *, \
826 #define ctdb_set_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
827 ctdb_set_message_handler_send((ctdb), (srvid), \
828 ctdb_msgcb((handler), (hdata)), (hdata), \
829 ctdb_sendcb((cb), (cbdata)), (cbdata))
831 #define ctdb_remove_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
832 ctdb_remove_message_handler_send((ctdb), (srvid), \
833 ctdb_msgcb((handler), (hdata)), (hdata), \
834 ctdb_sendcb((cb), (cbdata)), (cbdata))
836 #define ctdb_getpnn_send(ctdb, destnode, cb, cbdata) \
837 ctdb_getpnn_send((ctdb), (destnode), \
838 ctdb_sendcb((cb), (cbdata)), (cbdata))
840 #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata) \
841 ctdb_getrecmaster_send((ctdb), (destnode), \
842 ctdb_sendcb((cb), (cbdata)), (cbdata))
844 #define ctdb_getnodemap_send(ctdb, destnode, cb, cbdata) \
845 ctdb_getnodemap_send((ctdb), (destnode), \
846 ctdb_sendcb((cb), (cbdata)), (cbdata))
848 #define ctdb_getpublicips_send(ctdb, destnode, cb, cbdata) \
849 ctdb_getpublicips_send((ctdb), (destnode), \
850 ctdb_sendcb((cb), (cbdata)), (cbdata))
852 #define ctdb_getdbseqnum_send(ctdb, destnode, dbid, cb, cbdata) \
853 ctdb_getdbseqnum_send((ctdb), (destnode), (dbid), \
854 ctdb_sendcb((cb), (cbdata)), (cbdata))