]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
lockdep: allow lockdep to be dynamically enabled/disabled 5768/head
authorJason Dillaman <dillaman@redhat.com>
Wed, 29 Jul 2015 16:46:24 +0000 (12:46 -0400)
committerLoic Dachary <ldachary@redhat.com>
Sun, 6 Sep 2015 14:05:30 +0000 (16:05 +0200)
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 <dillaman@redhat.com>
(cherry picked from commit af0cade0293be22e74a3293765676c7b227b06c4)

src/common/ceph_context.cc
src/common/ceph_context.h
src/common/common_init.cc
src/common/lockdep.cc
src/global/global_init.cc

index 6697142b3ebb7a815102fe7e2842ca57701b9618..39c7f4e1907eade36ecb3d921c6b692b1257e199 100644 (file)
 
 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 <std::string> &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;
index a8dfec55410e75805db9510136b870ae6aa1acb4..91810aa09baf3c33f0955689845178f21b6a1e48 100644 (file)
@@ -173,6 +173,8 @@ private:
   ceph_spinlock_t _feature_lock;
   std::set<std::string> _experimental_features;
 
+  md_config_obs_t *_lockdep_obs;
+
   friend class CephContextObs;
 };
 
index dd0b0e767dd3dc308a023aa8b646421b0a6a7097..90232c19a63daf0f569d9991a86c1b711d40c11e 100644 (file)
@@ -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);
-  }
 }
index ea3f6d55d17b08a59e3da01ca6102cdd3c24f509..5f9fa191a07d0a3df955b18575e0d299ac0809f3 100644 (file)
@@ -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;
 
index f03677c028c39b1348cce5d77078f74b412c5733..3464b0aff534fa7f5e299c87f731d384d2505cc5 100644 (file)
@@ -116,8 +116,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);
@@ -138,9 +136,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