From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mi47P-0005S6-DU for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:28:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mi47K-0005QQ-HM for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:28:10 -0400 Received: from [199.232.76.173] (port=56579 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mi47K-0005QG-BZ for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:28:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55364) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mi47J-0003YO-Rj for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:28:06 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7VAS20c016993 for ; Mon, 31 Aug 2009 06:28:02 -0400 From: Kevin Wolf Date: Mon, 31 Aug 2009 12:26:57 +0200 Message-Id: <1251714417-5909-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2: Fix metadata preallocation List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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