summaryrefslogtreecommitdiffstats
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-02-19 18:45:18 +1100
committerAmitay Isaacs <amitay@samba.org>2014-03-23 04:20:14 +0100
commite728a35dc19c397cb17e1bf434401df25c35f337 (patch)
tree5ebb4bac41c719494f77e6c7dcb0d1bcf836bc5e /ctdb
parent26c9a591e539e33dd0896ec1e2958192b3e4efd4 (diff)
downloadsamba-e728a35dc19c397cb17e1bf434401df25c35f337.tar.gz
samba-e728a35dc19c397cb17e1bf434401df25c35f337.tar.xz
samba-e728a35dc19c397cb17e1bf434401df25c35f337.zip
ctdb-tools-ctdb: Update LVS commands to use filter_nodemap_by_flags()
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.c108
1 files changed, 41 insertions, 67 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 758fd9343af..5040012b4fb 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -3539,13 +3539,21 @@ static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const ch
/*
display lvs configuration
*/
+
+static uint32_t lvs_exclude_flags[] = {
+ /* Look for a nice healthy node */
+ NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED,
+ /* If not found, an UNHEALTHY node will do */
+ NODE_FLAGS_INACTIVE|NODE_FLAGS_PERMANENTLY_DISABLED,
+ 0,
+};
+
static int control_lvs(struct ctdb_context *ctdb, int argc, const char **argv)
{
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
struct ctdb_node_map *orig_nodemap=NULL;
struct ctdb_node_map *nodemap;
int i, ret;
- int healthy_count = 0;
ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn,
tmp_ctx, &orig_nodemap);
@@ -3565,39 +3573,26 @@ static int control_lvs(struct ctdb_context *ctdb, int argc, const char **argv)
ret = 0;
- /* collect capabilities for all connected nodes */
- for (i=0; i<nodemap->num; i++) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
- continue;
- }
- if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
- continue;
- }
-
- if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
- healthy_count++;
- }
- }
-
- /* Print all LVS nodes */
- for (i=0; i<nodemap->num; i++) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
- continue;
- }
- if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
- continue;
+ for (i = 0; lvs_exclude_flags[i] != 0; i++) {
+ struct ctdb_node_map *t =
+ filter_nodemap_by_flags(ctdb, nodemap,
+ lvs_exclude_flags[i]);
+ if (t == NULL) {
+ /* No memory */
+ ret = -1;
+ goto done;
}
-
- if (healthy_count != 0) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
- continue;
+ if (t->num > 0) {
+ /* At least 1 node without excluded flags */
+ int j;
+ for (j = 0; j < t->num; j++) {
+ printf("%d:%s\n", t->nodes[j].pnn,
+ ctdb_addr_to_str(&t->nodes[j].addr));
}
+ goto done;
}
-
- printf("%d:%s\n", nodemap->nodes[i].pnn,
- ctdb_addr_to_str(&nodemap->nodes[i].addr));
+ talloc_free(t);
}
-
done:
talloc_free(tmp_ctx);
return ret;
@@ -3612,7 +3607,6 @@ static int control_lvsmaster(struct ctdb_context *ctdb, int argc, const char **a
struct ctdb_node_map *orig_nodemap=NULL;
struct ctdb_node_map *nodemap;
int i, ret;
- int healthy_count = 0;
ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn,
tmp_ctx, &orig_nodemap);
@@ -3630,47 +3624,27 @@ static int control_lvsmaster(struct ctdb_context *ctdb, int argc, const char **a
goto done;
}
- /* collect capabilities for all connected nodes */
- for (i=0; i<nodemap->num; i++) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
- continue;
- }
- if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
- continue;
- }
-
- if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
- healthy_count++;
- }
- }
-
- ret = -1;
-
- /* find and show the lvsmaster */
- for (i=0; i<nodemap->num; i++) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
- continue;
- }
- if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
- continue;
- }
- if (healthy_count != 0) {
- if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
- continue;
- }
+ for (i = 0; lvs_exclude_flags[i] != 0; i++) {
+ struct ctdb_node_map *t =
+ filter_nodemap_by_flags(ctdb, nodemap,
+ lvs_exclude_flags[i]);
+ if (t == NULL) {
+ /* No memory */
+ ret = -1;
+ goto done;
}
-
- if (options.machinereadable){
- printf("%d\n", nodemap->nodes[i].pnn);
- } else {
- printf("Node %d is LVS master\n",
- nodemap->nodes[i].pnn);
+ if (t->num > 0) {
+ ret = 0;
+ printf(options.machinereadable ?
+ "%d\n" : "Node %d is LVS master\n",
+ t->nodes[0].pnn);
+ goto done;
}
- ret = 0;
- goto done;
+ talloc_free(t);
}
printf("There is no LVS master\n");
+ ret = 255;
done:
talloc_free(tmp_ctx);
return ret;