]> 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)
committerZhansong Gao <zhsgao@hotmail.com>
Wed, 1 Feb 2023 10:28:07 +0000 (18:28 +0800)
Signed-off-by: Zhansong Gao <zhsgao@hotmail.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDSDaemon.cc
src/mds/MDSRank.cc
src/mds/MDSRank.h

index 101b0b55b37a6b89f94d3ac9abeb2e396867c6a4..38ca143bbe3c9b5cbe1bf07f1125619b6395e6cb 100644 (file)
@@ -13488,6 +13488,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 7b544998b3c12c95c37c43084dd50f1ecd1b24f8..4c2e85e233865b00263721a369e96fa2ac0659f7 100644 (file)
@@ -514,6 +514,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 ca8c3b6567853fb81456a9637794433fea931372..80caf1499e8591f63e1e1205cf64f740a0118329 100644 (file)
@@ -446,6 +446,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 d1294c8ce97103412f92d96552b91e14271525bc..888a0062e2043e3bc737260f1dd87181fe1045f8 100644 (file)
@@ -2875,6 +2875,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);
@@ -3311,6 +3313,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 fb2061eb548ab06168715920bc83fa121de35305..d28933c6aaf12b9782d2bd5c7ea99d8337d3fe51 100644 (file)
@@ -508,6 +508,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