diff options
author | Alex Elder <elder@inktank.com> | 2012-08-29 18:11:07 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-01 15:30:52 -0400 |
commit | 05fd6f6f8c7b07e746d513e4cf862675b70aac59 (patch) | |
tree | 330b959abad9744b2c377daf803efd274973df1e | |
parent | 5ed1617731a1e9201c3541a9c05ce3ec73975589 (diff) |
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: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | drivers/block/rbd.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a9f5de2706ec..aa4752d9d9fa 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -2601,10 +2601,25 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2601 | goto err_out_client; | 2601 | goto err_out_client; |
2602 | sprintf(rbd_dev->header_name, "%s%s", rbd_dev->image_name, RBD_SUFFIX); | 2602 | sprintf(rbd_dev->header_name, "%s%s", rbd_dev->image_name, RBD_SUFFIX); |
2603 | 2603 | ||
2604 | /* Get information about the image being mapped */ | ||
2605 | |||
2606 | rc = rbd_read_header(rbd_dev, &rbd_dev->header); | ||
2607 | if (rc) | ||
2608 | goto err_out_client; | ||
2609 | |||
2610 | /* no need to lock here, as rbd_dev is not registered yet */ | ||
2611 | rc = rbd_dev_snaps_update(rbd_dev); | ||
2612 | if (rc) | ||
2613 | goto err_out_header; | ||
2614 | |||
2615 | rc = rbd_dev_set_mapping(rbd_dev, snap_name); | ||
2616 | if (rc) | ||
2617 | goto err_out_header; | ||
2618 | |||
2604 | /* register our block device */ | 2619 | /* register our block device */ |
2605 | rc = register_blkdev(0, rbd_dev->name); | 2620 | rc = register_blkdev(0, rbd_dev->name); |
2606 | if (rc < 0) | 2621 | if (rc < 0) |
2607 | goto err_out_client; | 2622 | goto err_out_header; |
2608 | rbd_dev->major = rc; | 2623 | rbd_dev->major = rc; |
2609 | 2624 | ||
2610 | rc = rbd_bus_add_dev(rbd_dev); | 2625 | rc = rbd_bus_add_dev(rbd_dev); |
@@ -2616,20 +2631,6 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2616 | * of the sysfs code (initiated by rbd_bus_del_dev()). | 2631 | * of the sysfs code (initiated by rbd_bus_del_dev()). |
2617 | */ | 2632 | */ |
2618 | 2633 | ||
2619 | /* contact OSD, request size info about the object being mapped */ | ||
2620 | rc = rbd_read_header(rbd_dev, &rbd_dev->header); | ||
2621 | if (rc) | ||
2622 | goto err_out_bus; | ||
2623 | |||
2624 | /* no need to lock here, as rbd_dev is not registered yet */ | ||
2625 | rc = rbd_dev_snaps_update(rbd_dev); | ||
2626 | if (rc) | ||
2627 | goto err_out_bus; | ||
2628 | |||
2629 | rc = rbd_dev_set_mapping(rbd_dev, snap_name); | ||
2630 | if (rc) | ||
2631 | goto err_out_bus; | ||
2632 | |||
2633 | down_write(&rbd_dev->header_rwsem); | 2634 | down_write(&rbd_dev->header_rwsem); |
2634 | rc = rbd_dev_snaps_register(rbd_dev); | 2635 | rc = rbd_dev_snaps_register(rbd_dev); |
2635 | up_write(&rbd_dev->header_rwsem); | 2636 | up_write(&rbd_dev->header_rwsem); |
@@ -2664,6 +2665,8 @@ err_out_bus: | |||
2664 | 2665 | ||
2665 | err_out_blkdev: | 2666 | err_out_blkdev: |
2666 | unregister_blkdev(rbd_dev->major, rbd_dev->name); | 2667 | unregister_blkdev(rbd_dev->major, rbd_dev->name); |
2668 | err_out_header: | ||
2669 | rbd_header_free(&rbd_dev->header); | ||
2667 | err_out_client: | 2670 | err_out_client: |
2668 | kfree(rbd_dev->header_name); | 2671 | kfree(rbd_dev->header_name); |
2669 | rbd_put_client(rbd_dev); | 2672 | rbd_put_client(rbd_dev); |