[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [COMMIT ea80b90] qcow2: Fix metadata preallocation

From: Anthony Liguori
Subject: [Qemu-commits] [COMMIT ea80b90] qcow2: Fix metadata preallocation
Date: Wed, 09 Sep 2009 22:37:05 -0000

From: Kevin Wolf <address@hidden>

The wrong version of the preallocation patch has been applied, so this is the
remaining diff.

We can't use truncate to grow the image file to the right size because we don't
know if metadata has been written after the last data cluster. In this case
truncate would shrink the file and destroy its metadata. Write a zero sector at
the end of the virtual disk instead to ensure that the file is big enough.

Signed-off-by: Kevin Wolf <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/block/qcow2.c b/block/qcow2.c
index 9637f2e..b8eae90 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -677,7 +677,9 @@ static int preallocate(BlockDriverState *bs)
      * EOF). Extend the image to the last allocated sector.
     if (cluster_offset != 0) {
-        bdrv_truncate(s->hd, cluster_offset + (num <<  9));
+        uint8_t buf[512];
+        memset(buf, 0, 512);
+        bdrv_write(s->hd, (cluster_offset >> 9) + num - 1, buf, 1);
     return 0;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]