]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:ctdbd_conn: add ctdbd_nodes_foreach() helper
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Jul 2026 16:01:41 +0000 (18:01 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 4 Aug 2026 09:51:32 +0000 (09:51 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/ctdbd_conn.h
source3/lib/ctdbd_conn.c

index c3b049ec14c23f77df045dc21199dec8ec4cb5a9..94e99d43f5830a01d547d64323edb972151a43b7 100644 (file)
@@ -28,6 +28,7 @@
 #include <tevent.h>
 
 struct ctdbd_connection;
+struct ctdb_node_and_flags;
 struct messaging_context;
 struct messaging_rec;
 struct cluster_level_active;
@@ -41,6 +42,12 @@ int ctdbd_init_async_connection(
        int timeout,
        struct ctdbd_connection **pconn);
 
+int ctdbd_nodes_foreach(struct ctdbd_connection *conn,
+                       int (*cb)(uint32_t total_nodes_count,
+                                 const struct ctdb_node_and_flags *nf,
+                                 void *private_data),
+                       void *private_data);
+
 int ctdbd_generation(struct ctdbd_connection *conn, uint32_t *generation);
 const struct cluster_level_active *ctdbd_conn_get_cluster_level(
                                        struct ctdbd_connection *conn);
index 4e584371d90ad98836feca9c8c4b2da55f397b36..82c1b9f727e3db27eb4063a01add7149d5572f3c 100644 (file)
@@ -379,6 +379,60 @@ static int ctdbd_control_get_nodemap(struct ctdbd_connection *conn,
        return 0;
 }
 
+/*
+ * This includes all nodes without NODE_FLAGS_DELETED
+ * of the whole cluster.
+ */
+int ctdbd_nodes_foreach(struct ctdbd_connection *conn,
+                       int (*cb)(uint32_t total_nodes_count,
+                                 const struct ctdb_node_and_flags *nf,
+                                 void *private_data),
+                       void *private_data)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct ctdb_node_map_old *nodemap = NULL;
+       int ret = ENOMEM;
+       uint32_t total_nodes_count = 0;
+       uint32_t i;
+
+       ret = ctdbd_control_get_nodemap(conn, frame, &nodemap);
+       if (ret != 0) {
+               DBG_WARNING("ctdbd_control_get_nodemap() failed: %s\n",
+                           strerror(ret));
+               TALLOC_FREE(frame);
+               return -1;
+       }
+
+       for (i = 0; i < nodemap->num; i++) {
+               const struct ctdb_node_and_flags *nf = &nodemap->nodes[i];
+
+               if (nf->flags & NODE_FLAGS_DELETED) {
+                       continue;
+               }
+
+               total_nodes_count += 1;
+       }
+
+       for (i = 0; i < nodemap->num; i++) {
+               const struct ctdb_node_and_flags *nf = &nodemap->nodes[i];
+
+               if (nf->flags & NODE_FLAGS_DELETED) {
+                       continue;
+               }
+
+               ret = cb(total_nodes_count,
+                        nf,
+                        private_data);
+               if (ret != 0) {
+                       TALLOC_FREE(frame);
+                       return ret;
+               }
+       }
+
+       TALLOC_FREE(frame);
+       return 0;
+}
+
 int ctdbd_generation(struct ctdbd_connection *conn, uint32_t *generation)
 {
        struct ctdb_vnn_map *vnnmap = NULL;