From 7425b9cdf2ddadbb51bbbe18669e5272b34568ea Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 12 Nov 2013 15:16:49 +1100 Subject: [PATCH] recoverd: Fix backward compatibility for CTDB_SRVID_TAKEOVER_RUN When running a mixed version cluster, compatibility with older versions was was broken during recent refactorisation. Signed-off-by: Martin Schwenke Pair-programmed-with: Amitay Isaacs --- include/ctdb_private.h | 7 ++++++- server/ctdb_recoverd.c | 14 +++++++------- tools/ctdb.c | 41 +++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/include/ctdb_private.h b/include/ctdb_private.h index b4966b88..279fa2f4 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -24,11 +24,16 @@ #include /* - * 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; }; diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c index d5b36acc..6820ec92 100644 --- a/server/ctdb_recoverd.c +++ b/server/ctdb_recoverd.c @@ -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 */ diff --git a/tools/ctdb.c b/tools/ctdb.c index 7d1563cf..e906a693 100644 --- a/tools/ctdb.c +++ b/tools/ctdb.c @@ -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); -- 2.34.1