aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-10 21:30:10 -0400
committerAlex Elder <elder@inktank.com>2012-10-01 15:30:51 -0400
commit2ac4e75d89e9df8eea6390a759eac2b6df0ebff6 (patch)
tree77e02e2fa3376325ff7c93aaf469369e15eb1928 /drivers/block
parent8836b995fd192dba23d312d2a4fba68dd8ca7183 (diff)
rbd: do some header initialization earlier
Move some of the code that initializes an rbd header out of rbd_init_disk() and into its caller. Move the code at the end of rbd_init_disk() that sets the device capacity and activates the Linux device out of that function and into the caller, ensuring we still have the disk size available where we need it. Update rbd_free_disk() so it still aligns well as an inverse of rbd_init_disk(), moving the rbd_header_free() call out to its caller. 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.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 46b8f8e536be..6e735a754b5f 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1652,8 +1652,6 @@ static void rbd_free_disk(struct rbd_device *rbd_dev)
1652 if (!disk) 1652 if (!disk)
1653 return; 1653 return;
1654 1654
1655 rbd_header_free(&rbd_dev->header);
1656
1657 if (disk->flags & GENHD_FL_UP) 1655 if (disk->flags & GENHD_FL_UP)
1658 del_gendisk(disk); 1656 del_gendisk(disk);
1659 if (disk->queue) 1657 if (disk->queue)
@@ -1875,20 +1873,6 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1875 int rc; 1873 int rc;
1876 u64 segment_size; 1874 u64 segment_size;
1877 1875
1878 /* contact OSD, request size info about the object being mapped */
1879 rc = rbd_read_header(rbd_dev, &rbd_dev->header);
1880 if (rc)
1881 return rc;
1882
1883 /* no need to lock here, as rbd_dev is not registered yet */
1884 rc = rbd_dev_snap_devs_update(rbd_dev);
1885 if (rc)
1886 return rc;
1887
1888 rc = rbd_header_set_snap(rbd_dev, snap_name);
1889 if (rc)
1890 return rc;
1891
1892 /* create gendisk info */ 1876 /* create gendisk info */
1893 rc = -ENOMEM; 1877 rc = -ENOMEM;
1894 disk = alloc_disk(RBD_MINORS_PER_MAJOR); 1878 disk = alloc_disk(RBD_MINORS_PER_MAJOR);
@@ -1925,12 +1909,6 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1925 1909
1926 rbd_dev->disk = disk; 1910 rbd_dev->disk = disk;
1927 1911
1928 /* finally, announce the disk to the world */
1929 set_capacity(disk, (sector_t) rbd_dev->mapping.size / SECTOR_SIZE);
1930 add_disk(disk);
1931
1932 pr_info("%s: added with size 0x%llx\n",
1933 disk->disk_name, (unsigned long long) rbd_dev->mapping.size);
1934 return 0; 1912 return 0;
1935 1913
1936out_disk: 1914out_disk:
@@ -2622,13 +2600,35 @@ static ssize_t rbd_add(struct bus_type *bus,
2622 /* 2600 /*
2623 * At this point cleanup in the event of an error is the job 2601 * At this point cleanup in the event of an error is the job
2624 * of the sysfs code (initiated by rbd_bus_del_dev()). 2602 * of the sysfs code (initiated by rbd_bus_del_dev()).
2625 *
2626 * Set up and announce blkdev mapping.
2627 */ 2603 */
2604
2605 /* contact OSD, request size info about the object being mapped */
2606 rc = rbd_read_header(rbd_dev, &rbd_dev->header);
2607 if (rc)
2608 goto err_out_bus;
2609
2610 /* no need to lock here, as rbd_dev is not registered yet */
2611 rc = rbd_dev_snap_devs_update(rbd_dev);
2612 if (rc)
2613 goto err_out_bus;
2614
2615 rc = rbd_header_set_snap(rbd_dev, snap_name);
2616 if (rc)
2617 goto err_out_bus;
2618
2619 /* Set up the blkdev mapping. */
2620
2628 rc = rbd_init_disk(rbd_dev); 2621 rc = rbd_init_disk(rbd_dev);
2629 if (rc) 2622 if (rc)
2630 goto err_out_bus; 2623 goto err_out_bus;
2631 2624
2625 /* Everything's ready. Announce the disk to the world. */
2626
2627 set_capacity(rbd_dev->disk, rbd_dev->mapping.size / SECTOR_SIZE);
2628 add_disk(rbd_dev->disk);
2629 pr_info("%s: added with size 0x%llx\n", rbd_dev->disk->disk_name,
2630 (unsigned long long) rbd_dev->mapping.size);
2631
2632 rc = rbd_init_watch_dev(rbd_dev); 2632 rc = rbd_init_watch_dev(rbd_dev);
2633 if (rc) 2633 if (rc)
2634 goto err_out_bus; 2634 goto err_out_bus;
@@ -2700,6 +2700,9 @@ static void rbd_dev_release(struct device *dev)
2700 rbd_free_disk(rbd_dev); 2700 rbd_free_disk(rbd_dev);
2701 unregister_blkdev(rbd_dev->major, rbd_dev->name); 2701 unregister_blkdev(rbd_dev->major, rbd_dev->name);
2702 2702
2703 /* release allocated disk header fields */
2704 rbd_header_free(&rbd_dev->header);
2705
2703 /* done with the id, and with the rbd_dev */ 2706 /* done with the id, and with the rbd_dev */
2704 kfree(rbd_dev->mapping.snap_name); 2707 kfree(rbd_dev->mapping.snap_name);
2705 kfree(rbd_dev->header_name); 2708 kfree(rbd_dev->header_name);