change the controls to return a struct ctdb_client_control_state* instead of a handle
[sahlberg/ctdb.git] / include / ctdb.h
index d0b9507711a63efdb6b8e681922162643c840c75..716e2a1312ff142b834180a4645eeb8fd53f7f8c 100644 (file)
 /* 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.
  */
 
 /*
@@ -62,6 +75,9 @@ int ctdb_service(struct ctdb_context *ctdb);
 
 
 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);
 
 
 /*
@@ -128,6 +144,99 @@ int ctdb_writerecord(ctdb_handle *handle,
 
 
 
+/*
+   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
  * these functions provide a messaging layer for applications to communicate
@@ -181,16 +290,17 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, T
 
 /*
  * 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,
                 uint32_t destnode,
-                ctdb_getpnn_cb callback,
+                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,
@@ -201,26 +311,32 @@ int ctdb_getpnn(struct ctdb_context *ctdb,
 
 /*
  * 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_free(ctdb_handle *);