From 0607bbba4b128a4f01df71bd6b1271380c9757f5 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Sat, 17 Feb 2024 10:23:43 -0500 Subject: [PATCH] mds: add path argument to `ops` and `dump tree` to stream result to local file This file can be collected during testing to avoid sending a large JSON result over the `ceph tell`/asok interface. Signed-off-by: Patrick Donnelly (cherry picked from commit a1303a52af7504c3748a75ade9619c7a6c454831) --- src/mds/MDSDaemon.cc | 10 ++++---- src/mds/MDSRank.cc | 54 +++++++++++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index e69bacf8f49..e59419d1533 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -260,9 +260,10 @@ void MDSDaemon::set_up_admin_socket() "show the ops currently in flight"); ceph_assert(r == 0); r = admin_socket->register_command("ops " - "name=flags,type=CephChoices,strings=locks,n=N,req=false ", - asok_hook, - "show the ops currently in flight"); + "name=flags,type=CephChoices,strings=locks,n=N,req=false " + "name=path,type=CephString,req=false " + ,asok_hook + ,"show the ops currently in flight"); ceph_assert(r == 0); r = admin_socket->register_command("dump_blocked_ops", asok_hook, @@ -342,7 +343,8 @@ void MDSDaemon::set_up_admin_socket() ceph_assert(r == 0); r = admin_socket->register_command("dump tree " "name=root,type=CephString,req=true " - "name=depth,type=CephInt,req=false ", + "name=depth,type=CephInt,req=false " + "name=path,type=CephString,req=false ", asok_hook, "dump metadata cache for subtree"); ceph_assert(r == 0); diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 791765ddd66..e8486b1344b 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2664,6 +2664,8 @@ void MDSRankDispatcher::handle_asok_command( } else if (command == "ops") { vector flags; cmd_getval(cmdmap, "flags", flags); + string path; + cmd_getval(cmdmap, "path", path); std::unique_lock l(mds_lock, std::defer_lock); auto lambda = OpTracker::default_dumper; if (flags.size()) { @@ -2678,8 +2680,18 @@ void MDSRankDispatcher::handle_asok_command( }; l.lock(); } - if (!op_tracker.dump_ops_in_flight(f, false, {""}, false, lambda)) { - *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; + if (!path.empty()) { + auto ff = JSONFormatterFile(path, false); + if (!op_tracker.dump_ops_in_flight(&ff, false, {""}, false, lambda)) { + *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; + } + f->open_object_section("result"); + f->dump_string("path", path); + f->close_section(); + } else { + if (!op_tracker.dump_ops_in_flight(f, false, {""}, false, lambda)) { + *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; + } } } else if (command == "dump_blocked_ops") { if (!op_tracker.dump_ops_in_flight(f, true)) { @@ -3206,23 +3218,39 @@ int MDSRank::_command_export_dir( void MDSRank::command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f) { + std::string path; + cmd_getval(cmdmap, "path", path); std::string root; - int64_t depth; cmd_getval(cmdmap, "root", root); + int64_t depth; + if (!cmd_getval(cmdmap, "depth", depth)) { + depth = -1; + } if (root.empty()) { root = "/"; } - if (!cmd_getval(cmdmap, "depth", depth)) - depth = -1; - std::lock_guard l(mds_lock); - CInode *in = mdcache->cache_traverse(filepath(root.c_str())); - if (!in) { - ss << "inode for path '" << filepath(root.c_str()) << "' is not in cache"; - return; + + auto dump = [&](Formatter *f) { + std::lock_guard l(mds_lock); + CInode *in = mdcache->cache_traverse(filepath(root.c_str())); + if (!in) { + ss << "inode for path '" << filepath(root.c_str()) << "' is not in cache"; + return; + } + f->open_array_section("inodes"); + mdcache->dump_tree(in, 0, depth, f); + f->close_section(); + }; + + if (!path.empty()) { + auto ff = JSONFormatterFile(path, false); + dump(&ff); + f->open_object_section("result"); + f->dump_string("path", path); + f->close_section(); + } else { + dump(f); } - f->open_array_section("inodes"); - mdcache->dump_tree(in, 0, depth, f); - f->close_section(); } CDir *MDSRank::_command_dirfrag_get( -- 2.39.5