Skip to content

Commit 47cde58

Browse files
committed
Merge PR ceph#62465 into main
* refs/pull/62465/head: qa: add test for `mgr status` command mgr: add status command Reviewed-by: Laura Flores <[email protected]> Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents b047ff8 + 9074e2c commit 47cde58

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

qa/suites/rados/mgr/tasks/3-mgrmodules.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ mgrmodules:
66
tasks:
77
- sequential:
88
- mgrmodules
9+
- exec:
10+
mon.a:
11+
- ceph tell mgr status

src/mgr/MgrStandby.cc

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ using std::string;
4242
using std::vector;
4343
using namespace std::literals;
4444

45+
class MgrHook : public AdminSocketHook {
46+
MgrStandby* mgr;
47+
public:
48+
explicit MgrHook(MgrStandby *m) : mgr(m) {}
49+
int call(std::string_view admin_command,
50+
const cmdmap_t& cmdmap,
51+
const bufferlist& inbl,
52+
Formatter *f,
53+
std::ostream& errss,
54+
bufferlist& outbl) override {
55+
int r = 0;
56+
try {
57+
r = mgr->asok_command(admin_command, cmdmap, f, errss);
58+
} catch (const TOPNSPC::common::bad_cmd_get& e) {
59+
errss << e.what();
60+
r = -EINVAL;
61+
}
62+
return r;
63+
}
64+
};
65+
4566
MgrStandby::MgrStandby(int argc, const char **argv) :
4667
Dispatcher(g_ceph_context),
4768
monc{g_ceph_context, poolctx},
@@ -67,7 +88,12 @@ MgrStandby::MgrStandby(int argc, const char **argv) :
6788
{
6889
}
6990

70-
MgrStandby::~MgrStandby() = default;
91+
MgrStandby::~MgrStandby() {
92+
if (asok_hook) {
93+
g_ceph_context->get_admin_socket()->unregister_commands(asok_hook.get());
94+
asok_hook.reset();
95+
}
96+
}
7197

7298
std::vector<std::string> MgrStandby::get_tracked_keys() const noexcept
7399
{
@@ -114,6 +140,18 @@ void MgrStandby::handle_conf_change(
114140
}
115141
}
116142

143+
int MgrStandby::asok_command(std::string_view cmd, const cmdmap_t& cmdmap, Formatter* f, std::ostream& errss)
144+
{
145+
dout(10) << __func__ << ": " << cmd << dendl;
146+
if (cmd == "status") {
147+
f->open_object_section("status");
148+
f->close_section();
149+
return 0;
150+
} else {
151+
return -ENOSYS;
152+
}
153+
}
154+
117155
int MgrStandby::init()
118156
{
119157
init_async_signal_handler();
@@ -131,6 +169,13 @@ int MgrStandby::init()
131169
client_messenger->add_dispatcher_head(&objecter);
132170
client_messenger->start();
133171

172+
AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
173+
asok_hook.reset(new MgrHook(this));
174+
{
175+
int r = admin_socket->register_command("status", asok_hook.get(), "show status");
176+
ceph_assert(r == 0);
177+
}
178+
134179
poolctx.start(2);
135180

136181
// Initialize MonClient

src/mgr/MgrStandby.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
class MMgrMap;
3030
class Mgr;
3131
class PyModuleConfig;
32+
class MgrHook;
3233

3334
class MgrStandby : public Dispatcher,
3435
public md_config_obs_t {
@@ -37,6 +38,7 @@ class MgrStandby : public Dispatcher,
3738
std::vector<std::string> get_tracked_keys() const noexcept override;
3839
void handle_conf_change(const ConfigProxy& conf,
3940
const std::set <std::string> &changed) override;
41+
int asok_command(std::string_view cmd, const cmdmap_t& cmdmap, Formatter* f, std::ostream& errss);
4042

4143
protected:
4244
ceph::async::io_context_pool poolctx;
@@ -55,6 +57,7 @@ class MgrStandby : public Dispatcher,
5557

5658
PyModuleRegistry py_module_registry;
5759
std::shared_ptr<Mgr> active_mgr;
60+
std::unique_ptr<MgrHook> asok_hook;
5861

5962
int orig_argc;
6063
const char **orig_argv;

0 commit comments

Comments
 (0)