提交 a51aa0c0 编写于 作者: J Josh Durgin 提交者: Sage Weil

rbd: expose the correct size of the device in sysfs

If an image was mapped to a snapshot, the size of the head version
would be shown. Protect capacity with header_rwsem, since it may
change.
Signed-off-by: NJosh Durgin <josh.durgin@dreamhost.com>
Reviewed-by: NAlex Elder <elder@inktank.com>
上级 474ef7ce
......@@ -1724,6 +1724,8 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev)
if (ret < 0)
return ret;
down_write(&rbd_dev->header_rwsem);
/* resized? */
if (rbd_dev->snap_id == CEPH_NOSNAP) {
sector_t size = (sector_t) h.image_size / SECTOR_SIZE;
......@@ -1732,8 +1734,6 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev)
set_capacity(rbd_dev->disk, size);
}
down_write(&rbd_dev->header_rwsem);
snap_seq = rbd_dev->header.snapc->seq;
if (rbd_dev->header.total_snaps &&
rbd_dev->header.snapc->snaps[0] == snap_seq)
......@@ -1853,8 +1853,13 @@ static ssize_t rbd_size_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
sector_t size;
down_read(&rbd_dev->header_rwsem);
size = get_capacity(rbd_dev->disk);
up_read(&rbd_dev->header_rwsem);
return sprintf(buf, "%llu\n", (unsigned long long)rbd_dev->header.image_size);
return sprintf(buf, "%llu\n", (unsigned long long) size * SECTOR_SIZE);
}
static ssize_t rbd_major_show(struct device *dev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册