]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: filter the trackedop that we needed.
authorYan Jun <yan.jun8@zte.com.cn>
Tue, 25 Jul 2017 07:57:32 +0000 (15:57 +0800)
committerYan Jun <yan.jun8@zte.com.cn>
Wed, 26 Jul 2017 03:49:12 +0000 (11:49 +0800)
Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
src/common/TrackedOp.cc
src/common/TrackedOp.h
src/osd/OSD.cc
src/osd/OpRequest.cc
src/osd/OpRequest.h

index ea3f607cfe24882c3fcbb79790321c0af6b24a8e..bd605e54cc7c6bc3bd5b3595f8393410c2517cd8 100644 (file)
@@ -68,7 +68,7 @@ void OpHistory::cleanup(utime_t now)
   }
 }
 
-void OpHistory::dump_ops(utime_t now, Formatter *f)
+void OpHistory::dump_ops(utime_t now, Formatter *f, set<string> filters)
 {
   Mutex::Locker history_lock(ops_history_lock);
   cleanup(now);
@@ -81,6 +81,8 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
           arrived.begin();
         i != arrived.end();
         ++i) {
+      if (!i->second->filter_out(filters))
+        continue;
       f->open_object_section("op");
       i->second->dump(now, f);
       f->close_section();
@@ -90,7 +92,7 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
   f->close_section();
 }
 
-void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f)
+void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f, set<string> filters)
 {
   Mutex::Locker history_lock(ops_history_lock);
   cleanup(now);
@@ -107,6 +109,8 @@ void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f)
             arrived.begin();
           i != arrived.end();
           ++i) {
+       if (!i->second->filter_out(filters))
+         continue;
        durationvec.push_back(pair<double, TrackedOpRef>(i->second->get_duration(), i->second));
       }
 
@@ -152,7 +156,7 @@ OpTracker::~OpTracker() {
   }
 }
 
-bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration)
+bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration, set<string> filters)
 {
   RWLock::RLocker l(lock);
   if (!tracking_enabled)
@@ -160,14 +164,14 @@ bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration)
 
   utime_t now = ceph_clock_now();
   if (by_duration) {
-    history.dump_ops_by_duration(now, f);
+    history.dump_ops_by_duration(now, f, filters);
   } else {
-    history.dump_ops(now, f);
+    history.dump_ops(now, f, filters);
   }
   return true;
 }
 
-void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
+void OpHistory::dump_slow_ops(utime_t now, Formatter *f, set<string> filters)
 {
   Mutex::Locker history_lock(ops_history_lock);
   cleanup(now);
@@ -180,6 +184,8 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
           slow_op.begin();
         i != slow_op.end();
         ++i) {
+      if (!i->second->filter_out(filters))
+        continue;
       f->open_object_section("Op");
       i->second->dump(now, f);
       f->close_section();
@@ -189,18 +195,18 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
   f->close_section();
 }
 
-bool OpTracker::dump_historic_slow_ops(Formatter *f)
+bool OpTracker::dump_historic_slow_ops(Formatter *f, set<string> filters)
 {
   RWLock::RLocker l(lock);
   if (!tracking_enabled)
     return false;
 
   utime_t now = ceph_clock_now();
-  history.dump_slow_ops(now, f);
+  history.dump_slow_ops(now, f, filters);
   return true;
 }
 
-bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked)
+bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked, set<string> filters)
 {
   RWLock::RLocker l(lock);
   if (!tracking_enabled)
@@ -217,6 +223,8 @@ bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked)
     for (auto& op : sdata->ops_in_flight_sharded) {
       if (print_only_blocked && (now - op.get_initiated() <= complaint_time))
         break;
+      if (!op.filter_out(filters))
+        continue;
       f->open_object_section("op");
       op.dump(now, f);
       f->close_section(); // this TrackedOp
index 1ee81075d23f95e280888fec61787b9680a99404..aa8b09a4b48e62123ab738ed1524c2fb63af950e 100644 (file)
@@ -46,9 +46,9 @@ public:
     assert(slow_op.empty());
   }
   void insert(utime_t now, TrackedOpRef op);
-  void dump_ops(utime_t now, Formatter *f);
-  void dump_ops_by_duration(utime_t now, Formatter *f);
-  void dump_slow_ops(utime_t now, Formatter *f);
+  void dump_ops(utime_t now, Formatter *f, set<string> filters = {""});
+  void dump_ops_by_duration(utime_t now, Formatter *f, set<string> filters = {""});
+  void dump_slow_ops(utime_t now, Formatter *f, set<string> filters = {""});
   void on_shutdown();
   void set_size_and_duration(uint32_t new_size, uint32_t new_duration) {
     history_size = new_size;
@@ -90,9 +90,9 @@ public:
     RWLock::WLocker l(lock);
     tracking_enabled = enable;
   }
-  bool dump_ops_in_flight(Formatter *f, bool print_only_blocked=false);
-  bool dump_historic_ops(Formatter *f, bool by_duration = false);
-  bool dump_historic_slow_ops(Formatter *f);
+  bool dump_ops_in_flight(Formatter *f, bool print_only_blocked = false, set<string> filters = {""});
+  bool dump_historic_ops(Formatter *f, bool by_duration = false, set<string> filters = {""});
+  bool dump_historic_slow_ops(Formatter *f, set<string> filters = {""});
   bool register_inflight_op(TrackedOp *i);
   void unregister_inflight_op(TrackedOp *i);
 
@@ -215,6 +215,8 @@ protected:
   /// called when the last non-OpTracker reference is dropped
   virtual void _unregistered() {};
 
+  virtual bool filter_out(const set<string>& filters) { return true; }
+
 public:
   ZTracer::Trace osd_trace;
   ZTracer::Trace pg_trace;
index 33ee4182d185c9beff945794eba0ca7109f547f6..1fafd65332714734329090c1b6db0c7074d833cf 100644 (file)
@@ -2044,30 +2044,48 @@ bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format,
   } else if (admin_command == "flush_journal") {
     store->flush_journal();
   } else if (admin_command == "dump_ops_in_flight" ||
-            admin_command == "ops") {
-    if (!op_tracker.dump_ops_in_flight(f)) {
-      ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
-       Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
-    }
-  } else if (admin_command == "dump_blocked_ops") {
-    if (!op_tracker.dump_ops_in_flight(f, true)) {
-      ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
-       Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
-    }
-  } else if (admin_command == "dump_historic_ops") {
-    if (!op_tracker.dump_historic_ops(f, false)) {
-      ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
-       Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
-    }
-  } else if (admin_command == "dump_historic_ops_by_duration") {
-    if (!op_tracker.dump_historic_ops(f, true)) {
-      ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
-       Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
-    }
-  } else if (admin_command == "dump_historic_slow_ops") {
-    if (!op_tracker.dump_historic_slow_ops(f)) {
-      ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
-       Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
+             admin_command == "ops" ||
+             admin_command == "dump_blocked_ops" ||
+             admin_command == "dump_historic_ops" ||
+             admin_command == "dump_historic_ops_by_duration" ||
+             admin_command == "dump_historic_slow_ops") {
+
+    const string error_str = "op_tracker tracking is not enabled now, so no ops are tracked currently, \
+even those get stuck. Please enable \"osd_enable_op_tracker\", and the tracker \
+will start to track new ops received afterwards.";
+
+    set<string> filters;
+    vector<string> filter_str;
+    if (cmd_getval(cct, cmdmap, "filterstr", filter_str)) {
+        copy(filter_str.begin(), filter_str.end(),
+           inserter(filters, filters.end()));
+    }
+
+    if (admin_command == "dump_ops_in_flight" ||
+        admin_command == "ops") {
+      if (!op_tracker.dump_ops_in_flight(f, false, filters)) {
+        ss << error_str;
+      }
+    }
+    if (admin_command == "dump_blocked_ops") {
+      if (!op_tracker.dump_ops_in_flight(f, true, filters)) {
+        ss << error_str;
+      }
+    }
+    if (admin_command == "dump_historic_ops") {
+      if (!op_tracker.dump_historic_ops(f, false, filters)) {
+        ss << error_str;
+      }
+    }
+    if (admin_command == "dump_historic_ops_by_duration") {
+      if (!op_tracker.dump_historic_ops(f, true, filters)) {
+        ss << error_str;
+      }
+    }
+    if (admin_command == "dump_historic_slow_ops") {
+      if (!op_tracker.dump_historic_slow_ops(f, filters)) {
+        ss << error_str;
+      }
     }
   } else if (admin_command == "dump_op_pq_state") {
     f->open_object_section("pq");
@@ -2684,26 +2702,38 @@ void OSD::final_init()
                                      "flush the journal to permanent store");
   assert(r == 0);
   r = admin_socket->register_command("dump_ops_in_flight",
-                                    "dump_ops_in_flight", asok_hook,
+                                    "dump_ops_in_flight " \
+                                    "name=filterstr,type=CephString,n=N,req=false",
+                                    asok_hook,
                                     "show the ops currently in flight");
   assert(r == 0);
   r = admin_socket->register_command("ops",
-                                    "ops", asok_hook,
+                                    "ops " \
+                                    "name=filterstr,type=CephString,n=N,req=false",
+                                    asok_hook,
                                     "show the ops currently in flight");
   assert(r == 0);
   r = admin_socket->register_command("dump_blocked_ops",
-                                    "dump_blocked_ops", asok_hook,
+                                    "dump_blocked_ops " \
+                                    "name=filterstr,type=CephString,n=N,req=false",
+                                    asok_hook,
                                     "show the blocked ops currently in flight");
   assert(r == 0);
-  r = admin_socket->register_command("dump_historic_ops", "dump_historic_ops",
+  r = admin_socket->register_command("dump_historic_ops",
+                                     "dump_historic_ops " \
+                                     "name=filterstr,type=CephString,n=N,req=false",
                                     asok_hook,
                                     "show recent ops");
   assert(r == 0);
-  r = admin_socket->register_command("dump_historic_slow_ops", "dump_historic_slow_ops",
+  r = admin_socket->register_command("dump_historic_slow_ops",
+                                     "dump_historic_slow_ops " \
+                                     "name=filterstr,type=CephString,n=N,req=false",
                                     asok_hook,
                                     "show slowest recent ops");
   assert(r == 0);
-  r = admin_socket->register_command("dump_historic_ops_by_duration", "dump_historic_ops_by_duration",
+  r = admin_socket->register_command("dump_historic_ops_by_duration",
+                                     "dump_historic_ops_by_duration " \
+                                     "name=filterstr,type=CephString,n=N,req=false",
                                     asok_hook,
                                     "show slowest recent ops, sorted by duration");
   assert(r == 0);
index 7d7f33e256a2c5d3b7b53d4187b93e0ee7ef2fe2..4a85a2c5610b54257dd0bbbc464434b76e75b7ce 100644 (file)
@@ -162,6 +162,34 @@ void OpRequest::mark_flag_point_string(uint8_t flag, const string& s) {
             flag, s.c_str(), old_flags, hit_flag_points);
 }
 
+bool OpRequest::filter_out(const set<string>& filters)
+{
+  set<entity_addr_t> addrs;
+  for (auto it = filters.begin(); it != filters.end(); it++) {
+    entity_addr_t addr;
+    if (addr.parse((*it).c_str())) {
+      addrs.insert(addr);
+    }
+  }
+  if (addrs.empty())
+    return true;
+
+  entity_addr_t cmp_addr = req_src_inst.addr;
+  if (addrs.count(cmp_addr)) {
+    return true;
+  }
+  cmp_addr.set_nonce(0);
+  if (addrs.count(cmp_addr)) {
+    return true;
+  }
+  cmp_addr.set_port(0);
+  if (addrs.count(cmp_addr)) {
+    return true;
+  }
+
+  return false;
+}
+
 ostream& operator<<(ostream& out, const OpRequest::ClassInfo& i)
 {
   out << "class " << i.name << " rd " << i.read
index 8008bf08a12a875853385769c0a9291e8d31160d..c0e77730dcb2a4e0568f2a5f592056761a466b8b 100644 (file)
@@ -103,6 +103,7 @@ private:
 protected:
   void _dump_op_descriptor_unlocked(ostream& stream) const override;
   void _unregistered() override;
+  bool filter_out(const set<string>& filters) override;
 
 public:
   ~OpRequest() override {