qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qcow2: Check request size in qcow2_co_pwritev_compressed_part()

When issuing a compressed write request the number of bytes must be a
multiple of the cluster size or reach the end of the last cluster.

With the current code such requests are allowed and we hit an
assertion:

$ qemu-img create -f qcow2 img.qcow2 1M
$ qemu-io -c 'write -c 0 32k' img.qcow2

qemu-io: block/qcow2.c:4257: qcow2_co_pwritev_compressed_task:
Assertion `bytes == s->cluster_size || (bytes < s->cluster_size &&
(offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))' failed.
Aborted

This patch fixes a regression introduced in 0d483dce38

Signed-off-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20200406143401.26854-1-berto@igalia.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Alberto Garcia and committed by
Max Reitz
fb43d2d4 39f77cb6

+5
+5
block/qcow2.c
··· 4355 4355 return -EINVAL; 4356 4356 } 4357 4357 4358 + if (offset_into_cluster(s, bytes) && 4359 + (offset + bytes) != (bs->total_sectors << BDRV_SECTOR_BITS)) { 4360 + return -EINVAL; 4361 + } 4362 + 4358 4363 while (bytes && aio_task_pool_status(aio) == 0) { 4359 4364 uint64_t chunk_size = MIN(bytes, s->cluster_size); 4360 4365