]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: Add path filtering for dump cache
authorDouglas Fuller <dfuller@redhat.com>
Fri, 17 Jun 2016 20:13:14 +0000 (13:13 -0700)
committerDouglas Fuller <dfuller@redhat.com>
Tue, 28 Jun 2016 19:21:49 +0000 (12:21 -0700)
Add a new admin socket command, dump below, to filter
cache dumps by path. An optional integer depth parameter
limits the depth below the specified path.

Fixes: http://tracker.ceph.com/issues/11171
Signed-off-by: Douglas Fuller <dfuller@redhat.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDSDaemon.cc
src/mds/MDSRank.cc

index 28691e016d712a35780812c73af4061b6943487f..4aabbdf2cbcb273e5b6acf17d3b82e15264c354b 100644 (file)
@@ -11601,11 +11601,17 @@ void MDCache::dump_cache(Formatter *f)
   dump_cache(NULL, f);
 }
 
+void MDCache::dump_cache(const string& dump_root, int depth, Formatter *f)
+{
+  dump_cache(NULL, f, dump_root, depth);
+}
+
 /**
  * Dump the metadata cache, either to a Formatter, if
  * provided, else to a plain text file.
  */
-void MDCache::dump_cache(const char *fn, Formatter *f)
+void MDCache::dump_cache(const char *fn, Formatter *f,
+                        const string& dump_root, int depth)
 {
   int r = 0;
   int fd = -1;
@@ -11627,11 +11633,28 @@ void MDCache::dump_cache(const char *fn, Formatter *f)
       return;
     }
   }
-  
+
   for (ceph::unordered_map<vinodeno_t,CInode*>::iterator it = inode_map.begin();
        it != inode_map.end();
        ++it) {
     CInode *in = it->second;
+
+    if (!dump_root.empty()) {
+      string ipath;
+      if (in->is_root())
+       ipath = "/";
+      else
+       in->make_path_string(ipath);
+
+      if (dump_root.length() > ipath.length() ||
+         !equal(dump_root.begin(), dump_root.end(), ipath.begin()))
+       continue;
+
+      if (depth >= 0 &&
+         count(ipath.begin() + dump_root.length(), ipath.end(), '/') > depth)
+       continue;
+    }
+
     if (f) {
       f->open_object_section("inode");
       in->dump(f);
@@ -11641,7 +11664,7 @@ void MDCache::dump_cache(const char *fn, Formatter *f)
       std::string s = ss.str();
       r = safe_write(fd, s.c_str(), s.length());
       if (r < 0) {
-        goto out;
+       goto out;
       }
     }
 
index ff3115e62270126acd33c22e6630d4b8d4a63829..582f495d5533b65e683ee86a9acfbaee471b8bd9 100644 (file)
@@ -1111,11 +1111,14 @@ public:
   void notify_osdmap_changed();
 
 protected:
-  void dump_cache(const char *fn, Formatter *f);
+  void dump_cache(const char *fn, Formatter *f,
+                 const std::string& dump_root = "",
+                 int depth = -1);
 public:
   void dump_cache() {dump_cache(NULL, NULL);}
   void dump_cache(const std::string &filename);
   void dump_cache(Formatter *f);
+  void dump_cache(const std::string& dump_root, int depth, Formatter *f);
 
   void dump_resolve_status(Formatter *f) const;
   void dump_rejoin_status(Formatter *f) const;
index ef9ade80fc8773739ae162198f21cc361525b62c..13500210d82bbbe81a71917c4b8120686419d41a 100644 (file)
@@ -273,6 +273,13 @@ void MDSDaemon::set_up_admin_socket()
                                      asok_hook,
                                      "dump metadata cache (optionally to a file)");
   assert(r == 0);
+  r = admin_socket->register_command("dump tree",
+                                    "dump tree "
+                                    "name=root,type=CephString,req=true "
+                                    "name=depth,type=CephInt,req=false ",
+                                    asok_hook,
+                                    "dump metadata cache for subtree");
+  assert(r == 0);
   r = admin_socket->register_command("session evict",
                                     "session evict name=client_id,type=CephString",
                                     asok_hook,
@@ -339,6 +346,7 @@ void MDSDaemon::clean_up_admin_socket()
   admin_socket->unregister_command("flush_path");
   admin_socket->unregister_command("export dir");
   admin_socket->unregister_command("dump cache");
+  admin_socket->unregister_command("dump tree");
   admin_socket->unregister_command("session evict");
   admin_socket->unregister_command("osdmap barrier");
   admin_socket->unregister_command("session ls");
index 16a93485b2b437d0facf3d06d19c6e13089dd4bf..8dd1c4f3978864f1c4b20a7ac802243ac221b7ab 100644 (file)
@@ -1758,6 +1758,16 @@ bool MDSRankDispatcher::handle_asok_command(
     } else {
       mdcache->dump_cache(path);
     }
+  } else if (command == "dump tree") {
+    string root;
+    int64_t depth;
+    cmd_getval(g_ceph_context, cmdmap, "root", root);
+    if (!cmd_getval(g_ceph_context, cmdmap, "depth", depth))
+      depth = -1;
+    {
+      Mutex::Locker l(mds_lock);
+      mdcache->dump_cache(root, depth, f);
+    }
   } else if (command == "force_readonly") {
     mds_lock.Lock();
     mdcache->force_readonly();