]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: add path argument to `ops` and `dump tree` to stream result to local file
authorPatrick Donnelly <pdonnell@redhat.com>
Sat, 17 Feb 2024 15:23:43 +0000 (10:23 -0500)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 22 Mar 2024 15:38:02 +0000 (11:38 -0400)
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 <pdonnell@redhat.com>
(cherry picked from commit a1303a52af7504c3748a75ade9619c7a6c454831)

src/mds/MDSDaemon.cc
src/mds/MDSRank.cc

index e69bacf8f49d7509177bb6927bd2bc5acd60f558..e59419d1533e53d2018c21aaffb3d7bf6c32c0b8 100644 (file)
@@ -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);
index 791765ddd66188f81126442df75ab614d924f380..e8486b1344b170e30e146ef1431088127a8ae822 100644 (file)
@@ -2664,6 +2664,8 @@ void MDSRankDispatcher::handle_asok_command(
   } else if (command == "ops") {
     vector<string> 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(