client: Add ctdb_client_check_message_handlers() function
authorAmitay Isaacs <amitay@gmail.com>
Fri, 23 Aug 2013 06:51:26 +0000 (16:51 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 4 Oct 2013 05:15:34 +0000 (15:15 +1000)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
client/ctdb_client.c
include/ctdb_client.h

index 57dc9ba0025d22f46a5ab925371e2135f4926544..42645133bff7b2a3a76ed9929dfa2a34229b6940 100644 (file)
@@ -511,6 +511,41 @@ int ctdb_client_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid
        return 0;
 }
 
+/*
+ * check server ids
+ */
+int ctdb_client_check_message_handlers(struct ctdb_context *ctdb, uint64_t *ids, uint32_t num,
+                                      uint8_t *result)
+{
+       TDB_DATA indata, outdata;
+       int res;
+       int32_t status;
+       int i;
+
+       indata.dptr = (uint8_t *)ids;
+       indata.dsize = num * sizeof(*ids);
+
+       res = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CHECK_SRVIDS, 0,
+                          indata, ctdb, &outdata, &status, NULL, NULL);
+       if (res != 0 || status != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " failed to check srvids\n"));
+               return -1;
+       }
+
+       if (outdata.dsize != num*sizeof(uint8_t)) {
+               DEBUG(DEBUG_ERR, (__location__ " expected %lu bytes, received %zi bytes\n",
+                                 num*sizeof(uint8_t), outdata.dsize));
+               talloc_free(outdata.dptr);
+               return -1;
+       }
+
+       for (i=0; i<num; i++) {
+               result[i] = outdata.dptr[i];
+       }
+
+       talloc_free(outdata.dptr);
+       return 0;
+}
 
 /*
   send a message - from client context
index 28f0aae884c7685337a8ccdffcffb47af9096b42..f21167a710a56a41ee02a49f2c8472d85eeab63e 100644 (file)
@@ -159,7 +159,9 @@ int ctdb_client_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
                             void *private_data);
 int ctdb_client_remove_message_handler(struct ctdb_context *ctdb,
                                       uint64_t srvid, void *private_data);
-
+int ctdb_client_check_message_handlers(struct ctdb_context *ctdb,
+                                      uint64_t *ids, uint32_t num,
+                                      uint8_t *result);
 
 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);