aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-27 00:37:14 -0400
committerAlex Elder <elder@inktank.com>2012-10-01 15:30:52 -0400
commit85ae8926751db5e09b9a12ee44609ee9e74b7aad (patch)
treec25795bfa1c0d0fe08a950a2a6f79cb4ed9ab29f /drivers/block
parent05fd6f6f8c7b07e746d513e4cf862675b70aac59 (diff)
rbd: defer setting device id
Hold off setting the device id and formatting the device name in rbd_add() until just before it's needed. 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.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index aa4752d9d9fa..7a600ca2dbcf 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2554,10 +2554,10 @@ static ssize_t rbd_add(struct bus_type *bus,
2554 2554
2555 options = kmalloc(count, GFP_KERNEL); 2555 options = kmalloc(count, GFP_KERNEL);
2556 if (!options) 2556 if (!options)
2557 goto err_nomem; 2557 goto err_out_mem;
2558 rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); 2558 rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
2559 if (!rbd_dev) 2559 if (!rbd_dev)
2560 goto err_nomem; 2560 goto err_out_mem;
2561 2561
2562 /* static rbd_device initialization */ 2562 /* static rbd_device initialization */
2563 spin_lock_init(&rbd_dev->lock); 2563 spin_lock_init(&rbd_dev->lock);
@@ -2565,25 +2565,17 @@ static ssize_t rbd_add(struct bus_type *bus,
2565 INIT_LIST_HEAD(&rbd_dev->snaps); 2565 INIT_LIST_HEAD(&rbd_dev->snaps);
2566 init_rwsem(&rbd_dev->header_rwsem); 2566 init_rwsem(&rbd_dev->header_rwsem);
2567 2567
2568 /* generate unique id: find highest unique id, add one */
2569 rbd_dev_id_get(rbd_dev);
2570
2571 /* Fill in the device name, now that we have its id. */
2572 BUILD_BUG_ON(DEV_NAME_LEN
2573 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
2574 sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
2575
2576 /* parse add command */ 2568 /* parse add command */
2577 snap_name = rbd_add_parse_args(rbd_dev, buf, 2569 snap_name = rbd_add_parse_args(rbd_dev, buf,
2578 &mon_addrs, &mon_addrs_size, options, count); 2570 &mon_addrs, &mon_addrs_size, options, count);
2579 if (IS_ERR(snap_name)) { 2571 if (IS_ERR(snap_name)) {
2580 rc = PTR_ERR(snap_name); 2572 rc = PTR_ERR(snap_name);
2581 goto err_put_id; 2573 goto err_out_mem;
2582 } 2574 }
2583 2575
2584 rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options); 2576 rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options);
2585 if (rc < 0) 2577 if (rc < 0)
2586 goto err_put_id; 2578 goto err_out_args;
2587 2579
2588 /* pick the pool */ 2580 /* pick the pool */
2589 osdc = &rbd_dev->rbd_client->client->osdc; 2581 osdc = &rbd_dev->rbd_client->client->osdc;
@@ -2616,10 +2608,19 @@ static ssize_t rbd_add(struct bus_type *bus,
2616 if (rc) 2608 if (rc)
2617 goto err_out_header; 2609 goto err_out_header;
2618 2610
2619 /* register our block device */ 2611 /* generate unique id: find highest unique id, add one */
2612 rbd_dev_id_get(rbd_dev);
2613
2614 /* Fill in the device name, now that we have its id. */
2615 BUILD_BUG_ON(DEV_NAME_LEN
2616 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
2617 sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
2618
2619 /* Get our block major device number. */
2620
2620 rc = register_blkdev(0, rbd_dev->name); 2621 rc = register_blkdev(0, rbd_dev->name);
2621 if (rc < 0) 2622 if (rc < 0)
2622 goto err_out_header; 2623 goto err_out_id;
2623 rbd_dev->major = rc; 2624 rbd_dev->major = rc;
2624 2625
2625 rc = rbd_bus_add_dev(rbd_dev); 2626 rc = rbd_bus_add_dev(rbd_dev);
@@ -2665,19 +2666,18 @@ err_out_bus:
2665 2666
2666err_out_blkdev: 2667err_out_blkdev:
2667 unregister_blkdev(rbd_dev->major, rbd_dev->name); 2668 unregister_blkdev(rbd_dev->major, rbd_dev->name);
2669err_out_id:
2670 rbd_dev_id_put(rbd_dev);
2668err_out_header: 2671err_out_header:
2669 rbd_header_free(&rbd_dev->header); 2672 rbd_header_free(&rbd_dev->header);
2670err_out_client: 2673err_out_client:
2671 kfree(rbd_dev->header_name); 2674 kfree(rbd_dev->header_name);
2672 rbd_put_client(rbd_dev); 2675 rbd_put_client(rbd_dev);
2673err_put_id: 2676err_out_args:
2674 if (rbd_dev->pool_name) { 2677 kfree(rbd_dev->mapping.snap_name);
2675 kfree(rbd_dev->mapping.snap_name); 2678 kfree(rbd_dev->image_name);
2676 kfree(rbd_dev->image_name); 2679 kfree(rbd_dev->pool_name);
2677 kfree(rbd_dev->pool_name); 2680err_out_mem:
2678 }
2679 rbd_dev_id_put(rbd_dev);
2680err_nomem:
2681 kfree(rbd_dev); 2681 kfree(rbd_dev);
2682 kfree(options); 2682 kfree(options);
2683 2683