From: Andrew Tridgell Date: Sat, 28 Apr 2007 15:42:40 +0000 (+0200) Subject: use ctdb_get_connected_nodes for node listing X-Git-Tag: tevent-0.9.20~348^2~2815 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c885b159f4d90448d8d963af330ca2efb8b7f8a6;p=thirdparty%2Fsamba.git use ctdb_get_connected_nodes for node listing (This used to be ctdb commit b4efdd1944207e51dccd6cd5e50f451a7dddcd91) --- diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 63e5b654384..65b678fbcae 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 18685cd25e5..3e3827ce69f 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;inum;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;inum;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 7dba352a46f..d512fc0e1a6 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 7809f1406fb..601a8cb5514 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;inum_nodes;i++) { + for (i=0;inum_nodes;i++) { + for (i=0;inum_nodes;i++) { + for (i=0;inum_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