]> git-server-git.apps.pok.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>
Mon, 24 Mar 2025 18:14:55 +0000 (14:14 -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>
src/mgr/MgrStandby.cc
src/mgr/MgrStandby.h

index ea9e51b0dd118a3824e1b1eaf56e3321c992cd5c..c7976aa1e50d7188de87446da00a6f226cba08d9 100644 (file)
@@ -42,6 +42,27 @@ using std::string;
 using std::vector;
 using namespace std::literals;
 
+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},
@@ -67,7 +88,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();
+  }
+}
 
 std::vector<std::string> MgrStandby::get_tracked_keys() const noexcept
 {
@@ -114,6 +140,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();
@@ -131,6 +169,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 5c7e2222049fabd77f0c512339f1cecab12d67d3..dda322e68989dd3873d1220580bcff469ef0f2ef 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:
   std::vector<std::string> get_tracked_keys() const noexcept 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;