]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: add a command to dump directory information
authorZhansong Gao <zhsgao@hotmail.com>
Mon, 16 Jan 2023 09:50:29 +0000 (17:50 +0800)
committerJos Collin <jcollin@redhat.com>
Wed, 6 Mar 2024 09:31:07 +0000 (15:01 +0530)
Signed-off-by: Zhansong Gao <zhsgao@hotmail.com>
(cherry picked from commit 42492d5058f6b61be0bbc355d9205db836c45af1)

src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDSDaemon.cc
src/mds/MDSRank.cc
src/mds/MDSRank.h

index 2a1277d9e0ec47a46ce7726fd3728ee2422c53f5..e6b92c509f82cc1f12a53516e3866d8972b37c00 100644 (file)
@@ -13324,6 +13324,12 @@ bool MDCache::dump_inode(Formatter *f, uint64_t number) {
   return true;
 }
 
+void MDCache::dump_dir(Formatter *f, CDir *dir, bool dentry_dump) {
+  f->open_object_section("dir");
+  dir->dump(f, dentry_dump ? CDir::DUMP_ALL : CDir::DUMP_DEFAULT);
+  f->close_section();
+}
+
 void MDCache::handle_mdsmap(const MDSMap &mdsmap, const MDSMap &oldmap) {
   const mds_rank_t max_mds = mdsmap.get_max_mds();
 
index f1a6d37b1ba0ba4161672721afe0d0d0df97ca6a..758dac6eb82e51d8a63257174845f3f704b49a28 100644 (file)
@@ -520,6 +520,7 @@ class MDCache {
   void clean_open_file_lists();
   void dump_openfiles(Formatter *f);
   bool dump_inode(Formatter *f, uint64_t number);
+  void dump_dir(Formatter *f, CDir *dir, bool dentry_dump=false);
 
   void rejoin_start(MDSContext *rejoin_done_);
   void rejoin_gather_finish();
index cd7b2e35fc22cd8f21ff61acce82593b9de1f144..126a9a668e1682b64b97bbb7e789ce9a621559d3 100644 (file)
@@ -440,6 +440,12 @@ void MDSDaemon::set_up_admin_socket()
                                     asok_hook,
                                     "dump inode by inode number");
   ceph_assert(r == 0);
+  r = admin_socket->register_command("dump dir "
+                                    "name=path,type=CephString,req=true "
+                                    "name=dentry_dump,type=CephBool,req=false",
+                                    asok_hook,
+                                    "dump directory by path");
+  ceph_assert(r == 0);
   r = admin_socket->register_command("exit",
                                     asok_hook,
                                     "Terminate this MDS");
index 890b1013892eff4090d6768b3b67dbac260c49a5..f28b1ff4b3ececaa04aff9f5419a82368211f961 100644 (file)
@@ -2905,6 +2905,8 @@ void MDSRankDispatcher::handle_asok_command(
     command_openfiles_ls(f);
   } else if (command == "dump inode") {
     command_dump_inode(f, cmdmap, *css);
+  } else if (command == "dump dir") {
+    command_dump_dir(f, cmdmap, *css);
   } else if (command == "damage ls") {
     std::lock_guard l(mds_lock);
     damage_table.dump(f);
@@ -3345,6 +3347,36 @@ void MDSRank::command_dump_inode(Formatter *f, const cmdmap_t &cmdmap, std::ostr
   }
 }
 
+void MDSRank::command_dump_dir(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss)
+{
+  std::lock_guard l(mds_lock);
+  std::string path;
+  bool got = cmd_getval(cmdmap, "path", path);
+  if (!got) {
+    ss << "missing path argument";
+    return;
+  }
+
+  bool dentry_dump = false;
+  cmd_getval(cmdmap, "dentry_dump", dentry_dump);
+
+  CInode *in = mdcache->cache_traverse(filepath(path.c_str()));
+  if (!in) {
+    ss << "directory inode not in cache";
+    return;
+  }
+
+  f->open_array_section("dirs");
+  frag_vec_t leaves;
+  in->dirfragtree.get_leaves_under(frag_t(), leaves);
+  for (const auto& leaf : leaves) {
+    CDir *dir = in->get_dirfrag(leaf);
+    if (dir)
+      mdcache->dump_dir(f, dir, dentry_dump);
+  }
+  f->close_section();
+}
+
 void MDSRank::dump_status(Formatter *f) const
 {
   f->dump_string("fs_name", std::string(mdsmap->get_fs_name()));
index e3f7c785199c7e9a047059690b8ae9bdac92103c..8b294902cc4188515cebc537cef44a3db14daea6 100644 (file)
@@ -542,6 +542,7 @@ class MDSRank {
     void command_openfiles_ls(Formatter *f);
     void command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f);
     void command_dump_inode(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss);
+    void command_dump_dir(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss);
     void command_cache_drop(uint64_t timeout, Formatter *f, Context *on_finish);
 
     // FIXME the state machine logic should be separable from the dispatch