From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941426; cv=none;
	d=zohomail.com; s=zohoarc;
	b=E4u8q1ldemSeOwdWsjaRBLeBcNSqKWAOKn1HSHDN3pi6PGn6hEUzmeK8mul/aV2R7sAPTCVjtnGqyTDlE7q80U9khQlmZ3XmBnddlN6C65skegA3QoSDlgLjOz6dVKxoDs+CFERpQ6gITVMw+5g53ZlC8Vbf4o2rD3pKS2funWE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941426;
 h=Content-Type: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=FOy2nQnwPIklpZwfOTtGVb1JhnKuVMjQB1kgp9F4dkI=;
	b=HqPbEVQx4S3mUGs73GpXWS2q8OQk8HUFGqespgR4oc9QrD5hG7Rl7Pq0ovJe8grbrtL3adVEOIoUlfMaItVTJU308bwZ1wlaqgHbXB6PbSwlOTgFKwah2VZSA0k6lk2X9MyeewcSJQ3AF8Vj5mXVhyIpJEpiHTmTHxqq+s4mfsM=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941426809677.6590452350313;
 Wed, 11 Mar 2020 08:43:46 -0700 (PDT)
Received: from localhost ([::1]:54470 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3WL-0004MA-OT
	for importer@patchew.org; Wed, 11 Mar 2020 11:43:45 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59593)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3V7-0002XC-7U
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:30 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3V6-0001sv-3P
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:29 -0400
Received: from us-smtp-1.mimecast.com ([207.211.31.81]:60172
 helo=us-smtp-delivery-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3V5-0001qX-W2
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:28 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-167-wJ1QGxfkO1ioyARjRNF6Jg-1; Wed, 11 Mar 2020 11:42:25 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3D7F818A5502;
 Wed, 11 Mar 2020 15:42:24 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 453CE91D74;
 Wed, 11 Mar 2020 15:42:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941347;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=FOy2nQnwPIklpZwfOTtGVb1JhnKuVMjQB1kgp9F4dkI=;
 b=ej06Qd4j5+P8vJ93dXMPt7Co/VbaLVMgEYoNzSe08aMpXNdhAMudBSgBHNW8Fiks5Rd3c2
 UorO/H6ZjCAPfBE4NREFmHepTKgF5S5JUgwyWQuumsLu3J2r47Vq7LwSCHsnPxrOjFjRy3
 JewtFbeDA3KBhueUx449w10GAbrdz/o=
X-MC-Unique: wJ1QGxfkO1ioyARjRNF6Jg-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 01/13] qom-qmp-cmds: fix two memleaks in qmp_object_add
Date: Wed, 11 Mar 2020 16:42:06 +0100
Message-Id: <20200311154218.15532-2-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.81
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Pan Nengyuan <pannengyuan@huawei.com>

'type/id' forgot to free in qmp_object_add, this patch fix that.

The leak stack:
Direct leak of 84 byte(s) in 6 object(s) allocated from:
    #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768)
    #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445)
    #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92)
    #3 0x56344954e692 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qo=
m/qom-qmp-cmds.c:258
    #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/q=
api/qmp-dispatch.c:132
    #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi=
/qmp-dispatch.c:175
    #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/q=
emu/monitor/qmp.c:145
    #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_t=
est/qemu/monitor/qmp.c:234
    #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/=
async.c:136

Direct leak of 54 byte(s) in 6 object(s) allocated from:
    #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768)
    #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445)
    #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92)
    #3 0x56344954e6c4 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qo=
m/qom-qmp-cmds.c:267
    #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/q=
api/qmp-dispatch.c:132
    #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi=
/qmp-dispatch.c:175
    #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/q=
emu/monitor/qmp.c:145
    #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_t=
est/qemu/monitor/qmp.c:234
    #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/=
async.c:136

Fixes: 5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Message-Id: <20200310064640.5059-1-pannengyuan@huawei.com>
Reviewed-by: Daniel P. Berrang=C3=A9 <berrange@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qom/qom-qmp-cmds.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 49db926fcc..435193b036 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -247,26 +247,22 @@ void qmp_object_add(QDict *qdict, QObject **ret_data,=
 Error **errp)
     QDict *pdict;
     Visitor *v;
     Object *obj;
-    const char *type;
-    const char *id;
+    g_autofree char *type =3D NULL;
+    g_autofree char *id =3D NULL;
=20
-    type =3D qdict_get_try_str(qdict, "qom-type");
+    type =3D g_strdup(qdict_get_try_str(qdict, "qom-type"));
     if (!type) {
         error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
         return;
-    } else {
-        type =3D g_strdup(type);
-        qdict_del(qdict, "qom-type");
     }
+    qdict_del(qdict, "qom-type");
=20
-    id =3D qdict_get_try_str(qdict, "id");
+    id =3D g_strdup(qdict_get_try_str(qdict, "id"));
     if (!id) {
         error_setg(errp, QERR_MISSING_PARAMETER, "id");
         return;
-    } else {
-        id =3D g_strdup(id);
-        qdict_del(qdict, "id");
     }
+    qdict_del(qdict, "id");
=20
     props =3D qdict_get(qdict, "props");
     if (props) {
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941863; cv=none;
	d=zohomail.com; s=zohoarc;
	b=nD5wcHIEk+YWJhsd1Ge3Mfqrio7fwiyA+Fm928RCLpPSr6dGiSl5N8/OGyjY+5zyOUn+DiRUBpwqNdiV9ba+VPku4CTLxYx3dCCFYBeHGyvZ8ny36xtJfrrpTU+9x8Gvnbt68tKFB8Oru0lK4XAs2/+G6AdFO+FHCMeWJV0nEIA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941863;
 h=Content-Type: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=qtRbuuoYu3vUpINTNeXrWqzHkgO+/Uo3yQUFHwEdpQc=;
	b=luqc4nKM9kPN9iRHDIR1YKf8dxrX9fQd+d9NSvfWG2wFYqKMMlA2IE2gJmN4fREc077viGQ0Ni2/fxbAi6L4WlQwnIPNivo8FOzUhmZ8UB29ZGJW1sJgKDI+rkvRdMTGHjn5IPXh0/zM3NR+2BFCTLKR6JpEGyQXuQLok2OaeCg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941863970529.0678024766183;
 Wed, 11 Mar 2020 08:51:03 -0700 (PDT)
Received: from localhost ([::1]:54642 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3dM-0008Uh-Jz
	for importer@patchew.org; Wed, 11 Mar 2020 11:51:00 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59749)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VG-0002oX-It
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VF-0002lZ-Ar
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:38 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:22927
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VF-0002jC-6y
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:37 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-237-9C414H2dNAKouDANC3UapA-1; Wed, 11 Mar 2020 11:42:26 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FE0E18A5508;
 Wed, 11 Mar 2020 15:42:25 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 8346391D74;
 Wed, 11 Mar 2020 15:42:24 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941356;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=qtRbuuoYu3vUpINTNeXrWqzHkgO+/Uo3yQUFHwEdpQc=;
 b=V6+6L50dtB7qvEZ1tEapUHosmiB7c3Tn2cxKOZlSLL3oP16A+++oSVq0ZIMyw6+kGZqrAZ
 uDgHXxERNpny9kAABBztfreMyonyZS1WRsr4dyMk2f0SQR0t80lVcD4E0xxvHLJSgAfgW1
 Zww7EX6oQl4uyLeNQwrvlJN+IK3IBoQ=
X-MC-Unique: 9C414H2dNAKouDANC3UapA-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 02/13] block: Make bdrv_get_cumulative_perm() public
Date: Wed, 11 Mar 2020 16:42:07 +0100
Message-Id: <20200311154218.15532-3-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-2-kwolf@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/block_int.h | 3 +++
 block.c                   | 6 ++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/block/block_int.h b/include/block/block_int.h
index 3f70a98b2d..d8d13700a9 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -1224,6 +1224,9 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *c=
hild_bs,
                                   void *opaque, Error **errp);
 void bdrv_root_unref_child(BdrvChild *child);
=20
+void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
+                              uint64_t *shared_perm);
+
 /**
  * Sets a BdrvChild's permissions.  Avoid if the parent is a BDS; use
  * bdrv_child_refresh_perms() instead and make the parent's
diff --git a/block.c b/block.c
index 957630b1c5..79a5a2770f 100644
--- a/block.c
+++ b/block.c
@@ -1872,8 +1872,6 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockR=
eopenQueue *q,
                                  bool *tighten_restrictions, Error **errp);
 static void bdrv_child_abort_perm_update(BdrvChild *c);
 static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shar=
ed);
-static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
-                                     uint64_t *shared_perm);
=20
 typedef struct BlockReopenQueueEntry {
      bool prepared;
@@ -2097,8 +2095,8 @@ static void bdrv_set_perm(BlockDriverState *bs, uint6=
4_t cumulative_perms,
     }
 }
=20
-static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
-                                     uint64_t *shared_perm)
+void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
+                              uint64_t *shared_perm)
 {
     BdrvChild *c;
     uint64_t cumulative_perms =3D 0;
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941428; cv=none;
	d=zohomail.com; s=zohoarc;
	b=SUUffotFuB0mm2+89AsZA+gWRj7YXP60vfcVUXOMJFEl1HbVoKjRQ6PNuOoxLMkMNw1B24v+XLRsSdIgkQJSA3vsqsPMcww1WjnvsEye7oY8lyfTP3G2/nNRZiiilIOZL+3mHI4283sTO1+paLbeGV6lXUlAvegTN0nBZo0W1bI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941428;
 h=Content-Type: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=dHBO9R+zUZqsajXF82ZWfcPQFIROfvmOtd4KApaM7jg=;
	b=V8Q/Tdg0Ya0ZGAUX0qp6iC6zLca2UHl5QNzKKJoBMZZCXsbPdR4OYwERf0WRDgTsHUP7v6xmTGzH7rqjQ8l66PncuCFrbX+c/ZQWbNF8mnlYjEWOUhjtICaiEOwhca7OGwDQ2y1LLn9Vnu4PNV3vud4UOs1hfQ1OBxJLqA8r26s=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941428506364.88293758654163;
 Wed, 11 Mar 2020 08:43:48 -0700 (PDT)
Received: from localhost ([::1]:54480 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3WN-0004Uc-GU
	for importer@patchew.org; Wed, 11 Mar 2020 11:43:47 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59667)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VC-0002hk-JZ
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VB-0002Tj-6e
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:34 -0400
Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23141
 helo=us-smtp-delivery-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VB-0002PL-22
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:33 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-252-XXMMMva_OFakeeVW84iW0g-1; Wed, 11 Mar 2020 11:42:27 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6B10107ACC4;
 Wed, 11 Mar 2020 15:42:26 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id C541360BEE;
 Wed, 11 Mar 2020 15:42:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941352;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=dHBO9R+zUZqsajXF82ZWfcPQFIROfvmOtd4KApaM7jg=;
 b=gVLZLAWx0ElwuKpB9yDnaBxPTP8R9csphmx3PDqZDeW1PdjSReZHpyKIqBJAcU9niQTJ1H
 qaJuhBPbB5Gg+CsmX1T8IrBou2GqEg9gFG57Wy8OuASzcdTee11hmKdwGDM0xuN5OS5KbG
 JEtoMbpP8ImYm/4vylcSsaM4FGIHL4I=
X-MC-Unique: XXMMMva_OFakeeVW84iW0g-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 03/13] block: Relax restrictions for blockdev-snapshot
Date: Wed, 11 Mar 2020 16:42:08 +0100
Message-Id: <20200311154218.15532-4-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.61
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

blockdev-snapshot returned an error if the overlay was already in use,
which it defined as having any BlockBackend parent. This is in fact both
too strict (some parents can tolerate the change of visible data caused
by attaching a backing file) and too loose (some non-BlockBackend
parents may not be happy with it).

One important use case that is prevented by the too strict check is live
storage migration with blockdev-mirror. Here, the target node is
usually opened without a backing file so that the active layer is
mirrored while its backing chain can be copied in the background.

The backing chain should be attached to the mirror target node when
finalising the job, just before switching the users of the source node
to the new copy (at which point the mirror job still has a reference to
the node). drive-mirror did this automatically, but with blockdev-mirror
this is the job of the QMP client, so it needs a way to do this.

blockdev-snapshot is the obvious way, so this patch makes it work in
this scenario. The new condition is that no parent uses CONSISTENT_READ
permissions. This will ensure that the operation will still be blocked
when the node is attached to the guest device, so blockdev-snapshot
remains safe.

(For the sake of completeness, x-blockdev-reopen can be used to achieve
the same, however it is a big hammer, performs the graph change
completely unchecked and is still experimental. So even with the option
of using x-blockdev-reopen, there are reasons why blockdev-snapshot
should be able to perform this operation.)

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-3-kwolf@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 blockdev.c                 | 14 ++++++++------
 tests/qemu-iotests/085.out |  4 ++--
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 257cb37682..ea89896f27 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1471,6 +1471,7 @@ static void external_snapshot_prepare(BlkActionState =
*common,
     TransactionAction *action =3D common->action;
     AioContext *aio_context;
     AioContext *old_context;
+    uint64_t perm, shared;
     int ret;
=20
     /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar
@@ -1586,16 +1587,17 @@ static void external_snapshot_prepare(BlkActionStat=
e *common,
         goto out;
     }
=20
-    if (bdrv_has_blk(state->new_bs)) {
+    /*
+     * Allow attaching a backing file to an overlay that's already in use =
only
+     * if the parents don't assume that they are already seeing a valid im=
age.
+     * (Specifically, allow it as a mirror target, which is write-only acc=
ess.)
+     */
+    bdrv_get_cumulative_perm(state->new_bs, &perm, &shared);
+    if (perm & BLK_PERM_CONSISTENT_READ) {
         error_setg(errp, "The overlay is already in use");
         goto out;
     }
=20
-    if (bdrv_op_is_blocked(state->new_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
-                           errp)) {
-        goto out;
-    }
-
     if (state->new_bs->backing !=3D NULL) {
         error_setg(errp, "The overlay already has a backing image");
         goto out;
diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out
index d94ad22f70..fd11aae678 100644
--- a/tests/qemu-iotests/085.out
+++ b/tests/qemu-iotests/085.out
@@ -82,7 +82,7 @@ Formatting 'TEST_DIR/12-snapshot-v0.IMGFMT', fmt=3DIMGFMT=
 size=3D134217728 backing_f
 =3D=3D=3D Invalid command - cannot create a snapshot using a file BDS =3D=
=3D=3D
=20
 { 'execute': 'blockdev-snapshot', 'arguments': { 'node':'virtio0', 'overla=
y':'file_12' } }
-{"error": {"class": "GenericError", "desc": "The overlay does not support =
backing images"}}
+{"error": {"class": "GenericError", "desc": "The overlay is already in use=
"}}
=20
 =3D=3D=3D Invalid command - snapshot node used as active layer =3D=3D=3D
=20
@@ -96,7 +96,7 @@ Formatting 'TEST_DIR/12-snapshot-v0.IMGFMT', fmt=3DIMGFMT=
 size=3D134217728 backing_f
 =3D=3D=3D Invalid command - snapshot node used as backing hd =3D=3D=3D
=20
 { 'execute': 'blockdev-snapshot', 'arguments': { 'node': 'virtio0', 'overl=
ay':'snap_11' } }
-{"error": {"class": "GenericError", "desc": "Node 'snap_11' is busy: node =
is used as backing hd of 'snap_12'"}}
+{"error": {"class": "GenericError", "desc": "The overlay is already in use=
"}}
=20
 =3D=3D=3D Invalid command - snapshot node has a backing image =3D=3D=3D
=20
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941592; cv=none;
	d=zohomail.com; s=zohoarc;
	b=UyCpQpGFSOoxtk+vDv7P5BhyLh4lgQE1daXSJ/QGxNnb97/fyr2GPf0ZUK3//77u0y/LWsL7E0Y4PkoPBQ6lbhI+eycugRSNl1zY0RLGhXFD/lnSfyjv2tsNL2+m/Jk5bhTmWdpiQlbXlVgf4goJZbpEeUY3Elw1XPeRuwKi9Z4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941592;
 h=Content-Type: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=MWPhV+y2kBgTCwkC0yfNMHzSleKX6ycdVr9jjlicdOU=;
	b=UwSR4zrSJQJYnJKM93DrSmKcL934bFyG1KU3eYnPd68p5UCimq+lFLv9BB+snxf3CYgw+9Dz8ge0hV5K+cl2v2uwtJ+lzRscXf30SG2RI6Tm/wN0aYMHiANv53wDk9Xq0R8/QcI5hL1dyJow51nwKubJBO9SxDFEBKQzg619Of8=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941592795356.5791984842348;
 Wed, 11 Mar 2020 08:46:32 -0700 (PDT)
Received: from localhost ([::1]:54562 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3Yz-00005g-W4
	for importer@patchew.org; Wed, 11 Mar 2020 11:46:30 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59676)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VD-0002iH-19
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:35 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VC-0002XP-0f
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:34 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40974
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VB-0002Wo-Su
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:33 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-154-dyzrZS-EMcyxk-2DKoZ9mw-1; Wed, 11 Mar 2020 11:42:29 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 124D3DB60;
 Wed, 11 Mar 2020 15:42:28 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 1AB5D60BEE;
 Wed, 11 Mar 2020 15:42:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941353;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=MWPhV+y2kBgTCwkC0yfNMHzSleKX6ycdVr9jjlicdOU=;
 b=CfWjE32rTqtCETNko3lTF7FpoxXRXao1jpny7m/H5XS5v0nP60cSgXi0gU2I+JLjHimR+C
 Qwmg/2QJvRcZpUiYexcacYlhNWyigmyyAwrOnu/bGeCkA/XcFbyma+i7xaPw6Wq0a4zEH+
 IhwJDSo61PyZ/4HIWjVu3d4Tj1kvFrs=
X-MC-Unique: dyzrZS-EMcyxk-2DKoZ9mw-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 04/13] iotests: Fix run_job() with use_log=False
Date: Wed, 11 Mar 2020 16:42:09 +0100
Message-Id: <20200311154218.15532-5-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

The 'job-complete' QMP command should be run with qmp() rather than
qmp_log() if use_log=3DFalse is passed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-4-kwolf@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/iotests.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 8815052eb5..23043baa26 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -624,7 +624,10 @@ class VM(qtest.QEMUQtestMachine):
                         if use_log:
                             log('Job failed: %s' % (j['error']))
             elif status =3D=3D 'ready':
-                self.qmp_log('job-complete', id=3Djob)
+                if use_log:
+                    self.qmp_log('job-complete', id=3Djob)
+                else:
+                    self.qmp('job-complete', id=3Djob)
             elif status =3D=3D 'pending' and not auto_finalize:
                 if pre_finalize:
                     pre_finalize()
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941480; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ZWsSf6Gh9vACiegw9CSqvvEtKl35oQK93C8Nb6mCqoAYmRSKLBUK06ZX4Ppzokq1LeSTh3wUKshYGC1X7AsmRu7AY6DqdAG/rbxtDALXFKz2z6HeE2un2vGAyX6koapzZ/puNSPQfH+dpk7WjmH6eoOsrO677wQ/1c1YLp5wymQ=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941480;
 h=Content-Type: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=DxnNtm1kTpCV9VYuByxY/yfho1dAzl7t7Nd0hY5+KB0=;
	b=QACllpjMa/ZQ0BVstR1s6bscNT9cC2wSW66YUOblCcPAZjQ25BGvJtoEDIKiC1ChAi02DddNQeifIB2KIK37eUQkcrjFjm0LCo1MCZoKUD2lrsDX3XjD29cS/wtmK1+zShvohRKwYIjYiD3x/JIoHH8qKJwJgQ6XX9hsjSwN78g=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941480736760.9564920977439;
 Wed, 11 Mar 2020 08:44:40 -0700 (PDT)
Received: from localhost ([::1]:54486 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3XD-0005eq-Fj
	for importer@patchew.org; Wed, 11 Mar 2020 11:44:39 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59660)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VC-0002hb-Eb
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:35 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VB-0002S2-0o
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:34 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:50288
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VA-0002Ox-Rq
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:32 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-193-a-1HMf-9OrCObNz29T7T_g-1; Wed, 11 Mar 2020 11:42:30 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52536DB65;
 Wed, 11 Mar 2020 15:42:29 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 59ABF92D2C;
 Wed, 11 Mar 2020 15:42:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941352;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=DxnNtm1kTpCV9VYuByxY/yfho1dAzl7t7Nd0hY5+KB0=;
 b=TnTINuKR786/uP7d1b2INqVjschri4lzELJaEB+HhNwEv5dp8vgjf281BOf13Va2wUVBXt
 20fAfBUbdWmwPDV+hixclcRaM9gsdrQhWz6itiGAykrcgNAFvFNw+fKyzCaEtnf0MUP8Ti
 TvjWkIV6SeFeNkDP67yv99PlaIc+FJU=
X-MC-Unique: a-1HMf-9OrCObNz29T7T_g-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 05/13] iotests: Test mirror with temporarily disabled target
 backing file
Date: Wed, 11 Mar 2020 16:42:10 +0100
Message-Id: <20200311154218.15532-6-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

The newly tested scenario is a common live storage migration scenario:
The target node is opened without a backing file so that the active
layer is mirrored while its backing chain can be copied in the
background.

The backing chain should be attached to the mirror target node when
finalising the job, just before switching the users of the source node
to the new copy (at which point the mirror job still has a reference to
the node). drive-mirror did this automatically, but with blockdev-mirror
this is the job of the QMP client.

This patch adds test cases for two ways to achieve the desired result,
using either x-blockdev-reopen or blockdev-snapshot.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-5-kwolf@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/155     | 56 ++++++++++++++++++++++++++++++++++----
 tests/qemu-iotests/155.out |  4 +--
 2 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
index f237868710..74ddefc849 100755
--- a/tests/qemu-iotests/155
+++ b/tests/qemu-iotests/155
@@ -45,10 +45,15 @@ target_img =3D os.path.join(iotests.test_dir, 'target.'=
 + iotests.imgfmt)
 #                      image during runtime, only makes sense if
 #                      target_blockdev_backing is not None
 #                      (None: same as target_backing)
+# target_open_with_backing: If True, the target image is added with its ba=
cking
+#                           chain opened right away. If False, blockdev-add
+#                           opens it without a backing file and job comple=
tion
+#                           is supposed to open the backing chain.
=20
 class BaseClass(iotests.QMPTestCase):
     target_blockdev_backing =3D None
     target_real_backing =3D None
+    target_open_with_backing =3D True
=20
     def setUp(self):
         qemu_img('create', '-f', iotests.imgfmt, back0_img, '1440K')
@@ -80,9 +85,13 @@ class BaseClass(iotests.QMPTestCase):
                 options =3D { 'node-name': 'target',
                             'driver': iotests.imgfmt,
                             'file': { 'driver': 'file',
+                                      'node-name': 'target-file',
                                       'filename': target_img } }
-                if self.target_blockdev_backing:
-                    options['backing'] =3D self.target_blockdev_backing
+
+                if not self.target_open_with_backing:
+                        options['backing'] =3D None
+                elif self.target_blockdev_backing:
+                        options['backing'] =3D self.target_blockdev_backing
=20
                 result =3D self.vm.qmp('blockdev-add', **options)
                 self.assert_qmp(result, 'return', {})
@@ -147,10 +156,14 @@ class BaseClass(iotests.QMPTestCase):
 # cmd: Mirroring command to execute, either drive-mirror or blockdev-mirror
=20
 class MirrorBaseClass(BaseClass):
+    def openBacking(self):
+        pass
+
     def runMirror(self, sync):
         if self.cmd =3D=3D 'blockdev-mirror':
             result =3D self.vm.qmp(self.cmd, job_id=3D'mirror-job', device=
=3D'source',
-                                 sync=3Dsync, target=3D'target')
+                                 sync=3Dsync, target=3D'target',
+                                 auto_finalize=3DFalse)
         else:
             if self.existing:
                 mode =3D 'existing'
@@ -159,11 +172,12 @@ class MirrorBaseClass(BaseClass):
             result =3D self.vm.qmp(self.cmd, job_id=3D'mirror-job', device=
=3D'source',
                                  sync=3Dsync, target=3Dtarget_img,
                                  format=3Diotests.imgfmt, mode=3Dmode,
-                                 node_name=3D'target')
+                                 node_name=3D'target', auto_finalize=3DFal=
se)
=20
         self.assert_qmp(result, 'return', {})
=20
-        self.complete_and_wait('mirror-job')
+        self.vm.run_job('mirror-job', use_log=3DFalse, auto_finalize=3DFal=
se,
+                        pre_finalize=3Dself.openBacking, auto_dismiss=3DTr=
ue)
=20
     def testFull(self):
         self.runMirror('full')
@@ -221,6 +235,38 @@ class TestBlockdevMirrorForcedBacking(MirrorBaseClass):
     target_blockdev_backing =3D { 'driver': 'null-co' }
     target_real_backing =3D 'null-co://'
=20
+# Attach the backing chain only during completion, with blockdev-reopen
+class TestBlockdevMirrorReopen(MirrorBaseClass):
+    cmd =3D 'blockdev-mirror'
+    existing =3D True
+    target_backing =3D 'null-co://'
+    target_open_with_backing =3D False
+
+    def openBacking(self):
+        if not self.target_open_with_backing:
+            result =3D self.vm.qmp('blockdev-add', node_name=3D"backing",
+                                 driver=3D"null-co")
+            self.assert_qmp(result, 'return', {})
+            result =3D self.vm.qmp('x-blockdev-reopen', node_name=3D"targe=
t",
+                                 driver=3Diotests.imgfmt, file=3D"target-f=
ile",
+                                 backing=3D"backing")
+            self.assert_qmp(result, 'return', {})
+
+# Attach the backing chain only during completion, with blockdev-snapshot
+class TestBlockdevMirrorSnapshot(MirrorBaseClass):
+    cmd =3D 'blockdev-mirror'
+    existing =3D True
+    target_backing =3D 'null-co://'
+    target_open_with_backing =3D False
+
+    def openBacking(self):
+        if not self.target_open_with_backing:
+            result =3D self.vm.qmp('blockdev-add', node_name=3D"backing",
+                                 driver=3D"null-co")
+            self.assert_qmp(result, 'return', {})
+            result =3D self.vm.qmp('blockdev-snapshot', node=3D"backing",
+                                 overlay=3D"target")
+            self.assert_qmp(result, 'return', {})
=20
 class TestCommit(BaseClass):
     existing =3D False
diff --git a/tests/qemu-iotests/155.out b/tests/qemu-iotests/155.out
index 4176bb9402..4fd1c2dcd2 100644
--- a/tests/qemu-iotests/155.out
+++ b/tests/qemu-iotests/155.out
@@ -1,5 +1,5 @@
-...................
+.........................
 ----------------------------------------------------------------------
-Ran 19 tests
+Ran 25 tests
=20
 OK
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941750; cv=none;
	d=zohomail.com; s=zohoarc;
	b=PH0eP2xy4zMrv39MxdTN1kKS3ZRSCtnSnnDUiUxLWkWqAYOjl+obvG0pQH78VzvkqN5l1fo8B1BLJn20Xwubd49Q8sMPVHIU4Ru9Hqe1udBE6yos1RcfJcXJW2AwR0GMquHTPtGLa4ZqU5hWoYhDY0wKafyil7g7o+HbAnWzaJQ=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941750;
 h=Content-Type: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=Y9q4xxw9kvinCE4RZV1+LP35j8HfhlfEZQlRQGgKSxo=;
	b=WXi7dh1yUxAJ7HjR7kBuSYsOh4o/+vE85i8z3ktH7RfY93a9ccRvts3tfzWjfInbhQ6ypmIZ5REfFMQOYl4hEtS78Dmqxj7fI74DkNyMfuE9qoWrZaPGKTwUH/xFyVMgtPsiXu9/HJWWnECxyIkOclMGUZYesEAsII9U4nnKteg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941750203935.7694299218072;
 Wed, 11 Mar 2020 08:49:10 -0700 (PDT)
Received: from localhost ([::1]:54596 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3bX-0004NU-MM
	for importer@patchew.org; Wed, 11 Mar 2020 11:49:07 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59731)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VF-0002lz-N3
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VE-0002gD-Ee
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:37 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49538
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VE-0002dV-9Q
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:36 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-310-TXPDf_YnO9GeTslbn73kpA-1; Wed, 11 Mar 2020 11:42:33 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B040E18A550D;
 Wed, 11 Mar 2020 15:42:32 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 98DBB92D2C;
 Wed, 11 Mar 2020 15:42:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941355;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=Y9q4xxw9kvinCE4RZV1+LP35j8HfhlfEZQlRQGgKSxo=;
 b=jBxFEyN/hyGmj2OlZdTq5xLS7t20gWK73Jih17GV3KTCPNIrXPNfkUwWX2vSmSWYaDUJSH
 CS6Jp2qQ/LDBliyHMNDBeEeWKujrTkqbcKWX67P6CuHdSHDw5G8SEXLnNZrLBrNQ8MMeEL
 PsSxEc55pzwAzGSnNOSuK/Sqfntfx9o=
X-MC-Unique: TXPDf_YnO9GeTslbn73kpA-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 06/13] block: Fix cross-AioContext blockdev-snapshot
Date: Wed, 11 Mar 2020 16:42:11 +0100
Message-Id: <20200311154218.15532-7-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

external_snapshot_prepare() tries to move the overlay to the AioContext
of the backing file (the snapshotted node). However, it's possible that
this doesn't work, but the backing file can instead be moved to the
overlay's AioContext (e.g. opening the backing chain for a mirror
target).

bdrv_append() already indirectly uses bdrv_attach_node(), which takes
care to move nodes to make sure they use the same AioContext and which
tries both directions.

So the problem has a simple fix: Just delete the unnecessary extra
bdrv_try_set_aio_context() call in external_snapshot_prepare() and
instead assert in bdrv_append() that both nodes were indeed moved to the
same AioContext.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-6-kwolf@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c    |  1 +
 blockdev.c | 16 ----------------
 2 files changed, 1 insertion(+), 16 deletions(-)

diff --git a/block.c b/block.c
index 79a5a2770f..8fc7b56937 100644
--- a/block.c
+++ b/block.c
@@ -4365,6 +4365,7 @@ void bdrv_replace_node(BlockDriverState *from, BlockD=
riverState *to,
     bdrv_ref(from);
=20
     assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context());
+    assert(bdrv_get_aio_context(from) =3D=3D bdrv_get_aio_context(to));
     bdrv_drained_begin(from);
=20
     /* Put all parents into @list and calculate their cumulative permissio=
ns */
diff --git a/blockdev.c b/blockdev.c
index ea89896f27..fa8630cb41 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1470,9 +1470,7 @@ static void external_snapshot_prepare(BlkActionState =
*common,
                              DO_UPCAST(ExternalSnapshotState, common, comm=
on);
     TransactionAction *action =3D common->action;
     AioContext *aio_context;
-    AioContext *old_context;
     uint64_t perm, shared;
-    int ret;
=20
     /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar
      * purpose but a different set of parameters */
@@ -1608,20 +1606,6 @@ static void external_snapshot_prepare(BlkActionState=
 *common,
         goto out;
     }
=20
-    /* Honor bdrv_try_set_aio_context() context acquisition requirements. =
*/
-    old_context =3D bdrv_get_aio_context(state->new_bs);
-    aio_context_release(aio_context);
-    aio_context_acquire(old_context);
-
-    ret =3D bdrv_try_set_aio_context(state->new_bs, aio_context, errp);
-
-    aio_context_release(old_context);
-    aio_context_acquire(aio_context);
-
-    if (ret < 0) {
-        goto out;
-    }
-
     /* This removes our old bs and adds the new bs. This is an operation t=
hat
      * can fail, so we need to do it in .prepare; undoing it for abort is
      * always possible. */
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941732; cv=none;
	d=zohomail.com; s=zohoarc;
	b=E+/oMGZxhkYI2xBSAeV9p/RoopzKIXZs2H5CDTHZPwTaF+njKATJsRKCZHyDRe/7ZILYnT14Fswp6y0iPWVY0sdKxcti+BFwZkrnA8f9dkg+iHXiguGdwfEFw+llyIhMV8TB5g0B+JWFhMPArvK5XAt7vLD4hFFPlcU0k1Qp5nQ=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941732;
 h=Content-Type: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=9YBF35cxgmsBEnODs2CmusRZCij2P4n9Ow0NgBi7/D0=;
	b=oETxLb3vrsuZUgfA0gIn5/iAPC8FjCEIooJuNt5S32xi9YsTLv2Ke5JjAPkqM4xujvYaEyf17rUgsCF5N8NTHnnmCOOiMmwImaIGzUS+3umQXvwRqNsUJcfRSthaNEDms20F6AblWORqmxQOjq4C5dP11mD0UM1fMOtcmmbDcKs=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941732316843.3012794074427;
 Wed, 11 Mar 2020 08:48:52 -0700 (PDT)
Received: from localhost ([::1]:54592 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3bH-0003o8-69
	for importer@patchew.org; Wed, 11 Mar 2020 11:48:51 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59826)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VK-0002xu-Sq
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VI-00036V-R0
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:42 -0400
Received: from us-smtp-1.mimecast.com ([207.211.31.81]:33323
 helo=us-smtp-delivery-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VI-00033W-M3
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:40 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-59-soxvhbkLP_WrvNyScMAfOw-1; Wed, 11 Mar 2020 11:42:36 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0016800D50;
 Wed, 11 Mar 2020 15:42:33 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 03BF260BEE;
 Wed, 11 Mar 2020 15:42:32 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941360;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=9YBF35cxgmsBEnODs2CmusRZCij2P4n9Ow0NgBi7/D0=;
 b=DSAHwjFVhUbU0gpekeDpLAX84LxidzYltFiNP8kleUSudM5m+bR4XeA0wSIFU9MEBjKuTN
 bf0ozHiC7i8R3zujF0LWBoNFQIOhUfF6azk/PBOTSs1KgOxp70Q4MbQxe+YcBcPoSSLfIL
 jMVbYqPpITJhvFRbQ3Brhr2tVwL4ksE=
X-MC-Unique: soxvhbkLP_WrvNyScMAfOw-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 07/13] iotests: Add iothread cases to 155
Date: Wed, 11 Mar 2020 16:42:12 +0100
Message-Id: <20200311154218.15532-8-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.81
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

This patch adds test cases for attaching the backing chain to a mirror
job target right before finalising the job, where the image is in a
non-mainloop AioContext (i.e. the backing chain needs to be moved to the
AioContext of the mirror target).

This requires switching the test case from virtio-blk to virtio-scsi
because virtio-blk only actually starts using the iothreads when the
guest driver initialises the device (which never happens in a test case
without a guest OS). virtio-scsi always keeps its block nodes in the
AioContext of the the requested iothread without guest interaction.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-7-kwolf@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/155     | 32 +++++++++++++++++++++++---------
 tests/qemu-iotests/155.out |  4 ++--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
index 74ddefc849..571bce9de4 100755
--- a/tests/qemu-iotests/155
+++ b/tests/qemu-iotests/155
@@ -49,11 +49,14 @@ target_img =3D os.path.join(iotests.test_dir, 'target.'=
 + iotests.imgfmt)
 #                           chain opened right away. If False, blockdev-add
 #                           opens it without a backing file and job comple=
tion
 #                           is supposed to open the backing chain.
+# use_iothread: If True, an iothread is configured for the virtio-blk devi=
ce
+#               that uses the image being mirrored
=20
 class BaseClass(iotests.QMPTestCase):
     target_blockdev_backing =3D None
     target_real_backing =3D None
     target_open_with_backing =3D True
+    use_iothread =3D False
=20
     def setUp(self):
         qemu_img('create', '-f', iotests.imgfmt, back0_img, '1440K')
@@ -69,7 +72,16 @@ class BaseClass(iotests.QMPTestCase):
                     'file': {'driver': 'file',
                              'filename': source_img}}
         self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev))
-        self.vm.add_device('virtio-blk,id=3Dqdev0,drive=3Dsource')
+
+        if self.use_iothread:
+            self.vm.add_object('iothread,id=3Diothread0')
+            iothread =3D ",iothread=3Diothread0"
+        else:
+            iothread =3D ""
+
+        self.vm.add_device('virtio-scsi%s' % iothread)
+        self.vm.add_device('scsi-hd,id=3Dqdev0,drive=3Dsource')
+
         self.vm.launch()
=20
         self.assertIntactSourceBackingChain()
@@ -182,24 +194,21 @@ class MirrorBaseClass(BaseClass):
     def testFull(self):
         self.runMirror('full')
=20
-        node =3D self.findBlockNode('target',
-                                  '/machine/peripheral/qdev0/virtio-backen=
d')
+        node =3D self.findBlockNode('target', 'qdev0')
         self.assertCorrectBackingImage(node, None)
         self.assertIntactSourceBackingChain()
=20
     def testTop(self):
         self.runMirror('top')
=20
-        node =3D self.findBlockNode('target',
-                                  '/machine/peripheral/qdev0/virtio-backen=
d')
+        node =3D self.findBlockNode('target', 'qdev0')
         self.assertCorrectBackingImage(node, back2_img)
         self.assertIntactSourceBackingChain()
=20
     def testNone(self):
         self.runMirror('none')
=20
-        node =3D self.findBlockNode('target',
-                                  '/machine/peripheral/qdev0/virtio-backen=
d')
+        node =3D self.findBlockNode('target', 'qdev0')
         self.assertCorrectBackingImage(node, source_img)
         self.assertIntactSourceBackingChain()
=20
@@ -252,6 +261,9 @@ class TestBlockdevMirrorReopen(MirrorBaseClass):
                                  backing=3D"backing")
             self.assert_qmp(result, 'return', {})
=20
+class TestBlockdevMirrorReopenIothread(TestBlockdevMirrorReopen):
+    use_iothread =3D True
+
 # Attach the backing chain only during completion, with blockdev-snapshot
 class TestBlockdevMirrorSnapshot(MirrorBaseClass):
     cmd =3D 'blockdev-mirror'
@@ -268,6 +280,9 @@ class TestBlockdevMirrorSnapshot(MirrorBaseClass):
                                  overlay=3D"target")
             self.assert_qmp(result, 'return', {})
=20
+class TestBlockdevMirrorSnapshotIothread(TestBlockdevMirrorSnapshot):
+    use_iothread =3D True
+
 class TestCommit(BaseClass):
     existing =3D False
=20
@@ -283,8 +298,7 @@ class TestCommit(BaseClass):
=20
         self.vm.event_wait('BLOCK_JOB_COMPLETED')
=20
-        node =3D self.findBlockNode(None,
-                                  '/machine/peripheral/qdev0/virtio-backen=
d')
+        node =3D self.findBlockNode(None, 'qdev0')
         self.assert_qmp(node, 'image' + '/backing-image' * 0 + '/filename',
                         back1_img)
         self.assert_qmp(node, 'image' + '/backing-image' * 1 + '/filename',
diff --git a/tests/qemu-iotests/155.out b/tests/qemu-iotests/155.out
index 4fd1c2dcd2..ed714d5263 100644
--- a/tests/qemu-iotests/155.out
+++ b/tests/qemu-iotests/155.out
@@ -1,5 +1,5 @@
-.........................
+...............................
 ----------------------------------------------------------------------
-Ran 25 tests
+Ran 31 tests
=20
 OK
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941582; cv=none;
	d=zohomail.com; s=zohoarc;
	b=jsRYxIV/jPVOv0Y9761d3R0JltB/mJjxhtfYir5Hl7rH3YW6tMcs9gQlniJVduUgWfhYmuzGw9+tqgJnR2w3YJwkuyyvXcJgMkelxfXHyZt/YxsQSC8tVMJksWwglkHbi8HwAZSLw6d3V25Ka0lnVipFxQnv/2/mFv7HjE1E/Ns=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941582;
 h=Content-Type: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=nwtrIe9mlPyMqFukWE3oYgseNckLG6yMm06xtJDpqmM=;
	b=QZGOftF9m0qQf4e5jWblGJjs0rKDSrxulbNqBwXIGda48tB5vEjCQi7Dlu5Jrg2TQxLwwgCC9PYXwGnAL7hUZ/VDv+3a0nHKvgfJK9GYToosv2LBfytMHh8Eg6nyUidzm9fc3EydWd6iPe8up6+LOaRsbg4uwxzi7P27RWCmSbU=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941582260341.77545755902395;
 Wed, 11 Mar 2020 08:46:22 -0700 (PDT)
Received: from localhost ([::1]:54560 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3Yq-0008I3-M4
	for importer@patchew.org; Wed, 11 Mar 2020 11:46:20 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59784)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VI-0002sf-4h
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:41 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VH-0002vH-2Y
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:39 -0400
Received: from us-smtp-2.mimecast.com ([205.139.110.61]:21248
 helo=us-smtp-delivery-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VG-0002tV-T1
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:38 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-476-_L-w9CqzPd25RHYR-MThdQ-1; Wed, 11 Mar 2020 11:42:36 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BD02800D4E;
 Wed, 11 Mar 2020 15:42:35 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 431C160BEE;
 Wed, 11 Mar 2020 15:42:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941358;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=nwtrIe9mlPyMqFukWE3oYgseNckLG6yMm06xtJDpqmM=;
 b=HTgsAAHhIM7fhA7BBsVIB/S8N5Yb3AXXEFFRU/a02YaAH7GzBuB2YD1j0jHXltG4LodAGs
 Qk/Pni/IXmPyAF3TGdF9SLw4d+ubpzLUzchFz5P1aKZcYEWZUzc9NMgWIM4JEcU53yPtOh
 x79IENyjkJ+FNrryx5Uryu2/e5f8fKU=
X-MC-Unique: _L-w9CqzPd25RHYR-MThdQ-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 08/13] qapi: Add '@allow-write-only-overlay' feature for
 'blockdev-snapshot'
Date: Wed, 11 Mar 2020 16:42:13 +0100
Message-Id: <20200311154218.15532-9-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.61
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Peter Krempa <pkrempa@redhat.com>

Anounce that 'blockdev-snapshot' command's permissions allow changing
of the backing file if the 'consistent_read' permission is not required.

This is useful for libvirt to allow late opening of the backing chain
during a blockdev-mirror.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200310113831.27293-8-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qapi/block-core.json | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 9758fc48d2..91586fb1fb 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1472,6 +1472,12 @@
 #
 # For the arguments, see the documentation of BlockdevSnapshot.
 #
+# Features:
+# @allow-write-only-overlay: If present, the check whether this operation =
is safe
+#                            was relaxed so that it can be used to change
+#                            backing file of a destination of a blockdev-m=
irror.
+#                            (since 5.0)
+#
 # Since: 2.5
 #
 # Example:
@@ -1492,7 +1498,8 @@
 #
 ##
 { 'command': 'blockdev-snapshot',
-  'data': 'BlockdevSnapshot' }
+  'data': 'BlockdevSnapshot',
+  'features': [ 'allow-write-only-overlay' ] }
=20
 ##
 # @change-backing-file:
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941938; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ZSLQh4at8UTsA5EuUyhHahb7Nj+GxNZsf3K0/JsAV00ShB9Nky3Ll6LYSC4Losz0v7EuUq48Gd5vuiOf6aGSwT62fbY8eY45HgDOpFV8epLdkOM0I/fzX68ggIW/QV2Fd0kVtloEhBNrEcUPj+Zr2cC5Omx/WfGQ1VYrpXNRc5E=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941938;
 h=Content-Type: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=G4epXuozV5upAZ2otn3gIuX0f++/O+nBRWrJUTAsG6Q=;
	b=b2YLRpza/InuZcwOmie/2GYb+OV1S9HArV1Y84R0f9rTMrYVWB/T+aJlPSHC0nK2VAd/yhnOn4tyvDmw+AX8gGXjPfTGn6zdEXAd57/WtB8KJuesdJswuiGwS6ZW3cKPPppcWcS78Z6Krs5O/ZXXSL6tyt2t+4lrhikzy3+8MhI=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941938064242.34875860361467;
 Wed, 11 Mar 2020 08:52:18 -0700 (PDT)
Received: from localhost ([::1]:54668 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3ea-0002rY-Kz
	for importer@patchew.org; Wed, 11 Mar 2020 11:52:16 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59828)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VK-0002xw-TL
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VI-00033F-DJ
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:42 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55911
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VI-00030T-6x
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:40 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-11-nii55XpTN4CY7myDP1CXeQ-1; Wed, 11 Mar 2020 11:42:37 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75E9F8017CC;
 Wed, 11 Mar 2020 15:42:36 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 810B560BEE;
 Wed, 11 Mar 2020 15:42:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941359;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=G4epXuozV5upAZ2otn3gIuX0f++/O+nBRWrJUTAsG6Q=;
 b=SKnZcc5L0bvnGs1EHYM49Yt/Ui/84Q4R1mHzO9R5+wuin8C1kmnwQSoZWnIhnWMPLPFNZs
 FBR5sB9kahSe5IiAwrHO8+RRtMbYIQLZrB0LlgxfLO62+zkjEKjFr+86ZuFE34Zm0S2z2a
 TknAvw+83QwGybRlyWYNaujQE+QQVtE=
X-MC-Unique: nii55XpTN4CY7myDP1CXeQ-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 09/13] tests/qemu-iotests: Fix socket_scm_helper build path
Date: Wed, 11 Mar 2020 16:42:14 +0100
Message-Id: <20200311154218.15532-10-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Philippe Mathieu-Daud=C3=A9 <philmd@redhat.com>

The socket_scm_helper path got corrupted during the mechanical
refactor moving the qtests files into their own sub-directory.

Fixes: 1e8a1fae7 ("test: Move qtests to a separate directory")
Signed-off-by: Philippe Mathieu-Daud=C3=A9 <philmd@redhat.com>
Message-Id: <20200306165751.18986-1-philmd@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/Makefile.include       | 1 +
 tests/qtest/Makefile.include | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index edcbd475aa..67e8fcddda 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -589,6 +589,7 @@ include $(SRC_PATH)/tests/qtest/Makefile.include
 tests/test-qga$(EXESUF): qemu-ga$(EXESUF)
 tests/test-qga$(EXESUF): tests/test-qga.o $(qtest-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-ob=
j-y) libvhost-user.a
+tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_s=
cm_helper.o
=20
 SPEED =3D quick
=20
diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include
index 383b0ab217..76672990a7 100644
--- a/tests/qtest/Makefile.include
+++ b/tests/qtest/Makefile.include
@@ -287,7 +287,6 @@ tests/qtest/usb-hcd-ehci-test$(EXESUF): tests/qtest/usb=
-hcd-ehci-test.o $(libqos
 tests/qtest/usb-hcd-xhci-test$(EXESUF): tests/qtest/usb-hcd-xhci-test.o $(=
libqos-usb-obj-y)
 tests/qtest/cpu-plug-test$(EXESUF): tests/qtest/cpu-plug-test.o
 tests/qtest/migration-test$(EXESUF): tests/qtest/migration-test.o tests/qt=
est/migration-helpers.o
-tests/qtest/qemu-iotests/qtest/socket_scm_helper$(EXESUF): tests/qtest/qem=
u-iotests/qtest/socket_scm_helper.o
 tests/qtest/test-netfilter$(EXESUF): tests/qtest/test-netfilter.o $(qtest-=
obj-y)
 tests/qtest/test-filter-mirror$(EXESUF): tests/qtest/test-filter-mirror.o =
$(qtest-obj-y)
 tests/qtest/test-filter-redirector$(EXESUF): tests/qtest/test-filter-redir=
ector.o $(qtest-obj-y)
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941890; cv=none;
	d=zohomail.com; s=zohoarc;
	b=IGFtaqvYY+lbhnSGnV7eIC/p/DbZegjBsYvnQX0A0JtO9xxGglm9/euNfBJBbYQKiV0Cenizbc/B3BNQEGZGMjM0Wui8Ud3U3ZUAXy1M3YfVBN6BRsZ+mzkMLfmsdjfFmQu4wjrkDkfcyO3Fq/wALTC3PwqJe6+cHrlxetl+80w=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941890;
 h=Content-Type: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=TybeXpzKZnnidKvMeVUslFZhOOC2RpdS7pjktkiZCoI=;
	b=Gcr0Q45wx7eY1jOFYBEqvHxo7pvWbt7p6K17eYbim0e6nUmwA8YhAylQF2Rl6WgTIOzb6qdYRN2HaX1hrnV36uOzClTHfYMdZNKAldqMQYPfNNxXDdzhFd8mJMaQdKk0QmjobbAsuZYNxssEVknyVS78/sZlHcvzZraI58+OQlU=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 15839418903301003.3124710716315;
 Wed, 11 Mar 2020 08:51:30 -0700 (PDT)
Received: from localhost ([::1]:54646 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3dn-00018V-Qb
	for importer@patchew.org; Wed, 11 Mar 2020 11:51:27 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59925)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VS-0003DK-K2
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VQ-0003hi-G0
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:50 -0400
Received: from us-smtp-2.mimecast.com ([205.139.110.61]:52094
 helo=us-smtp-delivery-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VQ-0003gj-Cf
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:48 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-116-I9RaoBGoMi-gzqyH7WMaQw-1; Wed, 11 Mar 2020 11:42:40 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C36318017CC;
 Wed, 11 Mar 2020 15:42:39 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id BF6BC90519;
 Wed, 11 Mar 2020 15:42:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941368;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=TybeXpzKZnnidKvMeVUslFZhOOC2RpdS7pjktkiZCoI=;
 b=dNT8EPfUKBajmgJ7iFh9m+qr4xAz+9q8+Ldiy/nWmwcTzG312cT15jfDDqsvLIipy2JQ/A
 4TbfGPa1OGZ2LbNtRUZJt6fajN/0vp5/6a4nCAQfwQgWoMZ8jBAAJYtB0a8nIowNWsYnxO
 +AXHocP/WWcLYR+bboJrucnv7RB24rM=
X-MC-Unique: I9RaoBGoMi-gzqyH7WMaQw-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 10/13] block: introducing 'bdrv_co_delete_file' interface
Date: Wed, 11 Mar 2020 16:42:15 +0100
Message-Id: <20200311154218.15532-11-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.61
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Daniel Henrique Barboza <danielhb413@gmail.com>

Adding to Block Drivers the capability of being able to clean up
its created files can be useful in certain situations. For the
LUKS driver, for instance, a failure in one of its authentication
steps can leave files in the host that weren't there before.

This patch adds the 'bdrv_co_delete_file' interface to block
drivers and add it to the 'file' driver in file-posix.c. The
implementation is given by 'raw_co_delete_file'.

Suggested-by: Daniel P. Berrang=C3=A9 <berrange@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200130213907.2830642-2-danielhb413@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/block_int.h |  4 ++++
 block/file-posix.c        | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/block/block_int.h b/include/block/block_int.h
index d8d13700a9..ae9c4da4d0 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -314,6 +314,10 @@ struct BlockDriver {
      */
     int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs);
=20
+    /* Delete a created file. */
+    int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs,
+                                            Error **errp);
+
     /*
      * Flushes all data that was already written to the OS all the way dow=
n to
      * the disk (for example file-posix.c calls fsync()).
diff --git a/block/file-posix.c b/block/file-posix.c
index 0f77447a25..9bc3838b2a 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2445,6 +2445,28 @@ static int coroutine_fn raw_co_create_opts(const cha=
r *filename, QemuOpts *opts,
     return raw_co_create(&options, errp);
 }
=20
+static int coroutine_fn raw_co_delete_file(BlockDriverState *bs,
+                                           Error **errp)
+{
+    struct stat st;
+    int ret;
+
+    if (!(stat(bs->filename, &st) =3D=3D 0) || !S_ISREG(st.st_mode)) {
+        error_setg_errno(errp, ENOENT, "%s is not a regular file",
+                         bs->filename);
+        return -ENOENT;
+    }
+
+    ret =3D unlink(bs->filename);
+    if (ret < 0) {
+        ret =3D -errno;
+        error_setg_errno(errp, -ret, "Error when deleting file %s",
+                         bs->filename);
+    }
+
+    return ret;
+}
+
 /*
  * Find allocation range in @bs around offset @start.
  * May change underlying file descriptor's file offset.
@@ -3075,6 +3097,7 @@ BlockDriver bdrv_file =3D {
     .bdrv_co_block_status =3D raw_co_block_status,
     .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache,
     .bdrv_co_pwrite_zeroes =3D raw_co_pwrite_zeroes,
+    .bdrv_co_delete_file =3D raw_co_delete_file,
=20
     .bdrv_co_preadv         =3D raw_co_preadv,
     .bdrv_co_pwritev        =3D raw_co_pwritev,
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941790; cv=none;
	d=zohomail.com; s=zohoarc;
	b=OWTuQuXlSgrtr8ouVPSvSM0qvRhWZgdHqkIPEfw3jVsr5Z2iocXtN3rJifa/wG9ME29lIu5m1kWFWj9z+J66IX/IewiLmOKFS46P0SAN6pL9T0BjfjrCO7gEesQFM+PfpQQRsqABr/NBmuzIhg19e8WJxcWVr5l8aTD8Q+fPqmo=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941790;
 h=Content-Type: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=T/LwV56RNgFYCSdmy8UpKDULA6AtwJDp690fsNSHhS0=;
	b=Qc1hbtQW0KLXLq4IEC1PwQIszr3+WiTuK4uL2zmVvHaGb20bJMHp7bV5ZlTTACnoXGeU1MCwcMJvsHuIkkuF7dZN+DOgbWtK1+VWFRrfmFwd1vxZu/eISi2EGvsbrZn08NIX/lsSxfJELrSdJhbuNFnk4+xIG8wScU7UvOS9cT4=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941790376481.81679641486664;
 Wed, 11 Mar 2020 08:49:50 -0700 (PDT)
Received: from localhost ([::1]:54602 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3c9-0005c7-0F
	for importer@patchew.org; Wed, 11 Mar 2020 11:49:45 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59912)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VR-0003Bf-Vy
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VP-0003g5-Sh
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:48 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44143
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VP-0003ek-PP
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:47 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-64-G97Tpj47PmSQX6ASoOfI-g-1; Wed, 11 Mar 2020 11:42:42 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DD98DB62;
 Wed, 11 Mar 2020 15:42:41 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 15B6B92D2C;
 Wed, 11 Mar 2020 15:42:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941367;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=T/LwV56RNgFYCSdmy8UpKDULA6AtwJDp690fsNSHhS0=;
 b=T1aWor/chYMKNqYSmChtfrDKzCX/Mw19MCFowihRLmkEw5Uo5yuEwXTB5lEFWeXJEEBVin
 hX4CV/gIH/8KrVtl+rFFaqnDBsA40fOVksBTPvYLozNj7sAtBlkQ/1Bip2wpsFkKbI2/e+
 w+DtxpRFP6UVgWj20ZDna9ZXIAEBBQM=
X-MC-Unique: G97Tpj47PmSQX6ASoOfI-g-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 11/13] block.c: adding bdrv_co_delete_file
Date: Wed, 11 Mar 2020 16:42:16 +0100
Message-Id: <20200311154218.15532-12-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Daniel Henrique Barboza <danielhb413@gmail.com>

Using the new 'bdrv_co_delete_file' interface, a pure co_routine function
'bdrv_co_delete_file' inside block.c can can be used in a way similar of
the existing bdrv_create_file to to clean up a created file.

We're creating a pure co_routine because the only caller of
'bdrv_co_delete_file' will be already in co_routine context, thus there
is no need to add all the machinery to check for qemu_in_coroutine() and
create a separated co_routine to do the job.

Suggested-by: Daniel P. Berrang=C3=A9 <berrange@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200130213907.2830642-3-danielhb413@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/block.h |  1 +
 block.c               | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/block/block.h b/include/block/block.h
index cd6b5b95aa..e569a4d747 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -363,6 +363,7 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState *bs,=
 BlockDriverState *base,
 int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base,
                               Error **errp);
 void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *b=
ase);
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
=20
=20
 typedef struct BdrvCheckResult {
diff --git a/block.c b/block.c
index 8fc7b56937..a2542c977b 100644
--- a/block.c
+++ b/block.c
@@ -668,6 +668,32 @@ int bdrv_create_file(const char *filename, QemuOpts *o=
pts, Error **errp)
     }
 }
=20
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
+{
+    Error *local_err =3D NULL;
+    int ret;
+
+    assert(bs !=3D NULL);
+
+    if (!bs->drv) {
+        error_setg(errp, "Block node '%s' is not opened", bs->filename);
+        return -ENOMEDIUM;
+    }
+
+    if (!bs->drv->bdrv_co_delete_file) {
+        error_setg(errp, "Driver '%s' does not support image deletion",
+                   bs->drv->format_name);
+        return -ENOTSUP;
+    }
+
+    ret =3D bs->drv->bdrv_co_delete_file(bs, &local_err);
+    if (ret < 0) {
+        error_propagate(errp, local_err);
+    }
+
+    return ret;
+}
+
 /**
  * Try to get @bs's logical and physical block size.
  * On success, store them in @bsz struct and return 0.
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941656; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Y8aP+NMIUpkroYFsoXT2lx2tTOjXeYiulTlr1gBMasdQqRngtpIpOvKdrxPjxlxG7G2z3FzPAFo5RHjVe08SCAYfNC7st0dz7iSYsVDZMi9noSs9S1+CSRRu0S+8RrLftusR0CwSuCVkredGmgjH2jaIQx6MsxO6/q3AqFXq6jM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941656;
 h=Content-Type: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=tKC+fGb4Qp8widUD3WBtl9IBM3etB5pxspJJQN3QxP8=;
	b=G/CDl94+xwSPhVx6zbScP7VnF3bWPdHdemaeYC5j7/mr//4TeYxc+HY4rubrt+GdT8cI+bYT2n7ST4xpb01ITC6luPnS+i1FlZmGbA4P/YKH/xiS4oq9qhg2D04EGBbRhVfjDefcPpyvOdN5xCPY0kO8KrdL7YKMKqxGePXHtqU=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1583941656314554.1748961832451;
 Wed, 11 Mar 2020 08:47:36 -0700 (PDT)
Received: from localhost ([::1]:54566 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3a2-0001VJ-TT
	for importer@patchew.org; Wed, 11 Mar 2020 11:47:34 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59901)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VQ-0003B2-QD
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:49 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VP-0003eX-GG
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:48 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20534
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VP-0003cI-BA
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:47 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-350-T11-4Y34PCKMAsNBHlxzow-1; Wed, 11 Mar 2020 11:42:45 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F140B8010EB;
 Wed, 11 Mar 2020 15:42:43 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 56AEB92D2C;
 Wed, 11 Mar 2020 15:42:41 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941367;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=tKC+fGb4Qp8widUD3WBtl9IBM3etB5pxspJJQN3QxP8=;
 b=Tzccep2LbSG3vvzgX4v2h8xhHCoDNSNa7kKap0Jfkhz1CLSxs9yPknKvQqLBfvkMa2znvV
 ih1fOb7ASNdi6vz8BXzKpZF9sfxBKr09CHF4cGjBsJHjx8V1AxGNTJgLmiQbfdfOfrDYsK
 ggIzuqKkucyh1L7rxrk+ZKbFmSWhqvY=
X-MC-Unique: T11-4Y34PCKMAsNBHlxzow-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 12/13] crypto.c: cleanup created file when
 block_crypto_co_create_opts_luks fails
Date: Wed, 11 Mar 2020 16:42:17 +0100
Message-Id: <20200311154218.15532-13-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 205.139.110.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Daniel Henrique Barboza <danielhb413@gmail.com>

When using a non-UTF8 secret to create a volume using qemu-img, the
following error happens:

$ qemu-img create -f luks --object secret,id=3Dvol_1_encrypt0,file=3Dvol_re=
size_pool.vol_1.secret.qzVQrI -o key-secret=3Dvol_1_encrypt0 /var/tmp/pool_=
target/vol_1 10240K

Formatting '/var/tmp/pool_target/vol_1', fmt=3Dluks size=3D10485760 key-sec=
ret=3Dvol_1_encrypt0
qemu-img: /var/tmp/pool_target/vol_1: Data from secret vol_1_encrypt0 is no=
t valid UTF-8

However, the created file '/var/tmp/pool_target/vol_1' is left behind in the
file system after the failure. This behavior can be observed when creating
the volume using Libvirt, via 'virsh vol-create', and then getting "volume
target path already exist" errors when trying to re-create the volume.

The volume file is created inside block_crypto_co_create_opts_luks(), in
block/crypto.c. If the bdrv_create_file() call is successful but any
succeeding step fails*, the existing 'fail' label does not take into
account the created file, leaving it behind.

This patch changes block_crypto_co_create_opts_luks() to delete
'filename' in case of failure. A failure in this point means that
the volume is now truncated/corrupted, so even if 'filename' was an
existing volume before calling qemu-img, it is now unusable. Deleting
the file it is not much worse than leaving it in the filesystem in
this scenario, and we don't have to deal with checking the file
pre-existence in the code.

* in our case, block_crypto_co_create_generic calls qcrypto_block_create,
which calls qcrypto_block_luks_create, and this function fails when
calling qcrypto_secret_lookup_as_utf8.

Reported-by: Srikanth Aithal <bssrikanth@in.ibm.com>
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200130213907.2830642-4-danielhb413@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/crypto.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/block/crypto.c b/block/crypto.c
index 24823835c1..00e8ec537d 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -30,6 +30,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
+#include "qemu/cutils.h"
 #include "crypto.h"
=20
 typedef struct BlockCrypto BlockCrypto;
@@ -596,6 +597,23 @@ static int coroutine_fn block_crypto_co_create_opts_lu=
ks(const char *filename,
=20
     ret =3D 0;
 fail:
+    /*
+     * If an error occurred, delete 'filename'. Even if the file existed
+     * beforehand, it has been truncated and corrupted in the process.
+     */
+    if (ret && bs) {
+        Error *local_delete_err =3D NULL;
+        int r_del =3D bdrv_co_delete_file(bs, &local_delete_err);
+        /*
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del !=3D -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }
+    }
+
     bdrv_unref(bs);
     qapi_free_QCryptoBlockCreateOptions(create_opts);
     qobject_unref(cryptoopts);
--=20
2.20.1


From nobody Tue Apr 29 20:40:30 2025
Delivered-To: importer@patchew.org
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;
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1583941636; cv=none;
	d=zohomail.com; s=zohoarc;
	b=XeqBKnYtyy7Viv2ihFzA3g6pgrwRIvqFIR9DblZV+8YUDsK3P9cTrI/+sVCkYYewTAySHgHXN7pMUDNvJS70lNKlgKGI8+wjECrUr4B3EWubw35DxvdsKm3HnJmGLCnfkOaobSVCM2cN91G0oVdwizF6RcSNjpl9KEUoI3Cvbmo=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1583941636;
 h=Content-Type: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=76NlVCw3qHJpEpDwfRi5QoXq+jKPycEfZ+rVrxUVgR4=;
	b=j9lx/ba/TsBaN/GX7t81h5rXIQFNeFzmXNJrukt+pwiY7S5GJQSq9ef1w5B+Ok8dvwdVcePna7cnVq7YDV1nBsxkzQoSkUY8l3WPMBCm/SyQHK7J0t+/tYxOB2CsS/DWh0kx81CyK8Y4zVoLojaZvSSBRM8RhitzkHmxa6h1ZuA=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=pass header.from=<kwolf@redhat.com> (p=none dis=none)
 header.from=<kwolf@redhat.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 158394163618762.18698627284107;
 Wed, 11 Mar 2020 08:47:16 -0700 (PDT)
Received: from localhost ([::1]:54564 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1jC3Zj-00013Z-2Q
	for importer@patchew.org; Wed, 11 Mar 2020 11:47:15 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59944)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <kwolf@redhat.com>) id 1jC3VT-0003Fs-WF
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <kwolf@redhat.com>) id 1jC3VS-0003nJ-E4
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:51 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:56302
 helo=us-smtp-1.mimecast.com)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1jC3VS-0003ld-Ad
 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 11:42:50 -0400
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-343-9Yf52PUUPwCyGVu53oTYFQ-1; Wed, 11 Mar 2020 11:42:46 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3ADD718A5516;
 Wed, 11 Mar 2020 15:42:45 +0000 (UTC)
Received: from linux.fritz.box.com (ovpn-117-234.ams2.redhat.com
 [10.36.117.234])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 42A0792D2C;
 Wed, 11 Mar 2020 15:42:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1583941370;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=76NlVCw3qHJpEpDwfRi5QoXq+jKPycEfZ+rVrxUVgR4=;
 b=DEdp/B3nO4rk9OgfgvTgbaSqZxaE3a5gc1mpnjvBxHFrZXtV1MCc5dLNVveRs+ROZDydT6
 8UzLofn9uhCbnl+0m8PpO2dSv+TXzuFsv+zoa83z8pC19jVixc38C7+a1cTmo7LEV/LWze
 iGkaopU+ee4Z0a2Oga6bXEojtSOpMwQ=
X-MC-Unique: 9Yf52PUUPwCyGVu53oTYFQ-1
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Subject: [PULL 13/13] qemu-iotests: adding LUKS cleanup for non-UTF8 secret
 error
Date: Wed, 11 Mar 2020 16:42:18 +0100
Message-Id: <20200311154218.15532-14-kwolf@redhat.com>
In-Reply-To: <20200311154218.15532-1-kwolf@redhat.com>
References: <20200311154218.15532-1-kwolf@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
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: 207.211.31.120
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: pass (identity @redhat.com)
Content-Type: text/plain; charset="utf-8"

From: Daniel Henrique Barboza <danielhb413@gmail.com>

This patch adds a new test file to exercise the case where
qemu-img fails to complete for the LUKS format when a non-UTF8
secret is used.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200130213907.2830642-5-danielhb413@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/282     | 67 ++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/282.out | 11 +++++++
 tests/qemu-iotests/group   |  1 +
 3 files changed, 79 insertions(+)
 create mode 100755 tests/qemu-iotests/282
 create mode 100644 tests/qemu-iotests/282.out

diff --git a/tests/qemu-iotests/282 b/tests/qemu-iotests/282
new file mode 100755
index 0000000000..081eb12080
--- /dev/null
+++ b/tests/qemu-iotests/282
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Test qemu-img file cleanup for LUKS when using a non-UTF8 secret
+#
+# Copyright (C) 2020, IBM Corporation.
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+
+seq=3D`basename $0`
+echo "QA output created by $seq"
+
+status=3D1	# failure is the default!
+TEST_IMAGE_FILE=3D'vol.img'
+
+_cleanup()
+{
+  _cleanup_test_img
+  rm non_utf8_secret
+  rm -f $TEST_IMAGE_FILE
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt luks
+_supported_proto generic
+_unsupported_proto vxhs
+
+echo "=3D=3D Create non-UTF8 secret =3D=3D"
+echo -n -e '\x3a\x3c\x3b\xff' > non_utf8_secret
+SECRET=3D"secret,id=3Dsec0,file=3Dnon_utf8_secret"
+
+echo "=3D=3D Throws an error because of invalid UTF-8 secret =3D=3D"
+$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=3Dsec0" $TEST_=
IMAGE_FILE 4M
+
+echo "=3D=3D Image file should not exist after the error =3D=3D"
+if test -f "$TEST_IMAGE_FILE"; then
+    exit 1
+fi
+
+echo "=3D=3D Create a stub image file and run qemu-img again =3D=3D"
+touch $TEST_IMAGE_FILE
+$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=3Dsec0" $TEST_=
IMAGE_FILE 4M
+
+echo "=3D=3D Pre-existing image file should also be deleted after the erro=
r =3D=3D"
+if test -f "$TEST_IMAGE_FILE"; then
+    exit 1
+fi
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=3D0
diff --git a/tests/qemu-iotests/282.out b/tests/qemu-iotests/282.out
new file mode 100644
index 0000000000..5d079dabce
--- /dev/null
+++ b/tests/qemu-iotests/282.out
@@ -0,0 +1,11 @@
+QA output created by 282
+=3D=3D Create non-UTF8 secret =3D=3D
+=3D=3D Throws an error because of invalid UTF-8 secret =3D=3D
+qemu-img: vol.img: Data from secret sec0 is not valid UTF-8
+Formatting 'vol.img', fmt=3Dluks size=3D4194304 key-secret=3Dsec0
+=3D=3D Image file should not exist after the error =3D=3D
+=3D=3D Create a stub image file and run qemu-img again =3D=3D
+qemu-img: vol.img: Data from secret sec0 is not valid UTF-8
+Formatting 'vol.img', fmt=3Dluks size=3D4194304 key-secret=3Dsec0
+=3D=3D Pre-existing image file should also be deleted after the error =3D=
=3D
+ *** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 0317667695..3c1329b081 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -290,6 +290,7 @@
 279 rw backing quick
 280 rw migration quick
 281 rw quick
+282 rw img quick
 283 auto quick
 284 rw
 286 rw quick
--=20
2.20.1