]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-daemon: Use ctdb_read_nodes() in ctdbd
authorMartin Schwenke <mschwenke@ddn.com>
Fri, 5 Jul 2024 08:07:36 +0000 (18:07 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 23 Jul 2024 11:37:34 +0000 (11:37 +0000)
ctdb_control_getnodesfile() calls ctdb_read_nodes(), which returns a
struct ctdb_node_map rather than the old version, so update associated
marshalling.  While here modernise a debug message and wrap the
function arguments.

For ctdb_load_nodes_file() to use ctdb_read_nodes(), tweak
convert_node_map_to_list() to also use the modern node map structure.

Remove unused copy of ctdb_read_nodes_file().

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
ctdb/common/common.h
ctdb/common/ctdb_util.c
ctdb/server/ctdb_daemon.c
ctdb/server/ctdb_server.c
ctdb/wscript

index 4f48e8926da375cffd6f97939dd2159ed7ec15c1..6a52fb4e4c6027a5b43051ceb4f7af04cfaa4df0 100644 (file)
@@ -142,9 +142,6 @@ char *ctdb_addr_to_str(ctdb_sock_addr *addr);
 
 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
 
-struct ctdb_node_map_old *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
-                                              const char *nlist);
-
 struct ctdb_node_map_old *ctdb_node_list_to_map(struct ctdb_node **nodes,
                                                uint32_t num_nodes,
                                                TALLOC_CTX *mem_ctx);
index ebf0203871faffed086066c36bce62eb1f9f991e..831a2877b8a8a931e785e5c09aab8a76bf72f779 100644 (file)
@@ -464,110 +464,6 @@ unsigned ctdb_addr_to_port(ctdb_sock_addr *addr)
        return 0;
 }
 
-/* Add a node to a node map with given address and flags */
-static bool node_map_add(TALLOC_CTX *mem_ctx,
-                        const char *nstr, uint32_t flags,
-                        struct ctdb_node_map_old **node_map)
-{
-       ctdb_sock_addr addr;
-       uint32_t num;
-       size_t s;
-       struct ctdb_node_and_flags *n;
-
-       /* Might as well do this before trying to allocate memory */
-       if (ctdb_parse_address(mem_ctx, nstr, &addr) == -1) {
-               return false;
-       }
-
-       num = (*node_map)->num + 1;
-       s = offsetof(struct ctdb_node_map_old, nodes) +
-               num * sizeof(struct ctdb_node_and_flags);
-       *node_map = talloc_realloc_size(mem_ctx, *node_map, s);
-       if (*node_map == NULL) {
-               DEBUG(DEBUG_ERR, (__location__ " Out of memory\n"));
-               return false;
-       }
-
-       n = &(*node_map)->nodes[(*node_map)->num];
-       n->addr = addr;
-       n->pnn = (*node_map)->num;
-       n->flags = flags;
-
-       (*node_map)->num++;
-
-       return true;
-}
-
-/* Read a nodes file into a node map */
-struct ctdb_node_map_old *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
-                                          const char *nlist)
-{
-       char **lines;
-       int nlines;
-       int i;
-       struct ctdb_node_map_old *ret;
-
-       /* Allocate node map header */
-       ret = talloc_zero_size(mem_ctx, offsetof(struct ctdb_node_map_old, nodes));
-       if (ret == NULL) {
-               DEBUG(DEBUG_ERR, (__location__ " Out of memory\n"));
-               return false;
-       }
-
-       lines = file_lines_load(nlist, &nlines, 0, mem_ctx);
-       if (lines == NULL) {
-               DEBUG(DEBUG_ERR, ("Failed to read nodes file \"%s\"\n", nlist));
-               return false;
-       }
-       while (nlines > 0 && strcmp(lines[nlines-1], "") == 0) {
-               nlines--;
-       }
-
-       for (i=0; i < nlines; i++) {
-               char *node;
-               uint32_t flags;
-               size_t len;
-
-               node = lines[i];
-               /* strip leading spaces */
-               while((*node == ' ') || (*node == '\t')) {
-                       node++;
-               }
-
-               len = strlen(node);
-
-               while ((len > 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(mem_ctx, node, flags, &ret)) {
-                       talloc_free(lines);
-                       TALLOC_FREE(ret);
-                       return NULL;
-               }
-       }
-
-       talloc_free(lines);
-       return ret;
-}
-
 struct ctdb_node_map_old *
 ctdb_node_list_to_map(struct ctdb_node **nodes, uint32_t num_nodes,
                      TALLOC_CTX *mem_ctx)
index c5dd1ed60aabee58516030b7ec143d7b14f396ab..97dfc80ffd1da2f16af4c15c66b15910721c62b5 100644 (file)
@@ -40,6 +40,9 @@
 #include "ctdb_private.h"
 #include "ctdb_client.h"
 
+#include "protocol/protocol.h"
+#include "protocol/protocol_api.h"
+
 #include "common/rb_tree.h"
 #include "common/reqid.h"
 #include "common/system.h"
@@ -48,6 +51,8 @@
 #include "common/pidfile.h"
 #include "common/sock_io.h"
 
+#include "conf/node.h"
+
 struct ctdb_client_pid_list {
        struct ctdb_client_pid_list *next, *prev;
        struct ctdb_context *ctdb;
@@ -2175,22 +2180,43 @@ int32_t ctdb_control_check_pid_srvid(struct ctdb_context *ctdb,
        return -1;
 }
 
-int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
+int ctdb_control_getnodesfile(struct ctdb_context *ctdb,
+                             uint32_t opcode,
+                             TDB_DATA indata,
+                             TDB_DATA *outdata)
 {
-       struct ctdb_node_map_old *node_map = NULL;
+       struct ctdb_node_map *node_map = NULL;
+       size_t len;
+       uint8_t *buf = NULL;
+       size_t npush = 0;
+       int ret = -1;
 
        CHECK_CONTROL_DATA_SIZE(0);
 
-       node_map = ctdb_read_nodes_file(ctdb, ctdb->nodes_file);
+       node_map = ctdb_read_nodes(ctdb, ctdb->nodes_file);
        if (node_map == NULL) {
-               DEBUG(DEBUG_ERR, ("Failed to read nodes file\n"));
+               D_ERR("Failed to read nodes file\n");
                return -1;
        }
 
-       outdata->dptr  = (unsigned char *)node_map;
-       outdata->dsize = talloc_get_size(outdata->dptr);
+       len = ctdb_node_map_len(node_map);
+       buf = talloc_size(ctdb, len);
+       if (buf == NULL) {
+               goto done;
+       }
+
+       ctdb_node_map_push(node_map, buf, &npush);
+       if (len != npush) {
+               talloc_free(buf);
+               goto done;
+       }
 
-       return 0;
+       outdata->dptr  = buf;
+       outdata->dsize = len;
+       ret = 0;
+done:
+       talloc_free(node_map);
+       return ret;
 }
 
 void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code)
index b602ceebc0e68a2d770d9cc9f22c0d445f7a50fb..40f8e28923905620b759a1b5113385e0978be0c0 100644 (file)
 #include "ctdb_private.h"
 #include "ctdb_client.h"
 
+#include "protocol/protocol.h"
+
 #include "common/common.h"
 #include "common/logging.h"
 
+#include "conf/node.h"
+
 /*
   choose the transport we will use
 */
@@ -80,7 +84,7 @@ uint32_t ctdb_ip_to_pnn(struct ctdb_context *ctdb,
 /* Load a nodes list file into a nodes array */
 static int convert_node_map_to_list(struct ctdb_context *ctdb,
                                    TALLOC_CTX *mem_ctx,
-                                   struct ctdb_node_map_old *node_map,
+                                   struct ctdb_node_map *node_map,
                                    struct ctdb_node ***nodes,
                                    uint32_t *num_nodes)
 {
@@ -98,12 +102,12 @@ static int convert_node_map_to_list(struct ctdb_context *ctdb,
                CTDB_NO_MEMORY(ctdb, node);
                (*nodes)[i] = node;
 
-               node->address = node_map->nodes[i].addr;
+               node->address = node_map->node[i].addr;
                node->name = talloc_asprintf(node, "%s:%u",
                                             ctdb_addr_to_str(&node->address),
                                             ctdb_addr_to_port(&node->address));
 
-               node->flags = node_map->nodes[i].flags;
+               node->flags = node_map->node[i].flags;
                if (!(node->flags & NODE_FLAGS_DELETED)) {
                        node->flags = NODE_FLAGS_UNHEALTHY;
                }
@@ -120,10 +124,10 @@ static int convert_node_map_to_list(struct ctdb_context *ctdb,
 /* Load the nodes list from a file */
 void ctdb_load_nodes_file(struct ctdb_context *ctdb)
 {
-       struct ctdb_node_map_old *node_map;
+       struct ctdb_node_map *node_map;
        int ret;
 
-       node_map = ctdb_read_nodes_file(ctdb, ctdb->nodes_file);
+       node_map = ctdb_read_nodes(ctdb, ctdb->nodes_file);
        if (node_map == NULL) {
                goto fail;
        }
index 58acb70cb5455e306a3448d200bd286b2e298980..5e4766959cf4610b0491b2cdb29f64b3f18ce754 100644 (file)
@@ -604,11 +604,23 @@ def build(bld):
                                              ctdb_tunnel.c ctdb_client.c
                                           '''),
                      includes='include',
-                     deps='''ctdb-common ctdb-system ctdb-protocol
-                             ctdb-tcp ctdb-util replace sys_rw popt
+                     deps='''ctdb-common
                              ctdb-conf
+                             ctdb-conf-util
                              ctdb-event-protocol
-                             talloc tevent tdb-wrap tdb talloc_report''' +
+                             ctdb-protocol
+                             ctdb-system
+                             ctdb-tcp
+                             ctdb-util
+                             popt
+                             replace
+                             sys_rw
+                             talloc
+                             talloc_report
+                             tdb
+                             tdb-wrap
+                             tevent
+                          ''' +
                           ib_deps,
                      install_path='${SBINDIR}',
                      manpages='ctdbd.1')