diff options
author | Alex Elder <elder@dreamhost.com> | 2012-01-29 14:57:43 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:47 -0400 |
commit | b7f23c361b65a0bdcc81acd8d38471b7810df3ff (patch) | |
tree | 6ff42f4ebe263453ba14d61d6b0cf56c98d22e42 /drivers/block/rbd.c | |
parent | cc9d734c3d1b39c6a557673469aea26364060226 (diff) |
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: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r-- | 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 d8d052d42258..aaa19d8c3670 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -2149,6 +2149,23 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev) | |||
2149 | return ret; | 2149 | return ret; |
2150 | } | 2150 | } |
2151 | 2151 | ||
2152 | /* caller must hold ctl_mutex */ | ||
2153 | static int rbd_id_get(void) | ||
2154 | { | ||
2155 | struct list_head *tmp; | ||
2156 | int new_id = 0; | ||
2157 | |||
2158 | list_for_each(tmp, &rbd_dev_list) { | ||
2159 | struct rbd_device *rbd_dev; | ||
2160 | |||
2161 | rbd_dev = list_entry(tmp, struct rbd_device, node); | ||
2162 | if (rbd_dev->id >= new_id) | ||
2163 | new_id = rbd_dev->id + 1; | ||
2164 | } | ||
2165 | |||
2166 | return new_id; | ||
2167 | } | ||
2168 | |||
2152 | static ssize_t rbd_add(struct bus_type *bus, | 2169 | static ssize_t rbd_add(struct bus_type *bus, |
2153 | const char *buf, | 2170 | const char *buf, |
2154 | size_t count) | 2171 | size_t count) |
@@ -2156,8 +2173,7 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2156 | struct ceph_osd_client *osdc; | 2173 | struct ceph_osd_client *osdc; |
2157 | struct rbd_device *rbd_dev; | 2174 | struct rbd_device *rbd_dev; |
2158 | ssize_t rc = -ENOMEM; | 2175 | ssize_t rc = -ENOMEM; |
2159 | int irc, new_id = 0; | 2176 | int irc; |
2160 | struct list_head *tmp; | ||
2161 | char *mon_dev_name; | 2177 | char *mon_dev_name; |
2162 | char *options; | 2178 | char *options; |
2163 | 2179 | ||
@@ -2187,15 +2203,7 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2187 | /* generate unique id: find highest unique id, add one */ | 2203 | /* generate unique id: find highest unique id, add one */ |
2188 | mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); | 2204 | mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); |
2189 | 2205 | ||
2190 | list_for_each(tmp, &rbd_dev_list) { | 2206 | rbd_dev->id = rbd_id_get(); |
2191 | struct rbd_device *rbd_dev; | ||
2192 | |||
2193 | rbd_dev = list_entry(tmp, struct rbd_device, node); | ||
2194 | if (rbd_dev->id >= new_id) | ||
2195 | new_id = rbd_dev->id + 1; | ||
2196 | } | ||
2197 | |||
2198 | rbd_dev->id = new_id; | ||
2199 | 2207 | ||
2200 | /* add to global list */ | 2208 | /* add to global list */ |
2201 | list_add_tail(&rbd_dev->node, &rbd_dev_list); | 2209 | list_add_tail(&rbd_dev->node, &rbd_dev_list); |