ctdbd: Add nodes_file member to struct ctdb_context
authorMartin Schwenke <martin@meltin.net>
Mon, 21 Oct 2013 08:33:10 +0000 (19:33 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 22 Oct 2013 04:37:54 +0000 (15:37 +1100)
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 <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

include/ctdb_client.h
include/ctdb_private.h
server/ctdb_server.c
server/ctdbd.c
tests/src/ctdbd_test.c

index ca2f7620e5b04d523e17cfa10a1606a307ab72b9..c8c37da8e672076537c1883f01fce1df7b1b556a 100644 (file)
@@ -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
index 13e482f233488bc840994e427e796dafeec89cc7..967dd63c9a060ab59e2e9144e9c7f3ea985f56cc 100644 (file)
@@ -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; 
 
index d0c346129734a323fcee630f54f462661869381c..1c0fa4ca9e719600f6957ddcedd78c09f5ec669c 100644 (file)
@@ -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
index 28fe87986404db5240a333bf6f2e018e74de85bc..b04971760d415e1946b539ad91ba145bffe75e5d 100644 (file)
@@ -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);
 }
index bf95e0b84ff354a141d9fd3cdc3c5a21276fd27d..fb29ba8f1b32b19a92326cace822b7e5ce63bbfc 100644 (file)
@@ -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"