From 3a8351725667d6cc363164a3c280246acf53ccd0 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 6 Feb 2012 17:37:55 -0800 Subject: [PATCH] RadosModel: separate initialization and construction Several error codes needed to be checked. Signed-off-by: Josh Durgin Reviewed-by: Samuel Just --- src/test/osd/RadosModel.h | 39 ++++++++++++++++++++++++++++++++------- src/test/osd/TestRados.cc | 7 +++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/test/osd/RadosModel.h b/src/test/osd/RadosModel.h index bb6bf6022f4a5..7ea333a8633da 100644 --- a/src/test/osd/RadosModel.h +++ b/src/test/osd/RadosModel.h @@ -117,6 +117,8 @@ public: int seq_num; map snaps; uint64_t seq; + const char *rados_id; + bool initialized; RadosTestContext(const string &pool_name, @@ -129,27 +131,50 @@ public: pool_name(pool_name), errors(0), max_in_flight(max_in_flight), - cont_gen(cont_gen), seq_num(0), seq(0) + cont_gen(cont_gen), seq_num(0), seq(0), + rados_id(id), initialized(false) { - rados.init(id); - rados.conf_read_file(NULL); - rados.conf_parse_env(NULL); - rados.connect(); - rados.ioctx_create(pool_name.c_str(), io_ctx); + } + + int init() + { + int r = rados.init(rados_id); + if (r < 0) + return r; + r = rados.conf_read_file(NULL); + if (r < 0) + return r; + r = rados.conf_parse_env(NULL); + if (r < 0) + return r; + r = rados.connect(); + if (r < 0) + return r; + r = rados.ioctx_create(pool_name.c_str(), io_ctx); + if (r < 0) { + rados.shutdown(); + return r; + } char hostname_cstr[100]; gethostname(hostname_cstr, 100); stringstream hostpid; hostpid << hostname_cstr << getpid() << "-"; prefix = hostpid.str(); + assert(!initialized); + initialized = true; + return 0; } void shutdown() { - rados.shutdown(); + if (initialized) { + rados.shutdown(); + } } void loop(TestOpGenerator *gen) { + assert(initialized); list inflight; state_lock.Lock(); diff --git a/src/test/osd/TestRados.cc b/src/test/osd/TestRados.cc index 248066814cd3b..1b4766a881fc7 100644 --- a/src/test/osd/TestRados.cc +++ b/src/test/osd/TestRados.cc @@ -1,6 +1,7 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- #include "common/Mutex.h" #include "common/Cond.h" +#include "common/errno.h" #include #include @@ -245,6 +246,12 @@ int main(int argc, char **argv) TestOpStat stats; WeightedTestGenerator gen = WeightedTestGenerator(ops, objects, op_weights, &stats, max_seconds); + int r = context.init(); + if (r < 0) { + cerr << "Error initializing rados test context: " + << cpp_strerror(r) << std::endl; + exit(1); + } context.loop(&gen); context.shutdown(); -- 2.39.5