aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-08-30 15:42:15 -0400
committerAlex Elder <elder@inktank.com>2012-10-01 15:30:51 -0400
commit99c1f08f6459cfa6fe1f5fb68706b437e006be2e (patch)
treee4289381489493e0979a63e28c831d40f5a31ac0 /drivers/block
parentf84344f334df8f1d41eba7cfa7eb1024da25e1fe (diff)
rbd: record mapped size
Add the size of the mapped image to the set of mapping-specific fields in an rbd_device, and use it when setting the capacity of the disk. 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.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index dff621060432..4377a8302fc3 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -151,6 +151,7 @@ struct rbd_snap {
151struct rbd_mapping { 151struct rbd_mapping {
152 char *snap_name; 152 char *snap_name;
153 u64 snap_id; 153 u64 snap_id;
154 u64 size;
154 bool snap_exists; 155 bool snap_exists;
155 bool read_only; 156 bool read_only;
156}; 157};
@@ -643,7 +644,7 @@ static int snap_by_name(struct rbd_image_header *header, const char *snap_name,
643 return -ENOENT; 644 return -ENOENT;
644} 645}
645 646
646static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) 647static int rbd_header_set_snap(struct rbd_device *rbd_dev)
647{ 648{
648 int ret; 649 int ret;
649 650
@@ -652,19 +653,16 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size)
652 if (!memcmp(rbd_dev->mapping.snap_name, RBD_SNAP_HEAD_NAME, 653 if (!memcmp(rbd_dev->mapping.snap_name, RBD_SNAP_HEAD_NAME,
653 sizeof (RBD_SNAP_HEAD_NAME))) { 654 sizeof (RBD_SNAP_HEAD_NAME))) {
654 rbd_dev->mapping.snap_id = CEPH_NOSNAP; 655 rbd_dev->mapping.snap_id = CEPH_NOSNAP;
656 rbd_dev->mapping.size = rbd_dev->header.image_size;
655 rbd_dev->mapping.snap_exists = false; 657 rbd_dev->mapping.snap_exists = false;
656 rbd_dev->mapping.read_only = rbd_dev->rbd_opts.read_only; 658 rbd_dev->mapping.read_only = rbd_dev->rbd_opts.read_only;
657 if (size)
658 *size = rbd_dev->header.image_size;
659 } else { 659 } else {
660 u64 snap_id = 0;
661
662 ret = snap_by_name(&rbd_dev->header, 660 ret = snap_by_name(&rbd_dev->header,
663 rbd_dev->mapping.snap_name, 661 rbd_dev->mapping.snap_name,
664 &snap_id, size); 662 &rbd_dev->mapping.snap_id,
663 &rbd_dev->mapping.size);
665 if (ret < 0) 664 if (ret < 0)
666 goto done; 665 goto done;
667 rbd_dev->mapping.snap_id = snap_id;
668 rbd_dev->mapping.snap_exists = true; 666 rbd_dev->mapping.snap_exists = true;
669 rbd_dev->mapping.read_only = true; 667 rbd_dev->mapping.read_only = true;
670 } 668 }
@@ -1830,8 +1828,12 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver)
1830 if (rbd_dev->mapping.snap_id == CEPH_NOSNAP) { 1828 if (rbd_dev->mapping.snap_id == CEPH_NOSNAP) {
1831 sector_t size = (sector_t) h.image_size / SECTOR_SIZE; 1829 sector_t size = (sector_t) h.image_size / SECTOR_SIZE;
1832 1830
1833 dout("setting size to %llu sectors", (unsigned long long) size); 1831 if (size != (sector_t) rbd_dev->mapping.size) {
1834 set_capacity(rbd_dev->disk, size); 1832 dout("setting size to %llu sectors",
1833 (unsigned long long) size);
1834 rbd_dev->mapping.size = (u64) size;
1835 set_capacity(rbd_dev->disk, size);
1836 }
1835 } 1837 }
1836 1838
1837 /* rbd_dev->header.object_prefix shouldn't change */ 1839 /* rbd_dev->header.object_prefix shouldn't change */
@@ -1875,7 +1877,6 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1875 struct request_queue *q; 1877 struct request_queue *q;
1876 int rc; 1878 int rc;
1877 u64 segment_size; 1879 u64 segment_size;
1878 u64 total_size = 0;
1879 1880
1880 /* contact OSD, request size info about the object being mapped */ 1881 /* contact OSD, request size info about the object being mapped */
1881 rc = rbd_read_header(rbd_dev, &rbd_dev->header); 1882 rc = rbd_read_header(rbd_dev, &rbd_dev->header);
@@ -1887,7 +1888,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1887 if (rc) 1888 if (rc)
1888 return rc; 1889 return rc;
1889 1890
1890 rc = rbd_header_set_snap(rbd_dev, &total_size); 1891 rc = rbd_header_set_snap(rbd_dev);
1891 if (rc) 1892 if (rc)
1892 return rc; 1893 return rc;
1893 1894
@@ -1928,11 +1929,11 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1928 rbd_dev->disk = disk; 1929 rbd_dev->disk = disk;
1929 1930
1930 /* finally, announce the disk to the world */ 1931 /* finally, announce the disk to the world */
1931 set_capacity(disk, total_size / SECTOR_SIZE); 1932 set_capacity(disk, (sector_t) rbd_dev->mapping.size / SECTOR_SIZE);
1932 add_disk(disk); 1933 add_disk(disk);
1933 1934
1934 pr_info("%s: added with size 0x%llx\n", 1935 pr_info("%s: added with size 0x%llx\n",
1935 disk->disk_name, (unsigned long long)total_size); 1936 disk->disk_name, (unsigned long long) rbd_dev->mapping.size);
1936 return 0; 1937 return 0;
1937 1938
1938out_disk: 1939out_disk: