From 5ce4f32975d058dd6a8394927139708cf8c62a2f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 30 Oct 2019 07:24:59 -0500 Subject: [PATCH] mds: convert 'cache drop' Signed-off-by: Sage Weil --- src/mds/MDSDaemon.cc | 6 +++++- src/mds/MDSRank.cc | 44 ++++++++++++++++---------------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 05403360d1f..0dc90540833 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -308,6 +308,11 @@ void MDSDaemon::set_up_admin_socket() asok_hook, "dump metadata cache (optionally to a file)"); ceph_assert(r == 0); + r = admin_socket->register_command("cache drop " + "name=timeout,type=CephInt,range=0,req=false", + asok_hook, + "trim cache and optionally request client to release all caps and flush the journal"); + ceph_assert(r == 0); r = admin_socket->register_command("cache status", asok_hook, "show cache status"); @@ -641,7 +646,6 @@ void MDSDaemon::handle_command(const cref_t &m) const std::vector& MDSDaemon::get_commands() { static const std::vector commands = { - MDSCommand("cache drop name=timeout,type=CephInt,range=0,req=false", "trim cache and optionally request client to release all caps and flush the journal"), }; return commands; }; diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index dd11155a68b..6c1085415c2 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2619,6 +2619,21 @@ void MDSRankDispatcher::handle_asok_command( } else { r = mdcache->dump_cache(path); } + } else if (command == "cache drop") { + int64_t timeout = 0; + cmd_getval(g_ceph_context, cmdmap, "timeout", timeout); + finisher->queue( + new LambdaContext( + [this, on_finish, f, timeout](int r) { + command_cache_drop( + timeout, f, + new LambdaContext( + [on_finish](int r) { + bufferlist outbl; + on_finish(r, {}, outbl); + })); + })); + return; } else if (command == "cache status") { std::lock_guard l(mds_lock); mdcache->cache_status(f); @@ -2719,21 +2734,6 @@ protected: JSONFormatter f; }; -class C_CacheDropExecAndReply : public C_ExecAndReply { -public: - C_CacheDropExecAndReply(MDSRank *mds, const cref_t &m, - uint64_t timeout) - : C_ExecAndReply(mds, m), timeout(timeout) { - } - - void exec() override { - mds->command_cache_drop(timeout, &f, this); - } - -private: - uint64_t timeout; -}; - /** * This function drops the mds_lock, so don't do anything with * MDSRank after calling it (we could have gone into shutdown): just @@ -3551,19 +3551,7 @@ bool MDSRankDispatcher::handle_command( std::string prefix; cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); - if (prefix == "cache drop") { - int64_t timeout; - if (!cmd_getval(g_ceph_context, cmdmap, "timeout", timeout)) { - timeout = 0; - } - - *need_reply = false; - *run_later = create_async_exec_context(new C_CacheDropExecAndReply - (this, m, (uint64_t)timeout)); - return true; - } else { - return false; - } + return false; } void MDSRank::command_cache_drop(uint64_t timeout, Formatter *f, Context *on_finish) { -- 2.39.5