From nobody Mon Nov 25 02:09:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1719413542; cv=none; d=zohomail.com; s=zohoarc; b=H6jTlIMURXCsSzjASjoU80Tjp5m6l6Uh5PCeYX/cqyCw+b0okmN8VFQkQu2CJTavW2HtoM15/WbkJQQ3CwJ4headWgwHrpL63nwwQFqNkV8sMPZwLDlEz3BOxSOdeKoB8XiByAP9c2SeAHt4J9dZh9D2JBVd48QGjVAMVvS2CEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719413542; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6YFkVEVHcdtg+ey8WHEMcbq0FjjptYTHFhCj9XTAgY4=; b=dA4oFtaP+ULAidSbYYZaE8kRdjY9VzwUWuv9sHMgxLUDakNd+nzCZ1AQroVOHi3V73J5RNLf8/IzILGg1gtDumc2HvFaK+aCOS7tcSWzussi0FIZriemGswZQe0BaGvHB+h6zegT5mPrZuJ7m2JMehYlAjHdw+7tBaDLWIQVT7s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719413542403217.3304586983163; Wed, 26 Jun 2024 07:52:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMTzF-0000qB-24; Wed, 26 Jun 2024 10:51:05 -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 1sMTzD-0000p8-8P; Wed, 26 Jun 2024 10:51:03 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sMTz9-0005UF-NT; Wed, 26 Jun 2024 10:51:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c16:1680:0:640:d42f:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id A513260D92; Wed, 26 Jun 2024 17:50:54 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b645::1:29]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id eoRt0i0IXKo0-ps725Jpk; Wed, 26 Jun 2024 17:50:53 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1719413453; bh=6YFkVEVHcdtg+ey8WHEMcbq0FjjptYTHFhCj9XTAgY4=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=ndXFqpfOQCzCcHp48F6hRTm5gqRg/95XpfOcLm7MLjdusk2OYp4saQc6/1cAGEosE 3o1PWHb9fWwWXdeLREi7GIMSTH8j/66IlOjsHh5lPJr2kwhNbxARdPnFXKgrwGEwaF HBoGXFk3uc2miMA/4ngxLCWBdVe0AEVH6QnrgMcE= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, jsnow@redhat.com, den@openvz.org, f.ebner@proxmox.com Subject: [PATCH v2 1/3] block/commit: implement final flush Date: Wed, 26 Jun 2024 17:50:36 +0300 Message-Id: <20240626145038.458709-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240626145038.458709-1-vsementsov@yandex-team.ru> References: <20240626145038.458709-1-vsementsov@yandex-team.ru> 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1719413543567100001 Content-Type: text/plain; charset="utf-8" Actually block job is not completed without the final flush. It's rather unexpected to have broken target when job was successfully completed long ago and now we fail to flush or process just crashed/killed. Mirror job already has mirror_flush() for this. So, it's OK. Do this for commit job too. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/block/commit.c b/block/commit.c index 7c3fdcb0ca..81971692a2 100644 --- a/block/commit.c +++ b/block/commit.c @@ -134,6 +134,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) int64_t n =3D 0; /* bytes */ QEMU_AUTO_VFREE void *buf =3D NULL; int64_t len, base_len; + bool need_final_flush =3D true; =20 len =3D blk_co_getlength(s->top); if (len < 0) { @@ -155,8 +156,8 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) =20 buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); =20 - for (offset =3D 0; offset < len; offset +=3D n) { - bool copy; + for (offset =3D 0; offset < len || need_final_flush; offset +=3D n) { + bool copy =3D false; bool error_in_source =3D true; =20 /* Note that even when no rate limit is applied we need to yield @@ -166,22 +167,34 @@ static int coroutine_fn commit_run(Job *job, Error **= errp) if (job_is_cancelled(&s->common.job)) { break; } - /* Copy if allocated above the base */ - ret =3D blk_co_is_allocated_above(s->top, s->base_overlay, true, - offset, COMMIT_BUFFER_SIZE, &n); - copy =3D (ret > 0); - trace_commit_one_iteration(s, offset, n, ret); - if (copy) { - assert(n < SIZE_MAX); =20 - 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 (offset < len) { + /* Copy if allocated above the base */ + ret =3D blk_co_is_allocated_above(s->top, s->base_overlay, tru= e, + offset, COMMIT_BUFFER_SIZE, &n= ); + copy =3D (ret > 0); + 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; + } } } + } else { + assert(need_final_flush); + ret =3D blk_co_flush(s->base); + if (ret < 0) { + error_in_source =3D false; + } else { + need_final_flush =3D false; + } } + if (ret < 0) { BlockErrorAction action =3D block_job_error_action(&s->common, s->on_error, --=20 2.34.1