From nobody Sat May 4 16:47:55 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=1564496392; cv=none; d=zoho.com; s=zohoarc; b=eeZNx0hm8ALR7mf5TmVUpgv8SCr/m1oBN/wPIQ6uKnfriRZzhP6m2s3MMss+eUkedy69x2sK+BksrMh1sYUllOOj+V/3Wn1WZitydnGmaxaDoKhyLweVOM0dyRMPGh+9ZNDeFaq/K4A+BID8R+ZakJOF/3T7sS5NvHjFkyonFAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564496392; 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:ARC-Authentication-Results; bh=s+k+ByqDz4WtiAtcNEVNlVsK7RjJB2fcHPHiUrLysiQ=; b=SQQDj56V7jOnvC+s/2uLiOhQGDZxfzpMfpZEh3m/qJPbXKV8AoplOqVy0Om2Dw4QaGYfJ0hH7VVYxxOBlxdR3GmyhKbOhGLY8h0y5E7DYQ6SengvIPJc2hxr5+uLnjfMLmuXXxSnwvXTcxntB+efRevcRphkulfC2lNObxplHAI= 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 1564496392549168.07348262348341; Tue, 30 Jul 2019 07:19:52 -0700 (PDT) Received: from localhost ([::1]:33398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSyc-0003qP-46 for importer@patchew.org; Tue, 30 Jul 2019 10:19:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59352) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSxV-0002IH-I1 for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsSxT-0002ho-NR for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:49374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsSxT-0002g9-Fa; Tue, 30 Jul 2019 10:18:31 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hsSxP-0000jQ-J9; Tue, 30 Jul 2019 17:18:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:18:23 +0300 Message-Id: <20190730141826.709849-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190730141826.709849-1-vsementsov@virtuozzo.com> References: <20190730141826.709849-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 v2 1/4] block: introduce aio task pool 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, stefanha@redhat.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" Common interface for aio task loops. To be used for improving performance of synchronous io loops in qcow2, block-stream, copy-on-read, and may be other places. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/aio_task.h | 52 +++++++++++++++++++ block/aio_task.c | 119 ++++++++++++++++++++++++++++++++++++++++++++ block/Makefile.objs | 2 + 3 files changed, 173 insertions(+) create mode 100644 block/aio_task.h create mode 100644 block/aio_task.c diff --git a/block/aio_task.h b/block/aio_task.h new file mode 100644 index 0000000000..933af1d8e7 --- /dev/null +++ b/block/aio_task.h @@ -0,0 +1,52 @@ +/* + * Aio tasks loops + * + * Copyright (c) 2019 Virtuozzo International GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_AIO_TASK_H +#define BLOCK_AIO_TASK_H + +#include "qemu/coroutine.h" + +typedef struct AioTaskPool AioTaskPool; +typedef struct AioTask AioTask; +typedef int (*AioTaskFunc)(AioTask *task); +struct AioTask { + AioTaskPool *pool; + AioTaskFunc func; + int ret; +}; + +/* + * aio_task_pool_new + * + * The caller is responsible to g_free AioTaskPool pointer after use. + */ +AioTaskPool *aio_task_pool_new(int max_busy_tasks); +int aio_task_pool_status(AioTaskPool *pool); +bool aio_task_pool_empty(AioTaskPool *pool); +void aio_task_pool_start_task(AioTaskPool *pool, AioTask *task); +void aio_task_pool_wait_slot(AioTaskPool *pool); +void aio_task_pool_wait_one(AioTaskPool *pool); +void aio_task_pool_wait_all(AioTaskPool *pool); + +#endif /* BLOCK_AIO_TASK_H */ diff --git a/block/aio_task.c b/block/aio_task.c new file mode 100644 index 0000000000..807be8deb5 --- /dev/null +++ b/block/aio_task.c @@ -0,0 +1,119 @@ +/* + * Aio tasks loops + * + * Copyright (c) 2019 Virtuozzo International GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/aio.h" +#include "aio_task.h" + +struct AioTaskPool { + Coroutine *main_co; + int status; + int max_busy_tasks; + int busy_tasks; + bool wait_done; +}; + +static void aio_task_co(void *opaque) +{ + AioTask *task =3D opaque; + AioTaskPool *pool =3D task->pool; + + assert(pool->busy_tasks < pool->max_busy_tasks); + pool->busy_tasks++; + + task->ret =3D task->func(task); + + pool->busy_tasks--; + + if (task->ret < 0 && pool->status =3D=3D 0) { + pool->status =3D task->ret; + } + + g_free(task); + + if (pool->wait_done) { + pool->wait_done =3D false; + aio_co_wake(pool->main_co); + } +} + +void aio_task_pool_wait_one(AioTaskPool *pool) +{ + assert(pool->busy_tasks > 0); + assert(qemu_coroutine_self() =3D=3D pool->main_co); + + pool->wait_done =3D true; + qemu_coroutine_yield(); + + assert(!pool->wait_done); + assert(pool->busy_tasks < pool->max_busy_tasks); +} + +void aio_task_pool_wait_slot(AioTaskPool *pool) +{ + if (pool->busy_tasks < pool->max_busy_tasks) { + return; + } + + aio_task_pool_wait_one(pool); +} + +void aio_task_pool_wait_all(AioTaskPool *pool) +{ + while (pool->busy_tasks > 0) { + aio_task_pool_wait_one(pool); + } +} + +void aio_task_pool_start_task(AioTaskPool *pool, AioTask *task) +{ + aio_task_pool_wait_slot(pool); + + task->pool =3D pool; + qemu_coroutine_enter(qemu_coroutine_create(aio_task_co, task)); +} + +AioTaskPool *aio_task_pool_new(int max_busy_tasks) +{ + AioTaskPool *pool =3D g_new0(AioTaskPool, 1); + + pool->main_co =3D qemu_coroutine_self(); + pool->max_busy_tasks =3D max_busy_tasks; + + return pool; +} + +int aio_task_pool_status(AioTaskPool *pool) +{ + if (!pool) { + return 0; /* Sugar for lazy allocation of aio pool */ + } + + return pool->status; +} + +bool aio_task_pool_empty(AioTaskPool *pool) +{ + return pool->busy_tasks =3D=3D 0; +} diff --git a/block/Makefile.objs b/block/Makefile.objs index 35f3bca4d9..c2eb8c8769 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -40,6 +40,8 @@ block-obj-y +=3D throttle.o copy-on-read.o =20 block-obj-y +=3D crypto.o =20 +block-obj-y +=3D aio_task.o + common-obj-y +=3D stream.o =20 nfs.o-libs :=3D $(LIBNFS_LIBS) --=20 2.18.0 From nobody Sat May 4 16:47:55 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=1564496392; cv=none; d=zoho.com; s=zohoarc; b=c+jKKSGNpYq6pUiOQljtQHu6hi356o4gQUCWSQ0rcWR5XDKPUiRtCcgP7pmFHmG8qyAivRaRTDWCw1V4Dfu9Om7CB4oQBdGCnmimmkS9vPpOlSEYu09KGeBo+vzmS49tSvGTykpnAxKHrl5AzvRJclRacAnAURnBLTgAiSeM1Ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564496392; 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:ARC-Authentication-Results; bh=DYXcEHxnicwQ0xv1T0ylY2FbgeLfOlGy2+YQM6DlDIA=; b=GcnVkL6DLUXcBRW+ZOLwsFdQDk7KJkva/vGMJ+r8OlyLBjJj4P+HMOLn2Rc4p4cZB6p1YBvUwshWp8UjJz8FZZ0jHgfLB98KDsTVnzQM7tBDYPvIpBeQ9yXFacx9VGFfF96yhP3IOfL8NJs6nW/xV6a5Ize2/gbSi28SihT01jY= 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 1564496392217610.9258445898105; Tue, 30 Jul 2019 07:19:52 -0700 (PDT) Received: from localhost ([::1]:33400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSyg-0003vP-A4 for importer@patchew.org; Tue, 30 Jul 2019 10:19:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59349) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSxV-0002IG-Gq for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsSxT-0002hp-Nn for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:49370) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsSxT-0002gB-FS; Tue, 30 Jul 2019 10:18:31 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hsSxP-0000jQ-Ll; Tue, 30 Jul 2019 17:18:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:18:24 +0300 Message-Id: <20190730141826.709849-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190730141826.709849-1-vsementsov@virtuozzo.com> References: <20190730141826.709849-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 v2 2/4] block/qcow2: refactor qcow2_co_preadv_part 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, stefanha@redhat.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" Further patch will run partial requests of iterations of qcow2_co_preadv in parallel for performance reasons. To prepare for this, separate part which may be parallelized into separate function (qcow2_co_preadv_task). While being here, also separate encrypted clusters reading to own function, like it is done for compressed reading. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 2 +- block/qcow2.c | 206 +++++++++++++++++++++++-------------------- 2 files changed, 112 insertions(+), 96 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 0d43d4f37c..dd80aa11db 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3266,7 +3266,7 @@ 'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev', 'pwritev_zero', 'pwritev_done', 'empty_image_prepare', 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters', - 'cor_write', 'cluster_alloc_space', 'none'] } + 'cor_write', 'cluster_alloc_space', 'none', 'read_encrypted'] } =20 ## # @BlkdebugIOType: diff --git a/block/qcow2.c b/block/qcow2.c index 93ab7edcea..7fa71968b2 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1967,17 +1967,115 @@ out: return ret; } =20 +static coroutine_fn int +qcow2_co_preadv_encrypted(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov, + uint64_t qiov_offset) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + uint8_t *buf; + + assert(bs->encrypted && s->crypto); + assert(bytes <=3D QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); + + /* + * For encrypted images, read everything into a temporary + * contiguous buffer on which the AES functions can work. + * Note, that we can implement enctyption, working on qiov, + * but we must not do decryption in guest buffers for security + * reasons. + */ + + buf =3D qemu_try_blockalign(s->data_file->bs, bytes); + if (buf =3D=3D NULL) { + return -ENOMEM; + } + + BLKDBG_EVENT(bs->file, BLKDBG_READ_ENCRYPTED); + ret =3D bdrv_co_pread(s->data_file, + file_cluster_offset + offset_into_cluster(s, offse= t), + bytes, buf, 0); + if (ret < 0) { + goto fail; + } + + assert((offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); + assert((bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); + if (qcow2_co_decrypt(bs, file_cluster_offset, offset, buf, bytes) < 0)= { + ret =3D -EIO; + goto fail; + } + qemu_iovec_from_buf(qiov, qiov_offset, buf, bytes); + +fail: + qemu_vfree(buf); + + return ret; +} + +static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, + QCow2ClusterType cluster_type, + uint64_t file_cluster_offset, + uint64_t offset, uint64_t byt= es, + QEMUIOVector *qiov, + size_t qiov_offset) +{ + BDRVQcow2State *s =3D bs->opaque; + int offset_in_cluster =3D offset_into_cluster(s, offset); + + switch (cluster_type) { + case QCOW2_CLUSTER_UNALLOCATED: + assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part = */ + + BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); + return bdrv_co_preadv_part(bs->backing, offset, bytes, + qiov, qiov_offset, 0); + + case QCOW2_CLUSTER_COMPRESSED: + return qcow2_co_preadv_compressed(bs, file_cluster_offset, + offset, bytes, qiov, qiov_offset= ); + + case QCOW2_CLUSTER_NORMAL: + if ((file_cluster_offset & 511) !=3D 0) { + return -EIO; + } + + if (bs->encrypted) { + return qcow2_co_preadv_encrypted(bs, file_cluster_offset, + offset, bytes, qiov, qiov_off= set); + } + + BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); + return bdrv_co_preadv_part(s->data_file, + file_cluster_offset + offset_in_cluster, + bytes, qiov, qiov_offset, 0); + + default: + g_assert_not_reached(); + /* + * QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC handled + * in qcow2_co_preadv_part + */ + } + + g_assert_not_reached(); + + return -EIO; +} + static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, uint64_t offset, uint64_t byt= es, QEMUIOVector *qiov, size_t qiov_offset, int flags) { BDRVQcow2State *s =3D bs->opaque; - int offset_in_cluster; int ret; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t cluster_offset =3D 0; - uint8_t *cluster_data =3D NULL; =20 while (bytes !=3D 0) { =20 @@ -1992,111 +2090,29 @@ static coroutine_fn int qcow2_co_preadv_part(Block= DriverState *bs, ret =3D qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_= offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { - goto fail; + return ret; } =20 - offset_in_cluster =3D offset_into_cluster(s, offset); - - switch (ret) { - case QCOW2_CLUSTER_UNALLOCATED: - - if (bs->backing) { - BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_preadv_part(bs->backing, offset, cur_bytes, - qiov, qiov_offset, 0); - if (ret < 0) { - goto fail; - } - } else { - /* Note: in this case, no need to wait */ - qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); - } - break; - - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: + if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || + ret =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || + (ret =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) + { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); - break; - - case QCOW2_CLUSTER_COMPRESSED: - ret =3D qcow2_co_preadv_compressed(bs, cluster_offset, - offset, cur_bytes, - qiov, qiov_offset); + } else { + ret =3D qcow2_co_preadv_task(bs, ret, + cluster_offset, offset, cur_bytes, + qiov, qiov_offset); if (ret < 0) { - goto fail; - } - - break; - - case QCOW2_CLUSTER_NORMAL: - if ((cluster_offset & 511) !=3D 0) { - ret =3D -EIO; - goto fail; - } - - if (bs->encrypted) { - assert(s->crypto); - - /* - * For encrypted images, read everything into a temporary - * contiguous buffer on which the AES functions can work. - */ - if (!cluster_data) { - cluster_data =3D - qemu_try_blockalign(s->data_file->bs, - QCOW_MAX_CRYPT_CLUSTERS - * s->cluster_size); - if (cluster_data =3D=3D NULL) { - ret =3D -ENOMEM; - goto fail; - } - } - - assert(cur_bytes <=3D QCOW_MAX_CRYPT_CLUSTERS * s->cluster= _size); - - BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_pread(s->data_file, - cluster_offset + offset_in_cluster, - cur_bytes, cluster_data, 0); - if (ret < 0) { - goto fail; - } - - assert((offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); - assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); - if (qcow2_co_decrypt(bs, cluster_offset, offset, - cluster_data, cur_bytes) < 0) { - ret =3D -EIO; - goto fail; - } - qemu_iovec_from_buf(qiov, qiov_offset, cluster_data, cur_b= ytes); - } else { - BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_preadv_part(s->data_file, - cluster_offset + offset_in_clust= er, - cur_bytes, qiov, qiov_offset, 0); - if (ret < 0) { - goto fail; - } + return ret; } - break; - - default: - g_assert_not_reached(); - ret =3D -EIO; - goto fail; } =20 bytes -=3D cur_bytes; offset +=3D cur_bytes; qiov_offset +=3D cur_bytes; } - ret =3D 0; - -fail: - qemu_vfree(cluster_data); =20 - return ret; + return 0; } =20 /* Check if it's possible to merge a write request with the writing of --=20 2.18.0 From nobody Sat May 4 16:47:55 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=1564496393; cv=none; d=zoho.com; s=zohoarc; b=mWmVlOgSccLD0zYXA+m9rGciVa5EtvyPBg4k1FQ7D+g3yWqla+SWvTB4jjTh4BLK3l/mWSmkoa4RPDdQjC34HM+j/zr8cSPgRypwcn9ch9soXbsJmf0Fx+kQ7VgPLO9qxMQ4Ebs05LNG/mPBVctuYjquG/ukng9iJZMGT9dx9H0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564496393; 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:ARC-Authentication-Results; bh=/dk1wfH8gMOr3PrzNGBcqlJXnYgD0xCo1/Ekaop8hmI=; b=i+aIeoBY6QTWc5Btdb/fs59ZgrsPEnBClH6Ib95HScoc1KSYrT5bj3C/HALu3BhtEbT6iaxRDjWJdaGYPQcrxaKLsxzwaD+77gi2oEPJ/aXzAAC7Zl+ZBSmZGev4fmYufzdNH+z0yszFiy2zx4NF3jvA8zegh6ydIuuCoPNQ7hY= 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 1564496393515268.7227998686801; Tue, 30 Jul 2019 07:19:53 -0700 (PDT) Received: from localhost ([::1]:33402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSyh-0003xX-3Z for importer@patchew.org; Tue, 30 Jul 2019 10:19:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59347) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSxV-0002IE-GP for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsSxT-0002hV-Jl for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:49376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsSxT-0002g8-Ck; Tue, 30 Jul 2019 10:18:31 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hsSxP-0000jQ-Qs; Tue, 30 Jul 2019 17:18:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:18:25 +0300 Message-Id: <20190730141826.709849-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190730141826.709849-1-vsementsov@virtuozzo.com> References: <20190730141826.709849-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 v2 3/4] block/qcow2: refactor qcow2_co_pwritev_part 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, stefanha@redhat.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" Similarly to previous commit, prepare for parallelizing write-loop iterations. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 150 +++++++++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 62 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7fa71968b2..37766b8b7c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2235,6 +2235,87 @@ static int handle_alloc_space(BlockDriverState *bs, = QCowL2Meta *l2meta) return 0; } =20 +/* + * qcow2_co_pwritev_task + * Called with s->lock unlocked + * l2meta - if not NULL, qcow2_co_do_pwritev() will consume it. Caller mu= st not + * use it somehow after qcow2_co_pwritev_task() call + */ +static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, uint64_t by= tes, + QEMUIOVector *qiov, + uint64_t qiov_offset, + QCowL2Meta *l2meta) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + void *crypt_buf =3D NULL; + int offset_in_cluster =3D offset_into_cluster(s, offset); + QEMUIOVector encrypted_qiov; + + if (bs->encrypted) { + assert(s->crypto); + assert(bytes <=3D QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); + crypt_buf =3D qemu_try_blockalign(bs->file->bs, bytes); + if (crypt_buf =3D=3D NULL) { + ret =3D -ENOMEM; + goto out_unlocked; + } + qemu_iovec_to_buf(qiov, qiov_offset, crypt_buf, bytes); + + if (qcow2_co_encrypt(bs, file_cluster_offset, offset, + crypt_buf, bytes) < 0) { + ret =3D -EIO; + goto out_unlocked; + } + + qemu_iovec_init_buf(&encrypted_qiov, crypt_buf, bytes); + qiov =3D &encrypted_qiov; + qiov_offset =3D 0; + } + + /* Try to efficiently initialize the physical space with zeroes */ + ret =3D handle_alloc_space(bs, l2meta); + if (ret < 0) { + goto out_unlocked; + } + + /* + * If we need to do COW, check if it's possible to merge the + * writing of the guest data together with that of the COW regions. + * If it's not possible (or not necessary) then write the + * guest data now. + */ + if (!merge_cow(offset, bytes, qiov, qiov_offset, l2meta)) { + BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); + trace_qcow2_writev_data(qemu_coroutine_self(), + file_cluster_offset + offset_in_cluster); + ret =3D bdrv_co_pwritev_part(s->data_file, + file_cluster_offset + offset_in_cluster, + bytes, qiov, qiov_offset, 0); + if (ret < 0) { + goto out_unlocked; + } + } + + qemu_co_mutex_lock(&s->lock); + + ret =3D qcow2_handle_l2meta(bs, &l2meta, true); + goto out_locked; + +out_unlocked: + qemu_co_mutex_lock(&s->lock); + +out_locked: + qcow2_handle_l2meta(bs, &l2meta, false); + qemu_co_mutex_unlock(&s->lock); + + qemu_vfree(crypt_buf); + + return ret; +} + static coroutine_fn int qcow2_co_pwritev_part( BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, int flags) @@ -2244,15 +2325,11 @@ static coroutine_fn int qcow2_co_pwritev_part( int ret; unsigned int cur_bytes; /* number of sectors in current iteration */ uint64_t cluster_offset; - QEMUIOVector encrypted_qiov; uint64_t bytes_done =3D 0; - uint8_t *cluster_data =3D NULL; QCowL2Meta *l2meta =3D NULL; =20 trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 - qemu_co_mutex_lock(&s->lock); - while (bytes !=3D 0) { =20 l2meta =3D NULL; @@ -2266,6 +2343,8 @@ static coroutine_fn int qcow2_co_pwritev_part( - offset_in_cluster); } =20 + qemu_co_mutex_lock(&s->lock); + ret =3D qcow2_alloc_cluster_offset(bs, offset, &cur_bytes, &cluster_offset, &l2meta); if (ret < 0) { @@ -2283,62 +2362,11 @@ static coroutine_fn int qcow2_co_pwritev_part( =20 qemu_co_mutex_unlock(&s->lock); =20 - if (bs->encrypted) { - assert(s->crypto); - if (!cluster_data) { - cluster_data =3D qemu_try_blockalign(bs->file->bs, - QCOW_MAX_CRYPT_CLUSTERS - * s->cluster_size); - if (cluster_data =3D=3D NULL) { - ret =3D -ENOMEM; - goto out_unlocked; - } - } - - assert(cur_bytes <=3D QCOW_MAX_CRYPT_CLUSTERS * s->cluster_siz= e); - qemu_iovec_to_buf(qiov, qiov_offset + bytes_done, - cluster_data, cur_bytes); - - if (qcow2_co_encrypt(bs, cluster_offset, offset, - cluster_data, cur_bytes) < 0) { - ret =3D -EIO; - goto out_unlocked; - } - - qemu_iovec_init_buf(&encrypted_qiov, cluster_data, cur_bytes); - } - - /* Try to efficiently initialize the physical space with zeroes */ - ret =3D handle_alloc_space(bs, l2meta); + ret =3D qcow2_co_pwritev_task(bs, cluster_offset, offset, cur_byte= s, + qiov, bytes_done, l2meta); + l2meta =3D NULL; /* l2meta is consumed by qcow2_co_do_pwritev() */ if (ret < 0) { - goto out_unlocked; - } - - /* If we need to do COW, check if it's possible to merge the - * writing of the guest data together with that of the COW regions. - * If it's not possible (or not necessary) then write the - * guest data now. */ - if (!merge_cow(offset, cur_bytes, - bs->encrypted ? &encrypted_qiov : qiov, - bs->encrypted ? 0 : qiov_offset + bytes_done, l2met= a)) - { - BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); - trace_qcow2_writev_data(qemu_coroutine_self(), - cluster_offset + offset_in_cluster); - ret =3D bdrv_co_pwritev_part( - s->data_file, cluster_offset + offset_in_cluster, cur_= bytes, - bs->encrypted ? &encrypted_qiov : qiov, - bs->encrypted ? 0 : qiov_offset + bytes_done, 0); - if (ret < 0) { - goto out_unlocked; - } - } - - qemu_co_mutex_lock(&s->lock); - - ret =3D qcow2_handle_l2meta(bs, &l2meta, true); - if (ret) { - goto out_locked; + goto fail_nometa; } =20 bytes -=3D cur_bytes; @@ -2347,9 +2375,7 @@ static coroutine_fn int qcow2_co_pwritev_part( trace_qcow2_writev_done_part(qemu_coroutine_self(), cur_bytes); } ret =3D 0; - goto out_locked; =20 -out_unlocked: qemu_co_mutex_lock(&s->lock); =20 out_locked: @@ -2357,7 +2383,7 @@ out_locked: =20 qemu_co_mutex_unlock(&s->lock); =20 - qemu_vfree(cluster_data); +fail_nometa: trace_qcow2_writev_done_req(qemu_coroutine_self(), ret); =20 return ret; --=20 2.18.0 From nobody Sat May 4 16:47:55 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=1564496391; cv=none; d=zoho.com; s=zohoarc; b=gpvTYVuoKFWydST9Dq8E8L6FzMyDCKfPAsCcPXLwEg9eUxrIXo4xEM9Z4kp2DEtg+Qfw749RxIGAkRaWQAPruOKRbClcvGWVdDvTh5wLx98PRzTPZuqKP6Bz1RW01cUW4gvayH8TqeDm355GNNf2gfRM+0ZSc/bM0Ewear0iJIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564496391; 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:ARC-Authentication-Results; bh=5Dxn30WcHw1XocK4CEULTUuB7CQPQlNg/FWAQepJR5c=; b=Z9XfgtjfTXFLJQ3pzn+ykDbC+DG2yNuWTS5j8/vorDEIqu9rv3a1TtYhEWLBTmUgvh3EsYN3UsdoR6CQztxOEx+VDZt+0Rshygy/XxlW3zl1cCyEvcurpu1J6+4rwfVM1qJhLjgW+P8RSe9+ahat9Urmv2W5Eg0ITUEX+213qPE= 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 1564496391611576.4151924715502; Tue, 30 Jul 2019 07:19:51 -0700 (PDT) Received: from localhost ([::1]:33404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSyh-000406-RD for importer@patchew.org; Tue, 30 Jul 2019 10:19:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59348) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsSxV-0002IF-Gp for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsSxT-0002hg-NI for qemu-devel@nongnu.org; Tue, 30 Jul 2019 10:18:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:49368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsSxT-0002gC-FD; Tue, 30 Jul 2019 10:18:31 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hsSxP-0000jQ-Tx; Tue, 30 Jul 2019 17:18:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:18:26 +0300 Message-Id: <20190730141826.709849-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190730141826.709849-1-vsementsov@virtuozzo.com> References: <20190730141826.709849-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 v2 4/4] block/qcow2: introduce parallel subrequest handling in read and write 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, stefanha@redhat.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" It improves performance for fragmented qcow2 images. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 125 +++++++++++++++++++++++++++++++++++++++++---- block/trace-events | 1 + 2 files changed, 115 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 37766b8b7c..5f0e66ea48 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -40,6 +40,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" #include "crypto.h" +#include "aio_task.h" =20 /* Differences with QCOW: @@ -2017,6 +2018,62 @@ fail: return ret; } =20 +typedef struct Qcow2AioTask { + AioTask task; + + BlockDriverState *bs; + QCow2ClusterType cluster_type; /* only for read */ + uint64_t file_cluster_offset; + uint64_t offset; + uint64_t bytes; + QEMUIOVector *qiov; + uint64_t qiov_offset; + QCowL2Meta *l2meta; /* only for write */ +} Qcow2AioTask; + +#define QCOW2_MAX_WORKERS 8 + +static coroutine_fn int qcow2_co_preadv_task_entry(AioTask *task); +static coroutine_fn int qcow2_add_task(BlockDriverState *bs, + AioTaskPool *pool, + AioTaskFunc func, + QCow2ClusterType cluster_type, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov, + size_t qiov_offset, + QCowL2Meta *l2meta) +{ + Qcow2AioTask local_task; + Qcow2AioTask *task =3D pool ? g_new(Qcow2AioTask, 1) : &local_task; + + *task =3D (Qcow2AioTask) { + .task.func =3D func, + .bs =3D bs, + .cluster_type =3D cluster_type, + .qiov =3D qiov, + .file_cluster_offset =3D file_cluster_offset, + .offset =3D offset, + .bytes =3D bytes, + .qiov_offset =3D qiov_offset, + .l2meta =3D l2meta, + }; + + trace_qcow2_add_task(qemu_coroutine_self(), bs, pool, + func =3D=3D qcow2_co_preadv_task_entry ? "read" := "write", + cluster_type, file_cluster_offset, offset, bytes, + qiov, qiov_offset); + + if (!pool) { + return func(&task->task); + } + + aio_task_pool_start_task(pool, &task->task); + + return 0; +} + static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, QCow2ClusterType cluster_type, uint64_t file_cluster_offset, @@ -2067,6 +2124,16 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDr= iverState *bs, return -EIO; } =20 +static coroutine_fn int qcow2_co_preadv_task_entry(AioTask *task) +{ + Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); + + assert(!t->l2meta); + + return qcow2_co_preadv_task(t->bs, t->cluster_type, t->file_cluster_of= fset, + t->offset, t->bytes, t->qiov, t->qiov_offs= et); +} + static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, uint64_t offset, uint64_t byt= es, QEMUIOVector *qiov, @@ -2076,9 +2143,9 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, int ret; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t cluster_offset =3D 0; + AioTaskPool *aio =3D NULL; =20 - while (bytes !=3D 0) { - + while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); if (s->crypto) { @@ -2090,7 +2157,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, ret =3D qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_= offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { - return ret; + goto out; } =20 if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || @@ -2099,11 +2166,14 @@ static coroutine_fn int qcow2_co_preadv_part(BlockD= riverState *bs, { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { - ret =3D qcow2_co_preadv_task(bs, ret, - cluster_offset, offset, cur_bytes, - qiov, qiov_offset); + if (!aio && cur_bytes !=3D bytes) { + aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); + } + ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, re= t, + cluster_offset, offset, cur_bytes, + qiov, qiov_offset, NULL); if (ret < 0) { - return ret; + goto out; } } =20 @@ -2112,7 +2182,16 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDr= iverState *bs, qiov_offset +=3D cur_bytes; } =20 - return 0; +out: + 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; } =20 /* Check if it's possible to merge a write request with the writing of @@ -2316,6 +2395,17 @@ out_locked: return ret; } =20 +static coroutine_fn int qcow2_co_pwritev_task_entry(AioTask *task) +{ + Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); + + assert(!t->cluster_type); + + return qcow2_co_pwritev_task(t->bs, t->file_cluster_offset, + t->offset, t->bytes, t->qiov, t->qiov_off= set, + t->l2meta); +} + static coroutine_fn int qcow2_co_pwritev_part( BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, int flags) @@ -2327,10 +2417,11 @@ static coroutine_fn int qcow2_co_pwritev_part( uint64_t cluster_offset; uint64_t bytes_done =3D 0; QCowL2Meta *l2meta =3D NULL; + AioTaskPool *aio =3D NULL; =20 trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 - while (bytes !=3D 0) { + while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { =20 l2meta =3D NULL; =20 @@ -2362,8 +2453,12 @@ static coroutine_fn int qcow2_co_pwritev_part( =20 qemu_co_mutex_unlock(&s->lock); =20 - ret =3D qcow2_co_pwritev_task(bs, cluster_offset, offset, cur_byte= s, - qiov, bytes_done, l2meta); + if (!aio && cur_bytes !=3D bytes) { + aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); + } + ret =3D qcow2_add_task(bs, aio, qcow2_co_pwritev_task_entry, 0, + cluster_offset, offset, cur_bytes, + qiov, bytes_done, l2meta); l2meta =3D NULL; /* l2meta is consumed by qcow2_co_do_pwritev() */ if (ret < 0) { goto fail_nometa; @@ -2384,6 +2479,14 @@ out_locked: qemu_co_mutex_unlock(&s->lock); =20 fail_nometa: + if (aio) { + aio_task_pool_wait_all(aio); + if (ret =3D=3D 0) { + ret =3D aio_task_pool_status(aio); + } + g_free(aio); + } + trace_qcow2_writev_done_req(qemu_coroutine_self(), ret); =20 return ret; diff --git a/block/trace-events b/block/trace-events index d724df0117..7f51550ba3 100644 --- a/block/trace-events +++ b/block/trace-events @@ -61,6 +61,7 @@ file_paio_submit(void *acb, void *opaque, int64_t offset,= int count, int type) " file_copy_file_range(void *bs, int src, int64_t src_off, int dst, int64_t = dst_off, int64_t bytes, int flags, int64_t ret) "bs %p src_fd %d offset %"P= RIu64" dst_fd %d offset %"PRIu64" bytes %"PRIu64" flags %d ret %"PRId64 =20 # qcow2.c +qcow2_add_task(void *co, void *bs, void *pool, const char *action, int clu= ster_type, uint64_t file_cluster_offset, uint64_t offset, uint64_t bytes, v= oid *qiov, size_t qiov_offset) "co %p bs %p pool %p: %s: cluster_type %d fi= le_cluster_offset %" PRIu64 " offset %" PRIu64 " bytes %" PRIu64 " qiov %p = qiov_offset %zu" qcow2_writev_start_req(void *co, int64_t offset, int bytes) "co %p offset = 0x%" PRIx64 " bytes %d" qcow2_writev_done_req(void *co, int ret) "co %p ret %d" qcow2_writev_start_part(void *co) "co %p" --=20 2.18.0