ceph osd crush add $o3 123 root=default
ceph osd tree | grep osd.$o3 | grep 123
ceph osd crush reweight osd.$o3 113
+expect_false ceph osd crush reweight osd.$o3 123456
ceph osd tree | grep osd.$o3 | grep 113
ceph osd crush rm osd.$o3
ceph osd rm osd.$o3
ceph osd tree | grep osd.$o4 | grep 123
ceph osd tree | grep osd.$o5 | grep 123
ceph osd crush reweight-subtree foobaz 155
+expect_false ceph osd crush reweight-subtree foobaz 123456
ceph osd tree | grep osd.$o4 | grep 155
ceph osd tree | grep osd.$o5 | grep 155
ceph osd crush rm osd.$o4
if (!is_valid_crush_loc(cct, loc))
return -EINVAL;
+ int r = validate_weightf(weight);
+ if (r < 0) {
+ return r;
+ }
+
if (name_exists(name)) {
if (get_item_id(name) != item) {
ldout(cct, 10) << "device name '" << name << "' already exists as id "
if (!is_valid_crush_loc(cct, loc))
return -EINVAL;
+ ret = validate_weightf(weight);
+ if (ret < 0) {
+ return ret;
+ }
+
// compare quantized (fixed-point integer) weights!
int iweight = (int)(weight * (float)0x10000);
int old_iweight;
return (float)get_item_weight_in_loc(id, loc) / (float)0x10000;
}
+ int validate_weightf(float weight) {
+ uint64_t iweight = weight * 0x10000;
+ if (iweight > std::numeric_limits<int>::max()) {
+ return -EOVERFLOW;
+ }
+ return 0;
+ }
int adjust_item_weight(CephContext *cct, int id, int weight);
int adjust_item_weightf(CephContext *cct, int id, float weight) {
+ int r = validate_weightf(weight);
+ if (r < 0) {
+ return r;
+ }
return adjust_item_weight(cct, id, (int)(weight * (float)0x10000));
}
int adjust_item_weight_in_loc(CephContext *cct, int id, int weight, const map<string,string>& loc);
int adjust_item_weightf_in_loc(CephContext *cct, int id, float weight, const map<string,string>& loc) {
+ int r = validate_weightf(weight);
+ if (r < 0) {
+ return r;
+ }
return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000), loc);
}
void reweight(CephContext *cct);
int adjust_subtree_weight(CephContext *cct, int id, int weight);
int adjust_subtree_weightf(CephContext *cct, int id, float weight) {
+ int r = validate_weightf(weight);
+ if (r < 0) {
+ return r;
+ }
return adjust_subtree_weight(cct, id, (int)(weight * (float)0x10000));
}