Commit 05fd6f6f authored by Alex Elder's avatar Alex Elder

rbd: read the header before registering device

Read the rbd header information and call rbd_dev_set_mapping()
earlier--before registering the block device or setting up the sysfs
entries for the image.  The sysfs entries provide users access to
some information that's only available after doing the rbd header
initialization, so this will make sure it's valid right away.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 5ed16177
...@@ -2601,10 +2601,25 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2601,10 +2601,25 @@ static ssize_t rbd_add(struct bus_type *bus,
goto err_out_client; goto err_out_client;
sprintf(rbd_dev->header_name, "%s%s", rbd_dev->image_name, RBD_SUFFIX); sprintf(rbd_dev->header_name, "%s%s", rbd_dev->image_name, RBD_SUFFIX);
/* Get information about the image being mapped */
rc = rbd_read_header(rbd_dev, &rbd_dev->header);
if (rc)
goto err_out_client;
/* no need to lock here, as rbd_dev is not registered yet */
rc = rbd_dev_snaps_update(rbd_dev);
if (rc)
goto err_out_header;
rc = rbd_dev_set_mapping(rbd_dev, snap_name);
if (rc)
goto err_out_header;
/* register our block device */ /* register our block device */
rc = register_blkdev(0, rbd_dev->name); rc = register_blkdev(0, rbd_dev->name);
if (rc < 0) if (rc < 0)
goto err_out_client; goto err_out_header;
rbd_dev->major = rc; rbd_dev->major = rc;
rc = rbd_bus_add_dev(rbd_dev); rc = rbd_bus_add_dev(rbd_dev);
...@@ -2616,20 +2631,6 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2616,20 +2631,6 @@ static ssize_t rbd_add(struct bus_type *bus,
* of the sysfs code (initiated by rbd_bus_del_dev()). * of the sysfs code (initiated by rbd_bus_del_dev()).
*/ */
/* contact OSD, request size info about the object being mapped */
rc = rbd_read_header(rbd_dev, &rbd_dev->header);
if (rc)
goto err_out_bus;
/* no need to lock here, as rbd_dev is not registered yet */
rc = rbd_dev_snaps_update(rbd_dev);
if (rc)
goto err_out_bus;
rc = rbd_dev_set_mapping(rbd_dev, snap_name);
if (rc)
goto err_out_bus;
down_write(&rbd_dev->header_rwsem); down_write(&rbd_dev->header_rwsem);
rc = rbd_dev_snaps_register(rbd_dev); rc = rbd_dev_snaps_register(rbd_dev);
up_write(&rbd_dev->header_rwsem); up_write(&rbd_dev->header_rwsem);
...@@ -2664,6 +2665,8 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2664,6 +2665,8 @@ 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_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);
......
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