ctdb-ipalloc: Move set_ipflags_internal() to ipalloc
authorMartin Schwenke <martin@meltin.net>
Wed, 22 Jun 2016 03:18:04 +0000 (13:18 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 4 Jul 2016 13:42:25 +0000 (15:42 +0200)
Rename it ipalloc_set_node_flags().

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
ctdb/tests/src/ctdb_takeover_tests.c

index 5b4f7958a90e97dc2eb8301b7a2382f5b26e6bef..b696599579f4e9e5899af4bcdccd7ef727ca24ce 100644 (file)
@@ -1185,21 +1185,6 @@ ctdb_fetch_remote_public_ips(struct ctdb_context *ctdb,
        return public_ips;
 }
 
-static bool all_nodes_are_disabled(struct ctdb_node_map *nodemap)
-{
-       int i;
-
-       for (i=0;i<nodemap->num;i++) {
-               if (!(nodemap->node[i].flags &
-                     (NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED))) {
-                       /* Found one completely healthy node */
-                       return false;
-               }
-       }
-
-       return true;
-}
-
 struct get_tunable_callback_data {
        const char *tunable;
        uint32_t *out;
@@ -1312,55 +1297,6 @@ static uint32_t *get_tunable_from_nodes(struct ctdb_context *ctdb,
        return tvals;
 }
 
-/* Set internal flags for IP allocation:
- *   Clear ip flags
- *   Set NOIPTAKOVER ip flags from per-node NoIPTakeover tunable
- *   Set NOIPHOST ip flag for each INACTIVE node
- *   if all nodes are disabled:
- *     Set NOIPHOST ip flags from per-node NoIPHostOnAllDisabled tunable
- *   else
- *     Set NOIPHOST ip flags for disabled nodes
- */
-static void set_ipflags_internal(struct ipalloc_state *ipalloc_state,
-                                struct ctdb_node_map *nodemap,
-                                uint32_t *tval_noiptakeover,
-                                uint32_t *tval_noiphostonalldisabled)
-{
-       int i;
-
-       for (i=0;i<nodemap->num;i++) {
-               /* Can not take IPs on node with NoIPTakeover set */
-               if (tval_noiptakeover[i] != 0) {
-                       ipalloc_state->noiptakeover[i] = true;
-               }
-
-               /* Can not host IPs on INACTIVE node */
-               if (nodemap->node[i].flags & NODE_FLAGS_INACTIVE) {
-                       ipalloc_state->noiphost[i] = true;
-               }
-       }
-
-       if (all_nodes_are_disabled(nodemap)) {
-               /* If all nodes are disabled, can not host IPs on node
-                * with NoIPHostOnAllDisabled set
-                */
-               for (i=0;i<nodemap->num;i++) {
-                       if (tval_noiphostonalldisabled[i] != 0) {
-                               ipalloc_state->noiphost[i] = true;
-                       }
-               }
-       } else {
-               /* If some nodes are not disabled, then can not host
-                * IPs on DISABLED node
-                */
-               for (i=0;i<nodemap->num;i++) {
-                       if (nodemap->node[i].flags & NODE_FLAGS_DISABLED) {
-                               ipalloc_state->noiphost[i] = true;
-                       }
-               }
-       }
-}
-
 static struct ctdb_node_map *
 ctdb_node_map_old_to_new(TALLOC_CTX *mem_ctx,
                         const struct ctdb_node_map_old *old)
@@ -1409,7 +1345,7 @@ static bool set_ipflags(struct ctdb_context *ctdb,
                return false;
        }
 
-       set_ipflags_internal(ipalloc_state, new,
+       ipalloc_set_node_flags(ipalloc_state, new,
                             tval_noiptakeover,
                             tval_noiphostonalldisabled);
 
@@ -1531,12 +1467,10 @@ static void takeover_run_process_failures(struct ctdb_context *ctdb,
  *   + 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).
- * - Retrieve tunables NoIPTakeover and NoIPHostOnAllDisabled from all
- *   connected nodes - this is done separately so tunable values can
- *   be faked in unit testing
- * - Populate NoIPTakover tunable in IP allocation state
- * - Populate NoIPHost in IP allocation state, derived from node flags
- *   and NoIPHostOnAllDisabled tunable
+ * - Set IP flags for IP allocation based on node map and tunables
+ *   NoIPTakeover/NoIPHostOnAllDisabled from all connected nodes
+ *   (tunable fetching done separately so values can be faked in unit
+ *   testing)
  * - Retrieve known and available IP addresses (done separately so
  *   values can be faked in unit testing)
  * - Use ipalloc_set_public_ips() to set known and available IP
@@ -1592,7 +1526,8 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem
        }
 
        if (!set_ipflags(ctdb, ipalloc_state, nodemap)) {
-               DEBUG(DEBUG_ERR,("Failed to set IP flags - aborting takeover run\n"));
+               DEBUG(DEBUG_ERR,
+                     ("Failed to set IP flags - aborting takeover run\n"));
                talloc_free(tmp_ctx);
                return -1;
        }
index b1a74bcfd1b2ff23d55d652cd95840d34c61f1f9..de6d94268ddd159a3ae641b760ba66c4cfc31473 100644 (file)
@@ -161,6 +161,70 @@ create_merged_ip_list(struct ipalloc_state *ipalloc_state,
        return ip_list;
 }
 
+static bool all_nodes_are_disabled(struct ctdb_node_map *nodemap)
+{
+       int i;
+
+       for (i=0;i<nodemap->num;i++) {
+               if (!(nodemap->node[i].flags &
+                     (NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED))) {
+                       /* Found one completely healthy node */
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+/* Set internal flags for IP allocation:
+ *   Clear ip flags
+ *   Set NOIPTAKOVER ip flags from per-node NoIPTakeover tunable
+ *   Set NOIPHOST ip flag for each INACTIVE node
+ *   if all nodes are disabled:
+ *     Set NOIPHOST ip flags from per-node NoIPHostOnAllDisabled tunable
+ *   else
+ *     Set NOIPHOST ip flags for disabled nodes
+ */
+void ipalloc_set_node_flags(struct ipalloc_state *ipalloc_state,
+                           struct ctdb_node_map *nodemap,
+                           uint32_t *tval_noiptakeover,
+                           uint32_t *tval_noiphostonalldisabled)
+{
+       int i;
+
+       for (i=0;i<nodemap->num;i++) {
+               /* Can not take IPs on node with NoIPTakeover set */
+               if (tval_noiptakeover[i] != 0) {
+                       ipalloc_state->noiptakeover[i] = true;
+               }
+
+               /* Can not host IPs on INACTIVE node */
+               if (nodemap->node[i].flags & NODE_FLAGS_INACTIVE) {
+                       ipalloc_state->noiphost[i] = true;
+               }
+       }
+
+       if (all_nodes_are_disabled(nodemap)) {
+               /* If all nodes are disabled, can not host IPs on node
+                * with NoIPHostOnAllDisabled set
+                */
+               for (i=0;i<nodemap->num;i++) {
+                       if (tval_noiphostonalldisabled[i] != 0) {
+                               ipalloc_state->noiphost[i] = true;
+                       }
+               }
+       } else {
+               /* If some nodes are not disabled, then can not host
+                * IPs on DISABLED node
+                */
+               for (i=0;i<nodemap->num;i++) {
+                       if (nodemap->node[i].flags & NODE_FLAGS_DISABLED) {
+                               ipalloc_state->noiphost[i] = true;
+                       }
+               }
+       }
+}
+
 bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state,
                            struct ctdb_public_ip_list *known_ips,
                            struct ctdb_public_ip_list *available_ips)
index bb3ef1e5bfc3d8b29ba5eed4a6d067366fcc9931..243d6af0c3a5c184d41b2adf3677eb565e195b0d 100644 (file)
@@ -63,6 +63,11 @@ struct ipalloc_state * ipalloc_state_init(TALLOC_CTX *mem_ctx,
                                          bool no_ip_failback,
                                          uint32_t *force_rebalance_nodes);
 
+void ipalloc_set_node_flags(struct ipalloc_state *ipalloc_state,
+                           struct ctdb_node_map *nodemap,
+                           uint32_t *tval_noiptakeover,
+                           uint32_t *tval_noiphostonalldisabled);
+
 bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state,
                            struct ctdb_public_ip_list *known_ips,
                            struct ctdb_public_ip_list *available_ips);
index 20d4b3404fa18f7b1a7b1d24b7ab76d43222876b..d564e7b338c76323aa44dd3e21048265bfd0f6c9 100644 (file)
@@ -286,12 +286,6 @@ static void ctdb_test_init(const char nodestates[],
                }
        }
 
-       tval_noiptakeover = get_tunable_values(*ctdb, nodemap->num,
-                                              "CTDB_SET_NoIPTakeover");
-       tval_noiptakeoverondisabled =
-               get_tunable_values(*ctdb, nodemap->num,
-                                  "CTDB_SET_NoIPHostOnAllDisabled");
-
        (*ctdb)->nodes = talloc_array(*ctdb, struct ctdb_node *, nodemap->num); // FIXME: bogus size, overkill
 
        *ipalloc_state = ipalloc_state_init(*ctdb, nodemap->num,
@@ -313,9 +307,17 @@ static void ctdb_test_init(const char nodestates[],
                exit(1);
        }
 
-       set_ipflags_internal(*ipalloc_state, nodemap,
-                            tval_noiptakeover,
-                            tval_noiptakeoverondisabled);
+       tval_noiptakeover = get_tunable_values(*ctdb, nodemap->num,
+                                              "CTDB_SET_NoIPTakeover");
+       assert(tval_noiptakeover != NULL);
+       tval_noiptakeoverondisabled =
+               get_tunable_values(*ctdb, nodemap->num,
+                                  "CTDB_SET_NoIPHostOnAllDisabled");
+       assert(tval_noiptakeoverondisabled != NULL);
+
+       ipalloc_set_node_flags(*ipalloc_state, nodemap,
+                              tval_noiptakeover,
+                              tval_noiptakeoverondisabled);
 }
 
 /* IP layout is read from stdin.  See comment for ctdb_test_init() for