qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: Fix metadata preallocation
@ 2009-08-31 10:26 Kevin Wolf
  0 siblings, 0 replies; only message in thread
From: Kevin Wolf @ 2009-08-31 10:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

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 <kwolf@redhat.com>
---
 block/qcow2.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

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;
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-31 10:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-31 10:26 [Qemu-devel] [PATCH] qcow2: Fix metadata preallocation Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).