CEPH filesystem development
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 1/7] rbd: have __rbd_add_snap_dev() return a pointer
Date: Thu, 26 Jul 2012 14:08:29 -0500	[thread overview]
Message-ID: <501195AD.8080405@inktank.com> (raw)
In-Reply-To: <50119421.1090702@inktank.com>

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 <elder@inktank.com>
---
 drivers/block/rbd.c |   37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

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];
 	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);
 	}

-- 
1.7.9.5


  reply	other threads:[~2012-07-26 19:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 19:01 [PATCH 0/7] rbd: more miscellaneous refactoring Alex Elder
2012-07-26 19:08 ` Alex Elder [this message]
2012-07-30 20:42   ` [PATCH 1/7] rbd: have __rbd_add_snap_dev() return a pointer Josh Durgin
2012-07-26 19:08 ` [PATCH 2/7] rbd: make rbd_create_rw_ops() " Alex Elder
2012-07-30 20:46   ` Josh Durgin
2012-07-26 19:08 ` [PATCH 3/7] rbd: pass null version pointer in add_snap() Alex Elder
2012-07-30 20:48   ` Josh Durgin
2012-07-26 19:08 ` [PATCH 4/7] rbd: always pass ops array to rbd_req_sync_op() Alex Elder
2012-07-30 20:51   ` Josh Durgin
2012-07-26 19:08 ` [PATCH 5/7] rbd: fixes in rbd_header_from_disk() Alex Elder
2012-07-30 21:23   ` Josh Durgin
2012-07-30 22:45     ` Alex Elder
2012-07-26 19:09 ` [PATCH 6/7] rbd: return obj version in __rbd_refresh_header() Alex Elder
2012-07-30 21:32   ` Josh Durgin
2012-07-26 19:09 ` [PATCH 7/7] rbd: create rbd_refresh_header() Alex Elder
2012-07-30 21:33   ` Josh Durgin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=501195AD.8080405@inktank.com \
    --to=elder@inktank.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox