From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154109700601782.64544202283935; Thu, 1 Nov 2018 11:30:06 -0700 (PDT) Received: from localhost ([::1]:43482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHj2-0004UH-4l for importer@patchew.org; Thu, 01 Nov 2018 14:29:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002XY-8J for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh8-0007j6-M0 for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh6-0007ew-OC; Thu, 01 Nov 2018 14:27:48 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgy-0002Mo-A5; Thu, 01 Nov 2018 21:27:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:32 +0300 Message-Id: <20181101182738.70462-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/7] qcow2: use Z_OK instead of 0 for deflateInit2 return code check 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use appropriate macro, corresponding to deflateInit2 spec. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 30689b7688..3e9367c449 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3734,7 +3734,7 @@ static ssize_t qcow2_compress(void *dest, const void = *src, size_t size) memset(&strm, 0, sizeof(strm)); ret =3D deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY); - if (ret !=3D 0) { + if (ret !=3D Z_OK) { return -2; } =20 --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154109699750762.492642607351854; Thu, 1 Nov 2018 11:29:57 -0700 (PDT) Received: from localhost ([::1]:43481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHj1-0004Tt-CF for importer@patchew.org; Thu, 01 Nov 2018 14:29:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002XV-8F for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh6-0007iA-V0 for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47964) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh4-0007ex-Hi; Thu, 01 Nov 2018 14:27:47 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgy-0002Mo-GC; Thu, 01 Nov 2018 21:27:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:33 +0300 Message-Id: <20181101182738.70462-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/7] qcow2: make more generic interface for qcow2_compress 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Give explicit size both for source and destination buffers, to make it similar with decompression path and than cleanly reuse parameter structure for decompression threads. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 3e9367c449..9eab2dbfb6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3718,14 +3718,15 @@ fail: /* * qcow2_compress() * - * @dest - destination buffer, at least of @size-1 bytes - * @src - source buffer, @size bytes + * @dest - destination buffer, @dest_size bytes + * @src - source buffer, @src_size bytes * * Returns: compressed size on success - * -1 if compression is inefficient + * -1 destination buffer is not enough to store compressed data * -2 on any other error */ -static ssize_t qcow2_compress(void *dest, const void *src, size_t size) +static ssize_t qcow2_compress(void *dest, size_t dest_size, + const void *src, size_t src_size) { ssize_t ret; z_stream strm; @@ -3740,14 +3741,14 @@ static ssize_t qcow2_compress(void *dest, const voi= d *src, size_t size) =20 /* strm.next_in is not const in old zlib versions, such as those used = on * OpenBSD/NetBSD, so cast the const away */ - strm.avail_in =3D size; + strm.avail_in =3D src_size; strm.next_in =3D (void *) src; - strm.avail_out =3D size - 1; + strm.avail_out =3D dest_size; strm.next_out =3D dest; =20 ret =3D deflate(&strm, Z_FINISH); if (ret =3D=3D Z_STREAM_END) { - ret =3D size - 1 - strm.avail_out; + ret =3D dest_size - strm.avail_out; } else { ret =3D (ret =3D=3D Z_OK ? -1 : -2); } @@ -3761,8 +3762,9 @@ static ssize_t qcow2_compress(void *dest, const void = *src, size_t size) =20 typedef struct Qcow2CompressData { void *dest; + size_t dest_size; const void *src; - size_t size; + size_t src_size; ssize_t ret; } Qcow2CompressData; =20 @@ -3770,7 +3772,8 @@ static int qcow2_compress_pool_func(void *opaque) { Qcow2CompressData *data =3D opaque; =20 - data->ret =3D qcow2_compress(data->dest, data->src, data->size); + data->ret =3D qcow2_compress(data->dest, data->dest_size, + data->src, data->src_size); =20 return 0; } @@ -3782,15 +3785,17 @@ static void qcow2_compress_complete(void *opaque, i= nt ret) =20 /* See qcow2_compress definition for parameters description */ static ssize_t qcow2_co_compress(BlockDriverState *bs, - void *dest, const void *src, size_t size) + void *dest, size_t dest_size, + const void *src, size_t src_size) { BDRVQcow2State *s =3D bs->opaque; BlockAIOCB *acb; ThreadPool *pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); Qcow2CompressData arg =3D { .dest =3D dest, + .dest_size =3D dest_size, .src =3D src, - .size =3D size, + .src_size =3D src_size, }; =20 while (s->nb_compress_threads >=3D MAX_COMPRESS_THREADS) { @@ -3857,7 +3862,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, =20 out_buf =3D g_malloc(s->cluster_size); =20 - out_len =3D qcow2_co_compress(bs, out_buf, buf, s->cluster_size); + out_len =3D qcow2_co_compress(bs, out_buf, s->cluster_size - 1, + buf, s->cluster_size); if (out_len =3D=3D -2) { ret =3D -EINVAL; goto fail; --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541097346165419.63565165185366; Thu, 1 Nov 2018 11:35:46 -0700 (PDT) Received: from localhost ([::1]:43524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHom-00020F-LI for importer@patchew.org; Thu, 01 Nov 2018 14:35:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002Ye-Fx for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh9-0007jn-9E for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh8-0007f0-SN; Thu, 01 Nov 2018 14:27:51 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgy-0002Mo-Jr; Thu, 01 Nov 2018 21:27:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:34 +0300 Message-Id: <20181101182738.70462-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 3/7] qcow2: move decompression from qcow2-cluster.c to qcow2.c 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Compression is done in threads in qcow2.c. We want to do decompression in the same way, so, firstly, move it to the same file. The only change is braces around if-body in decompress_buffer, to satisfy checkpatch. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2-cluster.c | 70 ------------------------------------------ block/qcow2.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index d37fe08b3d..e2737429f5 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1571,76 +1571,6 @@ again: return 0; } =20 -static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) -{ - 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 qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) -{ - BDRVQcow2State *s =3D bs->opaque; - int ret, csize, nb_csectors, sector_offset; - uint64_t coffset; - - coffset =3D cluster_offset & s->cluster_offset_mask; - if (s->cluster_cache_offset !=3D coffset) { - nb_csectors =3D ((cluster_offset >> s->csize_shift) & s->csize_mas= k) + 1; - sector_offset =3D coffset & 511; - csize =3D nb_csectors * 512 - sector_offset; - - /* Allocate buffers on first decompress operation, most images are - * uncompressed and the memory overhead can be avoided. The buffe= rs - * are freed in .bdrv_close(). - */ - if (!s->cluster_data) { - /* one more sector for decompressed data alignment */ - s->cluster_data =3D qemu_try_blockalign(bs->file->bs, - QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); - if (!s->cluster_data) { - return -ENOMEM; - } - } - if (!s->cluster_cache) { - s->cluster_cache =3D g_malloc(s->cluster_size); - } - - BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret =3D bdrv_read(bs->file, coffset >> 9, s->cluster_data, - nb_csectors); - if (ret < 0) { - return ret; - } - if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0)= { - return -EIO; - } - s->cluster_cache_offset =3D coffset; - } - return 0; -} - /* * This discards as many clusters of nb_clusters as possible at once (i.e. * all clusters in the same L2 slice) and returns the number of discarded diff --git a/block/qcow2.c b/block/qcow2.c index 9eab2dbfb6..b45a6c4135 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3758,6 +3758,34 @@ static ssize_t qcow2_compress(void *dest, size_t des= t_size, return ret; } =20 +static int decompress_buffer(uint8_t *out_buf, int out_buf_size, + const uint8_t *buf, int buf_size) +{ + 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; +} + #define MAX_COMPRESS_THREADS 4 =20 typedef struct Qcow2CompressData { @@ -3911,6 +3939,49 @@ fail: return ret; } =20 +int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret, csize, nb_csectors, sector_offset; + uint64_t coffset; + + coffset =3D cluster_offset & s->cluster_offset_mask; + if (s->cluster_cache_offset !=3D coffset) { + nb_csectors =3D ((cluster_offset >> s->csize_shift) & s->csize_mas= k) + 1; + sector_offset =3D coffset & 511; + csize =3D nb_csectors * 512 - sector_offset; + + /* Allocate buffers on first decompress operation, most images are + * uncompressed and the memory overhead can be avoided. The buffe= rs + * are freed in .bdrv_close(). + */ + if (!s->cluster_data) { + /* one more sector for decompressed data alignment */ + s->cluster_data =3D qemu_try_blockalign(bs->file->bs, + QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); + if (!s->cluster_data) { + return -ENOMEM; + } + } + if (!s->cluster_cache) { + s->cluster_cache =3D g_malloc(s->cluster_size); + } + + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); + ret =3D bdrv_read(bs->file, coffset >> 9, s->cluster_data, + nb_csectors); + if (ret < 0) { + return ret; + } + if (decompress_buffer(s->cluster_cache, s->cluster_size, + s->cluster_data + sector_offset, csize) < 0)= { + return -EIO; + } + s->cluster_cache_offset =3D coffset; + } + return 0; +} + static int make_completely_empty(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541097519911319.9956635691459; Thu, 1 Nov 2018 11:38:39 -0700 (PDT) Received: from localhost ([::1]:43538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHra-0004uG-EM for importer@patchew.org; Thu, 01 Nov 2018 14:38:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002Xg-92 for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh9-0007je-3F for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh8-0007ey-O0; Thu, 01 Nov 2018 14:27:50 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgy-0002Mo-RI; Thu, 01 Nov 2018 21:27:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:35 +0300 Message-Id: <20181101182738.70462-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 4/7] qcow2: refactor decompress_buffer 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" - make it look more like a pair of qcow2_compress - rename the function and its parameters - drop extra out_len variable, check filling of output buffer by strm structure itself - fix code style - add some documentation Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2.c | 56 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index b45a6c4135..e9d24b801e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3758,32 +3758,46 @@ static ssize_t qcow2_compress(void *dest, size_t de= st_size, return ret; } =20 -static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) +/* qcow2_decompress() + * + * Decompress some data (not more than @src_size bytes) to produce exactly + * @dest_size bytes. + * + * @dest - destination buffer, @dest_size bytes + * @src - source buffer, @src_size bytes + * + * Returns: 0 on success + * -1 on fail + */ +static ssize_t qcow2_decompress(void *dest, size_t dest_size, + const void *src, size_t src_size) { - z_stream strm1, *strm =3D &strm1; - int ret, out_len; - - memset(strm, 0, sizeof(*strm)); + int ret =3D 0; + z_stream strm; =20 - 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; + memset(&strm, 0, sizeof(strm)); + strm.avail_in =3D src_size; + strm.next_in =3D (void *) src; + strm.avail_out =3D dest_size; + strm.next_out =3D dest; =20 - ret =3D inflateInit2(strm, -12); + 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; + + ret =3D inflate(&strm, Z_FINISH); + if ((ret !=3D Z_STREAM_END && ret !=3D Z_BUF_ERROR) || strm.avail_out = !=3D 0) { + /* We approve Z_BUF_ERROR because we need @dest buffer to be fille= d, but + * @src buffer may be processed partly (because in qcow2 we know s= ize of + * compressed data with precision of one sector) + */ + ret =3D -1; } - inflateEnd(strm); - return 0; + + inflateEnd(&strm); + + return ret; } =20 #define MAX_COMPRESS_THREADS 4 @@ -3973,8 +3987,8 @@ int qcow2_decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) if (ret < 0) { return ret; } - if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0)= { + if (qcow2_decompress(s->cluster_cache, s->cluster_size, + s->cluster_data + sector_offset, csize) < 0) { return -EIO; } s->cluster_cache_offset =3D coffset; --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541097006481330.1441433642415; Thu, 1 Nov 2018 11:30:06 -0700 (PDT) Received: from localhost ([::1]:43480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHj0-0004Tp-Sk for importer@patchew.org; Thu, 01 Nov 2018 14:29:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002Xe-8y for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh9-0007jW-1n for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh8-0007f1-Mp; Thu, 01 Nov 2018 14:27:50 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgz-0002Mo-1D; Thu, 01 Nov 2018 21:27:41 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:36 +0300 Message-Id: <20181101182738.70462-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 5/7] qcow2: use byte-based read in qcow2_decompress_cluster 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Get rid of it here too. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index e9d24b801e..950b9f7ec6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3956,14 +3956,15 @@ fail: int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) { BDRVQcow2State *s =3D bs->opaque; - int ret, csize, nb_csectors, sector_offset; + int ret, csize, nb_csectors; uint64_t coffset; + struct iovec iov; + QEMUIOVector local_qiov; =20 coffset =3D cluster_offset & s->cluster_offset_mask; if (s->cluster_cache_offset !=3D coffset) { nb_csectors =3D ((cluster_offset >> s->csize_shift) & s->csize_mas= k) + 1; - sector_offset =3D coffset & 511; - csize =3D nb_csectors * 512 - sector_offset; + csize =3D nb_csectors * 512 - (coffset & 511); =20 /* Allocate buffers on first decompress operation, most images are * uncompressed and the memory overhead can be avoided. The buffe= rs @@ -3981,14 +3982,17 @@ int qcow2_decompress_cluster(BlockDriverState *bs, = uint64_t cluster_offset) s->cluster_cache =3D g_malloc(s->cluster_size); } =20 + iov.iov_base =3D s->cluster_data; + iov.iov_len =3D csize; + qemu_iovec_init_external(&local_qiov, &iov, 1); + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret =3D bdrv_read(bs->file, coffset >> 9, s->cluster_data, - nb_csectors); + ret =3D bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); if (ret < 0) { return ret; } if (qcow2_decompress(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0) { + s->cluster_data, csize) < 0) { return -EIO; } s->cluster_cache_offset =3D coffset; --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541097173126612.7993056821534; Thu, 1 Nov 2018 11:32:53 -0700 (PDT) Received: from localhost ([::1]:43504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHls-0006rR-CQ for importer@patchew.org; Thu, 01 Nov 2018 14:32:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002XW-8G for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh8-0007jO-Rq for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh8-0007f2-It; Thu, 01 Nov 2018 14:27:50 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgz-0002Mo-5N; Thu, 01 Nov 2018 21:27:41 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:37 +0300 Message-Id: <20181101182738.70462-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 6/7] qcow2: aio support for compressed cluster read 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allocate buffers locally and release qcow2 lock. Than, reads inside qcow2_co_preadv_compressed may be done in parallel, however all decompression is still done synchronously. Let's improve it in the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2.h | 4 --- block/qcow2.c | 93 ++++++++++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 50 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 29c98d87a0..8495d2efbe 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -272,9 +272,6 @@ typedef struct BDRVQcow2State { QEMUTimer *cache_clean_timer; unsigned cache_clean_interval; =20 - uint8_t *cluster_cache; - uint8_t *cluster_data; - uint64_t cluster_cache_offset; QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs; =20 uint64_t *refcount_table; @@ -610,7 +607,6 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t = min_size, bool exact_size); int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); -int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset= ); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 diff --git a/block/qcow2.c b/block/qcow2.c index 950b9f7ec6..678d737044 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -74,6 +74,12 @@ typedef struct { #define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 #define QCOW2_EXT_MAGIC_BITMAPS 0x23852875 =20 +static int qcow2_co_preadv_compressed(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov); + static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filen= ame) { const QCowHeader *cow_header =3D (const void *)buf; @@ -1410,7 +1416,6 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, goto fail; } =20 - s->cluster_cache_offset =3D -1; s->flags =3D flags; =20 ret =3D qcow2_refcount_init(bs); @@ -1910,15 +1915,15 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, break; =20 case QCOW2_CLUSTER_COMPRESSED: - /* add AIO support for compressed blocks ? */ - ret =3D qcow2_decompress_cluster(bs, cluster_offset); + qemu_co_mutex_unlock(&s->lock); + ret =3D qcow2_co_preadv_compressed(bs, cluster_offset, + offset, cur_bytes, + &hd_qiov); + qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto fail; } =20 - qemu_iovec_from_buf(&hd_qiov, 0, - s->cluster_cache + offset_in_cluster, - cur_bytes); break; =20 case QCOW2_CLUSTER_NORMAL: @@ -2054,8 +2059,6 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverS= tate *bs, uint64_t offset, =20 qemu_iovec_init(&hd_qiov, qiov->niov); =20 - s->cluster_cache_offset =3D -1; /* disable compressed cache */ - qemu_co_mutex_lock(&s->lock); =20 while (bytes !=3D 0) { @@ -2219,8 +2222,6 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); =20 - g_free(s->cluster_cache); - qemu_vfree(s->cluster_data); qcow2_refcount_close(bs); qcow2_free_snapshots(bs); } @@ -3397,7 +3398,6 @@ qcow2_co_copy_range_to(BlockDriverState *bs, QCowL2Meta *l2meta =3D NULL; =20 assert(!bs->encrypted); - s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 qemu_co_mutex_lock(&s->lock); =20 @@ -3953,51 +3953,52 @@ fail: return ret; } =20 -int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) +static int qcow2_co_preadv_compressed(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov) { BDRVQcow2State *s =3D bs->opaque; - int ret, csize, nb_csectors; + int ret =3D 0, csize, nb_csectors; uint64_t coffset; + uint8_t *buf, *out_buf; struct iovec iov; QEMUIOVector local_qiov; + int offset_in_cluster =3D offset_into_cluster(s, offset); =20 - coffset =3D cluster_offset & s->cluster_offset_mask; - if (s->cluster_cache_offset !=3D coffset) { - nb_csectors =3D ((cluster_offset >> s->csize_shift) & s->csize_mas= k) + 1; - csize =3D nb_csectors * 512 - (coffset & 511); + coffset =3D file_cluster_offset & s->cluster_offset_mask; + nb_csectors =3D ((file_cluster_offset >> s->csize_shift) & s->csize_ma= sk) + 1; + csize =3D nb_csectors * 512 - (coffset & 511); =20 - /* Allocate buffers on first decompress operation, most images are - * uncompressed and the memory overhead can be avoided. The buffe= rs - * are freed in .bdrv_close(). - */ - if (!s->cluster_data) { - /* one more sector for decompressed data alignment */ - s->cluster_data =3D qemu_try_blockalign(bs->file->bs, - QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); - if (!s->cluster_data) { - return -ENOMEM; - } - } - if (!s->cluster_cache) { - s->cluster_cache =3D g_malloc(s->cluster_size); - } + buf =3D g_try_malloc(csize); + if (!buf) { + return -ENOMEM; + } + iov.iov_base =3D buf; + iov.iov_len =3D csize; + qemu_iovec_init_external(&local_qiov, &iov, 1); =20 - iov.iov_base =3D s->cluster_data; - iov.iov_len =3D csize; - qemu_iovec_init_external(&local_qiov, &iov, 1); + out_buf =3D qemu_blockalign(bs, s->cluster_size); =20 - BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret =3D bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); - if (ret < 0) { - return ret; - } - if (qcow2_decompress(s->cluster_cache, s->cluster_size, - s->cluster_data, csize) < 0) { - return -EIO; - } - s->cluster_cache_offset =3D coffset; + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); + ret =3D bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); + if (ret < 0) { + goto fail; } - return 0; + + if (qcow2_decompress(out_buf, s->cluster_size, buf, csize) < 0) { + ret =3D -EIO; + goto fail; + } + + qemu_iovec_from_buf(qiov, 0, out_buf + offset_in_cluster, bytes); + +fail: + qemu_vfree(out_buf); + g_free(buf); + + return ret; } =20 static int make_completely_empty(BlockDriverState *bs) --=20 2.18.0 From nobody Wed May 8 01:41:19 2024 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541097166673990.2190986255881; Thu, 1 Nov 2018 11:32:46 -0700 (PDT) Received: from localhost ([::1]:43505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHlt-0006s4-8k for importer@patchew.org; Thu, 01 Nov 2018 14:32:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIHhA-0002XZ-8L for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIHh8-0007jE-Nq for qemu-devel@nongnu.org; Thu, 01 Nov 2018 14:27:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:47990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gIHh6-0007f3-UT; Thu, 01 Nov 2018 14:27:50 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gIHgz-0002Mo-BM; Thu, 01 Nov 2018 21:27:41 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 1 Nov 2018 21:27:38 +0300 Message-Id: <20181101182738.70462-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com> References: <20181101182738.70462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 7/7] qcow2: do decompression in threads 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, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do decompression in threads, like it is already done for compression. This improves asynchronous compressed reads performance. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 678d737044..3f1c773b13 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3802,20 +3802,24 @@ static ssize_t qcow2_decompress(void *dest, size_t = dest_size, =20 #define MAX_COMPRESS_THREADS 4 =20 +typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size, + const void *src, size_t src_size); typedef struct Qcow2CompressData { void *dest; size_t dest_size; const void *src; size_t src_size; ssize_t ret; + + Qcow2CompressFunc func; } Qcow2CompressData; =20 static int qcow2_compress_pool_func(void *opaque) { Qcow2CompressData *data =3D opaque; =20 - data->ret =3D qcow2_compress(data->dest, data->dest_size, - data->src, data->src_size); + data->ret =3D data->func(data->dest, data->dest_size, + data->src, data->src_size); =20 return 0; } @@ -3825,10 +3829,10 @@ static void qcow2_compress_complete(void *opaque, i= nt ret) qemu_coroutine_enter(opaque); } =20 -/* See qcow2_compress definition for parameters description */ -static ssize_t qcow2_co_compress(BlockDriverState *bs, - void *dest, size_t dest_size, - const void *src, size_t src_size) +static ssize_t qcow2_co_do_compress(BlockDriverState *bs, + void *dest, size_t dest_size, + const void *src, size_t src_size, + Qcow2CompressFunc func) { BDRVQcow2State *s =3D bs->opaque; BlockAIOCB *acb; @@ -3838,6 +3842,7 @@ static ssize_t qcow2_co_compress(BlockDriverState *bs, .dest_size =3D dest_size, .src =3D src, .src_size =3D src_size, + .func =3D func, }; =20 while (s->nb_compress_threads >=3D MAX_COMPRESS_THREADS) { @@ -3860,6 +3865,22 @@ static ssize_t qcow2_co_compress(BlockDriverState *b= s, return arg.ret; } =20 +static ssize_t qcow2_co_compress(BlockDriverState *bs, + void *dest, size_t dest_size, + const void *src, size_t src_size) +{ + return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, + qcow2_compress); +} + +static ssize_t qcow2_co_decompress(BlockDriverState *bs, + void *dest, size_t dest_size, + const void *src, size_t src_size) +{ + return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, + qcow2_decompress); +} + /* XXX: put compressed sectors first, then all the cluster aligned tables to avoid losing bytes in alignment */ static coroutine_fn int @@ -3987,7 +4008,7 @@ static int qcow2_co_preadv_compressed(BlockDriverStat= e *bs, goto fail; } =20 - if (qcow2_decompress(out_buf, s->cluster_size, buf, csize) < 0) { + if (qcow2_co_decompress(bs, out_buf, s->cluster_size, buf, csize) < 0)= { ret =3D -EIO; goto fail; } --=20 2.18.0