From patchwork Thu Mar 27 18:18:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899241 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 040839F2E8 for ; Thu, 27 Mar 2014 18:19:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2100A20253 for ; Thu, 27 Mar 2014 18:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3953E20225 for ; Thu, 27 Mar 2014 18:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757108AbaC0SS7 (ORCPT ); Thu, 27 Mar 2014 14:18:59 -0400 Received: from mail-ee0-f47.google.com ([74.125.83.47]:39486 "EHLO mail-ee0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757100AbaC0SS7 (ORCPT ); Thu, 27 Mar 2014 14:18:59 -0400 Received: by mail-ee0-f47.google.com with SMTP id b15so3189344eek.20 for ; Thu, 27 Mar 2014 11:18:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=eCKTnm9kAkPerRJWAVEZOgQLfqfRAKhmQIcv+DD4HzY=; b=BI599QSwZVL9RBF1Er/8awEX0BV8FFdISheok3lzDzCfGxlGMjBIFnI+1TdaFKzv82 76JmxfszeLzTGG2fGZe4kyhi4QUoGsLgR6Yb0uca3I7Zha/VZOQU7RFyO39yVlkNdTMt psZJ7EwchyB8ALHec7Edrlff6YNqkWJOxxSvhD2Khs2K4lSS75xOpLrUUXZvmHOHaBex h+4U1DjcXpfxttj1VU7zCHT0aVM4toW1xJX2o78SLrWeE8ZbttEtjEP5KoSO9sbmzOj1 jGHoZov6pgBhOglAJlC1GpEt4j1IkZR8WA8yCn8dnE6j9YWJqjOkIoJkpHy/OznF7BR5 caQw== X-Gm-Message-State: ALoCoQntLzYJhzTYMxyTywr4XdLIIZdRn/4REzH0y/dHEaHVFYNes22Yr5tL6eFcFMQpSBC4jSeJ X-Received: by 10.14.6.1 with SMTP id 1mr98260eem.71.1395944338015; Thu, 27 Mar 2014 11:18:58 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id 48sm5964803eei.24.2014.03.27.11.18.56 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:18:57 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 15/33] libceph: switch osdmap_set_max_osd() to krealloc() Date: Thu, 27 Mar 2014 20:18:01 +0200 Message-Id: <1395944299-21970-16-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> References: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index d6a569c5508f..4565c72fec5c 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -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) { u8 *state; - struct ceph_entity_addr *addr; u32 *weight; + struct ceph_entity_addr *addr; + int i; - state = kcalloc(max, sizeof(*state), GFP_NOFS); - addr = kcalloc(max, sizeof(*addr), GFP_NOFS); - weight = kcalloc(max, sizeof(*weight), GFP_NOFS); - if (state == NULL || addr == NULL || weight == NULL) { + state = krealloc(map->osd_state, max*sizeof(*state), GFP_NOFS); + weight = krealloc(map->osd_weight, max*sizeof(*weight), GFP_NOFS); + addr = krealloc(map->osd_addr, max*sizeof(*addr), GFP_NOFS); + if (!state || !weight || !addr) { kfree(state); - kfree(addr); kfree(weight); + kfree(addr); + return -ENOMEM; } - /* copy old? */ - if (map->osd_state) { - memcpy(state, map->osd_state, map->max_osd*sizeof(*state)); - memcpy(addr, map->osd_addr, map->max_osd*sizeof(*addr)); - memcpy(weight, map->osd_weight, map->max_osd*sizeof(*weight)); - kfree(map->osd_state); - kfree(map->osd_addr); - kfree(map->osd_weight); + for (i = map->max_osd; i < max; i++) { + state[i] = 0; + weight[i] = CEPH_OSD_OUT; + memset(addr + i, 0, sizeof(*addr)); } map->osd_state = state; map->osd_weight = weight; map->osd_addr = addr; + map->max_osd = max; + return 0; }