From: Sage Weil Date: Sun, 22 May 2011 23:25:35 +0000 (-0700) Subject: crushtool: add --reweight-item X-Git-Tag: v0.29~42^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5d982803113e3c17e728b2608f1a9853a86dfa38;p=ceph.git crushtool: add --reweight-item Reweight and individual item via crushtool. Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index ba1d5932082db..41becbcb2e203 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -128,7 +128,7 @@ int CrushWrapper::insert_device(int item, int weight, string name, return -EINVAL; } -void CrushWrapper::adjust_item_weight(int id, int weight) +int CrushWrapper::adjust_item_weight(int id, int weight) { cout << "adjust_item_weight " << id << " weight " << weight << std::endl; for (int bidx = 0; bidx < crush->max_buckets; bidx++) { @@ -140,8 +140,10 @@ void CrushWrapper::adjust_item_weight(int id, int weight) int diff = crush_bucket_adjust_item_weight(b, id, weight); cout << "adjust_item_weight " << id << " diff " << diff << std::endl; adjust_item_weight(-1 - bidx, b->weight); + return 0; } } + return -ENOENT; } void CrushWrapper::reweight() diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 62203df89caa0..f70f52ab093c9 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -156,7 +156,10 @@ public: void find_roots(set& roots) const; int insert_device(int id, int weight, string name, map& loc); int remove_device(int id); - void adjust_item_weight(int id, int weight); + int adjust_item_weight(int id, int weight); + int adjust_item_weightf(int id, float weight) { + return adjust_item_weight(id, (int)(weight * (float)0x10000)); + } void reweight(); diff --git a/src/crushtool.cc b/src/crushtool.cc index af8dcf783585b..188422edccdf4 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -805,7 +805,9 @@ int main(int argc, const char **argv) float add_weight = 0; const char *add_name = 0; map add_loc; - const char *remove_name = 0; + const char *remove_name = 0; + const char *reweight_name = 0; + float reweight_weight = 0; int build = 0; int num_osds =0; @@ -844,6 +846,9 @@ int main(int argc, const char **argv) add_loc[type] = name; } else if (CEPH_ARGPARSE_EQ("remove_item", '\0')) { CEPH_ARGPARSE_SET_ARG_VAL(&remove_name, OPT_STR); + } else if (CEPH_ARGPARSE_EQ("reweight_item", '\0')) { + CEPH_ARGPARSE_SET_ARG_VAL(&reweight_name, OPT_STR); + CEPH_ARGPARSE_SET_ARG_VAL(&reweight_weight, OPT_FLOAT); } else if (CEPH_ARGPARSE_EQ("verbose", 'v')) { verbose++; } else if (CEPH_ARGPARSE_EQ("build", '\0')) { @@ -889,7 +894,8 @@ int main(int argc, const char **argv) } if (decompile + compile + build > 1) usage(); - if (!compile && !decompile && !build && !test && !reweight && add_item < 0 && !remove_name) + if (!compile && !decompile && !build && !test && !reweight && add_item < 0 && + !remove_name && !reweight_name) usage(); /* @@ -1043,6 +1049,24 @@ int main(int argc, const char **argv) modified = true; } + if (reweight_name) { + cout << me << " reweighting item " << reweight_name << " to " << reweight_weight << std::endl; + int r; + if (!crush.name_exists(reweight_name)) { + cerr << " name " << reweight_name << " dne" << std::endl; + r = -ENOENT; + } else { + int item = crush.get_item_id(reweight_name); + r = crush.adjust_item_weightf(item, reweight_weight); + } + if (r == 0) + modified = true; + else { + cerr << me << " " << cpp_strerror(r) << std::endl; + return r; + } + + } if (remove_name) { cout << me << " removing item " << remove_name << std::endl; int r;