]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: pass crush_map * to various builder methods
authorSage Weil <sage@redhat.com>
Tue, 2 Dec 2014 22:45:04 +0000 (14:45 -0800)
committerSage Weil <sage@redhat.com>
Fri, 13 Feb 2015 16:30:45 +0000 (08:30 -0800)
In particular, we will need it for crush_calc_straw().

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit f35a3d88cb944c292e966f679ac7a8d7a1cd3093)

Conflicts:
src/crush/CrushWrapper.cc

src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/crush/builder.c
src/crush/builder.h

index cbdf719014d573a2fbe4eeecb2009c0d46e45b03..6cdf09c2e3d46bf9e20a9fc6c56486f551484fa6 100644 (file)
@@ -152,7 +152,7 @@ int CrushWrapper::remove_item(CephContext *cct, int item, bool unlink_only)
       if (id == item) {
        ldout(cct, 5) << "remove_item removing item " << item
                      << " from bucket " << b->id << dendl;
-       crush_bucket_remove_item(b, item);
+       crush_bucket_remove_item(crush, b, item);
        adjust_item_weight(cct, b->id, b->weight);
        ret = 0;
       }
@@ -198,7 +198,7 @@ int CrushWrapper::_remove_item_under(CephContext *cct, int item, int ancestor, b
     int id = b->items[i];
     if (id == item) {
       ldout(cct, 5) << "_remove_item_under removing item " << item << " from bucket " << b->id << dendl;
-      crush_bucket_remove_item(b, item);
+      crush_bucket_remove_item(crush, b, item);
       adjust_item_weight(cct, b->id, b->weight);
       ret = 0;
     } else if (id < 0) {
@@ -520,7 +520,7 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n
 
     ldout(cct, 5) << "insert_item adding " << cur << " weight " << weight
                  << " to bucket " << id << dendl;
-    int r = crush_bucket_add_item(b, cur, 0);
+    int r = crush_bucket_add_item(crush, b, cur, 0);
     assert (!r);
     break;
   }
@@ -684,7 +684,7 @@ int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
       continue;
     for (unsigned i = 0; i < b->size; i++) {
       if (b->items[i] == id) {
-       int diff = crush_bucket_adjust_item_weight(b, id, weight);
+       int diff = crush_bucket_adjust_item_weight(crush, b, id, weight);
        ldout(cct, 5) << "adjust_item_weight " << id << " diff " << diff << " in bucket " << bidx << dendl;
        adjust_item_weight(cct, -1 - bidx, b->weight);
        changed++;
@@ -710,7 +710,7 @@ int CrushWrapper::adjust_item_weight_in_loc(CephContext *cct, int id, int weight
       continue;
     for (unsigned int i = 0; i < b->size; i++) {
       if (b->items[i] == id) {
-       int diff = crush_bucket_adjust_item_weight(b, id, weight);
+       int diff = crush_bucket_adjust_item_weight(crush, b, id, weight);
        ldout(cct, 5) << "adjust_item_weight_in_loc " << id << " diff " << diff << " in bucket " << bid << dendl;
        adjust_item_weight(cct, bid, b->weight);
        changed++;
index 525051ffece7289674fab14720cda5c9af3d33f3..1839681f153dc6eaf0c560bffdf0d6b69c5009b9 100644 (file)
@@ -781,11 +781,11 @@ private:
 
     if (!IS_ERR(parent_bucket)) {
       // zero out the bucket weight
-      crush_bucket_adjust_item_weight(parent_bucket, item, 0);
+      crush_bucket_adjust_item_weight(crush, parent_bucket, item, 0);
       adjust_item_weight(cct, parent_bucket->id, parent_bucket->weight);
 
       // remove the bucket from the parent
-      crush_bucket_remove_item(parent_bucket, item);
+      crush_bucket_remove_item(crush, parent_bucket, item);
     } else if (PTR_ERR(parent_bucket) != -ENOENT) {
       return PTR_ERR(parent_bucket);
     }
@@ -865,7 +865,7 @@ public:
                 int *items, int *weights, int *idout) {
     if (type == 0)
       return -EINVAL;
-    crush_bucket *b = crush_make_bucket(alg, hash, type, size, items, weights);
+    crush_bucket *b = crush_make_bucket(crush, alg, hash, type, size, items, weights);
     assert(b);
     return crush_add_bucket(crush, bucketno, b, idout);
   }
index 6328ad448c083d0a4c7adbf70a282fd52b9ecfd1..12f18b5509882a5c5e00e8be736e0f411298ebc6 100644 (file)
@@ -405,7 +405,7 @@ err:
 
 /* straw bucket */
 
-int crush_calc_straw(struct crush_bucket_straw *bucket)
+int crush_calc_straw(struct crush_map *map, struct crush_bucket_straw *bucket)
 {
        int *reverse;
        int i, j, k;
@@ -485,7 +485,8 @@ int crush_calc_straw(struct crush_bucket_straw *bucket)
 }
 
 struct crush_bucket_straw *
-crush_make_straw_bucket(int hash, 
+crush_make_straw_bucket(struct crush_map *map,
+                       int hash,
                        int type,
                        int size,
                        int *items,
@@ -523,7 +524,7 @@ crush_make_straw_bucket(int hash,
                bucket->item_weights[i] = weights[i];
        }
 
-        if (crush_calc_straw(bucket) < 0)
+        if (crush_calc_straw(map, bucket) < 0)
                 goto err;
 
        return bucket;
@@ -539,7 +540,8 @@ err:
 
 
 struct crush_bucket*
-crush_make_bucket(int alg, int hash, int type, int size,
+crush_make_bucket(struct crush_map *map,
+                 int alg, int hash, int type, int size,
                  int *items,
                  int *weights)
 {
@@ -560,7 +562,7 @@ crush_make_bucket(int alg, int hash, int type, int size,
                return (struct crush_bucket *)crush_make_tree_bucket(hash, type, size, items, weights);
 
        case CRUSH_BUCKET_STRAW:
-               return (struct crush_bucket *)crush_make_straw_bucket(hash, type, size, items, weights);
+               return (struct crush_bucket *)crush_make_straw_bucket(map, hash, type, size, items, weights);
        }
        return 0;
 }
@@ -699,7 +701,9 @@ int crush_add_tree_bucket_item(struct crush_bucket_tree *bucket, int item, int w
        return 0;
 }
 
-int crush_add_straw_bucket_item(struct crush_bucket_straw *bucket, int item, int weight)
+int crush_add_straw_bucket_item(struct crush_map *map,
+                               struct crush_bucket_straw *bucket,
+                               int item, int weight)
 {
        int newsize = bucket->h.size + 1;
        
@@ -732,13 +736,14 @@ int crush_add_straw_bucket_item(struct crush_bucket_straw *bucket, int item, int
        if (crush_addition_is_unsafe(bucket->h.weight, weight))
                 return -ERANGE;
 
-        bucket->h.weight += weight;
-        bucket->h.size++;
+       bucket->h.weight += weight;
+       bucket->h.size++;
        
-       return crush_calc_straw(bucket);
+       return crush_calc_straw(map, bucket);
 }
 
-int crush_bucket_add_item(struct crush_bucket *b, int item, int weight)
+int crush_bucket_add_item(struct crush_map *map,
+                         struct crush_bucket *b, int item, int weight)
 {
        /* invalidate perm cache */
        b->perm_n = 0;
@@ -751,7 +756,7 @@ int crush_bucket_add_item(struct crush_bucket *b, int item, int weight)
        case CRUSH_BUCKET_TREE:
                return crush_add_tree_bucket_item((struct crush_bucket_tree *)b, item, weight);
        case CRUSH_BUCKET_STRAW:
-               return crush_add_straw_bucket_item((struct crush_bucket_straw *)b, item, weight);
+               return crush_add_straw_bucket_item(map, (struct crush_bucket_straw *)b, item, weight);
        default:
                return -1;
        }
@@ -915,7 +920,8 @@ int crush_remove_tree_bucket_item(struct crush_bucket_tree *bucket, int item)
        return 0;
 }
 
-int crush_remove_straw_bucket_item(struct crush_bucket_straw *bucket, int item)
+int crush_remove_straw_bucket_item(struct crush_map *map,
+                                  struct crush_bucket_straw *bucket, int item)
 {
        int newsize = bucket->h.size - 1;
        unsigned i, j;
@@ -960,10 +966,10 @@ int crush_remove_straw_bucket_item(struct crush_bucket_straw *bucket, int item)
                bucket->straws = _realloc;
        }
 
-       return crush_calc_straw(bucket);
+       return crush_calc_straw(map, bucket);
 }
 
-int crush_bucket_remove_item(struct crush_bucket *b, int item)
+int crush_bucket_remove_item(struct crush_map *map, struct crush_bucket *b, int item)
 {
        /* invalidate perm cache */
        b->perm_n = 0;
@@ -976,7 +982,7 @@ int crush_bucket_remove_item(struct crush_bucket *b, int item)
        case CRUSH_BUCKET_TREE:
                return crush_remove_tree_bucket_item((struct crush_bucket_tree *)b, item);
        case CRUSH_BUCKET_STRAW:
-               return crush_remove_straw_bucket_item((struct crush_bucket_straw *)b, item);
+               return crush_remove_straw_bucket_item(map, (struct crush_bucket_straw *)b, item);
        default:
                return -1;
        }
@@ -1045,7 +1051,9 @@ int crush_adjust_tree_bucket_item_weight(struct crush_bucket_tree *bucket, int i
        return diff;
 }
 
-int crush_adjust_straw_bucket_item_weight(struct crush_bucket_straw *bucket, int item, int weight)
+int crush_adjust_straw_bucket_item_weight(struct crush_map *map,
+                                         struct crush_bucket_straw *bucket,
+                                         int item, int weight)
 {
        unsigned idx;
        int diff;
@@ -1061,14 +1069,16 @@ int crush_adjust_straw_bucket_item_weight(struct crush_bucket_straw *bucket, int
        bucket->item_weights[idx] = weight;
        bucket->h.weight += diff;
 
-       r = crush_calc_straw(bucket);
+       r = crush_calc_straw(map, bucket);
         if (r < 0)
                 return r;
 
        return diff;
 }
 
-int crush_bucket_adjust_item_weight(struct crush_bucket *b, int item, int weight)
+int crush_bucket_adjust_item_weight(struct crush_map *map,
+                                   struct crush_bucket *b,
+                                   int item, int weight)
 {
        switch (b->alg) {
        case CRUSH_BUCKET_UNIFORM:
@@ -1081,7 +1091,8 @@ int crush_bucket_adjust_item_weight(struct crush_bucket *b, int item, int weight
                return crush_adjust_tree_bucket_item_weight((struct crush_bucket_tree *)b,
                                                            item, weight);
        case CRUSH_BUCKET_STRAW:
-               return crush_adjust_straw_bucket_item_weight((struct crush_bucket_straw *)b,
+               return crush_adjust_straw_bucket_item_weight(map,
+                                                            (struct crush_bucket_straw *)b,
                                                             item, weight);
        default:
                return -1;
@@ -1184,7 +1195,7 @@ static int crush_reweight_straw_bucket(struct crush_map *crush, struct crush_buc
 
                 bucket->h.weight += bucket->item_weights[i];
        }
-       crush_calc_straw(bucket);
+       crush_calc_straw(crush, bucket);
 
        return 0;
 }
index 1003c353e6075496b94b913224d6c3e8ec7039b2..efd7c8aec43d29a645ce75cb7a67602927584311 100644 (file)
@@ -16,12 +16,12 @@ extern int crush_get_next_bucket_id(struct crush_map *map);
 extern int crush_add_bucket(struct crush_map *map,
                            int bucketno,
                            struct crush_bucket *bucket, int *idout);
-struct crush_bucket *crush_make_bucket(int alg, int hash, int type, int size, int *items, int *weights);
-extern int crush_bucket_add_item(struct crush_bucket *bucket, int item, int weight);
-extern int crush_bucket_adjust_item_weight(struct crush_bucket *bucket, int item, int weight);
+struct crush_bucket *crush_make_bucket(struct crush_map *map, int alg, int hash, int type, int size, int *items, int *weights);
+extern int crush_bucket_add_item(struct crush_map *map, struct crush_bucket *bucket, int item, int weight);
+extern int crush_bucket_adjust_item_weight(struct crush_map *map, struct crush_bucket *bucket, int item, int weight);
 extern int crush_reweight_bucket(struct crush_map *crush, struct crush_bucket *bucket);
 extern int crush_remove_bucket(struct crush_map *map, struct crush_bucket *bucket);
-extern int crush_bucket_remove_item(struct crush_bucket *bucket, int item);
+extern int crush_bucket_remove_item(struct crush_map *map, struct crush_bucket *bucket, int item);
 
 struct crush_bucket_uniform *
 crush_make_uniform_bucket(int hash, int type, int size,
@@ -36,7 +36,8 @@ crush_make_tree_bucket(int hash, int type, int size,
                       int *items,    /* in leaf order */
                       int *weights);
 struct crush_bucket_straw *
-crush_make_straw_bucket(int hash, int type, int size,
+crush_make_straw_bucket(struct crush_map *map,
+                       int hash, int type, int size,
                        int *items,
                        int *weights);