From: Sage Weil Date: Tue, 29 Oct 2019 23:12:41 +0000 (-0500) Subject: mds: convert 'session evict' and 'session kill' X-Git-Tag: v15.1.0~519^2~11 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=59f818cc48a41583b5ca7e1274dececb48081819;p=ceph-ci.git mds: convert 'session evict' and 'session kill' This one is a bit tricky, since evict takes a filter and kill takes an id. Favor the tell usage pattern since I'm guessing it's more likely to be in use. Signed-off-by: Sage Weil --- diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index fb03b367c21..a91bbbc730d 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -302,9 +302,17 @@ void MDSDaemon::set_up_admin_socket() asok_hook, "dump snapshots"); ceph_assert(r == 0); - r = admin_socket->register_command("session evict name=client_id,type=CephString", + r = admin_socket->register_command("session evict name=filters,type=CephString,n=N,req=false", asok_hook, - "Evict a CephFS client"); + "Evict client session(s) based on a filter"); + ceph_assert(r == 0); + r = admin_socket->register_command("client evict name=filters,type=CephString,n=N,req=false", + asok_hook, + "Evict client session(s) based on a filter"); + ceph_assert(r == 0); + r = admin_socket->register_command("session kill name=client_id,type=CephString", + asok_hook, + "Evict a client session by id"); ceph_assert(r == 0); r = admin_socket->register_command("session ls", asok_hook, @@ -584,11 +592,8 @@ void MDSDaemon::handle_command(const cref_t &m) const std::vector& MDSDaemon::get_commands() { static const std::vector commands = { - MDSCommand("session kill name=session_id,type=CephInt", "End a client session"), 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("session config name=client_id,type=CephInt name=option,type=CephString name=value,type=CephString,req=false", "Config a client session"), MDSCommand("client config name=client_id,type=CephInt name=option,type=CephString name=value,type=CephString,req=false", @@ -645,22 +650,7 @@ int MDSDaemon::_handle_command( } cmd_getval(cct, cmdmap, "format", format); - if (prefix == "session kill") { - if (mds_rank == NULL) { - r = -EINVAL; - ss << "MDS not active"; - goto out; - } - // FIXME harmonize `session kill` with admin socket session evict - int64_t session_id = 0; - bool got = cmd_getval(cct, cmdmap, "session_id", session_id); - ceph_assert(got); - bool killed = mds_rank->evict_client(session_id, false, - g_conf()->mds_session_blacklist_on_evict, - ss); - if (!killed) - r = -ENOENT; - } else { + if (true) { // Give MDSRank a shot at the command if (!mds_rank) { ss << "MDS not active"; diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 81b576d0c77..54ed67e1219 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2434,7 +2434,7 @@ void MDSRankDispatcher::handle_asok_command( std::function on_finish) { int r = 0; - ostringstream ss; + stringstream ss; bufferlist outbl; if (command == "dump_ops_in_flight" || command == "ops") { @@ -2482,10 +2482,23 @@ void MDSRankDispatcher::handle_asok_command( heartbeat_reset(); dump_sessions(SessionFilter(), f); - } else if (command == "session evict") { + } else if (command == "session evict" || + command == "client evict") { + std::lock_guard l(mds_lock); + std::vector filter_args; + cmd_getval(g_ceph_context, cmdmap, "filters", filter_args); + + SessionFilter filter; + r = filter.parse(filter_args, &ss); + if (r != 0) { + r = -EINVAL; + goto out; + } + evict_clients(filter, on_finish); + return; + } else if (command == "session kill") { std::string client_id; - const bool got_arg = cmd_getval(g_ceph_context, cmdmap, "client_id", client_id); - if(!got_arg) { + if (!cmd_getval(g_ceph_context, cmdmap, "client_id", client_id)) { ss << "Invalid client_id specified"; r = -ENOENT; goto out; @@ -2495,7 +2508,7 @@ void MDSRankDispatcher::handle_asok_command( g_conf()->mds_session_blacklist_on_evict, ss); if (!evicted) { dout(15) << ss.str() << dendl; - r = -EBUSY; + r = -ENOENT; } } else if (command == "session config") { int64_t client_id; @@ -2708,13 +2721,13 @@ private: * MDSRank after calling it (we could have gone into shutdown): just * send your result back to the calling client and finish. */ -void MDSRankDispatcher::evict_clients(const SessionFilter &filter, const cref_t &m) +void MDSRankDispatcher::evict_clients( + const SessionFilter &filter, + std::function on_finish) { - C_MDS_Send_Command_Reply *reply = new C_MDS_Send_Command_Reply(this, m); - + bufferlist outbl; if (is_any_replay()) { - reply->send(-EAGAIN, "MDS is replaying log"); - delete reply; + on_finish(-EAGAIN, "MDS is replaying log", outbl); return; } @@ -2727,7 +2740,8 @@ void MDSRankDispatcher::evict_clients(const SessionFilter &filter, const cref_t< Session *s = p.second; - if (filter.match(*s, std::bind(&Server::waiting_for_reconnect, server, std::placeholders::_1))) { + if (filter.match(*s, std::bind(&Server::waiting_for_reconnect, server, + std::placeholders::_1))) { victims.push_back(s); } } @@ -2735,12 +2749,15 @@ void MDSRankDispatcher::evict_clients(const SessionFilter &filter, const cref_t< dout(20) << __func__ << " matched " << victims.size() << " sessions" << dendl; if (victims.empty()) { - reply->send(0, ""); - delete reply; + on_finish(0, {}, outbl); return; } - C_GatherBuilder gather(g_ceph_context, reply); + C_GatherBuilder gather(g_ceph_context, + new LambdaContext([on_finish](int r) { + bufferlist bl; + on_finish(r, {}, bl); + })); for (const auto s : victims) { std::stringstream ss; evict_client(s->get_client().v, false, @@ -3528,20 +3545,6 @@ bool MDSRankDispatcher::handle_command( dump_sessions(filter, &f); f.flush(*ds); return true; - } else if (prefix == "session evict" || prefix == "client evict") { - std::vector filter_args; - cmd_getval(g_ceph_context, cmdmap, "filters", filter_args); - - SessionFilter filter; - *r = filter.parse(filter_args, ss); - if (*r != 0) { - return true; - } - - evict_clients(filter, m); - - *need_reply = false; - return true; } else if (prefix == "session config" || prefix == "client config") { int64_t client_id; std::string option; diff --git a/src/mds/MDSRank.h b/src/mds/MDSRank.h index 016af1a4bf2..4f5bbc7cca0 100644 --- a/src/mds/MDSRank.h +++ b/src/mds/MDSRank.h @@ -653,7 +653,8 @@ public: bool *need_reply); void dump_sessions(const SessionFilter &filter, Formatter *f) const; - void evict_clients(const SessionFilter &filter, const cref_t &m); + void evict_clients(const SessionFilter &filter, + std::function on_finish); // Call into me from MDS::ms_dispatch bool ms_dispatch(const cref_t &m);