From nobody Sun Nov 24 10:26:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725200811046630.3762108072983; Sun, 1 Sep 2024 07:26:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sklWJ-0002Tw-H7; Sun, 01 Sep 2024 10:25:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sklWE-0002F2-R7; Sun, 01 Sep 2024 10:25:30 -0400 Received: from icts-p-cavuit-4.kulnet.kuleuven.be ([134.58.240.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sklWB-0003XT-K2; Sun, 01 Sep 2024 10:25:30 -0400 Received: from icts-p-ceifnet-smtps-0.kuleuven.be (icts-p-ceifnet-smtps.service.icts.svcd [IPv6:2a02:2c40:0:51:144:242:ac11:2e]) by icts-p-cavuit-4.kulnet.kuleuven.be (Postfix) with ESMTP id CDE8615; Sun, 1 Sep 2024 16:25:21 +0200 (CEST) Received: from flutterbat.volkihar.be (236.58-240-81.adsl-dyn.isp.belgacom.be [81.240.58.236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by icts-p-ceifnet-smtps-0.kuleuven.be (Postfix) with ESMTPSA id B1A11D4F7A4C1; Sun, 1 Sep 2024 16:25:21 +0200 (CEST) Received: by flutterbat.volkihar.be (Postfix, from userid 1000) id 7C5B316E208; Sun, 01 Sep 2024 16:25:21 +0200 (CEST) X-KULeuven-Envelope-From: libvirt-e6954efa@volkihar.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: CDE8615.AB8BA X-KULeuven-Information: Katholieke Universiteit Leuven BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: X-CAV-Cluster: smtps X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Vincent Vanlaer To: qemu-devel@nongnu.org Cc: John Snow , Vladimir Sementsov-Ogievskiy , Kevin Wolf , qemu-block@nongnu.org, Hanna Reitz , Vincent Vanlaer Subject: [PATCH v3 2/5] block: move commit_run loop to separate function Date: Sun, 1 Sep 2024 16:24:02 +0200 Message-ID: <20240901142405.3183874-3-libvirt-e6954efa@volkihar.be> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240901142405.3183874-1-libvirt-e6954efa@volkihar.be> References: <20240901142405.3183874-1-libvirt-e6954efa@volkihar.be> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=134.58.240.134; envelope-from=libvirt-e6954efa@volkihar.be; helo=icts-p-cavuit-4.kulnet.kuleuven.be X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1725200812661116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vincent Vanlaer Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 85 ++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/block/commit.c b/block/commit.c index 8dee25b313..9eedd1fa47 100644 --- a/block/commit.c +++ b/block/commit.c @@ -128,6 +128,51 @@ static void commit_clean(Job *job) blk_unref(s->top); } =20 +static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n,= void *buf) { + int ret =3D 0; + bool copy; + bool error_in_source =3D true; + + /* Copy if allocated above the base */ + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), + s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE, + n, NULL, NULL, NULL); + } + + copy =3D (ret >=3D 0 && ret & BDRV_BLOCK_ALLOCATED); + trace_commit_one_iteration(s, offset, *n, ret); + if (copy) { + assert(*n < SIZE_MAX); + + ret =3D blk_co_pread(s->top, offset, *n, buf, 0); + if (ret >=3D 0) { + ret =3D blk_co_pwrite(s->base, offset, *n, buf, 0); + if (ret < 0) { + error_in_source =3D false; + } + } + } + if (ret < 0) { + BlockErrorAction action =3D block_job_error_action(&s->common, s->= on_error, + error_in_source, = -ret); + if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { + return ret; + } else { + *n =3D 0; + return 0; + } + } + /* Publish progress */ + job_progress_update(&s->common.job, *n); + + if (copy) { + block_job_ratelimit_processed_bytes(&s->common, *n); + } + + return 0; +} + static int coroutine_fn commit_run(Job *job, Error **errp) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); @@ -158,9 +203,6 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); =20 for (offset =3D 0; offset < len; offset +=3D n) { - bool copy; - bool error_in_source =3D true; - /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ @@ -168,42 +210,11 @@ static int coroutine_fn commit_run(Job *job, Error **= errp) if (job_is_cancelled(&s->common.job)) { break; } - /* Copy if allocated above the base */ - WITH_GRAPH_RDLOCK_GUARD() { - ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), - s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE, - &n, NULL, NULL, NULL); - } =20 - copy =3D (ret >=3D 0 && ret & BDRV_BLOCK_ALLOCATED); - trace_commit_one_iteration(s, offset, n, ret); - if (copy) { - assert(n < SIZE_MAX); - - ret =3D blk_co_pread(s->top, offset, n, buf, 0); - if (ret >=3D 0) { - ret =3D blk_co_pwrite(s->base, offset, n, buf, 0); - if (ret < 0) { - error_in_source =3D false; - } - } - } - if (ret < 0) { - BlockErrorAction action =3D - block_job_error_action(&s->common, s->on_error, - error_in_source, -ret); - if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { - return ret; - } else { - n =3D 0; - continue; - } - } - /* Publish progress */ - job_progress_update(&s->common.job, n); + ret =3D commit_iteration(s, offset, &n, buf); =20 - if (copy) { - block_job_ratelimit_processed_bytes(&s->common, n); + if (ret < 0) { + return ret; } } =20 --=20 2.44.1