From patchwork Mon Apr 22 11:31:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 238485 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 900FE2C014B for ; Mon, 22 Apr 2013 22:00:19 +1000 (EST) Received: from localhost ([::1]:39070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUF0O-0007Dd-7w for incoming@patchwork.ozlabs.org; Mon, 22 Apr 2013 07:33:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUEyN-00044G-KG for qemu-devel@nongnu.org; Mon, 22 Apr 2013 07:31:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUEyM-00021a-9E for qemu-devel@nongnu.org; Mon, 22 Apr 2013 07:31:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUEyM-00021N-13 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 07:31:50 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3MBVmHT008200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Apr 2013 07:31:48 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3MBVfDX031324; Mon, 22 Apr 2013 07:31:47 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Mon, 22 Apr 2013 13:31:17 +0200 Message-Id: <1366630294-18984-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1366630294-18984-1-git-send-email-kwolf@redhat.com> References: <1366630294-18984-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 03/20] qemu-img: do not zero-pad the compressed write buffer 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 Hajnoczi bdrv_write_compressed() does not allow requests that span the end of the device. Therefore it is useless to zero-pad the last cluster and thereby exceed the end of the device. Let image formats handle zero-padding the final compressed cluster, if necessary. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- qemu-img.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 31627b0..cd096a1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1425,12 +1425,8 @@ static int img_convert(int argc, char **argv) } assert (remainder == 0); - if (n < cluster_sectors) { - memset(buf + n * 512, 0, cluster_size - n * 512); - } - if (!buffer_is_zero(buf, cluster_size)) { - ret = bdrv_write_compressed(out_bs, sector_num, buf, - cluster_sectors); + if (!buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)) { + ret = bdrv_write_compressed(out_bs, sector_num, buf, n); if (ret != 0) { error_report("error while compressing sector %" PRId64 ": %s", sector_num, strerror(-ret));