429
438
::encode(rule_name_map, bl);
432
void decode(bufferlist::iterator &blp) {
441
void decode(bufferlist::iterator &blp)
436
446
::decode(magic, blp);
437
assert(magic == CRUSH_MAGIC);
447
if (magic != CRUSH_MAGIC)
448
throw buffer::malformed_input("bad magic number");
439
450
::decode(crush->max_buckets, blp);
440
451
::decode(crush->max_rules, blp);
441
452
::decode(crush->max_devices, blp);
444
crush->buckets = (crush_bucket**)malloc(sizeof(crush_bucket*)*crush->max_buckets);
445
for (int i=0; i<crush->max_buckets; i++) {
449
crush->buckets[i] = 0;
456
crush->buckets = (crush_bucket**)calloc(1, crush->max_buckets * sizeof(crush_bucket*));
457
for (int i=0; i<crush->max_buckets; i++) {
458
decode_crush_bucket(&crush->buckets[i], blp);
462
crush->rules = (crush_rule**)calloc(1, crush->max_rules * sizeof(crush_rule*));
463
for (unsigned i = 0; i < crush->max_rules; ++i) {
467
crush->rules[i] = NULL;
473
crush->rules[i] = (crush_rule*)calloc(1, crush_rule_size(len));
474
crush->rules[i]->len = len;
475
::decode(crush->rules[i]->mask, blp);
476
for (unsigned j=0; j<crush->rules[i]->len; j++)
477
::decode(crush->rules[i]->steps[j], blp);
481
::decode(type_map, blp);
482
::decode(name_map, blp);
483
::decode(rule_name_map, blp);
489
crush_destroy(crush);
494
void decode_crush_bucket(crush_bucket** bptr, bufferlist::iterator &blp)
455
505
case CRUSH_BUCKET_UNIFORM:
456
506
size = sizeof(crush_bucket_uniform);
464
514
case CRUSH_BUCKET_STRAW:
465
515
size = sizeof(crush_bucket_straw);
519
snprintf(str, sizeof(str), "unsupported bucket algorithm: %d", alg);
520
throw buffer::malformed_input(str);
523
crush_bucket *bucket = (crush_bucket*)calloc(1, size);
526
::decode(bucket->id, blp);
527
::decode(bucket->type, blp);
528
::decode(bucket->alg, blp);
529
::decode(bucket->hash, blp);
530
::decode(bucket->weight, blp);
531
::decode(bucket->size, blp);
533
bucket->items = (__s32*)calloc(1, bucket->size * sizeof(__s32));
534
for (unsigned j = 0; j < bucket->size; ++j) {
535
::decode(bucket->items[j], blp);
538
bucket->perm = (__u32*)calloc(1, bucket->size * sizeof(__s32));
541
switch (bucket->alg) {
542
case CRUSH_BUCKET_UNIFORM: {
543
::decode(((crush_bucket_uniform*)bucket)->item_weight, blp);
547
case CRUSH_BUCKET_LIST: {
548
crush_bucket_list* cbl = (crush_bucket_list*)bucket;
549
cbl->item_weights = (__u32*)calloc(1, bucket->size * sizeof(__u32));
550
cbl->sum_weights = (__u32*)calloc(1, bucket->size * sizeof(__u32));
552
for (unsigned j = 0; j < bucket->size; ++j) {
553
::decode(cbl->item_weights[j], blp);
554
::decode(cbl->sum_weights[j], blp);
559
case CRUSH_BUCKET_TREE: {
561
crush_bucket_tree* cbt = (crush_bucket_tree*)bucket;
562
::decode(num_nodes, blp);
563
cbt->num_nodes = num_nodes;
564
cbt->node_weights = (__u32*)calloc(1, num_nodes * sizeof(__u32));
565
for (unsigned j=0; j<num_nodes; j++) {
566
::decode(cbt->node_weights[j], blp);
571
case CRUSH_BUCKET_STRAW: {
572
crush_bucket_straw* cbs = (crush_bucket_straw*)bucket;
573
cbs->straws = (__u32*)calloc(1, bucket->size * sizeof(__u32));
574
cbs->item_weights = (__u32*)calloc(1, bucket->size * sizeof(__u32));
575
for (unsigned j = 0; j < bucket->size; ++j) {
576
::decode(cbs->item_weights[j], blp);
577
::decode(cbs->straws[j], blp);
583
// We should have handled this case in the first switch statement
470
crush->buckets[i] = (crush_bucket*)malloc(size);
471
memset(crush->buckets[i], 0, size);
473
::decode(crush->buckets[i]->id, blp);
474
::decode(crush->buckets[i]->type, blp);
475
::decode(crush->buckets[i]->alg, blp);
476
::decode(crush->buckets[i]->hash, blp);
477
::decode(crush->buckets[i]->weight, blp);
478
::decode(crush->buckets[i]->size, blp);
480
crush->buckets[i]->items = (__s32*)malloc(sizeof(__s32)*crush->buckets[i]->size);
481
for (unsigned j=0; j<crush->buckets[i]->size; j++)
482
::decode(crush->buckets[i]->items[j], blp);
484
crush->buckets[i]->perm = (__u32*)malloc(sizeof(__s32)*crush->buckets[i]->size);
485
crush->buckets[i]->perm_n = 0;
487
switch (crush->buckets[i]->alg) {
488
case CRUSH_BUCKET_UNIFORM:
489
::decode(((crush_bucket_uniform*)crush->buckets[i])->item_weight, blp);
492
case CRUSH_BUCKET_LIST:
493
((crush_bucket_list*)crush->buckets[i])->item_weights =
494
(__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
495
((crush_bucket_list*)crush->buckets[i])->sum_weights =
496
(__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
498
for (unsigned j=0; j<crush->buckets[i]->size; j++) {
499
::decode(((crush_bucket_list*)crush->buckets[i])->item_weights[j], blp);
500
::decode(((crush_bucket_list*)crush->buckets[i])->sum_weights[j], blp);
504
case CRUSH_BUCKET_TREE:
506
::decode(((crush_bucket_tree*)crush->buckets[i])->num_nodes, blp);
507
unsigned num_nodes = ((crush_bucket_tree*)crush->buckets[i])->num_nodes;
508
((crush_bucket_tree*)crush->buckets[i])->node_weights =
509
(__u32*)malloc(num_nodes * sizeof(__u32));
510
for (unsigned j=0; j<num_nodes; j++)
511
::decode(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], blp);
515
case CRUSH_BUCKET_STRAW:
516
((crush_bucket_straw*)crush->buckets[i])->straws =
517
(__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
518
((crush_bucket_straw*)crush->buckets[i])->item_weights =
519
(__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
520
for (unsigned j=0; j<crush->buckets[i]->size; j++) {
521
::decode(((crush_bucket_straw*)crush->buckets[i])->item_weights[j], blp);
522
::decode(((crush_bucket_straw*)crush->buckets[i])->straws[j], blp);
529
crush->rules = (crush_rule**)malloc(sizeof(crush_rule*)*crush->max_rules);
530
for (unsigned i=0; i<crush->max_rules; i++) {
540
crush->rules[i] = (crush_rule*)malloc(crush_rule_size(len));
541
crush->rules[i]->len = len;
542
::decode(crush->rules[i]->mask, blp);
543
for (unsigned j=0; j<crush->rules[i]->len; j++)
544
::decode(crush->rules[i]->steps[j], blp);
548
::decode(type_map, blp);
549
::decode(name_map, blp);
550
::decode(rule_name_map, blp);