All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/5] rbd: encapsulate new rbd id selection
Date: Tue, 28 Feb 2012 19:40:07 -0800	[thread overview]
Message-ID: <4F4D9E17.6000302@dreamhost.com> (raw)
In-Reply-To: <4F4D9DA5.8050101@dreamhost.com>

Move the loop that finds a new unique rbd id to use into
its own helper function.

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

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 25ed3c0..35290b1 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2148,6 +2148,23 @@ static int rbd_init_watch_dev(struct rbd_device 
*rbd_dev)
  	return ret;
  }

+/* caller must hold ctl_mutex */
+static int rbd_id_get(void)
+{
+	struct list_head *tmp;
+	int new_id = 0;
+
+	list_for_each(tmp, &rbd_dev_list) {
+		struct rbd_device *rbd_dev;
+
+		rbd_dev = list_entry(tmp, struct rbd_device, node);
+		if (rbd_dev->id >= new_id)
+			new_id = rbd_dev->id + 1;
+	}
+
+	return new_id;
+}
+
  static ssize_t rbd_add(struct bus_type *bus,
  		       const char *buf,
  		       size_t count)
@@ -2155,8 +2172,7 @@ static ssize_t rbd_add(struct bus_type *bus,
  	struct ceph_osd_client *osdc;
  	struct rbd_device *rbd_dev;
  	ssize_t rc = -ENOMEM;
-	int irc, new_id = 0;
-	struct list_head *tmp;
+	int irc;
  	char *mon_dev_name;
  	char *options;

@@ -2184,15 +2200,7 @@ static ssize_t rbd_add(struct bus_type *bus,
  	/* generate unique id: find highest unique id, add one */
  	mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);

-	list_for_each(tmp, &rbd_dev_list) {
-		struct rbd_device *rbd_dev;
-
-		rbd_dev = list_entry(tmp, struct rbd_device, node);
-		if (rbd_dev->id >= new_id)
-			new_id = rbd_dev->id + 1;
-	}
-
-	rbd_dev->id = new_id;
+	rbd_dev->id = rbd_id_get();

  	/* add to global list */
  	list_add_tail(&rbd_dev->node, &rbd_dev_list);
-- 
1.7.5.4


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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  3:38 [PATCH 0/5] rbd: improve how rbd ids are selected Alex Elder
2012-02-29  3:40 ` Alex Elder [this message]
2012-02-29  3:40 ` [PATCH 2/5] rbd: rework calculation of new rbd id's Alex Elder
2012-02-29 20:37   ` Yehuda Sadeh Weinraub
2012-02-29  3:40 ` [PATCH 3/5] rbd: protect the rbd_dev_list with a spinlock Alex Elder
2012-02-29  3:40 ` [PATCH 4/5] rbd: tie rbd_dev_list changes to rbd_id operations Alex Elder
2012-02-29  3:40 ` [PATCH 5/5] rbd: restore previous rbd id sequence behavior Alex Elder
2012-02-29 20:53   ` Yehuda Sadeh Weinraub
2012-02-29 21:27     ` Alex Elder
2012-03-02 19:54 ` [PATCH 0/5] rbd: improve how rbd ids are selected 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=4F4D9E17.6000302@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.