From: Ilya Dryomov Date: Tue, 27 Jun 2017 15:22:11 +0000 (+0200) Subject: crush/CrushWrapper: crush_choose_arg::ids should be __s32 X-Git-Tag: ses5-milestone8^2~9^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=dbdf66b8e54ac432b3769c3bfbac6460c0710ce6;p=ceph.git crush/CrushWrapper: crush_choose_arg::ids should be __s32 crush_choose_arg::ids array is encoded on the wire. int is not fixed size -- use __s32 instead (crush_bucket::id is __s32). This was introduced in commit dbe36e08be00 ("crush: compile/decompile crush_choose_arg_map") under SERVER_LUMINOUS bit. Signed-off-by: Ilya Dryomov --- diff --git a/src/crush/CrushCompiler.cc b/src/crush/CrushCompiler.cc index a6b62456699ff..e01d089acbcf2 100644 --- a/src/crush/CrushCompiler.cc +++ b/src/crush/CrushCompiler.cc @@ -232,7 +232,7 @@ int CrushCompiler::decompile_weight_set(crush_weight_set *weight_set, return 0; } -int CrushCompiler::decompile_ids(int *ids, +int CrushCompiler::decompile_ids(__s32 *ids, __u32 size, ostream &out) { @@ -972,7 +972,7 @@ int CrushCompiler::parse_choose_arg_ids(iter_t const& i, int bucket_id, crush_ch return -1; } arg->ids_size = size; - arg->ids = (int *)calloc(arg->ids_size, sizeof(int)); + arg->ids = (__s32 *)calloc(arg->ids_size, sizeof(__s32)); __u32 pos = 0; for (iter_t p = i->children.begin() + 2; pos < size; p++, pos++) arg->ids[pos] = int_node(*p); diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index f375c7412f853..7d4dd3c6abbaf 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1498,7 +1498,7 @@ int CrushWrapper::bucket_add_item(crush_bucket *bucket, int item, int weight) weight_set->size = new_size; } if (arg->ids_size) { - arg->ids = (int*)realloc(arg->ids, new_size * sizeof(int)); + arg->ids = (__s32 *)realloc(arg->ids, new_size * sizeof(__s32)); assert(arg->ids_size + 1 == new_size); arg->ids[arg->ids_size] = item; arg->ids_size = new_size; @@ -1530,7 +1530,7 @@ int CrushWrapper::bucket_remove_item(crush_bucket *bucket, int item) assert(arg->ids_size - 1 == new_size); for (__u32 k = position; k < new_size; k++) arg->ids[k] = arg->ids[k+1]; - arg->ids = (int*)realloc(arg->ids, new_size * sizeof(int)); + arg->ids = (__s32 *)realloc(arg->ids, new_size * sizeof(__s32)); arg->ids_size = new_size; } } @@ -1915,7 +1915,7 @@ void CrushWrapper::decode(bufferlist::iterator& blp) ::decode(weight_set->weights[l], blp); } ::decode(arg->ids_size, blp); - arg->ids = (int*)calloc(arg->ids_size, sizeof(int)); + arg->ids = (__s32 *)calloc(arg->ids_size, sizeof(__s32)); for (__u32 k = 0; k < arg->ids_size; k++) ::decode(arg->ids[k], blp); } diff --git a/src/crush/builder.c b/src/crush/builder.c index dc342d28a0168..3b4ba25b277b4 100644 --- a/src/crush/builder.c +++ b/src/crush/builder.c @@ -1413,13 +1413,13 @@ struct crush_choose_arg *crush_make_choose_args(struct crush_map *map, int num_p int size = (sizeof(struct crush_choose_arg) * map->max_buckets + sizeof(struct crush_weight_set) * bucket_count * num_positions + sizeof(__u32) * sum_bucket_size * num_positions + // weights - sizeof(__u32) * sum_bucket_size); // ids + sizeof(__s32) * sum_bucket_size); // ids char *space = malloc(size); struct crush_choose_arg *arg = (struct crush_choose_arg *)space; struct crush_weight_set *weight_set = (struct crush_weight_set *)(arg + map->max_buckets); __u32 *weights = (__u32 *)(weight_set + bucket_count * num_positions); char *weight_set_ends = (char*)weights; - int *ids = (int *)(weights + sum_bucket_size * num_positions); + __s32 *ids = (__s32 *)(weights + sum_bucket_size * num_positions); char *weights_end = (char *)ids; char *ids_end = (char *)(ids + sum_bucket_size); BUG_ON(space + size != ids_end); @@ -1442,7 +1442,7 @@ struct crush_choose_arg *crush_make_choose_args(struct crush_map *map, int num_p arg[b].weight_set_size = num_positions; weight_set += position; - memcpy(ids, bucket->h.items, sizeof(int) * bucket->h.size); + memcpy(ids, bucket->h.items, sizeof(__s32) * bucket->h.size); arg[b].ids = ids; arg[b].ids_size = bucket->h.size; ids += bucket->h.size; diff --git a/src/crush/crush.h b/src/crush/crush.h index 31fb94deff489..4be114631e36b 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -271,7 +271,7 @@ struct crush_weight_set { * */ struct crush_choose_arg { - int *ids; /*!< values to use instead of items */ + __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 */ diff --git a/src/crush/mapper.c b/src/crush/mapper.c index 321e7a7d549cf..8ea91897dfa41 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 return arg->weight_set[position].weights; } -static inline int *get_choose_arg_ids(const struct crush_bucket_straw2 *bucket, - const struct crush_choose_arg *arg) +static inline __s32 *get_choose_arg_ids(const struct crush_bucket_straw2 *bucket, + const struct crush_choose_arg *arg) { if ((arg == NULL) || (arg->ids == NULL)) return bucket->h.items; @@ -328,7 +328,7 @@ static int bucket_straw2_choose(const struct crush_bucket_straw2 *bucket, unsigned int u; __s64 ln, draw, high_draw = 0; __u32 *weights = get_choose_arg_weights(bucket, arg, position); - int *ids = get_choose_arg_ids(bucket, arg); + __s32 *ids = get_choose_arg_ids(bucket, arg); for (i = 0; i < bucket->h.size; i++) { dprintk("weight 0x%x item %d\n", weights[i], ids[i]); if (weights[i]) {