mirror of
https://github.com/ceph/ceph
synced 2025-01-19 17:41:39 +00:00
common/admin_socket: drop unregister_command(); use per-hook variant
There's never a need to unregister individual commands; doing it by hook is sufficient for all users. Simpler and faster. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
1a7cdedb56
commit
d134a622a5
@ -487,30 +487,6 @@ int AdminSocket::register_command(std::string_view cmddesc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdminSocket::unregister_command(std::string_view command)
|
||||
{
|
||||
int ret;
|
||||
std::unique_lock l(lock);
|
||||
auto i = hooks.find(command);
|
||||
if (i != hooks.cend()) {
|
||||
ldout(m_cct, 5) << "unregister_command " << command << dendl;
|
||||
|
||||
// If we are currently processing a command, wait for it to
|
||||
// complete in case it referenced the hook that we are
|
||||
// unregistering.
|
||||
in_hook_cond.wait(l, [this]() { return !in_hook; });
|
||||
|
||||
hooks.erase(i);
|
||||
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
ldout(m_cct, 5) << "unregister_command " << command << " ENOENT" << dendl;
|
||||
ret = -ENOENT;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AdminSocket::unregister_commands(const AdminSocketHook *hook)
|
||||
{
|
||||
std::unique_lock l(lock);
|
||||
@ -674,10 +650,10 @@ void AdminSocket::shutdown()
|
||||
unregister_commands(version_hook.get());
|
||||
version_hook.reset();
|
||||
|
||||
unregister_command("help");
|
||||
unregister_commands(help_hook.get());
|
||||
help_hook.reset();
|
||||
|
||||
unregister_command("get_command_descriptions");
|
||||
unregister_commands(getdescs_hook.get());
|
||||
getdescs_hook.reset();
|
||||
|
||||
remove_cleanup_file(m_path);
|
||||
|
@ -74,18 +74,6 @@ public:
|
||||
AdminSocketHook *hook,
|
||||
std::string_view help);
|
||||
|
||||
/**
|
||||
* unregister an admin socket command.
|
||||
*
|
||||
* If a command is currently in progress, this will block until it
|
||||
* is done. For that reason, you must not hold any locks required
|
||||
* by your hook while you call this.
|
||||
*
|
||||
* @param command command string
|
||||
* @return 0 on succest, -ENOENT if command dne.
|
||||
*/
|
||||
int unregister_command(std::string_view command);
|
||||
|
||||
/*
|
||||
* unregister all commands belong to hook.
|
||||
*/
|
||||
|
@ -145,7 +145,7 @@ public:
|
||||
}
|
||||
~MempoolObs() override {
|
||||
cct->_conf.remove_observer(this);
|
||||
cct->get_admin_socket()->unregister_command("dump_mempools");
|
||||
cct->get_admin_socket()->unregister_commands(this);
|
||||
}
|
||||
|
||||
// md_config_obs_t
|
||||
|
@ -81,9 +81,9 @@ LibrbdAdminSocketHook::LibrbdAdminSocketHook(ImageCtx *ictx) :
|
||||
}
|
||||
|
||||
LibrbdAdminSocketHook::~LibrbdAdminSocketHook() {
|
||||
(void)admin_socket->unregister_commands(this);
|
||||
for (Commands::const_iterator i = commands.begin(); i != commands.end();
|
||||
++i) {
|
||||
(void)admin_socket->unregister_command(i->first);
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +46,7 @@ public:
|
||||
{
|
||||
AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
|
||||
if (admin_socket && alloc) {
|
||||
int r = admin_socket->unregister_command(("bluestore allocator dump " + name).c_str());
|
||||
ceph_assert(r == 0);
|
||||
r = admin_socket->unregister_command(("bluestore allocator score " + name).c_str());
|
||||
ceph_assert(r == 0);
|
||||
r = admin_socket->unregister_command(("bluestore allocator fragmentation " + name).c_str());
|
||||
ceph_assert(r == 0);
|
||||
admin_socket->unregister_commands(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,7 @@ public:
|
||||
|
||||
~SocketHook() {
|
||||
AdminSocket* admin_socket = bluefs->cct->get_admin_socket();
|
||||
int r = admin_socket->unregister_command("bluestore bluefs available");
|
||||
ceph_assert(r == 0);
|
||||
admin_socket->unregister_commands(this);
|
||||
}
|
||||
private:
|
||||
SocketHook(BlueFS* bluefs) :
|
||||
|
@ -531,7 +531,7 @@ void Objecter::shutdown()
|
||||
// shutdown() with the ::initialized check at start.
|
||||
if (m_request_state_hook) {
|
||||
AdminSocket* admin_socket = cct->get_admin_socket();
|
||||
admin_socket->unregister_command("objecter_requests");
|
||||
admin_socket->unregister_commands(m_request_state_hook);
|
||||
delete m_request_state_hook;
|
||||
m_request_state_hook = NULL;
|
||||
}
|
||||
|
@ -832,7 +832,7 @@ RGWCoroutinesManagerRegistry::~RGWCoroutinesManagerRegistry()
|
||||
{
|
||||
AdminSocket *admin_socket = cct->get_admin_socket();
|
||||
if (!admin_command.empty()) {
|
||||
admin_socket->unregister_command(admin_command);
|
||||
admin_socket->unregister_commands(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -840,7 +840,7 @@ int RGWCoroutinesManagerRegistry::hook_to_admin_command(const string& command)
|
||||
{
|
||||
AdminSocket *admin_socket = cct->get_admin_socket();
|
||||
if (!admin_command.empty()) {
|
||||
admin_socket->unregister_command(admin_command);
|
||||
admin_socket->unregister_commands(this);
|
||||
}
|
||||
admin_command = command;
|
||||
int r = admin_socket->register_command(admin_command, this,
|
||||
|
@ -98,9 +98,9 @@ public:
|
||||
}
|
||||
|
||||
~ImageDeleterAdminSocketHook() override {
|
||||
(void)admin_socket->unregister_commands(this);
|
||||
for (Commands::const_iterator i = commands.begin(); i != commands.end();
|
||||
++i) {
|
||||
(void)admin_socket->unregister_command(i->first);
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
@ -188,10 +188,8 @@ public:
|
||||
}
|
||||
|
||||
~ImageReplayerAdminSocketHook() override {
|
||||
admin_socket->unregister_commands(this);
|
||||
for (auto &it : commands) {
|
||||
if (it.second->registered) {
|
||||
admin_socket->unregister_command(it.first);
|
||||
}
|
||||
delete it.second;
|
||||
}
|
||||
commands.clear();
|
||||
|
@ -314,9 +314,9 @@ public:
|
||||
}
|
||||
|
||||
~MirrorAdminSocketHook() override {
|
||||
(void)admin_socket->unregister_commands(this);
|
||||
for (Commands::const_iterator i = commands.begin(); i != commands.end();
|
||||
++i) {
|
||||
(void)admin_socket->unregister_command(i->first);
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
@ -179,8 +179,8 @@ public:
|
||||
}
|
||||
|
||||
~PoolReplayerAdminSocketHook() override {
|
||||
(void)admin_socket->unregister_commands(this);
|
||||
for (auto i = commands.begin(); i != commands.end(); ++i) {
|
||||
(void)admin_socket->unregister_command(i->first);
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user