From 04d0526718ccfc220b4fe0c9046ac58899d9dafc Mon Sep 17 00:00:00 2001 From: Xiaoxi Chen Date: Mon, 28 Jul 2014 16:54:48 +0800 Subject: [PATCH] PGMonitor: fix bug in caculating pool avail space Currently for pools with different rules, "ceph df" cannot report right available space for them, respectively. For detail assisment of the bug ,pls refer to bug report #8943 This patch fix this bug and make ceph df works correctlly. Fixes Bug #8943 Signed-off-by: Xiaoxi Chen --- src/crush/CrushWrapper.cc | 15 +++++++++++---- src/crush/CrushWrapper.h | 2 +- src/mon/PGMonitor.cc | 6 ++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 63e1ca32ff833..2e33598569ca4 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -821,7 +821,7 @@ int CrushWrapper::add_simple_ruleset(string name, string root_name, return rno; } -int CrushWrapper::get_rule_weight_map(unsigned ruleno, map *pmap) +int CrushWrapper::get_rule_weight_osd_map(unsigned ruleno, map *pmap) { if (ruleno >= crush->max_rules) return -ENOENT; @@ -841,15 +841,22 @@ int CrushWrapper::get_rule_weight_map(unsigned ruleno, map *pmap) } else { list q; q.push_back(n); + //breadth first iterate the OSD tree while (!q.empty()) { int bno = q.front(); q.pop_front(); crush_bucket *b = crush->buckets[-1-bno]; assert(b); for (unsigned j=0; jsize; ++j) { - float w = crush_get_bucket_item_weight(b, j); - m[b->items[j]] = w; - sum += w; + int item_id = b->items[j]; + if (item_id >= 0) //it's an OSD + { + float w = crush_get_bucket_item_weight(b, j); + m[item_id] = w; + sum += w; + } + else //not an OSD, expand the child later + q.push_back(item_id); } } } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 9aff1d3c76768..1b5e830fd501d 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -646,7 +646,7 @@ public: * @param pmap [out] map of osd to weight * @return 0 for success, or negative error code */ - int get_rule_weight_map(unsigned ruleno, map *pmap); + int get_rule_weight_osd_map(unsigned ruleno, map *pmap); /* modifiers */ int add_rule(int len, int ruleset, int type, int minsize, int maxsize, int ruleno) { diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 3c41112f06874..9757af5f386ae 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -1252,12 +1252,14 @@ void PGMonitor::dump_object_stat_sum(TextTable &tbl, Formatter *f, int64_t PGMonitor::get_rule_avail(OSDMap& osdmap, int ruleno) { map wm; - int r = osdmap.crush->get_rule_weight_map(ruleno, &wm); + int r = osdmap.crush->get_rule_weight_osd_map(ruleno, &wm); if (r < 0) return r; + if(wm.size() == 0) + return 0; int64_t min = -1; for (map::iterator p = wm.begin(); p != wm.end(); ++p) { - int64_t proj = (float)(pg_map.osd_sum.kb_avail * 1024ull) / + int64_t proj = (float)(pg_map.osd_stat[p->first].kb_avail * 1024ull) / (double)p->second; if (min < 0 || proj < min) min = proj; -- 2.39.5