From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040425982897.3006700855886; Fri, 1 Feb 2019 09:00:25 -0800 (PST) Received: from localhost ([127.0.0.1]:58075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcAt-0001ZD-SX for importer@patchew.org; Fri, 01 Feb 2019 12:00:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbno-0007Qt-D2 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbng-0008He-Up for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnT-0007c7-GU; Fri, 01 Feb 2019 11:36:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 009BEC004BA6; Fri, 1 Feb 2019 16:35:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 695EC608C7; Fri, 1 Feb 2019 16:35:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:52 +0100 Message-Id: <20190201163518.31157-2-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 01 Feb 2019 16:35:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/27] mirror: Release the dirty bitmap if mirror_start_job() fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia At the moment I don't see how to make this function fail after the dirty bitmap has been created, but if that was possible then we would hit the assert(QLIST_EMPTY(&bs->dirty_bitmaps)) in bdrv_close(). Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/mirror.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/mirror.c b/block/mirror.c index 24ede6fdaa..4cf1c088c0 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1649,6 +1649,9 @@ fail: g_free(s->replaces); blk_unref(s->target); bs_opaque->job =3D NULL; + if (s->dirty_bitmap) { + bdrv_release_dirty_bitmap(bs, s->dirty_bitmap); + } job_early_fail(&s->common.job); } =20 --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154904025558298.54432746262694; Fri, 1 Feb 2019 08:57:35 -0800 (PST) Received: from localhost ([127.0.0.1]:58049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc8C-0007fl-L9 for importer@patchew.org; Fri, 01 Feb 2019 11:57:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnJ-0006zg-1e for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:35:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnE-00088Z-QF for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:35:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55361) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbn3-0007nv-Pm; Fri, 01 Feb 2019 11:35:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C89181F10; Fri, 1 Feb 2019 16:35:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47209608C6; Fri, 1 Feb 2019 16:35:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:53 +0100 Message-Id: <20190201163518.31157-3-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/27] mirror: Block the source BlockDriverState in mirror_start_job() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia The mirror_start_job() function used for the commit-active job blocks the source, target and all intermediate nodes for the duration of the job. target <- intermediate <- source Since 4ef85a9c2339 this function creates a dummy mirror_top_bs that goes on top of the source node, and it is this dummy node that gets blocked instead. The source node is never blocked or added to the job's list of nodes. target <- intermediate <- source <- mirror_top At the moment I don't think it is possible to exploit this problem because any additional job on 'source' would either be forbidden for other reasons or it would need to involve an additional node that is blocked, causing an error. This can be seen in the error messages, however, because they never refer to the source node being blocked: $ qemu-img create -f qcow2 hd0.qcow2 1M $ qemu-img create -f qcow2 -b hd0.qcow2 hd1.qcow2 $ qemu-io -c 'write 0 1M' hd0.qcow2 $ $QEMU -drive if=3Dnone,file=3Dhd1.qcow2,node-name=3Dhd1 { "execute": "qmp_capabilities" } { "execute": "block-commit", "arguments": {"device": "hd1", "speed": 256}} { "execute": "block-stream", "arguments": {"device": "hd1"}} { "error": {"class": "GenericError", "desc": "Node 'hd0' is busy: block device is in use by block job: commi= t"}} After this patch the error message refers to 'hd1', as it should. The expected output of iotest 141 also needs to be updated for the same reason. Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/mirror.c | 8 ++++++++ tests/qemu-iotests/141.out | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 4cf1c088c0..b67b0120f8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1612,6 +1612,14 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, goto fail; } =20 + ret =3D block_job_add_bdrv(&s->common, "source", bs, 0, + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE | + BLK_PERM_CONSISTENT_READ, + errp); + if (ret < 0) { + goto fail; + } + /* Required permissions are already taken with blk_new() */ block_job_add_bdrv(&s->common, "target", target, 0, BLK_PERM_ALL, &error_abort); diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out index f252c86875..41c7291258 100644 --- a/tests/qemu-iotests/141.out +++ b/tests/qemu-iotests/141.out @@ -28,7 +28,7 @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D10485= 76 backing_file=3DTEST_DIR/t. {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "spe= ed": 0, "type": "mirror"}} {"return": {}} -{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: node is = used as backing hd of 'NODE_NAME'"}} +{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block de= vice is in use by block job: mirror"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "job0"}} @@ -45,7 +45,7 @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D10485= 76 backing_file=3DTEST_DIR/t. {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "spe= ed": 0, "type": "commit"}} {"return": {}} -{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: node is = used as backing hd of 'NODE_NAME'"}} +{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block de= vice is in use by block job: commit"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "job0"}} --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041075421581.1402511785797; Fri, 1 Feb 2019 09:11:15 -0800 (PST) Received: from localhost ([127.0.0.1]:58285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcLN-00022R-Bj for importer@patchew.org; Fri, 01 Feb 2019 12:11:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbo7-0007nq-Rl for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbo5-00006p-O3 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnz-0007om-Mb; Fri, 01 Feb 2019 11:36:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82B571393DF; Fri, 1 Feb 2019 16:35:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65C1B608C7; Fri, 1 Feb 2019 16:35:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:54 +0100 Message-Id: <20190201163518.31157-4-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Feb 2019 16:35:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/27] qcow2: Assert that refcount block offsets fit in the refcount table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia Refcount table entries have a field to store the offset of the refcount block. The rest of the bits of the entry are currently reserved. The offset is always taken from the entry using REFT_OFFSET_MASK to ensure that we only use the bits that belong to that field. While that mask is used every time we read from the refcount table, it is never used when we write to it. Due to the other constraints of the qcow2 format QEMU can never produce refcount block offsets that don't fit in that field so any such offset when allocating a refcount block would indicate a bug in QEMU. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 1c63ac244a..6f13d470d3 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -368,6 +368,9 @@ static int alloc_refcount_block(BlockDriverState *bs, return new_block; } =20 + /* The offset must fit in the offset field of the refcount table entry= */ + assert((new_block & REFT_OFFSET_MASK) =3D=3D new_block); + /* If we're allocating the block at offset 0 then something is wrong */ if (new_block =3D=3D 0) { qcow2_signal_corruption(bs, true, -1, -1, "Preventing invalid " --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041133096920.9458115836828; Fri, 1 Feb 2019 09:12:13 -0800 (PST) Received: from localhost ([127.0.0.1]:58290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcMD-0002uE-S4 for importer@patchew.org; Fri, 01 Feb 2019 12:12:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00085E-5g for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboM-0000JG-6s for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-0007pt-3W; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E36E23DBE6; Fri, 1 Feb 2019 16:35:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id C880D608C6; Fri, 1 Feb 2019 16:35:36 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:55 +0100 Message-Id: <20190201163518.31157-5-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Feb 2019 16:35:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/27] qemu-iotests: add test case for dmg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: yuchenlin Recently, some bugs in dmg file have been fixed. To prevent reading dmg is broken someday in the future, add a simple test which ensures the conversion from dmg to raw should not hang or face any I/O error. Signed-off-by: yuchenlin Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- tests/qemu-iotests/239 | 53 ++++++++++++++++++ tests/qemu-iotests/239.out | 4 ++ tests/qemu-iotests/check | 7 +++ tests/qemu-iotests/group | 1 + .../sample_images/simple-dmg.dmg.bz2 | Bin 0 -> 3479 bytes 5 files changed, 65 insertions(+) create mode 100755 tests/qemu-iotests/239 create mode 100644 tests/qemu-iotests/239.out create mode 100644 tests/qemu-iotests/sample_images/simple-dmg.dmg.bz2 diff --git a/tests/qemu-iotests/239 b/tests/qemu-iotests/239 new file mode 100755 index 0000000000..6f085d573d --- /dev/null +++ b/tests/qemu-iotests/239 @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Test case for dmg +# +# Copyright (C) 2019 yuchenlin +# +# 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 . +# + +# creator +owner=3Dnpes87184@gmail.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + rm -f "$TEST_IMG.raw" + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc + +_supported_fmt dmg +_supported_proto file +_supported_os Linux + +echo +echo "=3D=3D Testing conversion to raw should success =3D=3D" +_use_sample_img simple-dmg.dmg.bz2 +if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw" ; then + exit 1 +fi + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/239.out b/tests/qemu-iotests/239.out new file mode 100644 index 0000000000..bedbad065b --- /dev/null +++ b/tests/qemu-iotests/239.out @@ -0,0 +1,4 @@ +QA output created by 239 + +=3D=3D Testing conversion to raw should success =3D=3D +*** done diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check index 89ed275988..895e1e3dcb 100755 --- a/tests/qemu-iotests/check +++ b/tests/qemu-iotests/check @@ -237,6 +237,7 @@ image format options -vhdx test vhdx -vmdk test vmdk -luks test luks + -dmg test dmg =20 image protocol options -file test file (default) @@ -304,6 +305,12 @@ testlist options xpand=3Dfalse ;; =20 + -dmg) + IMGFMT=3Ddmg + IMGFMT_GENERIC=3Dfalse + xpand=3Dfalse + ;; + -qed) IMGFMT=3Dqed xpand=3Dfalse diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 0f1c3f9cdf..3e310c7f87 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -235,3 +235,4 @@ 235 auto quick 236 auto quick 238 auto quick +239 rw auto quick diff --git a/tests/qemu-iotests/sample_images/simple-dmg.dmg.bz2 b/tests/qe= mu-iotests/sample_images/simple-dmg.dmg.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..05e719d03d48d6df4f0e995dd8b= ae1ce54c9f5f0 GIT binary patch literal 3479 zcmV;I4QTR0T4*^jL0KkKS(36)s{k7pfB*mg|NsC0|NsC0|NsC0|NsC0|Ns5}|NsC0 z|NsC0|Nr0#eji@i`+e|w_jjtUioUNn9=3Dbhi?FYz+8lea^Pt`n6Q`GfM=3DuI^|rccqR z#)^4QQ(&j0^vx-<6U8+BMo&{rPgMO9KU6K>tx+G-x7 zKxhH7gFqfr)EbhWqfmN7Xqi0_(|U$T%^~Te(<9O!s(P57)gFnX(HMqCnW^apCLkWB zfB?c`7=3DY8$P|yP*p{9YL8X6e}jSLZ{Kmat*Y9I=3DF1sjv(V%IjnFNxA1T<(7k~Y;aPez3F!fB&IWZEW%)byHqn^PtYN0c*2G*ZllN2a;wYb5Z@K!FpiLKS04 zAXF_RNbYzNTvjprs6=3DNSa4=3D(xVBCm>1#>twBnc>5NRuJv+UXVcw)$K?45Ra5gMtys z5#=3DtTi{6o_Dolm>AW0*9z$7i33Gt*7^pYSUXUfIy=3D|9=3D(Y5F2D)W#);#I!)dBq)W~ zrFlJ*pf<%vEyY-2j;_z6FzSi8mQn!dfdGLU#z+u}O%{xk@FlI` z^B@Tz!-52v0~!WxwY>yM5j2L!wDW07lb>SjKuGF1Bv7*3#(>;&j=3DWH?%<2(%C(%mi z3SK&{tsN6|F+h=3D$fRF|SAT&YV;=3D$CM8UPyf&KPGXD@;hw?Ie+ur$Ms`?n=3D z=3DTVuCRg<`%CTS#rC3Rqi{8+-#G7{}$If&w>{u-}tqnXQGZ1vrDn(W+-ydtwD_5(m9 zUlJm4YF$|a547Ok)VNY_1&|O?|T) z42v8J{j@}JBoR7501!b0TQLa}5=3D%fGiZ01vc2PsfW3IL_R4y29^38$GN@}eFEu8;#~W3O zhYo*p2)1qo0FWCdNC$P6JWDI)lRL3RsCq~;CddNVfDeUAK|}zQbl`V}JlvEcUSn8M zpVIf%kFZ>u>OO0J!nRehCj34b&G%X*%F`iNsN=3D6_pV&CdsRu0CM-x>qqFshZ5Cm#cE(tAoIY;2;n; z>6lWK8VC|iQ`TBT@eh_haUvW?s0F~|jWOEDBrNGaBoJh|LX9lsM4vqVlOYszX7pdA z{D&2t%ysWP&xa%2Q6LEk#Gf-=3D1UdvZ5a1%=3DkY@b_PJ?B`u>CaLI&B7em_7b|;n=3DZa zp~fR)pUI5+fvC#Km(lVCNpb=3DXW#mzCYrKf$7gM(TqYzYBKqz54qqz-xcv$fGQrdYy zRD%pqsY(=3D-5JXlPYst2Xv=3D#sccTUb6A-KFq8XNZ`G)4wExi9zHxBO=3DzO;AbFM}`M! zOk?+aXaO;H02oI0Bn>Mv09F(z2D>5BS#O#$P6Hjd6boVGU|fj(_>6Wj@RrKIn;8EB zble1^sy2Z1#DvynHzELF0f+`WC;nB6;l*sYRsG&{OT)PkEN{C-fC@>voA`)pYKBGR zy0qd5hS(-IOAKl(iXY}a|K}p1?TmbyuKT-Qeer)gFKD88^Tpxr*kmLy;0FL}C&d#` zQ|v00fv3#W*mSyZs|-K{zsMn+fmSxpq9<;PGzUke*7{Vc;ba?~~Fp@>uleN{!WoS8VmG%z%nuX9{w6QC^ z>cY}_BnH5wp)m6urZ5+Eu`$-#pj&flXy9V9wq!p zo^)}9fQDYjW6Ab;cYA9~3Cm@szFUBpm=3D2bWB#w0?id*4t_2g7y|0*g1ylSPW9s834 ztjELX^xWJGpL*3Qc>%uRKQna>8~ayaq=3D0g~k?u90E|+R&pb}xi6sAxgk{0I9Tdk7g zC&mCT7%%O`$bs$IGS?S?7$DVck$e=3D=3D@QS_=3DnF(o3(InF7Dn=3D3k=3DLs-^Fw9D7{(U3k zK*%{w#OE;-n}5J@QnW~k0W^>q6Frr!p|88#+Wy;ioe~<*h=3Di%&J;)%alO@Pegg+7j zs``QTeEyD)x7p(92)N`E@8T8H#s^c%*24OW;aGvPuVQef*wBsRpU@6A_g9zdDt9$k z2zRm#rdLi0A^}Fb?sXZ{X@%WaZzShTNF-5=3DFu)3i@t^qa`TwTucE88qh>EN`Jdw+s*<*u-@$9+o1#_6XJ989lqI=3Daz!E}P5riY* zHPwYH$BT`e?rVGc3nGpD(|bD_E!3{ti_*;NZZ0isXL2=3DSVRX$Ti~X!dedY#W1K<$# zh_IvD035p;=3DEk~DC$}ZJd(G3-dd#k6CG#xgT;mmS6+SLid1tQO-9~P#9iv%f zd!`qvbczBF)AAe0yE+WI*}DYOL2J~*ZCc}JWiu0LShw&6`-5`^SkNJY!gsi|e-MHy zZlN9Lb5NbuT7S&4oY6v}13BpeQ|?u0c*7n)Ku*p%ZDF?$7zjKXj(9#K?tO1dMW=3D8& z;MDsGo0=3DCLWp{b5$Kk0kxAl*^l^ziX<28c4->Ed%#N16IrySH$q`4%gn}5ksr>_0H zs-;Y4Bb7U_pNGMK075wJ%DahB2ArR=3DjC`2UWMe`ID;mPgA25l6GVc9>Rqybi7N6(i z3BcjbfprP7Ivcy%+Vs~Z6Hw>JB!kJcD>mdTThTpO$(fg`Ds7pYN4BN<|%(+#T+h1sdgPjUAWN73ki+$-%j_&6PZ$I2$HnSEa zQ?n{BB*A3zmlLHvH@o+ZJm1NSC9(?ka<7OppIcAi{V`Nj+^8SL!ywYLI$v(ivC_){ z5anb)=3DMQS%hUHR@_HKDhdDPf*Hm`w^E{GT!Yq<}Hg8Ia{?PyA70;yx8nD^~B| zjuGESS*z1(bcT1?|;LuVOg&xLebEk(1uB(fZJN&W3!xADj zQD;ugVYYpOt=3DNBu$Bi07WcepgHm6q}1y>vxs^oJetK;=3Dix$9i9M#>O`?6X2pJoXi; z#0mlFG2eK~z-yqErVC2`l5B&)s}jKZMRZxCyQ0^?cp$L5J>4{eoCysx+#X0J?r^+C z#R8d5A5=3D5V#(QMr1?kT}qh|eQ8{a94K6_Sq=3DvcWz&WH@!TREj$F3%=3DNwMQ3YR-$or zlXmr#8-D_(N;#e;g#CE1WYh8byF-ojSdtGh>P8pbz39Ew5qWHa^1-M77ji{7P>_ Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040308139279.2972682924768; Fri, 1 Feb 2019 08:58:28 -0800 (PST) Received: from localhost ([127.0.0.1]:58051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc93-0008Pv-4M for importer@patchew.org; Fri, 01 Feb 2019 11:58:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnT-0007Br-EA for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnQ-0008Ch-Qt for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnA-0007rX-GN; Fri, 01 Feb 2019 11:35:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 465BC8666D; Fri, 1 Feb 2019 16:35:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33851608C8; Fri, 1 Feb 2019 16:35:38 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:56 +0100 Message-Id: <20190201163518.31157-6-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 01 Feb 2019 16:35:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/27] block: Replace qdict_put() by qdict_put_obj() where appropriate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Patch created mechanically by rerunning: $ spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h \ --dir block --in-place Signed-off-by: Markus Armbruster Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/blklogwrites.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index ff98cd5533..d2e01bdb1d 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -295,10 +295,9 @@ static void blk_log_writes_refresh_filename(BlockDrive= rState *bs, qdict_put_str(opts, "driver", "blklogwrites"); =20 qobject_ref(bs->file->bs->full_open_options); - qdict_put_obj(opts, "file", QOBJECT(bs->file->bs->full_open_option= s)); + qdict_put(opts, "file", bs->file->bs->full_open_options); qobject_ref(s->log_file->bs->full_open_options); - qdict_put_obj(opts, "log", - QOBJECT(s->log_file->bs->full_open_options)); + qdict_put(opts, "log", s->log_file->bs->full_open_options); qdict_put_int(opts, "log-sector-size", s->sectorsize); =20 bs->full_open_options =3D opts; --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040450177903.4598695864818; Fri, 1 Feb 2019 09:00:50 -0800 (PST) Received: from localhost ([127.0.0.1]:58079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcBH-0001mZ-Qj for importer@patchew.org; Fri, 01 Feb 2019 12:00:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnV-0007Cw-HO for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnM-0008Bp-UA for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbn4-0007wo-Iu; Fri, 01 Feb 2019 11:35:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD2A7A171C; Fri, 1 Feb 2019 16:35:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94737608C6; Fri, 1 Feb 2019 16:35:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:57 +0100 Message-Id: <20190201163518.31157-7-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Feb 2019 16:35:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/27] block: Fix hangs in synchronous APIs with iothreads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" In the block layer, synchronous APIs are often implemented by creating a coroutine that calls the asynchronous coroutine-based implementation and then waiting for completion with BDRV_POLL_WHILE(). For this to work with iothreads (more specifically, when the synchronous API is called in a thread that is not the home thread of the block device, so that the coroutine will run in a different thread), we must make sure to call aio_wait_kick() at the end of the operation. Many places are missing this, so that BDRV_POLL_WHILE() keeps hanging even if the condition has long become false. Note that bdrv_dec_in_flight() involves an aio_wait_kick() call. This corresponds to the BDRV_POLL_WHILE() in the drain functions, but it is generally not enough for most other operations because they haven't set the return value in the coroutine entry stub yet. To avoid race conditions there, we need to kick after setting the return value. The race window is small enough that the problem doesn't usually surface in the common path. However, it does surface and causes easily reproducible hangs if the operation can return early before even calling bdrv_inc/dec_in_flight, which many of them do (trivial error or no-op success paths). The bug in bdrv_truncate(), bdrv_check() and bdrv_invalidate_cache() is slightly different: These functions even neglected to schedule the coroutine in the home thread of the node. This avoids the hang, but is obviously wrong, too. Fix those to schedule the coroutine in the right AioContext in addition to adding aio_wait_kick() calls. Cc: qemu-stable@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block.c | 6 +- block/block-backend.c | 5 + block/io.c | 8 +- block/nbd-client.c | 1 + block/nvme.c | 1 + block/qcow2.c | 1 + block/qed.c | 1 + tests/test-block-iothread.c | 372 ++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 2 + 9 files changed, 394 insertions(+), 3 deletions(-) create mode 100644 tests/test-block-iothread.c diff --git a/block.c b/block.c index e795a7c5de..0c5d1f11a5 100644 --- a/block.c +++ b/block.c @@ -3725,6 +3725,7 @@ static void bdrv_check_co_entry(void *opaque) { CheckCo *cco =3D opaque; cco->ret =3D bdrv_co_check(cco->bs, cco->res, cco->fix); + aio_wait_kick(); } =20 int bdrv_check(BlockDriverState *bs, @@ -3743,7 +3744,7 @@ int bdrv_check(BlockDriverState *bs, bdrv_check_co_entry(&cco); } else { co =3D qemu_coroutine_create(bdrv_check_co_entry, &cco); - qemu_coroutine_enter(co); + bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, cco.ret =3D=3D -EINPROGRESS); } =20 @@ -4708,6 +4709,7 @@ static void coroutine_fn bdrv_invalidate_cache_co_ent= ry(void *opaque) InvalidateCacheCo *ico =3D opaque; bdrv_co_invalidate_cache(ico->bs, ico->errp); ico->done =3D true; + aio_wait_kick(); } =20 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) @@ -4724,7 +4726,7 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Erro= r **errp) bdrv_invalidate_cache_co_entry(&ico); } else { co =3D qemu_coroutine_create(bdrv_invalidate_cache_co_entry, &ico); - qemu_coroutine_enter(co); + bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !ico.done); } } diff --git a/block/block-backend.c b/block/block-backend.c index cf05abd89d..f0be0d9039 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1220,6 +1220,7 @@ static void blk_read_entry(void *opaque) =20 rwco->ret =3D blk_co_preadv(rwco->blk, rwco->offset, qiov->size, qiov, rwco->flags); + aio_wait_kick(); } =20 static void blk_write_entry(void *opaque) @@ -1229,6 +1230,7 @@ static void blk_write_entry(void *opaque) =20 rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->offset, qiov->size, qiov, rwco->flags); + aio_wait_kick(); } =20 static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf, @@ -1540,6 +1542,7 @@ static void blk_ioctl_entry(void *opaque) =20 rwco->ret =3D blk_co_ioctl(rwco->blk, rwco->offset, qiov->iov[0].iov_base); + aio_wait_kick(); } =20 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf) @@ -1586,6 +1589,7 @@ static void blk_flush_entry(void *opaque) { BlkRwCo *rwco =3D opaque; rwco->ret =3D blk_co_flush(rwco->blk); + aio_wait_kick(); } =20 int blk_flush(BlockBackend *blk) @@ -2018,6 +2022,7 @@ static void blk_pdiscard_entry(void *opaque) QEMUIOVector *qiov =3D rwco->iobuf; =20 rwco->ret =3D blk_co_pdiscard(rwco->blk, rwco->offset, qiov->size); + aio_wait_kick(); } =20 int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes) diff --git a/block/io.c b/block/io.c index bd9d688f8b..213ca03d8d 100644 --- a/block/io.c +++ b/block/io.c @@ -806,6 +806,7 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque) rwco->qiov->size, rwco->qiov, rwco->flags); } + aio_wait_kick(); } =20 /* @@ -2279,6 +2280,7 @@ static void coroutine_fn bdrv_block_status_above_co_e= ntry(void *opaque) data->offset, data->bytes, data->pnum, data->map, data->fi= le); data->done =3D true; + aio_wait_kick(); } =20 /* @@ -2438,6 +2440,7 @@ static void coroutine_fn bdrv_co_rw_vmstate_entry(voi= d *opaque) { BdrvVmstateCo *co =3D opaque; co->ret =3D bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); + aio_wait_kick(); } =20 static inline int @@ -2559,6 +2562,7 @@ static void coroutine_fn bdrv_flush_co_entry(void *op= aque) FlushCo *rwco =3D opaque; =20 rwco->ret =3D bdrv_co_flush(rwco->bs); + aio_wait_kick(); } =20 int coroutine_fn bdrv_co_flush(BlockDriverState *bs) @@ -2704,6 +2708,7 @@ static void coroutine_fn bdrv_pdiscard_co_entry(void = *opaque) DiscardCo *rwco =3D opaque; =20 rwco->ret =3D bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); + aio_wait_kick(); } =20 int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int by= tes) @@ -3217,6 +3222,7 @@ static void coroutine_fn bdrv_truncate_co_entry(void = *opaque) TruncateCo *tco =3D opaque; tco->ret =3D bdrv_co_truncate(tco->child, tco->offset, tco->prealloc, tco->errp); + aio_wait_kick(); } =20 int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, @@ -3236,7 +3242,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, P= reallocMode prealloc, bdrv_truncate_co_entry(&tco); } else { co =3D qemu_coroutine_create(bdrv_truncate_co_entry, &tco); - qemu_coroutine_enter(co); + bdrv_coroutine_enter(child->bs, co); BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); } =20 diff --git a/block/nbd-client.c b/block/nbd-client.c index 813539676d..50a8dadd85 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -119,6 +119,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) s->quit =3D true; nbd_recv_coroutines_wake_all(s); s->read_reply_co =3D NULL; + aio_wait_kick(); } =20 static int nbd_co_send_request(BlockDriverState *bs, diff --git a/block/nvme.c b/block/nvme.c index 982097b5b1..b5952c9b08 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -390,6 +390,7 @@ static void nvme_cmd_sync_cb(void *opaque, int ret) { int *pret =3D opaque; *pret =3D ret; + aio_wait_kick(); } =20 static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, diff --git a/block/qcow2.c b/block/qcow2.c index 4897abae5e..8c91b92865 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1671,6 +1671,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, /* From bdrv_co_create. */ qcow2_open_entry(&qoc); } else { + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context(= )); qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc)= ); BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); } diff --git a/block/qed.c b/block/qed.c index 9377c0b7ad..1280870024 100644 --- a/block/qed.c +++ b/block/qed.c @@ -559,6 +559,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *o= ptions, int flags, if (qemu_in_coroutine()) { bdrv_qed_open_entry(&qoc); } else { + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context(= )); qemu_coroutine_enter(qemu_coroutine_create(bdrv_qed_open_entry, &q= oc)); BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); } diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c new file mode 100644 index 0000000000..97ac0b159d --- /dev/null +++ b/tests/test-block-iothread.c @@ -0,0 +1,372 @@ +/* + * Block tests for iothreads + * + * Copyright (c) 2018 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/block.h" +#include "block/blockjob_int.h" +#include "sysemu/block-backend.h" +#include "qapi/error.h" +#include "iothread.h" + +static int coroutine_fn bdrv_test_co_prwv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags) +{ + return 0; +} + +static int coroutine_fn bdrv_test_co_pdiscard(BlockDriverState *bs, + int64_t offset, int bytes) +{ + return 0; +} + +static int coroutine_fn +bdrv_test_co_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) +{ + return 0; +} + +static int coroutine_fn bdrv_test_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t = count, + int64_t *pnum, int64_t *= map, + BlockDriverState **file) +{ + *pnum =3D count; + return 0; +} + +static BlockDriver bdrv_test =3D { + .format_name =3D "test", + .instance_size =3D 1, + + .bdrv_co_preadv =3D bdrv_test_co_prwv, + .bdrv_co_pwritev =3D bdrv_test_co_prwv, + .bdrv_co_pdiscard =3D bdrv_test_co_pdiscard, + .bdrv_co_truncate =3D bdrv_test_co_truncate, + .bdrv_co_block_status =3D bdrv_test_co_block_status, +}; + +static void test_sync_op_pread(BdrvChild *c) +{ + uint8_t buf[512]; + int ret; + + /* Success */ + ret =3D bdrv_pread(c, 0, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, 512); + + /* Early error: Negative offset */ + ret =3D bdrv_pread(c, -2, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_pwrite(BdrvChild *c) +{ + uint8_t buf[512]; + int ret; + + /* Success */ + ret =3D bdrv_pwrite(c, 0, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, 512); + + /* Early error: Negative offset */ + ret =3D bdrv_pwrite(c, -2, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_blk_pread(BlockBackend *blk) +{ + uint8_t buf[512]; + int ret; + + /* Success */ + ret =3D blk_pread(blk, 0, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, 512); + + /* Early error: Negative offset */ + ret =3D blk_pread(blk, -2, buf, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_blk_pwrite(BlockBackend *blk) +{ + uint8_t buf[512]; + int ret; + + /* Success */ + ret =3D blk_pwrite(blk, 0, buf, sizeof(buf), 0); + g_assert_cmpint(ret, =3D=3D, 512); + + /* Early error: Negative offset */ + ret =3D blk_pwrite(blk, -2, buf, sizeof(buf), 0); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_load_vmstate(BdrvChild *c) +{ + uint8_t buf[512]; + int ret; + + /* Error: Driver does not support snapshots */ + ret =3D bdrv_load_vmstate(c->bs, buf, 0, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, -ENOTSUP); +} + +static void test_sync_op_save_vmstate(BdrvChild *c) +{ + uint8_t buf[512]; + int ret; + + /* Error: Driver does not support snapshots */ + ret =3D bdrv_save_vmstate(c->bs, buf, 0, sizeof(buf)); + g_assert_cmpint(ret, =3D=3D, -ENOTSUP); +} + +static void test_sync_op_pdiscard(BdrvChild *c) +{ + int ret; + + /* Normal success path */ + c->bs->open_flags |=3D BDRV_O_UNMAP; + ret =3D bdrv_pdiscard(c, 0, 512); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early success: UNMAP not supported */ + c->bs->open_flags &=3D ~BDRV_O_UNMAP; + ret =3D bdrv_pdiscard(c, 0, 512); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early error: Negative offset */ + ret =3D bdrv_pdiscard(c, -2, 512); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_blk_pdiscard(BlockBackend *blk) +{ + int ret; + + /* Early success: UNMAP not supported */ + ret =3D blk_pdiscard(blk, 0, 512); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early error: Negative offset */ + ret =3D blk_pdiscard(blk, -2, 512); + g_assert_cmpint(ret, =3D=3D, -EIO); +} + +static void test_sync_op_truncate(BdrvChild *c) +{ + int ret; + + /* Normal success path */ + ret =3D bdrv_truncate(c, 65536, PREALLOC_MODE_OFF, NULL); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early error: Negative offset */ + ret =3D bdrv_truncate(c, -2, PREALLOC_MODE_OFF, NULL); + g_assert_cmpint(ret, =3D=3D, -EINVAL); + + /* Error: Read-only image */ + c->bs->read_only =3D true; + c->bs->open_flags &=3D ~BDRV_O_RDWR; + + ret =3D bdrv_truncate(c, 65536, PREALLOC_MODE_OFF, NULL); + g_assert_cmpint(ret, =3D=3D, -EACCES); + + c->bs->read_only =3D false; + c->bs->open_flags |=3D BDRV_O_RDWR; +} + +static void test_sync_op_block_status(BdrvChild *c) +{ + int ret; + int64_t n; + + /* Normal success path */ + ret =3D bdrv_is_allocated(c->bs, 0, 65536, &n); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early success: No driver support */ + bdrv_test.bdrv_co_block_status =3D NULL; + ret =3D bdrv_is_allocated(c->bs, 0, 65536, &n); + g_assert_cmpint(ret, =3D=3D, 1); + + /* Early success: bytes =3D 0 */ + ret =3D bdrv_is_allocated(c->bs, 0, 0, &n); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early success: Offset > image size*/ + ret =3D bdrv_is_allocated(c->bs, 0x1000000, 0x1000000, &n); + g_assert_cmpint(ret, =3D=3D, 0); +} + +static void test_sync_op_flush(BdrvChild *c) +{ + int ret; + + /* Normal success path */ + ret =3D bdrv_flush(c->bs); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early success: Read-only image */ + c->bs->read_only =3D true; + c->bs->open_flags &=3D ~BDRV_O_RDWR; + + ret =3D bdrv_flush(c->bs); + g_assert_cmpint(ret, =3D=3D, 0); + + c->bs->read_only =3D false; + c->bs->open_flags |=3D BDRV_O_RDWR; +} + +static void test_sync_op_blk_flush(BlockBackend *blk) +{ + BlockDriverState *bs =3D blk_bs(blk); + int ret; + + /* Normal success path */ + ret =3D blk_flush(blk); + g_assert_cmpint(ret, =3D=3D, 0); + + /* Early success: Read-only image */ + bs->read_only =3D true; + bs->open_flags &=3D ~BDRV_O_RDWR; + + ret =3D blk_flush(blk); + g_assert_cmpint(ret, =3D=3D, 0); + + bs->read_only =3D false; + bs->open_flags |=3D BDRV_O_RDWR; +} + +static void test_sync_op_check(BdrvChild *c) +{ + BdrvCheckResult result; + int ret; + + /* Error: Driver does not implement check */ + ret =3D bdrv_check(c->bs, &result, 0); + g_assert_cmpint(ret, =3D=3D, -ENOTSUP); +} + +static void test_sync_op_invalidate_cache(BdrvChild *c) +{ + /* Early success: Image is not inactive */ + bdrv_invalidate_cache(c->bs, NULL); +} + + +typedef struct SyncOpTest { + const char *name; + void (*fn)(BdrvChild *c); + void (*blkfn)(BlockBackend *blk); +} SyncOpTest; + +const SyncOpTest sync_op_tests[] =3D { + { + .name =3D "/sync-op/pread", + .fn =3D test_sync_op_pread, + .blkfn =3D test_sync_op_blk_pread, + }, { + .name =3D "/sync-op/pwrite", + .fn =3D test_sync_op_pwrite, + .blkfn =3D test_sync_op_blk_pwrite, + }, { + .name =3D "/sync-op/load_vmstate", + .fn =3D test_sync_op_load_vmstate, + }, { + .name =3D "/sync-op/save_vmstate", + .fn =3D test_sync_op_save_vmstate, + }, { + .name =3D "/sync-op/pdiscard", + .fn =3D test_sync_op_pdiscard, + .blkfn =3D test_sync_op_blk_pdiscard, + }, { + .name =3D "/sync-op/truncate", + .fn =3D test_sync_op_truncate, + }, { + .name =3D "/sync-op/block_status", + .fn =3D test_sync_op_block_status, + }, { + .name =3D "/sync-op/flush", + .fn =3D test_sync_op_flush, + .blkfn =3D test_sync_op_blk_flush, + }, { + .name =3D "/sync-op/check", + .fn =3D test_sync_op_check, + }, { + .name =3D "/sync-op/invalidate_cache", + .fn =3D test_sync_op_invalidate_cache, + }, +}; + +/* Test synchronous operations that run in a different iothread, so we hav= e to + * poll for the coroutine there to return. */ +static void test_sync_op(const void *opaque) +{ + const SyncOpTest *t =3D opaque; + IOThread *iothread =3D iothread_new(); + AioContext *ctx =3D iothread_get_aio_context(iothread); + BlockBackend *blk; + BlockDriverState *bs; + BdrvChild *c; + + blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs =3D bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_ab= ort); + bs->total_sectors =3D 65536 / BDRV_SECTOR_SIZE; + blk_insert_bs(blk, bs, &error_abort); + c =3D QLIST_FIRST(&bs->parents); + + blk_set_aio_context(blk, ctx); + aio_context_acquire(ctx); + t->fn(c); + if (t->blkfn) { + t->blkfn(blk); + } + aio_context_release(ctx); + blk_set_aio_context(blk, qemu_get_aio_context()); + + bdrv_unref(bs); + blk_unref(blk); +} + +int main(int argc, char **argv) +{ + int i; + + bdrv_init(); + qemu_init_main_loop(&error_abort); + + g_test_init(&argc, &argv, NULL); + + for (i =3D 0; i < ARRAY_SIZE(sync_op_tests); i++) { + const SyncOpTest *t =3D &sync_op_tests[i]; + g_test_add_data_func(t->name, t, test_sync_op); + } + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 19b4c0a696..75ad9c0dd3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -73,6 +73,7 @@ check-unit-y +=3D tests/test-bdrv-drain$(EXESUF) check-unit-y +=3D tests/test-blockjob$(EXESUF) check-unit-y +=3D tests/test-blockjob-txn$(EXESUF) check-unit-y +=3D tests/test-block-backend$(EXESUF) +check-unit-y +=3D tests/test-block-iothread$(EXESUF) check-unit-y +=3D tests/test-image-locking$(EXESUF) check-unit-y +=3D tests/test-x86-cpuid$(EXESUF) # all code tested by test-x86-cpuid is inside topology.h @@ -557,6 +558,7 @@ tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o= $(test-block-obj-y) $(te tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(= test-util-obj-y) tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-o= bj-y) $(test-util-obj-y) tests/test-block-backend$(EXESUF): tests/test-block-backend.o $(test-block= -obj-y) $(test-util-obj-y) +tests/test-block-iothread$(EXESUF): tests/test-block-iothread.o $(test-blo= ck-obj-y) $(test-util-obj-y) tests/test-image-locking$(EXESUF): tests/test-image-locking.o $(test-block= -obj-y) $(test-util-obj-y) tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj= -y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041452706787.897677844513; Fri, 1 Feb 2019 09:17:32 -0800 (PST) Received: from localhost ([127.0.0.1]:58475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcRS-0007c6-FY for importer@patchew.org; Fri, 01 Feb 2019 12:17:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboB-0007s7-63 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbo7-00008f-MJ for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44122) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnt-00082h-2h; Fri, 01 Feb 2019 11:36:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 585B72DE40D; Fri, 1 Feb 2019 16:35:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AF95608C8; Fri, 1 Feb 2019 16:35:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:58 +0100 Message-Id: <20190201163518.31157-8-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 01 Feb 2019 16:35:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/27] iotests: Make 234 stable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Max Reitz This test waits for a MIGRATION event with status=3Dcompleted on the source VM before querying the migration status on both source and destination. However, just because the source says migration has completed does not mean the destination thinks the same. Therefore, in some cases, the destination VM may still report "active" instead of "completed" when asked for its migration status. Fix this by enabling migration events on both VMs and waiting until both source and destination emit a status=3Dcompleted MIGRATION event. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- tests/qemu-iotests/234 | 56 ++++++++++++++++++++------------------ tests/qemu-iotests/234.out | 10 +++++-- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/tests/qemu-iotests/234 b/tests/qemu-iotests/234 index a8185b4360..c4c26bc21e 100755 --- a/tests/qemu-iotests/234 +++ b/tests/qemu-iotests/234 @@ -26,6 +26,22 @@ import os iotests.verify_image_format(supported_fmts=3D['qcow2']) iotests.verify_platform(['linux']) =20 +def enable_migration_events(vm, name): + iotests.log('Enabling migration QMP events on %s...' % name) + iotests.log(vm.qmp('migrate-set-capabilities', capabilities=3D[ + { + 'capability': 'events', + 'state': True + } + ])) + +def wait_migration(vm): + while True: + event =3D vm.event_wait('MIGRATION') + iotests.log(event, filters=3D[iotests.filter_qmp_event]) + if event['data']['status'] =3D=3D 'completed': + break + with iotests.FilePath('img') as img_path, \ iotests.FilePath('backing') as backing_path, \ iotests.FilePath('mig_fifo_a') as fifo_a, \ @@ -46,6 +62,8 @@ with iotests.FilePath('img') as img_path, \ .add_blockdev('%s,file=3Ddrive0-backing-file,node-name=3Ddrive0-b= acking' % (iotests.imgfmt)) .launch()) =20 + enable_migration_events(vm_a, 'A') + iotests.log('Launching destination VM...') (vm_b.add_blockdev('file,filename=3D%s,node-name=3Ddrive0-file' % (img= _path)) .add_blockdev('%s,file=3Ddrive0-file,node-name=3Ddrive0' % (iotes= ts.imgfmt)) @@ -54,6 +72,8 @@ with iotests.FilePath('img') as img_path, \ .add_incoming("exec: cat '%s'" % (fifo_a)) .launch()) =20 + enable_migration_events(vm_b, 'B') + # Add a child node that was created after the parent node. The reverse= case # is covered by the -blockdev options above. iotests.log(vm_a.qmp('blockdev-snapshot', node=3D'drive0-backing', @@ -61,22 +81,13 @@ with iotests.FilePath('img') as img_path, \ iotests.log(vm_b.qmp('blockdev-snapshot', node=3D'drive0-backing', overlay=3D'drive0')) =20 - iotests.log('Enabling migration QMP events on A...') - iotests.log(vm_a.qmp('migrate-set-capabilities', capabilities=3D[ - { - 'capability': 'events', - 'state': True - } - ])) - iotests.log('Starting migration to B...') iotests.log(vm_a.qmp('migrate', uri=3D'exec:cat >%s' % (fifo_a))) with iotests.Timeout(3, 'Migration does not complete'): - while True: - event =3D vm_a.event_wait('MIGRATION') - iotests.log(event, filters=3D[iotests.filter_qmp_event]) - if event['data']['status'] =3D=3D 'completed': - break + # Wait for the source first (which includes setup=3Dsetup) + wait_migration(vm_a) + # Wait for the destination second (which does not) + wait_migration(vm_b) =20 iotests.log(vm_a.qmp('query-migrate')['return']['status']) iotests.log(vm_b.qmp('query-migrate')['return']['status']) @@ -94,25 +105,18 @@ with iotests.FilePath('img') as img_path, \ .add_incoming("exec: cat '%s'" % (fifo_b)) .launch()) =20 + enable_migration_events(vm_a, 'A') + iotests.log(vm_a.qmp('blockdev-snapshot', node=3D'drive0-backing', overlay=3D'drive0')) =20 - iotests.log('Enabling migration QMP events on B...') - iotests.log(vm_b.qmp('migrate-set-capabilities', capabilities=3D[ - { - 'capability': 'events', - 'state': True - } - ])) - iotests.log('Starting migration back to A...') iotests.log(vm_b.qmp('migrate', uri=3D'exec:cat >%s' % (fifo_b))) with iotests.Timeout(3, 'Migration does not complete'): - while True: - event =3D vm_b.event_wait('MIGRATION') - iotests.log(event, filters=3D[iotests.filter_qmp_event]) - if event['data']['status'] =3D=3D 'completed': - break + # Wait for the source first (which includes setup=3Dsetup) + wait_migration(vm_b) + # Wait for the destination second (which does not) + wait_migration(vm_a) =20 iotests.log(vm_a.qmp('query-migrate')['return']['status']) iotests.log(vm_b.qmp('query-migrate')['return']['status']) diff --git a/tests/qemu-iotests/234.out b/tests/qemu-iotests/234.out index b9ed910b1a..692976d1c6 100644 --- a/tests/qemu-iotests/234.out +++ b/tests/qemu-iotests/234.out @@ -1,14 +1,18 @@ Launching source VM... +Enabling migration QMP events on A... +{"return": {}} Launching destination VM... +Enabling migration QMP events on B... {"return": {}} {"return": {}} -Enabling migration QMP events on A... {"return": {}} Starting migration to B... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microse= conds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} +{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} completed completed {"return": {"running": false, "singlestep": false, "status": "postmigrate"= }} @@ -16,14 +20,16 @@ completed Add a second parent to drive0-file... {"return": {}} Restart A with -incoming and second parent... +Enabling migration QMP events on A... {"return": {}} -Enabling migration QMP events on B... {"return": {}} Starting migration back to A... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microse= conds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} +{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} completed completed {"return": {"running": true, "singlestep": false, "status": "running"}} --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040256338461.7438455974743; Fri, 1 Feb 2019 08:57:36 -0800 (PST) Received: from localhost ([127.0.0.1]:58047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc88-0007cj-7k for importer@patchew.org; Fri, 01 Feb 2019 11:57:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboE-0007wN-JK for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboA-0000C6-Lj for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54816) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnz-00083i-Up; Fri, 01 Feb 2019 11:36:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A528BC0C18B4; Fri, 1 Feb 2019 16:35:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DA82608C6; Fri, 1 Feb 2019 16:35:42 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:34:59 +0100 Message-Id: <20190201163518.31157-9-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 01 Feb 2019 16:35:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/27] vmdk: Refactor vmdk_create_extent X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Fam Zheng The extracted vmdk_init_extent takes a BlockBackend object and initializes the format metadata. It is the common part between "qemu-img create" and "blockdev-create". Add a "BlockBackend *pbb" parameter to vmdk_create_extent, to return the opened BB to the caller in the next patch. Signed-off-by: Fam Zheng Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block/vmdk.c | 69 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 2c9e86d98f..32fc2c84b3 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1741,35 +1741,17 @@ static int coroutine_fn vmdk_co_pwrite_zeroes(Block= DriverState *bs, return ret; } =20 -static int vmdk_create_extent(const char *filename, int64_t filesize, - bool flat, bool compress, bool zeroed_grain, - QemuOpts *opts, Error **errp) +static int vmdk_init_extent(BlockBackend *blk, + int64_t filesize, bool flat, + bool compress, bool zeroed_grain, + Error **errp) { int ret, i; - BlockBackend *blk =3D NULL; VMDK4Header header; - Error *local_err =3D NULL; uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count; uint32_t *gd_buf =3D NULL; int gd_buf_size; =20 - ret =3D bdrv_create_file(filename, opts, &local_err); - if (ret < 0) { - error_propagate(errp, local_err); - goto exit; - } - - blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, - &local_err); - if (blk =3D=3D NULL) { - error_propagate(errp, local_err); - ret =3D -EIO; - goto exit; - } - - blk_set_allow_write_beyond_eof(blk, true); - if (flat) { ret =3D blk_truncate(blk, filesize, PREALLOC_MODE_OFF, errp); goto exit; @@ -1863,15 +1845,50 @@ static int vmdk_create_extent(const char *filename,= int64_t filesize, gd_buf, gd_buf_size, 0); if (ret < 0) { error_setg(errp, QERR_IO_ERROR); - goto exit; } =20 ret =3D 0; +exit: + g_free(gd_buf); + return ret; +} + +static int vmdk_create_extent(const char *filename, int64_t filesize, + bool flat, bool compress, bool zeroed_grain, + BlockBackend **pbb, + QemuOpts *opts, Error **errp) +{ + int ret; + BlockBackend *blk =3D NULL; + Error *local_err =3D NULL; + + ret =3D bdrv_create_file(filename, opts, &local_err); + if (ret < 0) { + error_propagate(errp, local_err); + goto exit; + } + + blk =3D blk_new_open(filename, NULL, NULL, + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + &local_err); + if (blk =3D=3D NULL) { + error_propagate(errp, local_err); + ret =3D -EIO; + goto exit; + } + + blk_set_allow_write_beyond_eof(blk, true); + + ret =3D vmdk_init_extent(blk, filesize, flat, compress, zeroed_grain, = errp); exit: if (blk) { - blk_unref(blk); + if (pbb) { + *pbb =3D blk; + } else { + blk_unref(blk); + blk =3D NULL; + } } - g_free(gd_buf); return ret; } =20 @@ -2094,7 +2111,7 @@ static int coroutine_fn vmdk_co_create_opts(const cha= r *filename, QemuOpts *opts snprintf(ext_filename, PATH_MAX, "%s%s", path, desc_filename); =20 if (vmdk_create_extent(ext_filename, size, - flat, compress, zeroed_grain, opts, errp)) { + flat, compress, zeroed_grain, NULL, opts, e= rrp)) { ret =3D -EINVAL; goto exit; } --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041398987559.6948125724139; Fri, 1 Feb 2019 09:16:38 -0800 (PST) Received: from localhost ([127.0.0.1]:58463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcQa-0006tp-O3 for importer@patchew.org; Fri, 01 Feb 2019 12:16:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00085H-66 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboL-0000Iu-LA for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnz-00084m-UM; Fri, 01 Feb 2019 11:36:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C74DC0C0581; Fri, 1 Feb 2019 16:35:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0965608C6; Fri, 1 Feb 2019 16:35:43 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:00 +0100 Message-Id: <20190201163518.31157-10-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 01 Feb 2019 16:35:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/27] vmdk: Implement .bdrv_co_create callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Fam Zheng This makes VMDK support blockdev-create. The implementation reuses the image creation code in vmdk_co_create_opts which now acceptes a callback pointer to "retrieve" BlockBackend pointers from the caller. This way we separate the logic between file/extent acquisition and initialization. The QAPI command parameters are mostly the same as the old create_opts except the dropped legacy @compat6 switch, which is redundant with @hwversion. Signed-off-by: Fam Zheng Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- qapi/block-core.json | 70 +++++++ qapi/qapi-schema.json | 16 +- block/vmdk.c | 448 ++++++++++++++++++++++++++++++------------ 3 files changed, 400 insertions(+), 134 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index cde1b53708..a5924b40af 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4137,6 +4137,75 @@ 'size': 'size', '*cluster-size' : 'size' } } =20 +## +# @BlockdevVmdkSubformat: +# +# Subformat options for VMDK images +# +# @monolithicSparse: Single file image with sparse cluster allocation +# +# @monolithicFlat: Single flat data image and a descriptor file +# +# @twoGbMaxExtentSparse: Data is split into 2GB (per virtual LBA) sparse e= xtent +# files, in addition to a descriptor file +# +# @twoGbMaxExtentFlat: Data is split into 2GB (per virtual LBA) flat ext= ent +# files, in addition to a descriptor file +# +# @streamOptimized: Single file image sparse cluster allocation, opti= mized +# for streaming over network. +# +# Since: 4.0 +## +{ 'enum': 'BlockdevVmdkSubformat', + 'data': [ 'monolithicSparse', 'monolithicFlat', 'twoGbMaxExtentSparse', + 'twoGbMaxExtentFlat', 'streamOptimized'] } + +## +# @BlockdevVmdkAdapterType: +# +# Adapter type info for VMDK images +# +# Since: 4.0 +## +{ 'enum': 'BlockdevVmdkAdapterType', + 'data': [ 'ide', 'buslogic', 'lsilogic', 'legacyESX'] } + +## +# @BlockdevCreateOptionsVmdk: +# +# Driver specific image creation options for VMDK. +# +# @file Where to store the new image file. This refers to the image +# file for monolithcSparse and streamOptimized format, or the +# descriptor file for other formats. +# @size Size of the virtual disk in bytes +# @extents Where to store the data extents. Required for monolithcFla= t, +# twoGbMaxExtentSparse and twoGbMaxExtentFlat formats. For +# monolithicFlat, only one entry is required; for +# twoGbMaxExtent* formats, the number of entries required is +# calculated as extent_number =3D virtual_size / 2GB. +# @subformat The subformat of the VMDK image. Default: "monolithicSpars= e". +# @backing-file The path of backing file. Default: no backing file is used. +# @adapter-type The adapter type used to fill in the descriptor. Default: = ide. +# @hwversion Hardware version. The meaningful options are "4" or "6". +# Default: "4". +# @zeroed-grain Whether to enable zeroed-grain feature for sparse subforma= ts. +# Default: false. +# +# Since: 4.0 +## +{ 'struct': 'BlockdevCreateOptionsVmdk', + 'data': { 'file': 'BlockdevRef', + 'size': 'size', + '*extents': ['BlockdevRef'], + '*subformat': 'BlockdevVmdkSubformat', + '*backing-file': 'str', + '*adapter-type': 'BlockdevVmdkAdapterType', + '*hwversion': 'str', + '*zeroed-grain': 'bool' } } + + ## # @SheepdogRedundancyType: # @@ -4331,6 +4400,7 @@ 'ssh': 'BlockdevCreateOptionsSsh', 'vdi': 'BlockdevCreateOptionsVdi', 'vhdx': 'BlockdevCreateOptionsVhdx', + 'vmdk': 'BlockdevCreateOptionsVmdk', 'vpc': 'BlockdevCreateOptionsVpc' } } =20 diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 3bbdfcee84..1845aa78ff 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -63,13 +63,15 @@ 'query-tpm-types', 'ringbuf-read' ], 'name-case-whitelist': [ - 'ACPISlotType', # DIMM, visible through query-acpi-ospm-st= atus - 'CpuInfoMIPS', # PC, visible through query-cpu - 'CpuInfoTricore', # PC, visible through query-cpu - 'QapiErrorClass', # all members, visible through errors - 'UuidInfo', # UUID, visible through query-uuid - 'X86CPURegister32', # all members, visible indirectly through = qom-get - 'q_obj_CpuInfo-base' # CPU, visible through query-cpu + 'ACPISlotType', # DIMM, visible through query-acpi-osp= m-status + 'CpuInfoMIPS', # PC, visible through query-cpu + 'CpuInfoTricore', # PC, visible through query-cpu + 'BlockdevVmdkSubformat', # all members, to match VMDK spec spel= lings + 'BlockdevVmdkAdapterType', # legacyESX, to match VMDK spec spelli= ngs + 'QapiErrorClass', # all members, visible through errors + 'UuidInfo', # UUID, visible through query-uuid + 'X86CPURegister32', # all members, visible indirectly thro= ugh qom-get + 'q_obj_CpuInfo-base' # CPU, visible through query-cpu ] } } =20 # Documentation generated with qapi-gen.py is in source order, with diff --git a/block/vmdk.c b/block/vmdk.c index 32fc2c84b3..5a162ee85c 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1932,33 +1932,56 @@ static int filename_decompose(const char *filename,= char *path, char *prefix, return VMDK_OK; } =20 -static int coroutine_fn vmdk_co_create_opts(const char *filename, QemuOpts= *opts, - Error **errp) +/* + * idx =3D=3D 0: get or create the descriptor file (also the image file if= in a + * non-split format. + * idx >=3D 1: get the n-th extent if in a split subformat + */ +typedef BlockBackend *(*vmdk_create_extent_fn)(int64_t size, + int idx, + bool flat, + bool split, + bool compress, + bool zeroed_grain, + void *opaque, + Error **errp); + +static void vmdk_desc_add_extent(GString *desc, + const char *extent_line_fmt, + int64_t size, const char *filename) +{ + char *basename =3D g_path_get_basename(filename); + + g_string_append_printf(desc, extent_line_fmt, + DIV_ROUND_UP(size, BDRV_SECTOR_SIZE), basename); + g_free(basename); +} + +static int coroutine_fn vmdk_co_do_create(int64_t size, + BlockdevVmdkSubformat subformat, + BlockdevVmdkAdapterType adapter_= type, + const char *backing_file, + const char *hw_version, + bool compat6, + bool zeroed_grain, + vmdk_create_extent_fn extent_fn, + void *opaque, + Error **errp) { - int idx =3D 0; - BlockBackend *new_blk =3D NULL; + int extent_idx; + BlockBackend *blk =3D NULL; Error *local_err =3D NULL; char *desc =3D NULL; - int64_t total_size =3D 0, filesize; - char *adapter_type =3D NULL; - char *backing_file =3D NULL; - char *hw_version =3D NULL; - char *fmt =3D NULL; int ret =3D 0; bool flat, split, compress; GString *ext_desc_lines; - char *path =3D g_malloc0(PATH_MAX); - char *prefix =3D g_malloc0(PATH_MAX); - char *postfix =3D g_malloc0(PATH_MAX); - char *desc_line =3D g_malloc0(BUF_SIZE); - char *ext_filename =3D g_malloc0(PATH_MAX); - char *desc_filename =3D g_malloc0(PATH_MAX); const int64_t split_size =3D 0x80000000; /* VMDK has constant split s= ize */ - const char *desc_extent_line; + int64_t extent_size; + int64_t created_size =3D 0; + const char *extent_line_fmt; char *parent_desc_line =3D g_malloc0(BUF_SIZE); uint32_t parent_cid =3D 0xffffffff; uint32_t number_heads =3D 16; - bool zeroed_grain =3D false; uint32_t desc_offset =3D 0, desc_len; const char desc_template[] =3D "# Disk DescriptorFile\n" @@ -1982,71 +2005,35 @@ static int coroutine_fn vmdk_co_create_opts(const c= har *filename, QemuOpts *opts =20 ext_desc_lines =3D g_string_new(NULL); =20 - if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp= )) { - ret =3D -EINVAL; - goto exit; - } /* Read out options */ - total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - adapter_type =3D qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); - backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); - hw_version =3D qemu_opt_get_del(opts, BLOCK_OPT_HWVERSION); - if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) { - if (strcmp(hw_version, "undefined")) { + if (compat6) { + if (hw_version) { error_setg(errp, "compat6 cannot be enabled with hwversion set"); ret =3D -EINVAL; goto exit; } - g_free(hw_version); - hw_version =3D g_strdup("6"); - } - if (strcmp(hw_version, "undefined") =3D=3D 0) { - g_free(hw_version); - hw_version =3D g_strdup("4"); + hw_version =3D "6"; } - fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); - if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) { - zeroed_grain =3D true; + if (!hw_version) { + hw_version =3D "4"; } =20 - if (!adapter_type) { - adapter_type =3D g_strdup("ide"); - } else if (strcmp(adapter_type, "ide") && - strcmp(adapter_type, "buslogic") && - strcmp(adapter_type, "lsilogic") && - strcmp(adapter_type, "legacyESX")) { - error_setg(errp, "Unknown adapter type: '%s'", adapter_type); - ret =3D -EINVAL; - goto exit; - } - if (strcmp(adapter_type, "ide") !=3D 0) { + if (adapter_type !=3D BLOCKDEV_VMDK_ADAPTER_TYPE_IDE) { /* that's the number of heads with which vmware operates when creating, exporting, etc. vmdk files with a non-ide adapter typ= e */ number_heads =3D 255; } - if (!fmt) { - /* Default format to monolithicSparse */ - fmt =3D g_strdup("monolithicSparse"); - } else if (strcmp(fmt, "monolithicFlat") && - strcmp(fmt, "monolithicSparse") && - strcmp(fmt, "twoGbMaxExtentSparse") && - strcmp(fmt, "twoGbMaxExtentFlat") && - strcmp(fmt, "streamOptimized")) { - error_setg(errp, "Unknown subformat: '%s'", fmt); - ret =3D -EINVAL; - goto exit; - } - split =3D !(strcmp(fmt, "twoGbMaxExtentFlat") && - strcmp(fmt, "twoGbMaxExtentSparse")); - flat =3D !(strcmp(fmt, "monolithicFlat") && - strcmp(fmt, "twoGbMaxExtentFlat")); - compress =3D !strcmp(fmt, "streamOptimized"); + split =3D (subformat =3D=3D BLOCKDEV_VMDK_SUBFORMAT_TWOGBMAXEXTENTFLAT= ) || + (subformat =3D=3D BLOCKDEV_VMDK_SUBFORMAT_TWOGBMAXEXTENTSPARSE= ); + flat =3D (subformat =3D=3D BLOCKDEV_VMDK_SUBFORMAT_MONOLITHICFLAT) || + (subformat =3D=3D BLOCKDEV_VMDK_SUBFORMAT_TWOGBMAXEXTENTFLAT); + compress =3D subformat =3D=3D BLOCKDEV_VMDK_SUBFORMAT_STREAMOPTIMIZED; + if (flat) { - desc_extent_line =3D "RW %" PRId64 " FLAT \"%s\" 0\n"; + extent_line_fmt =3D "RW %" PRId64 " FLAT \"%s\" 0\n"; } else { - desc_extent_line =3D "RW %" PRId64 " SPARSE \"%s\"\n"; + extent_line_fmt =3D "RW %" PRId64 " SPARSE \"%s\"\n"; } if (flat && backing_file) { error_setg(errp, "Flat image can't have backing file"); @@ -2058,10 +2045,34 @@ static int coroutine_fn vmdk_co_create_opts(const c= har *filename, QemuOpts *opts ret =3D -ENOTSUP; goto exit; } + + /* Create extents */ + if (split) { + extent_size =3D split_size; + } else { + extent_size =3D size; + } + if (!split && !flat) { + created_size =3D extent_size; + } else { + created_size =3D 0; + } + /* Get the descriptor file BDS */ + blk =3D extent_fn(created_size, 0, flat, split, compress, zeroed_grain, + opaque, errp); + if (!blk) { + ret =3D -EIO; + goto exit; + } + if (!split && !flat) { + vmdk_desc_add_extent(ext_desc_lines, extent_line_fmt, created_size, + blk_bs(blk)->filename); + } + if (backing_file) { - BlockBackend *blk; + BlockBackend *backing; char *full_backing =3D g_new0(char, PATH_MAX); - bdrv_get_full_backing_filename_from_filename(filename, backing_fil= e, + bdrv_get_full_backing_filename_from_filename(blk_bs(blk)->filename= , backing_file, full_backing, PATH_MA= X, &local_err); if (local_err) { @@ -2071,106 +2082,211 @@ static int coroutine_fn vmdk_co_create_opts(const= char *filename, QemuOpts *opts goto exit; } =20 - blk =3D blk_new_open(full_backing, NULL, NULL, - BDRV_O_NO_BACKING, errp); + backing =3D blk_new_open(full_backing, NULL, NULL, + BDRV_O_NO_BACKING, errp); g_free(full_backing); - if (blk =3D=3D NULL) { + if (backing =3D=3D NULL) { ret =3D -EIO; goto exit; } - if (strcmp(blk_bs(blk)->drv->format_name, "vmdk")) { - blk_unref(blk); + if (strcmp(blk_bs(backing)->drv->format_name, "vmdk")) { + error_setg(errp, "Invalid backing file format: %s. Must be vmd= k", + blk_bs(backing)->drv->format_name); + blk_unref(backing); ret =3D -EINVAL; goto exit; } - ret =3D vmdk_read_cid(blk_bs(blk), 0, &parent_cid); - blk_unref(blk); + ret =3D vmdk_read_cid(blk_bs(backing), 0, &parent_cid); + blk_unref(backing); if (ret) { + error_setg(errp, "Failed to read parent CID"); goto exit; } snprintf(parent_desc_line, BUF_SIZE, "parentFileNameHint=3D\"%s\"", backing_file); } - - /* Create extents */ - filesize =3D total_size; - while (filesize > 0) { - int64_t size =3D filesize; - - if (split && size > split_size) { - size =3D split_size; - } - if (split) { - snprintf(desc_filename, PATH_MAX, "%s-%c%03d%s", - prefix, flat ? 'f' : 's', ++idx, postfix); - } else if (flat) { - snprintf(desc_filename, PATH_MAX, "%s-flat%s", prefix, postfix= ); - } else { - snprintf(desc_filename, PATH_MAX, "%s%s", prefix, postfix); - } - snprintf(ext_filename, PATH_MAX, "%s%s", path, desc_filename); - - if (vmdk_create_extent(ext_filename, size, - flat, compress, zeroed_grain, NULL, opts, e= rrp)) { + extent_idx =3D 1; + while (created_size < size) { + BlockBackend *extent_blk; + int64_t cur_size =3D MIN(size - created_size, extent_size); + extent_blk =3D extent_fn(cur_size, extent_idx, flat, split, compre= ss, + zeroed_grain, opaque, errp); + if (!extent_blk) { ret =3D -EINVAL; goto exit; } - filesize -=3D size; - - /* Format description line */ - snprintf(desc_line, BUF_SIZE, - desc_extent_line, size / BDRV_SECTOR_SIZE, desc_filena= me); - g_string_append(ext_desc_lines, desc_line); + vmdk_desc_add_extent(ext_desc_lines, extent_line_fmt, cur_size, + blk_bs(extent_blk)->filename); + created_size +=3D cur_size; + extent_idx++; + blk_unref(extent_blk); } /* generate descriptor file */ desc =3D g_strdup_printf(desc_template, g_random_int(), parent_cid, - fmt, + BlockdevVmdkSubformat_str(subformat), parent_desc_line, ext_desc_lines->str, hw_version, - total_size / + size / (int64_t)(63 * number_heads * BDRV_SECTOR_S= IZE), number_heads, - adapter_type); + BlockdevVmdkAdapterType_str(adapter_type)); desc_len =3D strlen(desc); /* the descriptor offset =3D 0x200 */ if (!split && !flat) { desc_offset =3D 0x200; - } else { - ret =3D bdrv_create_file(filename, opts, &local_err); + } + + ret =3D blk_pwrite(blk, desc_offset, desc, desc_len, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not write description"); + goto exit; + } + /* bdrv_pwrite write padding zeros to align to sector, we don't need t= hat + * for description file */ + if (desc_offset =3D=3D 0) { + ret =3D blk_truncate(blk, desc_len, PREALLOC_MODE_OFF, errp); if (ret < 0) { - error_propagate(errp, local_err); goto exit; } } + ret =3D 0; +exit: + if (blk) { + blk_unref(blk); + } + g_free(desc); + g_free(parent_desc_line); + g_string_free(ext_desc_lines, true); + return ret; +} =20 - new_blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, - &local_err); - if (new_blk =3D=3D NULL) { - error_propagate(errp, local_err); - ret =3D -EIO; +typedef struct { + char *path; + char *prefix; + char *postfix; + QemuOpts *opts; +} VMDKCreateOptsData; + +static BlockBackend *vmdk_co_create_opts_cb(int64_t size, int idx, + bool flat, bool split, bool co= mpress, + bool zeroed_grain, void *opaqu= e, + Error **errp) +{ + BlockBackend *blk =3D NULL; + BlockDriverState *bs =3D NULL; + VMDKCreateOptsData *data =3D opaque; + char *ext_filename =3D NULL; + char *rel_filename =3D NULL; + + if (idx =3D=3D 0) { + rel_filename =3D g_strdup_printf("%s%s", data->prefix, data->postf= ix); + } else if (split) { + rel_filename =3D g_strdup_printf("%s-%c%03d%s", + data->prefix, + flat ? 'f' : 's', idx, data->postfi= x); + } else { + assert(idx =3D=3D 1); + rel_filename =3D g_strdup_printf("%s-flat%s", data->prefix, data->= postfix); + } + + ext_filename =3D g_strdup_printf("%s%s", data->path, rel_filename); + g_free(rel_filename); + + if (vmdk_create_extent(ext_filename, size, + flat, compress, zeroed_grain, &blk, data->opts, + errp)) { goto exit; } + bdrv_unref(bs); +exit: + g_free(ext_filename); + return blk; +} =20 - blk_set_allow_write_beyond_eof(new_blk, true); +static int coroutine_fn vmdk_co_create_opts(const char *filename, QemuOpts= *opts, + Error **errp) +{ + Error *local_err =3D NULL; + char *desc =3D NULL; + int64_t total_size =3D 0; + char *adapter_type =3D NULL; + BlockdevVmdkAdapterType adapter_type_enum; + char *backing_file =3D NULL; + char *hw_version =3D NULL; + char *fmt =3D NULL; + BlockdevVmdkSubformat subformat; + int ret =3D 0; + char *path =3D g_malloc0(PATH_MAX); + char *prefix =3D g_malloc0(PATH_MAX); + char *postfix =3D g_malloc0(PATH_MAX); + char *desc_line =3D g_malloc0(BUF_SIZE); + char *ext_filename =3D g_malloc0(PATH_MAX); + char *desc_filename =3D g_malloc0(PATH_MAX); + char *parent_desc_line =3D g_malloc0(BUF_SIZE); + bool zeroed_grain; + bool compat6; + VMDKCreateOptsData data; =20 - ret =3D blk_pwrite(new_blk, desc_offset, desc, desc_len, 0); - if (ret < 0) { - error_setg_errno(errp, -ret, "Could not write description"); + if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp= )) { + ret =3D -EINVAL; goto exit; } - /* bdrv_pwrite write padding zeros to align to sector, we don't need t= hat - * for description file */ - if (desc_offset =3D=3D 0) { - ret =3D blk_truncate(new_blk, desc_len, PREALLOC_MODE_OFF, errp); + /* Read out options */ + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); + adapter_type =3D qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); + backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); + hw_version =3D qemu_opt_get_del(opts, BLOCK_OPT_HWVERSION); + compat6 =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false); + if (strcmp(hw_version, "undefined") =3D=3D 0) { + g_free(hw_version); + hw_version =3D g_strdup("4"); } -exit: - if (new_blk) { - blk_unref(new_blk); + fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); + zeroed_grain =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, f= alse); + + if (adapter_type) { + adapter_type_enum =3D qapi_enum_parse(&BlockdevVmdkAdapterType_loo= kup, + adapter_type, + BLOCKDEV_VMDK_ADAPTER_TYPE_IDE, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto exit; + } + } else { + adapter_type_enum =3D BLOCKDEV_VMDK_ADAPTER_TYPE_IDE; } + + if (!fmt) { + /* Default format to monolithicSparse */ + subformat =3D BLOCKDEV_VMDK_SUBFORMAT_MONOLITHICSPARSE; + } else { + subformat =3D qapi_enum_parse(&BlockdevVmdkSubformat_lookup, + fmt, + BLOCKDEV_VMDK_SUBFORMAT_MONOLITHICSPAR= SE, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto exit; + } + } + data =3D (VMDKCreateOptsData){ + .prefix =3D prefix, + .postfix =3D postfix, + .path =3D path, + .opts =3D opts, + }; + ret =3D vmdk_co_do_create(total_size, subformat, adapter_type_enum, + backing_file, hw_version, compat6, zeroed_grai= n, + vmdk_co_create_opts_cb, &data, errp); + +exit: g_free(adapter_type); g_free(backing_file); g_free(hw_version); @@ -2183,7 +2299,84 @@ exit: g_free(ext_filename); g_free(desc_filename); g_free(parent_desc_line); - g_string_free(ext_desc_lines, true); + return ret; +} + +static BlockBackend *vmdk_co_create_cb(int64_t size, int idx, + bool flat, bool split, bool compres= s, + bool zeroed_grain, void *opaque, + Error **errp) +{ + int ret; + BlockDriverState *bs; + BlockBackend *blk; + BlockdevCreateOptionsVmdk *opts =3D opaque; + + if (idx =3D=3D 0) { + bs =3D bdrv_open_blockdev_ref(opts->file, errp); + } else { + int i; + BlockdevRefList *list =3D opts->extents; + for (i =3D 1; i < idx; i++) { + if (!list || !list->next) { + error_setg(errp, "Extent [%d] not specified", i); + return NULL; + } + list =3D list->next; + } + if (!list) { + error_setg(errp, "Extent [%d] not specified", idx - 1); + return NULL; + } + bs =3D bdrv_open_blockdev_ref(list->value, errp); + } + if (!bs) { + return NULL; + } + blk =3D blk_new(BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_R= ESIZE, + BLK_PERM_ALL); + if (blk_insert_bs(blk, bs, errp)) { + bdrv_unref(bs); + return NULL; + } + blk_set_allow_write_beyond_eof(blk, true); + bdrv_unref(bs); + + ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp= ); + if (ret) { + blk_unref(blk); + blk =3D NULL; + } + return blk; +} + +static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_optio= ns, + Error **errp) +{ + int ret; + BlockdevCreateOptionsVmdk *opts; + + opts =3D &create_options->u.vmdk; + + /* Validate options */ + if (!QEMU_IS_ALIGNED(opts->size, BDRV_SECTOR_SIZE)) { + error_setg(errp, "Image size must be a multiple of 512 bytes"); + ret =3D -EINVAL; + goto out; + } + + ret =3D vmdk_co_do_create(opts->size, + opts->subformat, + opts->adapter_type, + opts->backing_file, + opts->hwversion, + false, + opts->zeroed_grain, + vmdk_co_create_cb, + opts, errp); + return ret; + +out: return ret; } =20 @@ -2451,6 +2644,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_co_pwrite_zeroes =3D vmdk_co_pwrite_zeroes, .bdrv_close =3D vmdk_close, .bdrv_co_create_opts =3D vmdk_co_create_opts, + .bdrv_co_create =3D vmdk_co_create, .bdrv_co_flush_to_disk =3D vmdk_co_flush, .bdrv_co_block_status =3D vmdk_co_block_status, .bdrv_get_allocated_file_size =3D vmdk_get_allocated_file_size, --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040674952247.91148532856175; Fri, 1 Feb 2019 09:04:34 -0800 (PST) Received: from localhost ([127.0.0.1]:58153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcEu-0004eR-Sx for importer@patchew.org; Fri, 01 Feb 2019 12:04:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnz-0007ea-Oo for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnx-0008Ri-Pj for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26383) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnk-00086J-FY; Fri, 01 Feb 2019 11:36:28 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E48B7AEB2; Fri, 1 Feb 2019 16:35:46 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 862DF608C6; Fri, 1 Feb 2019 16:35:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:01 +0100 Message-Id: <20190201163518.31157-11-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/27] iotests: Filter cid numbers in VMDK extent info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Fam Zheng Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- tests/qemu-iotests/common.filter | 1 + tests/qemu-iotests/iotests.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 2031e353a5..1aa7d57140 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -165,6 +165,7 @@ _filter_img_info() -e "/table_size: [0-9]\\+/d" \ -e "/compat: '[^']*'/d" \ -e "/compat6: \\(on\\|off\\)/d" \ + -e "s/cid: [0-9]\+/cid: XXXXXXXXXX/" \ -e "/static: \\(on\\|off\\)/d" \ -e "/zeroed_grain: \\(on\\|off\\)/d" \ -e "/subformat: '[^']*'/d" \ diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 009c614ef7..71214d46b5 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -299,6 +299,7 @@ def filter_img_info(output, filename): .replace(imgfmt, 'IMGFMT') line =3D re.sub('iters: [0-9]+', 'iters: XXX', line) line =3D re.sub('uuid: [-a-f0-9]+', 'uuid: XXXXXXXX-XXXX-XXXX-XXXX= -XXXXXXXXXXXX', line) + line =3D re.sub('cid: [0-9]+', 'cid: XXXXXXXXXX', line) lines.append(line) return '\n'.join(lines) =20 --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040906348942.8699519179826; Fri, 1 Feb 2019 09:08:26 -0800 (PST) Received: from localhost ([127.0.0.1]:58226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcIc-0007oJ-3j for importer@patchew.org; Fri, 01 Feb 2019 12:08:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbo0-0007eo-0K for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnx-0008Ra-P8 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnX-00087Y-H2; Fri, 01 Feb 2019 11:36:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09719CA396; Fri, 1 Feb 2019 16:35:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id E58A2608C7; Fri, 1 Feb 2019 16:35:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:02 +0100 Message-Id: <20190201163518.31157-12-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Feb 2019 16:35:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/27] iotests: Add VMDK tests for blockdev-create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- tests/qemu-iotests/237 | 233 +++++++++++++++++++++++++ tests/qemu-iotests/237.out | 347 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 581 insertions(+) create mode 100755 tests/qemu-iotests/237 create mode 100644 tests/qemu-iotests/237.out diff --git a/tests/qemu-iotests/237 b/tests/qemu-iotests/237 new file mode 100755 index 0000000000..e04a1ac6be --- /dev/null +++ b/tests/qemu-iotests/237 @@ -0,0 +1,233 @@ +#!/usr/bin/env python +# +# Test vmdk and file image creation +# +# Copyright (C) 2018 Red Hat, Inc. +# +# Creator/Owner: Kevin Wolf +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +from iotests import imgfmt + +iotests.verify_image_format(supported_fmts=3D['vmdk']) + +def blockdev_create(vm, options): + result =3D vm.qmp_log('blockdev-create', job_id=3D'job0', options=3Dop= tions) + + if 'return' in result: + assert result['return'] =3D=3D {} + vm.run_job('job0') + iotests.log("") + +with iotests.FilePath('t.vmdk') as disk_path, \ + iotests.FilePath('t.vmdk.1') as extent1_path, \ + iotests.FilePath('t.vmdk.2') as extent2_path, \ + iotests.FilePath('t.vmdk.3') as extent3_path, \ + iotests.VM() as vm: + + # + # Successful image creation (defaults) + # + iotests.log("=3D=3D=3D Successful image creation (defaults) =3D=3D=3D") + iotests.log("") + + size =3D 5 * 1024 * 1024 * 1024 + + vm.launch() + blockdev_create(vm, { 'driver': 'file', + 'filename': disk_path, + 'size': 0 }) + + vm.qmp_log('blockdev-add', driver=3D'file', filename=3Ddisk_path, + node_name=3D'imgfile') + + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'imgfile', + 'size': size }) + vm.shutdown() + + iotests.img_info_log(disk_path) + + # + # Successful image creation (inline blockdev-add, explicit defaults) + # + iotests.log("=3D=3D=3D Successful image creation (inline blockdev-add,= explicit defaults) =3D=3D=3D") + iotests.log("") + + # Choose a different size to show that we got a new image + size =3D 64 * 1024 * 1024 + + vm.launch() + blockdev_create(vm, { 'driver': 'file', + 'filename': disk_path, + 'size': 0 }) + + blockdev_create(vm, { 'driver': imgfmt, + 'file': { + 'driver': 'file', + 'filename': disk_path, + }, + 'size': size, + 'extents': [], + 'subformat': 'monolithicSparse', + 'adapter-type': 'ide', + 'hwversion': '4', + 'zeroed-grain': False }) + vm.shutdown() + + iotests.img_info_log(disk_path) + + # + # Successful image creation (non-default options) + # + iotests.log("=3D=3D=3D Successful image creation (with non-default opt= ions) =3D=3D=3D") + iotests.log("") + + # Choose a different size to show that we got a new image + size =3D 32 * 1024 * 1024 + + vm.launch() + blockdev_create(vm, { 'driver': 'file', + 'filename': disk_path, + 'size': 0 }) + + blockdev_create(vm, { 'driver': imgfmt, + 'file': { + 'driver': 'file', + 'filename': disk_path, + }, + 'size': size, + 'extents': [], + 'subformat': 'monolithicSparse', + 'adapter-type': 'buslogic', + 'zeroed-grain': True }) + vm.shutdown() + + iotests.img_info_log(disk_path) + + # + # Invalid BlockdevRef + # + iotests.log("=3D=3D=3D Invalid BlockdevRef =3D=3D=3D") + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': imgfmt, + 'file': "this doesn't exist", + 'size': size }) + vm.shutdown() + + # + # Adapter types + # + + iotests.log("=3D=3D=3D Adapter types =3D=3D=3D") + iotests.log("") + + vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3Dnode0' % (dis= k_path)) + + # Valid + iotests.log("=3D=3D Valid adapter types =3D=3D") + iotests.log("") + + vm.launch() + for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]: + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': size, + 'adapter-type': adapter_type }) + vm.shutdown() + + # Invalid + iotests.log("=3D=3D Invalid adapter types =3D=3D") + iotests.log("") + + vm.launch() + for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]: + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': size, + 'adapter-type': adapter_type }) + vm.shutdown() + + # + # Other subformats + # + iotests.log("=3D=3D=3D Other subformats =3D=3D=3D") + iotests.log("") + + for path in [ extent1_path, extent2_path, extent3_path ]: + msg =3D iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0') + iotests.log(msg, [iotests.filter_testfiles]) + + vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3Dext1' % (exte= nt1_path)) + vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3Dext2' % (exte= nt2_path)) + vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3Dext3' % (exte= nt3_path)) + + # Missing extent + iotests.log("=3D=3D Missing extent =3D=3D") + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': size, + 'subformat': 'monolithicFlat' }) + vm.shutdown() + + # Correct extent + iotests.log("=3D=3D Correct extent =3D=3D") + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': size, + 'subformat': 'monolithicFlat', + 'extents': ['ext1'] }) + vm.shutdown() + + # Extra extent + iotests.log("=3D=3D Extra extent =3D=3D") + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': 512, + 'subformat': 'monolithicFlat', + 'extents': ['ext1', 'ext2', 'ext3'] }) + vm.shutdown() + + # Split formats + iotests.log("=3D=3D Split formats =3D=3D") + iotests.log("") + + for size in [ 512, 1073741824, 2147483648, 5368709120 ]: + for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]: + iotests.log("=3D %s %d =3D" % (subfmt, size)) + iotests.log("") + + vm.launch() + blockdev_create(vm, { 'driver': imgfmt, + 'file': 'node0', + 'size': size, + 'subformat': subfmt, + 'extents': ['ext1', 'ext2', 'ext3'] }) + vm.shutdown() + + iotests.img_info_log(disk_path) diff --git a/tests/qemu-iotests/237.out b/tests/qemu-iotests/237.out new file mode 100644 index 0000000000..1aa9aad349 --- /dev/null +++ b/tests/qemu-iotests/237.out @@ -0,0 +1,347 @@ +=3D=3D=3D Successful image creation (defaults) =3D=3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "file", "filename": "TEST_DIR/PID-t.vmdk", "size": 0}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-add", "arguments": {"driver": "file", "filename": "T= EST_DIR/PID-t.vmdk", "node_name": "imgfile"}} +{"return": {}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "file": "imgfile", "size": 5368709120}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 5.0G (5368709120 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: monolithicSparse + extents: + [0]: + virtual size: 5368709120 + filename: TEST_IMG + cluster size: 65536 + format:=20 + +=3D=3D=3D Successful image creation (inline blockdev-add, explicit default= s) =3D=3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "file", "filename": "TEST_DIR/PID-t.vmdk", "size": 0}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "ide", "driver": "vmdk", "extents": [], "file": {"driver":= "file", "filename": "TEST_DIR/PID-t.vmdk"}, "hwversion": "4", "size": 6710= 8864, "subformat": "monolithicSparse", "zeroed-grain": false}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 64M (67108864 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: monolithicSparse + extents: + [0]: + virtual size: 67108864 + filename: TEST_IMG + cluster size: 65536 + format:=20 + +=3D=3D=3D Successful image creation (with non-default options) =3D=3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "file", "filename": "TEST_DIR/PID-t.vmdk", "size": 0}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "buslogic", "driver": "vmdk", "extents": [], "file": {"dri= ver": "file", "filename": "TEST_DIR/PID-t.vmdk"}, "size": 33554432, "subfor= mat": "monolithicSparse", "zeroed-grain": true}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 32M (33554432 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: monolithicSparse + extents: + [0]: + virtual size: 33554432 + filename: TEST_IMG + cluster size: 65536 + format:=20 + +=3D=3D=3D Invalid BlockdevRef =3D=3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "file": "this doesn't exist", "size": 33554432}}} +{"return": {}} +Job failed: Cannot find device=3Dthis doesn't exist nor node_name=3Dthis d= oesn't exist +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +=3D=3D=3D Adapter types =3D=3D=3D + +=3D=3D Valid adapter types =3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "ide", "driver": "vmdk", "file": "node0", "size": 33554432= }}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "buslogic", "driver": "vmdk", "file": "node0", "size": 335= 54432}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "lsilogic", "driver": "vmdk", "file": "node0", "size": 335= 54432}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "legacyESX", "driver": "vmdk", "file": "node0", "size": 33= 554432}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +=3D=3D Invalid adapter types =3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "foo", "driver": "vmdk", "file": "node0", "size": 33554432= }}} +{"error": {"class": "GenericError", "desc": "Invalid parameter 'foo'"}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "IDE", "driver": "vmdk", "file": "node0", "size": 33554432= }}} +{"error": {"class": "GenericError", "desc": "Invalid parameter 'IDE'"}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": "legacyesx", "driver": "vmdk", "file": "node0", "size": 33= 554432}}} +{"error": {"class": "GenericError", "desc": "Invalid parameter 'legacyesx'= "}} + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"adapter-type": 1, "driver": "vmdk", "file": "node0", "size": 33554432}}} +{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'o= ptions.adapter-type', expected: string"}} + +=3D=3D=3D Other subformats =3D=3D=3D + +Formatting 'TEST_DIR/PID-t.vmdk.1', fmt=3Dvmdk size=3D0 compat6=3Doff hwve= rsion=3Dundefined + +Formatting 'TEST_DIR/PID-t.vmdk.2', fmt=3Dvmdk size=3D0 compat6=3Doff hwve= rsion=3Dundefined + +Formatting 'TEST_DIR/PID-t.vmdk.3', fmt=3Dvmdk size=3D0 compat6=3Doff hwve= rsion=3Dundefined + +=3D=3D Missing extent =3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "file": "node0", "size": 33554432, "subformat": "monolit= hicFlat"}}} +{"return": {}} +Job failed: Extent [0] not specified +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +=3D=3D Correct extent =3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 33554432, = "subformat": "monolithicFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +=3D=3D Extra extent =3D=3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "monolithicFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +=3D=3D Split formats =3D=3D + +=3D twoGbMaxExtentFlat 512 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 512 (512 bytes) +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentFlat + extents: + [0]: + virtual size: 512 + filename: TEST_IMG.1 + format: FLAT + +=3D twoGbMaxExtentSparse 512 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentSparse"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 512 (512 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentSparse + extents: + [0]: + virtual size: 512 + filename: TEST_IMG.1 + cluster size: 65536 + format: SPARSE + +=3D twoGbMaxExtentFlat 1073741824 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 1.0G (1073741824 bytes) +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentFlat + extents: + [0]: + virtual size: 1073741824 + filename: TEST_IMG.1 + format: FLAT + +=3D twoGbMaxExtentSparse 1073741824 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentSparse"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 1.0G (1073741824 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentSparse + extents: + [0]: + virtual size: 1073741824 + filename: TEST_IMG.1 + cluster size: 65536 + format: SPARSE + +=3D twoGbMaxExtentFlat 2147483648 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 2.0G (2147483648 bytes) +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentFlat + extents: + [0]: + virtual size: 2147483648 + filename: TEST_IMG.1 + format: FLAT + +=3D twoGbMaxExtentSparse 2147483648 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentSparse"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 2.0G (2147483648 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentSparse + extents: + [0]: + virtual size: 2147483648 + filename: TEST_IMG.1 + cluster size: 65536 + format: SPARSE + +=3D twoGbMaxExtentFlat 5368709120 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 5368709120, "subformat": "twoGbMaxExtentFlat"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 5.0G (5368709120 bytes) +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentFlat + extents: + [0]: + virtual size: 2147483648 + filename: TEST_IMG.1 + format: FLAT + [1]: + virtual size: 2147483648 + filename: TEST_IMG.2 + format: FLAT + [2]: + virtual size: 1073741824 + filename: TEST_IMG.3 + format: FLAT + +=3D twoGbMaxExtentSparse 5368709120 =3D + +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 5368709120, "subformat": "twoGbMaxExtentSparse"}}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} + +image: TEST_IMG +file format: IMGFMT +virtual size: 5.0G (5368709120 bytes) +cluster_size: 65536 +Format specific information: + cid: XXXXXXXXXX + parent cid: XXXXXXXXXX + create type: twoGbMaxExtentSparse + extents: + [0]: + virtual size: 2147483648 + filename: TEST_IMG.1 + cluster size: 65536 + format: SPARSE + [1]: + virtual size: 2147483648 + filename: TEST_IMG.2 + cluster size: 65536 + format: SPARSE + [2]: + virtual size: 1073741824 + filename: TEST_IMG.3 + cluster size: 65536 + format: SPARSE + diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 3e310c7f87..c87400f497 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -234,5 +234,6 @@ 234 auto quick migration 235 auto quick 236 auto quick +237 rw auto quick 238 auto quick 239 rw auto quick --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15490402464791010.0122285526912; Fri, 1 Feb 2019 08:57:26 -0800 (PST) Received: from localhost ([127.0.0.1]:58045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc83-0007XR-1s for importer@patchew.org; Fri, 01 Feb 2019 11:57:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbno-0007Qs-D3 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbng-0008Hf-Un for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnT-00087q-Gj; Fri, 01 Feb 2019 11:36:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 899F37AE95; Fri, 1 Feb 2019 16:35:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 536F5608C6; Fri, 1 Feb 2019 16:35:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:03 +0100 Message-Id: <20190201163518.31157-13-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/27] vmdk: Reject excess extents in blockdev-create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" Clarify that the number of extents provided in BlockdevCreateOptionsVmdk must match the number of extents that will actually be used. Providing more extents will result in an error now. This requires adapting the test case to provide the right number of extents. Signed-off-by: Kevin Wolf Reviewed-by: Markus Armbruster --- qapi/block-core.json | 3 ++- block/vmdk.c | 29 ++++++++++++++++++++++++----- tests/qemu-iotests/237 | 6 +++++- tests/qemu-iotests/237.out | 13 +++++++------ 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index a5924b40af..5f17d67d71 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4184,7 +4184,8 @@ # twoGbMaxExtentSparse and twoGbMaxExtentFlat formats. For # monolithicFlat, only one entry is required; for # twoGbMaxExtent* formats, the number of entries required is -# calculated as extent_number =3D virtual_size / 2GB. +# calculated as extent_number =3D virtual_size / 2GB. Provid= ing +# more extents than will be used is an error. # @subformat The subformat of the VMDK image. Default: "monolithicSpars= e". # @backing-file The path of backing file. Default: no backing file is used. # @adapter-type The adapter type used to fill in the descriptor. Default: = ide. diff --git a/block/vmdk.c b/block/vmdk.c index 5a162ee85c..682ad93aa1 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1970,6 +1970,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t siz= e, { int extent_idx; BlockBackend *blk =3D NULL; + BlockBackend *extent_blk; Error *local_err =3D NULL; char *desc =3D NULL; int ret =3D 0; @@ -2107,7 +2108,6 @@ static int coroutine_fn vmdk_co_do_create(int64_t siz= e, } extent_idx =3D 1; while (created_size < size) { - BlockBackend *extent_blk; int64_t cur_size =3D MIN(size - created_size, extent_size); extent_blk =3D extent_fn(cur_size, extent_idx, flat, split, compre= ss, zeroed_grain, opaque, errp); @@ -2121,6 +2121,17 @@ static int coroutine_fn vmdk_co_do_create(int64_t si= ze, extent_idx++; blk_unref(extent_blk); } + + /* Check whether we got excess extents */ + extent_blk =3D extent_fn(-1, extent_idx, flat, split, compress, zeroed= _grain, + opaque, NULL); + if (extent_blk) { + blk_unref(extent_blk); + error_setg(errp, "List of extents contains unused extents"); + ret =3D -EINVAL; + goto exit; + } + /* generate descriptor file */ desc =3D g_strdup_printf(desc_template, g_random_int(), @@ -2181,6 +2192,12 @@ static BlockBackend *vmdk_co_create_opts_cb(int64_t = size, int idx, char *ext_filename =3D NULL; char *rel_filename =3D NULL; =20 + /* We're done, don't create excess extents. */ + if (size =3D=3D -1) { + assert(errp =3D=3D NULL); + return NULL; + } + if (idx =3D=3D 0) { rel_filename =3D g_strdup_printf("%s%s", data->prefix, data->postf= ix); } else if (split) { @@ -2342,10 +2359,12 @@ static BlockBackend *vmdk_co_create_cb(int64_t size= , int idx, blk_set_allow_write_beyond_eof(blk, true); bdrv_unref(bs); =20 - ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp= ); - if (ret) { - blk_unref(blk); - blk =3D NULL; + if (size !=3D -1) { + ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, = errp); + if (ret) { + blk_unref(blk); + blk =3D NULL; + } } return blk; } diff --git a/tests/qemu-iotests/237 b/tests/qemu-iotests/237 index e04a1ac6be..251771d7fb 100755 --- a/tests/qemu-iotests/237 +++ b/tests/qemu-iotests/237 @@ -20,6 +20,7 @@ # along with this program. If not, see . # =20 +import math import iotests from iotests import imgfmt =20 @@ -222,12 +223,15 @@ with iotests.FilePath('t.vmdk') as disk_path, \ iotests.log("=3D %s %d =3D" % (subfmt, size)) iotests.log("") =20 + num_extents =3D math.ceil(size / 2.0**31) + extents =3D [ "ext%d" % (i) for i in range(1, num_extents + 1)= ] + vm.launch() blockdev_create(vm, { 'driver': imgfmt, 'file': 'node0', 'size': size, 'subformat': subfmt, - 'extents': ['ext1', 'ext2', 'ext3'] }) + 'extents': extents }) vm.shutdown() =20 iotests.img_info_log(disk_path) diff --git a/tests/qemu-iotests/237.out b/tests/qemu-iotests/237.out index 1aa9aad349..241c864369 100644 --- a/tests/qemu-iotests/237.out +++ b/tests/qemu-iotests/237.out @@ -154,6 +154,7 @@ Job failed: Extent [0] not specified =20 {"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "monolithicFlat"}}} {"return": {}} +Job failed: List of extents contains unused extents {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 @@ -161,7 +162,7 @@ Job failed: Extent [0] not specified =20 =3D twoGbMaxExtentFlat 512 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subf= ormat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -181,7 +182,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 512 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 512, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 512, "subf= ormat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -203,7 +204,7 @@ Format specific information: =20 =3D twoGbMaxExtentFlat 1073741824 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 1073741824= , "subformat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -223,7 +224,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 1073741824 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 1073741824, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 1073741824= , "subformat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -245,7 +246,7 @@ Format specific information: =20 =3D twoGbMaxExtentFlat 2147483648 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentFlat"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 2147483648= , "subformat": "twoGbMaxExtentFlat"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} @@ -265,7 +266,7 @@ Format specific information: =20 =3D twoGbMaxExtentSparse 2147483648 =3D =20 -{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1", "ext2", "ext3"], "file": "node0", "s= ize": 2147483648, "subformat": "twoGbMaxExtentSparse"}}} +{"execute": "blockdev-create", "arguments": {"job_id": "job0", "options": = {"driver": "vmdk", "extents": ["ext1"], "file": "node0", "size": 2147483648= , "subformat": "twoGbMaxExtentSparse"}}} {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040572875611.5880863720711; Fri, 1 Feb 2019 09:02:52 -0800 (PST) Received: from localhost ([127.0.0.1]:58141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcDE-0003LH-Gq for importer@patchew.org; Fri, 01 Feb 2019 12:02:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbo5-0007nC-Q7 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbo3-0008W9-Le for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37631) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnt-000884-4F; Fri, 01 Feb 2019 11:36:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4B1C796E0; Fri, 1 Feb 2019 16:35:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2505608C8; Fri, 1 Feb 2019 16:35:49 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:04 +0100 Message-Id: <20190201163518.31157-14-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/27] block/vpc: Don't take address of fields in packed structs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Peter Maydell Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the bug by generating the UUID into a local variable which is definitely safely aligned and then copying it into place. Signed-off-by: Peter Maydell Signed-off-by: Kevin Wolf --- block/vpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/vpc.c b/block/vpc.c index d886465b7e..52ab717642 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -979,6 +979,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOpt= ions *opts, int64_t total_size; int disk_type; int ret =3D -EIO; + QemuUUID uuid; =20 assert(opts->driver =3D=3D BLOCKDEV_DRIVER_VPC); vpc_opts =3D &opts->u.vpc; @@ -1062,7 +1063,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, =20 footer->type =3D cpu_to_be32(disk_type); =20 - qemu_uuid_generate(&footer->uuid); + qemu_uuid_generate(&uuid); + footer->uuid =3D uuid; =20 footer->checksum =3D cpu_to_be32(vpc_checksum(buf, HEADER_SIZE)); =20 --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040456212578.7632874173809; Fri, 1 Feb 2019 09:00:56 -0800 (PST) Received: from localhost ([127.0.0.1]:58089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcBO-0001sI-5C for importer@patchew.org; Fri, 01 Feb 2019 12:00:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboN-00084I-S0 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboK-0000IR-Dq for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40388) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-00088L-4i; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32A3FA329C; Fri, 1 Feb 2019 16:35:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E037608C6; Fri, 1 Feb 2019 16:35:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:05 +0100 Message-Id: <20190201163518.31157-15-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 01 Feb 2019 16:35:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/27] block/vdi: Don't take address of fields in packed structs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Peter Maydell Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Instead of passing UUID related functions the address of a possibly unaligned QemuUUID struct, use local variables and then copy to/from the struct field as appropriate. Signed-off-by: Peter Maydell Signed-off-by: Kevin Wolf --- block/vdi.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 2380daa583..4cc726047c 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -235,7 +235,8 @@ static void vdi_header_to_le(VdiHeader *header) =20 static void vdi_header_print(VdiHeader *header) { - char uuid[37]; + char uuidstr[37]; + QemuUUID uuid; logout("text %s", header->text); logout("signature 0x%08x\n", header->signature); logout("header size 0x%04x\n", header->header_size); @@ -254,14 +255,18 @@ static void vdi_header_print(VdiHeader *header) logout("block extra 0x%04x\n", header->block_extra); logout("blocks tot. 0x%04x\n", header->blocks_in_image); logout("blocks all. 0x%04x\n", header->blocks_allocated); - qemu_uuid_unparse(&header->uuid_image, uuid); - logout("uuid image %s\n", uuid); - qemu_uuid_unparse(&header->uuid_last_snap, uuid); - logout("uuid snap %s\n", uuid); - qemu_uuid_unparse(&header->uuid_link, uuid); - logout("uuid link %s\n", uuid); - qemu_uuid_unparse(&header->uuid_parent, uuid); - logout("uuid parent %s\n", uuid); + uuid =3D header->uuid_image; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid image %s\n", uuidstr); + uuid =3D header->uuid_last_snap; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid snap %s\n", uuidstr); + uuid =3D header->uuid_link; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid link %s\n", uuidstr); + uuid =3D header->uuid_parent; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid parent %s\n", uuidstr); } =20 static int coroutine_fn vdi_co_check(BlockDriverState *bs, BdrvCheckResult= *res, @@ -368,6 +373,7 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, size_t bmap_size; int ret; Error *local_err =3D NULL; + QemuUUID uuid_link, uuid_parent; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -395,6 +401,9 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, goto fail; } =20 + uuid_link =3D header.uuid_link; + uuid_parent =3D header.uuid_parent; + if (header.disk_size % SECTOR_SIZE !=3D 0) { /* 'VBoxManage convertfromraw' can create images with odd disk siz= es. We accept them but round the disk size to the next multiple of @@ -444,11 +453,11 @@ static int vdi_open(BlockDriverState *bs, QDict *opti= ons, int flags, (uint64_t)header.blocks_in_image * header.block_size); ret =3D -ENOTSUP; goto fail; - } else if (!qemu_uuid_is_null(&header.uuid_link)) { + } else if (!qemu_uuid_is_null(&uuid_link)) { error_setg(errp, "unsupported VDI image (non-NULL link UUID)"); ret =3D -ENOTSUP; goto fail; - } else if (!qemu_uuid_is_null(&header.uuid_parent)) { + } else if (!qemu_uuid_is_null(&uuid_parent)) { error_setg(errp, "unsupported VDI image (non-NULL parent UUID)"); ret =3D -ENOTSUP; goto fail; @@ -733,6 +742,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreate= Options *create_options, BlockDriverState *bs_file =3D NULL; BlockBackend *blk =3D NULL; uint32_t *bmap =3D NULL; + QemuUUID uuid; =20 assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_VDI); vdi_opts =3D &create_options->u.vdi; @@ -819,8 +829,10 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreat= eOptions *create_options, if (image_type =3D=3D VDI_TYPE_STATIC) { header.blocks_allocated =3D blocks; } - qemu_uuid_generate(&header.uuid_image); - qemu_uuid_generate(&header.uuid_last_snap); + qemu_uuid_generate(&uuid); + header.uuid_image =3D uuid; + qemu_uuid_generate(&uuid); + header.uuid_last_snap =3D uuid; /* There is no need to set header.uuid_link or header.uuid_parent here= . */ if (VDI_DEBUG) { vdi_header_print(&header); --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041264017141.7510661299848; Fri, 1 Feb 2019 09:14:24 -0800 (PST) Received: from localhost ([127.0.0.1]:58393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcOM-0004yW-Qy for importer@patchew.org; Fri, 01 Feb 2019 12:14:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboG-0007wW-IZ for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboB-0000Cy-St for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo3-000892-Qn; Fri, 01 Feb 2019 11:36:45 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB8D042BDA; Fri, 1 Feb 2019 16:35:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B264608C6; Fri, 1 Feb 2019 16:35:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:06 +0100 Message-Id: <20190201163518.31157-16-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Feb 2019 16:35:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a QemuUUID X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Peter Maydell Currently qemu_uuid_bswap() takes a pointer to the QemuUUID to be byte-swapped. This means it can't be used when the UUID to be swapped is in a packed member of a struct. It's also out of line with the general bswap*() functions we provide in bswap.h, which take the value to be swapped and return it. Make qemu_uuid_bswap() take a QemuUUID and return the swapped version. This fixes some clang warnings about taking the address of a packed struct member in block/vdi.c. Signed-off-by: Peter Maydell Reviewed-by: Michael S. Tsirkin Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Kevin Wolf --- include/qemu/uuid.h | 2 +- block/vdi.c | 16 ++++++++-------- hw/acpi/vmgenid.c | 6 ++---- tests/vmgenid-test.c | 2 +- util/uuid.c | 10 +++++----- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h index 09489ce5c5..037357d990 100644 --- a/include/qemu/uuid.h +++ b/include/qemu/uuid.h @@ -56,6 +56,6 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid); =20 int qemu_uuid_parse(const char *str, QemuUUID *uuid); =20 -void qemu_uuid_bswap(QemuUUID *uuid); +QemuUUID qemu_uuid_bswap(QemuUUID uuid); =20 #endif diff --git a/block/vdi.c b/block/vdi.c index 4cc726047c..0c34f6bae4 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -203,10 +203,10 @@ static void vdi_header_to_cpu(VdiHeader *header) header->block_extra =3D le32_to_cpu(header->block_extra); header->blocks_in_image =3D le32_to_cpu(header->blocks_in_image); header->blocks_allocated =3D le32_to_cpu(header->blocks_allocated); - qemu_uuid_bswap(&header->uuid_image); - qemu_uuid_bswap(&header->uuid_last_snap); - qemu_uuid_bswap(&header->uuid_link); - qemu_uuid_bswap(&header->uuid_parent); + header->uuid_image =3D qemu_uuid_bswap(header->uuid_image); + header->uuid_last_snap =3D qemu_uuid_bswap(header->uuid_last_snap); + header->uuid_link =3D qemu_uuid_bswap(header->uuid_link); + header->uuid_parent =3D qemu_uuid_bswap(header->uuid_parent); } =20 static void vdi_header_to_le(VdiHeader *header) @@ -227,10 +227,10 @@ static void vdi_header_to_le(VdiHeader *header) header->block_extra =3D cpu_to_le32(header->block_extra); header->blocks_in_image =3D cpu_to_le32(header->blocks_in_image); header->blocks_allocated =3D cpu_to_le32(header->blocks_allocated); - qemu_uuid_bswap(&header->uuid_image); - qemu_uuid_bswap(&header->uuid_last_snap); - qemu_uuid_bswap(&header->uuid_link); - qemu_uuid_bswap(&header->uuid_parent); + header->uuid_image =3D qemu_uuid_bswap(header->uuid_image); + header->uuid_last_snap =3D qemu_uuid_bswap(header->uuid_last_snap); + header->uuid_link =3D qemu_uuid_bswap(header->uuid_link); + header->uuid_parent =3D qemu_uuid_bswap(header->uuid_parent); } =20 static void vdi_header_print(VdiHeader *header) diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index d78b579a20..02717a8b0d 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -30,8 +30,7 @@ void vmgenid_build_acpi(VmGenIdState *vms, GArray *table_= data, GArray *guid, * first, since that's what the guest expects */ g_array_set_size(guid, VMGENID_FW_CFG_SIZE - ARRAY_SIZE(guid_le.data)); - guid_le =3D vms->guid; - qemu_uuid_bswap(&guid_le); + guid_le =3D qemu_uuid_bswap(vms->guid); /* The GUID is written at a fixed offset into the fw_cfg file * in order to implement the "OVMF SDT Header probe suppressor" * see docs/specs/vmgenid.txt for more details @@ -149,8 +148,7 @@ static void vmgenid_update_guest(VmGenIdState *vms) * however, will expect the fields to be little-endian. * Perform a byte swap immediately before writing. */ - guid_le =3D vms->guid; - qemu_uuid_bswap(&guid_le); + guid_le =3D qemu_uuid_bswap(vms->guid); /* The GUID is written at a fixed offset into the fw_cfg file * in order to implement the "OVMF SDT Header probe suppressor" * see docs/specs/vmgenid.txt for more details. diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 52cdd83ec0..ae38ee5ac0 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -88,7 +88,7 @@ static void read_guid_from_memory(QTestState *qts, QemuUU= ID *guid) /* The GUID is in little-endian format in the guest, while QEMU * uses big-endian. Swap after reading. */ - qemu_uuid_bswap(guid); + *guid =3D qemu_uuid_bswap(*guid); } =20 static void read_guid_from_monitor(QTestState *qts, QemuUUID *guid) diff --git a/util/uuid.c b/util/uuid.c index ebf06c049a..5787f0978c 100644 --- a/util/uuid.c +++ b/util/uuid.c @@ -110,10 +110,10 @@ int qemu_uuid_parse(const char *str, QemuUUID *uuid) =20 /* Swap from UUID format endian (BE) to the opposite or vice versa. */ -void qemu_uuid_bswap(QemuUUID *uuid) +QemuUUID qemu_uuid_bswap(QemuUUID uuid) { - assert(QEMU_PTR_IS_ALIGNED(uuid, sizeof(uint32_t))); - bswap32s(&uuid->fields.time_low); - bswap16s(&uuid->fields.time_mid); - bswap16s(&uuid->fields.time_high_and_version); + bswap32s(&uuid.fields.time_low); + bswap16s(&uuid.fields.time_mid); + bswap16s(&uuid.fields.time_high_and_version); + return uuid; } --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549039638794671.5534481673731; Fri, 1 Feb 2019 08:47:18 -0800 (PST) Received: from localhost ([127.0.0.1]:57849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbyF-00082K-OI for importer@patchew.org; Fri, 01 Feb 2019 11:47:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnz-0007eP-KB for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnu-0008Q5-0X for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43180) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnX-00089R-GJ; Fri, 01 Feb 2019 11:36:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 061723F21B; Fri, 1 Feb 2019 16:35:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBF51608C6; Fri, 1 Feb 2019 16:35:53 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:07 +0100 Message-Id: <20190201163518.31157-17-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Feb 2019 16:35:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/27] block: Apply auto-read-only for ro-whitelist drivers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" If QEMU was configured with a driver in --block-drv-ro-whitelist, trying to use that driver read-write resulted in an error message even if auto-read-only=3Don was set. Consider auto-read-only=3Don for the whitelist checking and use it to automatically degrade to read-only for block drivers on the read-only whitelist. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 0c5d1f11a5..5a4d27173e 100644 --- a/block.c +++ b/block.c @@ -1438,13 +1438,19 @@ static int bdrv_open_common(BlockDriverState *bs, B= lockBackend *file, bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { - error_setg(errp, - !bs->read_only && bdrv_is_whitelisted(drv, true) - ? "Driver '%s' can only be used for read-only devi= ces" - : "Driver '%s' is not whitelisted", - drv->format_name); - ret =3D -ENOTSUP; - goto fail_opts; + if (!bs->read_only && bdrv_is_whitelisted(drv, true)) { + ret =3D bdrv_apply_auto_read_only(bs, NULL, NULL); + } else { + ret =3D -ENOTSUP; + } + if (ret < 0) { + error_setg(errp, + !bs->read_only && bdrv_is_whitelisted(drv, true) + ? "Driver '%s' can only be used for read-only devic= es" + : "Driver '%s' is not whitelisted", + drv->format_name); + goto fail_opts; + } } =20 /* bdrv_new() and bdrv_close() make it so */ --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549039852859506.4071720561835; Fri, 1 Feb 2019 08:50:52 -0800 (PST) Received: from localhost ([127.0.0.1]:57919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc1h-0002CN-Nw for importer@patchew.org; Fri, 01 Feb 2019 11:50:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnz-0007ed-Q7 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbnx-0008Rb-PD for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnX-00089m-Fb; Fri, 01 Feb 2019 11:36:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66D2F81F10; Fri, 1 Feb 2019 16:35:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48962608C6; Fri, 1 Feb 2019 16:35:55 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:08 +0100 Message-Id: <20190201163518.31157-18-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 17/27] block: Remove blk_attach_dev_legacy() / legacy_dev code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Thomas Huth The last user of blk_attach_dev_legacy() was the code in xen_disk which has recently been reworked. Now there is no user for this legacy function anymore. Thus we can finally remove all code related to the "legacy_dev" flag, too, and turn the related "void *" in block-backend.c into proper "DeviceState *" to fix some of the remaining TODOs there. Signed-off-by: Thomas Huth Reviewed-by: Stefano Garzarella Signed-off-by: Kevin Wolf --- include/sysemu/block-backend.h | 5 ++-- block/block-backend.c | 54 ++++++---------------------------- 2 files changed, 11 insertions(+), 48 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index c8f816a200..832a4bf168 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -110,9 +110,8 @@ void blk_iostatus_disable(BlockBackend *blk); void blk_iostatus_reset(BlockBackend *blk); void blk_iostatus_set_err(BlockBackend *blk, int error); int blk_attach_dev(BlockBackend *blk, DeviceState *dev); -void blk_attach_dev_legacy(BlockBackend *blk, void *dev); -void blk_detach_dev(BlockBackend *blk, void *dev); -void *blk_get_attached_dev(BlockBackend *blk); +void blk_detach_dev(BlockBackend *blk, DeviceState *dev); +DeviceState *blk_get_attached_dev(BlockBackend *blk); char *blk_get_attached_dev_id(BlockBackend *blk); BlockBackend *blk_by_dev(void *dev); BlockBackend *blk_by_qdev_id(const char *id, Error **errp); diff --git a/block/block-backend.c b/block/block-backend.c index f0be0d9039..f6ea824308 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -47,9 +47,7 @@ struct BlockBackend { QTAILQ_ENTRY(BlockBackend) monitor_link; /* for monitor_block_backends= */ BlockBackendPublic public; =20 - void *dev; /* attached device model, if any */ - bool legacy_dev; /* true if dev is not a DeviceState */ - /* TODO change to DeviceState when all users are qdevified */ + DeviceState *dev; /* attached device model, if any */ const BlockDevOps *dev_ops; void *dev_opaque; =20 @@ -836,7 +834,11 @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, u= int64_t *shared_perm) *shared_perm =3D blk->shared_perm; } =20 -static int blk_do_attach_dev(BlockBackend *blk, void *dev) +/* + * Attach device model @dev to @blk. + * Return 0 on success, -EBUSY when a device model is attached already. + */ +int blk_attach_dev(BlockBackend *blk, DeviceState *dev) { if (blk->dev) { return -EBUSY; @@ -851,40 +853,16 @@ static int blk_do_attach_dev(BlockBackend *blk, void = *dev) =20 blk_ref(blk); blk->dev =3D dev; - blk->legacy_dev =3D false; blk_iostatus_reset(blk); =20 return 0; } =20 -/* - * Attach device model @dev to @blk. - * Return 0 on success, -EBUSY when a device model is attached already. - */ -int blk_attach_dev(BlockBackend *blk, DeviceState *dev) -{ - return blk_do_attach_dev(blk, dev); -} - -/* - * Attach device model @dev to @blk. - * @blk must not have a device model attached already. - * TODO qdevified devices don't use this, remove when devices are qdevified - */ -void blk_attach_dev_legacy(BlockBackend *blk, void *dev) -{ - if (blk_do_attach_dev(blk, dev) < 0) { - abort(); - } - blk->legacy_dev =3D true; -} - /* * Detach device model @dev from @blk. * @dev must be currently attached to @blk. */ -void blk_detach_dev(BlockBackend *blk, void *dev) -/* TODO change to DeviceState *dev when all users are qdevified */ +void blk_detach_dev(BlockBackend *blk, DeviceState *dev) { assert(blk->dev =3D=3D dev); blk->dev =3D NULL; @@ -898,8 +876,7 @@ void blk_detach_dev(BlockBackend *blk, void *dev) /* * Return the device model attached to @blk if any, else null. */ -void *blk_get_attached_dev(BlockBackend *blk) -/* TODO change to return DeviceState * when all users are qdevified */ +DeviceState *blk_get_attached_dev(BlockBackend *blk) { return blk->dev; } @@ -908,10 +885,7 @@ void *blk_get_attached_dev(BlockBackend *blk) * device attached to the BlockBackend. */ char *blk_get_attached_dev_id(BlockBackend *blk) { - DeviceState *dev; - - assert(!blk->legacy_dev); - dev =3D blk->dev; + DeviceState *dev =3D blk->dev; =20 if (!dev) { return g_strdup(""); @@ -949,11 +923,6 @@ BlockBackend *blk_by_dev(void *dev) void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque) { - /* All drivers that use blk_set_dev_ops() are qdevified and we want to= keep - * it that way, so we can assume blk->dev, if present, is a DeviceStat= e if - * blk->dev_ops is set. Non-device users may use dev_ops without devic= e. */ - assert(!blk->legacy_dev); - blk->dev_ops =3D ops; blk->dev_opaque =3D opaque; =20 @@ -979,8 +948,6 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool lo= ad, Error **errp) bool tray_was_open, tray_is_open; Error *local_err =3D NULL; =20 - assert(!blk->legacy_dev); - tray_was_open =3D blk_dev_is_tray_open(blk); blk->dev_ops->change_media_cb(blk->dev_opaque, load, &local_err); if (local_err) { @@ -1783,9 +1750,6 @@ void blk_eject(BlockBackend *blk, bool eject_flag) BlockDriverState *bs =3D blk_bs(blk); char *id; =20 - /* blk_eject is only called by qdevified devices */ - assert(!blk->legacy_dev); - if (bs) { bdrv_eject(bs, eject_flag); } --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040663063933.3676889156309; Fri, 1 Feb 2019 09:04:23 -0800 (PST) Received: from localhost ([127.0.0.1]:58147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcEi-0004UC-SD for importer@patchew.org; Fri, 01 Feb 2019 12:04:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboN-00084N-SD for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboK-0000IG-DV for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-0008Af-7E; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4571796F2; Fri, 1 Feb 2019 16:35:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id A98D2608C6; Fri, 1 Feb 2019 16:35:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:09 +0100 Message-Id: <20190201163518.31157-19-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:35:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/27] block: Eliminate the S_1KiB, S_2KiB, ... macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Markus Armbruster We define 54 macros for the powers of two >=3D 1024. We use six, in six macro definitions. Four of them could just as well use the common MiB macro, so do that. The remaining two can't, because they get passed to stringify. Replace the macro by the literal number there. Slightly harder to read in one instance (1048576 vs. S_1MiB), so add a comment there. The other instance is a wash: 65536 vs S_64KiB. 65536 has been good enough for more than seven years there. This effectively reverts commit 540b8492618 and 1240ac558d3. Signed-off-by: Markus Armbruster Reviewed-by: Alberto Garcia Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2.h | 10 +++--- include/qemu/units.h | 73 -------------------------------------------- block/vdi.c | 3 +- 3 files changed, 7 insertions(+), 79 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 438a1dee9e..32cce9eee2 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -50,11 +50,11 @@ =20 /* 8 MB refcount table is enough for 2 PB images at 64k cluster size * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */ -#define QCOW_MAX_REFTABLE_SIZE S_8MiB +#define QCOW_MAX_REFTABLE_SIZE (8 * MiB) =20 /* 32 MB L1 table is enough for 2 PB images at 64k cluster size * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */ -#define QCOW_MAX_L1_SIZE S_32MiB +#define QCOW_MAX_L1_SIZE (32 * MiB) =20 /* Allow for an average of 1k per snapshot table entry, should be plenty of * space for snapshot names and IDs */ @@ -81,15 +81,15 @@ #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */ =20 #ifdef CONFIG_LINUX -#define DEFAULT_L2_CACHE_MAX_SIZE S_32MiB +#define DEFAULT_L2_CACHE_MAX_SIZE (32 * MiB) #define DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */ #else -#define DEFAULT_L2_CACHE_MAX_SIZE S_8MiB +#define DEFAULT_L2_CACHE_MAX_SIZE (8 * MiB) /* Cache clean interval is currently available only on Linux, so must be 0= */ #define DEFAULT_CACHE_CLEAN_INTERVAL 0 #endif =20 -#define DEFAULT_CLUSTER_SIZE S_64KiB +#define DEFAULT_CLUSTER_SIZE 65536 =20 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts" #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request" diff --git a/include/qemu/units.h b/include/qemu/units.h index 1c959d182e..692db3fbb2 100644 --- a/include/qemu/units.h +++ b/include/qemu/units.h @@ -17,77 +17,4 @@ #define PiB (INT64_C(1) << 50) #define EiB (INT64_C(1) << 60) =20 -/* - * The following lookup table is intended to be used when a literal string= of - * the number of bytes is required (for example if it needs to be stringif= ied). - * It can also be used for generic shortcuts of power-of-two sizes. - * This table is generated using the AWK script below: - * - * BEGIN { - * suffix=3D"KMGTPE"; - * for(i=3D10; i<64; i++) { - * val=3D2**i; - * s=3Dsubstr(suffix, int(i/10), 1); - * n=3D2**(i%10); - * pad=3D21-int(log(n)/log(10)); - * printf("#define S_%d%siB %*d\n", n, s, pad, val); - * } - * } - */ - -#define S_1KiB 1024 -#define S_2KiB 2048 -#define S_4KiB 4096 -#define S_8KiB 8192 -#define S_16KiB 16384 -#define S_32KiB 32768 -#define S_64KiB 65536 -#define S_128KiB 131072 -#define S_256KiB 262144 -#define S_512KiB 524288 -#define S_1MiB 1048576 -#define S_2MiB 2097152 -#define S_4MiB 4194304 -#define S_8MiB 8388608 -#define S_16MiB 16777216 -#define S_32MiB 33554432 -#define S_64MiB 67108864 -#define S_128MiB 134217728 -#define S_256MiB 268435456 -#define S_512MiB 536870912 -#define S_1GiB 1073741824 -#define S_2GiB 2147483648 -#define S_4GiB 4294967296 -#define S_8GiB 8589934592 -#define S_16GiB 17179869184 -#define S_32GiB 34359738368 -#define S_64GiB 68719476736 -#define S_128GiB 137438953472 -#define S_256GiB 274877906944 -#define S_512GiB 549755813888 -#define S_1TiB 1099511627776 -#define S_2TiB 2199023255552 -#define S_4TiB 4398046511104 -#define S_8TiB 8796093022208 -#define S_16TiB 17592186044416 -#define S_32TiB 35184372088832 -#define S_64TiB 70368744177664 -#define S_128TiB 140737488355328 -#define S_256TiB 281474976710656 -#define S_512TiB 562949953421312 -#define S_1PiB 1125899906842624 -#define S_2PiB 2251799813685248 -#define S_4PiB 4503599627370496 -#define S_8PiB 9007199254740992 -#define S_16PiB 18014398509481984 -#define S_32PiB 36028797018963968 -#define S_64PiB 72057594037927936 -#define S_128PiB 144115188075855872 -#define S_256PiB 288230376151711744 -#define S_512PiB 576460752303423488 -#define S_1EiB 1152921504606846976 -#define S_2EiB 2305843009213693952 -#define S_4EiB 4611686018427387904 -#define S_8EiB 9223372036854775808 - #endif diff --git a/block/vdi.c b/block/vdi.c index 0c34f6bae4..e1c42ad732 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -85,7 +85,8 @@ #define BLOCK_OPT_STATIC "static" =20 #define SECTOR_SIZE 512 -#define DEFAULT_CLUSTER_SIZE S_1MiB +#define DEFAULT_CLUSTER_SIZE 1048576 +/* Note: can't use 1 * MiB, because it's passed to stringify() */ =20 #if defined(CONFIG_VDI_DEBUG) #define VDI_DEBUG 1 --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041693157618.684649101274; Fri, 1 Feb 2019 09:21:33 -0800 (PST) Received: from localhost ([127.0.0.1]:58561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcVL-0002ih-0N for importer@patchew.org; Fri, 01 Feb 2019 12:21:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00085D-5m for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboL-0000Is-LN for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo7-0008B5-PF; Fri, 01 Feb 2019 11:36:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B01B40F30; Fri, 1 Feb 2019 16:35:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 165AB608C6; Fri, 1 Feb 2019 16:35:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:10 +0100 Message-Id: <20190201163518.31157-20-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Feb 2019 16:35:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 19/27] virtio-scsi: Move BlockBackend back to the main AioContext on unplug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia This fixes a crash when attaching a disk to a SCSI device using iothreads, then detaching it and reattaching it again. Test case included. Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- hw/scsi/virtio-scsi.c | 6 +++ tests/qemu-iotests/240 | 89 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/240.out | 18 ++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 114 insertions(+) create mode 100755 tests/qemu-iotests/240 create mode 100644 tests/qemu-iotests/240.out diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 3aa99717e2..e1f7b208c7 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -824,6 +824,12 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotp= lug_dev, DeviceState *dev, virtio_scsi_release(s); } =20 + if (s->ctx) { + virtio_scsi_acquire(s); + blk_set_aio_context(sd->conf.blk, qemu_get_aio_context()); + virtio_scsi_release(s); + } + qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); } =20 diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 new file mode 100755 index 0000000000..ead7ee08eb --- /dev/null +++ b/tests/qemu-iotests/240 @@ -0,0 +1,89 @@ +#!/bin/bash +# +# Test hot plugging and unplugging with iothreads +# +# Copyright (C) 2019 Igalia, S.L. +# Author: Alberto Garcia +# +# 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 . +# + +# creator +owner=3Dberto@igalia.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto generic +_supported_os Linux + +do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +# Remove QMP events from (pretty-printed) output. Doesn't handle +# nested dicts correctly, but we don't get any of those in this test. +_filter_qmp_events() +{ + tr '\n' '\t' | sed -e \ + 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\= ?\s*}\s*//g' \ + | tr '\t' '\n' +} + +run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events +} + +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtio_scsi=3Dvirtio-scsi-ccw + ;; + *) + virtio_scsi=3Dvirtio-scsi-pci + ;; +esac + +echo +echo =3D=3D=3D Unplug a SCSI disk and then plug it again =3D=3D=3D +echo + +run_qemu < Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040641553470.6957551925291; Fri, 1 Feb 2019 09:04:01 -0800 (PST) Received: from localhost ([127.0.0.1]:58145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcEM-0004Ck-Df for importer@patchew.org; Fri, 01 Feb 2019 12:03:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbnu-0007Y4-22 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbns-0008Mc-HA for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbnV-0008EA-Tl; Fri, 01 Feb 2019 11:36:11 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FD8988E5A; Fri, 1 Feb 2019 16:36:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74243608C6; Fri, 1 Feb 2019 16:35:59 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:11 +0100 Message-Id: <20190201163518.31157-21-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:36:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 20/27] scsi-disk: Acquire the AioContext in scsi_*_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia This fixes a crash when attaching two disks with the same blockdev to a SCSI device that is using iothreads. Test case included. Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- hw/scsi/scsi-disk.c | 23 ++++++++++++++++++++--- tests/qemu-iotests/240 | 18 ++++++++++++++++++ tests/qemu-iotests/240.out | 16 ++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 0e9027c8f3..b049026219 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2381,10 +2381,13 @@ static void scsi_realize(SCSIDevice *dev, Error **e= rrp) static void scsi_hd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx =3D NULL; /* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { + ctx =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf); } s->qdev.blocksize =3D s->qdev.conf.logical_block_size; @@ -2393,11 +2396,15 @@ static void scsi_hd_realize(SCSIDevice *dev, Error = **errp) s->product =3D g_strdup("QEMU HARDDISK"); } scsi_realize(&s->qdev, errp); + if (ctx) { + aio_context_release(ctx); + } } =20 static void scsi_cd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int ret; =20 if (!dev->conf.blk) { @@ -2408,6 +2415,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) assert(ret =3D=3D 0); } =20 + ctx =3D blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); s->qdev.blocksize =3D 2048; s->qdev.type =3D TYPE_ROM; s->features |=3D 1 << SCSI_DISK_F_REMOVABLE; @@ -2415,6 +2424,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) s->product =3D g_strdup("QEMU CD-ROM"); } scsi_realize(&s->qdev, errp); + aio_context_release(ctx); } =20 static void scsi_disk_realize(SCSIDevice *dev, Error **errp) @@ -2553,6 +2563,7 @@ static int get_device_type(SCSIDiskState *s) static void scsi_block_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int sg_version; int rc; =20 @@ -2567,6 +2578,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error= **errp) "be removed in a future version"); } =20 + ctx =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); + /* check we are using a driver managing SG_IO (version 3 and after) */ rc =3D blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); if (rc < 0) { @@ -2574,18 +2588,18 @@ static void scsi_block_realize(SCSIDevice *dev, Err= or **errp) if (rc !=3D -EPERM) { error_append_hint(errp, "Is this a SCSI device?\n"); } - return; + goto out; } if (sg_version < 30000) { error_setg(errp, "scsi generic interface too old"); - return; + goto out; } =20 /* get device type from INQUIRY data */ rc =3D get_device_type(s); if (rc < 0) { error_setg(errp, "INQUIRY failed"); - return; + goto out; } =20 /* Make a guess for the block size, we'll fix it when the guest sends. @@ -2605,6 +2619,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error= **errp) =20 scsi_realize(&s->qdev, errp); scsi_generic_read_device_inquiry(&s->qdev); + +out: + aio_context_release(ctx); } =20 typedef struct SCSIBlockReq { diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 index ead7ee08eb..5d499c9a00 100755 --- a/tests/qemu-iotests/240 +++ b/tests/qemu-iotests/240 @@ -83,6 +83,24 @@ run_qemu < Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040959906499.2006566929183; Fri, 1 Feb 2019 09:09:19 -0800 (PST) Received: from localhost ([127.0.0.1]:58232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcJV-00005F-Po for importer@patchew.org; Fri, 01 Feb 2019 12:09:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboE-0007wU-M7 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboA-0000CB-PW for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo0-0008E9-07; Fri, 01 Feb 2019 11:36:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17AE97AEBB; Fri, 1 Feb 2019 16:36:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id D57D7608C6; Fri, 1 Feb 2019 16:36:00 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:12 +0100 Message-Id: <20190201163518.31157-22-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:36:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 21/27] virtio-scsi: Forbid devices with different iothreads sharing a blockdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia This patch forbids attaching a disk to a SCSI device if its using a different AioContext. Test case included. Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- hw/scsi/virtio-scsi.c | 7 +++++++ tests/qemu-iotests/240 | 22 ++++++++++++++++++++++ tests/qemu-iotests/240.out | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index e1f7b208c7..eb90288f47 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -791,9 +791,16 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplu= g_dev, DeviceState *dev, SCSIDevice *sd =3D SCSI_DEVICE(dev); =20 if (s->ctx && !s->dataplane_fenced) { + AioContext *ctx; if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)= ) { return; } + ctx =3D blk_get_aio_context(sd->conf.blk); + if (ctx !=3D s->ctx && ctx !=3D qemu_get_aio_context()) { + error_setg(errp, "Cannot attach a blockdev that is using " + "a different iothread"); + return; + } virtio_scsi_acquire(s); blk_set_aio_context(sd->conf.blk, s->ctx); virtio_scsi_release(s); diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 index 5d499c9a00..65cc3b39b1 100755 --- a/tests/qemu-iotests/240 +++ b/tests/qemu-iotests/240 @@ -101,6 +101,28 @@ run_qemu < Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040887026897.0501729938358; Fri, 1 Feb 2019 09:08:07 -0800 (PST) Received: from localhost ([127.0.0.1]:58223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcIK-0007Ys-Si for importer@patchew.org; Fri, 01 Feb 2019 12:08:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00084C-07 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboK-0000IM-Cw for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-0008Fr-C0; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3D3E88E7A; Fri, 1 Feb 2019 16:36:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40881608C7; Fri, 1 Feb 2019 16:36:02 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:13 +0100 Message-Id: <20190201163518.31157-23-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:36:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 22/27] iotests: Filter second BLOCK_JOB_ERROR from 229 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Max Reitz Without this filter, this test sometimes fails. Signed-off-by: Max Reitz Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- tests/qemu-iotests/229 | 6 +++++- tests/qemu-iotests/229.out | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/229 b/tests/qemu-iotests/229 index 893d098ad2..b0d4885fa6 100755 --- a/tests/qemu-iotests/229 +++ b/tests/qemu-iotests/229 @@ -81,11 +81,15 @@ echo echo '=3D=3D=3D Force cancel job paused in error state =3D=3D=3D' echo =20 +# Filter out BLOCK_JOB_ERROR events because they may or may not occur. +# Cancelling the job means resuming it for a bit before it is actually +# aborted, and in that time it may or may not re-encounter the error. success_or_failure=3D"y" _send_qemu_cmd $QEMU_HANDLE \ "{'execute': 'block-job-cancel', 'arguments': { 'device': 'testdisk', 'force': true}}" \ - "BLOCK_JOB_CANCELLED" "Assertion" + "BLOCK_JOB_CANCELLED" "Assertion" \ + | grep -v '"BLOCK_JOB_ERROR"' =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/229.out b/tests/qemu-iotests/229.out index 4c4112805f..a3eb33788a 100644 --- a/tests/qemu-iotests/229.out +++ b/tests/qemu-iotests/229.out @@ -17,7 +17,6 @@ wrote 2097152/2097152 bytes at offset 0 =20 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "testdisk"}} {"return": {}} -{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_ERROR", "data": {"device": "testdisk", "operation": "write", "= action": "stop"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "testdisk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_JOB_CANCELLED", "data": {"device": "testdisk", "len": 2097152, "of= fset": 1048576, "speed": 0, "type": "mirror"}} *** done --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040761847506.9358571241204; Fri, 1 Feb 2019 09:06:01 -0800 (PST) Received: from localhost ([127.0.0.1]:58195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcGM-0005r1-Mu for importer@patchew.org; Fri, 01 Feb 2019 12:05:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbo5-0007nH-Rw for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbo3-0008WI-Lk for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44064) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbns-0008DJ-Qq; Fri, 01 Feb 2019 11:36:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C75089AE8; Fri, 1 Feb 2019 16:36:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5CFF608C6; Fri, 1 Feb 2019 16:36:04 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:14 +0100 Message-Id: <20190201163518.31157-24-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 01 Feb 2019 16:36:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 23/27] iotests/236: fix transaction kwarg order X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: John Snow It's not enough to order the kwargs for consistent QMP log output, we must also sort any sub-dictionaries in lists that appear as values. Reported-by: Kevin Wolf Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- tests/qemu-iotests/236.out | 56 +++++++++++++++++------------------ tests/qemu-iotests/iotests.py | 21 ++++++------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/tests/qemu-iotests/236.out b/tests/qemu-iotests/236.out index 1dad24db0d..bb2d71ea5e 100644 --- a/tests/qemu-iotests/236.out +++ b/tests/qemu-iotests/236.out @@ -45,23 +45,23 @@ write -P0xcd 0x3ff0000 64k "actions": [ { "data": { - "node": "drive0", - "name": "bitmapB" + "name": "bitmapB", + "node": "drive0" }, "type": "block-dirty-bitmap-disable" }, { "data": { - "node": "drive0", + "granularity": 65536, "name": "bitmapC", - "granularity": 65536 + "node": "drive0" }, "type": "block-dirty-bitmap-add" }, { "data": { - "node": "drive0", - "name": "bitmapA" + "name": "bitmapA", + "node": "drive0" }, "type": "block-dirty-bitmap-clear" }, @@ -105,30 +105,30 @@ write -P0xcd 0x3ff0000 64k "actions": [ { "data": { - "node": "drive0", - "name": "bitmapB" + "name": "bitmapB", + "node": "drive0" }, "type": "block-dirty-bitmap-disable" }, { "data": { - "node": "drive0", + "granularity": 65536, "name": "bitmapC", - "granularity": 65536 + "node": "drive0" }, "type": "block-dirty-bitmap-add" }, { "data": { - "node": "drive0", - "name": "bitmapC" + "name": "bitmapC", + "node": "drive0" }, "type": "block-dirty-bitmap-disable" }, { "data": { - "node": "drive0", - "name": "bitmapC" + "name": "bitmapC", + "node": "drive0" }, "type": "block-dirty-bitmap-enable" } @@ -158,15 +158,15 @@ write -P0xea 0x3fe0000 64k "actions": [ { "data": { - "node": "drive0", - "name": "bitmapA" + "name": "bitmapA", + "node": "drive0" }, "type": "block-dirty-bitmap-disable" }, { "data": { - "node": "drive0", - "name": "bitmapC" + "name": "bitmapC", + "node": "drive0" }, "type": "block-dirty-bitmap-disable" } @@ -209,21 +209,21 @@ write -P0xea 0x3fe0000 64k "actions": [ { "data": { - "node": "drive0", "disabled": true, + "granularity": 65536, "name": "bitmapD", - "granularity": 65536 + "node": "drive0" }, "type": "block-dirty-bitmap-add" }, { "data": { - "node": "drive0", - "target": "bitmapD", "bitmaps": [ "bitmapB", "bitmapC" - ] + ], + "node": "drive0", + "target": "bitmapD" }, "type": "block-dirty-bitmap-merge" }, @@ -273,21 +273,21 @@ write -P0xea 0x3fe0000 64k "actions": [ { "data": { - "node": "drive0", "disabled": true, + "granularity": 65536, "name": "bitmapD", - "granularity": 65536 + "node": "drive0" }, "type": "block-dirty-bitmap-add" }, { "data": { - "node": "drive0", - "target": "bitmapD", "bitmaps": [ "bitmapB", "bitmapC" - ] + ], + "node": "drive0", + "target": "bitmapD" }, "type": "block-dirty-bitmap-merge" } diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 71214d46b5..b461f53abf 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -76,15 +76,16 @@ def qemu_img(*args): sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode,= ' '.join(qemu_img_args + list(args)))) return exitcode =20 -def ordered_kwargs(kwargs): - # kwargs prior to 3.6 are not ordered, so: - od =3D OrderedDict() - for k, v in sorted(kwargs.items()): - if isinstance(v, dict): - od[k] =3D ordered_kwargs(v) - else: - od[k] =3D v - return od +def ordered_qmp(qmsg): + # Dictionaries are not ordered prior to 3.6, therefore: + if isinstance(qmsg, list): + return [ordered_qmp(atom) for atom in qmsg] + if isinstance(qmsg, dict): + od =3D OrderedDict() + for k, v in sorted(qmsg.items()): + od[k] =3D ordered_qmp(v) + return od + return qmsg =20 def qemu_img_create(*args): args =3D list(args) @@ -506,7 +507,7 @@ class VM(qtest.QEMUQtestMachine): def qmp_log(self, cmd, filters=3D[], indent=3DNone, **kwargs): full_cmd =3D OrderedDict(( ("execute", cmd), - ("arguments", ordered_kwargs(kwargs)) + ("arguments", ordered_qmp(kwargs)) )) log(full_cmd, filters, indent=3Dindent) result =3D self.qmp(cmd, **kwargs) --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549040056299781.7270589886322; Fri, 1 Feb 2019 08:54:16 -0800 (PST) Received: from localhost ([127.0.0.1]:57978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpc4z-0004l3-87 for importer@patchew.org; Fri, 01 Feb 2019 11:54:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbo7-0007nk-P1 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbo3-0008WA-Lg for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbns-0008Dh-Gq; Fri, 01 Feb 2019 11:36:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BF35C0C2368; Fri, 1 Feb 2019 16:36:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 515B0608C7; Fri, 1 Feb 2019 16:36:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:15 +0100 Message-Id: <20190201163518.31157-25-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 01 Feb 2019 16:36:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 24/27] block: Fix invalidate_cache error path for parent activation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" bdrv_co_invalidate_cache() clears the BDRV_O_INACTIVE flag before actually activating a node so that the correct permissions etc. are taken. In case of errors, the flag must be restored so that the next call to bdrv_co_invalidate_cache() retries activation. Restoring the flag was missing in the error path for a failed parent->role->activate() call. The consequence is that this attempt to activate all images correctly fails because we still set errp, however on the next attempt BDRV_O_INACTIVE is already clear, so we return success without actually retrying the failed action. An example where this is observable in practice is migration to a QEMU instance that has a raw format block node attached to a guest device with share-rw=3Doff (the default) while another process holds BLK_PERM_WRITE for the same image. In this case, all activation steps before parent->role->activate() succeed because raw can tolerate other writers to the image. Only the parent callback (in particular blk_root_activate()) tries to implement the share-rw=3Don property and requests exclusive write permissions. This fails when the migration completes and correctly displays an error. However, a manual 'cont' will incorrectly resume the VM without calling blk_root_activate() again. This case is described in more detail in the following bug report: https://bugzilla.redhat.com/show_bug.cgi?id=3D1531888 Fix this by correctly restoring the BDRV_O_INACTIVE flag in the error path. Cc: qemu-stable@nongnu.org Signed-off-by: Kevin Wolf Tested-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block.c b/block.c index 5a4d27173e..b67d9b7b65 100644 --- a/block.c +++ b/block.c @@ -4697,6 +4697,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (parent->role->activate) { parent->role->activate(parent, &local_err); if (local_err) { + bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); return; } --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041219395141.29799136542465; Fri, 1 Feb 2019 09:13:39 -0800 (PST) Received: from localhost ([127.0.0.1]:58357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcNh-0004Lz-7Z for importer@patchew.org; Fri, 01 Feb 2019 12:13:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00084A-9y for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboK-0000I6-9y for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49779) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-0008Fp-7f; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBC5E88E76; Fri, 1 Feb 2019 16:36:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0023608C6; Fri, 1 Feb 2019 16:36:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:16 +0100 Message-Id: <20190201163518.31157-26-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:36:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 25/27] qtest.py: Wait for the result of qtest commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia The cmd() method of the QEMUQtestProtocol class sends a qtest command to QEMU but doesn't wait for the return message ("OK", "FAIL", "ERR"). Because of this, it can return control to the caller before the command has actually finished. In cases like clock_step or clock_set this means that cmd() can return before all the timers triggered by the clock change have been fired. This can be fixed by making cmd() wait for the output of the qtest command. This fixes iotests 093 and 136, which are flaky since commit 8258292e18c39480b64eba9f3551 when the machine is under heavy workload. Signed-off-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- scripts/qtest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/qtest.py b/scripts/qtest.py index adf1fe3f26..afac3fe900 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -31,6 +31,7 @@ class QEMUQtestProtocol(object): """ self._address =3D address self._sock =3D self._get_sock() + self._sockfile =3D None if server: self._sock.bind(self._address) self._sock.listen(1) @@ -49,6 +50,7 @@ class QEMUQtestProtocol(object): @raise socket.error on socket connection errors """ self._sock.connect(self._address) + self._sockfile =3D self._sock.makefile() =20 def accept(self): """ @@ -57,6 +59,7 @@ class QEMUQtestProtocol(object): @raise socket.error on socket connection errors """ self._sock, _ =3D self._sock.accept() + self._sockfile =3D self._sock.makefile() =20 def cmd(self, qtest_cmd): """ @@ -65,9 +68,12 @@ class QEMUQtestProtocol(object): @param qtest_cmd: qtest command text to be sent """ self._sock.sendall((qtest_cmd + "\n").encode('utf-8')) + resp =3D self._sockfile.readline() + return resp =20 def close(self): self._sock.close() + self._sockfile.close() =20 def settimeout(self, timeout): self._sock.settimeout(timeout) --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154904084163894.5372726029475; Fri, 1 Feb 2019 09:07:21 -0800 (PST) Received: from localhost ([127.0.0.1]:58211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcHe-00070G-IS for importer@patchew.org; Fri, 01 Feb 2019 12:07:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-00085C-5L for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboL-0000Iv-LL for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1411) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo8-0008Ii-2Q; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 363E08AE44; Fri, 1 Feb 2019 16:36:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CCDB608C6; Fri, 1 Feb 2019 16:36:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:17 +0100 Message-Id: <20190201163518.31157-27-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 16:36:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 26/27] scsi-disk: Don't use empty string as device id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" scsi-disk includes in the Device Identification VPD page, depending on configuration amongst others, a vendor specific designator that consists either of the serial number if given or the BlockBackend name (which is a host detail that better shouldn't have been leaked to the guest, but now we have to maintain it for compatibility). With anonymous BlockBackends, i.e. scsi-disk devices constructed with drive=3D, and no serial number explicitly specified, this ends up as an empty string. If this happens to more than one disk, we have accidentally signalled to the OS that this is a multipath setup, which is obviously not what was intended. Instead of using an empty string for the vendor specific designator, simply leave out that designator, which makes Linux detect such setups as separate disks again. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/scsi/scsi-disk.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index b049026219..11392a8db8 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -652,12 +652,14 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *re= q, uint8_t *outbuf) DPRINTF("Inquiry EVPD[Device identification] " "buffer size %zd\n", req->cmd.xfer); =20 - outbuf[buflen++] =3D 0x2; /* ASCII */ - outbuf[buflen++] =3D 0; /* not officially assigned */ - outbuf[buflen++] =3D 0; /* reserved */ - outbuf[buflen++] =3D id_len; /* length of data following */ - memcpy(outbuf + buflen, str, id_len); - buflen +=3D id_len; + if (id_len) { + outbuf[buflen++] =3D 0x2; /* ASCII */ + outbuf[buflen++] =3D 0; /* not officially assigned */ + outbuf[buflen++] =3D 0; /* reserved */ + outbuf[buflen++] =3D id_len; /* length of data following */ + memcpy(outbuf + buflen, str, id_len); + buflen +=3D id_len; + } =20 if (s->qdev.wwn) { outbuf[buflen++] =3D 0x1; /* Binary */ --=20 2.20.1 From nobody Mon May 6 12:22:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549041055313609.521028682283; Fri, 1 Feb 2019 09:10:55 -0800 (PST) Received: from localhost ([127.0.0.1]:58280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpcL3-0001bN-5c for importer@patchew.org; Fri, 01 Feb 2019 12:10:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboO-000849-2L for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboK-0000I9-A8 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:37:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44176) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpbo7-0008Ft-Qx; Fri, 01 Feb 2019 11:36:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E567806BA; Fri, 1 Feb 2019 16:36:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-95.ams2.redhat.com [10.36.117.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73F5C608C6; Fri, 1 Feb 2019 16:36:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 17:35:18 +0100 Message-Id: <20190201163518.31157-28-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 01 Feb 2019 16:36:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 27/27] scsi-disk: Add device_id property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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" Content-Type: text/plain; charset="utf-8" The new device_id property specifies which value to use for the vendor specific designator in the Device Identification VPD page. In particular, this is necessary for libvirt to maintain guest ABI compatibility when no serial number is given and a VM is switched from -drive (where the BlockBackend name is used) to -blockdev (where the vendor specific designator is left out by default). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- hw/scsi/scsi-disk.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 11392a8db8..e6db6d7c15 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -104,6 +104,7 @@ typedef struct SCSIDiskState char *serial; char *vendor; char *product; + char *device_id; bool tray_open; bool tray_locked; /* @@ -642,13 +643,8 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req= , uint8_t *outbuf) =20 case 0x83: /* Device identification page, mandatory */ { - const char *str =3D s->serial ?: blk_name(s->qdev.conf.blk); - int max_len =3D s->serial ? 20 : 255 - 8; - int id_len =3D strlen(str); + int id_len =3D s->device_id ? MIN(strlen(s->device_id), 255 - 8) := 0; =20 - if (id_len > max_len) { - id_len =3D max_len; - } DPRINTF("Inquiry EVPD[Device identification] " "buffer size %zd\n", req->cmd.xfer); =20 @@ -657,7 +653,7 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req,= uint8_t *outbuf) outbuf[buflen++] =3D 0; /* not officially assigned */ outbuf[buflen++] =3D 0; /* reserved */ outbuf[buflen++] =3D id_len; /* length of data following */ - memcpy(outbuf + buflen, str, id_len); + memcpy(outbuf + buflen, s->device_id, id_len); buflen +=3D id_len; } =20 @@ -2363,6 +2359,16 @@ static void scsi_realize(SCSIDevice *dev, Error **er= rp) if (!s->vendor) { s->vendor =3D g_strdup("QEMU"); } + if (!s->device_id) { + if (s->serial) { + s->device_id =3D g_strdup_printf("%.20s", s->serial); + } else { + const char *str =3D blk_name(s->qdev.conf.blk); + if (str && *str) { + s->device_id =3D g_strdup(str); + } + } + } =20 if (blk_is_sg(s->qdev.conf.blk)) { error_setg(errp, "unwanted /dev/sg*"); @@ -2921,7 +2927,9 @@ static const TypeInfo scsi_disk_base_info =3D { DEFINE_PROP_STRING("ver", SCSIDiskState, version), \ DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \ DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \ - DEFINE_PROP_STRING("product", SCSIDiskState, product) + DEFINE_PROP_STRING("product", SCSIDiskState, product), \ + DEFINE_PROP_STRING("device_id", SCSIDiskState, device_id) + =20 static Property scsi_hd_properties[] =3D { DEFINE_SCSI_DISK_PROPERTIES(), --=20 2.20.1