Skip to content

Commit 1b6a78b

Browse files
committed
libceph: add osdmap_set_crush() helper
Simplify osdmap_decode() and osdmap_apply_incremental() a bit. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 19def16 commit 1b6a78b

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

‎net/ceph/osdmap.c‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,17 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
808808
return 0;
809809
}
810810

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+
811822
#define OSDMAP_WRAPPER_COMPAT_VER 7
812823
#define OSDMAP_CLIENT_DATA_COMPAT_VER 1
813824

@@ -1214,13 +1225,9 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
12141225

12151226
/* crush */
12161227
ceph_decode_32_safe(p, end, len, e_inval);
1217-
map->crush = crush_decode(*p, min(*p + len, end));
1218-
if (IS_ERR(map->crush)) {
1219-
err = PTR_ERR(map->crush);
1220-
map->crush = NULL;
1228+
err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
1229+
if (err)
12211230
goto bad;
1222-
}
1223-
*p += len;
12241231

12251232
/* ignore the rest */
12261233
*p = end;
@@ -1375,7 +1382,6 @@ static int decode_new_up_state_weight(void **p, void *end,
13751382
struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
13761383
struct ceph_osdmap *map)
13771384
{
1378-
struct crush_map *newcrush = NULL;
13791385
struct ceph_fsid fsid;
13801386
u32 epoch = 0;
13811387
struct ceph_timespec modified;
@@ -1414,12 +1420,10 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
14141420
/* new crush? */
14151421
ceph_decode_32_safe(p, end, len, e_inval);
14161422
if (len > 0) {
1417-
newcrush = crush_decode(*p, min(*p+len, end));
1418-
if (IS_ERR(newcrush)) {
1419-
err = PTR_ERR(newcrush);
1420-
newcrush = NULL;
1423+
err = osdmap_set_crush(map,
1424+
crush_decode(*p, min(*p + len, end)));
1425+
if (err)
14211426
goto bad;
1422-
}
14231427
*p += len;
14241428
}
14251429

@@ -1439,12 +1443,6 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
14391443

14401444
map->epoch++;
14411445
map->modified = modified;
1442-
if (newcrush) {
1443-
if (map->crush)
1444-
crush_destroy(map->crush);
1445-
map->crush = newcrush;
1446-
newcrush = NULL;
1447-
}
14481446

14491447
/* new_pools */
14501448
err = decode_new_pools(p, end, map);
@@ -1505,8 +1503,6 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
15051503
print_hex_dump(KERN_DEBUG, "osdmap: ",
15061504
DUMP_PREFIX_OFFSET, 16, 1,
15071505
start, end - start, true);
1508-
if (newcrush)
1509-
crush_destroy(newcrush);
15101506
return ERR_PTR(err);
15111507
}
15121508

0 commit comments

Comments
 (0)