summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2012-07-11 19:59:32 -0700
committerSage Weil <sage@inktank.com>2012-07-11 19:59:32 -0700
commit762a5b63833b3df4f958bfd3e66acaa6d1ba6c95 (patch)
tree9559be5584fe5a270a87620c65b5e0fb9cfbf1a1
parentf20b602296066a6a094409cbb0d92183adcd2717 (diff)
parent22d0648db224f181914882787b25b36e2eac38b0 (diff)
downloadceph-762a5b63833b3df4f958bfd3e66acaa6d1ba6c95.tar.gz
Merge remote-tracking branch 'gh/wip-cct'
Reviewed-by: Josh Durgin <josh.durgin@inktank.com> Reviewed-by: Greg Farnum <greg@inktank.com>
-rw-r--r--src/common/ceph_context.cc9
-rw-r--r--src/common/ceph_context.h16
-rw-r--r--src/common/common_init.cc4
-rw-r--r--src/common/common_init.h6
-rw-r--r--src/common/lockdep.cc11
-rw-r--r--src/common/lockdep.h1
-rw-r--r--src/libcephfs.cc2
-rw-r--r--src/librados/RadosClient.cc6
-rw-r--r--src/librados/librados.cc2
-rw-r--r--src/osd/OSDMap.cc2
-rw-r--r--src/rgw/librgw.cc2
11 files changed, 43 insertions, 18 deletions
diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc
index e14e73c9149..4134dd785ee 100644
--- a/src/common/ceph_context.cc
+++ b/src/common/ceph_context.cc
@@ -22,6 +22,7 @@
#include "common/debug.h"
#include "common/HeartbeatMap.h"
#include "common/errno.h"
+#include "common/lockdep.h"
#include "log/Log.h"
#include <iostream>
@@ -211,7 +212,8 @@ void CephContext::do_command(std::string command, std::string args, bufferlist *
CephContext::CephContext(uint32_t module_type_)
- : _conf(new md_config_t()),
+ : nref(1),
+ _conf(new md_config_t()),
_log(NULL),
_module_type(module_type_),
_service_thread(NULL),
@@ -249,6 +251,10 @@ CephContext::CephContext(uint32_t module_type_)
CephContext::~CephContext()
{
+ if (_conf->lockdep) {
+ lockdep_unregister_ceph_context(this);
+ }
+
join_service_thread();
_admin_socket->unregister_command("perfcounters_dump");
@@ -263,6 +269,7 @@ CephContext::~CephContext()
_admin_socket->unregister_command("log dump");
_admin_socket->unregister_command("log reopen");
delete _admin_hook;
+ delete _admin_socket;
delete _heartbeat_map;
diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h
index ba7f02d93cf..bb38053c49a 100644
--- a/src/common/ceph_context.h
+++ b/src/common/ceph_context.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include "include/buffer.h"
+#include "include/atomic.h"
class AdminSocket;
class CephContextServiceThread;
@@ -46,9 +47,22 @@ using ceph::bufferlist;
class CephContext {
public:
CephContext(uint32_t module_type_);
+
+ // ref count!
+private:
~CephContext();
- md_config_t *_conf;
+ atomic_t nref;
+public:
+ CephContext *get() {
+ nref.inc();
+ return this;
+ }
+ void put() {
+ if (nref.dec() == 0)
+ delete this;
+ }
+ md_config_t *_conf;
ceph::log::Log *_log;
/* Start the Ceph Context's service thread */
diff --git a/src/common/common_init.cc b/src/common/common_init.cc
index 558d039b1db..76b50e714a5 100644
--- a/src/common/common_init.cc
+++ b/src/common/common_init.cc
@@ -119,7 +119,3 @@ void common_init_finish(CephContext *cct)
}
}
-void common_destroy_context(CephContext *cct)
-{
- //delete cct; // TODO: fix #845
-}
diff --git a/src/common/common_init.h b/src/common/common_init.h
index 88ef485859a..3dfd12915f4 100644
--- a/src/common/common_init.h
+++ b/src/common/common_init.h
@@ -74,10 +74,4 @@ void complain_about_parse_errors(CephContext *cct,
*/
void common_init_finish(CephContext *cct);
-/* This function is called from library code to destroy a context created by
- * the library.
- * You should not call this function if you called global_init.
- */
-void common_destroy_context(CephContext *cct);
-
#endif
diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc
index 1e0c45fa41f..9dbe5f08bf4 100644
--- a/src/common/lockdep.cc
+++ b/src/common/lockdep.cc
@@ -64,6 +64,17 @@ void lockdep_register_ceph_context(CephContext *cct)
pthread_mutex_unlock(&lockdep_mutex);
}
+void lockdep_unregister_ceph_context(CephContext *cct)
+{
+ pthread_mutex_lock(&lockdep_mutex);
+ if (cct == g_lockdep_ceph_ctx) {
+ // this cct is going away; shut it down!
+ g_lockdep = false;
+ g_lockdep_ceph_ctx = NULL;
+ }
+ pthread_mutex_unlock(&lockdep_mutex);
+}
+
int lockdep_dump_locks()
{
pthread_mutex_lock(&lockdep_mutex);
diff --git a/src/common/lockdep.h b/src/common/lockdep.h
index 9debdb66771..1dcf05378ee 100644
--- a/src/common/lockdep.h
+++ b/src/common/lockdep.h
@@ -20,6 +20,7 @@ class CephContext;
extern int g_lockdep;
extern void lockdep_register_ceph_context(CephContext *cct);
+extern void lockdep_unregister_ceph_context(CephContext *cct);
extern int lockdep_register(const char *n);
extern int lockdep_will_lock(const char *n, int id);
extern int lockdep_locked(const char *n, int id, bool force_backtrace=false);
diff --git a/src/libcephfs.cc b/src/libcephfs.cc
index b83677551a1..a240cc3a2fb 100644
--- a/src/libcephfs.cc
+++ b/src/libcephfs.cc
@@ -48,7 +48,7 @@ public:
try {
shutdown();
if (cct) {
- common_destroy_context(cct);
+ cct->put();
cct = NULL;
}
}
diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc
index ceacf7523fa..e70033623c6 100644
--- a/src/librados/RadosClient.cc
+++ b/src/librados/RadosClient.cc
@@ -57,13 +57,13 @@ bool librados::RadosClient::ms_get_authorizer(int dest_type,
librados::RadosClient::RadosClient(CephContext *cct_)
: Dispatcher(cct_),
- cct(cct_),
+ cct(cct_->get()),
conf(cct_->_conf),
state(DISCONNECTED),
monclient(cct_),
messenger(NULL),
objecter(NULL),
- lock("radosclient"),
+ lock("librados::RadosClient::lock"),
timer(cct, lock),
refcnt(1),
finisher(cct),
@@ -236,7 +236,7 @@ librados::RadosClient::~RadosClient()
delete messenger;
if (objecter)
delete objecter;
- common_destroy_context(cct);
+ cct->put();
cct = NULL;
}
diff --git a/src/librados/librados.cc b/src/librados/librados.cc
index dd3f88c1189..69ba440d5de 100644
--- a/src/librados/librados.cc
+++ b/src/librados/librados.cc
@@ -1301,6 +1301,8 @@ extern "C" int rados_create(rados_t *pcluster, const char * const id)
librados::RadosClient *radosp = new librados::RadosClient(cct);
*pcluster = (void *)radosp;
+
+ cct->put();
return 0;
}
diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc
index a6bca13b1b0..aaad4d8a028 100644
--- a/src/osd/OSDMap.cc
+++ b/src/osd/OSDMap.cc
@@ -1240,7 +1240,7 @@ void OSDMap::generate_test_instances(list<OSDMap*>& o)
uuid_d fsid;
o.back()->build_simple(cct, 1, fsid, 16, 7, 8);
o.back()->created = o.back()->modified = utime_t(1, 2); // fix timestamp
- delete cct;
+ cct->put();
}
string OSDMap::get_flag_string(unsigned f)
diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc
index b5db66a3558..556f57f3ba0 100644
--- a/src/rgw/librgw.cc
+++ b/src/rgw/librgw.cc
@@ -130,5 +130,5 @@ void librgw_free_bin(librgw_t rgw, char *bin)
void librgw_shutdown(librgw_t rgw)
{
- common_destroy_context(rgw);
+ rgw->put();
}