IPALLOCATION : If the node is held pinned down in "init" state
[sahlberg/ctdb.git] / server / ctdb_takeover.c
index 27c9ac07234ec419fd2476d39ac78d21cb9dd836..1d6fe6e4b8ba13c4a71b447501d227674ebb4e19 100644 (file)
@@ -490,15 +490,6 @@ static int32_t ctdb_do_updateip(struct ctdb_context *ctdb,
                return -1;
        }
 
-       if (vnn->iface == old) {
-               DEBUG(DEBUG_ERR,("update of IP %s/%u trying to "
-                                "assin a same interface '%s'\n",
-                                ctdb_addr_to_str(&vnn->public_address),
-                                vnn->public_netmask_bits,
-                                old->name));
-               return -1;
-       }
-
        state = talloc(vnn, struct ctdb_do_updateip_state);
        CTDB_NO_MEMORY(ctdb, state);
 
@@ -603,14 +594,12 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
 
        if (vnn->iface == NULL && have_ip) {
                DEBUG(DEBUG_CRIT,(__location__ " takeoverip of IP %s is known to the kernel, "
-                                 "but we have no interface assigned, has someone manually configured it?"
-                                 "banning ourself\n",
+                                 "but we have no interface assigned, has someone manually configured it? Ignore for now.\n",
                                 ctdb_addr_to_str(&vnn->public_address)));
-               ctdb_ban_self(ctdb);
                return -1;
        }
 
-       if (vnn->pnn != ctdb->pnn && have_ip) {
+       if (vnn->pnn != ctdb->pnn && have_ip && vnn->pnn != -1) {
                DEBUG(DEBUG_CRIT,(__location__ " takeoverip of IP %s is known to the kernel, "
                                  "and we have it on iface[%s], but it was assigned to node %d"
                                  "and we are node %d, banning ourself\n",
@@ -620,6 +609,15 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
                return -1;
        }
 
+       if (vnn->pnn == -1 && have_ip) {
+               vnn->pnn = ctdb->pnn;
+               DEBUG(DEBUG_CRIT,(__location__ " takeoverip of IP %s is known to the kernel, "
+                                 "and we already have it on iface[%s], update local daemon\n",
+                                ctdb_addr_to_str(&vnn->public_address),
+                                 ctdb_vnn_iface_string(vnn)));
+               return 0;
+       }
+
        if (vnn->iface) {
                if (vnn->iface->link_up) {
                        /* only move when the rebalance gains something */
@@ -794,12 +792,10 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
        }
 
        if (vnn->iface == NULL) {
-               DEBUG(DEBUG_CRIT,(__location__ " release_ip of IP %s is known to the kernel, "
-                                 "but we have no interface assigned, has someone manually configured it?"
-                                 "banning ourself\n",
+               DEBUG(DEBUG_ERR,(__location__ " release_ip of IP %s is known to the kernel, "
+                                "but we have no interface assigned, has someone manually configured it? Ignore for now.\n",
                                 ctdb_addr_to_str(&vnn->public_address)));
-               ctdb_ban_self(ctdb);
-               return -1;
+               return 0;
        }
 
        DEBUG(DEBUG_NOTICE,("Release of IP %s/%u on interface %s  node:%d\n",
@@ -896,7 +892,7 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
        vnn->public_netmask_bits = mask;
        vnn->pnn                 = -1;
        if (ctdb_sys_have_ip(addr)) {
-               DEBUG(DEBUG_ERR,("We are already hosting public address '%s'\n", ctdb_addr_to_str(addr)));
+               DEBUG(DEBUG_ERR,("We are already hosting public address '%s'. setting PNN to ourself:%d\n", ctdb_addr_to_str(addr), ctdb->pnn));
                vnn->pnn = ctdb->pnn;
        }
 
@@ -1000,6 +996,7 @@ int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
                              const char *ip)
 {
        struct ctdb_vnn *svnn;
+       struct ctdb_iface *cur = NULL;
        bool ok;
        int ret;
 
@@ -1028,6 +1025,14 @@ int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
                return -1;
        }
 
+       /* assume the single public ip interface is initially "good" */
+       cur = ctdb_find_iface(ctdb, iface);
+       if (cur == NULL) {
+               DEBUG(DEBUG_CRIT,("Can not find public interface %s used by --single-public-ip", iface));
+               return -1;
+       }
+       cur->link_up = true;
+
        ret = ctdb_vnn_assign_iface(ctdb, svnn);
        if (ret != 0) {
                talloc_free(svnn);
@@ -1166,6 +1171,16 @@ static uint32_t *ip_key(ctdb_sock_addr *ip)
 
 static void *add_ip_callback(void *parm, void *data)
 {
+       struct ctdb_public_ip_list *this_ip = parm; 
+       struct ctdb_public_ip_list *prev_ip = data; 
+
+       if (prev_ip == NULL) {
+               return parm;
+       }
+       if (this_ip->pnn == -1) {
+               this_ip->pnn = prev_ip->pnn;
+       }
+
        return parm;
 }