]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: add DUMP_DIRFRAGS to CInode and DUMP_ITEMS to CDir
authordongdong tao <tdd21151186@gmail.com>
Sat, 17 Feb 2018 03:01:56 +0000 (11:01 +0800)
committerdongdong tao <tdd21151186@gmail.com>
Sat, 24 Feb 2018 03:45:15 +0000 (11:45 +0800)
Signed-off-by: dongdong tao <tdd21151186@gmail.com>
src/mds/CDir.cc
src/mds/CDir.h
src/mds/CInode.cc
src/mds/CInode.h
src/mds/MDCache.cc
src/mds/MDCache.h

index 9fb6a323fe8a21bdb9d6dc4061fba4a9ebdcd898..08888c325d222c9baf32f6ba38af064e22506767 100644 (file)
@@ -3012,45 +3012,64 @@ void CDir::unfreeze_dir()
  * for identifying a directory and its state rather than for dumping
  * debug output.
  */
-void CDir::dump(Formatter *f) const
+void CDir::dump(Formatter *f, int flags) const
 {
   assert(f != NULL);
-
-  f->dump_stream("path") << get_path();
-
-  f->dump_stream("dirfrag") << dirfrag();
-  f->dump_int("snapid_first", first);
-
-  f->dump_stream("projected_version") << get_projected_version();
-  f->dump_stream("version") << get_version();
-  f->dump_stream("committing_version") << get_committing_version();
-  f->dump_stream("committed_version") << get_committed_version();
-
-  f->dump_bool("is_rep", is_rep());
-
-  if (get_dir_auth() != CDIR_AUTH_DEFAULT) {
-    if (get_dir_auth().second == CDIR_AUTH_UNKNOWN) {
-      f->dump_stream("dir_auth") << get_dir_auth().first;
+  if (flags & DUMP_PATH) {
+    f->dump_stream("path") << get_path();
+  }
+  if (flags & DUMP_DIRFRAG) {
+    f->dump_stream("dirfrag") << dirfrag();
+  }
+  if (flags & DUMP_SNAPID_FIRST) {
+    f->dump_int("snapid_first", first);
+  }
+  if (flags & DUMP_VERSIONS) {
+    f->dump_stream("projected_version") << get_projected_version();
+    f->dump_stream("version") << get_version();
+    f->dump_stream("committing_version") << get_committing_version();
+    f->dump_stream("committed_version") << get_committed_version();
+  }
+  if (flags & DUMP_REP) {
+    f->dump_bool("is_rep", is_rep());
+  }
+  if (flags & DUMP_DIR_AUTH) {
+    if (get_dir_auth() != CDIR_AUTH_DEFAULT) {
+      if (get_dir_auth().second == CDIR_AUTH_UNKNOWN) {
+        f->dump_stream("dir_auth") << get_dir_auth().first;
+      } else {
+        f->dump_stream("dir_auth") << get_dir_auth();
+      }
     } else {
-      f->dump_stream("dir_auth") << get_dir_auth();
+      f->dump_string("dir_auth", "");
     }
-  } else {
-    f->dump_string("dir_auth", "");
-  }
-
-  f->open_array_section("states");
-  MDSCacheObject::dump_states(f);
-  if (state_test(CDir::STATE_COMPLETE)) f->dump_string("state", "complete");
-  if (state_test(CDir::STATE_FREEZINGTREE)) f->dump_string("state", "freezingtree");
-  if (state_test(CDir::STATE_FROZENTREE)) f->dump_string("state", "frozentree");
-  if (state_test(CDir::STATE_FROZENDIR)) f->dump_string("state", "frozendir");
-  if (state_test(CDir::STATE_FREEZINGDIR)) f->dump_string("state", "freezingdir");
-  if (state_test(CDir::STATE_EXPORTBOUND)) f->dump_string("state", "exportbound");
-  if (state_test(CDir::STATE_IMPORTBOUND)) f->dump_string("state", "importbound");
-  if (state_test(CDir::STATE_BADFRAG)) f->dump_string("state", "badfrag");
-  f->close_section();
-
-  MDSCacheObject::dump(f);
+  }
+  if (flags & DUMP_STATES) {
+    f->open_array_section("states");
+    MDSCacheObject::dump_states(f);
+    if (state_test(CDir::STATE_COMPLETE)) f->dump_string("state", "complete");
+    if (state_test(CDir::STATE_FREEZINGTREE)) f->dump_string("state", "freezingtree");
+    if (state_test(CDir::STATE_FROZENTREE)) f->dump_string("state", "frozentree");
+    if (state_test(CDir::STATE_FROZENDIR)) f->dump_string("state", "frozendir");
+    if (state_test(CDir::STATE_FREEZINGDIR)) f->dump_string("state", "freezingdir");
+    if (state_test(CDir::STATE_EXPORTBOUND)) f->dump_string("state", "exportbound");
+    if (state_test(CDir::STATE_IMPORTBOUND)) f->dump_string("state", "importbound");
+    if (state_test(CDir::STATE_BADFRAG)) f->dump_string("state", "badfrag");
+    f->close_section();
+  }
+  if (flags & DUMP_MDS_CACHE_OBJECT) {
+    MDSCacheObject::dump(f);
+  }
+  if (flags & DUMP_ITEMS) {
+    f->open_array_section("dentries");
+    for (auto &p : items) {
+      CDentry *dn = p.second;
+      f->open_object_section("dentry");
+      dn->dump(f);
+      f->close_section();
+    }
+    f->close_section();
+  }
 }
 
 void CDir::dump_load(Formatter *f, utime_t now, const DecayRate& rate)
index 3e6bc0eb2d29076f233aaee14b51f5261edc45a5..c1e92cf57041c39a485af31a0737489b57122b19 100644 (file)
@@ -140,8 +140,18 @@ public:
   static const uint64_t WAIT_ATFREEZEROOT = (WAIT_UNFREEZE);
   static const uint64_t WAIT_ATSUBTREEROOT = (WAIT_SINGLEAUTH);
 
-
-
+  // -- dump flags --
+  static const int DUMP_PATH             = (1 << 0);
+  static const int DUMP_DIRFRAG          = (1 << 1);
+  static const int DUMP_SNAPID_FIRST     = (1 << 2);
+  static const int DUMP_VERSIONS         = (1 << 3);
+  static const int DUMP_REP              = (1 << 4);
+  static const int DUMP_DIR_AUTH         = (1 << 5);
+  static const int DUMP_STATES           = (1 << 6);
+  static const int DUMP_MDS_CACHE_OBJECT = (1 << 7);
+  static const int DUMP_ITEMS            = (1 << 8);
+  static const int DUMP_ALL              = (-1);
+  static const int DUMP_DEFAULT          = DUMP_ALL & (~DUMP_ITEMS); 
 
  public:
   // context
@@ -746,7 +756,7 @@ public:
 
   ostream& print_db_line_prefix(ostream& out) override;
   void print(ostream& out) override;
-  void dump(Formatter *f) const;
+  void dump(Formatter *f, int flags = DUMP_DEFAULT) const;
   void dump_load(Formatter *f, utime_t now, const DecayRate& rate);
 };
 
index 8c1719dc32edab6fcae92203de5451118db139e5..3cdd6b6b19d9f0208252a3eaabda43ad68890b5e 100644 (file)
@@ -601,7 +601,7 @@ CDir *CInode::get_approx_dirfrag(frag_t fg)
   return NULL;
 }      
 
-void CInode::get_dirfrags(std::list<CDir*>& ls) 
+void CInode::get_dirfrags(std::list<CDir*>& ls) const
 {
   // all dirfrags
   for (const auto &p : dirfrags) {
@@ -4359,6 +4359,19 @@ void CInode::dump(Formatter *f, int flags) const
     }
     f->close_section();
   }
+
+  if (flags & DUMP_DIRFRAGS) {
+    f->open_array_section("dirfrags");
+    list<CDir*> dfs;
+    get_dirfrags(dfs);
+    for(const auto &dir: dfs) {
+      f->open_object_section("dir");
+      dir->dump(f, CDir::DUMP_DEFAULT | CDir::DUMP_ITEMS);
+      dir->check_rstats();
+      f->close_section();
+    }
+    f->close_section();
+  }
 }
 
 /****** Scrub Stuff *****/
index 152456e82526d80ad8767b44dc822b32805c77dc..43287bebcb1ad565324a87294670b1202ad1a184 100644 (file)
@@ -210,8 +210,9 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
   static const int DUMP_STATE =            (1 << 3);
   static const int DUMP_CAPS =             (1 << 4);
   static const int DUMP_PATH =             (1 << 5);
+  static const int DUMP_DIRFRAGS =         (1 << 6);
   static const int DUMP_ALL =              (-1);
-  static const int DUMP_DEFAULT = DUMP_ALL & (~DUMP_PATH);
+  static const int DUMP_DEFAULT = DUMP_ALL & (~DUMP_PATH) & (~DUMP_DIRFRAGS);
 
   // -- state --
   static const int STATE_EXPORTING =   (1<<2);   // on nonauth bystander.
@@ -533,7 +534,7 @@ public:
   }
   bool get_dirfrags_under(frag_t fg, std::list<CDir*>& ls);
   CDir* get_approx_dirfrag(frag_t fg);
-  void get_dirfrags(std::list<CDir*>& ls);
+  void get_dirfrags(std::list<CDir*>& ls) const;
   void get_nested_dirfrags(std::list<CDir*>& ls);
   void get_subtree_dirfrags(std::list<CDir*>& ls);
   CDir *get_or_open_dirfrag(MDCache *mdcache, frag_t fg);
index fd53f51d6b4529b3d108342a9c16757ceb0274c9..edb1e6bee82106b50a9b214ddca5dca18e846195 100644 (file)
@@ -11964,7 +11964,7 @@ void MDCache::dump_tree(CInode *in, const int cur_depth, const int max_depth, Fo
     }
   }
   f->open_object_section("inode");
-  in->dump(f);
+  in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_DIRFRAGS);
   f->close_section();
 }
 
@@ -11982,7 +11982,7 @@ int MDCache::dump_cache(Formatter *f)
  * Dump the metadata cache, either to a Formatter, if
  * provided, else to a plain text file.
  */
-int MDCache::dump_cache(const char *fn, Formatter *f)
+int MDCache::dump_cache(std::string_view fn, Formatter *f)
 {
   int r = 0;
   int fd = -1;
@@ -12010,67 +12010,35 @@ int MDCache::dump_cache(const char *fn, Formatter *f)
     int r;
     if (f) {
       f->open_object_section("inode");
-      in->dump(f);
-    } else {
-      ostringstream ss;
-      ss << *in << std::endl;
-      std::string s = ss.str();
-      r = safe_write(fd, s.c_str(), s.length());
-      if (r < 0)
-       return r;
-    }
-
+      in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_DIRFRAGS);
+      f->close_section();
+      return 1;
+    } 
+    ostringstream ss;
+    ss << *in << std::endl;
+    std::string s = ss.str();
+    r = safe_write(fd, s.c_str(), s.length());
+    if (r < 0)
+      return r;
     list<CDir*> dfs;
     in->get_dirfrags(dfs);
-    if (f) {
-      f->open_array_section("dirfrags");
-    }
-    for (list<CDir*>::iterator p = dfs.begin(); p != dfs.end(); ++p) {
-      CDir *dir = *p;
-      if (f) {
-        f->open_object_section("dir");
-        dir->dump(f);
-      } else {
-        ostringstream tt;
-        tt << " " << *dir << std::endl;
-        string t = tt.str();
-        r = safe_write(fd, t.c_str(), t.length());
-        if (r < 0)
-         return r;
-      }
-      
-      if (f) {
-        f->open_array_section("dentries");
-      }
+    for (auto &dir : dfs) {
+      ostringstream tt;
+      tt << " " << *dir << std::endl;
+      std::string t = tt.str();
+      r = safe_write(fd, t.c_str(), t.length());
+      if (r < 0)
+        return r;
       for (auto &p : dir->items) {
        CDentry *dn = p.second;
-        if (f) {
-         f->open_object_section("dentry");
-          dn->dump(f);
-          f->close_section();
-        } else {
-          ostringstream uu;
-          uu << "  " << *dn << std::endl;
-          string u = uu.str();
-          r = safe_write(fd, u.c_str(), u.length());
-          if (r < 0)
-           return r;
-        }
-      }
-      if (f) {
-       f->close_section();  //dentries
+        ostringstream uu;
+        uu << "  " << *dn << std::endl;
+        std::string u = uu.str();
+        r = safe_write(fd, u.c_str(), u.length());
+        if (r < 0)
+          return r;
       }
       dir->check_rstats();
-      if (f) {
-       f->close_section();  //dir
-      }
-    }
-    if (f) {
-      f->close_section();  // dirfrags
-    }
-
-    if (f) {
-      f->close_section();  // inode
     }
     return 1;
   };
index 9a8c1b9456f4da2b0fd06f309ac447c2b6370352..660b0e0f60af7a601d26b57c3a9c33ba3241b0a5 100644 (file)
@@ -1172,7 +1172,7 @@ public:
   void discard_delayed_expire(CDir *dir);
 
 protected:
-  int dump_cache(const char *fn, Formatter *f);
+  int dump_cache(std::string_view fn, Formatter *f);
 public:
   int dump_cache() { return dump_cache(NULL, NULL); }
   int dump_cache(std::string_view filename);