ctdb-recoverd: Fix backward compatibility for CTDB_SRVID_TAKEOVER_RUN
authorMartin Schwenke <martin@meltin.net>
Tue, 12 Nov 2013 04:16:49 +0000 (15:16 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 27 Nov 2013 17:46:16 +0000 (18:46 +0100)
When running a mixed version cluster, compatibility with older
versions was was broken during recent refactorisation.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_recoverd.c
ctdb/tools/ctdb.c

index b4966b8807ce070f16dc4f48e2873f6d6b7eefec..279fa2f44ada48c8001f43e8607a7fe39f63e8d0 100644 (file)
 #include <sys/socket.h>
 
 /*
- * Structure to support SRVID requests and replies
+ * Structures to support SRVID requests and replies
  */
 struct srvid_request {
        uint32_t pnn;
        uint64_t srvid;
+};
+
+struct srvid_request_data {
+       uint32_t pnn;
+       uint64_t srvid;
        uint32_t data;
 };
 
index d5b36acc19a04d341e1f617fa5601de652bc002c..6820ec92f201e4c2e762da9f01c7823d53f9e425 100644 (file)
@@ -1652,7 +1652,7 @@ static bool do_takeover_run(struct ctdb_recoverd *rec,
                            bool banning_credits_on_fail)
 {
        uint32_t *nodes = NULL;
-       struct srvid_request dtr;
+       struct srvid_request_data dtr;
        TDB_DATA data;
        int i;
        uint32_t *rebalance_nodes = rec->force_rebalance_nodes;
@@ -2470,13 +2470,13 @@ static void disable_takeover_runs_handler(struct ctdb_context *ctdb,
 {
        struct ctdb_recoverd *rec = talloc_get_type(private_data,
                                                    struct ctdb_recoverd);
-       struct srvid_request *r;
+       struct srvid_request_data *r;
        uint32_t timeout;
        TDB_DATA result;
        int32_t ret = 0;
 
        /* Validate input data */
-       if (data.dsize != sizeof(struct srvid_request)) {
+       if (data.dsize != sizeof(struct srvid_request_data)) {
                DEBUG(DEBUG_ERR,(__location__ " Wrong size for data :%lu "
                                 "expecting %lu\n", (long unsigned)data.dsize,
                                 (long unsigned)sizeof(struct srvid_request)));
@@ -2487,7 +2487,7 @@ static void disable_takeover_runs_handler(struct ctdb_context *ctdb,
                return;
        }
 
-       r = (struct srvid_request *)data.dptr;
+       r = (struct srvid_request_data *)data.dptr;
        timeout = r->data;
 
        if (timeout == 0) {
@@ -2537,7 +2537,7 @@ static void disable_takeover_runs_handler(struct ctdb_context *ctdb,
 done:
        result.dsize = sizeof(int32_t);
        result.dptr  = (uint8_t *)&ret;
-       srvid_request_reply(ctdb, r, result);
+       srvid_request_reply(ctdb, (struct srvid_request *)r, result);
 }
 
 /* Backward compatibility for this SRVID - call
@@ -2549,7 +2549,7 @@ static void disable_ip_check_handler(struct ctdb_context *ctdb, uint64_t srvid,
        struct ctdb_recoverd *rec = talloc_get_type(private_data,
                                                    struct ctdb_recoverd);
        TDB_DATA data2;
-       struct srvid_request *req;
+       struct srvid_request_data *req;
 
        if (data.dsize != sizeof(uint32_t)) {
                DEBUG(DEBUG_ERR,(__location__ " Wrong size for data :%lu "
@@ -2562,7 +2562,7 @@ static void disable_ip_check_handler(struct ctdb_context *ctdb, uint64_t srvid,
                return;
        }
 
-       req = talloc(ctdb, struct srvid_request);
+       req = talloc(ctdb, struct srvid_request_data);
        CTDB_NO_MEMORY_VOID(ctdb, req);
 
        req->srvid = 0; /* No reply */
index 7d1563cf1207e6de6097c4b2e7cbd7474b5e1d50..e906a6939cfc1e5dea17534b16f8f6e077767944 100644 (file)
@@ -2128,12 +2128,15 @@ static void srvid_broadcast_reply_handler(struct ctdb_context *ctdb,
  * pass in the srvid_request structure - pass 0 if this isn't needed.
  */
 static int srvid_broadcast(struct ctdb_context *ctdb,
-                          uint64_t srvid, uint32_t arg,
+                          uint64_t srvid, uint32_t *arg,
                           const char *srvid_str, bool wait_for_all)
 {
        int ret;
        TDB_DATA data;
+       uint32_t pnn;
+       uint64_t reply_srvid;
        struct srvid_request request;
+       struct srvid_request_data request_data;
        struct srvid_reply_handler_data reply_data;
        struct timeval tv;
 
@@ -2144,18 +2147,29 @@ static int srvid_broadcast(struct ctdb_context *ctdb,
                                timeval_current_ofs(1, 0),
                                ctdb_every_second, ctdb);
 
-       request.pnn = ctdb_get_pnn(ctdb);
-       request.srvid = getpid();
-       request.data = arg;
+       pnn = ctdb_get_pnn(ctdb);
+       reply_srvid = getpid();
+
+       if (arg == NULL) {
+               request.pnn = pnn;
+               request.srvid = reply_srvid;
+
+               data.dptr = (uint8_t *)&request;
+               data.dsize = sizeof(request);
+       } else {
+               request_data.pnn = pnn;
+               request_data.srvid = reply_srvid;
+               request_data.data = *arg;
+
+               data.dptr = (uint8_t *)&request_data;
+               data.dsize = sizeof(request_data);
+       }
 
        /* Register message port for reply from recovery master */
-       ctdb_client_set_message_handler(ctdb, request.srvid,
+       ctdb_client_set_message_handler(ctdb, reply_srvid,
                                        srvid_broadcast_reply_handler,
                                        &reply_data);
 
-       data.dptr = (uint8_t *)&request;
-       data.dsize = sizeof(request);
-
        reply_data.wait_for_all = wait_for_all;
        reply_data.nodes = NULL;
        reply_data.srvid_str = srvid_str;
@@ -2211,7 +2225,7 @@ again:
                goto again;
        }
 
-       ctdb_client_remove_message_handler(ctdb, request.srvid, &reply_data);
+       ctdb_client_remove_message_handler(ctdb, reply_srvid, &reply_data);
 
        talloc_free(reply_data.nodes);
 
@@ -2220,7 +2234,7 @@ again:
 
 static int ipreallocate(struct ctdb_context *ctdb)
 {
-       return srvid_broadcast(ctdb, CTDB_SRVID_TAKEOVER_RUN, 0,
+       return srvid_broadcast(ctdb, CTDB_SRVID_TAKEOVER_RUN, NULL,
                               "IP reallocation", false);
 }
 
@@ -4409,6 +4423,7 @@ static int control_reloadips(struct ctdb_context *ctdb, int argc, const char **a
        TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
        uint32_t *nodes;
        uint32_t pnn_mode;
+       uint32_t timeout;
        int ret;
 
        assert_single_node_only();
@@ -4434,7 +4449,8 @@ again:
         * there are disconnected nodes.  However, this should
         * probably be left up to the administrator.
         */
-       srvid_broadcast(ctdb, CTDB_SRVID_DISABLE_TAKEOVER_RUNS, LONGTIMEOUT,
+       timeout = LONGTIMEOUT;
+       srvid_broadcast(ctdb, CTDB_SRVID_DISABLE_TAKEOVER_RUNS, &timeout,
                        "Disable takeover runs", true);
 
        /* Now tell all the desired nodes to reload their public IPs.
@@ -4453,7 +4469,8 @@ again:
        /* It isn't strictly necessary to wait until takeover runs are
         * re-enabled but doing so can't hurt.
         */
-       srvid_broadcast(ctdb, CTDB_SRVID_DISABLE_TAKEOVER_RUNS, 0,
+       timeout = 0;
+       srvid_broadcast(ctdb, CTDB_SRVID_DISABLE_TAKEOVER_RUNS, &timeout,
                        "Enable takeover runs", true);
 
        ipreallocate(ctdb);