ctdb-ipalloc: New function ipalloc_can_host_ips()
authorMartin Schwenke <martin@meltin.net>
Tue, 21 Jun 2016 11:16:27 +0000 (21:16 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 4 Jul 2016 13:42:25 +0000 (15:42 +0200)
Abstracts out code involving internals of IP allocation state.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c
ctdb/server/ipalloc.c
ctdb/server/ipalloc.h

index c45b218cc384d4c984dbac1cfb7168b63ea9ea56..efa466a77a0ff7e93e50422b29d1fbdddef20c57 100644 (file)
@@ -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;
        }
index 72e0fc4d34fee5b06f6a64a04593bc4043403742..868ac841bcb317bb4ea70a16d122d94933f0a26b 100644 (file)
@@ -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)
 {
index 06c69f87d0c2acac6b46bbe0855eb4d38841a97a..3d7d783d88732c83edb663dc93ea2acea932bcfa 100644 (file)
@@ -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__ */