From fe97d04f18084c6ac76106fce28e55db4b72b8cc Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 5 Jul 2024 17:45:44 +1000 Subject: [PATCH] ctdb-tests: Use ctdb_read_nodes() in the fake ctdbd Remove unused copy of ctdb_read_nodes_file(). Signed-off-by: Martin Schwenke Reviewed-by: Anoop C S --- ctdb/tests/src/fake_ctdbd.c | 107 ++---------------------------------- ctdb/wscript | 12 +++- 2 files changed, 13 insertions(+), 106 deletions(-) diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c index 522b5509cb0..cceba225bb9 100644 --- a/ctdb/tests/src/fake_ctdbd.c +++ b/ctdb/tests/src/fake_ctdbd.c @@ -45,6 +45,8 @@ #include "common/srvid.h" #include "common/system.h" +#include "conf/node.h" + #include "ipalloc_read_known_ips.h" @@ -284,107 +286,6 @@ fail: } -/* Append a node to a node map with given address and flags */ -static bool node_map_add(struct ctdb_node_map *nodemap, - const char *nstr, uint32_t flags) -{ - ctdb_sock_addr addr; - uint32_t num; - struct ctdb_node_and_flags *n; - int ret; - - ret = ctdb_sock_addr_from_string(nstr, &addr, false); - if (ret != 0) { - fprintf(stderr, "Invalid IP address %s\n", nstr); - return false; - } - ctdb_sock_addr_set_port(&addr, CTDB_PORT); - - num = nodemap->num; - nodemap->node = talloc_realloc(nodemap, nodemap->node, - struct ctdb_node_and_flags, num+1); - if (nodemap->node == NULL) { - return false; - } - - n = &nodemap->node[num]; - n->addr = addr; - n->pnn = num; - n->flags = flags; - - nodemap->num = num+1; - return true; -} - -/* Read a nodes file into a node map */ -static struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx, - const char *nlist) -{ - char **lines; - int nlines; - int i; - struct ctdb_node_map *nodemap; - - nodemap = talloc_zero(mem_ctx, struct ctdb_node_map); - if (nodemap == NULL) { - return NULL; - } - - lines = file_lines_load(nlist, &nlines, 0, mem_ctx); - if (lines == NULL) { - return NULL; - } - - while (nlines > 0 && strcmp(lines[nlines-1], "") == 0) { - nlines--; - } - - for (i=0; i 1) && - ((node[len-1] == ' ') || (node[len-1] == '\t'))) - { - node[len-1] = '\0'; - len--; - } - - if (len == 0) { - continue; - } - if (*node == '#') { - /* A "deleted" node is a node that is - commented out in the nodes file. This is - used instead of removing a line, which - would cause subsequent nodes to change - their PNN. */ - flags = NODE_FLAGS_DELETED; - node = discard_const("0.0.0.0"); - } else { - flags = 0; - } - if (! node_map_add(nodemap, node, flags)) { - talloc_free(lines); - TALLOC_FREE(nodemap); - return NULL; - } - } - - talloc_free(lines); - return nodemap; -} - static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, uint32_t pnn) { @@ -406,7 +307,7 @@ static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, D_ERR("nodes file path too long\n"); return NULL; } - nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list); + nodemap = ctdb_read_nodes(mem_ctx, nodes_list); if (nodemap != NULL) { /* Fake a load failure for an empty nodemap */ if (nodemap->num == 0) { @@ -425,7 +326,7 @@ static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, D_ERR("nodes file path too long\n"); return NULL; } - nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list); + nodemap = ctdb_read_nodes(mem_ctx, nodes_list); if (nodemap != NULL) { return nodemap; } diff --git a/ctdb/wscript b/ctdb/wscript index 31ed62b1a21..58acb70cb54 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -1122,9 +1122,15 @@ def build(bld): bld.SAMBA_BINARY('fake_ctdbd', source='''tests/src/fake_ctdbd.c tests/src/ipalloc_read_known_ips.c''', - deps='''ctdb-util ctdb-protocol ctdb-protocol-util - ctdb-system samba-util tevent-util - LIBASYNC_REQ popt''', + deps='''ctdb-conf-util + ctdb-protocol + ctdb-protocol-util + ctdb-system + ctdb-util + popt + samba-util + tevent-util + LIBASYNC_REQ''', install_path='${CTDB_TEST_LIBEXECDIR}') bld.SAMBA_BINARY('cluster_mutex_test',