server: only do the mkdir() calls for db_directory* once at the start
authorStefan Metzmacher <metze@samba.org>
Sun, 29 Nov 2009 11:39:23 +0000 (12:39 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 16 Dec 2009 07:03:56 +0000 (08:03 +0100)
metze

include/ctdb_private.h
server/ctdb_daemon.c
server/ctdb_ltdb_server.c
tests/scripts/ctdb_test_functions.bash

index 38dd788b4492d8489980574e773f226b39a62bf7..b99f12e1f1ff68aaf8f2ff2bf14a8a728a386378 100644 (file)
@@ -1416,7 +1416,7 @@ int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
 int32_t ctdb_control_uptime(struct ctdb_context *ctdb, 
                      TDB_DATA *outdata);
 
-int ctdb_attach_persistent(struct ctdb_context *ctdb);
+int ctdb_attach_databases(struct ctdb_context *ctdb);
 
 int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb, 
                                      struct ctdb_req_control *c, 
index 9ade55aca86bc66ef1cca45c44402c2081b6dd16..42b2c124b15671ab311598363710b19804c6ca98 100644 (file)
@@ -764,9 +764,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
                ctdb_fatal(ctdb, "transport failed to initialise");
        }
 
-       /* attach to any existing persistent databases */
-       if (ctdb_attach_persistent(ctdb) != 0) {
-               ctdb_fatal(ctdb, "Failed to attach to persistent databases\n");         
+       /* attach to existing databases */
+       if (ctdb_attach_databases(ctdb) != 0) {
+               ctdb_fatal(ctdb, "Failed to attach to databases\n");
        }
 
        /* start frozen, then let the first election sort things out */
index ca8fd48a11e8f7ba67d7009a82eb23a200a0a989..162a694b834732ee1bfde9338819220e2abd19a1 100644 (file)
@@ -223,25 +223,6 @@ static int ctdb_local_attach(struct ctdb_context *ctdb, const char *db_name, boo
                }
        }
 
-       if (ctdb->db_directory == NULL) {
-               ctdb->db_directory = VARDIR "/ctdb";
-       }
-
-       /* make sure the db directory exists */
-       if (mkdir(ctdb->db_directory, 0700) == -1 && errno != EEXIST) {
-               DEBUG(DEBUG_CRIT,(__location__ " Unable to create ctdb directory '%s'\n", 
-                        ctdb->db_directory));
-               talloc_free(ctdb_db);
-               return -1;
-       }
-
-       if (persistent && mkdir(ctdb->db_directory_persistent, 0700) == -1 && errno != EEXIST) {
-               DEBUG(DEBUG_CRIT,(__location__ " Unable to create ctdb persistent directory '%s'\n", 
-                        ctdb->db_directory_persistent));
-               talloc_free(ctdb_db);
-               return -1;
-       }
-
        /* open the database */
        ctdb_db->db_path = talloc_asprintf(ctdb_db, "%s/%s.%u", 
                                           persistent?ctdb->db_directory_persistent:ctdb->db_directory, 
@@ -377,7 +358,7 @@ int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
 /*
   attach to all existing persistent databases
  */
-int ctdb_attach_persistent(struct ctdb_context *ctdb)
+static int ctdb_attach_persistent(struct ctdb_context *ctdb)
 {
        DIR *d;
        struct dirent *de;
@@ -432,6 +413,52 @@ int ctdb_attach_persistent(struct ctdb_context *ctdb)
        return 0;
 }
 
+int ctdb_attach_databases(struct ctdb_context *ctdb)
+{
+       int ret;
+
+       if (ctdb->db_directory == NULL) {
+               ctdb->db_directory = VARDIR "/ctdb";
+       }
+       if (ctdb->db_directory_persistent == NULL) {
+               ctdb->db_directory_persistent = VARDIR "/ctdb/persistent";
+       }
+       if (ctdb->db_directory_state == NULL) {
+               ctdb->db_directory_state = VARDIR "/ctdb/state";
+       }
+
+       /* make sure the db directory exists */
+       ret = mkdir(ctdb->db_directory, 0700);
+       if (ret == -1 && errno != EEXIST) {
+               DEBUG(DEBUG_CRIT,(__location__ " Unable to create ctdb directory '%s'\n",
+                        ctdb->db_directory));
+               return -1;
+       }
+
+       /* make sure the persistent db directory exists */
+       ret = mkdir(ctdb->db_directory_persistent, 0700);
+       if (ret == -1 && errno != EEXIST) {
+               DEBUG(DEBUG_CRIT,(__location__ " Unable to create ctdb persistent directory '%s'\n",
+                        ctdb->db_directory_persistent));
+               return -1;
+       }
+
+       /* make sure the internal state db directory exists */
+       ret = mkdir(ctdb->db_directory_state, 0700);
+       if (ret == -1 && errno != EEXIST) {
+               DEBUG(DEBUG_CRIT,(__location__ " Unable to create ctdb state directory '%s'\n",
+                        ctdb->db_directory_state));
+               return -1;
+       }
+
+       ret = ctdb_attach_persistent(ctdb);
+       if (ret != 0) {
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
   called when a broadcast seqnum update comes in
  */
index 832a42bf16892907a874dc822a581aa304857579..d8a0de94aa5bf0154a419bb2d879a7e49f705528 100644 (file)
@@ -679,7 +679,7 @@ daemons_start_1 ()
        echo "Node $no_public_ips will have no public IPs."
     fi
 
-    local ctdb_options="--reclock=$var_dir/rec.lock --nlist $nodes --nopublicipcheck --event-script-dir=$CTDB_DIR/tests/events.d --logfile=$var_dir/daemons.log -d 0 --dbdir=$var_dir/test.db --dbdir-persistent=$var_dir/test.db/persistent"
+    local ctdb_options="--reclock=$var_dir/rec.lock --nlist $nodes --nopublicipcheck --event-script-dir=$CTDB_DIR/tests/events.d --logfile=$var_dir/daemons.log -d 0 --dbdir=$var_dir/test.db --dbdir-persistent=$var_dir/test.db/persistent --dbdir-state=$var_dir/test.db/state"
 
     if [ $(id -u) -eq 0 ]; then
         ctdb_options="$ctdb_options --public-interface=lo"