From nobody Sun Feb 8 12:38:52 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 1648806532706576.1448635178523; Fri, 1 Apr 2022 02:48:52 -0700 (PDT) Received: from localhost ([::1]:59102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDtj-0006sK-M7 for importer@patchew.org; Fri, 01 Apr 2022 05:48:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRW-0000Gf-NM for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:44 -0400 Received: from [2a00:1450:4864:20::22e] (port=43859 helo=mail-lj1-x22e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRU-0006se-Uq for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:42 -0400 Received: by mail-lj1-x22e.google.com with SMTP id b43so3057382ljr.10 for ; Fri, 01 Apr 2022 02:19:36 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:34 -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=63KOcHkFUD4WLCydVmQXmoksEDdiR3xCGd3+SRNPvy4=; b=YC5zoMu5N14vxV6JFMDQSRZRKYC2L7P9k/hMWjgr8IJ5dfoWvtSRwXCeXl5e9QNhxJ p/Yh4zgFf02ASAxslGB25Dicxnk2Xe3nD73CPqn1+u2WWFkMtIgrMHcu9degneL/Iw8R DV56K//pdnSJeA4+T2FA6nmFqqQRjJ3kPAZCbwz3XLVfmqnIxVkZ1DLdkXV9BqxsEw/A z2xKF9yzu3dbnLDCzfS17d3youLUe+KTgQFTRf9TUmGf2aLDeQaIB/b/xNnKKn98bsRx YhWkmJys94Mgl6Mrhsy3KM3yiD2UvJRqNYbaKl3qjnXxcSKEl5u5aQkCapEae+Xup2w0 0fww== 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=63KOcHkFUD4WLCydVmQXmoksEDdiR3xCGd3+SRNPvy4=; b=iTMBTsUxuNgaA4Wt+QWloaaEbOpiGe2LvbX2kNeJKj59y78ZT1oVYApCzXw5nJYAZG FrfE/9kktbSkupeRtiffm5PFqKJUWcnUQ9z3MIeYY1TtyyJN63054BQ5vDBYKR03GANd A2xRkElC+yx+EDKrwdMFoGeurauFycA/dRUT7CzsGgzyE1zr3qgozspiZnL3WZ/RPaD/ 4GcqGOlRPqbidc7zdLWmeeYTUbI+sUgffD52I8gkZTxfbrt/MET5aJNujDOv6SVuyTY8 yFeAgXS3ZSBvc2RfdoJ8oyt7hfEoxhFYoTfFpIl1B4CrbT98+CB4HOHSX44PCLdAyaO9 PgNQ== X-Gm-Message-State: AOAM531Ahgo8WYFJDcjUckfAun16Vhs3cdpvrizAW5ysCJ/mKJS/hSo9 QZ4TVCbK57gC/EKNSOdsJIVDhw== X-Google-Smtp-Source: ABdhPJyJZNrKghyQU8lIbJVCUUIVWnsMPoIPCmfxIvK6o/1OjJDGuyk4pHFxwbK0y1hZKDBb3G9Hxw== X-Received: by 2002:a2e:2e16:0:b0:24a:f25e:41e with SMTP id u22-20020a2e2e16000000b0024af25e041emr6422545lju.45.1648804774864; Fri, 01 Apr 2022 02:19:34 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 1/7] block/copy-before-write: refactor option parsing Date: Fri, 1 Apr 2022 12:19:14 +0300 Message-Id: <20220401091920.287612-2-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::22e (failed) 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::22e; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x22e.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648806533445100001 Content-Type: text/plain; charset="utf-8" We are going to add one more option of enum type. Let's refactor option parsing so that we can simply work with BlockdevOptionsCbw object. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/copy-before-write.c | 68 +++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index a8a06fdc09..394e73b094 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -24,6 +24,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/qmp/qjson.h" =20 #include "sysemu/block-backend.h" #include "qemu/cutils.h" @@ -328,46 +329,49 @@ static void cbw_child_perm(BlockDriverState *bs, Bdrv= Child *c, } } =20 -static bool cbw_parse_bitmap_option(QDict *options, BdrvDirtyBitmap **bitm= ap, - Error **errp) +static BlockdevOptionsCbw *cbw_parse_options(QDict *options, Error **errp) { - QDict *bitmap_qdict =3D NULL; - BlockDirtyBitmap *bmp_param =3D NULL; + QDict *cbw_qdict =3D NULL; + BlockdevOptionsCbw *opts =3D NULL; Visitor *v =3D NULL; - bool ret =3D false; =20 - *bitmap =3D NULL; + cbw_qdict =3D qdict_clone_shallow(options); =20 - qdict_extract_subqdict(options, &bitmap_qdict, "bitmap."); - if (!qdict_size(bitmap_qdict)) { - ret =3D true; - goto out; - } - - v =3D qobject_input_visitor_new_flat_confused(bitmap_qdict, errp); + /* + * Delete BlockdevOptions base fields, that are not part of + * BlockdevOptionsCbw. + */ + qdict_del(cbw_qdict, "driver"); + qdict_del(cbw_qdict, "node-name"); + qdict_del(cbw_qdict, "discard"); + qdict_del(cbw_qdict, "cache"); + qdict_extract_subqdict(cbw_qdict, NULL, "cache."); + qdict_del(cbw_qdict, "read-only"); + qdict_del(cbw_qdict, "auto-read-only"); + qdict_del(cbw_qdict, "force-share"); + qdict_del(cbw_qdict, "detect-zeroes"); + + v =3D qobject_input_visitor_new_flat_confused(cbw_qdict, errp); if (!v) { goto out; } =20 - visit_type_BlockDirtyBitmap(v, NULL, &bmp_param, errp); - if (!bmp_param) { - goto out; - } - - *bitmap =3D block_dirty_bitmap_lookup(bmp_param->node, bmp_param->name= , NULL, - errp); - if (!*bitmap) { + visit_type_BlockdevOptionsCbw(v, NULL, &opts, errp); + if (!opts) { goto out; } =20 - ret =3D true; + /* + * Delete options which we are going to parse through BlockdevOptionsC= bw + * object for original options. + */ + qdict_extract_subqdict(options, NULL, "bitmap"); =20 out: - qapi_free_BlockDirtyBitmap(bmp_param); visit_free(v); - qobject_unref(bitmap_qdict); + qobject_unref(cbw_qdict); =20 - return ret; + return opts; } =20 static int cbw_open(BlockDriverState *bs, QDict *options, int flags, @@ -376,6 +380,12 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, BDRVCopyBeforeWriteState *s =3D bs->opaque; BdrvDirtyBitmap *bitmap =3D NULL; int64_t cluster_size; + g_autoptr(BlockdevOptionsCbw) opts =3D NULL; + + opts =3D cbw_parse_options(options, errp); + if (!opts) { + return -EINVAL; + } =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, @@ -390,8 +400,12 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, return -EINVAL; } =20 - if (!cbw_parse_bitmap_option(options, &bitmap, errp)) { - return -EINVAL; + if (opts->has_bitmap) { + bitmap =3D block_dirty_bitmap_lookup(opts->bitmap->node, + opts->bitmap->name, NULL, errp); + if (!bitmap) { + return -EINVAL; + } } =20 bs->total_sectors =3D bs->file->bs->total_sectors; --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648805012441547.055930270505; Fri, 1 Apr 2022 02:23:32 -0700 (PDT) Received: from localhost ([::1]:47040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDVD-0003sF-Bp for importer@patchew.org; Fri, 01 Apr 2022 05:23:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRY-0000Hh-FH for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: from [2a00:1450:4864:20::22c] (port=45621 helo=mail-lj1-x22c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRU-0006sk-W0 for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:43 -0400 Received: by mail-lj1-x22c.google.com with SMTP id q14so3042601ljc.12 for ; Fri, 01 Apr 2022 02:19:36 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:35 -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=ViEHEA0d9uGyAW6tQbnNNxaf+SfwsruQbjKtBfxNGc4=; b=51k6CfCRQW/N83/SBuEwjwusB6K0BzbCDzCypBbImftYN/ixPULgDiGbJv5mS0KpUX RZTMfYeV/tAeRTIZLit4/iti58TyDVLk724C5sLlHJ9M+Kp1PtudkybFUVeDwoFkm6NX hF/yODnhvdhgPAvGQnmoL4Gph0PtL1fnqxzI7AAMcNqVDyEfLMbR3hIBrtD0NtZ64puk BC3lRlO1r+5E1ZEM0ojgyIIEo9gFLdqXxj4/4Lksbf81njyQzBpD/3xRsE0Qblo1Q9MW qzlFRvfJdG2oNd4D6Xh0rM6LzG/SUujoemXdpEwOn1bOPord0K02pkmuOkBq6wCHGrzD jMVw== 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=ViEHEA0d9uGyAW6tQbnNNxaf+SfwsruQbjKtBfxNGc4=; b=ANnhD47VbMDTLYcBHc8XF2KHdWgLz52dEVyuZd2c8qosIieO+URGHltxKHt5sm1dh+ 4EuWrndZVotv7Zf2kUnr2DBrmtl4GdT8ixzgX8iDx+G87LkRrEUyLeWjJ7/+QQa6GoH7 gopnkl3PWhQD5w8YWb3QwZXyKJvkAySDXHyoukxx648jh9ifu9FTkVxfR7XiR6nAmqYG GxcuIwE95lo47nPL2LM6yRH++ldqG/w+47hzlKYvDmYM3Qqm8Wo3jBvFIviNNd0Ltdmn Cdkcgmdsrg7Fw+TnvzN4ysyzI9D+UIFDpSVS96P65LpNo0v3tPLm0HWINhE/8ZjDZizq 33wQ== X-Gm-Message-State: AOAM531Zg0f5NTzggpshrfJss43+HW2TCK2ouaBPv0n6qmiwO6uYZ1hI cWJM4/ot2Elu5SlxQE/+yDFHFA== X-Google-Smtp-Source: ABdhPJyo2GO4w8+yhUqSisJTcX91gX2JH+QIwMa1cGmEFXSFvfL7cIdMioyB2p2FQ0v9VpxJ77z2jQ== X-Received: by 2002:a2e:9dc7:0:b0:24a:ff6a:c145 with SMTP id x7-20020a2e9dc7000000b0024aff6ac145mr2237797ljj.334.1648804775544; Fri, 01 Apr 2022 02:19:35 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 2/7] block/copy-before-write: add on-cbw-error open parameter Date: Fri, 1 Apr 2022 12:19:15 +0300 Message-Id: <20220401091920.287612-3-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::22c (failed) 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::22c; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x22c.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648805014751100001 Content-Type: text/plain; charset="utf-8" Currently, behavior on copy-before-write operation failure is simple: report error to the guest. Let's implement alternative behavior: break the whole copy-before-write process (and corresponding backup job or NBD client) but keep guest working. It's needed if we consider guest stability as more important. The realisation is simple: on copy-before-write failure we immediately continue guest write operation and set s->snapshot_ret variable which will lead to all further and in-flight snapshot-API requests failure. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/copy-before-write.c | 62 ++++++++++++++++++++++++++++++++++----- qapi/block-core.json | 27 ++++++++++++++++- 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 394e73b094..0614c3d08b 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -41,6 +41,7 @@ typedef struct BDRVCopyBeforeWriteState { BlockCopyState *bcs; BdrvChild *target; + OnCbwError on_cbw_error; =20 /* * @lock: protects access to @access_bitmap, @done_bitmap and @@ -65,6 +66,14 @@ typedef struct BDRVCopyBeforeWriteState { * node. These areas must not be rewritten by guest. */ BlockReqList frozen_read_reqs; + + /* + * @snapshot_error is normally zero. But on first copy-before-write fa= ilure + * when @on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_SNAPSHOT, @snapshot_er= ror takes + * value of this error (<0). After that all in-flight and further + * snaoshot-API requests will fail with that error. + */ + int snapshot_error; } BDRVCopyBeforeWriteState; =20 static coroutine_fn int cbw_co_preadv( @@ -99,11 +108,25 @@ static coroutine_fn int cbw_do_copy_before_write(Block= DriverState *bs, end =3D QEMU_ALIGN_UP(offset + bytes, cluster_size); =20 ret =3D block_copy(s->bcs, off, end - off, true); - if (ret < 0) { + if (ret < 0 && s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_GUEST_WRITE) { return ret; } =20 WITH_QEMU_LOCK_GUARD(&s->lock) { + if (ret < 0) { + assert(s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_SNAPSHOT); + if (!s->snapshot_error) { + s->snapshot_error =3D ret; + } + /* + * No need to wait for s->frozen_read_reqs: they will fail any= way, + * as s->snapshot_error is set. + * + * We return 0, as error is handled. Guest operation should be + * continued. + */ + return 0; + } bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off); reqlist_wait_all(&s->frozen_read_reqs, off, end - off, &s->lock); } @@ -176,6 +199,11 @@ static BlockReq *cbw_snapshot_read_lock(BlockDriverSta= te *bs, =20 QEMU_LOCK_GUARD(&s->lock); =20 + if (s->snapshot_error) { + g_free(req); + return NULL; + } + if (bdrv_dirty_bitmap_next_zero(s->access_bitmap, offset, bytes) !=3D = -1) { g_free(req); return NULL; @@ -198,19 +226,26 @@ static BlockReq *cbw_snapshot_read_lock(BlockDriverSt= ate *bs, return req; } =20 -static void cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq *req) +static int cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq *req) { BDRVCopyBeforeWriteState *s =3D bs->opaque; =20 if (req->offset =3D=3D -1 && req->bytes =3D=3D -1) { g_free(req); - return; + /* + * No real need to read snapshot_error under mutex here: we are ac= tually + * safe to ignore it and return 0, as this request was to s->targe= t, and + * can't be influenced by guest write. But if we can new read nega= tive + * s->snapshot_error let's return it, so that backup failed earlie= r. + */ + return s->snapshot_error; } =20 QEMU_LOCK_GUARD(&s->lock); =20 reqlist_remove_req(req); g_free(req); + return s->snapshot_error; } =20 static coroutine_fn int @@ -219,7 +254,7 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, { BlockReq *req; BdrvChild *file; - int ret; + int ret, ret2; =20 /* TODO: upgrade to async loop using AioTask */ while (bytes) { @@ -232,10 +267,13 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t = offset, int64_t bytes, =20 ret =3D bdrv_co_preadv_part(file, offset, cur_bytes, qiov, qiov_offset, 0); - cbw_snapshot_read_unlock(bs, req); + ret2 =3D cbw_snapshot_read_unlock(bs, req); if (ret < 0) { return ret; } + if (ret2 < 0) { + return ret2; + } =20 bytes -=3D cur_bytes; offset +=3D cur_bytes; @@ -253,7 +291,7 @@ cbw_co_snapshot_block_status(BlockDriverState *bs, { BDRVCopyBeforeWriteState *s =3D bs->opaque; BlockReq *req; - int ret; + int ret, ret2; int64_t cur_bytes; BdrvChild *child; =20 @@ -273,7 +311,14 @@ cbw_co_snapshot_block_status(BlockDriverState *bs, assert(ret & BDRV_BLOCK_ALLOCATED); } =20 - cbw_snapshot_read_unlock(bs, req); + ret2 =3D cbw_snapshot_read_unlock(bs, req); + + if (ret < 0) { + return ret; + } + if (ret2 < 0) { + return ret2; + } =20 return ret; } @@ -366,6 +411,7 @@ static BlockdevOptionsCbw *cbw_parse_options(QDict *opt= ions, Error **errp) * object for original options. */ qdict_extract_subqdict(options, NULL, "bitmap"); + qdict_del(options, "on-cbw-error"); =20 out: visit_free(v); @@ -407,6 +453,8 @@ static int cbw_open(BlockDriverState *bs, QDict *option= s, int flags, return -EINVAL; } } + s->on_cbw_error =3D opts->has_on_cbw_error ? opts->on_cbw_error : + ON_CBW_ERROR_BREAK_GUEST_WRITE; =20 bs->total_sectors =3D bs->file->bs->total_sectors; bs->supported_write_flags =3D BDRV_REQ_WRITE_UNCHANGED | diff --git a/qapi/block-core.json b/qapi/block-core.json index e89f2dfb5b..3f08025114 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4162,6 +4162,27 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { '*bottom': 'str' } } =20 +## +# @OnCbwError: +# +# An enumeration of possible behaviors for copy-before-write operation +# failures. +# +# @break-guest-write: report the error to the guest. This way the state +# of copy-before-write process is kept OK and +# copy-before-write filter continues to work normally. +# +# @break-snapshot: continue guest write. Since this, the snapshot state +# provided by copy-before-write filter becomes broken. +# So, all in-flight and all further snapshot-access +# operations (through snapshot-access block driver) +# will fail. +# +# Since: 7.0 +## +{ 'enum': 'OnCbwError', + 'data': [ 'break-guest-write', 'break-snapshot' ] } + ## # @BlockdevOptionsCbw: # @@ -4183,11 +4204,15 @@ # modifications (or removing) of specified bitmap doesn't # influence the filter. (Since 7.0) # +# @on-cbw-error: Behavior on failure of copy-before-write operation. +# Default is @break-guest-write. (Since 7.0) +# # Since: 6.2 ## { 'struct': 'BlockdevOptionsCbw', 'base': 'BlockdevOptionsGenericFormat', - 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } } + 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap', + '*on-cbw-error': 'OnCbwError' } } =20 ## # @BlockdevOptions: --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648805212771707.1376234996796; Fri, 1 Apr 2022 02:26:52 -0700 (PDT) Received: from localhost ([::1]:53328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDYR-00085I-5p for importer@patchew.org; Fri, 01 Apr 2022 05:26:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRa-0000IA-D9 for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: from [2a00:1450:4864:20::136] (port=42609 helo=mail-lf1-x136.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRV-0006sx-3n for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:45 -0400 Received: by mail-lf1-x136.google.com with SMTP id d5so3716005lfj.9 for ; Fri, 01 Apr 2022 02:19:37 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:36 -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=rpLiCSzJwgOLvt2u/fjZZnNkCVti5LYFLIM9A5wltYA=; b=4+aKUHrtHC3Lk0r2WohT5JxBybGdKBnVIvqsOenpSkZz3UqikOl7l9Sxpg+jLCqy3M T7uaaaXUvR3ROUl1EIf6qOp1nQs/6zNwGAjpo4Qe0z0iniJ8rQEp/3ts47oyz9fhYzOI ndYhPoY0pAb7Oe9LoGaVxA29sjblLXGqn1Jo84gTqy64pzoT7KPg+hHCEu47yCfs1CFU L7lbZaBPnhYRdVWGAQ6jMlStfI3o77zzIuCom1EwfiFl8W9ZLk6hWPMQbaGDEo1pzUaw +TttnJtdUxw5aat11Jr7Fbfk8XGMY5odesygrHxYT9F8kwYKtr7wSnYl9+t0WNEGOrJd r92A== 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=rpLiCSzJwgOLvt2u/fjZZnNkCVti5LYFLIM9A5wltYA=; b=q9jIlcfRN4jpEuqI0Bw8TMtCBdKxVg3IpjIEfymMD8rC9asGnawQBE2GDNOw8FJDEL 469QZWUg/mL07nM5zpbcSJZ4IICHso2ZxyHFNGD/RSu6Gm6DWvo3mFyYeBzrfohPjnFa GwCVNOevxa6t+VJ8ZAm0k7+QrlWrnu1E7wXdA3KHczvR9+1HMhZjjbKtw+9i8FEfZehk 1gOH/D/ZjTOdGwYiScLPVTy3/6RPfciXGYA6jQ6bY9m4rzsURrqv4TYbGkkuMbV07kIe +NZ/sEqcLRPt0+2GaEz0YUmd0HxC7i/3IFN0JlpbIhOiM/6XTz+1eHXejgcu4MXq+s2a yvNA== X-Gm-Message-State: AOAM532sjEuyCJiUo293tWhvz+T97wM4PHp0SDqEBC/mKALMRETmbuBv /VCwRLIcr8CCGkJfn/jlU5LKF9Be+z7t1Q== X-Google-Smtp-Source: ABdhPJzRXEKn2UbulbJNwCc2rTipRk0odOdAX0XZzacvI9X265jwDVatrJF+eJdyQ0csB7GyVKnGRA== X-Received: by 2002:a05:6512:318a:b0:44a:be25:7082 with SMTP id i10-20020a056512318a00b0044abe257082mr9235154lfe.439.1648804776260; Fri, 01 Apr 2022 02:19:36 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 3/7] iotests: add copy-before-write: on-cbw-error tests Date: Fri, 1 Apr 2022 12:19:16 +0300 Message-Id: <20220401091920.287612-4-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::136 (failed) 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::136; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x136.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648805214355100001 Content-Type: text/plain; charset="utf-8" Add tests for new option of copy-before-write filter: on-cbw-error. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- tests/qemu-iotests/tests/copy-before-write | 128 ++++++++++++++++++ .../qemu-iotests/tests/copy-before-write.out | 5 + 2 files changed, 133 insertions(+) create mode 100755 tests/qemu-iotests/tests/copy-before-write create mode 100644 tests/qemu-iotests/tests/copy-before-write.out diff --git a/tests/qemu-iotests/tests/copy-before-write b/tests/qemu-iotest= s/tests/copy-before-write new file mode 100755 index 0000000000..a32608f597 --- /dev/null +++ b/tests/qemu-iotests/tests/copy-before-write @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +# group: auto backup +# +# Copyright (c) 2022 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import re + +import iotests +from iotests import qemu_img_create, qemu_io + + +temp_img =3D os.path.join(iotests.test_dir, 'temp') +source_img =3D os.path.join(iotests.test_dir, 'source') +size =3D '1M' + + +class TestCbwError(iotests.QMPTestCase): + def tearDown(self): + self.vm.shutdown() + os.remove(temp_img) + os.remove(source_img) + + def setUp(self): + qemu_img_create('-f', iotests.imgfmt, source_img, size) + qemu_img_create('-f', iotests.imgfmt, temp_img, size) + qemu_io('-c', 'write 0 1M', source_img) + + self.vm =3D iotests.VM() + self.vm.launch() + + def do_cbw_error(self, on_cbw_error): + result =3D self.vm.qmp('blockdev-add', { + 'node-name': 'cbw', + 'driver': 'copy-before-write', + 'on-cbw-error': on_cbw_error, + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': source_img, + } + }, + 'target': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'blkdebug', + 'image': { + 'driver': 'file', + 'filename': temp_img + }, + 'inject-error': [ + { + 'event': 'write_aio', + 'errno': 5, + 'immediately': False, + 'once': True + } + ] + } + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', { + 'node-name': 'access', + 'driver': 'snapshot-access', + 'file': 'cbw' + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.hmp_qemu_io('cbw', 'write 0 1M') + self.assert_qmp(result, 'return', '') + + result =3D self.vm.hmp_qemu_io('access', 'read 0 1M') + self.assert_qmp(result, 'return', '') + + self.vm.shutdown() + log =3D self.vm.get_log() + log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log =3D iotests.filter_qemu_io(log) + return log + + def test_break_snapshot_on_cbw_error(self): + """break-snapshot behavior: + Guest write succeed, but further snapshot-read fails, as snapshot = is + broken. + """ + log =3D self.do_cbw_error('break-snapshot') + + self.assertEqual(log, """\ +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read failed: Permission denied +""") + + def test_break_guest_write_on_cbw_error(self): + """break-guest-write behavior: + Guest write fails, but snapshot-access continues working and furth= er + snapshot-read succeeds. + """ + log =3D self.do_cbw_error('break-guest-write') + + self.assertEqual(log, """\ +write failed: Input/output error +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +""") + + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2'], + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/copy-before-write.out b/tests/qemu-io= tests/tests/copy-before-write.out new file mode 100644 index 0000000000..fbc63e62f8 --- /dev/null +++ b/tests/qemu-iotests/tests/copy-before-write.out @@ -0,0 +1,5 @@ +.. +---------------------------------------------------------------------- +Ran 2 tests + +OK --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648805721831546.2282384301955; Fri, 1 Apr 2022 02:35:21 -0700 (PDT) Received: from localhost ([::1]:36862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDgd-0007uQ-EB for importer@patchew.org; Fri, 01 Apr 2022 05:35:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRY-0000Hk-F6 for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: from [2a00:1450:4864:20::236] (port=34686 helo=mail-lj1-x236.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRV-0006tB-1k for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:43 -0400 Received: by mail-lj1-x236.google.com with SMTP id 17so3120279lji.1 for ; Fri, 01 Apr 2022 02:19:38 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:36 -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=nFVdnuw+3o5G9R5rQeBbXGWA5P0kYYacFZZwVwvOqB4=; b=mvBWJ30ufOsXXse3c/eA0VSPunDQWrxy8eZ8H8hANsIQpjQiEnUXwegydFIU37ukTI 2Gk3265mgDLtNTIyAFwptOUs4AVfcHea4k4gXLm9foltiETFTYbut0ySuoruM3Sje0wv +8CZAA/Pjkt/59SxZOuLHm/8OzI9H3ViGuxV2xo+dDU/jAbyrxbT/zRbwMVG2YABscPo KRYLPAtg7SaDTKei4zdw/xBc+r08fMH57aCHVBVFp3uQso2R/9/5uRemvCRlrfl7Rmgr SNA/EUInxNXf7N1wHn1jq5b2wJda/krttuGLKw7RsS9/AHwRfzVZfOvonZ/eMat4Gmnw T2xA== 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=nFVdnuw+3o5G9R5rQeBbXGWA5P0kYYacFZZwVwvOqB4=; b=1qg0hgFwvCd+4OVZZnx1hlB5P8K7v1Rb4kikAtCjsVusjKwS0ByAfxzdHI8LggvrGY cID2sC+N4spQ4NPEgbva/7g27CvTS7aVVMOsJx0wUjpu1nWammN0J02tn4cKOzbq2Axn MTIwZzpfjpHaMLgpIZp3+k0rtaDc2/jMW7eZTnUHA/BgaQvK3+53XIqKcQOEbUgU3X4U CL86D7+xQPU9/fJj11LrSSzzrvx2yNcI7Bfu4ItEX8v/CC5UAYp4h0opijeafgBnZSkC 9Ve7gkqq/uz+jyBMGGRh9EegiK1FBAV1llmBUgF+sLp5WGE0CUyMrp/p2lzwMyScj/Ky W8+Q== X-Gm-Message-State: AOAM533/iUh47lQdZUPwaaAyfhB5xrK1Iw1jpipGMtb4Q0wRD8y/7Zzf WDsdeWNo4Y9JTmrxi8ZZGkORtA== X-Google-Smtp-Source: ABdhPJz4sOBktV+pwqvdsj3bp1TswVB2eUCWxYpk2D4ES5if6GZ3BNIDdn3Y8+YS/y20WTZ8TuW/tg== X-Received: by 2002:a2e:6e0d:0:b0:247:fc9c:284e with SMTP id j13-20020a2e6e0d000000b00247fc9c284emr13326088ljc.251.1648804776920; Fri, 01 Apr 2022 02:19:36 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 4/7] util: add qemu-co-timeout Date: Fri, 1 Apr 2022 12:19:17 +0300 Message-Id: <20220401091920.287612-5-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::236 (failed) 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::236; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x236.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648805724380100001 Content-Type: text/plain; charset="utf-8" Add new API, to make a time limited call of the coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qemu/coroutine.h | 13 ++++++ util/meson.build | 1 + util/qemu-co-timeout.c | 89 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 util/qemu-co-timeout.c diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c828a95ee0..8704b05da8 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -316,6 +316,19 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUC= lockType type, int64_t ns) qemu_co_sleep_ns_wakeable(&w, type, ns); } =20 +typedef void CleanupFunc(void *opaque); +/** + * Run entry in a coroutine and start timer. Wait for entry to finish or f= or + * timer to elapse, what happen first. If entry finished, return 0, if tim= er + * elapsed earlier, return -ETIMEDOUT. + * + * Be careful, entry execution is not canceled, user should handle it some= how. + * If @clean is provided, it's called after coroutine finish if timeout + * happened. + */ +int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque, + uint64_t timeout_ns, CleanupFunc clean); + /** * Wake a coroutine if it is sleeping in qemu_co_sleep_ns. The timer will = be * deleted. @sleep_state must be the variable whose address was given to diff --git a/util/meson.build b/util/meson.build index f6ee74ad0c..249891db72 100644 --- a/util/meson.build +++ b/util/meson.build @@ -83,6 +83,7 @@ if have_block util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c')) + util_ss.add(files('qemu-co-timeout.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) util_ss.add(files('readline.c')) util_ss.add(files('throttle.c')) diff --git a/util/qemu-co-timeout.c b/util/qemu-co-timeout.c new file mode 100644 index 0000000000..00cd335649 --- /dev/null +++ b/util/qemu-co-timeout.c @@ -0,0 +1,89 @@ +/* + * Helper functionality for distributing a fixed total amount of + * an abstract resource among multiple coroutines. + * + * Copyright (c) 2022 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/coroutine.h" +#include "block/aio.h" + +typedef struct QemuCoTimeoutState { + CoroutineEntry *entry; + void *opaque; + QemuCoSleep sleep_state; + bool marker; + CleanupFunc *clean; +} QemuCoTimeoutState; + +static void coroutine_fn qemu_co_timeout_entry(void *opaque) +{ + QemuCoTimeoutState *s =3D opaque; + + s->entry(s->opaque); + + if (s->marker) { + assert(!s->sleep_state.to_wake); + /* .marker set by qemu_co_timeout, it have been failed */ + if (s->clean) { + s->clean(s->opaque); + } + g_free(s); + } else { + s->marker =3D true; + qemu_co_sleep_wake(&s->sleep_state); + } +} + +int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque, + uint64_t timeout_ns, CleanupFunc clean) +{ + QemuCoTimeoutState *s; + Coroutine *co; + + if (timeout_ns =3D=3D 0) { + entry(opaque); + return 0; + } + + s =3D g_new(QemuCoTimeoutState, 1); + *s =3D (QemuCoTimeoutState) { + .entry =3D entry, + .opaque =3D opaque, + .clean =3D clean + }; + + co =3D qemu_coroutine_create(qemu_co_timeout_entry, s); + + aio_co_enter(qemu_get_current_aio_context(), co); + qemu_co_sleep_ns_wakeable(&s->sleep_state, QEMU_CLOCK_REALTIME, timeou= t_ns); + + if (s->marker) { + /* .marker set by qemu_co_timeout_entry, success */ + g_free(s); + return 0; + } + + /* Don't free s, as we can't cancel qemu_co_timeout_entry execution */ + s->marker =3D true; + return -ETIMEDOUT; +} --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648805915003826.3988603461517; Fri, 1 Apr 2022 02:38:35 -0700 (PDT) Received: from localhost ([::1]:42774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDjm-0003jR-2H for importer@patchew.org; Fri, 01 Apr 2022 05:38:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRa-0000IB-Cq for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: from [2a00:1450:4864:20::22d] (port=42887 helo=mail-lj1-x22d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRW-0006tJ-9R for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: by mail-lj1-x22d.google.com with SMTP id c15so3066387ljr.9 for ; Fri, 01 Apr 2022 02:19:38 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:37 -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=mRK7WxLX+HR4rJNJEmFqrnmUVkOna7RNQuFOtOFhYr8=; b=tIZBwEAeJL7VYcTJjnEVZPJ6BVBOIUrDDRdTx6LkrgQhfxMiA6wcO+BSYez7EmDjRe 2gId61gPMlLg0l59l9H6Lcf/XXe6OlSCg2PRMp7l2Ckm2F6BRtxfA6VN3Ew6G8VF9N2b 8zdNJCmYX1lgwfjmE4HO9EmSe+pDYiaTAS/dtmXI+USdfwGL7o2N5pbt83mPucWlwp7i +k6PmQ6uE8ZQ6zQCLC5LCur39sVVJgGnKsPeRzUUEbh6lkKkMSyDPj83CqwgVSZiHoXj IIlOPTlQ6Q/dHNpSiv+mn+Q9VkxaxgTtWJNOhBxXLGFYvts1jRf5GtIs4dS4w0wc/Mvk gbLQ== 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=mRK7WxLX+HR4rJNJEmFqrnmUVkOna7RNQuFOtOFhYr8=; b=PKk7uPBiXhi1DIPOOzFfOU+wtLrig4n8OCxAA6hDyrFZe0Tx2o2U5E7eTb9FcMpLah H6MypkG/VdifVcdD9w8kyVEAy9Nbzj4z8Z5k2KMnAlcjc6Yr5CDBBW2FJFJYzsyj6zVy jbEA7oZCOSazE3YIzsEZlFc2sqIYFxCRARDGL9jBQa2nAWsEnGb+plhB5qxpAITvSLyX /SO04jQyqbDoHMM9pAeST3APJW4rLlY5MnskXenk87vAGbm4T6TYEWFfNphNoqdoxkWA yo+IAk/65PxuhRm6eU4wY0Rh33nWhMrwQLYVB0ZKivtzm94QOk7fRYrV2WtpblxpV55y EwgA== X-Gm-Message-State: AOAM533i/Zz3xmvWbQ6T49oJf6pZFsEoyfgBKVB+FZ0wAeoou4v4j9lk hqYt3EmFa8J6OOPq4APWPSb6Ng== X-Google-Smtp-Source: ABdhPJxySh4ISsDwJlbva98Fu7uJ0Vp+WpCEv0MWq9sfrffpgTi8lBT5v4dHMjpslV6BJh60RPybNg== X-Received: by 2002:a2e:1617:0:b0:24a:a6b4:40b2 with SMTP id w23-20020a2e1617000000b0024aa6b440b2mr12984731ljd.83.1648804777581; Fri, 01 Apr 2022 02:19:37 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 5/7] block/block-copy: block_copy(): add timeout_ns parameter Date: Fri, 1 Apr 2022 12:19:18 +0300 Message-Id: <20220401091920.287612-6-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::22d (failed) 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::22d; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x22d.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648805916430100001 Content-Type: text/plain; charset="utf-8" Add possibility to limit block_copy() call in time. To be used in the next commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 26 +++++++++++++++++++------- block/copy-before-write.c | 2 +- include/block/block-copy.h | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index ec46775ea5..b47cb188dd 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -883,10 +883,18 @@ 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) { - 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, @@ -894,12 +902,16 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_= t start, int64_t bytes, .max_workers =3D BLOCK_COPY_MAX_WORKERS, }; =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) { + /* Timeout. 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; + + return ret; } =20 BlockCopyCallState *block_copy_async(BlockCopyState *s, diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 0614c3d08b..7ef3f9f4c1 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -107,7 +107,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); 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..1c9616cdee 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -40,7 +40,7 @@ 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); =20 /* * Run block-copy in a coroutine, create corresponding BlockCopyCallState --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648805447074741.1198762398914; Fri, 1 Apr 2022 02:30:47 -0700 (PDT) Received: from localhost ([::1]:59842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDcD-00040u-KH for importer@patchew.org; Fri, 01 Apr 2022 05:30:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRc-0000LO-5n for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:54 -0400 Received: from [2a00:1450:4864:20::12c] (port=44876 helo=mail-lf1-x12c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRW-0006tV-Ak for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: by mail-lf1-x12c.google.com with SMTP id m3so3704210lfj.11 for ; Fri, 01 Apr 2022 02:19:39 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19: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=ESo7rdotHdZMR0iHY1h3nO2pJdxOeDhAmWJR8wsYiEQ=; b=Mj6UokXRlY9/A1J9aQGWXvKU0AQeHIjtlQSuY6dMclz+/woH3+CU7VclvKqpIcuORT q3GMQhArfktEKsgnyczLb8hfG8GjqdUCOuHklOGlFXICzKdxL1h1oS/q8tev5pzc/svH 0rLMow1HZcW4eB+CV15T1VdFU88dus4QgSgP3IdDwwjVRUr/J4eaKY8ivhekug3wILUR GuTBHl4Ao53TFLotld58Tjz2oKIaevf/QrrZpzxGuIvoh8Iyo9OE4i3zptNHBKaHYgbC 8X+ZzbTUW+rL63VnjsXE+8TPXF6G82r9Org2wRtNEohv+vdToux40zFtQl3wjAnb7bgG 8/Xg== 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=ESo7rdotHdZMR0iHY1h3nO2pJdxOeDhAmWJR8wsYiEQ=; b=S6447inYuxsMnMufGw97l7Nxxi4CWcHwirWaRTn1ej/MHLogAajRVNRub/7+pZpBMQ 146onj5n3GTj7rmkDOttOkg/QhCzkyGwbO99jkByR00X02b936nbjBD++K5XvW0y1QpS f24unBPzj6q7skHMM1nFj65HTcfoH+QVC7bel6bRpj9lvIzqsH39mQ08VFlRgkrA19ZH 0ew0usUcfTkF6XtBKcIiLNkxJUhd8xnNr00nyOfyKA+awkwNu2zR3eLGxXd2fyAcEvSx AkHDjV2ZmP86YfHC5ieCAJy3J+OFV5ipgjCPuOGO//O55U4KjdyY4F3V3t8D+6Rz+Px4 c+AA== X-Gm-Message-State: AOAM531GcGPxN5p1m4v14dNDZONq1IvU9SmHfj/aoYW2zTEQ3tDs1BFH Bj3OiP18dU7NPv3ICppMSl20ag== X-Google-Smtp-Source: ABdhPJy5/JKGmBUmf/3LDUOGYvAJ5DBqx7xaGpsmUpbmzyZn2gIP1/wNm8N9+C8VEsCfJG4kkqysDA== X-Received: by 2002:ac2:4dbb:0:b0:44a:da57:33f5 with SMTP id h27-20020ac24dbb000000b0044ada5733f5mr1481485lfe.653.1648804778300; Fri, 01 Apr 2022 02:19:38 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 6/7] block/copy-before-write: implement cbw-timeout option Date: Fri, 1 Apr 2022 12:19:19 +0300 Message-Id: <20220401091920.287612-7-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::12c (failed) 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::12c; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x12c.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648805447964100001 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. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block/copy-before-write.c | 6 +++++- qapi/block-core.json | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 7ef3f9f4c1..0ea5506f77 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 @@ -107,7 +108,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, 0); + ret =3D block_copy(s->bcs, off, end - off, true, s->cbw_timeout_ns); if (ret < 0 && s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_GUEST_WRITE) { return ret; } @@ -412,6 +413,7 @@ static BlockdevOptionsCbw *cbw_parse_options(QDict *opt= ions, Error **errp) */ qdict_extract_subqdict(options, NULL, "bitmap"); qdict_del(options, "on-cbw-error"); + qdict_del(options, "cbw-timeout"); =20 out: visit_free(v); @@ -455,6 +457,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 | diff --git a/qapi/block-core.json b/qapi/block-core.json index 3f08025114..e077506e0f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4207,12 +4207,15 @@ # @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. Default 0. (Since 7.0) +# # 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: --=20 2.35.1 From nobody Sun Feb 8 12:38:52 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 1648806744159885.5015083332642; Fri, 1 Apr 2022 02:52:24 -0700 (PDT) Received: from localhost ([::1]:36088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDx9-0002Cw-3D for importer@patchew.org; Fri, 01 Apr 2022 05:52:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRY-0000Hg-Ed for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:46 -0400 Received: from [2a00:1450:4864:20::135] (port=40617 helo=mail-lf1-x135.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRV-0006th-3S for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:43 -0400 Received: by mail-lf1-x135.google.com with SMTP id t25so3729009lfg.7 for ; Fri, 01 Apr 2022 02:19:40 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19: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=sZ60no0T2SKpnDHqmzl+ewaJt3tOk+gpxGjhzlf+0KQ=; b=E4j1SfdZ2wOiqH5Plh3yZ7AhtNvwZim3t6aOc7iviTaY1RFSnMmg1YtKRwShjuT2Tx 5Dk9xGU9UvfeZQPfOU5e09LA77sSuB/tO0rtCNNkQEoTizGleHwPYe/577QBf+DvMEFR VekTyChweOrSy3NX4MYbgRbEBeT+gpBBCJRr32gsVsPNSqbRyijrPKqV4moIef/SYm6C nkXvLCYE4hASKXZGgkWQliw+5pa2l7bx6o86OWWLN7wK3rqy/+28ji741F7G4aGQ8apA k8kxFW9/D8PQ6NLfyo9i//dPhM4G4uzEuqKKhVmwOqkGsE7uINsGdC9kR6qsra5Amcve +YRw== 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=sZ60no0T2SKpnDHqmzl+ewaJt3tOk+gpxGjhzlf+0KQ=; b=BjqlH2ejOO99otRrESlWl5JSSes/y2Spmp78dxDbKmt9t7dtVU7bOaGQzTA2N5tMlz HieAmGZ/KI4QsjZkq1GciEC4T25nY2UA+xvMoqgf/UGxsZB2mbxYttgyxjvPuNdiT3Uf wOHo+/nZdqM4l9a/U6kuapzGhPyk+p++Ugh77tOwGA4NBRMpcx1WIb9h2nysaNjBaZIg KFGq7e5SraCYgifFwxSWjDAak66jBfSriZRIo3CpcZ1ziN6AiHpwstjhzwnIRxvzXYLR DDxYUbm3ymO6Gv9z4DZMH++y+Y5PbcPjfQT2/W216a9ATz8s1L16cXSzAPN7ntLDgZoG 9RMA== X-Gm-Message-State: AOAM531Co3FkrALksKQnJ7fKFrzAktS6AY7tK9xjrCVDubgluWluEVho TziEXVQ5OQN+jqCYHvHFZsRAYQ== X-Google-Smtp-Source: ABdhPJyppJ++G5a/ZJL04IqjPCV0aoukubLys5Or6ssZ4Chk+AG/ED1vLRvpZdUXI3ffe3FLWkLPMA== X-Received: by 2002:a05:6512:6c5:b0:44a:2642:b77d with SMTP id u5-20020a05651206c500b0044a2642b77dmr13656883lff.616.1648804778998; Fri, 01 Apr 2022 02:19:38 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 7/7] iotests: copy-before-write: add cases for cbw-timeout option Date: Fri, 1 Apr 2022 12:19:20 +0300 Message-Id: <20220401091920.287612-8-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::135 (failed) 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::135; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x135.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1648806744885100001 Content-Type: text/plain; charset="utf-8" Add two simple test-cases: timeout failure with break-snapshot-on-cbw-error behavior and similar with break-guest-write-on-cbw-error behavior. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- tests/qemu-iotests/tests/copy-before-write | 78 +++++++++++++++++++ .../qemu-iotests/tests/copy-before-write.out | 4 +- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/tests/copy-before-write b/tests/qemu-iotest= s/tests/copy-before-write index a32608f597..265299957c 100755 --- a/tests/qemu-iotests/tests/copy-before-write +++ b/tests/qemu-iotests/tests/copy-before-write @@ -122,6 +122,84 @@ read 1048576/1048576 bytes at offset 0 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) """) =20 + def do_cbw_timeout(self, on_cbw_error): + result =3D self.vm.qmp('object-add', { + 'qom-type': 'throttle-group', + 'id': 'group0', + 'limits': {'bps-write': 1} + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', { + 'node-name': 'cbw', + 'driver': 'copy-before-write', + 'on-cbw-error': on_cbw_error, + 'cbw-timeout': 1, + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': source_img, + } + }, + 'target': { + 'driver': 'throttle', + 'throttle-group': 'group0', + 'file': { + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': temp_img + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', { + 'node-name': 'access', + 'driver': 'snapshot-access', + 'file': 'cbw' + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.hmp_qemu_io('cbw', 'write 0 512K') + self.assert_qmp(result, 'return', '') + + # We need second write to trigger throttling + result =3D self.vm.hmp_qemu_io('cbw', 'write 512K 512K') + self.assert_qmp(result, 'return', '') + + result =3D self.vm.hmp_qemu_io('access', 'read 0 1M') + self.assert_qmp(result, 'return', '') + + self.vm.shutdown() + log =3D self.vm.get_log() + log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log =3D iotests.filter_qemu_io(log) + return log + + def test_timeout_break_guest(self): + log =3D self.do_cbw_timeout('break-guest-write') + self.assertEqual(log, """\ +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +write failed: Connection timed out +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +""") + + def test_timeout_break_snapshot(self): + log =3D self.do_cbw_timeout('break-snapshot') + self.assertEqual(log, """\ +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read failed: Permission denied +""") + =20 if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], diff --git a/tests/qemu-iotests/tests/copy-before-write.out b/tests/qemu-io= tests/tests/copy-before-write.out index fbc63e62f8..89968f35d7 100644 --- a/tests/qemu-iotests/tests/copy-before-write.out +++ b/tests/qemu-iotests/tests/copy-before-write.out @@ -1,5 +1,5 @@ -.. +.... ---------------------------------------------------------------------- -Ran 2 tests +Ran 4 tests =20 OK --=20 2.35.1