diff options
| author | Andrew Tridgell <tridge@samba.org> | 2007-04-28 17:42:40 +0200 |
|---|---|---|
| committer | Andrew Tridgell <tridge@samba.org> | 2007-04-28 17:42:40 +0200 |
| commit | c885b159f4d90448d8d963af330ca2efb8b7f8a6 (patch) | |
| tree | 401c992788004d66000ea39e324ed932238afb03 | |
| parent | 4b6d00974d0c27ce8c7a399b21bfa6dcf9db7d0c (diff) | |
| download | samba-c885b159f4d90448d8d963af330ca2efb8b7f8a6.tar.gz samba-c885b159f4d90448d8d963af330ca2efb8b7f8a6.tar.xz samba-c885b159f4d90448d8d963af330ca2efb8b7f8a6.zip | |
use ctdb_get_connected_nodes for node listing
(This used to be ctdb commit b4efdd1944207e51dccd6cd5e50f451a7dddcd91)
| -rw-r--r-- | ctdb/common/ctdb.c | 1 | ||||
| -rw-r--r-- | ctdb/common/ctdb_client.c | 55 | ||||
| -rw-r--r-- | ctdb/include/ctdb.h | 6 | ||||
| -rw-r--r-- | ctdb/tools/ctdb_control.c | 74 |
4 files changed, 101 insertions, 35 deletions
diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 63e5b65438..65b678fbca 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -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++; diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 18685cd25e..3e3827ce69 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -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; +} diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 7dba352a46..d512fc0e1a 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -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 diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 7809f1406f..601a8cb551 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -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; } |
