From: Stefan Metzmacher Date: Fri, 24 Jul 2026 16:01:41 +0000 (+0200) Subject: s3:ctdbd_conn: add ctdbd_nodes_foreach() helper X-Git-Tag: samba-4.25.0rc1~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=603709c4e24cd3340fd5d48bd100313929a1a1da;p=thirdparty%2Fsamba.git s3:ctdbd_conn: add ctdbd_nodes_foreach() helper Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h index c3b049ec14c..94e99d43f58 100644 --- a/source3/include/ctdbd_conn.h +++ b/source3/include/ctdbd_conn.h @@ -28,6 +28,7 @@ #include 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); diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 4e584371d90..82c1b9f727e 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -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;