From patchwork Fri Apr 12 17:37:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 236167 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 F38CD2C00B3 for ; Sat, 13 Apr 2013 03:38:19 +1000 (EST) Received: from localhost ([::1]:46724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQhvW-0004dc-89 for incoming@patchwork.ozlabs.org; Fri, 12 Apr 2013 13:38:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQhvB-0004cS-0t for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:38:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQhv5-0007FX-2H for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:37:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQhv4-0007FO-Qy for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:37:50 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3CHboSs028124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 13:37:50 -0400 Received: from localhost (ovpn-112-42.ams2.redhat.com [10.36.112.42]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r3CHbmj0009075; Fri, 12 Apr 2013 13:37:49 -0400 From: Stefan Hajnoczi To: Date: Fri, 12 Apr 2013 19:37:48 +0200 Message-Id: <1365788268-24787-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] qemu-img: refuse to compress files with invalid size 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 Image file compression works at cluster granularity. It is not possible to compress less than a cluster of data at a time. Print an error when attempting qemu-img convert -c with an input file that is not a multiple of the cluster size. I considered automatically adjusting the output file size but think it's better to be explicit. This avoids confusion when users notice that image file size changed after conversion. Signed-off-by: Stefan Hajnoczi Reviewed-by: Benoit Canet --- qemu-img.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 31627b0..2273851 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1370,6 +1370,13 @@ static int img_convert(int argc, char **argv) goto out; } cluster_sectors = cluster_size >> 9; + if (total_sectors % cluster_sectors) { + error_report("compression requires that input file size is a " + "multiple of %d bytes", + cluster_size); + ret = -1; + goto out; + } sector_num = 0; nb_sectors = total_sectors;