Commit b7f23c36 authored by Alex Elder's avatar Alex Elder

rbd: encapsulate new rbd id selection

Move the loop that finds a new unique rbd id to use into
its own helper function.
Signed-off-by: default avatarAlex Elder <elder@dreamhost.com>
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent cc9d734c
...@@ -2149,6 +2149,23 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev) ...@@ -2149,6 +2149,23 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev)
return ret; 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, static ssize_t rbd_add(struct bus_type *bus,
const char *buf, const char *buf,
size_t count) size_t count)
...@@ -2156,8 +2173,7 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2156,8 +2173,7 @@ static ssize_t rbd_add(struct bus_type *bus,
struct ceph_osd_client *osdc; struct ceph_osd_client *osdc;
struct rbd_device *rbd_dev; struct rbd_device *rbd_dev;
ssize_t rc = -ENOMEM; ssize_t rc = -ENOMEM;
int irc, new_id = 0; int irc;
struct list_head *tmp;
char *mon_dev_name; char *mon_dev_name;
char *options; char *options;
...@@ -2187,15 +2203,7 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2187,15 +2203,7 @@ static ssize_t rbd_add(struct bus_type *bus,
/* generate unique id: find highest unique id, add one */ /* generate unique id: find highest unique id, add one */
mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
list_for_each(tmp, &rbd_dev_list) { rbd_dev->id = rbd_id_get();
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;
/* add to global list */ /* add to global list */
list_add_tail(&rbd_dev->node, &rbd_dev_list); list_add_tail(&rbd_dev->node, &rbd_dev_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment