mirror of
https://github.com/ceph/ceph
synced 2025-01-01 08:32:24 +00:00
librbd / ImageCtx: singleton safetimer instance helper
Signed-off-by: Venky Shankar <vshankar@redhat.com>
This commit is contained in:
parent
21e6573d49
commit
1416f1c3bc
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user