From ee7fc252c879fc8e490a8073118713fc9ad41a59 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 23 May 2016 14:28:33 +1000 Subject: [PATCH] ctdb-ipalloc: Move ipalloc state initialisation to ipalloc.c Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/server/ctdb_takeover.c | 43 ------------------------------------ ctdb/server/ipalloc.c | 44 +++++++++++++++++++++++++++++++++++++ ctdb/server/ipalloc.h | 8 +++++++ 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 209ecbac2ca..00e06715c5e 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -1403,49 +1403,6 @@ determine_algorithm(const struct ctdb_tunable_list *tunables) } } -static struct ipalloc_state * -ipalloc_state_init(TALLOC_CTX *mem_ctx, - uint32_t num_nodes, - enum ipalloc_algorithm algorithm, - bool no_ip_failback, - uint32_t *force_rebalance_nodes) -{ - struct ipalloc_state *ipalloc_state = - talloc_zero(mem_ctx, struct ipalloc_state); - if (ipalloc_state == NULL) { - DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); - return NULL; - } - - ipalloc_state->num = num_nodes; - - ipalloc_state->noiptakeover = - talloc_zero_array(ipalloc_state, - bool, - ipalloc_state->num); - if (ipalloc_state->noiptakeover == NULL) { - DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); - goto fail; - } - ipalloc_state->noiphost = - talloc_zero_array(ipalloc_state, - bool, - ipalloc_state->num); - if (ipalloc_state->noiphost == NULL) { - DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); - goto fail; - } - - ipalloc_state->algorithm = algorithm; - ipalloc_state->no_ip_failback = no_ip_failback; - ipalloc_state->force_rebalance_nodes = force_rebalance_nodes; - - return ipalloc_state; -fail: - talloc_free(ipalloc_state); - return NULL; -} - struct takeover_callback_data { uint32_t num_nodes; unsigned int *fail_count; diff --git a/ctdb/server/ipalloc.c b/ctdb/server/ipalloc.c index 295671a924f..b1a74bcfd1b 100644 --- a/ctdb/server/ipalloc.c +++ b/ctdb/server/ipalloc.c @@ -31,6 +31,50 @@ #include "server/ipalloc_private.h" +/* Initialise main ipalloc state and sub-structures */ +struct ipalloc_state * +ipalloc_state_init(TALLOC_CTX *mem_ctx, + uint32_t num_nodes, + enum ipalloc_algorithm algorithm, + bool no_ip_failback, + uint32_t *force_rebalance_nodes) +{ + struct ipalloc_state *ipalloc_state = + talloc_zero(mem_ctx, struct ipalloc_state); + if (ipalloc_state == NULL) { + DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); + return NULL; + } + + ipalloc_state->num = num_nodes; + + ipalloc_state->noiptakeover = + talloc_zero_array(ipalloc_state, + bool, + ipalloc_state->num); + if (ipalloc_state->noiptakeover == NULL) { + DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); + goto fail; + } + ipalloc_state->noiphost = + talloc_zero_array(ipalloc_state, + bool, + ipalloc_state->num); + if (ipalloc_state->noiphost == NULL) { + DEBUG(DEBUG_ERR, (__location__ " Out of memory\n")); + goto fail; + } + + ipalloc_state->algorithm = algorithm; + ipalloc_state->no_ip_failback = no_ip_failback; + ipalloc_state->force_rebalance_nodes = force_rebalance_nodes; + + return ipalloc_state; +fail: + talloc_free(ipalloc_state); + return NULL; +} + static void *add_ip_callback(void *parm, void *data) { struct public_ip_list *this_ip = parm; diff --git a/ctdb/server/ipalloc.h b/ctdb/server/ipalloc.h index 990fca46d1c..bb3ef1e5bfc 100644 --- a/ctdb/server/ipalloc.h +++ b/ctdb/server/ipalloc.h @@ -22,6 +22,8 @@ #ifndef __CTDB_IPALLOC_H__ #define __CTDB_IPALLOC_H__ +#include + #include "replace.h" #include "system/network.h" @@ -55,6 +57,12 @@ struct ipalloc_state { uint32_t *force_rebalance_nodes; }; +struct ipalloc_state * ipalloc_state_init(TALLOC_CTX *mem_ctx, + uint32_t num_nodes, + enum ipalloc_algorithm algorithm, + bool no_ip_failback, + uint32_t *force_rebalance_nodes); + bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state, struct ctdb_public_ip_list *known_ips, struct ctdb_public_ip_list *available_ips);