]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/PGMonitor: batch filter pg state for "pg ls *" command family
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 30 May 2016 09:01:49 +0000 (17:01 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Fri, 3 Jun 2016 09:45:51 +0000 (17:45 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/mon/PGMap.cc
src/mon/PGMap.h
src/mon/PGMonitor.cc

index 3064edf09149452f60907f237266b9c316783613..da524f80ea65e9fe34ee90e47f745363d1a13913 100644 (file)
@@ -1754,16 +1754,9 @@ void PGMap::generate_test_instances(list<PGMap*>& o)
   }
 }
 
-void PGMap::get_filtered_pg_stats(const string& state, int64_t poolid, int64_t osdid,
+void PGMap::get_filtered_pg_stats(uint32_t state, int64_t poolid, int64_t osdid,
                                   bool primary, set<pg_t>& pgs)
 {
-  int type = 0;
-  if (state != "all") {
-    type = pg_string_state(state);
-    if (type == -1)
-      assert(0 == "invalid type");
-  }
-
   for (ceph::unordered_map<pg_t, pg_stat_t>::const_iterator i = pg_stat.begin();
        i != pg_stat.end();
        ++i) {
@@ -1771,7 +1764,7 @@ void PGMap::get_filtered_pg_stats(const string& state, int64_t poolid, int64_t o
       continue;
     if ((osdid >= 0) && !(i->second.is_acting_osd(osdid,primary)))
       continue;
-    if ((state != "all") && !(i->second.state & type))
+    if (!(i->second.state & state))
       continue;
     pgs.insert(i->first);
   }
index 20f86db9269677bd1b9429bfa9390315e9b4e070..97f24305a57d0a9d7b2f16e80b5db9d1f4acff2e 100644 (file)
@@ -300,7 +300,7 @@ public:
   void dump_osd_blocked_by_stats(Formatter *f) const;
   void print_osd_blocked_by_stats(std::ostream *ss) const;
 
-  void get_filtered_pg_stats(const string& state, int64_t poolid, int64_t osdid,
+  void get_filtered_pg_stats(uint32_t state, int64_t poolid, int64_t osdid,
                              bool primary, set<pg_t>& pgs);
   void recovery_summary(Formatter *f, list<string> *psl,
                         const pool_stat_t& delta_sum) const;
index ac81028175d5d86d1c146c998db7f6c290d35073..68f8a71e3223a7952910bb9f383b228e34bacd7b 100644 (file)
@@ -1771,16 +1771,31 @@ bool PGMonitor::preprocess_command(MonOpRequestRef op)
     }
     if (states.empty())
       states.push_back("all");
+
+    uint32_t state = 0;
+
     while (!states.empty()) {
-      string state = states.back();
-      pg_map.get_filtered_pg_stats(state,pool,osd,primary,pgs);
+      string state_str = states.back();
+
+      if (state_str == "all") {
+        state = -1;
+        break;
+      } else {
+        int filter = pg_string_state(state_str);
+        assert(filter != -1);
+        state |= filter;
+      }
+
       states.pop_back();
     }
+
+    pg_map.get_filtered_pg_stats(state, pool, osd, primary, pgs);
+
     if (f && !pgs.empty()) {
-      pg_map.dump_filtered_pg_stats(f.get(),pgs);
+      pg_map.dump_filtered_pg_stats(f.get(), pgs);
       f->flush(ds);
     } else if (!pgs.empty()) {
-      pg_map.dump_filtered_pg_stats(ds,pgs);
+      pg_map.dump_filtered_pg_stats(ds, pgs);
     }
     r = 0;
   } else if (prefix == "pg dump_stuck") {