From nobody Fri May 3 12:42:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571067757; cv=none; d=zoho.com; s=zohoarc; b=Vp3wez2rcU0L1UiTapuIjQkBg4TLIwMygPSLR/C1XyuPu88d0qGYQ4lT2jmjMNR5LIGUN/Ts0PZCmXSOea7mCTG16ORbyBGVxhhZseRVqwmtSywSYfNDOz+94qmm5oDRksPFMjNCEZ4UsWLlj9Gu/JP/AIHqLDtNJbIkCqmnMkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571067757; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F45PXWKM5Ac1xd2K17PN60D0xKmTHDIWsREJRfGkgBE=; b=PjXawGEwyVEvym5wuAQGmqQMLm5iwgMxusgYOwNGeFAEFYguYtQbxEhaHzmA2jtS6ZYjUx/Iyey3l/4SLJp/UTwkdbbD/fh4i8VSBwKGusYWXsaaRbChxc/3fuM5dl39s87qOZex8Qtzq4GCS9ESpf5mDDQIbRBeIsC46qZTfbQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571067757851650.5270787479899; Mon, 14 Oct 2019 08:42:37 -0700 (PDT) Received: from localhost ([::1]:51680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2UU-0001BF-Ju for importer@patchew.org; Mon, 14 Oct 2019 11:42:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60954) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2Rp-0005vP-OR for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:39:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2Ro-0004Cn-ME for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:39:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iK2Rm-0004Ao-D0; Mon, 14 Oct 2019 11:39:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 885ACC049E1A; Mon, 14 Oct 2019 15:39:45 +0000 (UTC) Received: from localhost (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A05D60BE2; Mon, 14 Oct 2019 15:39:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 1/4] mirror: Do not dereference invalid pointers Date: Mon, 14 Oct 2019 17:39:28 +0200 Message-Id: <20191014153931.20699-2-mreitz@redhat.com> In-Reply-To: <20191014153931.20699-1-mreitz@redhat.com> References: <20191014153931.20699-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 14 Oct 2019 15:39:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" mirror_exit_common() may be called twice (if it is called from mirror_prepare() and fails, it will be called from mirror_abort() again). In such a case, many of the pointers in the MirrorBlockJob object will already be freed. This can be seen most reliably for s->target, which is set to NULL (and then dereferenced by blk_bs()). Cc: qemu-stable@nongnu.org Fixes: 737efc1eda23b904fbe0e66b37715fb0e5c3e58b Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/mirror.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index fe984efb90..706d80fced 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -620,11 +620,11 @@ static int mirror_exit_common(Job *job) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockJob *bjob =3D &s->common; - MirrorBDSOpaque *bs_opaque =3D s->mirror_top_bs->opaque; + MirrorBDSOpaque *bs_opaque; AioContext *replace_aio_context =3D NULL; - BlockDriverState *src =3D s->mirror_top_bs->backing->bs; - BlockDriverState *target_bs =3D blk_bs(s->target); - BlockDriverState *mirror_top_bs =3D s->mirror_top_bs; + BlockDriverState *src; + BlockDriverState *target_bs; + BlockDriverState *mirror_top_bs; Error *local_err =3D NULL; bool abort =3D job->ret < 0; int ret =3D 0; @@ -634,6 +634,11 @@ static int mirror_exit_common(Job *job) } s->prepared =3D true; =20 + mirror_top_bs =3D s->mirror_top_bs; + bs_opaque =3D mirror_top_bs->opaque; + src =3D mirror_top_bs->backing->bs; + target_bs =3D blk_bs(s->target); + if (bdrv_chain_contains(src, target_bs)) { bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs); } --=20 2.21.0 From nobody Fri May 3 12:42:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571067701; cv=none; d=zoho.com; s=zohoarc; b=JxGBIRwSxqfj92ZZBnpAKWEAo13vRKvXuS0+SDx1q+q8o2hxcxf9e7VvJjIfhOTk8EIQ1DYlF65gn1cggCd1ijtrohAielgkwADek/nqvnAZFskqyOmqlo4uZ19HpARyfFETkJR7jeYBxG4x8YV/LJhfzm8ndsPCRd7K5CSMBwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571067701; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SWLIsjbgNZkWd4LwobD27Qkdofsnrm3IcL/uySPt2k8=; b=ZIa98qynr/grWX27FAR5K+9wCPf8UhjWyo9Cw1Z3gHt++m4vwKExaEMXBqCVd7DSoHcFr/4kEpJnJSF2wTP5JKopV+boNtyDJkgt+bCG4KYrjJ6TIuUeML3Znj/VZSUlDbvaMd0n4FgX73l1RdILsVPvAy9XzLqfGXazJZX/zus= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571067701815859.1176869018349; Mon, 14 Oct 2019 08:41:41 -0700 (PDT) Received: from localhost ([::1]:51648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2TX-0007jj-HF for importer@patchew.org; Mon, 14 Oct 2019 11:41:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60979) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2Rx-00063D-3f for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:39:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2Rv-0004Jc-LU for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:39:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iK2Rs-0004FP-Gb; Mon, 14 Oct 2019 11:39:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC51B30A7B9A; Mon, 14 Oct 2019 15:39:51 +0000 (UTC) Received: from localhost (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B9FF67268; Mon, 14 Oct 2019 15:39:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 2/4] blkdebug: Allow taking/unsharing permissions Date: Mon, 14 Oct 2019 17:39:29 +0200 Message-Id: <20191014153931.20699-3-mreitz@redhat.com> In-Reply-To: <20191014153931.20699-1-mreitz@redhat.com> References: <20191014153931.20699-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 14 Oct 2019 15:39:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Sometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug. (Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.) Signed-off-by: Max Reitz --- qapi/block-core.json | 14 ++++++- block/blkdebug.c | 91 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index f66553aac7..054ce651de 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3453,6 +3453,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 4.2) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug', @@ -3462,7 +3472,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } =20 ## # @BlockdevOptionsBlklogwrites: diff --git a/block/blkdebug.c b/block/blkdebug.c index 5ae96c52b0..6807c03065 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -28,10 +28,14 @@ #include "qemu/cutils.h" #include "qemu/config-file.h" #include "block/block_int.h" +#include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "sysemu/qtest.h" =20 typedef struct BDRVBlkdebugState { @@ -44,6 +48,9 @@ typedef struct BDRVBlkdebugState { uint64_t opt_discard; uint64_t max_discard; =20 + uint64_t take_child_perms; + uint64_t unshare_child_perms; + /* For blkdebug_refresh_filename() */ char *config_file; =20 @@ -344,6 +351,67 @@ static void blkdebug_parse_filename(const char *filena= me, QDict *options, qdict_put_str(options, "x-image", filename); } =20 +static int blkdebug_parse_perm_list(uint64_t *dest, QDict *options, + const char *prefix, Error **errp) +{ + int ret =3D 0; + QDict *subqdict =3D NULL; + QObject *crumpled_subqdict =3D NULL; + Visitor *v =3D NULL; + BlockPermissionList *perm_list =3D NULL, *element; + Error *local_err =3D NULL; + + qdict_extract_subqdict(options, &subqdict, prefix); + if (!qdict_size(subqdict)) { + goto out; + } + + crumpled_subqdict =3D qdict_crumple(subqdict, errp); + if (!crumpled_subqdict) { + ret =3D -EINVAL; + goto out; + } + + v =3D qobject_input_visitor_new(crumpled_subqdict); + visit_type_BlockPermissionList(v, NULL, &perm_list, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto out; + } + + for (element =3D perm_list; element; element =3D element->next) { + *dest |=3D UINT64_C(1) << element->value; + } + +out: + qapi_free_BlockPermissionList(perm_list); + visit_free(v); + qobject_unref(subqdict); + qobject_unref(crumpled_subqdict); + return ret; +} + +static int blkdebug_parse_perms(BDRVBlkdebugState *s, QDict *options, + Error **errp) +{ + int ret; + + ret =3D blkdebug_parse_perm_list(&s->take_child_perms, options, + "take-child-perms.", errp); + if (ret < 0) { + return ret; + } + + ret =3D blkdebug_parse_perm_list(&s->unshare_child_perms, options, + "unshare-child-perms.", errp); + if (ret < 0) { + return ret; + } + + return 0; +} + static QemuOptsList runtime_opts =3D { .name =3D "blkdebug", .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), @@ -419,6 +487,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *= options, int flags, /* Set initial state */ s->state =3D 1; =20 + /* Parse permissions modifiers before opening the image file */ + ret =3D blkdebug_parse_perms(s, options, errp); + if (ret < 0) { + goto out; + } + /* Open the image file */ bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "= image", bs, &child_file, false, &local_err); @@ -916,6 +990,21 @@ static int blkdebug_reopen_prepare(BDRVReopenState *re= open_state, return 0; } =20 +static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + BDRVBlkdebugState *s =3D bs->opaque; + + bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, + nperm, nshared); + + *nperm |=3D s->take_child_perms; + *nshared &=3D ~s->unshare_child_perms; +} + static const char *const blkdebug_strong_runtime_opts[] =3D { "config", "inject-error.", @@ -940,7 +1029,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_file_open =3D blkdebug_open, .bdrv_close =3D blkdebug_close, .bdrv_reopen_prepare =3D blkdebug_reopen_prepare, - .bdrv_child_perm =3D bdrv_filter_default_perms, + .bdrv_child_perm =3D blkdebug_child_perm, =20 .bdrv_getlength =3D blkdebug_getlength, .bdrv_refresh_filename =3D blkdebug_refresh_filename, --=20 2.21.0 From nobody Fri May 3 12:42:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571067698; cv=none; d=zoho.com; s=zohoarc; b=b0ayZo7DXLVZal7AUp1jY03W/lgpnR+p5UtuHwAnFAk0e9vdZXffwC4i1Ra1cJhebyrgEVeNqAUzND7d1YUgdeXA3VVte+Tzmhui5TgZehz7pdb/u/uVmY+JFze/czopOZmm4A+ERwvfYw7nUiQ5DEwFwRPASGPtbDKWTakLtWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571067698; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7fs2eeGjhdb5fF/H01BS5A30KuEBgPOC++z3d8WfZKw=; b=cWuelD3P7Po+PEApmcR9ujNoUIWmbehMjreSBUktFaR22UK0g8R0YDzC0IFMdbaW+vEC+/ZjvmDiWeUACOuQUuckFxN0vILs6netLJIN7HBaEeVacdpufaLfF/KTnBTd16+Wwwl4WctlHWnvi065ftj2cEp9XY6Tci2RMFEGRSA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571067698896467.25392723626567; Mon, 14 Oct 2019 08:41:38 -0700 (PDT) Received: from localhost ([::1]:51646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2TX-0007ik-J6 for importer@patchew.org; Mon, 14 Oct 2019 11:41:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32770) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2S1-0006B4-Uc for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:40:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2S0-0004LT-RJ for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:40:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iK2Ry-0004KI-9X; Mon, 14 Oct 2019 11:39:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BCC01017C0F; Mon, 14 Oct 2019 15:39:57 +0000 (UTC) Received: from localhost (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0031166A2; Mon, 14 Oct 2019 15:39:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 3/4] iotests: Add @error to wait_until_completed Date: Mon, 14 Oct 2019 17:39:30 +0200 Message-Id: <20191014153931.20699-4-mreitz@redhat.com> In-Reply-To: <20191014153931.20699-1-mreitz@redhat.com> References: <20191014153931.20699-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 14 Oct 2019 15:39:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Callers can use this new parameter to expect failure during the completion process. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/iotests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 43759e4e27..7af77ef496 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -770,15 +770,20 @@ class QMPTestCase(unittest.TestCase): self.assert_no_active_block_jobs() return result =20 - def wait_until_completed(self, drive=3D'drive0', check_offset=3DTrue, = wait=3D60.0): + def wait_until_completed(self, drive=3D'drive0', check_offset=3DTrue, = wait=3D60.0, + error=3DNone): '''Wait for a block job to finish, returning the event''' while True: for event in self.vm.get_qmp_events(wait=3Dwait): if event['event'] =3D=3D 'BLOCK_JOB_COMPLETED': self.assert_qmp(event, 'data/device', drive) - self.assert_qmp_absent(event, 'data/error') - if check_offset: - self.assert_qmp(event, 'data/offset', event['data'= ]['len']) + if error is None: + self.assert_qmp_absent(event, 'data/error') + if check_offset: + self.assert_qmp(event, 'data/offset', + event['data']['len']) + else: + self.assert_qmp(event, 'data/error', error) self.assert_no_active_block_jobs() return event elif event['event'] =3D=3D 'JOB_STATUS_CHANGE': @@ -796,7 +801,8 @@ class QMPTestCase(unittest.TestCase): self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/offset', event['data']['len']) =20 - def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue): + def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue, + completion_error=3DNone): '''Complete a block job and wait for it to finish''' if wait_ready: self.wait_ready(drive=3Ddrive) @@ -804,7 +810,7 @@ class QMPTestCase(unittest.TestCase): result =3D self.vm.qmp('block-job-complete', device=3Ddrive) self.assert_qmp(result, 'return', {}) =20 - event =3D self.wait_until_completed(drive=3Ddrive) + event =3D self.wait_until_completed(drive=3Ddrive, error=3Dcomplet= ion_error) self.assert_qmp(event, 'data/type', 'mirror') =20 def pause_wait(self, job_id=3D'job0'): --=20 2.21.0 From nobody Fri May 3 12:42:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571067838; cv=none; d=zoho.com; s=zohoarc; b=ckFNZl50KlZqXUxYyhjR1l9KLmlKtH6W/lMAbkPYrRIj9dSlOAbD3bGQULX+lqxfC94NoOfCYU6RusV67AWI+T+qHLl/FPrSjD4emWTlL29v1fPoEPeyj3OyPoNdUhXrfAejo9KqlQ7im7OnMXMaXqxCpoZ/NdcSDAdWACsbUvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571067838; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/5QDp5etfSMbam5+QuMUMeY8mRdzZ4VZ1kJVVHIXcMw=; b=PNbMNw/SaEF+7zdySXYnJdFeuNtGRguBcPcnInA/Lb12G5cCk7ZYgAIoOZpJbBNrV5QZQpvtYNxQPdwLoyYk2f0LO59ySIHdHSEpdAYervHk993LRN0WjSigGjqOzd1jq7UKdJHVU7SgS7Yx8EOsXxoto2Nxvz9PQp9XmxXTNhM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571067838434648.9570600393827; Mon, 14 Oct 2019 08:43:58 -0700 (PDT) Received: from localhost ([::1]:51692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2Vp-0002DH-9S for importer@patchew.org; Mon, 14 Oct 2019 11:43:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32826) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2S9-0006OO-1v for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:40:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2S7-0004Og-Ru for qemu-devel@nongnu.org; Mon, 14 Oct 2019 11:40:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iK2S5-0004NO-8F; Mon, 14 Oct 2019 11:40:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E2818E1CEA; Mon, 14 Oct 2019 15:40:04 +0000 (UTC) Received: from localhost (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2E1567617; Mon, 14 Oct 2019 15:39:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v3 4/4] iotests: Add test for failing mirror complete Date: Mon, 14 Oct 2019 17:39:31 +0200 Message-Id: <20191014153931.20699-5-mreitz@redhat.com> In-Reply-To: <20191014153931.20699-1-mreitz@redhat.com> References: <20191014153931.20699-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Mon, 14 Oct 2019 15:40:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy Tested-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- tests/qemu-iotests/041 | 44 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 8568426311..d7be30b62b 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1121,6 +1121,50 @@ class TestOrphanedSource(iotests.QMPTestCase): target=3D'dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') =20 + def test_failing_permission_in_complete(self): + self.assert_no_active_block_jobs() + + # Unshare consistent-read on the target + # (The mirror job does not care) + result =3D self.vm.qmp('blockdev-add', + driver=3D'blkdebug', + node_name=3D'dest-perm', + image=3D'dest', + unshare_child_perms=3D['consistent-read']) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', job_id=3D'job', device= =3D'src', + sync=3D'full', target=3D'dest', + filter_node_name=3D'mirror-filter') + self.assert_qmp(result, 'return', {}) + + # Require consistent-read on the source + # (We can only add this node once the job has started, or it + # will complain that it does not want to run on non-root nodes) + result =3D self.vm.qmp('blockdev-add', + driver=3D'blkdebug', + node_name=3D'src-perm', + image=3D'src', + take_child_perms=3D['consistent-read']) + self.assert_qmp(result, 'return', {}) + + # While completing, mirror will attempt to replace src by + # dest, which must fail because src-perm requires + # consistent-read but dest-perm does not share it; thus + # aborting the job when it is supposed to complete + self.complete_and_wait('job', + completion_error=3D'Operation not permitted= ') + + # Assert that all of our nodes are still there (except for the + # mirror filter, which should be gone despite the failure) + nodes =3D self.vm.qmp('query-named-block-nodes')['return'] + nodes =3D [node['node-name'] for node in nodes] + + for expect in ('src', 'src-perm', 'dest', 'dest-perm'): + self.assertTrue(expect in nodes, '%s disappeared' % expect) + self.assertFalse('mirror-filter' in nodes, + 'Mirror filter node did not disappear') + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 2c448b4239..f496be9197 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= ................ +..........................................................................= ................. ---------------------------------------------------------------------- -Ran 90 tests +Ran 91 tests =20 OK --=20 2.21.0