]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: add status command
authorPatrick Donnelly <pdonnell@ibm.com>
Mon, 24 Mar 2025 15:50:50 +0000 (11:50 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Tue, 25 Mar 2025 18:45:02 +0000 (14:45 -0400)
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 <pdonnell@ibm.com>
(cherry picked from commit 4a7976a57c1ff823753c1c25274b6482f0a8c8ea)

src/mgr/MgrStandby.cc
src/mgr/MgrStandby.h

index 8795ad7f3a01ce840cb85d1d303f08cf83ae2de2..c845f9c8167100d4f6ec0c3e67c25520bd7d13e9 100644 (file)
@@ -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
index ab5a8d05cbf02f9461f5c8deff1ba3c51263ac55..72b7cdc4b19945f203340e3e416215b08be25a5e 100644 (file)
@@ -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 <std::string> &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<Mgr> active_mgr;
+  std::unique_ptr<MgrHook> asok_hook;
 
   int orig_argc;
   const char **orig_argv;