From patchwork Fri Aug 14 19:50:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 31431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 1662CB6F31 for ; Sat, 15 Aug 2009 05:50:50 +1000 (EST) Received: from localhost ([127.0.0.1]:42020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mc2nW-0003bu-A4 for incoming@patchwork.ozlabs.org; Fri, 14 Aug 2009 15:50:46 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mc2n2-0003an-Af for qemu-devel@nongnu.org; Fri, 14 Aug 2009 15:50:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mc2mx-0003Yg-Li for qemu-devel@nongnu.org; Fri, 14 Aug 2009 15:50:15 -0400 Received: from [199.232.76.173] (port=54537 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mc2mx-0003Yd-Dy for qemu-devel@nongnu.org; Fri, 14 Aug 2009 15:50:11 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:57449) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mc2mw-0002yw-SO for qemu-devel@nongnu.org; Fri, 14 Aug 2009 15:50:11 -0400 Received: from flocke.weilnetz.de (p54ADEB6F.dip.t-dialin.net [84.173.235.111]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0MKt2u-1Mc2mp3n7b-000SQu; Fri, 14 Aug 2009 21:50:04 +0200 Received: from stefan by flocke.weilnetz.de with local (Exim 4.69) (envelope-from ) id 1Mc2mo-0001t9-S3; Fri, 14 Aug 2009 21:50:02 +0200 From: Stefan Weil To: qemu-devel@nongnu.org Date: Fri, 14 Aug 2009 21:50:02 +0200 Message-Id: <1250279402-7233-1-git-send-email-weil@mail.berlios.de> X-Mailer: git-send-email 1.5.6.5 X-Provags-ID: V01U2FsdGVkX1/29+O2vyXqayYZdAxTcu8OFj0N7JzYw8MKSok X4gkeghpV1b7o4Aur8UXAku9DlSSFWe+GGifruaIEyaCugAPbw tIaWbvudCOriCJUaUfdrzTuusbM4PRZIrFVD+m7rV/icGVVse2 xdQ== X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH] block/vdi.c: Fix several bugs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org * The code for option '-static' was wrong, so image creation always created static images. * Static images created with qemu-img did not set header entry blocks_allocated. * The size of the block map must be rounded to the next multiple of SECTOR_SIZE, otherwise the block map is only read partially for block map sizes which are not a multiple of SECTOR_SIZE. Signed-off-by: Stefan Weil --- block/vdi.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index db3fe16..b8198ea 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -437,9 +437,9 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags) s->header = header; bmap_size = header.blocks_in_image * sizeof(uint32_t); - s->bmap = qemu_malloc(bmap_size); - if (bdrv_read(s->hd, s->bmap_sector, - (uint8_t *)s->bmap, bmap_size / SECTOR_SIZE) < 0) { + bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE; + s->bmap = qemu_malloc(bmap_size * SECTOR_SIZE); + if (bdrv_read(s->hd, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) < 0) { goto fail_free_bmap; } @@ -817,7 +817,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) #endif #if defined(CONFIG_VDI_STATIC_IMAGE) } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) { - image_type = VDI_TYPE_STATIC; + if (options->value.n) { + image_type = VDI_TYPE_STATIC; + } #endif } options++; @@ -845,6 +847,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) header.disk_size = bytes; header.block_size = block_size; header.blocks_in_image = blocks; + if (image_type == VDI_TYPE_STATIC) { + header.blocks_allocated = blocks; + } uuid_generate(header.uuid_image); uuid_generate(header.uuid_last_snap); /* There is no need to set header.uuid_link or header.uuid_parent here. */