]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tools: update cli tool to optionally load nodes from command
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 7 Jun 2024 15:12:17 +0000 (11:12 -0400)
committerMartin Schwenke <martins@samba.org>
Tue, 6 Aug 2024 00:43:36 +0000 (00:43 +0000)
Similar to the recent changes to the ctdb server code, add the ability
to load the nodes from a subprocess stdout.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/UNIT/tool/ctdb.listnodes.001.sh
ctdb/tools/ctdb.c
ctdb/wscript

index 5a494ee8c9e0f6f6ff68024effa98d262960c0ea..443f11f45e792f157923ae1b6ed36b4695d58ab4 100755 (executable)
@@ -14,7 +14,7 @@ f="${CTDB_BASE}/nodes"
 rm -f "$f"
 
 required_result 1 <<EOF
-${TEST_DATE_STAMP}Failed to read nodes file "${f}"
+${TEST_DATE_STAMP}Failed to read nodes from "${f}"
 EOF
 
 simple_test
index 14249b4110a6434430e7ea8d60bf14953513ab4b..bf99e7bc526c8a21771af683afda657b47e268d0 100644 (file)
@@ -47,6 +47,8 @@
 #include "common/system_socket.h"
 #include "client/client.h"
 #include "client/client_sync.h"
+#include "conf/cluster_conf.h"
+#include "conf/ctdb_config.h"
 #include "conf/node.h"
 
 #define TIMEOUT()      timeval_current_ofs(options.timelimit, 0)
@@ -72,6 +74,7 @@ static struct {
        int printrecordflags;
 } options;
 
+struct conf_context *config_ctx;
 static poptContext pc;
 
 struct ctdb_context {
@@ -464,25 +467,19 @@ static bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2)
        return ret;
 }
 
-static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, uint32_t pnn)
+static struct ctdb_node_map *read_nodes(TALLOC_CTX *mem_ctx, uint32_t pnn)
 {
        struct ctdb_node_map *nodemap;
-       const char *nodes_list = NULL;
-
-       const char *basedir = getenv("CTDB_BASE");
-       if (basedir == NULL) {
-               basedir = CTDB_ETCDIR;
-       }
-       nodes_list = talloc_asprintf(mem_ctx, "%s/nodes", basedir);
-       if (nodes_list == NULL) {
+       const char *nodes_source = cluster_conf_nodes_list(mem_ctx, config_ctx);
+       if (nodes_source == NULL) {
                fprintf(stderr, "Memory allocation error\n");
                return NULL;
        }
 
-       nodemap = ctdb_read_nodes(mem_ctx, nodes_list);
+       nodemap = ctdb_read_nodes(mem_ctx, nodes_source);
        if (nodemap == NULL) {
-               fprintf(stderr, "Failed to read nodes file \"%s\"\n",
-                       nodes_list);
+               fprintf(stderr, "Failed to read nodes from \"%s\"\n",
+                       nodes_source);
                return NULL;
        }
 
@@ -3406,7 +3403,7 @@ static int control_listnodes(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                usage("listnodes");
        }
 
-       nodemap = read_nodes_file(mem_ctx, CTDB_UNKNOWN_PNN);
+       nodemap = read_nodes(mem_ctx, CTDB_UNKNOWN_PNN);
        if (nodemap == NULL) {
                return 1;
        }
@@ -3659,7 +3656,7 @@ static int control_reloadnodes(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                return 1;
        }
 
-       file_nodemap = read_nodes_file(mem_ctx, ctdb->pnn);
+       file_nodemap = read_nodes(mem_ctx, ctdb->pnn);
        if (file_nodemap == NULL) {
                return 1;
        }
@@ -4741,7 +4738,7 @@ static bool find_node_xpnn(TALLOC_CTX *mem_ctx, uint32_t *pnn)
        struct ctdb_node_map *nodemap;
        unsigned int i;
 
-       nodemap = read_nodes_file(mem_ctx, CTDB_UNKNOWN_PNN);
+       nodemap = read_nodes(mem_ctx, CTDB_UNKNOWN_PNN);
        if (nodemap == NULL) {
                return false;
        }
@@ -6301,6 +6298,12 @@ static int process_command(const struct ctdb_cmd *cmd, int argc,
                goto fail;
        }
 
+       ret = ctdb_config_load(tmp_ctx, &config_ctx, false);
+       if (ret != 0) {
+               fprintf(stderr, "Failed to load configuration\n");
+               goto fail;
+       }
+
        if (cmd->without_daemon) {
                if (options.pnn != -1) {
                        fprintf(stderr,
@@ -6376,10 +6379,12 @@ static int process_command(const struct ctdb_cmd *cmd, int argc,
        }
 
        ret = cmd->fn(tmp_ctx, ctdb, argc-1, argv+1);
+       config_ctx = NULL;
        talloc_free(tmp_ctx);
        return ret;
 
 fail:
+       config_ctx = NULL;
        talloc_free(tmp_ctx);
        return 1;
 }
index 5e4766959cf4610b0491b2cdb29f64b3f18ce754..a211afbc77d4f82b5f13e4b23afc464be5c1d17b 100644 (file)
@@ -628,6 +628,7 @@ def build(bld):
     bld.SAMBA_BINARY('ctdb',
                      source='tools/ctdb.c',
                      deps='''ctdb-client
+                             ctdb-conf
                              ctdb-conf-util
                              ctdb-protocol
                              ctdb-protocol-util