From: Patrick Donnelly Date: Mon, 24 Mar 2025 15:50:50 +0000 (-0400) Subject: mgr: add status command X-Git-Tag: v19.2.3~238^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6ba1a7a6dab64283189e00f8b043fbe8fb3405f5;p=ceph.git mgr: add status command The Rook operator relies on a `status` (asok) command to the mgr to verify it is operational. However, this command was actually served by the CephFS `Client` library that the ceph-mgr daemon statically linked in and used for sending MDS commands. That statically linked client was removed via 048fc68c (case insensitive directory tree feature). So, add a legitimate ceph-mgr status command which simply outputs an empty dictionary and returns success (0). TBD on adding useful information. Fixes: 048fc68c517f50b9978457f478ca4638f01caa09 Fixes: https://tracker.ceph.com/issues/70571 Signed-off-by: Patrick Donnelly (cherry picked from commit 4a7976a57c1ff823753c1c25274b6482f0a8c8ea) --- diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index 8795ad7f3a01c..c845f9c816710 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -41,6 +41,27 @@ using std::map; using std::string; using std::vector; +class MgrHook : public AdminSocketHook { + MgrStandby* mgr; +public: + explicit MgrHook(MgrStandby *m) : mgr(m) {} + int call(std::string_view admin_command, + const cmdmap_t& cmdmap, + const bufferlist& inbl, + Formatter *f, + std::ostream& errss, + bufferlist& outbl) override { + int r = 0; + try { + r = mgr->asok_command(admin_command, cmdmap, f, errss); + } catch (const TOPNSPC::common::bad_cmd_get& e) { + errss << e.what(); + r = -EINVAL; + } + return r; + } +}; + MgrStandby::MgrStandby(int argc, const char **argv) : Dispatcher(g_ceph_context), monc{g_ceph_context, poolctx}, @@ -66,7 +87,12 @@ MgrStandby::MgrStandby(int argc, const char **argv) : { } -MgrStandby::~MgrStandby() = default; +MgrStandby::~MgrStandby() { + if (asok_hook) { + g_ceph_context->get_admin_socket()->unregister_commands(asok_hook.get()); + asok_hook.reset(); + } +} const char** MgrStandby::get_tracked_conf_keys() const { @@ -115,6 +141,18 @@ void MgrStandby::handle_conf_change( } } +int MgrStandby::asok_command(std::string_view cmd, const cmdmap_t& cmdmap, Formatter* f, std::ostream& errss) +{ + dout(10) << __func__ << ": " << cmd << dendl; + if (cmd == "status") { + f->open_object_section("status"); + f->close_section(); + return 0; + } else { + return -ENOSYS; + } +} + int MgrStandby::init() { init_async_signal_handler(); @@ -132,6 +170,13 @@ int MgrStandby::init() client_messenger->add_dispatcher_head(&objecter); client_messenger->start(); + AdminSocket *admin_socket = g_ceph_context->get_admin_socket(); + asok_hook.reset(new MgrHook(this)); + { + int r = admin_socket->register_command("status", asok_hook.get(), "show status"); + ceph_assert(r == 0); + } + poolctx.start(2); // Initialize MonClient diff --git a/src/mgr/MgrStandby.h b/src/mgr/MgrStandby.h index ab5a8d05cbf02..72b7cdc4b1994 100644 --- a/src/mgr/MgrStandby.h +++ b/src/mgr/MgrStandby.h @@ -29,6 +29,7 @@ class MMgrMap; class Mgr; class PyModuleConfig; +class MgrHook; class MgrStandby : public Dispatcher, public md_config_obs_t { @@ -37,6 +38,7 @@ public: const char** get_tracked_conf_keys() const override; void handle_conf_change(const ConfigProxy& conf, const std::set &changed) override; + int asok_command(std::string_view cmd, const cmdmap_t& cmdmap, Formatter* f, std::ostream& errss); protected: ceph::async::io_context_pool poolctx; @@ -55,6 +57,7 @@ protected: PyModuleRegistry py_module_registry; std::shared_ptr active_mgr; + std::unique_ptr asok_hook; int orig_argc; const char **orig_argv;