From: Venky Shankar Date: Wed, 13 Jul 2016 05:57:28 +0000 (+0530) Subject: librbd / ImageCtx: singleton safetimer instance helper X-Git-Tag: ses5-milestone5~161^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1416f1c3bc7600feacd325472a4d2f27e37bbc18;p=ceph.git librbd / ImageCtx: singleton safetimer instance helper Signed-off-by: Venky Shankar --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 56989fa1c974..748d11a2aa53 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -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( + safe_timer_singleton, "librbd::journal::safe_timer"); + *timer = safe_timer_singleton; + *timer_lock = &safe_timer_singleton->lock; + } } diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index fd580d9cc9fa..320ee95e20e4 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -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); }; } diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index f98977bac6dd..d807af716063 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -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 int open_journaler(CephContext *cct, J *journaler, cls::journal::Client *client, @@ -324,12 +309,7 @@ Journal::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( - 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