@@ -463,21 +463,21 @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
}
static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
- uint64_t guest_cluster_offset,
- uint64_t host_cluster_offset,
- unsigned offset_in_cluster,
+ uint64_t guest_offset,
+ uint64_t host_offset,
uint8_t *buffer,
unsigned bytes)
{
if (bytes && bs->encrypted) {
BDRVQcow2State *s = bs->opaque;
- assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0);
- assert((bytes & ~BDRV_SECTOR_MASK) == 0);
+
+ assert(QEMU_IS_ALIGNED(guest_offset, BDRV_SECTOR_SIZE));
+ assert(QEMU_IS_ALIGNED(host_offset, BDRV_SECTOR_SIZE));
+ assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE));
assert(s->crypto);
- if (qcow2_co_encrypt(bs,
- host_cluster_offset + offset_in_cluster,
- guest_cluster_offset + offset_in_cluster,
- buffer, bytes) < 0) {
+
+ if (qcow2_co_encrypt(bs, host_offset, guest_offset,
+ buffer, bytes) < 0) {
return false;
}
}
@@ -891,11 +891,15 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
/* Encrypt the data if necessary before writing it */
if (bs->encrypted) {
- if (!do_perform_cow_encrypt(bs, m->offset, m->alloc_offset,
- start->offset, start_buffer,
+ if (!do_perform_cow_encrypt(bs,
+ m->offset + start->offset,
+ m->alloc_offset + start->offset,
+ start_buffer,
start->nb_bytes) ||
- !do_perform_cow_encrypt(bs, m->offset, m->alloc_offset,
- end->offset, end_buffer, end->nb_bytes)) {
+ !do_perform_cow_encrypt(bs,
+ m->offset + end->offset,
+ m->alloc_offset + end->offset,
+ end_buffer, end->nb_bytes)) {
ret = -EIO;
goto fail;
}