ctdb-ipalloc: New enum ipalloc_algorithm in ipalloc_state
authorMartin Schwenke <martin@meltin.net>
Thu, 29 Oct 2015 08:41:10 +0000 (19:41 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 20 Nov 2015 00:36:31 +0000 (01:36 +0100)
Algorithm-related tunables from the CTDB context no longer need to be
accessed in the allocation logic.

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

index 1e30daf82b6b7daa5001de71edf753a99c42f78a..c49e05ceac64778ce83331d5c6b3c8b01d22355b 100644 (file)
@@ -53,12 +53,20 @@ struct ctdb_ipflags {
        bool noiphost;
 };
 
+enum ipalloc_algorithm {
+       IPALLOC_DETERMINISTIC,
+       IPALLOC_NONDETERMINISTIC,
+       IPALLOC_LCP2,
+};
+
 struct ipalloc_state {
        uint32_t num;
 
        /* Arrays with data for each node */
        struct ctdb_public_ip_list_old **known_public_ips;
        struct ctdb_public_ip_list_old **available_public_ips;
+
+       enum ipalloc_algorithm algorithm;
 };
 
 struct ctdb_interface {
@@ -2214,12 +2222,16 @@ static void ctdb_takeover_run_core(struct ctdb_context *ctdb,
        */
        *all_ips_p = create_merged_ip_list(ctdb);
 
-        if (1 == ctdb->tunable.lcp2_public_ip_assignment) {
+       switch (ctdb->ipalloc_state->algorithm) {
+       case IPALLOC_LCP2:
                ip_alloc_lcp2(ctdb, ipflags, *all_ips_p, force_rebalance_nodes);
-       } else if (1 == ctdb->tunable.deterministic_public_ips) {
+               break;
+       case IPALLOC_DETERMINISTIC:
                ip_alloc_deterministic_ips(ctdb, ipflags, *all_ips_p);
-       } else {
+               break;
+       case IPALLOC_NONDETERMINISTIC:
                ip_alloc_nondeterministic_ips(ctdb, ipflags, *all_ips_p);
+               break;
        }
 
        /* at this point ->pnn is the node which will own each IP
@@ -2462,6 +2474,14 @@ static struct ipalloc_state * ipalloc_state_init(struct ctdb_context *ctdb,
                return NULL;
        }
 
+       if (1 == ctdb->tunable.lcp2_public_ip_assignment) {
+               ipalloc_state->algorithm = IPALLOC_LCP2;
+       } else if (1 == ctdb->tunable.deterministic_public_ips) {
+               ipalloc_state->algorithm = IPALLOC_DETERMINISTIC;
+       } else {
+               ipalloc_state->algorithm = IPALLOC_NONDETERMINISTIC;
+       }
+
        return ipalloc_state;
 }