From a37a17d97cb1df79ec1cb1ff0ca05637eecc3210 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 10 Oct 2018 09:11:46 -0700 Subject: [PATCH] mds: cleanup command descriptions In particular, the cap on the command had no effect. (We require "*" unconditionally when processing commands.) Fixes: http://tracker.ceph.com/issues/36380 Signed-off-by: Patrick Donnelly --- src/mds/MDSDaemon.cc | 93 +++++++++++++------------------------------- src/mds/MDSDaemon.h | 16 +++++++- 2 files changed, 40 insertions(+), 69 deletions(-) diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 99f12fc7eda..a27de15c9a4 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -643,70 +643,31 @@ void MDSDaemon::handle_command(const MCommand::const_ref &m) } } - -struct MDSCommand { - string cmdstring; - string helpstring; - string module; - string perm; - string availability; -} mds_commands[] = { - -#define COMMAND(parsesig, helptext, module, perm, availability) \ - {parsesig, helptext, module, perm, availability}, - -COMMAND("injectargs " \ - "name=injected_args,type=CephString,n=N", - "inject configuration arguments into running MDS", - "mds", "*", "cli,rest") -COMMAND("config set " \ - "name=key,type=CephString name=value,type=CephString", - "Set a configuration option at runtime (not persistent)", - "mds", "*", "cli,rest") -COMMAND("config unset " \ - "name=key,type=CephString", - "Unset a configuration option at runtime (not persistent)", - "mds", "*", "cli,rest") -COMMAND("exit", - "Terminate this MDS", - "mds", "*", "cli,rest") -COMMAND("respawn", - "Restart this MDS", - "mds", "*", "cli,rest") -COMMAND("session kill " \ - "name=session_id,type=CephInt", - "End a client session", - "mds", "*", "cli,rest") -COMMAND("cpu_profiler " \ - "name=arg,type=CephChoices,strings=status|flush", - "run cpu profiling on daemon", "mds", "rw", "cli,rest") -COMMAND("session ls " \ - "name=filters,type=CephString,n=N,req=false", - "List client sessions", "mds", "r", "cli,rest") -COMMAND("client ls " \ - "name=filters,type=CephString,n=N,req=false", - "List client sessions", "mds", "r", "cli,rest") -COMMAND("session evict " \ - "name=filters,type=CephString,n=N,req=false", - "Evict client session(s)", "mds", "rw", "cli,rest") -COMMAND("client evict " \ - "name=filters,type=CephString,n=N,req=false", - "Evict client session(s)", "mds", "rw", "cli,rest") -COMMAND("damage ls", - "List detected metadata damage", "mds", "r", "cli,rest") -COMMAND("damage rm name=damage_id,type=CephInt", - "Remove a damage table entry", "mds", "rw", "cli,rest") -COMMAND("version", "report version of MDS", "mds", "r", "cli,rest") -COMMAND("heap " \ - "name=heapcmd,type=CephChoices,strings=dump|start_profiler|stop_profiler|release|stats", \ - "show heap usage info (available only if compiled with tcmalloc)", \ - "mds", "*", "cli,rest") -COMMAND("cache drop name=timeout,type=CephInt,range=1", "trim cache and optionally " - "request client to release all caps and flush the journal", "mds", - "r", "cli,rest") +const std::vector& MDSDaemon::get_commands() +{ + static const std::vector commands = { + MDSCommand("injectargs name=injected_args,type=CephString,n=N", "inject configuration arguments into running MDS"), + MDSCommand("config set name=key,type=CephString name=value,type=CephString", "Set a configuration option at runtime (not persistent)"), + MDSCommand("config unset name=key,type=CephString", "Unset a configuration option at runtime (not persistent)"), + MDSCommand("exit", "Terminate this MDS"), + MDSCommand("respawn", "Restart this MDS"), + MDSCommand("session kill name=session_id,type=CephInt", "End a client session"), + MDSCommand("cpu_profiler name=arg,type=CephChoices,strings=status|flush", "run cpu profiling on daemon"), + MDSCommand("session ls name=filters,type=CephString,n=N,req=false", "List client sessions"), + MDSCommand("client ls name=filters,type=CephString,n=N,req=false", "List client sessions"), + MDSCommand("session evict name=filters,type=CephString,n=N,req=false", "Evict client session(s)"), + MDSCommand("client evict name=filters,type=CephString,n=N,req=false", "Evict client session(s)"), + MDSCommand("damage ls", "List detected metadata damage"), + MDSCommand("damage rm name=damage_id,type=CephInt", "Remove a damage table entry"), + MDSCommand("version", "report version of MDS"), + MDSCommand("heap " + "name=heapcmd,type=CephChoices,strings=dump|start_profiler|stop_profiler|release|stats", + "show heap usage info (available only if compiled with tcmalloc)"), + MDSCommand("cache drop name=timeout,type=CephInt,range=1", "trim cache and optionally request client to release all caps and flush the journal"), + }; + return commands; }; - int MDSDaemon::_handle_command( const cmdmap_t &cmdmap, const MCommand::const_ref &m, @@ -763,13 +724,11 @@ int MDSDaemon::_handle_command( int cmdnum = 0; std::unique_ptr f(std::make_unique()); f->open_object_section("command_descriptions"); - for (MDSCommand *cp = mds_commands; - cp < &mds_commands[ARRAY_SIZE(mds_commands)]; cp++) { - + for (auto& c : get_commands()) { ostringstream secname; secname << "cmd" << setfill('0') << std::setw(3) << cmdnum; - dump_cmddesc_to_json(f.get(), secname.str(), cp->cmdstring, cp->helpstring, - cp->module, cp->perm, cp->availability, 0); + dump_cmddesc_to_json(f.get(), secname.str(), c.cmdstring, c.helpstring, + c.module, "*", c.availability, 0); cmdnum++; } f->close_section(); // command_descriptions diff --git a/src/mds/MDSDaemon.h b/src/mds/MDSDaemon.h index 745b4042816..5689924678e 100644 --- a/src/mds/MDSDaemon.h +++ b/src/mds/MDSDaemon.h @@ -168,8 +168,20 @@ protected: void _handle_mds_map(const MDSMap &oldmap); private: - mono_time starttime = mono_clock::zero(); -}; + struct MDSCommand { + MDSCommand(std::string_view signature, std::string_view help) + : cmdstring(signature), helpstring(help) + {} + + std::string cmdstring; + std::string helpstring; + std::string module = "mds"; + std::string availability = "cli,rest"; + }; + static const std::vector& get_commands(); + + mono_time starttime = mono_clock::zero(); +}; #endif -- 2.39.5