ctdb-tools: Don't trust non-hosting nodes in "ctdb ip all"
authorMartin Schwenke <martin@meltin.net>
Tue, 13 Dec 2016 00:16:05 +0000 (11:16 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 16 Dec 2016 11:32:02 +0000 (12:32 +0100)
Redundant RELEASE_IPs gives nodes a preview of where an IP address
will move to.  However, if the associated TAKEOVER_IP fails then the
node will actually be unhosted.

This is similar to commit 77a29b37334b9df62b755b6f538fb975e105e1ff.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12470

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Fri Dec 16 12:32:02 CET 2016 on sn-devel-144

ctdb/tools/ctdb.c

index 83693add17233fd0327b3182922437faab8df1d8..5f172effcb64686bdf8826220975b74c65c9a92b 100644 (file)
@@ -1536,11 +1536,34 @@ static int get_all_public_ips(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
                        ip.pnn = ips->ip[j].pnn;
                        ip.addr = ips->ip[j].addr;
 
-                       ret = db_hash_add(ipdb, (uint8_t *)&ip.addr,
-                                         sizeof(ip.addr),
-                                         (uint8_t *)&ip, sizeof(ip));
-                       if (ret != 0) {
-                               goto failed;
+                       if (pnn_list[i] == ip.pnn) {
+                               /* Node claims IP is hosted on it, so
+                                * save that information
+                                */
+                               ret = db_hash_add(ipdb, (uint8_t *)&ip.addr,
+                                                 sizeof(ip.addr),
+                                                 (uint8_t *)&ip, sizeof(ip));
+                               if (ret != 0) {
+                                       goto failed;
+                               }
+                       } else {
+                               /* Node thinks IP is hosted elsewhere,
+                                * so overwrite with CTDB_UNKNOWN_PNN
+                                * if there's no existing entry
+                                */
+                               ret = db_hash_exists(ipdb, (uint8_t *)&ip.addr,
+                                                    sizeof(ip.addr));
+                               if (ret == ENOENT) {
+                                       ip.pnn = CTDB_UNKNOWN_PNN;
+                                       ret = db_hash_add(ipdb,
+                                                         (uint8_t *)&ip.addr,
+                                                         sizeof(ip.addr),
+                                                         (uint8_t *)&ip,
+                                                         sizeof(ip));
+                                       if (ret != 0) {
+                                               goto failed;
+                                       }
+                               }
                        }
                }