X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Ftools%2Fcrushtool.cc;h=b73a1d8c2adc7ece38f31e60b9eb5c5f8be6cff1;hb=31f18b776d001752a193a7cec8bb49033c1a904c;hp=12eff342fdd9e278ce7673175f4705709afd3584;hpb=40152f1e46a80b3405e5558a442ee632198dfd24;p=ceph.git diff --git a/ceph/src/tools/crushtool.cc b/ceph/src/tools/crushtool.cc index 12eff342f..b73a1d8c2 100644 --- a/ceph/src/tools/crushtool.cc +++ b/ceph/src/tools/crushtool.cc @@ -166,6 +166,12 @@ void usage() cout << " reweight a given item (and adjust ancestor\n" << " weights as needed)\n"; cout << " -i mapfn --reweight recalculate all bucket weights\n"; + cout << " -i mapfn --create-simple-rule name root type mode\n" + << " create crush rule to start from ,\n" + << " replicate across buckets of type , using\n" + << " a choose mode of \n"; + cout << " -i mapfn --remove-rule name\n" + << " remove the specified crush rule\n"; cout << "\n"; cout << "Options for the display/test stage\n"; cout << "\n"; @@ -252,6 +258,9 @@ int main(int argc, const char **argv) bool reweight = false; int add_item = -1; bool update_item = false; + bool add_rule = false; + std::string rule_name, rule_root, rule_type, rule_mode; + bool del_rule = false; float add_weight = 0; map add_loc; float reweight_weight = 0; @@ -406,6 +415,48 @@ int main(int argc, const char **argv) } add_name.assign(*i); i = args.erase(i); + } else if (ceph_argparse_witharg(args, i, &val, err, "--create-simple-rule", (char*)NULL)) { + rule_name.assign(val); + if (!err.str().empty()) { + cerr << err.str() << std::endl; + return EXIT_FAILURE; + } + if (i == args.end()) { + cerr << "expecting additional argument to --create-simple-rule" << std::endl; + return EXIT_FAILURE; + } + + rule_root.assign(*i); + i = args.erase(i); + if (i == args.end()) { + cerr << "expecting additional argument to --create-simple-rule" << std::endl; + return EXIT_FAILURE; + } + + rule_type.assign(*i); + i = args.erase(i); + if (i == args.end()) { + cerr << "expecting additional argument to --create-simple-rule" << std::endl; + return EXIT_FAILURE; + } + + rule_mode.assign(*i); + i = args.erase(i); + + cout << "--create-simple-rule:" + << " name=" << rule_name + << " root=" << rule_root + << " type=" << rule_type + << " mode=" << rule_mode + << std::endl; + add_rule = true; + } else if (ceph_argparse_witharg(args, i, &val, "--remove-rule", (char*)NULL)) { + rule_name.assign(val); + if (!err.str().empty()) { + cerr << err.str() << std::endl; + return EXIT_FAILURE; + } + del_rule = true; } else if (ceph_argparse_witharg(args, i, &val, "--loc", (char*)NULL)) { std::string type(val); if (i == args.end()) { @@ -548,7 +599,7 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && !dump && - add_item < 0 && full_location < 0 && + add_item < 0 && !add_rule && !del_rule && full_location < 0 && remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; return EXIT_FAILURE; @@ -748,7 +799,7 @@ int main(int argc, const char **argv) << dendl; } - if (OSDMap::build_simple_crush_rulesets(g_ceph_context, crush, root, &cerr)) + if (OSDMap::build_simple_crush_rules(g_ceph_context, crush, root, &cerr)) return EXIT_FAILURE; modified = true; @@ -840,6 +891,35 @@ int main(int argc, const char **argv) } } + if (add_rule) { + if (crush.rule_exists(rule_name)) { + cerr << "rule " << rule_name << " already exists" << std::endl; + return EXIT_FAILURE; + } + int r = crush.add_simple_rule(rule_name, rule_root, rule_type, rule_mode, + pg_pool_t::TYPE_REPLICATED, &err); + if (r < 0) { + cerr << err.str() << std::endl; + return EXIT_FAILURE; + } + modified = true; + } + + if (del_rule) { + if (!crush.rule_exists(rule_name)) { + cerr << "rule " << rule_name << " does not exist" << std::endl; + return 0; + } + int ruleno = crush.get_rule_id(rule_name); + assert(ruleno >= 0); + int r = crush.remove_rule(ruleno); + if (r < 0) { + cerr << "fail to remove rule " << rule_name << std::endl; + return EXIT_FAILURE; + } + modified = true; + } + if (reweight) { crush.reweight(g_ceph_context); modified = true;