LibCTDB: add support for the check-srvids control
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 29 Nov 2011 23:00:07 +0000 (10:00 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 29 Nov 2011 23:00:07 +0000 (10:00 +1100)
include/ctdb.h
libctdb/control.c
libctdb/sync.c

index 43ab192c0feeffa213046b76db0c3a21016bf4fd..aeab615b440930966aefc85c5731e71ef0eb1b5e 100644 (file)
@@ -509,6 +509,48 @@ bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
                      struct ctdb_request *req, uint32_t *pnn);
 
 
+/**
+ * ctdb_check_message_handlers_send - check a list of message_handlers
+ * if they are registered
+ * message_handlers are registered on the daemon using the
+ *   ctdb_set_message_handler_send() call
+ *
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @num: number of srvids to check
+ * @mhs: @num message_handlers values to check
+ * @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_check_message_handlers_send(struct ctdb_connection *ctdb,
+                uint32_t destnode,
+                uint32_t num,
+                uint64_t *mhs,
+                ctdb_callback_t callback,
+                void *cbdata);
+/**
+ * ctdb_check_message_handlers_recv - read a ctdb_check_message_handlers
+ * reply from ctdbd
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @req: the completed request.
+ * @num: number of message_handlers to check
+ * @result: an array of @num uint8_t fields containing the result of the check
+ *     0: message_handler does not exist
+ *     1: message_handler exists
+ *
+ * This returns false if something went wrong, or otherwise fills in result.
+ */
+bool
+ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb,
+                                 struct ctdb_request *req, uint32_t num,
+                                 uint8_t *result);
+
+
 /**
  * ctdb_getdbseqnum_send - read the sequence number off a db
  * @ctdb: the ctdb_connection from ctdb_connect.
@@ -766,6 +808,27 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb,
                 uint32_t destnode,
                 uint32_t *pnn);
 
+/**
+ * ctdb_check_message_handlers - check a list of message_handlers (synchronous)
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @num: number of srvids to check
+ * @mhs: @num message_handlers to check
+ * @result: an array of @num uint8_t fields containing the result of the check
+ *     0: message_handler does not exist
+ *     1: message_handler exists
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ */
+bool
+ctdb_check_message_handlers(struct ctdb_connection *ctdb,
+                          uint32_t destnode,
+                          uint32_t num,
+                          uint64_t *mhs,
+                          uint8_t *result);
+
 /**
  * ctdb_getdbseqnum - read the seqnum of a database
  * @ctdb: the ctdb_connection from ctdb_connect.
@@ -922,6 +985,12 @@ void ctdb_free_publicips(struct ctdb_all_public_ips *ips);
        ctdb_getpnn_send((ctdb), (destnode),                            \
                         ctdb_sendcb((cb), (cbdata)), (cbdata))
 
+#define ctdb_check_message_handlers_send(ctdb, destnode, num, mhs,     \
+                        cb, cbdata)                                    \
+       ctdb_check_message_handlers_send((ctdb), (destnode), (num),     \
+                        (mhs),                                         \
+                        ctdb_sendcb((cb), (cbdata)), (cbdata))
+
 #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata)             \
        ctdb_getrecmaster_send((ctdb), (destnode),                      \
                               ctdb_sendcb((cb), (cbdata)), (cbdata))
index 70c8e51950efbc2a83e7e4fc54dc82799fb9142d..419238101c854097211f94980323b3ec31ec9f9f 100644 (file)
@@ -25,6 +25,7 @@
 #undef ctdb_getrecmaster_send
 #undef ctdb_getrecmode_send
 #undef ctdb_getpnn_send
+#undef ctdb_check_message_handlers_send
 #undef ctdb_getnodemap_send
 #undef ctdb_getpublicips_send
 #undef ctdb_getdbseqnum_send
@@ -240,3 +241,46 @@ struct ctdb_request *ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
                                        destnode, &indata, sizeof(uint64_t),
                                        callback, private_data);
 }
+
+bool ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb,
+                                     struct ctdb_request *req,
+                                     uint32_t num, uint8_t *result)
+{
+       struct ctdb_reply_control *reply;
+       int i, count;
+
+       reply = unpack_reply_control(req, CTDB_CONTROL_CHECK_SRVIDS);
+       if (!reply) {
+               return false;
+       }
+       if (reply->status == -1) {
+               DEBUG(ctdb, LOG_ERR, "ctdb_check_message_handlers_recv: status -1");
+               return false;
+       }
+       
+       count = (num + 7) / 8;
+       if (count != reply->datalen) {
+               DEBUG(ctdb, LOG_ERR, "ctdb_check_message_handlers_recv: wrong amount of data returned, expected %d bytes for %d srvids but received %d bytes", count, num, reply->datalen);
+               return false;
+       }
+
+       for (i = 0; i < num; i++) {
+               result[i] = !!(reply->data[i / 8] & (1 << (i % 8)));
+       }
+
+       return true;
+}
+
+struct ctdb_request *
+ctdb_check_message_handlers_send(struct ctdb_connection *ctdb,
+                               uint32_t destnode,
+                               uint32_t num,
+                               uint64_t *mhs,
+                               ctdb_callback_t callback,
+                               void *private_data)
+{
+       return new_ctdb_control_request(ctdb, CTDB_CONTROL_CHECK_SRVIDS,
+                                       destnode,
+                                       mhs, num * sizeof(uint64_t) ,
+                                       callback, private_data);
+}
index 7c9949464b8ef75af850ce7469c0a2a6d8c4175f..6696283f04c123ff86b91e79f059abee2c1b5773 100644 (file)
@@ -136,6 +136,24 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb,
        return ret;
 }
 
+bool ctdb_check_message_handlers(struct ctdb_connection *ctdb,
+                     uint32_t destnode, uint32_t num,
+                     uint64_t *mhs, uint8_t *result)
+{
+       struct ctdb_request *req;
+       bool done = false;
+       bool ret = false;
+
+       req = synchronous(ctdb,
+                         ctdb_check_message_handlers_send(ctdb, destnode, num, mhs, set, &done),
+                         &done);
+       if (req != NULL) {
+               ret = ctdb_check_message_handlers_recv(ctdb, req, num, result);
+               ctdb_request_free(req);
+       }
+       return ret;
+}
+
 bool ctdb_getnodemap(struct ctdb_connection *ctdb,
                 uint32_t destnode, struct ctdb_node_map **nodemap)
 {