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;
}
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) {
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;
}
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++;
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++;
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);
}
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);
}
/* 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;
}
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,
bucket->item_weights[i] = weights[i];
}
- if (crush_calc_straw(bucket) < 0)
+ if (crush_calc_straw(map, bucket) < 0)
goto err;
return bucket;
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)
{
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;
}
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;
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;
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;
}
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;
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;
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;
}
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;
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:
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;
bucket->h.weight += bucket->item_weights[i];
}
- crush_calc_straw(bucket);
+ crush_calc_straw(crush, bucket);
return 0;
}
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,
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);