From patchwork Thu May 6 18:29:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 51860 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 ozlabs.org (Postfix) with ESMTPS id 42D5AB7D27 for ; Fri, 7 May 2010 04:31:52 +1000 (EST) Received: from localhost ([127.0.0.1]:40969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OA5rJ-0006xE-8u for incoming@patchwork.ozlabs.org; Thu, 06 May 2010 14:31:41 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1OA5pf-0006us-Hm for qemu-devel@nongnu.org; Thu, 06 May 2010 14:29:59 -0400 Received: from [140.186.70.92] (port=51138 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OA5pZ-0006o5-SH for qemu-devel@nongnu.org; Thu, 06 May 2010 14:29:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OA5pT-0007r7-OW for qemu-devel@nongnu.org; Thu, 06 May 2010 14:29:53 -0400 Received: from moutng.kundenserver.de ([212.227.17.8]:57943) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OA5pT-0007qT-AI for qemu-devel@nongnu.org; Thu, 06 May 2010 14:29:47 -0400 Received: from flocke.weilnetz.de (p54ADC2A5.dip.t-dialin.net [84.173.194.165]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0LhziI-1NW8FE42iY-00mW4m; Thu, 06 May 2010 20:29:39 +0200 Received: from stefan by flocke.weilnetz.de with local (Exim 4.71) (envelope-from ) id 1OA5pK-0005Gi-2g; Thu, 06 May 2010 20:29:38 +0200 From: Stefan Weil To: QEMU Developers Date: Thu, 6 May 2010 20:29:30 +0200 Message-Id: <1273170570-20087-1-git-send-email-weil@mail.berlios.de> X-Mailer: git-send-email 1.7.0 In-Reply-To: <4BE304DE.3060200@mail.berlios.de> References: <4BE304DE.3060200@mail.berlios.de> MIME-Version: 1.0 X-Provags-ID: V01U2FsdGVkX18jPwEvgxH+KN/zPud2340HYRkJ+lmtDDU5/ft xfFSllKv6QJzYgw9UuiVqTdQzMSUek/TuAOtW5rL0pZ0/V5Yfs cbrmFW6kAt6n+Uvsb7r0DdP7Sjx8XUYlcimMzJaoMOc8fgid+Z ACg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf , =?UTF-8?q?Fran=C3=A7ois=20Revol?= Subject: [Qemu-devel] [PATCH] vdi: Fix image opening and creation for odd disk sizes 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 This patch fixes a regression introduced by commit 95a2f9bc588c3f83375d87b0a9394f89a1bcfada. The fix is based on a patch from Kevin Wolf. Here his comment: "The number of blocks needs to be rounded up to cover all of the virtual hard disk. Without this fix, we can't even open our own images if their size is not a multiple of the block size." While Kevin's patch addressed vdi_create, my modification also fixes vdi_open which now accepts any image which is large enough to hold the blocks. I also decided to keep the original code in vdi_create which rounds down. Rounding works in both directions, and there are good arguments for both, so I just left the original simple code. It is very important to use the rounded value for the new disk size, too - otherwise VirtualBox cannot open our disk image. Cc: Kevin Wolf Cc: François Revol Signed-off-by: Stefan Weil --- block/vdi.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 1d257b4..2213819 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -414,8 +414,8 @@ static int vdi_open(BlockDriverState *bs, int flags) } else if (header.block_size != 1 * MiB) { logout("unsupported block size %u B\n", header.block_size); goto fail; - } else if ((header.disk_size + header.block_size - 1) / header.block_size != - (uint64_t)header.blocks_in_image) { + } else if (header.disk_size < + (uint64_t)header.blocks_in_image * header.block_size) { logout("unexpected block number %u B\n", header.blocks_in_image); goto fail; } else if (!uuid_is_null(header.uuid_link)) { @@ -827,7 +827,10 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) return -errno; } + /* VirtualBox wants a disk size which is a multiple of the block size. */ blocks = bytes / block_size; + bytes = blocks * block_size; + bmap_size = blocks * sizeof(uint32_t); bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE -1));