From nobody Wed Nov 12 16:48:00 2025 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=1571603944; cv=none; d=zoho.com; s=zohoarc; b=OO/r5ChEg5H+OtjOcQ9S8aikwP4127lgFTdH6WCY1sqj8lax2SMLuQ8bdicYK4eikea9wmBYXGB2IxHgFHrMnTqlCL03E8dwB7SRGJ8l3jpm4wtCxnpRyntXyYUZml+78IQzMcIt/TsDBh218eIyIJ0PQyHdRUgNGUO/LiqyhsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571603944; 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=aMX3+uqSKv1OzqLht1+KohFBYVCkVjW/qU8FNnb5oPY=; b=LfNJAKzk1ZMQjmYKVyCYVUZJUF5aceWO6KPUEFc3nA4rnCPoqSzeTUEbiVVPaiRlb9YMBXF2w/MAMI9exWHKuQaEyaZ7I92VcnGlGtyrwBfagJJhtl3l1doKiZYQYMpLmr1Q94yj3eNvdH3+os3I33J68wls4O7+PNZplW8dnsw= 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 1571603944859899.1535554726337; Sun, 20 Oct 2019 13:39:04 -0700 (PDT) Received: from localhost ([::1]:47086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMHyf-00078t-Lm for importer@patchew.org; Sun, 20 Oct 2019 16:39:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51660) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMHx7-0005vR-AU for qemu-devel@nongnu.org; Sun, 20 Oct 2019 16:37:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMHx5-0006Y4-Mz for qemu-devel@nongnu.org; Sun, 20 Oct 2019 16:37:24 -0400 Received: from relay.sw.ru ([185.231.240.75]:58846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMHx5-0006Wy-Fd; Sun, 20 Oct 2019 16:37:23 -0400 Received: from [172.16.25.136] (helo=dhcp-172-16-25-136.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iMHx1-00089m-DA; Sun, 20 Oct 2019 23:37:19 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v5 2/4] qcow2: Allow writing compressed data of multiple clusters Date: Sun, 20 Oct 2019 23:37:06 +0300 Message-Id: <1571603828-185910-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571603828-185910-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1571603828-185910-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, fam@euphon.net, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, stefanha@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 6b29e16..a1e7279 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4156,10 +4156,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) { @@ -4169,32 +4167,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, PREALLOC_MODE_OFF, NULL); - } - - 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); } @@ -4243,6 +4220,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, PREALLOC_MODE_OFF, NULL); + } + + 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