diff mbox

[5/9] rbd: defer setting device id

Message ID 504A167D.7000405@inktank.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Elder Sept. 7, 2012, 3:45 p.m. UTC
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>
---
 drivers/block/rbd.c |   44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

Comments

Josh Durgin Sept. 11, 2012, 3:03 p.m. UTC | #1
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

On 09/07/2012 08:45 AM, Alex Elder wrote:
> 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>
> ---
>   drivers/block/rbd.c |   44 ++++++++++++++++++++++----------------------
>   1 file changed, 22 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 89d8ed7..53e5308 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -2549,10 +2549,10 @@ static ssize_t rbd_add(struct bus_type *bus,
>
>   	options = kmalloc(count, GFP_KERNEL);
>   	if (!options)
> -		goto err_nomem;
> +		goto err_out_mem;
>   	rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
>   	if (!rbd_dev)
> -		goto err_nomem;
> +		goto err_out_mem;
>
>   	/* static rbd_device initialization */
>   	spin_lock_init(&rbd_dev->lock);
> @@ -2562,25 +2562,17 @@ static ssize_t rbd_add(struct bus_type *bus,
>
>   	down_write(&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 */
>   	snap_name = rbd_add_parse_args(rbd_dev, buf,
>   				&mon_addrs, &mon_addrs_size, options, count);
>   	if (IS_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);
>   	if (rc < 0)
> -		goto err_put_id;
> +		goto err_out_args;
>
>   	/* pick the pool */
>   	osdc = &rbd_dev->rbd_client->client->osdc;
> @@ -2612,10 +2604,19 @@ static ssize_t rbd_add(struct bus_type *bus,
>   	if (rc)
>   		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);
>   	if (rc < 0)
> -		goto err_out_header;
> +		goto err_out_id;
>   	rbd_dev->major = rc;
>
>   	rc = rbd_bus_add_dev(rbd_dev);
> @@ -2663,20 +2664,19 @@ err_out_bus:
>
>   err_out_blkdev:
>   	unregister_blkdev(rbd_dev->major, rbd_dev->name);
> +err_out_id:
> +	rbd_dev_id_put(rbd_dev);
>   err_out_header:
>   	rbd_header_free(&rbd_dev->header);
>   err_out_client:
>   	kfree(rbd_dev->header_name);
>   	rbd_put_client(rbd_dev);
> -err_put_id:
> -	if (rbd_dev->pool_name) {
> -		kfree(rbd_dev->mapping.snap_name);
> -		kfree(rbd_dev->image_name);
> -		kfree(rbd_dev->pool_name);
> -	}
> -	rbd_dev_id_put(rbd_dev);
> +err_out_args:
> +	kfree(rbd_dev->mapping.snap_name);
> +	kfree(rbd_dev->image_name);
> +	kfree(rbd_dev->pool_name);
>   	up_write(&rbd_dev->header_rwsem);
> -err_nomem:
> +err_out_mem:
>   	kfree(rbd_dev);
>   	kfree(options);
>

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 89d8ed7..53e5308 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2549,10 +2549,10 @@  static ssize_t rbd_add(struct bus_type *bus,

 	options = kmalloc(count, GFP_KERNEL);
 	if (!options)
-		goto err_nomem;
+		goto err_out_mem;
 	rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
 	if (!rbd_dev)
-		goto err_nomem;
+		goto err_out_mem;

 	/* static rbd_device initialization */
 	spin_lock_init(&rbd_dev->lock);
@@ -2562,25 +2562,17 @@  static ssize_t rbd_add(struct bus_type *bus,

 	down_write(&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 */
 	snap_name = rbd_add_parse_args(rbd_dev, buf,
 				&mon_addrs, &mon_addrs_size, options, count);
 	if (IS_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);
 	if (rc < 0)
-		goto err_put_id;
+		goto err_out_args;

 	/* pick the pool */
 	osdc = &rbd_dev->rbd_client->client->osdc;
@@ -2612,10 +2604,19 @@  static ssize_t rbd_add(struct bus_type *bus,
 	if (rc)
 		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);
 	if (rc < 0)
-		goto err_out_header;
+		goto err_out_id;
 	rbd_dev->major = rc;

 	rc = rbd_bus_add_dev(rbd_dev);
@@ -2663,20 +2664,19 @@  err_out_bus:

 err_out_blkdev:
 	unregister_blkdev(rbd_dev->major, rbd_dev->name);
+err_out_id:
+	rbd_dev_id_put(rbd_dev);
 err_out_header:
 	rbd_header_free(&rbd_dev->header);
 err_out_client:
 	kfree(rbd_dev->header_name);
 	rbd_put_client(rbd_dev);
-err_put_id:
-	if (rbd_dev->pool_name) {
-		kfree(rbd_dev->mapping.snap_name);
-		kfree(rbd_dev->image_name);
-		kfree(rbd_dev->pool_name);
-	}
-	rbd_dev_id_put(rbd_dev);
+err_out_args:
+	kfree(rbd_dev->mapping.snap_name);
+	kfree(rbd_dev->image_name);
+	kfree(rbd_dev->pool_name);
 	up_write(&rbd_dev->header_rwsem);
-err_nomem:
+err_out_mem:
 	kfree(rbd_dev);
 	kfree(options);