libctdb: add ctdb_getcapabilities()
authorMartin Schwenke <martin@meltin.net>
Wed, 18 Jul 2012 04:24:08 +0000 (14:24 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 28 Sep 2012 07:05:34 +0000 (17:05 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 140fafef23050d40d66f5b5558c7efcb78f80cd2)

ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/include/ctdb_protocol.h
ctdb/libctdb/control.c
ctdb/libctdb/sync.c

index 93224cbdaa63277e95f029e42d91816f28e0baec..c3da06897cbc3f825002cf74556876da070ca0d7 100644 (file)
@@ -584,6 +584,35 @@ ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb,
                                  uint8_t *result);
 
 
+/**
+ * ctdb_getcapabilities_send - read the capabilities of a node
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @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_getcapabilities_send(struct ctdb_connection *ctdb,
+                         uint32_t destnode,
+                         ctdb_callback_t callback, void *cbdata);
+
+/**
+ * ctdb_getcapabilities_recv - read an ctdb_getcapabilities reply from ctdbd
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @req: the completed request.
+ * @capabilities: a pointer to the capabilities to fill in
+ *
+ * This returns false if something went wrong, or otherwise fills in
+ * capabilities.
+ */
+bool ctdb_getcapabilities_recv(struct ctdb_connection *ctdb,
+                              struct ctdb_request *handle,
+                              uint32_t *capabilities);
+
 /**
  * ctdb_getdbseqnum_send - read the sequence number off a db
  * @ctdb: the ctdb_connection from ctdb_connect.
@@ -949,6 +978,23 @@ ctdb_check_message_handlers(struct ctdb_connection *ctdb,
                           uint64_t *mhs,
                           uint8_t *result);
 
+/**
+ * ctdb_getcapabilities - read the capabilities of a node (synchronous)
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @capabilities: a pointer to the capabilities to fill in
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ *
+ * Returns true and fills in *capabilities on success.
+ */
+bool ctdb_getcapabilities(struct ctdb_connection *ctdb,
+                         uint32_t destnode,
+                         uint32_t *capabilities);
+
+
 /**
  * ctdb_getdbseqnum - read the seqnum of a database
  * @ctdb: the ctdb_connection from ctdb_connect.
@@ -1145,6 +1191,10 @@ void ctdb_free_vnnmap(struct ctdb_vnn_map *vnnmap);
        ctdb_getpnn_send((ctdb), (destnode),                            \
                         ctdb_sendcb((cb), (cbdata)), (cbdata))
 
+#define ctdb_getcapabilities_send(ctdb, destnode, cb, cbdata)          \
+       ctdb_getcapabilities_send((ctdb), (destnode),                   \
+                                 ctdb_sendcb((cb), (cbdata)), (cbdata))
+
 #define ctdb_getdbstat_send(ctdb, destnode, db_id, cb, cbdata)         \
        ctdb_getdbstat_send((ctdb), (destnode), (db_id),                \
                            ctdb_sendcb((cb), (cbdata)), (cbdata))
index 0f9da360c61c5c1144e0c1d291b661308f682bbb..984dc355a8855712e5c03ccc08e4dd499ca6ff53 100644 (file)
@@ -394,14 +394,6 @@ enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN
 #define CTDB_MONITORING_ACTIVE         0
 #define CTDB_MONITORING_DISABLED       1
 
-/* The different capabilities of the ctdb daemon. */
-#define CTDB_CAP_RECMASTER             0x00000001
-#define CTDB_CAP_LMASTER               0x00000002
-/* This capability is set if CTDB_LVS_PUBLIC_IP is set */
-#define CTDB_CAP_LVS                   0x00000004
-/* This capability is set if NATGW is enabled */
-#define CTDB_CAP_NATGW                 0x00000008
-
 #define NUM_DB_PRIORITIES 3
 /* main state of the ctdb daemon */
 struct ctdb_context {
index 33187c78428655a6a48ec8d0fdc06b4023c99824..96827563c1fe82db0713e0c9ae844530dcf0f591 100644 (file)
@@ -568,6 +568,17 @@ struct ctdb_node_map {
 #define NODE_FLAGS_NOIPTAKEOVER                0x01000000 /* this node can takeover any new ip addresses, this flag is ONLY valid within the recovery daemon */
 
 
+/*
+ * Node capabilities
+ */
+#define CTDB_CAP_RECMASTER             0x00000001
+#define CTDB_CAP_LMASTER               0x00000002
+/* This capability is set if CTDB_LVS_PUBLIC_IP is set */
+#define CTDB_CAP_LVS                   0x00000004
+/* This capability is set if NATGW is enabled */
+#define CTDB_CAP_NATGW                 0x00000008
+
+
 struct ctdb_public_ip {
        uint32_t pnn;
        ctdb_sock_addr addr;
index e8a5cd71eabded349135ec27a286e7561c565268..176c48c896f655061fe534e84663592f03ceb03f 100644 (file)
@@ -33,6 +33,7 @@
 #undef ctdb_getdbseqnum_send
 #undef ctdb_getifaces_send
 #undef ctdb_getvnnmap_send
+#undef ctdb_getcapabilities_send
 
 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
                           struct ctdb_request *req, uint32_t *recmaster)
@@ -515,3 +516,30 @@ struct ctdb_request *ctdb_getvnnmap_send(struct ctdb_connection *ctdb,
                                        NULL, 0, callback, private_data);
 }
 
+bool ctdb_getcapabilities_recv(struct ctdb_connection *ctdb,
+                              struct ctdb_request *req, uint32_t *capabilities)
+{
+       struct ctdb_reply_control *reply;
+
+       reply = unpack_reply_control(req, CTDB_CONTROL_GET_CAPABILITIES);
+       if (!reply) {
+               return false;
+       }
+       if (reply->status == -1) {
+               DEBUG(ctdb, LOG_ERR, "ctdb_getcapabilities_recv: status -1");
+               return false;
+       }
+       *capabilities = *((uint32_t *)reply->data);
+       return true;
+}
+
+struct ctdb_request *ctdb_getcapabilities_send(struct ctdb_connection *ctdb,
+                                              uint32_t destnode,
+                                              ctdb_callback_t callback,
+                                              void *private_data)
+{
+       return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_CAPABILITIES,
+                                       destnode,
+                                       NULL, 0, callback, private_data);
+}
+
index 0e175f7f1296f911a401c680db352fd7a2d71dc0..9a827476e988fdc2d8b2557f1341ab1a416924b8 100644 (file)
@@ -338,3 +338,20 @@ bool ctdb_getvnnmap(struct ctdb_connection *ctdb,
        return ret;
 }
 
+bool ctdb_getcapabilities(struct ctdb_connection *ctdb,
+                         uint32_t destnode, uint32_t *capabilities)
+{
+       struct ctdb_request *req;
+       bool done = false;
+       bool ret = false;
+
+       req = synchronous(ctdb,
+                         ctdb_getcapabilities_send(ctdb, destnode, set, &done),
+                         &done);
+       if (req != NULL) {
+               ret = ctdb_getcapabilities_recv(ctdb, req, capabilities);
+               ctdb_request_free(req);
+       }
+       return ret;
+}
+