]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
PGMonitor: fix bug in caculating pool avail space
authorXiaoxi Chen <xiaoxi.chen@intel.com>
Mon, 28 Jul 2014 08:54:48 +0000 (16:54 +0800)
committerSage Weil <sage@redhat.com>
Sat, 2 Aug 2014 00:45:17 +0000 (17:45 -0700)
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 <xiaoxi.chen@intel.com>
(cherry picked from commit 04d0526718ccfc220b4fe0c9046ac58899d9dafc)

src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/mon/PGMonitor.cc

index 2ff1327a740d2e6eef421a07d30c6f95e8658b99..15a46c25881d865203400b404d6f61e67facaf45 100644 (file)
@@ -794,7 +794,7 @@ int CrushWrapper::add_simple_ruleset(string name, string root_name,
   return rno;
 }
 
-int CrushWrapper::get_rule_weight_map(unsigned ruleno, map<int,float> *pmap)
+int CrushWrapper::get_rule_weight_osd_map(unsigned ruleno, map<int,float> *pmap)
 {
   if (ruleno >= crush->max_rules)
     return -ENOENT;
@@ -814,15 +814,22 @@ int CrushWrapper::get_rule_weight_map(unsigned ruleno, map<int,float> *pmap)
       } else {
        list<int> 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; j<b->size; ++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);
          }
        }
       }
index 35bd93093b1989af4b9919809b83099303acc7c5..cc4d77e84a262e59a95270c05b9b5ebecebd9b14 100644 (file)
@@ -641,7 +641,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<int,float> *pmap);
+  int get_rule_weight_osd_map(unsigned ruleno, map<int,float> *pmap);
 
   /* modifiers */
   int add_rule(int len, int ruleset, int type, int minsize, int maxsize, int ruleno) {
index 078202d0cbd207a1b2015dca0a787cb7a5dd1019..269d6ab52e40f5e1e703676c5ccc529a4323b48b 100644 (file)
@@ -1247,12 +1247,14 @@ void PGMonitor::dump_object_stat_sum(TextTable &tbl, Formatter *f,
 int64_t PGMonitor::get_rule_avail(OSDMap& osdmap, int ruleno)
 {
   map<int,float> 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<int,float>::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;