| 3266 | } |
| 3267 | |
| 3268 | void CrushWrapper::decode(bufferlist::const_iterator& blp) |
| 3269 | { |
| 3270 | using ceph::decode; |
| 3271 | create(); |
| 3272 | |
| 3273 | __u32 magic; |
| 3274 | decode(magic, blp); |
| 3275 | if (magic != CRUSH_MAGIC) |
| 3276 | throw ceph::buffer::malformed_input("bad magic number"); |
| 3277 | |
| 3278 | decode(crush->max_buckets, blp); |
| 3279 | decode(crush->max_rules, blp); |
| 3280 | decode(crush->max_devices, blp); |
| 3281 | |
| 3282 | // legacy tunables, unless we decode something newer |
| 3283 | set_tunables_legacy(); |
| 3284 | |
| 3285 | try { |
| 3286 | // buckets |
| 3287 | crush->buckets = (crush_bucket**)calloc(1, crush->max_buckets * sizeof(crush_bucket*)); |
| 3288 | for (int i=0; i<crush->max_buckets; i++) { |
| 3289 | decode_crush_bucket(&crush->buckets[i], blp); |
| 3290 | } |
| 3291 | |
| 3292 | // rules |
| 3293 | crush->rules = (crush_rule**)calloc(1, crush->max_rules * sizeof(crush_rule*)); |
| 3294 | for (unsigned i = 0; i < crush->max_rules; ++i) { |
| 3295 | __u32 yes; |
| 3296 | decode(yes, blp); |
| 3297 | if (!yes) { |
| 3298 | crush->rules[i] = NULL; |
| 3299 | continue; |
| 3300 | } |
| 3301 | |
| 3302 | __u32 len; |
| 3303 | decode(len, blp); |
| 3304 | crush->rules[i] = reinterpret_cast<crush_rule*>(calloc(1, crush_rule_size(len))); |
| 3305 | crush->rules[i]->len = len; |
| 3306 | |
| 3307 | __u8 ruleset; // ignore + discard |
| 3308 | decode(ruleset, blp); |
| 3309 | if (ruleset != i) { |
| 3310 | throw ::ceph::buffer::malformed_input("crush ruleset_id != rule_id; encoding is too old"); |
| 3311 | } |
| 3312 | decode(crush->rules[i]->type, blp); |
| 3313 | decode(crush->rules[i]->deprecated_min_size, blp); |
| 3314 | decode(crush->rules[i]->deprecated_max_size, blp); |
| 3315 | |
| 3316 | for (unsigned j=0; j<crush->rules[i]->len; j++) |
| 3317 | decode(crush->rules[i]->steps[j], blp); |
| 3318 | } |
| 3319 | |
| 3320 | // name info |
| 3321 | // NOTE: we had a bug where we were incoding int instead of int32, which means the |
| 3322 | // 'key' field for these maps may be either 32 or 64 bits, depending. tolerate |
| 3323 | // both by assuming the string is always non-empty. |
| 3324 | decode_32_or_64_string_map(type_map, blp); |
| 3325 | decode_32_or_64_string_map(name_map, blp); |
nothing calls this directly
no test coverage detected