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 1496844758953206.67622666467275; Wed, 7 Jun 2017 07:12:38 -0700 (PDT) Received: from localhost ([::1]:44232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIbhK-0002Mk-CJ for importer@patchew.org; Wed, 07 Jun 2017 10:12:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIbdw-00081A-Dj 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-0002Yp-Ba for qemu-devel@nongnu.org; Wed, 07 Jun 2017 10:09:04 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:58675) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIbdq-0002WM-L0; 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-0001gW-PS; Wed, 07 Jun 2017 16:08:54 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dIbdW-0005i8-Oh; 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=kJX5IPg7Sky0PAaSdDg7UOd9Ofzb4Ddcdp5THC7OFls=; b=oEF6f2LIFbaZRLaSq/0O5jn8Sxv2viQ7DxJ60JN5C9tP7FqdX8tn4+cHHs2dBlVbbebv44q6h4+WCmVsaIF2uiqfgVGRG7hMdEAFchTyT07ob8IUl6E5mEmXL7qAUby9u/OqLeGi7+1G56znRSMe4Z1iBHCB8yNoGcIYEQFCk9HI/lig5msmhFYV3YgPUohhKLnq1qwW7CApSJXfDnz7MCTwX8Wes9QgbE8pTitoHWfe9FNF3y+LWVM/Q0oAe1LARz9uBn1tX/8/izDvRL1h+npNAfk9WHZmE7pLxgxOKUUhtjbpF5OD48qXTlFYjQud3s2WaPvMIXwxjE4ZGjMqFA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 17:08:24 +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 3/7] qcow2: Make perform_cow() call do_perform_cow() twice 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 calling perform_cow() twice with a different COW region each time, call it just once and make perform_cow() handle both regions. This patch simply moves code around. The next one will do the actual reordering of the COW operations. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- block/qcow2-cluster.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a86c5a75a9..4c03639a72 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -414,6 +414,10 @@ static int coroutine_fn do_perform_cow(BlockDriverStat= e *bs, struct iovec iov; int ret; =20 + if (bytes =3D=3D 0) { + return 0; + } + iov.iov_len =3D bytes; iov.iov_base =3D qemu_try_blockalign(bs, iov.iov_len); if (iov.iov_base =3D=3D NULL) { @@ -751,31 +755,40 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockD= riverState *bs, return cluster_offset; } =20 -static int perform_cow(BlockDriverState *bs, QCowL2Meta *m, Qcow2COWRegion= *r) +static int perform_cow(BlockDriverState *bs, QCowL2Meta *m) { BDRVQcow2State *s =3D bs->opaque; + Qcow2COWRegion *start =3D &m->cow_start; + Qcow2COWRegion *end =3D &m->cow_end; int ret; =20 - if (r->nb_bytes =3D=3D 0) { + if (start->nb_bytes =3D=3D 0 && end->nb_bytes =3D=3D 0) { return 0; } =20 qemu_co_mutex_unlock(&s->lock); - ret =3D do_perform_cow(bs, m->offset, m->alloc_offset, r->offset, r->n= b_bytes); + ret =3D do_perform_cow(bs, m->offset, m->alloc_offset, + start->offset, start->nb_bytes); + if (ret < 0) { + goto fail; + } + + ret =3D do_perform_cow(bs, m->offset, m->alloc_offset, + end->offset, end->nb_bytes); + +fail: qemu_co_mutex_lock(&s->lock); =20 - if (ret < 0) { - return ret; - } - /* * Before we update the L2 table to actually point to the new cluster,= we * need to be sure that the refcounts have been increased and COW was * handled. */ - qcow2_cache_depends_on_flush(s->l2_table_cache); + if (ret =3D=3D 0) { + qcow2_cache_depends_on_flush(s->l2_table_cache); + } =20 - return 0; + return ret; } =20 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) @@ -795,12 +808,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, = QCowL2Meta *m) } =20 /* copy content of unmodified sectors */ - ret =3D perform_cow(bs, m, &m->cow_start); - if (ret < 0) { - goto err; - } - - ret =3D perform_cow(bs, m, &m->cow_end); + ret =3D perform_cow(bs, m); if (ret < 0) { goto err; } --=20 2.11.0