diff options
author | Sage Weil <sage@newdream.net> | 2012-05-02 12:17:27 -0700 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-05-02 14:55:53 -0700 |
commit | ce5842b60b4ab0e259b2166e94871c971760976e (patch) | |
tree | 6b0ed10ac0b954956daf794cc0d328f2e9059aab | |
parent | 5aadb5783315d83241ea4a1dbaf4d763e5e0fb34 (diff) | |
download | ceph-ce5842b60b4ab0e259b2166e94871c971760976e.tar.gz |
crushtool: add --update-item command
Similar to --add-item, except it will move, rename, or reweight the item if
it is already present in the map.
Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r-- | src/crushtool.cc | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/crushtool.cc b/src/crushtool.cc index 28a64acb95e..38f469a3a9f 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -63,6 +63,9 @@ void usage() cout << " -i mapfn --add-item id weight name [--loc type name ...]\n"; cout << " insert an item into the hierarchy at the\n"; cout << " given location\n"; + cout << " -i mapfn --update-item id weight name [--loc type name ...]\n"; + cout << " insert or move an item into the hierarchy at the\n"; + cout << " given location\n"; cout << " -i mapfn --remove-item name\n" << " remove the given item\n"; cout << " -i mapfn --reweight-item name weight\n"; @@ -103,6 +106,7 @@ int main(int argc, const char **argv) bool reweight = false; int add_item = -1; + bool update_item = false; float add_weight = 0; map<string,string> add_loc; float reweight_weight = 0; @@ -158,6 +162,20 @@ int main(int argc, const char **argv) usage(); add_name.assign(*i); i = args.erase(i); + } else if (ceph_argparse_withint(args, i, &add_item, &err, "--update_item", (char*)NULL)) { + update_item = true; + if (!err.str().empty()) { + cerr << err.str() << std::endl; + exit(EXIT_FAILURE); + } + if (i == args.end()) + usage(); + add_weight = atof(*i); + i = args.erase(i); + if (i == args.end()) + usage(); + add_name.assign(*i); + i = args.erase(i); } else if (ceph_argparse_witharg(args, i, &val, "--loc", (char*)NULL)) { std::string type(val); if (i == args.end()) @@ -467,12 +485,15 @@ int main(int argc, const char **argv) } } if (add_item >= 0) { - cout << me << " adding item " << add_item << " weight " << add_weight - << " at " << add_loc << std::endl; - int r = crush.insert_item(g_ceph_context, add_item, add_weight, add_name.c_str(), add_loc); - if (r == 0) + int r; + if (update_item) { + r = crush.update_item(g_ceph_context, add_item, add_weight, add_name.c_str(), add_loc); + } else { + r = crush.insert_item(g_ceph_context, add_item, add_weight, add_name.c_str(), add_loc); + } + if (r >= 0) { modified = true; - else { + } else { cerr << me << " " << cpp_strerror(r) << std::endl; return r; } |