From 6ed099f31cf87e47e9417f4a72ffe04a13748bff Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 3 Apr 2018 12:19:43 +0100 Subject: [PATCH] mgr: expose OSDMap.pool_raw_used_rate Signed-off-by: John Spray --- src/mgr/PyOSDMap.cc | 19 +++++++++++++++++++ src/mon/PGMap.cc | 35 ++--------------------------------- src/osd/OSDMap.cc | 31 +++++++++++++++++++++++++++++++ src/osd/OSDMap.h | 3 +++ src/pybind/mgr/mgr_module.py | 3 +++ 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index 4ec585d50fa..5c249512de0 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -253,6 +253,23 @@ static PyObject *osdmap_pg_to_up_acting_osds(BasePyOSDMap *self, PyObject *args) return f.get(); } +static PyObject *osdmap_pool_raw_used_rate(BasePyOSDMap *self, PyObject *args) +{ + int pool_id = 0; + if (!PyArg_ParseTuple(args, "i:pool_raw_used_rate", + &pool_id)) { + return nullptr; + } + + if (!self->osdmap->have_pg_pool(pool_id)) { + return nullptr; + } + + float rate = self->osdmap->pool_raw_used_rate(pool_id); + + return PyFloat_FromDouble(rate); +} + PyMethodDef BasePyOSDMap_methods[] = { {"_get_epoch", (PyCFunction)osdmap_get_epoch, METH_NOARGS, "Get OSDMap epoch"}, @@ -272,6 +289,8 @@ PyMethodDef BasePyOSDMap_methods[] = { "Calculate up set mappings for all PGs in a pool"}, {"_pg_to_up_acting_osds", (PyCFunction)osdmap_pg_to_up_acting_osds, METH_VARARGS, "Calculate up+acting OSDs for a PG ID"}, + {"_pool_raw_used_rate", (PyCFunction)osdmap_pool_raw_used_rate, METH_VARARGS, + "Get raw space to logical space ratio"}, {NULL, NULL, 0, NULL} }; diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 33a20e1611f..23f34eafb52 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -703,37 +703,6 @@ void PGMapDigest::pool_cache_io_rate_summary(Formatter *f, ostream *out, cache_io_rate_summary(f, out, p->second.first, ts->second); } -static float pool_raw_used_rate(const OSDMap &osd_map, int64_t poolid) -{ - const pg_pool_t *pool = osd_map.get_pg_pool(poolid); - - switch (pool->get_type()) { - case pg_pool_t::TYPE_REPLICATED: - return pool->get_size(); - break; - case pg_pool_t::TYPE_ERASURE: - { - auto& ecp = - osd_map.get_erasure_code_profile(pool->erasure_code_profile); - auto pm = ecp.find("m"); - auto pk = ecp.find("k"); - if (pm != ecp.end() && pk != ecp.end()) { - int k = atoi(pk->second.c_str()); - int m = atoi(pm->second.c_str()); - int mk = m + k; - ceph_assert(mk != 0); - ceph_assert(k != 0); - return (float)mk / k; - } else { - return 0.0; - } - } - break; - default: - ceph_abort_msg("unrecognized pool type"); - } -} - ceph_statfs PGMapDigest::get_statfs(OSDMap &osdmap, boost::optional data_pool) const { @@ -826,7 +795,7 @@ void PGMapDigest::dump_pool_stats_full( tbl << pool_name << pool_id; } - float raw_used_rate = ::pool_raw_used_rate(osd_map, pool_id); + float raw_used_rate = osd_map.pool_raw_used_rate(pool_id); dump_object_stat_sum(tbl, f, stat, avail, raw_used_rate, verbose, pool); if (f) { f->close_section(); // stats @@ -986,7 +955,7 @@ int64_t PGMapDigest::get_pool_free_space(const OSDMap &osd_map, if (avail < 0) avail = 0; - return avail / ::pool_raw_used_rate(osd_map, poolid); + return avail / osd_map.pool_raw_used_rate(poolid); } int64_t PGMap::get_rule_avail(const OSDMap& osdmap, int ruleno) const diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 676638fdfbc..1b51e2cc3ff 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -5354,3 +5354,34 @@ void OSDMap::get_random_up_osds_by_subtree(int n, // whoami } } +float OSDMap::pool_raw_used_rate(int64_t poolid) const +{ + const pg_pool_t *pool = get_pg_pool(poolid); + assert(pool != nullptr); + + switch (pool->get_type()) { + case pg_pool_t::TYPE_REPLICATED: + return pool->get_size(); + break; + case pg_pool_t::TYPE_ERASURE: + { + auto& ecp = + get_erasure_code_profile(pool->erasure_code_profile); + auto pm = ecp.find("m"); + auto pk = ecp.find("k"); + if (pm != ecp.end() && pk != ecp.end()) { + int k = atoi(pk->second.c_str()); + int m = atoi(pm->second.c_str()); + int mk = m + k; + ceph_assert(mk != 0); + ceph_assert(k != 0); + return (float)mk / k; + } else { + return 0.0; + } + } + break; + default: + ceph_abort_msg("unrecognized pool type"); + } +} diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index f0f9e70a647..f860cd15108 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -1475,6 +1475,9 @@ public: int parse_osd_id_list(const vector& ls, set *out, ostream *ss) const; + + float pool_raw_used_rate(int64_t poolid) const; + }; WRITE_CLASS_ENCODER_FEATURES(OSDMap) WRITE_CLASS_ENCODER_FEATURES(OSDMap::Incremental) diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index e143468b20d..964a4612e87 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -150,6 +150,9 @@ class OSDMap(ceph_module.BasePyOSDMap): def pg_to_up_acting_osds(self, pool_id, ps): return self._pg_to_up_acting_osds(pool_id, ps) + def pool_raw_used_rate(self, pool_id): + return self._pool_raw_used_rate(pool_id) + class OSDMapIncremental(ceph_module.BasePyOSDMapIncremental): def get_epoch(self): -- 2.39.5