From 5360d8612d63768f90ceb55ba4a03d772e2c7a37 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Tue, 23 Feb 2016 22:20:51 +0200 Subject: [PATCH] librbd: init asok_hook on open so name is always known Signed-off-by: Mykola Golub --- src/librbd/ImageCtx.cc | 15 ++++++++++++--- src/librbd/ImageCtx.h | 1 + src/librbd/image/CloseRequest.cc | 5 +---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 762d637421e2f..fa7c5a52e306c 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -175,8 +175,6 @@ struct C_InvalidateCache : public Context { if (snap) snap_name = snap; - asok_hook = new LibrbdAdminSocketHook(this); - memset(&header, 0, sizeof(header)); memset(&layout, 0, sizeof(layout)); @@ -196,6 +194,7 @@ struct C_InvalidateCache : public Context { assert(exclusive_lock == NULL); assert(object_map == NULL); assert(journal == NULL); + assert(asok_hook == NULL); if (perfcounter) { perf_stop(); @@ -221,7 +220,6 @@ struct C_InvalidateCache : public Context { delete op_work_queue; delete aio_work_queue; - delete asok_hook; delete operations; delete state; } @@ -234,6 +232,8 @@ struct C_InvalidateCache : public Context { } apply_metadata_confs(); + asok_hook = new LibrbdAdminSocketHook(this); + string pname = string("librbd-") + id + string("-") + data_ctx.get_pool_name() + string("-") + name; if (!snap_name.empty()) { @@ -286,6 +286,15 @@ struct C_InvalidateCache : public Context { readahead.set_max_readahead_size(readahead_max_bytes); } + void ImageCtx::shutdown() { + if (image_watcher != nullptr) { + unregister_watch(); + } + + delete asok_hook; + asok_hook = nullptr; + } + void ImageCtx::init_layout() { if (stripe_unit == 0 || stripe_count == 0) { diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index caf9bdc9bec34..0d84f0caad370 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -197,6 +197,7 @@ namespace librbd { const char *snap, IoCtx& p, bool read_only); ~ImageCtx(); void init(); + void shutdown(); void init_layout(); void perf_start(std::string name); void perf_stop(); diff --git a/src/librbd/image/CloseRequest.cc b/src/librbd/image/CloseRequest.cc index 145a998dbf6cf..19916396a0715 100644 --- a/src/librbd/image/CloseRequest.cc +++ b/src/librbd/image/CloseRequest.cc @@ -248,10 +248,7 @@ void CloseRequest::handle_flush_image_watcher(int r) { template void CloseRequest::finish() { - if (m_image_ctx->image_watcher != nullptr) { - m_image_ctx->unregister_watch(); - } - + m_image_ctx->shutdown(); m_on_finish->complete(m_error_result); delete this; } -- 2.47.3