]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd / ImageCtx: singleton safetimer instance helper
authorVenky Shankar <vshankar@redhat.com>
Wed, 13 Jul 2016 05:57:28 +0000 (11:27 +0530)
committerVenky Shankar <vshankar@redhat.com>
Sun, 7 Aug 2016 11:01:36 +0000 (16:31 +0530)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/Journal.cc

index 56989fa1c974990d42d27e838774a54276b9eb30..748d11a2aa53c1f5fd74a25be2001df8946042cc 100644 (file)
@@ -9,6 +9,7 @@
 #include "common/errno.h"
 #include "common/perf_counters.h"
 #include "common/WorkQueue.h"
+#include "common/Timer.h"
 
 #include "librbd/AioImageRequestWQ.h"
 #include "librbd/AioCompletion.h"
@@ -62,6 +63,21 @@ public:
   }
 };
 
+class SafeTimerSingleton : public SafeTimer {
+public:
+  Mutex lock;
+
+  explicit SafeTimerSingleton(CephContext *cct)
+      : SafeTimer(cct, lock, true),
+        lock("librbd::Journal::SafeTimerSingleton::lock") {
+    init();
+  }
+  virtual ~SafeTimerSingleton() {
+    Mutex::Locker locker(lock);
+    shutdown();
+  }
+};
+
 struct C_FlushCache : public Context {
   ImageCtx *image_ctx;
   Context *on_safe;
@@ -1049,4 +1065,13 @@ struct C_InvalidateCache : public Context {
       thread_pool_singleton, "librbd::thread_pool");
     return thread_pool_singleton;
   }
+
+  void ImageCtx::get_timer_instance(CephContext *cct, SafeTimer **timer,
+                                    Mutex **timer_lock) {
+    SafeTimerSingleton *safe_timer_singleton;
+    cct->lookup_or_create_singleton_object<SafeTimerSingleton>(
+      safe_timer_singleton, "librbd::journal::safe_timer");
+    *timer = safe_timer_singleton;
+    *timer_lock = &safe_timer_singleton->lock;
+  }
 }
index fd580d9cc9fa4aee3e0cfe01e2613ff19a58731a..320ee95e20e4edd86b9575f02e7bfc0943a4b06c 100644 (file)
@@ -33,6 +33,7 @@ class ContextWQ;
 class Finisher;
 class PerfCounters;
 class ThreadPool;
+class SafeTimer;
 
 namespace librbd {
 
@@ -303,6 +304,8 @@ namespace librbd {
     void set_journal_policy(journal::Policy *policy);
 
     static ThreadPool *get_thread_pool_instance(CephContext *cct);
+    static void get_timer_instance(CephContext *cct, SafeTimer **timer,
+                                   Mutex **timer_lock);
   };
 }
 
index f98977bac6dd94a644bf017463a384421bad23a4..d807af7160632ca2972878295f3e6ead94f912db 100644 (file)
@@ -155,21 +155,6 @@ public:
   }
 };
 
-class SafeTimerSingleton : public SafeTimer {
-public:
-  Mutex lock;
-
-  explicit SafeTimerSingleton(CephContext *cct)
-      : SafeTimer(cct, lock, true),
-        lock("librbd::Journal::SafeTimerSingleton::lock") {
-    init();
-  }
-  virtual ~SafeTimerSingleton() {
-    Mutex::Locker locker(lock);
-    shutdown();
-  }
-};
-
 template <typename J>
 int open_journaler(CephContext *cct, J *journaler,
                    cls::journal::Client *client,
@@ -324,12 +309,7 @@ Journal<I>::Journal(I &image_ctx)
   m_work_queue = new ContextWQ("librbd::journal::work_queue",
                                cct->_conf->rbd_op_thread_timeout,
                                thread_pool_singleton);
-
-  SafeTimerSingleton *safe_timer_singleton;
-  cct->lookup_or_create_singleton_object<SafeTimerSingleton>(
-    safe_timer_singleton, "librbd::journal::safe_timer");
-  m_timer = safe_timer_singleton;
-  m_timer_lock = &safe_timer_singleton->lock;
+  ImageCtx::get_timer_instance(cct, &m_timer, &m_timer_lock);
 }
 
 template <typename I>