From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446200; cv=none; d=zohomail.com; s=zohoarc; b=UFGjZIZG4lH2sF7yaENUPlmweyJ0dT6V1fxsF08zSo3Rk4c8HKtyxtX5BXPnsya3zakJ4Zlyf1Rqd1PAQVsgFUXmca5XOn9Em2t4HAq1QoTAXjhuKMBfPHQyjUFWhsqZphAasQVLhHknL2sA2ZrAhqNcAp5xkdq/M/mkzB+++nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446200; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aDxvVmkPXexgiS9X3iRKQ8orejZNzGobrPsRmXPMC7I=; b=ndiDPpW8OUniGy0a3j/xnM7/gfQHOqmNsaZp9ZvREg3VkBH7h8QGef93zlDDUiBBiUqXxlE5RxXRa2zLBean5Y7XJufJuQV4aSpwf5V/Z0zCK1blKkU43kTKpFj6LySYzjV27Sx4NhQ2kQEr1YmWhr0f3TL4Vgup9odd8MO7ses= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446200014583.6919249143508; Tue, 17 Mar 2020 04:56:40 -0700 (PDT) Received: from localhost ([::1]:59622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEApq-0001HH-GQ for importer@patchew.org; Tue, 17 Mar 2020 07:56:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56574) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoN-0007jP-Jm for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoL-0005HE-TX for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:07 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:56633) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoL-0005Eu-PW for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-449-GNYpot09PqiC-XRZAk3obA-1; Tue, 17 Mar 2020 07:55:03 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45EA21007272; Tue, 17 Mar 2020 11:55:02 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C5E528982; Tue, 17 Mar 2020 11:55:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EE6E01138405; Tue, 17 Mar 2020 12:54:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aDxvVmkPXexgiS9X3iRKQ8orejZNzGobrPsRmXPMC7I=; b=OubgA5XSi3tWfGdOO3W0TVr4EmPuqF5NCD9wACfrij2AKY+zV5DPPR4LXxMZQ9tazAJLK/ xnExLispqsgv5y97axAClBLZOavyMuH2/82QBNMzTb70x80kfFh8F8WrMjrRCC6Ym4lUgL Ei+EDMnWCyG1BcW3d1FDru5L4NbnJao= X-MC-Unique: GNYpot09PqiC-XRZAk3obA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 01/34] qemu-doc: Belatedly document QMP command arg & result deprecation Date: Tue, 17 Mar 2020 12:54:26 +0100 Message-Id: <20200317115459.31821-2-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A number of deprecated QMP arguments and results were missed in commit eb22aeca65 "docs: document deprecation policy & deprecated features in appendix" (v2.10.0): * Commit b33945cfff "block: Accept device model name for blockdev-open/close-tray" (v2.8.0) deprecated blockdev-open-tray, blockdev-close-tray argument @device. * Commit fbe2d8163e "block: Accept device model name for eject" (v2.8.0) deprecated eject argument @device. * Commit 70e2cb3bd7 "block: Accept device model name for blockdev-change-medium" (v2.8.0) deprecated blockdev-change-medium argument @device. * Commit 7a9877a026 "block: Accept device model name for block_set_io_throttle" (v2.8.0) deprecated block_set_io_throttle argument @device. * Commit c01c214b69 "block: remove all encryption handling APIs" (v2.10.0) deprecated query-named-block-nodes result @encryption_key_missing and query-block result @inserted member @encryption_key_missing. * Commit c42e8742f5 "block: Use JSON null instead of "" to disable backing file" (v2.10.0) deprecated blockdev-add empty string argument @backing. Since then, we missed a few more: * Commit 3c605f4074 "commit: Add top-node/base-node options" (v3.1.0) deprecated block-commit arguments @base and @top. * Commit 4db6ceb0b5 "block/dirty-bitmap: add recording and busy properties" (v4.0.0) deprecated query-named-block-nodes result @dirty-bitmaps member @status, not just query-block. Make up for all that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/system/deprecated.rst | 48 ++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst index 0838338d8f..bfc693e8e0 100644 --- a/docs/system/deprecated.rst +++ b/docs/system/deprecated.rst @@ -180,27 +180,67 @@ QEMU Machine Protocol (QMP) commands =20 Use ``blockdev-change-medium`` or ``change-vnc-password`` instead. =20 +``blockdev-open-tray``, ``blockdev-close-tray`` argument ``device`` (since= 2.8.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''= ''''''' + +Use argument ``id`` instead. + +``eject`` argument ``device`` (since 2.8.0) +''''''''''''''''''''''''''''''''''''''''''' + +Use argument ``id`` instead. + +``blockdev-change-medium`` argument ``device`` (since 2.8.0) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use argument ``id`` instead. + +``block_set_io_throttle`` argument ``device`` (since 2.8.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use argument ``id`` instead. + ``migrate_set_downtime`` and ``migrate_set_speed`` (since 2.8.0) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' =20 Use ``migrate-set-parameters`` instead. =20 +``query-named-block-nodes`` result ``encryption_key_missing`` (since 2.10.= 0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''= '' + +Always false. + +``query-block`` result ``inserted.encryption_key_missing`` (since 2.10.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Always false. + +``blockdev-add`` empty string argument ``backing`` (since 2.10.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use argument value ``null`` instead. + ``migrate-set-cache-size`` and ``query-migrate-cache-size`` (since 2.11.0) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' =20 Use ``migrate-set-parameters`` and ``query-migrate-parameters`` instead. =20 +``block-commit`` arguments ``base`` and ``top`` (since 3.1.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use arguments ``base-node`` and ``top-node`` instead. + ``object-add`` option ``props`` (since 5.0) ''''''''''''''''''''''''''''''''''''''''''' =20 Specify the properties for the object as top-level arguments instead. =20 -``query-block`` result field ``dirty-bitmaps[i].status`` (since 4.0) -'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +``query-named-block-nodes`` and ``query-block`` result dirty-bitmaps[i].st= atus (since 4.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''= '''''''''''''''' =20 The ``status`` field of the ``BlockDirtyInfo`` structure, returned by -the query-block command is deprecated. Two new boolean fields, -``recording`` and ``busy`` effectively replace it. +these commands is deprecated. Two new boolean fields, ``recording`` and +``busy`` effectively replace it. =20 ``query-block`` result field ``dirty-bitmaps`` (Since 4.2) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446436; cv=none; d=zohomail.com; s=zohoarc; b=dfhCiEoT5hQ55v6lUc4Dw0Qz/UMT0lUXZ2L5btjV9cmfKcGVqni9pazq3fx5GZtcgqKZw7hRPs9j3rqunLSgJ9Th98wyPzQRKeLAK6Wu5yG3RsrHtZnvQetvMYdiQBWoO2ElVUbyFQr32teZKWXPJw9XYCgo5Kb0oPxsa1+rRWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446436; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8ABRG8KWxhm6A2Skw9kxLZ9D4zjdKyrn2TPrFrbOvoY=; b=kKXA13SEVUbbaz1NxEhL9JW9GFQSleaQ6nYwfKk0EEze0pWmtjlkONbsDWmEGyf6sDlhlJLPcsCny1RR0mm2/8Kk3mhCDvfJF8NQPbCrFqHlmxP0zldMxWBibZkwerX9T0MDaF2SyK1dO8YJ9iofwsaiKo0kUd9hJb5kTjQb+rA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446436021263.5452268777793; Tue, 17 Mar 2020 05:00:36 -0700 (PDT) Received: from localhost ([::1]:59695 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAtZ-0007my-H9 for importer@patchew.org; Tue, 17 Mar 2020 08:00:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56708) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoU-00081g-Tu for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoT-0006H9-Mf for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:59537) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoT-0006EE-I5 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-fixifcSZMYGsr51dAAqJbA-1; Tue, 17 Mar 2020 07:55:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5FAA2477; Tue, 17 Mar 2020 11:55:10 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 705EA60E1C; Tue, 17 Mar 2020 11:55:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F104C11366CC; Tue, 17 Mar 2020 12:54:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ABRG8KWxhm6A2Skw9kxLZ9D4zjdKyrn2TPrFrbOvoY=; b=aW+9X2ZLQaarw5AfAYDrnLp+6hvUDznpMMBqKWm/Bw3AtkgqOrIdbg0Yr/6At6WeWNje+i 1k+2IkrxzRHEHExIWfDwQZon9WgDgUOVssybkYQjx9IEDGcJj2L4k6OQEajhVpMo5IL3Z+ vcu5gQ58j8Jy6POEGOhcRGo0cDrRYcw= X-MC-Unique: fixifcSZMYGsr51dAAqJbA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 02/34] qapi: Belatedly update doc comment for @wait deprecation Date: Tue, 17 Mar 2020 12:54:27 +0100 Message-Id: <20200317115459.31821-3-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit a9b305ba29 "socket: allow wait=3Dfalse for client socket" deprecated use of @wait for client socket chardevs, but neglected to update char.json's doc comment. Make up for that. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- qapi/char.json | 1 + 1 file changed, 1 insertion(+) diff --git a/qapi/char.json b/qapi/char.json index 6907b2bfdb..daceb20f84 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -258,6 +258,7 @@ # @server: create server socket (default: true) # @wait: wait for incoming connection on server # sockets (default: false). +# Silently ignored with server: false. This use is deprecated. # @nodelay: set TCP_NODELAY socket option (default: false) # @telnet: enable telnet protocol on server # sockets (default: false) --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446303; cv=none; d=zohomail.com; s=zohoarc; b=ODEZH1AySNWTsoee5HQsvgvz8yFvZ3dez7txQDpWhjIidNsR7AITxxzwIel7RaSS5E9kx6Gt4g2ki+jNaD18ZHc9+szlY3fmhXQXghlxWwA3I1EGM92ZVRcgR5B6oYtOoTp/uT2vzh1drLjuaMSyc53eyIb3XnERMITGtfgM+Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446303; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+9aJ6ZhTuZtf5NkualOeUErag8XWQSpDFZwLjlPGywg=; b=avfJuYJw99COGzfWYLAkBmRiUriGcO0AxzURP8gQn+/wNJIYNIO77chEmXM2uz+3otqxDFTNh1p85r+V9tEM6qkgz6NXTLAYjIEKS/8MUrs0mCAdcJhJKd8P99j5O+yfAMg36W7WTn4wI8fY1k/0rckE7gjFa2jmUA0VnxYHGuI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446303432189.05730020549015; Tue, 17 Mar 2020 04:58:23 -0700 (PDT) Received: from localhost ([::1]:59656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEArW-0004Qx-Cn for importer@patchew.org; Tue, 17 Mar 2020 07:58:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56578) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoN-0007jf-IP for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoM-0005La-ER for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:07 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:59883) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoM-0005GN-9b for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-UIodSZ6_O46d24Vj3q9oHg-1; Tue, 17 Mar 2020 07:55:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36B248017DF; Tue, 17 Mar 2020 11:55:03 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73BBC5DE56; Tue, 17 Mar 2020 11:55:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 001AC11366CF; Tue, 17 Mar 2020 12:54:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+9aJ6ZhTuZtf5NkualOeUErag8XWQSpDFZwLjlPGywg=; b=Lc7/1qtcPBtt5AJc28UybcSbBT9ufhTP2MSYv29pDic17b+JFiDI3zEuXPczPtg9nsO795 ChOVUVZfvc5H3t6+BHY13MqpMHjcUsvAU0aLXIQp7MveS52L7dgqzf+wH4/cB6Ob6rmI9U lM+2dyf+nvGdenGvFN61zkzpd3KGhDw= X-MC-Unique: UIodSZ6_O46d24Vj3q9oHg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 03/34] docs/devel/qapi-code-gen: Clarify allow-oob introspection Date: Tue, 17 Mar 2020 12:54:28 +0100 Message-Id: <20200317115459.31821-4-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Mention SchemaInfo variant member "allow-oob" defaults to false. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 59d6973e1e..5906602504 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -988,9 +988,9 @@ The SchemaInfo for a command has meta-type "command", a= nd variant members "arg-type", "ret-type" and "allow-oob". On the wire, the "arguments" member of a client's "execute" command must conform to the object type named by "arg-type". The "return" member that the server -passes in a success response conforms to the type named by -"ret-type". When "allow-oob" is set, it means the command supports -out-of-band execution. +passes in a success response conforms to the type named by "ret-type". +When "allow-oob" is true, it means the command supports out-of-band +execution. It defaults to false. =20 If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type" --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446314; cv=none; d=zohomail.com; s=zohoarc; b=OnbuTJ9l3e25NTd3XqULMpBm5tqCpVMtV9NWZA3VQ6ROMJXZghLwXSRm+IRYWST3kgOOhYICz22uyH5XDnqEAGyzFeVojujaIepcNkv27BqkB/k/yDW05tO4Npd3KCuDp+aBu0xo4c1ynlHvcfkmrJ8v4iWNbqLJvDO7FkK4Dmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446314; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BMAiTQHwLDlJaV8j1xo9Y/A4zk6T4gUIm/WSSe4QRmQ=; b=VC2MH5UOALGeuMjxn/zTXBRYr9xjZdVNqqHlg04Xo5r3PiJVqBopyitPzngb1tBCaoib9GwolEKs4IoqPnKDbU+q3AY0u93/7BlIw/7vHdnWgLfxBegPJme3/FR6HZBhvvfLn3aCWjLPnk/ULVPp3beyFuLGvjRSLbd8agnnZNI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158444631405439.927221605025125; Tue, 17 Mar 2020 04:58:34 -0700 (PDT) Received: from localhost ([::1]:59658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEArg-0004fJ-Uq for importer@patchew.org; Tue, 17 Mar 2020 07:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56569) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoN-0007j9-Jb for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoL-0005F5-LF for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:07 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:51833) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoL-0005EX-Ec for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-j2MJDn5ANzCkn5EERTjlGg-1; Tue, 17 Mar 2020 07:55:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57B23192203D; Tue, 17 Mar 2020 11:55:02 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78AD010372D5; Tue, 17 Mar 2020 11:55:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 034C211366D1; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BMAiTQHwLDlJaV8j1xo9Y/A4zk6T4gUIm/WSSe4QRmQ=; b=hu5Bos8/HwBy7G/Z4WrhzatAdy3SubWtJucQWQf99h92DQ3U+OtS/MfWLYa0z9PXq7/MjP 1FR1M49gEm5RNKW3FvOdAfZZuiG8yTimakHrRZ9x7uhRCIZk4QiFQwyn+R1+sVRtJWGvPk kura0KgIfiXD8Al3hdWoDQyRHVQSBX4= X-MC-Unique: j2MJDn5ANzCkn5EERTjlGg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 04/34] docs/devel/qapi-code-gen: Document 'features' introspection Date: Tue, 17 Mar 2020 12:54:29 +0100 Message-Id: <20200317115459.31821-5-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 6a8c0b5102 "qapi: Add feature flags to struct types" neglected to update section "Client JSON Protocol introspection", and commit 23394b4c39 "qapi: Add feature flags to commands" didn't either. Make up for that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 43 +++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 5906602504..297a725084 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -642,13 +642,8 @@ that previously resulted in an error). QMP clients ma= y still need to know whether the extension is available. =20 For this purpose, a list of features can be specified for a command or -struct type. This is exposed to the client as a list of strings, -where each string signals that this build of QEMU shows a certain -behaviour. - -Each member of the 'features' array defines a feature. It can either -be { 'name': STRING, '*if': COND }, or STRING, which is shorthand for -{ 'name': STRING }. +struct type. Each list member can either be { 'name': STRING, '*if': +COND }, or STRING, which is shorthand for { 'name': STRING }. =20 The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. @@ -659,6 +654,12 @@ Example: 'data': { 'number': 'int' }, 'features': [ 'allow-negative-numbers' ] } =20 +The feature strings are exposed to clients in introspection, as +explained in section "Client JSON Protocol introspection". + +Intended use is to have each feature string signal that this build of +QEMU shows a certain behaviour. + =20 =3D=3D=3D Naming rules and reserved names =3D=3D=3D =20 @@ -965,7 +966,7 @@ schema, along with the SchemaInfo type. This text atte= mpts to give an overview how things work. For details you need to consult the QAPI schema. =20 -SchemaInfo objects have common members "name" and "meta-type", and +SchemaInfo objects have common members "name", "meta-type", and additional variant members depending on the value of meta-type. =20 Each SchemaInfo object describes a wire ABI entity of a certain @@ -985,12 +986,13 @@ references by name. QAPI schema definitions not reachable that way are omitted. =20 The SchemaInfo for a command has meta-type "command", and variant -members "arg-type", "ret-type" and "allow-oob". On the wire, the -"arguments" member of a client's "execute" command must conform to the -object type named by "arg-type". The "return" member that the server -passes in a success response conforms to the type named by "ret-type". -When "allow-oob" is true, it means the command supports out-of-band -execution. It defaults to false. +members "arg-type", "ret-type", "allow-oob", and "features". On the +wire, the "arguments" member of a client's "execute" command must +conform to the object type named by "arg-type". The "return" member +that the server passes in a success response conforms to the type +named by "ret-type". When "allow-oob" is true, it means the command +supports out-of-band execution. It defaults to false. "features" +exposes the command's feature strings as a JSON array of strings. =20 If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type" @@ -1025,7 +1027,8 @@ Example: the SchemaInfo for EVENT_C from section Even= ts =20 The SchemaInfo for struct and union types has meta-type "object". =20 -The SchemaInfo for a struct type has variant member "members". +The SchemaInfo for a struct type has variant members "members" and +"features". =20 The SchemaInfo for a union type additionally has variant members "tag" and "variants". @@ -1047,6 +1050,16 @@ Example: the SchemaInfo for MyType from section Stru= ct types { "name": "member2", "type": "int" }, { "name": "member3", "type": "str", "default": null } ] } =20 +"features" exposes the command's feature strings as a JSON array of +strings. + +Example: the SchemaInfo for TestType from section Features: + + { "name": "TestType", "meta-type": "object", + "members": [ + { "name": "number", "type": "int" } ], + "features": ["allow-negative-numbers"] } + "tag" is the name of the common member serving as type tag. "variants" is a JSON array describing the object's variant members. Each element is a JSON object with members "case" (the value of type --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446349; cv=none; d=zohomail.com; s=zohoarc; b=IPIwhoHt+z8kis0tempqCNqnGw7hn0e1JUaY3RWZDGjW5Rlq2dYOh50KrMhg4Pp4pNXZJaJaHEnY/+M3eeznBzuNdkkd7rMEvq+/DnqEKBUc6c0bmjbbzDN5YyQC1pfKVbOAKqzQnpUbkIW8y102xVyBPM0f9CAdu8fkdVKwe14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446349; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kf+1SEw5rF2M4TLuz4qDRuz7bjjAQazXHPlRzdIIh0o=; b=nw0/5pzCPX2tlNR9UItlGasgeuzlDGSiBG7YFgNnheTDSIwVvlfDEwp1c1NgIS2XhiVucPhVtn1Nbr3Jchjy1Sp9gtnhWftnXQOzW653Vx+JTtMAAg1zKKaJvsY8BGMksLtC3NDqH2pVAEWvuVc+0Aopl+nIdiyYOrNF8QW9HLE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446349487764.7029901775466; Tue, 17 Mar 2020 04:59:09 -0700 (PDT) Received: from localhost ([::1]:59678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAsG-0005u2-DN for importer@patchew.org; Tue, 17 Mar 2020 07:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56657) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoT-0007wU-30 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoR-0005xy-J3 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:12 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:27530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoR-0005tX-EV for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-46Kj5pQqNY6peF7i5D8PrA-1; Tue, 17 Mar 2020 07:55:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17DEEDBA3; Tue, 17 Mar 2020 11:55:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE5031036B53; Tue, 17 Mar 2020 11:55:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0676111366D5; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kf+1SEw5rF2M4TLuz4qDRuz7bjjAQazXHPlRzdIIh0o=; b=ervTr/Y5Yt568bmX8n/iHxVNMBu+pksKGeL8xPprto+c/6vQ5QKeSbayTz+xV9gGpeAln8 Kv2xJFIkrhkPSb0SyZMa+WKGy0oWniEREGXfsE0IUCZmAs8ysNfK3EXUNfahQC7iPwQU8w K6JkoJEBznxOQMy+up7OL076n3p/FsM= X-MC-Unique: 46Kj5pQqNY6peF7i5D8PrA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 05/34] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers Date: Tue, 17 Mar 2020 12:54:30 +0100 Message-Id: <20200317115459.31821-6-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Checking the value of qmp_dispatch() is repetitive. Factor out helpers do_qmp_dispatch() and do_qmp_dispatch_error(). Without this, the next commit would make things even more repetitive. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qmp-cmds.c | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 79507d9e54..fb18475c7e 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -145,34 +145,55 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_q= emu_x_EnumList *a, } =20 =20 +static QObject *do_qmp_dispatch(QDict *req, bool allow_oob) +{ + QDict *resp; + QObject *ret; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && !qdict_haskey(resp, "error")); + ret =3D qdict_get(resp, "return"); + g_assert(ret); + + qobject_ref(ret); + qobject_unref(resp); + return ret; +} + +static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) +{ + QDict *resp; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && qdict_haskey(resp, "error")); + + qobject_unref(resp); +} + /* test commands with no input and no return value */ static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, false); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 static void test_dispatch_cmd_oob(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "exec-oob", "test-flags-command"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), true); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, true); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 @@ -181,15 +202,11 @@ static void test_dispatch_cmd_failure(void) { QDict *req =3D qdict_new(); QDict *args =3D qdict_new(); - QDict *resp; =20 qdict_put_str(req, "execute", "user_def_cmd2"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); =20 /* check that with extra arguments it throws an error */ @@ -199,11 +216,8 @@ static void test_dispatch_cmd_failure(void) =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); } =20 @@ -218,20 +232,6 @@ static void test_dispatch_cmd_success_response(void) qobject_unref(req); } =20 -static QObject *test_qmp_dispatch(QDict *req) -{ - QDict *resp; - QObject *ret; - - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp && !qdict_haskey(resp, "error")); - ret =3D qdict_get(resp, "return"); - assert(ret); - qobject_ref(ret); - qobject_unref(resp); - return ret; -} - /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { @@ -254,7 +254,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args); qdict_put_str(req, "execute", "user_def_cmd2"); =20 - ret =3D qobject_to(QDict, test_qmp_dispatch(req)); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -275,7 +275,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args3); qdict_put_str(req, "execute", "guest-get-time"); =20 - ret3 =3D qobject_to(QNum, test_qmp_dispatch(req)); + ret3 =3D qobject_to(QNum, do_qmp_dispatch(req, false)); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); qobject_unref(ret3); --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446252; cv=none; d=zohomail.com; s=zohoarc; b=DaYY0BNo/v3/lHK2RSrmztjUxIL1Ilhc3SLC/vRSgrFoFfVGbJ9hFTmPbqmfW4bF4FbVA6llHgm76HPRMnsLtF3EeBGbiv1BQNh+6qHNmhva0EAVDBxgcwGv0Kp3TkI8AQOE15BonHfjqstPqwTukyj5TRR6FQehH1doDj48sRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446252; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EZNBiYwCYvb6dGx1F/O1ypA8W1wWLGTL3UO2PfGa0Ns=; b=mnQKEsUC9dsszhxW+ej8ADcOWwyQyIBIM0xsH+BbY+TZCQbjmmbK7HsQcBhmX1gJymkPNB6ZwsgdvRfMf5xtFCRv8RanvTsFGw3wRBW5qjUSxiexCiEhR1V9Y9A9ieuOjRr72FHRi3Rc3c4sgfhuHpZZflPs3HEC3iVyqRg5S7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446252834359.17056755209524; Tue, 17 Mar 2020 04:57:32 -0700 (PDT) Received: from localhost ([::1]:59650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAqh-0003Er-QD for importer@patchew.org; Tue, 17 Mar 2020 07:57:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56661) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoT-0007ws-6g for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoR-00060L-SL for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:52112) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoR-0005xI-Nl for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-ZMfyunm-NSGkEJM_pcNdKg-1; Tue, 17 Mar 2020 07:55:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6D04DBB9; Tue, 17 Mar 2020 11:55:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC63E5DE56; Tue, 17 Mar 2020 11:55:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 09A2211366DB; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EZNBiYwCYvb6dGx1F/O1ypA8W1wWLGTL3UO2PfGa0Ns=; b=AZ216wDJcHjfnV1NHTtacW6O7RfOoM1VDNnR7kJb4vcLkb2iSY6TMuHtgdUGl8s+Hpkq08 EC3TSd6hXjEAJ8bd1xeexR3kjV5kv472zrKXA90GqLbu31JDhjz5IB7TRj3Rk5e4gu+09N DiaZQd4D6kwo1xkEENn3HJYMkc0npso= X-MC-Unique: ZMfyunm-NSGkEJM_pcNdKg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 06/34] tests/test-qmp-cmds: Check responses more thoroughly Date: Tue, 17 Mar 2020 12:54:31 +0100 Message-Id: <20200317115459.31821-7-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- tests/test-qmp-cmds.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index fb18475c7e..1563556e7c 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -151,9 +151,10 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow= _oob) QObject *ret; =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); - g_assert(resp && !qdict_haskey(resp, "error")); + g_assert(resp); ret =3D qdict_get(resp, "return"); g_assert(ret); + g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_ref(ret); qobject_unref(resp); @@ -163,9 +164,17 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow= _oob) static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) { QDict *resp; + QDict *error; =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); - g_assert(resp && qdict_haskey(resp, "error")); + g_assert(resp); + error =3D qdict_get_qdict(resp, "error"); + g_assert(error); + g_assert_cmpstr(qdict_get_try_str(error, "class"), + =3D=3D, QapiErrorClass_str(cls)); + g_assert(qdict_get_try_str(error, "desc")); + g_assert(qdict_size(error) =3D=3D 2); + g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_unref(resp); } @@ -174,11 +183,12 @@ static void do_qmp_dispatch_error(QDict *req, bool al= low_oob, ErrorClass cls) static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QObject *ret; + QDict *ret; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - ret =3D do_qmp_dispatch(req, false); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + assert(ret && qdict_size(ret) =3D=3D 0); =20 qobject_unref(ret); qobject_unref(req); @@ -187,11 +197,12 @@ static void test_dispatch_cmd(void) static void test_dispatch_cmd_oob(void) { QDict *req =3D qdict_new(); - QObject *ret; + QDict *ret; =20 qdict_put_str(req, "exec-oob", "test-flags-command"); =20 - ret =3D do_qmp_dispatch(req, true); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, true)); + assert(ret && qdict_size(ret) =3D=3D 0); =20 qobject_unref(ret); qobject_unref(req); --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446368; cv=none; d=zohomail.com; s=zohoarc; b=cIBdM9aAMs2SCKnETa09HEFIJk43ETAWiC9xxDoaTxHxeqWI1d6xJoRWCkT9JfC/162jG12xBcArGn+I/D993MN7JkjJjiMt+XX2fNMLPoWWjudhR/Vwdg91qCxrufgaQE50fbrny/fUfzsJL1wfSzzL+T1IADiAWMfoslENzp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446368; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D0uvarjntmway33kjJNYBtUlb9puOJe40SGh5+RD2sw=; b=dNHStgsIvfwMfwUW50tHRaZ6PRhS33UOLtJHOi4I+qnlQqu1Xg1WHy7X4r3RSkVARQ9vWZ4x6RYoxg/mPzxs1rnBb9KiiLRXkRkXLg38QM7saWyoAygnWWjE0TcM0Aqt8ZzZqZdD5DHb74cBmgMXz0vR3Vmyr1sB35K4OLkKdFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446368026438.44072418468113; Tue, 17 Mar 2020 04:59:28 -0700 (PDT) Received: from localhost ([::1]:59688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAsY-0006Xk-KW for importer@patchew.org; Tue, 17 Mar 2020 07:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56710) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoU-00081i-U9 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoT-0006D6-6L for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:31064) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoT-0006Az-1t for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-AdOVuRQ-NOSRhMizGqh76w-1; Tue, 17 Mar 2020 07:55:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D101C102CE27; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1E8E60BF3; Tue, 17 Mar 2020 11:55:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0CDAE11366DF; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D0uvarjntmway33kjJNYBtUlb9puOJe40SGh5+RD2sw=; b=YWkxxPwkLIJWDMxjm65ZzxlaTnR721Axm0ZRopMm4SF2u5Rct5yUwsZ/V752G+mZtw1PTV cknA4fhIJoW5dkzeUCoBrh05ygR3R0dbMXVMwap8WCI6B+Q+zzYxgBo96dg5M1gO6CAu4L vXpafGUgIHRy7LCN8k3J7UD6Ems08QA= X-MC-Unique: AdOVuRQ-NOSRhMizGqh76w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 07/34] tests/test-qmp-cmds: Simplify test data setup Date: Tue, 17 Mar 2020 12:54:32 +0100 Message-Id: <20200317115459.31821-8-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Building requests with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_vjsonf_nofail() instead. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-qmp-cmds.c | 95 +++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 57 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 1563556e7c..99013ff37b 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -1,5 +1,6 @@ #include "qemu/osdep.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/error.h" @@ -145,11 +146,16 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_q= emu_x_EnumList *a, } =20 =20 -static QObject *do_qmp_dispatch(QDict *req, bool allow_oob) +static QObject *do_qmp_dispatch(bool allow_oob, const char *template, ...) { - QDict *resp; + va_list ap; + QDict *req, *resp; QObject *ret; =20 + va_start(ap, template); + req =3D qdict_from_vjsonf_nofail(template, ap); + va_end(ap); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); g_assert(resp); ret =3D qdict_get(resp, "return"); @@ -158,14 +164,21 @@ static QObject *do_qmp_dispatch(QDict *req, bool allo= w_oob) =20 qobject_ref(ret); qobject_unref(resp); + qobject_unref(req); return ret; } =20 -static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) +static void do_qmp_dispatch_error(bool allow_oob, ErrorClass cls, + const char *template, ...) { - QDict *resp; + va_list ap; + QDict *req, *resp; QDict *error; =20 + va_start(ap, template); + req =3D qdict_from_vjsonf_nofail(template, ap); + va_end(ap); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); g_assert(resp); error =3D qdict_get_qdict(resp, "error"); @@ -177,59 +190,43 @@ static void do_qmp_dispatch_error(QDict *req, bool al= low_oob, ErrorClass cls) g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_unref(resp); + qobject_unref(req); } =20 /* test commands with no input and no return value */ static void test_dispatch_cmd(void) { - QDict *req =3D qdict_new(); QDict *ret; =20 - qdict_put_str(req, "execute", "user_def_cmd"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + ret =3D qobject_to(QDict, + do_qmp_dispatch(false, + "{ 'execute': 'user_def_cmd' }")); assert(ret && qdict_size(ret) =3D=3D 0); - qobject_unref(ret); - qobject_unref(req); } =20 static void test_dispatch_cmd_oob(void) { - QDict *req =3D qdict_new(); QDict *ret; =20 - qdict_put_str(req, "exec-oob", "test-flags-command"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, true)); + ret =3D qobject_to(QDict, + do_qmp_dispatch(true, + "{ 'exec-oob': 'test-flags-command' }= ")); assert(ret && qdict_size(ret) =3D=3D 0); - qobject_unref(ret); - qobject_unref(req); } =20 /* test commands that return an error due to invalid parameters */ static void test_dispatch_cmd_failure(void) { - QDict *req =3D qdict_new(); - QDict *args =3D qdict_new(); - - qdict_put_str(req, "execute", "user_def_cmd2"); - - do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); - - qobject_unref(req); - - /* check that with extra arguments it throws an error */ - req =3D qdict_new(); - qdict_put_int(args, "a", 66); - qdict_put(req, "arguments", args); - - qdict_put_str(req, "execute", "user_def_cmd"); - - do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); - - qobject_unref(req); + /* missing arguments */ + do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, + "{ 'execute': 'user_def_cmd2' }"); + + /* extra arguments */ + do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, + "{ 'execute': 'user_def_cmd'," + " 'arguments': { 'a': 66 } }"); } =20 static void test_dispatch_cmd_success_response(void) @@ -246,26 +243,15 @@ static void test_dispatch_cmd_success_response(void) /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { - QDict *req =3D qdict_new(); - QDict *args =3D qdict_new(); - QDict *args3 =3D qdict_new(); - QDict *ud1a =3D qdict_new(); - QDict *ud1b =3D qdict_new(); QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef; QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QNum *ret3; int64_t val; =20 - qdict_put_int(ud1a, "integer", 42); - qdict_put_str(ud1a, "string", "hello"); - qdict_put_int(ud1b, "integer", 422); - qdict_put_str(ud1b, "string", "hello2"); - qdict_put(args, "ud1a", ud1a); - qdict_put(args, "ud1b", ud1b); - qdict_put(req, "arguments", args); - qdict_put_str(req, "execute", "user_def_cmd2"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + ret =3D qobject_to(QDict, do_qmp_dispatch(false, + "{ 'execute': 'user_def_cmd2', 'arguments': {" + " 'ud1a': { 'integer': 42, 'string': 'hello' }," + " 'ud1b': { 'integer': 422, 'string': 'hello2' } } }")); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -282,16 +268,11 @@ static void test_dispatch_cmd_io(void) assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4")); qobject_unref(ret); =20 - qdict_put_int(args3, "a", 66); - qdict_put(req, "arguments", args3); - qdict_put_str(req, "execute", "guest-get-time"); - - ret3 =3D qobject_to(QNum, do_qmp_dispatch(req, false)); + ret3 =3D qobject_to(QNum, do_qmp_dispatch(false, + "{ 'execute': 'guest-get-time', 'arguments': { 'a': 66 } }")); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); qobject_unref(ret3); - - qobject_unref(req); } =20 /* test generated dealloc functions for generated types */ --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446232; cv=none; d=zohomail.com; s=zohoarc; b=F4tE8jg8ZOubkWXWxByywS+n2dW19IUHMpk+H/lyoj2tIt6YkZ5ZGpl7XwjklXoxkltptQuNg75PTyVh2A3Zmv0ABazt4gggI/Ww52eahzVElFgAHp8hDzqCsqjoE9utqlwqpvlljEMqwsCuYqmYnn+mw+AMTze1lqHy9TT0cCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446232; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jJ7RlGJeHH3Hz2YywEYf3ea7a0J9IqEyPWR424EXrlE=; b=e+rWf3zc5UWznLykhUaaJVC790qE1azz1B+paNUb3foFAIObcfcYd4pfnyKHOPRSaGd8roZ7732UQ3FD3Fmh2VeYAnjiw6QwSPhTtJIgR9Ju1YohfqgochZzt8wlhSOKcmo8XQQD5CptG608TzGcQUWx+W69V1oYcJApEebXnw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446232106197.1919050759617; Tue, 17 Mar 2020 04:57:12 -0700 (PDT) Received: from localhost ([::1]:59636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAqM-0002VA-SL for importer@patchew.org; Tue, 17 Mar 2020 07:57:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56637) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoS-0007tQ-3B for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoQ-0005nh-L4 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:11 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:37510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoQ-0005k8-FS for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-iJuxXdNzMTetwkMtBDWCzg-1; Tue, 17 Mar 2020 07:55:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 937178010FD; Tue, 17 Mar 2020 11:55:07 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B583E1036B47; Tue, 17 Mar 2020 11:55:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 101DC11366E6; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jJ7RlGJeHH3Hz2YywEYf3ea7a0J9IqEyPWR424EXrlE=; b=brBqqRXVN9oLkcMdNahuhtg9wt26mu0yKgJSz3CqjCue+ifdZOBMypPFuF2D5oUBHhgE0t VKvDEvvnCUecad7ZMiSdshMYexmW0lXDV9SJnyCZuOq53LtOsGPYkypQlD38UDe3DDqVsP De/adQBMMF2TA/zOBAvpNQ4y2jGqH14= X-MC-Unique: iJuxXdNzMTetwkMtBDWCzg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 08/34] tests/test-qmp-event: Simplify test data setup Date: Tue, 17 Mar 2020 12:54:33 +0100 Message-Id: <20200317115459.31821-9-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Building expected data with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_jsonf_nofail() instead. While there, use initializers instead of assignments for initializing aggregate event arguments. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-qmp-event.c | 93 ++++++++++++------------------------------ 1 file changed, 27 insertions(+), 66 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index eee7e08ab6..430001e622 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp-event.h" @@ -124,17 +125,13 @@ static void event_prepare(TestEventData *data, /* Global variable test_event_data was used to pass the expectation, so test cases can't be executed at same time. */ g_mutex_lock(&test_event_lock); - - data->expect =3D qdict_new(); test_event_data =3D data; } =20 static void event_teardown(TestEventData *data, const void *unused) { - qobject_unref(data->expect); test_event_data =3D NULL; - g_mutex_unlock(&test_event_lock); } =20 @@ -152,90 +149,54 @@ static void event_test_add(const char *testpath, static void test_event_a(TestEventData *data, const void *unused) { - QDict *d; - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_A"); + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_A' }"); qapi_event_send_event_a(); + qobject_unref(data->expect); } =20 static void test_event_b(TestEventData *data, const void *unused) { - QDict *d; - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_B"); + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_B' }"); qapi_event_send_event_b(); + qobject_unref(data->expect); } =20 static void test_event_c(TestEventData *data, const void *unused) { - QDict *d, *d_data, *d_b; - - UserDefOne b; - b.integer =3D 2; - b.string =3D g_strdup("test1"); - b.has_enum1 =3D false; - - d_b =3D qdict_new(); - qdict_put_int(d_b, "integer", 2); - qdict_put_str(d_b, "string", "test1"); - - d_data =3D qdict_new(); - qdict_put_int(d_data, "a", 1); - qdict_put(d_data, "b", d_b); - qdict_put_str(d_data, "c", "test2"); - - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_C"); - qdict_put(d, "data", d_data); + UserDefOne b =3D { .integer =3D 2, .string =3D (char *)"test1" }; =20 + data->expect =3D qdict_from_jsonf_nofail( + "{ 'event': 'EVENT_C', 'data': {" + " 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' }= }"); qapi_event_send_event_c(true, 1, true, &b, "test2"); - - g_free(b.string); + qobject_unref(data->expect); } =20 /* Complex type */ static void test_event_d(TestEventData *data, const void *unused) { - UserDefOne struct1; - EventStructOne a; - QDict *d, *d_data, *d_a, *d_struct1; - - struct1.integer =3D 2; - struct1.string =3D g_strdup("test1"); - struct1.has_enum1 =3D true; - struct1.enum1 =3D ENUM_ONE_VALUE1; - - a.struct1 =3D &struct1; - a.string =3D g_strdup("test2"); - a.has_enum2 =3D true; - a.enum2 =3D ENUM_ONE_VALUE2; - - d_struct1 =3D qdict_new(); - qdict_put_int(d_struct1, "integer", 2); - qdict_put_str(d_struct1, "string", "test1"); - qdict_put_str(d_struct1, "enum1", "value1"); - - d_a =3D qdict_new(); - qdict_put(d_a, "struct1", d_struct1); - qdict_put_str(d_a, "string", "test2"); - qdict_put_str(d_a, "enum2", "value2"); - - d_data =3D qdict_new(); - qdict_put(d_data, "a", d_a); - qdict_put_str(d_data, "b", "test3"); - qdict_put_str(d_data, "enum3", "value3"); - - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_D"); - qdict_put(d, "data", d_data); + UserDefOne struct1 =3D { + .integer =3D 2, .string =3D (char *)"test1", + .has_enum1 =3D true, .enum1 =3D ENUM_ONE_VALUE1, + }; + EventStructOne a =3D { + .struct1 =3D &struct1, + .string =3D (char *)"test2", + .has_enum2 =3D true, + .enum2 =3D ENUM_ONE_VALUE2, + }; =20 + data->expect =3D qdict_from_jsonf_nofail( + "{ 'event': 'EVENT_D', 'data': {" + " 'a': {" + " 'struct1': { 'integer': 2, 'string': 'test1', 'enum1': 'value1'= }," + " 'string': 'test2', 'enum2': 'value2' }," + " 'b': 'test3', 'enum3': 'value3' } }"); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE= 3); - - g_free(struct1.string); - g_free(a.string); + qobject_unref(data->expect); } =20 int main(int argc, char **argv) --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446502; cv=none; d=zohomail.com; s=zohoarc; b=AZB2TS+MJalgcVC9P2eaI+4oWb7ki15m2zdRDt3dseA34JFRaoVSkyHYQ1rWRDE1+sJl5LS6J8IJ9nU9Hkh2jQwnnC3NK/EAOfZ+Esz+xJb6C94GlOm8qkCKGXTHMIMy8j6Na93BhcatYF3kEN4Iurvf3MfV59s6ZvB97w2ES6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446502; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oOhxt0yl3sOJGHT6J/7kewazDZ/vpEGtMZrn+xQsExI=; b=VwR8+xdqs7Icnp2O7ORaHTqf2W86fzp17/qi0RszRP78yIOdqT5Z0OKZ0vG0P6lp9tkpCkecmdNQb+KCyr9qS4/ncgt8hZOg4bKJooxiGPAegtSX90LINw30g050njavrJKCCe0FJx4zaTNH5TRreORUOCzAT/KMfDEWYlreOxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446502058118.77117198593635; Tue, 17 Mar 2020 05:01:42 -0700 (PDT) Received: from localhost ([::1]:59720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAuh-0000wp-0E for importer@patchew.org; Tue, 17 Mar 2020 08:01:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56704) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoU-00081S-RS for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoT-0006GJ-Jg for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:34303) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoT-0006DT-Dz for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-YrHJBRC9NMWidYBGconcxQ-1; Tue, 17 Mar 2020 07:55:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89F911922053; Tue, 17 Mar 2020 11:55:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FAC167154; Tue, 17 Mar 2020 11:55:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1352A11366EC; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oOhxt0yl3sOJGHT6J/7kewazDZ/vpEGtMZrn+xQsExI=; b=YKeApxuFBcdzzgDPPVWWGTI4ev7XDAlMRVn7VkFmPRA4TQs1I79AC5qxcRjdO23Iwt53Ot ksp5j1jTMogDM/4DLX0eGSJwEdX6eHNeW7QekH7OZWZpfnx7XXNs+G8XgR7/k50l+lgoev p0H09zzHCr7mlRTHvSWgsouyZ4LdcHs= X-MC-Unique: YrHJBRC9NMWidYBGconcxQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 09/34] tests/test-qmp-event: Use qobject_is_equal() Date: Tue, 17 Mar 2020 12:54:34 +0100 Message-Id: <20200317115459.31821-10-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Locally defined helper qdict_cmp_simple() implements just enough of a comparison to serve here. Replace it by qobject_is_equal(), which implements all of it. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-qmp-event.c | 66 +----------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 430001e622..d64066139c 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -28,73 +28,9 @@ typedef struct TestEventData { QDict *expect; } TestEventData; =20 -typedef struct QDictCmpData { - QDict *expect; - bool result; -} QDictCmpData; - TestEventData *test_event_data; static GMutex test_event_lock; =20 -/* Only compares bool, int, string */ -static -void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque) - -{ - QObject *obj2; - QDictCmpData d_new, *d =3D opaque; - int64_t val1, val2; - - if (!d->result) { - return; - } - - obj2 =3D qdict_get(d->expect, key); - if (!obj2) { - d->result =3D false; - return; - } - - if (qobject_type(obj1) !=3D qobject_type(obj2)) { - d->result =3D false; - return; - } - - switch (qobject_type(obj1)) { - case QTYPE_QBOOL: - d->result =3D (qbool_get_bool(qobject_to(QBool, obj1)) =3D=3D - qbool_get_bool(qobject_to(QBool, obj2))); - return; - case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to(QNum, obj1), &val1)); - g_assert(qnum_get_try_int(qobject_to(QNum, obj2), &val2)); - d->result =3D val1 =3D=3D val2; - return; - case QTYPE_QSTRING: - d->result =3D g_strcmp0(qstring_get_str(qobject_to(QString, obj1)), - qstring_get_str(qobject_to(QString, obj2))) = =3D=3D 0; - return; - case QTYPE_QDICT: - d_new.expect =3D qobject_to(QDict, obj2); - d_new.result =3D true; - qdict_iter(qobject_to(QDict, obj1), qdict_cmp_do_simple, &d_new); - d->result =3D d_new.result; - return; - default: - abort(); - } -} - -static bool qdict_cmp_simple(QDict *a, QDict *b) -{ - QDictCmpData d; - - d.expect =3D b; - d.result =3D true; - qdict_iter(a, qdict_cmp_do_simple, &d); - return d.result; -} - void test_qapi_event_emit(test_QAPIEvent event, QDict *d) { QDict *t; @@ -115,7 +51,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d) =20 qdict_del(d, "timestamp"); =20 - g_assert(qdict_cmp_simple(d, test_event_data->expect)); + g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect)= )); =20 } =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446726; cv=none; d=zohomail.com; s=zohoarc; b=jYr51SKWUKcHlkr/m/vOxyoTErrrm5zcdezBISe2wirEkeJNOtH6VvwsJ2vHyJ5ylOgXCrlAmRC9U+DWViaygeGjW2uDI5o9NCV8hfxkRLWVUPjXidkxAnzwoRJNKwdWTTFQgAMBvBH0nSWxUIJxVdtvBakzg0GkIdgZHL9GWaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446726; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iUZ3WpdIbsn1AW91ePeEuZovpH+cQrT6WloC1s+rk7g=; b=gQGKjeBlb1HZBjLzLNq1/si6YGsoe915zp13VgOniDVqwrMOetEJarYwZ5sR9pBIpoazFNl32Px5sanodreFSU83dvQ4lY2HQJgm+iC7lSCGBj5A76zMgxINjIdHbD/EhX4Vl3kApp5Zz2Gi4P6elWOpbuNGAXU3JYZhB0ZED/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446726364954.4611646209011; Tue, 17 Mar 2020 05:05:26 -0700 (PDT) Received: from localhost ([::1]:59788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAyL-0007JA-4a for importer@patchew.org; Tue, 17 Mar 2020 08:05:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56875) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoa-0008ER-Sp for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoY-0006ps-WC for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:20 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:60226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoY-0006mG-Pb for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-AWjWNZ_KMEqGlVYms_INNA-1; Tue, 17 Mar 2020 07:55:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A78AE19251A0; Tue, 17 Mar 2020 11:55:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73FFD5C1BB; Tue, 17 Mar 2020 11:55:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 166DD11366F1; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iUZ3WpdIbsn1AW91ePeEuZovpH+cQrT6WloC1s+rk7g=; b=NtjYGCHEM1j3bs9BHibRl2HMDARkCJkYxNgOGfEIQChTt62uYieyzzZ68D+unmND7v5xS+ Ht6QZDsJfzcNygu6+ahcaQgcgkua/5whxouTKongHyOMFuSKYp2bu4wBxQcK3BYRB6g01c MS+XlOgfIjo2S4irDLCOAYZoxXqTbZ4= X-MC-Unique: AWjWNZ_KMEqGlVYms_INNA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 10/34] tests/test-qmp-event: Check event is actually emitted Date: Tue, 17 Mar 2020 12:54:35 +0100 Message-Id: <20200317115459.31821-11-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-qmp-event.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index d64066139c..7dd0053190 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -26,6 +26,7 @@ =20 typedef struct TestEventData { QDict *expect; + bool emitted; } TestEventData; =20 TestEventData *test_event_data; @@ -52,7 +53,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d) qdict_del(d, "timestamp"); =20 g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect)= )); - + test_event_data->emitted =3D true; } =20 static void event_prepare(TestEventData *data, @@ -87,6 +88,7 @@ static void test_event_a(TestEventData *data, { data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_A' }"); qapi_event_send_event_a(); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -95,6 +97,7 @@ static void test_event_b(TestEventData *data, { data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_B' }"); qapi_event_send_event_b(); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -107,6 +110,7 @@ static void test_event_c(TestEventData *data, "{ 'event': 'EVENT_C', 'data': {" " 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' }= }"); qapi_event_send_event_c(true, 1, true, &b, "test2"); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -132,6 +136,7 @@ static void test_event_d(TestEventData *data, " 'string': 'test2', 'enum2': 'value2' }," " 'b': 'test3', 'enum3': 'value3' } }"); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE= 3); + g_assert(data->emitted); qobject_unref(data->expect); } =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446661; cv=none; d=zohomail.com; s=zohoarc; b=lTol6SSokPXkxA2nZPyEVkHDhULFGWRa9l/iOXxrqwEViPS6HWLFBBrzCDoRhDtweHvDjc+d8eQ74Kex0oCr31w+x6fmXMYhB0PATWAdT6Id/6WNPDBln86xyG4xWiu6bZlrorZcekK0IA0WFeAa0YRYCaOFp2xbk3aNf8E6+WI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446661; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1NrBoOJiPpPijarSOpG1Aow+BnBWvtdHBq3tpL59k0M=; b=A8jsHqTPv5QSVJ7/nIa4NLuybnoWNvMJXpX/i+90UEPFC/OoxE1D97XJPClfgstKdSv9iKjQ3BlUotJbegdN9H1k3yGiEEZIRkA9XoYlBXBVDVYDleHwOu0yJFckMSiYyxdeemR2h5LDKerpE22v9ySeIXnxQEUB54LtEHVSMyI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446661948380.6048151413406; Tue, 17 Mar 2020 05:04:21 -0700 (PDT) Received: from localhost ([::1]:59766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAxI-0004i0-PI for importer@patchew.org; Tue, 17 Mar 2020 08:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56801) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoY-00088G-4p for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoW-0006cc-L4 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:48509) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoW-0006Yk-FP for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-4DMogmT2OP6LZWmXMItqIA-1; Tue, 17 Mar 2020 07:55:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E53EBDBAB; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC0B89080B; Tue, 17 Mar 2020 11:55:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1A6E311366F2; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1NrBoOJiPpPijarSOpG1Aow+BnBWvtdHBq3tpL59k0M=; b=XBPyL5wBBgxpDaUmst+fbIZ1JnN4AdGhnEgfg/aVOb/R41AFpoZTHzTkDob5RltoQb+K8q IuDJw+9reNeMF7u87mGoIiBL3s+gGo6EjK3jALKuLS7CySTltrKYQlxVEhMFpE7mqWgujJ M9RI08ZwC3fzq8rXdg56xHUULIPkzTc= X-MC-Unique: 4DMogmT2OP6LZWmXMItqIA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 11/34] qapi/schema: Clean up around QAPISchemaEntity.connect_doc() Date: Tue, 17 Mar 2020 12:54:36 +0100 Message-Id: <20200317115459.31821-12-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QAPISchemaEntity calls doc.connect_feature() in .check(). Improper since commit ee1e6a1f6c8 split .connect_doc() off .check(). Move the call. Requires making the children call super().connect_doc() as they should. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- scripts/qapi/schema.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d759308b4e..2a2b495987 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -53,13 +53,13 @@ class QAPISchemaEntity: seen =3D {} for f in self.features: f.check_clash(self.info, seen) - if self.doc: - self.doc.connect_feature(f) - self._checked =3D True =20 def connect_doc(self, doc=3DNone): - pass + doc =3D doc or self.doc + if doc: + for f in self.features: + doc.connect_feature(f) =20 def check_doc(self): if self.doc: @@ -250,6 +250,7 @@ class QAPISchemaEnumType(QAPISchemaType): m.check_clash(self.info, seen) =20 def connect_doc(self, doc=3DNone): + super().connect_doc(doc) doc =3D doc or self.doc if doc: for m in self.members: @@ -392,6 +393,7 @@ class QAPISchemaObjectType(QAPISchemaType): m.check_clash(info, seen) =20 def connect_doc(self, doc=3DNone): + super().connect_doc(doc) doc =3D doc or self.doc if doc: if self.base and self.base.is_implicit(): @@ -667,6 +669,7 @@ class QAPISchemaAlternateType(QAPISchemaType): types_seen[qt] =3D v.name =20 def connect_doc(self, doc=3DNone): + super().connect_doc(doc) doc =3D doc or self.doc if doc: for v in self.variants.variants: @@ -733,6 +736,7 @@ class QAPISchemaCommand(QAPISchemaEntity): % self.ret_type.describe()) =20 def connect_doc(self, doc=3DNone): + super().connect_doc(doc) doc =3D doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit(): @@ -775,6 +779,7 @@ class QAPISchemaEvent(QAPISchemaEntity): % self.arg_type.describe()) =20 def connect_doc(self, doc=3DNone): + super().connect_doc(doc) doc =3D doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit(): --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447073; cv=none; d=zohomail.com; s=zohoarc; b=AULKkpesmdUiTgZKvYN9J9NwuzXFT2EZTvXqUqPljSJV70tXNGnsPETQgEjBvFng2vQ+2QEm6iAsfqx3O9HwHWYWeKSTdW/HFv4/KntBFPL3QqZAVrv0dFtD4+bA5BB2u5sHlQSV1T4RaINkdAGCPoCnU5iSw1Zj/+dLTsyXFuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xp8891nS0UYig0gCtD+5iDm/QrmpDJEm07n17KUBXZA=; b=hXTN42XxIwVA+a0Qg971MqLO/RQkOwDhK03mfuM+Y0vs+I9tmN3rp8wwQrfYOzrPlTGT8rRSgdaWdLGqQKjUd3RI4sooybCoiYPIDyjvl9oB2gkMa6HVeJMXqo3qrkRrgAitkliEvoRrvPZdXkk3VwyRMjiVaNMCz2bngMBntnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447073949344.68038704864864; Tue, 17 Mar 2020 05:11:13 -0700 (PDT) Received: from localhost ([::1]:59960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB3w-0001t9-L9 for importer@patchew.org; Tue, 17 Mar 2020 08:11:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57024) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAog-0008NK-07 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006iZ-Jj for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:25 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:57686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006e8-9u for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-4H1jKr63OfOjyZZzKYVcgg-1; Tue, 17 Mar 2020 07:55:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 190D7101FC69; Tue, 17 Mar 2020 11:55:10 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D48B710021B2; Tue, 17 Mar 2020 11:55:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 28ABA11366F3; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xp8891nS0UYig0gCtD+5iDm/QrmpDJEm07n17KUBXZA=; b=JZ287DAHQ8wdQ272iZhG9ZdcCn8QqUutlfzooNfz9iLonbKQaFfP4TYg3xloAUCn/Qclrp zY5DB1DI/mxL+oGHmVAGOWNnog1FZNExz80Agj674cSvdnpicmLMCxrLwtfc3T/hwul74R VVKdTsvhQ2WInrvap9Z2CEaLCRMgDaE= X-MC-Unique: 4H1jKr63OfOjyZZzKYVcgg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 12/34] qapi: Add feature flags to remaining definitions Date: Tue, 17 Mar 2020 12:54:37 +0100 Message-Id: <20200317115459.31821-13-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In v4.1.0, we added feature flags just to struct types (commit 6a8c0b5102^..f3ed93d545), to satisfy an immediate need (commit c9d4070991 "file-posix: Add dynamic-auto-read-only QAPI feature"). In v4.2.0, we added them to commands (commit 23394b4c39 "qapi: Add feature flags to commands") to satisfy another immediate need (commit d76744e65e "qapi: Allow introspecting fix for savevm's cooperation with blockdev"). Add them to the remaining definitions: enumeration types, union types, alternate types, and events. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 54 +++++++++----- tests/qapi-schema/doc-good.texi | 30 ++++++++ qapi/introspect.json | 20 +++--- tests/test-qmp-cmds.c | 6 +- scripts/qapi/doc.py | 6 +- scripts/qapi/events.py | 2 +- scripts/qapi/expr.py | 11 ++- scripts/qapi/introspect.py | 31 ++++---- scripts/qapi/schema.py | 96 ++++++++++++++----------- scripts/qapi/types.py | 4 +- scripts/qapi/visit.py | 4 +- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/doc-good.json | 17 +++++ tests/qapi-schema/doc-good.out | 15 ++++ tests/qapi-schema/qapi-schema-test.json | 29 ++++++-- tests/qapi-schema/qapi-schema-test.out | 27 +++++-- tests/qapi-schema/test-qapi.py | 9 ++- 17 files changed, 242 insertions(+), 121 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 297a725084..9fce78dcad 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -172,7 +172,8 @@ Syntax: ENUM =3D { 'enum': STRING, 'data': [ ENUM-VALUE, ... ], '*prefix': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } ENUM-VALUE =3D STRING | { 'name': STRING, '*if': COND } =20 @@ -207,6 +208,9 @@ the job satisfactorily. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Type references and array types =3D=3D=3D =20 @@ -279,12 +283,14 @@ below for more on this. Syntax: UNION =3D { 'union': STRING, 'data': BRANCHES, - '*if': COND } + '*if': COND, + '*features': FEATURES } | { 'union': STRING, 'data': BRANCHES, 'base': ( MEMBERS | STRING ), 'discriminator': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } BRANCHES =3D { BRANCH, ... } BRANCH =3D STRING : TYPE-REF | STRING : { 'type': TYPE-REF, '*if': COND } @@ -391,13 +397,17 @@ is identical on the wire to: The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Alternate types =3D=3D=3D =20 Syntax: ALTERNATE =3D { 'alternate': STRING, 'data': ALTERNATIVES, - '*if': COND } + '*if': COND, + '*features': FEATURES } ALTERNATIVES =3D { ALTERNATIVE, ... } ALTERNATIVE =3D STRING : TYPE-REF | STRING : { 'type': STRING, '*if': COND } @@ -441,6 +451,9 @@ following example objects: The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Commands =3D=3D=3D =20 @@ -584,6 +597,9 @@ started with --preconfig. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Events =3D=3D=3D =20 @@ -595,7 +611,8 @@ Syntax: 'data': STRING, 'boxed': true, ) - '*if': COND } + '*if': COND, + '*features': FEATURES } =20 Member 'event' names the event. This is the event name used in the Client JSON Protocol. @@ -628,6 +645,9 @@ complex type. See section "Code generated for events" = for examples. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Features =3D=3D=3D =20 @@ -966,8 +986,9 @@ schema, along with the SchemaInfo type. This text atte= mpts to give an overview how things work. For details you need to consult the QAPI schema. =20 -SchemaInfo objects have common members "name", "meta-type", and -additional variant members depending on the value of meta-type. +SchemaInfo objects have common members "name", "meta-type", +"features", and additional variant members depending on the value of +meta-type. =20 Each SchemaInfo object describes a wire ABI entity of a certain meta-type: a command, event or one of several kinds of type. @@ -980,19 +1001,21 @@ not. Therefore, the SchemaInfo for types have auto-= generated meaningless names. For readability, the examples in this section use meaningful type names instead. =20 +Optional member "features" exposes the entity's feature strings as a +JSON array of strings. + To examine a type, start with a command or event using it, then follow references by name. =20 QAPI schema definitions not reachable that way are omitted. =20 The SchemaInfo for a command has meta-type "command", and variant -members "arg-type", "ret-type", "allow-oob", and "features". On the -wire, the "arguments" member of a client's "execute" command must -conform to the object type named by "arg-type". The "return" member -that the server passes in a success response conforms to the type -named by "ret-type". When "allow-oob" is true, it means the command -supports out-of-band execution. It defaults to false. "features" -exposes the command's feature strings as a JSON array of strings. +members "arg-type", "ret-type" and "allow-oob". On the wire, the +"arguments" member of a client's "execute" command must conform to the +object type named by "arg-type". The "return" member that the server +passes in a success response conforms to the type named by "ret-type". +When "allow-oob" is true, it means the command supports out-of-band +execution. It defaults to false. =20 If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type" @@ -1027,8 +1050,7 @@ Example: the SchemaInfo for EVENT_C from section Even= ts =20 The SchemaInfo for struct and union types has meta-type "object". =20 -The SchemaInfo for a struct type has variant members "members" and -"features". +The SchemaInfo for a struct type has variant member "members". =20 The SchemaInfo for a union type additionally has variant members "tag" and "variants". diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index d4b15dabf0..76b396dae6 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -88,6 +88,12 @@ The @emph{one} @{and only@} @item @code{two} Not documented @end table + +@b{Features:} +@table @asis +@item @code{enum-feat} +Also @emph{one} @{and only@} +@end table @code{two} is undocumented =20 @b{If:} @code{defined(IFCOND)} @@ -151,6 +157,12 @@ a feature @item The members of @code{Variant2} when @code{base1} is @t{"two"} (@b{If= :} @code{IFTWO}) @end table =20 +@b{Features:} +@table @asis +@item @code{union-feat1} +a feature +@end table + @end deftp =20 =20 @@ -167,6 +179,12 @@ One of @t{"one"}, @t{"two"} @item @code{data: Variant2} when @code{type} is @t{"two"} (@b{If:} @code{I= FTWO}) @end table =20 +@b{Features:} +@table @asis +@item @code{union-feat2} +a feature +@end table + @end deftp =20 =20 @@ -184,6 +202,12 @@ an integer Not documented @end table =20 +@b{Features:} +@table @asis +@item @code{alt-feat} +a feature +@end table + @end deftp =20 =20 @@ -283,5 +307,11 @@ another feature =20 @b{Arguments:} the members of @code{Object} =20 +@b{Features:} +@table @asis +@item @code{feat3} +a feature +@end table + @end deftypefn =20 diff --git a/qapi/introspect.json b/qapi/introspect.json index 8756e7920e..da3e176899 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -89,12 +89,18 @@ # # @meta-type: the entity's meta type, inherited from @base. # +# @features: names of features associated with the entity, in no +# particular order. +# (since 4.1 for object types, 4.2 for commands, 5.0 for +# the rest) +# # Additional members depend on the value of @meta-type. # # Since: 2.5 ## { 'union': 'SchemaInfo', - 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType' }, + 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType', + '*features': [ 'str' ] }, 'discriminator': 'meta-type', 'data': { 'builtin': 'SchemaInfoBuiltin', @@ -174,9 +180,6 @@ # and may even differ from the order of the values of the # enum type of the @tag. # -# @features: names of features associated with the type, in no particular -# order. (since: 4.1) -# # Values of this type are JSON object on the wire. # # Since: 2.5 @@ -184,8 +187,7 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ], - '*features': [ 'str' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ] } } =20 ## # @SchemaInfoObjectMember: @@ -266,17 +268,13 @@ # @allow-oob: whether the command allows out-of-band execution, # defaults to false (Since: 2.12) # -# @features: names of features associated with the command, in no particul= ar -# order. (since 4.2) -# # TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ## { 'struct': 'SchemaInfoCommand', 'data': { 'arg-type': 'str', 'ret-type': 'str', - '*allow-oob': 'bool', - '*features': [ 'str' ] } } + '*allow-oob': 'bool' } } =20 ## # @SchemaInfoEvent: diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 99013ff37b..d12ff47e26 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -45,7 +45,7 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp) { } =20 -void qmp_test_features(FeatureStruct0 *fs0, FeatureStruct1 *fs1, +void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruct1 *fs1, FeatureStruct2 *fs2, FeatureStruct3 *fs3, FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1, CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3, @@ -53,10 +53,6 @@ void qmp_test_features(FeatureStruct0 *fs0, FeatureStruc= t1 *fs1, { } =20 -void qmp_test_command_features0(Error **errp) -{ -} - void qmp_test_command_features1(Error **errp) { } diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 1787a53d91..36e823338b 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -243,7 +243,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): def write(self, output_dir): self._gen.write(output_dir) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): doc =3D self.cur_doc self._gen.add(texi_type('Enum', doc, ifcond, texi_members(doc, 'Values', @@ -257,7 +257,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Object', doc, ifcond, texi_members(doc, 'Members', base, variant= s))) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): doc =3D self.cur_doc self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) @@ -270,7 +270,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_arguments(doc, arg_type if boxed else None)= )) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): doc =3D self.cur_doc self._gen.add(texi_msg('Event', doc, ifcond, texi_arguments(doc, diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index a98b9f5099..b544af5a1c 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -189,7 +189,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); event_emit=3Dself._event_emit_name, event_enum=3Dself._event_enum_name)) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) self._genc.add(gen_event_send(name, arg_type, boxed, diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index fecf466fa7..f9c4448980 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -219,7 +219,6 @@ def check_struct(expr, info): =20 check_type(members, info, "'data'", allow_dict=3Dname) check_type(expr.get('base'), info, "'base'") - check_features(expr.get('features'), info) =20 =20 def check_union(expr, info): @@ -267,7 +266,6 @@ def check_command(expr, info): raise QAPISemError(info, "'boxed': true requires 'data'") check_type(args, info, "'data'", allow_dict=3Dnot boxed) check_type(rets, info, "'returns'", allow_array=3DTrue) - check_features(expr.get('features'), info) =20 =20 def check_event(expr, info): @@ -319,18 +317,18 @@ def check_exprs(exprs): =20 if meta =3D=3D 'enum': check_keys(expr, info, meta, - ['enum', 'data'], ['if', 'prefix']) + ['enum', 'data'], ['if', 'features', 'prefix']) check_enum(expr, info) elif meta =3D=3D 'union': check_keys(expr, info, meta, ['union', 'data'], - ['base', 'discriminator', 'if']) + ['base', 'discriminator', 'if', 'features']) normalize_members(expr.get('base')) normalize_members(expr['data']) check_union(expr, info) elif meta =3D=3D 'alternate': check_keys(expr, info, meta, - ['alternate', 'data'], ['if']) + ['alternate', 'data'], ['if', 'features']) normalize_members(expr['data']) check_alternate(expr, info) elif meta =3D=3D 'struct': @@ -348,13 +346,14 @@ def check_exprs(exprs): check_command(expr, info) elif meta =3D=3D 'event': check_keys(expr, info, meta, - ['event'], ['data', 'boxed', 'if']) + ['event'], ['data', 'boxed', 'if', 'features']) normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' =20 check_if(expr, info, meta) + check_features(expr.get('features'), info) check_flags(expr, info) =20 return exprs diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b5537eddc0..2e9e00aa1f 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -144,7 +144,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 - def _gen_qlit(self, name, mtype, obj, ifcond): + def _gen_qlit(self, name, mtype, obj, ifcond, features): extra =3D {} if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -154,6 +154,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype + if features: + obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] if ifcond: extra['if'] =3D ifcond if extra: @@ -178,18 +180,18 @@ const QLitObject %(c_name)s =3D %(c_string)s; {'if': variant.ifcond}) =20 def visit_builtin_type(self, name, info, json_type): - self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) + self._gen_qlit(name, 'builtin', {'json-type': json_type}, [], None) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): self._gen_qlit(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, - ifcond) + ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, - ifcond) + ifcond, None) =20 def visit_object_type_flat(self, name, info, ifcond, members, variants, features): @@ -197,16 +199,15 @@ const QLitObject %(c_name)s =3D %(c_string)s; if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] =20 - self._gen_qlit(name, 'object', obj, ifcond) + self._gen_qlit(name, 'object', obj, ifcond, features) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_qlit(name, 'alternate', {'members': [ ({'type': self._use_type(m.type)}, {'if': m.ifc= ond}) - for m in variants.variants]}, ifcond) + for m in variants.variants]}, + ifcond, features) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, @@ -217,16 +218,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; 'ret-type': self._use_type(ret_type)} if allow_oob: obj['allow-oob'] =3D allow_oob + self._gen_qlit(name, 'command', obj, ifcond, features) =20 - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] - - self._gen_qlit(name, 'command', obj, ifcond) - - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}, - ifcond) + ifcond, features) =20 =20 def gen_introspect(schema, output_dir, prefix, opt_unmask): diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 2a2b495987..22238005ff 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -109,7 +109,7 @@ class QAPISchemaVisitor: def visit_builtin_type(self, name, info, json_type): pass =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): pass =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -123,7 +123,7 @@ class QAPISchemaVisitor: features): pass =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): pass =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, @@ -131,7 +131,7 @@ class QAPISchemaVisitor: features): pass =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): pass =20 =20 @@ -234,8 +234,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): class QAPISchemaEnumType(QAPISchemaType): meta =3D 'enum' =20 - def __init__(self, name, info, doc, ifcond, members, prefix): - super().__init__(name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, members, prefix): + super().__init__(name, info, doc, ifcond, features) for m in members: assert isinstance(m, QAPISchemaEnumMember) m.set_defined_in(name) @@ -271,15 +271,16 @@ class QAPISchemaEnumType(QAPISchemaType): =20 def visit(self, visitor): super().visit(visitor) - visitor.visit_enum_type(self.name, self.info, self.ifcond, - self.members, self.prefix) + visitor.visit_enum_type( + self.name, self.info, self.ifcond, self.features, + self.members, self.prefix) =20 =20 class QAPISchemaArrayType(QAPISchemaType): meta =3D 'array' =20 def __init__(self, name, info, element_type): - super().__init__(name, info, None, None) + super().__init__(name, info, None) assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type =3D None @@ -325,8 +326,8 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, ifcond, - base, local_members, variants, features): + def __init__(self, name, info, doc, ifcond, features, + base, local_members, variants): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base @@ -622,8 +623,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeM= ember): class QAPISchemaAlternateType(QAPISchemaType): meta =3D 'alternate' =20 - def __init__(self, name, info, doc, ifcond, variants): - super().__init__(name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, variants): + super().__init__(name, info, doc, ifcond, features) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_defined_in(name) @@ -683,16 +684,16 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 def visit(self, visitor): super().visit(visitor) - visitor.visit_alternate_type(self.name, self.info, self.ifcond, - self.variants) + visitor.visit_alternate_type( + self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 class QAPISchemaCommand(QAPISchemaEntity): meta =3D 'command' =20 - def __init__(self, name, info, doc, ifcond, arg_type, ret_type, - gen, success_response, boxed, allow_oob, allow_preconfig, - features): + def __init__(self, name, info, doc, ifcond, features, + arg_type, ret_type, + gen, success_response, boxed, allow_oob, allow_preconfig): super().__init__(name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -755,8 +756,8 @@ class QAPISchemaCommand(QAPISchemaEntity): class QAPISchemaEvent(QAPISchemaEntity): meta =3D 'event' =20 - def __init__(self, name, info, doc, ifcond, arg_type, boxed): - super().__init__(name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, arg_type, boxed): + super().__init__(name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -787,8 +788,9 @@ class QAPISchemaEvent(QAPISchemaEntity): =20 def visit(self, visitor): super().visit(visitor) - visitor.visit_event(self.name, self.info, self.ifcond, - self.arg_type, self.boxed) + visitor.visit_event( + self.name, self.info, self.ifcond, self.features, + self.arg_type, self.boxed) =20 =20 class QAPISchema: @@ -893,7 +895,7 @@ class QAPISchema: ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( - 'q_empty', None, None, None, None, [], None, []) + 'q_empty', None, None, None, None, None, [], None) self._def_entity(self.the_empty_object_type) =20 qtypes =3D ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', @@ -901,10 +903,11 @@ class QAPISchema: qtype_values =3D self._make_enum_members( [{'name': n} for n in qtypes], None) =20 - self._def_entity(QAPISchemaEnumType('QType', None, None, None, + self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, qtype_values, 'QTYPE')) =20 - def _make_features(self, features, info): + def _make_features(self, expr, info): + features =3D expr.get('features', []) return [QAPISchemaFeature(f['name'], info, f.get('if')) for f in features] =20 @@ -916,7 +919,8 @@ class QAPISchema: # See also QAPISchemaObjectTypeMember.describe() name =3D name + 'Kind' # reserved by check_defn_name_str() self._def_entity(QAPISchemaEnumType( - name, info, None, ifcond, self._make_enum_members(values, info= ), + name, info, None, ifcond, None, + self._make_enum_members(values, info), None)) return name =20 @@ -944,8 +948,8 @@ class QAPISchema: # TODO kill simple unions or implement the disjunction assert (ifcond or []) =3D=3D typ._ifcond # pylint: disable=3Dp= rotected-access else: - self._def_entity(QAPISchemaObjectType(name, info, None, ifcond, - None, members, None, [])) + self._def_entity(QAPISchemaObjectType( + name, info, None, ifcond, None, None, members, None)) return name =20 def _def_enum_type(self, expr, info, doc): @@ -953,8 +957,9 @@ class QAPISchema: data =3D expr['data'] prefix =3D expr.get('prefix') ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) self._def_entity(QAPISchemaEnumType( - name, info, doc, ifcond, + name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 def _make_member(self, name, typ, ifcond, info): @@ -976,12 +981,11 @@ class QAPISchema: base =3D expr.get('base') data =3D expr['data'] ifcond =3D expr.get('if') - features =3D expr.get('features', []) + features =3D self._make_features(expr, info) self._def_entity(QAPISchemaObjectType( - name, info, doc, ifcond, base, + name, info, doc, ifcond, features, base, self._make_members(data, info), - None, - self._make_features(features, info))) + None)) =20 def _make_variant(self, case, typ, ifcond, info): return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) @@ -1000,6 +1004,7 @@ class QAPISchema: data =3D expr['data'] base =3D expr.get('base') ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): @@ -1020,21 +1025,22 @@ class QAPISchema: tag_member =3D QAPISchemaObjectTypeMember('type', info, typ, F= alse) members =3D [tag_member] self._def_entity( - QAPISchemaObjectType(name, info, doc, ifcond, base, members, + QAPISchemaObjectType(name, info, doc, ifcond, features, + base, members, QAPISchemaObjectTypeVariants( - tag_name, info, tag_member, variants), - [])) + tag_name, info, tag_member, variants)= )) =20 def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) variants =3D [self._make_variant(key, value['type'], value.get('if= '), info) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) self._def_entity( - QAPISchemaAlternateType(name, info, doc, ifcond, + QAPISchemaAlternateType(name, info, doc, ifcond, features, QAPISchemaObjectTypeVariants( None, info, tag_member, variants))) =20 @@ -1048,27 +1054,31 @@ class QAPISchema: allow_oob =3D expr.get('allow-oob', False) allow_preconfig =3D expr.get('allow-preconfig', False) ifcond =3D expr.get('if') - features =3D expr.get('features', []) + features =3D self._make_features(expr, info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, ifcond, 'arg', self._make_members(data, info)) + name, info, ifcond, + 'arg', self._make_members(data, info)) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) - self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, data, = rets, + self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, featur= es, + data, rets, gen, success_response, - boxed, allow_oob, allow_preconf= ig, - self._make_features(features, i= nfo))) + boxed, allow_oob, allow_preconf= ig)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, ifcond, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, data, bo= xed)) + name, info, ifcond, + 'arg', self._make_members(data, info)) + self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, features, + data, boxed)) =20 def _def_exprs(self, exprs): for expr_elem in exprs: diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3c83b6e4be..d0d5c03646 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -278,7 +278,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_enum(name, members, prefix)) self._genc.add(gen_enum_lookup(name, members, prefix)) @@ -306,7 +306,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, None, diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 421e5bd8cd..6e5ed781d7 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -316,7 +316,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) @@ -342,7 +342,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name, base, members, varia= nts)) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants)) diff --git a/tests/qapi-schema/alternate-base.err b/tests/qapi-schema/alter= nate-base.err index 31ebe56bbf..970a08ab26 100644 --- a/tests/qapi-schema/alternate-base.err +++ b/tests/qapi-schema/alternate-base.err @@ -1,3 +1,3 @@ alternate-base.json: In alternate 'Alt': alternate-base.json:4: alternate has unknown key 'base' -Valid keys are 'alternate', 'data', 'if'. +Valid keys are 'alternate', 'data', 'features', 'if'. diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index d992e713d9..457b8b2cdf 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -53,10 +53,14 @@ # @Enum: # @one: The _one_ {and only} # +# Features: +# @enum-feat: Also _one_ {and only} +# # @two is undocumented ## { 'enum': 'Enum', 'data': [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ], + 'features': [ 'enum-feat' ], 'if': 'defined(IFCOND)' } =20 ## @@ -86,24 +90,34 @@ =20 ## # @Object: +# Features: +# @union-feat1: a feature ## { 'union': 'Object', + 'features': [ 'union-feat1' ], 'base': 'Base', 'discriminator': 'base1', 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # @SugaredUnion: +# Features: +# @union-feat2: a feature ## { 'union': 'SugaredUnion', + 'features': [ 'union-feat2' ], 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # @Alternate: # @i: an integer # @b is undocumented +# +# Features: +# @alt-feat: a feature ## { 'alternate': 'Alternate', + 'features': [ 'alt-feat' ], 'data': { 'i': 'int', 'b': 'bool' } } =20 ## @@ -160,6 +174,9 @@ =20 ## # @EVT-BOXED: +# Features: +# @feat3: a feature ## { 'event': 'EVT-BOXED', 'boxed': true, + 'features': [ 'feat3' ], 'data': 'Object' } diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 4c9406a464..9bcb2b3e91 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -15,6 +15,7 @@ enum Enum if ['defined(IFONE)'] member two if ['defined(IFCOND)'] + feature enum-feat object Base member base1: Enum optional=3DFalse object Variant1 @@ -28,6 +29,7 @@ object Object case one: Variant1 case two: Variant2 if ['IFTWO'] + feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse object q_obj_Variant2-wrapper @@ -42,10 +44,12 @@ object SugaredUnion case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper if ['IFTWO'] + feature union-feat2 alternate Alternate tag type case i: int case b: bool + feature alt-feat object q_obj_cmd-arg member arg1: int optional=3DFalse member arg2: str optional=3DTrue @@ -60,6 +64,7 @@ command cmd-boxed Object -> None feature cmd-feat2 event EVT-BOXED Object boxed=3DTrue + feature feat3 doc freeform body=3D =3D Section @@ -112,6 +117,8 @@ doc symbol=3DEnum The _one_ {and only} arg=3Dtwo =20 + feature=3Denum-feat +Also _one_ {and only} section=3DNone @two is undocumented doc symbol=3DBase @@ -134,11 +141,15 @@ doc symbol=3DVariant2 doc symbol=3DObject body=3D =20 + feature=3Dunion-feat1 +a feature doc symbol=3DSugaredUnion body=3D =20 arg=3Dtype =20 + feature=3Dunion-feat2 +a feature doc symbol=3DAlternate body=3D =20 @@ -147,6 +158,8 @@ an integer @b is undocumented arg=3Db =20 + feature=3Dalt-feat +a feature doc freeform body=3D =3D=3D Another subsection @@ -197,3 +210,5 @@ another feature doc symbol=3DEVT-BOXED body=3D =20 + feature=3Dfeat3 +a feature diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 9abf175fe0..fa4f3a15da 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -252,7 +252,7 @@ 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } =20 -# test 'features' for structs +# test 'features' =20 { 'struct': 'FeatureStruct0', 'data': { 'foo': 'int' }, @@ -281,7 +281,22 @@ 'data': { 'foo': 'int' }, 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } -{ 'command': 'test-features', + +{ 'enum': 'FeatureEnum1', + 'data': [ 'eins', 'zwei', 'drei' ], + 'features': [ 'feature1' ] } + +{ 'union': 'FeatureUnion1', + 'base': { 'tag': 'FeatureEnum1' }, + 'discriminator': 'tag', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'alternate': 'FeatureAlternate1', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'command': 'test-features0', 'data': { 'fs0': 'FeatureStruct0', 'fs1': 'FeatureStruct1', 'fs2': 'FeatureStruct2', @@ -289,12 +304,9 @@ 'fs4': 'FeatureStruct4', 'cfs1': 'CondFeatureStruct1', 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' } } - -# test 'features' for command - -{ 'command': 'test-command-features0', + 'cfs3': 'CondFeatureStruct3' }, 'features': [] } + { 'command': 'test-command-features1', 'features': [ 'feature1' ] } { 'command': 'test-command-features3', @@ -308,3 +320,6 @@ { 'command': 'test-command-cond-features3', 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } + +{ 'event': 'TEST-EVENT-FEATURES1', + 'features': [ 'feature1' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 9bd3c4a490..1cbd0802b3 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -387,7 +387,25 @@ object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] -object q_obj_test-features-arg +enum FeatureEnum1 + member eins + member zwei + member drei + feature feature1 +object q_obj_FeatureUnion1-base + member tag: FeatureEnum1 optional=3DFalse +object FeatureUnion1 + base q_obj_FeatureUnion1-base + tag tag + case eins: FeatureStruct1 + case zwei: q_empty + case drei: q_empty + feature feature1 +alternate FeatureAlternate1 + tag type + case eins: FeatureStruct1 + feature feature1 +object q_obj_test-features0-arg member fs0: FeatureStruct0 optional=3DFalse member fs1: FeatureStruct1 optional=3DFalse member fs2: FeatureStruct2 optional=3DFalse @@ -396,9 +414,7 @@ object q_obj_test-features-arg member cfs1: CondFeatureStruct1 optional=3DFalse member cfs2: CondFeatureStruct2 optional=3DFalse member cfs3: CondFeatureStruct3 optional=3DFalse -command test-features q_obj_test-features-arg -> None - gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse -command test-command-features0 None -> None +command test-features0 q_obj_test-features0-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse @@ -421,6 +437,9 @@ command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] +event TEST-EVENT-FEATURES1 None + boxed=3DFalse + feature feature1 module include/sub-module.json include sub-sub-module.json object SecondArrayRef diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index bee18ee344..af5b57a0b1 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -30,7 +30,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_include(self, name, info): print('include %s' % name) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): print('enum %s' % name) if prefix: print(' prefix %s' % prefix) @@ -38,6 +38,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s' % m.name) self._print_if(m.ifcond, indent=3D8) self._print_if(ifcond) + self._print_features(features) =20 def visit_array_type(self, name, info, ifcond, element_type): if not info: @@ -58,10 +59,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): print('alternate %s' % name) self._print_variants(variants) self._print_if(ifcond) + self._print_features(features) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, @@ -74,10 +76,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): print('event %s %s' % (name, arg_type and arg_type.name)) print(' boxed=3D%s' % boxed) self._print_if(ifcond) + self._print_features(features) =20 @staticmethod def _print_variants(variants): --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446958; cv=none; d=zohomail.com; s=zohoarc; b=g4MecJHVj50tnYrvTj3JnaIKESeOpgPP9fGbXozzKeN+1+CIhumFKDqBnMUmbucm9iSVBAZMyut0PebMKrFaKUnf55/WAhC8xq6FTZ9shP/xrqrmALBngpem6ETlKrZQUZaMiOL1sPJtyHOjl/2MagH3ABDSMW3kkGXbn5zwl24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446958; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p3qAHO5W0XR5q6Vn93COHS6lD/G1Y2D7BotBFtVbssw=; b=e0c72n1HXZjOeq/nIx3FExEUGmG+76+iY/YmGNivub4sHGeySY3Q57/IhhHPHT0hieYz6Iq3bn7QqY+FfU6zJEPVtfKKormJk8CNhbwWiW0C1R/YUbtA5yeKte2rVHXjcT/Qr8UBasxHYcIjR2ffjiSWPJI6TsHECXbC6tGM+kQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446958112556.3400583557577; Tue, 17 Mar 2020 05:09:18 -0700 (PDT) Received: from localhost ([::1]:59906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB24-0006uX-Vy for importer@patchew.org; Tue, 17 Mar 2020 08:09:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56940) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoc-0008Ge-C1 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoY-0006lA-5e for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:54058) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006jV-Vp for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-YJ_gNIhhPbuSLr_X_5Pbvw-1; Tue, 17 Mar 2020 07:55:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B6221922966; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5372194949; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 33DA111366F7; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p3qAHO5W0XR5q6Vn93COHS6lD/G1Y2D7BotBFtVbssw=; b=ePF4nUxSFbrQBWfaN3+2hfM1Q9LwG4zc+uC0QvdMKv2a7eSZdDVJ8hm7S6eMte7+jHI/n6 NNeREDKkkiirWxa0MCdX8yFWRSH0hf/vqsTWrc/Ep5hYE59YAOMhwnSORpRZ8/aiwrbGkm 5oy9ThLmlgLjniMx723fLUcFS7chxKY= X-MC-Unique: YJ_gNIhhPbuSLr_X_5Pbvw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 13/34] qapi: Consistently put @features parameter right after @ifcond Date: Tue, 17 Mar 2020 12:54:38 +0100 Message-Id: <20200317115459.31821-14-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- scripts/qapi/commands.py | 6 +++--- scripts/qapi/doc.py | 10 +++++----- scripts/qapi/introspect.py | 10 +++++----- scripts/qapi/schema.py | 36 ++++++++++++++++------------------ scripts/qapi/types.py | 4 ++-- scripts/qapi/visit.py | 4 ++-- tests/qapi-schema/test-qapi.py | 10 +++++----- 7 files changed, 39 insertions(+), 41 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 0e13e82989..bc30876c88 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -283,9 +283,9 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); prefix=3Dself._prefix)) self._genc.add(gen_registry(self._regy.get_content(), self._prefix= )) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): if not gen: return # FIXME: If T is a user-defined type, the user is responsible diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 36e823338b..92f584edcf 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -249,8 +249,8 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_members(doc, 'Values', member_func=3Dtexi_enum_value= ))) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): doc =3D self.cur_doc if base and base.is_implicit(): base =3D None @@ -262,9 +262,9 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): doc =3D self.cur_doc self._gen.add(texi_msg('Command', doc, ifcond, texi_arguments(doc, diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 2e9e00aa1f..b54910510d 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -193,8 +193,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, ifcond, features, + members, variants): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, @@ -209,9 +209,9 @@ const QLitObject %(c_name)s =3D %(c_string)s; for m in variants.variants]}, ifcond, features) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type obj =3D {'arg-type': self._use_type(arg_type), diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 22238005ff..958756ecd6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -115,20 +115,20 @@ class QAPISchemaVisitor: def visit_array_type(self, name, info, ifcond, element_type): pass =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): pass =20 - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, ifcond, features, + members, variants): pass =20 def visit_alternate_type(self, name, info, ifcond, features, variants): pass =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): pass =20 def visit_event(self, name, info, ifcond, features, arg_type, boxed): @@ -436,12 +436,12 @@ class QAPISchemaObjectType(QAPISchemaType): =20 def visit(self, visitor): super().visit(visitor) - visitor.visit_object_type(self.name, self.info, self.ifcond, - self.base, self.local_members, self.vari= ants, - self.features) - visitor.visit_object_type_flat(self.name, self.info, self.ifcond, - self.members, self.variants, - self.features) + visitor.visit_object_type( + self.name, self.info, self.ifcond, self.features, + self.base, self.local_members, self.variants) + visitor.visit_object_type_flat( + self.name, self.info, self.ifcond, self.features, + self.members, self.variants) =20 =20 class QAPISchemaMember: @@ -745,12 +745,10 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 def visit(self, visitor): super().visit(visitor) - visitor.visit_command(self.name, self.info, self.ifcond, - self.arg_type, self.ret_type, - self.gen, self.success_response, - self.boxed, self.allow_oob, - self.allow_preconfig, - self.features) + visitor.visit_command( + self.name, self.info, self.ifcond, self.features, + self.arg_type, self.ret_type, self.gen, self.success_response, + self.boxed, self.allow_oob, self.allow_preconfig) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index d0d5c03646..3ad33af4ee 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -289,8 +289,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 6e5ed781d7..23d9194aa4 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -326,8 +326,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index af5b57a0b1..8e09e54edb 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -46,8 +46,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('array %s %s' % (name, element_type.name)) self._print_if(ifcond) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): print('object %s' % name) if base: print(' base %s' % base.name) @@ -65,9 +65,9 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): print('command %s %s -> %s' % (name, arg_type and arg_type.name, ret_type and ret_type.name)) --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447310; cv=none; d=zohomail.com; s=zohoarc; b=S3AKaydA9N/s7+S+GgaUHwx2woYlrMOQKmGLuQkC3hgqR33LJPP+YtlPgVpAxpdkFdnXe6KXfSmfoBvqoHmrKDyjQDfx8jO3qXkhDjb3zD8Sbu/gCuqCRJyW+JIkUFS7YFLIT4GXlJIvsJMBeLniWIpH0iKdQ5xam2rxZoi8dEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447310; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=93Rwp/6Y0/ev1Q+rHH85YoKP9imLZBHWRL9X2s+GWiY=; b=dzhvlFkbi1DIrhUn5DxD+FSLgMS66D7I70QhqQBKdXF8wWiohW9/k68mA4usgnoTDowBQ4g8mxnYAV0HvQNAnGPJxzx80NkamVUDfUvSb3Os3/nrP6uTSSby0M3KEjeocQf4CZcq4qmzhQGKE75b+dke3dRPdwmuoSd9OR0mitw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447310076702.1686616148733; Tue, 17 Mar 2020 05:15:10 -0700 (PDT) Received: from localhost ([::1]:60061 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB7k-0000hq-Tz for importer@patchew.org; Tue, 17 Mar 2020 08:15:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57150) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoq-0000GN-VM for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAop-0008JG-Ei for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:36 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:46945) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAop-0008Gd-98 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-TYtK9f7CNgyINIfIAsQ6iQ-1; Tue, 17 Mar 2020 07:55:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C56051005513; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 560E110027A8; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3E4B9113639C; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=93Rwp/6Y0/ev1Q+rHH85YoKP9imLZBHWRL9X2s+GWiY=; b=E8oaecmAymIJIzcutlO+Npr2hLXZ3qt1b8kiT/HSKT1QRLikVEN+PDIv9bUAf11X0XhH7M nDU2F946rSQZSgq7nZo57956fFtEw+kFaUQ3g2GNddwPDFP+7E4WsJdyjyaLoWp8U6P7Kn m7kZAAp5GWIJyYPw2gBbg9Ikcg9oUVE= X-MC-Unique: TYtK9f7CNgyINIfIAsQ6iQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 14/34] qapi/introspect: Rename *qlit* to reduce confusion Date: Tue, 17 Mar 2020 12:54:39 +0100 Message-Id: <20200317115459.31821-15-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We generate the value of qmp_schema_qlit from an expression tree. The function doing that is named to_qlit(), and its inputs are accumulated in QAPISchemaGenIntrospectVisitor._qlits. We call both its input and its output "qlit". This is confusing. Use "tree" for input, and "qlit" only for output: rename to_qlit() to _tree_to_qlit(), ._qlits to ._trees, ._gen_qlit() to ._gen_tree(). Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/introspect.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b54910510d..e4fc9d90f1 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -16,7 +16,7 @@ from qapi.schema import (QAPISchemaArrayType, QAPISchemaB= uiltinType, QAPISchemaType) =20 =20 -def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): +def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): =20 def indent(level): return level * 4 * ' ' @@ -30,7 +30,7 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse= ): ret +=3D indent(level) + '/* %s */\n' % comment if ifcond: ret +=3D gen_if(ifcond) - ret +=3D to_qlit(ifobj, level) + ret +=3D _tree_to_qlit(ifobj, level) if ifcond: ret +=3D '\n' + gen_endif(ifcond) return ret @@ -43,7 +43,7 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse= ): elif isinstance(obj, str): ret +=3D 'QLIT_QSTR(' + to_c_string(obj) + ')' elif isinstance(obj, list): - elts =3D [to_qlit(elt, level + 1).strip('\n') + elts =3D [_tree_to_qlit(elt, level + 1).strip('\n') for elt in obj] elts.append(indent(level + 1) + "{}") ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' @@ -53,7 +53,8 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse= ): elts =3D [] for key, value in sorted(obj.items()): elts.append(indent(level + 1) + '{ %s, %s }' % - (to_c_string(key), to_qlit(value, level + 1, True)= )) + (to_c_string(key), + _tree_to_qlit(value, level + 1, True))) elts.append(indent(level + 1) + '{}') ret +=3D 'QLIT_QDICT(((QLitDictEntry[]) {\n' ret +=3D ',\n'.join(elts) + '\n' @@ -79,7 +80,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithic= CVisitor): ' * QAPI/QMP schema introspection', __doc__) self._unmask =3D unmask self._schema =3D None - self._qlits =3D [] + self._trees =3D [] self._used_types =3D [] self._name_map =3D {} self._genc.add(mcgen(''' @@ -108,9 +109,9 @@ extern const QLitObject %(c_name)s; const QLitObject %(c_name)s =3D %(c_string)s; ''', c_name=3Dc_name(name), - c_string=3Dto_qlit(self._qlits))) + c_string=3D_tree_to_qlit(self._trees))) self._schema =3D None - self._qlits =3D [] + self._trees =3D [] self._used_types =3D [] self._name_map =3D {} =20 @@ -144,7 +145,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 - def _gen_qlit(self, name, mtype, obj, ifcond, features): + def _gen_tree(self, name, mtype, obj, ifcond, features): extra =3D {} if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -159,9 +160,9 @@ const QLitObject %(c_name)s =3D %(c_string)s; if ifcond: extra['if'] =3D ifcond if extra: - self._qlits.append((obj, extra)) + self._trees.append((obj, extra)) else: - self._qlits.append(obj) + self._trees.append(obj) =20 def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -180,17 +181,17 @@ const QLitObject %(c_name)s =3D %(c_string)s; {'if': variant.ifcond}) =20 def visit_builtin_type(self, name, info, json_type): - self._gen_qlit(name, 'builtin', {'json-type': json_type}, [], None) + self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): - self._gen_qlit(name, 'enum', + self._gen_tree(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) - self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, + self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 def visit_object_type_flat(self, name, info, ifcond, features, @@ -200,10 +201,10 @@ const QLitObject %(c_name)s =3D %(c_string)s; obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) =20 - self._gen_qlit(name, 'object', obj, ifcond, features) + self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name, info, ifcond, features, variants): - self._gen_qlit(name, 'alternate', + self._gen_tree(name, 'alternate', {'members': [ ({'type': self._use_type(m.type)}, {'if': m.ifc= ond}) for m in variants.variants]}, @@ -218,11 +219,11 @@ const QLitObject %(c_name)s =3D %(c_string)s; 'ret-type': self._use_type(ret_type)} if allow_oob: obj['allow-oob'] =3D allow_oob - self._gen_qlit(name, 'command', obj, ifcond, features) + self._gen_tree(name, 'command', obj, ifcond, features) =20 def visit_event(self, name, info, ifcond, features, arg_type, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type - self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}, + self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) =20 =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447363; cv=none; d=zohomail.com; s=zohoarc; b=AJEvFJOFqhUypszb56QQQA3Hw8+1Ajy1AwJWwCJ8++6CPUYWqJ/4r9Zd8d1QsXdLxmIpXof94gbtBcwWy2r0lxb/uHB7yNgzu2k8obDh+VCplORpi7DaQCRCWEDLGgF9u7paJlXhlTdJ86jCXJ2WgtVbIhKBADa9IlEJ7ffAdIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447363; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bBypn0WmvXJtvIQptVIylzIgB0vIczmMxB341Fjd2io=; b=cFgOCF1qhzSVmZYfk3DkB28y5VR1BlsGiOPtgW8MGdGCAqkEV/5r79D6aGBLLxaDItcmkBP4gpRCzec2nqX32IEV8nJzKAzSgjL6gQ8DZl7x2dZXkBparOibHVhKuscZ1y0Y3fBZY0IXflH3GAbq8bSbuxdexxfkPwX83DHs5Hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447363599804.6739240053668; Tue, 17 Mar 2020 05:16:03 -0700 (PDT) Received: from localhost ([::1]:60080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB8c-0002hU-E0 for importer@patchew.org; Tue, 17 Mar 2020 08:16:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57130) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAop-0000Da-JI for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoo-0008Bh-6j for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:35 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:25018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoo-00088A-1G for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170--MrmuDgPOx6XBG97CtHW5g-1; Tue, 17 Mar 2020 07:55:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6527E8024F4; Tue, 17 Mar 2020 11:55:17 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B257E92D5C; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 432191135A56; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bBypn0WmvXJtvIQptVIylzIgB0vIczmMxB341Fjd2io=; b=WDw3FaX2cOEeeQ5pzJ1THgWWcFhVKYz7sVOIRnimLhny3xpr4vNSw8hkD33OMKQOeTjB2a RiSq4Qa1Q4LKzqlQ3ysIK06R4CDhu3fJ9FYRKQfZnknOXoBaMy6S8psgrBbCl+yW3OZk0X hDog3fY8p2edomstcwC/ln+hVwb/EjM= X-MC-Unique: -MrmuDgPOx6XBG97CtHW5g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 15/34] qapi/introspect: Factor out _make_tree() Date: Tue, 17 Mar 2020 12:54:40 +0100 Message-Id: <20200317115459.31821-16-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The value of @qmp_schema_qlit is generated from an expression tree. Tree nodes are created in several places. Factor out the common code into _make_tree(). This isn't much of a win now. It will pay off when we add feature flags in the next few commits. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/introspect.py | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e4fc9d90f1..a3fa9865db 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -16,6 +16,18 @@ from qapi.schema import (QAPISchemaArrayType, QAPISchema= BuiltinType, QAPISchemaType) =20 =20 +def _make_tree(obj, ifcond, features, extra=3DNone): + if extra is None: + extra =3D {} + if ifcond: + extra['if'] =3D ifcond + if features: + obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in features] + if extra: + return (obj, extra) + return obj + + def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): =20 def indent(level): @@ -146,47 +158,38 @@ const QLitObject %(c_name)s =3D %(c_string)s; return self._name(typ.name) =20 def _gen_tree(self, name, mtype, obj, ifcond, features): - extra =3D {} + extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra['comment'] =3D '"%s" =3D %s' % (self._name(name), na= me) + extra =3D {'comment': '"%s" =3D %s' % (self._name(name), n= ame)} name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] - if ifcond: - extra['if'] =3D ifcond - if extra: - self._trees.append((obj, extra)) - else: - self._trees.append(obj) + self._trees.append(_make_tree(obj, ifcond, features, extra)) =20 def _gen_member(self, member): - ret =3D {'name': member.name, 'type': self._use_type(member.type)} + obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: - ret['default'] =3D None - if member.ifcond: - ret =3D (ret, {'if': member.ifcond}) - return ret + obj['default'] =3D None + return _make_tree(obj, member.ifcond, None) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} =20 def _gen_variant(self, variant): - return ({'case': variant.name, 'type': self._use_type(variant.type= )}, - {'if': variant.ifcond}) + obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} + return _make_tree(obj, variant.ifcond, None) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): self._gen_tree(name, 'enum', - {'values': - [(m.name, {'if': m.ifcond}) for m in members]}, + {'values': [_make_tree(m.name, m.ifcond, None) + for m in members]}, ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -206,7 +209,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_tree(name, 'alternate', {'members': [ - ({'type': self._use_type(m.type)}, {'if': m.ifc= ond}) + _make_tree({'type': self._use_type(m.type)}, + m.ifcond, None) for m in variants.variants]}, ifcond, features) =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446453; cv=none; d=zohomail.com; s=zohoarc; b=FKjQGrm0mloVHCebpQwJw+pOndxStC8Xl87RdgrOAZhUj2qCQFZoIhqPJ4qtba7UV5i5PRzEGLOHqxeUrUwM7hksh+fxHYa6wmdZb8Sf82anZUcY06tY4pBxZebhZShMlHj1u7FZ5iA89zIP1xmSwWwPHNdlVXzP/MYwLWDqEkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446453; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=deHWtMLcOFVqmfety9mvhUjyvqnRYqCfdMv/VU5iTRQ=; b=PaxftexDlF3HA3P2ElCykqd6qvjejcfX20Mqd4UNk6VX5uaQ1kAbz6+QvIf6ApvKoZEJwgSZ3EFtAvxIQ/opk6Cx0U+DWugVebzFQMHoIQxGawZ3vKMVI+5Q3lKag/UwPRzD3Vrtz2PL7CqwriPHImH34ezOPlQrbhBmqHIL44M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446453208945.3156916951208; Tue, 17 Mar 2020 05:00:53 -0700 (PDT) Received: from localhost ([::1]:59702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAtt-00085B-5L for importer@patchew.org; Tue, 17 Mar 2020 08:00:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56731) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoV-000831-Ki for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoU-0006K7-22 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:15 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:52802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoT-0006H3-Sl for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-cL444LzyOvCr-0-BUk0Clg-1; Tue, 17 Mar 2020 07:55:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB7CA1034B05; Tue, 17 Mar 2020 11:55:10 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3CCB9129A; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 47C831135A59; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=deHWtMLcOFVqmfety9mvhUjyvqnRYqCfdMv/VU5iTRQ=; b=ZqrjliA070QOckY++isPr0JQ3F/3I4iX/Am2EFesZuNyiyFS8Pctr2z10uI7KZ4ClXKJkm PZXQUyE8+B2coU8dES4fbt6cHseybl+pJZAGdaUVuDHJ9slSzowPEiMeppaXflJ3T7gDhv CgLz+yCurkzW5RDCI3cnJOJ9mmNPT7w= X-MC-Unique: cL444LzyOvCr-0-BUk0Clg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 16/34] qapi/schema: Change _make_features() to a take feature list Date: Tue, 17 Mar 2020 12:54:41 +0100 Message-Id: <20200317115459.31821-17-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QAPISchema._make_features() takes a definition expression, and extracts its 'features' member. The other ._make_FOO() leave destructuring expressions to their callers. Change ._make_features() to match them. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/schema.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 958756ecd6..4d8ad67303 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -904,8 +904,9 @@ class QAPISchema: self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, qtype_values, 'QTYPE')) =20 - def _make_features(self, expr, info): - features =3D expr.get('features', []) + def _make_features(self, features, info): + if features is None: + return [] return [QAPISchemaFeature(f['name'], info, f.get('if')) for f in features] =20 @@ -955,7 +956,7 @@ class QAPISchema: data =3D expr['data'] prefix =3D expr.get('prefix') ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaEnumType( name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix)) @@ -979,7 +980,7 @@ class QAPISchema: base =3D expr.get('base') data =3D expr['data'] ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaObjectType( name, info, doc, ifcond, features, base, self._make_members(data, info), @@ -1002,7 +1003,7 @@ class QAPISchema: data =3D expr['data'] base =3D expr.get('base') ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): @@ -1032,7 +1033,7 @@ class QAPISchema: name =3D expr['alternate'] data =3D expr['data'] ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) variants =3D [self._make_variant(key, value['type'], value.get('if= '), info) for (key, value) in data.items()] @@ -1052,7 +1053,7 @@ class QAPISchema: allow_oob =3D expr.get('allow-oob', False) allow_preconfig =3D expr.get('allow-preconfig', False) ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( name, info, ifcond, @@ -1070,7 +1071,7 @@ class QAPISchema: data =3D expr.get('data') boxed =3D expr.get('boxed', False) ifcond =3D expr.get('if') - features =3D self._make_features(expr, info) + features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( name, info, ifcond, --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447004; cv=none; d=zohomail.com; s=zohoarc; b=mKBbcllTe/5zY135U1Ma5Aq2Xh+OUAyWbQoMJzeJ7vJg0vSHqT6OUD+MUemcDHvwRXUL3Xsp77haVa5oU9ZmvbXxdVYraLANrBDMu01cIGcxcDn/lY7/9o6Ck+MQlN/dFR4ES3eDfqbSLO9CXGECQwzJm6oJdSiOrsa4TnxAAmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447004; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TgGX4lIj7YKgm+EM+OXuKQ+G5357jqiXMJoldM3tJc0=; b=IA+1u4c5JrbbkYoC3o95Tl4L78KmLCMftpkWn7RWHQqbPQEzriQmV9b93H1iL8iQGoZ5wA9+Lr3QUCsVQdZn6CQAFRlRGn318z3EgI8uEM6NvHaVX7Ko6S7TQf7ZxQA/vE672pp9e/IYVg43lcBy1QUiyyXBsW0kHFbFLoJBCug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447004717615.6143067670108; Tue, 17 Mar 2020 05:10:04 -0700 (PDT) Received: from localhost ([::1]:59926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB2p-0000JF-IE for importer@patchew.org; Tue, 17 Mar 2020 08:10:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56907) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAob-0008Fk-QC for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006j4-Ls for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:21 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:34874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006eN-E0 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-0cPnYk0lMemdirjy5Z8VbA-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19D11801E66; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F25AE9129E; Tue, 17 Mar 2020 11:55:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4CD041135A5A; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TgGX4lIj7YKgm+EM+OXuKQ+G5357jqiXMJoldM3tJc0=; b=V524NYvmBbPMzxbjTE48kkPImgwmS1xy/YNaODeth00R60JVY/9Y0iaQ2Y+3XKV7s/uJab AFG6u7U9FvT8AmkPV380RaXx6pV9F3Bwc5rqQLti4L4H9BusK7S5Kf1V78yseH7cr8C22f +bNe1tXnjhj5gtNYFKh3xTiDS1YeteE= X-MC-Unique: 0cPnYk0lMemdirjy5Z8VbA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 17/34] qapi/schema: Reorder classes so related ones are together Date: Tue, 17 Mar 2020 12:54:42 +0100 Message-Id: <20200317115459.31821-18-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move QAPISchemaAlternateType up some, so that all QAPISchemaFOOType are together. Move QAPISchemaObjectTypeVariants right behind its users. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 284 ++++++++++++++++++++--------------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 4d8ad67303..0acf8b466f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -444,82 +444,72 @@ class QAPISchemaObjectType(QAPISchemaType): self.members, self.variants) =20 =20 -class QAPISchemaMember: - """ Represents object members, enum members and features """ - role =3D 'member' - - def __init__(self, name, info, ifcond=3DNone): - assert isinstance(name, str) - self.name =3D name - self.info =3D info - self.ifcond =3D ifcond or [] - self.defined_in =3D None - - def set_defined_in(self, name): - assert not self.defined_in - self.defined_in =3D name - - def check_clash(self, info, seen): - cname =3D c_name(self.name) - if cname in seen: - raise QAPISemError( - info, - "%s collides with %s" - % (self.describe(info), seen[cname].describe(info))) - seen[cname] =3D self - - def describe(self, info): - role =3D self.role - defined_in =3D self.defined_in - assert defined_in - - if defined_in.startswith('q_obj_'): - # See QAPISchema._make_implicit_object_type() - reverse the - # mapping there to create a nice human-readable description - defined_in =3D defined_in[6:] - if defined_in.endswith('-arg'): - # Implicit type created for a command's dict 'data' - assert role =3D=3D 'member' - role =3D 'parameter' - elif defined_in.endswith('-base'): - # Implicit type created for a flat union's dict 'base' - role =3D 'base ' + role - else: - # Implicit type created for a simple union's branch - assert defined_in.endswith('-wrapper') - # Unreachable and not implemented - assert False - elif defined_in.endswith('Kind'): - # See QAPISchema._make_implicit_enum_type() - # Implicit enum created for simple union's branches - assert role =3D=3D 'value' - role =3D 'branch' - elif defined_in !=3D info.defn_name: - return "%s '%s' of type '%s'" % (role, self.name, defined_in) - return "%s '%s'" % (role, self.name) - - -class QAPISchemaEnumMember(QAPISchemaMember): - role =3D 'value' - - -class QAPISchemaFeature(QAPISchemaMember): - role =3D 'feature' - - -class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=3DNone): - super().__init__(name, info, ifcond) - assert isinstance(typ, str) - assert isinstance(optional, bool) - self._type_name =3D typ - self.type =3D None - self.optional =3D optional +class QAPISchemaAlternateType(QAPISchemaType): + meta =3D 'alternate' + + def __init__(self, name, info, doc, ifcond, features, variants): + super().__init__(name, info, doc, ifcond, features) + assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert variants.tag_member + variants.set_defined_in(name) + variants.tag_member.set_defined_in(self.name) + self.variants =3D variants =20 def check(self, schema): - assert self.defined_in - self.type =3D schema.resolve_type(self._type_name, self.info, - self.describe) + super().check(schema) + self.variants.tag_member.check(schema) + # Not calling self.variants.check_clash(), because there's nothing + # to clash with + self.variants.check(schema, {}) + # Alternate branch names have no relation to the tag enum values; + # so we have to check for potential name collisions ourselves. + seen =3D {} + types_seen =3D {} + for v in self.variants.variants: + v.check_clash(self.info, seen) + qtype =3D v.type.alternate_qtype() + if not qtype: + raise QAPISemError( + self.info, + "%s cannot use %s" + % (v.describe(self.info), v.type.describe())) + conflicting =3D set([qtype]) + if qtype =3D=3D 'QTYPE_QSTRING': + if isinstance(v.type, QAPISchemaEnumType): + for m in v.type.members: + if m.name in ['on', 'off']: + conflicting.add('QTYPE_QBOOL') + if re.match(r'[-+0-9.]', m.name): + # lazy, could be tightened + conflicting.add('QTYPE_QNUM') + else: + conflicting.add('QTYPE_QNUM') + conflicting.add('QTYPE_QBOOL') + for qt in conflicting: + if qt in types_seen: + raise QAPISemError( + self.info, + "%s can't be distinguished from '%s'" + % (v.describe(self.info), types_seen[qt])) + types_seen[qt] =3D v.name + + def connect_doc(self, doc=3DNone): + super().connect_doc(doc) + doc =3D doc or self.doc + if doc: + for v in self.variants.variants: + doc.connect_member(v) + + def c_type(self): + return c_name(self.name) + pointer_suffix + + def json_type(self): + return 'value' + + def visit(self, visitor): + super().visit(visitor) + visitor.visit_alternate_type( + self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 class QAPISchemaObjectTypeVariants: @@ -613,6 +603,84 @@ class QAPISchemaObjectTypeVariants: v.type.check_clash(info, dict(seen)) =20 =20 +class QAPISchemaMember: + """ Represents object members, enum members and features """ + role =3D 'member' + + def __init__(self, name, info, ifcond=3DNone): + assert isinstance(name, str) + self.name =3D name + self.info =3D info + self.ifcond =3D ifcond or [] + self.defined_in =3D None + + def set_defined_in(self, name): + assert not self.defined_in + self.defined_in =3D name + + def check_clash(self, info, seen): + cname =3D c_name(self.name) + if cname in seen: + raise QAPISemError( + info, + "%s collides with %s" + % (self.describe(info), seen[cname].describe(info))) + seen[cname] =3D self + + def describe(self, info): + role =3D self.role + defined_in =3D self.defined_in + assert defined_in + + if defined_in.startswith('q_obj_'): + # See QAPISchema._make_implicit_object_type() - reverse the + # mapping there to create a nice human-readable description + defined_in =3D defined_in[6:] + if defined_in.endswith('-arg'): + # Implicit type created for a command's dict 'data' + assert role =3D=3D 'member' + role =3D 'parameter' + elif defined_in.endswith('-base'): + # Implicit type created for a flat union's dict 'base' + role =3D 'base ' + role + else: + # Implicit type created for a simple union's branch + assert defined_in.endswith('-wrapper') + # Unreachable and not implemented + assert False + elif defined_in.endswith('Kind'): + # See QAPISchema._make_implicit_enum_type() + # Implicit enum created for simple union's branches + assert role =3D=3D 'value' + role =3D 'branch' + elif defined_in !=3D info.defn_name: + return "%s '%s' of type '%s'" % (role, self.name, defined_in) + return "%s '%s'" % (role, self.name) + + +class QAPISchemaEnumMember(QAPISchemaMember): + role =3D 'value' + + +class QAPISchemaFeature(QAPISchemaMember): + role =3D 'feature' + + +class QAPISchemaObjectTypeMember(QAPISchemaMember): + def __init__(self, name, info, typ, optional, ifcond=3DNone): + super().__init__(name, info, ifcond) + assert isinstance(typ, str) + assert isinstance(optional, bool) + self._type_name =3D typ + self.type =3D None + self.optional =3D optional + + def check(self, schema): + assert self.defined_in + self.type =3D schema.resolve_type(self._type_name, self.info, + self.describe) + + class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 @@ -620,74 +688,6 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectType= Member): super().__init__(name, info, typ, False, ifcond) =20 =20 -class QAPISchemaAlternateType(QAPISchemaType): - meta =3D 'alternate' - - def __init__(self, name, info, doc, ifcond, features, variants): - super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaObjectTypeVariants) - assert variants.tag_member - variants.set_defined_in(name) - variants.tag_member.set_defined_in(self.name) - self.variants =3D variants - - def check(self, schema): - super().check(schema) - self.variants.tag_member.check(schema) - # Not calling self.variants.check_clash(), because there's nothing - # to clash with - self.variants.check(schema, {}) - # Alternate branch names have no relation to the tag enum values; - # so we have to check for potential name collisions ourselves. - seen =3D {} - types_seen =3D {} - for v in self.variants.variants: - v.check_clash(self.info, seen) - qtype =3D v.type.alternate_qtype() - if not qtype: - raise QAPISemError( - self.info, - "%s cannot use %s" - % (v.describe(self.info), v.type.describe())) - conflicting =3D set([qtype]) - if qtype =3D=3D 'QTYPE_QSTRING': - if isinstance(v.type, QAPISchemaEnumType): - for m in v.type.members: - if m.name in ['on', 'off']: - conflicting.add('QTYPE_QBOOL') - if re.match(r'[-+0-9.]', m.name): - # lazy, could be tightened - conflicting.add('QTYPE_QNUM') - else: - conflicting.add('QTYPE_QNUM') - conflicting.add('QTYPE_QBOOL') - for qt in conflicting: - if qt in types_seen: - raise QAPISemError( - self.info, - "%s can't be distinguished from '%s'" - % (v.describe(self.info), types_seen[qt])) - types_seen[qt] =3D v.name - - def connect_doc(self, doc=3DNone): - super().connect_doc(doc) - doc =3D doc or self.doc - if doc: - for v in self.variants.variants: - doc.connect_member(v) - - def c_type(self): - return c_name(self.name) + pointer_suffix - - def json_type(self): - return 'value' - - def visit(self, visitor): - super().visit(visitor) - visitor.visit_alternate_type( - self.name, self.info, self.ifcond, self.features, self.variant= s) - - class QAPISchemaCommand(QAPISchemaEntity): meta =3D 'command' =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446734; cv=none; d=zohomail.com; s=zohoarc; b=PlzzxGZJ/pLQ2fqhaqNRcpJ3J41sZK9JJpcYB6nKEy4iwLL/Tw5vYbdOcoOuwJ1Yyp56SlEhxDhJKiLoZDAFU5+QeeaS8wDS995aHBFQv+FHapgMavuZ2bbLNsR0xnsF0iuynrLLgbomzEk1Wemld7ac7YS/FfJvKbkFv7UK/f4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446734; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=une4xGgZT160EAMFqaHMHMGsITsc/Uj+p02OpPoV6pY=; b=RzDBraoDKspRHBU1JrwqQ1THnlsRoh3/LDaaDK0rjJER7iMwVqKBpjww7RXFuCa82gMHRyiHXCiNSXl5rzl9mNX94e16gokx9MChZwZnG2mhqNfkWHSzmlxZQksOeI8H2iNpJrACPnE6UdAH96lfJcDNOukjQisUfbumcsK4/y8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446734691399.2359860189905; Tue, 17 Mar 2020 05:05:34 -0700 (PDT) Received: from localhost ([::1]:59790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAyT-0007dL-FV for importer@patchew.org; Tue, 17 Mar 2020 08:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56856) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoa-0008CR-48 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoY-0006ky-4Z for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:55690) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006iO-U1 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-LxPzqZIdMuWAKNfUjF0xrw-1; Tue, 17 Mar 2020 07:55:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4CBF149CC; Tue, 17 Mar 2020 11:55:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 035091E4; Tue, 17 Mar 2020 11:55:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 519041135A63; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=une4xGgZT160EAMFqaHMHMGsITsc/Uj+p02OpPoV6pY=; b=RQAwenG/uqiPCWshO3x4uca2GTmNWZ39YauQS7jhQ+sP8uzoHyVHnpxxLZe4zeLUOdkf70 wLOmaR4Re0pxURP8XAQhrptnDl2UhfbBMZGR8tjWceTX7ODn6vCLsDO/3heG2knWKmv9Zo idUooCJmCyJMVoG6Z62gZKwe4NBM6jg= X-MC-Unique: LxPzqZIdMuWAKNfUjF0xrw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 18/34] qapi/schema: Rename QAPISchemaObjectType{Variant, Variants} Date: Tue, 17 Mar 2020 12:54:43 +0100 Message-Id: <20200317115459.31821-19-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QAPISchemaObjectTypeVariants represents both object type and alternate type variants. Rename to QAPISchemaVariants. Rename QAPISchemaObjectTypeVariant the same way. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 0acf8b466f..033c84c4a0 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -338,7 +338,7 @@ class QAPISchemaObjectType(QAPISchemaType): assert isinstance(m, QAPISchemaObjectTypeMember) m.set_defined_in(name) if variants is not None: - assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert isinstance(variants, QAPISchemaVariants) variants.set_defined_in(name) self._base_name =3D base self.base =3D None @@ -449,7 +449,7 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 def __init__(self, name, info, doc, ifcond, features, variants): super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert isinstance(variants, QAPISchemaVariants) assert variants.tag_member variants.set_defined_in(name) variants.tag_member.set_defined_in(self.name) @@ -512,7 +512,7 @@ class QAPISchemaAlternateType(QAPISchemaType): self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 -class QAPISchemaObjectTypeVariants: +class QAPISchemaVariants: def __init__(self, tag_name, info, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name. @@ -522,7 +522,7 @@ class QAPISchemaObjectTypeVariants: assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember)) for v in variants: - assert isinstance(v, QAPISchemaObjectTypeVariant) + assert isinstance(v, QAPISchemaVariant) self._tag_name =3D tag_name self.info =3D info self.tag_member =3D tag_member @@ -572,8 +572,8 @@ class QAPISchemaObjectTypeVariants: cases =3D {v.name for v in self.variants} for m in self.tag_member.type.members: if m.name not in cases: - v =3D QAPISchemaObjectTypeVariant(m.name, self.info, - 'q_empty', m.ifcond) + v =3D QAPISchemaVariant(m.name, self.info, + 'q_empty', m.ifcond) v.set_defined_in(self.tag_member.defined_in) self.variants.append(v) if not self.variants: @@ -681,7 +681,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): self.describe) =20 =20 -class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): +class QAPISchemaVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 def __init__(self, name, info, typ, ifcond=3DNone): @@ -987,7 +987,7 @@ class QAPISchema: None)) =20 def _make_variant(self, case, typ, ifcond, info): - return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) + return QAPISchemaVariant(case, info, typ, ifcond) =20 def _make_simple_variant(self, case, typ, ifcond, info): if isinstance(typ, list): @@ -996,7 +996,7 @@ class QAPISchema: typ =3D self._make_implicit_object_type( typ, info, self.lookup_type(typ), 'wrapper', [self._make_member('data', typ, None, info)]) - return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) + return QAPISchemaVariant(case, info, typ, ifcond) =20 def _def_union_type(self, expr, info, doc): name =3D expr['union'] @@ -1026,7 +1026,7 @@ class QAPISchema: self._def_entity( QAPISchemaObjectType(name, info, doc, ifcond, features, base, members, - QAPISchemaObjectTypeVariants( + QAPISchemaVariants( tag_name, info, tag_member, variants)= )) =20 def _def_alternate_type(self, expr, info, doc): @@ -1040,7 +1040,7 @@ class QAPISchema: tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) self._def_entity( QAPISchemaAlternateType(name, info, doc, ifcond, features, - QAPISchemaObjectTypeVariants( + QAPISchemaVariants( None, info, tag_member, variants))) =20 def _def_command(self, expr, info, doc): --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446908; cv=none; d=zohomail.com; s=zohoarc; b=X4efyQGwBKjjqvlR2uBaWecxbX+9MX4RB/rF64zGm5gHGMLW949CZC82kbVcDg6Ym4VTGh0K5Pgj8l86/Wt4BZMstZeYrRaFdRyi6uXkNHe7F4w7AM/Of8/JrLGhyQr3zhcUKAfqXsn2aPshdKj9Okb5BOol29BkpwOeloimkDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446908; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FBfqP4hIPTb5VFxn3RgdzfQuJ8b0Cqp1te5HxvWNdPg=; b=koy1rJ3BXbJxsXdUL/Mq7iex7uwzL4iXXDSHZ8RlF4XV/HfxFEjrvdG8JHvyYvEFXUzB8D011pQlxun1you2xnj2WkZX9w/kDSseJkxF3rpwrzX1DPrmp9dYbclpgELH/vWLMFjBCfMGdqaSspi89n3qy+8HSdIA3yY7Q3t9fcI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446908117668.7559643496046; Tue, 17 Mar 2020 05:08:28 -0700 (PDT) Received: from localhost ([::1]:59866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB1H-0005SS-11 for importer@patchew.org; Tue, 17 Mar 2020 08:08:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56953) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoc-0008HG-Ng for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoa-0006xg-9o for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:27021) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoa-0006tf-1h for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-BHfKcf89OIm2WFtKGZJOLw-1; Tue, 17 Mar 2020 07:55:17 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB153100DFDE; Tue, 17 Mar 2020 11:55:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0818519757; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 564EA1135A64; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446119; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FBfqP4hIPTb5VFxn3RgdzfQuJ8b0Cqp1te5HxvWNdPg=; b=giCwWzPdH5ZhbBHNbay5TBGvOWTW0XSk3wrhp1X6bUt8RDjbhbXlxSf3JIkIV9x6XS0qk/ 9aZa4x43HCWzWHUbVJ8HsWyBU2RdEO4j6evFtKr06pCIk1rSL+jPVIeYnFyWeVOmeMdhro VRBqFol9GcZgnclrcgRF+z1dNg/HnYc= X-MC-Unique: BHfKcf89OIm2WFtKGZJOLw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 19/34] qapi/schema: Call QAPIDoc.connect_member() in just one place Date: Tue, 17 Mar 2020 12:54:44 +0100 Message-Id: <20200317115459.31821-20-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The .connect_doc() of classes that have QAPISchemaMember connect them to their documentation. Change them to delegate the actual work to new QAPISchemaMember.connect_doc(). Matches the .connect_doc() that already exist. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 033c84c4a0..59e1f5a395 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -252,9 +252,8 @@ class QAPISchemaEnumType(QAPISchemaType): def connect_doc(self, doc=3DNone): super().connect_doc(doc) doc =3D doc or self.doc - if doc: - for m in self.members: - doc.connect_member(m) + for m in self.members: + m.connect_doc(doc) =20 def is_implicit(self): # See QAPISchema._make_implicit_enum_type() and ._def_predefineds() @@ -396,11 +395,10 @@ class QAPISchemaObjectType(QAPISchemaType): def connect_doc(self, doc=3DNone): super().connect_doc(doc) doc =3D doc or self.doc - if doc: - if self.base and self.base.is_implicit(): - self.base.connect_doc(doc) - for m in self.local_members: - doc.connect_member(m) + if self.base and self.base.is_implicit(): + self.base.connect_doc(doc) + for m in self.local_members: + m.connect_doc(doc) =20 @property def ifcond(self): @@ -496,9 +494,8 @@ class QAPISchemaAlternateType(QAPISchemaType): def connect_doc(self, doc=3DNone): super().connect_doc(doc) doc =3D doc or self.doc - if doc: - for v in self.variants.variants: - doc.connect_member(v) + for v in self.variants.variants: + v.connect_doc(doc) =20 def c_type(self): return c_name(self.name) + pointer_suffix @@ -627,6 +624,10 @@ class QAPISchemaMember: % (self.describe(info), seen[cname].describe(info))) seen[cname] =3D self =20 + def connect_doc(self, doc): + if doc: + doc.connect_member(self) + def describe(self, info): role =3D self.role defined_in =3D self.defined_in --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447173; cv=none; d=zohomail.com; s=zohoarc; b=SuRGVtmDdWHucO86kCgtRF+N9So6PdKXw4mUzDhh/LQe1umehwTRZDP3S5LKkqoNNx2EIjhKGzzKy6f4hW9LB3KAsSzdiugn/OECrwKS/m1GuHldVnUp1hrEZcyzr8KCUsjL3yWM4J8PyRjk8ZUmFVAMExZLTFRdW/jCr/to5sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447173; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VpWeiBGxvTJjSpS1IhpBA3HU0RqRXGBUXMMDPDGdbRI=; b=WWGbMsCjUtb8J1Eq5/QKmOo7tIMyVP1mtgWe7ZOcsq/dr+6ihDgsAW+1WBxzKCZb4sNz5hy4usEjJjcfO5809u/SJ8Wc7U/Z5YB0kqXcRrPNcwQEwUBtsLQJQfLqGVWkzLm3xxjitdHEz/rHhIJDwN2sDaeig1iWvtyZPf8wPhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15844471736301018.9828317418621; Tue, 17 Mar 2020 05:12:53 -0700 (PDT) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB5Y-0005lQ-GY for importer@patchew.org; Tue, 17 Mar 2020 08:12:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57114) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoo-0000BJ-Gp for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAom-00081D-DQ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:34 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:30666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAom-0007yd-82 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-258-b1FDJLOUNQqiDNNz7EpzCw-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9763B801E6C; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 108BF1036B47; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5BD2E1135A70; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VpWeiBGxvTJjSpS1IhpBA3HU0RqRXGBUXMMDPDGdbRI=; b=ftZUDmrltILwRFCGRPwib8iRptLPHJqoRd56sMiEB7OVS8hzIfGWnkVKi7VbfMBdai2yZh EALLCta3CQym5vvQqe2LMstLK4EDz6e1e9qZbq31JYccpXNcYjAly5HQFpmQCdYprGcdbE kX7GVBFd2cJ2jcXeQTYllEZQ948OLBA= X-MC-Unique: b1FDJLOUNQqiDNNz7EpzCw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 20/34] qapi: Add feature flags to struct members Date: Tue, 17 Mar 2020 12:54:45 +0100 Message-Id: <20200317115459.31821-21-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 4 +++- tests/qapi-schema/doc-good.texi | 2 ++ qapi/introspect.json | 6 +++++- scripts/qapi/expr.py | 3 ++- scripts/qapi/introspect.py | 2 +- scripts/qapi/schema.py | 25 ++++++++++++++++++++----- tests/qapi-schema/doc-good.json | 5 ++++- tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 1 + tests/qapi-schema/test-qapi.py | 7 ++++--- 11 files changed, 46 insertions(+), 14 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 9fce78dcad..a1ef1cfd61 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -234,7 +234,9 @@ Syntax: '*features': FEATURES } MEMBERS =3D { MEMBER, ... } MEMBER =3D STRING : TYPE-REF - | STRING : { 'type': TYPE-REF, '*if': COND } + | STRING : { 'type': TYPE-REF, + '*if': COND, + '*features': FEATURES } =20 Member 'struct' names the struct type. =20 diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index 76b396dae6..7f28fb7a0f 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -132,6 +132,8 @@ Not documented @table @asis @item @code{variant1-feat} a feature +@item @code{member-feat} +a member feature @end table =20 @end deftp diff --git a/qapi/introspect.json b/qapi/introspect.json index da3e176899..b1aabd4cfd 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -206,11 +206,15 @@ # Future extension: if present and non-null, the parameter # is optional, and defaults to this value. # +# @features: names of features associated with the member, in no +# particular order. (since 5.0) +# # Since: 2.5 ## { 'struct': 'SchemaInfoObjectMember', - 'data': { 'name': 'str', 'type': 'str', '*default': 'any' } } + 'data': { 'name': 'str', 'type': 'str', '*default': 'any', # @default's type must be null or match @type + '*features': [ 'str' ] } } =20 ## # @SchemaInfoObjectVariant: diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index f9c4448980..2942520399 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -167,8 +167,9 @@ def check_type(value, info, source, allow_optional=3DTrue, permit_upper=3Dpermit_upper) if c_name(key, False) =3D=3D 'u' or c_name(key, False).startswith(= 'has_'): raise QAPISemError(info, "%s uses reserved name" % key_source) - check_keys(arg, info, key_source, ['type'], ['if']) + check_keys(arg, info, key_source, ['type'], ['if', 'features']) check_if(arg, info, key_source) + check_features(arg.get('features'), info) check_type(arg['type'], info, key_source, allow_array=3DTrue) =20 =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index a3fa9865db..23652be810 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -173,7 +173,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] =3D None - return _make_tree(obj, member.ifcond, None) + return _make_tree(obj, member.ifcond, member.features) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 59e1f5a395..6ee3677215 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -668,18 +668,31 @@ class QAPISchemaFeature(QAPISchemaMember): =20 =20 class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=3DNone): + def __init__(self, name, info, typ, optional, ifcond=3DNone, features= =3DNone): super().__init__(name, info, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) + for f in features or []: + assert isinstance(f, QAPISchemaFeature) + f.set_defined_in(name) self._type_name =3D typ self.type =3D None self.optional =3D optional + self.features =3D features or [] =20 def check(self, schema): assert self.defined_in self.type =3D schema.resolve_type(self._type_name, self.info, self.describe) + seen =3D {} + for f in self.features: + f.check_clash(self.info, seen) + + def connect_doc(self, doc): + super().connect_doc(doc) + if doc: + for f in self.features: + doc.connect_feature(f) =20 =20 class QAPISchemaVariant(QAPISchemaObjectTypeMember): @@ -962,7 +975,7 @@ class QAPISchema: name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 - def _make_member(self, name, typ, ifcond, info): + def _make_member(self, name, typ, ifcond, features, info): optional =3D False if name.startswith('*'): name =3D name[1:] @@ -970,10 +983,12 @@ class QAPISchema: if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) - return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcon= d) + return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcon= d, + self._make_features(features, in= fo)) =20 def _make_members(self, data, info): - return [self._make_member(key, value['type'], value.get('if'), inf= o) + return [self._make_member(key, value['type'], value.get('if'), + value.get('features'), info) for (key, value) in data.items()] =20 def _def_struct_type(self, expr, info, doc): @@ -996,7 +1011,7 @@ class QAPISchema: typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( typ, info, self.lookup_type(typ), - 'wrapper', [self._make_member('data', typ, None, info)]) + 'wrapper', [self._make_member('data', typ, None, None, info)]) return QAPISchemaVariant(case, info, typ, ifcond) =20 def _def_union_type(self, expr, info, doc): diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 457b8b2cdf..ddd89d1233 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -78,10 +78,13 @@ # # Features: # @variant1-feat: a feature +# @member-feat: a member feature ## { 'struct': 'Variant1', 'features': [ 'variant1-feat' ], - 'data': { 'var1': { 'type': 'str', 'if': 'defined(IFSTR)' } } } + 'data': { 'var1': { 'type': 'str', + 'features': [ 'member-feat' ], + 'if': 'defined(IFSTR)' } } } =20 ## # @Variant2: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 9bcb2b3e91..6757dd26a2 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -21,6 +21,7 @@ object Base object Variant1 member var1: str optional=3DFalse if ['defined(IFSTR)'] + feature member-feat feature variant1-feat object Variant2 object Object @@ -135,6 +136,8 @@ Another paragraph (but no @var: line) =20 feature=3Dvariant1-feat a feature + feature=3Dmember-feat +a member feature doc symbol=3DVariant2 body=3D =20 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index fa4f3a15da..f576c337af 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -258,7 +258,7 @@ 'data': { 'foo': 'int' }, 'features': [] } { 'struct': 'FeatureStruct1', - 'data': { 'foo': 'int' }, + 'data': { 'foo': { 'type': 'int', 'features': [ 'member-feature1' ] } }, 'features': [ 'feature1' ] } { 'struct': 'FeatureStruct2', 'data': { 'foo': 'int' }, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 1cbd0802b3..cd863ae966 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -359,6 +359,7 @@ object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 member foo: int optional=3DFalse + feature member-feature1 feature feature1 object FeatureStruct2 member foo: int optional=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 8e09e54edb..f396b471eb 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -55,6 +55,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s: %s optional=3D%s' % (m.name, m.type.name, m.optional)) self._print_if(m.ifcond, 8) + self._print_features(m.features, indent=3D8) self._print_variants(variants) self._print_if(ifcond) self._print_features(features) @@ -96,11 +97,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('%sif %s' % (' ' * indent, ifcond)) =20 @classmethod - def _print_features(cls, features): + def _print_features(cls, features, indent=3D4): if features: for f in features: - print(' feature %s' % f.name) - cls._print_if(f.ifcond, 8) + print('%sfeature %s' % (' ' * indent, f.name)) + cls._print_if(f.ifcond, indent + 4) =20 =20 def test_frontend(fname): --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446601; cv=none; d=zohomail.com; s=zohoarc; b=F7TQaxMMCRxyI+TG5AJyYcTIJuN7t4wKATFpfpb7d26xRZu+9KueadgWkew4c8ji8GDuFp1vgHXq4WE0N+moYdoFAHPjFgVmi3j+FIQb165SB3JXA4nANbYvrehAm6scnFZZeyld43d0OJvEhFt/MaHkDKzGik9Bq4sDJyOYCmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446601; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g00Prh+uvQe+VSOmvW8i9oEnkuZZI+qq9LLubpzlJw0=; b=YGKx8ttje0LnCLn19RQ9VcysWBDAgEC2VU7Ox3wZ61L4veLeHumLiElDBKW7wt6lOZi1yuJTXQkxsa+IBbZQgIF1gJDO0Fh2azQMowyHV9nbTJopThClLNkN621hJ5h+OJzvB4iJ9HVbl7OURlCreWu++cX8XghgQU0rl2Xr9vE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446601862423.60483296731957; Tue, 17 Mar 2020 05:03:21 -0700 (PDT) Received: from localhost ([::1]:59752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAwK-00031C-PA for importer@patchew.org; Tue, 17 Mar 2020 08:03:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56830) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoZ-0008AO-6g for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006et-3U for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:31110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoW-0006cC-Sb for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-I0-VlpQLPra7urAgHnE7MA-1; Tue, 17 Mar 2020 07:55:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F1E21922960; Tue, 17 Mar 2020 11:55:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B504953B1; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 60ACA11358A3; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g00Prh+uvQe+VSOmvW8i9oEnkuZZI+qq9LLubpzlJw0=; b=EGt745Ep5FctyDMZRfqJch1wnj49RJr2BZDqD8hgVaRSixs+ZqICFY2EL/QJE5GyH+nATD +TRgO62ZYXjMVcTYcg3XhlRSoq74ZMMsvu89yS+Tn0YjBO5hgB4Y6sjhSu/v3xM1kRw3F6 RfLBoC9n6O4Wv4jANm2aZA+EOB1XoPw= X-MC-Unique: I0-VlpQLPra7urAgHnE7MA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 21/34] qapi: Inline do_qmp_dispatch() into qmp_dispatch() Date: Tue, 17 Mar 2020 12:54:46 +0100 Message-Id: <20200317115459.31821-22-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Both functions check @request is a QDict, and both have code for QCO_NO_SUCCESS_RESP. This wasn't the case back when they were created. It's a sign of muddled responsibilities. Inline. The next commits will clean up some more. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- qapi/qmp-dispatch.c | 90 +++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index bc264b3c9b..a588072523 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -75,19 +75,42 @@ static QDict *qmp_dispatch_check_obj(const QObject *req= uest, bool allow_oob, return dict; } =20 -static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob, Error **errp) +QDict *qmp_error_response(Error *err) { - Error *local_err =3D NULL; + QDict *rsp; + + rsp =3D qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s = } }", + QapiErrorClass_str(error_get_class(err)), + error_get_pretty(err)); + error_free(err); + return rsp; +} + +/* + * Does @qdict look like a command to be run out-of-band? + */ +bool qmp_is_oob(const QDict *dict) +{ + return qdict_haskey(dict, "exec-oob") + && !qdict_haskey(dict, "execute"); +} + +QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob) +{ + Error *err =3D NULL; bool oob; const char *command; - QDict *args, *dict; + QDict *args; QmpCommand *cmd; + QDict *dict =3D qobject_to(QDict, request); + QObject *id =3D dict ? qdict_get(dict, "id") : NULL; QObject *ret =3D NULL; + QDict *rsp; =20 - dict =3D qmp_dispatch_check_obj(request, allow_oob, errp); + dict =3D qmp_dispatch_check_obj(request, allow_oob, &err); if (!dict) { - return NULL; + goto out; } =20 command =3D qdict_get_try_str(dict, "execute"); @@ -99,27 +122,27 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, } cmd =3D qmp_find_command(cmds, command); if (cmd =3D=3D NULL) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has not been found", command); - return NULL; + goto out; } if (!cmd->enabled) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance", command); - return NULL; + goto out; } if (oob && !(cmd->options & QCO_ALLOW_OOB)) { - error_setg(errp, "The command %s does not support OOB", + error_setg(&err, "The command %s does not support OOB", command); - return NULL; + goto out; } =20 if (runstate_check(RUN_STATE_PRECONFIG) && !(cmd->options & QCO_ALLOW_PRECONFIG)) { - error_setg(errp, "The command '%s' isn't permitted in '%s' state", + error_setg(&err, "The command '%s' isn't permitted in '%s' state", cmd->name, RunState_str(RUN_STATE_PRECONFIG)); - return NULL; + goto out; } =20 if (!qdict_haskey(dict, "arguments")) { @@ -129,9 +152,9 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, Q= Object *request, qobject_ref(args); } =20 - cmd->fn(args, &ret, &local_err); - if (local_err) { - error_propagate(errp, local_err); + cmd->fn(args, &ret, &err); + if (err) { + ; } else if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); } else if (!ret) { @@ -141,38 +164,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, =20 qobject_unref(args); =20 - return ret; -} - -QDict *qmp_error_response(Error *err) -{ - QDict *rsp; - - rsp =3D qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s = } }", - QapiErrorClass_str(error_get_class(err)), - error_get_pretty(err)); - error_free(err); - return rsp; -} - -/* - * Does @qdict look like a command to be run out-of-band? - */ -bool qmp_is_oob(const QDict *dict) -{ - return qdict_haskey(dict, "exec-oob") - && !qdict_haskey(dict, "execute"); -} - -QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob) -{ - Error *err =3D NULL; - QDict *dict =3D qobject_to(QDict, request); - QObject *ret, *id =3D dict ? qdict_get(dict, "id") : NULL; - QDict *rsp; - - ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); +out: if (err) { rsp =3D qmp_error_response(err); } else if (ret) { --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446794; cv=none; d=zohomail.com; s=zohoarc; b=bdX7YH3lTPwokwqxew/eEIVNyTGGIKFfkHBg7H1/AEQENPHkzY1AantNt0MJLSzA3BGsnch+t1FJjNg6QkEQupQbF1zcEyWLbX/F96g1rzEJbsbJyQBg1kKOgwUKwEOUwHi3XQb4kd668BqCCxTIHjTb+GQXnw/lN/GDNVKAmrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446794; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0D4PB9YjJB08aB6926cQUW1CYMw+l3Wfh+7zQ7cWyvs=; b=TVJU4uy7syt5wbwLE3M6AYTEUXGdF7seloqB/E6e1rUp95QVOLAkEOau+QIkHkNmxtrAQLDp+9NyL2dXnFrP3bNQQ66sjBV1DX+sqYghpd4+OiCV/F3X+XAi9k3z81xCfOTEcG9fIzNimuwmlDUrxz+22Lf+gUWm50SIvOY/50Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446794727107.4130594907648; Tue, 17 Mar 2020 05:06:34 -0700 (PDT) Received: from localhost ([::1]:59822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAzR-0001Qk-K2 for importer@patchew.org; Tue, 17 Mar 2020 08:06:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56863) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoa-0008DQ-G9 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoY-0006kY-1C for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:20 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:42238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006ei-R1 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-457-xQK2fX6lNy-hRrH9e1XMwA-1; Tue, 17 Mar 2020 07:55:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51B8B8017CC; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D250953B9; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6619C11358C9; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0D4PB9YjJB08aB6926cQUW1CYMw+l3Wfh+7zQ7cWyvs=; b=V/MsB5OaBINkxW2xX5TMc7JAYYPGd3IRN7FEC/ltWCe8ceDKldNkWMqEr0QG6EAGVv+YQJ V5KomAYYYaZYYMHMepQ4/l7A1OCeShQM93dqnq5LS2L78nljfi2AO09WzH8MxWTwNkc6z5 mwXcXNtlmN2Q2WWYzsgicLbaXu0Nmtw= X-MC-Unique: xQK2fX6lNy-hRrH9e1XMwA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 22/34] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP Date: Tue, 17 Mar 2020 12:54:47 +0100 Message-Id: <20200317115459.31821-23-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- qapi/qmp-dispatch.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index a588072523..550d1fe8d2 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -106,7 +106,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, QDict *dict =3D qobject_to(QDict, request); QObject *id =3D dict ? qdict_get(dict, "id") : NULL; QObject *ret =3D NULL; - QDict *rsp; + QDict *rsp =3D NULL; =20 dict =3D qmp_dispatch_check_obj(request, allow_oob, &err); if (!dict) { @@ -151,31 +151,32 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, args =3D qdict_get_qdict(dict, "arguments"); qobject_ref(args); } - cmd->fn(args, &ret, &err); + qobject_unref(args); if (err) { - ; - } else if (cmd->options & QCO_NO_SUCCESS_RESP) { + goto out; + } + + if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); + return NULL; } else if (!ret) { /* TODO turn into assertion */ ret =3D QOBJECT(qdict_new()); } =20 - qobject_unref(args); + rsp =3D qdict_new(); + qdict_put_obj(rsp, "return", ret); =20 out: if (err) { + assert(!rsp); rsp =3D qmp_error_response(err); - } else if (ret) { - rsp =3D qdict_new(); - qdict_put_obj(rsp, "return", ret); - } else { - /* Can only happen for commands with QCO_NO_SUCCESS_RESP */ - rsp =3D NULL; } =20 - if (rsp && id) { + assert(rsp); + + if (id) { qdict_put_obj(rsp, "id", qobject_ref(id)); } =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446678; cv=none; d=zohomail.com; s=zohoarc; b=nm03flNbBqJyrgYB3eH0mqAAkszhqgadbSF31lozrvKhPiMpBGgPafUE1xl+cZ9e0A0033fK/Bxrj9UX8DatKeZ1sE+HFxIq3SNsvX6LGrx+Ep2PnaHgEt18gSlPjZGN82fRJo3A37AfsaNVUU8zrCRajf4IEXorPYKIc2STirY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446678; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ePcL4jMr5ho3uFRr0SwI3tKaouKaWGPYWwp+LQfUZMc=; b=ekjsrZhzEJZM18oqnB36UStQimdcsqn8NDay5leKbTWoXAMLbc0CnFRadxB07ACZe8vwwQUOLwUN6ACCcYYuSD/tyjPkhSQs/OcMrP+TJUHf3n9RO42Of9UM6li2LDA05hVEpS3KZOO0wtSVI6efJXTBJ9ajHzwmF+8gTwAizOY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158444667813772.52639197470376; Tue, 17 Mar 2020 05:04:38 -0700 (PDT) Received: from localhost ([::1]:59776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAxZ-0005Rd-0n for importer@patchew.org; Tue, 17 Mar 2020 08:04:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56757) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoW-00085D-IC for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoU-0006Pl-VZ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:56578) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoU-0006N3-R3 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-QzxlLTXrNhW-R25ItuWmEQ-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FAA9800D4E; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B8CA9128E; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6C2F9113522F; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ePcL4jMr5ho3uFRr0SwI3tKaouKaWGPYWwp+LQfUZMc=; b=EG7GWmbjLOLeL9lENdqccllzBBztpe3eRY7L9c29kIna7yjk5w+gpBUeMCr9jXwqdHaPSk 2CpjsqccoMot6N2DqqO3XQX4+CCxtBLxwDr4M9ClWdeVSjYyoxMi9LJCEYIbiOBV2o4w9S gEqUc9A74GVhRJZFq8xd1ixx94uOe/U= X-MC-Unique: QzxlLTXrNhW-R25ItuWmEQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 23/34] qapi: Simplify how qmp_dispatch() gets the request ID Date: Tue, 17 Mar 2020 12:54:48 +0100 Message-Id: <20200317115459.31821-24-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We convert the request object to a QDict twice: first in qmp_dispatch() to get the request ID, and then again in qmp_dispatch_check_obj(), which converts to QDict, then checks and returns it. We can't get the request ID from the latter, because it's null when the qdict flunks the checks. Move the checked conversion to QDict from qmp_dispatch_check_obj() to qmp_dispatch(), and drop the duplicate there. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- qapi/qmp-dispatch.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 550d1fe8d2..91e50fa0dd 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -19,20 +19,13 @@ #include "sysemu/runstate.h" #include "qapi/qmp/qbool.h" =20 -static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oo= b, +static QDict *qmp_dispatch_check_obj(QDict *dict, bool allow_oob, Error **errp) { const char *exec_key =3D NULL; const QDictEntry *ent; const char *arg_name; const QObject *arg_obj; - QDict *dict; - - dict =3D qobject_to(QDict, request); - if (!dict) { - error_setg(errp, "QMP input must be a JSON object"); - return NULL; - } =20 for (ent =3D qdict_first(dict); ent; ent =3D qdict_next(dict, ent)) { @@ -103,13 +96,21 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *req= uest, const char *command; QDict *args; QmpCommand *cmd; - QDict *dict =3D qobject_to(QDict, request); - QObject *id =3D dict ? qdict_get(dict, "id") : NULL; + QDict *dict; + QObject *id; QObject *ret =3D NULL; QDict *rsp =3D NULL; =20 - dict =3D qmp_dispatch_check_obj(request, allow_oob, &err); + dict =3D qobject_to(QDict, request); if (!dict) { + id =3D NULL; + error_setg(&err, "QMP input must be a JSON object"); + goto out; + } + + id =3D qdict_get(dict, "id"); + + if (!qmp_dispatch_check_obj(dict, allow_oob, &err)) { goto out; } =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446559; cv=none; d=zohomail.com; s=zohoarc; b=Hb/BugO0OITVpT+t/w7uguF4L5DQjIz4GvEx9jtq8pg15mK3bdihF4WQj39ZDJxkIm7QRs1tvwsqZzRMGsWP/PUg/jjyZPd1HOguH2iLuyTCbvQIlRbmkhL2OzvSR2KltyalUuPlBf7dzvXJ3WfENYwgNm8AloeCEQ+rK5uykPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446559; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8wzpm51EAR+NpI4m/REJ78plUW41NCsP2bm+mM4rMFg=; b=IzY+3/zryg02RW5+p4iLo0SkKG0HMstaaaAdfGJkYaqwfMShEOmBCNMfBacn8/jitkfrYAiqniNHjnWOlup3TQb7WeRH3XSBEjtlHvjA+L7hkJjuZztMeSfXDWmbhjMGm3ec2+VJHRJNADEYr+iSMkLAlPeRLugSbsEmhOPTMvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446559294696.9863904389899; Tue, 17 Mar 2020 05:02:39 -0700 (PDT) Received: from localhost ([::1]:59730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAvd-0001ev-04 for importer@patchew.org; Tue, 17 Mar 2020 08:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56752) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoW-00084m-Bt for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoU-0006PX-Ut for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:43190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoU-0006MK-QX for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-0ToojTiaNzy-VTcMiY80fg-1; Tue, 17 Mar 2020 07:55:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCF04101FC68; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61D6D66840; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7110F1135234; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8wzpm51EAR+NpI4m/REJ78plUW41NCsP2bm+mM4rMFg=; b=YYorQJtchnB9q5y0W8ZC4tJbOsyjON+qGKpcAlWKiURec1P2u8ak4Ky27cHRWI5BG/O/b5 opG4tTEes18fIFbOsrJOd7CQexUNbDphfyTEhREh3AWLHh3FI09bSE2PkDKZ2f+MWmFME0 Kpk6QhQVRhm1pNcvJs++6yWUBrS2pKE= X-MC-Unique: 0ToojTiaNzy-VTcMiY80fg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 24/34] qapi: Replace qmp_dispatch()'s TODO comment by an explanation Date: Tue, 17 Mar 2020 12:54:49 +0100 Message-Id: <20200317115459.31821-25-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/qmp-dispatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 91e50fa0dd..44fc368d61 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -162,7 +162,11 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *req= uest, g_assert(!ret); return NULL; } else if (!ret) { - /* TODO turn into assertion */ + /* + * When the command's schema has no 'returns', cmd->fn() + * leaves @ret null. The QMP spec calls for an empty object + * then; supply it. + */ ret =3D QOBJECT(qdict_new()); } =20 --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446891; cv=none; d=zohomail.com; s=zohoarc; b=A8RT9f/NorcRAkjVmmptvDdzKtyrPsohMipiSelYpU5XWhHk6r2o3/7H1yFCZPuOUDQwQ/ph9gmMBt4LaZPtIqwZ+fFlCL00Mvt/tu1nmLRUMiayN4sxwXco9+QCKWmB0OOEFKg886D264on2Uwf3VRuWg/GGlHoCY/gpggIjo4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446891; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c7ZSBZCNo/ZgAY5gyqS52uAcS239rFzvOxIBhE8+2aY=; b=UFzDHIP8cqIlMQ08x1nGmLffdQsywk05D4YEJK7HqOAgXsdHC8QKzFl+VsokEAC0GYWhjjZjJSbOfXAE2AMTgXJQ9zzCunlN6Or1BmeEMLE0pSflh8pkvvo0dQ6VVRGMqIhmF5jmln9ERsCVpIgeQ6EPnevOCUBhFE0uGSp9DTk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446891478740.3535932072006; Tue, 17 Mar 2020 05:08:11 -0700 (PDT) Received: from localhost ([::1]:59840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB10-000518-9r for importer@patchew.org; Tue, 17 Mar 2020 08:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56848) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoZ-0008Bk-RZ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006ey-2z for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:22702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoW-0006c6-Sw for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-296-UWR_-thANVKOsEt5PcYAug-1; Tue, 17 Mar 2020 07:55:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA30DDBC9; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A42292F9C; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 75BF7113523D; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c7ZSBZCNo/ZgAY5gyqS52uAcS239rFzvOxIBhE8+2aY=; b=A2TchYbiXWkCJjUOYqOxABazU4F2+6WJzpb67aPfUxfOvrx6XLFP3yav8j2cx68Hl0gzko IZmMcJD5k1+R+DH3wyAWLEemUmameANN4HxBCJgYivdHEFlDPJImwNs8Wqt1qFSwTwdGCi 5/umo9lKc2Iu9ucN81Go+Tc791Nk0dg= X-MC-Unique: UWR_-thANVKOsEt5PcYAug-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 25/34] qapi: New special feature flag "deprecated" Date: Tue, 17 Mar 2020 12:54:50 +0100 Message-Id: <20200317115459.31821-26-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Unlike regular feature flags, the new special feature flag "deprecated" is recognized by the QAPI generator. For now, it's only permitted with commands, events, and struct members. It will be put to use shortly. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 6 ++++++ scripts/qapi/schema.py | 6 ++++++ tests/Makefile.include | 1 + tests/qapi-schema/features-deprecated-type.err | 2 ++ tests/qapi-schema/features-deprecated-type.json | 3 +++ tests/qapi-schema/features-deprecated-type.out | 0 tests/qapi-schema/qapi-schema-test.json | 6 +++--- tests/qapi-schema/qapi-schema-test.out | 6 +++--- 8 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/qapi-schema/features-deprecated-type.err create mode 100644 tests/qapi-schema/features-deprecated-type.json create mode 100644 tests/qapi-schema/features-deprecated-type.out diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index a1ef1cfd61..823adbabda 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -683,6 +683,12 @@ Intended use is to have each feature string signal tha= t this build of QEMU shows a certain behaviour. =20 =20 +=3D=3D=3D=3D Special features =3D=3D=3D=3D + +Feature "deprecated" makes a command, event, or struct member as +deprecated. It is not supported elsewhere so far. + + =3D=3D=3D Naming rules and reserved names =3D=3D=3D =20 All names must begin with a letter, and contain only ASCII letters, diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 6ee3677215..78309a00f0 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -193,6 +193,12 @@ class QAPISchemaType(QAPISchemaEntity): return None return self.name =20 + def check(self, schema): + QAPISchemaEntity.check(self, schema) + if 'deprecated' in [f.name for f in self.features]: + raise QAPISemError( + self.info, "feature 'deprecated' is not supported for type= s") + def describe(self): assert self.meta return "%s type '%s'" % (self.meta, self.name) diff --git a/tests/Makefile.include b/tests/Makefile.include index 67e8fcddda..d1340301b2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -242,6 +242,7 @@ qapi-schema +=3D event-case.json qapi-schema +=3D event-member-invalid-dict.json qapi-schema +=3D event-nest-struct.json qapi-schema +=3D features-bad-type.json +qapi-schema +=3D features-deprecated-type.json qapi-schema +=3D features-duplicate-name.json qapi-schema +=3D features-if-invalid.json qapi-schema +=3D features-missing-name.json diff --git a/tests/qapi-schema/features-deprecated-type.err b/tests/qapi-sc= hema/features-deprecated-type.err new file mode 100644 index 0000000000..af4ffe20aa --- /dev/null +++ b/tests/qapi-schema/features-deprecated-type.err @@ -0,0 +1,2 @@ +features-deprecated-type.json: In struct 'S': +features-deprecated-type.json:2: feature 'deprecated' is not supported for= types diff --git a/tests/qapi-schema/features-deprecated-type.json b/tests/qapi-s= chema/features-deprecated-type.json new file mode 100644 index 0000000000..4b5bf5b86e --- /dev/null +++ b/tests/qapi-schema/features-deprecated-type.json @@ -0,0 +1,3 @@ +# Feature 'deprecated' is not supported for types +{ 'struct': 'S', 'data': {}, + 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/features-deprecated-type.out b/tests/qapi-sc= hema/features-deprecated-type.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index f576c337af..6b1f05afa7 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -258,7 +258,7 @@ 'data': { 'foo': 'int' }, 'features': [] } { 'struct': 'FeatureStruct1', - 'data': { 'foo': { 'type': 'int', 'features': [ 'member-feature1' ] } }, + 'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } }, 'features': [ 'feature1' ] } { 'struct': 'FeatureStruct2', 'data': { 'foo': 'int' }, @@ -308,7 +308,7 @@ 'features': [] } =20 { 'command': 'test-command-features1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] } { 'command': 'test-command-features3', 'features': [ 'feature1', 'feature2' ] } =20 @@ -322,4 +322,4 @@ 'defined(TEST_IF_COND_2)'] }= ] } =20 { 'event': 'TEST-EVENT-FEATURES1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index cd863ae966..891b4101e0 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -359,7 +359,7 @@ object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 member foo: int optional=3DFalse - feature member-feature1 + feature deprecated feature feature1 object FeatureStruct2 member foo: int optional=3DFalse @@ -419,7 +419,7 @@ command test-features0 q_obj_test-features0-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - feature feature1 + feature deprecated command test-command-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 @@ -440,7 +440,7 @@ command test-command-cond-features3 None -> None if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] event TEST-EVENT-FEATURES1 None boxed=3DFalse - feature feature1 + feature deprecated module include/sub-module.json include sub-sub-module.json object SecondArrayRef --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446955; cv=none; d=zohomail.com; s=zohoarc; b=NWoirKcMNLeSj+2QB3d/Q6vi5hOHcY0gkHkavG6ZfCMAFdM4hp0JMHX1N2LTMWmmOukBKNv+KhyR8Pspg/MH+GJk8lIoalyzaUdf3uSjEdgzhxU34m60wDh2rAA5f8oH1CqsxhjZf7QhbWPvsPPRhH2VTurc14/qMBoPsSgNxbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446955; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sJhlVzaLjOESlp7sH9EzT1iPivs9BmQbuJRGb5TJMY4=; b=lZaz3LREaajmg0saQdkAzGr0c4TA39djWy9iUFJGaQG1oDjfPe2X4wyhgXq0aNYwPgdmipIMRJPruM6ZEhEzIShcsO3Y/cA5TCek5x8ugwqQqZAi9XzjDc3JPntk9yk1boMnj2jgT2qtsHQU5Wh80JwdASbHfPM/Yfxtll7Tkz0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446955081911.9015803338134; Tue, 17 Mar 2020 05:09:15 -0700 (PDT) Received: from localhost ([::1]:59902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB21-0006lI-OY for importer@patchew.org; Tue, 17 Mar 2020 08:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56823) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoZ-00089y-1S for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoV-0006T4-El for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:38272) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoV-0006Q2-6x for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-1ySgjKvUPWmMIF5dPeBN_A-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56E1C800D53; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0C1791298; Tue, 17 Mar 2020 11:55:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7AD02113523E; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sJhlVzaLjOESlp7sH9EzT1iPivs9BmQbuJRGb5TJMY4=; b=XWOOsf9GPCue1Kw8ERtMzQK5HL87n3MXiGn0frnUCFKx283y4beGwGb31OhcHE0Y/UuUep jBMFMLqsi88pORHZ+aK8heN8P+GXDf09R2Fir8e15iTkPTAwNmabxRsaDsKf9EkTvwLqUq rd5elCUqvWPWQ6uqpdJHBXGW9fPfB9s= X-MC-Unique: 1ySgjKvUPWmMIF5dPeBN_A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 26/34] qapi: Mark deprecated QMP parts with feature 'deprecated' Date: Tue, 17 Mar 2020 12:54:51 +0100 Message-Id: <20200317115459.31821-27-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add feature 'deprecated' to the deprecated QMP commands, so their deprecation becomes visible in output of query-qmp-schema. Looks like this: {"name": "query-cpus", "ret-type": "[164]", "meta-type": "command", "arg-type": "0", Reviewed-by: Eric Blake ---> "features": ["deprecated"]} Management applications could conceivably use this for static checking. The deprecated commands are change, cpu-add, migrate-set-cache-size, migrate_set_downtime, migrate_set_speed, query-cpus, query-events, query-migrate-cache-size. The deprecated command arguments are block-commit arguments @base and @top, and block_set_io_throttle, blockdev-change-medium, blockdev-close-tray, blockdev-open-tray, eject argument @device. The deprecated command results are query-cpus-fast result @arch, query-block result @dirty-bitmaps, query-named-block-nodes result @encryption_key_missing and result @dirty-bitmaps's member @status. Same for query-block result @inserted, which mirrors query-named-block-nodes. Signed-off-by: Markus Armbruster --- qapi/block-core.json | 48 ++++++++++++++++++++++++++++++++++---------- qapi/block.json | 30 ++++++++++++++++++--------- qapi/control.json | 11 ++++++---- qapi/machine.json | 34 +++++++++++++++++-------------- qapi/migration.json | 36 ++++++++++++++++++++++----------- qapi/misc.json | 13 ++++++------ 6 files changed, 115 insertions(+), 57 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 91586fb1fb..943df1926a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -297,7 +297,7 @@ # # @encrypted: true if the backing device is encrypted # -# @encryption_key_missing: Deprecated; always false +# @encryption_key_missing: always false # # @detect_zeroes: detect and optimize zero writes (Since 2.1) # @@ -363,13 +363,19 @@ # @dirty-bitmaps: dirty bitmaps information (only present if node # has one or more dirty bitmaps) (Since 4.2) # +# Features: +# @deprecated: Member @encryption_key_missing is deprecated. It is +# always false. +# # Since: 0.14.0 # ## { 'struct': 'BlockDeviceInfo', 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', - 'encrypted': 'bool', 'encryption_key_missing': 'bool', + 'encrypted': 'bool', + 'encryption_key_missing': { 'type': 'bool', + 'features': [ 'deprecated' ] }, 'detect_zeroes': 'BlockdevDetectZeroesOptions', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', @@ -475,7 +481,7 @@ # # @granularity: granularity of the dirty bitmap in bytes (since 1.4) # -# @status: Deprecated in favor of @recording and @locked. (since 2.4) +# @status: current status of the dirty bitmap (since 2.4) # # @recording: true if the bitmap is recording new writes from the guest. # Replaces `active` and `disabled` statuses. (since 4.0) @@ -492,11 +498,17 @@ # @busy to be false. This bitmap cannot be used. To remove # it, use @block-dirty-bitmap-remove. (Since 4.0) # +# Features: +# @deprecated: Member @status is deprecated. Use @recording and +# @locked instead. +# # Since: 1.3 ## { 'struct': 'BlockDirtyInfo', 'data': {'*name': 'str', 'count': 'int', 'granularity': 'uint32', - 'recording': 'bool', 'busy': 'bool', 'status': 'DirtyBitmapStat= us', + 'recording': 'bool', 'busy': 'bool', + 'status': { 'type': 'DirtyBitmapStatus', + 'features': [ 'deprecated' ] }, 'persistent': 'bool', '*inconsistent': 'bool' } } =20 ## @@ -587,7 +599,6 @@ # # @dirty-bitmaps: dirty bitmaps information (only present if the # driver has one or more dirty bitmaps) (Since 2.0) -# Deprecated in 4.2; see BlockDeviceInfo instead. # # @io-status: @BlockDeviceIoStatus. Only present if the device # supports it and the VM is configured to stop on errors @@ -597,13 +608,18 @@ # @inserted: @BlockDeviceInfo describing the device if media is # present # +# Features: +# @deprecated: Member @dirty-bitmaps is deprecated. Use @inserted +# member @dirty-bitmaps instead. +# # Since: 0.14.0 ## { 'struct': 'BlockInfo', 'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'b= ool', 'locked': 'bool', '*inserted': 'BlockDeviceInfo', '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus', - '*dirty-bitmaps': ['BlockDirtyInfo'] } } + '*dirty-bitmaps': { 'type': ['BlockDirtyInfo'], + 'features': [ 'deprecated' ] } } } =20 ## # @BlockMeasureInfo: @@ -1551,7 +1567,7 @@ # @base: Same as @base-node, except that it is a file name rather than a n= ode # name. This must be the exact filename string that was used to ope= n the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @top-node: The node name of the backing image within the image chain # which contains the topmost data to be committed down. If @@ -1560,7 +1576,7 @@ # @top: Same as @top-node, except that it is a file name rather than a node # name. This must be the exact filename string that was used to open= the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @backing-file: The backing file string to write into the overlay # image of 'top'. If 'top' is the active layer, @@ -1614,6 +1630,10 @@ # list without user intervention. # Defaults to true. (Since 3.1) # +# Features: +# @deprecated: Members @base and @top are deprecated. Use @base-node +# and @top-node instead. +# # Returns: - Nothing on success # - If @device does not exist, DeviceNotFound # - Any other error returns a GenericError. @@ -1630,7 +1650,9 @@ ## { 'command': 'block-commit', 'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str', - '*base': 'str', '*top-node': 'str', '*top': 'str', + '*base': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*top-node': 'str', + '*top': { 'type': 'str', 'features': [ 'deprecated' ] }, '*backing-file': 'str', '*speed': 'int', '*on-error': 'BlockdevOnError', '*filter-node-name': 'str', @@ -2296,7 +2318,7 @@ # # A set of parameters describing block throttling. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # @@ -2364,10 +2386,14 @@ # # @group: throttle group name (Since 2.4) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': '= int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', diff --git a/qapi/block.json b/qapi/block.json index 97bf52b7c7..2ddbfa8306 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -90,15 +90,18 @@ ## # @eject: # -# Ejects a device from a removable drive. +# Ejects the medium from a removable drive. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # # @force: If true, eject regardless of whether the drive is locked. # If not specified, the default value is false. # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Returns: - Nothing on success # - If @device is not a valid block device, DeviceNotFound # Notes: Ejecting a device with no media results in success @@ -111,7 +114,7 @@ # <- { "return": {} } ## { 'command': 'eject', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } } =20 @@ -134,7 +137,7 @@ # to it # - if the guest device does not have an actual tray # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # @@ -143,6 +146,9 @@ # immediately); if true, the tray will be opened regardless of whe= ther # it is locked # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example: @@ -161,7 +167,7 @@ # ## { 'command': 'blockdev-open-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } } =20 @@ -174,10 +180,13 @@ # # If the tray was already closed before, this will be a no-op. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example: @@ -196,7 +205,7 @@ # ## { 'command': 'blockdev-close-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str' } } =20 ## @@ -303,7 +312,7 @@ # combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-med= ium # and blockdev-close-tray). # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device # (since: 2.8) @@ -316,6 +325,9 @@ # @read-only-mode: change the read-only mode of the device; defaults # to 'retain' # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Examples: @@ -350,7 +362,7 @@ # ## { 'command': 'blockdev-change-medium', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', 'filename': 'str', '*format': 'str', diff --git a/qapi/control.json b/qapi/control.json index 85b12fe0fb..6b816bb61f 100644 --- a/qapi/control.json +++ b/qapi/control.json @@ -174,13 +174,15 @@ # # Return information on QMP events. # +# Features: +# @deprecated: This command is deprecated, because its output doesn't +# reflect compile-time configuration. Use 'query-qmp-schema' +# instead. +# # Returns: A list of @EventInfo. # # Since: 1.2.0 # -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# # Example: # # -> { "execute": "query-events" } @@ -198,7 +200,8 @@ # Note: This example has been shortened as the real response is too long. # ## -{ 'command': 'query-events', 'returns': ['EventInfo'] } +{ 'command': 'query-events', 'returns': ['EventInfo'], + 'features': [ 'deprecated' ] } =20 ## # @quit: diff --git a/qapi/machine.json b/qapi/machine.json index 6c11e3cf3a..0da3f3adc4 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -184,8 +184,11 @@ # This command causes vCPU threads to exit to userspace, which causes # a small interruption to guest CPU execution. This will have a negative # impact on realtime guests and other latency sensitive guest workloads. -# It is recommended to use @query-cpus-fast instead of this command to -# avoid the vCPU interruption. +# +# Features: +# @deprecated: This command is deprecated, because it interferes with +# the guest. Use 'query-cpus-fast' instead to avoid the vCPU +# interruption. # # Returns: a list of @CpuInfo for each virtual CPU # @@ -216,12 +219,9 @@ # ] # } # -# Notes: This interface is deprecated (since 2.12.0), and it is strongly -# recommended that you avoid using it. Use @query-cpus-fast to -# obtain information about virtual CPUs. -# ## -{ 'command': 'query-cpus', 'returns': ['CpuInfo'] } +{ 'command': 'query-cpus', 'returns': ['CpuInfo'], + 'features': [ 'deprecated' ] } =20 ## # @CpuInfoFast: @@ -237,12 +237,14 @@ # @props: properties describing to which node/socket/core/thread # virtual CPU belongs to, provided if supported by board # -# @arch: base architecture of the cpu; deprecated since 3.0.0 in favor -# of @target +# @arch: base architecture of the cpu # # @target: the QEMU system emulation target, which determines which # additional fields will be listed (since 3.0) # +# Features: +# @deprecated: Member @arch is deprecated. Use @target instead. +# # Since: 2.12 # ## @@ -251,7 +253,8 @@ 'qom-path' : 'str', 'thread-id' : 'int', '*props' : 'CpuInstanceProperties', - 'arch' : 'CpuInfoArch', + 'arch' : { 'type': 'CpuInfoArch', + 'features': [ 'deprecated' ] }, 'target' : 'SysEmuTarget' }, 'discriminator' : 'target', 'data' : { 's390x' : 'CpuInfoS390' } } @@ -307,21 +310,22 @@ # # @id: ID of CPU to be created, valid values [0..max_cpus) # +# Features: +# @deprecated: This command is deprecated. Use `device_add` instead. +# See the `query-hotpluggable-cpus` command for details. +# # Returns: Nothing on success # # Since: 1.5 # -# Note: This command is deprecated. The `device_add` command should be -# used instead. See the `query-hotpluggable-cpus` command for -# details. -# # Example: # # -> { "execute": "cpu-add", "arguments": { "id": 2 } } # <- { "return": {} } # ## -{ 'command': 'cpu-add', 'data': {'id': 'int'} } +{ 'command': 'cpu-add', 'data': {'id': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @MachineInfo: diff --git a/qapi/migration.json b/qapi/migration.json index 0d1c0712ca..eca2981d0a 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1210,9 +1210,11 @@ # # @value: maximum downtime in seconds # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 # @@ -1222,7 +1224,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } +{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'}, + 'features': [ 'deprecated' ] } =20 ## # @migrate_set_speed: @@ -1231,9 +1234,11 @@ # # @value: maximum speed in bytes per second. # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 # @@ -1243,7 +1248,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_speed', 'data': {'value': 'int'} } +{ 'command': 'migrate_set_speed', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @migrate-set-cache-size: @@ -1252,13 +1258,15 @@ # # @value: cache size in bytes # +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. +# # The size will be rounded down to the nearest power of 2. # The cache size can be modified before and during ongoing migration # # Returns: nothing on success # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' -# # Since: 1.2 # # Example: @@ -1268,17 +1276,20 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} } +{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @query-migrate-cache-size: # # Query migration XBZRLE cache size # +# Features: +# @deprecated: This command is deprecated. Use +# 'query-migrate-parameters' instead. +# # Returns: XBZRLE cache size in bytes # -# Notes: This command is deprecated in favor of 'query-migrate-parameters' -# # Since: 1.2 # # Example: @@ -1287,7 +1298,8 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int' } +{ 'command': 'query-migrate-cache-size', 'returns': 'int', + 'features': [ 'deprecated' ] } =20 ## # @migrate: diff --git a/qapi/misc.json b/qapi/misc.json index c18fe681fb..99b90ac80b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -872,14 +872,14 @@ # If @device is 'vnc' and @target is 'password', this is the new VNC # password to set. See change-vnc-password for additional notes. # +# Features: +# @deprecated: This command is deprecated. For changing block +# devices, use 'blockdev-change-medium' instead; for changing VNC +# parameters, use 'change-vnc-password' instead. +# # Returns: - Nothing on success. # - If @device is not a valid block device, DeviceNotFound # -# Notes: This interface is deprecated, and it is strongly recommended that= you -# avoid using it. For changing block devices, use -# blockdev-change-medium; for changing VNC parameters, use -# change-vnc-password. -# # Since: 0.14.0 # # Example: @@ -900,7 +900,8 @@ # ## { 'command': 'change', - 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'}, + 'features': [ 'deprecated' ] } =20 ## # @xen-set-global-dirty-log: --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446614; cv=none; d=zohomail.com; s=zohoarc; b=jJwVs+HvVqamHFZOHQYFfuMdjN0np6uH/axbRr/pyxq5kfzDrrMDeIFOLLIv5giyc+uDKXHNBs34qy6PvySXw3w4DeHPc1xGJ+gCIF0m7+CGAmw9c5u6S1HWs+RhqD0D8zgGMjPmd+MzdY5GQa1n5BFzOZmseBXCKSBHx4kJNJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446614; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZKyGflvugJ/tysPqkI5mAHh1d3oTtN9q/B5Ln7NJZXM=; b=OHft46GGACqDJ8UhbPBkTBvNebHy14fytAOV/VXUdRiuyTLaENzxBrn00O7BCZKA06fzoCUoz2BcF0b4intkFLp4i2f8UP/m7MHoT6HvxWuKPKLuAcshuV42OyBO9BsSLPH5wxoz8iSCQwqv07fr0F2nnPAb+c4U+vk1Pb3bl58= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446614564551.9375206381671; Tue, 17 Mar 2020 05:03:34 -0700 (PDT) Received: from localhost ([::1]:59756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAwX-0003Je-3k for importer@patchew.org; Tue, 17 Mar 2020 08:03:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56794) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoX-00087w-TR for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoV-0006WO-PP for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:54843) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoV-0006Sn-Jt for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-1zhyNceNMTiOxZop1K1gUg-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93543801E67; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 301091036B4B; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7FB2F1135243; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZKyGflvugJ/tysPqkI5mAHh1d3oTtN9q/B5Ln7NJZXM=; b=KCOnFygUh4pU+7F98tA8AyNxb1A2kqDNjRfzcBc2rKKBqusT78A2hmv8Ynr3ChhzS5I2xd yohC/vfbJcVv3MWcIdkxjj6xX6kC/K+7dhjPjLmpFhHXSpJjNDtNqF85pxotoDifBcij3E +GNP+xu3TmcPG20VF0/7QruUquD7ku4= X-MC-Unique: 1zhyNceNMTiOxZop1K1gUg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 27/34] qemu-options: New -compat to set policy for deprecated interfaces Date: Tue, 17 Mar 2020 12:54:52 +0100 Message-Id: <20200317115459.31821-28-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Policy is separate for input and output. Input policy can be "accept" (accept silently), or "reject" (reject the request with an error). Output policy can be "accept" (pass on unchanged), or "hide" (filter out the deprecated parts). Default is "accept". Policies other than "accept" are implemented later in this series. For now, -compat covers only syntactic aspects of QMP, i.e. stuff tagged with feature 'deprecated'. We may want to extend it to cover semantic aspects, CLI, and experimental features. The option is experimental. Signed-off-by: Markus Armbruster --- qapi/compat.json | 51 ++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + include/qapi/compat-policy.h | 20 ++++++++++++++ qapi/qmp-dispatch.c | 3 +++ softmmu/vl.c | 17 ++++++++++++ qapi/Makefile.objs | 8 +++--- qemu-options.hx | 20 ++++++++++++++ 7 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 qapi/compat.json create mode 100644 include/qapi/compat-policy.h diff --git a/qapi/compat.json b/qapi/compat.json new file mode 100644 index 0000000000..fd6f8e932c --- /dev/null +++ b/qapi/compat.json @@ -0,0 +1,51 @@ +# -*- Mode: Python -*- + +## +# =3D Compatibility policy +## + +## +# @CompatPolicyInput: +# +# Policy for handling "funny" input. +# +# @accept: Accept silently +# @reject: Reject with an error +# +# Since: 5.0 +## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept', 'reject' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# @hide: Filter out +# +# Since: 5.0 +## +{ 'enum': 'CompatPolicyOutput', + 'data': [ 'accept', 'hide' ] } + +## +# @CompatPolicy: +# +# Policy for handling deprecated management interfaces. +# +# This is intended for testing users of the management interfaces. +# +# Limitation: covers only syntactic aspects of QMP, i.e. stuff tagged +# with feature 'deprecated'. We may want to extend it to cover +# semantic aspects, CLI, and experimental features. +# +# @deprecated-input: how to handle deprecated input (default 'accept') +# @deprecated-output: how to handle deprecated output (default 'accept') +# +# Since: 5.0 +## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 43b0ba0dea..f575b76d81 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -75,6 +75,7 @@ { 'include': 'migration.json' } { 'include': 'transaction.json' } { 'include': 'trace.json' } +{ 'include': 'compat.json' } { 'include': 'control.json' } { 'include': 'introspect.json' } { 'include': 'qom.json' } diff --git a/include/qapi/compat-policy.h b/include/qapi/compat-policy.h new file mode 100644 index 0000000000..8efb2c58aa --- /dev/null +++ b/include/qapi/compat-policy.h @@ -0,0 +1,20 @@ +/* + * Policy for handling "funny" management interfaces + * + * Copyright (C) 2019 Red Hat, Inc. + * + * Authors: + * Markus Armbruster , + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef QAPI_COMPAT_POLICY_H +#define QAPI_COMPAT_POLICY_H + +#include "qapi/qapi-types-compat.h" + +extern CompatPolicy compat_policy; + +#endif diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 44fc368d61..57d823c8e1 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -12,6 +12,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" @@ -19,6 +20,8 @@ #include "sysemu/runstate.h" #include "qapi/qmp/qbool.h" =20 +CompatPolicy compat_policy; + static QDict *qmp_dispatch_check_obj(QDict *dict, bool allow_oob, Error **errp) { diff --git a/softmmu/vl.c b/softmmu/vl.c index ff2685dff8..74eb43d114 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -27,6 +27,7 @@ #include "qemu/units.h" #include "hw/boards.h" #include "hw/qdev-properties.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qemu-version.h" #include "qemu/cutils.h" @@ -105,6 +106,7 @@ #include "sysemu/replay.h" #include "qapi/qapi-events-run-state.h" #include "qapi/qapi-visit-block-core.h" +#include "qapi/qapi-visit-compat.h" #include "qapi/qapi-visit-ui.h" #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-run-state.h" @@ -3749,6 +3751,21 @@ void qemu_init(int argc, char **argv, char **envp) qemu_opt_get_bool(opts, "mem-lock", false); enable_cpu_pm =3D qemu_opt_get_bool(opts, "cpu-pm", false); break; + case QEMU_OPTION_compat: + { + CompatPolicy *opts; + Visitor *v; + + v =3D qobject_input_visitor_new_str(optarg, NULL, + &error_fatal); + + visit_type_CompatPolicy(v, NULL, &opts, &error_fatal); + QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts); + + qapi_free_CompatPolicy(opts); + visit_free(v); + break; + } case QEMU_OPTION_msg: opts =3D qemu_opts_parse_noisily(qemu_find_opts("msg"), op= targ, false); diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 4673ab7490..a3de2e2756 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -5,10 +5,10 @@ util-obj-y +=3D opts-visitor.o qapi-clone-visitor.o util-obj-y +=3D qmp-event.o util-obj-y +=3D qapi-util.o =20 -QAPI_COMMON_MODULES =3D audio authz block-core block char common control c= rypto -QAPI_COMMON_MODULES +=3D dump error introspect job machine migration misc -QAPI_COMMON_MODULES +=3D net pragma qdev qom rdma rocker run-state sockets= tpm -QAPI_COMMON_MODULES +=3D trace transaction ui +QAPI_COMMON_MODULES =3D audio authz block-core block char common compat +QAPI_COMMON_MODULES +=3D control crypto dump error introspect job +QAPI_COMMON_MODULES +=3D machine migration misc net pragma qdev qom rdma +QAPI_COMMON_MODULES +=3D rocker run-state sockets tpm trace transaction ui QAPI_TARGET_MODULES =3D machine-target misc-target QAPI_MODULES =3D $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) =20 diff --git a/qemu-options.hx b/qemu-options.hx index 962a5ebaa6..263d18d63a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3357,6 +3357,26 @@ DEFHEADING() =20 DEFHEADING(Debug/Expert options:) =20 +DEF("compat", HAS_ARG, QEMU_OPTION_compat, + "-compat [deprecated-input=3Daccept|reject][,deprecated-output=3Daccep= t|hide]\n" + " Policy for handling deprecated management interfaces\= n", + QEMU_ARCH_ALL) +SRST +``-compat [deprecated-input=3D@var{input-policy}][,deprecated-output=3D@va= r{output-policy}]`` + Set policy for handling deprecated management interfaces (experimental= ): + + ``deprecated-input=3Daccept`` (default) + Accept deprecated commands and arguments + ``deprecated-input=3Dreject`` + Reject deprecated commands and arguments + ``deprecated-output=3Daccept`` (default) + Emit deprecated command results and events + ``deprecated-output=3Dhide`` + Suppress deprecated command results and events + + Limitation: covers only syntactic aspects of QMP. +ERST + DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, "-fw_cfg [name=3D],file=3D\n" " add named fw_cfg entry with contents from file\n" --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447109; cv=none; d=zohomail.com; s=zohoarc; b=BdKnvLh84K8Yr50UrauLS14rQfX90DXANyjDYDVF7xFPYhueQXXLoJBBRrQtz91O81mNtTDDmlsBIIY693Ef7LaDw0Ff2JDDXGkzTIVO/JOlLPwxIjhQF4VRcoq5JqWMbLKDMnYtkBeq9kkGaxzPiIU9O+PrsQdOF7O2Z7dMkMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447109; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iFoWNzsJY50h+D+cw8ftjU8cjOlchFCyDTr3cIsHFwk=; b=jMbJBlETON8LJl37cuWGM2EAgCy2CmyuJh5HwuKx6uFiYUdmJR4/XvztclmhzcDYkPEquMer+hqKQ3ZzzmmKhWFdOMZekeo63tTqCuPtmAKXwOyBLYRRLhzS7VKq1wIeNRG6u3r8etJBbLwkYneqABhIkv9BClYfSwKFI9AEDKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447109923189.62965996306696; Tue, 17 Mar 2020 05:11:49 -0700 (PDT) Received: from localhost ([::1]:59978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB4W-0003h1-Ig for importer@patchew.org; Tue, 17 Mar 2020 08:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56951) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoc-0008H9-KS for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006jh-QY for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:52324) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006gR-JG for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-jyB7CPfeMAC4wADxPTavxQ-1; Tue, 17 Mar 2020 07:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7A861034B35; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38D029497E; Tue, 17 Mar 2020 11:55:12 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 84AA21135245; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iFoWNzsJY50h+D+cw8ftjU8cjOlchFCyDTr3cIsHFwk=; b=J1J3mxgdbwSz8UWU4EmsmXhqTQNB5ZKzUfX+UeChWj1tqYRZXot0gaDqYnNdYWXkPV7u8g ULsr5BV3qyiJhBBBikmz0VDi0xaPso62HHv1DGgbX1HN9UN/AYaKyJjhgaIu4da9PBQSre rI8eaV7tZjb7tNdPSZBaA678HIjWRjI= X-MC-Unique: jyB7CPfeMAC4wADxPTavxQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 28/34] qapi: Implement deprecated-output=hide for QMP command results Date: Tue, 17 Mar 2020 12:54:53 +0100 Message-Id: <20200317115459.31821-29-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP command results. Example: when QEMU is run with -compat deprecated-output=3Dhide, then {"execute": "query-cpus-fast"} yields {"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0,= "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index":= 0, "target": "x86_64"}]} instead of {"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0,= "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0= ]", "cpu-index": 0, "target": "x86_64"}]} Note the suppression of deprecated member "arch". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qobject-output-visitor.h | 9 ++++++ include/qapi/visitor-impl.h | 3 ++ include/qapi/visitor.h | 9 ++++++ qapi/qapi-visit-core.c | 9 ++++++ qapi/qobject-output-visitor.c | 19 +++++++++++ tests/test-qmp-cmds.c | 42 ++++++++++++++++++++++--- qapi/trace-events | 1 + scripts/qapi/commands.py | 2 +- scripts/qapi/visit.py | 12 +++++++ tests/qapi-schema/qapi-schema-test.json | 17 +++++----- tests/qapi-schema/qapi-schema-test.out | 18 +++++------ 11 files changed, 118 insertions(+), 23 deletions(-) diff --git a/include/qapi/qobject-output-visitor.h b/include/qapi/qobject-o= utput-visitor.h index 2b1726baf5..29f4ea6aad 100644 --- a/include/qapi/qobject-output-visitor.h +++ b/include/qapi/qobject-output-visitor.h @@ -53,4 +53,13 @@ typedef struct QObjectOutputVisitor QObjectOutputVisitor; */ Visitor *qobject_output_visitor_new(QObject **result); =20 +/* + * Create a QObject output visitor for @obj for use with QMP + * + * This is like qobject_output_visitor_new(), except it obeys the + * policy for handling deprecated management interfaces set with + * -compat. + */ +Visitor *qobject_output_visitor_new_qmp(QObject **result); + #endif diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 8ccb3b6c20..a6b26b7a5b 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -110,6 +110,9 @@ struct Visitor The core takes care of the return type in the public interface. */ void (*optional)(Visitor *v, const char *name, bool *present); =20 + /* Optional */ + bool (*deprecated)(Visitor *v, const char *name); + /* Must be set */ VisitorType type; =20 diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index c5b23851a1..c89d51b2a4 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -449,6 +449,15 @@ void visit_end_alternate(Visitor *v, void **obj); */ bool visit_optional(Visitor *v, const char *name, bool *present); =20 +/* + * Should we visit deprecated member @name? + * + * @name must not be NULL. This function is only useful between + * visit_start_struct() and visit_end_struct(), since only objects + * have deprecated members. + */ +bool visit_deprecated(Visitor *v, const char *name); + /* * Visit an enum value. * diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 5365561b07..501b3ccdef 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -137,6 +137,15 @@ bool visit_optional(Visitor *v, const char *name, bool= *present) return *present; } =20 +bool visit_deprecated(Visitor *v, const char *name) +{ + trace_visit_deprecated(v, name); + if (v->deprecated) { + return v->deprecated(v, name); + } + return true; +} + bool visit_is_input(Visitor *v) { return v->type =3D=3D VISITOR_INPUT; diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 26d7be5ec9..84cee17596 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -13,6 +13,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/qobject-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/queue.h" @@ -31,6 +32,8 @@ typedef struct QStackEntry { =20 struct QObjectOutputVisitor { Visitor visitor; + CompatPolicyOutput deprecated_policy; + QSLIST_HEAD(, QStackEntry) stack; /* Stack of unfinished containers */ QObject *root; /* Root of the output visit */ QObject **result; /* User's storage location for result */ @@ -198,6 +201,13 @@ static void qobject_output_type_null(Visitor *v, const= char *name, qobject_output_add(qov, name, qnull()); } =20 +static bool qobject_output_deprecated(Visitor *v, const char *name) +{ + QObjectOutputVisitor *qov =3D to_qov(v); + + return qov->deprecated_policy !=3D COMPAT_POLICY_OUTPUT_HIDE; +} + /* Finish building, and return the root object. * The root object is never null. The caller becomes the object's * owner, and should use qobject_unref() when done with it. */ @@ -247,6 +257,7 @@ Visitor *qobject_output_visitor_new(QObject **result) v->visitor.type_number =3D qobject_output_type_number; v->visitor.type_any =3D qobject_output_type_any; v->visitor.type_null =3D qobject_output_type_null; + v->visitor.deprecated =3D qobject_output_deprecated; v->visitor.complete =3D qobject_output_complete; v->visitor.free =3D qobject_output_free; =20 @@ -255,3 +266,11 @@ Visitor *qobject_output_visitor_new(QObject **result) =20 return &v->visitor; } + +Visitor *qobject_output_visitor_new_qmp(QObject **result) +{ + QObjectOutputVisitor *v =3D to_qov(qobject_output_visitor_new(result)); + + v->deprecated_policy =3D compat_policy.deprecated_output; + return &v->visitor; +} diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index d12ff47e26..82d599630c 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" @@ -45,12 +46,17 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp) { } =20 -void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruct1 *fs1, - FeatureStruct2 *fs2, FeatureStruct3 *fs3, - FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1, - CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3, - Error **errp) +FeatureStruct1 *qmp_test_features0(bool has_fs0, FeatureStruct0 *fs0, + bool has_fs1, FeatureStruct1 *fs1, + bool has_fs2, FeatureStruct2 *fs2, + bool has_fs3, FeatureStruct3 *fs3, + bool has_fs4, FeatureStruct4 *fs4, + bool has_cfs1, CondFeatureStruct1 *cfs1, + bool has_cfs2, CondFeatureStruct2 *cfs2, + bool has_cfs3, CondFeatureStruct3 *cfs3, + Error **errp) { + return g_new(FeatureStruct1, 1); } =20 void qmp_test_command_features1(Error **errp) @@ -271,6 +277,30 @@ static void test_dispatch_cmd_io(void) qobject_unref(ret3); } =20 +static void test_dispatch_cmd_ret_deprecated(void) +{ + const char *cmd =3D "{ 'execute': 'test-features0' }"; + QDict *ret; + + memset(&compat_policy, 0, sizeof(compat_policy)); + + /* default accept */ + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 1); + qobject_unref(ret); + + compat_policy.has_deprecated_output =3D true; + compat_policy.deprecated_output =3D COMPAT_POLICY_OUTPUT_ACCEPT; + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 1); + qobject_unref(ret); + + compat_policy.deprecated_output =3D COMPAT_POLICY_OUTPUT_HIDE; + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 0); + qobject_unref(ret); +} + /* test generated dealloc functions for generated types */ static void test_dealloc_types(void) { @@ -345,6 +375,8 @@ int main(int argc, char **argv) g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io); g_test_add_func("/qmp/dispatch_cmd_success_response", test_dispatch_cmd_success_response); + g_test_add_func("/qmp/dispatch_cmd_ret_deprecated", + test_dispatch_cmd_ret_deprecated); g_test_add_func("/qmp/dealloc_types", test_dealloc_types); g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial); =20 diff --git a/qapi/trace-events b/qapi/trace-events index 5eb4afa110..eff1fbd199 100644 --- a/qapi/trace-events +++ b/qapi/trace-events @@ -17,6 +17,7 @@ visit_start_alternate(void *v, const char *name, void *ob= j, size_t size) "v=3D%p n visit_end_alternate(void *v, void *obj) "v=3D%p obj=3D%p" =20 visit_optional(void *v, const char *name, bool *present) "v=3D%p name=3D%s= present=3D%p" +visit_deprecated(void *v, const char *name) "v=3D%p name=3D%s" =20 visit_type_enum(void *v, const char *name, int *obj) "v=3D%p name=3D%s obj= =3D%p" visit_type_int(void *v, const char *name, int64_t *obj) "v=3D%p name=3D%s = obj=3D%p" diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index bc30876c88..35b79c554d 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -69,7 +69,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_= in, QObject **ret_out, Error *err =3D NULL; Visitor *v; =20 - v =3D qobject_output_visitor_new(ret_out); + v =3D qobject_output_visitor_new_qmp(ret_out); visit_type_%(c_name)s(v, "unused", &ret_in, &err); if (!err) { visit_complete(v, ret_out); diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 23d9194aa4..21df3abed2 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -56,6 +56,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) c_type=3Dbase.c_name()) =20 for memb in members: + deprecated =3D 'deprecated' in [f.name for f in memb.features] ret +=3D gen_if(memb.ifcond) if memb.optional: ret +=3D mcgen(''' @@ -63,6 +64,12 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)= s *obj, Error **errp) ''', name=3Dmemb.name, c_name=3Dc_name(memb.name)) push_indent() + if deprecated: + ret +=3D mcgen(''' + if (visit_deprecated(v, "%(name)s")) { +''', + name=3Dmemb.name) + push_indent() ret +=3D mcgen(''' visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err); if (err) { @@ -71,6 +78,11 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)= s *obj, Error **errp) ''', c_type=3Dmemb.type.c_name(), name=3Dmemb.name, c_name=3Dc_name(memb.name)) + if deprecated: + pop_indent() + ret +=3D mcgen(''' + } +''') if memb.optional: pop_indent() ret +=3D mcgen(''' diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 6b1f05afa7..e4cce0d5b0 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -297,14 +297,15 @@ 'features': [ 'feature1' ] } =20 { 'command': 'test-features0', - 'data': { 'fs0': 'FeatureStruct0', - 'fs1': 'FeatureStruct1', - 'fs2': 'FeatureStruct2', - 'fs3': 'FeatureStruct3', - 'fs4': 'FeatureStruct4', - 'cfs1': 'CondFeatureStruct1', - 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' }, + 'data': { '*fs0': 'FeatureStruct0', + '*fs1': 'FeatureStruct1', + '*fs2': 'FeatureStruct2', + '*fs3': 'FeatureStruct3', + '*fs4': 'FeatureStruct4', + '*cfs1': 'CondFeatureStruct1', + '*cfs2': 'CondFeatureStruct2', + '*cfs3': 'CondFeatureStruct3' }, + 'returns': 'FeatureStruct1', 'features': [] } =20 { 'command': 'test-command-features1', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 891b4101e0..cd53323abd 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -407,15 +407,15 @@ alternate FeatureAlternate1 case eins: FeatureStruct1 feature feature1 object q_obj_test-features0-arg - member fs0: FeatureStruct0 optional=3DFalse - member fs1: FeatureStruct1 optional=3DFalse - member fs2: FeatureStruct2 optional=3DFalse - member fs3: FeatureStruct3 optional=3DFalse - member fs4: FeatureStruct4 optional=3DFalse - member cfs1: CondFeatureStruct1 optional=3DFalse - member cfs2: CondFeatureStruct2 optional=3DFalse - member cfs3: CondFeatureStruct3 optional=3DFalse -command test-features0 q_obj_test-features0-arg -> None + member fs0: FeatureStruct0 optional=3DTrue + member fs1: FeatureStruct1 optional=3DTrue + member fs2: FeatureStruct2 optional=3DTrue + member fs3: FeatureStruct3 optional=3DTrue + member fs4: FeatureStruct4 optional=3DTrue + member cfs1: CondFeatureStruct1 optional=3DTrue + member cfs2: CondFeatureStruct2 optional=3DTrue + member cfs3: CondFeatureStruct3 optional=3DTrue +command test-features0 q_obj_test-features0-arg -> FeatureStruct1 gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446994; cv=none; d=zohomail.com; s=zohoarc; b=E3B1xJca0K7sRDDQ4r4zXSgLsINGUHAMJfm1KQGcENLKt+UyJGMSfqWvQjXJhIVxRDgZqO5+dqcIVcbb+3V36WJxwLMJ0CHMS1vtXIsHDtdX0SU/GJNz7XTPT3XEbBjvm0v7/JQ7qRZ9gdkUuzqbz5ih6zgCBVL4KDa31XHg4IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446994; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Fq4EW+oFromDiIjy76Jj42Gb0RRXNiFOAif+yCT6AnU=; b=TvhGWPJ1CiUoQK0lUbs0r7F5jQlp3+SNv/G80BrCKyDuaO9fR32vMBz850T5A6/I8YwHKaycFhdwIKiMFwnUlEvjxCXI03afJ0069xjWpRe6B9g1vmbJqP6SKo/gNWf3Mxy+W1IfT5piDvaW55/hlOQrmBomCv65mT1j9bysySQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446994713592.3317914793031; Tue, 17 Mar 2020 05:09:54 -0700 (PDT) Received: from localhost ([::1]:59916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB2f-0008MU-Fr for importer@patchew.org; Tue, 17 Mar 2020 08:09:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56855) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoa-0008CM-52 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoX-0006jF-Ml for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:21375) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoX-0006fa-F1 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-bZpEtGPXNSmUV9zYQAcbMw-1; Tue, 17 Mar 2020 07:55:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B8998014D7; Tue, 17 Mar 2020 11:55:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05BEB5F700; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8953C1135246; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fq4EW+oFromDiIjy76Jj42Gb0RRXNiFOAif+yCT6AnU=; b=B0EGG9Q8K3qcrBzaZCViS64Rzer6p/I+mftvN+nEFKZfJMV0ZyiD1oaLy6P/eQ2K62/KKZ 2mWfblGUhUine7JVxS5LeC/avDOo0H6PLr9NV8ljtzsRLZg7NcQk2ANGr0b2NBa3xwfrkY 4VpNh4dLxQu1D+zAcMeCgY8g4KrdioM= X-MC-Unique: bZpEtGPXNSmUV9zYQAcbMw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 29/34] qapi: Implement deprecated-output=hide for QMP events Date: Tue, 17 Mar 2020 12:54:54 +0100 Message-Id: <20200317115459.31821-30-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP events: suppress deprecated ones. No QMP event is deprecated right now. Signed-off-by: Markus Armbruster --- tests/test-qmp-event.c | 19 +++++++++++++++++++ scripts/qapi/events.py | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 7dd0053190..ae4913ceb3 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" =20 #include "qemu-common.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" @@ -140,6 +141,23 @@ static void test_event_d(TestEventData *data, qobject_unref(data->expect); } =20 +static void test_event_deprecated(TestEventData *data, const void *unused) +{ + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATU= RES1' }"); + + memset(&compat_policy, 0, sizeof(compat_policy)); + + qapi_event_send_test_event_features1(); + g_assert(data->emitted); + + compat_policy.deprecated_output =3D COMPAT_POLICY_OUTPUT_HIDE; + data->emitted =3D false; + qapi_event_send_test_event_features1(); + g_assert(!data->emitted); + + qobject_unref(data->expect); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -148,6 +166,7 @@ int main(int argc, char **argv) event_test_add("/event/event_b", test_event_b); event_test_add("/event/event_c", test_event_c); event_test_add("/event/event_d", test_event_d); + event_test_add("/event/deprecated", test_event_deprecated); g_test_run(); =20 return 0; diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index b544af5a1c..95ca4b4753 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -61,7 +61,8 @@ def gen_param_var(typ): return ret =20 =20 -def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): +def gen_event_send(name, arg_type, features, boxed, + event_enum_name, event_emit): # FIXME: Our declaration of local variables (and of 'errp' in the # parameter list) can collide with exploded members of the event's # data type passed in as parameters. If this collision ever hits in @@ -86,6 +87,14 @@ def gen_event_send(name, arg_type, boxed, event_enum_nam= e, event_emit): if not boxed: ret +=3D gen_param_var(arg_type) =20 + if 'deprecated' in [f.name for f in features]: + ret +=3D mcgen(''' + + if (compat_policy.deprecated_output =3D=3D COMPAT_POLICY_OUTPUT_HIDE) { + return; + } +''') + ret +=3D mcgen(''' =20 qmp =3D qmp_event_build_dict("%(name)s"); @@ -154,6 +163,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): #include "%(prefix)sqapi-emit-events.h" #include "%(events)s.h" #include "%(visit)s.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qapi/qobject-output-visitor.h" @@ -192,7 +202,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) - self._genc.add(gen_event_send(name, arg_type, boxed, + self._genc.add(gen_event_send(name, arg_type, features, boxed, self._event_enum_name, self._event_emit_name)) # Note: we generate the enum member regardless of @ifcond, to --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446781; cv=none; d=zohomail.com; s=zohoarc; b=VRxYi8dGUxTMFnwm541gsUxwGkP6VFTQu2YiRiqlsoIaj/nf1BXhFNHIym78kRYW1tFWC+MEFPGJ1FTIvyHKg6tD40ORTxtnfgcXkEFfssmEDjl2p/ZP9lRRxYBtSTyFuqXdRr5XPGvlG/NJkLUMIIG6Ov2M5XMhduhzZ+Z28Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446781; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CvOx35c4RmSVqE2C8Lo+PAWiSQ8b2GO0AA0lr3sVtLs=; b=hQLndloShIJe+bBrnc7MPP3de2ob20+GacHwHKYKO2Tun/Fjk+MW8NCQxrPmysVdJdwObD/SdBCYag3zIeSUVs1ArJFYL4+MsKmTC+hVhRxWPoyjzwwLUitGxuX/VZZlwkIh6xo71kke0DxmOOJZq0QtcBccyhy31jVt6mPX+0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446781281410.2389353687727; Tue, 17 Mar 2020 05:06:21 -0700 (PDT) Received: from localhost ([::1]:59810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAzE-0000mw-7N for importer@patchew.org; Tue, 17 Mar 2020 08:06:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56814) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoY-00089E-Kb for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoW-0006eB-Ut for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:56675) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoW-0006c3-PO for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-BAj-RO45PcqVY6HeXtGSFA-1; Tue, 17 Mar 2020 07:55:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC0E8805751; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A4C628980; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8EEC0113525D; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CvOx35c4RmSVqE2C8Lo+PAWiSQ8b2GO0AA0lr3sVtLs=; b=AuX5yWNwsDQChUxMtzvteYcYzZWKZQYRxMN/1w/fso9CxwCaZ5Bv9gI8mRneqs91xGZY29 U79QO9iWtjs0hsb0d2SawVOt5qLk/FkcJoUMDE50dwX+xmiBE8544oSQ4G1fkspy0trpXW 3ogpzJJ30beVghNngI7Ra3oGS3aI7n8= X-MC-Unique: BAj-RO45PcqVY6HeXtGSFA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 30/34] qapi: Implement deprecated-output=hide for QMP event data Date: Tue, 17 Mar 2020 12:54:55 +0100 Message-Id: <20200317115459.31821-31-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP event data: suppress deprecated members. No QMP event data is deprecated right now. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qmp-event.c | 20 ++++++++++++++++++++ scripts/qapi/events.py | 8 ++++++-- tests/qapi-schema/qapi-schema-test.json | 3 +++ tests/qapi-schema/qapi-schema-test.out | 2 ++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index ae4913ceb3..8f77485454 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -158,6 +158,25 @@ static void test_event_deprecated(TestEventData *data,= const void *unused) qobject_unref(data->expect); } =20 +static void test_event_deprecated_data(TestEventData *data, const void *un= used) +{ + memset(&compat_policy, 0, sizeof(compat_policy)); + + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATU= RES0'," + " 'data': { 'foo': 42 } }"); + qapi_event_send_test_event_features0(42); + g_assert(data->emitted); + + qobject_unref(data->expect); + + compat_policy.deprecated_output =3D COMPAT_POLICY_OUTPUT_HIDE; + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATU= RES0' }"); + qapi_event_send_test_event_features0(42); + g_assert(data->emitted); + + qobject_unref(data->expect); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -167,6 +186,7 @@ int main(int argc, char **argv) event_test_add("/event/event_c", test_event_c); event_test_add("/event/event_d", test_event_d); event_test_add("/event/deprecated", test_event_deprecated); + event_test_add("/event/deprecated_data", test_event_deprecated_data); g_test_run(); =20 return 0; diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 95ca4b4753..f03c825cc1 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -104,7 +104,7 @@ def gen_event_send(name, arg_type, features, boxed, =20 if have_args: ret +=3D mcgen(''' - v =3D qobject_output_visitor_new(&obj); + v =3D qobject_output_visitor_new_qmp(&obj); ''') if not arg_type.is_implicit(): ret +=3D mcgen(''' @@ -123,7 +123,11 @@ def gen_event_send(name, arg_type, features, boxed, ret +=3D mcgen(''' =20 visit_complete(v, &obj); - qdict_put_obj(qmp, "data", obj); + if (qdict_size(qobject_to(QDict, obj))) { + qdict_put_obj(qmp, "data", obj); + } else { + qobject_unref(obj); + } ''') =20 ret +=3D mcgen(''' diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index e4cce0d5b0..23f58b8724 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -322,5 +322,8 @@ 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } =20 +{ 'event': 'TEST-EVENT-FEATURES0', + 'data': 'FeatureStruct1' } + { 'event': 'TEST-EVENT-FEATURES1', 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index cd53323abd..1a63d3bca7 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -438,6 +438,8 @@ command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] +event TEST-EVENT-FEATURES0 FeatureStruct1 + boxed=3DFalse event TEST-EVENT-FEATURES1 None boxed=3DFalse feature deprecated --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447073; cv=none; d=zohomail.com; s=zohoarc; b=b5kZH3abror6i4kWAjdi0hDPfWXjsBmerx3kVgN83RR0RNvGV8IlxqCiKWKfkPFgsJPgHxcamxy/QQV7EOEgDmTOtBvfkmFuXes3W+KMcGr4PgmiiJ2EdD8ILSYgAIxx+kv7WTuCijrwSZn5VKpZt0pSOq8E5Nd8nAcQqYytAfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oYE3kivzTU/MHGBvZenoCiESySyZ9Mfy3dijo0V7Q1w=; b=ZT4lF8pa7OJkbzJ71cL8hwLSoG5QeXnAnZYlSE8G+x+1yM+ZuUiSzC4z2BtqIk81E2noe3LZmLdFi0PBFKRT80o6N2kXtoFFotDYzekZkqDgMOvcbJeD+sY7Vz+CPqNZ3hcvj8G/G0q+ir2IUxwerOf5x7Z4vs5BzjTVMMSRmRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158444707334471.39010225936988; Tue, 17 Mar 2020 05:11:13 -0700 (PDT) Received: from localhost ([::1]:59958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB3w-0001sf-3p for importer@patchew.org; Tue, 17 Mar 2020 08:11:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56973) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAod-0008Is-Q3 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoa-00070P-RK for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:23 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:24185) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoa-0006xf-Jp for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-366-vOStGJGVMlO1EPGFmkNMxw-1; Tue, 17 Mar 2020 07:55:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E54A19251AD; Tue, 17 Mar 2020 11:55:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BAE528981; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 93A26113525E; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oYE3kivzTU/MHGBvZenoCiESySyZ9Mfy3dijo0V7Q1w=; b=Qb8hOBA07lV//6pswMhmbFduqq2tmm5sTcNJmHrunye3VAZ/S0WCspZjACqbaYtbgao8Vf jJEZi0rD8Z3vGI6zoNe2JI/IcA4aEDyH4B2+NKeI7qZCeOMsP7AA3XRIitINub6oMfvJZm rpJYifen8kWDQY6cRQ/2cgeW4Fik5dI= X-MC-Unique: vOStGJGVMlO1EPGFmkNMxw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 31/34] qapi: Implement deprecated-output=hide for QMP introspection Date: Tue, 17 Mar 2020 12:54:56 +0100 Message-Id: <20200317115459.31821-32-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP command query-qmp-schema: suppress information on deprecated commands, events and object type members, i.e. anything that has the special feature flag "deprecated". Signed-off-by: Markus Armbruster --- qapi/introspect.json | 2 +- monitor/monitor-internal.h | 3 -- monitor/misc.c | 2 - monitor/qmp-cmds-control.c | 102 ++++++++++++++++++++++++++++++++----- qemu-storage-daemon.c | 2 - 5 files changed, 90 insertions(+), 21 deletions(-) diff --git a/qapi/introspect.json b/qapi/introspect.json index b1aabd4cfd..3ebd817866 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -48,7 +48,7 @@ ## { 'command': 'query-qmp-schema', 'returns': [ 'SchemaInfo' ], - 'gen': false } # just to simplify qmp_query_json() + 'allow-preconfig': true } =20 ## # @SchemaMetaType: diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 3e6baba88f..4d402ded85 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -180,7 +180,4 @@ void help_cmd(Monitor *mon, const char *name); void handle_hmp_command(MonitorHMP *mon, const char *cmdline); int hmp_compare_cmd(const char *name, const char *list); =20 -void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, - Error **errp); - #endif diff --git a/monitor/misc.c b/monitor/misc.c index c3bc34c099..0237c71140 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -243,8 +243,6 @@ static void monitor_init_qmp_commands(void) =20 qmp_init_marshal(&qmp_commands); =20 - qmp_register_command(&qmp_commands, "query-qmp-schema", - qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG); qmp_register_command(&qmp_commands, "device_add", qmp_device_add, QCO_NO_OPTIONS); qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index 5cd9bb817c..bf5b711a7b 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -26,10 +26,14 @@ =20 #include "monitor-internal.h" #include "qemu-version.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-introspect.h" #include "qapi/qapi-emit-events.h" #include "qapi/qapi-introspect.h" +#include "qapi/qapi-visit-introspect.h" +#include "qapi/qobject-input-visitor.h" =20 /* * Accept QMP capabilities in @list for @mon. @@ -153,17 +157,89 @@ EventInfoList *qmp_query_events(Error **errp) return ev_list; } =20 -/* - * Minor hack: generated marshalling suppressed for this command - * ('gen': false in the schema) so we can parse the JSON string - * directly into QObject instead of first parsing it with - * visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it - * to QObject with generated output marshallers, every time. Instead, - * we do it in test-qobject-input-visitor.c, just to make sure - * qapi-gen.py's output actually conforms to the schema. - */ -void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, - Error **errp) -{ - *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); +static void *split_off_generic_list(void *list, + bool (*splitp)(void *elt), + void **part) +{ + GenericList *keep =3D NULL, **keep_tailp =3D &keep; + GenericList *split =3D NULL, **split_tailp =3D &split; + GenericList *tail; + + for (tail =3D list; tail; tail =3D tail->next) { + if (splitp(tail)) { + *split_tailp =3D tail; + split_tailp =3D &tail->next; + } else { + *keep_tailp =3D tail; + keep_tailp =3D &tail->next; + } + } + + *keep_tailp =3D *split_tailp =3D NULL; + *part =3D split; + return keep; +} + +static bool is_in(const char *s, strList *list) +{ + strList *tail; + + for (tail =3D list; tail; tail =3D tail->next) { + if (!strcmp(tail->value, s)) { + return true; + } + } + return false; +} + +static bool is_entity_deprecated(void *link) +{ + return is_in("deprecated", ((SchemaInfoList *)link)->value->features); +} + +static bool is_member_deprecated(void *link) +{ + return is_in("deprecated", + ((SchemaInfoObjectMemberList *)link)->value->features); +} + +static SchemaInfoList *zap_deprecated(SchemaInfoList *schema) +{ + void *to_zap; + SchemaInfoList *tail; + SchemaInfo *ent; + + schema =3D split_off_generic_list(schema, is_entity_deprecated, &to_za= p); + qapi_free_SchemaInfoList(to_zap); + + for (tail =3D schema; tail; tail =3D tail->next) { + ent =3D tail->value; + if (ent->meta_type =3D=3D SCHEMA_META_TYPE_OBJECT) { + ent->u.object.members + =3D split_off_generic_list(ent->u.object.members, + is_member_deprecated, &to_zap); + qapi_free_SchemaInfoObjectMemberList(to_zap); + } + } + + return schema; +} + +SchemaInfoList *qmp_query_qmp_schema(Error **errp) +{ + QObject *obj =3D qobject_from_qlit(&qmp_schema_qlit); + Visitor *v =3D qobject_input_visitor_new(obj); + SchemaInfoList *schema =3D NULL; + + /* test_visitor_in_qmp_introspect() ensures this can't fail */ + visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); + g_assert(schema); + + qobject_unref(obj); + visit_free(v); + + if (compat_policy.deprecated_output =3D=3D COMPAT_POLICY_OUTPUT_HIDE) { + return zap_deprecated(schema); + } + return schema; } diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index dd128978cc..23433090a8 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -142,8 +142,6 @@ static QemuOptsList qemu_object_opts =3D { static void init_qmp_commands(void) { qmp_init_marshal(&qmp_commands); - qmp_register_command(&qmp_commands, "query-qmp-schema", - qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446833; cv=none; d=zohomail.com; s=zohoarc; b=JQRMSdrF5gju48GkqgJbFcZb1hvJ+dskxXXDwtw/Fu7PsVJsn7U67OvVAI/hPM2wJCi2aZqG2nVxvieB22reHw9xoZ2Iw8UV1psCp5UOPARJQWSaOcIB2FtVah7yCWuv+xKJ0yppqbj4ipAK09mvArWoMYVAlr0IW8ZAXRJo9Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446833; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=21luhvS9y0rAMdcbNzOO4uFJBqRLIs1zjLQKrJoDI30=; b=c96osDeEQKJwPVldK8O7xrOkq0CSHNASros/85kWIUG9zxk6BhhSFF/WMi7Plb9qVQSpugo/eZxFVdQg4iUrXN93ConCHkrtWPtz3gfBvyTI4ptE7gmN1b5M1SkYZSCUAu3ZCj4ofFibiwPmB6VXMeKpuG9RD4uYU1O+9hei/II= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446833894333.8072958682611; Tue, 17 Mar 2020 05:07:13 -0700 (PDT) Received: from localhost ([::1]:59828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB04-0002oQ-Om for importer@patchew.org; Tue, 17 Mar 2020 08:07:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56923) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoc-0008GA-51 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoZ-0006qO-3b for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:21 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:20109) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoY-0006oM-So for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-i-YNyQu_MgWJGlvIQWDFDQ-1; Tue, 17 Mar 2020 07:55:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 028A085EE8E; Tue, 17 Mar 2020 11:55:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3706F10027A8; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9862D113525F; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=21luhvS9y0rAMdcbNzOO4uFJBqRLIs1zjLQKrJoDI30=; b=Jp3N8vCWprwdzWqkus+/flrr7btsG107v7/ipcMvzMU6e4bplBvzUCkyusPhbF52aVdHpL f7EfIsRkBtz/Offti4dVvZy+6I+9hwHGMmTNd36sZcm3illkZoCEs61Uf8D79BLl1QcBmS GYejFC4vVHZn+V0wHOPf5sGIZdOvPbo= X-MC-Unique: i-YNyQu_MgWJGlvIQWDFDQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 32/34] qapi: Implement deprecated-input=reject for QMP commands Date: Tue, 17 Mar 2020 12:54:57 +0100 Message-Id: <20200317115459.31821-33-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy rejects deprecated input, and thus permits "testing the future". Implement it for QMP commands: make deprecated ones fail. Example: when QEMU is run with -compat deprecated-input=3Dreject, then {"execute": "query-cpus"} fails like this {"error": {"class": "CommandNotFound", "desc": "Deprecated command quer= y-cpus disabled by policy"}} When the command is removed, the error will change to {"error": {"class": "CommandNotFound", "desc": "The command query-cpus = has not been found"}} Signed-off-by: Markus Armbruster --- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 13 +++++++++++++ tests/test-qmp-cmds.c | 24 ++++++++++++++++++++++++ scripts/qapi/commands.py | 10 +++++++--- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 9aa426a398..ef256f2bb7 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -24,6 +24,7 @@ typedef enum QmpCommandOptions QCO_NO_SUCCESS_RESP =3D (1U << 0), QCO_ALLOW_OOB =3D (1U << 1), QCO_ALLOW_PRECONFIG =3D (1U << 2), + QCO_DEPRECATED =3D (1U << 3), } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 57d823c8e1..18d62cd83b 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -130,6 +130,19 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *req= uest, "The command %s has not been found", command); goto out; } + if (cmd->options & QCO_DEPRECATED) { + switch (compat_policy.deprecated_input) { + case COMPAT_POLICY_INPUT_ACCEPT: + break; + case COMPAT_POLICY_INPUT_REJECT: + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, + "Deprecated command %s disabled by policy", + command); + goto out; + default: + abort(); + } + } if (!cmd->enabled) { error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance", diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 82d599630c..a2099fee7d 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -277,6 +277,28 @@ static void test_dispatch_cmd_io(void) qobject_unref(ret3); } =20 +static void test_dispatch_cmd_deprecated(void) +{ + const char *cmd =3D "{ 'execute': 'test-command-features1' }"; + QDict *ret; + + memset(&compat_policy, 0, sizeof(compat_policy)); + + /* accept */ + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 0); + qobject_unref(ret); + + compat_policy.has_deprecated_input =3D true; + compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_ACCEPT; + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 0); + qobject_unref(ret); + + compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_REJECT; + do_qmp_dispatch_error(false, ERROR_CLASS_COMMAND_NOT_FOUND, cmd); +} + static void test_dispatch_cmd_ret_deprecated(void) { const char *cmd =3D "{ 'execute': 'test-features0' }"; @@ -375,6 +397,8 @@ int main(int argc, char **argv) g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io); g_test_add_func("/qmp/dispatch_cmd_success_response", test_dispatch_cmd_success_response); + g_test_add_func("/qmp/dispatch_cmd_deprecated", + test_dispatch_cmd_deprecated); g_test_add_func("/qmp/dispatch_cmd_ret_deprecated", test_dispatch_cmd_ret_deprecated); g_test_add_func("/qmp/dealloc_types", test_dealloc_types); diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 35b79c554d..f628bbf144 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -194,9 +194,13 @@ out: return ret =20 =20 -def gen_register_command(name, success_response, allow_oob, allow_preconfi= g): +def gen_register_command(name, features, + success_response, allow_oob, allow_preconfig): options =3D [] =20 + if 'deprecated' in [f.name for f in features]: + options +=3D ['QCO_DEPRECATED'] + if not success_response: options +=3D ['QCO_NO_SUCCESS_RESP'] if allow_oob: @@ -302,8 +306,8 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); self._genh.add(gen_command_decl(name, arg_type, boxed, ret_typ= e)) self._genh.add(gen_marshal_decl(name)) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) - self._regy.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig= )) + self._regy.add(gen_register_command( + name, features, success_response, allow_oob, allow_preconf= ig)) =20 =20 def gen_commands(schema, output_dir, prefix): --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584447169; cv=none; d=zohomail.com; s=zohoarc; b=DI+YFjYqk17XI0b6orokaUUVO+Fl2D7ryl0F3obyAaf+9/WlqOsdsET36FhdPvpDonfz+VeHyE+ihMBn6j0AYtrk18zN853/W1QqNFOuWbXpCO4p5VnqKwO+PWo5o3efMjpYoNDgwI5udDwJUfnO2ULcqJWZz/jlC+kHaK0FeH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584447169; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=60n4UvY4nJ9qhhi+o1KATEXmoVRpzmup+ji/INf9+7E=; b=Yf6DiKJO7tof+JSlPmkkLNwhcv2cP+Bsg3J/0+ES2xArov+63xzhvCqdt1xj7wf3qgXuGTsTeiuNj1Tq0TKhOwJJEbROBCG/335zlASF1kQWikSMoM5gRuMN4R2WP4bSg4/fbTHMYN9CP7iHe9e0nRXoZHxAU8QD3rnaV/ccoVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584447169968658.8832052385018; Tue, 17 Mar 2020 05:12:49 -0700 (PDT) Received: from localhost ([::1]:60002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB5U-0005e1-OP for importer@patchew.org; Tue, 17 Mar 2020 08:12:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57039) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAog-0008PA-Us for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoe-0007Lf-Vi for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:26 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:36554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoe-0007JH-PQ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-23-kKdbWKsZO6qO_bp64ftKuA-1; Tue, 17 Mar 2020 07:55:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83F4C149E2; Tue, 17 Mar 2020 11:55:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4747F10027AA; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9D3F211336AF; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=60n4UvY4nJ9qhhi+o1KATEXmoVRpzmup+ji/INf9+7E=; b=VqSuNXoGUigJABQkna7TyhMWFbOEllBCHrsVcR/bOemysmUkkpmf+WBZt1slZYbhX9S/IM mlr2OWFgGu6XocGqoacuXMWIGz3r+ZRr6OSWn+1SARMgrYNJRY2CMnV6bioUnOzBJUIWWH bU0GGxhVfXorYnerh++noSLX/qGm0lk= X-MC-Unique: kKdbWKsZO6qO_bp64ftKuA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 33/34] qapi: Implement deprecated-input=reject for QMP command arguments Date: Tue, 17 Mar 2020 12:54:58 +0100 Message-Id: <20200317115459.31821-34-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This policy rejects deprecated input, and thus permits "testing the future". Implement it for QMP command arguments: reject commands with deprecated ones. Example: when QEMU is run with -compat deprecated-input=3Dreject, then {"execute": "eject", "arguments": {"device": "cd"}} fails like this {"error": {"class": "GenericError", "desc": "Deprecated parameter 'devi= ce' disabled by policy"}} When the argument is removed, the error will change to {"error": {"class": "GenericError", "desc": "Parameter 'device' is unex= pected"}} Signed-off-by: Markus Armbruster --- include/qapi/qobject-input-visitor.h | 9 +++++++++ include/qapi/visitor-impl.h | 2 +- include/qapi/visitor.h | 2 +- qapi/qapi-visit-core.c | 4 ++-- qapi/qobject-input-visitor.c | 28 ++++++++++++++++++++++++++++ qapi/qobject-output-visitor.c | 3 ++- tests/test-qmp-cmds.c | 25 +++++++++++++++++++++++++ scripts/qapi/commands.py | 2 +- scripts/qapi/visit.py | 10 ++++++---- 9 files changed, 75 insertions(+), 10 deletions(-) diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-in= put-visitor.h index 95985e25e5..cbc54de4ac 100644 --- a/include/qapi/qobject-input-visitor.h +++ b/include/qapi/qobject-input-visitor.h @@ -58,6 +58,15 @@ typedef struct QObjectInputVisitor QObjectInputVisitor; */ Visitor *qobject_input_visitor_new(QObject *obj); =20 +/* + * Create a QObject input visitor for @obj for use with QMP + * + * This is like qobject_input_visitor_new(), except it obeys the + * policy for handling deprecated management interfaces set with + * -compat. + */ +Visitor *qobject_input_visitor_new_qmp(QObject *obj); + /* * Create a QObject input visitor for @obj for use with keyval_parse() * diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index a6b26b7a5b..ccc159a0d2 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -111,7 +111,7 @@ struct Visitor void (*optional)(Visitor *v, const char *name, bool *present); =20 /* Optional */ - bool (*deprecated)(Visitor *v, const char *name); + bool (*deprecated)(Visitor *v, const char *name, Error **errp); =20 /* Must be set */ VisitorType type; diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index c89d51b2a4..2a3c4d0407 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -456,7 +456,7 @@ bool visit_optional(Visitor *v, const char *name, bool = *present); * visit_start_struct() and visit_end_struct(), since only objects * have deprecated members. */ -bool visit_deprecated(Visitor *v, const char *name); +bool visit_deprecated(Visitor *v, const char *name, Error **errp); =20 /* * Visit an enum value. diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 501b3ccdef..71e4978a6f 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -137,11 +137,11 @@ bool visit_optional(Visitor *v, const char *name, boo= l *present) return *present; } =20 -bool visit_deprecated(Visitor *v, const char *name) +bool visit_deprecated(Visitor *v, const char *name, Error **errp) { trace_visit_deprecated(v, name); if (v->deprecated) { - return v->deprecated(v, name); + return v->deprecated(v, name, errp); } return true; } diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 32236cbcb1..6ea93f5a7a 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -14,6 +14,7 @@ =20 #include "qemu/osdep.h" #include +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/visitor-impl.h" @@ -43,6 +44,7 @@ typedef struct StackObject { =20 struct QObjectInputVisitor { Visitor visitor; + CompatPolicyInput deprecated_policy; =20 /* Root of visit at visitor creation. */ QObject *root; @@ -640,6 +642,23 @@ static void qobject_input_optional(Visitor *v, const c= har *name, bool *present) *present =3D true; } =20 +static bool qobject_input_deprecated(Visitor *v, const char *name, + Error **errp) +{ + QObjectInputVisitor *qiv =3D to_qiv(v); + + switch (qiv->deprecated_policy) { + case COMPAT_POLICY_INPUT_ACCEPT: + return true; + case COMPAT_POLICY_INPUT_REJECT: + error_setg(errp, "Deprecated parameter '%s' disabled by policy", + name); + return false; + default: + abort(); + } +} + static void qobject_input_free(Visitor *v) { QObjectInputVisitor *qiv =3D to_qiv(v); @@ -674,6 +693,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_= new(QObject *obj) v->visitor.end_list =3D qobject_input_end_list; v->visitor.start_alternate =3D qobject_input_start_alternate; v->visitor.optional =3D qobject_input_optional; + v->visitor.deprecated =3D qobject_input_deprecated; v->visitor.free =3D qobject_input_free; =20 v->root =3D qobject_ref(obj); @@ -696,6 +716,14 @@ Visitor *qobject_input_visitor_new(QObject *obj) return &v->visitor; } =20 +Visitor *qobject_input_visitor_new_qmp(QObject *obj) +{ + QObjectInputVisitor *v =3D to_qiv(qobject_input_visitor_new(obj)); + + v->deprecated_policy =3D compat_policy.deprecated_input; + return &v->visitor; +} + Visitor *qobject_input_visitor_new_keyval(QObject *obj) { QObjectInputVisitor *v =3D qobject_input_visitor_base_new(obj); diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 84cee17596..73983ca5cc 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -201,7 +201,8 @@ static void qobject_output_type_null(Visitor *v, const = char *name, qobject_output_add(qov, name, qnull()); } =20 -static bool qobject_output_deprecated(Visitor *v, const char *name) +static bool qobject_output_deprecated(Visitor *v, const char *name, + Error **errp) { QObjectOutputVisitor *qov =3D to_qov(v); =20 diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index a2099fee7d..4ca658acf9 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -299,6 +299,29 @@ static void test_dispatch_cmd_deprecated(void) do_qmp_dispatch_error(false, ERROR_CLASS_COMMAND_NOT_FOUND, cmd); } =20 +static void test_dispatch_cmd_arg_deprecated(void) +{ + const char *cmd =3D "{ 'execute': 'test-features0'," + " 'arguments': { 'fs1': { 'foo': 42 } } }"; + QDict *ret; + + memset(&compat_policy, 0, sizeof(compat_policy)); + + /* accept */ + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 1); + qobject_unref(ret); + + compat_policy.has_deprecated_input =3D true; + compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_ACCEPT; + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 1); + qobject_unref(ret); + + compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_REJECT; + do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, cmd); +} + static void test_dispatch_cmd_ret_deprecated(void) { const char *cmd =3D "{ 'execute': 'test-features0' }"; @@ -399,6 +422,8 @@ int main(int argc, char **argv) test_dispatch_cmd_success_response); g_test_add_func("/qmp/dispatch_cmd_deprecated", test_dispatch_cmd_deprecated); + g_test_add_func("/qmp/dispatch_cmd_arg_deprecated", + test_dispatch_cmd_arg_deprecated); g_test_add_func("/qmp/dispatch_cmd_ret_deprecated", test_dispatch_cmd_ret_deprecated); g_test_add_func("/qmp/dealloc_types", test_dealloc_types); diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index f628bbf144..3fb4ed42ed 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -132,7 +132,7 @@ def gen_marshal(name, arg_type, boxed, ret_type): push_indent() =20 ret +=3D mcgen(''' - v =3D qobject_input_visitor_new(QOBJECT(args)); + v =3D qobject_input_visitor_new_qmp(QOBJECT(args)); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 21df3abed2..9119eb015b 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -66,15 +66,12 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name= )s *obj, Error **errp) push_indent() if deprecated: ret +=3D mcgen(''' - if (visit_deprecated(v, "%(name)s")) { + if (visit_deprecated(v, "%(name)s", &err)) { ''', name=3Dmemb.name) push_indent() ret +=3D mcgen(''' visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err); - if (err) { - goto out; - } ''', c_type=3Dmemb.type.c_name(), name=3Dmemb.name, c_name=3Dc_name(memb.name)) @@ -82,6 +79,11 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)= s *obj, Error **errp) pop_indent() ret +=3D mcgen(''' } +''') + ret +=3D mcgen(''' + if (err) { + goto out; + } ''') if memb.optional: pop_indent() --=20 2.21.1 From nobody Sun Apr 28 13:32:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584446841; cv=none; d=zohomail.com; s=zohoarc; b=c/6FdAf8Nx3YgVDI8cw7oGxiS0zo6MXQyj1ab262LlTQl8NsQzG7t44OlH5tCECwVgQCXtn7g3YsOveMjiddiuheMUr0u+Jma3wlQJg6hWNoJVZZXrsCrTrGIMDn0UrQ+k0x2bpBldgciND2RYwqGyL+K7zzE6CWMIVZHdxxSJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584446841; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0e0Um50E7TCBs44NSnKcmH5G7C0qOWmhvpEoLzLz/DQ=; b=ncI3T4k3AceZEzVdOZ9GklKsHnb8NMQaKe6rRRm5sM2xiXkvJtFsmqKkDPs7JJWshqzDPfJq+Jv3A1AKV+8cSpXCZfleEpalQUlqOy/FQ13MPTocmlHpx5LbGuWvUW+wgC+85V9JN3r+vM8hHxE0sjLTCmFXzhLSkpftBbaeKS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584446841186665.1487819308164; Tue, 17 Mar 2020 05:07:21 -0700 (PDT) Received: from localhost ([::1]:59832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEB0C-00034h-2g for importer@patchew.org; Tue, 17 Mar 2020 08:07:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56924) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAoc-0008GD-3c for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEAoZ-0006st-G9 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:21 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:27547) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEAoZ-0006q6-9j for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:55:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-eoEJyeDfPv-DHMzydiK_TA-1; Tue, 17 Mar 2020 07:55:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 094B813F5; Tue, 17 Mar 2020 11:55:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5408E5C541; Tue, 17 Mar 2020 11:55:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A204C11336B0; Tue, 17 Mar 2020 12:55:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584446118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0e0Um50E7TCBs44NSnKcmH5G7C0qOWmhvpEoLzLz/DQ=; b=VPHZNoLWYkzTLveiylVxx+GsPNq7Ix49CFAaxpDgQQQCPvinWHPl5EaIxLumPdjscJuOG/ Li6yfs5s8Zc3Vhu1AXS3caG9jB8gR6eOKD9UnKioOJaM1gDrTXT0eYzxgScxCWZHLiz4ua eDnydjJ4r1fhyZrtm0utKqWE8jU7YP4= X-MC-Unique: eoEJyeDfPv-DHMzydiK_TA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 34/34] qapi: New -compat deprecated-input=crash Date: Tue, 17 Mar 2020 12:54:59 +0100 Message-Id: <20200317115459.31821-35-armbru@redhat.com> In-Reply-To: <20200317115459.31821-1-armbru@redhat.com> References: <20200317115459.31821-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@gmail.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Policy "crash" calls abort() when deprecated input is received. Bugs in integration tests may mask the error from policy "reject". Provide a larger hammer: crash outright. Masking that seems unlikely. Signed-off-by: Markus Armbruster --- qapi/compat.json | 3 ++- qapi/qmp-dispatch.c | 1 + qapi/qobject-input-visitor.c | 1 + qemu-options.hx | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qapi/compat.json b/qapi/compat.json index fd6f8e932c..ec24567639 100644 --- a/qapi/compat.json +++ b/qapi/compat.json @@ -11,11 +11,12 @@ # # @accept: Accept silently # @reject: Reject with an error +# @crash: abort() the process # # Since: 5.0 ## { 'enum': 'CompatPolicyInput', - 'data': [ 'accept', 'reject' ] } + 'data': [ 'accept', 'reject', 'crash' ] } =20 ## # @CompatPolicyOutput: diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 18d62cd83b..90335a1b7f 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -139,6 +139,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, "Deprecated command %s disabled by policy", command); goto out; + case COMPAT_POLICY_INPUT_CRASH: default: abort(); } diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 6ea93f5a7a..a74c901be9 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -654,6 +654,7 @@ static bool qobject_input_deprecated(Visitor *v, const = char *name, error_setg(errp, "Deprecated parameter '%s' disabled by policy", name); return false; + case COMPAT_POLICY_INPUT_CRASH: default: abort(); } diff --git a/qemu-options.hx b/qemu-options.hx index 263d18d63a..7052d6e802 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3358,7 +3358,7 @@ DEFHEADING() DEFHEADING(Debug/Expert options:) =20 DEF("compat", HAS_ARG, QEMU_OPTION_compat, - "-compat [deprecated-input=3Daccept|reject][,deprecated-output=3Daccep= t|hide]\n" + "-compat [deprecated-input=3Daccept|reject|crash][,deprecated-output= =3Daccept|hide]\n" " Policy for handling deprecated management interfaces\= n", QEMU_ARCH_ALL) SRST @@ -3369,6 +3369,8 @@ SRST Accept deprecated commands and arguments ``deprecated-input=3Dreject`` Reject deprecated commands and arguments + ``deprecated-input=3Dcrash`` + Crash on deprecated command ``deprecated-output=3Daccept`` (default) Emit deprecated command results and events ``deprecated-output=3Dhide`` --=20 2.21.1