aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-10-26 00:34:42 -0400
committerAlex Elder <elder@inktank.com>2012-11-01 08:55:42 -0400
commitbd4ba6554dcbae652b8b27a44f5a7795c9f3178a (patch)
tree18080b60df8735e40ec5e5e8ec30461377eaa162 /drivers/block
parent9d3997fdf4c82adfb37a4886a21eaa513ee071b6 (diff)
rbd: consolidate rbd_dev init in rbd_add()
Group the allocation and initialization of fields of the rbd device structure created in rbd_add(). Move the grouped code down later in the function, just prior to the call to rbd_dev_probe(). This is for the most part simple code movement. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/rbd.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a528d4ca7a67..4771de2fba8a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3232,29 +3232,16 @@ static ssize_t rbd_add(struct bus_type *bus,
3232 if (!try_module_get(THIS_MODULE)) 3232 if (!try_module_get(THIS_MODULE))
3233 return -ENODEV; 3233 return -ENODEV;
3234 3234
3235 rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
3236 if (!rbd_dev)
3237 return -ENOMEM;
3238
3239 /* static rbd_device initialization */
3240 spin_lock_init(&rbd_dev->lock);
3241 INIT_LIST_HEAD(&rbd_dev->node);
3242 INIT_LIST_HEAD(&rbd_dev->snaps);
3243 init_rwsem(&rbd_dev->header_rwsem);
3244
3245 /* parse add command */ 3235 /* parse add command */
3246 rc = rbd_add_parse_args(buf, &ceph_opts, &rbd_opts, &spec); 3236 rc = rbd_add_parse_args(buf, &ceph_opts, &rbd_opts, &spec);
3247 if (rc < 0) 3237 if (rc < 0)
3248 goto err_out_mem; 3238 goto err_out_module;
3249
3250 rbd_dev->mapping.read_only = rbd_opts->read_only;
3251 3239
3252 rbdc = rbd_get_client(ceph_opts); 3240 rbdc = rbd_get_client(ceph_opts);
3253 if (IS_ERR(rbdc)) { 3241 if (IS_ERR(rbdc)) {
3254 rc = PTR_ERR(rbdc); 3242 rc = PTR_ERR(rbdc);
3255 goto err_out_args; 3243 goto err_out_args;
3256 } 3244 }
3257 rbd_dev->rbd_client = rbdc;
3258 ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */ 3245 ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */
3259 3246
3260 /* pick the pool */ 3247 /* pick the pool */
@@ -3264,11 +3251,22 @@ static ssize_t rbd_add(struct bus_type *bus,
3264 goto err_out_client; 3251 goto err_out_client;
3265 spec->pool_id = (u64) rc; 3252 spec->pool_id = (u64) rc;
3266 3253
3254 rbd_dev = kzalloc(sizeof (*rbd_dev), GFP_KERNEL);
3255 if (!rbd_dev)
3256 goto err_out_client;
3257
3258 spin_lock_init(&rbd_dev->lock);
3259 INIT_LIST_HEAD(&rbd_dev->node);
3260 INIT_LIST_HEAD(&rbd_dev->snaps);
3261 init_rwsem(&rbd_dev->header_rwsem);
3262 rbd_dev->rbd_client = rbdc;
3267 rbd_dev->spec = spec; 3263 rbd_dev->spec = spec;
3268 3264
3265 rbd_dev->mapping.read_only = rbd_opts->read_only;
3266
3269 rc = rbd_dev_probe(rbd_dev); 3267 rc = rbd_dev_probe(rbd_dev);
3270 if (rc < 0) 3268 if (rc < 0)
3271 goto err_out_client; 3269 goto err_out_mem;
3272 3270
3273 /* no need to lock here, as rbd_dev is not registered yet */ 3271 /* no need to lock here, as rbd_dev is not registered yet */
3274 rc = rbd_dev_snaps_update(rbd_dev); 3272 rc = rbd_dev_snaps_update(rbd_dev);
@@ -3348,19 +3346,20 @@ err_out_snaps:
3348 rbd_remove_all_snaps(rbd_dev); 3346 rbd_remove_all_snaps(rbd_dev);
3349err_out_probe: 3347err_out_probe:
3350 rbd_header_free(&rbd_dev->header); 3348 rbd_header_free(&rbd_dev->header);
3351err_out_client:
3352 kfree(rbd_dev->header_name); 3349 kfree(rbd_dev->header_name);
3350err_out_mem:
3351 kfree(rbd_dev);
3352err_out_client:
3353 rbd_put_client(rbdc); 3353 rbd_put_client(rbdc);
3354err_out_args: 3354err_out_args:
3355 if (ceph_opts) 3355 if (ceph_opts)
3356 ceph_destroy_options(ceph_opts); 3356 ceph_destroy_options(ceph_opts);
3357 kfree(rbd_opts); 3357 kfree(rbd_opts);
3358 rbd_spec_put(spec); 3358 rbd_spec_put(spec);
3359err_out_mem: 3359err_out_module:
3360 kfree(rbd_dev); 3360 module_put(THIS_MODULE);
3361 3361
3362 dout("Error adding device %s\n", buf); 3362 dout("Error adding device %s\n", buf);
3363 module_put(THIS_MODULE);
3364 3363
3365 return (ssize_t) rc; 3364 return (ssize_t) rc;
3366} 3365}