From nobody Mon Feb 9 16:32:43 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 1495540328013985.182127457749; Tue, 23 May 2017 04:52:08 -0700 (PDT) Received: from localhost ([::1]:47958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dD8MA-00078N-OE for importer@patchew.org; Tue, 23 May 2017 07:52:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dD7ux-0000Ab-Ez for qemu-devel@nongnu.org; Tue, 23 May 2017 07:24:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dD7us-0000HV-F2 for qemu-devel@nongnu.org; Tue, 23 May 2017 07:23:59 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:55463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dD7us-00085F-0r; Tue, 23 May 2017 07:23:54 -0400 Received: from [192.168.13.244] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dD7uD-0002iW-SB; Tue, 23 May 2017 13:23:13 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dD7uD-0005Ll-P8; Tue, 23 May 2017 14:23:13 +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=pNRJ0cGcgV6jlNtSye7A43+EdZi4ecivQyu2VCjM4S8=; b=SzAYxfuBD9M7oD7TXAXfPTlUdoBQ39OreFAmH1JfCmpMWjYJpzkLilEO//MAIu52Mw6KLbMeTyhi7e5TXk7eJRZij9A1TQcNDq7kZor/LxfXv0vtWDzshukN3rvj94DohA1jvsABIJZsIURKc/NYnOth99B1rOWs45+ofOHBxVaZRzUJ6tm7mnVuLPybgyVXWEZ8+thlvB6z4Vh114bsH3llwUllMDa17xxq1fQ/mVbXJlnTXBYzNeqZIxmsMQ/MjwuWFyNKKK9i2uY/SPujWAeDvD3HG718Tx4KxuDuGrAuGFI0LsE9P4nPLUrz3HUy/slTTgd7LXeaJkq00SZyYQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 23 May 2017 13:22:58 +0200 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 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 --- 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 6757875ec9..59a0ffba1a 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