qcow2: Prepare qcow2_co_block_status() for data file

Offset 0 cannot be assumed to mean an unallocated cluster any more.
Instead, the cluster type needs to be checked.

*file must refer to the data file instead of the image file if a valid
offset is returned from qcow2_co_block_status().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2019-02-27 13:22:56 +01:00
parent 77e023ff79
commit 37be14036b

View File

@ -1829,11 +1829,11 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
*pnum = bytes; *pnum = bytes;
if (cluster_offset != 0 && ret != QCOW2_CLUSTER_COMPRESSED && if ((ret == QCOW2_CLUSTER_NORMAL || ret == QCOW2_CLUSTER_ZERO_ALLOC) &&
!s->crypto) { !s->crypto) {
index_in_cluster = offset & (s->cluster_size - 1); index_in_cluster = offset & (s->cluster_size - 1);
*map = cluster_offset | index_in_cluster; *map = cluster_offset | index_in_cluster;
*file = bs->file->bs; *file = s->data_file->bs;
status |= BDRV_BLOCK_OFFSET_VALID; status |= BDRV_BLOCK_OFFSET_VALID;
} }
if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) { if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) {