]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move most PGMapStatService into PGMap; rename PGMon's to PGMonStatService
authorGreg Farnum <gfarnum@redhat.com>
Fri, 9 Jun 2017 22:31:02 +0000 (15:31 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Thu, 15 Jun 2017 00:01:32 +0000 (17:01 -0700)
Most of this is independent of the PGMonitor, so move it into
PGMap and strip out those few bits. It'll come in handy shortly
when I move "ceph osd df" into the mgr.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/mon/PGMap.h
src/mon/PGMonitor.cc
src/mon/PGMonitor.h

index a79dfcdfb3743f9914874dfbdb4106eca1c54b7c..0bf8445b9b0106931b0df98ab657e7738d4c1a28 100644 (file)
@@ -26,6 +26,7 @@
 #include "osd/osd_types.h"
 #include "include/mempool.h"
 #include <sstream>
+#include "mon/PGStatService.h"
 
 // FIXME: don't like including this here to get OSDMap::Incremental, maybe
 // PGMapUpdater needs its own header.
@@ -579,4 +580,90 @@ namespace reweight {
                     Formatter *f);
 }
 
+
+class PGMapStatService : public PGStatService {
+  const PGMap& pgmap;
+public:
+  PGMapStatService(const PGMap& o)
+    : pgmap(o) {}
+
+  bool is_readable() const override { return true; }
+
+  const pool_stat_t* get_pool_stat(int poolid) const override {
+    auto i = pgmap.pg_pool_sum.find(poolid);
+    if (i != pgmap.pg_pool_sum.end()) {
+      return &i->second;
+    }
+    return nullptr;
+  }
+
+  const osd_stat_t& get_osd_sum() const override { return pgmap.osd_sum; }
+
+  const osd_stat_t *get_osd_stat(int osd) const override {
+    auto i = pgmap.osd_stat.find(osd);
+    if (i == pgmap.osd_stat.end()) {
+      return nullptr;
+    }
+    return &i->second;
+  }
+  const mempool::pgmap::unordered_map<int32_t,osd_stat_t>& get_osd_stat() const override {
+    return pgmap.osd_stat;
+  }
+  float get_full_ratio() const override { return pgmap.full_ratio; }
+  float get_nearfull_ratio() const override { return pgmap.nearfull_ratio; }
+
+  bool have_creating_pgs() const override {
+    return !pgmap.creating_pgs.empty();
+  }
+  bool is_creating_pg(pg_t pgid) const override {
+    return pgmap.creating_pgs.count(pgid);
+  }
+
+  epoch_t get_min_last_epoch_clean() const override {
+    return pgmap.get_min_last_epoch_clean();
+  }
+
+  bool have_full_osds() const override { return !pgmap.full_osds.empty(); }
+  bool have_nearfull_osds() const override {
+    return !pgmap.nearfull_osds.empty();
+  }
+
+  size_t get_num_pg_by_osd(int osd) const override {
+    return pgmap.get_num_pg_by_osd(osd);
+  }
+  ceph_statfs get_statfs() const override {
+    ceph_statfs statfs;
+    statfs.kb = pgmap.osd_sum.kb;
+    statfs.kb_used = pgmap.osd_sum.kb_used;
+    statfs.kb_avail = pgmap.osd_sum.kb_avail;
+    statfs.num_objects = pgmap.pg_sum.stats.sum.num_objects;
+    return statfs;
+  }
+  void print_summary(Formatter *f, ostream *out) const override {
+    pgmap.print_summary(f, out);
+  }
+  virtual void dump_info(Formatter *f) const override {
+    f->dump_object("pgmap", pgmap);
+  }
+  void dump_fs_stats(stringstream *ss,
+                    Formatter *f,
+                    bool verbose) const override {
+    pgmap.dump_fs_stats(ss, f, verbose);
+  }
+  void dump_pool_stats(const OSDMap& osdm, stringstream *ss, Formatter *f,
+                      bool verbose) const override {
+    pgmap.dump_pool_stats_full(osdm, ss, f, verbose);
+  }
+
+  int process_pg_command(const string& prefix,
+                        const map<string,cmd_vartype>& cmdmap,
+                        const OSDMap& osdmap,
+                        Formatter *f,
+                        stringstream *ss,
+                        bufferlist *odata) const override {
+    return process_pg_map_command(prefix, cmdmap, pgmap, osdmap, f, ss, odata);
+  }
+};
+
+
 #endif
index 7bf41506dc5b0e9eaa5d7cce09c464610d39bc52..2d35fe6e8ce580704aaa69ac1dfdcd366a389d26 100644 (file)
@@ -1172,11 +1172,11 @@ bool PGMonitor::check_sub(Subscription *sub)
   return true;
 }
 
-class PGMapStatService : public MonPGStatService {
+class PGMonStatService : public MonPGStatService {
   const PGMap& pgmap;
   PGMonitor *pgmon;
 public:
-  PGMapStatService(const PGMap& o, PGMonitor *pgm)
+  PGMonStatService(const PGMap& o, PGMonitor *pgm)
     : pgmap(o),
       pgmon(pgm) {}
 
@@ -1314,7 +1314,7 @@ public:
 MonPGStatService *PGMonitor::get_pg_stat_service()
 {
   if (!pgservice) {
-    pgservice.reset(new PGMapStatService(pg_map, this));
+    pgservice.reset(new PGMonStatService(pg_map, this));
   }
   return pgservice.get();
 }
index c025bfff994b7708b115c6bfccd0d9464e2f6363..5395c5bb37f89fb3d70dae00f82510fddd4d2498 100644 (file)
@@ -34,10 +34,11 @@ using namespace std;
 
 class MPGStats;
 class MonPGStatService;
+class PGMonStatService;
 
 class PGMonitor : public PaxosService {
   PGMap pg_map;
-  std::unique_ptr<MonPGStatService> pgservice;
+  std::unique_ptr<PGMonStatService> pgservice;
 
   bool do_delete = false;   ///< propose deleting pgmap data
   bool did_delete = false;  ///< we already deleted pgmap data