All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 1/3] rbd: have rbd_get_client() return a rbd_client
Date: Tue, 28 Feb 2012 19:52:56 -0800	[thread overview]
Message-ID: <4F4DA118.3020201@dreamhost.com> (raw)
In-Reply-To: <4F4DA086.7050601@dreamhost.com>

Since rbd_get_client() currently returns an error code.  It assigns
the rbd_client field of the rbd_device structure it is passed if
successful.  Instead, have it return the created rbd_client
structure and return a pointer-coded error if there is an error.
This makes the assignment of the client pointer more obvious at the
call site.

Signed-off-by: Alex Elder <elder@dreamhost.com>
---
  drivers/block/rbd.c |   32 ++++++++++++--------------------
  1 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index e7d6dfc..d5b4500 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -384,17 +384,15 @@ static int parse_rbd_opts_token(char *c, void 
*private)
   * Get a ceph client with specific addr and configuration, if one does
   * not exist create it.
   */
-static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
-			  char *options)
+static struct rbd_client *rbd_get_client(const char *mon_addr, char 
*options)
  {
  	struct rbd_client *rbdc;
  	struct ceph_options *opt;
-	int ret;
  	struct rbd_options *rbd_opts;

  	rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL);
  	if (!rbd_opts)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);

  	rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;

@@ -402,8 +400,8 @@ static int rbd_get_client(struct rbd_device 
*rbd_dev, const char *mon_addr,
  				mon_addr + strlen(mon_addr),
  				parse_rbd_opts_token, rbd_opts);
  	if (IS_ERR(opt)) {
-		ret = PTR_ERR(opt);
-		goto done_err;
+		kfree(rbd_opts);
+		return ERR_CAST(opt);
  	}

  	spin_lock(&rbd_client_list_lock);
@@ -413,27 +411,19 @@ static int rbd_get_client(struct rbd_device 
*rbd_dev, const char *mon_addr,
  		kref_get(&rbdc->kref);
  		spin_unlock(&rbd_client_list_lock);

-		rbd_dev->rbd_client = rbdc;
-
  		ceph_destroy_options(opt);
  		kfree(rbd_opts);

-		return 0;
+		return rbdc;
  	}
  	spin_unlock(&rbd_client_list_lock);

  	rbdc = rbd_client_create(opt, rbd_opts);

-	if (IS_ERR(rbdc)) {
-		ret = PTR_ERR(rbdc);
-		goto done_err;
-	}
+	if (IS_ERR(rbdc))
+		kfree(rbd_opts);

-	rbd_dev->rbd_client = rbdc;
-	return 0;
-done_err:
-	kfree(rbd_opts);
-	return ret;
+	return rbdc;
  }

  /*
@@ -2287,9 +2277,11 @@ static ssize_t rbd_add(struct bus_type *bus,
  	/* initialize rest of new object */
  	snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id);

-	rc = rbd_get_client(rbd_dev, mon_dev_name, options);
-	if (rc < 0)
+	rbd_dev->rbd_client = rbd_get_client(mon_dev_name, options);
+	if (IS_ERR(rbd_dev->rbd_client)) {
+		rc = PTR_ERR(rbd_dev->rbd_client);
  		goto err_put_id;
+	}

  	/* pick the pool */
  	osdc = &rbd_dev->rbd_client->client->osdc;
-- 
1.7.5.4


  reply	other threads:[~2012-02-29  3:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  3:50 [PATCH 0/3] rbd: minor cleanups in rbd_add() Alex Elder
2012-02-29  3:52 ` Alex Elder [this message]
2012-02-29  3:52 ` [PATCH 2/3] rbd: reduce memory used for rbd_dev fields Alex Elder
2012-02-29  3:53 ` [PATCH 3/3] rbd: simplify error handling in rbd_add() Alex Elder
2012-03-02 21:00 ` [PATCH 0/3] rbd: minor cleanups " Sage Weil

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=4F4DA118.3020201@dreamhost.com \
    --to=elder@dreamhost.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.