From patchwork Thu Jul 12 17:24:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1190131 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id DB5633FDAE for ; Thu, 12 Jul 2012 17:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932586Ab2GLRYN (ORCPT ); Thu, 12 Jul 2012 13:24:13 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:44005 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932742Ab2GLRYM (ORCPT ); Thu, 12 Jul 2012 13:24:12 -0400 Received: by ghrr11 with SMTP id r11so2664814ghr.19 for ; Thu, 12 Jul 2012 10:24:12 -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=n2UulR1mOyWkyYZe0M6P3/xq1a6opXwRNJQAR9DLyI8=; b=cp3F3L+AzECmMwOFZQO+P8EPpheUeDMw5XwHM2MHNKEVA3sBUnkAcjYvtlrDDXmi5x n6tsOs3kIa3LFTGhbvqSYVcT+InKUpzE7JtgFeP/M5Mg+E0iyVxRVVNlEJnYN6C4/KHp ZRnZrmYSji7zjYWMfxTsiTMkmH6xslMqVeEwWUGkJYgAGuEN4U2VjAUcGAarq41dqLSk qOzwVFBzugdiv1GR0gaTQNiH6mOiXpDb4jR73Gfm4y4xm/p4dIKkiwdMyr996Aizrp/r Xt2//mZD7d+nJeBOADhCyCAbQPM74RaP+fjOXT4vmm5WaI+RLueTMcFGLoV7ci3c/xoz Zxpw== Received: by 10.101.134.18 with SMTP id l18mr14615022ann.37.1342113851891; Thu, 12 Jul 2012 10:24:11 -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 a7sm5923569yhm.0.2012.07.12.10.24.10 (version=SSLv3 cipher=OTHER); Thu, 12 Jul 2012 10:24:11 -0700 (PDT) Message-ID: <4FFF083A.30903@inktank.com> Date: Thu, 12 Jul 2012 12:24:10 -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 v2 07/16] rbd: dynamically allocate object prefix References: <4FFD847C.7070205@inktank.com> <4FFD8750.7010407@inktank.com> In-Reply-To: <4FFD8750.7010407@inktank.com> X-Gm-Message-State: ALoCoQm8fHUP39aIHQRW8Ds60rtAx3MX5O9Zdg5pOrRi+adEFrgJY3lGFoJhK9YYmtVOn5J+s44Z 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 object prefix recorded for an rbd image in a struct rbd_image_header. Remove the limitation by allocating space for the object prefix dynamically. Signed-off-by: Alex Elder v2: The object prefix shouldn't change when the header is refreshed. Verify that (but still free the extra copy that gets allocated when the header is re-read). Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: b/drivers/block/rbd.c =================================================================== --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -77,7 +77,7 @@ */ struct rbd_image_header { u64 image_size; - char object_prefix[32]; + char *object_prefix; __u8 obj_order; __u8 crypt_type; __u8 comp_type; @@ -517,8 +517,15 @@ static int rbd_header_from_disk(struct r header->snap_names = NULL; header->snap_sizes = NULL; } + + header->object_prefix = kmalloc(sizeof (ondisk->block_name) + 1, + gfp_flags); + if (!header->object_prefix) + goto err_sizes; + memcpy(header->object_prefix, ondisk->block_name, sizeof(ondisk->block_name)); + header->object_prefix[sizeof (ondisk->block_name)] = '\0'; header->image_size = le64_to_cpu(ondisk->image_size); header->obj_order = ondisk->options.order; @@ -545,6 +552,8 @@ static int rbd_header_from_disk(struct r return 0; +err_sizes: + kfree(header->snap_sizes); err_names: kfree(header->snap_names); err_snapc: @@ -610,9 +619,10 @@ done: static void rbd_header_free(struct rbd_image_header *header) { - kfree(header->snapc); - kfree(header->snap_names); + kfree(header->object_prefix); kfree(header->snap_sizes); + kfree(header->snap_names); + kfree(header->snapc); } /* @@ -1710,15 +1720,20 @@ static int __rbd_refresh_header(struct r if head moves */ follow_seq = 1; - kfree(rbd_dev->header.snapc); - kfree(rbd_dev->header.snap_names); + /* rbd_dev->header.object_prefix shouldn't change */ kfree(rbd_dev->header.snap_sizes); + kfree(rbd_dev->header.snap_names); + kfree(rbd_dev->header.snapc); rbd_dev->header.total_snaps = h.total_snaps; rbd_dev->header.snapc = h.snapc; rbd_dev->header.snap_names = h.snap_names; rbd_dev->header.snap_names_len = h.snap_names_len; rbd_dev->header.snap_sizes = h.snap_sizes; + /* Free the extra copy of the object prefix */ + WARN_ON(strcmp(rbd_dev->header.object_prefix, h.object_prefix)); + kfree(h.object_prefix); + if (follow_seq) rbd_dev->header.snapc->seq = rbd_dev->header.snapc->snaps[0]; else @@ -2361,10 +2376,11 @@ static int rbd_add_parse_args(struct rbd if (!rbd_dev->pool_name) return -ENOMEM; - ret = -EINVAL; len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj)); - if (!len || len >= sizeof (rbd_dev->obj)) + if (!len || len >= sizeof (rbd_dev->obj)) { + ret = -EINVAL; goto out_err; + } /* We have the object length in hand, save it. */ @@ -2382,8 +2398,10 @@ static int rbd_add_parse_args(struct rbd 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 0;