From b0e5225eddef47a27a25289437543f610c9633cf Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 9 Jun 2017 15:31:02 -0700 Subject: [PATCH] mon: move most PGMapStatService into PGMap; rename PGMon's to PGMonStatService 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 --- src/mon/PGMap.h | 87 ++++++++++++++++++++++++++++++++++++++++++++ src/mon/PGMonitor.cc | 6 +-- src/mon/PGMonitor.h | 3 +- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index a79dfcdfb37..0bf8445b9b0 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -26,6 +26,7 @@ #include "osd/osd_types.h" #include "include/mempool.h" #include +#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& 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& 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 diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 7bf41506dc5..2d35fe6e8ce 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -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(); } diff --git a/src/mon/PGMonitor.h b/src/mon/PGMonitor.h index c025bfff994..5395c5bb37f 100644 --- a/src/mon/PGMonitor.h +++ b/src/mon/PGMonitor.h @@ -34,10 +34,11 @@ using namespace std; class MPGStats; class MonPGStatService; +class PGMonStatService; class PGMonitor : public PaxosService { PGMap pg_map; - std::unique_ptr pgservice; + std::unique_ptr pgservice; bool do_delete = false; ///< propose deleting pgmap data bool did_delete = false; ///< we already deleted pgmap data -- 2.39.5