From patchwork Mon Aug 6 18:17:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1280651 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 E78A8DF288 for ; Mon, 6 Aug 2012 18:17:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932316Ab2HFSRi (ORCPT ); Mon, 6 Aug 2012 14:17:38 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:53282 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932114Ab2HFSRi (ORCPT ); Mon, 6 Aug 2012 14:17:38 -0400 Received: by pbbrr13 with SMTP id rr13so2921462pbb.19 for ; Mon, 06 Aug 2012 11:17:37 -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=Gtt749nzqIzi3ArdoHt/Nf6m2t9QB9DC/cmKNrIIX4w=; b=ne/jlk7fr0xWU1/GcC4O19XBP1Zrx9BmZgOp0tL1UJKkqMCIofx3eYQaOs3lp4LOjJ DFx5yZ0Wn5yMHKWDeIl7dPGAM7DcOrNbd1osE/XMZh48vnOp8szC1Tb4SndIeDkruNCM NTQKotcH1A60eLfUOekVePndn0NWWMKMMPZsq2y0kbGHp42nDzcnVbmM3IegSx2f6snP FyXvLY53djKKKJgms9iWl0pnBOGroHVq8Z45X9bo3AhS0Ld/R/HNr8osSMAGMLDEQOkB lVIaT/yvG3hl+FdCuxxNXMJ/HvgtXI7+M3Z0Pap1HMXkaW8aok+us56i7DqZfJ5UHiQ9 cUcQ== Received: by 10.68.224.170 with SMTP id rd10mr20809967pbc.106.1344277057789; Mon, 06 Aug 2012 11:17:37 -0700 (PDT) Received: from ?IPv6:2607:f298:a:607:3c9c:52cb:843e:71a9? ([2607:f298:a:607:3c9c:52cb:843e:71a9]) by mx.google.com with ESMTPS id pp2sm9408068pbb.1.2012.08.06.11.17.36 (version=SSLv3 cipher=OTHER); Mon, 06 Aug 2012 11:17:37 -0700 (PDT) Message-ID: <50200A3F.60802@inktank.com> Date: Mon, 06 Aug 2012 11:17:35 -0700 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 1/4] rbd: rearrange rbd_header_from_disk() References: <502009D1.7090005@inktank.com> In-Reply-To: <502009D1.7090005@inktank.com> X-Gm-Message-State: ALoCoQmg/mc3gX5KKaG1hpjYwTX9IpTGuXYYdkU7z4UVbPRdKW9eY86vCXGB9+H+1DeaN962Rfe9 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org This just moves code around for the most part. It was pulled out as a separate patch to avoid cluttering up some upcoming patches which are more substantive. The point is basically to group everything related to initializing the snapshot context together. The only functional change is that rbd_header_from_disk() now ensures the (in-core) header it is passed is zero-filled. This allows a simpler error handling path in rbd_header_from_disk(). Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 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 @@ -507,11 +507,14 @@ static int rbd_header_from_disk(struct r if (snap_count > size / sizeof (header->snapc->snaps[0])) return -EINVAL; - size = sizeof (struct ceph_snap_context); - size += snap_count * sizeof (header->snapc->snaps[0]); - header->snapc = kmalloc(size, GFP_KERNEL); - if (!header->snapc) + memset(header, 0, sizeof (*header)); + + size = sizeof (ondisk->block_name) + 1; + header->object_prefix = kmalloc(size, GFP_KERNEL); + if (!header->object_prefix) return -ENOMEM; + memcpy(header->object_prefix, ondisk->block_name, size - 1); + header->object_prefix[size - 1] = '\0'; if (snap_count) { header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); @@ -519,11 +522,12 @@ static int rbd_header_from_disk(struct r header->snap_names = kmalloc(header->snap_names_len, GFP_KERNEL); if (!header->snap_names) - goto err_snapc; + goto out_err; + size = snap_count * sizeof (*header->snap_sizes); header->snap_sizes = kmalloc(size, GFP_KERNEL); if (!header->snap_sizes) - goto err_names; + goto out_err; } else { WARN_ON(ondisk->snap_names_len); header->snap_names_len = 0; @@ -531,22 +535,23 @@ static int rbd_header_from_disk(struct r header->snap_sizes = NULL; } - size = sizeof (ondisk->block_name) + 1; - header->object_prefix = kmalloc(size, GFP_KERNEL); - if (!header->object_prefix) - goto err_sizes; - memcpy(header->object_prefix, ondisk->block_name, size - 1); - header->object_prefix[size - 1] = '\0'; - header->image_size = le64_to_cpu(ondisk->image_size); header->obj_order = ondisk->options.order; header->crypt_type = ondisk->options.crypt_type; header->comp_type = ondisk->options.comp_type; + header->total_snaps = snap_count; + + /* Set up the snapshot context */ + + size = sizeof (struct ceph_snap_context); + size += snap_count * sizeof (header->snapc->snaps[0]); + header->snapc = kzalloc(size, GFP_KERNEL); + if (!header->snapc) + goto out_err; atomic_set(&header->snapc->nref, 1); header->snapc->seq = le64_to_cpu(ondisk->snap_seq); header->snapc->num_snaps = snap_count; - header->total_snaps = snap_count; if (snap_count && allocated_snaps == snap_count) { int i; @@ -565,16 +570,14 @@ static int rbd_header_from_disk(struct r return 0; -err_sizes: +out_err: kfree(header->snap_sizes); header->snap_sizes = NULL; -err_names: kfree(header->snap_names); header->snap_names = NULL; header->snap_names_len = 0; -err_snapc: - kfree(header->snapc); - header->snapc = NULL; + kfree(header->object_prefix); + header->object_prefix = NULL; return -ENOMEM; }