From: xie xingguo Date: Mon, 10 Jul 2017 10:38:19 +0000 (+0800) Subject: osd/OSDMap: fix potential divided-by-zero error X-Git-Tag: v12.1.1~81^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5f7576c96a4b032678af675909b760fbc1c48ee6;p=ceph.git osd/OSDMap: fix potential divided-by-zero error Signed-off-by: xie xingguo --- diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index f6590080258c..421f32d7f821 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -3789,6 +3789,10 @@ int OSDMap::calc_pg_upmaps( << " pgs " << pgs << dendl; } + if (osd_weight_total == 0) { + lderr(cct) << __func__ << " abort due to osd_weight_total == 0" << dendl; + break; + } float pgs_per_weight = total_pgs / osd_weight_total; ldout(cct, 10) << " osd_weight_total " << osd_weight_total << dendl; ldout(cct, 10) << " pgs_per_weight " << pgs_per_weight << dendl; @@ -3838,6 +3842,7 @@ int OSDMap::calc_pg_upmaps( int osd = p->second; float deviation = p->first; float target = osd_weight[osd] * pgs_per_weight; + assert(target > 0); if (deviation/target < max_deviation_ratio) { ldout(cct, 10) << " osd." << osd << " target " << target