Skip to content

Commit a2505d6

Browse files
idryomovSage Weil
authored andcommitted
libceph: split osdmap allocation and decode steps
Split osdmap allocation and initialization into a separate function, ceph_osdmap_decode(). Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Alex Elder <elder@linaro.org>
1 parent 38a8d56 commit a2505d6

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

‎include/linux/ceph/osdmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
156156
return 0;
157157
}
158158

159-
extern struct ceph_osdmap *osdmap_decode(void **p, void *end);
159+
extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
160160
extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
161161
struct ceph_osdmap *map,
162162
struct ceph_messenger *msgr);

‎net/ceph/osd_client.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
20622062
int skipped_map = 0;
20632063

20642064
dout("taking full map %u len %d\n", epoch, maplen);
2065-
newmap = osdmap_decode(&p, p+maplen);
2065+
newmap = ceph_osdmap_decode(&p, p+maplen);
20662066
if (IS_ERR(newmap)) {
20672067
err = PTR_ERR(newmap);
20682068
goto bad;

‎net/ceph/osdmap.c‎

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -684,24 +684,16 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
684684
/*
685685
* decode a full map.
686686
*/
687-
struct ceph_osdmap *osdmap_decode(void **p, void *end)
687+
static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
688688
{
689-
struct ceph_osdmap *map;
690689
u16 version;
691690
u32 len, max, i;
692691
int err = -EINVAL;
693692
u32 epoch = 0;
694693
void *start = *p;
695694
struct ceph_pg_pool_info *pi;
696695

697-
dout("osdmap_decode %p to %p len %d\n", *p, end, (int)(end - *p));
698-
699-
map = kzalloc(sizeof(*map), GFP_NOFS);
700-
if (map == NULL)
701-
return ERR_PTR(-ENOMEM);
702-
703-
map->pg_temp = RB_ROOT;
704-
mutex_init(&map->crush_scratch_mutex);
696+
dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p));
705697

706698
ceph_decode_16_safe(p, end, version, bad);
707699
if (version > 6) {
@@ -751,7 +743,6 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
751743
err = osdmap_set_max_osd(map, max);
752744
if (err < 0)
753745
goto bad;
754-
dout("osdmap_decode max_osd = %d\n", map->max_osd);
755746

756747
/* osds */
757748
err = -EINVAL;
@@ -819,16 +810,39 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
819810
*p = end;
820811

821812
dout("full osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd);
822-
return map;
813+
return 0;
823814

824815
bad:
825816
pr_err("corrupt full osdmap (%d) epoch %d off %d (%p of %p-%p)\n",
826817
err, epoch, (int)(*p - start), *p, start, end);
827818
print_hex_dump(KERN_DEBUG, "osdmap: ",
828819
DUMP_PREFIX_OFFSET, 16, 1,
829820
start, end - start, true);
830-
ceph_osdmap_destroy(map);
831-
return ERR_PTR(err);
821+
return err;
822+
}
823+
824+
/*
825+
* Allocate and decode a full map.
826+
*/
827+
struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end)
828+
{
829+
struct ceph_osdmap *map;
830+
int ret;
831+
832+
map = kzalloc(sizeof(*map), GFP_NOFS);
833+
if (!map)
834+
return ERR_PTR(-ENOMEM);
835+
836+
map->pg_temp = RB_ROOT;
837+
mutex_init(&map->crush_scratch_mutex);
838+
839+
ret = osdmap_decode(p, end, map);
840+
if (ret) {
841+
ceph_osdmap_destroy(map);
842+
return ERR_PTR(ret);
843+
}
844+
845+
return map;
832846
}
833847

834848
/*
@@ -872,7 +886,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
872886
if (len > 0) {
873887
dout("apply_incremental full map len %d, %p to %p\n",
874888
len, *p, end);
875-
return osdmap_decode(p, min(*p+len, end));
889+
return ceph_osdmap_decode(p, min(*p+len, end));
876890
}
877891

878892
/* new crush? */

0 commit comments

Comments
 (0)