summaryrefslogtreecommitdiffstats
path: root/src/librbd/TaskFinisher.h
diff options
context:
space:
mode:
authorJason Dillaman <dillaman@redhat.com>2020-07-24 18:13:10 +0200
committerJason Dillaman <dillaman@redhat.com>2020-07-27 15:15:15 +0200
commit90bd1d7a857c0f3c57bda60975f58f9859940185 (patch)
treef6512ec74322df9dbaa73ba132368cf9e5e23816 /src/librbd/TaskFinisher.h
parentMerge pull request #36149 from adamemerson/wip-warn-more (diff)
downloadceph-90bd1d7a857c0f3c57bda60975f58f9859940185.tar.xz
ceph-90bd1d7a857c0f3c57bda60975f58f9859940185.zip
librbd: use task finisher thread for image open/close callbacks
There was a potential race condition with utilizing the AsioEngine to deliver asynchronous image open and close callbacks. This left the potential for the io_context thread to attempt to destroy itself. This commit changes the behavior of the image open and close callbacks to always delete the ImageCtx (now matches the synchronous API behavior) and it always invokes the callback in Finisher thread whose lifetime is tied to the CephContext. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Diffstat (limited to 'src/librbd/TaskFinisher.h')
-rw-r--r--src/librbd/TaskFinisher.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/librbd/TaskFinisher.h b/src/librbd/TaskFinisher.h
index a791e786ff1..bf76f633f7b 100644
--- a/src/librbd/TaskFinisher.h
+++ b/src/librbd/TaskFinisher.h
@@ -20,6 +20,11 @@ struct TaskFinisherSingleton {
SafeTimer *m_safe_timer;
Finisher *m_finisher;
+ static TaskFinisherSingleton& get_singleton(CephContext* cct) {
+ return cct->lookup_or_create_singleton_object<
+ TaskFinisherSingleton>("librbd::TaskFinisherSingleton", false, cct);
+ }
+
explicit TaskFinisherSingleton(CephContext *cct) {
m_safe_timer = new SafeTimer(cct, m_lock, false);
m_safe_timer->init();
@@ -36,6 +41,10 @@ struct TaskFinisherSingleton {
m_finisher->stop();
delete m_finisher;
}
+
+ void queue(Context* ctx, int r) {
+ m_finisher->queue(ctx, r);
+ }
};
@@ -43,9 +52,7 @@ template <typename Task>
class TaskFinisher {
public:
TaskFinisher(CephContext &cct) : m_cct(cct) {
- auto& singleton =
- cct.lookup_or_create_singleton_object<TaskFinisherSingleton>(
- "librbd::TaskFinisher::m_safe_timer", false, &cct);
+ auto& singleton = TaskFinisherSingleton::get_singleton(&cct);
m_lock = &singleton.m_lock;
m_safe_timer = singleton.m_safe_timer;
m_finisher = singleton.m_finisher;