aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph
diff options
context:
space:
mode:
authorIlya Dryomov <ilya.dryomov@inktank.com>2014-03-21 13:05:28 -0400
committerSage Weil <sage@inktank.com>2014-04-05 00:07:52 -0400
commit4d60351f9089ef0f39d73c0b6a103e61fc0ed187 (patch)
tree12f0c5e54657361e9aac7961b59ad96d5f696dec /net/ceph
parent433fbdd31db267564bab20420bd8f161a7c69e4d (diff)
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: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'net/ceph')
-rw-r--r--net/ceph/osdmap.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 0ba3062d3317..a350286fd826 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -646,38 +646,40 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
646} 646}
647 647
648/* 648/*
649 * adjust max osd value. reallocate arrays. 649 * Adjust max_osd value, (re)allocate arrays.
650 *
651 * The new elements are properly initialized.
650 */ 652 */
651static int osdmap_set_max_osd(struct ceph_osdmap *map, int max) 653static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
652{ 654{
653 u8 *state; 655 u8 *state;
654 struct ceph_entity_addr *addr;
655 u32 *weight; 656 u32 *weight;
657 struct ceph_entity_addr *addr;
658 int i;
656 659
657 state = kcalloc(max, sizeof(*state), GFP_NOFS); 660 state = krealloc(map->osd_state, max*sizeof(*state), GFP_NOFS);
658 addr = kcalloc(max, sizeof(*addr), GFP_NOFS); 661 weight = krealloc(map->osd_weight, max*sizeof(*weight), GFP_NOFS);
659 weight = kcalloc(max, sizeof(*weight), GFP_NOFS); 662 addr = krealloc(map->osd_addr, max*sizeof(*addr), GFP_NOFS);
660 if (state == NULL || addr == NULL || weight == NULL) { 663 if (!state || !weight || !addr) {
661 kfree(state); 664 kfree(state);
662 kfree(addr);
663 kfree(weight); 665 kfree(weight);
666 kfree(addr);
667
664 return -ENOMEM; 668 return -ENOMEM;
665 } 669 }
666 670
667 /* copy old? */ 671 for (i = map->max_osd; i < max; i++) {
668 if (map->osd_state) { 672 state[i] = 0;
669 memcpy(state, map->osd_state, map->max_osd*sizeof(*state)); 673 weight[i] = CEPH_OSD_OUT;
670 memcpy(addr, map->osd_addr, map->max_osd*sizeof(*addr)); 674 memset(addr + i, 0, sizeof(*addr));
671 memcpy(weight, map->osd_weight, map->max_osd*sizeof(*weight));
672 kfree(map->osd_state);
673 kfree(map->osd_addr);
674 kfree(map->osd_weight);
675 } 675 }
676 676
677 map->osd_state = state; 677 map->osd_state = state;
678 map->osd_weight = weight; 678 map->osd_weight = weight;
679 map->osd_addr = addr; 679 map->osd_addr = addr;
680
680 map->max_osd = max; 681 map->max_osd = max;
682
681 return 0; 683 return 0;
682} 684}
683 685