]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crush: weight_set_size -> weight_set_positions
authorSage Weil <sage@redhat.com>
Fri, 18 May 2018 17:30:21 +0000 (12:30 -0500)
committerSage Weil <sage@redhat.com>
Fri, 18 May 2018 17:30:21 +0000 (12:30 -0500)
This naming was confusing!  This is the number of positions we
have weight_sets for.

Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushCompiler.cc
src/crush/CrushTreeDumper.h
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/crush/builder.c
src/crush/crush.h
src/crush/mapper.c
src/test/crush/CrushWrapper.cc

index 47fe77629c706a8218b8f3dc6949f539498b1d02..d6d20dd07759cc3c9635c7e64dd30d47e9dd8aa4 100644 (file)
@@ -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 {
index 0c4b79e569bf4eeff16e14ebf31cb1f104124da1..5c0430c2ed8697b162cd07e124f3d61f3a41a3cb 100644 (file)
@@ -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;
index 3b8199fe030a6dbb1f1c979871f3924ba10ed313..6fde997e07f003e1afe94df6219a64b97e4ecb93 100644 (file)
@@ -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<crush_weight_set*>(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<crush_weight_set*>(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<int> bucket_weights(n.weight_set_size);
+    for (size_t s = 0; s < n.weight_set_positions; ++s) {
+      vector<int> 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_bucket_straw2*>(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<crush_weight_set*>(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;
   }
index 99f50980353cbcc06a6801827ceda7df925c99ba..bef4e075f19ded7e4c4107b3c96e005e31edb378 100644 (file)
@@ -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<crush_bucket_straw2*>(b);
-       carg.weight_set_size = positions;
+       carg.weight_set_positions = positions;
        carg.weight_set = static_cast<crush_weight_set*>(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;
index f492a27d3819b98125978e3c02c156f75c480737..be8b5e24cebcac4fc24988d5b0fc35dfc1e114c4 100644 (file)
@@ -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);
index ff78656e2af26973e50e38e9d82f2c24bc061716..dd08aa7bf5cdfbfe70cb6277a3d443c0e3f2239e 100644 (file)
@@ -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
index d2cd61494e18308d649818894495f01ebfed76f0..73f92a77d9f220e0e0989e9d223166cea9b8c3bb 100644 (file)
@@ -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;
 }
 
index ec240823b956e0c6e19bd53fcee517db0caa2d48..13de0cc1422fc2465b7de739652e0c1063951321 100644 (file)
@@ -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));
   }