Commit 85ae8926 authored by Alex Elder's avatar Alex Elder

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: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 05fd6f6f
...@@ -2554,10 +2554,10 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2554,10 +2554,10 @@ static ssize_t rbd_add(struct bus_type *bus,
options = kmalloc(count, GFP_KERNEL); options = kmalloc(count, GFP_KERNEL);
if (!options) if (!options)
goto err_nomem; goto err_out_mem;
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
if (!rbd_dev) if (!rbd_dev)
goto err_nomem; goto err_out_mem;
/* static rbd_device initialization */ /* static rbd_device initialization */
spin_lock_init(&rbd_dev->lock); spin_lock_init(&rbd_dev->lock);
...@@ -2565,25 +2565,17 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2565,25 +2565,17 @@ static ssize_t rbd_add(struct bus_type *bus,
INIT_LIST_HEAD(&rbd_dev->snaps); INIT_LIST_HEAD(&rbd_dev->snaps);
init_rwsem(&rbd_dev->header_rwsem); init_rwsem(&rbd_dev->header_rwsem);
/* generate unique id: find highest unique id, add one */
rbd_dev_id_get(rbd_dev);
/* Fill in the device name, now that we have its id. */
BUILD_BUG_ON(DEV_NAME_LEN
< sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
/* parse add command */ /* parse add command */
snap_name = rbd_add_parse_args(rbd_dev, buf, snap_name = rbd_add_parse_args(rbd_dev, buf,
&mon_addrs, &mon_addrs_size, options, count); &mon_addrs, &mon_addrs_size, options, count);
if (IS_ERR(snap_name)) { if (IS_ERR(snap_name)) {
rc = PTR_ERR(snap_name); rc = PTR_ERR(snap_name);
goto err_put_id; goto err_out_mem;
} }
rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options); rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options);
if (rc < 0) if (rc < 0)
goto err_put_id; goto err_out_args;
/* pick the pool */ /* pick the pool */
osdc = &rbd_dev->rbd_client->client->osdc; osdc = &rbd_dev->rbd_client->client->osdc;
...@@ -2616,10 +2608,19 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2616,10 +2608,19 @@ static ssize_t rbd_add(struct bus_type *bus,
if (rc) if (rc)
goto err_out_header; goto err_out_header;
/* register our block device */ /* generate unique id: find highest unique id, add one */
rbd_dev_id_get(rbd_dev);
/* Fill in the device name, now that we have its id. */
BUILD_BUG_ON(DEV_NAME_LEN
< sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->dev_id);
/* Get our block major device number. */
rc = register_blkdev(0, rbd_dev->name); rc = register_blkdev(0, rbd_dev->name);
if (rc < 0) if (rc < 0)
goto err_out_header; goto err_out_id;
rbd_dev->major = rc; rbd_dev->major = rc;
rc = rbd_bus_add_dev(rbd_dev); rc = rbd_bus_add_dev(rbd_dev);
...@@ -2665,19 +2666,18 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2665,19 +2666,18 @@ static ssize_t rbd_add(struct bus_type *bus,
err_out_blkdev: err_out_blkdev:
unregister_blkdev(rbd_dev->major, rbd_dev->name); unregister_blkdev(rbd_dev->major, rbd_dev->name);
err_out_id:
rbd_dev_id_put(rbd_dev);
err_out_header: err_out_header:
rbd_header_free(&rbd_dev->header); rbd_header_free(&rbd_dev->header);
err_out_client: err_out_client:
kfree(rbd_dev->header_name); kfree(rbd_dev->header_name);
rbd_put_client(rbd_dev); rbd_put_client(rbd_dev);
err_put_id: err_out_args:
if (rbd_dev->pool_name) { kfree(rbd_dev->mapping.snap_name);
kfree(rbd_dev->mapping.snap_name); kfree(rbd_dev->image_name);
kfree(rbd_dev->image_name); kfree(rbd_dev->pool_name);
kfree(rbd_dev->pool_name); err_out_mem:
}
rbd_dev_id_put(rbd_dev);
err_nomem:
kfree(rbd_dev); kfree(rbd_dev);
kfree(options); kfree(options);
......
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