From: Chengyuan Li Date: Fri, 20 Nov 2015 05:29:39 +0000 (-0700) Subject: mon/PGMonitor: MAX AVAIL is 0 if some OSDs' weight is 0 X-Git-Tag: v10.0.1~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=06b3b47ebca16b8383b3dca047281e1477a48106;p=ceph.git mon/PGMonitor: MAX AVAIL is 0 if some OSDs' weight is 0 In get_rule_avail(), even p->second is 0, it's possible to be used as divisor and quotient is infinity, then is converted to an integer which is negative value. So we should check p->second value before calculation. It fixes BUG #13840. Signed-off-by: Chengyuan Li (cherry picked from commit 18713e60edd1fe16ab571f7c83e6de026db483ca) --- diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index e250f59ee218..2f37a56abdc8 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -1366,9 +1366,12 @@ int64_t PGMonitor::get_rule_avail(OSDMap& osdmap, int ruleno) const for (map::iterator p = wm.begin(); p != wm.end(); ++p) { ceph::unordered_map::const_iterator osd_info = pg_map.osd_stat.find(p->first); if (osd_info != pg_map.osd_stat.end()) { - if (osd_info->second.kb == 0) { + if (osd_info->second.kb == 0 || p->second == 0) { // osd must be out, hence its stats have been zeroed // (unless we somehow managed to have a disk with size 0...) + // + // (p->second == 0), if osd weight is 0, no need to + // calculate proj below. continue; } int64_t proj = (float)((osd_info->second).kb_avail * 1024ull) /