]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
RadosModel: separate initialization and construction
authorJosh Durgin <josh.durgin@dreamhost.com>
Tue, 7 Feb 2012 01:37:55 +0000 (17:37 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Fri, 2 Mar 2012 01:18:31 +0000 (17:18 -0800)
Several error codes needed to be checked.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
Reviewed-by: Samuel Just <samuel.just@dreamhost.com>
src/test/osd/RadosModel.h
src/test/osd/TestRados.cc

index bb6bf6022f4a501ad6a8f731ce2204f46699a171..7ea333a8633da1571bf1e84956d301b02f8de80a 100644 (file)
@@ -117,6 +117,8 @@ public:
   int seq_num;
   map<int,uint64_t> 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<TestOp*> inflight;
     state_lock.Lock();
 
index 248066814cd3b09a3b5563a0b9ed234e9b473a75..1b4766a881fc7dc58e12385fd50a6fcebe432f23 100644 (file)
@@ -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 <iostream>
 #include <sstream>
@@ -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();