client: New generic node listing function list_of_nodes()
authorMartin Schwenke <martin@meltin.net>
Tue, 19 Feb 2013 03:29:06 +0000 (14:29 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 20 Feb 2013 04:04:18 +0000 (15:04 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Cherry-pick-from: a73bb56991b8c07ed0e9517ffcf0dc264be30487

client/ctdb_client.c
include/ctdb_client.h

index 5e0660457e48ac730e359496d30fa7608c863c2b..7e2dd4a2c73930f4384f74141edc983939dce9b5 100644 (file)
@@ -3176,6 +3176,44 @@ uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
        return nodes;
 }
 
+/* Get list of nodes not including those with flags specified by mask.
+ * If exclude_pnn is not -1 then exclude that pnn from the list.
+ */
+uint32_t *list_of_nodes(struct ctdb_context *ctdb,
+                       struct ctdb_node_map *node_map,
+                       TALLOC_CTX *mem_ctx,
+                       uint32_t mask,
+                       int exclude_pnn)
+{
+       int i, j, num_nodes;
+       uint32_t *nodes;
+
+       for (i=num_nodes=0;i<node_map->num;i++) {
+               if (node_map->nodes[i].flags & mask) {
+                       continue;
+               }
+               if (node_map->nodes[i].pnn == exclude_pnn) {
+                       continue;
+               }
+               num_nodes++;
+       } 
+
+       nodes = talloc_array(mem_ctx, uint32_t, num_nodes);
+       CTDB_NO_MEMORY_FATAL(ctdb, nodes);
+
+       for (i=j=0;i<node_map->num;i++) {
+               if (node_map->nodes[i].flags & mask) {
+                       continue;
+               }
+               if (node_map->nodes[i].pnn == exclude_pnn) {
+                       continue;
+               }
+               nodes[j++] = node_map->nodes[i].pnn;
+       } 
+
+       return nodes;
+}
+
 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
                                struct ctdb_node_map *node_map,
                                TALLOC_CTX *mem_ctx,
index 3dc115f0ccd441ba72793cef30e1cba376e22e9d..94987911256017642c2e3e7d101fcafa388a27cd 100644 (file)
@@ -486,6 +486,11 @@ int ctdb_ctrl_setreclock(struct ctdb_context *ctdb,
        const char *reclock);
 
 
+uint32_t *list_of_nodes(struct ctdb_context *ctdb,
+                       struct ctdb_node_map *node_map,
+                       TALLOC_CTX *mem_ctx,
+                       uint32_t mask,
+                       int exclude_pnn);
 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
                                struct ctdb_node_map *node_map,
                                TALLOC_CTX *mem_ctx,