|
|
cd9d16 |
From e246af75817264aa340cc4e8bb42c17a2d48cbb7 Mon Sep 17 00:00:00 2001
|
|
|
cd9d16 |
From: Stefan Weil <sw@weilnetz.de>
|
|
|
cd9d16 |
Date: Sat, 21 Jan 2012 13:54:24 +0100
|
|
|
cd9d16 |
Subject: [PATCH] block/vdi: Zero unused parts when allocating a new block
|
|
|
cd9d16 |
(fix #919242)
|
|
|
cd9d16 |
MIME-Version: 1.0
|
|
|
cd9d16 |
Content-Type: text/plain; charset=UTF-8
|
|
|
cd9d16 |
Content-Transfer-Encoding: 8bit
|
|
|
cd9d16 |
|
|
|
cd9d16 |
The new block was filled with zero when it was allocated by g_malloc0,
|
|
|
cd9d16 |
but when it was reused later and only partially used, data from the
|
|
|
cd9d16 |
previously allocated block were still present and written to the new
|
|
|
cd9d16 |
block.
|
|
|
cd9d16 |
|
|
|
cd9d16 |
This caused the problems reported by bug #919242
|
|
|
cd9d16 |
(https://bugs.launchpad.net/qemu/+bug/919242).
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Now the unused parts of the new block which are before and after the data
|
|
|
cd9d16 |
are always filled with zero, so it is no longer necessary to zero the whole
|
|
|
cd9d16 |
block with g_malloc0.
|
|
|
cd9d16 |
|
|
|
cd9d16 |
I also updated the copyright comment.
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Signed-off-by: Stefan Weil <sw@weilnetz.de>
|
|
|
cd9d16 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
cd9d16 |
(cherry picked from commit 641543b76b82a8b361482b727e08de0c8ec093b0)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
[AF: g_malloc() -> qemu_malloc()]
|
|
|
cd9d16 |
Signed-off-by: Andreas Färber <afaerber@suse.de>
|
|
|
cd9d16 |
---
|
|
|
cd9d16 |
block/vdi.c | 8 ++++++--
|
|
|
cd9d16 |
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
diff --git a/block/vdi.c b/block/vdi.c
|
|
|
cd9d16 |
index 1be0cdc..07413af 100644
|
|
|
cd9d16 |
--- a/block/vdi.c
|
|
|
cd9d16 |
+++ b/block/vdi.c
|
|
|
cd9d16 |
@@ -1,7 +1,7 @@
|
|
|
cd9d16 |
/*
|
|
|
cd9d16 |
* Block driver for the Virtual Disk Image (VDI) format
|
|
|
cd9d16 |
*
|
|
|
cd9d16 |
- * Copyright (c) 2009 Stefan Weil
|
|
|
cd9d16 |
+ * Copyright (c) 2009, 2012 Stefan Weil
|
|
|
cd9d16 |
*
|
|
|
cd9d16 |
* This program is free software: you can redistribute it and/or modify
|
|
|
cd9d16 |
* it under the terms of the GNU General Public License as published by
|
|
|
cd9d16 |
@@ -765,15 +765,19 @@ static void vdi_aio_write_cb(void *opaque, int ret)
|
|
|
cd9d16 |
(uint64_t)bmap_entry * s->block_sectors;
|
|
|
cd9d16 |
block = acb->block_buffer;
|
|
|
cd9d16 |
if (block == NULL) {
|
|
|
cd9d16 |
- block = qemu_mallocz(s->block_size);
|
|
|
cd9d16 |
+ block = qemu_malloc(s->block_size);
|
|
|
cd9d16 |
acb->block_buffer = block;
|
|
|
cd9d16 |
acb->bmap_first = block_index;
|
|
|
cd9d16 |
assert(!acb->header_modified);
|
|
|
cd9d16 |
acb->header_modified = 1;
|
|
|
cd9d16 |
}
|
|
|
cd9d16 |
acb->bmap_last = block_index;
|
|
|
cd9d16 |
+ /* Copy data to be written to new block and zero unused parts. */
|
|
|
cd9d16 |
+ memset(block, 0, sector_in_block * SECTOR_SIZE);
|
|
|
cd9d16 |
memcpy(block + sector_in_block * SECTOR_SIZE,
|
|
|
cd9d16 |
acb->buf, n_sectors * SECTOR_SIZE);
|
|
|
cd9d16 |
+ memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
|
|
|
cd9d16 |
+ (s->block_sectors - n_sectors - sector_in_block) * SECTOR_SIZE);
|
|
|
cd9d16 |
acb->hd_iov.iov_base = (void *)block;
|
|
|
cd9d16 |
acb->hd_iov.iov_len = s->block_size;
|
|
|
cd9d16 |
qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1);
|
|
|
cd9d16 |
--
|
|
|
cd9d16 |
1.7.11.2
|
|
|
cd9d16 |
|