]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/osd_types: include number of locally stored PGs in osd_stat_t
authorSage Weil <sage@redhat.com>
Thu, 10 Aug 2017 18:05:10 +0000 (14:05 -0400)
committerSage Weil <sage@redhat.com>
Sun, 13 Aug 2017 19:03:22 +0000 (15:03 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit c2945479f4364ba599262e00cbf200dff66617bb)

src/osd/OSD.cc
src/osd/OSD.h
src/osd/osd_types.cc
src/osd/osd_types.h

index 58245ecb49de3eb2ad53bcef1a0c7e8e8d77a933..afbfe68a22e2f3f6f95e8b4dd953072dc5b95bd3 100644 (file)
@@ -923,7 +923,8 @@ void OSDService::set_injectfull(s_names type, int64_t count)
 }
 
 osd_stat_t OSDService::set_osd_stat(const struct store_statfs_t &stbuf,
-                                    vector<int>& hb_peers)
+                                    vector<int>& hb_peers,
+                                   int num_pgs)
 {
   uint64_t bytes = stbuf.total;
   uint64_t used = bytes - stbuf.available;
@@ -940,6 +941,7 @@ osd_stat_t OSDService::set_osd_stat(const struct store_statfs_t &stbuf,
     osd_stat.kb = bytes >> 10;
     osd_stat.kb_used = used >> 10;
     osd_stat.kb_avail = avail >> 10;
+    osd_stat.num_pgs = num_pgs;
     return osd_stat;
   }
 }
@@ -954,7 +956,7 @@ void OSDService::update_osd_stat(vector<int>& hb_peers)
     return;
   }
 
-  auto new_stat = set_osd_stat(stbuf, hb_peers);
+  auto new_stat = set_osd_stat(stbuf, hb_peers, osd->get_num_pgs());
   dout(20) << "update_osd_stat " << new_stat << dendl;
   assert(new_stat.kb);
   float ratio = ((float)new_stat.kb_used) / ((float)new_stat.kb);
index a4244e5d76ca42a2e7124a7e53f0ea76ea462484..88e84710ff531bf4f9eee2a59d4df2762c469a97 100644 (file)
@@ -1047,7 +1047,8 @@ public:
 
   void update_osd_stat(vector<int>& hb_peers);
   osd_stat_t set_osd_stat(const struct store_statfs_t &stbuf,
-                          vector<int>& hb_peers);
+                          vector<int>& hb_peers,
+                         int num_pgs);
   osd_stat_t get_osd_stat() {
     Mutex::Locker l(stat_lock);
     ++seq;
@@ -1951,6 +1952,11 @@ protected:
 public:
   PG   *lookup_lock_pg(spg_t pgid);
 
+  int get_num_pgs() {
+    RWLock::RLocker l(pg_map_lock);
+    return pg_map.size();
+  }
+
 protected:
   PG   *_open_lock_pg(OSDMapRef createmap,
                      spg_t pg, bool no_lockdep_check=false);
index 56ff2b42f7d06981ed9ae33a299c8ea7c1548355..393cd7097d23fdb9483949fd2571e506fc31f629 100644 (file)
@@ -309,6 +309,7 @@ void osd_stat_t::dump(Formatter *f) const
 {
   f->dump_unsigned("up_from", up_from);
   f->dump_unsigned("seq", seq);
+  f->dump_unsigned("num_pgs", num_pgs);
   f->dump_unsigned("kb", kb);
   f->dump_unsigned("kb_used", kb_used);
   f->dump_unsigned("kb_avail", kb_avail);
@@ -328,7 +329,7 @@ void osd_stat_t::dump(Formatter *f) const
 
 void osd_stat_t::encode(bufferlist &bl) const
 {
-  ENCODE_START(6, 2, bl);
+  ENCODE_START(7, 2, bl);
   ::encode(kb, bl);
   ::encode(kb_used, bl);
   ::encode(kb_avail, bl);
@@ -340,6 +341,7 @@ void osd_stat_t::encode(bufferlist &bl) const
   ::encode(os_perf_stat, bl);
   ::encode(up_from, bl);
   ::encode(seq, bl);
+  ::encode(num_pgs, bl);
   ENCODE_FINISH(bl);
 }
 
@@ -362,6 +364,9 @@ void osd_stat_t::decode(bufferlist::iterator &bl)
     ::decode(up_from, bl);
     ::decode(seq, bl);
   }
+  if (struct_v >= 7) {
+    ::decode(num_pgs, bl);
+  }
   DECODE_FINISH(bl);
 }
 
index 100c01e2d0ad4240d90a83d67457c9afdce2c833..9d9a142b0f3ff27b1fc795f4d00bbcf18d618529 100644 (file)
@@ -904,6 +904,8 @@ struct osd_stat_t {
   epoch_t up_from = 0;
   uint64_t seq = 0;
 
+  uint32_t num_pgs = 0;
+
   osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
                 snap_trim_queue_len(0), num_snap_trimming(0) {}
 
@@ -915,6 +917,7 @@ struct osd_stat_t {
     num_snap_trimming += o.num_snap_trimming;
     op_queue_age_hist.add(o.op_queue_age_hist);
     os_perf_stat.add(o.os_perf_stat);
+    num_pgs += o.num_pgs;
   }
   void sub(const osd_stat_t& o) {
     kb -= o.kb;
@@ -924,6 +927,7 @@ struct osd_stat_t {
     num_snap_trimming -= o.num_snap_trimming;
     op_queue_age_hist.sub(o.op_queue_age_hist);
     os_perf_stat.sub(o.os_perf_stat);
+    num_pgs -= o.num_pgs;
   }
 
   void dump(Formatter *f) const;
@@ -941,7 +945,8 @@ inline bool operator==(const osd_stat_t& l, const osd_stat_t& r) {
     l.num_snap_trimming == r.num_snap_trimming &&
     l.hb_peers == r.hb_peers &&
     l.op_queue_age_hist == r.op_queue_age_hist &&
-    l.os_perf_stat == r.os_perf_stat;
+    l.os_perf_stat == r.os_perf_stat &&
+    l.num_pgs == r.num_pgs;
 }
 inline bool operator!=(const osd_stat_t& l, const osd_stat_t& r) {
   return !(l == r);