From patchwork Fri Aug 24 16:33:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1372141 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 209BFDF28C for ; Fri, 24 Aug 2012 16:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759912Ab2HXQde (ORCPT ); Fri, 24 Aug 2012 12:33:34 -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 S1759622Ab2HXQdd (ORCPT ); Fri, 24 Aug 2012 12:33:33 -0400 Received: by mail-iy0-f174.google.com with SMTP id o24so3735552ial.19 for ; Fri, 24 Aug 2012 09:33:33 -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=h1ID4hTIJt2CCGCgNoiDdB8fAsTITcJJAlpMGGpH7jg=; b=Y/AXRob/gP764i/H71zzayH2/lMCMI0i313cioFeAGL1rU+3wa4cZnXlWqLuGznc9/ 0R7JE3EGS1Ilj09kXInpLKgmTC+bAMWdTpw165BZ/4oo6Lysyv1ZvGK5sm7HybEx6QCP t2fE40/gn0fK3dasp6hEYGTVT4YAPv5IeW1q9m8gg+veT+dp/+aAKGp9brOUHw8+j+gm a3VDxjKw6cvclUxyZEE4d6wYDqsAANPRqNrJ8fveb4mU0cDwL6IsqWSfd+hKBPSzTUnI QUTYxgU/1It4BJJ7FoRB4m6qwQeCPXMF/+ui3G7OK2yBKW46qxQ/TH24zyV3QoLz3Uv4 n1oA== Received: by 10.42.123.130 with SMTP id s2mr4964152icr.50.1345826013503; Fri, 24 Aug 2012 09:33:33 -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 wm7sm695441igb.6.2012.08.24.09.33.30 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:33:32 -0700 (PDT) Message-ID: <5037ACDA.3010004@inktank.com> Date: Fri, 24 Aug 2012 11:33:30 -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 04/11] rbd: more cleanup in rbd_header_from_disk() References: <5037AB20.4000103@inktank.com> In-Reply-To: <5037AB20.4000103@inktank.com> X-Gm-Message-State: ALoCoQlQddWZRHUOA39wuCixek4W3DR78ypS9urOz9a4O1mxHacpkq/ehEKCokfISPG8j2D9tC+B Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org This just rearranges things a bit more in rbd_header_from_disk() so that the snapshot sizes are initialized right after the buffer to hold them is allocated, and doing a little further consolidation that follows from that. It also adds a few simple comments. Signed-off-by: Alex Elder Reviewed-by: Yehuda Sadeh --- drivers/block/rbd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) @@ -535,6 +536,8 @@ static int rbd_header_from_disk(struct rbd_image_header *header, if (snap_count) { u64 snap_names_len = le64_to_cpu(ondisk->snap_names_len); + /* Save a copy of the snapshot names */ + BUG_ON(snap_names_len > (u64) SIZE_MAX); header->snap_names = kmalloc(snap_names_len, GFP_KERNEL); if (!header->snap_names) @@ -542,10 +545,15 @@ static int rbd_header_from_disk(struct rbd_image_header *header, memcpy(header->snap_names, &ondisk->snaps[snap_count], snap_names_len); + /* Record each snapshot's size */ + size = snap_count * sizeof (*header->snap_sizes); header->snap_sizes = kmalloc(size, GFP_KERNEL); if (!header->snap_sizes) goto out_err; + for (i = 0; i < snap_count; i++) + header->snap_sizes[i] = + le64_to_cpu(ondisk->snaps[i].image_size); } else { WARN_ON(ondisk->snap_names_len); header->snap_names = NULL; @@ -558,6 +566,8 @@ static int rbd_header_from_disk(struct rbd_image_header *header, header->comp_type = ondisk->options.comp_type; header->total_snaps = snap_count; + /* Allocate and fill in the snapshot context */ + size = sizeof (struct ceph_snap_context); size += snap_count * sizeof (header->snapc->snaps[0]); header->snapc = kzalloc(size, GFP_KERNEL); @@ -567,19 +577,9 @@ static int rbd_header_from_disk(struct rbd_image_header *header, atomic_set(&header->snapc->nref, 1); header->snapc->seq = le64_to_cpu(ondisk->snap_seq); header->snapc->num_snaps = snap_count; - - /* Fill in the snapshot information */ - - if (snap_count) { - u32 i; - - for (i = 0; i < snap_count; i++) { - header->snapc->snaps[i] = - le64_to_cpu(ondisk->snaps[i].id); - header->snap_sizes[i] = - le64_to_cpu(ondisk->snaps[i].image_size); - } - } + for (i = 0; i < snap_count; i++) + header->snapc->snaps[i] = + le64_to_cpu(ondisk->snaps[i].id); return 0; diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 7b3d861..130dbc2 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -520,6 +520,7 @@ static int rbd_header_from_disk(struct rbd_image_header *header, u32 snap_count; size_t len; size_t size; + u32 i; memset(header, 0, sizeof (*header));