Patchwork [02/12] VMDK: bugfix, align offset to cluster in get_whole_cluster

login
register
mail settings
Submitter Feiran Zheng
Date June 4, 2011, 12:40 a.m.
Message ID <BANLkTi=bvqLorVbO3qU+9_XDqN2j5+rsNA@mail.gmail.com>
Download mbox | patch
Permalink /patch/98703/
State New
Headers show

Comments

Feiran Zheng - June 4, 2011, 12:40 a.m.
In get_whole_cluster, the offset is not aligned, to cluster when
reading from backing_hd. So if it's the first write to child and the
offset is not the cluster boundary, data is copied from parent at a
wrong position.

Signed-off-by: Fam Zheng <famcool@gmail.com>
---
 block/vmdk.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 9442794..f787528 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -489,6 +489,8 @@  static int get_whole_cluster(BlockDriverState *bs,
         if (!vmdk_is_cid_valid(bs, extent))
             return -1;

+        // floor offset to cluster
+        offset -= offset % (extent->cluster_sectors * 512);
         ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
                 extent->cluster_sectors);
         if (ret < 0) {