Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libceph: add osdmap_set_crush() helper

Simplify osdmap_decode() and osdmap_apply_incremental() a bit.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

+16 -20
+16 -20
net/ceph/osdmap.c
··· 808 808 return 0; 809 809 } 810 810 811 + static int osdmap_set_crush(struct ceph_osdmap *map, struct crush_map *crush) 812 + { 813 + if (IS_ERR(crush)) 814 + return PTR_ERR(crush); 815 + 816 + if (map->crush) 817 + crush_destroy(map->crush); 818 + map->crush = crush; 819 + return 0; 820 + } 821 + 811 822 #define OSDMAP_WRAPPER_COMPAT_VER 7 812 823 #define OSDMAP_CLIENT_DATA_COMPAT_VER 1 813 824 ··· 1225 1214 1226 1215 /* crush */ 1227 1216 ceph_decode_32_safe(p, end, len, e_inval); 1228 - map->crush = crush_decode(*p, min(*p + len, end)); 1229 - if (IS_ERR(map->crush)) { 1230 - err = PTR_ERR(map->crush); 1231 - map->crush = NULL; 1217 + err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); 1218 + if (err) 1232 1219 goto bad; 1233 - } 1234 - *p += len; 1235 1220 1236 1221 /* ignore the rest */ 1237 1222 *p = end; ··· 1382 1375 struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, 1383 1376 struct ceph_osdmap *map) 1384 1377 { 1385 - struct crush_map *newcrush = NULL; 1386 1378 struct ceph_fsid fsid; 1387 1379 u32 epoch = 0; 1388 1380 struct ceph_timespec modified; ··· 1420 1414 /* new crush? */ 1421 1415 ceph_decode_32_safe(p, end, len, e_inval); 1422 1416 if (len > 0) { 1423 - newcrush = crush_decode(*p, min(*p+len, end)); 1424 - if (IS_ERR(newcrush)) { 1425 - err = PTR_ERR(newcrush); 1426 - newcrush = NULL; 1417 + err = osdmap_set_crush(map, 1418 + crush_decode(*p, min(*p + len, end))); 1419 + if (err) 1427 1420 goto bad; 1428 - } 1429 1421 *p += len; 1430 1422 } 1431 1423 ··· 1443 1439 1444 1440 map->epoch++; 1445 1441 map->modified = modified; 1446 - if (newcrush) { 1447 - if (map->crush) 1448 - crush_destroy(map->crush); 1449 - map->crush = newcrush; 1450 - newcrush = NULL; 1451 - } 1452 1442 1453 1443 /* new_pools */ 1454 1444 err = decode_new_pools(p, end, map); ··· 1503 1505 print_hex_dump(KERN_DEBUG, "osdmap: ", 1504 1506 DUMP_PREFIX_OFFSET, 16, 1, 1505 1507 start, end - start, true); 1506 - if (newcrush) 1507 - crush_destroy(newcrush); 1508 1508 return ERR_PTR(err); 1509 1509 } 1510 1510