diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c index f899f7e2bba..cae33912a0d 100644 --- a/ctdb/tests/src/fake_ctdbd.c +++ b/ctdb/tests/src/fake_ctdbd.c @@ -86,6 +86,7 @@ struct vnn_map { struct database { struct database *prev, *next; const char *name; + const char *path; uint32_t id; uint8_t flags; uint64_t seq_num; @@ -93,6 +94,7 @@ struct database { struct database_map { struct database *db; + const char *dbdir; }; struct fake_control_failure { @@ -629,7 +631,8 @@ fail: return false; } -static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx) +static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx, + const char *dbdir) { struct database_map *db_map; @@ -638,6 +641,12 @@ static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx) return NULL; } + db_map->dbdir = talloc_strdup(db_map, dbdir); + if (db_map->dbdir == NULL) { + talloc_free(db_map); + return NULL; + } + return db_map; } @@ -721,6 +730,11 @@ static bool dbmap_parse(struct database_map *db_map) db->id = id; db->name = talloc_steal(db, name); + db->path = talloc_asprintf(db, "%s/%s", db_map->dbdir, name); + if (db->path == NULL) { + talloc_free(db); + goto fail; + } db->flags = flags; db->seq_num = seq_num; @@ -936,7 +950,8 @@ static uint32_t new_generation(uint32_t old_generation) return generation; } -static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx) +static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx, + const char *dbdir) { struct ctdbd_context *ctdb; char line[1024]; @@ -963,7 +978,7 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx) goto fail; } - ctdb->db_map = dbmap_init(ctdb); + ctdb->db_map = dbmap_init(ctdb, dbdir); if (ctdb->db_map == NULL) { goto fail; } @@ -1414,15 +1429,8 @@ static void control_getdbpath(TALLOC_CTX *mem_ctx, reply.status = ENOENT; reply.errmsg = "Database not found"; } else { - const char *base; - if (db->flags & CTDB_DB_FLAGS_PERSISTENT) { - base = "/var/lib/ctdb/persistent"; - } else { - base = "/var/run/ctdb/DB_DIR"; - } reply.rdata.data.db_path = - talloc_asprintf(mem_ctx, "%s/%s.%u", - base, db->name, header->destnode); + talloc_strdup(mem_ctx, db->path); if (reply.rdata.data.db_path == NULL) { reply.status = ENOMEM; reply.errmsg = "Memory error"; @@ -3676,18 +3684,23 @@ fail: } static struct options { + const char *dbdir; const char *sockpath; const char *pidfile; const char *debuglevel; } options; static struct poptOption cmdline_options[] = { + POPT_AUTOHELP + { "dbdir", 'D', POPT_ARG_STRING, &options.dbdir, 0, + "Database directory", "directory" }, { "socket", 's', POPT_ARG_STRING, &options.sockpath, 0, "Unix domain socket path", "filename" }, { "pidfile", 'p', POPT_ARG_STRING, &options.pidfile, 0, "pid file", "filename" } , { "debug", 'd', POPT_ARG_STRING, &options.debuglevel, 0, "debug level", "ERR|WARNING|NOTICE|INFO|DEBUG" } , + POPT_TABLEEND }; static void cleanup(void) @@ -3751,6 +3764,12 @@ int main(int argc, const char *argv[]) exit(1); } + if (options.dbdir == NULL) { + fprintf(stderr, "Please specify database directory\n"); + poptPrintHelp(pc, stdout, 0); + exit(1); + } + if (options.sockpath == NULL) { fprintf(stderr, "Please specify socket path\n"); poptPrintHelp(pc, stdout, 0); @@ -3776,7 +3795,7 @@ int main(int argc, const char *argv[]) exit(1); } - ctdb = ctdbd_setup(mem_ctx); + ctdb = ctdbd_setup(mem_ctx, options.dbdir); if (ctdb == NULL) { exit(1); } diff --git a/ctdb/tests/takeover_helper/scripts/local.sh b/ctdb/tests/takeover_helper/scripts/local.sh index c3a1ac0a098..2bab8c7a06e 100644 --- a/ctdb/tests/takeover_helper/scripts/local.sh +++ b/ctdb/tests/takeover_helper/scripts/local.sh @@ -14,6 +14,7 @@ PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR" ctdbd_socket="${TEST_VAR_DIR}/ctdbd.socket.$$" ctdbd_pidfile="${TEST_VAR_DIR}/ctdbd.pid.$$" +ctdbd_dbdir="${TEST_VAR_DIR}/ctdbd.db.$$" define_test () { @@ -42,14 +43,17 @@ cleanup_ctdbd () rm -f "$ctdbd_pidfile" fi rm -f "$ctdbd_socket" + rm -rf "$ctdbd_dbdir" } setup_ctdbd () { debug "Setting up fake ctdbd" + mkdir -p "$ctdbd_dbdir" $VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \ - -s "$ctdbd_socket" -p "$ctdbd_pidfile" + -s "$ctdbd_socket" -p "$ctdbd_pidfile" \ + -D "$ctdbd_dbdir" export CTDB_SOCKET="$ctdbd_socket" # This current translates to a 6 second timeout for the # important controls diff --git a/ctdb/tests/tool/ctdb.getdbmap.001.sh b/ctdb/tests/tool/ctdb.getdbmap.001.sh index 912371552c9..f766e9c0e38 100755 --- a/ctdb/tests/tool/ctdb.getdbmap.001.sh +++ b/ctdb/tests/tool/ctdb.getdbmap.001.sh @@ -22,13 +22,13 @@ EOF ok <