aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2.c
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2020-07-10 18:12:44 +0200
committerMax Reitz <mreitz@redhat.com>2020-08-25 08:33:20 +0200
commit388e581615d11126bc6d37223d50cbf8e127bde1 (patch)
tree154f606f9c42fc6f71f0d182c861b232ea48bb82 /block/qcow2.c
parent9c4269d54b8bcc1939641009a2ea9b24d887fd58 (diff)
downloadqemu-388e581615d11126bc6d37223d50cbf8e127bde1.zip
qemu-388e581615d11126bc6d37223d50cbf8e127bde1.tar.gz
qemu-388e581615d11126bc6d37223d50cbf8e127bde1.tar.bz2
qcow2: Convert qcow2_get_cluster_offset() into qcow2_get_host_offset()
qcow2_get_cluster_offset() takes an (unaligned) guest offset and returns the (aligned) offset of the corresponding cluster in the qcow2 image. In practice none of the callers need to know where the cluster starts so this patch makes the function calculate and return the final host offset directly. The function is also renamed accordingly. There is a pre-existing exception with compressed clusters: in this case the function returns the complete cluster descriptor (containing the offset and size of the compressed data). This does not change with this patch but it is now documented. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <ffae6cdc5ca8950e8280ac0f696dcc376cb07095.1594396418.git.berto@igalia.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 5ab1f45..6738daa 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2036,7 +2036,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
BlockDriverState **file)
{
BDRVQcow2State *s = bs->opaque;
- uint64_t cluster_offset;
+ uint64_t host_offset;
unsigned int bytes;
int ret, status = 0;
@@ -2049,7 +2049,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
}
bytes = MIN(INT_MAX, count);
- ret = qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset);
+ ret = qcow2_get_host_offset(bs, offset, &bytes, &host_offset);
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
return ret;
@@ -2059,7 +2059,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
if ((ret == QCOW2_CLUSTER_NORMAL || ret == QCOW2_CLUSTER_ZERO_ALLOC) &&
!s->crypto) {
- *map = cluster_offset | offset_into_cluster(s, offset);
+ *map = host_offset;
*file = s->data_file->bs;
status |= BDRV_BLOCK_OFFSET_VALID;
}
@@ -2273,7 +2273,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs,
BDRVQcow2State *s = bs->opaque;
int ret = 0;
unsigned int cur_bytes; /* number of bytes in current iteration */
- uint64_t cluster_offset = 0;
+ uint64_t host_offset = 0;
AioTaskPool *aio = NULL;
while (bytes != 0 && aio_task_pool_status(aio) == 0) {
@@ -2285,7 +2285,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs,
}
qemu_co_mutex_lock(&s->lock);
- ret = qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_offset);
+ ret = qcow2_get_host_offset(bs, offset, &cur_bytes, &host_offset);
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
goto out;
@@ -2297,15 +2297,6 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs,
{
qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes);
} else {
- /*
- * For compressed clusters the variable cluster_offset
- * does not actually store the offset but the full
- * descriptor. We need to leave it unchanged because
- * that's what qcow2_co_preadv_compressed() expects.
- */
- uint64_t host_offset = (ret == QCOW2_CLUSTER_COMPRESSED) ?
- cluster_offset :
- cluster_offset + offset_into_cluster(s, offset);
if (!aio && cur_bytes != bytes) {
aio = aio_task_pool_new(QCOW2_MAX_WORKERS);
}
@@ -3853,7 +3844,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
offset = QEMU_ALIGN_DOWN(offset, s->cluster_size);
bytes = s->cluster_size;
nr = s->cluster_size;
- ret = qcow2_get_cluster_offset(bs, offset, &nr, &off);
+ ret = qcow2_get_host_offset(bs, offset, &nr, &off);
if (ret != QCOW2_CLUSTER_UNALLOCATED &&
ret != QCOW2_CLUSTER_ZERO_PLAIN &&
ret != QCOW2_CLUSTER_ZERO_ALLOC) {
@@ -3924,7 +3915,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs,
cur_bytes = MIN(bytes, INT_MAX);
cur_write_flags = write_flags;
- ret = qcow2_get_cluster_offset(bs, src_offset, &cur_bytes, &copy_offset);
+ ret = qcow2_get_host_offset(bs, src_offset, &cur_bytes, &copy_offset);
if (ret < 0) {
goto out;
}
@@ -3956,7 +3947,6 @@ qcow2_co_copy_range_from(BlockDriverState *bs,
case QCOW2_CLUSTER_NORMAL:
child = s->data_file;
- copy_offset += offset_into_cluster(s, src_offset);
break;
default: