Commit 4d60351f authored by Ilya Dryomov's avatar Ilya Dryomov Committed by Sage Weil

libceph: switch osdmap_set_max_osd() to krealloc()

Use krealloc() instead of rolling our own.  (krealloc() with a NULL
first argument acts as a kmalloc()).  Properly initalize the new array
elements.  This is needed to make future additions to osdmap easier.
Signed-off-by: default avatarIlya Dryomov <ilya.dryomov@inktank.com>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
parent 433fbdd3
...@@ -646,38 +646,40 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map) ...@@ -646,38 +646,40 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
} }
/* /*
* adjust max osd value. reallocate arrays. * Adjust max_osd value, (re)allocate arrays.
*
* The new elements are properly initialized.
*/ */
static int osdmap_set_max_osd(struct ceph_osdmap *map, int max) static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
{ {
u8 *state; u8 *state;
struct ceph_entity_addr *addr;
u32 *weight; u32 *weight;
struct ceph_entity_addr *addr;
int i;
state = kcalloc(max, sizeof(*state), GFP_NOFS); state = krealloc(map->osd_state, max*sizeof(*state), GFP_NOFS);
addr = kcalloc(max, sizeof(*addr), GFP_NOFS); weight = krealloc(map->osd_weight, max*sizeof(*weight), GFP_NOFS);
weight = kcalloc(max, sizeof(*weight), GFP_NOFS); addr = krealloc(map->osd_addr, max*sizeof(*addr), GFP_NOFS);
if (state == NULL || addr == NULL || weight == NULL) { if (!state || !weight || !addr) {
kfree(state); kfree(state);
kfree(addr);
kfree(weight); kfree(weight);
kfree(addr);
return -ENOMEM; return -ENOMEM;
} }
/* copy old? */ for (i = map->max_osd; i < max; i++) {
if (map->osd_state) { state[i] = 0;
memcpy(state, map->osd_state, map->max_osd*sizeof(*state)); weight[i] = CEPH_OSD_OUT;
memcpy(addr, map->osd_addr, map->max_osd*sizeof(*addr)); memset(addr + i, 0, sizeof(*addr));
memcpy(weight, map->osd_weight, map->max_osd*sizeof(*weight));
kfree(map->osd_state);
kfree(map->osd_addr);
kfree(map->osd_weight);
} }
map->osd_state = state; map->osd_state = state;
map->osd_weight = weight; map->osd_weight = weight;
map->osd_addr = addr; map->osd_addr = addr;
map->max_osd = max; map->max_osd = max;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment