From: Lucian Petrut Date: Tue, 26 Sep 2023 08:00:19 +0000 (+0000) Subject: rbd-wnbd: adjust admin socket hook to accept image path X-Git-Tag: v19.1.0~262^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=14b873047b0429b82117aa6f974c46fbeab7f89c;p=ceph.git rbd-wnbd: adjust admin socket hook to accept image path For each rbd-wnbd mapping we set an admin socket hook that can be used to retrieve IO stats. Now that the same daemon is reused for multiple mappings, we need to distinguish the images when receiving a "stats" request. For this reason, we'll add the image identifier to "wnbd stats" admin socket commands. Signed-off-by: Lucian Petrut (cherry picked from commit 83d58ab307063b4a37f3a297af2b0e6ba27e84dc) --- diff --git a/src/tools/rbd_wnbd/rbd_wnbd.cc b/src/tools/rbd_wnbd/rbd_wnbd.cc index b3a42285b2c1..57691bb72360 100644 --- a/src/tools/rbd_wnbd/rbd_wnbd.cc +++ b/src/tools/rbd_wnbd/rbd_wnbd.cc @@ -1159,8 +1159,8 @@ static int do_stats(std::string search_devpath) AdminSocketClient client = AdminSocketClient(cfg.admin_sock_path); std::string output; - std::string result = client.do_request("{\"prefix\":\"wnbd stats\"}", - &output); + std::string cmd = "{\"prefix\":\"wnbd stats " + cfg.devpath + "\"}"; + std::string result = client.do_request(cmd, &output); if (!result.empty()) { std::cerr << "Admin socket error: " << result << std::endl; return -EINVAL; diff --git a/src/tools/rbd_wnbd/wnbd_handler.cc b/src/tools/rbd_wnbd/wnbd_handler.cc index d5f4356ad177..d6597e32c449 100644 --- a/src/tools/rbd_wnbd/wnbd_handler.cc +++ b/src/tools/rbd_wnbd/wnbd_handler.cc @@ -65,6 +65,13 @@ int WnbdHandler::wait() return err; } +WnbdAdminHook::WnbdAdminHook(WnbdHandler *handler) : m_handler(handler) +{ + g_ceph_context->get_admin_socket()->register_command( + std::string("wnbd stats ") + m_handler->instance_name, + this, "get WNBD stats"); +} + int WnbdAdminHook::call ( std::string_view command, const cmdmap_t& cmdmap, const bufferlist&, @@ -72,7 +79,7 @@ int WnbdAdminHook::call ( std::ostream& errss, bufferlist& out) { - if (command == "wnbd stats") { + if (command == "wnbd stats " + m_handler->instance_name) { return m_handler->dump_stats(f); } return -ENOSYS; diff --git a/src/tools/rbd_wnbd/wnbd_handler.h b/src/tools/rbd_wnbd/wnbd_handler.h index f3b3e4341b01..6b9886a6e38d 100644 --- a/src/tools/rbd_wnbd/wnbd_handler.h +++ b/src/tools/rbd_wnbd/wnbd_handler.h @@ -44,11 +44,7 @@ class WnbdAdminHook : public AdminSocketHook { WnbdHandler *m_handler; public: - explicit WnbdAdminHook(WnbdHandler *handler) : - m_handler(handler) { - g_ceph_context->get_admin_socket()->register_command( - "wnbd stats", this, "get WNBD stats"); - } + explicit WnbdAdminHook(WnbdHandler *handler); ~WnbdAdminHook() override { g_ceph_context->get_admin_socket()->unregister_commands(this); } @@ -140,6 +136,7 @@ private: void set_sense(uint8_t sense_key, uint8_t asc); }; + friend WnbdAdminHook; friend std::ostream &operator<<(std::ostream &os, const IOContext &ctx); void send_io_response(IOContext *ctx);