summaryrefslogtreecommitdiffstats
path: root/hw/block/xen-block.c
diff options
context:
space:
mode:
authorPaul Durrant2019-04-01 14:17:19 +0200
committerAnthony PERARD2019-04-04 19:00:07 +0200
commit2bcd05cf24a7de34e7e265247c010977e43f40bc (patch)
tree24f489fd871b4e6850844cbd5aca1711c20cc461 /hw/block/xen-block.c
parentxen-block: only advertize discard to the frontend when it is enabled... (diff)
downloadqemu-2bcd05cf24a7de34e7e265247c010977e43f40bc.tar.gz
qemu-2bcd05cf24a7de34e7e265247c010977e43f40bc.tar.xz
qemu-2bcd05cf24a7de34e7e265247c010977e43f40bc.zip
xen-block: scale sector based quantities correctly
The Xen blkif protocol requires that sector based quantities should be interpreted strictly as multiples of 512 bytes. Specifically: "first_sect and last_sect in blkif_request_segment, as well as sector_number in blkif_request, are always expressed in 512-byte units." Commit fcab2b464e06 "xen: add header and build dataplane/xen-block.c" incorrectly modified behaviour to use the block device logical_block_size property as the scale, instead of correctly shifting values by the hardcoded BDRV_SECTOR_BITS (and hence scaling them to 512 byte units). This patch undoes that change and restores compliance with the spec. Furthermore, this patch also restores the original xen_disk behaviour of advertizing a hardcoded 'sector-size' value of 512 in xenstore and scaling 'sectors' accordingly. The realize() method is also modified to fail if logical_block_size is set to anything other than 512. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com> Message-Id: <20190401121719.27208-1-paul.durrant@citrix.com> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Diffstat (limited to 'hw/block/xen-block.c')
-rw-r--r--hw/block/xen-block.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 475a67845d..ef635be4c2 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -149,7 +149,7 @@ static void xen_block_set_size(XenBlockDevice *blockdev)
const char *type = object_get_typename(OBJECT(blockdev));
XenBlockVdev *vdev = &blockdev->props.vdev;
BlockConf *conf = &blockdev->props.conf;
- int64_t sectors = blk_getlength(conf->blk) / conf->logical_block_size;
+ int64_t sectors = blk_getlength(conf->blk) / XEN_BLKIF_SECTOR_SIZE;
XenDevice *xendev = XEN_DEVICE(blockdev);
trace_xen_block_size(type, vdev->disk, vdev->partition, sectors);
@@ -223,6 +223,12 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
blkconf_blocksizes(conf);
+ if (conf->logical_block_size != XEN_BLKIF_SECTOR_SIZE) {
+ error_setg(errp, "logical_block_size != %u not supported",
+ XEN_BLKIF_SECTOR_SIZE);
+ return;
+ }
+
if (conf->logical_block_size > conf->physical_block_size) {
error_setg(
errp, "logical_block_size > physical_block_size not supported");
@@ -253,7 +259,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
blockdev->device_type);
xen_device_backend_printf(xendev, "sector-size", "%u",
- conf->logical_block_size);
+ XEN_BLKIF_SECTOR_SIZE);
xen_block_set_size(blockdev);