From patchwork Wed Jul 11 14:02:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1182741 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 50082DF25A for ; Wed, 11 Jul 2012 14:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932675Ab2GKOCW (ORCPT ); Wed, 11 Jul 2012 10:02:22 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:48415 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932605Ab2GKOCU (ORCPT ); Wed, 11 Jul 2012 10:02:20 -0400 Received: by yenl2 with SMTP id l2so1226905yen.19 for ; Wed, 11 Jul 2012 07:02:20 -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=H71RBZuprxXTG6SvvwmBopFnz9/B2ykvMXpPlEREdwU=; b=FvHeGWEKpkHcF31B0ebONW/gSjMzwMHOBsLIn4g0GSCOczS4CBAe8/L+3Vuia7NOG7 y/V51Q24EJVVNNsEskHYrf+QW0SM3+0+NjusV5vmztMBvuAePBGYNKMXwepwPhGIY6xR I9aQ3JgZofNNLvG+QGEZu2FvI8/msxKy4RAbAXyShzUWmLT3S8M2MWyVwBD/VdaOd7uA BqgXzF5F+L2g2KvjPJqt4bjQsSQBEilgRBOKfCLTfzjxy2pQQa/5XtKIQhyXDd48dkod Kjnypg+Yp+DJv5xK2RqF2jVOG5fEMvQieawrlI8PBhpPjk681JdIvaX5rECKm1MpI/H0 japw== Received: by 10.236.197.3 with SMTP id s3mr6847630yhn.1.1342015340318; Wed, 11 Jul 2012 07:02:20 -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 q3sm1493884ani.15.2012.07.11.07.02.18 (version=SSLv3 cipher=OTHER); Wed, 11 Jul 2012 07:02:19 -0700 (PDT) Message-ID: <4FFD8769.90501@inktank.com> Date: Wed, 11 Jul 2012 09:02:17 -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 10/16] rbd: dynamically allocate image name References: <4FFD847C.7070205@inktank.com> In-Reply-To: <4FFD847C.7070205@inktank.com> X-Gm-Message-State: ALoCoQl65HGLNcpB2IOGTy+L9ApLQeAShVOUpu7oKXCe8QX+x8kri22B0n/zKvHUkyJ7nRm941QP 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 rbd image name recorded in a struct rbd_dev. Remove the limitation by allocating space for the image name dynamically. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 34 ++++++++++++++++++---------------- drivers/block/rbd_types.h | 1 - 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 4d11337..28afff9 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -161,8 +161,8 @@ struct rbd_device { spinlock_t lock; /* queue lock */ struct rbd_image_header header; - char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */ - int obj_len; + char *obj; /* rbd image name */ + size_t obj_len; char *obj_md_name; /* hdr nm. */ int pool_id; @@ -2333,6 +2333,8 @@ static inline char *dup_token(const char **buf, size_t *lenp) * Returns a pointer to a dynamically-allocated buffer containing * the pool name provided, or a pointer-coded errno if an error * occurs. + * + * Note: rbd_dev is assumed to have been initially zero-filled. */ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, const char *buf, @@ -2360,27 +2362,22 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, if (!len || len >= options_size) goto out_err; + ret = -ENOMEM; pool_name = dup_token(&buf, NULL); - if (!pool_name) { - ret = -ENOMEM; + if (!pool_name) goto out_err; - } - len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj)); - if (!len || len >= sizeof (rbd_dev->obj)) + rbd_dev->obj = dup_token(&buf, &rbd_dev->obj_len); + if (!rbd_dev->obj) goto out_err; - /* We have the object length in hand, save it. */ - - rbd_dev->obj_len = len; - /* 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; + rbd_dev->obj_md_name = kmalloc(rbd_dev->obj_len + + sizeof (RBD_SUFFIX), + GFP_KERNEL); + if (!rbd_dev->obj_md_name) goto out_err; - } sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX); /* @@ -2391,13 +2388,16 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, if (!len) memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME, sizeof (RBD_SNAP_HEAD_NAME)); - else if (len >= sizeof (rbd_dev->snap_name)) + else if (len >= sizeof (rbd_dev->snap_name)) { + ret = -EINVAL; goto out_err; + } return pool_name; out_err: kfree(rbd_dev->obj_md_name); + kfree(rbd_dev->obj); kfree(pool_name); return ERR_PTR(ret); @@ -2506,6 +2506,7 @@ err_out_client: err_put_id: if (pool_name) { kfree(rbd_dev->obj_md_name); + kfree(rbd_dev->obj); kfree(pool_name); } rbd_id_put(rbd_dev); @@ -2557,6 +2558,7 @@ static void rbd_dev_release(struct device *dev) /* done with the id, and with the rbd_dev */ kfree(rbd_dev->obj_md_name); + kfree(rbd_dev->obj); rbd_id_put(rbd_dev); kfree(rbd_dev); diff --git a/drivers/block/rbd_types.h b/drivers/block/rbd_types.h index 9507086..0924e9e 100644 --- a/drivers/block/rbd_types.h +++ b/drivers/block/rbd_types.h @@ -31,7 +31,6 @@ #define RBD_MIN_OBJ_ORDER 16 #define RBD_MAX_OBJ_ORDER 30 -#define RBD_MAX_OBJ_NAME_LEN 96 #define RBD_MAX_SEG_NAME_LEN 128 #define RBD_COMP_NONE 0