From nobody Mon Feb 9 11:32:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=openvz.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649268890591253.98365802865806; Wed, 6 Apr 2022 11:14:50 -0700 (PDT) Received: from localhost ([::1]:47426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncAB7-0003T4-EZ for importer@patchew.org; Wed, 06 Apr 2022 14:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5E-0000OQ-9N for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:44 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]:42894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA5A-0001yS-F8 for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:43 -0400 Received: by mail-lj1-x234.google.com with SMTP id c15so4315857ljr.9 for ; Wed, 06 Apr 2022 11:08:39 -0700 (PDT) Received: from fedora.. ([185.215.60.161]) by smtp.gmail.com with ESMTPSA id a20-20020a194f54000000b0044a9afab7e7sm1904321lfk.290.2022.04.06.11.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1ENmWFN7sIJ5AH9c9BqRXvLC/5EA/2JEQfd9vHLRWLo=; b=rCnzh7A8a0iasWaR+3W5o/oA6Q7Kl0AJj7UZ4Po+mh1v1Ra3P/+PM4oFN7NCFcqPlw HnoIUYe+U0jLVUTY1F4jE+Sn+VbWl0Xd/14OJNaRLDtvTGb+hERdyIk+TRguaxhUj32g Fa+vzOV8WHEZXdt9hKHF3+a0GljZkyHlJ8it2B8OoII4r5dmGTtzJq5nRXz1TgzT8RM1 Vwo8ofM0QSGQ+BREWthSdwKLMZejzPFqEzpYGx+deX+iGPr3dfq86I3w4w1O4BOUXC7T g6Jiv03QwLPpoXyQOTRJDS0ttKgNW3l66aP8+NsStEXUpVrlgmiLeIxwTNhG6J7q+Q1L 0kJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1ENmWFN7sIJ5AH9c9BqRXvLC/5EA/2JEQfd9vHLRWLo=; b=fTp7hO7tG7sZZ6rft5LS+rmoExolWfvgXmTHGT2FGMsJwnBnn0UOS9IiaDgvJcrYMv gLjFawSBw2SJVxiZpuruZDX0f02GC0GbL7Gta8wySlJ+h/+wywOA9LYC1Q+WXSkaWXuj DrnHKd1cyKIjTztnuXu2K86VuTJjnQ4qapsSISsXFJKVOrZTty491io8Bnbnra6tUwYx MbV3R6sPYxAzhhiZ4KqwSoxEjZBnTLj61/49qiPR5oqnZbROk7j8GWnIMBugTLII1JBK Uq9qf/WYLvvYteQ8Fi3t5+lYjNphuAN2v9VqcEi2COkL/heeNkmO7yha2y9zrZzTnXQq DaDQ== X-Gm-Message-State: AOAM531jnuGoX6xD8AMvcaH0s6GzBfv1Vvl9JwCGYQWJErc1G+Dc0Myi eGkz+tdFyjVVMQxX5LaMWkm4Ow== X-Google-Smtp-Source: ABdhPJzJClnjdhpRSYhuRrWmF0+Df6pnnycgnJZaJ/6Lvb94A/3xdBfrzpMm1lJPmJpmC9/eXvuuQQ== X-Received: by 2002:a2e:9e13:0:b0:247:e32a:ddce with SMTP id e19-20020a2e9e13000000b00247e32addcemr6390017ljk.9.1649268518801; Wed, 06 Apr 2022 11:08:38 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 6/7] block/copy-before-write: implement cbw-timeout option Date: Wed, 6 Apr 2022 21:08:00 +0300 Message-Id: <20220406180801.374844-7-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406180801.374844-1-vsementsov@openvz.org> References: <20220406180801.374844-1-vsementsov@openvz.org> 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=2a00:1450:4864:20::234; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x234.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Cc: kwolf@redhat.com, v.sementsov-og@mail.ru, jsnow@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, hreitz@redhat.com, vsementsov@openvz.org, stefanha@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649268892575100001 Content-Type: text/plain; charset="utf-8" In some scenarios, when copy-before-write operations lasts too long time, it's better to cancel it. Most useful would be to use the new option together with on-cbw-error=3Dbreak-snapshot: this way if cbw operation takes too long time we'll just cancel backup process but do not disturb the guest too much. Note the tricky point of realization: we keep additional point in bs->in_fligth during block_copy operation even if it's timed-out. Background "cancelled" block_copy operations will finish at some point and will want to access state. We should care to not free the state in .bdrv_close() earlier. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- qapi/block-core.json | 8 +++++++- block/copy-before-write.c | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 085f1666af..e9cd7e88f6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4206,12 +4206,18 @@ # @on-cbw-error: Behavior on failure of copy-before-write operation. # Default is @break-guest-write. (Since 7.0) # +# @cbw-timeout: Zero means no limit. Non-zero sets the timeout in seconds +# for copy-before-write operation. When a timeout occurs, +# the respective copy-before-write operation will fail, and +# the @on-cbw-error parameter will decide how this failure +# is handled. Default 0. (Since 7.1) +# # Since: 6.2 ## { 'struct': 'BlockdevOptionsCbw', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap', - '*on-cbw-error': 'OnCbwError' } } + '*on-cbw-error': 'OnCbwError', '*cbw-timeout': 'uint32' } } =20 ## # @BlockdevOptions: diff --git a/block/copy-before-write.c b/block/copy-before-write.c index b7487e4ffe..13992d28c2 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -42,6 +42,7 @@ typedef struct BDRVCopyBeforeWriteState { BlockCopyState *bcs; BdrvChild *target; OnCbwError on_cbw_error; + uint32_t cbw_timeout_ns; =20 /* * @lock: protects access to @access_bitmap, @done_bitmap and @@ -83,6 +84,14 @@ static coroutine_fn int cbw_co_preadv( return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 +static void block_copy_cb(void *opaque) +{ + BlockDriverState *bs =3D opaque; + + bs->in_flight--; + aio_wait_kick(); +} + /* * Do copy-before-write operation. * @@ -111,7 +120,16 @@ static coroutine_fn int cbw_do_copy_before_write(Block= DriverState *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, 0, NULL, NULL); + /* + * Increase in_flight, so that in case of timed-out block-copy, the + * remaining background block_copy() request (which can't be immediate= ly + * cancelled by timeout) is presented in bs->in_flight. This way we are + * sure that on bs close() we'll previously wait for all timed-out but= yet + * running block_copy calls. + */ + bs->in_flight++; + ret =3D block_copy(s->bcs, off, end - off, true, s->cbw_timeout_ns, + block_copy_cb, bs); if (ret < 0 && s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_GUEST_WRITE) { return ret; } @@ -377,6 +395,7 @@ static BlockdevOptions *cbw_parse_options(QDict *option= s, Error **errp) */ qdict_extract_subqdict(options, NULL, "bitmap"); qdict_del(options, "on-cbw-error"); + qdict_del(options, "cbw-timeout"); =20 out: visit_free(v); @@ -422,6 +441,8 @@ static int cbw_open(BlockDriverState *bs, QDict *option= s, int flags, } s->on_cbw_error =3D opts->has_on_cbw_error ? opts->on_cbw_error : ON_CBW_ERROR_BREAK_GUEST_WRITE; + s->cbw_timeout_ns =3D opts->has_cbw_timeout ? + opts->cbw_timeout * NANOSECONDS_PER_SECOND : 0; =20 bs->total_sectors =3D bs->file->bs->total_sectors; bs->supported_write_flags =3D BDRV_REQ_WRITE_UNCHANGED | --=20 2.35.1