From patchwork Thu Feb 7 19:26:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 218978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8546E2C0090 for ; Fri, 8 Feb 2013 06:27:19 +1100 (EST) Received: from localhost ([::1]:50841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3X7p-0000Qq-I1 for incoming@patchwork.ozlabs.org; Thu, 07 Feb 2013 14:27:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:37765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3X7g-0000OC-7b for qemu-devel@nongnu.org; Thu, 07 Feb 2013 14:27:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3X7a-00051u-MY for qemu-devel@nongnu.org; Thu, 07 Feb 2013 14:27:03 -0500 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:36260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3X7a-00051X-FT for qemu-devel@nongnu.org; Thu, 07 Feb 2013 14:26:58 -0500 Received: from localhost (v220110690675601.yourvserver.net.local [127.0.0.1]) by v220110690675601.yourvserver.net (Postfix) with ESMTP id 701BE7280030; Thu, 7 Feb 2013 20:26:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at weilnetz.de Received: from v220110690675601.yourvserver.net ([127.0.0.1]) by localhost (v220110690675601.yourvserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WiR6F60X0Wus; Thu, 7 Feb 2013 20:26:55 +0100 (CET) Received: by v220110690675601.yourvserver.net (Postfix, from userid 1000) id E6C107280046; Thu, 7 Feb 2013 20:26:55 +0100 (CET) From: Stefan Weil To: Anthony Liguori Date: Thu, 7 Feb 2013 20:26:52 +0100 Message-Id: <1360265212-22037-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 78.47.199.172 Cc: Kevin Wolf , Stefan Weil , jcody@redhat.com, qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH for 1.4] block/vpc: Fix size calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Weil The size calculated from the CHS values is not the real image (disk) size, but usually a smaller value. This is caused by rounding effects. Only older operating systems use CHS. Such guests won't be able to use the whole disk. All modern operating systems use the real size. This patch fixes https://bugs.launchpad.net/qemu/+bug/1105670/. Signed-off-by: Stefan Weil Reviewed-by: Stefan Hajnoczi --- This is a rebased extract from my patch series for block/vpc.c. It's the minimum needed to fix the open bug for QEMU 1.4. The rest of the series can be discussed and applied after 1.4. Regards Stefan W. PS. Please excuse a previous personal mail which I had sent with a wrong signature and without addressing qemu-devel. block/vpc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 82229ef..b4ff564 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -34,6 +34,8 @@ #define HEADER_SIZE 512 +#define VHD_SECTOR_SIZE 512 + //#define CACHE enum vhd_type { @@ -204,11 +206,13 @@ static int vpc_open(BlockDriverState *bs, int flags) /* Write 'checksum' back to footer, or else will leave it with zero. */ footer->checksum = be32_to_cpu(checksum); - // The visible size of a image in Virtual PC depends on the geometry - // rather than on the size stored in the footer (the size in the footer - // is too large usually) - bs->total_sectors = (int64_t) - be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl; + /* The visible size of a image in Virtual PC depends on the guest: + * QEMU and other emulators report the real size (here in sectors). + * All modern operating systems use this real size. + * Very old operating systems use CHS values to calculate the total size. + * This calculated size is usually smaller than the real size. + */ + bs->total_sectors = be64_to_cpu(footer->size) / VHD_SECTOR_SIZE; /* Allow a maximum disk size of approximately 2 TB */ if (bs->total_sectors >= 65535LL * 255 * 255) {