]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: reject negative weights at ceph osd <n> reweight
authorDan Mick <dan.mick@inktank.com>
Sat, 19 Jan 2013 02:30:03 +0000 (18:30 -0800)
committerDan Mick <dan.mick@inktank.com>
Sat, 19 Jan 2013 02:32:21 +0000 (18:32 -0800)
Check the integer (fixed-point) value to avoid any worries
about floating-point rounding.  Add tests for reweight < 0.

Fixes: #3872
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Sage Weil <sage.weil@inktank.com>
qa/workunits/cephtool/test.sh
src/mon/OSDMonitor.cc

index 1c9b48a5d9f28b1e3963ed02c6daa512a21f1f8b..42442c83e1c52c34c12cb6efa5207032b2901f4d 100755 (executable)
@@ -16,6 +16,9 @@ ceph tell osd.0 version
 ! ceph tell osd.9999 version 
 ! ceph tell osd.foo version
 
+ceph osd reweight 0 0.9
+! ceph osd reweight 0 -1
+ceph osd reweight 0 1
 
 for id in `ceph osd ls` ; do
        ceph tell osd.$id version
index c21a014a33d2ff27e8e8a1e22dfc4f8a8776afd3..2b51ebc8858a816a60323eb20ac7138820bc4c28 100644 (file)
@@ -2478,6 +2478,11 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       } else {
        float w = strtof(m->cmd[3].c_str(), 0);
        long ww = (int)((float)CEPH_OSD_IN*w);
+       if (ww < 0L) {
+         ss << "weight must be > 0";
+         err = -EINVAL;
+         goto out;
+       }
        if (osdmap.exists(osd)) {
          pending_inc.new_weight[osd] = ww;
          ss << "reweighted osd." << osd << " to " << w << " (" << ios::hex << ww << ios::dec << ")";