1 From 66922efc83a670178b208dec2f5123ec85fb6ba3 Mon Sep 17 00:00:00 2001
2 From: Fam Zheng <famcool@gmail.com>
3 Date: Tue, 12 Jul 2011 19:56:29 +0800
4 Subject: [PATCH 03/12] VMDK: bugfix, align offset to cluster in
7 In get_whole_cluster, the offset is not aligned to cluster when reading
8 from backing_hd. When the first write to child is not at the cluster
9 boundary, wrong address data from parent is copied to child.
11 Signed-off-by: Fam Zheng <famcool@gmail.com>
12 Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
13 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15 block/vmdk.c | 8 +++++---
16 1 file changed, 5 insertions(+), 3 deletions(-)
20 @@ -514,21 +514,23 @@ static int get_whole_cluster(BlockDriver
21 /* 128 sectors * 512 bytes each = grain size 64KB */
22 uint8_t whole_grain[extent->cluster_sectors * 512];
24 - // we will be here if it's first write on non-exist grain(cluster).
25 - // try to read from parent image, if exist
26 + /* we will be here if it's first write on non-exist grain(cluster).
27 + * try to read from parent image, if exist */
31 if (!vmdk_is_cid_valid(bs))
34 + /* floor offset to cluster */
35 + offset -= offset % (extent->cluster_sectors * 512);
36 ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
37 extent->cluster_sectors);
42 - //Write grain only into the active image
43 + /* Write grain only into the active image */
44 ret = bdrv_write(extent->file, cluster_offset, whole_grain,
45 extent->cluster_sectors);