From: Sage Weil Date: Fri, 14 Jul 2017 19:15:17 +0000 (-0400) Subject: crush/CrushWrapper: add_bucket: populate weight-sets X-Git-Tag: v12.1.2~150^2~22 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e3df727c47b604523e30dcc45c43e4748029c74f;p=ceph.git crush/CrushWrapper: add_bucket: populate weight-sets Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 0613a47723b..27325e32ed2 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1585,6 +1585,53 @@ int CrushWrapper::bucket_adjust_item_weight(CephContext *cct, crush_bucket *buck return crush_bucket_adjust_item_weight(crush, bucket, item, weight); } +int CrushWrapper::add_bucket( + int bucketno, int alg, int hash, int type, int size, + int *items, int *weights, int *idout) +{ + if (alg == 0) { + alg = get_default_bucket_alg(); + if (alg == 0) + return -EINVAL; + } + crush_bucket *b = crush_make_bucket(crush, alg, hash, type, size, items, + weights); + assert(b); + int r = crush_add_bucket(crush, bucketno, b, idout); + for (auto& p : choose_args) { + crush_choose_arg_map& cmap = p.second; + if (cmap.args) { + if ((int)cmap.size <= *idout) { + cmap.args = (crush_choose_arg*)realloc( + cmap.args, + sizeof(crush_choose_arg) * (*idout + 1)); + memset(&cmap.args[cmap.size], 0, + sizeof(crush_choose_arg) * (*idout + 1 - cmap.size)); + cmap.size = *idout + 1; + } + } else { + cmap.args = (crush_choose_arg*)calloc(sizeof(crush_choose_arg), + *idout + 1); + cmap.size = *idout + 1; + } + if (size > 0) { + int positions = get_choose_args_positions(cmap); + crush_choose_arg& carg = cmap.args[*idout]; + carg.weight_set = (crush_weight_set*)calloc(sizeof(crush_weight_set), + size); + carg.weight_set_size = positions; + for (int ppos = 0; ppos < positions; ++ppos) { + carg.weight_set[ppos].weights = (__u32*)calloc(sizeof(__u32), size); + carg.weight_set[ppos].size = size; + for (int bpos = 0; bpos < size; ++bpos) { + carg.weight_set[ppos].weights[bpos] = weights[bpos]; + } + } + } + } + return r; +} + int CrushWrapper::bucket_add_item(crush_bucket *bucket, int item, int weight) { __u32 new_size = bucket->size + 1; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 0835d79abdb..ba6ffdf5b88 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1234,17 +1234,7 @@ public: /* modifiers */ int add_bucket(int bucketno, int alg, int hash, int type, int size, - int *items, int *weights, int *idout) { - if (alg == 0) { - alg = get_default_bucket_alg(); - if (alg == 0) - return -EINVAL; - } - crush_bucket *b = crush_make_bucket(crush, alg, hash, type, size, items, weights); - assert(b); - return crush_add_bucket(crush, bucketno, b, idout); - } - + int *items, int *weights, int *idout); int bucket_add_item(crush_bucket *bucket, int item, int weight); int bucket_remove_item(struct crush_bucket *bucket, int item); int bucket_adjust_item_weight(CephContext *cct, struct crush_bucket *bucket, int item, int weight);