libceph: add osdmap_set_crush() helper

Simplify osdmap_decode() and osdmap_apply_incremental() a bit.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
Ilya Dryomov 2017-01-31 15:55:06 +01:00
parent 19def166f3
commit 1b6a78b5b9

View file

@ -808,6 +808,17 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
return 0; return 0;
} }
static int osdmap_set_crush(struct ceph_osdmap *map, struct crush_map *crush)
{
if (IS_ERR(crush))
return PTR_ERR(crush);
if (map->crush)
crush_destroy(map->crush);
map->crush = crush;
return 0;
}
#define OSDMAP_WRAPPER_COMPAT_VER 7 #define OSDMAP_WRAPPER_COMPAT_VER 7
#define OSDMAP_CLIENT_DATA_COMPAT_VER 1 #define OSDMAP_CLIENT_DATA_COMPAT_VER 1
@ -1214,13 +1225,9 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
/* crush */ /* crush */
ceph_decode_32_safe(p, end, len, e_inval); ceph_decode_32_safe(p, end, len, e_inval);
map->crush = crush_decode(*p, min(*p + len, end)); err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
if (IS_ERR(map->crush)) { if (err)
err = PTR_ERR(map->crush);
map->crush = NULL;
goto bad; goto bad;
}
*p += len;
/* ignore the rest */ /* ignore the rest */
*p = end; *p = end;
@ -1375,7 +1382,6 @@ static int decode_new_up_state_weight(void **p, void *end,
struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
struct ceph_osdmap *map) struct ceph_osdmap *map)
{ {
struct crush_map *newcrush = NULL;
struct ceph_fsid fsid; struct ceph_fsid fsid;
u32 epoch = 0; u32 epoch = 0;
struct ceph_timespec modified; struct ceph_timespec modified;
@ -1414,12 +1420,10 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
/* new crush? */ /* new crush? */
ceph_decode_32_safe(p, end, len, e_inval); ceph_decode_32_safe(p, end, len, e_inval);
if (len > 0) { if (len > 0) {
newcrush = crush_decode(*p, min(*p+len, end)); err = osdmap_set_crush(map,
if (IS_ERR(newcrush)) { crush_decode(*p, min(*p + len, end)));
err = PTR_ERR(newcrush); if (err)
newcrush = NULL;
goto bad; goto bad;
}
*p += len; *p += len;
} }
@ -1439,12 +1443,6 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
map->epoch++; map->epoch++;
map->modified = modified; map->modified = modified;
if (newcrush) {
if (map->crush)
crush_destroy(map->crush);
map->crush = newcrush;
newcrush = NULL;
}
/* new_pools */ /* new_pools */
err = decode_new_pools(p, end, map); err = decode_new_pools(p, end, map);
@ -1505,8 +1503,6 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
print_hex_dump(KERN_DEBUG, "osdmap: ", print_hex_dump(KERN_DEBUG, "osdmap: ",
DUMP_PREFIX_OFFSET, 16, 1, DUMP_PREFIX_OFFSET, 16, 1,
start, end - start, true); start, end - start, true);
if (newcrush)
crush_destroy(newcrush);
return ERR_PTR(err); return ERR_PTR(err);
} }