diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index e24d572d7ad..161529ec272 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -313,9 +313,9 @@ public: } /* modifiers */ - int add_bucket(int bucketno, int alg, int type, int size, + int add_bucket(int bucketno, int alg, int hash, int type, int size, int *items, int *weights) { - crush_bucket *b = crush_make_bucket(alg, type, size, items, weights); + crush_bucket *b = crush_make_bucket(alg, hash, type, size, items, weights); return crush_add_bucket(crush, bucketno, b); } @@ -374,8 +374,8 @@ public: ::encode(crush->buckets[i]->id, bl); ::encode(crush->buckets[i]->type, bl); - ::encode(crush->buckets[i]->hash, bl); ::encode(crush->buckets[i]->alg, bl); + ::encode(crush->buckets[i]->hash, bl); ::encode(crush->buckets[i]->weight, bl); ::encode(crush->buckets[i]->size, bl); for (unsigned j=0; jbuckets[i]->size; j++) @@ -469,8 +469,8 @@ public: ::decode(crush->buckets[i]->id, blp); ::decode(crush->buckets[i]->type, blp); - ::decode(crush->buckets[i]->hash, blp); ::decode(crush->buckets[i]->alg, blp); + ::decode(crush->buckets[i]->hash, blp); ::decode(crush->buckets[i]->weight, blp); ::decode(crush->buckets[i]->size, blp); diff --git a/src/crush/builder.c b/src/crush/builder.c index c0d9e7a2b40..4b0319197a8 100644 --- a/src/crush/builder.c +++ b/src/crush/builder.c @@ -141,7 +141,7 @@ int crush_add_bucket(struct crush_map *map, /* uniform bucket */ struct crush_bucket_uniform * -crush_make_uniform_bucket(int type, int size, +crush_make_uniform_bucket(int hash, int type, int size, int *items, int item_weight) { @@ -151,8 +151,8 @@ crush_make_uniform_bucket(int type, int size, bucket = malloc(sizeof(*bucket)); memset(bucket, 0, sizeof(*bucket)); bucket->h.alg = CRUSH_BUCKET_UNIFORM; + bucket->h.hash = hash; bucket->h.type = type; - bucket->h.hash = CRUSH_HASH_RJENKINS1; bucket->h.size = size; bucket->h.weight = size * item_weight; @@ -170,7 +170,7 @@ crush_make_uniform_bucket(int type, int size, /* list bucket */ struct crush_bucket_list* -crush_make_list_bucket(int type, int size, +crush_make_list_bucket(int hash, int type, int size, int *items, int *weights) { @@ -181,8 +181,8 @@ crush_make_list_bucket(int type, int size, bucket = malloc(sizeof(*bucket)); memset(bucket, 0, sizeof(*bucket)); bucket->h.alg = CRUSH_BUCKET_LIST; + bucket->h.hash = hash; bucket->h.type = type; - bucket->h.hash = CRUSH_HASH_RJENKINS1; bucket->h.size = size; bucket->h.items = malloc(sizeof(__u32)*size); @@ -228,7 +228,7 @@ static int parent(int n) } struct crush_bucket_tree* -crush_make_tree_bucket(int type, int size, +crush_make_tree_bucket(int hash, int type, int size, int *items, /* in leaf order */ int *weights) { @@ -240,8 +240,8 @@ crush_make_tree_bucket(int type, int size, bucket = malloc(sizeof(*bucket)); memset(bucket, 0, sizeof(*bucket)); bucket->h.alg = CRUSH_BUCKET_TREE; + bucket->h.hash = hash; bucket->h.type = type; - bucket->h.hash = CRUSH_HASH_RJENKINS1; bucket->h.size = size; bucket->h.items = malloc(sizeof(__u32)*size); @@ -282,7 +282,8 @@ crush_make_tree_bucket(int type, int size, /* straw bucket */ struct crush_bucket_straw * -crush_make_straw_bucket(int type, +crush_make_straw_bucket(int hash, + int type, int size, int *items, int *weights) @@ -297,8 +298,8 @@ crush_make_straw_bucket(int type, bucket = malloc(sizeof(*bucket)); memset(bucket, 0, sizeof(*bucket)); bucket->h.alg = CRUSH_BUCKET_STRAW; + bucket->h.hash = hash; bucket->h.type = type; - bucket->h.hash = CRUSH_HASH_RJENKINS1; bucket->h.size = size; bucket->h.items = malloc(sizeof(__u32)*size); @@ -382,7 +383,7 @@ crush_make_straw_bucket(int type, struct crush_bucket* -crush_make_bucket(int alg, int type, int size, +crush_make_bucket(int alg, int hash, int type, int size, int *items, int *weights) { @@ -394,16 +395,16 @@ crush_make_bucket(int alg, int type, int size, item_weight = weights[0]; else item_weight = 0; - return (struct crush_bucket *)crush_make_uniform_bucket(type, size, items, item_weight); + return (struct crush_bucket *)crush_make_uniform_bucket(hash, type, size, items, item_weight); case CRUSH_BUCKET_LIST: - return (struct crush_bucket *)crush_make_list_bucket(type, size, items, weights); + return (struct crush_bucket *)crush_make_list_bucket(hash, type, size, items, weights); case CRUSH_BUCKET_TREE: - return (struct crush_bucket *)crush_make_tree_bucket(type, size, items, 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(type, size, items, weights); + return (struct crush_bucket *)crush_make_straw_bucket(hash, type, size, items, weights); } return 0; } diff --git a/src/crush/builder.h b/src/crush/builder.h index 2b36380e556..a83d858c76c 100644 --- a/src/crush/builder.h +++ b/src/crush/builder.h @@ -16,22 +16,22 @@ 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); -struct crush_bucket *crush_make_bucket(int alg, int type, int size, int *items, int *weights); +struct crush_bucket *crush_make_bucket(int alg, int hash, int type, int size, int *items, int *weights); struct crush_bucket_uniform * -crush_make_uniform_bucket(int type, int size, +crush_make_uniform_bucket(int hash, int type, int size, int *items, int item_weight); struct crush_bucket_list* -crush_make_list_bucket(int type, int size, +crush_make_list_bucket(int hash, int type, int size, int *items, int *weights); struct crush_bucket_tree* -crush_make_tree_bucket(int type, int size, +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 type, int size, +crush_make_straw_bucket(int hash, int type, int size, int *items, int *weights); diff --git a/src/crush/hash.h b/src/crush/hash.h index ab7bb532d25..ff48e110e4b 100644 --- a/src/crush/hash.h +++ b/src/crush/hash.h @@ -3,6 +3,8 @@ #define CRUSH_HASH_RJENKINS1 0 +#define CRUSH_HASH_DEFAULT CRUSH_HASH_RJENKINS1 + extern const char *crush_hash_name(int type); extern __u32 crush_hash32(int type, __u32 a); diff --git a/src/crushtool.cc b/src/crushtool.cc index 7fd99a838b5..6665be20056 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -113,6 +113,7 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush) int id = 0; // none, yet! int alg = -1; + int hash = -1; set used_items; int size = 0; @@ -137,6 +138,13 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush) exit(1); } } + else if (tag == "hash") { + string a = string_node(sub->children[1]); + if (a == "rjenkins1") + hash = CRUSH_HASH_RJENKINS1; + else + hash = atoi(a.c_str()); + } else if (tag == "item") { // first, just determine which item pos's are already used size++; @@ -214,7 +222,7 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush) item_id[name] = id; item_weight[id] = bucketweight; - crush.add_bucket(id, alg, type, size, &items[0], &weights[0]); + crush.add_bucket(id, alg, hash, type, size, &items[0], &weights[0]); crush.set_item_name(id, name.c_str()); } diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index b25e6e4e2cf..334950ebb63 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -171,7 +171,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map& rweights[i] += 0x10000; } - crush_bucket *domain = crush_make_bucket(CRUSH_BUCKET_UNIFORM, 1, j, items, weights); + crush_bucket *domain = crush_make_bucket(CRUSH_BUCKET_UNIFORM, CRUSH_HASH_DEFAULT, 1, j, items, weights); ritems[i] = crush_add_bucket(crush.crush, 0, domain); dout(20) << "added domain bucket i " << ritems[i] << " of size " << j << dendl; @@ -181,7 +181,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map& } // root - crush_bucket *root = crush_make_bucket(CRUSH_BUCKET_STRAW, 2, ndom, ritems, rweights); + crush_bucket *root = crush_make_bucket(CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, 2, ndom, ritems, rweights); int rootid = crush_add_bucket(crush.crush, 0, root); crush.set_item_name(rootid, "root"); @@ -206,7 +206,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map& weights[i] = 0x10000; } - crush_bucket *b = crush_make_bucket(CRUSH_BUCKET_STRAW, 1, num_osd, items, weights); + crush_bucket *b = crush_make_bucket(CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, 1, num_osd, items, weights); int rootid = crush_add_bucket(crush.crush, 0, b); crush.set_item_name(rootid, "root");