From a14003c492ad26ed4eef13e3d73e42212dd2bd93 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Tue, 26 Sep 2023 11:52:31 +0000 Subject: [PATCH] rbd-wnbd: use the right AdminSocket instance The rbd-wnbd daemon currently caches one rados context per cluster. However, it's registering hooks against the global context admin socket, which won't be available. For this reason, the "rbd-wnbd stats" command no longer works. To address this issue, we'll ensure that rbd-wnbd sets command hooks against the right admin socket instance, leveraging the image context. Signed-off-by: Lucian Petrut --- src/tools/rbd_wnbd/rbd_mapping.cc | 6 +++++- src/tools/rbd_wnbd/wnbd_handler.cc | 15 +++++++++++---- src/tools/rbd_wnbd/wnbd_handler.h | 12 ++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tools/rbd_wnbd/rbd_mapping.cc b/src/tools/rbd_wnbd/rbd_mapping.cc index eaa79180929cb..35e3b7718c885 100644 --- a/src/tools/rbd_wnbd/rbd_mapping.cc +++ b/src/tools/rbd_wnbd/rbd_mapping.cc @@ -76,13 +76,17 @@ int RbdMapping::init() initial_image_size = info.size; + CephContext* cct = reinterpret_cast(io_ctx.cct()); + ceph_assert(cct != nullptr); + handler = new WnbdHandler(image, cfg.devpath, info.size / RBD_WNBD_BLKSIZE, RBD_WNBD_BLKSIZE, !cfg.snapname.empty() || cfg.readonly, g_conf().get_val("rbd_cache"), cfg.io_req_workers, - cfg.io_reply_workers); + cfg.io_reply_workers, + cct->get_admin_socket()); return 0; } diff --git a/src/tools/rbd_wnbd/wnbd_handler.cc b/src/tools/rbd_wnbd/wnbd_handler.cc index d6597e32c4496..82b01c906f264 100644 --- a/src/tools/rbd_wnbd/wnbd_handler.cc +++ b/src/tools/rbd_wnbd/wnbd_handler.cc @@ -65,11 +65,18 @@ int WnbdHandler::wait() return err; } -WnbdAdminHook::WnbdAdminHook(WnbdHandler *handler) : m_handler(handler) +WnbdAdminHook::WnbdAdminHook(WnbdHandler *handler, AdminSocket* admin_socket) + : m_handler(handler) + , m_admin_socket(admin_socket) { - g_ceph_context->get_admin_socket()->register_command( - std::string("wnbd stats ") + m_handler->instance_name, - this, "get WNBD stats"); + if (m_admin_socket) { + m_admin_socket->register_command( + std::string("wnbd stats ") + m_handler->instance_name, + this, "get WNBD stats"); + } else { + dout(0) << "no admin socket provided, skipped registering wnbd hooks" + << dendl; + } } int WnbdAdminHook::call ( diff --git a/src/tools/rbd_wnbd/wnbd_handler.h b/src/tools/rbd_wnbd/wnbd_handler.h index 6b9886a6e38de..139621483242f 100644 --- a/src/tools/rbd_wnbd/wnbd_handler.h +++ b/src/tools/rbd_wnbd/wnbd_handler.h @@ -42,11 +42,14 @@ class WnbdHandler; class WnbdAdminHook : public AdminSocketHook { WnbdHandler *m_handler; + AdminSocket *m_admin_socket; public: - explicit WnbdAdminHook(WnbdHandler *handler); + explicit WnbdAdminHook(WnbdHandler *handler, AdminSocket* admin_socket); ~WnbdAdminHook() override { - g_ceph_context->get_admin_socket()->unregister_commands(this); + if (m_admin_socket) { + m_admin_socket->unregister_commands(this); + } } int call(std::string_view command, const cmdmap_t& cmdmap, @@ -74,7 +77,8 @@ public: uint64_t _block_count, uint32_t _block_size, bool _readonly, bool _rbd_cache_enabled, uint32_t _io_req_workers, - uint32_t _io_reply_workers) + uint32_t _io_reply_workers, + AdminSocket* admin_socket) : image(_image) , instance_name(_instance_name) , block_count(_block_count) @@ -84,7 +88,7 @@ public: , io_req_workers(_io_req_workers) , io_reply_workers(_io_reply_workers) { - admin_hook = new WnbdAdminHook(this); + admin_hook = new WnbdAdminHook(this, admin_socket); // Instead of relying on librbd's own thread pool, we're going to use a // separate one. This allows us to make assumptions on the threads that // are going to send the IO replies and thus be able to cache Windows -- 2.39.5