From c5d85a071b33ac8a80ae8f6ddaf26f9fa7bc67a6 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 21 Jun 2016 21:16:27 +1000 Subject: [PATCH] ctdb-ipalloc: New function ipalloc_can_host_ips() Abstracts out code involving internals of IP allocation state. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/server/ctdb_takeover.c | 12 ++---------- ctdb/server/ipalloc.c | 13 +++++++++++++ ctdb/server/ipalloc.h | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index c45b218cc38..efa466a77a0 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -1543,7 +1543,7 @@ static void takeover_run_process_failures(struct ctdb_context *ctdb, * values can be faked in unit testing) * - Use ipalloc_set_public_ips() to set known and available IP addresses for allocation - * - If no available IP addresses then early exit + * - If cluster can't host IP addresses then early exit * - Populate list of nodes to force rebalance - internal structure, * currently no way to fetch, only used by LCP2 for nodes that have * had new IP addresses added @@ -1567,7 +1567,6 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem struct ipalloc_state *ipalloc_state; struct ctdb_public_ip_list *known_ips, *available_ips; struct takeover_callback_data *takeover_data; - bool can_host_ips; /* Initialise fail callback data to be used with * takeover_run_fail_callback(). A failure in any of the @@ -1624,14 +1623,7 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem return -1; } - /* Short-circuit IP allocation if no node has available IPs */ - can_host_ips = false; - for (i=0; i < ipalloc_state->num; i++) { - if (ipalloc_state->available_public_ips[i].num != 0) { - can_host_ips = true; - } - } - if (!can_host_ips) { + if (! ipalloc_can_host_ips(ipalloc_state)) { DEBUG(DEBUG_WARNING,("No nodes available to host public IPs yet\n")); goto ipreallocated; } diff --git a/ctdb/server/ipalloc.c b/ctdb/server/ipalloc.c index 72e0fc4d34f..868ac841bcb 100644 --- a/ctdb/server/ipalloc.c +++ b/ctdb/server/ipalloc.c @@ -129,6 +129,19 @@ bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state, return (ipalloc_state->all_ips != NULL); } +bool ipalloc_can_host_ips(struct ipalloc_state *ipalloc_state) +{ + int i; + + for (i=0; i < ipalloc_state->num; i++) { + if (ipalloc_state->available_public_ips[i].num != 0) { + return true; + } + } + + return false; +} + /* The calculation part of the IP allocation algorithm. */ bool ipalloc(struct ipalloc_state *ipalloc_state) { diff --git a/ctdb/server/ipalloc.h b/ctdb/server/ipalloc.h index 06c69f87d0c..3d7d783d887 100644 --- a/ctdb/server/ipalloc.h +++ b/ctdb/server/ipalloc.h @@ -59,6 +59,8 @@ bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state, struct ctdb_public_ip_list *known_ips, struct ctdb_public_ip_list *available_ips); +bool ipalloc_can_host_ips(struct ipalloc_state *ipalloc_state); + bool ipalloc(struct ipalloc_state *ipalloc_state); #endif /* __CTDB_IPALLOC_H__ */