1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-03 01:18:10 +03:00

ctdb-daemon: Use ctdb_read_nodes() in ctdbd

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>
This commit is contained in:
Martin Schwenke 2024-07-05 18:07:36 +10:00 committed by Martin Schwenke
parent 5d2a864c0b
commit 181cc097ef
5 changed files with 57 additions and 122 deletions

View 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);

View 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)

View 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;
}
return 0;
ctdb_node_map_push(node_map, buf, &npush);
if (len != npush) {
talloc_free(buf);
goto done;
}
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)

View File

@ -31,9 +31,13 @@
#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;
}

View 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')