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);
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)
#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"
#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;
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)
#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
*/
/* 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)
{
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;
}
/* 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;
}
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')