add libctdb getrecmaster control recv function and
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 11 May 2010 01:26:48 +0000 (11:26 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 11 May 2010 01:26:48 +0000 (11:26 +1000)
a sync version of getrecmaster

include/libctdb.h
libctdb/libctdb.c
libctdb/tst.c

index 928da5653cdc10ded71393103457e8a98c0be69e..6a1926b30222965f882290b882c3456413982bcb 100644 (file)
@@ -42,10 +42,17 @@ typedef void (*get_recmaster_cb)(int32_t status, int32_t recmaster, void *privat
 
 
 libctdb_handle *
-libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb,
+libctdb_getrecmaster_send(struct ctdb_context *ctdb,
                        uint32_t destnode,
                        get_recmaster_cb callback,
                        void *private_data);
+int libctdb_getrecmaster_recv(struct ctdb_context *ctdb,
+                       libctdb_handle *handle,
+                       uint32_t *recmaster);
+int libctdb_getrecmaster(struct ctdb_context *ctdb,
+                       uint32_t destnode,
+                       uint32_t *recmaster);
+
 
 int libctdb_cancel(libctdb_handle *);
 
index 994c074591143209c8d5a3f725e553e927ed8cd5..e3a7c1abadb0de5c6c393d3926d8e50e812c6584 100644 (file)
@@ -153,7 +153,7 @@ libctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
   get the recovery master of a remote node
  */
 libctdb_handle *
-libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb,
+libctdb_getrecmaster_send(struct ctdb_context *ctdb,
                        uint32_t destnode,
                        get_recmaster_cb callback,
                        void *private_data)
@@ -165,17 +165,49 @@ libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb,
                           CTDB_CONTROL_GET_RECMASTER, 0, tdb_null, 
                           ctdb, NULL, NULL);
 
-       cb_data = talloc(state, struct libctdb_control_cb_data);
-       cb_data->callback     = callback;
-       cb_data->private_data = private_data;
+       if (callback != NULL) {
+               cb_data = talloc(state, struct libctdb_control_cb_data);
+               cb_data->callback     = callback;
+               cb_data->private_data = private_data;
 
-       state->async.fn           = libctdb_getrecmaster_recv_cb;
-       state->async.private_data = cb_data;
+               state->async.fn           = libctdb_getrecmaster_recv_cb;
+               state->async.private_data = cb_data;
+       }
 
        return (libctdb_handle *)state;
 }
 
+int libctdb_getrecmaster_recv(struct ctdb_context *ctdb, libctdb_handle *handle, uint32_t *recmaster)
+{
+       struct ctdb_client_control_state *state = talloc_get_type(handle, struct ctdb_client_control_state);
+       int ret;
+       int32_t res;
+
+       ret = ctdb_control_recv(ctdb, state, state, NULL, &res, NULL);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,(__location__ " libctdb_getrecmaster_recv failed\n"));
+               return -1;
+       }
+
+       if (recmaster) {
+               *recmaster = (uint32_t)res;
+       }
+
+       return 0;
+}
+
+int libctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmaster)
+{
+       struct ctdb_client_control_state *state;
+       
+       state = libctdb_getrecmaster_send(ctdb, destnode, NULL, recmaster);
+       if (state == NULL) {
+               DEBUG(DEBUG_ERR,(__location__ " libctdb_getrecmaster_send() failed.\n"));
+               return -1;
+       }
 
+       return libctdb_getrecmaster_recv(ctdb, state, recmaster);
+}
 
 
 
index 6781746bbe29b3cb816c668ca4249965148d21c3..251c3768413bd17da0b15e80664489cf9cd49278 100644 (file)
@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
 
        pfd.fd = libctdb_get_fd(ctdb_context);
 
-       state = libctdb_getrecmaster_cb_send(ctdb_context, 0, rm_cb, NULL);
+       state = libctdb_getrecmaster_send(ctdb_context, 0, rm_cb, NULL);
 
        for (;;) {
          pfd.events = libctdb_which_events(ctdb_context);