[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [STABLE][PATCH 03/14] vmdk: Fix COW
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [STABLE][PATCH 03/14] vmdk: Fix COW |
Date: |
Wed, 14 Jul 2010 13:24:02 +0200 |
When trying to do COW, VMDK wrote the data back to the backing file. This
problem was revealed by the patch that made backing files read-only. This patch
does not only fix the problem, but also simplifies the VMDK code a bit.
This fixes the backing file qemu-iotests cases for VMDK.
Signed-off-by: Kevin Wolf <address@hidden>
(cherry picked from commit c336500df5bf08492f4e7796b2193cd4976f3548)
---
block/vmdk.c | 35 +++++++++++------------------------
1 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 765e95a..d52904a 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -87,14 +87,6 @@ typedef struct VmdkMetaData {
int valid;
} VmdkMetaData;
-typedef struct ActiveBDRVState{
- BlockDriverState *hd; // active image handler
- uint64_t cluster_offset; // current write offset
-}ActiveBDRVState;
-
-static ActiveBDRVState activeBDRV;
-
-
static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
{
uint32_t magic;
@@ -458,30 +450,28 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
VmdkMetaData *m_data,
static int get_whole_cluster(BlockDriverState *bs, uint64_t cluster_offset,
uint64_t offset, int allocate)
{
- uint64_t parent_cluster_offset;
BDRVVmdkState *s = bs->opaque;
uint8_t whole_grain[s->cluster_sectors*512]; // 128 sectors * 512
bytes each = grain size 64KB
// we will be here if it's first write on non-exist grain(cluster).
// try to read from parent image, if exist
if (bs->backing_hd) {
- BDRVVmdkState *ps = bs->backing_hd->opaque;
+ int ret;
if (!vmdk_is_cid_valid(bs))
return -1;
- parent_cluster_offset = get_cluster_offset(bs->backing_hd, NULL,
- offset, allocate);
-
- if (parent_cluster_offset) {
- BDRVVmdkState *act_s = activeBDRV.hd->opaque;
-
- if (bdrv_pread(ps->hd, parent_cluster_offset, whole_grain,
ps->cluster_sectors*512) != ps->cluster_sectors*512)
- return -1;
+ ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
+ s->cluster_sectors);
+ if (ret < 0) {
+ return -1;
+ }
- //Write grain only into the active image
- if (bdrv_pwrite(act_s->hd, activeBDRV.cluster_offset << 9,
whole_grain, sizeof(whole_grain)) != sizeof(whole_grain))
- return -1;
+ //Write grain only into the active image
+ ret = bdrv_write(s->hd, cluster_offset, whole_grain,
+ s->cluster_sectors);
+ if (ret < 0) {
+ return -1;
}
}
return 0;
@@ -567,9 +557,6 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
VmdkMetaData *m_data,
cluster_offset >>= 9;
tmp = cpu_to_le32(cluster_offset);
l2_table[l2_index] = tmp;
- // Save the active image state
- activeBDRV.cluster_offset = cluster_offset;
- activeBDRV.hd = bs;
}
/* First of all we write grain itself, to avoid race condition
* that may to corrupt the image.
--
1.7.1.1
- [Qemu-devel] [STABLE][PULL 00/14] Block patches for 0.12.5, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 01/14] vmdk: fix double free, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 04/14] qcow2: Remove abort on free_clusters failure, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 03/14] vmdk: Fix COW,
Kevin Wolf <=
- [Qemu-devel] [STABLE][PATCH 02/14] qcow2: Fix creation of large images, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 05/14] block/vpc: Fix conversion from size to disk geometry, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 06/14] block/vdi: Fix image opening and creation for odd disk sizes, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 07/14] qcow2: Restore L1 entry on l2_allocate failure, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 09/14] qcow: Use bdrv_(p)write_sync for metadata writes, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 08/14] block: Add bdrv_(p)write_sync, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 11/14] vmdk: Use bdrv_(p)write_sync for metadata writes, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 10/14] qcow2: Use bdrv_(p)write_sync for metadata writes, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 13/14] block: Fix early failure in multiwrite, Kevin Wolf, 2010/07/14
- [Qemu-devel] [STABLE][PATCH 14/14] block: Handle multiwrite errors only when all requests have completed, Kevin Wolf, 2010/07/14