From nobody Wed May 8 01:49:18 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=1569240456; cv=none; d=zoho.com; s=zohoarc; b=gLT1/KMsSzjYU3gFnMeWbS8kF6OKaSp+onLNtBxhvLwqVIR3Iv2ERYw1b+9f0DQ3OflrmkYJLnjf1KHWWXmkbgeOxSbnTL1R2f8P8hUNodngcqcR8Dq6BKlfcaDaQBS0mu3042aNrLFiqoRBoCGMnAK2xDTMRN1yFRVQHOdorqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569240456; 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:ARC-Authentication-Results; bh=F45PXWKM5Ac1xd2K17PN60D0xKmTHDIWsREJRfGkgBE=; b=Lt70xBD8Wq+xZprxouUHbMNOAAv2JM3o6q58MCz3refxwFOIKMXRSmkC2vpXyAb5UD8slddU07fVuP7gkA1GD6mC2sW4CSB+1ZhMc2QqwfZhjKxmHF9nkRcHXn6x41YBvOiDU2h2LyUpUC2dBbR/rHKIRMfC5i8OwIY3JWTDTqY= 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 1569240456136341.42136037522357; Mon, 23 Sep 2019 05:07:36 -0700 (PDT) Received: from localhost ([::1]:55404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCN7u-0001j9-PI for importer@patchew.org; Mon, 23 Sep 2019 08:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45237) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCMyO-0003Lt-Ic for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCMyM-0006sv-GN for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42260) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCMyI-0006q4-9P; Mon, 23 Sep 2019 07:57:38 -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 9A12C3090FC4; Mon, 23 Sep 2019 11:57:37 +0000 (UTC) Received: from localhost (unknown [10.40.205.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6B9719D70; Mon, 23 Sep 2019 11:57:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 1/4] mirror: Do not dereference invalid pointers Date: Mon, 23 Sep 2019 13:57:25 +0200 Message-Id: <20190923115728.28250-2-mreitz@redhat.com> In-Reply-To: <20190923115728.28250-1-mreitz@redhat.com> References: <20190923115728.28250-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.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 23 Sep 2019 11:57:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 Wed May 8 01:49:18 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=1569240007; cv=none; d=zoho.com; s=zohoarc; b=VsHxk5UNbvmQfGQ6uynr0p7pa8/ScCOI6J7z34iBqoQ3xxjg6g6ODpzEMdfx30apgegKe+fEeNXYAEfrgHJt86TZhPGtTyHNXgLHo4kD4gqG2BIyoi/CEmDqwTupDhS0ZaT5OQigj86v1L/HqHgLBxTdPg6SBEkNYyqbC2H2vLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569240007; 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:ARC-Authentication-Results; bh=i/w4/sjonu1HgA/+7QFO26iQDyVMsKxxkUuoeOpbYpU=; b=meT6CjYtWhKkdh0Jy7/Xnb0VrhoW4J6fPgudoN0IJbIoxntm8vNp4b7hmDFOyCjc1Cr6o/+YnD4UrkJDRWOh9FIliXKTGelPfYNkwqoslagtg4B+2GVWkSyVaRxRyGqcT2IpIPDX/VZ5r4rjTDFjHE0o4IYD++raM7P7jSdsej8= 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 1569240007116687.7906257415923; Mon, 23 Sep 2019 05:00:07 -0700 (PDT) Received: from localhost ([::1]:55218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCN0f-0004v4-Sc for importer@patchew.org; Mon, 23 Sep 2019 08:00:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45259) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCMyR-0003P9-Q6 for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCMyQ-0006w1-8A for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCMyN-0006t0-1S; Mon, 23 Sep 2019 07:57:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BFA310C0937; Mon, 23 Sep 2019 11:57:42 +0000 (UTC) Received: from localhost (unknown [10.40.205.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D40C5D717; Mon, 23 Sep 2019 11:57:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 2/4] blkdebug: Allow taking/unsharing permissions Date: Mon, 23 Sep 2019 13:57:26 +0200 Message-Id: <20190923115728.28250-3-mreitz@redhat.com> In-Reply-To: <20190923115728.28250-1-mreitz@redhat.com> References: <20190923115728.28250-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Mon, 23 Sep 2019 11:57:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 | 106 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index b5cd00c361..572c5756f1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3394,6 +3394,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', @@ -3403,7 +3413,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..f3c1e4ad7b 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -28,9 +28,11 @@ #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/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" #include "sysemu/qtest.h" =20 @@ -44,6 +46,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 +349,84 @@ 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; + QList *perm_list; + const QListEntry *perm; + + 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; + } + + perm_list =3D qobject_to(QList, crumpled_subqdict); + if (!perm_list) { + /* Omit the trailing . from the prefix */ + error_setg(errp, "%.*s expects a list", + (int)(strlen(prefix) - 1), prefix); + ret =3D -EINVAL; + goto out; + } + + for (perm =3D qlist_first(perm_list); perm; perm =3D qlist_next(perm))= { + const char *perm_name; + BlockPermission perm_bit; + + perm_name =3D qstring_get_try_str(qobject_to(QString, perm->value)= ); + if (!perm_name) { + /* Omit the trailing . from the prefix */ + error_setg(errp, "%.*s expects a list of enum strings", + (int)(strlen(prefix) - 1), prefix); + ret =3D -EINVAL; + goto out; + } + + perm_bit =3D qapi_enum_parse(&BlockPermission_lookup, perm_name, + BLOCK_PERMISSION__MAX, errp); + if (perm_bit =3D=3D BLOCK_PERMISSION__MAX) { + ret =3D -EINVAL; + goto out; + } + + *dest |=3D UINT64_C(1) << perm_bit; + } + +out: + 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 +502,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 +1005,21 @@ static int blkdebug_reopen_prepare(BDRVReopenState *r= eopen_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 +1044,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 Wed May 8 01:49:18 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=1569240209; cv=none; d=zoho.com; s=zohoarc; b=UWMLWf94pEshzh//thOuCrWv6naBgv1/b1Kk7/DR3g7rdN4J8y54BhFLFh1pUnE9nVlXFrGQrhNcO2+vsGqnW5KT840ZjF6ogNHT49PhiIIrX1aO3XlW4F0MbOheRjpHA/i8sw+dVNfkEZ8YycjubaP/v01VpsfPvuhciWlrCr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569240209; 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:ARC-Authentication-Results; bh=9wLGMa4ElPbfy9dXBIGD90qcn/OPxWRl4ZdBw2bqOkM=; b=mpnN2SxoRo9BuOo8dvmlDPm+4DTpCKAJjXCQNm8Kg+s5agP0avWNot5qFBvJflBwBes6jN1N4g9H+iRXzNtpGL16YolQkCwgNtRGiURjkmOwz8JXplUlm86kX9WOijadNWc/a0N1tA/J0nNangRKbSCWz0XUuSs7NupOnVccRiI= 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 1569240208842704.9608191520628; Mon, 23 Sep 2019 05:03:28 -0700 (PDT) Received: from localhost ([::1]:55298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCN3p-00071D-Qf for importer@patchew.org; Mon, 23 Sep 2019 08:03:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45288) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCMyW-0003VN-Hm for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCMyU-0006zv-VC for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:57:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCMyS-0006ws-67; Mon, 23 Sep 2019 07:57:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 608DB2BF02; Mon, 23 Sep 2019 11:57:47 +0000 (UTC) Received: from localhost (unknown [10.40.205.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CE97608C2; Mon, 23 Sep 2019 11:57:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 3/4] iotests: Add @error to wait_until_completed Date: Mon, 23 Sep 2019 13:57:27 +0200 Message-Id: <20190923115728.28250-4-mreitz@redhat.com> In-Reply-To: <20190923115728.28250-1-mreitz@redhat.com> References: <20190923115728.28250-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Sep 2019 11:57:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 3a8f378f90..5d44183f8f 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 Wed May 8 01:49:18 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=1569240233; cv=none; d=zoho.com; s=zohoarc; b=eT+ZyuNH2lraBelc/WGNUGTF+t8V7j9Ft+JO76Ut2p6zfb49st4PtisAaL+SpwFESrnqjZqh8pLZmJUfYyqDw+gEezEQAcs7PC3OLvh/D/HICoVTGtxD5DRkdMS7I06gGD5/k2D92zWjW1DWsotHNB6hYGerDYM5+LCMySgMeok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569240233; 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:ARC-Authentication-Results; bh=/5QDp5etfSMbam5+QuMUMeY8mRdzZ4VZ1kJVVHIXcMw=; b=l2CVjlBCQTSI3OUGu8FAeVvUG0y9eQ8ESo0ye63RD/TlIBZ5e5U6FeWnNV+18lanlsZ2EzMpVm2vsI/6Vkes1sSwJPgF5Bw+bSwPuVBIa63901k9GDNJ/6flE5S1qlv2Kg7+quu2pdNBI5PxmSskSiRlWW0XNd9EfnL/+XF06Sk= 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 1569240233466662.6629946641909; Mon, 23 Sep 2019 05:03:53 -0700 (PDT) Received: from localhost ([::1]:55302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCN4K-0007ME-B1 for importer@patchew.org; Mon, 23 Sep 2019 08:03:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45339) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCMye-0003bq-Rh for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:58:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCMyd-0007Gc-Ij for qemu-devel@nongnu.org; Mon, 23 Sep 2019 07:58:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57383) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCMyY-000710-FA; Mon, 23 Sep 2019 07:57:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B23A10DCC81; Mon, 23 Sep 2019 11:57:52 +0000 (UTC) Received: from localhost (unknown [10.40.205.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73E6D600C4; Mon, 23 Sep 2019 11:57:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 4/4] iotests: Add test for failing mirror complete Date: Mon, 23 Sep 2019 13:57:28 +0200 Message-Id: <20190923115728.28250-5-mreitz@redhat.com> In-Reply-To: <20190923115728.28250-1-mreitz@redhat.com> References: <20190923115728.28250-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 23 Sep 2019 11:57:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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