summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-02-22 06:49:04 +1100
committerAmitay Isaacs <amitay@samba.org>2015-03-23 12:23:12 +0100
commit5148228f414ea1cc2ad71dfbb4d5f82353ae5b56 (patch)
treef9120f3348307c23a47527a0257d2b725ad73dd8
parent1ada9c4ef787af4097f228c4629fac99a5b9bf13 (diff)
downloadsamba-5148228f414ea1cc2ad71dfbb4d5f82353ae5b56.tar.gz
ctdb-daemon: Move ctdb_read_nodes_file() to utilities
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rw-r--r--ctdb/common/ctdb_util.c92
-rw-r--r--ctdb/include/ctdb_private.h2
-rw-r--r--ctdb/server/ctdb_server.c93
3 files changed, 94 insertions, 93 deletions
diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index 59a24af967b..76fb06d5606 100644
--- a/ctdb/common/ctdb_util.c
+++ b/ctdb/common/ctdb_util.c
@@ -486,6 +486,98 @@ 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 **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, 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 *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
+ const char *nlist)
+{
+ char **lines;
+ int nlines;
+ int i;
+ struct ctdb_node_map *ret;
+
+ /* Allocate node map header */
+ ret = talloc_zero_size(mem_ctx, offsetof(struct ctdb_node_map, 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++) {
+ const char *node;
+ uint32_t flags;
+
+ node = lines[i];
+ /* strip leading spaces */
+ while((*node == ' ') || (*node == '\t')) {
+ node++;
+ }
+ if (strcmp(node, "") == 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 = "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;
+}
const char *ctdb_eventscript_call_names[] = {
"init",
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 8a90ae98e42..4ffb431bde3 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -1388,6 +1388,8 @@ int ctdb_client_async_control(struct ctdb_context *ctdb,
client_async_callback fail_callback,
void *callback_data);
+struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
+ const char *nlist);
void ctdb_load_nodes_file(struct ctdb_context *ctdb);
int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c
index 08b10f9cf23..81ef361b225 100644
--- a/ctdb/server/ctdb_server.c
+++ b/ctdb/server/ctdb_server.c
@@ -76,99 +76,6 @@ int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file)
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 **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, 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 */
-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 *ret;
-
- /* Allocate node map header */
- ret = talloc_zero_size(mem_ctx, offsetof(struct ctdb_node_map, 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++) {
- const char *node;
- uint32_t flags;
-
- node = lines[i];
- /* strip leading spaces */
- while((*node == ' ') || (*node == '\t')) {
- node++;
- }
- if (strcmp(node, "") == 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 = "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;
-}
-
/* Load a nodes list file into a nodes array */
static int convert_node_map_to_list(struct ctdb_context *ctdb,
TALLOC_CTX *mem_ctx,