From nobody Thu May 16 12:41:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1573490360; cv=none; d=zoho.com; s=zohoarc; b=gP63PeG/FZRaJeI+N065NIxtl4cNhB/CTdMlw9NfHn+teue3csVEpYS0p766OWco57p0v6gPHzFerA6tKnlqFRO9W8zmX5ook7v4zgoQ9P3F58wk4UkRwJgUxCSuiZOmdD+LwVSikFOdgtAzR2RCtzON+BsFTIAncMhQ5KJWRbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573490360; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=k92blLoht0obYqNjI5KByyLPEVEjbe0z0AV4BuLeMOY=; b=W8csTjzTglU0/5luLx4+yjOetT+pTWFcLZWGmvGW4Br3XaGF+7gyoJTy6esbYM49dGoYaM+2WkQ3UEzXQELqGrpVnIt3vdU5Bmu/4uybzoM5c+G1o2qNSJ06RADBaeMF3FiVoYNTfbfzj5p80UM1R6Faft22gpZw7toBObSIJhE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157349035981265.65842451136098; Mon, 11 Nov 2019 08:39:19 -0800 (PST) Received: from localhost ([::1]:55052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCik-0008Tu-2K for importer@patchew.org; Mon, 11 Nov 2019 11:39:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39622) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCBO-0001ND-WB for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCBN-0003SG-3G for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:50 -0500 Received: from relay.sw.ru ([185.231.240.75]:58210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCBL-0003RT-AD; Mon, 11 Nov 2019 11:04:48 -0500 Received: from dhcp-172-16-25-136.sw.ru ([172.16.25.136]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iUCBC-0003my-OJ; Mon, 11 Nov 2019 19:04:38 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v6 1/3] block: introduce compress filter driver Date: Mon, 11 Nov 2019 19:04:35 +0300 Message-Id: <1573488277-794975-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org 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" Allow writing all the data compressed through the filter driver. The written data will be aligned by the cluster size. Based on the QEMU current implementation, that data can be written to unallocated clusters only. May be used for a backup job. Suggested-by: Max Reitz Signed-off-by: Andrey Shinkevich --- block/Makefile.objs | 1 + block/filter-compress.c | 212 ++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/block-core.json | 10 ++- 3 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 block/filter-compress.c diff --git a/block/Makefile.objs b/block/Makefile.objs index e394fe0..330529b 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -43,6 +43,7 @@ block-obj-y +=3D crypto.o =20 block-obj-y +=3D aio_task.o block-obj-y +=3D backup-top.o +block-obj-y +=3D filter-compress.o =20 common-obj-y +=3D stream.o =20 diff --git a/block/filter-compress.c b/block/filter-compress.c new file mode 100644 index 0000000..a7b0337 --- /dev/null +++ b/block/filter-compress.c @@ -0,0 +1,212 @@ +/* + * Compress filter block driver + * + * Copyright (c) 2019 Virtuozzo International GmbH + * + * Author: + * Andrey Shinkevich + * (based on block/copy-on-read.c by Max Reitz) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "qemu/module.h" + + +static int zip_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + bs->backing =3D bdrv_open_child(NULL, options, "file", bs, &child_file= , false, + errp); + if (!bs->backing) { + return -EINVAL; + } + + bs->supported_write_flags =3D BDRV_REQ_WRITE_UNCHANGED | + BDRV_REQ_WRITE_COMPRESSED | + (BDRV_REQ_FUA & bs->backing->bs->supported_write_flags); + + bs->supported_zero_flags =3D BDRV_REQ_WRITE_UNCHANGED | + ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & + bs->backing->bs->supported_zero_flags); + + return 0; +} + + +#define PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \ + | BLK_PERM_WRITE \ + | BLK_PERM_RESIZE) +#define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) + +static void zip_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + *nperm =3D perm & PERM_PASSTHROUGH; + *nshared =3D (shared & PERM_PASSTHROUGH) | PERM_UNCHANGED; + + /* + * We must not request write permissions for an inactive node, the chi= ld + * cannot provide it. + */ + if (!(bs->open_flags & BDRV_O_INACTIVE)) { + *nperm |=3D BLK_PERM_WRITE_UNCHANGED; + } +} + + +static int64_t zip_getlength(BlockDriverState *bs) +{ + return bdrv_getlength(bs->backing->bs); +} + + +static int coroutine_fn zip_co_truncate(BlockDriverState *bs, int64_t offs= et, + bool exact, PreallocMode prealloc, + Error **errp) +{ + return bdrv_co_truncate(bs->backing, offset, exact, prealloc, errp); +} + + +static int coroutine_fn zip_co_preadv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags) +{ + return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); +} + + +static int coroutine_fn zip_co_preadv_part(BlockDriverState *bs, + uint64_t offset, uint64_t byte= s, + QEMUIOVector *qiov, + size_t qiov_offset, + int flags) +{ + return bdrv_co_preadv_part(bs->backing, offset, bytes, qiov, qiov_offs= et, + flags); +} + + +static int coroutine_fn zip_co_pwritev(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags) +{ + return bdrv_co_pwritev(bs->backing, offset, bytes, qiov, + flags | BDRV_REQ_WRITE_COMPRESSED); +} + + +static int coroutine_fn zip_co_pwritev_part(BlockDriverState *bs, + uint64_t offset, uint64_t byt= es, + QEMUIOVector *qiov, + size_t qiov_offset, int flags) +{ + return bdrv_co_pwritev_part(bs->backing, offset, bytes, qiov, qiov_off= set, + flags | BDRV_REQ_WRITE_COMPRESSED); +} + + +static int coroutine_fn zip_co_pwrite_zeroes(BlockDriverState *bs, + int64_t offset, int bytes, + BdrvRequestFlags flags) +{ + return bdrv_co_pwrite_zeroes(bs->backing, offset, bytes, flags); +} + + +static int coroutine_fn zip_co_pdiscard(BlockDriverState *bs, + int64_t offset, int bytes) +{ + return bdrv_co_pdiscard(bs->backing, offset, bytes); +} + + +static void zip_refresh_limits(BlockDriverState *bs, Error **errp) +{ + BlockDriverInfo bdi; + int ret; + + if (!bs->backing) { + return; + } + + ret =3D bdrv_get_info(bs->backing->bs, &bdi); + if (ret < 0 || bdi.cluster_size =3D=3D 0) { + return; + } + + bs->backing->bs->bl.request_alignment =3D bdi.cluster_size; + bs->backing->bs->bl.max_transfer =3D bdi.cluster_size; +} + + +static void zip_eject(BlockDriverState *bs, bool eject_flag) +{ + bdrv_eject(bs->backing->bs, eject_flag); +} + + +static void zip_lock_medium(BlockDriverState *bs, bool locked) +{ + bdrv_lock_medium(bs->backing->bs, locked); +} + + +static bool zip_recurse_is_first_non_filter(BlockDriverState *bs, + BlockDriverState *candidate) +{ + return bdrv_recurse_is_first_non_filter(bs->backing->bs, candidate); +} + + +static BlockDriver bdrv_compress =3D { + .format_name =3D "compress", + + .bdrv_open =3D zip_open, + .bdrv_child_perm =3D zip_child_perm, + + .bdrv_getlength =3D zip_getlength, + .bdrv_co_truncate =3D zip_co_truncate, + + .bdrv_co_preadv =3D zip_co_preadv, + .bdrv_co_preadv_part =3D zip_co_preadv_part, + .bdrv_co_pwritev =3D zip_co_pwritev, + .bdrv_co_pwritev_part =3D zip_co_pwritev_part, + .bdrv_co_pwrite_zeroes =3D zip_co_pwrite_zeroes, + .bdrv_co_pdiscard =3D zip_co_pdiscard, + .bdrv_refresh_limits =3D zip_refresh_limits, + + .bdrv_eject =3D zip_eject, + .bdrv_lock_medium =3D zip_lock_medium, + + .bdrv_co_block_status =3D bdrv_co_block_status_from_back= ing, + + .bdrv_recurse_is_first_non_filter =3D zip_recurse_is_first_non_filte= r, + + .has_variable_length =3D true, + .is_filter =3D true, +}; + +static void bdrv_compress_init(void) +{ + bdrv_register(&bdrv_compress); +} + +block_init(bdrv_compress_init); diff --git a/qapi/block-core.json b/qapi/block-core.json index aa97ee2..33d8cd8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2884,15 +2884,16 @@ # @copy-on-read: Since 3.0 # @blklogwrites: Since 3.0 # @blkreplay: Since 4.2 +# @compress: Since 4.2 # # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', - 'cloop', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluste= r', - 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', - 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qco= w', - 'qcow2', 'qed', 'quorum', 'raw', 'rbd', + 'cloop', 'copy-on-read', 'compress', 'dmg', 'file', 'ftp', 'ft= ps', + 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscs= i', + 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', + 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, 'sheepdog', 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxh= s' ] } @@ -4045,6 +4046,7 @@ 'bochs': 'BlockdevOptionsGenericFormat', 'cloop': 'BlockdevOptionsGenericFormat', 'copy-on-read':'BlockdevOptionsGenericFormat', + 'compress': 'BlockdevOptionsGenericFormat', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', 'ftp': 'BlockdevOptionsCurlFtp', --=20 1.8.3.1 From nobody Thu May 16 12:41:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1573489325; cv=none; d=zoho.com; s=zohoarc; b=fJl9Z6tlPS4M90P0UPRMQmSkI7RTXFruexzPFfp420Y42+77I9GvayVItqjL/+BlecSRu5kyNuHZd5fVWJZDdYYSLWgciG1K2necBhhs5mYqtgPrLGGPNTbzRFXMoZ5pi3kFHWwrovWIRxld1ck5CYdWQHeNmU/rIR1olp0iaAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573489325; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=EYQR8dA8q0nSWMRZRj/+nN+ijQu/W8zRHt2S/xsyxSc=; b=frWTaBeODv/4L4hkg1vXPB+Wv31BXt+iS8JjuxHW1BnK2i2RRYiuE5NCqJc/j9O7m8rtaIFyGlu+iNjbfOtOuerpTLPs55v/O8nmUFoqmkdPjJuDul4/a5wwOWjMxQ/myhAlcY2em7SohpIbKevV+/qmuirMBuLhyJ9mJ6H2MuE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573489325031251.44384145007757; Mon, 11 Nov 2019 08:22:05 -0800 (PST) Received: from localhost ([::1]:54820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCS2-0005Of-8j for importer@patchew.org; Mon, 11 Nov 2019 11:22:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39617) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCBO-0001MT-Sy for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCBN-0003SN-3u for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:50 -0500 Received: from relay.sw.ru ([185.231.240.75]:58220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCBL-0003RV-An; Mon, 11 Nov 2019 11:04:49 -0500 Received: from dhcp-172-16-25-136.sw.ru ([172.16.25.136]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iUCBC-0003my-Rx; Mon, 11 Nov 2019 19:04:38 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v6 2/3] qcow2: Allow writing compressed data of multiple clusters Date: Mon, 11 Nov 2019 19:04:36 +0300 Message-Id: <1573488277-794975-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org 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" QEMU currently supports writing compressed data of the size equal to one cluster. This patch allows writing QCOW2 compressed data that exceed one cluster. Now, we split buffered data into separate clusters and write them compressed using the existing functionality. Suggested-by: Pavel Butsykin Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 102 ++++++++++++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7c18721..0e03a1a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4222,10 +4222,8 @@ fail: return ret; } =20 -/* XXX: put compressed sectors first, then all the cluster aligned - tables to avoid losing bytes in alignment */ static coroutine_fn int -qcow2_co_pwritev_compressed_part(BlockDriverState *bs, +qcow2_co_pwritev_compressed_task(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) { @@ -4235,32 +4233,11 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *= bs, uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 - if (has_data_file(bs)) { - return -ENOTSUP; - } - - if (bytes =3D=3D 0) { - /* align end of file to a sector boundary to ease reading with - sector based I/Os */ - int64_t len =3D bdrv_getlength(bs->file->bs); - if (len < 0) { - return len; - } - return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, N= ULL); - } - - if (offset_into_cluster(s, offset)) { - return -EINVAL; - } + assert(bytes =3D=3D s->cluster_size || (bytes < s->cluster_size && + (offset + bytes =3D=3D bs->total_sectors << BDRV_SECTOR_BITS))); =20 buf =3D qemu_blockalign(bs, s->cluster_size); - if (bytes !=3D s->cluster_size) { - if (bytes > s->cluster_size || - offset + bytes !=3D bs->total_sectors << BDRV_SECTOR_BITS) - { - qemu_vfree(buf); - return -EINVAL; - } + if (bytes < s->cluster_size) { /* Zero-pad last write if image size is not cluster aligned */ memset(buf + bytes, 0, s->cluster_size - bytes); } @@ -4309,6 +4286,77 @@ fail: return ret; } =20 +static coroutine_fn int qcow2_co_pwritev_compressed_task_entry(AioTask *ta= sk) +{ + Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); + + assert(!t->cluster_type && !t->l2meta); + + return qcow2_co_pwritev_compressed_task(t->bs, t->offset, t->bytes, t-= >qiov, + t->qiov_offset); +} + +/* + * XXX: put compressed sectors first, then all the cluster aligned + * tables to avoid losing bytes in alignment + */ +static coroutine_fn int +qcow2_co_pwritev_compressed_part(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset) +{ + BDRVQcow2State *s =3D bs->opaque; + AioTaskPool *aio =3D NULL; + int ret =3D 0; + + if (has_data_file(bs)) { + return -ENOTSUP; + } + + if (bytes =3D=3D 0) { + /* + * align end of file to a sector boundary to ease reading with + * sector based I/Os + */ + int64_t len =3D bdrv_getlength(bs->file->bs); + if (len < 0) { + return len; + } + return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, N= ULL); + } + + if (offset_into_cluster(s, offset)) { + return -EINVAL; + } + + while (bytes && aio_task_pool_status(aio) =3D=3D 0) { + uint64_t chunk_size =3D MIN(bytes, s->cluster_size); + + if (!aio && chunk_size !=3D bytes) { + aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); + } + + ret =3D qcow2_add_task(bs, aio, qcow2_co_pwritev_compressed_task_e= ntry, + 0, 0, offset, chunk_size, qiov, qiov_offset, = NULL); + if (ret < 0) { + break; + } + qiov_offset +=3D chunk_size; + offset +=3D chunk_size; + bytes -=3D chunk_size; + } + + if (aio) { + aio_task_pool_wait_all(aio); + if (ret =3D=3D 0) { + ret =3D aio_task_pool_status(aio); + } + g_free(aio); + } + + return ret; +} + static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t file_cluster_offset, --=20 1.8.3.1 From nobody Thu May 16 12:41:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1573489501; cv=none; d=zoho.com; s=zohoarc; b=atv1Jt4kKo8UdKMOuxMRZrocrZExLQBAbZ7sBDPxe4j8F4U4aSvtoMHK+CBy0ebCwLEREMo9fCSDIcoiNvz2eDRjFt5GfQl/n2BSjIFLgem5awXDhqQV4Hw0NCWpuxfhrqAgxwsl5gfU6x7GPvPQWP9Opy256rXxz9eNbt/3hdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573489501; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Slgn5faTns9SXSdiak22fh5BV8nvu0YlBLHzL5VHGBQ=; b=ZTvItgu8HILbcHKH5TivK9EEdOTQAS7E06hwVoj85IHhe9hY7Ej+MpYfF0OXtGGSzaM2bfqpj4Ht9p1hbCxhFLklm7QIxSewPk9VQm6ogYvSt4Q6S/xk1j9fF+n4iZCxS1Lke/l8p/Q1oj8paP21HiNyiWifeFEpD3rS2sLiSZI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573489501006733.2156654241447; Mon, 11 Nov 2019 08:25:01 -0800 (PST) Received: from localhost ([::1]:54866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCUm-0000rG-Gq for importer@patchew.org; Mon, 11 Nov 2019 11:24:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39614) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUCBO-0001Lz-RT for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUCBN-0003SB-2X for qemu-devel@nongnu.org; Mon, 11 Nov 2019 11:04:50 -0500 Received: from relay.sw.ru ([185.231.240.75]:58216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUCBL-0003RU-AD; Mon, 11 Nov 2019 11:04:48 -0500 Received: from dhcp-172-16-25-136.sw.ru ([172.16.25.136]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iUCBC-0003my-WE; Mon, 11 Nov 2019 19:04:39 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v6 3/3] tests/qemu-iotests: add case to write compressed data of multiple clusters Date: Mon, 11 Nov 2019 19:04:37 +0300 Message-Id: <1573488277-794975-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1573488277-794975-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org 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" Add the case to the iotest #214 that checks possibility of writing compressed data of more than one cluster size. The test case involves the compress filter driver showing a sample usage of that. Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/214 | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/214.out | 14 ++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/tests/qemu-iotests/214 b/tests/qemu-iotests/214 index 21ec8a2..5012112 100755 --- a/tests/qemu-iotests/214 +++ b/tests/qemu-iotests/214 @@ -89,6 +89,49 @@ _check_test_img -r all $QEMU_IO -c "read -P 0x11 0 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _fi= lter_testdir $QEMU_IO -c "read -P 0x22 4M 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _fi= lter_testdir =20 +echo +echo "=3D=3D=3D Write compressed data of multiple clusters =3D=3D=3D" +echo +cluster_size=3D0x10000 +_make_test_img 2M -o cluster_size=3D$cluster_size + +echo "Write uncompressed data:" +let data_size=3D"8 * $cluster_size" +$QEMU_IO -c "write -P 0xaa 0 $data_size" "$TEST_IMG" \ + 2>&1 | _filter_qemu_io | _filter_testdir +sizeA=3D$($QEMU_IMG info --output=3Djson "$TEST_IMG" | + sed -n '/"actual-size":/ s/[^0-9]//gp') + +_make_test_img 2M -o cluster_size=3D$cluster_size +echo "Write compressed data:" +let data_size=3D"3 * $cluster_size + ($cluster_size / 2)" +# Set compress=3Don. That will align the written data +# by the cluster size and will write them compressed. +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT \ +$QEMU_IO -c "write -P 0xbb 0 $data_size" --image-opts \ + "driver=3Dcompress,file.driver=3D$IMGFMT,file.file.driver=3Dfile,= file.file.filename=3D$TEST_IMG" \ + 2>&1 | _filter_qemu_io | _filter_testdir + +let offset=3D"4 * $cluster_size" +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT \ +$QEMU_IO -c "write -P 0xcc $offset $data_size" "json:{\ + 'driver': 'compress', + 'file': {'driver': '$IMGFMT', + 'file': {'driver': 'file', + 'filename': '$TEST_IMG'}}}" | \ + _filter_qemu_io | _filter_testdir + +sizeB=3D$($QEMU_IMG info --output=3Djson "$TEST_IMG" | + sed -n '/"actual-size":/ s/[^0-9]//gp') + +if [ $sizeA -le $sizeB ] +then + echo "Compression ERROR" +fi + +$QEMU_IMG check --output=3Djson "$TEST_IMG" | + sed -n 's/,$//; /"compressed-clusters":/ s/^ *//p' + # success, all done echo '*** done' rm -f $seq.full diff --git a/tests/qemu-iotests/214.out b/tests/qemu-iotests/214.out index 0fcd8dc..4a2ec33 100644 --- a/tests/qemu-iotests/214.out +++ b/tests/qemu-iotests/214.out @@ -32,4 +32,18 @@ read 4194304/4194304 bytes at offset 0 4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 4194304/4194304 bytes at offset 4194304 4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Write compressed data of multiple clusters =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2097152 +Write uncompressed data: +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2097152 +Write compressed data: +wrote 229376/229376 bytes at offset 0 +224 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 229376/229376 bytes at offset 262144 +224 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +"compressed-clusters": 8 *** done --=20 1.8.3.1