From patchwork Wed Jul 11 14:02:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1182751 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 D2649DF25A for ; Wed, 11 Jul 2012 14:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932548Ab2GKOCc (ORCPT ); Wed, 11 Jul 2012 10:02:32 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:45929 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932532Ab2GKOCb (ORCPT ); Wed, 11 Jul 2012 10:02:31 -0400 Received: by gglu4 with SMTP id u4so1233880ggl.19 for ; Wed, 11 Jul 2012 07:02:31 -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=qiAhO1zU2IeiTQ9BvLjd+6gJAGomWkbzVyXQQUQIx9M=; b=YaIASGwUVS4Yj+szpAvtbtU/Z7XlHi4tHNWa49emFnI4EsDusfHsJbyEZmIAl/uoxS LbYuuzVCXhIWQ8WS7anFGxPHCVZZT5LnDosSav2uSxF6X38uYYv0jjyV4x8lVvjDRqSc lZRcBbpGUK/IIsNMHJrwkUQ95GZVMlryWJXTTeBIKQnBIE89uBcg6AeaAay0hEXCcFcf ZdwZx6zzaSOe7/wVP1xyRaPB07ComK867jYkZe7ly5AgbWtL3NgwZjSL6CFKtjisupDp sK5hPxyCTGBh2MmZuWTnl3rlXM2b0Dm3/4KkO2L3KRWWbuvoMvKdMQVUlxbjgYYL/lUO Yk1Q== Received: by 10.101.11.18 with SMTP id o18mr16456443ani.14.1342015351280; Wed, 11 Jul 2012 07:02:31 -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 q10sm1491186anm.16.2012.07.11.07.02.28 (version=SSLv3 cipher=OTHER); Wed, 11 Jul 2012 07:02:29 -0700 (PDT) Message-ID: <4FFD8773.4020402@inktank.com> Date: Wed, 11 Jul 2012 09:02:27 -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 11/16] rbd: dynamically allocate snapshot name References: <4FFD847C.7070205@inktank.com> In-Reply-To: <4FFD847C.7070205@inktank.com> X-Gm-Message-State: ALoCoQlWN4GmfV2coD0hbWSJb4o/Q+csZ44vXz/h6IntiLCcSuKH5B3g5RCs2aDV5kiqHiLLFgxf 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 snapshot name recorded for an rbd image in a struct rbd_dev. Remove the limitation by allocating space for the snapshot name dynamically. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) if (!memcmp(dev->snap_name, RBD_SNAP_HEAD_NAME, @@ -2381,16 +2379,22 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX); /* - * The snapshot name is optional, but it's an error if it's - * too long. If no snapshot is supplied, fill in the default. + * The snapshot name is optional. If none is is supplied, + * we use the default value. */ - len = copy_token(&buf, rbd_dev->snap_name, sizeof (rbd_dev->snap_name)); - if (!len) + rbd_dev->snap_name = dup_token(&buf, &len); + if (!rbd_dev->snap_name) + goto out_err; + if (!len) { + /* Replace the empty name with the default */ + kfree(rbd_dev->snap_name); + rbd_dev->snap_name + = kmalloc(sizeof (RBD_SNAP_HEAD_NAME), GFP_KERNEL); + if (!rbd_dev->snap_name) + goto out_err; + memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME, sizeof (RBD_SNAP_HEAD_NAME)); - else if (len >= sizeof (rbd_dev->snap_name)) { - ret = -EINVAL; - goto out_err; } return pool_name; @@ -2505,6 +2509,7 @@ err_out_client: rbd_put_client(rbd_dev); err_put_id: if (pool_name) { + kfree(rbd_dev->snap_name); kfree(rbd_dev->obj_md_name); kfree(rbd_dev->obj); kfree(pool_name); @@ -2557,6 +2562,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->snap_name); kfree(rbd_dev->obj_md_name); kfree(rbd_dev->obj); rbd_id_put(rbd_dev); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 28afff9..90fb388 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -171,7 +171,7 @@ struct rbd_device { /* protects updating the header */ struct rw_semaphore header_rwsem; - char snap_name[RBD_MAX_SNAP_NAME_LEN]; + char *snap_name; u64 snap_id; /* current snapshot id */ int read_only; @@ -587,8 +587,6 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size) struct ceph_snap_context *snapc = header->snapc; int ret = -ENOENT; - BUILD_BUG_ON(sizeof (dev->snap_name) < sizeof (RBD_SNAP_HEAD_NAME)); - down_write(&dev->header_rwsem);