From 4586007a9ca6c4b6c0cd024e9879a6f07f0bae60 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 18 May 2018 12:30:21 -0500 Subject: [PATCH] crush: weight_set_size -> weight_set_positions This naming was confusing! This is the number of positions we have weight_sets for. Signed-off-by: Sage Weil (cherry picked from commit c173a275dff3f5fc050832cb10f75bda51e653c5) --- src/crush/CrushCompiler.cc | 12 ++++---- src/crush/CrushTreeDumper.h | 4 +-- src/crush/CrushWrapper.cc | 54 +++++++++++++++++----------------- src/crush/CrushWrapper.h | 12 ++++---- src/crush/builder.c | 2 +- src/crush/crush.h | 4 +-- src/crush/mapper.c | 4 +-- src/test/crush/CrushWrapper.cc | 4 +-- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/crush/CrushCompiler.cc b/src/crush/CrushCompiler.cc index 47fe77629c706..d6d20dd07759c 100644 --- a/src/crush/CrushCompiler.cc +++ b/src/crush/CrushCompiler.cc @@ -250,8 +250,8 @@ int CrushCompiler::decompile_choose_arg(crush_choose_arg *arg, int r; out << " {\n"; out << " bucket_id " << bucket_id << "\n"; - if (arg->weight_set_size > 0) { - r = decompile_weight_set(arg->weight_set, arg->weight_set_size, out); + if (arg->weight_set_positions > 0) { + r = decompile_weight_set(arg->weight_set, arg->weight_set_positions, out); if (r < 0) return r; } @@ -269,7 +269,7 @@ int CrushCompiler::decompile_choose_arg_map(crush_choose_arg_map arg_map, { for (__u32 i = 0; i < arg_map.size; i++) { if ((arg_map.args[i].ids_size == 0) && - (arg_map.args[i].weight_set_size == 0)) + (arg_map.args[i].weight_set_positions == 0)) continue; int r = decompile_choose_arg(&arg_map.args[i], -1-i, out); if (r < 0) @@ -951,14 +951,14 @@ int CrushCompiler::parse_weight_set_weights(iter_t const& i, int bucket_id, crus int CrushCompiler::parse_weight_set(iter_t const& i, int bucket_id, crush_choose_arg *arg) { // -3 stands for the leading "weight_set" keyword and the enclosing [ ] - arg->weight_set_size = i->children.size() - 3; - arg->weight_set = (crush_weight_set *)calloc(arg->weight_set_size, sizeof(crush_weight_set)); + arg->weight_set_positions = i->children.size() - 3; + arg->weight_set = (crush_weight_set *)calloc(arg->weight_set_positions, sizeof(crush_weight_set)); __u32 pos = 0; for (iter_t p = i->children.begin(); p != i->children.end(); p++) { int r = 0; switch((int)p->value.id().to_long()) { case crush_grammar::_weight_set_weights: - if (pos < arg->weight_set_size) { + if (pos < arg->weight_set_positions) { r = parse_weight_set_weights(p, bucket_id, &arg->weight_set[pos]); pos++; } else { diff --git a/src/crush/CrushTreeDumper.h b/src/crush/CrushTreeDumper.h index 0c4b79e569bf4..5c0430c2ed869 100644 --- a/src/crush/CrushTreeDumper.h +++ b/src/crush/CrushTreeDumper.h @@ -216,7 +216,7 @@ namespace CrushTreeDumper { if (b && bidx < (int)cmap.size && cmap.args[bidx].weight_set && - cmap.args[bidx].weight_set_size >= 1) { + cmap.args[bidx].weight_set_positions >= 1) { int bpos; for (bpos = 0; bpos < (int)cmap.args[bidx].weight_set[0].size && @@ -232,7 +232,7 @@ namespace CrushTreeDumper { } f->open_array_section(name.c_str()); for (unsigned opos = 0; - opos < cmap.args[bidx].weight_set_size; + opos < cmap.args[bidx].weight_set_positions; ++opos) { float w = (float)cmap.args[bidx].weight_set[opos].weights[bpos] / (float)0x10000; diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 3b8199fe030a6..6fde997e07f00 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -159,10 +159,10 @@ bool CrushWrapper::has_incompat_choose_args() const crush_choose_arg_map arg_map = choose_args.begin()->second; for (__u32 i = 0; i < arg_map.size; i++) { crush_choose_arg *arg = &arg_map.args[i]; - if (arg->weight_set_size == 0 && + if (arg->weight_set_positions == 0 && arg->ids_size == 0) continue; - if (arg->weight_set_size != 1) + if (arg->weight_set_positions != 1) return true; if (arg->ids_size != 0) return true; @@ -1803,7 +1803,7 @@ int CrushWrapper::bucket_adjust_item_weight(CephContext *cct, crush_bucket *buck for (auto &w : choose_args) { crush_choose_arg_map &arg_map = w.second; crush_choose_arg *arg = &arg_map.args[-1-bucket->id]; - for (__u32 j = 0; j < arg->weight_set_size; j++) { + for (__u32 j = 0; j < arg->weight_set_positions; j++) { crush_weight_set *weight_set = &arg->weight_set[j]; weight_set->weights[position] = weight; } @@ -1850,7 +1850,7 @@ int CrushWrapper::add_bucket( crush_choose_arg& carg = cmap.args[pos]; carg.weight_set = static_cast(calloc(sizeof(crush_weight_set), size)); - carg.weight_set_size = positions; + carg.weight_set_positions = positions; for (int ppos = 0; ppos < positions; ++ppos) { carg.weight_set[ppos].weights = (__u32*)calloc(sizeof(__u32), size); carg.weight_set[ppos].size = size; @@ -1873,7 +1873,7 @@ int CrushWrapper::bucket_add_item(crush_bucket *bucket, int item, int weight) for (auto &w : choose_args) { crush_choose_arg_map &arg_map = w.second; crush_choose_arg *arg = &arg_map.args[-1-bucket->id]; - for (__u32 j = 0; j < arg->weight_set_size; j++) { + for (__u32 j = 0; j < arg->weight_set_positions; j++) { crush_weight_set *weight_set = &arg->weight_set[j]; weight_set->weights = (__u32*)realloc(weight_set->weights, new_size * sizeof(__u32)); @@ -1906,7 +1906,7 @@ int CrushWrapper::bucket_remove_item(crush_bucket *bucket, int item) for (auto &w : choose_args) { crush_choose_arg_map &arg_map = w.second; crush_choose_arg *arg = &arg_map.args[-1-bucket->id]; - for (__u32 j = 0; j < arg->weight_set_size; j++) { + for (__u32 j = 0; j < arg->weight_set_positions; j++) { crush_weight_set *weight_set = &arg->weight_set[j]; assert(weight_set->size - 1 == new_size); for (__u32 k = position; k < new_size; k++) @@ -2104,15 +2104,15 @@ int CrushWrapper::device_class_clone( auto& o = cmap.args[-1-original_id]; auto& n = cmap.args[-1-bno]; n.ids_size = 0; // FIXME: implement me someday - n.weight_set_size = o.weight_set_size; + n.weight_set_positions = o.weight_set_positions; n.weight_set = static_cast(calloc( - n.weight_set_size, sizeof(crush_weight_set))); - for (size_t s = 0; s < n.weight_set_size; ++s) { + n.weight_set_positions, sizeof(crush_weight_set))); + for (size_t s = 0; s < n.weight_set_positions; ++s) { n.weight_set[s].size = copy->size; n.weight_set[s].weights = (__u32*)calloc(copy->size, sizeof(__u32)); } - for (size_t s = 0; s < n.weight_set_size; ++s) { - vector bucket_weights(n.weight_set_size); + for (size_t s = 0; s < n.weight_set_positions; ++s) { + vector bucket_weights(n.weight_set_positions); for (size_t i = 0; i < copy->size; ++i) { int item = copy->items[i]; if (item >= 0) { @@ -2317,7 +2317,7 @@ void CrushWrapper::encode(bufferlist& bl, uint64_t features) const { __u32 *weights; if (encode_compat_choose_args && - arg_map.args[i].weight_set_size > 0) { + arg_map.args[i].weight_set_positions > 0) { weights = arg_map.args[i].weight_set[0].weights; } else { weights = (reinterpret_cast(crush->buckets[i]))->item_weights; @@ -2379,7 +2379,7 @@ void CrushWrapper::encode(bufferlist& bl, uint64_t features) const size = 0; for (__u32 i = 0; i < arg_map.size; i++) { crush_choose_arg *arg = &arg_map.args[i]; - if (arg->weight_set_size == 0 && + if (arg->weight_set_positions == 0 && arg->ids_size == 0) continue; size++; @@ -2387,12 +2387,12 @@ void CrushWrapper::encode(bufferlist& bl, uint64_t features) const encode(size, bl); for (__u32 i = 0; i < arg_map.size; i++) { crush_choose_arg *arg = &arg_map.args[i]; - if (arg->weight_set_size == 0 && + if (arg->weight_set_positions == 0 && arg->ids_size == 0) continue; encode(i, bl); - encode(arg->weight_set_size, bl); - for (__u32 j = 0; j < arg->weight_set_size; j++) { + encode(arg->weight_set_positions, bl); + for (__u32 j = 0; j < arg->weight_set_positions; j++) { crush_weight_set *weight_set = &arg->weight_set[j]; encode(weight_set->size, bl); for (__u32 k = 0; k < weight_set->size; k++) @@ -2521,11 +2521,11 @@ void CrushWrapper::decode(bufferlist::iterator& blp) decode(bucket_index, blp); assert(bucket_index < arg_map.size); crush_choose_arg *arg = &arg_map.args[bucket_index]; - decode(arg->weight_set_size, blp); - if (arg->weight_set_size) { + decode(arg->weight_set_positions, blp); + if (arg->weight_set_positions) { arg->weight_set = static_cast(calloc( - arg->weight_set_size, sizeof(crush_weight_set))); - for (__u32 k = 0; k < arg->weight_set_size; k++) { + arg->weight_set_positions, sizeof(crush_weight_set))); + for (__u32 k = 0; k < arg->weight_set_positions; k++) { crush_weight_set *weight_set = &arg->weight_set[k]; decode(weight_set->size, blp); weight_set->weights = (__u32*)calloc( @@ -2839,15 +2839,15 @@ void CrushWrapper::dump_choose_args(Formatter *f) const 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 && + if (arg->weight_set_positions == 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) { + if (arg->weight_set_positions > 0) { f->open_array_section("weight_set"); - for (__u32 j = 0; j < arg->weight_set_size; j++) { + for (__u32 j = 0; j < arg->weight_set_positions; j++) { f->open_array_section("weights"); __u32 *weights = arg->weight_set[j].weights; __u32 size = arg->weight_set[j].size; @@ -3015,7 +3015,7 @@ protected: if (b && bidx < (int)cmap.size && cmap.args[bidx].weight_set && - cmap.args[bidx].weight_set_size >= 1) { + cmap.args[bidx].weight_set_positions >= 1) { int pos; for (pos = 0; pos < (int)cmap.args[bidx].weight_set[0].size && @@ -3443,10 +3443,10 @@ int CrushWrapper::_choose_args_adjust_item_weight_in_bucket( << dendl; return 0; } - if (carg->weight_set_size != weight.size()) { + if (carg->weight_set_positions != weight.size()) { if (ss) - *ss << "weight_set_size != " << weight.size() << " for bucket " << b->id; - ldout(cct, 10) << __func__ << " weight_set_size != " << weight.size() + *ss << "weight_set_positions != " << weight.size() << " for bucket " << b->id; + ldout(cct, 10) << __func__ << " weight_set_positions != " << weight.size() << " for bucket " << b->id << dendl; return 0; } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 99f50980353cb..bef4e075f19de 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1404,7 +1404,7 @@ public: void destroy_choose_args(crush_choose_arg_map arg_map) { for (__u32 i = 0; i < arg_map.size; i++) { crush_choose_arg *arg = &arg_map.args[i]; - for (__u32 j = 0; j < arg->weight_set_size; j++) { + for (__u32 j = 0; j < arg->weight_set_positions; j++) { crush_weight_set *weight_set = &arg->weight_set[j]; free(weight_set->weights); } @@ -1431,9 +1431,9 @@ public: carg.ids_size = 0; if (b && b->alg == CRUSH_BUCKET_STRAW2) { crush_bucket_straw2 *sb = reinterpret_cast(b); - carg.weight_set_size = positions; + carg.weight_set_positions = positions; carg.weight_set = static_cast(calloc(sizeof(crush_weight_set), - carg.weight_set_size)); + carg.weight_set_positions)); // initialize with canonical weights for (int pos = 0; pos < positions; ++pos) { carg.weight_set[pos].size = b->size; @@ -1444,7 +1444,7 @@ public: } } else { carg.weight_set = NULL; - carg.weight_set_size = 0; + carg.weight_set_positions = 0; } } return true; @@ -1493,8 +1493,8 @@ public: int get_choose_args_positions(crush_choose_arg_map cmap) { // infer positions from other buckets for (unsigned j = 0; j < cmap.size; ++j) { - if (cmap.args[j].weight_set_size) { - return cmap.args[j].weight_set_size; + if (cmap.args[j].weight_set_positions) { + return cmap.args[j].weight_set_positions; } } return 1; diff --git a/src/crush/builder.c b/src/crush/builder.c index f492a27d3819b..be8b5e24cebca 100644 --- a/src/crush/builder.c +++ b/src/crush/builder.c @@ -1447,7 +1447,7 @@ struct crush_choose_arg *crush_make_choose_args(struct crush_map *map, int num_p weights += bucket->h.size; } arg[b].weight_set = weight_set; - arg[b].weight_set_size = num_positions; + arg[b].weight_set_positions = num_positions; weight_set += position; memcpy(ids, bucket->h.items, sizeof(__s32) * bucket->h.size); diff --git a/src/crush/crush.h b/src/crush/crush.h index ff78656e2af26..dd08aa7bf5cdf 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -258,7 +258,7 @@ struct crush_weight_set { * When crush_do_rule() chooses the Nth item from a straw2 bucket, the * replacement weights found at __weight_set[N]__ are used instead of * the weights from __item_weights__. If __N__ is greater than - * __weight_set_size__, the weights found at __weight_set_size-1__ are + * __weight_set_positions__, the weights found at __weight_set_positions-1__ are * used instead. For instance if __weight_set__ is: * * [ [ 0x10000, 0x20000 ], // position 0 @@ -274,7 +274,7 @@ struct crush_choose_arg { __s32 *ids; /*!< values to use instead of items */ __u32 ids_size; /*!< size of the __ids__ array */ struct crush_weight_set *weight_set; /*!< weight replacements for a given position */ - __u32 weight_set_size; /*!< size of the __weight_set__ array */ + __u32 weight_set_positions; /*!< size of the __weight_set__ array */ }; /** @ingroup API diff --git a/src/crush/mapper.c b/src/crush/mapper.c index d2cd61494e183..73f92a77d9f22 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -312,8 +312,8 @@ static inline __u32 *get_choose_arg_weights(const struct crush_bucket_straw2 *bu { if ((arg == NULL) || (arg->weight_set == NULL)) return bucket->item_weights; - if (position >= arg->weight_set_size) - position = arg->weight_set_size - 1; + if (position >= arg->weight_set_positions) + position = arg->weight_set_positions - 1; return arg->weight_set[position].weights; } diff --git a/src/test/crush/CrushWrapper.cc b/src/test/crush/CrushWrapper.cc index ec240823b956e..13de0cc1422fc 100644 --- a/src/test/crush/CrushWrapper.cc +++ b/src/test/crush/CrushWrapper.cc @@ -1027,7 +1027,7 @@ TEST(CrushWrapper, choose_args_compat) { crush_choose_arg choose_args[maxbuckets]; memset(choose_args, '\0', sizeof(crush_choose_arg) * maxbuckets); choose_args[-1-id].ids_size = 0; - choose_args[-1-id].weight_set_size = 1; + choose_args[-1-id].weight_set_positions = 1; choose_args[-1-id].weight_set = &weight_set; crush_choose_arg_map arg_map; arg_map.size = c.get_max_buckets(); @@ -1045,7 +1045,7 @@ TEST(CrushWrapper, choose_args_compat) { CrushWrapper c_new; c_new.decode(i); ASSERT_EQ(1u, c_new.choose_args.size()); - ASSERT_EQ(1u, c_new.choose_args[caid].args[-1-id].weight_set_size); + ASSERT_EQ(1u, c_new.choose_args[caid].args[-1-id].weight_set_positions); ASSERT_EQ(weights, c_new.choose_args[caid].args[-1-id].weight_set[0].weights[0]); ASSERT_EQ(weight, c_new.get_bucket_item_weightf(id, 0)); } -- 2.39.5