From nobody Sun Feb 8 20:17:33 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 164926877293776.54284838559181; Wed, 6 Apr 2022 11:12:52 -0700 (PDT) Received: from localhost ([::1]:41844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncA9D-0008AM-Uh for importer@patchew.org; Wed, 06 Apr 2022 14:12:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5A-0000NP-Io for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:40 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]:33763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA57-0001vX-Ic for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:40 -0400 Received: by mail-lf1-x12a.google.com with SMTP id bu29so5582740lfb.0 for ; Wed, 06 Apr 2022 11:08:36 -0700 (PDT) Received: from fedora.. ([185.215.60.161]) by smtp.gmail.com with ESMTPSA id a20-20020a194f54000000b0044a9afab7e7sm1904321lfk.290.2022.04.06.11.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08: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=/6hsA0EO/gNahUQKgd3/p5EZyNb6Mi/jxzXRr5F796I=; b=74bCCBpxFxxZ5KJ4k1PByOIiK1YRGg2wLLqDoWKG4b7udeTfIxLNIcVFEe7q6rSKWf b4OC4ze9MMP4fPbGKOa0AycjD78DwsGJL18H6/H0UAM1TOPCawfWRLxH7/Hh7FbDb4Co 3yWeb5dHwszLq62NdF9jzDKrHn8lCY72VIlp6rApVRJfis3sMkwD1PexmClwVSd2HIL0 3JGRRkD4KgiZ064OOWckfq6O1eqRQMzO8EvmB6FZATwPnbaoT9B5J+rZqWKvtvvls6LX CyeW7cVBCOxwlRuQDweL9+/W6KWiTw2kqEBolM8/f1zT8Ti6qrd4ZvboxVELULvuHH/J mzlQ== 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=/6hsA0EO/gNahUQKgd3/p5EZyNb6Mi/jxzXRr5F796I=; b=FAbIqZ2ABZCVurKT39A9zjNmWnzxm3/80QuSILuq3nTNlNEIDxFdvbtqGmiwzQ8rw7 /BKpUckgUFqGK58pW0ym7FwDn4z1iMSIq4k3Be5EjAYhoyiYKd8w8ljvaUr2D4OV36In g9nRKW0BKvaiasGyO/urlpWk6Ym6t8BO16DtqNrCpLdozAu2klHdRS3hDEzp7LV4V+eh s6owpVeuJa/fJ4TWaOK/mWYixj3XtXWVWu2oJvtXd4VL9y/BGgthzltSjc9/oZvKN2s+ rpM5YMQs9/P37w8ZiJFW6qWQefi+8hD00H39PlIDjDwXwMaE5srN4hSZl5NqrXM6gV5M Sbqw== X-Gm-Message-State: AOAM533g8QrBHZCE7u0exi//1PFNeylI22Xosz7KiEffX8JhjUsGWmqA /5Qw8fZyaMfkTOCRqosdBxyWVQ== X-Google-Smtp-Source: ABdhPJzoyCFZgJgPI7wT2WHn0jqtdj12CW9fwZkC2cqY4pbm4FdO3MDKGM9selFo+WBSROAqR9KYVQ== X-Received: by 2002:a05:6512:39cf:b0:44a:2453:d2fd with SMTP id k15-20020a05651239cf00b0044a2453d2fdmr6816688lfu.507.1649268515407; Wed, 06 Apr 2022 11:08:35 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 1/7] block/copy-before-write: refactor option parsing Date: Wed, 6 Apr 2022 21:07:55 +0300 Message-Id: <20220406180801.374844-2-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::12a; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x12a.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=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: , 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: 1649268773611100001 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 Reviewed-by: Hanna Reitz --- block/copy-before-write.c | 55 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index a8a06fdc09..6877ff893a 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,34 @@ 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 BlockdevOptions *cbw_parse_options(QDict *options, Error **errp) { - QDict *bitmap_qdict =3D NULL; - BlockDirtyBitmap *bmp_param =3D NULL; + BlockdevOptions *opts =3D NULL; Visitor *v =3D NULL; - bool ret =3D false; =20 - *bitmap =3D NULL; + qdict_put_str(options, "driver", "copy-before-write"); =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); + v =3D qobject_input_visitor_new_flat_confused(options, errp); if (!v) { goto out; } =20 - visit_type_BlockDirtyBitmap(v, NULL, &bmp_param, errp); - if (!bmp_param) { + visit_type_BlockdevOptions(v, NULL, &opts, errp); + if (!opts) { goto out; } =20 - *bitmap =3D block_dirty_bitmap_lookup(bmp_param->node, bmp_param->name= , NULL, - errp); - if (!*bitmap) { - goto out; - } - - ret =3D true; + /* + * Delete options which we are going to parse through BlockdevOptions + * object for original options. + */ + qdict_extract_subqdict(options, NULL, "bitmap"); =20 out: - qapi_free_BlockDirtyBitmap(bmp_param); visit_free(v); - qobject_unref(bitmap_qdict); + qdict_del(options, "driver"); =20 - return ret; + return opts; } =20 static int cbw_open(BlockDriverState *bs, QDict *options, int flags, @@ -376,6 +365,14 @@ 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(BlockdevOptions) full_opts =3D NULL; + BlockdevOptionsCbw *opts; + + full_opts =3D cbw_parse_options(options, errp); + if (!full_opts) { + return -EINVAL; + } + opts =3D &full_opts->u.copy_before_write; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, @@ -390,8 +387,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 20:17:33 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 1649268649769576.017171584204; Wed, 6 Apr 2022 11:10:49 -0700 (PDT) Received: from localhost ([::1]:35248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncA7E-0003gU-ED for importer@patchew.org; Wed, 06 Apr 2022 14:10:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5A-0000NS-Pj for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:43 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]:37445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA57-0001vl-Ol for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:40 -0400 Received: by mail-lj1-x229.google.com with SMTP id bx37so4333860ljb.4 for ; Wed, 06 Apr 2022 11:08:37 -0700 (PDT) Received: from fedora.. ([185.215.60.161]) by smtp.gmail.com with ESMTPSA id a20-20020a194f54000000b0044a9afab7e7sm1904321lfk.290.2022.04.06.11.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08: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=t6lsn4nW3rcF/M2cWGQSYle4tgbfFEygVPAUIGkb6Ik=; b=fuy7yht0WPSesHZesg4jFRv20FATiALL2yFY0b3wMNeSBO3QGBlgF7SIiIUryZEUEq 0iq/7xn9Id+in8VxFlm13mWHl7Md1Lm7XT6o9+Lx0Ay1xpOnsnV6AFrz0mJipVAWEOP5 Up8xshetbv0Yz259M3BmOWVVTPz4QMl7C20pxvPySw8aS1IVEppWWAx/VncQrMQQ5AB8 0U0il8VYa6SacK6vmiwLhrm2TQby629kTKyapqygETPoAkcSIoYH3bxVKGg2rmPAQToS w0ulrd/K/wRDAT5zpFdAHX8Q6BsiwAhRByDZrEjJKQah2CFv9/wtF1A+ncFy5RaKdNaP Ixeg== 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=t6lsn4nW3rcF/M2cWGQSYle4tgbfFEygVPAUIGkb6Ik=; b=yvlefpJojpuxyJ47pudatFvB7k7zjiit6Yak6t5O4mHsCj5tG9MoSkKwJ1PZq5VU5d XvdTWJB6BzZEwz8VBXl9Wf3a1bya3aGLhY+BBab58bU+XcHTmGAZREIoLtGI8YDVWtG0 SscgZQ889Zeh3Ql0xjTiSw/9aZ6EwBKfDZ6yevTeWJkQj5qzUzo0BgOsWv/qJUJxCo59 18EH9yxsro9BV5hdGvzV+D9DctWx4shgStyq71jTxfCCPA0t2+4O4tA5pHeMAEohcq/I cOWjNR+3Y+1dbIt7ILIb3v0dmKVUfqSG7TMHk1DP55fmq537kWhkLCN+gTLuPiauXMHG 5+iQ== X-Gm-Message-State: AOAM533Uf0vJFxHXZZt+l3n7V4D6fikgBQXHDKUAQ2SYtDU+XpJ0A2v7 76lHmslCbsT7oejSPBJsL+kfnA== X-Google-Smtp-Source: ABdhPJw1Zl2bzjzWHsZhttOXmFE0aGVp8vA4I6h6wfcyep6fh22kX6406M/cYKkJZWbiy27G82VRbA== X-Received: by 2002:a2e:a592:0:b0:24b:d8f:ae55 with SMTP id m18-20020a2ea592000000b0024b0d8fae55mr5970013ljp.460.1649268516059; Wed, 06 Apr 2022 11:08:36 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 2/7] block/copy-before-write: add on-cbw-error open parameter Date: Wed, 6 Apr 2022 21:07:56 +0300 Message-Id: <20220406180801.374844-3-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::229; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x229.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: 1649268651131100001 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 set s->snapshot_ret and continue guest operations. s->snapshot_ret being set will lead to all further snapshot API requests. Note that all in-flight snapshot-API requests may still success: we do wait for them on BREAK_SNAPSHOT-failure path in cbw_do_copy_before_write(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- qapi/block-core.json | 25 ++++++++++++++++++++++++- block/copy-before-write.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index beeb91952a..085f1666af 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4163,6 +4163,25 @@ '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 guest +# will not be able to overwrite areas that cannot be +# backed up, so the backup process remains valid. +# +# @break-snapshot: continue guest write. Doing so will make the provided +# snapshot state invalid and any backup or export +# process based on it will finally fail. +# +# Since: 7.1 +## +{ 'enum': 'OnCbwError', + 'data': [ 'break-guest-write', 'break-snapshot' ] } + ## # @BlockdevOptionsCbw: # @@ -4184,11 +4203,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: diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 6877ff893a..ffb05d22f8 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 + * snapshot-API requests will fail with that error. + */ + int snapshot_error; } BDRVCopyBeforeWriteState; =20 static coroutine_fn int cbw_co_preadv( @@ -95,16 +104,27 @@ static coroutine_fn int cbw_do_copy_before_write(Block= DriverState *bs, return 0; } =20 + if (s->snapshot_error) { + return 0; + } + 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); - 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) { - bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off); + if (ret < 0) { + assert(s->on_cbw_error =3D=3D ON_CBW_ERROR_BREAK_SNAPSHOT); + if (!s->snapshot_error) { + s->snapshot_error =3D ret; + } + } else { + bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off); + } reqlist_wait_all(&s->frozen_read_reqs, off, end - off, &s->lock); } =20 @@ -176,6 +196,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; @@ -351,6 +376,7 @@ static BlockdevOptions *cbw_parse_options(QDict *option= s, Error **errp) * object for original options. */ qdict_extract_subqdict(options, NULL, "bitmap"); + qdict_del(options, "on-cbw-error"); =20 out: visit_free(v); @@ -394,6 +420,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 | --=20 2.35.1 From nobody Sun Feb 8 20:17:33 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 1649268671059729.1452754131353; Wed, 6 Apr 2022 11:11:11 -0700 (PDT) Received: from localhost ([::1]:35882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncA7Z-00046Y-RP for importer@patchew.org; Wed, 06 Apr 2022 14:11:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5E-0000OS-Aa for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:44 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:38400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA58-0001xq-EB for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:41 -0400 Received: by mail-lf1-x136.google.com with SMTP id b21so5490957lfb.5 for ; Wed, 06 Apr 2022 11:08:38 -0700 (PDT) Received: from fedora.. ([185.215.60.161]) by smtp.gmail.com with ESMTPSA id a20-20020a194f54000000b0044a9afab7e7sm1904321lfk.290.2022.04.06.11.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08: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=rJRsr0n/uu+BAoATVvTtIWzH8Hkbp0PXJYDRy4MnElY=; b=hPEmyY2Ul2xSbKfx62i/US4tKCwChfc+OtOD8Dg7bds8mUnEIU9b7pHggG8U+DQJAR q40tk3DL5YWgf/xIJuB519yT4xRN2U4ZYijOHkmWvFzL65eJmrOZrZeUYyB7K9DNXXPQ 4xRr7oaiz6bQ85zyuS/8CHuM7ifDA65wKkizBunkOjBPJaKsEd7R88Xg5I2lwNrafeYJ G1c9Q+3Ze+R25r16AAKUJ/g9WO9q4OvGTsLWEsGyAI0GrQYSvOTxgbdT1tfCxcXVgvRN uvr80sdKNeM53C5eCmToac2hZP340iWV6F71ru16AGHvoBOMswj6Co76e93+aXYf3CB8 O6oA== 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=rJRsr0n/uu+BAoATVvTtIWzH8Hkbp0PXJYDRy4MnElY=; b=uya9U3INl5XbJFsh9JpyEdiTKa7EJMUh+62Gk2cakX6XeyKAK4r17B3HRDAdhjyJNR mZlK3i1qUCchTk69wLhd2Q7IugHrUAzz6Z8qbbbhGwFykEy/VcC/iPSsVU+Li1PHADxc 7LkmkYPTe/PhEie21z77rv5BGRUTM4SBHlMEL89Yt3iCpzn1EdyPQBLRGUkOcS9hI4Ru 6Elfy2K3rC0Zsry2EB7nfHH1uOwj/179jZIsP35AG760+nD8fn1C/Ate4k4A7IsWqeww paSaYcFD81mG8bhatirRF+q7OW3wG0c2Wn0X8qCr5W9m+Ji6ZBGWRlhKz3GFBxbv6BFU tl8A== X-Gm-Message-State: AOAM530Eks9SQSm+VNKz4eY2wg/48Ri05BXutlVCbxDcE8XTkHk+jr3C wgqL11v9ffUnSziRe/pdvVe84Q== X-Google-Smtp-Source: ABdhPJyJ4QCNU8+EcVtbjTNM1NbUY0b4X6WhWu3bJ+1aoIvDIWAigrCP2X1WfqHQK+hmbFnqQekvGg== X-Received: by 2002:ac2:4250:0:b0:44a:ff88:3795 with SMTP id m16-20020ac24250000000b0044aff883795mr6848801lfl.384.1649268516748; Wed, 06 Apr 2022 11:08:36 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 3/7] iotests: add copy-before-write: on-cbw-error tests Date: Wed, 6 Apr 2022 21:07:57 +0300 Message-Id: <20220406180801.374844-4-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::136; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x136.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: 1649268673113100001 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 20:17:33 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 1649269110463586.2147842209697; Wed, 6 Apr 2022 11:18:30 -0700 (PDT) Received: from localhost ([::1]:51754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncAEe-0006T4-Sn for importer@patchew.org; Wed, 06 Apr 2022 14:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5E-0000OO-9s for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:44 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:36759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA59-0001xx-4N for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:41 -0400 Received: by mail-lf1-x129.google.com with SMTP id b17so5516664lfv.3 for ; Wed, 06 Apr 2022 11:08:38 -0700 (PDT) Received: from fedora.. ([185.215.60.161]) by smtp.gmail.com with ESMTPSA id a20-20020a194f54000000b0044a9afab7e7sm1904321lfk.290.2022.04.06.11.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08: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=JktyRDyKx1CdohBSccgJOravxS4i1xbSxr6wTMl/cIk=; b=3TXu900dv2m7ANUsbfJ65mI2CPetxpCI2jmI1yyK/dB2F2detB/dwYDXOF4XqzSVNo BOkUGvZlnwzE6b4Nffgar6AKmXDPEbJ0dIz0TGVd66Vw/bGbz8jLe06P3IlbdeFCyqWL BvUbL/VyPQsUfrxSM5mhXH1nBnWZ0r0e5OfFGHVz6pgtgWaibwjGE1Tm3TVS/wsbiZVN jh/dF323XnwZkQBU2TD5XzYJixsRKAaDE5Gm7a+IaZrzRkj6D+4ysjQDR950gZe2ZtDH v3cnGNGeg6fRaEmPLv42GoScA9mswYlyK8B0VN7ls5esLKQiks2uXejXR9jWVGtAsR3E f3mA== 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=JktyRDyKx1CdohBSccgJOravxS4i1xbSxr6wTMl/cIk=; b=jS/MB4837ndsOCrVfyq26iYQIYOayn3JUD6CFk67SwBvH6hw04cKBB/yYOEeA18YUF N9/7eTRpHKhLuj4SMFvkZFvYLwLjF1lm9JtuHYLPHJ065AxIf3r7ttuXScwaHVStC+zR J0JpSsYllCHGGBBCQpTCIqw+dLPzqX3YfyXUlspYixiwAZPqM9hZUfLy+F+EhakmLor+ zX7XA6kQGcDQQuBHv1aip20dSwXCrPmBKD0KtQp1aLCT4wqljiGMqN9jae9jn+GzjqkY LPWvHKbdNKRH0D6EeBu9JAJpdO2AYxIIsqLsJfbqWcRrbpKvnM/eK/T60SLzIa/j1kij h90Q== X-Gm-Message-State: AOAM531urF6mJkV1fv6fc811XzBdhw6bPD4SXLClfokyiRv7xLBytv4+ XNkC8w7cuSM1Q40dR6i9/dESRg== X-Google-Smtp-Source: ABdhPJynA8MHZlu8VvPdyMIne0Wsic3oL/OEHehDlzjLSOUIVu+cBvzsi3rI7S+tYXazVLTmLamT1w== X-Received: by 2002:a05:6512:3184:b0:44a:78f2:500b with SMTP id i4-20020a056512318400b0044a78f2500bmr6609754lfe.434.1649268517448; Wed, 06 Apr 2022 11:08:37 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 4/7] util: add qemu-co-timeout Date: Wed, 6 Apr 2022 21:07:58 +0300 Message-Id: <20220406180801.374844-5-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::129; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x129.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=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: , 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: 1649269113819100001 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 Reviewed-by: Hanna Reitz --- include/qemu/coroutine.h | 13 ++++++ util/qemu-co-timeout.c | 89 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 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/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; +} 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')) --=20 2.35.1 From nobody Sun Feb 8 20:17:33 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 1649268644006446.0674282308189; Wed, 6 Apr 2022 11:10:44 -0700 (PDT) Received: from localhost ([::1]:34764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncA78-0003MH-9I for importer@patchew.org; Wed, 06 Apr 2022 14:10:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5E-0000OM-8H for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:44 -0400 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]:37447) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA59-0001y6-Nx for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:41 -0400 Received: by mail-lj1-x22b.google.com with SMTP id bx37so4333963ljb.4 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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:08: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=oqg7f41+VM2vEfQWhjrNPCfXrEnJ1rvaBBV839r4i28=; b=tZqQOhJ+FJW7OQXuUYaOCWrw+ctsybVQ3DdMTLoihmdJWg8iiVtpICTtiMSvjG/d1q 4iNDmIjU8x/OKUJsYB6e7Vou44Wl4XUbMpZIGt83xqFlvrvT3Ym1PSJlu1JnnaIShuXr j/YDUNCJGf+6jeu6Q+Izc2OE+TKmKWTuIkY7wO4FK18FCnMEUCoN50TCBA+g7vZgPkvq VoHYotSBq/6gPOADBm/J43HUxaDdjKCrJDE13sXslgjoKriSaMAJityjsFn+bf39i9MC YfYLt2wOqI4olpE80Swa0TxOv9aehFY1Ae8wd6CJCPubZnO/mzV/xHgm1tWcSVaHhbt3 S/HQ== 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=oqg7f41+VM2vEfQWhjrNPCfXrEnJ1rvaBBV839r4i28=; b=S9fgHrdaeG1dCcuE7aAo34UWSXNAEryT7GjbGqSBMesIIT+6I4aQ6aOSnKmqSGexro ynNzwBiOe9YDbSyYiZXVdgxiT6BPx2ap+TIV2KIe5GPD0ZVCzUhsdWishI2Ni9EnCukI pSjpmOgMq1sPSuqXkxP2gZaYeXSB7jiY660NSFJCbQP8RK2HBXRcoDw+2qRsGr+HMVlI LnrI/so6HeBISO4yaL6d4w1HFfNmIiS5lKPPygJ0ZQtIiTwr6/+/yMPdnbSb0zAD5RT6 4jeKsmwKyxNX/2SnijFWC/FxyBdXT7W83t2mIVxCeme0qAWcdXSpoZ/sNliFOZXuT1G/ WjVA== X-Gm-Message-State: AOAM533RzWCcaXnRRMhsld5pA5O9JVQstvfMWdTWLlETSn63gAiy4HpY JDQ7EbyzehO4GQstZuF+OcNEkA== X-Google-Smtp-Source: ABdhPJwj3mf0XV/kHzNKQywxGJVrrlMd5vlSUVQyg3lPOi/ADhEJFI3JngUfu6hgRi9NI92mKu1T6w== X-Received: by 2002:a05:651c:50e:b0:249:89ef:101b with SMTP id o14-20020a05651c050e00b0024989ef101bmr5902530ljp.109.1649268518136; 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 5/7] block/block-copy: block_copy(): add timeout_ns parameter Date: Wed, 6 Apr 2022 21:07:59 +0300 Message-Id: <20220406180801.374844-6-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::22b; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x22b.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: 1649268645035100001 Content-Type: text/plain; charset="utf-8" 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 --- include/block/block-copy.h | 4 +++- block/block-copy.c | 33 ++++++++++++++++++++++++++------- block/copy-before-write.c | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) 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 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 ffb05d22f8..b7487e4ffe 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; } --=20 2.35.1 From nobody Sun Feb 8 20:17:33 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 From nobody Sun Feb 8 20:17:33 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 1649268785285809.7672582645035; Wed, 6 Apr 2022 11:13:05 -0700 (PDT) Received: from localhost ([::1]:42380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncA9Q-00005Z-6T for importer@patchew.org; Wed, 06 Apr 2022 14:13:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncA5F-0000RF-Ji for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:45 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]:41906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncA5B-0001yk-4J for qemu-devel@nongnu.org; Wed, 06 Apr 2022 14:08:45 -0400 Received: by mail-lf1-x130.google.com with SMTP id p15so5475206lfk.8 for ; Wed, 06 Apr 2022 11:08:40 -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:39 -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=WA+1U5ZC+5q6mIi4Y/XXKldn5dP6kA8bCtL1n9+8Ttw=; b=GZZ4RaD8IBz7RiF16tGghcfpUj8fyo6aZ0mePV96nhx8rcpmRl5Cc9uHls57DWkuJD RfpdUIE24Zob9CzRWY3vB0GljGipB6ZaZx1DYigxjpfbBtGm26BlPMIx/NO8uU6cuOYk zxXyxBO3Nxh95E4Nrju0L/N6PRE15FNlo/TttjMQ3IGm6001kFtGObDwIM5XeLXptyJN AECdsJnktIA5MRsJmOz3znzwqL2jMSXPaWfVrzQ45ICgwnRuFiqYT8sFj2+smx4+jmZs s7RewFRDQ1yWMj0VI2Jm+BYSL0NfgHyTugpFoDd8H8Kldj2qTqMuO+lQc2z6deKursrP EGLw== 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=WA+1U5ZC+5q6mIi4Y/XXKldn5dP6kA8bCtL1n9+8Ttw=; b=RwGW0RxD9dfSnLcpUdgC1Yy4xBVa2c2brskT5/u9J2Y00At0UUdzOimvacXKxidtJ+ XRokx0oXD32uQp+zj3WlpfCMRbZ88BufTAdR80NHqa3cGIl96uUf2VpM+BTma0YNYnwm LpEzl6O18S61wTFyCQCY+ni9gf+TW5rLTrx3ZAjaIapeVQMguAZj3nYWewjQxGlNGl2n 4j4tg3O4KoAmcA9kz9FrUCXSRbANpSmHlaJ4INhF229aHXa4ZNRAaxMwv3hHkLyMxf4I pZ4ZUHnRzBrbEtBCYFf25Z+ZDqOoF+cYWYKIXzxeuL/eFOyT5K/5Eq9vgskeUKWRoU34 9gcA== X-Gm-Message-State: AOAM530E/tGjSc0FOlIfyANaPdU76+uuHZwobJ5KcI6L5/WW1kb2K4G4 KYxoYCNawRBm0QILBQ9vpqpSZw== X-Google-Smtp-Source: ABdhPJwxijL1aHDD4E/WlcMdazmVi0lYjZxqhA1EXNUJru5ZHiFGq+REfJO+FHTLjmuL2xhQuh3csg== X-Received: by 2002:a05:6512:3f97:b0:44a:f67d:7d8 with SMTP id x23-20020a0565123f9700b0044af67d07d8mr6468555lfa.81.1649268519488; Wed, 06 Apr 2022 11:08:39 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v3 7/7] iotests: copy-before-write: add cases for cbw-timeout option Date: Wed, 6 Apr 2022 21:08:01 +0300 Message-Id: <20220406180801.374844-8-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::130; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x130.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=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: , 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: 1649268785699100003 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 --- 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..5c90b8cd50 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': 300 * 1024} + }) + 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