]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-wnbd: use the right AdminSocket instance 52540/head
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Tue, 26 Sep 2023 11:52:31 +0000 (11:52 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 1 Mar 2024 17:39:00 +0000 (17:39 +0000)
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 <lpetrut@cloudbasesolutions.com>
src/tools/rbd_wnbd/rbd_mapping.cc
src/tools/rbd_wnbd/wnbd_handler.cc
src/tools/rbd_wnbd/wnbd_handler.h

index eaa79180929cb12323d788ae7b629fb7d696c358..35e3b7718c885ef0d517c48c2d0df0d64acc588d 100644 (file)
@@ -76,13 +76,17 @@ int RbdMapping::init()
 
   initial_image_size = info.size;
 
+  CephContext* cct = reinterpret_cast<CephContext*>(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<bool>("rbd_cache"),
                             cfg.io_req_workers,
-                            cfg.io_reply_workers);
+                            cfg.io_reply_workers,
+                            cct->get_admin_socket());
   return 0;
 }
 
index d6597e32c4496d9aab8e9890069a869ef1184120..82b01c906f2648711b1177117ddb622a2a74eadc 100644 (file)
@@ -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 (
index 6b9886a6e38de64411144692d314a652ba0900d0..139621483242fcfc1c2fa5af78b23446b0f768f3 100644 (file)
@@ -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