aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-10-30 16:47:17 -0400
committerAlex Elder <elder@inktank.com>2012-11-01 08:55:42 -0400
commit83a06263625b823afa3a842ddbf53473c22f24b2 (patch)
tree127904c100783d47866191a761b4a2c436011369 /drivers/block/rbd.c
parentc53d589337e9a211413484a604c76072e8474dc0 (diff)
rbd: encapsulate last part of probe
Group the activities that now take place after an rbd_dev_probe() call into a single function, and move the call to that function into rbd_dev_probe() itself. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c161
1 files changed, 86 insertions, 75 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a8ad8f8370b6..8d26c0f2be14 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3221,6 +3221,84 @@ out_err:
3221 return ret; 3221 return ret;
3222} 3222}
3223 3223
3224static int rbd_dev_probe_finish(struct rbd_device *rbd_dev)
3225{
3226 int ret;
3227
3228 /* no need to lock here, as rbd_dev is not registered yet */
3229 ret = rbd_dev_snaps_update(rbd_dev);
3230 if (ret)
3231 return ret;
3232
3233 ret = rbd_dev_set_mapping(rbd_dev);
3234 if (ret)
3235 goto err_out_snaps;
3236
3237 /* generate unique id: find highest unique id, add one */
3238 rbd_dev_id_get(rbd_dev);
3239
3240 /* Fill in the device name, now that we have its id. */
3241 BUILD_BUG_ON(DEV_NAME_LEN
3242 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
3243 sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
3244
3245 /* Get our block major device number. */
3246
3247 ret = register_blkdev(0, rbd_dev->name);
3248 if (ret < 0)
3249 goto err_out_id;
3250 rbd_dev->major = ret;
3251
3252 /* Set up the blkdev mapping. */
3253
3254 ret = rbd_init_disk(rbd_dev);
3255 if (ret)
3256 goto err_out_blkdev;
3257
3258 ret = rbd_bus_add_dev(rbd_dev);
3259 if (ret)
3260 goto err_out_disk;
3261
3262 /*
3263 * At this point cleanup in the event of an error is the job
3264 * of the sysfs code (initiated by rbd_bus_del_dev()).
3265 */
3266 down_write(&rbd_dev->header_rwsem);
3267 ret = rbd_dev_snaps_register(rbd_dev);
3268 up_write(&rbd_dev->header_rwsem);
3269 if (ret)
3270 goto err_out_bus;
3271
3272 ret = rbd_init_watch_dev(rbd_dev);
3273 if (ret)
3274 goto err_out_bus;
3275
3276 /* Everything's ready. Announce the disk to the world. */
3277
3278 add_disk(rbd_dev->disk);
3279
3280 pr_info("%s: added with size 0x%llx\n", rbd_dev->disk->disk_name,
3281 (unsigned long long) rbd_dev->mapping.size);
3282
3283 return ret;
3284err_out_bus:
3285 /* this will also clean up rest of rbd_dev stuff */
3286
3287 rbd_bus_del_dev(rbd_dev);
3288
3289 return ret;
3290err_out_disk:
3291 rbd_free_disk(rbd_dev);
3292err_out_blkdev:
3293 unregister_blkdev(rbd_dev->major, rbd_dev->name);
3294err_out_id:
3295 rbd_dev_id_put(rbd_dev);
3296err_out_snaps:
3297 rbd_remove_all_snaps(rbd_dev);
3298
3299 return ret;
3300}
3301
3224/* 3302/*
3225 * Probe for the existence of the header object for the given rbd 3303 * Probe for the existence of the header object for the given rbd
3226 * device. For format 2 images this includes determining the image 3304 * device. For format 2 images this includes determining the image
@@ -3240,9 +3318,16 @@ static int rbd_dev_probe(struct rbd_device *rbd_dev)
3240 ret = rbd_dev_v1_probe(rbd_dev); 3318 ret = rbd_dev_v1_probe(rbd_dev);
3241 else 3319 else
3242 ret = rbd_dev_v2_probe(rbd_dev); 3320 ret = rbd_dev_v2_probe(rbd_dev);
3243 if (ret) 3321 if (ret) {
3244 dout("probe failed, returning %d\n", ret); 3322 dout("probe failed, returning %d\n", ret);
3245 3323
3324 return ret;
3325 }
3326
3327 ret = rbd_dev_probe_finish(rbd_dev);
3328 if (ret)
3329 rbd_header_free(&rbd_dev->header);
3330
3246 return ret; 3331 return ret;
3247} 3332}
3248 3333
@@ -3294,81 +3379,7 @@ static ssize_t rbd_add(struct bus_type *bus,
3294 if (rc < 0) 3379 if (rc < 0)
3295 goto err_out_rbd_dev; 3380 goto err_out_rbd_dev;
3296 3381
3297 /* no need to lock here, as rbd_dev is not registered yet */
3298 rc = rbd_dev_snaps_update(rbd_dev);
3299 if (rc)
3300 goto err_out_probe;
3301
3302 rc = rbd_dev_set_mapping(rbd_dev);
3303 if (rc)
3304 goto err_out_snaps;
3305
3306 /* generate unique id: find highest unique id, add one */
3307 rbd_dev_id_get(rbd_dev);
3308
3309 /* Fill in the device name, now that we have its id. */
3310 BUILD_BUG_ON(DEV_NAME_LEN
3311 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
3312 sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
3313
3314 /* Get our block major device number. */
3315
3316 rc = register_blkdev(0, rbd_dev->name);
3317 if (rc < 0)
3318 goto err_out_id;
3319 rbd_dev->major = rc;
3320
3321 /* Set up the blkdev mapping. */
3322
3323 rc = rbd_init_disk(rbd_dev);
3324 if (rc)
3325 goto err_out_blkdev;
3326
3327 rc = rbd_bus_add_dev(rbd_dev);
3328 if (rc)
3329 goto err_out_disk;
3330
3331 /*
3332 * At this point cleanup in the event of an error is the job
3333 * of the sysfs code (initiated by rbd_bus_del_dev()).
3334 */
3335
3336 down_write(&rbd_dev->header_rwsem);
3337 rc = rbd_dev_snaps_register(rbd_dev);
3338 up_write(&rbd_dev->header_rwsem);
3339 if (rc)
3340 goto err_out_bus;
3341
3342 rc = rbd_init_watch_dev(rbd_dev);
3343 if (rc)
3344 goto err_out_bus;
3345
3346 /* Everything's ready. Announce the disk to the world. */
3347
3348 add_disk(rbd_dev->disk);
3349
3350 pr_info("%s: added with size 0x%llx\n", rbd_dev->disk->disk_name,
3351 (unsigned long long) rbd_dev->mapping.size);
3352
3353 return count; 3382 return count;
3354
3355err_out_bus:
3356 /* this will also clean up rest of rbd_dev stuff */
3357
3358 rbd_bus_del_dev(rbd_dev);
3359
3360 return rc;
3361
3362err_out_disk:
3363 rbd_free_disk(rbd_dev);
3364err_out_blkdev:
3365 unregister_blkdev(rbd_dev->major, rbd_dev->name);
3366err_out_id:
3367 rbd_dev_id_put(rbd_dev);
3368err_out_snaps:
3369 rbd_remove_all_snaps(rbd_dev);
3370err_out_probe:
3371 rbd_header_free(&rbd_dev->header);
3372err_out_rbd_dev: 3383err_out_rbd_dev:
3373 rbd_dev_destroy(rbd_dev); 3384 rbd_dev_destroy(rbd_dev);
3374err_out_client: 3385err_out_client: