@@ -2421,6 +2421,9 @@ static int handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta)
for (m = l2meta; m != NULL; m = m->next) {
int ret;
+ uint64_t start_offset = m->alloc_offset + m->cow_start.offset;
+ unsigned nb_bytes = m->cow_end.offset + m->cow_end.nb_bytes -
+ m->cow_start.offset;
if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) {
continue;
@@ -2435,16 +2438,14 @@ static int handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta)
* efficiently zero out the whole clusters
*/
- ret = qcow2_pre_write_overlap_check(bs, 0, m->alloc_offset,
- m->nb_clusters * s->cluster_size,
+ ret = qcow2_pre_write_overlap_check(bs, 0, start_offset, nb_bytes,
true);
if (ret < 0) {
return ret;
}
BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
- ret = bdrv_co_pwrite_zeroes(s->data_file, m->alloc_offset,
- m->nb_clusters * s->cluster_size,
+ ret = bdrv_co_pwrite_zeroes(s->data_file, start_offset, nb_bytes,
BDRV_REQ_NO_FALLBACK);
if (ret < 0) {
if (ret != -ENOTSUP && ret != -EAGAIN) {