From nobody Mon Feb 9 03:29:57 2026 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.zoho.com; dkim=fail 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496844636033631.523489491148; Wed, 7 Jun 2017 07:10:36 -0700 (PDT) Received: from localhost ([::1]:44220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIbfN-0000kb-3o for importer@patchew.org; Wed, 07 Jun 2017 10:10:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIbdw-000817-DT for qemu-devel@nongnu.org; Wed, 07 Jun 2017 10:09:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIbdr-0002Yf-A5 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 10:09:04 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:58678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIbdq-0002WK-Kr; Wed, 07 Jun 2017 10:08:59 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dIbdm-0001ga-Kp; Wed, 07 Jun 2017 16:08:54 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dIbdW-0005iI-Rl; Wed, 07 Jun 2017 17:08:38 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=48XUcSn7iGBioE3OVg7ZP37tRWg5gDi2C6kVVy3lAoo=; b=JSKOrKHRMxAvV/VHmY4kZiX9pNTNNEcmoRiYpEC3JZmi+JdVcnCUlXhkbjd8XeSRqHNMvmyPSJAed0G1TW9wo2J4ZDYYnULHig7KKB6RzUqEuQQoQ3Agj0siOrjxT9nn15XUZo25xgFIo5BMlK2+qFaXwn4UU/0xQFWZm9VXkyyFZ9hC0jXnoGLx4nmRgn9MdjmbtTVteqWZVQWgZrVPKCuuTd743cokYSwSCt/F9n6LmWN93v52kRsPCEBEONGkZ45SSB9KGQIIQyPXcGhxvPNMs3mcsjtPYfOJb7iV41Nii/0il+3OwHJP1PNgEVsQo+Sk7ZxfnAT9IQbg6JqtIg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 17:08:27 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 6/7] qcow2: Pass a QEMUIOVector to do_perform_cow_{read, write}() 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: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of passing a single buffer pointer to do_perform_cow_write(), pass a QEMUIOVector. This will allow us to merge the write requests for the COW regions and the actual data into a single one. Although do_perform_cow_read() does not strictly need to change its API, we're doing it here as well for consistency. Signed-off-by: Alberto Garcia Reviewed-by: Manos Pitsidianakis --- block/qcow2-cluster.c | 51 ++++++++++++++++++++++++-----------------------= ---- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8f6bc3d0b9..71609ff7a2 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -406,19 +406,14 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t = sector_num, static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset, unsigned offset_in_cluster, - uint8_t *buffer, - unsigned bytes) + QEMUIOVector *qiov) { - QEMUIOVector qiov; - struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D bytes }; int ret; =20 - if (bytes =3D=3D 0) { + if (qiov->size =3D=3D 0) { return 0; } =20 - qemu_iovec_init_external(&qiov, &iov, 1); - BLKDBG_EVENT(bs->file, BLKDBG_COW_READ); =20 if (!bs->drv) { @@ -430,7 +425,7 @@ static int coroutine_fn do_perform_cow_read(BlockDriver= State *bs, * which can lead to deadlock when block layer copy-on-read is enabled. */ ret =3D bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_clu= ster, - bytes, &qiov, 0); + qiov->size, qiov, 0); if (ret < 0) { return ret; } @@ -462,28 +457,23 @@ static bool coroutine_fn do_perform_cow_encrypt(Block= DriverState *bs, static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, uint64_t cluster_offset, unsigned offset_in_cluster, - uint8_t *buffer, - unsigned bytes) + QEMUIOVector *qiov) { - QEMUIOVector qiov; - struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D bytes }; int ret; =20 - if (bytes =3D=3D 0) { + if (qiov->size =3D=3D 0) { return 0; } =20 - qemu_iovec_init_external(&qiov, &iov, 1); - ret =3D qcow2_pre_write_overlap_check(bs, 0, - cluster_offset + offset_in_cluster, bytes); + cluster_offset + offset_in_cluster, qiov->size); if (ret < 0) { return ret; } =20 BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE); ret =3D bdrv_co_pwritev(bs->file, cluster_offset + offset_in_cluster, - bytes, &qiov, 0); + qiov->size, qiov, 0); if (ret < 0) { return ret; } @@ -780,6 +770,7 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta= *m) unsigned data_bytes =3D end->offset - (start->offset + start->nb_bytes= ); bool merge_reads =3D false; uint8_t *start_buffer, *end_buffer; + QEMUIOVector qiov; int ret; =20 assert(start->nb_bytes <=3D UINT_MAX - end->nb_bytes); @@ -807,22 +798,25 @@ static int perform_cow(BlockDriverState *bs, QCowL2Me= ta *m) /* The part of the buffer where the end region is located */ end_buffer =3D start_buffer + buffer_size - end->nb_bytes; =20 + qemu_iovec_init(&qiov, 3); + qemu_co_mutex_unlock(&s->lock); /* First we read the existing data from both COW regions. We * either read the whole region in one go, or the start and end * regions separately. */ if (merge_reads) { - ret =3D do_perform_cow_read(bs, m->offset, start->offset, - start_buffer, buffer_size); + qemu_iovec_add(&qiov, start_buffer, buffer_size); + ret =3D do_perform_cow_read(bs, m->offset, start->offset, &qiov); } else { - ret =3D do_perform_cow_read(bs, m->offset, start->offset, - start_buffer, start->nb_bytes); + qemu_iovec_add(&qiov, start_buffer, start->nb_bytes); + ret =3D do_perform_cow_read(bs, m->offset, start->offset, &qiov); if (ret < 0) { goto fail; } =20 - ret =3D do_perform_cow_read(bs, m->offset, end->offset, - end_buffer, end->nb_bytes); + qemu_iovec_reset(&qiov); + qemu_iovec_add(&qiov, end_buffer, end->nb_bytes); + ret =3D do_perform_cow_read(bs, m->offset, end->offset, &qiov); } if (ret < 0) { goto fail; @@ -840,14 +834,16 @@ static int perform_cow(BlockDriverState *bs, QCowL2Me= ta *m) } =20 /* And now we can write everything */ - ret =3D do_perform_cow_write(bs, m->alloc_offset, start->offset, - start_buffer, start->nb_bytes); + qemu_iovec_reset(&qiov); + qemu_iovec_add(&qiov, start_buffer, start->nb_bytes); + ret =3D do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov= ); if (ret < 0) { goto fail; } =20 - ret =3D do_perform_cow_write(bs, m->alloc_offset, end->offset, - end_buffer, end->nb_bytes); + qemu_iovec_reset(&qiov); + qemu_iovec_add(&qiov, end_buffer, end->nb_bytes); + ret =3D do_perform_cow_write(bs, m->alloc_offset, end->offset, &qiov); fail: qemu_co_mutex_lock(&s->lock); =20 @@ -861,6 +857,7 @@ fail: } =20 qemu_vfree(start_buffer); + qemu_iovec_destroy(&qiov); return ret; } =20 --=20 2.11.0