#include <stdarg.h>
#include <stdio.h>
#include <tdb.h>
+#include <netinet/in.h>
#include <ctdb_protocol.h>
/**
* programs; these can be found in the section marked "Synchronous API".
*/
+/**
+ * ctdb_log_fn_t - logging function for ctdbd
+ * @log_priv: private (typesafe) arg via ctdb_connect
+ * @severity: syslog-style severity
+ * @format: printf-style format string.
+ * @ap: arguments for formatting.
+ *
+ * The severity passed to log() are as per syslog(3). In particular,
+ * LOG_DEBUG is used for tracing, LOG_WARNING is used for unusual
+ * conditions which don't necessarily return an error through the API,
+ * LOG_ERR is used for errors such as lost communication with ctdbd or
+ * out-of-memory, LOG_ALERT is used for library usage bugs, LOG_CRIT is
+ * used for libctdb internal consistency checks.
+ *
+ * The log() function can be typesafe: the @log_priv arg to
+ * ctdb_donnect and signature of log() should match.
+ */
typedef void (*ctdb_log_fn_t)(void *log_priv,
int severity, const char *format, va_list ap);
* @log: the logging function
* @log_priv: the private argument to the logging function.
*
- * Returns a ctdb context if successful or NULL. Use ctdb_free() to
+ * Returns a ctdb context if successful or NULL. Use ctdb_disconnect() to
* release the returned ctdb_connection when finished.
*
- * The log() function can be typesafe: the log_priv arg and signature
- * of log() should match. The priority passed to log() os as per
- * syslog(3).
- *
* See Also:
- * ctdb_log_file()
+ * ctdb_log_fn_t, ctdb_log_file()
*/
struct ctdb_connection *ctdb_connect(const char *addr,
ctdb_log_fn_t log_fn, void *log_priv);
*/
extern int ctdb_log_level;
+/**
+ * ctdb_disconnect - close down a connection to ctdbd.
+ * @ctdb: the ctdb connectio returned from ctdb_connect.
+ *
+ * The @ctdb arg will be freed by this call, and must not be used again.
+ */
+void ctdb_disconnect(struct ctdb_connection *ctdb);
+
/***
*
* Asynchronous API
* actual private parameter.
*/
typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
- struct ctdb_request *req, void *private);
+ struct ctdb_request *req, void *private_data);
/**
* struct ctdb_db - connection to a particular open TDB
* This represents a particular open database: you receive it from
* ctdb_attachdb or ctdb_attachdb_recv to manipulate a database.
*
- * You have to free the handle with ctdb_detach_db() when finished with it.
+ * You have to free the handle with ctdb_detachdb() when finished with it.
*/
struct ctdb_db;
*/
struct ctdb_request *
ctdb_attachdb_send(struct ctdb_connection *ctdb,
- const char *name, int persistent, uint32_t tdb_flags,
+ const char *name, bool persistent, uint32_t tdb_flags,
ctdb_callback_t callback, void *cbdata);
/**
*
* You MUST NOT block during holding this lock and MUST release it
* quickly by performing ctdb_release_lock(lock).
+ * Do NOT make any system calls that may block while holding the lock.
+ *
+ * Try to release the lock as quickly as possible.
*/
struct ctdb_lock;
typedef void (*ctdb_rrl_callback_t)(struct ctdb_db *ctdb_db,
struct ctdb_lock *lock,
TDB_DATA data,
- void *private);
+ void *private_data);
/**
* ctdb_readrecordlock_async - read and lock a record
/**
* ctdb_writerecord - write a locked record in a TDB
+ * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
* @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_recv
* @data: the new data to place in the record.
*/
-int ctdb_writerecord(struct ctdb_lock *lock, TDB_DATA data);
+bool ctdb_writerecord(struct ctdb_db *ctdb_db,
+ struct ctdb_lock *lock, TDB_DATA data);
/**
* ctdb_release_lock - release a record lock on a TDB
+ * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
* @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_async
*/
-void ctdb_release_lock(struct ctdb_lock *lock);
+void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock);
/**
* ctdb_message_fn_t - messaging callback for ctdb messages
* @ctdb: the ctdb_connection from ctdb_connect.
* @srvid: the 64 bit identifier for our messages.
* @handler: the callback when we receive such a message (typesafe)
+ * @handler_data: the argument to handler()
* @callback: the callback when ctdb replies to our message (typesafe)
- * @cbdata: the argument to callback() and handler()
+ * @cbdata: the argument to callback()
*
* Note: our callback will always be called before handler.
*
struct ctdb_request *
ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
ctdb_message_fn_t handler,
+ void *handler_data,
ctdb_callback_t callback,
void *cbdata);
* ctdb_remove_message_handler_send - unregister for messages to a srvid
* @ctdb: the ctdb_connection from ctdb_connect.
* @srvid: the 64 bit identifier for our messages.
+ * @handler: the callback when we receive such a message (typesafe)
+ * @handler_data: the argument to handler()
* @callback: the callback when ctdb replies to our message (typesafe)
* @cbdata: the argument to callback()
*
*/
struct ctdb_request *
ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
+ ctdb_message_fn_t handler, void *handler_data,
ctdb_callback_t callback, void *cbdata);
/**
* After this returns true, the registered handler will no longer be called.
* If this returns false, the de-registration failed.
*/
-bool ctdb_remove_message_handler_recv(struct ctdb_request *handle);
+bool ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
+ struct ctdb_request *req);
/**
struct ctdb_request *req, uint32_t *pnn);
+/**
+ * ctdb_getnodemap_send - read the nodemap number from a node.
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @callback: the callback when ctdb replies to our message (typesafe)
+ * @cbdata: the argument to callback()
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ */
+struct ctdb_request *
+ctdb_getnodemap_send(struct ctdb_connection *ctdb,
+ uint32_t destnode,
+ ctdb_callback_t callback,
+ void *cbdata);
+/**
+ * ctdb_getnodemap_recv - read an ctdb_getnodemap reply from ctdbd
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @req: the completed request.
+ * @nodemap: a pointer to the returned nodemap structure
+ *
+ * This returns false if something went wrong.
+ * If the command failed, it guarantees to set nodemap to NULL.
+ * A non-NULL value for nodemap means the command was successful.
+ *
+ * A non-NULL value of the nodemap must be release released/freed
+ * by ctdb_free_nodemap().
+ */
+bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
+ struct ctdb_request *req, struct ctdb_node_map **nodemap);
+
/**
* ctdb_getrecmaster_send - read the recovery master of a node
* @ctdb: the ctdb_connection from ctdb_connect.
struct ctdb_request *
ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
uint32_t destnode,
- ctdb_callback_t callback, void *cbdata);
+ ctdb_callback_t callback, void *cbdata);
/**
* ctdb_getrecmaster_recv - read an ctdb_getrecmaster reply from ctdbd
* Returns NULL on failure.
*/
struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
- const char *name, int persistent,
+ const char *name, bool persistent,
uint32_t tdb_flags);
+/**
+ * ctdb_detachdb - close a clustered TDB.
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @db: the database from ctdb_attachdb/ctdb_attachdb_send
+ *
+ * Closes a clustered tdb.
+ */
+void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db);
+
/**
* ctdb_readrecordlock - read and lock a record (synchronous)
+ * @ctdb: the ctdb_connection from ctdb_connect.
* @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
* @key: the key of the record to lock.
* @req: a pointer to the request, if one is needed.
* Do a ctdb_readrecordlock_send and wait for it to complete.
* Returns NULL on failure.
*/
-struct ctdb_lock *ctdb_readrecordlock(struct ctdb_db *ctdb_db, TDB_DATA key,
+struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
+ struct ctdb_db *ctdb_db, TDB_DATA key,
TDB_DATA *data);
* failed.
*/
bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
- ctdb_message_fn_t handler, void *cbdata);
+ ctdb_message_fn_t handler, void *cbdata);
/**
* ctdb_remove_message_handler - deregister for messages (synchronous)
* @ctdb: the ctdb_connection from ctdb_connect.
* @srvid: the 64 bit identifier for our messages.
+ * @handler: the callback when we receive such a message (typesafe)
+ * @handler_data: the argument to handler()
*
* If this returns true, the message handler will no longer be called.
* If this returns false, the deregistration failed.
*/
-bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid);
+bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
+ ctdb_message_fn_t handler, void *handler_data);
/**
* ctdb_getpnn - read the pnn number of a node (synchronous)
uint32_t destnode,
uint32_t *recmaster);
+
+/**
+ * ctdb_getnodemap - read the nodemap from a node (synchronous)
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @nodemap: a pointer to the nodemap to fill in
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ *
+ * Returns true and fills in *nodemap on success.
+ * A non-NULL nodemap must be freed by calling ctdb_free_nodemap.
+ */
+bool ctdb_getnodemap(struct ctdb_connection *ctdb,
+ uint32_t destnode, struct ctdb_node_map **nodemap);
+
+/*
+ * This function is used to release/free the nodemap structure returned
+ * by ctdb_getnodemap() and ctdb_getnodemap_recv()
+ */
+void ctdb_free_nodemap(struct ctdb_node_map *nodemap);
+
+
+
/* These ugly macro wrappers make the callbacks typesafe. */
#include <ctdb_typesafe_cb.h>
#define ctdb_sendcb(cb, cbdata) \
typesafe_cb_preargs(void, (cb), (cbdata), \
struct ctdb_connection *, struct ctdb_request *)
+#define ctdb_msgcb(cb, cbdata) \
+ typesafe_cb_preargs(void, (cb), (cbdata), \
+ struct ctdb_connection *, uint64_t, TDB_DATA)
+
#define ctdb_connect(addr, log, logpriv) \
ctdb_connect((addr), \
typesafe_cb_postargs(void, (log), (logpriv), \
int, const char *, va_list), \
(logpriv))
+#define ctdb_set_message_handler(ctdb, srvid, handler, hdata) \
+ ctdb_set_message_handler((ctdb), (srvid), \
+ ctdb_msgcb((handler), (hdata)), (hdata))
+
+#define ctdb_remove_message_handler(ctdb, srvid, handler, hdata) \
+ ctdb_remove_message_handler((ctdb), (srvid), \
+ ctdb_msgcb((handler), (hdata)), (hdata))
#define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags), \
struct ctdb_db *, struct ctdb_lock *, \
TDB_DATA), (cbdata))
-#define ctdb_set_message_handler_send(ctdb, srvid, handler, cb, cbdata) \
- ctdb_set_message_handler_send((ctdb), (srvid), (handler), \
- ctdb_sendcb((cb), (cbdata)), (cbdata))
+#define ctdb_set_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
+ ctdb_set_message_handler_send((ctdb), (srvid), \
+ ctdb_msgcb((handler), (hdata)), (hdata), \
+ ctdb_sendcb((cb), (cbdata)), (cbdata))
-#define ctdb_remove_message_handler_send(ctdb, srvid, cb, cbdata) \
+#define ctdb_remove_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
ctdb_remove_message_handler_send((ctdb), (srvid), \
+ ctdb_msgcb((handler), (hdata)), (hdata), \
ctdb_sendcb((cb), (cbdata)), (cbdata))
#define ctdb_getpnn_send(ctdb, destnode, cb, cbdata) \
#define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata) \
ctdb_getrecmaster_send((ctdb), (destnode), \
ctdb_sendcb((cb), (cbdata)), (cbdata))
+
+#define ctdb_getnodemap_send(ctdb, destnode, cb, cbdata) \
+ ctdb_getnodemap_send((ctdb), (destnode), \
+ ctdb_sendcb((cb), (cbdata)), (cbdata))
+
#endif