From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URlAL-00039p-2K for qemu-devel@nongnu.org; Mon, 15 Apr 2013 11:18:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URlAH-0006vT-Oz for qemu-devel@nongnu.org; Mon, 15 Apr 2013 11:17:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URlAH-0006vM-IN for qemu-devel@nongnu.org; Mon, 15 Apr 2013 11:17:53 -0400 From: Stefan Hajnoczi Date: Mon, 15 Apr 2013 17:17:33 +0200 Message-Id: <1366039054-32536-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1366039054-32536-1-git-send-email-stefanha@redhat.com> References: <1366039054-32536-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 3/4] qemu-img: do not zero-pad the compressed write buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Ilkka Tengvall , 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 --- 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)); -- 1.8.1.4