]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: add command "openfiles ls"
authordongdong tao <tdd21151186@gmail.com>
Wed, 3 Jan 2018 12:51:44 +0000 (20:51 +0800)
committerdongdong tao <tdd21151186@gmail.com>
Sat, 13 Jan 2018 15:01:33 +0000 (23:01 +0800)
list all the opening files with the corresponding clients and their caps.

Signed-off-by: dongdong tao <tdd21151186@gmail.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDLog.h
src/mds/MDSDaemon.cc
src/mds/MDSRank.cc
src/mds/MDSRank.h

index 1f620e44e239fbc52c678beefa89734313181ce1..83e52b0421ef8d9e46c3c1d4c9a7fbe11b696869 100644 (file)
@@ -5631,7 +5631,33 @@ void MDCache::clean_open_file_lists()
   }
 }
 
-
+void MDCache::dump_openfiles(Formatter *f)
+{
+  f->open_array_section("openfiles");
+  for (auto p = mds->mdlog->segments.begin();
+       p != mds->mdlog->segments.end();
+       ++p) {
+    LogSegment *ls = p->second;
+    
+    auto q = ls->open_files.begin(member_offset(CInode, item_open_file));
+    while (!q.end()) {
+      CInode *in = *q;
+      ++q;
+      if ((in->last == CEPH_NOSNAP && !in->is_any_caps_wanted())
+          || (in->last != CEPH_NOSNAP && in->client_snap_caps.empty())) 
+        continue;
+      std::string path;
+      in->make_path_string(path, true);
+      if (path.empty())
+        path = "/"   
+      f->open_object_section("file");
+      f->dump_string("path", path);
+      in->dump(f);
+      f->close_section();
+    }
+  }
+  f->close_section();
+}
 
 Capability* MDCache::rejoin_import_cap(CInode *in, client_t client, const cap_reconnect_t& icr, mds_rank_t frommds)
 {
index 64a9adf43ea00931fce4ab36df1939f94a24b5f0..0914637330dc24be423a4f6cc862517137b1eab7 100644 (file)
@@ -534,7 +534,7 @@ public:
 
 
   void clean_open_file_lists();
-
+  void dump_openfiles(Formatter *f);
 protected:
   // [rejoin]
   bool rejoins_pending;
@@ -1178,7 +1178,7 @@ public:
   int dump_cache(const std::string &filename);
   int dump_cache(Formatter *f);
   int dump_cache(const std::string& dump_root, int depth, Formatter *f);
-
+  
   int cache_status(Formatter *f);
 
   void dump_resolve_status(Formatter *f) const;
index 5579e5abc007bde82ef30359d0d9ea476a437798..02dc5803056ba7ab811eae408b7f08b2feeab7a0 100644 (file)
@@ -246,6 +246,10 @@ public:
       return segments[seq];
     return NULL;
   }
+  
+  const std::map<uint64_t,LogSegment*> &get_segments() {
+    return segments;
+  }
 
   bool have_any_segments() const {
     return !segments.empty();
index 9eb133c03a64cd1446ea11b9d15daefd015a0840..04fcc3d7f0b38f60c3544db7dfa67c5298e90466 100644 (file)
@@ -309,6 +309,11 @@ void MDSDaemon::set_up_admin_socket()
                                     asok_hook,
                                     "List fragments in directory");
   assert(r == 0);
+  r = admin_socket->register_command("openfiles ls",
+                                     "openfiles ls",
+                                     asok_hook,
+                                     "List the opening files and their caps");
+  assert(r == 0);
 }
 
 void MDSDaemon::clean_up_admin_socket()
@@ -337,6 +342,7 @@ void MDSDaemon::clean_up_admin_socket()
   admin_socket->unregister_command("dirfrag split");
   admin_socket->unregister_command("dirfrag merge");
   admin_socket->unregister_command("dirfrag ls");
+  admin_socket->unregister_command("openfiles ls");
   delete asok_hook;
   asok_hook = NULL;
 }
index 4b9732fd3d3755f11e937619134cf2b1b29b2bef..7b55148903352a13dcfb0f84b9ed4cfc5f609cfa 100644 (file)
@@ -1986,6 +1986,8 @@ bool MDSRankDispatcher::handle_asok_command(
     command_dirfrag_merge(cmdmap, ss);
   } else if (command == "dirfrag ls") {
     command_dirfrag_ls(cmdmap, ss, f);
+  } else if (command == "openfiles ls") {
+    command_openfiles_ls(f);
   } else {
     return false;
   }
@@ -2497,6 +2499,12 @@ bool MDSRank::command_dirfrag_ls(
   return true;
 }
 
+void MDSRank::command_openfiles_ls(Formatter *f) 
+{
+  Mutex::Locker l(mds_lock);
+  mdcache->dump_openfiles(f);
+}
+
 void MDSRank::dump_status(Formatter *f) const
 {
   if (state == MDSMap::STATE_REPLAY ||
index 170bb6ed5a5a5e354274792217897d396c5fc103..26c76fef8611de5f69f34d22d582241d75d65a6d 100644 (file)
@@ -437,6 +437,7 @@ class MDSRank {
     CDir *_command_dirfrag_get(
         const cmdmap_t &cmdmap,
         std::ostream &ss);
+    void command_openfiles_ls(Formatter *f);
 
   protected:
     Messenger    *messenger;