[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/22] block/vdi: Zero unused parts when allocating
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 19/22] block/vdi: Zero unused parts when allocating a new block (fix #919242) |
Date: |
Thu, 26 Jan 2012 17:38:13 +0100 |
From: Stefan Weil <address@hidden>
The new block was filled with zero when it was allocated by g_malloc0,
but when it was reused later and only partially used, data from the
previously allocated block were still present and written to the new
block.
This caused the problems reported by bug #919242
(https://bugs.launchpad.net/qemu/+bug/919242).
Now the unused parts of the new block which are before and after the data
are always filled with zero, so it is no longer necessary to zero the whole
block with g_malloc0.
I also updated the copyright comment.
Signed-off-by: Stefan Weil <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vdi.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 31cdfab..6a0011f 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -1,7 +1,7 @@
/*
* Block driver for the Virtual Disk Image (VDI) format
*
- * Copyright (c) 2009 Stefan Weil
+ * Copyright (c) 2009, 2012 Stefan Weil
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -756,15 +756,19 @@ static void vdi_aio_write_cb(void *opaque, int ret)
(uint64_t)bmap_entry * s->block_sectors;
block = acb->block_buffer;
if (block == NULL) {
- block = g_malloc0(s->block_size);
+ block = g_malloc(s->block_size);
acb->block_buffer = block;
acb->bmap_first = block_index;
assert(!acb->header_modified);
acb->header_modified = 1;
}
acb->bmap_last = block_index;
+ /* Copy data to be written to new block and zero unused parts. */
+ memset(block, 0, sector_in_block * SECTOR_SIZE);
memcpy(block + sector_in_block * SECTOR_SIZE,
acb->buf, n_sectors * SECTOR_SIZE);
+ memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
+ (s->block_sectors - n_sectors - sector_in_block) * SECTOR_SIZE);
acb->hd_iov.iov_base = (void *)block;
acb->hd_iov.iov_len = s->block_size;
qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1);
--
1.7.6.5
- [Qemu-devel] [PATCH 05/22] block: make copy-on-read a per-request flag, (continued)
- [Qemu-devel] [PATCH 05/22] block: make copy-on-read a per-request flag, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 10/22] qmp: add block_job_set_speed command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 09/22] qmp: add block_stream command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 02/22] block: replace unchecked strdup/malloc/calloc with glib, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 08/22] block: rate-limit streaming operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 06/22] block: add BlockJob interface for long-running operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 12/22] qmp: add query-block-jobs, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 07/22] block: add image streaming block job, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 15/22] add QERR_BASE_NOT_FOUND, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 11/22] qmp: add block_job_cancel command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 19/22] block/vdi: Zero unused parts when allocating a new block (fix #919242),
Kevin Wolf <=
- [Qemu-devel] [PATCH 13/22] blockdev: make image streaming safe across hotplug, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 18/22] virtio-blk: add virtio_blk_handle_read trace event, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 17/22] docs: describe live block operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 14/22] block: add bdrv_find_backing_image, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 21/22] qcow: Use bdrv functions to replace file operation, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 20/22] qcow: Return real error code in qcow_open, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 16/22] block: add support for partial streaming, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 22/22] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command, Kevin Wolf, 2012/01/26
- Re: [Qemu-devel] [PULL 00/22] Block patches, Anthony Liguori, 2012/01/27