From: Jason Dillaman Date: Wed, 29 Jul 2015 16:46:24 +0000 (-0400) Subject: lockdep: allow lockdep to be dynamically enabled/disabled X-Git-Tag: v9.0.3~10^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F5425%2Fhead;p=ceph.git lockdep: allow lockdep to be dynamically enabled/disabled librbd test cases attempt to enable lockdep coverage via the librados API. Use a configuration observer to register/unregister lockdep support. Signed-off-by: Jason Dillaman --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e964e30701d3..7a5c52bb0621 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -40,6 +40,41 @@ using ceph::HeartbeatMap; +namespace { + +class LockdepObs : public md_config_obs_t { +public: + LockdepObs(CephContext *cct) : m_cct(cct), m_registered(false) { + } + virtual ~LockdepObs() { + if (m_registered) { + lockdep_unregister_ceph_context(m_cct); + } + } + + const char** get_tracked_conf_keys() const { + static const char *KEYS[] = {"lockdep", NULL}; + return KEYS; + } + + void handle_conf_change(const md_config_t *conf, + const std::set &changed) { + if (conf->lockdep && !m_registered) { + lockdep_register_ceph_context(m_cct); + m_registered = true; + } else if (!conf->lockdep && m_registered) { + lockdep_unregister_ceph_context(m_cct); + m_registered = false; + } + } +private: + CephContext *m_cct; + bool m_registered; +}; + + +} // anonymous namespace + class CephContextServiceThread : public Thread { public: @@ -371,7 +406,8 @@ CephContext::CephContext(uint32_t module_type_) _perf_counters_conf_obs(NULL), _heartbeat_map(NULL), _crypto_none(NULL), - _crypto_aes(NULL) + _crypto_aes(NULL), + _lockdep_obs(NULL) { ceph_spin_init(&_service_thread_lock); ceph_spin_init(&_associated_objs_lock); @@ -386,6 +422,9 @@ CephContext::CephContext(uint32_t module_type_) _cct_obs = new CephContextObs(this); _conf->add_observer(_cct_obs); + _lockdep_obs = new LockdepObs(this); + _conf->add_observer(_lockdep_obs); + _perf_counters_collection = new PerfCountersCollection(this); _admin_socket = new AdminSocket(this); _heartbeat_map = new HeartbeatMap(this); @@ -420,10 +459,6 @@ CephContext::~CephContext() it != _associated_objs.end(); ++it) delete it->second; - if (_conf->lockdep) { - lockdep_unregister_ceph_context(this); - } - _admin_socket->unregister_command("perfcounters_dump"); _admin_socket->unregister_command("perf dump"); _admin_socket->unregister_command("1"); @@ -457,6 +492,10 @@ CephContext::~CephContext() delete _cct_obs; _cct_obs = NULL; + _conf->remove_observer(_lockdep_obs); + delete _lockdep_obs; + _lockdep_obs = NULL; + _log->stop(); delete _log; _log = NULL; diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index cf2334206958..95f6ea59bda3 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -171,6 +171,8 @@ private: ceph_spinlock_t _feature_lock; std::set _experimental_features; + md_config_obs_t *_lockdep_obs; + friend class CephContextObs; }; diff --git a/src/common/common_init.cc b/src/common/common_init.cc index dd0b0e767dd3..90232c19a63d 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -119,9 +119,4 @@ void common_init_finish(CephContext *cct, int flags) if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) cct->start_service_thread(); - - if (cct->_conf->lockdep) { - g_lockdep = true; - lockdep_register_ceph_context(cct); - } } diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index ea3f6d55d17b..5f9fa191a07d 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -67,6 +67,7 @@ void lockdep_register_ceph_context(CephContext *cct) { pthread_mutex_lock(&lockdep_mutex); if (g_lockdep_ceph_ctx == NULL) { + g_lockdep = true; g_lockdep_ceph_ctx = cct; lockdep_dout(0) << "lockdep start" << dendl; diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 78dc00f5feb4..06a7c2eaff58 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -120,8 +120,6 @@ void global_init(std::vector < const char * > *alt_def_args, { global_pre_init(alt_def_args, args, module_type, code_env, flags); - g_lockdep = g_ceph_context->_conf->lockdep; - // signal stuff int siglist[] = { SIGPIPE, 0 }; block_signals(siglist, NULL); @@ -142,9 +140,6 @@ void global_init(std::vector < const char * > *alt_def_args, } } - if (g_lockdep) { - lockdep_register_ceph_context(g_ceph_context); - } register_assert_context(g_ceph_context); // call all observers now. this has the side-effect of configuring