/* Functions are not thread safe so all function calls must be wrapped
* inside a pthread_mutex for threaded applications.
*
- * All _send() functions are guaranteed to be non-blocking and fully
+ * All *_send() functions are guaranteed to be non-blocking and fully
* asynchronous.
*
- * Avoid using the synchronous calls
+ * The return data from a _send() call can be accessed through two different
+ * mechanisms.
+ *
+ * 1, by calling *_recv() directly on the handle.
+ * This function will block until the response is received so it
+ * should be avoided.
+ * The exception is when called from in the registered callback,
+ * in this case the fucntion is guaranteed not to block.
+ *
+ * 2, providing an async callback to be invoked when the call completes.
+ * From inside the callback you use the *_recv() function to extract the
+ * response data.
+ *
+ * After the *_recv() function returns, the handle will have been destroyed.
*/
/*
* Connect to ctdb using the specified domain socket.
* Returns a ctdb context if successful or NULL.
+ *
+ * Use ctdb_free() to release the returned ctdb_context when finished.
*/
struct ctdb_context *ctdb_connect(const char *addr);
int ctdb_service(struct ctdb_context *ctdb);
+/*
+ * Special node addresses :
+ */
+/* used on the domain socket, send a pdu to the local daemon */
+#define CTDB_CURRENT_NODE 0xF0000001
+/* send a broadcast to all nodes in the cluster, active or not */
+#define CTDB_BROADCAST_ALL 0xF0000002
+/* send a broadcast to all nodes in the current vnn map */
+#define CTDB_BROADCAST_VNNMAP 0xF0000003
+/* send a broadcast to all connected nodes */
+#define CTDB_BROADCAST_CONNECTED 0xF0000004
+
+
+
+
+
typedef void ctdb_handle;
+struct ctdb_client_control_state;
+
+typedef void (*ctdb_control_callback)(int32_t status, struct ctdb_context *ctdb, struct ctdb_client_control_state *state, void *private_data);
+
+
+/*
+ * functions to attach to a database
+ * if the database does not exist it will be created.
+ *
+ * You have to free the handle with ctdb_free() when finished with it.
+ */
+struct ctdb_db_context;
+
+typedef void (*ctdb_attachdb_cb)(int32_t status, ctdb_handle *, struct ctdb_db_context *ctdb_db, void *private_data);
+
+ctdb_handle *
+ctdb_attachdb_send(struct ctdb_context *ctdb,
+ const char *name, int persistent, uint32_t tdb_flags,
+ ctdb_attachdb_cb callback,
+ void *private_data);
+int ctdb_attachdb_recv(struct ctdb_context *ctdb,
+ ctdb_handle *handle, struct ctdb_db_context **);
+int ctdb_attachdb(struct ctdb_context *ctdb,
+ const char *name, int persistent, uint32_t tdb_flags,
+ struct ctdb_db_context **);
+
+
+/*
+ * functions to read a record from the database
+ * when the callback is invoked, the client will hold an exclusive lock
+ * on the record, until the handle is ctdb_free()d.
+ * the client MUST NOT block during holding this lock and MUST
+ * release it quickly by performing ctdb_free(handle).
+ *
+ * When the handle is freed, data is freed too, so make sure to copy the data
+ * before freeing the handle.
+ */
+typedef void (*ctdb_readrecordlock_cb)(int32_t status, ctdb_handle *handle, TDB_DATA data, void *private_data);
+
+ctdb_handle *
+ctdb_readrecordlock_send(struct ctdb_context *ctdb,
+ struct ctdb_db_context *ctdb_db_context,
+ TDB_DATA key,
+ ctdb_readrecordlock_cb callback,
+ void *private_data);
+int ctdb_readrecordlock_recv(struct ctdb_context *ctdb,
+ ctdb_handle *handle,
+ TDB_DATA **data);
+int ctdb_readrecordlock(struct ctdb_context *ctdb,
+ struct ctdb_db_context *ctdb_db_context,
+ TDB_DATA key,
+ TDB_DATA **data);
+
+
+
+/*
+ * Function to write data to a record
+ * This function may ONLY be called while holding a lock to the record
+ * created by ctdb_readrecordlock*
+ * Either from the callback provided to ctdb_readrecordlock_send()
+ * or after calling ctdb_readrecordlock_recv() but before calling
+ * ctdb_free() to release the handle.
+ */
+int ctdb_writerecord(ctdb_handle *handle,
+ TDB_DATA key,
+ TDB_DATA data);
+
+
+
+/*
+ Messaging serverid ports
+*/
+/*
+ a message handler ID meaning "give me all messages"
+ */
+#define CTDB_SRVID_ALL (~(uint64_t)0)
+
+/*
+ The top 32 bits of the server id represents the owner of
+ this part of the srvid space
+*/
+#define CTDB_SRVID_MASK 0xFFFFFFFF00000000LL
+
+
+/*
+ Samba owns all message handler IDs where the top 32 bits are all zero
+*/
+#define CTDB_SRVID_SAMBA 0x0000000000000000
+#define CTDB_IS_SAMBA_SRVID(srvid) ((srvid & CTDB_SRVID_MASK) == CTDB_SRVID_SAMBA)
+
+/*
+ Server ids reserved for testing
+*/
+#define CTDB_SRVID_TEST 0x0000000100000000
+#define CTDB_IS_TEST_SRVID(srvid) ((srvid & CTDB_SRVID_MASK) == CTDB_SRVID_TEST)
+
+/*
+ srvid type : RECOVERY
+*/
+#define CTDB_SRVID_RECOVERY 0xF100000000000000LL
+
+/*
+ a message handler ID meaning that the cluster has been reconfigured
+ */
+#define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
+
+/*
+ a message handler ID meaning that an IP address has been released
+ */
+#define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
+
+/*
+ a message ID to set the node flags in the recovery daemon
+ */
+#define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
+
+/*
+ a message ID to ask the recovery daemon to update the expected node
+ assignment for a public ip
+ */
+#define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
+
+/*
+ a message to tell the recovery daemon to fetch a set of records
+ */
+#define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
+
+/*
+ a message to tell the recovery daemon to write a talloc memdump
+ to the log
+ */
+#define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
+
+/*
+ a message ID to get the recovery daemon to push the node flags out
+ */
+#define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
+
+/*
+ a message ID to get the recovery daemon to reload the nodes file
+ */
+#define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
+
+/*
+ a message ID to get the recovery daemon to perform a takeover run
+ */
+#define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
+
+/* A message id to ask the recovery daemon to temporarily disable the
+ public ip checks
+*/
+#define CTDB_SRVID_DISABLE_IP_CHECK 0xFC00000000000000LL
+/* A dummy port used for sending back ipreallocate resposnes to the main
+ daemon
+*/
+#define CTDB_SRVID_TAKEOVER_RUN_RESPONSE 0xFD00000000000000LL
+
+/* A port reserved for samba (top 32 bits)
+ */
+#define CTDB_SRVID_SAMBA_NOTIFY 0xFE00000000000000LL
/*
* messaging functions
int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
ctdb_handle *handle);
-int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
- void *private_data);
+int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
+
+
/*
* send a message to a specific node/port
/*
* functions to read the pnn number of the local node
+ *
+ * ctdb_cancel_control(state) is used
+ * to abort this command before it completes.
*/
-typedef void (*ctdb_getpnn_cb)(int32_t status, int32_t pnn, void *private_data);
-
-ctdb_handle *
+struct ctdb_client_control_state *
ctdb_getpnn_send(struct ctdb_context *ctdb,
- ctdb_getpnn_cb callback,
+ uint32_t destnode,
+ ctdb_control_callback callback,
void *private_data);
int ctdb_getpnn_recv(struct ctdb_context *ctdb,
- ctdb_handle *handle,
+ struct ctdb_client_control_state *state,
uint32_t *pnn);
int ctdb_getpnn(struct ctdb_context *ctdb,
+ uint32_t destnode,
uint32_t *pnn);
/*
* functions to read the recovery master of a node
+ *
+ * ctdb_cancel_control(state) is used
+ * to abort this command before it completes.
*/
-typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
-
-ctdb_handle *
+struct ctdb_client_control_state *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
uint32_t destnode,
- ctdb_getrecmaster_cb callback,
+ ctdb_control_callback callback,
void *private_data);
int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
- ctdb_handle *handle,
- uint32_t *recmaster);
+ struct ctdb_client_control_state *state,
+ uint32_t *recmaster);
int ctdb_getrecmaster(struct ctdb_context *ctdb,
uint32_t destnode,
uint32_t *recmaster);
+/*
+ * Cancel a control before it has completed
+ */
+int ctdb_cancel_control(struct ctdb_client_control_state *state);
+
/*
- * cancel a request/call
+ * release a handle
*/
-int ctdb_cancel(ctdb_handle *);
+int ctdb_free(ctdb_handle *);