From patchwork Thu Jul 26 19:08:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1244221 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 B9A1FDFFCE for ; Thu, 26 Jul 2012 19:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752345Ab2GZTIb (ORCPT ); Thu, 26 Jul 2012 15:08:31 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:64259 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751486Ab2GZTIb (ORCPT ); Thu, 26 Jul 2012 15:08:31 -0400 Received: by gglu4 with SMTP id u4so2340802ggl.19 for ; Thu, 26 Jul 2012 12:08:30 -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=ZL1ek2a9p+xBYKtA1ZagkEpF+kqZFyiBq7H+0T+iHBE=; b=Le1o160iskrouF1P4XlXto4P/L9uc44iO4eCcUqZaR8bG8CbMpnm1BSEGKwrpHPSbh FPeflGZiNnUBbeQxKX8PqSHSF1QuKh/C2kGeL8sWBYwwSpEeUPbkX+Wl6sWU+9ezsHQJ 269GJjYu1m0aEHfiz2CmE97CwI3hajr4/iJIzYhsnWkCdNSYQXMoOttnMgcfE+wbJw7f 4l1JmLOYA0HMtFJ6MBNKPNnIUlWVUFMLR+ir9gPWY5YO+aeHSH9ypN9oEyKsf/E9KVzl 3zyJoa6sZNH4XeW6v8X1VJg4OpsIRXt+S+q/P87JBDevbawQTxgPWR1CuyQqRPecw+Kg 67hg== Received: by 10.236.141.42 with SMTP id f30mr28997260yhj.120.1343329710545; Thu, 26 Jul 2012 12:08:30 -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 y10sm49465yhd.6.2012.07.26.12.08.29 (version=SSLv3 cipher=OTHER); Thu, 26 Jul 2012 12:08:30 -0700 (PDT) Message-ID: <501195AD.8080405@inktank.com> Date: Thu, 26 Jul 2012 14:08:29 -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 1/7] rbd: have __rbd_add_snap_dev() return a pointer References: <50119421.1090702@inktank.com> In-Reply-To: <50119421.1090702@inktank.com> X-Gm-Message-State: ALoCoQn46+GEBv48i7k6t5OusMNAPeCV/CcXV0Pq12NR9amYzAhBW8EqhfaA+GIN0EmO3GRyxPpj Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org It's not obvious whether the snapshot pointer whose address is provided to __rbd_add_snap_dev() will be assigned by that function. Change it to return the snapshot, or a pointer-coded errno in the event of a failure. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) if (device_is_registered(&rbd_dev->dev)) { @@ -2041,12 +2047,14 @@ static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, if (ret < 0) goto err; } - *snapp = snap; - return 0; + + return snap; + err: kfree(snap->name); kfree(snap); - return ret; + + return ERR_PTR(ret); } /* @@ -2079,7 +2087,6 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) const char *name, *first_name; int i = rbd_dev->header.total_snaps; struct rbd_snap *snap, *old_snap = NULL; - int ret; struct list_head *p, *n; first_name = rbd_dev->header.snap_names; @@ -2122,9 +2129,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) if (cur_id >= old_snap->id) break; /* a new snapshot */ - ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); - if (ret < 0) - return ret; + snap = __rbd_add_snap_dev(rbd_dev, i - 1, name); + if (IS_ERR(snap)) + return PTR_ERR(snap); /* note that we add it backward so using n and not p */ list_add(&snap->node, n); @@ -2138,9 +2145,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) WARN_ON(1); return -EINVAL; } - ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); - if (ret < 0) - return ret; + snap = __rbd_add_snap_dev(rbd_dev, i - 1, name); + if (IS_ERR(snap)) + return PTR_ERR(snap); list_add(&snap->node, &rbd_dev->snaps); } diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index fd5f3038..fd91964 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2025,15 +2025,21 @@ static int rbd_register_snap_dev(struct rbd_snap *snap, return ret; } -static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, - int i, const char *name, - struct rbd_snap **snapp) +static struct rbd_snap *__rbd_add_snap_dev(struct rbd_device *rbd_dev, + int i, const char *name) { + struct rbd_snap *snap; int ret; - struct rbd_snap *snap = kzalloc(sizeof(*snap), GFP_KERNEL); + + snap = kzalloc(sizeof (*snap), GFP_KERNEL); if (!snap) - return -ENOMEM; + return ERR_PTR(-ENOMEM); + + ret = -ENOMEM; snap->name = kstrdup(name, GFP_KERNEL); + if (!snap->name) + goto err; + snap->size = rbd_dev->header.snap_sizes[i]; snap->id = rbd_dev->header.snapc->snaps[i];