From nobody Tue Feb 10 00:22:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560590397139.33059820742994; Thu, 20 Jul 2017 07:23:10 -0700 (PDT) Received: from localhost ([::1]:38283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCM4-000117-Ss for importer@patchew.org; Thu, 20 Jul 2017 10:23:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK0-0008BX-Kl for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCJy-0007uT-UP for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:56 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:41686 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCJy-0007tj-Ka for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:54 -0400 Received: (qmail 14951 invoked by uid 89); 20 Jul 2017 14:20:51 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.296065 secs); 20 Jul 2017 14:20:51 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:48 -0000 Received: (qmail 5162 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 2D1B026C5D; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:39 +0200 Message-Id: <1500560441-5670-9-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 08/10] block/qcow2: start using the compress format extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" we now pass the parameters to the zlib compressor if the extension is present and use the old default values if the extension is absent. Signed-off-by: Peter Lieven --- block/qcow2-cluster.c | 58 ++++++++++++++++++++++++++++++-----------------= ---- block/qcow2.c | 57 +++++++++++++++++++++++++++--------------------= --- 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f06c08f..6c14d59 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1479,30 +1479,39 @@ again: } =20 static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size, + int compress_format) { - z_stream strm1, *strm =3D &strm1; - int ret, out_len; - - memset(strm, 0, sizeof(*strm)); - - strm->next_in =3D (uint8_t *)buf; - strm->avail_in =3D buf_size; - strm->next_out =3D out_buf; - strm->avail_out =3D out_buf_size; - - ret =3D inflateInit2(strm, -12); - if (ret !=3D Z_OK) - return -1; - ret =3D inflate(strm, Z_FINISH); - out_len =3D strm->next_out - out_buf; - if ((ret !=3D Z_STREAM_END && ret !=3D Z_BUF_ERROR) || - out_len !=3D out_buf_size) { - inflateEnd(strm); - return -1; - } - inflateEnd(strm); - return 0; + int ret =3D 0, out_len; + + switch (compress_format) { + case QCOW2_COMPRESS_FORMAT_ZLIB: + case -1: { + z_stream z_strm =3D {}; + + z_strm.next_in =3D (uint8_t *)buf; + z_strm.avail_in =3D buf_size; + z_strm.next_out =3D out_buf; + z_strm.avail_out =3D out_buf_size; + + ret =3D inflateInit2(&z_strm, -15); + if (ret !=3D Z_OK) { + return -1; + } + ret =3D inflate(&z_strm, Z_FINISH); + out_len =3D z_strm.next_out - out_buf; + ret =3D -(ret !=3D Z_STREAM_END); + inflateEnd(&z_strm); + break; + } + default: + abort(); /* should never reach this point */ + } + + if (out_len !=3D out_buf_size) { + ret =3D -1; + } + return ret; } =20 int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) @@ -1523,7 +1532,8 @@ int qcow2_decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) return ret; } if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0)= { + s->cluster_data + sector_offset, csize, + s->compress_format) < 0) { return -EIO; } s->cluster_cache_offset =3D coffset; diff --git a/block/qcow2.c b/block/qcow2.c index 978e8d2..57249cc 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3391,9 +3391,10 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, ui= nt64_t offset, BDRVQcow2State *s =3D bs->opaque; QEMUIOVector hd_qiov; struct iovec iov; - z_stream strm; - int ret, out_len; - uint8_t *buf, *out_buf, *local_buf =3D NULL; + z_stream z_strm =3D {}; + int z_windowBits =3D -15, z_level =3D Z_DEFAULT_COMPRESSION; + int ret, out_len =3D 0; + uint8_t *buf, *out_buf =3D NULL, *local_buf =3D NULL; uint64_t cluster_offset; =20 if (bytes =3D=3D 0) { @@ -3418,34 +3419,38 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, u= int64_t offset, buf =3D qiov->iov[0].iov_base; } =20 - out_buf =3D g_malloc(s->cluster_size); + switch (s->compress_format) { + case -1: + z_windowBits =3D -12; + case QCOW2_COMPRESS_FORMAT_ZLIB: + out_buf =3D g_malloc(s->cluster_size); + if (s->compress_level > 0) { + z_level =3D s->compress_level; + } =20 - /* best compression, small window, no zlib header */ - memset(&strm, 0, sizeof(strm)); - ret =3D deflateInit2(&strm, Z_DEFAULT_COMPRESSION, - Z_DEFLATED, -12, - 9, Z_DEFAULT_STRATEGY); - if (ret !=3D 0) { - ret =3D -EINVAL; - goto fail; - } + ret =3D deflateInit2(&z_strm, z_level, Z_DEFLATED, z_windowBits, 9, + Z_DEFAULT_STRATEGY); + if (ret !=3D Z_OK) { + ret =3D -EINVAL; + goto fail; + } =20 - strm.avail_in =3D s->cluster_size; - strm.next_in =3D (uint8_t *)buf; - strm.avail_out =3D s->cluster_size; - strm.next_out =3D out_buf; + z_strm.avail_in =3D s->cluster_size; + z_strm.next_in =3D (uint8_t *)buf; + z_strm.avail_out =3D s->cluster_size; + z_strm.next_out =3D out_buf; =20 - ret =3D deflate(&strm, Z_FINISH); - if (ret !=3D Z_STREAM_END && ret !=3D Z_OK) { - deflateEnd(&strm); - ret =3D -EINVAL; - goto fail; - } - out_len =3D strm.next_out - out_buf; + ret =3D deflate(&z_strm, Z_FINISH); + out_len =3D z_strm.next_out - out_buf; + deflateEnd(&z_strm); =20 - deflateEnd(&strm); + ret =3D ret !=3D Z_STREAM_END; + break; + default: + abort(); /* should never reach this point */ + } =20 - if (ret !=3D Z_STREAM_END || out_len >=3D s->cluster_size) { + if (ret || out_len >=3D s->cluster_size) { /* could not compress: write normal cluster */ ret =3D qcow2_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { --=20 1.9.1