xen_disk: split discard input to match internal representation
commit7875efb9f641ed0e79320bf258ee69cd0bf03716
authorOlaf Hering <olaf@aepfle.de>
Wed, 23 Nov 2016 10:39:12 +0000 (23 10:39 +0000)
committerStefano Stabellini <sstabellini@kernel.org>
Wed, 23 Nov 2016 18:47:48 +0000 (23 10:47 -0800)
tree37ca801d5af3eb4eaf68f9d3988f89e59d86e00e
parent00227fefd2059464cd2f59aed29944874c630e2f
xen_disk: split discard input to match internal representation

The guest sends discard requests as u64 sector/count pairs, but the
block layer operates internally with s64/s32 pairs. The conversion
leads to IO errors in the guest, the discard request is not processed.

  domU.cfg:
  'vdev=xvda, format=qcow2, backendtype=qdisk, target=/x.qcow2'
  domU:
  mkfs.ext4 -F /dev/xvda
  Discarding device blocks: failed - Input/output error

Fix this by splitting the request into chunks of BDRV_REQUEST_MAX_SECTORS.
Add input range checking to avoid overflow.

Fixes f313520 ("xen_disk: add discard support")

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
hw/block/xen_disk.c