From nobody Wed Nov 5 10:26:00 2025 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 1533664289325834.0355847182318; Tue, 7 Aug 2018 10:51:29 -0700 (PDT) Received: from localhost ([::1]:40255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn68m-0005BV-5r for importer@patchew.org; Tue, 07 Aug 2018 13:51:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn60u-0007Th-5h for qemu-devel@nongnu.org; Tue, 07 Aug 2018 13:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fn60r-00021w-DP for qemu-devel@nongnu.org; Tue, 07 Aug 2018 13:43:20 -0400 Received: from relay.sw.ru ([185.231.240.75]:45014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fn60q-0001xY-Uk; Tue, 07 Aug 2018 13:43:17 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fn60n-0003lt-D1; Tue, 07 Aug 2018 20:43:13 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 7 Aug 2018 20:43:11 +0300 Message-Id: <20180807174311.32454-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180807174311.32454-1-vsementsov@virtuozzo.com> References: <20180807174311.32454-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 7/7] qcow2: async scheme for qcow2_co_pwritev 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" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Start several async requests instead of read chunk by chunk. Iotest 026 output is changed, as because of async io error path has changed. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 47 ++++++++++++++++++++++++++++++----= ---- tests/qemu-iotests/026.out | 18 ++++++++------- tests/qemu-iotests/026.out.nocache | 20 ++++++++-------- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 88b3fb8080..c7501adfc6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1874,6 +1874,7 @@ typedef struct Qcow2WorkerTask { uint64_t offset; uint64_t bytes; uint64_t bytes_done; + QCowL2Meta *l2meta; } Qcow2WorkerTask; =20 typedef int (*Qcow2DoWorkFunc)(BlockDriverState *bs, QEMUIOVector *qiov, @@ -1965,11 +1966,16 @@ static coroutine_fn void qcow2_rw_worker(void *opaq= ue) } } =20 +/* qcow2_rws_add_task +* l2meta - opaque pointer for do_work_func, so behavior depends on +* do_work_func, specified in qcow2_init_rws +*/ static coroutine_fn void qcow2_rws_add_task(Qcow2RWState *rws, uint64_t file_cluster_offset, uint64_t offset, uint64_t bytes, - uint64_t bytes_done) + uint64_t bytes_done, + QCowL2Meta *l2meta) { Qcow2Worker *w; =20 @@ -1980,7 +1986,8 @@ static coroutine_fn void qcow2_rws_add_task(Qcow2RWSt= ate *rws, .file_cluster_offset =3D file_cluster_offset, .offset =3D offset, .bytes =3D bytes, - .bytes_done =3D bytes_done + .bytes_done =3D bytes_done, + .l2meta =3D l2meta }; rws->ret =3D rws->do_work_func(rws->bs, rws->qiov, &task); return; @@ -2006,6 +2013,7 @@ static coroutine_fn void qcow2_rws_add_task(Qcow2RWSt= ate *rws, w->task.offset =3D offset; w->task.bytes =3D bytes; w->task.bytes_done =3D bytes_done; + w->task.l2meta =3D l2meta; =20 qemu_coroutine_enter(w->co); } @@ -2137,7 +2145,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, qemu_co_mutex_unlock(&s->lock); =20 qcow2_rws_add_task(&rws, cluster_offset, offset, cur_bytes, - bytes_done); + bytes_done, NULL); if (rws.ret < 0) { ret =3D rws.ret; goto fail_nolock; @@ -2289,6 +2297,19 @@ fail: return ret; } =20 +static coroutine_fn int qcow2_co_do_pwritev_task(BlockDriverState *bs, + QEMUIOVector *qiov, + Qcow2WorkerTask *task) +{ + return qcow2_co_do_pwritev(bs, + task->file_cluster_offset, + task->offset, + task->bytes, + qiov, + task->bytes_done, + task->l2meta); +} + static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t of= fset, uint64_t bytes, QEMUIOVector *qio= v, int flags) @@ -2299,16 +2320,19 @@ static coroutine_fn int qcow2_co_pwritev(BlockDrive= rState *bs, uint64_t offset, uint64_t bytes_done =3D 0; uint8_t *cluster_data =3D NULL; QCowL2Meta *l2meta =3D NULL; + Qcow2RWState rws =3D {0}; =20 trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 + qcow2_init_rws(&rws, bs, qiov, bytes, qcow2_co_do_pwritev_task); + qemu_iovec_init(&hd_qiov, qiov->niov); =20 s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 qemu_co_mutex_lock(&s->lock); =20 - while (bytes !=3D 0) { + while (bytes !=3D 0 && rws.ret =3D=3D 0) { int offset_in_cluster =3D offset_into_cluster(s, offset); unsigned int cur_bytes =3D MIN(bytes, INT_MAX); /* number of secto= rs in current iteration= */ @@ -2340,11 +2364,11 @@ static coroutine_fn int qcow2_co_pwritev(BlockDrive= rState *bs, uint64_t offset, =20 qemu_co_mutex_unlock(&s->lock); =20 - - ret =3D qcow2_co_do_pwritev(bs, cluster_offset, offset, cur_bytes, - qiov, bytes_done, l2meta); - l2meta =3D NULL; /* l2meta is consumed by qcow2_co_do_pwritev() */ - if (ret < 0) { + qcow2_rws_add_task(&rws, cluster_offset, offset, cur_bytes, bytes_= done, + l2meta); + l2meta =3D NULL; /* l2meta is consumed */ + if (rws.ret < 0) { + ret =3D rws.ret; goto fail_nometa; } =20 @@ -2362,6 +2386,11 @@ fail: =20 qemu_co_mutex_unlock(&s->lock); =20 + qcow2_finalize_rws(&rws); + if (ret =3D=3D 0) { + ret =3D rws.ret; + } + fail_nometa: =20 qemu_iovec_destroy(&hd_qiov); diff --git a/tests/qemu-iotests/026.out b/tests/qemu-iotests/026.out index dd10a82b51..8dd19f1b53 100644 --- a/tests/qemu-iotests/026.out +++ b/tests/qemu-iotests/026.out @@ -481,7 +481,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -55 leaked clusters were found on the image. +119 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -508,7 +508,9 @@ Event: refblock_alloc_write; errno: 28; imm: off; once:= off; write Failed to flush the L2 table cache: No space left on device Failed to flush the refcount block cache: No space left on device write failed: No space left on device -No errors were found on the image. + +64 leaked clusters were found on the image. +This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 Event: refblock_alloc_write; errno: 28; imm: off; once: off; write -b @@ -533,7 +535,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -542,7 +544,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -561,7 +563,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -570,7 +572,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -589,7 +591,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 @@ -598,7 +600,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. =20 =3D=3D=3D L1 growth tests =3D=3D=3D diff --git a/tests/qemu-iotests/026.out.nocache b/tests/qemu-iotests/026.ou= t.nocache index 1ca6cda15c..10218c1aa6 100644 --- a/tests/qemu-iotests/026.out.nocache +++ b/tests/qemu-iotests/026.out.nocache @@ -489,7 +489,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -55 leaked clusters were found on the image. +119 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -516,8 +516,10 @@ Event: refblock_alloc_write; errno: 28; imm: off; once= : off; write Failed to flush the L2 table cache: No space left on device Failed to flush the refcount block cache: No space left on device write failed: No space left on device -No errors were found on the image. -Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 + +64 leaked clusters were found on the image. +This means waste of disk space, but no harm to data. +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 =20 Event: refblock_alloc_write; errno: 28; imm: off; once: off; write -b Failed to flush the L2 table cache: No space left on device @@ -541,7 +543,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -550,7 +552,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -569,7 +571,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -578,7 +580,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -597,7 +599,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -10 leaked clusters were found on the image. +74 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -606,7 +608,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -23 leaked clusters were found on the image. +87 leaked clusters were found on the image. This means waste of disk space, but no harm to data. =20 =3D=3D=3D L1 growth tests =3D=3D=3D --=20 2.11.1