From 20e705e63bd3b20837cc3ac92fdcf2a9650ccfc8 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 21 Oct 2013 19:33:10 +1100 Subject: [PATCH] ctdbd: Add nodes_file member to struct ctdb_context This allows ctdb_load_nodes_file() to move to ctdb_server.c and ctdb_set_nlist() to become static. Setting ctdb->nodes_file needs to be done early, before the nodes file is loaded. It is now set from CTDB_BASE instead ETCDIR, so setting CTDB_BASE also needs to be done earlier. Unhack ctdbd_test.c - it no longer needs to define ctdb_load_nodes_file(). Signed-off-by: Martin Schwenke Pair-programmed-with: Amitay Isaacs --- include/ctdb_client.h | 6 ------ include/ctdb_private.h | 1 + server/ctdb_server.c | 12 +++++++++++- server/ctdbd.c | 29 ++++++++++++++--------------- tests/src/ctdbd_test.c | 2 -- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/ctdb_client.h b/include/ctdb_client.h index ca2f7620..c8c37da8 100644 --- a/include/ctdb_client.h +++ b/include/ctdb_client.h @@ -84,12 +84,6 @@ int ctdb_set_address(struct ctdb_context *ctdb, const char *address); int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname); const char *ctdb_get_socketname(struct ctdb_context *ctdb); -/* - tell ctdb what nodes are available. This takes a filename, which will contain - 1 node address per line, in a transport specific format -*/ -int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist); - /* Check that a specific ip address exists in the node list and returns the id for the node or -1 diff --git a/include/ctdb_private.h b/include/ctdb_private.h index 13e482f2..967dd63c 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -549,6 +549,7 @@ struct ctdb_context { struct ctdb_reloadips_handle *reload_ips; + const char *nodes_file; const char *public_addresses_file; struct trbt_tree *child_processes; diff --git a/server/ctdb_server.c b/server/ctdb_server.c index d0c34612..1c0fa4ca 100644 --- a/server/ctdb_server.c +++ b/server/ctdb_server.c @@ -197,7 +197,7 @@ static int ctdb_add_deleted_node(struct ctdb_context *ctdb) /* setup the node list from a file */ -int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist) +static int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist) { char **lines; int nlines; @@ -265,6 +265,16 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist) return 0; } +void ctdb_load_nodes_file(struct ctdb_context *ctdb) +{ + int ret; + + ret = ctdb_set_nlist(ctdb, ctdb->nodes_file); + if (ret == -1) { + DEBUG(DEBUG_ALERT,("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb))); + exit(1); + } +} /* setup the local node address diff --git a/server/ctdbd.c b/server/ctdbd.c index 28fe8798..b0497176 100644 --- a/server/ctdbd.c +++ b/server/ctdbd.c @@ -52,7 +52,7 @@ static struct { int no_publicipcheck; int max_persistent_check_errors; } options = { - .nlist = ETCDIR "/ctdb/nodes", + .nlist = NULL, .transport = "tcp", .event_script_dir = ETCDIR "/ctdb/events.d", .logfile = LOGDIR "/log.ctdb", @@ -86,17 +86,6 @@ static void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t len ctdb_input_pkt(ctdb, hdr); } -void ctdb_load_nodes_file(struct ctdb_context *ctdb) -{ - int ret; - - ret = ctdb_set_nlist(ctdb, options.nlist); - if (ret == -1) { - DEBUG(DEBUG_ALERT,("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb))); - exit(1); - } -} - static const struct ctdb_upcalls ctdb_upcalls = { .recv_pkt = ctdb_recv_pkt, .node_dead = ctdb_node_dead, @@ -250,7 +239,20 @@ int main(int argc, const char *argv[]) */ ctdb->pnn = -1; + /* Default value for CTDB_BASE - don't override */ + setenv("CTDB_BASE", ETCDIR "/ctdb", 0); + /* tell ctdb what nodes are available */ + if (options.nlist != NULL) { + ctdb->nodes_file = options.nlist; + } else { + ctdb->nodes_file = + talloc_asprintf(ctdb, "%s/nodes", getenv("CTDB_BASE")); + if (ctdb->nodes_file == NULL) { + DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n")); + exit(1); + } + } ctdb_load_nodes_file(ctdb); if (options.db_dir) { @@ -323,9 +325,6 @@ int main(int argc, const char *argv[]) ctdb->max_persistent_check_errors = (uint64_t)options.max_persistent_check_errors; } - /* Default value for CTDB_BASE - don't override */ - setenv("CTDB_BASE", ETCDIR "/ctdb", 0); - /* start the protocol running (as a child) */ return ctdb_start_daemon(ctdb, interactive?false:true, options.use_syslog, options.public_address_list); } diff --git a/tests/src/ctdbd_test.c b/tests/src/ctdbd_test.c index bf95e0b8..fb29ba8f 100644 --- a/tests/src/ctdbd_test.c +++ b/tests/src/ctdbd_test.c @@ -30,8 +30,6 @@ */ int script_log_level; bool fast_start; -void ctdb_load_nodes_file(struct ctdb_context *ctdb) {} - /* UTIL_OBJ */ #include "lib/util/idtree.c" -- 2.34.1