From: Jason Dillaman Date: Fri, 10 Jul 2020 15:24:08 +0000 (-0400) Subject: librbd: ensure all asio completions are complete at ImageCtx destruction X-Git-Tag: v16.1.0~1685^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fed9f94300609a41d98bc63cd783df74ed115958;p=ceph.git librbd: ensure all asio completions are complete at ImageCtx destruction With multiple threads of execution possible, we need to ensure that all completions have fired prior to the destruction of the AsioEngine. We also need to ensure that the AsioEngine is destoyed outside the context of its owned stands. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 2c238abbde7..ddfa8efc768 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -172,6 +172,11 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { delete state; delete plugin_registry; + + // destroy our AsioEngine via its shared io_context to ensure that we + // aren't executing within an AsioEngine-owned strand + auto& io_context = asio_engine->get_io_context(); + boost::asio::post(io_context, [asio_engine=std::move(asio_engine)]() {}); } void ImageCtx::init() { diff --git a/src/librbd/asio/ContextWQ.cc b/src/librbd/asio/ContextWQ.cc index db4fadec69f..2d12d5080fd 100644 --- a/src/librbd/asio/ContextWQ.cc +++ b/src/librbd/asio/ContextWQ.cc @@ -22,6 +22,7 @@ ContextWQ::ContextWQ(CephContext* cct, boost::asio::io_context& io_context) ContextWQ::~ContextWQ() { ldout(m_cct, 20) << dendl; + drain(); } void ContextWQ::drain() {