From nobody Tue Feb 10 08:31:19 2026 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=1655203031; cv=none; d=zohomail.com; s=zohoarc; b=Ryg/i9GLakrMdebXZrAILMrbsnmfwxFrpjY9+AdbG+oOVpRtyrg7wkLdP0ryDIdO8xYWYCO88wmsiBjjU17A4Hc4GmJavJEChaJc2HKoxBX8F8C6fws9Yi7zBh2bWhzMSLlkPbc/IQ0Luo4600rTbGJU6iUMNnNyxVtGaJHnN8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655203031; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BNgD/KiMpl4g2nP+eF8gjfR8XFJvAFN8LW/9MVbgWXM=; b=NYdF1wyFWB28uAQ9TsFTazub+y4/wSOkjSaCkN6fcZTs77kdqXQafW3KJ6slG+xJ/h6jx7Xs58aFK7zgix925FeS209B5s78Vc8kkPU0AbKqIRic9sH1BEeGss9zu8bc8DOHy/n8un25m7V/RL/0CJ0rgadwyJO46c+LTC1Ducw= 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 1655203031262565.1738729045305; Tue, 14 Jun 2022 03:37:11 -0700 (PDT) Received: from localhost ([::1]:58420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o13v4-0005O4-6f for importer@patchew.org; Tue, 14 Jun 2022 06:37:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o13ny-0001LJ-2q; Tue, 14 Jun 2022 06:29:50 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:57648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o13nh-0000ke-He; Tue, 14 Jun 2022 06:29:49 -0400 Received: from sas1-9c28cd37d27b.qloud-c.yandex.net (sas1-9c28cd37d27b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:309b:0:640:9c28:cd37]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 868D52E0D43; Tue, 14 Jun 2022 13:29:24 +0300 (MSK) Received: from sas1-c73b4b4f4b95.qloud-c.yandex.net (sas1-c73b4b4f4b95.qloud-c.yandex.net [2a02:6b8:c08:12a9:0:640:c73b:4b4f]) by sas1-9c28cd37d27b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id AcoUs8LFkf-TOJ4lu3p; Tue, 14 Jun 2022 13:29:24 +0300 Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:a427::1:2e]) by sas1-c73b4b4f4b95.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 15x97ivcvu-TNMm7BW2; Tue, 14 Jun 2022 13:29:23 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1655202564; bh=BNgD/KiMpl4g2nP+eF8gjfR8XFJvAFN8LW/9MVbgWXM=; h=Message-Id:References:Date:Subject:In-Reply-To:Cc:To:From; b=Z/VY6LZ0gzYigqMuz8Wao8ijg/aSHLF0a4Z2KCBJX3/qZsHabrEDTn7AtUvuP9+JG QwyV59viEoZobyDqGjV0gW5JpQvTod+F10ayGAEcl/nh75gMmX7qvSAF7NI1Z7VUGX ZiXV6IngnqeVwiB/hQ0ZOwbcHej9xZHzLXZsV0Vc= Authentication-Results: sas1-9c28cd37d27b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy Subject: [PULL 05/10] block/block-copy: block_copy(): add timeout_ns parameter Date: Tue, 14 Jun 2022 13:29:05 +0300 Message-Id: <20220614102910.1431380-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614102910.1431380-1-vsementsov@yandex-team.ru> References: <20220614102910.1431380-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=2a02:6b8:0:1619::183; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.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, 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" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1655203032885100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Add possibility to limit block_copy() call in time. To be used in the next commit. As timed-out block_copy() call will continue in background anyway (we can't immediately cancel IO operation), it's important also give user a possibility to pass a callback, to do some additional actions on block-copy call finish. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 33 ++++++++++++++++++++++++++------- block/copy-before-write.c | 2 +- include/block/block-copy.h | 4 +++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index ec46775ea5..bb947afdda 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -883,23 +883,42 @@ static int coroutine_fn block_copy_common(BlockCopyCa= llState *call_state) return ret; } =20 +static void coroutine_fn block_copy_async_co_entry(void *opaque) +{ + block_copy_common(opaque); +} + int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t byte= s, - bool ignore_ratelimit) + bool ignore_ratelimit, uint64_t timeout_ns, + BlockCopyAsyncCallbackFunc cb, + void *cb_opaque) { - BlockCopyCallState call_state =3D { + int ret; + BlockCopyCallState *call_state =3D g_new(BlockCopyCallState, 1); + + *call_state =3D (BlockCopyCallState) { .s =3D s, .offset =3D start, .bytes =3D bytes, .ignore_ratelimit =3D ignore_ratelimit, .max_workers =3D BLOCK_COPY_MAX_WORKERS, + .cb =3D cb, + .cb_opaque =3D cb_opaque, }; =20 - return block_copy_common(&call_state); -} + ret =3D qemu_co_timeout(block_copy_async_co_entry, call_state, timeout= _ns, + g_free); + if (ret < 0) { + assert(ret =3D=3D -ETIMEDOUT); + block_copy_call_cancel(call_state); + /* call_state will be freed by running coroutine. */ + return ret; + } =20 -static void coroutine_fn block_copy_async_co_entry(void *opaque) -{ - block_copy_common(opaque); + ret =3D call_state->ret; + g_free(call_state); + + return ret; } =20 BlockCopyCallState *block_copy_async(BlockCopyState *s, diff --git a/block/copy-before-write.c b/block/copy-before-write.c index c8a11a09d2..fc13c7cd44 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -111,7 +111,7 @@ static coroutine_fn int cbw_do_copy_before_write(BlockD= riverState *bs, off =3D QEMU_ALIGN_DOWN(offset, cluster_size); end =3D QEMU_ALIGN_UP(offset + bytes, cluster_size); =20 - ret =3D block_copy(s->bcs, off, end - off, true); + ret =3D block_copy(s->bcs, off, end - off, true, 0, NULL, NULL); if (ret < 0 && s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_GUEST_WRITE) { return ret; } diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 68bbd344b2..ba0b425d78 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -40,7 +40,9 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); =20 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, - bool ignore_ratelimit); + bool ignore_ratelimit, uint64_t timeout_ns, + BlockCopyAsyncCallbackFunc cb, + void *cb_opaque); =20 /* * Run block-copy in a coroutine, create corresponding BlockCopyCallState --=20 2.25.1