From patchwork Wed Jul 11 14:02:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1182731 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 213DEDF25A for ; Wed, 11 Jul 2012 14:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932494Ab2GKOCQ (ORCPT ); Wed, 11 Jul 2012 10:02:16 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:58247 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932723Ab2GKOCO (ORCPT ); Wed, 11 Jul 2012 10:02:14 -0400 Received: by mail-gh0-f174.google.com with SMTP id r11so1225639ghr.19 for ; Wed, 11 Jul 2012 07:02:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=PTPjj6Uvy4c9FcFEHqYtDZyUihsTmfRhwgNZNhXjRAM=; b=Bxqx+xuY+1UNiB8WM1YnWIQaOqGqV8RlONiAoa6aY40nfE5a05nYK+oCKSQnkcys95 D0BF8XplBSstXXWXn/LBwcKUS2k9O3ZOjMIIo+/N2WUNr1tvvxH6dcn65h0AaVW0TXOj u1FZHFpBdnfl5PashtETKIQqgtipl9M65rVJT4cFFx4iw9M85CwxMIR4a22tmJnMLFT9 WGkunw3LjPrX/sqxsd7s30kuj2t6OIVXIklJJZuuzTC62YywZ+Gd2jd73V4Vrg/5Cbnh 6PikD9QE3ZoY+6f9I9DwjDpLkrO0XtPc3GTw2RP8uGCR1tmfJCRT48CHKNxnrN4j3cE6 1l7A== Received: by 10.101.134.26 with SMTP id l26mr16872676ann.65.1342015334254; Wed, 11 Jul 2012 07:02:14 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id t22sm1488478anh.20.2012.07.11.07.02.12 (version=SSLv3 cipher=OTHER); Wed, 11 Jul 2012 07:02:13 -0700 (PDT) Message-ID: <4FFD8764.9040607@inktank.com> Date: Wed, 11 Jul 2012 09:02:12 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 09/16] rbd: dynamically allocate image header name References: <4FFD847C.7070205@inktank.com> In-Reply-To: <4FFD847C.7070205@inktank.com> X-Gm-Message-State: ALoCoQmYdoVDQqfa8xG1ZQ54T+VJjOdVacjVfFKlPzGyXzfDcLnMFBkcPi+v0NmMNv9KaClvNaXB Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org There is no need to impose a small limit the length of the header name recorded for an rbd image in a struct rbd_dev. Remove the limitation by allocating space for the header name dynamically. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 33 +++++++++++++++++++++------------ 1 files changed, 21 insertions(+), 12 deletions(-) /* @@ -2393,6 +2397,7 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, return pool_name; out_err: + kfree(rbd_dev->obj_md_name); kfree(pool_name); return ERR_PTR(ret); @@ -2402,23 +2407,23 @@ static ssize_t rbd_add(struct bus_type *bus, const char *buf, size_t count) { - struct rbd_device *rbd_dev; + char *options; + struct rbd_device *rbd_dev = NULL; const char *mon_addrs = NULL; size_t mon_addrs_size = 0; - char *options = NULL; - struct ceph_osd_client *osdc; char *pool_name; + struct ceph_osd_client *osdc; int rc = -ENOMEM; if (!try_module_get(THIS_MODULE)) return -ENODEV; - rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); - if (!rbd_dev) - goto err_nomem; options = kmalloc(count, GFP_KERNEL); if (!options) goto err_nomem; + rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); + if (!rbd_dev) + goto err_nomem; /* static rbd_device initialization */ spin_lock_init(&rbd_dev->lock); @@ -2499,11 +2504,14 @@ err_out_blkdev: err_out_client: rbd_put_client(rbd_dev); err_put_id: - kfree(pool_name); + if (pool_name) { + kfree(rbd_dev->obj_md_name); + kfree(pool_name); + } rbd_id_put(rbd_dev); err_nomem: - kfree(options); kfree(rbd_dev); + kfree(options); dout("Error adding device %s\n", buf); module_put(THIS_MODULE); @@ -2548,6 +2556,7 @@ static void rbd_dev_release(struct device *dev) unregister_blkdev(rbd_dev->major, rbd_dev->name); /* done with the id, and with the rbd_dev */ + kfree(rbd_dev->obj_md_name); rbd_id_put(rbd_dev); kfree(rbd_dev); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 76e978c..4d11337 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -55,7 +55,6 @@ #define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */ -#define RBD_MAX_MD_NAME_LEN (RBD_MAX_OBJ_NAME_LEN + sizeof(RBD_SUFFIX)) #define RBD_MAX_SNAP_NAME_LEN 32 #define RBD_MAX_OPT_LEN 1024 @@ -164,7 +163,7 @@ struct rbd_device { struct rbd_image_header header; char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */ int obj_len; - char obj_md_name[RBD_MAX_MD_NAME_LEN]; /* hdr nm. */ + char *obj_md_name; /* hdr nm. */ int pool_id; struct ceph_osd_event *watch_event; @@ -2375,8 +2374,13 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, rbd_dev->obj_len = len; - BUILD_BUG_ON(RBD_MAX_MD_NAME_LEN - < RBD_MAX_OBJ_NAME_LEN + sizeof (RBD_SUFFIX)); + /* Create the name of the header object */ + + rbd_dev->obj_md_name = kmalloc(len + sizeof (RBD_SUFFIX), GFP_KERNEL); + if (!rbd_dev->obj_md_name) { + ret = -ENOMEM; + goto out_err; + } sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX);