From patchwork Fri Aug 24 16:33:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1372131 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 9C107DF28C for ; Fri, 24 Aug 2012 16:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759888Ab2HXQdK (ORCPT ); Fri, 24 Aug 2012 12:33:10 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:45658 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759622Ab2HXQdJ (ORCPT ); Fri, 24 Aug 2012 12:33:09 -0400 Received: by ialo24 with SMTP id o24so3735552ial.19 for ; Fri, 24 Aug 2012 09:33:08 -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=yRJcnkv/2Nj2zbb8vqIK3MiHq/5LT8h3LFFgwuNXlo4=; b=mUhxElyD7NRcHQeGEHAVnnai02dflXj8k0eMQtCaCl/G4KxPk2aJSYMVty5XpfhqXB ew2NPN3m0jioZ0BIMTp72e5dcxbFHBi5T6zLioHXU3j0SWJUfYhL7tCQWT40QQ+D3pGU WjbkgopQnWG8lnumTHJTZCtG2a4oWTSc4CajWYmQx0k92woEGC7s+UhEEhrNGTe3YHgr cN68hVyfiLDh/4hP4yoZKiZn+dCguxdpsvFE1WsDfjMasb9y5sebN2xrKBQOL7FcYPQ/ zUiUVL43faIKOHUjj6D2I2nO7lJtX9E1xLtWQY6zZEXpVT0iIaiYxkSdwsp9vK60vr1q 7Xvg== Received: by 10.50.51.234 with SMTP id n10mr2788735igo.74.1345825988446; Fri, 24 Aug 2012 09:33:08 -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 10sm664550igf.11.2012.08.24.09.33.04 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:33:07 -0700 (PDT) Message-ID: <5037ACC0.1000108@inktank.com> Date: Fri, 24 Aug 2012 11:33:04 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 03/11] rbd: kill incore snap_names_len References: <5037AB20.4000103@inktank.com> In-Reply-To: <5037AB20.4000103@inktank.com> X-Gm-Message-State: ALoCoQl/r04UNaLpO1mNFrTzigu7iGd5nsycBClvdtScQTJHZUsENHPDMmF5jFqPLGGKVmyBAa5b Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org The only thing the on-disk snap_names_len field is used for is to size the buffer allocated to hold a copy of the snapshot names for an rbd image. Don't bother saving it in the in-core rbd_image_header structure. Just use a local variable to hold the required buffer size while it's needed. Move the code that actually copies the snapshot names up closer to where the required length is saved. Signed-off-by: Alex Elder --- drivers/block/rbd.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) header->snap_sizes = kmalloc(size, GFP_KERNEL); @@ -547,7 +548,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header, goto out_err; } else { WARN_ON(ondisk->snap_names_len); - header->snap_names_len = 0; header->snap_names = NULL; header->snap_sizes = NULL; } @@ -579,10 +579,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header, header->snap_sizes[i] = le64_to_cpu(ondisk->snaps[i].image_size); } - - /* copy snapshot names */ - memcpy(header->snap_names, &ondisk->snaps[snap_count], - header->snap_names_len); } return 0; @@ -592,7 +588,6 @@ out_err: header->snap_sizes = NULL; kfree(header->snap_names); header->snap_names = NULL; - header->snap_names_len = 0; kfree(header->object_prefix); header->object_prefix = NULL; @@ -660,7 +655,6 @@ static void rbd_header_free(struct rbd_image_header *header) header->snap_sizes = NULL; kfree(header->snap_names); header->snap_names = NULL; - header->snap_names_len = 0; ceph_put_snap_context(header->snapc); header->snapc = NULL; } @@ -1800,7 +1794,6 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) 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)); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a8a4cba..7b3d861 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -81,7 +81,6 @@ struct rbd_image_header { __u8 crypt_type; __u8 comp_type; struct ceph_snap_context *snapc; - u64 snap_names_len; u32 total_snaps; char *snap_names; @@ -534,12 +533,14 @@ static int rbd_header_from_disk(struct rbd_image_header *header, header->object_prefix[len] = '\0'; if (snap_count) { - header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); - BUG_ON(header->snap_names_len > (u64) SIZE_MAX); - header->snap_names = kmalloc(header->snap_names_len, - GFP_KERNEL); + u64 snap_names_len = le64_to_cpu(ondisk->snap_names_len); + + BUG_ON(snap_names_len > (u64) SIZE_MAX); + header->snap_names = kmalloc(snap_names_len, GFP_KERNEL); if (!header->snap_names) goto out_err; + memcpy(header->snap_names, &ondisk->snaps[snap_count], + snap_names_len); size = snap_count * sizeof (*header->snap_sizes);