diff options
author | Martin Schwenke <martin@meltin.net> | 2016-01-21 12:53:43 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2016-01-25 07:18:25 +0100 |
commit | 411ccb98c3e1c3d6bd26e74874c03acb0d470454 (patch) | |
tree | 0db2739e29fad80e80721e5b7b25953efe744091 /ctdb/tools/ctdb.c | |
parent | e515968a51b9a8c1bb8ad59fb010a8736e2c6bd0 (diff) | |
download | samba-411ccb98c3e1c3d6bd26e74874c03acb0d470454.tar.gz |
ctdb/tools: Update ctdb CLI tool to call ctdb_natgw
The "natgwlist" command is no longer marked "auto all" and is also
marked "without daemon". That latter is not strictly true because
ctdb_natgw needs the daemon so a subsequent invocation of "ctdb
nodestatus" will work. However, "without daemon" is used here because
the top-level "ctdb natgwlist" does not need to open a connection to
the daemon. It just needs to invoke ctdb_natgw.
Update tests to suit.
It would make sense to make "ctdb natgw" generally call out to
ctdb_natgw, passing all argument. However, that can be done later.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tools/ctdb.c')
-rw-r--r-- | ctdb/tools/ctdb.c | 174 |
1 files changed, 13 insertions, 161 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 5874df2b35d..5a5bcbc4910 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -1150,31 +1150,6 @@ static int control_nodestatus(struct ctdb_context *ctdb, int argc, const char ** return ret; } -static struct ctdb_node_map_old *read_natgw_nodes_file(struct ctdb_context *ctdb, - TALLOC_CTX *mem_ctx) -{ - const char *natgw_list; - struct ctdb_node_map_old *natgw_nodes = NULL; - - natgw_list = getenv("CTDB_NATGW_NODES"); - if (natgw_list == NULL) { - natgw_list = talloc_asprintf(mem_ctx, "%s/natgw_nodes", - getenv("CTDB_BASE")); - if (natgw_list == NULL) { - DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n")); - exit(1); - } - } - /* The PNNs/flags will be junk but they're not used */ - natgw_nodes = ctdb_read_nodes_file(mem_ctx, natgw_list); - if (natgw_nodes == NULL) { - DEBUG(DEBUG_ERR, - ("Failed to load natgw node list '%s'\n", natgw_list)); - } - return natgw_nodes; -} - - /* talloc off the existing nodemap... */ static struct ctdb_node_map_old *talloc_nodemap(struct ctdb_node_map_old *nodemap) { @@ -1184,37 +1159,6 @@ static struct ctdb_node_map_old *talloc_nodemap(struct ctdb_node_map_old *nodema } static struct ctdb_node_map_old * -filter_nodemap_by_addrs(struct ctdb_context *ctdb, - struct ctdb_node_map_old *nodemap, - struct ctdb_node_map_old *natgw_nodes) -{ - int i, j; - struct ctdb_node_map_old *ret; - - ret = talloc_nodemap(nodemap); - CTDB_NO_MEMORY_NULL(ctdb, ret); - - ret->num = 0; - - for (i = 0; i < nodemap->num; i++) { - for(j = 0; j < natgw_nodes->num ; j++) { - if (nodemap->nodes[j].flags & NODE_FLAGS_DELETED) { - continue; - } - if (ctdb_same_ip(&natgw_nodes->nodes[j].addr, - &nodemap->nodes[i].addr)) { - - ret->nodes[ret->num] = nodemap->nodes[i]; - ret->num++; - break; - } - } - } - - return ret; -} - -static struct ctdb_node_map_old * filter_nodemap_by_capabilities(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodemap, uint32_t required_capabilities, @@ -1290,116 +1234,24 @@ filter_nodemap_by_flags(struct ctdb_context *ctdb, */ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **argv) { - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - int i, ret; - struct ctdb_node_map_old *natgw_nodes = NULL; - struct ctdb_node_map_old *orig_nodemap=NULL; - struct ctdb_node_map_old *nodemap; - uint32_t mypnn, pnn; - const char *ip; - - /* When we have some nodes that could be the NATGW, make a - * series of attempts to find the first node that doesn't have - * certain status flags set. - */ - uint32_t exclude_flags[] = { - /* Look for a nice healthy node */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_UNHEALTHY, - /* If not found, an UNHEALTHY/BANNED node will do */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED, - /* If not found, a STOPPED node will do */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_DELETED, - 0, - }; - - /* read the natgw nodes file into a linked list */ - natgw_nodes = read_natgw_nodes_file(ctdb, tmp_ctx); - if (natgw_nodes == NULL) { - ret = -1; - goto done; - } - - ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, - tmp_ctx, &orig_nodemap); - if (ret != 0) { - DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node.\n")); - talloc_free(tmp_ctx); - return -1; - } + static char prog[PATH_MAX+1] = ""; - /* Get a nodemap that includes only the nodes in the NATGW - * group */ - nodemap = filter_nodemap_by_addrs(ctdb, orig_nodemap, natgw_nodes); - if (nodemap == NULL) { - ret = -1; - goto done; - } - - ret = 2; /* matches ENOENT */ - pnn = -1; - ip = "0.0.0.0"; - /* For each flag mask... */ - for (i = 0; exclude_flags[i] != 0; i++) { - /* ... get a nodemap that excludes nodes with with - * masked flags... */ - struct ctdb_node_map_old *t = - filter_nodemap_by_flags(ctdb, nodemap, - exclude_flags[i]); - if (t == NULL) { - /* No memory */ - ret = -1; - goto done; - } - if (t->num > 0) { - /* ... and find the first node with the NATGW - * capability */ - struct ctdb_node_map_old *n; - n = filter_nodemap_by_capabilities(ctdb, t, - CTDB_CAP_NATGW, - true); - if (n == NULL) { - /* No memory */ - ret = -1; - goto done; - } - if (n->num > 0) { - ret = 0; - pnn = n->nodes[0].pnn; - ip = ctdb_addr_to_str(&n->nodes[0].addr); - break; - } - } - talloc_free(t); + if (argc != 0) { + usage(); } - if (options.machinereadable) { - printm(":Node:IP:\n"); - printm(":%d:%s:\n", pnn, ip); - } else { - printf("%d %s\n", pnn, ip); + if (!ctdb_set_helper("NAT gateway helper", prog, sizeof(prog), + "CTDB_NATGW_HELPER", CTDB_HELPER_BINDIR, + "ctdb_natgw")) { + DEBUG(DEBUG_ERR, ("Unable to set NAT gateway helper\n")); + exit(1); } - /* print the pruned list of nodes belonging to this natgw list */ - mypnn = getpnn(ctdb); - if (options.machinereadable) { - control_status_header_machine(); - } else { - printf("Number of nodes:%d\n", nodemap->num); - } - for(i=0;i<nodemap->num;i++){ - if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) { - continue; - } - if (options.machinereadable) { - control_status_1_machine(ctdb, mypnn, &(nodemap->nodes[i])); - } else { - control_status_1_human(ctdb, mypnn, &(nodemap->nodes[i])); - } - } + execl(prog, prog, "natgwlist", NULL); -done: - talloc_free(tmp_ctx); - return ret; + DEBUG(DEBUG_ERR, + ("Unable to run NAT gateway helper %s\n", strerror(errno))); + exit(1); } /* @@ -6558,7 +6410,7 @@ static const struct { { "scriptstatus", control_scriptstatus, true, false, "show the status of the monitoring scripts (or all scripts)", "[all]"}, { "enablescript", control_enablescript, true, false, "enable an eventscript", "<script>"}, { "disablescript", control_disablescript, true, false, "disable an eventscript", "<script>"}, - { "natgwlist", control_natgwlist, true, false, "show the nodes belonging to this natgw configuration"}, + { "natgwlist", control_natgwlist, false, true, "show the nodes belonging to this natgw configuration"}, { "xpnn", control_xpnn, false, true, "find the pnn of the local node without talking to the daemon (unreliable)" }, { "getreclock", control_getreclock, true, false, "Show the reclock file of a node"}, { "setreclock", control_setreclock, true, false, "Set/clear the reclock file of a node", "[filename]"}, |