]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: give CDir a dump() method for JSON output
authorJohn Spray <john.spray@redhat.com>
Tue, 6 Jan 2015 18:13:28 +0000 (18:13 +0000)
committerJohn Spray <john.spray@redhat.com>
Fri, 9 Jan 2015 14:27:15 +0000 (14:27 +0000)
Useful when listing subtrees via admin socket.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/CDir.cc
src/mds/CDir.h

index 1d0078873783d1ca36495c236c34588325b1b96d..01b61b0d17af409c945fb39473de8aae88294885 100644 (file)
@@ -2677,10 +2677,65 @@ void CDir::unfreeze_dir()
   }
 }
 
+/**
+ * Slightly less complete than operator<<, because this is intended
+ * for identifying a directory and its state rather than for dumping
+ * debug output.
+ */
+void CDir::dump(Formatter *f) const
+{
+  assert(f != NULL);
 
+  string path;
+  get_inode()->make_path_string_projected(path);
+
+  f->dump_stream("dirfrag") << dirfrag();
+  f->dump_stream("path") << path;
+  f->dump_int("snapid_first", first);
+  f->dump_bool("auth", is_auth());
+
+  // >> Only meaningful for auth
+  f->open_object_section("replica_map");
+  for (std::map<mds_rank_t, unsigned>::const_iterator i = replica_map.begin();
+       i != replica_map.end(); ++i) {
+    std::ostringstream rank_str;
+    rank_str << i->first;
+    f->dump_int(rank_str.str().c_str(), i->second);
+  }
+  f->close_section();
+  f->dump_stream("projected_version") << get_projected_version();
+  f->dump_stream("version") << get_version();
+  f->dump_stream("comitting_version") << get_committing_version();
+  f->dump_stream("comitted_version") << get_committed_version();
+  // << Only meaningful for auth
+
+  // >> Only meaningful for replica
+  f->dump_stream("authority_first") << authority().first;
+  f->dump_stream("authority_second") << authority().second;
+  f->dump_stream("replica_nonce") << get_replica_nonce();
+  // << Only meaningful for replica
+  
+  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;
+    } else {
+      f->dump_stream("dir_auth") << get_dir_auth();
+    }
+  } else {
+    f->dump_string("dir_auth", "");
+  }
 
-
-
-
+  f->open_array_section("states");
+  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();
+}
 
index c89647800154286a7b65c79f0a792155edbe6c4f..f72a24987ea03435fb9b1ce70355c74e62e8f93e 100644 (file)
@@ -626,6 +626,7 @@ public:
 
   ostream& print_db_line_prefix(ostream& out);
   void print(ostream& out);
+  void dump(Formatter *f) const;
 };
 
 #endif