diff options
author | Loic Dachary <ldachary@redhat.com> | 2017-04-16 17:21:41 +0200 |
---|---|---|
committer | Loic Dachary <ldachary@redhat.com> | 2017-04-18 09:45:13 +0200 |
commit | 1b02fef697ad033ec57a272b9c06c1e62f2f2a7a (patch) | |
tree | c4d8f7b743950af852a334086ec028c12a75be74 | |
parent | crush: disable modification API when choose_args is not empty (diff) | |
download | ceph-1b02fef697ad033ec57a272b9c06c1e62f2f2a7a.tar.xz ceph-1b02fef697ad033ec57a272b9c06c1e62f2f2a7a.zip |
crush: implement CrushWrapper::dump(choose_args)
Signed-off-by: Loic Dachary <loic@dachary.org>
-rw-r--r-- | src/crush/CrushWrapper.cc | 43 | ||||
-rw-r--r-- | src/crush/CrushWrapper.h | 1 | ||||
-rw-r--r-- | src/test/cli/crushtool/choose-args.t | 273 |
3 files changed, 317 insertions, 0 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 4a32ccb7325..7974b9a7501 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -5,6 +5,7 @@ #include "common/debug.h" #include "common/Formatter.h" #include "common/errno.h" +#include "include/stringify.h" #include "CrushWrapper.h" #include "CrushTreeDumper.h" @@ -1822,6 +1823,8 @@ void CrushWrapper::dump(Formatter *f) const f->open_object_section("tunables"); dump_tunables(f); f->close_section(); + + dump_choose_args(f); } namespace { @@ -1914,6 +1917,46 @@ void CrushWrapper::dump_tunables(Formatter *f) const f->dump_int("has_v5_rules", (int)has_v5_rules()); } +void CrushWrapper::dump_choose_args(Formatter *f) const +{ + f->open_object_section("choose_args"); + for (auto c : choose_args) { + crush_choose_arg_map arg_map = c.second; + f->open_array_section(stringify(c.first).c_str()); + for (__u32 i = 0; i < arg_map.size; i++) { + crush_choose_arg *arg = &arg_map.args[i]; + if (arg->weight_set_size == 0 && + arg->ids_size == 0) + continue; + f->open_object_section("choose_args"); + int bucket_index = i; + f->dump_int("bucket_id", -1-bucket_index); + if (arg->weight_set_size > 0) { + f->open_array_section("weight_set"); + for (__u32 j = 0; j < arg->weight_set_size; j++) { + f->open_array_section("weights"); + __u32 *weights = arg->weight_set[j].weights; + __u32 size = arg->weight_set[j].size; + for (__u32 k = 0; k < size; k++) { + f->dump_float("weight", (float)weights[k]/(float)0x10000); + } + f->close_section(); + } + f->close_section(); + } + if (arg->ids_size > 0) { + f->open_array_section("ids"); + for (__u32 j = 0; j < arg->ids_size; j++) + f->dump_int("id", arg->ids[j]); + f->close_section(); + } + f->close_section(); + } + f->close_section(); + } + f->close_section(); +} + void CrushWrapper::dump_rules(Formatter *f) const { for (int i=0; i<get_max_rules(); i++) { diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 773824e4eba..3d829954d77 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1275,6 +1275,7 @@ public: void dump_rules(Formatter *f) const; void dump_rule(int ruleset, Formatter *f) const; void dump_tunables(Formatter *f) const; + void dump_choose_args(Formatter *f) const; void list_rules(Formatter *f) const; void dump_tree(ostream *out, Formatter *f) const; void dump_tree(Formatter *f) const; diff --git a/src/test/cli/crushtool/choose-args.t b/src/test/cli/crushtool/choose-args.t index 0c7e3220441..6f1b47274ac 100644 --- a/src/test/cli/crushtool/choose-args.t +++ b/src/test/cli/crushtool/choose-args.t @@ -4,3 +4,276 @@ $ crushtool -c choose-args.conf -o choose-args.recompiled $ cmp choose-args.crush choose-args.conf $ cmp choose-args.compiled choose-args.recompiled + $ crushtool -c choose-args.conf -o /dev/null --dump + { + "devices": [ + { + "id": 0, + "name": "device0" + }, + { + "id": 1, + "name": "device1" + }, + { + "id": 2, + "name": "device2" + } + ], + "types": [ + { + "type_id": 0, + "name": "device" + }, + { + "type_id": 1, + "name": "host" + }, + { + "type_id": 2, + "name": "rack" + }, + { + "type_id": 3, + "name": "root" + } + ], + "buckets": [ + { + "id": -1, + "name": "host0", + "type_id": 1, + "type_name": "host", + "weight": 65536, + "alg": "straw", + "hash": "rjenkins1", + "items": [ + { + "id": 0, + "weight": 65536, + "pos": 0 + } + ] + }, + { + "id": -2, + "name": "host1", + "type_id": 1, + "type_name": "host", + "weight": 65536, + "alg": "straw", + "hash": "rjenkins1", + "items": [ + { + "id": 1, + "weight": 65536, + "pos": 0 + } + ] + }, + { + "id": -3, + "name": "rack0", + "type_id": 2, + "type_name": "rack", + "weight": 196608, + "alg": "straw", + "hash": "rjenkins1", + "items": [ + { + "id": -1, + "weight": 65536, + "pos": 0 + }, + { + "id": -2, + "weight": 65536, + "pos": 1 + }, + { + "id": -5, + "weight": 65536, + "pos": 2 + } + ] + }, + { + "id": -4, + "name": "root", + "type_id": 3, + "type_name": "root", + "weight": 262144, + "alg": "straw", + "hash": "rjenkins1", + "items": [ + { + "id": -3, + "weight": 262144, + "pos": 0 + } + ] + }, + { + "id": -5, + "name": "host2", + "type_id": 1, + "type_name": "host", + "weight": 65536, + "alg": "straw", + "hash": "rjenkins1", + "items": [ + { + "id": 2, + "weight": 65536, + "pos": 0 + } + ] + } + ], + "rules": [ + { + "rule_id": 0, + "rule_name": "data", + "ruleset": 3, + "type": 1, + "min_size": 2, + "max_size": 2, + "steps": [ + { + "op": "take", + "item": -4, + "item_name": "root" + }, + { + "op": "chooseleaf_firstn", + "num": 0, + "type": "rack" + }, + { + "op": "emit" + } + ] + } + ], + "tunables": { + "choose_local_tries": 2, + "choose_local_fallback_tries": 5, + "choose_total_tries": 19, + "chooseleaf_descend_once": 0, + "chooseleaf_vary_r": 0, + "chooseleaf_stable": 0, + "straw_calc_version": 0, + "allowed_bucket_algs": 22, + "profile": "argonaut", + "optimal_tunables": 0, + "legacy_tunables": 1, + "minimum_required_version": "argonaut", + "require_feature_tunables": 0, + "require_feature_tunables2": 0, + "has_v2_rules": 0, + "require_feature_tunables3": 0, + "has_v3_rules": 0, + "has_v4_buckets": 0, + "require_feature_tunables5": 0, + "has_v5_rules": 0 + }, + "choose_args": { + "1": [], + "2": [ + { + "bucket_id": -3, + "ids": [ + -20, + 30, + -25 + ] + } + ], + "3": [ + { + "bucket_id": -3, + "weight_set": [ + [ + 1.000000, + 2.000000, + 5.000000 + ], + [ + 3.000000, + 2.000000, + 5.000000 + ] + ], + "ids": [ + -20, + -30, + -25 + ] + } + ], + "4": [ + { + "bucket_id": -2, + "weight_set": [ + [ + 1.000000 + ], + [ + 3.000000 + ] + ] + } + ], + "5": [ + { + "bucket_id": -1, + "ids": [ + -450 + ] + } + ], + "6": [ + { + "bucket_id": -1, + "ids": [ + -450 + ] + }, + { + "bucket_id": -2, + "weight_set": [ + [ + 1.000000 + ], + [ + 3.000000 + ] + ] + }, + { + "bucket_id": -3, + "weight_set": [ + [ + 1.000000, + 2.000000, + 5.000000 + ], + [ + 3.000000, + 2.000000, + 5.000000 + ] + ], + "ids": [ + -20, + -30, + -25 + ] + } + ] + } + } + + + $ crushtool -c choose-args.conf -o /dev/null --dump | jq .for_json_validation + null |