]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
use ctdb_get_connected_nodes for node listing
authorAndrew Tridgell <tridge@samba.org>
Sat, 28 Apr 2007 15:42:40 +0000 (17:42 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sat, 28 Apr 2007 15:42:40 +0000 (17:42 +0200)
(This used to be ctdb commit b4efdd1944207e51dccd6cd5e50f451a7dddcd91)

ctdb/common/ctdb.c
ctdb/common/ctdb_client.c
ctdb/include/ctdb.h
ctdb/tools/ctdb_control.c

index 63e5b6543848b5588bcdeb0836834012e1fa2f79..65b678fbcae736eb3168eebbc69345c700160c91 100644 (file)
@@ -105,6 +105,7 @@ static int ctdb_add_node(struct ctdb_context *ctdb, char *nstr)
 
        if (ctdb_same_address(&ctdb->address, &node->address)) {
                ctdb->vnn = node->vnn;
+               node->flags |= NODE_FLAGS_CONNECTED;
        }
 
        ctdb->num_nodes++;
index 18685cd25e5d97a48d0b4c6fd80d305a2a5e4884..3e3827ce69fd92a12da3fddab6d1d76b3a621d0a 100644 (file)
@@ -832,13 +832,15 @@ int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid
 /*
   get a list of nodes (vnn and flags ) from a remote node
  */
-int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap)
+int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, 
+                   TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap)
 {
        int ret;
        TDB_DATA data, outdata;
        int32_t i, res;
 
        ZERO_STRUCT(data);
+       ZERO_STRUCT(*nodemap);
        ret = ctdb_control(ctdb, destnode, 0, 
                           CTDB_CONTROL_GET_NODEMAP, data, 
                           ctdb, &outdata, &res);
@@ -848,15 +850,9 @@ int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_no
        }
 
        nodemap->num = ((uint32_t *)outdata.dptr)[0];
-       if (nodemap->nodes) {
-               talloc_free(nodemap->nodes);
-               nodemap->nodes=NULL;
-       }
-       nodemap->nodes=talloc_array(nodemap, struct ctdb_node_and_flags, nodemap->num);
-       if (!nodemap->nodes) {
-               DEBUG(0,(__location__ " failed to talloc nodemap\n"));
-               return -1;
-       }
+       nodemap->nodes=talloc_array(mem_ctx, struct ctdb_node_and_flags, nodemap->num);
+       CTDB_NO_MEMORY(ctdb, nodemap->nodes);
+
        for (i=0;i<nodemap->num;i++) {
                nodemap->nodes[i].vnn = ((uint32_t *)outdata.dptr)[2*i+1];
                nodemap->nodes[i].flags = ((uint32_t *)outdata.dptr)[2*i+2];
@@ -1019,3 +1015,42 @@ int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t l
        }
        return 0;
 }
+
+
+/*
+  get a list of connected nodes
+ */
+uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
+                                  uint32_t *num_nodes)
+{
+       struct ctdb_node_map *map;
+       int ret, i;
+       uint32_t *nodes;
+
+       *num_nodes = 0;
+
+       map = talloc(mem_ctx, struct ctdb_node_map);
+       CTDB_NO_MEMORY_VOID(ctdb, map);
+
+       ret = ctdb_getnodemap(ctdb, CTDB_CURRENT_NODE, map, map);
+       if (ret != 0) {
+               talloc_free(map);
+               return NULL;
+       }
+
+       nodes = talloc_array(mem_ctx, uint32_t, map->num);
+       if (nodes == NULL) {
+               talloc_free(map);
+               return NULL;
+       }
+
+       for (i=0;i<map->num;i++) {
+               if (map->nodes[i].flags & NODE_FLAGS_CONNECTED) {
+                       nodes[*num_nodes] = map->nodes[i].vnn;
+                       (*num_nodes)++;
+               }
+       }
+
+       talloc_free(map);
+       return nodes;
+}
index 7dba352a46ffb374277c7c56b3ba6a857a4c7b79..d512fc0e1a6944f1964afccee11ee376726bfe8e 100644 (file)
@@ -239,7 +239,8 @@ struct ctdb_node_map {
        uint32_t num;
        struct ctdb_node_and_flags *nodes;
 };
-int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap);
+int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, 
+                   TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap);
 
 int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
 
@@ -252,4 +253,7 @@ int ctdb_get_config(struct ctdb_context *ctdb);
 int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
 int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
 
+uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
+                                  uint32_t *num_nodes);
+
 #endif
index 7809f1406fb851f03fb99c4bbcd4551af623fbe1..601a8cb5514811ba134401056cd588f8631389cc 100644 (file)
@@ -112,18 +112,24 @@ static int control_status_all(struct ctdb_context *ctdb)
 {
        int ret, i;
        struct ctdb_status status;
+       uint32_t *nodes;
+       uint32_t num_nodes;
+
+       nodes = ctdb_get_connected_nodes(ctdb, ctdb, &num_nodes);
+       CTDB_NO_MEMORY(ctdb, nodes);
+       
        ZERO_STRUCT(status);
 
-       for (i=0;i<ctdb->num_nodes;i++) {
+       for (i=0;i<num_nodes;i++) {
                struct ctdb_status s1;
                int j;
                uint32_t *v1 = (uint32_t *)&s1;
                uint32_t *v2 = (uint32_t *)&status;
                uint32_t num_ints = 
                        offsetof(struct ctdb_status, __last_uint32) / sizeof(uint32_t);
-               ret = ctdb_status(ctdb, i, &s1);
+               ret = ctdb_status(ctdb, nodes[i], &s1);
                if (ret != 0) {
-                       printf("Unable to get status from node %u\n", i);
+                       printf("Unable to get status from node %u\n", nodes[i]);
                        return ret;
                }
                for (j=0;j<num_ints;j++) {
@@ -136,6 +142,8 @@ static int control_status_all(struct ctdb_context *ctdb)
                status.max_lockwait_latency = 
                        MAX(status.max_lockwait_latency, s1.max_lockwait_latency);
        }
+       talloc_free(nodes);
+       printf("Gathered status for %u nodes\n", num_nodes);
        show_status(&status);
        return 0;
 }
@@ -245,7 +253,7 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char **
        vnn = strtoul(argv[0], NULL, 0);
 
        nodemap = talloc_zero(ctdb, struct ctdb_node_map);
-       ret = ctdb_getnodemap(ctdb, vnn, nodemap);
+       ret = ctdb_getnodemap(ctdb, vnn, nodemap, nodemap);
        if (ret != 0) {
                printf("Unable to get nodemap from node %u\n", vnn);
                talloc_free(nodemap);
@@ -296,17 +304,23 @@ static int control_setvnnmap(struct ctdb_context *ctdb, int argc, const char **a
 static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
 {
        int ret, i;
+       uint32_t *nodes;
+       uint32_t num_nodes;
+
+       nodes = ctdb_get_connected_nodes(ctdb, ctdb, &num_nodes);
+       CTDB_NO_MEMORY(ctdb, nodes);
 
-       for (i=0;i<ctdb->num_nodes;i++) {
+       for (i=0;i<num_nodes;i++) {
                struct timeval tv = timeval_current();
-               ret = ctdb_ping(ctdb, i);
+               ret = ctdb_ping(ctdb, nodes[i]);
                if (ret == -1) {
-                       printf("Unable to get ping response from node %u\n", i);
+                       printf("Unable to get ping response from node %u\n", nodes[i]);
                } else {
                        printf("response from %u time=%.6f sec  (%d clients)\n", 
-                              i, timeval_elapsed(&tv), ret);
+                              nodes[i], timeval_elapsed(&tv), ret);
                }
        }
+       talloc_free(nodes);
        return 0;
 }
 
@@ -317,16 +331,23 @@ static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
 static int control_debuglevel(struct ctdb_context *ctdb, int argc, const char **argv)
 {
        int ret, i;
+       uint32_t *nodes;
+       uint32_t num_nodes;
+
+       nodes = ctdb_get_connected_nodes(ctdb, ctdb, &num_nodes);
+       CTDB_NO_MEMORY(ctdb, nodes);
 
-       for (i=0;i<ctdb->num_nodes;i++) {
+       for (i=0;i<num_nodes;i++) {
                uint32_t level;
-               ret = ctdb_get_debuglevel(ctdb, i, &level);
+               ret = ctdb_get_debuglevel(ctdb, nodes[i], &level);
                if (ret != 0) {
-                       printf("Unable to get debuglevel response from node %u\n", i);
+                       printf("Unable to get debuglevel response from node %u\n", 
+                               nodes[i]);
                } else {
-                       printf("Node %u is at debug level %u\n", i, level);
+                       printf("Node %u is at debug level %u\n", nodes[i], level);
                }
        }
+       talloc_free(nodes);
        return 0;
 }
 
@@ -337,6 +358,8 @@ static int control_debug(struct ctdb_context *ctdb, int argc, const char **argv)
 {
        int ret;
        uint32_t vnn, level, i;
+       uint32_t *nodes;
+       uint32_t num_nodes;
 
        if (argc < 2) {
                usage();
@@ -344,23 +367,26 @@ static int control_debug(struct ctdb_context *ctdb, int argc, const char **argv)
 
        level = strtoul(argv[1], NULL, 0);
 
-       if (strcmp(argv[0], "all") == 0) {
-               for (i=0;i<ctdb->num_nodes;i++) {
-                       ret = ctdb_set_debuglevel(ctdb, i, level);
-                       if (ret != 0) {
-                               printf("Unable to set debug level on node %u\n", i);
-                               break;
-                       }
+       if (strcmp(argv[0], "all") != 0) {
+               vnn = strtoul(argv[0], NULL, 0);
+               ret = ctdb_set_debuglevel(ctdb, vnn, level);
+               if (ret != 0) {
+                       printf("Unable to set debug level on node %u\n", vnn);
                }
+               
                return 0;
        }
 
-       vnn = strtoul(argv[0], NULL, 0);
-       ret = ctdb_set_debuglevel(ctdb, vnn, level);
-       if (ret != 0) {
-               printf("Unable to set debug level on node %u\n", vnn);
+       nodes = ctdb_get_connected_nodes(ctdb, ctdb, &num_nodes);
+       CTDB_NO_MEMORY(ctdb, nodes);
+       for (i=0;i<num_nodes;i++) {
+               ret = ctdb_set_debuglevel(ctdb, nodes[i], level);
+               if (ret != 0) {
+                       printf("Unable to set debug level on node %u\n", nodes[i]);
+                       break;
+               }
        }
-
+       talloc_free(nodes);
        return 0;
 }