summaryrefslogtreecommitdiffstats
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-02-18 17:11:53 +1100
committerAmitay Isaacs <amitay@samba.org>2014-03-23 04:20:14 +0100
commit33b1fcbd7083668cfd58b1cfb1172b6134cd07ca (patch)
treea9530a086a3d5a7cdd15a538e0c8f030ec541e62 /ctdb
parent798bd58370f6ea7bc70db96edd23ae86caf6bf79 (diff)
downloadsamba-33b1fcbd7083668cfd58b1cfb1172b6134cd07ca.tar.gz
samba-33b1fcbd7083668cfd58b1cfb1172b6134cd07ca.tar.xz
samba-33b1fcbd7083668cfd58b1cfb1172b6134cd07ca.zip
ctdb-tools-ctdb: Generalise find_natgw() -> filter_nodemap_by_flags()
Instead of just finding the first node that doesn't have any flags in flag_mask set, change it into a function that filters a nodemap to exclude nodes with the given flags. This makes the NATGW code simpler but also provides a function that can be used in other code. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/tools/ctdb.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 4bb794e9f8e..3eef1e21179 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -1166,22 +1166,29 @@ filter_nodemap_by_capabilities(struct ctdb_context *ctdb,
return ret;
}
-
-static int find_natgw(struct ctdb_context *ctdb,
- struct ctdb_node_map *nodemap, uint32_t flags,
- uint32_t *pnn, const char **ip)
+static struct ctdb_node_map *
+filter_nodemap_by_flags(struct ctdb_context *ctdb,
+ struct ctdb_node_map *nodemap,
+ uint32_t flags_mask)
{
int i;
+ struct ctdb_node_map *ret;
- for (i=0;i<nodemap->num;i++) {
- if (!(nodemap->nodes[i].flags & flags)) {
- *pnn = nodemap->nodes[i].pnn;
- *ip = ctdb_addr_to_str(&nodemap->nodes[i].addr);
- return 0;
+ ret = talloc_nodemap(nodemap);
+ CTDB_NO_MEMORY_NULL(ctdb, ret);
+
+ ret->num = 0;
+
+ for (i = 0; i < nodemap->num; i++) {
+ if (nodemap->nodes[i].flags & flags_mask) {
+ continue;
}
+
+ ret->nodes[ret->num] = nodemap->nodes[i];
+ ret->num++;
}
- return 2; /* matches ENOENT */
+ return ret;
}
/*
@@ -1300,15 +1307,21 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
pnn = -1;
ip = "0.0.0.0";
for (i = 0; exclude_flags[i] != 0; i++) {
- ret = find_natgw(ctdb, cnodemap,
- exclude_flags[i],
- &pnn, &ip);
- if (ret == -1) {
+ struct ctdb_node_map *t =
+ filter_nodemap_by_flags(ctdb, cnodemap,
+ exclude_flags[i]);
+ if (t == NULL) {
+ /* No memory */
+ ret = -1;
goto done;
}
- if (ret == 0) {
+ if (t->num > 0) {
+ ret = 0;
+ pnn = t->nodes[0].pnn;
+ ip = ctdb_addr_to_str(&t->nodes[0].addr);
break;
}
+ talloc_free(t);
}
if (options.machinereadable) {