From 96fe894bf6d8ab8076bf264e77ed1e9228217945 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 29 Oct 2019 15:23:09 -0500 Subject: [PATCH] mds: switch asok calls over to call_async interface A bit of cleanup here with the error messages (just let the caller end print a generic error message). Signed-off-by: Sage Weil --- src/mds/MDSDaemon.cc | 42 +++++++++++++++++++---------- src/mds/MDSDaemon.h | 8 ++++-- src/mds/MDSRank.cc | 63 ++++++++++++++++++++------------------------ src/mds/MDSRank.h | 8 ++++-- 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 45356177b990c..3f9f4ebafbf24 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -109,23 +109,36 @@ class MDSSocketHook : public AdminSocketHook { MDSDaemon *mds; public: explicit MDSSocketHook(MDSDaemon *m) : mds(m) {} - int call(std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, - std::ostream& ss, - bufferlist& out) override { - stringstream outss; - int r = mds->asok_command(command, cmdmap, f, outss); - out.append(outss); - return r; + int call( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + std::ostream& errss, + ceph::buffer::list& out) override { + ceph_abort("shoudl go to call_async"); + } + void call_async( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + const bufferlist& inbl, + std::function on_finish) override { + mds->asok_command(command, cmdmap, f, inbl, on_finish); } }; -int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, std::ostream& ss) +void MDSDaemon::asok_command( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + const bufferlist& inbl, + std::function on_finish) { - dout(1) << "asok_command: " << command << " (starting...)" << dendl; + dout(1) << "asok_command: " << command << " " << cmdmap + << " (starting...)" << dendl; int r = -ENOSYS; + stringstream ss; if (command == "status") { dump_status(f); r = 0; @@ -135,15 +148,16 @@ int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap, f->dump_string("error", "mds_not_active"); } else { try { - r = mds_rank->handle_asok_command(command, cmdmap, f, ss); + mds_rank->handle_asok_command(command, cmdmap, f, inbl, on_finish); + return; } catch (const bad_cmd_get& e) { ss << e.what(); r = -EINVAL; } } } - dout(1) << "asok_command: " << command << " (complete)" << dendl; - return r; + bufferlist outbl; + on_finish(r, ss.str(), outbl); } void MDSDaemon::dump_status(Formatter *f) diff --git a/src/mds/MDSDaemon.h b/src/mds/MDSDaemon.h index a4568ee9c738b..a3117679862cf 100644 --- a/src/mds/MDSDaemon.h +++ b/src/mds/MDSDaemon.h @@ -93,8 +93,12 @@ class MDSDaemon : public Dispatcher { void set_up_admin_socket(); void clean_up_admin_socket(); void check_ops_in_flight(); // send off any slow ops to monitor - int asok_command(std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, ostream& ss); + void asok_command( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + const bufferlist &inbl, + std::function on_finish); void dump_status(Formatter *f); diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 3f5ed581c56dc..81b576d0c77bd 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2426,11 +2426,16 @@ void MDSRank::handle_mds_failure(mds_rank_t who) snapclient->handle_mds_failure(who); } -int MDSRankDispatcher::handle_asok_command(std::string_view command, - const cmdmap_t& cmdmap, - Formatter *f, - std::ostream& ss) -{ +void MDSRankDispatcher::handle_asok_command( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + const bufferlist &inbl, + std::function on_finish) +{ + int r = 0; + ostringstream ss; + bufferlist outbl; if (command == "dump_ops_in_flight" || command == "ops") { if (!op_tracker.dump_ops_in_flight(f)) { @@ -2458,7 +2463,8 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, if (!got_val) { ss << "no target epoch given"; - return -EINVAL; + r = -EINVAL; + goto out; } { std::lock_guard l(mds_lock); @@ -2481,15 +2487,15 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, const bool got_arg = cmd_getval(g_ceph_context, cmdmap, "client_id", client_id); if(!got_arg) { ss << "Invalid client_id specified"; - return -ENOENT; + r = -ENOENT; + goto out; } std::lock_guard l(mds_lock); - std::stringstream dss; bool evicted = evict_client(strtol(client_id.c_str(), 0, 10), true, - g_conf()->mds_session_blacklist_on_evict, dss); + g_conf()->mds_session_blacklist_on_evict, ss); if (!evicted) { - dout(15) << dss.str() << dendl; - ss << dss.str(); + dout(15) << ss.str() << dendl; + r = -EBUSY; } } else if (command == "session config") { int64_t client_id; @@ -2501,7 +2507,7 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, bool got_value = cmd_getval(g_ceph_context, cmdmap, "value", value); std::lock_guard l(mds_lock); - config_client(client_id, !got_value, option, value, ss); + r = config_client(client_id, !got_value, option, value, ss); } else if (command == "scrub_path") { string path; vector scrubop_vec; @@ -2529,28 +2535,24 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, string path; if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) { ss << "malformed path"; - return -EINVAL; + r = -EINVAL; + goto out; } int64_t rank; if(!cmd_getval(g_ceph_context, cmdmap, "rank", rank)) { ss << "malformed rank"; - return -EINVAL; + r = -EINVAL; + goto out; } command_export_dir(f, path, (mds_rank_t)rank); } else if (command == "dump cache") { std::lock_guard l(mds_lock); string path; - int r; - if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) { + if (!cmd_getval(g_ceph_context, cmdmap, "path", path)) { r = mdcache->dump_cache(f); } else { r = mdcache->dump_cache(path); } - - if (r != 0) { - ss << "Failed to dump cache: " << cpp_strerror(r); - f->reset(); - } } else if (command == "cache status") { std::lock_guard l(mds_lock); mdcache->cache_status(f); @@ -2558,11 +2560,7 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, command_dump_tree(cmdmap, ss, f); } else if (command == "dump loads") { std::lock_guard l(mds_lock); - int r = balancer->dump_loads(f); - if (r != 0) { - ss << "Failed to dump loads: " << cpp_strerror(r); - f->reset(); - } + r = balancer->dump_loads(f); } else if (command == "dump snaps") { std::lock_guard l(mds_lock); string server; @@ -2571,14 +2569,11 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, if (mdsmap->get_tableserver() == whoami) { snapserver->dump(f); } else { + r = -EXDEV; ss << "Not snapserver"; } } else { - int r = snapclient->dump_cache(f); - if (r != 0) { - ss << "Failed to dump snapclient: " << cpp_strerror(r); - f->reset(); - } + r = snapclient->dump_cache(f); } } else if (command == "force_readonly") { std::lock_guard l(mds_lock); @@ -2594,10 +2589,10 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command, } else if (command == "dump inode") { command_dump_inode(f, cmdmap, ss); } else { - return -ENOSYS; + r = -ENOSYS; } - - return 0; +out: + on_finish(r, ss.str(), outbl); } class C_MDS_Send_Command_Reply : public MDSInternalContext { diff --git a/src/mds/MDSRank.h b/src/mds/MDSRank.h index 1944e2f17bde2..016af1a4bf2a4 100644 --- a/src/mds/MDSRank.h +++ b/src/mds/MDSRank.h @@ -630,8 +630,12 @@ public: void init(); void tick(); void shutdown(); - int handle_asok_command(std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, std::ostream& ss); + void handle_asok_command( + std::string_view command, + const cmdmap_t& cmdmap, + Formatter *f, + const bufferlist &inbl, + std::function on_finish); void handle_mds_map(const cref_t &m, const MDSMap &oldmap); void handle_osd_map(); void update_log_config(); -- 2.39.5