From patchwork Tue Feb 7 09:22:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 139890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D6E5B7224 for ; Tue, 7 Feb 2012 20:19:15 +1100 (EST) Received: from localhost ([::1]:52931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuhCi-0001WF-5o for incoming@patchwork.ozlabs.org; Tue, 07 Feb 2012 04:19:12 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuhCX-0001W5-NO for qemu-devel@nongnu.org; Tue, 07 Feb 2012 04:19:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RuhCT-00049h-GI for qemu-devel@nongnu.org; Tue, 07 Feb 2012 04:19:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuhCT-00048S-4X for qemu-devel@nongnu.org; Tue, 07 Feb 2012 04:18:57 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q179Iujl024985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 Feb 2012 04:18:56 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q179IsKI019245; Tue, 7 Feb 2012 04:18:55 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 7 Feb 2012 10:22:22 +0100 Message-Id: <1328606542-3230-1-git-send-email-kwolf@redhat.com> In-Reply-To: <4F30045B0200009100079F6E@novprvoes0310.provo.novell.com> References: <4F30045B0200009100079F6E@novprvoes0310.provo.novell.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, carnold@suse.com Subject: [Qemu-devel] [PATCH] vpc: Round up image size during fixed image creation 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 The geometry calculation algorithm from the VHD spec rounds the image size down if it doesn't exactly match a geometry. During image conversion, this causes the image to be truncated. For dynamic images, we already have code in place to round up instead, let's do the same for fixed images. Signed-off-by: Kevin Wolf --- block/vpc.c | 23 ++++++++++------------- 1 files changed, 10 insertions(+), 13 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index db6b14b..6b4816f 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -685,24 +685,21 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options) return -EIO; } + /* + * Calculate matching total_size and geometry. Increase the number of + * sectors requested until we get enough (or fail). This ensures that + * qemu-img convert doesn't truncate images, but rather rounds up. + */ total_sectors = total_size / BDRV_SECTOR_SIZE; - if (disk_type == VHD_DYNAMIC) { - /* Calculate matching total_size and geometry. Increase the number of - sectors requested until we get enough (or fail). */ - for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; - i++) { - if (calculate_geometry(total_sectors + i, - &cyls, &heads, &secs_per_cyl)) { - ret = -EFBIG; - goto fail; - } - } - } else { - if (calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl)) { + for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) { + if (calculate_geometry(total_sectors + i, &cyls, &heads, + &secs_per_cyl)) + { ret = -EFBIG; goto fail; } } + total_sectors = (int64_t) cyls * heads * secs_per_cyl; /* Prepare the Hard Disk Footer */