]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add new constructor to form a Rados object from IoCtx
authorDan Mick <dan.mick@inktank.com>
Mon, 9 Jul 2012 21:11:23 +0000 (14:11 -0700)
committerDan Mick <dan.mick@inktank.com>
Tue, 10 Jul 2012 20:59:11 +0000 (13:59 -0700)
This creates a separate reference to an existing connection, for
use when a client holding IoCtx needs to consult another (say,
for rbd cloning)

Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
src/include/rados/librados.hpp
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/librados/librados.cc

index 64101481b63c42da4d477d32a8dd2055836fc61e..7b6e68aa70ea6e377a82bc40ec8cec2d32c8ccd1 100644 (file)
@@ -475,6 +475,7 @@ namespace librados
     static void version(int *major, int *minor, int *extra);
 
     Rados();
+    explicit Rados(IoCtx& ioctx);
     ~Rados();
 
     int init(const char * const id);
index 0a08a3b82628b6b2a1df4b809fb40e471a72f7ff..0f9fc8c47fb1fa8cb455240acc3cf125ae5d87c9 100644 (file)
@@ -65,6 +65,7 @@ librados::RadosClient::RadosClient(CephContext *cct_)
     objecter(NULL),
     lock("radosclient"),
     timer(cct, lock),
+    refcnt(1),
     finisher(cct),
     max_watch_cookie(0)
 {
@@ -367,6 +368,19 @@ int librados::RadosClient::get_fs_stats(ceph_statfs& stats)
   return 0;
 }
 
+void librados::RadosClient::get() {
+  Mutex::Locker l(lock);
+  assert(refcnt > 0);
+  refcnt++;
+}
+
+bool librados::RadosClient::put() {
+  Mutex::Locker l(lock);
+  assert(refcnt > 0);
+  refcnt--;
+  return (refcnt == 0);
+}
 int librados::RadosClient::pool_create(string& name, unsigned long long auid,
                                       __u8 crush_rule)
 {
index 3439815dc75079701295d7b805661ffbedb31d64..3ca6153df5b88e6c291c378b8f53b059935c0e6d 100644 (file)
@@ -62,6 +62,7 @@ private:
   Mutex lock;
   Cond cond;
   SafeTimer timer;
+  int refcnt;
 
 public:
   Finisher finisher;
@@ -99,6 +100,8 @@ public:
                        librados::WatchCtx *ctx, uint64_t *cookie);
   void unregister_watcher(uint64_t cookie);
   void watch_notify(MWatchNotify *m);
+  void get();
+  bool put();
 };
 
 #endif
index 9fc2f4f2e5c175cabc1e7c8ec763c0bb1ab17a0d..452120f9c380db1787b8e3311ba13686c789a4e8 100644 (file)
@@ -1024,6 +1024,13 @@ librados::Rados::Rados() : client(NULL)
 {
 }
 
+librados::Rados::Rados(IoCtx &ioctx)
+{
+  client = ioctx.io_ctx_impl->client;
+  assert(client != NULL);
+  client->get();
+}
+
 librados::Rados::~Rados()
 {
   shutdown();
@@ -1053,9 +1060,11 @@ void librados::Rados::shutdown()
 {
   if (!client)
     return;
-  client->shutdown();
-  delete client;
-  client = NULL;
+  if (client->put()) {
+    client->shutdown();
+    delete client;
+    client = NULL;
+  }
 }
 
 uint64_t librados::Rados::get_instance_id()