From cd20ced3fb9c71d38450f90224677f21a27d2548 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 13 Dec 2016 11:16:05 +1100 Subject: [PATCH] ctdb-tools: Don't trust non-hosting nodes in "ctdb ip all" 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 Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Fri Dec 16 12:32:02 CET 2016 on sn-devel-144 --- ctdb/tools/ctdb.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 83693add172..5f172effcb6 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -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; + } + } } }