crush: hrm fix up builder too

fix
This commit is contained in:
Sage Weil 2009-11-07 20:12:21 -08:00
parent 28ac4441b8
commit 63d2008c47
6 changed files with 37 additions and 26 deletions

View File

@ -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; j<crush->buckets[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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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<int> 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());
}

View File

@ -171,7 +171,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map<int, const char*>&
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<int, const char*>&
}
// 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<int, const char*>&
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");