diff options
author | Sage Weil <sage@inktank.com> | 2012-07-26 15:04:12 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-07-26 15:04:12 -0700 |
commit | 87b6e8045a3a1ff6439d2684e960ad0dc8988b33 (patch) | |
tree | 6920e36e0e073b97ab84489ab995843297618eb1 /src/librados | |
parent | 81d72e5d7ba4713eb7c290878d901e21c0709028 (diff) | |
parent | 7dfdf4f8de16155edd434534e161e06ba7c79d7d (diff) | |
download | ceph-87b6e8045a3a1ff6439d2684e960ad0dc8988b33.tar.gz |
Merge remote-tracking branch 'gh/wip-rbd-bid' into stable-next
Diffstat (limited to 'src/librados')
-rw-r--r-- | src/librados/RadosClient.cc | 14 | ||||
-rw-r--r-- | src/librados/RadosClient.h | 3 | ||||
-rw-r--r-- | src/librados/librados.cc | 15 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 0a08a3b8262..0f9fc8c47fb 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -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) { diff --git a/src/librados/RadosClient.h b/src/librados/RadosClient.h index 3439815dc75..3ca6153df5b 100644 --- a/src/librados/RadosClient.h +++ b/src/librados/RadosClient.h @@ -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 diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 9fc2f4f2e5c..452120f9c38 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -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() |