s3: lib: ntlmssp: If NTLMSSP_NEGOTIATE_TARGET_INFO isn't set, cope with servers that...
[Samba.git] / ctdb / include / ctdb.h
blob93224cbdaa63277e95f029e42d91816f28e0baec
1 /*
2 ctdb database library
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/>.
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>
32 /**
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".
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.
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);
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.
76 * Returns a ctdb context if successful or NULL. Use ctdb_disconnect() to
77 * release the returned ctdb_connection when finished.
79 * See Also:
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);
85 /**
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);
93 /**
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);
112 /***
114 * Asynchronous API
116 ***/
119 * ctdb_num_active - get the number of active commands
120 * @ctdb: the ctdb_connection from ctdb_connect.
122 * This command can be used to find the number of active commands we have
123 * issued. An active command is a command we have queued, or sent
124 * to the ctdb daemon but which we have not yet received a reply to.
126 * See Also:
127 * ctdb_num_in_flight(), ctdb_num_out_queue()
129 int ctdb_num_active(struct ctdb_connection *ctdb);
132 * ctdb_num_in_flight - get the number of commands in flight.
133 * @ctdb: the ctdb_connection from ctdb_connect.
135 * This command can be used to find the number of commands we have
136 * sent to the ctdb daemon to which we have not yet received/processed
137 * the reply.
139 * See Also:
140 * ctdb_num_out_queue(), ctdb_num_active()
142 int ctdb_num_in_flight(struct ctdb_connection *ctdb);
145 * ctdb_num_out_queue - get the number of commands in the out queue
146 * @ctdb: the ctdb_connection from ctdb_connect.
148 * This command can be used to find the number of commands we have
149 * queued for delivery to the ctdb daemon but have not yet been
150 * written to the domain socket.
152 * See Also:
153 * ctdb_num_in_flight(), ctdb_num_active()
155 int ctdb_num_out_queue(struct ctdb_connection *ctdb);
158 * ctdb_get_fd - get the filedescriptor to select/poll on
159 * @ctdb: the ctdb_connection from ctdb_connect.
161 * By using poll or select on this file descriptor, you will know when to call
162 * ctdb_service().
164 * See Also:
165 * ctdb_which_events(), ctdb_service()
167 int ctdb_get_fd(struct ctdb_connection *ctdb);
170 * ctdb_which_events - determine which events ctdb_service wants to see
171 * @ctdb: the ctdb_connection from ctdb_connect.
173 * This returns POLLIN, possibly or'd with POLLOUT if there are writes
174 * pending. You can set this straight into poll.events.
176 * See Also:
177 * ctdb_service()
179 int ctdb_which_events(struct ctdb_connection *ctdb);
182 * ctdb_service - service any I/O and callbacks from ctdbd communication
183 * @ctdb: the ctdb_connection from ctdb_connect.
184 * @revents: which events are available.
186 * This is the core of the library: it read and writes to the ctdbd
187 * socket. It may call callbacks registered with the various _send
188 * functions.
190 * revents is a bitset: POLLIN and/or POLLOUT may be set to indicate
191 * it is worth attempting to read/write the (nonblocking)
192 * filedescriptor respectively.
194 * Note that the synchronous functions call this internally.
195 * Returns false on catastrophic failure.
197 bool ctdb_service(struct ctdb_connection *ctdb, int revents);
200 * struct ctdb_request - handle for an outstanding request
202 * This opaque structure returned from various *_send functions gives
203 * you a handle by which you can cancel a request. You can't do
204 * anything else with it until the request is completed and it is
205 * handed to your callback function.
207 struct ctdb_request;
210 * ctdb_request_free - free a completed request
212 * This frees a request: you should only call it once it has been
213 * handed to your callback. For incomplete requests, see ctdb_cancel().
215 void ctdb_request_free(struct ctdb_request *req);
218 * ctdb_callback_t - callback for completed requests.
220 * This would normally unpack the request using ctdb_*_recv(). You
221 * must free the request using ctdb_request_free().
223 * Note that due to macro magic, actual your callback can be typesafe:
224 * instead of taking a void *, it can take a type which matches the
225 * actual private parameter.
227 typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
228 struct ctdb_request *req, void *private_data);
231 * struct ctdb_db - connection to a particular open TDB
233 * This represents a particular open database: you receive it from
234 * ctdb_attachdb or ctdb_attachdb_recv to manipulate a database.
236 * You have to free the handle with ctdb_detachdb() when finished with it.
238 struct ctdb_db;
241 * ctdb_attachdb_send - open a clustered TDB
242 * @ctdb: the ctdb_connection from ctdb_connect.
243 * @name: the filename of the database (no /).
244 * @persistent: whether the database is persistent across ctdbd's life
245 * @tdb_flags: the flags to pass to tdb_open.
246 * @callback: the callback when we're attached or failed (typesafe)
247 * @cbdata: the argument to callback()
249 * This function connects to a TDB controlled by ctdbd. It can create
250 * a new TDB if it does not exist, depending on tdb_flags. Returns
251 * the pending request, or NULL on error.
253 struct ctdb_request *
254 ctdb_attachdb_send(struct ctdb_connection *ctdb,
255 const char *name, bool persistent, uint32_t tdb_flags,
256 ctdb_callback_t callback, void *cbdata);
259 * ctdb_attachdb_recv - read an ctdb_attach reply from ctdbd
260 * @ctdb: the ctdb_connection from ctdb_connect.
261 * @req: the completed request.
263 * This returns NULL if something went wrong, or otherwise the open database.
265 struct ctdb_db *ctdb_attachdb_recv(struct ctdb_connection *ctdb,
266 struct ctdb_request *req);
270 * struct ctdb_lock - a record lock on a clustered TDB database
272 * This locks a subset of the database across the entire cluster; it
273 * is the fundamental sychronization element for ctdb. You cannot have
274 * more than one lock at once.
276 * You MUST NOT block during holding this lock and MUST release it
277 * quickly by performing ctdb_release_lock(lock).
278 * Do NOT make any system calls that may block while holding the lock.
280 * Try to release the lock as quickly as possible.
282 struct ctdb_lock;
285 * ctdb_rrl_callback_t - callback for ctdb_readrecordlock_async
287 * This is not the standard ctdb_callback_t, because there is often no
288 * request required to access a database record (ie. if it is local already).
289 * So the callback is handed the lock directly: it might be NULL if there
290 * was an error obtaining the lock.
292 * See Also:
293 * ctdb_readrecordlock_async(), ctdb_readrecordlock()
295 typedef void (*ctdb_rrl_callback_t)(struct ctdb_db *ctdb_db,
296 struct ctdb_lock *lock,
297 TDB_DATA data,
298 void *private_data);
301 * ctdb_readrecordlock_async - read and lock a record
302 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
303 * @key: the key of the record to lock.
304 * @callback: the callback once the record is locked (typesafe).
305 * @cbdata: the argument to callback()
307 * This returns true on success. Commonly, we can obtain the record
308 * immediately and so the callback will be invoked. Otherwise a request
309 * will be queued to ctdbd for the record.
311 * If failure is immediate, false is returned. Otherwise, the callback
312 * may receive a NULL lock arg to indicate asynchronous failure.
314 bool ctdb_readrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
315 ctdb_rrl_callback_t callback, void *cbdata);
318 * ctdb_readonlyrecordlock_async - read and lock a record for read-only access
319 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
320 * @key: the key of the record to lock.
321 * @callback: the callback once the record is locked (typesafe).
322 * @cbdata: the argument to callback()
324 * This returns true on success. Commonly, we can obtain the record
325 * immediately and so the callback will be invoked. Otherwise a request
326 * will be queued to ctdbd for the record.
328 * If failure is immediate, false is returned. Otherwise, the callback
329 * may receive a NULL lock arg to indicate asynchronous failure.
331 bool ctdb_readonlyrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
332 ctdb_rrl_callback_t callback, void *cbdata);
336 * ctdb_writerecord - write a locked record in a TDB
337 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
338 * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_recv
339 * @data: the new data to place in the record.
341 bool ctdb_writerecord(struct ctdb_db *ctdb_db,
342 struct ctdb_lock *lock, TDB_DATA data);
345 * ctdb_release_lock - release a record lock on a TDB
346 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
347 * @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_async
349 void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock);
354 * ctdb_traverse_callback_t - callback for ctdb_traverse_async.
355 * return 0 - to continue traverse
356 * return 1 - to abort the traverse
358 * See Also:
359 * ctdb_traverse_async()
361 #define TRAVERSE_STATUS_RECORD 0
362 #define TRAVERSE_STATUS_FINISHED 1
363 #define TRAVERSE_STATUS_ERROR 2
364 typedef int (*ctdb_traverse_callback_t)(struct ctdb_connection *ctdb,
365 struct ctdb_db *ctdb_db,
366 int status,
367 TDB_DATA key,
368 TDB_DATA data,
369 void *private_data);
372 * ctdb_traverse_async - traverse a database.
373 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
374 * @callback: the callback once the record is locked (typesafe).
375 * @cbdata: the argument to callback()
377 * This returns true on success.
378 * when successfull, the callback will be invoked for each record
379 * until the traversal is finished.
381 * status ==
382 * TRAVERSE_STATUS_RECORD key/data contains a record.
383 * TRAVERSE_STATUS_FINISHED traverse is finished. key/data is undefined.
384 * TRAVERSE_STATUS_ERROR an error occured during traverse.
385 * key/data is undefined.
387 * If failure is immediate, false is returned.
389 bool ctdb_traverse_async(struct ctdb_db *ctdb_db,
390 ctdb_traverse_callback_t callback, void *cbdata);
393 * ctdb_message_fn_t - messaging callback for ctdb messages
395 * ctdbd provides a simple messaging API; you can register for a particular
396 * 64-bit id on which you want to send messages, and send to other ids.
398 * See Also:
399 * ctdb_set_message_handler_send()
401 typedef void (*ctdb_message_fn_t)(struct ctdb_connection *,
402 uint64_t srvid, TDB_DATA data, void *);
405 * ctdb_set_message_handler_send - register for messages to a srvid
406 * @ctdb: the ctdb_connection from ctdb_connect.
407 * @srvid: the 64 bit identifier for our messages.
408 * @handler: the callback when we receive such a message (typesafe)
409 * @handler_data: the argument to handler()
410 * @callback: the callback when ctdb replies to our message (typesafe)
411 * @cbdata: the argument to callback()
413 * Note: our callback will always be called before handler.
415 * See Also:
416 * ctdb_set_message_handler_recv(), ctdb_remove_message_handler_send()
418 struct ctdb_request *
419 ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
420 ctdb_message_fn_t handler,
421 void *handler_data,
422 ctdb_callback_t callback,
423 void *cbdata);
426 * ctdb_set_message_handler_recv - read a set_message_handler result
427 * @ctdb: the ctdb_connection from ctdb_connect.
428 * @req: the completed request
430 * If this returns true, the registered handler may be called from the next
431 * ctdb_service(). If this returns false, the registration failed.
433 bool ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
434 struct ctdb_request *handle);
437 * ctdb_remove_message_handler_send - unregister for messages to a srvid
438 * @ctdb: the ctdb_connection from ctdb_connect.
439 * @srvid: the 64 bit identifier for our messages.
440 * @handler: the callback when we receive such a message (typesafe)
441 * @handler_data: the argument to handler()
442 * @callback: the callback when ctdb replies to our message (typesafe)
443 * @cbdata: the argument to callback()
445 * This undoes a successful ctdb_set_message_handler or
446 * ctdb_set_message_handler_recv.
448 struct ctdb_request *
449 ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
450 ctdb_message_fn_t handler, void *handler_data,
451 ctdb_callback_t callback, void *cbdata);
454 * ctdb_remove_message_handler_recv - read a remove_message_handler result
455 * @ctdb: the ctdb_connection from ctdb_connect.
456 * @req: the completed request
458 * After this returns true, the registered handler will no longer be called.
459 * If this returns false, the de-registration failed.
461 bool ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
462 struct ctdb_request *req);
466 * ctdb_send_message - send a message via ctdbd
467 * @ctdb: the ctdb_connection from ctdb_connect.
468 * @pnn: the physical node number to send to
469 * @srvid: the 64 bit identifier for this message type.
470 * @data: the data to send
472 * This allows arbitrary messages to be sent across the cluster to those
473 * listening (via ctdb_set_message_handler et al).
475 * This queues a message to be sent: you will need to call
476 * ctdb_service() to actually send the message. There is no callback
477 * because there is no acknowledgement.
479 * See Also:
480 * ctdb_getpnn_send(), ctdb_getpnn()
482 bool ctdb_send_message(struct ctdb_connection *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
485 * ctdb_getpnn_send - read the pnn number of a node.
486 * @ctdb: the ctdb_connection from ctdb_connect.
487 * @destnode: the destination node (see below)
488 * @callback: the callback when ctdb replies to our message (typesafe)
489 * @cbdata: the argument to callback()
491 * There are several special values for destnode, detailed in
492 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
493 * local ctdbd.
495 struct ctdb_request *
496 ctdb_getpnn_send(struct ctdb_connection *ctdb,
497 uint32_t destnode,
498 ctdb_callback_t callback,
499 void *cbdata);
501 * ctdb_getpnn_recv - read an ctdb_getpnn reply from ctdbd
502 * @ctdb: the ctdb_connection from ctdb_connect.
503 * @req: the completed request.
504 * @pnn: a pointer to the pnn to fill in
506 * This returns false if something went wrong, or otherwise fills in pnn.
508 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
509 struct ctdb_request *req, uint32_t *pnn);
513 * ctdb_getdbstat_send - read statistics for a db
514 * @ctdb: the ctdb_connection from ctdb_connect.
515 * @destnode: the destination node (see below)
516 * @db_id: the database to collect the statistics from
517 * @callback: the callback when ctdb replies to our message (typesafe)
518 * @cbdata: the argument to callback()
520 * There are several special values for destnode, detailed in
521 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
522 * local ctdbd.
524 struct ctdb_request *
525 ctdb_getdbstat_send(struct ctdb_connection *ctdb,
526 uint32_t destnode,
527 uint32_t db_id,
528 ctdb_callback_t callback,
529 void *cbdata);
531 * ctdb_getdbstat_recv - read an ctdb_getdbstat reply from ctdbd
532 * @ctdb: the ctdb_connection from ctdb_connect.
533 * @req: the completed request.
534 * @stat: a pointer to the *stat to fill in
536 * This returns false if something went wrong, or otherwise fills in **stats
537 * stats must be freed later by calling ctdb_free_dbstat();
539 bool ctdb_getdbstat_recv(struct ctdb_connection *ctdb,
540 struct ctdb_request *req,
541 struct ctdb_db_statistics **stat);
543 void ctdb_free_dbstat(struct ctdb_db_statistics *stat);
546 * ctdb_check_message_handlers_send - check a list of message_handlers
547 * if they are registered
548 * message_handlers are registered on the daemon using the
549 * ctdb_set_message_handler_send() call
551 * @ctdb: the ctdb_connection from ctdb_connect.
552 * @destnode: the destination node (see below)
553 * @num: number of srvids to check
554 * @mhs: @num message_handlers values to check
555 * @callback: the callback when ctdb replies to our message (typesafe)
556 * @cbdata: the argument to callback()
558 * There are several special values for destnode, detailed in
559 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
560 * local ctdbd.
562 struct ctdb_request *
563 ctdb_check_message_handlers_send(struct ctdb_connection *ctdb,
564 uint32_t destnode,
565 uint32_t num,
566 uint64_t *mhs,
567 ctdb_callback_t callback,
568 void *cbdata);
570 * ctdb_check_message_handlers_recv - read a ctdb_check_message_handlers
571 * reply from ctdbd
572 * @ctdb: the ctdb_connection from ctdb_connect.
573 * @req: the completed request.
574 * @num: number of message_handlers to check
575 * @result: an array of @num uint8_t fields containing the result of the check
576 * 0: message_handler does not exist
577 * 1: message_handler exists
579 * This returns false if something went wrong, or otherwise fills in result.
581 bool
582 ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb,
583 struct ctdb_request *req, uint32_t num,
584 uint8_t *result);
588 * ctdb_getdbseqnum_send - read the sequence number off a db
589 * @ctdb: the ctdb_connection from ctdb_connect.
590 * @destnode: the destination node (see below)
591 * @dbid: database id
592 * @callback: the callback when ctdb replies to our message (typesafe)
593 * @cbdata: the argument to callback()
595 * There are several special values for destnode, detailed in
596 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
597 * local ctdbd.
599 struct ctdb_request *
600 ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
601 uint32_t destnode,
602 uint32_t dbid,
603 ctdb_callback_t callback,
604 void *cbdata);
606 * ctdb_getdbseqnum_recv - read the sequence number off a database
607 * @ctdb: the ctdb_connection from ctdb_connect.
608 * @req: the completed request.
609 * @seqnum: a pointer to the seqnum to fill in
611 * This returns false if something went wrong, or otherwise fills in pnn.
613 bool ctdb_getdbseqnum_recv(struct ctdb_connection *ctdb,
614 struct ctdb_request *req, uint64_t *seqnum);
617 * ctdb_getnodemap_send - read the nodemap number from a node.
618 * @ctdb: the ctdb_connection from ctdb_connect.
619 * @destnode: the destination node (see below)
620 * @callback: the callback when ctdb replies to our message (typesafe)
621 * @cbdata: the argument to callback()
623 * There are several special values for destnode, detailed in
624 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
625 * local ctdbd.
627 struct ctdb_request *
628 ctdb_getnodemap_send(struct ctdb_connection *ctdb,
629 uint32_t destnode,
630 ctdb_callback_t callback,
631 void *cbdata);
633 * ctdb_getnodemap_recv - read an ctdb_getnodemap reply from ctdbd
634 * @ctdb: the ctdb_connection from ctdb_connect.
635 * @req: the completed request.
636 * @nodemap: a pointer to the returned nodemap structure
638 * This returns false if something went wrong.
639 * If the command failed, it guarantees to set nodemap to NULL.
640 * A non-NULL value for nodemap means the command was successful.
642 * A non-NULL value of the nodemap must be release released/freed
643 * by ctdb_free_nodemap().
645 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
646 struct ctdb_request *req, struct ctdb_node_map **nodemap);
649 * ctdb_getifaces_send - read the list of interfaces from a node.
650 * @ctdb: the ctdb_connection from ctdb_connect.
651 * @destnode: the destination node (see below)
652 * @callback: the callback when ctdb replies to our message (typesafe)
653 * @cbdata: the argument to callback()
655 * There are several special values for destnode, detailed in
656 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
657 * local ctdbd.
659 struct ctdb_request *
660 ctdb_getifaces_send(struct ctdb_connection *ctdb,
661 uint32_t destnode,
662 ctdb_callback_t callback,
663 void *cbdata);
665 * ctdb_getifaces_recv - read an ctdb_getifaces reply from ctdbd
666 * @ctdb: the ctdb_connection from ctdb_connect.
667 * @req: the completed request.
668 * @ifaces: the list of interfaces
670 * This returns false if something went wrong.
671 * If the command failed, it guarantees to set ifaces to NULL.
672 * A non-NULL value for ifaces means the command was successful.
674 * A non-NULL value of the ifaces must be release released/freed
675 * by ctdb_free_ifaces().
677 bool ctdb_getifaces_recv(struct ctdb_connection *ctdb,
678 struct ctdb_request *req, struct ctdb_ifaces_list **ifaces);
680 /* Free a datastructure returned by ctdb_getifaces[_recv] */
681 void ctdb_free_ifaces(struct ctdb_ifaces_list *ifaces);
684 * ctdb_getpublicips_send - read the public ip list from a node.
685 * @ctdb: the ctdb_connection from ctdb_connect.
686 * @destnode: the destination node (see below)
687 * @callback: the callback when ctdb replies to our message (typesafe)
688 * @cbdata: the argument to callback()
690 * This control returns the list of public ips known to the local node.
691 * Deamons only know about those ips that are listed in the local
692 * public addresses file, which means the returned list of ips may
693 * be only a subset of all ips across the entire cluster.
695 * There are several special values for destnode, detailed in
696 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
697 * local ctdbd.
699 struct ctdb_request *
700 ctdb_getpublicips_send(struct ctdb_connection *ctdb,
701 uint32_t destnode,
702 ctdb_callback_t callback,
703 void *cbdata);
705 * ctdb_getpublicips_recv - read the public ip list from a node
706 * @ctdb: the ctdb_connection from ctdb_connect.
707 * @req: the completed request.
708 * @ips: a pointer to the returned public ip list
710 * This returns false if something went wrong.
711 * If the command failed, it guarantees to set ips to NULL.
712 * A non-NULL value for nodemap means the command was successful.
714 * A non-NULL value of the nodemap must be release released/freed
715 * by ctdb_free_publicips().
717 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
718 struct ctdb_request *req, struct ctdb_all_public_ips **ips);
722 * ctdb_getrecmaster_send - read the recovery master of a node
723 * @ctdb: the ctdb_connection from ctdb_connect.
724 * @destnode: the destination node (see below)
725 * @callback: the callback when ctdb replies to our message (typesafe)
726 * @cbdata: the argument to callback()
728 * There are several special values for destnode, detailed in
729 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
730 * local ctdbd.
732 struct ctdb_request *
733 ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
734 uint32_t destnode,
735 ctdb_callback_t callback, void *cbdata);
738 * ctdb_getrecmaster_recv - read an ctdb_getrecmaster reply from ctdbd
739 * @ctdb: the ctdb_connection from ctdb_connect.
740 * @req: the completed request.
741 * @recmaster: a pointer to the recmaster to fill in
743 * This returns false if something went wrong, or otherwise fills in
744 * recmaster.
746 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
747 struct ctdb_request *handle,
748 uint32_t *recmaster);
751 * ctdb_getrecmode_send - read the recovery mode of a node
752 * @ctdb: the ctdb_connection from ctdb_connect.
753 * @destnode: the destination node (see below)
754 * @callback: the callback when ctdb replies to our message (typesafe)
755 * @cbdata: the argument to callback()
757 * There are several special values for destnode, detailed in
758 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
759 * local ctdbd.
761 struct ctdb_request *
762 ctdb_getrecmode_send(struct ctdb_connection *ctdb,
763 uint32_t destnode,
764 ctdb_callback_t callback, void *cbdata);
767 * ctdb_getrecmode_recv - read an ctdb_getrecmode reply from ctdbd
768 * @ctdb: the ctdb_connection from ctdb_connect.
769 * @req: the completed request.
770 * @recmode: a pointer to the recmode to fill in
772 * This returns false if something went wrong, or otherwise fills in
773 * recmode.
775 bool ctdb_getrecmode_recv(struct ctdb_connection *ctdb,
776 struct ctdb_request *handle,
777 uint32_t *recmode);
780 * ctdb_getvnnmap_send - read the vnn map from a node.
781 * @ctdb: the ctdb_connection from ctdb_connect.
782 * @destnode: the destination node (see below)
783 * @callback: the callback when ctdb replies to our message (typesafe)
784 * @cbdata: the argument to callback()
786 * There are several special values for destnode, detailed in
787 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
788 * local ctdbd.
790 struct ctdb_request *
791 ctdb_getvnnmap_send(struct ctdb_connection *ctdb,
792 uint32_t destnode,
793 ctdb_callback_t callback,
794 void *cbdata);
796 * ctdb_getvnnmap_recv - read an ctdb_getvnnmap reply from ctdbd
797 * @ctdb: the ctdb_connection from ctdb_connect.
798 * @req: the completed request.
799 * @vnnmap: the list of interfaces
801 * This returns false if something went wrong.
802 * If the command failed, it guarantees to set vnnmap to NULL.
803 * A non-NULL value for vnnmap means the command was successful.
805 * A non-NULL value of the vnnmap must be released/freed
806 * by ctdb_free_vnnmap().
808 bool ctdb_getvnnmap_recv(struct ctdb_connection *ctdb,
809 struct ctdb_request *req, struct ctdb_vnn_map **vnnmap);
812 * ctdb_cancel - cancel an uncompleted request
813 * @ctdb: the ctdb_connection from ctdb_connect.
814 * @req: the uncompleted request.
816 * This cancels a request, returning true. You may not cancel a
817 * request which has already been completed (ie. once its callback has
818 * been called); you should simply use ctdb_request_free() in that case.
820 void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req);
822 /***
824 * Synchronous API
826 ***/
829 * ctdb_attachdb - open a clustered TDB (synchronous)
830 * @ctdb: the ctdb_connection from ctdb_connect.
831 * @name: the filename of the database (no /).
832 * @persistent: whether the database is persistent across ctdbd's life
833 * @tdb_flags: the flags to pass to tdb_open.
835 * Do a ctdb_attachdb_send and wait for it to complete.
836 * Returns NULL on failure.
838 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
839 const char *name, bool persistent,
840 uint32_t tdb_flags);
843 * ctdb_detachdb - close a clustered TDB.
844 * @ctdb: the ctdb_connection from ctdb_connect.
845 * @db: the database from ctdb_attachdb/ctdb_attachdb_send
847 * Closes a clustered tdb.
849 void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db);
852 * ctdb_readrecordlock - read and lock a record (synchronous)
853 * @ctdb: the ctdb_connection from ctdb_connect.
854 * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
855 * @key: the key of the record to lock.
856 * @req: a pointer to the request, if one is needed.
858 * Do a ctdb_readrecordlock_send and wait for it to complete.
859 * Returns NULL on failure.
861 struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
862 struct ctdb_db *ctdb_db, TDB_DATA key,
863 TDB_DATA *data);
867 * ctdb_set_message_handler - register for messages to a srvid (synchronous)
868 * @ctdb: the ctdb_connection from ctdb_connect.
869 * @srvid: the 64 bit identifier for our messages.
870 * @handler: the callback when we receive such a message (typesafe)
871 * @cbdata: the argument to handler()
873 * If this returns true, the message handler can be called from any
874 * ctdb_service() (which is also called indirectly by other
875 * synchronous functions). If this returns false, the registration
876 * failed.
878 bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
879 ctdb_message_fn_t handler, void *cbdata);
883 * ctdb_remove_message_handler - deregister for messages (synchronous)
884 * @ctdb: the ctdb_connection from ctdb_connect.
885 * @srvid: the 64 bit identifier for our messages.
886 * @handler: the callback when we receive such a message (typesafe)
887 * @handler_data: the argument to handler()
889 * If this returns true, the message handler will no longer be called.
890 * If this returns false, the deregistration failed.
892 bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
893 ctdb_message_fn_t handler, void *handler_data);
896 * ctdb_getpnn - read the pnn number of a node (synchronous)
897 * @ctdb: the ctdb_connection from ctdb_connect.
898 * @destnode: the destination node (see below)
899 * @pnn: a pointer to the pnn to fill in
901 * There are several special values for destnode, detailed in
902 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
903 * local ctdbd.
905 * Returns true and fills in *pnn on success.
907 bool ctdb_getpnn(struct ctdb_connection *ctdb,
908 uint32_t destnode,
909 uint32_t *pnn);
912 * ctdb_getdbstat - read the db stat of a node (synchronous)
913 * @ctdb: the ctdb_connection from ctdb_connect.
914 * @destnode: the destination node (see below)
915 * @db_id: the database to collect the statistics from
916 * @stat: a pointer to the *stat to fill in
918 * There are several special values for destnode, detailed in
919 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
920 * local ctdbd.
922 * This returns false if something went wrong, or otherwise fills in **stat
923 * stat must be freed later by calling ctdb_free_dbstat();
925 bool ctdb_getdbstat(struct ctdb_connection *ctdb,
926 uint32_t destnode,
927 uint32_t db_id,
928 struct ctdb_db_statistics **stat);
932 * ctdb_check_message_handlers - check a list of message_handlers (synchronous)
933 * @ctdb: the ctdb_connection from ctdb_connect.
934 * @destnode: the destination node (see below)
935 * @num: number of srvids to check
936 * @mhs: @num message_handlers to check
937 * @result: an array of @num uint8_t fields containing the result of the check
938 * 0: message_handler does not exist
939 * 1: message_handler exists
941 * There are several special values for destnode, detailed in
942 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
943 * local ctdbd.
945 bool
946 ctdb_check_message_handlers(struct ctdb_connection *ctdb,
947 uint32_t destnode,
948 uint32_t num,
949 uint64_t *mhs,
950 uint8_t *result);
953 * ctdb_getdbseqnum - read the seqnum of a database
954 * @ctdb: the ctdb_connection from ctdb_connect.
955 * @destnode: the destination node (see below)
956 * @dbid: database id
957 * @seqnum: sequence number for the database
959 * There are several special values for destnode, detailed in
960 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
961 * local ctdbd.
963 * Returns true and fills in *pnn on success.
965 bool
966 ctdb_getdbseqnum(struct ctdb_connection *ctdb,
967 uint32_t destnode,
968 uint32_t dbid,
969 uint64_t *seqnum);
972 * ctdb_getrecmaster - read the recovery master of a node (synchronous)
973 * @ctdb: the ctdb_connection from ctdb_connect.
974 * @destnode: the destination node (see below)
975 * @recmaster: a pointer to the recmaster to fill in
977 * There are several special values for destnode, detailed in
978 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
979 * local ctdbd.
981 * Returns true and fills in *recmaster on success.
983 bool ctdb_getrecmaster(struct ctdb_connection *ctdb,
984 uint32_t destnode,
985 uint32_t *recmaster);
989 * ctdb_getrecmode - read the recovery mode of a node (synchronous)
990 * @ctdb: the ctdb_connection from ctdb_connect.
991 * @destnode: the destination node (see below)
992 * @recmode: a pointer to the recmode to fill in
994 * There are several special values for destnode, detailed in
995 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
996 * local ctdbd.
998 * Returns true and fills in *recmode on success.
1000 bool ctdb_getrecmode(struct ctdb_connection *ctdb,
1001 uint32_t destnode,
1002 uint32_t *recmode);
1006 * ctdb_getnodemap - read the nodemap from a node (synchronous)
1007 * @ctdb: the ctdb_connection from ctdb_connect.
1008 * @destnode: the destination node (see below)
1009 * @nodemap: a pointer to the nodemap to fill in
1011 * There are several special values for destnode, detailed in
1012 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
1013 * local ctdbd.
1015 * Returns true and fills in *nodemap on success.
1016 * A non-NULL nodemap must be freed by calling ctdb_free_nodemap.
1018 bool ctdb_getnodemap(struct ctdb_connection *ctdb,
1019 uint32_t destnode, struct ctdb_node_map **nodemap);
1022 * ctdb_getifaces - read the list of interfaces from a node (synchronous)
1023 * @ctdb: the ctdb_connection from ctdb_connect.
1024 * @destnode: the destination node (see below)
1025 * @ifaces: a pointer to the ifaces to fill in
1027 * There are several special values for destnode, detailed in
1028 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
1029 * local ctdbd.
1031 * Returns true and fills in *ifaces on success.
1032 * A non-NULL value of the ifaces must be release released/freed
1033 * by ctdb_free_ifaces().
1035 bool ctdb_getifaces(struct ctdb_connection *ctdb,
1036 uint32_t destnode, struct ctdb_ifaces_list **ifaces);
1039 * This function is used to release/free the nodemap structure returned
1040 * by ctdb_getnodemap() and ctdb_getnodemap_recv()
1042 void ctdb_free_nodemap(struct ctdb_node_map *nodemap);
1046 * ctdb_getpublicips - read the public ip list from a node.
1047 * @ctdb: the ctdb_connection from ctdb_connect.
1048 * @destnode: the destination node (see below)
1049 * @ips: a pointer to the returned public ip list
1051 * This control returns the list of public ips known to the local node.
1052 * Deamons only know about those ips that are listed in the local
1053 * public addresses file, which means the returned list of ips may
1054 * be only a subset of all ips across the entire cluster.
1056 * There are several special values for destnode, detailed in
1057 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
1058 * local ctdbd.
1060 * This returns false if something went wrong.
1061 * If the command failed, it guarantees to set ips to NULL.
1062 * A non-NULL value for nodemap means the command was successful.
1064 * A non-NULL value of the nodemap must be release released/freed
1065 * by ctdb_free_publicips().
1067 bool ctdb_getpublicips(struct ctdb_connection *ctdb,
1068 uint32_t destnode, struct ctdb_all_public_ips **ips);
1071 * This function is used to release/free the public ip structure returned
1072 * by ctdb_getpublicips() and ctdb_getpublicips_recv()
1074 void ctdb_free_publicips(struct ctdb_all_public_ips *ips);
1078 * ctdb_getvnnmap - read the vnn map from a node (synchronous)
1079 * @ctdb: the ctdb_connection from ctdb_connect.
1080 * @destnode: the destination node (see below)
1081 * @vnnmap: a pointer to the vnnmap to fill in
1083 * There are several special values for destnode, detailed in
1084 * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
1085 * local ctdbd.
1087 * Returns true and fills in *vnnmap on success.
1088 * A non-NULL value of the vnnmap must be released/freed
1089 * by ctdb_free_vnnmap().
1091 bool ctdb_getvnnmap(struct ctdb_connection *ctdb,
1092 uint32_t destnode, struct ctdb_vnn_map **vnnmap);
1095 * This function is used to release/free the vnnmap structure returned
1096 * by ctdb_getvnnmap() and ctdb_getvnnmap_recv()
1098 void ctdb_free_vnnmap(struct ctdb_vnn_map *vnnmap);
1100 /* These ugly macro wrappers make the callbacks typesafe. */
1101 #include <ctdb_typesafe_cb.h>
1102 #define ctdb_sendcb(cb, cbdata) \
1103 typesafe_cb_preargs(void, (cb), (cbdata), \
1104 struct ctdb_connection *, struct ctdb_request *)
1106 #define ctdb_msgcb(cb, cbdata) \
1107 typesafe_cb_preargs(void, (cb), (cbdata), \
1108 struct ctdb_connection *, uint64_t, TDB_DATA)
1110 #define ctdb_connect(addr, log, logpriv) \
1111 ctdb_connect((addr), \
1112 typesafe_cb_postargs(void, (log), (logpriv), \
1113 int, const char *, va_list), \
1114 (logpriv))
1116 #define ctdb_set_message_handler(ctdb, srvid, handler, hdata) \
1117 ctdb_set_message_handler((ctdb), (srvid), \
1118 ctdb_msgcb((handler), (hdata)), (hdata))
1120 #define ctdb_remove_message_handler(ctdb, srvid, handler, hdata) \
1121 ctdb_remove_message_handler((ctdb), (srvid), \
1122 ctdb_msgcb((handler), (hdata)), (hdata))
1124 #define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
1125 ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags), \
1126 ctdb_sendcb((cb), (cbdata)), (cbdata))
1128 #define ctdb_readrecordlock_async(_ctdb_db, key, cb, cbdata) \
1129 ctdb_readrecordlock_async((_ctdb_db), (key), \
1130 typesafe_cb_preargs(void, (cb), (cbdata), \
1131 struct ctdb_db *, struct ctdb_lock *, \
1132 TDB_DATA), (cbdata))
1134 #define ctdb_set_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
1135 ctdb_set_message_handler_send((ctdb), (srvid), \
1136 ctdb_msgcb((handler), (hdata)), (hdata), \
1137 ctdb_sendcb((cb), (cbdata)), (cbdata))
1139 #define ctdb_remove_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
1140 ctdb_remove_message_handler_send((ctdb), (srvid), \
1141 ctdb_msgcb((handler), (hdata)), (hdata), \
1142 ctdb_sendcb((cb), (cbdata)), (cbdata))
1144 #define ctdb_getpnn_send(ctdb, destnode, cb, cbdata) \
1145 ctdb_getpnn_send((ctdb), (destnode), \
1146 ctdb_sendcb((cb), (cbdata)), (cbdata))
1148 #define ctdb_getdbstat_send(ctdb, destnode, db_id, cb, cbdata) \
1149 ctdb_getdbstat_send((ctdb), (destnode), (db_id), \
1150 ctdb_sendcb((cb), (cbdata)), (cbdata))
1152 #define ctdb_check_message_handlers_send(ctdb, destnode, num, mhs, \
1153 cb, cbdata) \
1154 ctdb_check_message_handlers_send((ctdb), (destnode), (num), \
1155 (mhs), \
1156 ctdb_sendcb((cb), (cbdata)), (cbdata))
1158 #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata) \
1159 ctdb_getrecmaster_send((ctdb), (destnode), \
1160 ctdb_sendcb((cb), (cbdata)), (cbdata))
1162 #define ctdb_getrecmode_send(ctdb, destnode, cb, cbdata) \
1163 ctdb_getrecmode_send((ctdb), (destnode), \
1164 ctdb_sendcb((cb), (cbdata)), (cbdata))
1166 #define ctdb_getnodemap_send(ctdb, destnode, cb, cbdata) \
1167 ctdb_getnodemap_send((ctdb), (destnode), \
1168 ctdb_sendcb((cb), (cbdata)), (cbdata))
1170 #define ctdb_getpublicips_send(ctdb, destnode, cb, cbdata) \
1171 ctdb_getpublicips_send((ctdb), (destnode), \
1172 ctdb_sendcb((cb), (cbdata)), (cbdata))
1174 #define ctdb_getdbseqnum_send(ctdb, destnode, dbid, cb, cbdata) \
1175 ctdb_getdbseqnum_send((ctdb), (destnode), (dbid), \
1176 ctdb_sendcb((cb), (cbdata)), (cbdata))
1178 #define ctdb_getifaces_send(ctdb, destnode, cb, cbdata) \
1179 ctdb_getifaces_send((ctdb), (destnode), \
1180 ctdb_sendcb((cb), (cbdata)), (cbdata))
1182 #define ctdb_getvnnmap_send(ctdb, destnode, cb, cbdata) \
1183 ctdb_getvnnmap_send((ctdb), (destnode), \
1184 ctdb_sendcb((cb), (cbdata)), (cbdata))
1186 #endif