From d91b28f8b749d516f31a0e13d4da4c1e3441c96c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 7 Sep 2007 16:45:19 +1000 Subject: [PATCH] ctdb ip must loop over all connected nodes to pull hte public ip list and merge into a big list since with the deassociation between a node and a public ipaddress the /etc/ctdb/public_addresses files can differ between nodes and no node know about all public addresses that a cluster can use (This used to be ctdb commit e208294fed183977cacc44b2cd1195c11d967c18) --- ctdb/tools/ctdb.c | 75 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 0417b27943d..1da8a32d09e 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -25,6 +25,7 @@ #include "cmdline.h" #include "../include/ctdb.h" #include "../include/ctdb_private.h" +#include "../common/rb_tree.h" static void usage(void); @@ -519,44 +520,76 @@ static int tickle_tcp(struct ctdb_context *ctdb, int argc, const char **argv) return -1; } + +static void *store_ip(void *p, void *d) +{ + return p; +} +static void print_ip(void *param, void *data) +{ + struct ctdb_public_ip *ip = (struct ctdb_public_ip *)data; + + if(options.machinereadable){ + printf(":%s:%d:\n", inet_ntoa(ip->sin.sin_addr), ip->pnn); + } else { + printf("%-16s %d\n", inet_ntoa(ip->sin.sin_addr), ip->pnn); + } +} + /* display public ip status */ static int control_ip(struct ctdb_context *ctdb, int argc, const char **argv) { - int i, ret; + int i, j, ret; + TALLOC_CTX *tmp_ctx = talloc_new(ctdb); + trbt_tree_t *tree; + struct ctdb_node_map *nodemap=NULL; struct ctdb_all_public_ips *ips; - int mypnn; + struct ctdb_public_ip *ip; - mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn); - if (mypnn == -1) { - return -1; - } - ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), options.pnn, ctdb, &ips); + ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &nodemap); if (ret != 0) { - DEBUG(0, ("Unable to get public ips from node %u\n", options.pnn)); + DEBUG(0, ("Unable to get nodemap from node %u\n", options.pnn)); + talloc_free(tmp_ctx); return ret; } - if(options.machinereadable){ - printf(":Public IP:Node:\n"); - for(i=0;inum;i++){ - printf(":%s:%d:\n", - inet_ntoa(ips->ips[i].sin.sin_addr), - ips->ips[i].pnn); + /* create a tree to store the public addresses in indexed by s_addr */ + tree = trbt_create(tmp_ctx, 0); + CTDB_NO_MEMORY(ctdb, tree); + + for (i=0;inum;i++) { + /* dont read the public ip list from disconnected nodes */ + if (nodemap->nodes[i].flags & NODE_FLAGS_DISCONNECTED) { + continue; + } + + /* read the public ip list from this node */ + ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), i, tmp_ctx, &ips); + if (ret != 0) { + DEBUG(0, ("Unable to get public ips from node %u\n", i)); + talloc_free(tmp_ctx); + return ret; } - return 0; - } - printf("Number of addresses:%d\n", ips->num); - for(i=0;inum;i++){ - printf("%-16s %d\n", - inet_ntoa(ips->ips[i].sin.sin_addr), - ips->ips[i].pnn); + /* store the public ip */ + for(j=0;jnum;j++){ + ip = talloc_memdup(tmp_ctx, &ips->ips[j], sizeof(struct ctdb_public_ip)); + /* ntohl() so that we sort by the first octet */ + trbt_insert32_callback(tree, ntohl(ips->ips[j].sin.sin_addr.s_addr), store_ip, ip); + } + } + + /* traverse the tree and read back all the public ips one by one */ + if(options.machinereadable){ + printf(":Public IP:Node:\n"); } + trbt_traversearray32(tree, 1, print_ip, NULL); + talloc_free(tmp_ctx); return 0; } -- 2.47.3