summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-01-18 18:30:03 -0800
committerDan Mick <dan.mick@inktank.com>2013-01-18 18:32:21 -0800
commitaea898db2b56878b50f09dcbbf52347f4cc5c754 (patch)
tree41ba1e6cffba483347a43b27511226da9a92c7c7
parent7d9d7651beab8a104c1f41b9ced0ed558ad079f1 (diff)
downloadceph-aea898db2b56878b50f09dcbbf52347f4cc5c754.tar.gz
ceph: reject negative weights at ceph osd <n> reweight
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>
-rwxr-xr-xqa/workunits/cephtool/test.sh3
-rw-r--r--src/mon/OSDMonitor.cc5
2 files changed, 8 insertions, 0 deletions
diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh
index 1c9b48a5d9f..42442c83e1c 100755
--- a/qa/workunits/cephtool/test.sh
+++ b/qa/workunits/cephtool/test.sh
@@ -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
diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc
index c21a014a33d..2b51ebc8858 100644
--- a/src/mon/OSDMonitor.cc
+++ b/src/mon/OSDMonitor.cc
@@ -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 << ")";