From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633287125925.8089328386824; Wed, 21 Mar 2018 04:54:47 -0700 (PDT) Received: from localhost ([::1]:54147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycKD-0006fG-CG for importer@patchew.org; Wed, 21 Mar 2018 07:54:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIA-0004vC-6w for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycI7-0007eE-1X for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53180 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycI6-0007dc-TE for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8AAE4040853 for ; Wed, 21 Mar 2018 11:52:21 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A6FD10B0094; Wed, 21 Mar 2018 11:52:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:23 +0100 Message-Id: <20180321115211.17937-2-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 01/49] qapi/visit: remove useless prefix argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/visit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 5d72d8936c..3c5ea1289e 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -293,7 +293,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): #include "qapi/qmp/qerror.h" #include "%(visit)s.h" ''', - visit=3Dvisit, prefix=3Dself._prefix= )) + visit=3Dvisit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-visit.h" #include "%(types)s.h" --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633292197786.2417097869246; Wed, 21 Mar 2018 04:54:52 -0700 (PDT) Received: from localhost ([::1]:54148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycKI-0006lP-Up for importer@patchew.org; Wed, 21 Mar 2018 07:54:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIA-0004vD-74 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycI7-0007eQ-9I for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34884 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycI7-0007e2-54 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6C7176FB9 for ; Wed, 21 Mar 2018 11:52:26 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E24AD50331; Wed, 21 Mar 2018 11:52:23 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:24 +0100 Message-Id: <20180321115211.17937-3-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:26 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 02/49] qapi/events: generate event enum in main module X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The event generator produces an enum, and put it in the last visited module. It fits better in the main module, since it's the set of all visited events, from all modules. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/events.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 3dc523cf39..3e448ae523 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -180,8 +180,9 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): types=3Dtypes)) =20 def visit_end(self): - self._genh.add(gen_enum(self._enum_name, self._event_names)) - self._genc.add(gen_enum_lookup(self._enum_name, self._event_names)) + (genc, genh) =3D self._module[self._main_module] + genh.add(gen_enum(self._enum_name, self._event_names)) + genc.add(gen_enum_lookup(self._enum_name, self._event_names)) =20 def visit_event(self, name, info, arg_type, boxed): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633462500510.7274199133998; Wed, 21 Mar 2018 04:57:42 -0700 (PDT) Received: from localhost ([::1]:54164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycNB-0000nG-KJ for importer@patchew.org; Wed, 21 Mar 2018 07:57:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIB-0004vS-KU for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycI9-0007fz-C1 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34888 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycI9-0007fR-1D for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9178BEAEB3 for ; Wed, 21 Mar 2018 11:52:28 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E46DA2022C08; Wed, 21 Mar 2018 11:52:27 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:25 +0100 Message-Id: <20180321115211.17937-4-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:28 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 03/49] qapi: add 'if' to top-level expressions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Accept 'if' key in top-level elements, accepted as string or list of string type. The following patches will modify the test visitor to check the value is correctly saved, and generate #if/#endif code (as a single #if/endif line or a series for a list). Example of 'if' key: { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, 'if': 'defined(TEST_IF_STRUCT)' } The generated code is for now *unconditional*. Later patches generate the conditionals. A following patch for qapi-code-gen.txt will provide more complete documentation for 'if' usage. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 35 ++++++++++++++++++++---- tests/test-qmp-cmds.c | 6 ++++ tests/Makefile.include | 6 ++++ tests/qapi-schema/bad-if-empty-list.err | 1 + tests/qapi-schema/bad-if-empty-list.exit | 1 + tests/qapi-schema/bad-if-empty-list.json | 3 ++ tests/qapi-schema/bad-if-empty-list.out | 0 tests/qapi-schema/bad-if-empty.err | 1 + tests/qapi-schema/bad-if-empty.exit | 1 + tests/qapi-schema/bad-if-empty.json | 3 ++ tests/qapi-schema/bad-if-empty.out | 0 tests/qapi-schema/bad-if-list.err | 1 + tests/qapi-schema/bad-if-list.exit | 1 + tests/qapi-schema/bad-if-list.json | 3 ++ tests/qapi-schema/bad-if-list.out | 0 tests/qapi-schema/bad-if.err | 1 + tests/qapi-schema/bad-if.exit | 1 + tests/qapi-schema/bad-if.json | 3 ++ tests/qapi-schema/bad-if.out | 0 tests/qapi-schema/qapi-schema-test.json | 20 ++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 22 +++++++++++++++ 21 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 tests/qapi-schema/bad-if-empty-list.err create mode 100644 tests/qapi-schema/bad-if-empty-list.exit create mode 100644 tests/qapi-schema/bad-if-empty-list.json create mode 100644 tests/qapi-schema/bad-if-empty-list.out create mode 100644 tests/qapi-schema/bad-if-empty.err create mode 100644 tests/qapi-schema/bad-if-empty.exit create mode 100644 tests/qapi-schema/bad-if-empty.json create mode 100644 tests/qapi-schema/bad-if-empty.out create mode 100644 tests/qapi-schema/bad-if-list.err create mode 100644 tests/qapi-schema/bad-if-list.exit create mode 100644 tests/qapi-schema/bad-if-list.json create mode 100644 tests/qapi-schema/bad-if-list.out create mode 100644 tests/qapi-schema/bad-if.err create mode 100644 tests/qapi-schema/bad-if.exit create mode 100644 tests/qapi-schema/bad-if.json create mode 100644 tests/qapi-schema/bad-if.out diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 2c05e3c284..4f9e02b0b4 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -637,6 +637,27 @@ def add_name(name, info, meta, implicit=3DFalse): all_names[name] =3D meta =20 =20 +def check_if(expr, info): + + def check_if_str(ifcond, info): + if not isinstance(ifcond, str): + raise QAPISemError( + info, "'if' condition must be a string or a list of string= s") + if ifcond =3D=3D '': + raise QAPISemError(info, "'if' condition '' makes no sense") + + ifcond =3D expr.get('if') + if ifcond is None: + return + if isinstance(ifcond, list): + if ifcond =3D=3D []: + raise QAPISemError(info, "'if' condition [] is useless") + for elt in ifcond: + check_if_str(elt, info) + else: + check_if_str(ifcond, info) + + def check_type(info, source, value, allow_array=3DFalse, allow_dict=3DFalse, allow_optional=3DFalse, allow_metas=3D[]): @@ -876,6 +897,8 @@ def check_keys(expr_elem, meta, required, optional=3D[]= ): raise QAPISemError(info, "'%s' of %s '%s' should only use true value" % (key, meta, name)) + if key =3D=3D 'if': + check_if(expr, info) for key in required: if key not in expr: raise QAPISemError(info, "Key '%s' is missing from %s '%s'" @@ -904,28 +927,28 @@ def check_exprs(exprs): =20 if 'enum' in expr: meta =3D 'enum' - check_keys(expr_elem, 'enum', ['data'], ['prefix']) + check_keys(expr_elem, 'enum', ['data'], ['if', 'prefix']) enum_types[expr[meta]] =3D expr elif 'union' in expr: meta =3D 'union' check_keys(expr_elem, 'union', ['data'], - ['base', 'discriminator']) + ['base', 'discriminator', 'if']) union_types[expr[meta]] =3D expr elif 'alternate' in expr: meta =3D 'alternate' - check_keys(expr_elem, 'alternate', ['data']) + check_keys(expr_elem, 'alternate', ['data'], ['if']) elif 'struct' in expr: meta =3D 'struct' - check_keys(expr_elem, 'struct', ['data'], ['base']) + check_keys(expr_elem, 'struct', ['data'], ['base', 'if']) struct_types[expr[meta]] =3D expr elif 'command' in expr: meta =3D 'command' check_keys(expr_elem, 'command', [], ['data', 'returns', 'gen', 'success-response', - 'boxed', 'allow-oob']) + 'boxed', 'allow-oob', 'if']) elif 'event' in expr: meta =3D 'event' - check_keys(expr_elem, 'event', [], ['data', 'boxed']) + check_keys(expr_elem, 'event', [], ['data', 'boxed', 'if']) else: raise QAPISemError(expr_elem['info'], "Expression is missing metatype") diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 93fbbb1b73..c25fc2100a 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -12,6 +12,12 @@ =20 static QmpCommandList qmp_commands; =20 +/* #if defined(TEST_IF_STRUCT) && defined(TEST_IF_CMD) */ +void qmp_TestIfCmd(TestIfStruct *foo, Error **errp) +{ +} +/* #endif */ + void qmp_user_def_cmd(Error **errp) { } diff --git a/tests/Makefile.include b/tests/Makefile.include index 0b277036df..f77ad2ba3b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -436,6 +436,10 @@ qapi-schema +=3D args-unknown.json qapi-schema +=3D bad-base.json qapi-schema +=3D bad-data.json qapi-schema +=3D bad-ident.json +qapi-schema +=3D bad-if.json +qapi-schema +=3D bad-if-empty.json +qapi-schema +=3D bad-if-empty-list.json +qapi-schema +=3D bad-if-list.json qapi-schema +=3D bad-type-bool.json qapi-schema +=3D bad-type-dict.json qapi-schema +=3D bad-type-int.json @@ -933,6 +937,8 @@ $(patsubst %, check-%, $(check-qapi-schema-y)): check-%= .json: $(SRC_PATH)/%.json "TEST","$*.out") @# Sanitize error messages (make them independent of build directory) @perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff -u $(SRC_PATH)/$*.= err - + @if test "$(QAPI_REGENERATE)" =3D=3D 1 ; then cp $*.test.out $(SRC_PATH)/= $*.out ; fi + @if test "$(QAPI_REGENERATE)" =3D=3D 1 ; then cp $*.test.err $(SRC_PATH)/= $*.err ; fi @diff -u $(SRC_PATH)/$*.out $*.test.out @diff -u $(SRC_PATH)/$*.exit $*.test.exit =20 diff --git a/tests/qapi-schema/bad-if-empty-list.err b/tests/qapi-schema/ba= d-if-empty-list.err new file mode 100644 index 0000000000..75fe6497bc --- /dev/null +++ b/tests/qapi-schema/bad-if-empty-list.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-if-empty-list.json:2: 'if' condition [] is useless diff --git a/tests/qapi-schema/bad-if-empty-list.exit b/tests/qapi-schema/b= ad-if-empty-list.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/bad-if-empty-list.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-if-empty-list.json b/tests/qapi-schema/b= ad-if-empty-list.json new file mode 100644 index 0000000000..94f2eb8670 --- /dev/null +++ b/tests/qapi-schema/bad-if-empty-list.json @@ -0,0 +1,3 @@ +# check empty 'if' list +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': [] } diff --git a/tests/qapi-schema/bad-if-empty-list.out b/tests/qapi-schema/ba= d-if-empty-list.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/bad-if-empty.err b/tests/qapi-schema/bad-if-= empty.err new file mode 100644 index 0000000000..358bdc3e51 --- /dev/null +++ b/tests/qapi-schema/bad-if-empty.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-if-empty.json:2: 'if' condition '' makes no sense diff --git a/tests/qapi-schema/bad-if-empty.exit b/tests/qapi-schema/bad-if= -empty.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/bad-if-empty.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-if-empty.json b/tests/qapi-schema/bad-if= -empty.json new file mode 100644 index 0000000000..fe1dd4eca6 --- /dev/null +++ b/tests/qapi-schema/bad-if-empty.json @@ -0,0 +1,3 @@ +# check empty 'if' +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': '' } diff --git a/tests/qapi-schema/bad-if-empty.out b/tests/qapi-schema/bad-if-= empty.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/bad-if-list.err b/tests/qapi-schema/bad-if-l= ist.err new file mode 100644 index 0000000000..0af6316f78 --- /dev/null +++ b/tests/qapi-schema/bad-if-list.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-if-list.json:2: 'if' condition '' makes no sense diff --git a/tests/qapi-schema/bad-if-list.exit b/tests/qapi-schema/bad-if-= list.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/bad-if-list.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-if-list.json b/tests/qapi-schema/bad-if-= list.json new file mode 100644 index 0000000000..49ced9b9ca --- /dev/null +++ b/tests/qapi-schema/bad-if-list.json @@ -0,0 +1,3 @@ +# check invalid 'if' content +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': ['foo', ''] } diff --git a/tests/qapi-schema/bad-if-list.out b/tests/qapi-schema/bad-if-l= ist.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/bad-if.err b/tests/qapi-schema/bad-if.err new file mode 100644 index 0000000000..c2e3f5f44c --- /dev/null +++ b/tests/qapi-schema/bad-if.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-if.json:2: 'if' condition must be a string or a list= of strings diff --git a/tests/qapi-schema/bad-if.exit b/tests/qapi-schema/bad-if.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/bad-if.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-if.json b/tests/qapi-schema/bad-if.json new file mode 100644 index 0000000000..3edd1a0bf2 --- /dev/null +++ b/tests/qapi-schema/bad-if.json @@ -0,0 +1,3 @@ +# check invalid 'if' type +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': { 'value': 'defined(TEST_IF_STRUCT)' } } diff --git a/tests/qapi-schema/bad-if.out b/tests/qapi-schema/bad-if.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 c72dbd8050..b997b2d43d 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -188,3 +188,23 @@ 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' }, 'returns': '__org.qemu_x-Union1' } + +# test 'if' condition handling + +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': 'defined(TEST_IF_STRUCT)' } + +{ 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ], + 'if': 'defined(TEST_IF_ENUM)' } + +{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, + 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } + +{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, + 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } + +{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' }, + 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] } + +{ 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, + 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 012e7fc06a..b11682314c 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -230,3 +230,25 @@ object q_obj___org.qemu_x-command-arg member d: __org.qemu_x-Alt optional=3DFalse command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_= x-Union1 gen=3DTrue success_response=3DTrue boxed=3DFalse +object TestIfStruct + member foo: int optional=3DFalse +enum TestIfEnum ['foo', 'bar'] +object q_obj_TestStruct-wrapper + member data: TestStruct optional=3DFalse +enum TestIfUnionKind ['foo'] +object TestIfUnion + member type: TestIfUnionKind optional=3DFalse + tag type + case foo: q_obj_TestStruct-wrapper +alternate TestIfAlternate + tag type + case foo: int + case bar: TestStruct +object q_obj_TestIfCmd-arg + member foo: TestIfStruct optional=3DFalse +command TestIfCmd q_obj_TestIfCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse +object q_obj_TestIfEvent-arg + member foo: TestIfStruct optional=3DFalse +event TestIfEvent q_obj_TestIfEvent-arg + boxed=3DFalse --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633470280546.2521204852234; Wed, 21 Mar 2018 04:57:50 -0700 (PDT) Received: from localhost ([::1]:54165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycNJ-0000w5-F7 for importer@patchew.org; Wed, 21 Mar 2018 07:57:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIC-0004wC-UC for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIB-0007hL-2T for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34892 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIA-0007gs-Tg for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6729D76FB9 for ; Wed, 21 Mar 2018 11:52:30 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC7F510B0099; Wed, 21 Mar 2018 11:52:29 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:26 +0100 Message-Id: <20180321115211.17937-5-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 04/49] qapi: pass 'if' condition into QAPISchemaEntity objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Built-in objects remain unconditional. Explicitly defined objects use the condition specified in the schema. Implicitly defined objects inherit their condition from their users. For most of them, there is exactly one user, so the condition to use is obvious. The exception is the wrapped type's generated for simple union variants, which can be shared by any number of simple unions. The tight condition would be the disjunction of the conditions of these simple unions. For now, use wrapped type's condition instead. Much simpler and good enough for now. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 97 ++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 4f9e02b0b4..d8ab3d8f7f 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1006,8 +1006,16 @@ def check_exprs(exprs): # Schema compiler frontend # =20 +def listify_cond(ifcond): + if not ifcond: + return [] + if not isinstance(ifcond, list): + return [ifcond] + return ifcond + + class QAPISchemaEntity(object): - def __init__(self, name, info, doc): + def __init__(self, name, info, doc, ifcond=3DNone): assert name is None or isinstance(name, str) self.name =3D name self.module =3D None @@ -1018,6 +1026,7 @@ class QAPISchemaEntity(object): # such place). self.info =3D info self.doc =3D doc + self.ifcond =3D listify_cond(ifcond) =20 def c_name(self): return c_name(self.name) @@ -1150,8 +1159,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 =20 class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, doc, values, prefix): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, ifcond, values, prefix): + QAPISchemaType.__init__(self, name, info, doc, ifcond) for v in values: assert isinstance(v, QAPISchemaMember) v.set_owner(name) @@ -1186,7 +1195,7 @@ class QAPISchemaEnumType(QAPISchemaType): =20 class QAPISchemaArrayType(QAPISchemaType): def __init__(self, name, info, element_type): - QAPISchemaType.__init__(self, name, info, None) + QAPISchemaType.__init__(self, name, info, None, None) assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type =3D None @@ -1194,6 +1203,7 @@ class QAPISchemaArrayType(QAPISchemaType): def check(self, schema): self.element_type =3D schema.lookup_type(self._element_type_name) assert self.element_type + self.ifcond =3D self.element_type.ifcond =20 def is_implicit(self): return True @@ -1215,11 +1225,12 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, base, local_members, variants): + def __init__(self, name, info, doc, ifcond, + 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 - QAPISchemaType.__init__(self, name, info, doc) + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) @@ -1407,8 +1418,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTyp= eMember): =20 =20 class QAPISchemaAlternateType(QAPISchemaType): - def __init__(self, name, info, doc, variants): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, ifcond, variants): + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_owner(name) @@ -1444,9 +1455,9 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 =20 class QAPISchemaCommand(QAPISchemaEntity): - def __init__(self, name, info, doc, arg_type, ret_type, + def __init__(self, name, info, doc, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): - QAPISchemaEntity.__init__(self, name, info, doc) + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type @@ -1485,8 +1496,8 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 =20 class QAPISchemaEvent(QAPISchemaEntity): - def __init__(self, name, info, doc, arg_type, boxed): - QAPISchemaEntity.__init__(self, name, info, doc) + def __init__(self, name, info, doc, ifcond, arg_type, boxed): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -1581,22 +1592,22 @@ class QAPISchema(object): ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( - 'q_empty', None, None, None, [], None) + 'q_empty', None, None, None, None, [], None) self._def_entity(self.the_empty_object_type) qtype_values =3D self._make_enum_members(['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist= ', 'qbool']) - self._def_entity(QAPISchemaEnumType('QType', None, None, + self._def_entity(QAPISchemaEnumType('QType', None, None, None, qtype_values, 'QTYPE')) =20 def _make_enum_members(self, values): return [QAPISchemaMember(v) for v in values] =20 - def _make_implicit_enum_type(self, name, info, values): + def _make_implicit_enum_type(self, name, info, ifcond, values): # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( - name, info, None, self._make_enum_members(values), None)) + name, info, None, ifcond, self._make_enum_members(values), Non= e)) return name =20 def _make_array_type(self, element_type, info): @@ -1605,22 +1616,37 @@ class QAPISchema(object): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name =20 - def _make_implicit_object_type(self, name, info, doc, role, members): + def _make_implicit_object_type(self, name, info, doc, ifcond, + role, members): if not members: return None # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D 'q_obj_%s-%s' % (name, role) - if not self.lookup_entity(name, QAPISchemaObjectType): - self._def_entity(QAPISchemaObjectType(name, info, doc, None, - members, None)) + typ =3D self.lookup_entity(name, QAPISchemaObjectType) + if typ: + # The implicit object type has multiple users. This can + # happen only for simple unions' implicit wrapper types. + # Its ifcond should be the disjunction of its user's + # ifconds. Not implemented. Instead, we always pass the + # wrapped type's ifcond, which is trivially the same for all + # users. It's also necessary for the wrapper to compile. + # But it's not tight: the disjunction need not imply it. We + # may end up compiling useless wrapper types. + # TODO kill simple unions or implement the disjunction + assert ifcond =3D=3D typ.ifcond + else: + self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, + None, members, None)) return name =20 def _def_enum_type(self, expr, info, doc): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') + ifcond =3D expr.get('if') self._def_entity(QAPISchemaEnumType( - name, info, doc, self._make_enum_members(data), prefix)) + name, info, doc, ifcond, + self._make_enum_members(data), prefix)) =20 def _make_member(self, name, typ, info): optional =3D False @@ -1640,7 +1666,8 @@ class QAPISchema(object): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] - self._def_entity(QAPISchemaObjectType(name, info, doc, base, + ifcond =3D expr.get('if') + self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, bas= e, self._make_members(data, inf= o), None)) =20 @@ -1652,18 +1679,21 @@ class QAPISchema(object): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( - typ, info, None, 'wrapper', [self._make_member('data', typ, in= fo)]) + typ, info, None, self.lookup_type(typ).ifcond, + 'wrapper', [self._make_member('data', typ, info)]) return QAPISchemaObjectTypeVariant(case, typ) =20 def _def_union_type(self, expr, info, doc): name =3D expr['union'] data =3D expr['data'] base =3D expr.get('base') + ifcond =3D expr.get('if') tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): - base =3D (self._make_implicit_object_type( - name, info, doc, 'base', self._make_members(base, info))) + base =3D self._make_implicit_object_type( + name, info, doc, ifcond, + 'base', self._make_members(base, info)) if tag_name: variants =3D [self._make_variant(key, value) for (key, value) in data.items()] @@ -1671,12 +1701,12 @@ class QAPISchema(object): else: variants =3D [self._make_simple_variant(key, value, info) for (key, value) in data.items()] - typ =3D self._make_implicit_enum_type(name, info, + typ =3D self._make_implicit_enum_type(name, info, ifcond, [v.name for v in variants]) tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] self._def_entity( - QAPISchemaObjectType(name, info, doc, base, members, + QAPISchemaObjectType(name, info, doc, ifcond, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, variants))) @@ -1684,11 +1714,12 @@ class QAPISchema(object): def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] + ifcond =3D expr.get('if') variants =3D [self._make_variant(key, value) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) self._def_entity( - QAPISchemaAlternateType(name, info, doc, + QAPISchemaAlternateType(name, info, doc, ifcond, QAPISchemaObjectTypeVariants(None, tag_membe= r, variants)= )) @@ -1701,13 +1732,14 @@ class QAPISchema(object): success_response =3D expr.get('success-response', True) boxed =3D expr.get('boxed', False) allow_oob =3D expr.get('allow-oob', False) + ifcond =3D expr.get('if') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) + name, info, doc, ifcond, 'arg', self._make_members(data, i= nfo)) 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, data, rets, + self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, data, = rets, gen, success_response, boxed, allow_oob)) =20 @@ -1715,10 +1747,11 @@ class QAPISchema(object): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) + ifcond =3D expr.get('if') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed)) + name, info, doc, ifcond, 'arg', self._make_members(data, i= nfo)) + self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, data, bo= xed)) =20 def _def_exprs(self, exprs): for expr_elem in exprs: --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633293978698.7514369349535; Wed, 21 Mar 2018 04:54:53 -0700 (PDT) Received: from localhost ([::1]:54149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycKT-0006w3-6X for importer@patchew.org; Wed, 21 Mar 2018 07:54:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIE-0004xT-6f for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIC-0007in-VM for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53192 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIC-0007iL-Q5 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D1A54040853 for ; Wed, 21 Mar 2018 11:52:32 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD1A2202322F; Wed, 21 Mar 2018 11:52:31 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:27 +0100 Message-Id: <20180321115211.17937-6-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 05/49] qapi: leave the ifcond attribute undefined until check() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We commonly initialize attributes to None in .init(), then set their real value in .check(). Accessing the attribute before .check() yields None. If we're lucky, the code that accesses the attribute prematurely chokes on None. It won't for .ifcond, because None is a legitimate value. Leave the ifcond attribute undefined until check(). Suggested-by: Markus Armbruster Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d8ab3d8f7f..eb07d641ab 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1026,13 +1026,19 @@ class QAPISchemaEntity(object): # such place). self.info =3D info self.doc =3D doc - self.ifcond =3D listify_cond(ifcond) + self._ifcond =3D ifcond # self.ifcond is set only after .check() =20 def c_name(self): return c_name(self.name) =20 def check(self, schema): - pass + if isinstance(self._ifcond, QAPISchemaType): + # inherit the condition from a type + typ =3D self._ifcond + typ.check(schema) + self.ifcond =3D typ.ifcond + else: + self.ifcond =3D listify_cond(self._ifcond) =20 def is_implicit(self): return not self.info @@ -1169,6 +1175,7 @@ class QAPISchemaEnumType(QAPISchemaType): self.prefix =3D prefix =20 def check(self, schema): + QAPISchemaType.check(self, schema) seen =3D {} for v in self.values: v.check_clash(self.info, seen) @@ -1201,8 +1208,10 @@ class QAPISchemaArrayType(QAPISchemaType): self.element_type =3D None =20 def check(self, schema): + QAPISchemaType.check(self, schema) self.element_type =3D schema.lookup_type(self._element_type_name) assert self.element_type + self.element_type.check(schema) self.ifcond =3D self.element_type.ifcond =20 def is_implicit(self): @@ -1245,6 +1254,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.members =3D None =20 def check(self, schema): + QAPISchemaType.check(self, schema) if self.members is False: # check for cycles raise QAPISemError(self.info, "Object %s contains itself" % self.name) @@ -1427,6 +1437,7 @@ class QAPISchemaAlternateType(QAPISchemaType): self.variants =3D variants =20 def check(self, schema): + QAPISchemaType.check(self, schema) self.variants.tag_member.check(schema) # Not calling self.variants.check_clash(), because there's nothing # to clash with @@ -1470,6 +1481,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.allow_oob =3D allow_oob =20 def check(self, schema): + QAPISchemaEntity.check(self, schema) if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) assert (isinstance(self.arg_type, QAPISchemaObjectType) or @@ -1504,6 +1516,7 @@ class QAPISchemaEvent(QAPISchemaEntity): self.boxed =3D boxed =20 def check(self, schema): + QAPISchemaEntity.check(self, schema) if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) assert (isinstance(self.arg_type, QAPISchemaObjectType) or @@ -1633,7 +1646,7 @@ class QAPISchema(object): # But it's not tight: the disjunction need not imply it. We # may end up compiling useless wrapper types. # TODO kill simple unions or implement the disjunction - assert ifcond =3D=3D typ.ifcond + assert ifcond =3D=3D typ._ifcond else: self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, None, members, None)) @@ -1679,7 +1692,7 @@ class QAPISchema(object): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( - typ, info, None, self.lookup_type(typ).ifcond, + typ, info, None, self.lookup_type(typ), 'wrapper', [self._make_member('data', typ, info)]) return QAPISchemaObjectTypeVariant(case, typ) =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633653214686.1690478752341; Wed, 21 Mar 2018 05:00:53 -0700 (PDT) Received: from localhost ([::1]:54184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycQG-00044B-AL for importer@patchew.org; Wed, 21 Mar 2018 08:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIH-00050s-G7 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIF-0007kL-32 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58148 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIE-0007k3-Tz for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6709780AD20C for ; Wed, 21 Mar 2018 11:52:34 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3E2110B0094; Wed, 21 Mar 2018 11:52:33 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:28 +0100 Message-Id: <20180321115211.17937-7-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:34 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 06/49] qapi: add 'ifcond' to visitor methods X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify the test visitor to check correct passing of values. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/common.py | 31 ++++++++++++++------------ scripts/qapi/doc.py | 10 ++++----- scripts/qapi/events.py | 2 +- scripts/qapi/introspect.py | 12 +++++----- scripts/qapi/types.py | 8 +++---- scripts/qapi/visit.py | 8 +++---- tests/qapi-schema/qapi-schema-test.out | 9 ++++++++ tests/qapi-schema/test-qapi.py | 19 +++++++++++----- 9 files changed, 61 insertions(+), 40 deletions(-) mode change 100644 =3D> 100755 scripts/qapi/doc.py diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 0c5da3a54d..e2366b4801 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -275,7 +275,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); c_prefix=3Dc_name(self._prefix, protect=3DFalse))) genc.add(gen_registry(self._regy, self._prefix)) =20 - def visit_command(self, name, info, arg_type, ret_type, + def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): if not gen: return diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index eb07d641ab..bc4ecd6c76 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1067,26 +1067,26 @@ class QAPISchemaVisitor(object): def visit_builtin_type(self, name, info, json_type): pass =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): pass =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, ifcond, element_type): pass =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variant= s): pass =20 - def visit_object_type_flat(self, name, info, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants= ): pass =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, ifcond, variants): pass =20 - def visit_command(self, name, info, arg_type, ret_type, + def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): pass =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, ifcond, arg_type, boxed): pass =20 =20 @@ -1196,7 +1196,7 @@ class QAPISchemaEnumType(QAPISchemaType): return 'string' =20 def visit(self, visitor): - visitor.visit_enum_type(self.name, self.info, + visitor.visit_enum_type(self.name, self.info, self.ifcond, self.member_names(), self.prefix) =20 =20 @@ -1230,7 +1230,8 @@ class QAPISchemaArrayType(QAPISchemaType): return 'array of ' + elt_doc_type =20 def visit(self, visitor): - visitor.visit_array_type(self.name, self.info, self.element_type) + visitor.visit_array_type(self.name, self.info, self.ifcond, + self.element_type) =20 =20 class QAPISchemaObjectType(QAPISchemaType): @@ -1312,9 +1313,9 @@ class QAPISchemaObjectType(QAPISchemaType): return 'object' =20 def visit(self, visitor): - visitor.visit_object_type(self.name, self.info, + visitor.visit_object_type(self.name, self.info, self.ifcond, self.base, self.local_members, self.vari= ants) - visitor.visit_object_type_flat(self.name, self.info, + visitor.visit_object_type_flat(self.name, self.info, self.ifcond, self.members, self.variants) =20 =20 @@ -1459,7 +1460,8 @@ class QAPISchemaAlternateType(QAPISchemaType): return 'value' =20 def visit(self, visitor): - visitor.visit_alternate_type(self.name, self.info, self.variants) + visitor.visit_alternate_type(self.name, self.info, self.ifcond, + self.variants) =20 def is_empty(self): return False @@ -1501,7 +1503,7 @@ class QAPISchemaCommand(QAPISchemaEntity): assert isinstance(self.ret_type, QAPISchemaType) =20 def visit(self, visitor): - visitor.visit_command(self.name, self.info, + 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) @@ -1533,7 +1535,8 @@ class QAPISchemaEvent(QAPISchemaEntity): raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") =20 def visit(self, visitor): - visitor.visit_event(self.name, self.info, self.arg_type, self.boxe= d) + visitor.visit_event(self.name, self.info, self.ifcond, + self.arg_type, self.boxed) =20 =20 class QAPISchema(object): diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py old mode 100644 new mode 100755 index 9b312b2c51..d5cfd2336b --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -204,14 +204,14 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaV= isitor): def write(self, output_dir): self._gen.write(output_dir, self._prefix + 'qapi-doc.texi') =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): doc =3D self.cur_doc self._gen.add(TYPE_FMT(type=3D'Enum', name=3Ddoc.symbol, body=3Dtexi_entity(doc, 'Values', member_func=3Dtexi_enum_va= lue))) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variant= s): doc =3D self.cur_doc if base and base.is_implicit(): base =3D None @@ -220,13 +220,13 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaV= isitor): body=3Dtexi_entity(doc, 'Members', base, variants))) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, ifcond, variants): doc =3D self.cur_doc self._gen.add(TYPE_FMT(type=3D'Alternate', name=3Ddoc.symbol, body=3Dtexi_entity(doc, 'Members'))) =20 - def visit_command(self, name, info, arg_type, ret_type, + def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): doc =3D self.cur_doc if boxed: @@ -240,7 +240,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): name=3Ddoc.symbol, body=3Dbody)) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, ifcond, arg_type, boxed): doc =3D self.cur_doc self._gen.add(MSG_FMT(type=3D'Event', name=3Ddoc.symbol, diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 3e448ae523..26ae00f6f7 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -184,7 +184,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): genh.add(gen_enum(self._enum_name, self._event_names)) genc.add(gen_enum_lookup(self._enum_name, self._event_names)) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, ifcond, arg_type, boxed): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) self._genc.add(gen_event_send(name, arg_type, boxed, self._enum_na= me)) self._event_names.append(name) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index f9e67e8227..6cb95cf53e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -152,26 +152,26 @@ const QLitObject %(c_name)s =3D %(c_string)s; def visit_builtin_type(self, name, info, json_type): self._gen_qlit(name, 'builtin', {'json-type': json_type}) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): self._gen_qlit(name, 'enum', {'values': values}) =20 - def visit_array_type(self, name, info, element_type): + 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}) =20 - def visit_object_type_flat(self, name, info, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants= ): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) self._gen_qlit(name, 'object', obj) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, ifcond, variants): self._gen_qlit(name, 'alternate', {'members': [{'type': self._use_type(m.type)} for m in variants.variants]}) =20 - def visit_command(self, name, info, arg_type, ret_type, + def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type @@ -180,7 +180,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; 'ret-type': self._use_type(ret_type), 'allow-oob': allow_oob}) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, ifcond, 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= )}) =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 64d9c0fb37..298a80db62 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -206,16 +206,16 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisi= tor): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): self._genh.preamble_add(gen_enum(name, values, prefix)) self._genc.add(gen_enum_lookup(name, values, prefix)) =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, ifcond, element_type): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variant= s): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -229,7 +229,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, variants): + def visit_alternate_type(self, name, info, ifcond, variants): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, None, [variants.tag_member], variants)) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 3c5ea1289e..9ea2e04f81 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -301,15 +301,15 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVis= itor): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, ifcond, element_type): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variant= s): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -322,7 +322,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name, base, members, variants)) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, ifcond, variants): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants)) =20 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index b11682314c..8fe9d7a3a8 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -232,23 +232,32 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> __org.qemu_x-Unio gen=3DTrue success_response=3DTrue boxed=3DFalse object TestIfStruct member foo: int optional=3DFalse + if ['defined(TEST_IF_STRUCT)'] enum TestIfEnum ['foo', 'bar'] + if ['defined(TEST_IF_ENUM)'] object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse enum TestIfUnionKind ['foo'] + if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper + if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] alternate TestIfAlternate tag type case foo: int case bar: TestStruct + if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)'] object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse + if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse + if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse + if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse + if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 10e68b01d9..6d25a37dda 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -23,12 +23,13 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_include(self, name, info): print('include %s' % name) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, ifcond, values, prefix): print('enum %s %s' % (name, values)) if prefix: print(' prefix %s' % prefix) + self._print_if(ifcond) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variant= s): print('object %s' % name) if base: print(' base %s' % base.name) @@ -36,21 +37,25 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s: %s optional=3D%s' % \ (m.name, m.type.name, m.optional)) self._print_variants(variants) + self._print_if(ifcond) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, ifcond, variants): print('alternate %s' % name) self._print_variants(variants) + self._print_if(ifcond) =20 - def visit_command(self, name, info, arg_type, ret_type, + def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): print('command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.nam= e)) print(' gen=3D%s success_response=3D%s boxed=3D%s' % \ (gen, success_response, boxed)) + self._print_if(ifcond) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, ifcond, arg_type, boxed): print('event %s %s' % (name, arg_type and arg_type.name)) print(' boxed=3D%s' % boxed) + self._print_if(ifcond) =20 @staticmethod def _print_variants(variants): @@ -59,6 +64,10 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): for v in variants.variants: print(' case %s: %s' % (v.name, v.type.name)) =20 + @staticmethod + def _print_if(ifcond, indent=3D4): + if ifcond: + print('%sif %s' % (' ' * indent, ifcond)) =20 try: schema =3D QAPISchema(sys.argv[1]) --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633297735162.826176945067; Wed, 21 Mar 2018 04:54:57 -0700 (PDT) Received: from localhost ([::1]:54150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycKW-0006zd-LI for importer@patchew.org; Wed, 21 Mar 2018 07:54:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIK-000529-0V for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIG-0007lK-QB for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42044 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIG-0007l8-Lm for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34103406DE12 for ; Wed, 21 Mar 2018 11:52:36 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8146202322F; Wed, 21 Mar 2018 11:52:35 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:29 +0100 Message-Id: <20180321115211.17937-8-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:36 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 07/49] qapi: mcgen() shouldn't indent # lines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Skip preprocessor lines when adding indentation, since that would likely result in invalid code. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index bc4ecd6c76..47efe79758 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1931,8 +1931,8 @@ def cgen(code, **kwds): if indent_level: indent =3D genindent(indent_level) # re.subn() lacks flags support before Python 2.7, use re.compile() - raw =3D re.subn(re.compile(r'^.', re.MULTILINE), - indent + r'\g<0>', raw) + raw =3D re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE), + indent, raw) raw =3D raw[0] return re.sub(re.escape(eatspace) + r' *', '', raw) =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633845600760.7539890692331; Wed, 21 Mar 2018 05:04:05 -0700 (PDT) Received: from localhost ([::1]:54202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycTM-0006jp-QB for importer@patchew.org; Wed, 21 Mar 2018 08:04:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIK-00052A-1a for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycII-0007md-Vv for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53198 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycII-0007mP-Ql for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F05E4040853 for ; Wed, 21 Mar 2018 11:52:38 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id D838D84456; Wed, 21 Mar 2018 11:52:37 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:30 +0100 Message-Id: <20180321115211.17937-9-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:38 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 08/49] qapi: add #if/#endif helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add helpers to wrap generated code with #if/#endif lines. Add QAPIGenCSnippet class to write C snippet code, make QAPIGenC inherit from it, for full C files with copyright headers etc. Add a 'with' statement context manager that will be used to wrap generator visitor methods. The manager will check if code was generated before adding #if/#endif lines on QAPIGenCSnippet objects. Used in the following patches. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 82 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 47efe79758..60c1d0a783 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,6 +12,7 @@ # See the COPYING file in the top-level directory. =20 from __future__ import print_function +from contextlib import contextmanager import errno import os import re @@ -1964,6 +1965,40 @@ def guardend(name): name=3Dguardname(name)) =20 =20 +def gen_if(ifcond): + ret =3D '' + for ifc in ifcond: + ret +=3D mcgen(''' +#if %(cond)s +''', cond=3Difc) + return ret + + +def gen_endif(ifcond): + ret =3D '' + for ifc in reversed(ifcond): + ret +=3D mcgen(''' +#endif /* %(cond)s */ +''', cond=3Difc) + return ret + + +def wrap_ifcond(ifcond, before, after): + if ifcond is None or before =3D=3D after: + return after + + assert after.startswith(before) + out =3D before + added =3D after[len(before):] + if added[0] =3D=3D '\n': + out +=3D '\n' + added =3D added[1:] + out +=3D gen_if(ifcond) + out +=3D added + out +=3D gen_endif(ifcond) + return out + + def gen_enum_lookup(name, values, prefix=3DNone): ret =3D mcgen(''' =20 @@ -2054,6 +2089,7 @@ class QAPIGen(object): def __init__(self): self._preamble =3D '' self._body =3D '' + self._ifcond =3D None =20 def preamble_add(self, text): self._preamble +=3D text @@ -2061,6 +2097,23 @@ class QAPIGen(object): def add(self, text): self._body +=3D text =20 + def start_if(self, ifcond): + self._ifcond =3D ifcond + self._start_if_body =3D self._body + self._start_if_preamble =3D self._preamble + + def _wrap_ifcond(self): + pass + + def end_if(self): + self._wrap_ifcond() + self._ifcond =3D None + + def get_content(self, fname=3DNone): + assert self._ifcond is None + return (self._top(fname) + self._preamble + self._body + + self._bottom(fname)) + def _top(self, fname): return '' =20 @@ -2078,8 +2131,7 @@ class QAPIGen(object): raise fd =3D os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) f =3D os.fdopen(fd, 'r+') - text =3D (self._top(fname) + self._preamble + self._body - + self._bottom(fname)) + text =3D self.get_content(fname) oldtext =3D f.read(len(text) + 1) if text !=3D oldtext: f.seek(0) @@ -2088,10 +2140,32 @@ class QAPIGen(object): f.close() =20 =20 -class QAPIGenC(QAPIGen): +@contextmanager +def ifcontext(ifcond, *args): + saved =3D [] + for arg in args: + arg.start_if(ifcond) + yield + for arg in args: + arg.end_if() =20 - def __init__(self, blurb, pydoc): + +class QAPIGenCSnippet(QAPIGen): + + def __init__(self): QAPIGen.__init__(self) + + def _wrap_ifcond(self): + self._body =3D wrap_ifcond(self._ifcond, + self._start_if_body, self._body) + self._preamble =3D wrap_ifcond(self._ifcond, + self._start_if_preamble, self._preamb= le) + + +class QAPIGenC(QAPIGenCSnippet): + + def __init__(self, blurb, pydoc): + QAPIGenCSnippet.__init__(self) self._blurb =3D blurb self._copyright =3D '\n * '.join(re.findall(r'^Copyright .*', pydo= c, re.MULTILINE)) --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633645641204.5395032949649; Wed, 21 Mar 2018 05:00:45 -0700 (PDT) Received: from localhost ([::1]:54180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycQ0-0003su-Gx for importer@patchew.org; Wed, 21 Mar 2018 08:00:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIL-00052G-L2 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIK-0007nT-Q0 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46132 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIK-0007nD-L3 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24929D1432 for ; Wed, 21 Mar 2018 11:52:40 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id B75028445E; Wed, 21 Mar 2018 11:52:39 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:31 +0100 Message-Id: <20180321115211.17937-10-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:52:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:52:40 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 09/49] qapi-introspect: modify to_qlit() to append ', ' on level > 0 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The following patch is going to break list entries with #if/#endif, so they should have the trailing ',' as suffix. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi/introspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 6cb95cf53e..1a8eb9e33e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -30,7 +30,7 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse= ): for elt in obj] elts.append(indent(level + 1) + "{}") ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' - ret +=3D ',\n'.join(elts) + '\n' + ret +=3D '\n'.join(elts) + '\n' ret +=3D indent(level) + '}))' elif isinstance(obj, dict): elts =3D [] @@ -45,6 +45,8 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse= ): ret +=3D 'QLIT_QBOOL(%s)' % ('true' if obj else 'false') else: assert False # not implemented + if level > 0: + ret +=3D ',' return ret =20 =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633832481781.7865855626019; Wed, 21 Mar 2018 05:03:52 -0700 (PDT) Received: from localhost ([::1]:54200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycT9-0006SY-KR for importer@patchew.org; Wed, 21 Mar 2018 08:03:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIN-00054M-I7 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIM-0007oI-Do for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34912 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIM-0007o4-8H for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C357BEB70F for ; Wed, 21 Mar 2018 11:52:41 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53F79200BCA1; Wed, 21 Mar 2018 11:52:41 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:32 +0100 Message-Id: <20180321115211.17937-11-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:41 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 10/49] qapi-introspect: add preprocessor conditions to generated QLit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The generator will take (obj, condition) tuples to wrap generated QLit objects for 'obj' with #if/#endif conditions. This commit adds 'ifcond' condition to top-level QLit objects. See generated tests/test-qmp-introspect.c. Example diff after this patch: --- before 2018-01-08 11:55:24.757083654 +0100 +++ tests/test-qmp-introspect.c 2018-01-08 13:08:44.477641629 +0100 @@ -51,6 +51,8 @@ { "name", QLIT_QSTR("EVENT_F"), }, {} })), +#if defined(TEST_IF_CMD) +#if defined(TEST_IF_STRUCT) QLIT_QDICT(((QLitDictEntry[]) { { "arg-type", QLIT_QSTR("5"), }, { "meta-type", QLIT_QSTR("command"), }, @@ -58,12 +60,16 @@ { "ret-type", QLIT_QSTR("0"), }, {} })), +#endif /* defined(TEST_IF_STRUCT) */ +#endif /* defined(TEST_IF_CMD) */ Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/introspect.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 1a8eb9e33e..cb4825f134 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -18,6 +18,15 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFals= e): def indent(level): return level * 4 * ' ' =20 + if isinstance(obj, tuple): + ifobj, ifcond =3D obj + ret =3D gen_if(ifcond) + ret +=3D to_qlit(ifobj, level) + endif =3D gen_endif(ifcond) + if endif: + ret +=3D '\n' + endif + return ret + ret =3D '' if not suppress_first_indent: ret +=3D indent(level) @@ -26,7 +35,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) + elts =3D [to_qlit(elt, level + 1).strip('\n') for elt in obj] elts.append(indent(level + 1) + "{}") ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' @@ -131,12 +140,12 @@ 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): + def _gen_qlit(self, name, mtype, obj, ifcond): if mtype not in ('command', 'event', 'builtin', 'array'): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._qlits.append(obj) + self._qlits.append((obj, ifcond)) =20 def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -152,26 +161,27 @@ const QLitObject %(c_name)s =3D %(c_string)s; return {'case': variant.name, 'type': self._use_type(variant.type)} =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}, []) =20 def visit_enum_type(self, name, info, ifcond, values, prefix): - self._gen_qlit(name, 'enum', {'values': values}) + self._gen_qlit(name, 'enum', {'values': values}, ifcond) =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_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, + ifcond) =20 def visit_object_type_flat(self, name, info, ifcond, members, variants= ): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - self._gen_qlit(name, 'object', obj) + self._gen_qlit(name, 'object', obj, ifcond) =20 def visit_alternate_type(self, name, info, ifcond, variants): self._gen_qlit(name, 'alternate', {'members': [{'type': self._use_type(m.type)} - for m in variants.variants]}) + for m in variants.variants]}, ifcond) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): @@ -180,11 +190,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_qlit(name, 'command', {'arg-type': self._use_type(arg_type), 'ret-type': self._use_type(ret_type), - 'allow-oob': allow_oob}) + 'allow-oob': allow_oob}, ifcond) =20 def visit_event(self, name, info, ifcond, 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_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}, + ifcond) =20 =20 def gen_introspect(schema, output_dir, prefix, opt_unmask): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633476867311.88723468568105; Wed, 21 Mar 2018 04:57:56 -0700 (PDT) Received: from localhost ([::1]:54168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycNQ-00014D-3l for importer@patchew.org; Wed, 21 Mar 2018 07:57:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIP-00055O-BG for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIO-0007pU-HB for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58158 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIO-0007pG-CP for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E39ED80AD20C for ; Wed, 21 Mar 2018 11:52:43 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81BA4215CDB7; Wed, 21 Mar 2018 11:52:43 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:33 +0100 Message-Id: <20180321115211.17937-12-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:43 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 11/49] qapi/commands: add #if conditions to commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wrap generated code with #if/#endif using an 'ifcontext' on QAPIGenCSnippet objects. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/commands.py | 19 ++++++++++--------- tests/test-qmp-cmds.c | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index e2366b4801..40bb680b7c 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -237,7 +237,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVis= itor): QAPISchemaModularCVisitor.__init__( self, prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', __doc__) - self._regy =3D '' + self._regy =3D QAPIGenCSnippet() self._visited_ret_types =3D {} =20 def _begin_module(self, name): @@ -273,19 +273,20 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCV= isitor): void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', c_prefix=3Dc_name(self._prefix, protect=3DFalse))) - genc.add(gen_registry(self._regy, self._prefix)) + 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): if not gen: return - self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type)) - if ret_type and ret_type not in self._visited_ret_types[self._genc= ]: - self._visited_ret_types[self._genc].add(ret_type) - self._genc.add(gen_marshal_output(ret_type)) - self._genh.add(gen_marshal_decl(name)) - self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) - self._regy +=3D gen_register_command(name, success_response, allow= _oob) + with ifcontext(ifcond, self._genh, self._genc, self._regy): + self._genh.add(gen_command_decl(name, arg_type, boxed, ret_typ= e)) + if ret_type and ret_type not in self._visited_ret_types[self._= genc]: + self._visited_ret_types[self._genc].add(ret_type) + self._genc.add(gen_marshal_output(ret_type)) + 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, al= low_oob)) =20 =20 def gen_commands(schema, output_dir, prefix): diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index c25fc2100a..e675722593 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -12,11 +12,11 @@ =20 static QmpCommandList qmp_commands; =20 -/* #if defined(TEST_IF_STRUCT) && defined(TEST_IF_CMD) */ +#if defined(TEST_IF_STRUCT) && defined(TEST_IF_CMD) void qmp_TestIfCmd(TestIfStruct *foo, Error **errp) { } -/* #endif */ +#endif =20 void qmp_user_def_cmd(Error **errp) { --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634023315476.48633876894735; Wed, 21 Mar 2018 05:07:03 -0700 (PDT) Received: from localhost ([::1]:54217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycW4-00014l-Qq for importer@patchew.org; Wed, 21 Mar 2018 08:06:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIT-00058e-PQ for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIQ-0007qa-J6 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42050 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIQ-0007qL-Ep for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB127406DE12 for ; Wed, 21 Mar 2018 11:52:45 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89BC8202322F; Wed, 21 Mar 2018 11:52:45 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:34 +0100 Message-Id: <20180321115211.17937-13-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 12/49] qapi/events: add #if conditions to events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wrap generated code with #if/#endif using an 'ifcontext' on QAPIGenCSnippet objects. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/events.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 26ae00f6f7..dae03e3d88 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -185,8 +185,9 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): genc.add(gen_enum_lookup(self._enum_name, self._event_names)) =20 def visit_event(self, name, info, ifcond, arg_type, boxed): - self._genh.add(gen_event_send_decl(name, arg_type, boxed)) - self._genc.add(gen_event_send(name, arg_type, boxed, self._enum_na= me)) + 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._enu= m_name)) self._event_names.append(name) =20 =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633649128383.7378991540744; Wed, 21 Mar 2018 05:00:49 -0700 (PDT) Received: from localhost ([::1]:54183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycQB-0003zQ-Rs for importer@patchew.org; Wed, 21 Mar 2018 08:00:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIV-0005AK-Fe for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIU-0007sQ-J2 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42054 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIU-0007sE-Dy for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7647406DE12 for ; Wed, 21 Mar 2018 11:52:49 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 809AA10B0099; Wed, 21 Mar 2018 11:52:47 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:35 +0100 Message-Id: <20180321115211.17937-14-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:52:49 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 13/49] qapi-types: refactor variants handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Generate variants objects outside gen_object(). This will allow to easily wrap gen_object() with ifcond_decorator in the following patch. gen_variants_objects() calls gen_object() for each variants, so it remains guarded for each generated variant object. self._gen_type_cleanup(name) is factored out in _gen_object(), helping generated code to be wrapped by the same condition in the following patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/types.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 298a80db62..3d9b0f9a07 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -55,23 +55,27 @@ def gen_struct_members(members): return ret =20 =20 -def gen_object(name, base, members, variants): - if name in objects_seen: - return '' - objects_seen.add(name) - +def gen_variants_objects(variants): ret =3D '' if variants: for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): + ret +=3D gen_variants_objects(v.type.variants) ret +=3D gen_object(v.type.name, v.type.base, v.type.local_members, v.type.variants) + return ret =20 - ret +=3D mcgen(''' + +def gen_object(name, base, members, variants): + if name in objects_seen: + return '' + objects_seen.add(name) + + ret =3D mcgen(''' =20 struct %(c_name)s { ''', - c_name=3Dc_name(name)) + c_name=3Dc_name(name)) =20 if base: if not base.is_implicit(): @@ -215,11 +219,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisit= or): 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): - # Nothing to do for the special empty builtin - if name =3D=3D 'q_empty': - return - self._genh.preamble_add(gen_fwd_object_or_array(name)) + def _gen_object(self, name, info, ifcond, base, members, variants): self._genh.add(gen_object(name, base, members, variants)) if base and not base.is_implicit(): self._genh.add(gen_upcast(name, base)) @@ -229,11 +229,19 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisi= tor): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 + def visit_object_type(self, name, info, ifcond, base, members, variant= s): + # Nothing to do for the special empty builtin + if name =3D=3D 'q_empty': + return + self._genh.preamble_add(gen_fwd_object_or_array(name)) + self._genh.add(gen_variants_objects(variants)) + self._gen_object(name, info, None, base, members, variants) + def visit_alternate_type(self, name, info, ifcond, variants): self._genh.preamble_add(gen_fwd_object_or_array(name)) - self._genh.add(gen_object(name, None, - [variants.tag_member], variants)) - self._gen_type_cleanup(name) + self._genh.add(gen_variants_objects(variants)) + self._gen_object(name, info, None, None, + [variants.tag_member], variants) =20 =20 def gen_types(schema, output_dir, prefix, opt_builtins): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633702746565.3460101299023; Wed, 21 Mar 2018 05:01:42 -0700 (PDT) Received: from localhost ([::1]:54190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycR3-0004lr-On for importer@patchew.org; Wed, 21 Mar 2018 08:01:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIZ-0005Dg-Th for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIY-0007uP-Ku for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34918 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIY-0007uB-FO for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F251A76FB9 for ; Wed, 21 Mar 2018 11:52:53 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A8DA50331; Wed, 21 Mar 2018 11:52:51 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:36 +0100 Message-Id: <20180321115211.17937-15-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:52:54 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 14/49] qapi-types: add #if conditions to types & visitors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Types & visitors are coupled and must be handled together to avoid temporary build regression. Wrap generated types/visitor code with #if/#endif using the context helpers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/types.py | 46 ++++++++++++++++++++++++++----------------- scripts/qapi/visit.py | 33 ++++++++++++++++++------------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3d9b0f9a07..ce4c91206c 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -61,8 +61,10 @@ def gen_variants_objects(variants): for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): ret +=3D gen_variants_objects(v.type.variants) + ret +=3D gen_if(v.type.ifcond) ret +=3D gen_object(v.type.name, v.type.base, v.type.local_members, v.type.variants) + ret +=3D gen_endif(v.type.ifcond) return ret =20 =20 @@ -206,41 +208,49 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisi= tor): # gen_object() is recursive, ensure it doesn't visit the empty type objects_seen.add(schema.the_empty_object_type.name) =20 - def _gen_type_cleanup(self, name): - self._genh.add(gen_type_cleanup_decl(name)) - self._genc.add(gen_type_cleanup(name)) + def _gen_type_cleanup(self, name, ifcond): + with ifcontext(ifcond, self._genh, self._genc): + self._genh.add(gen_type_cleanup_decl(name)) + self._genc.add(gen_type_cleanup(name)) =20 def visit_enum_type(self, name, info, ifcond, values, prefix): - self._genh.preamble_add(gen_enum(name, values, prefix)) - self._genc.add(gen_enum_lookup(name, values, prefix)) + with ifcontext(ifcond, self._genh, self._genc): + self._genh.preamble_add(gen_enum(name, values, prefix)) + self._genc.add(gen_enum_lookup(name, values, prefix)) =20 def visit_array_type(self, name, info, ifcond, element_type): - self._genh.preamble_add(gen_fwd_object_or_array(name)) - self._genh.add(gen_array(name, element_type)) - self._gen_type_cleanup(name) + with ifcontext(ifcond, self._genh): + self._genh.preamble_add(gen_fwd_object_or_array(name)) + self._genh.add(gen_array(name, element_type)) + self._gen_type_cleanup(name, ifcond) =20 def _gen_object(self, name, info, ifcond, base, members, variants): - self._genh.add(gen_object(name, base, members, variants)) - if base and not base.is_implicit(): - self._genh.add(gen_upcast(name, base)) - # TODO Worth changing the visitor signature, so we could - # directly use rather than repeat type.is_implicit()? + with ifcontext(ifcond, self._genh): + self._genh.add(gen_object(name, base, members, variants)) + if base and not base.is_implicit(): + self._genh.add(gen_upcast(name, base)) + # TODO Worth changing the visitor signature, so we could + # directly use rather than repeat type.is_implicit()? if not name.startswith('q_'): # implicit types won't be directly allocated/freed - self._gen_type_cleanup(name) + self._gen_type_cleanup(name, ifcond) + + def _gen_fwd_object_or_array(self, name, ifcond): + with ifcontext(ifcond, self._genh): + self._genh.preamble_add(gen_fwd_object_or_array(name)) =20 def visit_object_type(self, name, info, ifcond, base, members, variant= s): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return - self._genh.preamble_add(gen_fwd_object_or_array(name)) + self._gen_fwd_object_or_array(name, ifcond) self._genh.add(gen_variants_objects(variants)) - self._gen_object(name, info, None, base, members, variants) + self._gen_object(name, info, ifcond, base, members, variants) =20 def visit_alternate_type(self, name, info, ifcond, variants): - self._genh.preamble_add(gen_fwd_object_or_array(name)) + self._gen_fwd_object_or_array(name, ifcond) self._genh.add(gen_variants_objects(variants)) - self._gen_object(name, info, None, None, + self._gen_object(name, info, ifcond, None, [variants.tag_member], variants) =20 =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 9ea2e04f81..e4a62ce030 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -302,29 +302,34 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVis= itor): types=3Dtypes)) =20 def visit_enum_type(self, name, info, ifcond, values, prefix): - self._genh.add(gen_visit_decl(name, scalar=3DTrue)) - self._genc.add(gen_visit_enum(name)) + with ifcontext(ifcond, self._genh, self._genc): + self._genh.add(gen_visit_decl(name, scalar=3DTrue)) + self._genc.add(gen_visit_enum(name)) =20 def visit_array_type(self, name, info, ifcond, element_type): - self._genh.add(gen_visit_decl(name)) - self._genc.add(gen_visit_list(name, element_type)) + with ifcontext(ifcond, self._genh, self._genc): + 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): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return - self._genh.add(gen_visit_members_decl(name)) - self._genc.add(gen_visit_object_members(name, base, members, varia= nts)) - # TODO Worth changing the visitor signature, so we could - # directly use rather than repeat type.is_implicit()? - if not name.startswith('q_'): - # only explicit types need an allocating visit - self._genh.add(gen_visit_decl(name)) - self._genc.add(gen_visit_object(name, base, members, variants)) + with ifcontext(ifcond, self._genh, self._genc): + self._genh.add(gen_visit_members_decl(name)) + self._genc.add(gen_visit_object_members(name, base, + members, variants)) + # TODO Worth changing the visitor signature, so we could + # directly use rather than repeat type.is_implicit()? + if not name.startswith('q_'): + # only explicit types need an allocating visit + 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): - self._genh.add(gen_visit_decl(name)) - self._genc.add(gen_visit_alternate(name, variants)) + with ifcontext(ifcond, self._genh, self._genc): + self._genh.add(gen_visit_decl(name)) + self._genc.add(gen_visit_alternate(name, variants)) =20 =20 def gen_visit(schema, output_dir, prefix, opt_builtins): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634184613554.196184164906; Wed, 21 Mar 2018 05:09:44 -0700 (PDT) Received: from localhost ([::1]:54230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycYp-00045U-Nj for importer@patchew.org; Wed, 21 Mar 2018 08:09:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycId-0005Fz-BO for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIa-0007vP-MA for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58164 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIa-0007v9-HG for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E7E280AD20C for ; Wed, 21 Mar 2018 11:52:56 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B534215CDB7; Wed, 21 Mar 2018 11:52:55 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:37 +0100 Message-Id: <20180321115211.17937-16-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Mar 2018 11:52:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 15/49] qapi: do not define enumeration value explicitely X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The C standard has the initial value at 0 and the subsequent values incremented by 1. No need to set this explicitely. This will prevent from artificial "gaps" when compiling out some enum values and having unnecessarily large MAX values & enums arrays. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 60c1d0a783..68a567f53f 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -2032,14 +2032,11 @@ typedef enum %(c_name)s { ''', c_name=3Dc_name(name)) =20 - i =3D 0 for value in enum_values: ret +=3D mcgen(''' - %(c_enum)s =3D %(i)d, + %(c_enum)s, ''', - c_enum=3Dc_enum_const(name, value, prefix), - i=3Di) - i +=3D 1 + c_enum=3Dc_enum_const(name, value, prefix)) =20 ret +=3D mcgen(''' } %(c_name)s; --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634346782498.84765935022597; Wed, 21 Mar 2018 05:12:26 -0700 (PDT) Received: from localhost ([::1]:54246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycbR-0006YP-Pn for importer@patchew.org; Wed, 21 Mar 2018 08:12:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIe-0005H8-A4 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIc-0007wW-R7 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46142 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIc-0007wG-Lf for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:52:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30346D1432 for ; Wed, 21 Mar 2018 11:52:58 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B58A202322F; Wed, 21 Mar 2018 11:52:57 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:38 +0100 Message-Id: <20180321115211.17937-17-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:52:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:52:58 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 16/49] qapi: rename QAPISchemaEnumType.values to .members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rename QAPISchemaEnumType.values and related variables to members. Makes sense ever since commit 93bda4dd4 changed .values from list of string to list of QAPISchemaMember. Obvious no-op. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 36 +++++++++++++++++----------------- scripts/qapi/doc.py | 2 +- scripts/qapi/introspect.py | 4 ++-- scripts/qapi/types.py | 6 +++--- scripts/qapi/visit.py | 2 +- tests/qapi-schema/test-qapi.py | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 68a567f53f..ea5cdfe3be 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1068,7 +1068,7 @@ class QAPISchemaVisitor(object): def visit_builtin_type(self, name, info, json_type): pass =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): + def visit_enum_type(self, name, info, ifcond, members, prefix): pass =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -1166,22 +1166,22 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 =20 class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, doc, ifcond, values, prefix): + def __init__(self, name, info, doc, ifcond, members, prefix): QAPISchemaType.__init__(self, name, info, doc, ifcond) - for v in values: - assert isinstance(v, QAPISchemaMember) - v.set_owner(name) + for m in members: + assert isinstance(m, QAPISchemaMember) + m.set_owner(name) assert prefix is None or isinstance(prefix, str) - self.values =3D values + self.members =3D members self.prefix =3D prefix =20 def check(self, schema): QAPISchemaType.check(self, schema) seen =3D {} - for v in self.values: - v.check_clash(self.info, seen) + for m in self.members: + m.check_clash(self.info, seen) if self.doc: - self.doc.connect_member(v) + self.doc.connect_member(m) =20 def is_implicit(self): # See QAPISchema._make_implicit_enum_type() and ._def_predefineds() @@ -1191,7 +1191,7 @@ class QAPISchemaEnumType(QAPISchemaType): return c_name(self.name) =20 def member_names(self): - return [v.name for v in self.values] + return [m.name for m in self.members] =20 def json_type(self): return 'string' @@ -1999,19 +1999,19 @@ def wrap_ifcond(ifcond, before, after): return out =20 =20 -def gen_enum_lookup(name, values, prefix=3DNone): +def gen_enum_lookup(name, members, prefix=3DNone): ret =3D mcgen(''' =20 const QEnumLookup %(c_name)s_lookup =3D { .array =3D (const char *const[]) { ''', c_name=3Dc_name(name)) - for value in values: - index =3D c_enum_const(name, value, prefix) + for m in members: + index =3D c_enum_const(name, m, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(value)s", ''', - index=3Dindex, value=3Dvalue) + index=3Dindex, value=3Dm) =20 ret +=3D mcgen(''' }, @@ -2022,9 +2022,9 @@ const QEnumLookup %(c_name)s_lookup =3D { return ret =20 =20 -def gen_enum(name, values, prefix=3DNone): +def gen_enum(name, members, prefix=3DNone): # append automatically generated _MAX value - enum_values =3D values + ['_MAX'] + enum_members =3D members + ['_MAX'] =20 ret =3D mcgen(''' =20 @@ -2032,11 +2032,11 @@ typedef enum %(c_name)s { ''', c_name=3Dc_name(name)) =20 - for value in enum_values: + for m in enum_members: ret +=3D mcgen(''' %(c_enum)s, ''', - c_enum=3Dc_enum_const(name, value, prefix)) + c_enum=3Dc_enum_const(name, m, prefix)) =20 ret +=3D mcgen(''' } %(c_name)s; diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index d5cfd2336b..6c2bf98e1d 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -204,7 +204,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): def write(self, output_dir): self._gen.write(output_dir, self._prefix + 'qapi-doc.texi') =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): + def visit_enum_type(self, name, info, ifcond, members, prefix): doc =3D self.cur_doc self._gen.add(TYPE_FMT(type=3D'Enum', name=3Ddoc.symbol, diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index cb4825f134..66f7fd00a9 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -163,8 +163,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; def visit_builtin_type(self, name, info, json_type): self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): - self._gen_qlit(name, 'enum', {'values': values}, ifcond) + def visit_enum_type(self, name, info, ifcond, members, prefix): + self._gen_qlit(name, 'enum', {'values': members}, ifcond) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index ce4c91206c..5b790cb41d 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -213,10 +213,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisi= tor): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): + def visit_enum_type(self, name, info, ifcond, members, prefix): with ifcontext(ifcond, self._genh, self._genc): - self._genh.preamble_add(gen_enum(name, values, prefix)) - self._genc.add(gen_enum_lookup(name, values, prefix)) + self._genh.preamble_add(gen_enum(name, members, prefix)) + self._genc.add(gen_enum_lookup(name, members, prefix)) =20 def visit_array_type(self, name, info, ifcond, element_type): with ifcontext(ifcond, self._genh): diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index e4a62ce030..ee776386ae 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -301,7 +301,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): + def visit_enum_type(self, name, info, ifcond, members, prefix): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 6d25a37dda..f4b8feb9bc 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -23,8 +23,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_include(self, name, info): print('include %s' % name) =20 - def visit_enum_type(self, name, info, ifcond, values, prefix): - print('enum %s %s' % (name, values)) + def visit_enum_type(self, name, info, ifcond, members, prefix): + print('enum %s %s' % (name, members)) if prefix: print(' prefix %s' % prefix) self._print_if(ifcond) --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521633840635626.0268092593677; Wed, 21 Mar 2018 05:04:00 -0700 (PDT) Received: from localhost ([::1]:54201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycTH-0006Xy-MV for importer@patchew.org; Wed, 21 Mar 2018 08:03:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIf-0005IY-Jx for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIe-0007xa-Gw for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53224 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIe-0007xF-CH for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D855A4068035 for ; Wed, 21 Mar 2018 11:52:59 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE472022C08; Wed, 21 Mar 2018 11:52:59 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:39 +0100 Message-Id: <20180321115211.17937-18-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:52:59 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 17/49] qapi: change enum visitor to take QAPISchemaMember X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will allow to add and access more properties associated with enum values/members, like the associated 'if' condition. We may want to have a specialized type QAPISchemaEnumMember, for now this will do. Suggested-by: Markus Armbruster Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 12 ++++++------ scripts/qapi/events.py | 2 +- scripts/qapi/introspect.py | 3 ++- tests/qapi-schema/test-qapi.py | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index ea5cdfe3be..4d19146064 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1198,7 +1198,7 @@ class QAPISchemaEnumType(QAPISchemaType): =20 def visit(self, visitor): visitor.visit_enum_type(self.name, self.info, self.ifcond, - self.member_names(), self.prefix) + self.members, self.prefix) =20 =20 class QAPISchemaArrayType(QAPISchemaType): @@ -2007,11 +2007,11 @@ const QEnumLookup %(c_name)s_lookup =3D { ''', c_name=3Dc_name(name)) for m in members: - index =3D c_enum_const(name, m, prefix) + index =3D c_enum_const(name, m.name, prefix) ret +=3D mcgen(''' - [%(index)s] =3D "%(value)s", + [%(index)s] =3D "%(name)s", ''', - index=3Dindex, value=3Dm) + index=3Dindex, name=3Dm.name) =20 ret +=3D mcgen(''' }, @@ -2024,7 +2024,7 @@ const QEnumLookup %(c_name)s_lookup =3D { =20 def gen_enum(name, members, prefix=3DNone): # append automatically generated _MAX value - enum_members =3D members + ['_MAX'] + enum_members =3D members + [QAPISchemaMember('_MAX')] =20 ret =3D mcgen(''' =20 @@ -2036,7 +2036,7 @@ typedef enum %(c_name)s { ret +=3D mcgen(''' %(c_enum)s, ''', - c_enum=3Dc_enum_const(name, m, prefix)) + c_enum=3Dc_enum_const(name, m.name, prefix)) =20 ret +=3D mcgen(''' } %(c_name)s; diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index dae03e3d88..233c27a6c8 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -188,7 +188,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): 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._enu= m_name)) - self._event_names.append(name) + self._event_names.append(QAPISchemaMember(name)) =20 =20 def gen_events(schema, output_dir, prefix): diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 66f7fd00a9..d62fca84de 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -164,7 +164,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) =20 def visit_enum_type(self, name, info, ifcond, members, prefix): - self._gen_qlit(name, 'enum', {'values': members}, ifcond) + self._gen_qlit(name, 'enum', + {'values': [m.name for m in members]}, ifcond) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index f4b8feb9bc..3623deae62 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -24,7 +24,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('include %s' % name) =20 def visit_enum_type(self, name, info, ifcond, members, prefix): - print('enum %s %s' % (name, members)) + print('enum %s %s' % (name, [m.name for m in members])) if prefix: print(' prefix %s' % prefix) self._print_if(ifcond) --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634022954413.65726927148967; Wed, 21 Mar 2018 05:07:02 -0700 (PDT) Received: from localhost ([::1]:54218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycWD-0001Bl-VW for importer@patchew.org; Wed, 21 Mar 2018 08:07:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIi-0005JY-Bo for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIg-0007yf-PS for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42064 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIg-0007yT-KP for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D53F406DE12 for ; Wed, 21 Mar 2018 11:53:02 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85FEE10B0094; Wed, 21 Mar 2018 11:53:01 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:40 +0100 Message-Id: <20180321115211.17937-19-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:02 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 18/49] tests: modify visit_enum_type() in test-qapi to print members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use a common self._print_members() to print enum members details. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-schema/comments.out | 14 ++++++- tests/qapi-schema/doc-bad-section.out | 13 ++++++- tests/qapi-schema/doc-good.out | 17 ++++++-- tests/qapi-schema/empty.out | 9 ++++- tests/qapi-schema/event-case.out | 9 ++++- tests/qapi-schema/ident-with-escape.out | 9 ++++- tests/qapi-schema/include-relpath.out | 14 ++++++- tests/qapi-schema/include-repetition.out | 14 ++++++- tests/qapi-schema/include-simple.out | 14 ++++++- tests/qapi-schema/indented-expr.out | 9 ++++- tests/qapi-schema/qapi-schema-test.out | 49 +++++++++++++++++++----- tests/qapi-schema/test-qapi.py | 18 ++++++--- 12 files changed, 158 insertions(+), 31 deletions(-) diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 8d2f1ce8a2..d1abc4b5a1 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,5 +1,15 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module comments.json -enum Status ['good', 'bad', 'ugly'] +enum Status + member good + member bad + member ugly diff --git a/tests/qapi-schema/doc-bad-section.out b/tests/qapi-schema/doc-= bad-section.out index cd28721568..db8014eed0 100644 --- a/tests/qapi-schema/doc-bad-section.out +++ b/tests/qapi-schema/doc-bad-section.out @@ -1,8 +1,17 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module doc-bad-section.json -enum Enum ['one', 'two'] +enum Enum + member one + member two doc symbol=3DEnum body=3D =3D=3D Produces *invalid* texinfo diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 430b5a87db..3cd5c094aa 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -1,8 +1,17 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module doc-good.json -enum Enum ['one', 'two'] +enum Enum + member one + member two object Base member base1: Enum optional=3DFalse object Variant1 @@ -17,7 +26,9 @@ object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse object q_obj_Variant2-wrapper member data: Variant2 optional=3DFalse -enum SugaredUnionKind ['one', 'two'] +enum SugaredUnionKind + member one + member two object SugaredUnion member type: SugaredUnionKind optional=3DFalse tag type diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 0ec234eec4..5483cb7bc6 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,3 +1,10 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-cas= e.out index 88c0964917..f69d4ffe4e 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,6 +1,13 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module event-case.json event oops None boxed=3DFalse diff --git a/tests/qapi-schema/ident-with-escape.out b/tests/qapi-schema/id= ent-with-escape.out index ee3b34e623..41b90fb944 100644 --- a/tests/qapi-schema/ident-with-escape.out +++ b/tests/qapi-schema/ident-with-escape.out @@ -1,6 +1,13 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module ident-with-escape.json object q_obj_fooA-arg member bar1: str optional=3DFalse diff --git a/tests/qapi-schema/include-relpath.out b/tests/qapi-schema/incl= ude-relpath.out index ebbabd7a18..783ccfc855 100644 --- a/tests/qapi-schema/include-relpath.out +++ b/tests/qapi-schema/include-relpath.out @@ -1,9 +1,19 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module include-relpath.json include include/relpath.json module include/relpath.json include include-relpath-sub.json module include-relpath-sub.json -enum Status ['good', 'bad', 'ugly'] +enum Status + member good + member bad + member ugly diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/i= nclude-repetition.out index 7235e055bc..d45977ee56 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,10 +1,20 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module include-repetition.json include comments.json module comments.json -enum Status ['good', 'bad', 'ugly'] +enum Status + member good + member bad + member ugly module include-repetition.json include include-repetition-sub.json module include-repetition-sub.json diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/inclu= de-simple.out index 006f723eeb..1afe20802a 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,7 +1,17 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module include-simple.json include include-simple-sub.json module include-simple-sub.json -enum Status ['good', 'bad', 'ugly'] +enum Status + member good + member bad + member ugly diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indent= ed-expr.out index a79935e8c3..e2ede80310 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,6 +1,13 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module indented-expr.json command eins None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8fe9d7a3a8..fb89a798dd 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -1,6 +1,13 @@ object q_empty -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] +enum QType prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool module qapi-schema-test.json object TestStruct member integer: int optional=3DFalse @@ -11,19 +18,24 @@ object NestedEnumsOne member enum2: EnumOne optional=3DTrue member enum3: EnumOne optional=3DFalse member enum4: EnumOne optional=3DTrue -enum MyEnum [] +enum MyEnum object Empty1 object Empty2 base Empty1 command user_def_cmd0 Empty2 -> Empty2 gen=3DTrue success_response=3DTrue boxed=3DFalse -enum QEnumTwo ['value1', 'value2'] +enum QEnumTwo prefix QENUM_TWO + member value1 + member value2 object UserDefOne base UserDefZero member string: str optional=3DFalse member enum1: EnumOne optional=3DTrue -enum EnumOne ['value1', 'value2', 'value3'] +enum EnumOne + member value1 + member value2 + member value3 object UserDefZero member integer: int optional=3DFalse object UserDefTwoDictDict @@ -124,7 +136,21 @@ object q_obj_sizeList-wrapper member data: sizeList optional=3DFalse object q_obj_anyList-wrapper member data: anyList optional=3DFalse -enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', 's64', 'u8= ', 'u16', 'u32', 'u64', 'number', 'boolean', 'string', 'sizes', 'any'] +enum UserDefNativeListUnionKind + member integer + member s8 + member s16 + member s32 + member s64 + member u8 + member u16 + member u32 + member u64 + member number + member boolean + member string + member sizes + member any object UserDefNativeListUnion member type: UserDefNativeListUnionKind optional=3DFalse tag type @@ -197,7 +223,8 @@ event EVENT_E UserDefZero boxed=3DTrue event EVENT_F UserDefAlternate boxed=3DTrue -enum __org.qemu_x-Enum ['__org.qemu_x-value'] +enum __org.qemu_x-Enum + member __org.qemu_x-value object __org.qemu_x-Base member __org.qemu_x-member1: __org.qemu_x-Enum optional=3DFalse object __org.qemu_x-Struct @@ -206,7 +233,8 @@ object __org.qemu_x-Struct member wchar-t: int optional=3DTrue object q_obj_str-wrapper member data: str optional=3DFalse -enum __org.qemu_x-Union1Kind ['__org.qemu_x-branch'] +enum __org.qemu_x-Union1Kind + member __org.qemu_x-branch object __org.qemu_x-Union1 member type: __org.qemu_x-Union1Kind optional=3DFalse tag type @@ -233,11 +261,14 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> __org.qemu_x-Unio object TestIfStruct member foo: int optional=3DFalse if ['defined(TEST_IF_STRUCT)'] -enum TestIfEnum ['foo', 'bar'] +enum TestIfEnum + member foo + member bar if ['defined(TEST_IF_ENUM)'] object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse -enum TestIfUnionKind ['foo'] +enum TestIfUnionKind + member foo if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] object TestIfUnion member type: TestIfUnionKind optional=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 3623deae62..7e7b8f9f0f 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -12,7 +12,8 @@ =20 from __future__ import print_function import sys -from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor +from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor, \ + QAPISchemaObjectTypeMember =20 =20 class QAPISchemaTestVisitor(QAPISchemaVisitor): @@ -24,18 +25,17 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('include %s' % name) =20 def visit_enum_type(self, name, info, ifcond, members, prefix): - print('enum %s %s' % (name, [m.name for m in members])) + print('enum %s' % name) if prefix: print(' prefix %s' % prefix) + self._print_members(members) self._print_if(ifcond) =20 def visit_object_type(self, name, info, ifcond, base, members, variant= s): print('object %s' % name) if base: print(' base %s' % base.name) - for m in members: - print(' member %s: %s optional=3D%s' % \ - (m.name, m.type.name, m.optional)) + self._print_members(members) self._print_variants(variants) self._print_if(ifcond) =20 @@ -57,6 +57,14 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' boxed=3D%s' % boxed) self._print_if(ifcond) =20 + @staticmethod + def _print_members(members): + for m in members: + print(' member %s%s' % ( + m.name, + ': %s optional=3D%s' % (m.type.name, m.optional) + if isinstance(m, QAPISchemaObjectTypeMember) else '')) + @staticmethod def _print_variants(variants): if variants: --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152163389372842.94838721924441; Wed, 21 Mar 2018 05:04:53 -0700 (PDT) Received: from localhost ([::1]:54203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycU7-0007pX-4Q for importer@patchew.org; Wed, 21 Mar 2018 08:04:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIj-0005KV-L3 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIi-0007zh-J1 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34922 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIi-0007zK-Dt for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4E6D76FB9 for ; Wed, 21 Mar 2018 11:53:03 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72224215CDB7; Wed, 21 Mar 2018 11:53:03 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:41 +0100 Message-Id: <20180321115211.17937-20-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:53:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:53:03 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 19/49] qapi: factor out check_known_keys() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The following patches are going to need similar checks from various code path. This refactoring will report all conflicting keys (instead of the first one encountered). Modify unknown-expr-key to check plural form. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 27 ++++++++++++++++++------- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/enum-missing-data.err | 2 +- tests/qapi-schema/unknown-expr-key.err | 2 +- tests/qapi-schema/unknown-expr-key.json | 2 +- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 4d19146064..fdbb5f1823 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -879,6 +879,24 @@ def check_struct(expr, info): allow_metas=3D['struct']) =20 =20 +def check_known_keys(info, source, keys, required, optional): + + def pprint(elems): + return ', '.join("'" + e + "'" for e in sorted(elems)) + + missing =3D set(required) - set(keys) + if missing: + raise QAPISemError(info, "%s must have %s key%s" + % (source, pprint(missing), + 's' if len(missing) > 1 else '')) + allowed =3D set(required + optional) + unknown =3D set(keys) - allowed + if unknown: + raise QAPISemError(info, "%s has unknown key%s %s (allowed: %s)" + % (source, 's' if len(unknown) > 1 else '', + pprint(unknown), pprint(allowed))) + + def check_keys(expr_elem, meta, required, optional=3D[]): expr =3D expr_elem['expr'] info =3D expr_elem['info'] @@ -886,10 +904,9 @@ def check_keys(expr_elem, meta, required, optional=3D[= ]): if not isinstance(name, str): raise QAPISemError(info, "'%s' key must have a string value" % met= a) required =3D required + [meta] + source =3D "%s '%s'" % (meta, name) + check_known_keys(info, source, expr, required, optional) for (key, value) in expr.items(): - if key not in required and key not in optional: - raise QAPISemError(info, "Unknown key '%s' in %s '%s'" - % (key, meta, name)) if (key =3D=3D 'gen' or key =3D=3D 'success-response') and value i= s not False: raise QAPISemError(info, "'%s' of %s '%s' should only use false valu= e" @@ -900,10 +917,6 @@ def check_keys(expr_elem, meta, required, optional=3D[= ]): % (key, meta, name)) if key =3D=3D 'if': check_if(expr, info) - for key in required: - if key not in expr: - raise QAPISemError(info, "Key '%s' is missing from %s '%s'" - % (key, meta, name)) =20 =20 def check_exprs(exprs): diff --git a/tests/qapi-schema/alternate-base.err b/tests/qapi-schema/alter= nate-base.err index 30d8a34373..2b09c4c7a3 100644 --- a/tests/qapi-schema/alternate-base.err +++ b/tests/qapi-schema/alternate-base.err @@ -1 +1 @@ -tests/qapi-schema/alternate-base.json:4: Unknown key 'base' in alternate '= Alt' +tests/qapi-schema/alternate-base.json:4: alternate 'Alt' has unknown key '= base' (allowed: 'alternate', 'data', 'if') diff --git a/tests/qapi-schema/double-type.err b/tests/qapi-schema/double-t= ype.err index f9613c6d6b..a8c5637659 100644 --- a/tests/qapi-schema/double-type.err +++ b/tests/qapi-schema/double-type.err @@ -1 +1 @@ -tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' +tests/qapi-schema/double-type.json:2: struct 'bar' has unknown key 'comman= d' (allowed: 'base', 'data', 'if', 'struct') diff --git a/tests/qapi-schema/enum-missing-data.err b/tests/qapi-schema/en= um-missing-data.err index ba4873ae69..68e286badc 100644 --- a/tests/qapi-schema/enum-missing-data.err +++ b/tests/qapi-schema/enum-missing-data.err @@ -1 +1 @@ -tests/qapi-schema/enum-missing-data.json:2: Key 'data' is missing from enu= m 'MyEnum' +tests/qapi-schema/enum-missing-data.json:2: enum 'MyEnum' must have 'data'= key diff --git a/tests/qapi-schema/unknown-expr-key.err b/tests/qapi-schema/unk= nown-expr-key.err index 12f5ed5b43..d9f4e41cac 100644 --- a/tests/qapi-schema/unknown-expr-key.err +++ b/tests/qapi-schema/unknown-expr-key.err @@ -1 +1 @@ -tests/qapi-schema/unknown-expr-key.json:2: Unknown key 'bogus' in struct '= bar' +tests/qapi-schema/unknown-expr-key.json:2: struct 'bar' has unknown keys '= bogus', 'foo' (allowed: 'base', 'data', 'if', 'struct') diff --git a/tests/qapi-schema/unknown-expr-key.json b/tests/qapi-schema/un= known-expr-key.json index 3b2be00cc4..5bcb8efd1d 100644 --- a/tests/qapi-schema/unknown-expr-key.json +++ b/tests/qapi-schema/unknown-expr-key.json @@ -1,2 +1,2 @@ # we reject an expression with unknown top-level keys -{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } } +{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { }, 'foo': { } } --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634193348213.99720625909356; Wed, 21 Mar 2018 05:09:53 -0700 (PDT) Received: from localhost ([::1]:54231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycYy-0004DV-BE for importer@patchew.org; Wed, 21 Mar 2018 08:09:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIn-0005Ny-13 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIk-000816-EX for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53234 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIk-00080g-9G for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9BFB4001852 for ; Wed, 21 Mar 2018 11:53:05 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FB4A202322F; Wed, 21 Mar 2018 11:53:05 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:42 +0100 Message-Id: <20180321115211.17937-21-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:05 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 20/49] qapi: add a dictionnary form with 'name' key for enum members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Desugar the enum NAME form to { 'name': NAME }. This will allow to add new enum members, such as 'if' in the following patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 49 ++++++++++++++++--- tests/Makefile.include | 3 +- tests/qapi-schema/enum-bad-member.err | 1 + ...-dict-member.exit =3D> enum-bad-member.exit} | 0 tests/qapi-schema/enum-bad-member.json | 2 + ...um-dict-member.out =3D> enum-bad-member.out} | 0 .../qapi-schema/enum-dict-member-unknown.err | 1 + .../qapi-schema/enum-dict-member-unknown.exit | 1 + .../qapi-schema/enum-dict-member-unknown.json | 2 + .../qapi-schema/enum-dict-member-unknown.out | 0 tests/qapi-schema/enum-dict-member.err | 1 - tests/qapi-schema/enum-dict-member.json | 2 - tests/qapi-schema/enum-missing-data.err | 2 +- 13 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 tests/qapi-schema/enum-bad-member.err rename tests/qapi-schema/{enum-dict-member.exit =3D> enum-bad-member.exit}= (100%) create mode 100644 tests/qapi-schema/enum-bad-member.json rename tests/qapi-schema/{enum-dict-member.out =3D> enum-bad-member.out} (= 100%) create mode 100644 tests/qapi-schema/enum-dict-member-unknown.err create mode 100644 tests/qapi-schema/enum-dict-member-unknown.exit create mode 100644 tests/qapi-schema/enum-dict-member-unknown.json create mode 100644 tests/qapi-schema/enum-dict-member-unknown.out delete mode 100644 tests/qapi-schema/enum-dict-member.err delete mode 100644 tests/qapi-schema/enum-dict-member.json diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index fdbb5f1823..6aece364f1 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -739,6 +739,10 @@ def check_event(expr, info): allow_metas=3Dmeta) =20 =20 +def enum_get_names(expr): + return [e['name'] for e in expr['data']] + + def check_union(expr, info): name =3D expr['union'] base =3D expr.get('base') @@ -798,7 +802,7 @@ def check_union(expr, info): # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. if enum_define: - if key not in enum_define['data']: + if key not in enum_get_names(enum_define): raise QAPISemError(info, "Discriminator value '%s' is not found = in " "enum '%s'" @@ -806,7 +810,7 @@ def check_union(expr, info): =20 # If discriminator is user-defined, ensure all values are covered if enum_define: - for value in enum_define['data']: + for value in enum_get_names(enum_define): if value not in members.keys(): raise QAPISemError(info, "Union '%s' data missing '%s' bra= nch" % (name, value)) @@ -837,10 +841,10 @@ def check_alternate(expr, info): if qtype =3D=3D 'QTYPE_QSTRING': enum_expr =3D enum_types.get(value) if enum_expr: - for v in enum_expr['data']: + for v in enum_get_names(enum_expr): if v in ['on', 'off']: conflicting.add('QTYPE_QBOOL') - if re.match(r'[-+0-9.]', v): # lazy, could be tightened + if re.match(r'[-+0-9.]', v): # lazy, could be tighten= ed conflicting.add('QTYPE_QNUM') else: conflicting.add('QTYPE_QNUM') @@ -853,19 +857,34 @@ def check_alternate(expr, info): types_seen[qt] =3D key =20 =20 -def check_enum(expr, info): +def normalize_enum(expr, info): name =3D expr['enum'] members =3D expr.get('data') - prefix =3D expr.get('prefix') =20 if not isinstance(members, list): raise QAPISemError(info, "Enum '%s' requires an array for 'data'" % name) + + # translate short member form to dict form + for i, member in enumerate(members): + if not isinstance(member, dict): + member =3D {'name': member} + members[i] =3D member + + +def check_enum(expr, info): + name =3D expr['enum'] + members =3D expr.get('data') + prefix =3D expr.get('prefix') + if prefix is not None and not isinstance(prefix, str): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % na= me) + for member in members: - check_name(info, "Member of enum '%s'" % name, member, + source =3D "Dictionary member of enum '%s'" % name + check_known_keys(info, source, member, ['name'], []) + check_name(info, "Member of enum '%s'" % name, member['name'], enum_member=3DTrue) =20 =20 @@ -926,6 +945,13 @@ def check_exprs(exprs): for builtin in builtin_types.keys(): all_names[builtin] =3D 'built-in' =20 + # Normalize exprs + for expr_elem in exprs: + expr =3D expr_elem['expr'] + info =3D expr_elem['info'] + if 'enum' in expr: + normalize_enum(expr, info) + # Learn the types and check for valid expression keys for expr_elem in exprs: expr =3D expr_elem['expr'] @@ -1631,7 +1657,14 @@ class QAPISchema(object): qtype_values, 'QTYPE')) =20 def _make_enum_members(self, values): - return [QAPISchemaMember(v) for v in values] + enum =3D [] + for v in values: + if isinstance(v, dict): + name =3D v['name'] + else: + name =3D v + enum.append(QAPISchemaMember(name)) + return enum =20 def _make_implicit_enum_type(self, name, info, ifcond, values): # See also QAPISchemaObjectTypeMember._pretty_owner() diff --git a/tests/Makefile.include b/tests/Makefile.include index f77ad2ba3b..444c3fd33e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -476,10 +476,11 @@ qapi-schema +=3D double-data.json qapi-schema +=3D double-type.json qapi-schema +=3D duplicate-key.json qapi-schema +=3D empty.json +qapi-schema +=3D enum-bad-member.json qapi-schema +=3D enum-bad-name.json qapi-schema +=3D enum-bad-prefix.json qapi-schema +=3D enum-clash-member.json -qapi-schema +=3D enum-dict-member.json +qapi-schema +=3D enum-dict-member-unknown.json qapi-schema +=3D enum-int-member.json qapi-schema +=3D enum-member-case.json qapi-schema +=3D enum-missing-data.json diff --git a/tests/qapi-schema/enum-bad-member.err b/tests/qapi-schema/enum= -bad-member.err new file mode 100644 index 0000000000..211db9e6fc --- /dev/null +++ b/tests/qapi-schema/enum-bad-member.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-bad-member.json:2: Member of enum 'MyEnum' requires= a string name diff --git a/tests/qapi-schema/enum-dict-member.exit b/tests/qapi-schema/en= um-bad-member.exit similarity index 100% rename from tests/qapi-schema/enum-dict-member.exit rename to tests/qapi-schema/enum-bad-member.exit diff --git a/tests/qapi-schema/enum-bad-member.json b/tests/qapi-schema/enu= m-bad-member.json new file mode 100644 index 0000000000..98da6828b4 --- /dev/null +++ b/tests/qapi-schema/enum-bad-member.json @@ -0,0 +1,2 @@ +# we reject any enum member that is not a string +{ 'enum': 'MyEnum', 'data': [ [ ] ] } diff --git a/tests/qapi-schema/enum-dict-member.out b/tests/qapi-schema/enu= m-bad-member.out similarity index 100% rename from tests/qapi-schema/enum-dict-member.out rename to tests/qapi-schema/enum-bad-member.out diff --git a/tests/qapi-schema/enum-dict-member-unknown.err b/tests/qapi-sc= hema/enum-dict-member-unknown.err new file mode 100644 index 0000000000..7ed48beb2e --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-unknown.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-dict-member-unknown.json:2: Dictionary member of en= um 'MyEnum' has unknown key 'bad-key' (allowed: 'name') diff --git a/tests/qapi-schema/enum-dict-member-unknown.exit b/tests/qapi-s= chema/enum-dict-member-unknown.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-unknown.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-dict-member-unknown.json b/tests/qapi-s= chema/enum-dict-member-unknown.json new file mode 100644 index 0000000000..6664c59201 --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-unknown.json @@ -0,0 +1,2 @@ +# we reject any enum member that is not a string or a dict with 'name' +{ 'enum': 'MyEnum', 'data': [ { 'name': 'foo', 'bad-key': 'str' } ] } diff --git a/tests/qapi-schema/enum-dict-member-unknown.out b/tests/qapi-sc= hema/enum-dict-member-unknown.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/enum-dict-member.err b/tests/qapi-schema/enu= m-dict-member.err deleted file mode 100644 index 8ca146ea59..0000000000 --- a/tests/qapi-schema/enum-dict-member.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/enum-dict-member.json:2: Member of enum 'MyEnum' require= s a string name diff --git a/tests/qapi-schema/enum-dict-member.json b/tests/qapi-schema/en= um-dict-member.json deleted file mode 100644 index 79672e0f09..0000000000 --- a/tests/qapi-schema/enum-dict-member.json +++ /dev/null @@ -1,2 +0,0 @@ -# we reject any enum member that is not a string -{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] } diff --git a/tests/qapi-schema/enum-missing-data.err b/tests/qapi-schema/en= um-missing-data.err index 68e286badc..b8ccae071b 100644 --- a/tests/qapi-schema/enum-missing-data.err +++ b/tests/qapi-schema/enum-missing-data.err @@ -1 +1 @@ -tests/qapi-schema/enum-missing-data.json:2: enum 'MyEnum' must have 'data'= key +tests/qapi-schema/enum-missing-data.json:2: Enum 'MyEnum' requires an arra= y for 'data' --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634074305945.3407497064807; Wed, 21 Mar 2018 05:07:54 -0700 (PDT) Received: from localhost ([::1]:54220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycX3-0001tX-8I for importer@patchew.org; Wed, 21 Mar 2018 08:07:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIo-0005Pn-QJ for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIn-000830-F7 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51838 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIn-00082d-9N for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC3FC40267D7 for ; Wed, 21 Mar 2018 11:53:08 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09D998445F; Wed, 21 Mar 2018 11:53:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:43 +0100 Message-Id: <20180321115211.17937-22-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:08 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 21/49] qapi: add 'if' to enum members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QAPISchemaMember gains .ifcond for enum members: inherited classes, such as QAPISchemaObjectTypeMember, will thus have an ifcond member after this (those different types will also use the .ifcond to store the condition and generate conditional code in the following patches). Generated code is not changed by this patch, but with "qapi: add #if conditions to generated code" patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 10 +++++++--- tests/Makefile.include | 1 + tests/qapi-schema/enum-dict-member-unknown.err | 2 +- tests/qapi-schema/enum-if-invalid.err | 1 + tests/qapi-schema/enum-if-invalid.exit | 1 + tests/qapi-schema/enum-if-invalid.json | 3 +++ tests/qapi-schema/enum-if-invalid.out | 0 tests/qapi-schema/qapi-schema-test.json | 5 +++-- tests/qapi-schema/qapi-schema-test.out | 2 ++ tests/qapi-schema/test-qapi.py | 1 + 10 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 tests/qapi-schema/enum-if-invalid.err create mode 100644 tests/qapi-schema/enum-if-invalid.exit create mode 100644 tests/qapi-schema/enum-if-invalid.json create mode 100644 tests/qapi-schema/enum-if-invalid.out diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 6aece364f1..22ea286191 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -883,7 +883,8 @@ def check_enum(expr, info): =20 for member in members: source =3D "Dictionary member of enum '%s'" % name - check_known_keys(info, source, member, ['name'], []) + check_known_keys(info, source, member, ['name'], ['if']) + check_if(member, info) check_name(info, "Member of enum '%s'" % name, member['name'], enum_member=3DTrue) =20 @@ -1362,9 +1363,10 @@ class QAPISchemaObjectType(QAPISchemaType): class QAPISchemaMember(object): role =3D 'member' =20 - def __init__(self, name): + def __init__(self, name, ifcond=3DNone): assert isinstance(name, str) self.name =3D name + self.ifcond =3D listify_cond(ifcond) self.owner =3D None =20 def set_owner(self, name): @@ -1661,9 +1663,11 @@ class QAPISchema(object): for v in values: if isinstance(v, dict): name =3D v['name'] + ifcond =3D v.get('if') else: name =3D v - enum.append(QAPISchemaMember(name)) + ifcond =3D None + enum.append(QAPISchemaMember(name, ifcond)) return enum =20 def _make_implicit_enum_type(self, name, info, ifcond, values): diff --git a/tests/Makefile.include b/tests/Makefile.include index 444c3fd33e..19873ea887 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -481,6 +481,7 @@ qapi-schema +=3D enum-bad-name.json qapi-schema +=3D enum-bad-prefix.json qapi-schema +=3D enum-clash-member.json qapi-schema +=3D enum-dict-member-unknown.json +qapi-schema +=3D enum-if-invalid.json qapi-schema +=3D enum-int-member.json qapi-schema +=3D enum-member-case.json qapi-schema +=3D enum-missing-data.json diff --git a/tests/qapi-schema/enum-dict-member-unknown.err b/tests/qapi-sc= hema/enum-dict-member-unknown.err index 7ed48beb2e..3699c89167 100644 --- a/tests/qapi-schema/enum-dict-member-unknown.err +++ b/tests/qapi-schema/enum-dict-member-unknown.err @@ -1 +1 @@ -tests/qapi-schema/enum-dict-member-unknown.json:2: Dictionary member of en= um 'MyEnum' has unknown key 'bad-key' (allowed: 'name') +tests/qapi-schema/enum-dict-member-unknown.json:2: Dictionary member of en= um 'MyEnum' has unknown key 'bad-key' (allowed: 'if', 'name') diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err new file mode 100644 index 0000000000..54c3cf887b --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string = or a list of strings diff --git a/tests/qapi-schema/enum-if-invalid.exit b/tests/qapi-schema/enu= m-if-invalid.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-if-invalid.json b/tests/qapi-schema/enu= m-if-invalid.json new file mode 100644 index 0000000000..60bd0ef1d7 --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.json @@ -0,0 +1,3 @@ +# check invalid 'if' type +{ 'enum': 'TestIfEnum', 'data': + [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] } diff --git a/tests/qapi-schema/enum-if-invalid.out b/tests/qapi-schema/enum= -if-invalid.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 b997b2d43d..6a1d3b6337 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -194,7 +194,8 @@ { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, 'if': 'defined(TEST_IF_STRUCT)' } =20 -{ 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ], +{ 'enum': 'TestIfEnum', 'data': + [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], 'if': 'defined(TEST_IF_ENUM)' } =20 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, @@ -203,7 +204,7 @@ { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 -{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' }, +{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfE= num' }, 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] } =20 { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index fb89a798dd..bcef80efeb 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -264,6 +264,7 @@ object TestIfStruct enum TestIfEnum member foo member bar + if ['defined(TEST_IF_ENUM_BAR)'] if ['defined(TEST_IF_ENUM)'] object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse @@ -282,6 +283,7 @@ alternate TestIfAlternate if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)'] object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse + member bar: TestIfEnum optional=3DFalse if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 7e7b8f9f0f..9582742f90 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -64,6 +64,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): m.name, ': %s optional=3D%s' % (m.type.name, m.optional) if isinstance(m, QAPISchemaObjectTypeMember) else '')) + QAPISchemaTestVisitor._print_if(m.ifcond, 8) =20 @staticmethod def _print_variants(variants): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634503300907.8831030251339; Wed, 21 Mar 2018 05:15:03 -0700 (PDT) Received: from localhost ([::1]:54261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycdy-00016C-Dd for importer@patchew.org; Wed, 21 Mar 2018 08:15:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIs-0005VD-3q for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIr-00085c-69 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42076 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIr-00085D-26 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 930C1406DE12 for ; Wed, 21 Mar 2018 11:53:12 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 249AE10B0094; Wed, 21 Mar 2018 11:53:09 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:44 +0100 Message-Id: <20180321115211.17937-23-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:12 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 22/49] qapi-event: add 'if' condition to implicit event enum X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add condition to QAPIEvent enum members based on the event 'if'. Generated code is not changed by this patch, but with "qapi: add #if conditions to generated code" patch. There is no coverage of this change in qapi-schema-test.out since the event_names enum is an implicit type created by qapi-event.py. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 233c27a6c8..f02b65cf5a 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -188,7 +188,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): 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._enu= m_name)) - self._event_names.append(QAPISchemaMember(name)) + self._event_names.append(QAPISchemaMember(name, ifcond)) =20 =20 def gen_events(schema, output_dir, prefix): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634028624408.20015120833307; Wed, 21 Mar 2018 05:07:08 -0700 (PDT) Received: from localhost ([::1]:54219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycWJ-0001H4-Ld for importer@patchew.org; Wed, 21 Mar 2018 08:07:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIx-0005a7-0L for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIt-00088H-QE for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42078 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIt-00087t-Ky for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2ABA7406DE12 for ; Wed, 21 Mar 2018 11:53:15 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE60A202322F; Wed, 21 Mar 2018 11:53:14 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:45 +0100 Message-Id: <20180321115211.17937-24-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:15 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 23/49] qapi: rename allow_dict to allow_implicit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This makes it a bit clearer what is the intent of the dictionnary for the check_type() function, since there was some confusion on a previous iteration of this series. Suggested-by: Markus Armbruster Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 22ea286191..9eb2b0cc37 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -660,7 +660,7 @@ def check_if(expr, info): =20 =20 def check_type(info, source, value, allow_array=3DFalse, - allow_dict=3DFalse, allow_optional=3DFalse, + allow_implicit=3DFalse, allow_optional=3DFalse, allow_metas=3D[]): global all_names =20 @@ -687,7 +687,7 @@ def check_type(info, source, value, allow_array=3DFalse, (source, all_names[value], value)) return =20 - if not allow_dict: + if not allow_implicit: raise QAPISemError(info, "%s should be a type name" % source) =20 if not isinstance(value, OrderedDict): @@ -717,7 +717,7 @@ def check_command(expr, info): if boxed: args_meta +=3D ['union', 'alternate'] check_type(info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=3Dnot boxed, allow_optional=3D= True, + expr.get('data'), allow_implicit=3Dnot boxed, allow_optiona= l=3DTrue, allow_metas=3Dargs_meta) returns_meta =3D ['union', 'struct'] if name in returns_whitelist: @@ -735,7 +735,7 @@ def check_event(expr, info): if boxed: meta +=3D ['union', 'alternate'] check_type(info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=3Dnot boxed, allow_optional=3D= True, + expr.get('data'), allow_implicit=3Dnot boxed, allow_optiona= l=3DTrue, allow_metas=3Dmeta) =20 =20 @@ -763,7 +763,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=3DTrue, allow_optional=3DTrue, + base, allow_implicit=3DTrue, allow_optional=3DTrue, allow_metas=3D['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base" @@ -894,7 +894,7 @@ def check_struct(expr, info): members =3D expr['data'] =20 check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=3DTrue, allow_optional=3DTrue) + allow_implicit=3DTrue, allow_optional=3DTrue) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=3D['struct']) =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634529031444.9980430082186; Wed, 21 Mar 2018 05:15:29 -0700 (PDT) Received: from localhost ([::1]:54262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyce9-0001Fs-F5 for importer@patchew.org; Wed, 21 Mar 2018 08:15:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIy-0005bA-30 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIw-00089f-0q for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51842 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIv-00089P-RC for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E3C240267D7 for ; Wed, 21 Mar 2018 11:53:17 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 914F510B0094; Wed, 21 Mar 2018 11:53:16 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:46 +0100 Message-Id: <20180321115211.17937-25-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:17 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 24/49] qapi: add a dictionary form with 'type' key for members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wherever a struct/union/alternate/command/event member with NAME: TYPE form is accepted, desugar it to a NAME: { 'type': TYPE } form. This will allow to add new member details, such as 'if' in the following patch to introduce conditionals, or 'default' for default values etc. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 57 ++++++++++++------- tests/Makefile.include | 3 + tests/qapi-schema/alternate-invalid-dict.err | 1 + tests/qapi-schema/alternate-invalid-dict.exit | 1 + tests/qapi-schema/alternate-invalid-dict.json | 4 ++ tests/qapi-schema/alternate-invalid-dict.out | 0 tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/flat-union-inline.err | 2 +- tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/qapi-schema-test.json | 10 ++-- .../struct-member-invalid-dict.err | 1 + .../struct-member-invalid-dict.exit | 1 + .../struct-member-invalid-dict.json | 3 + .../struct-member-invalid-dict.out | 0 .../qapi-schema/union-branch-invalid-dict.err | 1 + .../union-branch-invalid-dict.exit | 1 + .../union-branch-invalid-dict.json | 4 ++ .../qapi-schema/union-branch-invalid-dict.out | 0 18 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 tests/qapi-schema/alternate-invalid-dict.err create mode 100644 tests/qapi-schema/alternate-invalid-dict.exit create mode 100644 tests/qapi-schema/alternate-invalid-dict.json create mode 100644 tests/qapi-schema/alternate-invalid-dict.out create mode 100644 tests/qapi-schema/struct-member-invalid-dict.err create mode 100644 tests/qapi-schema/struct-member-invalid-dict.exit create mode 100644 tests/qapi-schema/struct-member-invalid-dict.json create mode 100644 tests/qapi-schema/struct-member-invalid-dict.out create mode 100644 tests/qapi-schema/union-branch-invalid-dict.err create mode 100644 tests/qapi-schema/union-branch-invalid-dict.exit create mode 100644 tests/qapi-schema/union-branch-invalid-dict.json create mode 100644 tests/qapi-schema/union-branch-invalid-dict.out diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 9eb2b0cc37..3f46ed5530 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -587,11 +587,11 @@ def discriminator_find_enum_define(expr): if not base_members: return None =20 - discriminator_type =3D base_members.get(discriminator) - if not discriminator_type: + discriminator_member =3D base_members.get(discriminator) + if not discriminator_member: return None =20 - return enum_types.get(discriminator_type) + return enum_types.get(discriminator_member['type']) =20 =20 # Names must be letters, numbers, -, and _. They must start with letter, @@ -659,6 +659,15 @@ def check_if(expr, info): check_if_str(ifcond, info) =20 =20 +def normalize_members(expr, field): + members =3D expr.get(field) + if isinstance(members, OrderedDict): + for key, arg in members.items(): + if isinstance(arg, dict): + continue + members[key] =3D {'type': arg} + + def check_type(info, source, value, allow_array=3DFalse, allow_implicit=3DFalse, allow_optional=3DFalse, allow_metas=3D[]): @@ -703,8 +712,9 @@ def check_type(info, source, value, allow_array=3DFalse, % (source, key)) # Todo: allow dictionaries to represent default values of # an optional argument. - check_type(info, "Member '%s' of %s" % (key, source), arg, - allow_array=3DTrue, + member_source =3D "Member '%s' of %s" % (key, source) + check_known_keys(info, member_source, arg, ['type'], []) + check_type(info, member_source, arg['type'], allow_array=3DTrue, allow_metas=3D['built-in', 'union', 'alternate', 'struc= t', 'enum']) =20 @@ -775,13 +785,13 @@ def check_union(expr, info): # member of the base struct. check_name(info, "Discriminator of flat union '%s'" % name, discriminator) - discriminator_type =3D base_members.get(discriminator) - if not discriminator_type: + discriminator_member =3D base_members.get(discriminator) + if not discriminator_member: raise QAPISemError(info, "Discriminator '%s' is not a member of base= " "struct '%s'" % (discriminator, base)) - enum_define =3D enum_types.get(discriminator_type) + enum_define =3D enum_types.get(discriminator_member['type']) allow_metas =3D ['struct'] # Do not allow string discriminator if not enum_define: @@ -793,11 +803,14 @@ def check_union(expr, info): if len(members) =3D=3D 0: raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % n= ame) for (key, value) in members.items(): - check_name(info, "Member of union '%s'" % name, key) + source =3D "Member of union '%s'" % name + check_name(info, source, key) + check_known_keys(info, source, value, ['type'], []) + typ =3D value['type'] =20 # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name), - value, allow_array=3Dnot base, allow_metas=3Dallow_meta= s) + typ, allow_array=3Dnot base, allow_metas=3Dallow_metas) =20 # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. @@ -828,18 +841,20 @@ def check_alternate(expr, info): "in 'data'" % name) for (key, value) in members.items(): check_name(info, "Member of alternate '%s'" % name, key) + source =3D "Member '%s' of alternate '%s'" % (key, name) + check_known_keys(info, source, value, ['type'], []) + typ =3D value['type'] =20 # Ensure alternates have no type conflicts. - check_type(info, "Member '%s' of alternate '%s'" % (key, name), - value, + check_type(info, source, typ, allow_metas=3D['built-in', 'union', 'struct', 'enum']) - qtype =3D find_alternate_member_qtype(value) + qtype =3D find_alternate_member_qtype(typ) if not qtype: raise QAPISemError(info, "Alternate '%s' member '%s' cannot us= e " - "type '%s'" % (name, key, value)) + "type '%s'" % (name, key, typ)) conflicting =3D set([qtype]) if qtype =3D=3D 'QTYPE_QSTRING': - enum_expr =3D enum_types.get(value) + enum_expr =3D enum_types.get(typ) if enum_expr: for v in enum_get_names(enum_expr): if v in ['on', 'off']: @@ -952,6 +967,10 @@ def check_exprs(exprs): info =3D expr_elem['info'] if 'enum' in expr: normalize_enum(expr, info) + elif 'union' in expr: + normalize_members(expr, 'base') + if {'union', 'alternate', 'struct', 'command', 'event'} & set(expr= ): + normalize_members(expr, 'data') =20 # Learn the types and check for valid expression keys for expr_elem in exprs: @@ -1726,7 +1745,7 @@ class QAPISchema(object): return QAPISchemaObjectTypeMember(name, typ, optional) =20 def _make_members(self, data, info): - return [self._make_member(key, value, info) + return [self._make_member(key, value['type'], info) for (key, value) in data.items()] =20 def _def_struct_type(self, expr, info, doc): @@ -1762,11 +1781,11 @@ class QAPISchema(object): name, info, doc, ifcond, 'base', self._make_members(base, info)) if tag_name: - variants =3D [self._make_variant(key, value) + variants =3D [self._make_variant(key, value['type']) for (key, value) in data.items()] members =3D [] else: - variants =3D [self._make_simple_variant(key, value, info) + variants =3D [self._make_simple_variant(key, value['type'], in= fo) for (key, value) in data.items()] typ =3D self._make_implicit_enum_type(name, info, ifcond, [v.name for v in variants]) @@ -1782,7 +1801,7 @@ class QAPISchema(object): name =3D expr['alternate'] data =3D expr['data'] ifcond =3D expr.get('if') - variants =3D [self._make_variant(key, value) + variants =3D [self._make_variant(key, value['type']) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) self._def_entity( diff --git a/tests/Makefile.include b/tests/Makefile.include index 19873ea887..7a46c1620d 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -415,6 +415,7 @@ qapi-schema +=3D alternate-conflict-string.json qapi-schema +=3D alternate-conflict-bool-string.json qapi-schema +=3D alternate-conflict-num-string.json qapi-schema +=3D alternate-empty.json +qapi-schema +=3D alternate-invalid-dict.json qapi-schema +=3D alternate-nested.json qapi-schema +=3D alternate-unknown.json qapi-schema +=3D args-alternate.json @@ -556,6 +557,7 @@ qapi-schema +=3D returns-whitelist.json qapi-schema +=3D struct-base-clash-deep.json qapi-schema +=3D struct-base-clash.json qapi-schema +=3D struct-data-invalid.json +qapi-schema +=3D struct-member-invalid-dict.json qapi-schema +=3D struct-member-invalid.json qapi-schema +=3D trailing-comma-list.json qapi-schema +=3D trailing-comma-object.json @@ -567,6 +569,7 @@ qapi-schema +=3D unicode-str.json qapi-schema +=3D union-base-empty.json qapi-schema +=3D union-base-no-discriminator.json qapi-schema +=3D union-branch-case.json +qapi-schema +=3D union-branch-invalid-dict.json qapi-schema +=3D union-clash-branches.json qapi-schema +=3D union-empty.json qapi-schema +=3D union-invalid-base.json diff --git a/tests/qapi-schema/alternate-invalid-dict.err b/tests/qapi-sche= ma/alternate-invalid-dict.err new file mode 100644 index 0000000000..39d3b6bca5 --- /dev/null +++ b/tests/qapi-schema/alternate-invalid-dict.err @@ -0,0 +1 @@ +tests/qapi-schema/alternate-invalid-dict.json:2: Member 'two' of alternate= 'Alt' must have 'type' key diff --git a/tests/qapi-schema/alternate-invalid-dict.exit b/tests/qapi-sch= ema/alternate-invalid-dict.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/alternate-invalid-dict.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/alternate-invalid-dict.json b/tests/qapi-sch= ema/alternate-invalid-dict.json new file mode 100644 index 0000000000..45f2c8ebef --- /dev/null +++ b/tests/qapi-schema/alternate-invalid-dict.json @@ -0,0 +1,4 @@ +# invalid field dictionnary, missing type +{ 'alternate': 'Alt', + 'data': { 'one': 'str', + 'two': { 'if': 'foo' } } } diff --git a/tests/qapi-schema/alternate-invalid-dict.out b/tests/qapi-sche= ma/alternate-invalid-dict.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/event-nest-struct.err b/tests/qapi-schema/ev= ent-nest-struct.err index 5a42701b8f..66cd141112 100644 --- a/tests/qapi-schema/event-nest-struct.err +++ b/tests/qapi-schema/event-nest-struct.err @@ -1 +1 @@ -tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event= 'EVENT_A' should be a type name +tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event= 'EVENT_A' must have 'type' key diff --git a/tests/qapi-schema/flat-union-inline.err b/tests/qapi-schema/fl= at-union-inline.err index 2333358d28..82d511c7ef 100644 --- a/tests/qapi-schema/flat-union-inline.err +++ b/tests/qapi-schema/flat-union-inline.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-inline.json:7: Member 'value1' of union 'Test= Union' should be a type name +tests/qapi-schema/flat-union-inline.json:7: Member of union 'TestUnion' mu= st have 'type' key diff --git a/tests/qapi-schema/nested-struct-data.err b/tests/qapi-schema/n= ested-struct-data.err index da767bade2..728591fde3 100644 --- a/tests/qapi-schema/nested-struct-data.err +++ b/tests/qapi-schema/nested-struct-data.err @@ -1 +1 @@ -tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for comm= and 'foo' should be a type name +tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for comm= and 'foo' must have 'type' key diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 6a1d3b6337..71023fb277 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -11,7 +11,7 @@ 'guest-sync' ] } } =20 { 'struct': 'TestStruct', - 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } + 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str'= } } =20 # for testing enums { 'struct': 'NestedEnumsOne', @@ -74,7 +74,7 @@ { 'union': 'UserDefFlatUnion', 'base': 'UserDefUnionBase', # intentional forward reference 'discriminator': 'enum1', - 'data': { 'value1' : 'UserDefA', + 'data': { 'value1' : {'type': 'UserDefA'}, 'value2' : 'UserDefB', 'value3' : 'UserDefB' } } =20 @@ -93,7 +93,7 @@ { 'struct': 'WrapAlternate', 'data': { 'alt': 'UserDefAlternate' } } { 'alternate': 'UserDefAlternate', - 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int', + 'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'in= t', 'n': 'null' } } =20 { 'struct': 'UserDefC', @@ -129,7 +129,7 @@ { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} } { 'command': 'user_def_cmd2', - 'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'}, + 'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'}, 'returns': 'UserDefTwo' } =20 # Returning a non-dictionary requires a name from the whitelist @@ -156,7 +156,7 @@ =20 # testing event { 'struct': 'EventStructOne', - 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' = } } + 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': = 'EnumOne' } } =20 { 'event': 'EVENT_A' } { 'event': 'EVENT_B', diff --git a/tests/qapi-schema/struct-member-invalid-dict.err b/tests/qapi-= schema/struct-member-invalid-dict.err new file mode 100644 index 0000000000..8435a78cb4 --- /dev/null +++ b/tests/qapi-schema/struct-member-invalid-dict.err @@ -0,0 +1 @@ +tests/qapi-schema/struct-member-invalid-dict.json:2: Member '*a' of 'data'= for struct 'foo' must have 'type' key diff --git a/tests/qapi-schema/struct-member-invalid-dict.exit b/tests/qapi= -schema/struct-member-invalid-dict.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/struct-member-invalid-dict.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/struct-member-invalid-dict.json b/tests/qapi= -schema/struct-member-invalid-dict.json new file mode 100644 index 0000000000..ebd9733b49 --- /dev/null +++ b/tests/qapi-schema/struct-member-invalid-dict.json @@ -0,0 +1,3 @@ +# exploded member form must have a 'type' +{ 'struct': 'foo', + 'data': { '*a': { 'case': 'foo' } } } diff --git a/tests/qapi-schema/struct-member-invalid-dict.out b/tests/qapi-= schema/struct-member-invalid-dict.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/union-branch-invalid-dict.err b/tests/qapi-s= chema/union-branch-invalid-dict.err new file mode 100644 index 0000000000..65f9999fc0 --- /dev/null +++ b/tests/qapi-schema/union-branch-invalid-dict.err @@ -0,0 +1 @@ +tests/qapi-schema/union-branch-invalid-dict.json:2: Member of union 'Union= InvalidBranch' must have 'type' key diff --git a/tests/qapi-schema/union-branch-invalid-dict.exit b/tests/qapi-= schema/union-branch-invalid-dict.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/union-branch-invalid-dict.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/union-branch-invalid-dict.json b/tests/qapi-= schema/union-branch-invalid-dict.json new file mode 100644 index 0000000000..19c5d9cacd --- /dev/null +++ b/tests/qapi-schema/union-branch-invalid-dict.json @@ -0,0 +1,4 @@ +# exploded member form must have a 'type' +{ 'union': 'UnionInvalidBranch', + 'data': { 'integer': { 'if': 'foo'}, + 's8': 'int8' } } diff --git a/tests/qapi-schema/union-branch-invalid-dict.out b/tests/qapi-s= chema/union-branch-invalid-dict.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634360819355.1247992940164; Wed, 21 Mar 2018 05:12:40 -0700 (PDT) Received: from localhost ([::1]:54247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycba-0006gz-OM for importer@patchew.org; Wed, 21 Mar 2018 08:12:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycIz-0005c4-2S for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycIx-0008Ay-RY for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51844 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycIx-0008AY-MB for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3792440267D7 for ; Wed, 21 Mar 2018 11:53:19 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD26E2022C08; Wed, 21 Mar 2018 11:53:18 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:47 +0100 Message-Id: <20180321115211.17937-26-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:19 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 25/49] qapi: add 'if' to implicit struct members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Generated code is not changed by this patch, but with "qapi: add #if conditions to generated code" patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 14 +++++++------- tests/qapi-schema/qapi-schema-test.json | 12 +++++++++--- tests/qapi-schema/qapi-schema-test.out | 5 +++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 3f46ed5530..bbcb417a47 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -713,7 +713,7 @@ def check_type(info, source, value, allow_array=3DFalse, # Todo: allow dictionaries to represent default values of # an optional argument. member_source =3D "Member '%s' of %s" % (key, source) - check_known_keys(info, member_source, arg, ['type'], []) + check_known_keys(info, member_source, arg, ['type'], ['if']) check_type(info, member_source, arg['type'], allow_array=3DTrue, allow_metas=3D['built-in', 'union', 'alternate', 'struc= t', 'enum']) @@ -1426,8 +1426,8 @@ class QAPISchemaMember(object): =20 =20 class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, typ, optional): - QAPISchemaMember.__init__(self, name) + def __init__(self, name, typ, optional, ifcond=3DNone): + QAPISchemaMember.__init__(self, name, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) self._type_name =3D typ @@ -1734,7 +1734,7 @@ class QAPISchema(object): name, info, doc, ifcond, self._make_enum_members(data), prefix)) =20 - def _make_member(self, name, typ, info): + def _make_member(self, name, typ, ifcond, info): optional =3D False if name.startswith('*'): name =3D name[1:] @@ -1742,10 +1742,10 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) - return QAPISchemaObjectTypeMember(name, typ, optional) + return QAPISchemaObjectTypeMember(name, typ, optional, ifcond) =20 def _make_members(self, data, info): - return [self._make_member(key, value['type'], info) + return [self._make_member(key, value['type'], value.get('if'), inf= o) for (key, value) in data.items()] =20 def _def_struct_type(self, expr, info, doc): @@ -1766,7 +1766,7 @@ class QAPISchema(object): typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( typ, info, None, self.lookup_type(typ), - 'wrapper', [self._make_member('data', typ, info)]) + 'wrapper', [self._make_member('data', typ, None, info)]) return QAPISchemaObjectTypeVariant(case, typ) =20 def _def_union_type(self, expr, info, doc): diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 71023fb277..e29c9f0769 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -191,7 +191,9 @@ =20 # test 'if' condition handling =20 -{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, +{ 'struct': 'TestIfStruct', 'data': + { 'foo': 'int', + 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} }, 'if': 'defined(TEST_IF_STRUCT)' } =20 { 'enum': 'TestIfEnum', 'data': @@ -204,8 +206,12 @@ { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 -{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfE= num' }, +{ 'command': 'TestIfCmd', 'data': + { 'foo': 'TestIfStruct', + 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } }, 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] } =20 -{ 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, +{ 'event': 'TestIfEvent', 'data': + { 'foo': 'TestIfStruct', + 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index bcef80efeb..e1e41acd52 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -260,6 +260,8 @@ command __org.qemu_x-command q_obj___org.qemu_x-command= -arg -> __org.qemu_x-Unio gen=3DTrue success_response=3DTrue boxed=3DFalse object TestIfStruct member foo: int optional=3DFalse + member bar: int optional=3DFalse + if ['defined(TEST_IF_STRUCT_BAR)'] if ['defined(TEST_IF_STRUCT)'] enum TestIfEnum member foo @@ -284,12 +286,15 @@ alternate TestIfAlternate object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse + if ['defined(TEST_IF_CMD_BAR)'] if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse + member bar: TestIfEnum optional=3DFalse + if ['defined(TEST_IF_EVT_BAR)'] if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634196878396.13291685129036; Wed, 21 Mar 2018 05:09:56 -0700 (PDT) Received: from localhost ([::1]:54232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycZ2-0004HJ-1v for importer@patchew.org; Wed, 21 Mar 2018 08:09:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJ3-0005eX-5s for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJ2-0008Df-4S for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46148 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJ1-0008DP-W2 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85CCEA1BEB for ; Wed, 21 Mar 2018 11:53:23 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE45584456; Wed, 21 Mar 2018 11:53:20 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:48 +0100 Message-Id: <20180321115211.17937-27-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 26/49] qapi: add an error in case a discriminator is conditionnal X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Making a discriminator conditonal doesn't make much sense. Instead, the union could be made conditional. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 11 +++++++++-- tests/Makefile.include | 1 + .../flat-union-invalid-if-discriminator.err | 1 + .../flat-union-invalid-if-discriminator.exit | 1 + .../flat-union-invalid-if-discriminator.json | 17 +++++++++++++++++ .../flat-union-invalid-if-discriminator.out | 0 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.e= rr create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.e= xit create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.j= son create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.o= ut diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index bbcb417a47..d75dfbf97a 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -576,7 +576,8 @@ def find_alternate_member_qtype(qapi_type): =20 # Return the discriminator enum define if discriminator is specified as an # enum type, otherwise return None. -def discriminator_find_enum_define(expr): +def discriminator_find_enum_define(expr, info): + name =3D expr['union'] base =3D expr.get('base') discriminator =3D expr.get('discriminator') =20 @@ -591,6 +592,11 @@ def discriminator_find_enum_define(expr): if not discriminator_member: return None =20 + if discriminator_member.get('if'): + raise QAPISemError(info, 'The discriminator %s.%s for union %s ' + 'must not be conditional' % + (base, discriminator, name)) + return enum_types.get(discriminator_member['type']) =20 =20 @@ -1024,7 +1030,8 @@ def check_exprs(exprs): =20 if 'include' in expr: continue - if 'union' in expr and not discriminator_find_enum_define(expr): + info =3D expr_elem['info'] + if 'union' in expr and not discriminator_find_enum_define(expr, in= fo): name =3D '%sKind' % expr['union'] elif 'alternate' in expr: name =3D '%sKind' % expr['alternate'] diff --git a/tests/Makefile.include b/tests/Makefile.include index 7a46c1620d..e7429de9df 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -505,6 +505,7 @@ qapi-schema +=3D flat-union-inline.json qapi-schema +=3D flat-union-int-branch.json qapi-schema +=3D flat-union-invalid-branch-key.json qapi-schema +=3D flat-union-invalid-discriminator.json +qapi-schema +=3D flat-union-invalid-if-discriminator.json qapi-schema +=3D flat-union-no-base.json qapi-schema +=3D flat-union-optional-discriminator.json qapi-schema +=3D flat-union-string-discriminator.json diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.err b/te= sts/qapi-schema/flat-union-invalid-if-discriminator.err new file mode 100644 index 0000000000..0c94c9860d --- /dev/null +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-invalid-if-discriminator.json:13: The discrim= inator TestBase.enum1 for union TestUnion must not be conditional diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.exit b/t= ests/qapi-schema/flat-union-invalid-if-discriminator.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.json b/t= ests/qapi-schema/flat-union-invalid-if-discriminator.json new file mode 100644 index 0000000000..618ec36396 --- /dev/null +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.json @@ -0,0 +1,17 @@ +{ 'enum': 'TestEnum', + 'data': [ 'value1', 'value2' ] } + +{ 'struct': 'TestBase', + 'data': { 'enum1': { 'type': 'TestEnum', 'if': 'FOO' } } } + +{ 'struct': 'TestTypeA', + 'data': { 'string': 'str' } } + +{ 'struct': 'TestTypeB', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': 'TestBase', + 'discriminator': 'enum1', + 'data': { 'value1': 'TestTypeA', + 'value2': 'TestTypeB' } } diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.out b/te= sts/qapi-schema/flat-union-invalid-if-discriminator.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634297353294.71888880911877; Wed, 21 Mar 2018 05:11:37 -0700 (PDT) Received: from localhost ([::1]:54245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycae-0005p9-E6 for importer@patchew.org; Wed, 21 Mar 2018 08:11:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJ6-0005lR-HU for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJ4-0008Ev-5o for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46150 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJ4-0008Eb-0f for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EE45A1BEB for ; Wed, 21 Mar 2018 11:53:25 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E4C48445E; Wed, 21 Mar 2018 11:53:24 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:49 +0100 Message-Id: <20180321115211.17937-28-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 27/49] qapi: add 'if' on union members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add 'if' key to union members: { 'union': 'TestIfUnion', 'data': 'mem': { 'type': 'str', 'if': 'COND'} } Generated code is not changed by this patch but with "qapi: add #if conditions to generated code". Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 17 +++++++++-------- tests/qapi-schema/qapi-schema-test.json | 7 ++++++- tests/qapi-schema/qapi-schema-test.out | 10 ++++++++++ tests/qapi-schema/test-qapi.py | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d75dfbf97a..224e911085 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -811,7 +811,7 @@ def check_union(expr, info): for (key, value) in members.items(): source =3D "Member of union '%s'" % name check_name(info, source, key) - check_known_keys(info, source, value, ['type'], []) + check_known_keys(info, source, value, ['type'], ['if']) typ =3D value['type'] =20 # Each value must name a known type @@ -1492,8 +1492,8 @@ class QAPISchemaObjectTypeVariants(object): class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 - def __init__(self, name, typ): - QAPISchemaObjectTypeMember.__init__(self, name, typ, False) + def __init__(self, name, typ, ifcond=3DNone): + QAPISchemaObjectTypeMember.__init__(self, name, typ, False, ifcond) =20 =20 class QAPISchemaAlternateType(QAPISchemaType): @@ -1767,14 +1767,14 @@ class QAPISchema(object): def _make_variant(self, case, typ): return QAPISchemaObjectTypeVariant(case, typ) =20 - def _make_simple_variant(self, case, typ, info): + def _make_simple_variant(self, case, typ, ifcond, info): if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( typ, info, None, self.lookup_type(typ), 'wrapper', [self._make_member('data', typ, None, info)]) - return QAPISchemaObjectTypeVariant(case, typ) + return QAPISchemaObjectTypeVariant(case, typ, ifcond) =20 def _def_union_type(self, expr, info, doc): name =3D expr['union'] @@ -1792,10 +1792,11 @@ class QAPISchema(object): for (key, value) in data.items()] members =3D [] else: - variants =3D [self._make_simple_variant(key, value['type'], in= fo) + variants =3D [self._make_simple_variant(key, value['type'], + value.get('if'), info) for (key, value) in data.items()] - typ =3D self._make_implicit_enum_type(name, info, ifcond, - [v.name for v in variants]) + enum =3D [{'name': v.name, 'if': v.ifcond} for v in variants] + typ =3D self._make_implicit_enum_type(name, info, ifcond, enum) tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] self._def_entity( diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index e29c9f0769..b4b8a0a2cc 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -200,9 +200,14 @@ [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], 'if': 'defined(TEST_IF_ENUM)' } =20 -{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, +{ 'union': 'TestIfUnion', 'data': + { 'foo': 'TestStruct', + 'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } =20 +{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, + 'if': 'defined(TEST_IF_UNION)' } + { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index e1e41acd52..8dbcd6f24b 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -272,12 +272,22 @@ object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse enum TestIfUnionKind member foo + member union_bar + if ['defined(TEST_IF_UNION_BAR)'] if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper + case union_bar: q_obj_str-wrapper + if ['defined(TEST_IF_UNION_BAR)'] if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] +object q_obj_TestIfUnionCmd-arg + member union_cmd_arg: TestIfUnion optional=3DFalse + if ['defined(TEST_IF_UNION)'] +command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse + if ['defined(TEST_IF_UNION)'] alternate TestIfAlternate tag type case foo: int diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 9582742f90..4dfa8651c8 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -72,6 +72,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' tag %s' % variants.tag_member.name) for v in variants.variants: print(' case %s: %s' % (v.name, v.type.name)) + QAPISchemaTestVisitor._print_if(v.ifcond, 8) =20 @staticmethod def _print_if(ifcond, indent=3D4): --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634465457683.3688772111609; Wed, 21 Mar 2018 05:14:25 -0700 (PDT) Received: from localhost ([::1]:54259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycdF-0000Ha-JI for importer@patchew.org; Wed, 21 Mar 2018 08:14:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJ7-0005mk-Sq for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJ6-0008Ge-Ub for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46152 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJ6-0008GK-PS for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54A0AA1BEB for ; Wed, 21 Mar 2018 11:53:28 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id C96472166BDA; Wed, 21 Mar 2018 11:53:27 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:50 +0100 Message-Id: <20180321115211.17937-29-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:28 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 28/49] qapi: add 'if' to alternate members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add 'if' key to alternate members: { 'alternate': 'TestIfAlternate', 'data': { 'alt': { 'type': 'TestStruct', 'if': 'COND' } } } Generated code is not changed by this patch but with "qapi: add #if conditions to generated code". Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 10 +++++----- tests/qapi-schema/qapi-schema-test.json | 6 +++++- tests/qapi-schema/qapi-schema-test.out | 9 ++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 224e911085..c913c18d2d 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -848,7 +848,7 @@ def check_alternate(expr, info): for (key, value) in members.items(): check_name(info, "Member of alternate '%s'" % name, key) source =3D "Member '%s' of alternate '%s'" % (key, name) - check_known_keys(info, source, value, ['type'], []) + check_known_keys(info, source, value, ['type'], ['if']) typ =3D value['type'] =20 # Ensure alternates have no type conflicts. @@ -1764,8 +1764,8 @@ class QAPISchema(object): self._make_members(data, inf= o), None)) =20 - def _make_variant(self, case, typ): - return QAPISchemaObjectTypeVariant(case, typ) + def _make_variant(self, case, typ, ifcond): + return QAPISchemaObjectTypeVariant(case, typ, ifcond) =20 def _make_simple_variant(self, case, typ, ifcond, info): if isinstance(typ, list): @@ -1788,7 +1788,7 @@ class QAPISchema(object): name, info, doc, ifcond, 'base', self._make_members(base, info)) if tag_name: - variants =3D [self._make_variant(key, value['type']) + variants =3D [self._make_variant(key, value['type'], value.get= ('if')) for (key, value) in data.items()] members =3D [] else: @@ -1809,7 +1809,7 @@ class QAPISchema(object): name =3D expr['alternate'] data =3D expr['data'] ifcond =3D expr.get('if') - variants =3D [self._make_variant(key, value['type']) + variants =3D [self._make_variant(key, value['type'], value.get('if= ')) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) self._def_entity( diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index b4b8a0a2cc..cd33c084cb 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -208,9 +208,13 @@ { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, 'if': 'defined(TEST_IF_UNION)' } =20 -{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, +{ 'alternate': 'TestIfAlternate', 'data': + { 'foo': 'int', 'alt_bar': { 'type': 'TestStruct', 'if': 'defined(TEST_I= F_ALT_BAR)'} }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 +{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlterna= te' }, + 'if': 'defined(TEST_IF_ALT)' } + { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } }, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8dbcd6f24b..657e487cbf 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -291,8 +291,15 @@ command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None alternate TestIfAlternate tag type case foo: int - case bar: TestStruct + case alt_bar: TestStruct + if ['defined(TEST_IF_ALT_BAR)'] if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)'] +object q_obj_TestIfAlternateCmd-arg + member alt_cmd_arg: TestIfAlternate optional=3DFalse + if ['defined(TEST_IF_ALT)'] +command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse + if ['defined(TEST_IF_ALT)'] object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634700201941.1036689519929; Wed, 21 Mar 2018 05:18:20 -0700 (PDT) Received: from localhost ([::1]:54282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eych8-0003oj-SP for importer@patchew.org; Wed, 21 Mar 2018 08:18:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJC-0005up-Kr for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJB-0008JX-75 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53242 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJB-0008JF-0u for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B9BA4001852 for ; Wed, 21 Mar 2018 11:53:32 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9B1710B0094; Wed, 21 Mar 2018 11:53:29 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:51 +0100 Message-Id: <20180321115211.17937-30-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:32 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 29/49] qapi: add #if conditions to generated code members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wrap generated enum/struct members and code with #if/#endif, using the .ifcond members added in the previous patches. Some types generate both enum and struct members for example, so a step-by-step is unnecessarily complicated to deal with (it would easily generate invalid intermediary code). Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 4 ++++ scripts/qapi/introspect.py | 13 +++++++++---- scripts/qapi/types.py | 4 ++++ scripts/qapi/visit.py | 8 +++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c913c18d2d..174b39ea50 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -2084,11 +2084,13 @@ const QEnumLookup %(c_name)s_lookup =3D { ''', c_name=3Dc_name(name)) for m in members: + ret +=3D gen_if(m.ifcond) index =3D c_enum_const(name, m.name, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(name)s", ''', index=3Dindex, name=3Dm.name) + ret +=3D gen_endif(m.ifcond) =20 ret +=3D mcgen(''' }, @@ -2110,10 +2112,12 @@ typedef enum %(c_name)s { c_name=3Dc_name(name)) =20 for m in enum_members: + ret +=3D gen_if(m.ifcond) ret +=3D mcgen(''' %(c_enum)s, ''', c_enum=3Dc_enum_const(name, m.name, prefix)) + ret +=3D gen_endif(m.ifcond) =20 ret +=3D mcgen(''' } %(c_name)s; diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index d62fca84de..5b147a3d6f 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -151,6 +151,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; ret =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: ret['default'] =3D None + if member.ifcond: + ret =3D (ret, member.ifcond) return ret =20 def _gen_variants(self, tag_name, variants): @@ -158,14 +160,16 @@ const QLitObject %(c_name)s =3D %(c_string)s; '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)} + return ({'case': variant.name, 'type': self._use_type(variant.type= )}, + variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) =20 def visit_enum_type(self, name, info, ifcond, members, prefix): self._gen_qlit(name, 'enum', - {'values': [m.name for m in members]}, ifcond) + {'values': [(m.name, m.ifcond) for m in members]}, + ifcond) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) @@ -181,8 +185,9 @@ const QLitObject %(c_name)s =3D %(c_string)s; =20 def visit_alternate_type(self, name, info, ifcond, variants): self._gen_qlit(name, 'alternate', - {'members': [{'type': self._use_type(m.type)} - for m in variants.variants]}, ifcond) + {'members': [ + ({'type': self._use_type(m.type)}, m.ifcond) + for m in variants.variants]}, ifcond) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 5b790cb41d..b0d3ddb596 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -43,6 +43,7 @@ struct %(c_name)s { def gen_struct_members(members): ret =3D '' for memb in members: + ret +=3D gen_if(memb.ifcond) if memb.optional: ret +=3D mcgen(''' bool has_%(c_name)s; @@ -52,6 +53,7 @@ def gen_struct_members(members): %(c_type)s %(c_name)s; ''', c_type=3Dmemb.type.c_type(), c_name=3Dc_name(memb.nam= e)) + ret +=3D gen_endif(memb.ifcond) return ret =20 =20 @@ -131,11 +133,13 @@ def gen_variants(variants): c_name=3Dc_name(variants.tag_member.name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' %(c_type)s %(c_name)s; ''', c_type=3Dvar.type.c_unboxed_type(), c_name=3Dc_name(var.name)) + ret +=3D gen_endif(var.ifcond) =20 ret +=3D mcgen(''' } u; diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index ee776386ae..dc5a3173fc 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -54,6 +54,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: + ret +=3D gen_if(memb.ifcond) if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -73,6 +74,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) ret +=3D mcgen(''' } ''') + ret +=3D gen_endif(memb.ifcond) =20 if variants: ret +=3D mcgen(''' @@ -81,6 +83,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) c_name=3Dc_name(variants.tag_member.name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' case %(case)s: visit_type_%(c_type)s_members(v, &obj->u.%(c_name)s, &err); @@ -91,6 +94,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) variants.tag_member.type.prefix= ), c_type=3Dvar.type.c_name(), c_name=3Dc_name(var.n= ame)) =20 + ret +=3D gen_endif(var.ifcond) ret +=3D mcgen(''' default: abort(); @@ -178,9 +182,10 @@ void visit_type_%(c_name)s(Visitor *v, const char *nam= e, %(c_name)s **obj, Error } switch ((*obj)->type) { ''', - c_name=3Dc_name(name)) + c_name=3Dc_name(name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' case %(case)s: ''', @@ -208,6 +213,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error ret +=3D mcgen(''' break; ''') + ret +=3D gen_endif(var.ifcond) =20 ret +=3D mcgen(''' case QTYPE_NONE: --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634876200526.7593053340039; Wed, 21 Mar 2018 05:21:16 -0700 (PDT) Received: from localhost ([::1]:54301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycjz-0006yq-0V for importer@patchew.org; Wed, 21 Mar 2018 08:21:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJG-00067I-1o for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJC-0008Ka-OA for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42084 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJC-0008KC-JS for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FDCC406DE12 for ; Wed, 21 Mar 2018 11:53:34 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCDEC84456; Wed, 21 Mar 2018 11:53:33 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:52 +0100 Message-Id: <20180321115211.17937-31-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 30/49] docs: document schema configuration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/devel/qapi-code-gen.txt | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index a569d24745..eec52e63e5 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -728,6 +728,44 @@ Example: Red Hat, Inc. controls redhat.com, and may th= erefore add a downstream command __com.redhat_drive-mirror. =20 =20 +=3D=3D=3D Configuring the schema =3D=3D=3D + +Top-level QAPI expressions and various type expressions listed below +can take an 'if' key. The value must be a string or a list of +string. The corresponding generated code will then guard the inclusion +of that member in the larger struct or function with #if IFCOND +(or several #if lines for a list), where IFCOND is the value of the +'if' key. + +'struct', 'enum', 'union', 'alternate', 'command' and 'event' +top-level QAPI expressions can take an 'if' keyword like: + +{ 'struct': 'IfStruct', 'data': { 'foo': 'int' }, + 'if': 'defined(IFCOND)' } + +Where a member can normally be defined with a single string value as its +type, it is also possible to supply a dictionary with both 'type' and +'if' keys. + +{ 'struct': 'IfStruct', 'data': + { 'foo': 'int', + 'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } } + +An enum value can be replaced by a dictionary with a 'name' and a 'if' +key: + +{ 'enum': 'IfEnum', 'data': + [ 'foo', + { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } + +Please note that you are responsible to ensure that the C code will +compile with an arbitrary combination of conditions, since the +generators are unable to check it at this point. + +The presence of 'if' keys in the schema is reflected through to the +introspection output depending on the build configuration. + + =3D=3D Client JSON Protocol introspection =3D=3D =20 Clients of a Client JSON Protocol commonly need to figure out what --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634684233685.9534051114265; Wed, 21 Mar 2018 05:18:04 -0700 (PDT) Received: from localhost ([::1]:54281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycgq-0003bi-8Y for importer@patchew.org; Wed, 21 Mar 2018 08:18:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJG-00067G-1d for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJE-0008Mf-Tk for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42086 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJE-0008MD-Ol for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AB99406DE12 for ; Wed, 21 Mar 2018 11:53:36 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0B95202322F; Wed, 21 Mar 2018 11:53:35 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:53 +0100 Message-Id: <20180321115211.17937-32-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:36 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 31/49] qapi2texi: add 'If:' section to generated documentation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The documentation is generated only once, and doesn't know C pre-conditions. Add 'If:' sections for top-level entities. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/doc.py | 22 ++++++++++++---------- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 1 + tests/qapi-schema/doc-good.texi | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 6c2bf98e1d..783b13303a 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -174,7 +174,7 @@ def texi_members(doc, what, base, variants, member_func= ): return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items) =20 =20 -def texi_sections(doc): +def texi_sections(doc, ifcond): """Format additional sections following arguments""" body =3D '' for section in doc.sections: @@ -185,14 +185,16 @@ def texi_sections(doc): body +=3D texi_example(section.text) else: body +=3D texi_format(section.text) + if ifcond: + body +=3D '\n\n@b{If:} @code{%s}' % ", ".join(ifcond) return body =20 =20 -def texi_entity(doc, what, base=3DNone, variants=3DNone, +def texi_entity(doc, what, ifcond, base=3DNone, variants=3DNone, member_func=3Dtexi_member): return (texi_body(doc) + texi_members(doc, what, base, variants, member_func) - + texi_sections(doc)) + + texi_sections(doc, ifcond)) =20 =20 class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): @@ -208,7 +210,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): doc =3D self.cur_doc self._gen.add(TYPE_FMT(type=3D'Enum', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Values', + body=3Dtexi_entity(doc, 'Values', ifcond, member_func=3Dtexi_enum_va= lue))) =20 def visit_object_type(self, name, info, ifcond, base, members, variant= s): @@ -217,14 +219,14 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaV= isitor): base =3D None self._gen.add(TYPE_FMT(type=3D'Object', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Members', + body=3Dtexi_entity(doc, 'Members', ifcond, base, variants))) =20 def visit_alternate_type(self, name, info, ifcond, variants): doc =3D self.cur_doc self._gen.add(TYPE_FMT(type=3D'Alternate', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Members'))) + body=3Dtexi_entity(doc, 'Members', ifcond))) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): @@ -233,9 +235,9 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): body =3D texi_body(doc) body +=3D ('\n@b{Arguments:} the members of @code{%s}\n' % arg_type.name) - body +=3D texi_sections(doc) + body +=3D texi_sections(doc, ifcond) else: - body =3D texi_entity(doc, 'Arguments') + body =3D texi_entity(doc, 'Arguments', ifcond) self._gen.add(MSG_FMT(type=3D'Command', name=3Ddoc.symbol, body=3Dbody)) @@ -244,7 +246,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): doc =3D self.cur_doc self._gen.add(MSG_FMT(type=3D'Event', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Arguments'))) + body=3Dtexi_entity(doc, 'Arguments', ifcond)= )) =20 def symbol(self, doc, entity): if self._gen._body: @@ -257,7 +259,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVis= itor): assert not doc.args if self._gen._body: self._gen.add('\n') - self._gen.add(texi_body(doc) + texi_sections(doc)) + self._gen.add(texi_body(doc) + texi_sections(doc, None)) =20 =20 def gen_doc(schema, output_dir, prefix): diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 97ab4625ff..984cd8ed06 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -55,7 +55,7 @@ # # @two is undocumented ## -{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'enum': 'Enum', 'data': [ 'one', 'two' ], 'if': 'defined(IFCOND)' } =20 ## # @Base: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 3cd5c094aa..e4054e293c 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -12,6 +12,7 @@ module doc-good.json enum Enum member one member two + if ['defined(IFCOND)'] object Base member base1: Enum optional=3DFalse object Variant1 diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index 0aed2300a5..e42eace474 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -89,6 +89,8 @@ Not documented @end table @code{two} is undocumented =20 + +@b{If:} @code{defined(IFCOND)} @end deftp =20 =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634360399663.0189546762009; Wed, 21 Mar 2018 05:12:40 -0700 (PDT) Received: from localhost ([::1]:54248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycbf-0006kT-HK for importer@patchew.org; Wed, 21 Mar 2018 08:12:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJH-0006Cl-SK for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJH-0008OU-0Y for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46154 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJG-0008OC-SG for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6163CA2017 for ; Wed, 21 Mar 2018 11:53:38 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDE8D84456; Wed, 21 Mar 2018 11:53:37 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:54 +0100 Message-Id: <20180321115211.17937-33-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 21 Mar 2018 11:53:38 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 32/49] qapi2texi: add 'If:' condition to enum values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/doc.py | 5 ++++- tests/qapi-schema/doc-good.json | 4 +++- tests/qapi-schema/doc-good.out | 1 + tests/qapi-schema/doc-good.texi | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 783b13303a..f629425f53 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -128,7 +128,10 @@ def texi_body(doc): =20 def texi_enum_value(value): """Format a table of members item for an enumeration value""" - return '@item @code{%s}\n' % value.name + return '@item @code{%s}%s\n' % ( + value.name, + '\n@b{If:} @code{%s}\n' % + ', '.join(value.ifcond) if value.ifcond else '') =20 =20 def texi_member(member, suffix=3D''): diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 984cd8ed06..c7fe08c530 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -55,7 +55,9 @@ # # @two is undocumented ## -{ 'enum': 'Enum', 'data': [ 'one', 'two' ], 'if': 'defined(IFCOND)' } +{ 'enum': 'Enum', 'data': + [ { 'name': 'one', 'if': 'defined(IFENUM)' }, 'two' ], + 'if': 'defined(IFCOND)' } =20 ## # @Base: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index e4054e293c..d27d345de2 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -11,6 +11,7 @@ enum QType module doc-good.json enum Enum member one + if ['defined(IFENUM)'] member two if ['defined(IFCOND)'] object Base diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index e42eace474..2446a1c702 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -83,6 +83,8 @@ Examples: @b{Values:} @table @asis @item @code{one} +@b{If:} @code{defined(IFENUM)} + The @emph{one} @{and only@} @item @code{two} Not documented --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634812289960.8606552805975; Wed, 21 Mar 2018 05:20:12 -0700 (PDT) Received: from localhost ([::1]:54294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycix-0005hp-3S for importer@patchew.org; Wed, 21 Mar 2018 08:20:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJJ-0006FZ-UA for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJJ-0008Pu-3b for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42102 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJI-0008Pf-W3 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F4A8407519B for ; Wed, 21 Mar 2018 11:53:40 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A45B202322F; Wed, 21 Mar 2018 11:53:39 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:55 +0100 Message-Id: <20180321115211.17937-34-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:40 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 33/49] qapi2texi: add 'If:' condition to struct members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/doc.py | 4 +++- tests/qapi-schema/doc-good.json | 3 ++- tests/qapi-schema/doc-good.out | 1 + tests/qapi-schema/doc-good.texi | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index f629425f53..42e34e1fe3 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -138,9 +138,11 @@ def texi_member(member, suffix=3D''): """Format a table of members item for an object type member""" typ =3D member.type.doc_type() membertype =3D ': ' + typ if typ else '' - return '@item @code{%s%s}%s%s\n' % ( + return '@item @code{%s%s}%s%s%s\n' % ( member.name, membertype, ' (optional)' if member.optional else '', + '\n@b{If:} @code{%s}\n' % + ', '.join(member.ifcond) if member.ifcond else '', suffix) =20 =20 diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index c7fe08c530..158443b1a3 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -72,7 +72,8 @@ # # Another paragraph (but no @var: line) ## -{ 'struct': 'Variant1', 'data': { 'var1': 'str' } } +{ 'struct': 'Variant1', + 'data': { 'var1': { 'type': 'str', 'if': 'defined(IFSTR)' } } } =20 ## # @Variant2: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index d27d345de2..9976d29eb0 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -18,6 +18,7 @@ object Base member base1: Enum optional=3DFalse object Variant1 member var1: str optional=3DFalse + if ['defined(IFSTR)'] object Variant2 object Object base Base diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index 2446a1c702..255eed9a30 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -120,6 +120,8 @@ Another paragraph (but no @code{var}: line) @b{Members:} @table @asis @item @code{var1: string} +@b{If:} @code{defined(IFSTR)} + Not documented @end table =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635040013325.9388906530138; Wed, 21 Mar 2018 05:24:00 -0700 (PDT) Received: from localhost ([::1]:54347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycmc-00010x-Lh for importer@patchew.org; Wed, 21 Mar 2018 08:23:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJQ-0006UE-Sy for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJN-0008SE-MT for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51870 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJN-0008Rx-HW for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D357C40267D7 for ; Wed, 21 Mar 2018 11:53:44 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42A5C8445E; Wed, 21 Mar 2018 11:53:42 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:56 +0100 Message-Id: <20180321115211.17937-35-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:53:44 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 34/49] qapi2texi: add condition to variants X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/doc.py | 5 +++-- tests/qapi-schema/doc-good.json | 4 ++-- tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/doc-good.texi | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 42e34e1fe3..40dcedc6ed 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -165,8 +165,9 @@ def texi_members(doc, what, base, variants, member_func= ): items +=3D '@item The members of @code{%s}\n' % base.doc_type() if variants: for v in variants.variants: - when =3D ' when @code{%s} is @t{"%s"}' % ( - variants.tag_member.name, v.name) + when =3D ' when @code{%s} is @t{"%s"}%s' % ( + variants.tag_member.name, v.name, + ' (@b{If:} @code{%s})' % v.ifcond if v.ifcond else '') if v.type.is_implicit(): assert not v.type.base and not v.type.variants for m in v.type.local_members: diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 158443b1a3..afe46d93f0 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -86,13 +86,13 @@ { 'union': 'Object', 'base': 'Base', 'discriminator': 'base1', - 'data': { 'one': 'Variant1', 'two': 'Variant2' } } + 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # @SugaredUnion: ## { 'union': 'SugaredUnion', - 'data': { 'one': 'Variant1', 'two': 'Variant2' } } + 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # =3D=3D Another subsection diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 9976d29eb0..4b36cf6f7d 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -25,6 +25,7 @@ object Object tag base1 case one: Variant1 case two: Variant2 + if ['IFTWO'] object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse object q_obj_Variant2-wrapper @@ -32,11 +33,13 @@ object q_obj_Variant2-wrapper enum SugaredUnionKind member one member two + if ['IFTWO'] object SugaredUnion member type: SugaredUnionKind optional=3DFalse tag type case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper + if ['IFTWO'] object q_obj_cmd-arg member arg1: int optional=3DFalse member arg2: str optional=3DTrue diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index 255eed9a30..6e226a6231 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -145,7 +145,7 @@ Not documented @table @asis @item The members of @code{Base} @item The members of @code{Variant1} when @code{base1} is @t{"one"} -@item The members of @code{Variant2} when @code{base1} is @t{"two"} +@item The members of @code{Variant2} when @code{base1} is @t{"two"} (@b{If= :} @code{['IFTWO']}) @end table =20 @end deftp @@ -161,7 +161,7 @@ Not documented @item @code{type} One of @t{"one"}, @t{"two"} @item @code{data: Variant1} when @code{type} is @t{"one"} -@item @code{data: Variant2} when @code{type} is @t{"two"} +@item @code{data: Variant2} when @code{type} is @t{"two"} (@b{If:} @code{[= 'IFTWO']}) @end table =20 @end deftp --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635201577698.304688679653; Wed, 21 Mar 2018 05:26:41 -0700 (PDT) Received: from localhost ([::1]:54365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycpE-0003zv-9b for importer@patchew.org; Wed, 21 Mar 2018 08:26:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJQ-0006UD-Sv for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJP-0008Su-9G for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42106 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJP-0008Sk-2o for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97C4F4075392 for ; Wed, 21 Mar 2018 11:53:46 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16D2010B0094; Wed, 21 Mar 2018 11:53:45 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:57 +0100 Message-Id: <20180321115211.17937-36-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:46 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 35/49] qapi: add conditions to VNC type/commands/events on the schema X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add #if defined(CONFIG_VNC) in generated code, and adjust the qmp/hmp code accordingly. query-qmp-schema no longer reports the command/events etc as available when disabled at compile. Commands made conditional: * query-vnc, query-vnc-servers, change-vnc-password Before the patch, the commands for !CONFIG_VNC are stubs that fail like this: {"error": {"class": "GenericError", "desc": "The feature 'vnc' is not enabled"}} Afterwards, they fail like this: {"error": {"class": "CommandNotFound", "desc": "The command FOO has not been found"}} I call that an improvement, because it lets clients distinguish between command unavailable (class CommandNotFound) and command failed (class GenericError). Events made conditional: * VNC_CONNECTED, VNC_INITIALIZED, VNC_DISCONNECTED HMP change: * info vnc Will return "unknown command: 'info vnc'" when VNC is compiled out (same as error for spice when --disable-spice) Occurrences of VNC (case insensitive) in the schema that aren't covered by this change: * add_client Command has other uses, including "socket bases character devices". These are unconditional as far as I can tell. * set_password, expire_password In theory, these commands could be used for managing any service's password. In practice, they're used for VNC and SPICE services. They're documented for "remote display session" / "remote display server". The service is selected by argument @protocol. The code special-cases protocol-specific argument checking, then calls a protocol-specific function to do the work. If it fails, the command fails with "Could not set password". It does when the service isn't compiled in (it's a stub then). We could make these commands conditional on the conjunction of all services [currently: defined(CONFIG_VNC) || defined(CONFIG_SPICE)], but I doubt it's worthwhile. * change Command has other uses, namely changing media. This patch inlines a stub; no functional change. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Gerd Hoffmann --- qapi/ui.json | 45 +++++++++++++++++++++++++++----------------- ui/vnc.h | 2 ++ hmp.c | 9 ++++++++- qmp.c | 30 ++++------------------------- hmp-commands-info.hx | 2 ++ 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index 5d01ad4304..4b96509446 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -377,7 +377,8 @@ 'data': { 'host': 'str', 'service': 'str', 'family': 'NetworkAddressFamily', - 'websocket': 'bool' } } + 'websocket': 'bool' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncServerInfo: @@ -391,7 +392,8 @@ ## { 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', - 'data': { '*auth': 'str' } } + 'data': { '*auth': 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncClientInfo: @@ -408,7 +410,8 @@ ## { 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', - 'data': { '*x509_dname': 'str', '*sasl_username': 'str' } } + 'data': { '*x509_dname': 'str', '*sasl_username': 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncInfo: @@ -449,7 +452,8 @@ { 'struct': 'VncInfo', 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', - '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]} } + '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]}, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncPrimaryAuth: @@ -460,7 +464,8 @@ ## { 'enum': 'VncPrimaryAuth', 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', - 'tls', 'vencrypt', 'sasl' ] } + 'tls', 'vencrypt', 'sasl' ], + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncVencryptSubAuth: @@ -474,8 +479,8 @@ 'tls-none', 'x509-none', 'tls-vnc', 'x509-vnc', 'tls-plain', 'x509-plain', - 'tls-sasl', 'x509-sasl' ] } - + 'tls-sasl', 'x509-sasl' ], + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncServerInfo2: @@ -492,8 +497,8 @@ { 'struct': 'VncServerInfo2', 'base': 'VncBasicInfo', 'data': { 'auth' : 'VncPrimaryAuth', - '*vencrypt' : 'VncVencryptSubAuth' } } - + '*vencrypt' : 'VncVencryptSubAuth' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncInfo2: @@ -525,7 +530,8 @@ 'clients' : ['VncClientInfo'], 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth', - '*display' : 'str' } } + '*display' : 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @query-vnc: @@ -556,8 +562,8 @@ # } # ## -{ 'command': 'query-vnc', 'returns': 'VncInfo' } - +{ 'command': 'query-vnc', 'returns': 'VncInfo', + 'if': 'defined(CONFIG_VNC)' } ## # @query-vnc-servers: # @@ -567,7 +573,8 @@ # # Since: 2.3 ## -{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'] } +{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'], + 'if': 'defined(CONFIG_VNC)' } =20 ## # @change-vnc-password: @@ -581,7 +588,8 @@ # Notes: An empty password in this command will set the password to the e= mpty # string. Existing clients are unaffected by executing this comma= nd. ## -{ 'command': 'change-vnc-password', 'data': {'password': 'str'} } +{ 'command': 'change-vnc-password', 'data': {'password': 'str'}, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VNC_CONNECTED: @@ -610,7 +618,8 @@ ## { 'event': 'VNC_CONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncBasicInfo' } } + 'client': 'VncBasicInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VNC_INITIALIZED: @@ -637,7 +646,8 @@ ## { 'event': 'VNC_INITIALIZED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VNC_DISCONNECTED: @@ -663,7 +673,8 @@ ## { 'event': 'VNC_DISCONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # =3D Input diff --git a/ui/vnc.h b/ui/vnc.h index 7b29def77d..fede2096d9 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -294,7 +294,9 @@ struct VncState bool encode_ws; bool websocket; =20 +#ifdef CONFIG_VNC VncClientInfo *info; +#endif =20 /* Job thread bottom half has put data for a forced update * into the output buffer. This offset points to the end of diff --git a/hmp.c b/hmp.c index 679467d85a..352c2f56f4 100644 --- a/hmp.c +++ b/hmp.c @@ -596,6 +596,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdi= ct) qapi_free_BlockStatsList(stats_list); } =20 +#ifdef CONFIG_VNC /* Helper for hmp_info_vnc_clients, _servers */ static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, const char *name) @@ -683,6 +684,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict) qapi_free_VncInfo2List(info2l); =20 } +#endif =20 #ifdef CONFIG_SPICE void hmp_info_spice(Monitor *mon, const QDict *qdict) @@ -1721,12 +1723,14 @@ void hmp_eject(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } =20 +#ifdef CONFIG_VNC static void hmp_change_read_arg(void *opaque, const char *password, void *readline_opaque) { qmp_change_vnc_password(password, NULL); monitor_read_command(opaque, 1); } +#endif =20 void hmp_change(Monitor *mon, const QDict *qdict) { @@ -1737,6 +1741,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) BlockdevChangeReadOnlyMode read_only_mode =3D 0; Error *err =3D NULL; =20 +#ifdef CONFIG_VNC if (strcmp(device, "vnc") =3D=3D 0) { if (read_only) { monitor_printf(mon, @@ -1751,7 +1756,9 @@ void hmp_change(Monitor *mon, const QDict *qdict) } } qmp_change("vnc", target, !!arg, arg, &err); - } else { + } else +#endif + { if (read_only) { read_only_mode =3D qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, diff --git a/qmp.c b/qmp.c index f72261667f..ee1a816a42 100644 --- a/qmp.c +++ b/qmp.c @@ -129,22 +129,6 @@ void qmp_cpu_add(int64_t id, Error **errp) } } =20 -#ifndef CONFIG_VNC -/* If VNC support is enabled, the "true" query-vnc command is - defined in the VNC subsystem */ -VncInfo *qmp_query_vnc(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; - -VncInfo2List *qmp_query_vnc_servers(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; -#endif - #ifndef CONFIG_SPICE /* * qmp_unregister_commands_hack() ensures that QMP command query-spice @@ -402,23 +386,17 @@ static void qmp_change_vnc(const char *target, bool h= as_arg, const char *arg, qmp_change_vnc_listen(target, errp); } } -#else -void qmp_change_vnc_password(const char *password, Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} -static void qmp_change_vnc(const char *target, bool has_arg, const char *a= rg, - Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} #endif /* !CONFIG_VNC */ =20 void qmp_change(const char *device, const char *target, bool has_arg, const char *arg, Error **errp) { if (strcmp(device, "vnc") =3D=3D 0) { +#ifdef CONFIG_VNC qmp_change_vnc(target, has_arg, arg, errp); +#else + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); +#endif } else { qmp_blockdev_change_medium(true, device, false, NULL, target, has_arg, arg, false, 0, errp); diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ddfcd5adcc..7f681df119 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -421,6 +421,7 @@ STEXI Show which guest mouse is receiving events. ETEXI =20 +#if defined(CONFIG_VNC) { .name =3D "vnc", .args_type =3D "", @@ -428,6 +429,7 @@ ETEXI .help =3D "show the vnc server status", .cmd =3D hmp_info_vnc, }, +#endif =20 STEXI @item info vnc --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634869369162.05496906830854; Wed, 21 Mar 2018 05:21:09 -0700 (PDT) Received: from localhost ([::1]:54300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycjn-0006mv-IH for importer@patchew.org; Wed, 21 Mar 2018 08:21:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJS-0006W5-RH for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJR-0008UA-Hm for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42110 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJR-0008Tq-Cd for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA726406DE12 for ; Wed, 21 Mar 2018 11:53:48 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57D7C200BCA1; Wed, 21 Mar 2018 11:53:48 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:58 +0100 Message-Id: <20180321115211.17937-37-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 36/49] qapi: add conditions to SPICE type/commands/events on the schema X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add #if defined(CONFIG_SPICE) in generated code, and adjust the qmp/hmp code accordingly. query-qmp-schema no longer reports the command/events etc as available when disabled at compile time. Commands made conditional: * query-spice Before the patch, the command for !CONFIG_SPICE is unregistered. It will fail with the same error. Events made conditional: * SPICE_CONNECTED, SPICE_INITIALIZED, SPICE_DISCONNECTED, SPICE_MIGRATE_COMPLETED Chardev made conditional: * spiceport, spicevmc Before and after the patch for !CONFIG_SPICE, the error is the same ('spiceport' is not a valid char driver name). No HMP change, the code was already conditional. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Gerd Hoffmann --- qapi/char.json | 10 ++++++---- qapi/ui.json | 30 ++++++++++++++++++++---------- monitor.c | 3 --- qmp.c | 16 ---------------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/qapi/char.json b/qapi/char.json index ae19dcd1ed..7fa1762ae5 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -318,7 +318,8 @@ # Since: 1.5 ## { 'struct': 'ChardevSpiceChannel', 'data': { 'type' : 'str' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @ChardevSpicePort: @@ -330,7 +331,8 @@ # Since: 1.5 ## { 'struct': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @ChardevVC: @@ -384,8 +386,8 @@ 'testdev': 'ChardevCommon', 'stdio' : 'ChardevStdio', 'console': 'ChardevCommon', - 'spicevmc' : 'ChardevSpiceChannel', - 'spiceport' : 'ChardevSpicePort', + 'spicevmc' : { 'type': 'ChardevSpic= eChannel', 'if': 'defined(CONFIG_SPICE)' }, + 'spiceport' : { 'type': 'ChardevSpi= cePort', 'if': 'defined(CONFIG_SPICE)' }, 'vc' : 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility diff --git a/qapi/ui.json b/qapi/ui.json index 4b96509446..e47fae2e90 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -118,7 +118,8 @@ { 'struct': 'SpiceBasicInfo', 'data': { 'host': 'str', 'port': 'str', - 'family': 'NetworkAddressFamily' } } + 'family': 'NetworkAddressFamily' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceServerInfo: @@ -131,7 +132,8 @@ ## { 'struct': 'SpiceServerInfo', 'base': 'SpiceBasicInfo', - 'data': { '*auth': 'str' } } + 'data': { '*auth': 'str' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceChannel: @@ -156,7 +158,8 @@ { 'struct': 'SpiceChannel', 'base': 'SpiceBasicInfo', 'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'i= nt', - 'tls': 'bool'} } + 'tls': 'bool'}, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceQueryMouseMode: @@ -175,7 +178,8 @@ # Since: 1.1 ## { 'enum': 'SpiceQueryMouseMode', - 'data': [ 'client', 'server', 'unknown' ] } + 'data': [ 'client', 'server', 'unknown' ], + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceInfo: @@ -212,7 +216,8 @@ { 'struct': 'SpiceInfo', 'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port':= 'int', '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str', - 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChanne= l']} } + 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChanne= l']}, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @query-spice: @@ -257,7 +262,8 @@ # } # ## -{ 'command': 'query-spice', 'returns': 'SpiceInfo' } +{ 'command': 'query-spice', 'returns': 'SpiceInfo', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_CONNECTED: @@ -282,7 +288,8 @@ ## { 'event': 'SPICE_CONNECTED', 'data': { 'server': 'SpiceBasicInfo', - 'client': 'SpiceBasicInfo' } } + 'client': 'SpiceBasicInfo' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_INITIALIZED: @@ -310,7 +317,8 @@ ## { 'event': 'SPICE_INITIALIZED', 'data': { 'server': 'SpiceServerInfo', - 'client': 'SpiceChannel' } } + 'client': 'SpiceChannel' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_DISCONNECTED: @@ -335,7 +343,8 @@ ## { 'event': 'SPICE_DISCONNECTED', 'data': { 'server': 'SpiceBasicInfo', - 'client': 'SpiceBasicInfo' } } + 'client': 'SpiceBasicInfo' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_MIGRATE_COMPLETED: @@ -350,7 +359,8 @@ # "event": "SPICE_MIGRATE_COMPLETED" } # ## -{ 'event': 'SPICE_MIGRATE_COMPLETED' } +{ 'event': 'SPICE_MIGRATE_COMPLETED', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # =3D=3D VNC diff --git a/monitor.c b/monitor.c index 6ccd2fc089..8a5539579b 100644 --- a/monitor.c +++ b/monitor.c @@ -1087,9 +1087,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObjec= t **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef CONFIG_SPICE - qmp_unregister_command(&qmp_commands, "query-spice"); -#endif #ifndef CONFIG_REPLICATION qmp_unregister_command(&qmp_commands, "xen-set-replication"); qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); diff --git a/qmp.c b/qmp.c index ee1a816a42..d8f80cb04e 100644 --- a/qmp.c +++ b/qmp.c @@ -129,22 +129,6 @@ void qmp_cpu_add(int64_t id, Error **errp) } } =20 -#ifndef CONFIG_SPICE -/* - * qmp_unregister_commands_hack() ensures that QMP command query-spice - * exists only #ifdef CONFIG_SPICE. Necessary for an accurate - * query-commands result. However, the QAPI schema is blissfully - * unaware of that, and the QAPI code generator happily generates a - * dead qmp_marshal_query_spice() that calls qmp_query_spice(). - * Provide it one, or else linking fails. FIXME Educate the QAPI - * schema on CONFIG_SPICE. - */ -SpiceInfo *qmp_query_spice(Error **errp) -{ - abort(); -}; -#endif - void qmp_cont(Error **errp) { BlockBackend *blk; --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15216353640891009.1365788411046; Wed, 21 Mar 2018 05:29:24 -0700 (PDT) Received: from localhost ([::1]:54377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycrl-0006wb-OT for importer@patchew.org; Wed, 21 Mar 2018 08:29:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJU-0006Y4-Vv for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJT-0008VM-BA for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42112 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJT-0008V8-5Z for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEE86406DE12 for ; Wed, 21 Mar 2018 11:53:50 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 336EA215CDB7; Wed, 21 Mar 2018 11:53:50 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:51:59 +0100 Message-Id: <20180321115211.17937-38-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:53:50 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 37/49] qapi: add conditions to REPLICATION type/commands on the schema X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add #if defined(CONFIG_REPLICATION) in generated code, and adjust the code accordingly. Made conditional: * xen-set-replication, query-xen-replication-status, xen-colo-do-checkpoint Before the patch, we first register the commands unconditionally in generated code (requires a stub), then conditionally unregister in qmp_unregister_commands_hack(). Afterwards, we register only when CONFIG_REPLICATION. The command fails exactly the same, with CommandNotFound. Improvement, because now query-qmp-schema is accurate, and we're one step closer to killing qmp_unregister_commands_hack(). * enum BlockdevDriver value "replication" in command blockdev-add * BlockdevOptions variant @replication And related structures. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/block-core.json | 13 +++++++++---- qapi/migration.json | 12 ++++++++---- migration/colo.c | 16 ++++------------ monitor.c | 5 ----- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 1088ab0c78..c20d39049b 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2514,7 +2514,9 @@ 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow', 'qcow2', '= qed', - 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', + 'quorum', 'raw', 'rbd', + { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, + 'sheepdog', 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } =20 ## @@ -3228,7 +3230,8 @@ # # Since: 2.9 ## -{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ] } +{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ], + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @BlockdevOptionsReplication: @@ -3246,7 +3249,8 @@ { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @NFSTransport: @@ -3545,7 +3549,8 @@ 'quorum': 'BlockdevOptionsQuorum', 'raw': 'BlockdevOptionsRaw', 'rbd': 'BlockdevOptionsRbd', - 'replication':'BlockdevOptionsReplication', + 'replication': { 'type': 'BlockdevOptionsReplication', + 'if': 'defined(CONFIG_REPLICATION)' }, 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', 'throttle': 'BlockdevOptionsThrottle', diff --git a/qapi/migration.json b/qapi/migration.json index 9d0bf82cf4..d2c6e4d646 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1121,7 +1121,8 @@ # Since: 2.9 ## { 'command': 'xen-set-replication', - 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' } } + 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @ReplicationStatus: @@ -1136,7 +1137,8 @@ # Since: 2.9 ## { 'struct': 'ReplicationStatus', - 'data': { 'error': 'bool', '*desc': 'str' } } + 'data': { 'error': 'bool', '*desc': 'str' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @query-xen-replication-status: @@ -1153,7 +1155,8 @@ # Since: 2.9 ## { 'command': 'query-xen-replication-status', - 'returns': 'ReplicationStatus' } + 'returns': 'ReplicationStatus', + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @xen-colo-do-checkpoint: @@ -1169,4 +1172,5 @@ # # Since: 2.9 ## -{ 'command': 'xen-colo-do-checkpoint' } +{ 'command': 'xen-colo-do-checkpoint', + 'if': 'defined(CONFIG_REPLICATION)' } diff --git a/migration/colo.c b/migration/colo.c index 4381067ed4..2329e78e7f 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -24,7 +24,9 @@ #include "trace.h" #include "qemu/error-report.h" #include "migration/failover.h" +#ifdef CONFIG_REPLICATION #include "replication.h" +#endif =20 static bool vmstate_loading; =20 @@ -148,11 +150,11 @@ void colo_do_failover(MigrationState *s) } } =20 +#ifdef CONFIG_REPLICATION void qmp_xen_set_replication(bool enable, bool primary, bool has_failover, bool failover, Error **errp) { -#ifdef CONFIG_REPLICATION ReplicationMode mode =3D primary ? REPLICATION_MODE_PRIMARY : REPLICATION_MODE_SECONDARY; @@ -171,14 +173,10 @@ void qmp_xen_set_replication(bool enable, bool primar= y, } replication_stop_all(failover, failover ? NULL : errp); } -#else - abort(); -#endif } =20 ReplicationStatus *qmp_query_xen_replication_status(Error **errp) { -#ifdef CONFIG_REPLICATION Error *err =3D NULL; ReplicationStatus *s =3D g_new0(ReplicationStatus, 1); =20 @@ -193,19 +191,13 @@ ReplicationStatus *qmp_query_xen_replication_status(E= rror **errp) =20 error_free(err); return s; -#else - abort(); -#endif } =20 void qmp_xen_colo_do_checkpoint(Error **errp) { -#ifdef CONFIG_REPLICATION replication_do_checkpoint_all(errp); -#else - abort(); -#endif } +#endif =20 static void colo_send_message(QEMUFile *f, COLOMessage msg, Error **errp) diff --git a/monitor.c b/monitor.c index 8a5539579b..88e6fd2e6f 100644 --- a/monitor.c +++ b/monitor.c @@ -1087,11 +1087,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObje= ct **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef CONFIG_REPLICATION - qmp_unregister_command(&qmp_commands, "xen-set-replication"); - qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); - qmp_unregister_command(&qmp_commands, "xen-colo-do-checkpoint"); -#endif #ifndef TARGET_I386 qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); qmp_unregister_command(&qmp_commands, "query-sev"); --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152163498783719.67385689200387; Wed, 21 Mar 2018 05:23:07 -0700 (PDT) Received: from localhost ([::1]:54343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyclf-0008VH-7t for importer@patchew.org; Wed, 21 Mar 2018 08:22:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJV-0006Yn-LQ for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJU-0008Vw-Pf for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53276 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJU-0008Vk-Lq for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 388DB4001852 for ; Wed, 21 Mar 2018 11:53:52 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id D767F202322F; Wed, 21 Mar 2018 11:53:51 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:00 +0100 Message-Id: <20180321115211.17937-39-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 38/49] build-sys: move qmp-introspect per target X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The following patches are going to introduce per-target #ifdef in the schemas. The introspection data is statically generated once, and must thus be built per-target to reflect target-specific configuration. Drop "do_test_visitor_in_qmp_introspect(&qmp_schema_qlit)" since the schema is no longer in a common object. It is covered by the per-target query-qmp-schema test instead. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/test-qobject-input-visitor.c | 1 - Makefile.objs | 2 -- Makefile.target | 2 ++ 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 6dc59c6211..e14544fc89 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -1270,7 +1270,6 @@ static void test_visitor_in_qmp_introspect(TestInputV= isitorData *data, const void *unused) { do_test_visitor_in_qmp_introspect(data, &test_qmp_schema_qlit); - do_test_visitor_in_qmp_introspect(data, &qmp_schema_qlit); } =20 int main(int argc, char **argv) diff --git a/Makefile.objs b/Makefile.objs index c6c9b8fc21..f0b10dbf23 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -55,7 +55,6 @@ util-obj-y +=3D qapi/qapi-events-tpm.o util-obj-y +=3D qapi/qapi-events-trace.o util-obj-y +=3D qapi/qapi-events-transaction.o util-obj-y +=3D qapi/qapi-events-ui.o -util-obj-y +=3D qapi/qapi-introspect.o =20 chardev-obj-y =3D chardev/ =20 @@ -150,7 +149,6 @@ common-obj-y +=3D qapi/qapi-commands-tpm.o common-obj-y +=3D qapi/qapi-commands-trace.o common-obj-y +=3D qapi/qapi-commands-transaction.o common-obj-y +=3D qapi/qapi-commands-ui.o -common-obj-y +=3D qapi/qapi-introspect.o common-obj-y +=3D qmp.o hmp.o endif =20 diff --git a/Makefile.target b/Makefile.target index 6549481096..0bb18dff9e 100644 --- a/Makefile.target +++ b/Makefile.target @@ -150,6 +150,8 @@ endif =20 GENERATED_FILES +=3D hmp-commands.h hmp-commands-info.h =20 +obj-y +=3D qapi/qapi-introspect.o + endif # CONFIG_SOFTMMU =20 # Workaround for http://gcc.gnu.org/PR55489, see configure. --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635546724663.3567581736488; Wed, 21 Mar 2018 05:32:26 -0700 (PDT) Received: from localhost ([::1]:54423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycuk-00017E-3K for importer@patchew.org; Wed, 21 Mar 2018 08:32:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJZ-0006dO-MW for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJW-00005r-Qe for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53278 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJW-00005T-Mb for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 376B94001852 for ; Wed, 21 Mar 2018 11:53:54 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB4F7215CDB7; Wed, 21 Mar 2018 11:53:53 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:01 +0100 Message-Id: <20180321115211.17937-40-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 39/49] qapi-commands: don't initialize command list in qmp_init_marshall() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will let the caller add several list of commands coming from different schemas (the following patches split the schemas for common and arch-specific parts). Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/commands.py | 2 -- monitor.c | 1 + qga/main.c | 1 + tests/test-qmp-cmds.c | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 40bb680b7c..3d3e97f737 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -220,8 +220,6 @@ def gen_registry(registry, prefix): =20 void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) { - QTAILQ_INIT(cmds); - ''', c_prefix=3Dc_name(prefix, protect=3DFalse)) ret +=3D registry diff --git a/monitor.c b/monitor.c index 88e6fd2e6f..0d84c3edb4 100644 --- a/monitor.c +++ b/monitor.c @@ -1121,6 +1121,7 @@ static void monitor_init_qmp_commands(void) * "qmp_capabilities", to enforce capability negotiation */ =20 + QTAILQ_INIT(&qmp_commands); qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "query-qmp-schema", diff --git a/qga/main.c b/qga/main.c index df1888edc1..6905c82b6c 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1364,6 +1364,7 @@ int main(int argc, char **argv) =20 config->log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; =20 + QTAILQ_INIT(&ga_commands); qga_qmp_init_marshal(&ga_commands); =20 init_dfl_pathnames(); diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index e675722593..e723b440ca 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -285,6 +285,7 @@ int main(int argc, char **argv) g_test_add_func("/0.15/dealloc_types", test_dealloc_types); g_test_add_func("/0.15/dealloc_partial", test_dealloc_partial); =20 + QTAILQ_INIT(&qmp_commands); test_qmp_init_marshal(&qmp_commands); g_test_run(); =20 --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635721663858.4915568188783; Wed, 21 Mar 2018 05:35:21 -0700 (PDT) Received: from localhost ([::1]:54474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycxc-0004LH-K8 for importer@patchew.org; Wed, 21 Mar 2018 08:35:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJb-0006fP-Az for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJY-00006k-Qk for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53280 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJY-00006R-Is for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:53:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DEC74001852 for ; Wed, 21 Mar 2018 11:53:56 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B21084456; Wed, 21 Mar 2018 11:53:55 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:02 +0100 Message-Id: <20180321115211.17937-41-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:53:56 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 40/49] RFC: qapi: learn to split schema by 'top-unit' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Another take at making the schema modular, this time by introducing the concept of a 'top-unit'. With this approach, each module is part of a top-unit, which is visited first before visiting the module themselfs. The default 'top-unit' is None. Else, a module belong to a 'top-unit' whose name is given by the 'top-unit' pragma value. This gives a chance to the generators to break generated output into different files. The point of this excercice is to have modules that can be compiled per qemu targets, instead of everything belonging to the top schema without the right to use poisoin defines for conditional compilation. Generated types, visitors, events and commands are split by 'top-unit'. The generated introspection and documentation remain monolithic. TODO: if this approach is acceptable, write tests & doc. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/commands.py | 22 +++++--- scripts/qapi/common.py | 105 +++++++++++++++++++++++++++++++-------- scripts/qapi/events.py | 33 ++++++++---- scripts/qapi/types.py | 8 +-- scripts/qapi/visit.py | 8 +-- 5 files changed, 129 insertions(+), 47 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 3d3e97f737..3ca36fc33b 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -235,14 +235,20 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCV= isitor): QAPISchemaModularCVisitor.__init__( self, prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', __doc__) + + def visit_unit_begin(self, unit): + super(self.__class__, self).visit_unit_begin(unit) self._regy =3D QAPIGenCSnippet() self._visited_ret_types =3D {} =20 - def _begin_module(self, name): + def _begin_module(self, name, main_module): self._visited_ret_types[self._genc] =3D set() - commands =3D self._module_basename('qapi-commands', name) - types =3D self._module_basename('qapi-types', name) - visit =3D self._module_basename('qapi-visit', name) + commands =3D self._module_basename('qapi-commands', name, + self._unit, main_module) + types =3D self._module_basename('qapi-types', name, + self._unit, main_module) + visit =3D self._module_basename('qapi-visit', name, + self._unit, main_module) self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "qemu-common.h" @@ -265,13 +271,13 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCV= isitor): ''', types=3Dtypes)) =20 - def visit_end(self): - (genc, genh) =3D self._module[self._main_module] + def visit_unit_end(self): + (genc, genh) =3D self.get_module_gen(self._main_module) genh.add(mcgen(''' void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', - c_prefix=3Dc_name(self._prefix, protect=3DFalse))) - genc.add(gen_registry(self._regy.get_content(), self._prefix)) + c_prefix=3Dc_name(self._prefix_unit(), protect=3DFa= lse))) + genc.add(gen_registry(self._regy.get_content(), self._prefix_unit(= ))) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob): diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 174b39ea50..bff8de05d1 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -271,11 +271,12 @@ class QAPISchemaParser(object): self.exprs =3D [] self.docs =3D [] self.accept() + self._top_unit =3D None cur_doc =3D None =20 while self.tok is not None: info =3D {'file': self.fname, 'line': self.line, - 'parent': self.incl_info} + 'parent': self.incl_info, 'top-unit': self._top_unit} if self.tok =3D=3D '#': self.reject_expr_doc(cur_doc) cur_doc =3D self.get_doc(info) @@ -298,6 +299,9 @@ class QAPISchemaParser(object): exprs_include =3D self._include(include, info, incl_fname, previously_included) if exprs_include: + incl_info =3D self.exprs[-1]['info'] + if exprs_include._top_unit: + incl_info['has-pragma-top-unit'] =3D exprs_include= ._top_unit self.exprs.extend(exprs_include.exprs) self.docs.extend(exprs_include.docs) elif "pragma" in expr: @@ -356,6 +360,11 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Pragma 'doc-required' must be boolean") doc_required =3D value + elif name =3D=3D 'top-unit': + if not isinstance(value, str): + raise QAPISemError(info, + "Pragma 'top-unit' must be a string") + self._top_unit =3D value elif name =3D=3D 'returns-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): @@ -1098,6 +1107,11 @@ class QAPISchemaEntity(object): def c_name(self): return c_name(self.name) =20 + def get_top_unit(self): + if self.info: + return self.info['top-unit'] + return None + def check(self, schema): if isinstance(self._ifcond, QAPISchemaType): # inherit the condition from a type @@ -1118,6 +1132,12 @@ class QAPISchemaVisitor(object): def visit_begin(self, schema): pass =20 + def visit_unit_begin(self, unit): + pass + + def visit_unit_end(self): + pass + def visit_end(self): pass =20 @@ -1613,7 +1633,7 @@ class QAPISchema(object): parser =3D QAPISchemaParser(open(fname, 'r')) exprs =3D check_exprs(parser.exprs) self.docs =3D parser.docs - self._entity_list =3D [] + self._entity_list =3D {} # dict of unit name -> list of entity self._entity_dict =3D {} self._predefining =3D True self._def_predefineds() @@ -1625,7 +1645,8 @@ class QAPISchema(object): # Only the predefined types are allowed to not have info assert ent.info or self._predefining assert ent.name is None or ent.name not in self._entity_dict - self._entity_list.append(ent) + entity_list =3D self._entity_list.setdefault(ent.get_top_unit(), [= ]) + entity_list.append(ent) if ent.name is not None: self._entity_dict[ent.name] =3D ent if ent.info: @@ -1870,18 +1891,23 @@ class QAPISchema(object): assert False =20 def check(self): - for ent in self._entity_list: - ent.check(self) + for unit in self._entity_list: + for ent in self._entity_list[unit]: + ent.check(self) =20 def visit(self, visitor): visitor.visit_begin(self) - module =3D None - for entity in self._entity_list: - if visitor.visit_needed(entity): + for unit in self._entity_list: + module =3D None + visitor.visit_unit_begin(unit) + for entity in self._entity_list[unit]: + if not visitor.visit_needed(entity): + continue if entity.module !=3D module: module =3D entity.module visitor.visit_module(module) entity.visit(visitor) + visitor.visit_unit_end() visitor.visit_end() =20 =20 @@ -2301,6 +2327,19 @@ class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor= ): self._genh.write(output_dir, self._prefix + self._what + '.h') =20 =20 +class QAPIGenCModule(object): + + def __init__(self, blurb, pydoc, unit, main_module=3DFalse): + self.genc =3D QAPIGenC(blurb, pydoc) + self.genh =3D QAPIGenH(blurb, pydoc) + self.unit =3D unit + self.main_module =3D main_module + + def write(self, output_dir, basename): + self.genc.write(output_dir, basename + '.c') + self.genh.write(output_dir, basename + '.h') + + class QAPISchemaModularCVisitor(QAPISchemaVisitor): =20 def __init__(self, prefix, what, blurb, pydoc): @@ -2309,48 +2348,70 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._blurb =3D blurb self._pydoc =3D pydoc self._module =3D {} + self._unit =3D None self._main_module =3D None =20 - def _module_basename(self, what, name): + def _module_basename(self, what, name, unit=3DNone, main_module=3DFals= e): if name is None: return re.sub(r'-', '-builtin-', what) basename =3D os.path.join(os.path.dirname(name), self._prefix + what) - if name =3D=3D self._main_module: + if unit: + basename =3D unit + '-' + basename + if main_module: return basename return basename + '-' + os.path.splitext(os.path.basename(name))[0] =20 + def _prefix_unit(self): + if self._unit: + return self._prefix + self._unit + '-' + return self._prefix + + def visit_unit_begin(self, unit): + self._unit =3D unit + self._main_module =3D None + def _add_module(self, name, blurb): - if self._main_module is None and name is not None: + main_module =3D False + if (name is not None and + ((self._unit is None and self._main_module is None) or + (self._unit =3D=3D os.path.splitext(os.path.basename(name))[0= ]))): self._main_module =3D name - genc =3D QAPIGenC(blurb, self._pydoc) - genh =3D QAPIGenH(blurb, self._pydoc) - self._module[name] =3D (genc, genh) + main_module =3D True + self._module[name] =3D QAPIGenCModule(blurb, self._pydoc, + self._unit, main_module) self._set_module(name) + return main_module + + def get_module_gen(self, name): + mod =3D self._module[name] + return mod.genc, mod.genh =20 def _set_module(self, name): - self._genc, self._genh =3D self._module[name] + self._genc, self._genh =3D self.get_module_gen(name) =20 def write(self, output_dir, opt_builtins=3DFalse): for name in self._module: if name is None and not opt_builtins: continue - basename =3D self._module_basename(self._what, name) - (genc, genh) =3D self._module[name] - genc.write(output_dir, basename + '.c') - genh.write(output_dir, basename + '.h') + module =3D self._module[name] + basename =3D self._module_basename(self._what, name, + module.unit, module.main_modu= le) + module.write(output_dir, basename) =20 - def _begin_module(self, name): + def _begin_module(self, name, main_module): pass =20 def visit_module(self, name): if name in self._module: self._set_module(name) return - self._add_module(name, self._blurb) - self._begin_module(name) + main_module =3D self._add_module(name, self._blurb) + self._begin_module(name, main_module) =20 def visit_include(self, name, info): + if 'has-pragma-top-unit' in info: + return basename =3D self._module_basename(self._what, name) self._genh.preamble_add(mcgen(''' #include "%(basename)s.h" diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index f02b65cf5a..88bfcfcf2a 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -58,7 +58,12 @@ def gen_param_var(typ): return ret =20 =20 -def gen_event_send(name, arg_type, boxed, event_enum_name): +def gen_event_send(unit, name, arg_type, boxed, event_enum_name): + if not unit: + unit =3D '' + else: + unit +=3D '_' + # 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 @@ -87,7 +92,7 @@ def gen_event_send(name, arg_type, boxed, event_enum_name= ): =20 ret +=3D mcgen(''' =20 - emit =3D qmp_event_get_func_emit(); + emit =3D %(unit)sqmp_event_get_func_emit(); if (!emit) { return; } @@ -95,7 +100,7 @@ def gen_event_send(name, arg_type, boxed, event_enum_nam= e): qmp =3D qmp_event_build_dict("%(name)s"); =20 ''', - name=3Dname) + name=3Dname, unit=3Dunit) =20 if arg_type and not arg_type.is_empty(): ret +=3D mcgen(''' @@ -154,12 +159,17 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVis= itor): QAPISchemaModularCVisitor.__init__( self, prefix, 'qapi-events', ' * Schema-defined QAPI/QMP events', __doc__) - self._enum_name =3D c_name(prefix + 'QAPIEvent', protect=3DFalse) + + def visit_unit_begin(self, unit): + super(self.__class__, self).visit_unit_begin(unit) + self._enum_name =3D c_name(self._prefix_unit() + 'QAPIEvent', prot= ect=3DFalse) self._event_names =3D [] =20 - def _begin_module(self, name): - types =3D self._module_basename('qapi-types', name) - visit =3D self._module_basename('qapi-visit', name) + def _begin_module(self, name, main_module): + types =3D self._module_basename('qapi-types', name, + self._unit, main_module) + visit =3D self._module_basename('qapi-visit', name, + self._unit, main_module) self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "qemu-common.h" @@ -171,7 +181,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): #include "qapi/qmp-event.h" =20 ''', - visit=3Dvisit, prefix=3Dself._prefix)) + visit=3Dvisit, prefix=3Dself._prefix_unit())) self._genh.add(mcgen(''' #include "qapi/util.h" #include "%(types)s.h" @@ -179,15 +189,16 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVis= itor): ''', types=3Dtypes)) =20 - def visit_end(self): - (genc, genh) =3D self._module[self._main_module] + def visit_unit_end(self): + (genc, genh) =3D self.get_module_gen(self._main_module) genh.add(gen_enum(self._enum_name, self._event_names)) genc.add(gen_enum_lookup(self._enum_name, self._event_names)) =20 def visit_event(self, name, info, ifcond, 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._enu= m_name)) + self._genc.add(gen_event_send(self._unit, name, + arg_type, boxed, self._enum_name= )) self._event_names.append(QAPISchemaMember(name, ifcond)) =20 =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index b0d3ddb596..ac0c4603d4 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -194,9 +194,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisit= or): #include "qapi/util.h" ''')) =20 - def _begin_module(self, name): - types =3D self._module_basename('qapi-types', name) - visit =3D self._module_basename('qapi-visit', name) + def _begin_module(self, name, main_module): + types =3D self._module_basename('qapi-types', name, + self._unit, main_module) + visit =3D self._module_basename('qapi-visit', name, + self._unit, main_module) self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index dc5a3173fc..60625aae72 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -289,9 +289,11 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisi= tor): ''', prefix=3Dprefix)) =20 - def _begin_module(self, name): - types =3D self._module_basename('qapi-types', name) - visit =3D self._module_basename('qapi-visit', name) + def _begin_module(self, name, main_module): + types =3D self._module_basename('qapi-types', name, + self._unit, main_module) + visit =3D self._module_basename('qapi-visit', name, + self._unit, main_module) self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qemu-common.h" --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635032202976.7382304330383; Wed, 21 Mar 2018 05:23:52 -0700 (PDT) Received: from localhost ([::1]:54345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycmU-0000oa-Sx for importer@patchew.org; Wed, 21 Mar 2018 08:23:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJe-0006ii-J4 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJc-00009a-PR for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53284 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJc-00009I-Jk for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27B384001852 for ; Wed, 21 Mar 2018 11:54:00 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55A3D10B0094; Wed, 21 Mar 2018 11:53:57 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:03 +0100 Message-Id: <20180321115211.17937-42-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:54:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Mar 2018 11:54:00 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 41/49] qapi: add a top-unit 'target' schema X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a 'target' top-unit to be compiled seperately from the common qapi modules, in order to allow poisoined target #ifdef. The generated commands must be registered seperately. The events have a different enum, and must thus use a different limiter/emitter. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/qapi-schema.json | 1 + qapi/target.json | 13 +++ include/qapi/qmp-event.h | 4 + monitor.c | 205 ++++++++++++++++++++++++++------------- qapi/qmp-event.c | 11 +++ Makefile | 1 + Makefile.target | 2 + 7 files changed, 170 insertions(+), 67 deletions(-) create mode 100644 qapi/target.json diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 25bce78352..6e7f85ae6d 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -93,3 +93,4 @@ { 'include': 'trace.json' } { 'include': 'introspect.json' } { 'include': 'misc.json' } +{ 'include': 'target.json' } diff --git a/qapi/target.json b/qapi/target.json new file mode 100644 index 0000000000..be2360ca34 --- /dev/null +++ b/qapi/target.json @@ -0,0 +1,13 @@ +# -*- Mode: Python -*- +# + +## +# =3D Target-specific commands & events +## + +{ 'pragma': { 'top-unit': 'target' } } + +## +# @DUMMY: +## +{ 'event': 'DUMMY' } diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h index 0c87ad833e..cdf3b9b970 100644 --- a/include/qapi/qmp-event.h +++ b/include/qapi/qmp-event.h @@ -21,5 +21,9 @@ void qmp_event_set_func_emit(QMPEventFuncEmit emit); =20 QMPEventFuncEmit qmp_event_get_func_emit(void); =20 +void target_qmp_event_set_func_emit(QMPEventFuncEmit emit); + +QMPEventFuncEmit target_qmp_event_get_func_emit(void); + QDict *qmp_event_build_dict(const char *event_name); #endif diff --git a/monitor.c b/monitor.c index 0d84c3edb4..0b96285e94 100644 --- a/monitor.c +++ b/monitor.c @@ -77,6 +77,8 @@ #include "block/qapi.h" #include "qapi/qapi-commands.h" #include "qapi/qapi-events.h" +#include "qapi/target-qapi-commands.h" +#include "qapi/target-qapi-events.h" #include "qapi/error.h" #include "qapi/qmp-event.h" #include "qapi/qapi-introspect.h" @@ -184,22 +186,25 @@ typedef struct { GQueue *qmp_responses; } MonitorQMP; =20 +typedef struct { + GHashTable *state; + const size_t size; /* size of array =3D=3D number of events */ + const int64_t rate[]; /* Minimum time (in ns) between two events */ +} MonitorQAPIEventRateLimit; + /* * To prevent flooding clients, events can be throttled. The * throttling is calculated globally, rather than per-Monitor * instance. */ typedef struct MonitorQAPIEventState { - QAPIEvent event; /* Throttling state for this event type and... */ + const MonitorQAPIEventRateLimit *limiter; + unsigned event; /* Throttling state for this event type and... */ QDict *data; /* ... data, see qapi_event_throttle_equal() */ QEMUTimer *timer; /* Timer for handling delayed events */ QDict *qdict; /* Delayed event (if any) */ } MonitorQAPIEventState; =20 -typedef struct { - int64_t rate; /* Minimum time (in ns) between two events */ -} MonitorQAPIEventConf; - struct Monitor { CharBackend chr; int reset_seen; @@ -502,23 +507,11 @@ static void monitor_qmp_bh_responder(void *opaque) } } =20 -static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { - /* Limit guest-triggerable events to 1 per second */ - [QAPI_EVENT_RTC_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_WATCHDOG] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_BALLOON_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_QUORUM_REPORT_BAD] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_QUORUM_FAILURE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_VSERPORT_CHANGE] =3D { 1000 * SCALE_MS }, -}; - -GHashTable *monitor_qapi_event_state; - /* * Emits the event to every monitor instance, @event is only used for trace * Called with monitor_lock held. */ -static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict) +static void monitor_qapi_event_emit(unsigned event, QDict *qdict) { Monitor *mon; =20 @@ -538,30 +531,31 @@ static void monitor_qapi_event_handler(void *opaque); * applying any rate limiting if required. */ static void -monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp) +monitor_qapi_event_queue_limit(const MonitorQAPIEventRateLimit *limiter, + unsigned event, QDict *qdict, Error **errp) { - MonitorQAPIEventConf *evconf; + int64_t rate; MonitorQAPIEventState *evstate; =20 - assert(event < QAPI_EVENT__MAX); - evconf =3D &monitor_qapi_event_conf[event]; - trace_monitor_protocol_event_queue(event, qdict, evconf->rate); + assert(event < limiter->size); + rate =3D limiter->rate[event]; + trace_monitor_protocol_event_queue(event, qdict, rate); =20 qemu_mutex_lock(&monitor_lock); =20 - if (!evconf->rate) { + if (!rate) { /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { QDict *data =3D qobject_to(QDict, qdict_get(qdict, "data")); MonitorQAPIEventState key =3D { .event =3D event, .data =3D data }; =20 - evstate =3D g_hash_table_lookup(monitor_qapi_event_state, &key); + evstate =3D g_hash_table_lookup(limiter->state, &key); assert(!evstate || timer_pending(evstate->timer)); =20 if (evstate) { /* - * Timer is pending for (at least) evconf->rate ns after + * Timer is pending for (at least) rate ns after * last send. Store event for sending when timer fires, * replacing a prior stored event if any. */ @@ -570,9 +564,9 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict,= Error **errp) QINCREF(evstate->qdict); } else { /* - * Last send was (at least) evconf->rate ns ago. + * Last send was (at least) rate ns ago. * Send immediately, and arm the timer to call - * monitor_qapi_event_handler() in evconf->rate ns. Any + * monitor_qapi_event_handler() in rate ns. Any * events arriving before then will be delayed until then. */ int64_t now =3D qemu_clock_get_ns(event_clock_type); @@ -580,6 +574,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict,= Error **errp) monitor_qapi_event_emit(event, qdict); =20 evstate =3D g_new(MonitorQAPIEventState, 1); + evstate->limiter =3D limiter; evstate->event =3D event; evstate->data =3D data; QINCREF(evstate->data); @@ -587,44 +582,14 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdic= t, Error **errp) evstate->timer =3D timer_new_ns(event_clock_type, monitor_qapi_event_handler, evstate); - g_hash_table_add(monitor_qapi_event_state, evstate); - timer_mod_ns(evstate->timer, now + evconf->rate); + g_hash_table_add(limiter->state, evstate); + timer_mod_ns(evstate->timer, now + rate); } } =20 qemu_mutex_unlock(&monitor_lock); } =20 -/* - * This function runs evconf->rate ns after sending a throttled - * event. - * If another event has since been stored, send it. - */ -static void monitor_qapi_event_handler(void *opaque) -{ - MonitorQAPIEventState *evstate =3D opaque; - MonitorQAPIEventConf *evconf =3D &monitor_qapi_event_conf[evstate->eve= nt]; - - trace_monitor_protocol_event_handler(evstate->event, evstate->qdict); - qemu_mutex_lock(&monitor_lock); - - if (evstate->qdict) { - int64_t now =3D qemu_clock_get_ns(event_clock_type); - - monitor_qapi_event_emit(evstate->event, evstate->qdict); - QDECREF(evstate->qdict); - evstate->qdict =3D NULL; - timer_mod_ns(evstate->timer, now + evconf->rate); - } else { - g_hash_table_remove(monitor_qapi_event_state, evstate); - QDECREF(evstate->data); - timer_free(evstate->timer); - g_free(evstate); - } - - qemu_mutex_unlock(&monitor_lock); -} - static unsigned int qapi_event_throttle_hash(const void *key) { const MonitorQAPIEventState *evstate =3D key; @@ -663,15 +628,108 @@ static gboolean qapi_event_throttle_equal(const void= *a, const void *b) return TRUE; } =20 +static void +monitor_qapi_event_queue(unsigned event, QDict *qdict, Error **errp) +{ + static MonitorQAPIEventRateLimit limiter =3D { + .size =3D QAPI_EVENT__MAX, + .rate =3D { + /* Limit guest-triggerable events to 1 per second */ + [QAPI_EVENT_RTC_CHANGE] =3D 1000 * SCALE_MS, + [QAPI_EVENT_WATCHDOG] =3D 1000 * SCALE_MS, + [QAPI_EVENT_BALLOON_CHANGE] =3D 1000 * SCALE_MS, + [QAPI_EVENT_QUORUM_REPORT_BAD] =3D 1000 * SCALE_MS, + [QAPI_EVENT_QUORUM_FAILURE] =3D 1000 * SCALE_MS, + [QAPI_EVENT_VSERPORT_CHANGE] =3D 1000 * SCALE_MS, + [QAPI_EVENT__MAX] =3D 0, + }, + }; + + if (!limiter.state) { + limiter.state =3D g_hash_table_new(qapi_event_throttle_hash, + qapi_event_throttle_equal); + } + + monitor_qapi_event_queue_limit(&limiter, event, qdict, errp); +} + +static unsigned int target_qapi_event_throttle_hash(const void *key) +{ + const MonitorQAPIEventState *evstate =3D key; + unsigned int hash =3D evstate->event * 255; + + return hash; +} + +static gboolean target_qapi_event_throttle_equal(const void *a, const void= *b) +{ + const MonitorQAPIEventState *eva =3D a; + const MonitorQAPIEventState *evb =3D b; + + if (eva->event !=3D evb->event) { + return FALSE; + } + + return TRUE; +} + +static void +target_monitor_qapi_event_queue(unsigned event, QDict *qdict, Error **errp) +{ + static MonitorQAPIEventRateLimit limiter =3D { + .size =3D TARGET_QAPI_EVENT__MAX, + .rate =3D { + /* Limit guest-triggerable events to 1 per second */ + [TARGET_QAPI_EVENT__MAX] =3D 0, + }, + }; + + if (!limiter.state) { + limiter.state =3D g_hash_table_new(target_qapi_event_throttle_hash, + target_qapi_event_throttle_equal); + } + monitor_qapi_event_queue_limit(&limiter, event, qdict, errp); +} + +/* + * This function runs evconf->rate ns after sending a throttled + * event. + * If another event has since been stored, send it. + */ +static void monitor_qapi_event_handler(void *opaque) +{ + MonitorQAPIEventState *evstate =3D opaque; + const MonitorQAPIEventRateLimit *limiter =3D evstate->limiter; + int64_t rate =3D limiter->rate[evstate->event]; + + trace_monitor_protocol_event_handler(evstate->event, evstate->qdict); + qemu_mutex_lock(&monitor_lock); + + if (evstate->qdict) { + int64_t now =3D qemu_clock_get_ns(event_clock_type); + + monitor_qapi_event_emit(evstate->event, evstate->qdict); + QDECREF(evstate->qdict); + evstate->qdict =3D NULL; + timer_mod_ns(evstate->timer, now + rate); + } else { + g_hash_table_remove(limiter->state, evstate); + QDECREF(evstate->data); + timer_free(evstate->timer); + g_free(evstate); + } + + qemu_mutex_unlock(&monitor_lock); +} + static void monitor_qapi_event_init(void) { if (qtest_enabled()) { event_clock_type =3D QEMU_CLOCK_VIRTUAL; } =20 - monitor_qapi_event_state =3D g_hash_table_new(qapi_event_throttle_hash, - qapi_event_throttle_equal); qmp_event_set_func_emit(monitor_qapi_event_queue); + target_qmp_event_set_func_emit(target_monitor_qapi_event_queue); } =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); @@ -1039,9 +1097,10 @@ CommandInfoList *qmp_query_commands(Error **errp) return list; } =20 -EventInfoList *qmp_query_events(Error **errp) +static void qmp_query_events_list(EventInfoList **list, + const QEnumLookup *qenum, int max) { - EventInfoList *info, *ev_list =3D NULL; + EventInfoList *info; QAPIEvent e; =20 for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { @@ -1051,11 +1110,22 @@ EventInfoList *qmp_query_events(Error **errp) info->value =3D g_malloc0(sizeof(*info->value)); info->value->name =3D g_strdup(event_name); =20 - info->next =3D ev_list; - ev_list =3D info; + info->next =3D *list; + *list =3D info; } =20 - return ev_list; +} + +EventInfoList *qmp_query_events(Error **errp) +{ + EventInfoList *list =3D NULL; + + qmp_query_events_list(&list, &QAPIEvent_lookup, + QAPI_EVENT__MAX); + qmp_query_events_list(&list, &target_QAPIEvent_lookup, + TARGET_QAPI_EVENT__MAX); + + return list; } =20 /* @@ -1123,6 +1193,7 @@ static void monitor_init_qmp_commands(void) =20 QTAILQ_INIT(&qmp_commands); qmp_init_marshal(&qmp_commands); + target_qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "query-qmp-schema", qmp_query_qmp_schema, diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c index 9d7e88e84a..72fd83841d 100644 --- a/qapi/qmp-event.c +++ b/qapi/qmp-event.c @@ -20,6 +20,7 @@ #include "qapi/qmp/qjson.h" =20 static QMPEventFuncEmit qmp_emit; +static QMPEventFuncEmit target_qmp_emit; =20 void qmp_event_set_func_emit(QMPEventFuncEmit emit) { @@ -31,6 +32,16 @@ QMPEventFuncEmit qmp_event_get_func_emit(void) return qmp_emit; } =20 +void target_qmp_event_set_func_emit(QMPEventFuncEmit emit) +{ + target_qmp_emit =3D emit; +} + +QMPEventFuncEmit target_qmp_event_get_func_emit(void) +{ + return target_qmp_emit; +} + static void timestamp_put(QDict *qdict) { int err; diff --git a/Makefile b/Makefile index 727ef118f3..93a8ff5b78 100644 --- a/Makefile +++ b/Makefile @@ -588,6 +588,7 @@ qapi-modules =3D $(SRC_PATH)/qapi/qapi-schema.json $(SR= C_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/run-state.json \ $(SRC_PATH)/qapi/sockets.json \ + $(SRC_PATH)/qapi/target.json \ $(SRC_PATH)/qapi/tpm.json \ $(SRC_PATH)/qapi/trace.json \ $(SRC_PATH)/qapi/transaction.json \ diff --git a/Makefile.target b/Makefile.target index 0bb18dff9e..9db617cda9 100644 --- a/Makefile.target +++ b/Makefile.target @@ -150,6 +150,8 @@ endif =20 GENERATED_FILES +=3D hmp-commands.h hmp-commands-info.h =20 +obj-y +=3D qapi/target-qapi-types.o qapi/target-qapi-visit.o +obj-y +=3D qapi/target-qapi-events.o qapi/target-qapi-commands.o obj-y +=3D qapi/qapi-introspect.o =20 endif # CONFIG_SOFTMMU --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635211507135.8309786640276; Wed, 21 Mar 2018 05:26:51 -0700 (PDT) Received: from localhost ([::1]:54366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycpJ-000474-Ux for importer@patchew.org; Wed, 21 Mar 2018 08:26:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJl-0006mo-1e for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJh-0000Bq-9z for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42122 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJh-0000BY-4T for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A64E2406DE12 for ; Wed, 21 Mar 2018 11:54:04 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFD7784456; Wed, 21 Mar 2018 11:54:01 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:04 +0100 Message-Id: <20180321115211.17937-43-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:04 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 42/49] qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move rtc-reset-reinjection and SEV in target.json and make them conditional on TARGET_I386. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/misc.json | 166 -------------------------------------- qapi/target.json | 175 ++++++++++++++++++++++++++++++++++++++++- target/i386/sev_i386.h | 2 +- hw/timer/mc146818rtc.c | 2 +- monitor.c | 31 -------- 5 files changed, 175 insertions(+), 201 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 5636f4a149..690eeda41f 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3005,24 +3005,6 @@ { 'event': 'ACPI_DEVICE_OST', 'data': { 'info': 'ACPIOSTInfo' } } =20 -## -# @rtc-reset-reinjection: -# -# This command will reset the RTC interrupt reinjection backlog. -# Can be used if another mechanism to synchronize guest time -# is in effect, for example QEMU guest agent's guest-set-time -# command. -# -# Since: 2.1 -# -# Example: -# -# -> { "execute": "rtc-reset-reinjection" } -# <- { "return": {} } -# -## -{ 'command': 'rtc-reset-reinjection' } - ## # @RTC_CHANGE: # @@ -3247,154 +3229,6 @@ ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } =20 - -## -# @SevState: -# -# An enumeration of SEV state information used during @query-sev. -# -# @uninit: The guest is uninitialized. -# -# @launch-update: The guest is currently being launched; plaintext data and -# register state is being imported. -# -# @launch-secret: The guest is currently being launched; ciphertext data -# is being imported. -# -# @running: The guest is fully launched or migrated in. -# -# @send-update: The guest is currently being migrated out to another machi= ne. -# -# @receive-update: The guest is currently being migrated from another mach= ine. -# -# Since: 2.12 -## -{ 'enum': 'SevState', - 'data': ['uninit', 'launch-update', 'launch-secret', 'running', - 'send-update', 'receive-update' ] } - -## -# @SevInfo: -# -# Information about Secure Encrypted Virtualization (SEV) support -# -# @enabled: true if SEV is active -# -# @api-major: SEV API major version -# -# @api-minor: SEV API minor version -# -# @build-id: SEV FW build id -# -# @policy: SEV policy value -# -# @state: SEV guest state -# -# @handle: SEV firmware handle -# -# Since: 2.12 -## -{ 'struct': 'SevInfo', - 'data': { 'enabled': 'bool', - 'api-major': 'uint8', - 'api-minor' : 'uint8', - 'build-id' : 'uint8', - 'policy' : 'uint32', - 'state' : 'SevState', - 'handle' : 'uint32' - } -} - -## -# @query-sev: -# -# Returns information about SEV -# -# Returns: @SevInfo -# -# Since: 2.12 -# -# Example: -# -# -> { "execute": "query-sev" } -# <- { "return": { "enabled": true, "api-major" : 0, "api-minor" : 0, -# "build-id" : 0, "policy" : 0, "state" : "running", -# "handle" : 1 } } -# -## -{ 'command': 'query-sev', 'returns': 'SevInfo' } - -## -# @SevLaunchMeasureInfo: -# -# SEV Guest Launch measurement information -# -# @data: the measurement value encoded in base64 -# -# Since: 2.12 -# -## -{ 'struct': 'SevLaunchMeasureInfo', 'data': {'data': 'str'} } - -## -# @query-sev-launch-measure: -# -# Query the SEV guest launch information. -# -# Returns: The @SevLaunchMeasureInfo for the guest -# -# Since: 2.12 -# -# Example: -# -# -> { "execute": "query-sev-launch-measure" } -# <- { "return": { "data": "4l8LXeNlSPUDlXPJG5966/8%YZ" } } -# -## -{ 'command': 'query-sev-launch-measure', 'returns': 'SevLaunchMeasureInfo'= } - -## -# @SevCapability: -# -# The struct describes capability for a Secure Encrypted Virtualization -# feature. -# -# @pdh: Platform Diffie-Hellman key (base64 encoded) -# -# @cert-chain: PDH certificate chain (base64 encoded) -# -# @cbitpos: C-bit location in page table entry -# -# @reduced-phys-bits: Number of physical Address bit reduction when SEV is -# enabled -# -# Since: 2.12 -## -{ 'struct': 'SevCapability', - 'data': { 'pdh': 'str', - 'cert-chain': 'str', - 'cbitpos': 'int', - 'reduced-phys-bits': 'int'} } - -## -# @query-sev-capabilities: -# -# This command is used to get the SEV capabilities, and is supported on AMD -# X86 platforms only. -# -# Returns: SevCapability objects. -# -# Since: 2.12 -# -# Example: -# -# -> { "execute": "query-sev-capabilities" } -# <- { "return": { "pdh": "8CCDD8DDD", "cert-chain": "888CCCDDDEE", -# "cbitpos": 47, "reduced-phys-bits": 5}} -# -## -{ 'command': 'query-sev-capabilities', 'returns': 'SevCapability' } - ## # @CommandDropReason: # diff --git a/qapi/target.json b/qapi/target.json index be2360ca34..f277b69a2a 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -8,6 +8,177 @@ { 'pragma': { 'top-unit': 'target' } } =20 ## -# @DUMMY: +# @rtc-reset-reinjection: +# +# This command will reset the RTC interrupt reinjection backlog. +# Can be used if another mechanism to synchronize guest time +# is in effect, for example QEMU guest agent's guest-set-time +# command. +# +# Since: 2.1 +# +# Example: +# +# -> { "execute": "rtc-reset-reinjection" } +# <- { "return": {} } +# +## +{ 'command': 'rtc-reset-reinjection', + 'if': 'defined(TARGET_I386)' } + + +## +# @SevState: +# +# An enumeration of SEV state information used during @query-sev. +# +# @uninit: The guest is uninitialized. +# +# @launch-update: The guest is currently being launched; plaintext data and +# register state is being imported. +# +# @launch-secret: The guest is currently being launched; ciphertext data +# is being imported. +# +# @running: The guest is fully launched or migrated in. +# +# @send-update: The guest is currently being migrated out to another machi= ne. +# +# @receive-update: The guest is currently being migrated from another mach= ine. +# +# Since: 2.12 +## +{ 'enum': 'SevState', + 'data': ['uninit', 'launch-update', 'launch-secret', 'running', + 'send-update', 'receive-update' ], + 'if': 'defined(TARGET_I386)' } + +## +# @SevInfo: +# +# Information about Secure Encrypted Virtualization (SEV) support +# +# @enabled: true if SEV is active +# +# @api-major: SEV API major version +# +# @api-minor: SEV API minor version +# +# @build-id: SEV FW build id +# +# @policy: SEV policy value +# +# @state: SEV guest state +# +# @handle: SEV firmware handle +# +# Since: 2.12 +## +{ 'struct': 'SevInfo', + 'data': { 'enabled': 'bool', + 'api-major': 'uint8', + 'api-minor' : 'uint8', + 'build-id' : 'uint8', + 'policy' : 'uint32', + 'state' : 'SevState', + 'handle' : 'uint32' + }, + 'if': 'defined(TARGET_I386)' +} + +## +# @query-sev: +# +# Returns information about SEV +# +# Returns: @SevInfo +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "query-sev" } +# <- { "return": { "enabled": true, "api-major" : 0, "api-minor" : 0, +# "build-id" : 0, "policy" : 0, "state" : "running", +# "handle" : 1 } } +# +## +{ 'command': 'query-sev', 'returns': 'SevInfo', + 'if': 'defined(TARGET_I386)' } + + +## +# @SevLaunchMeasureInfo: +# +# SEV Guest Launch measurement information +# +# @data: the measurement value encoded in base64 +# +# Since: 2.12 +# +## +{ 'struct': 'SevLaunchMeasureInfo', 'data': {'data': 'str'}, + 'if': 'defined(TARGET_I386)' } + +## +# @query-sev-launch-measure: +# +# Query the SEV guest launch information. +# +# Returns: The @SevLaunchMeasureInfo for the guest +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "query-sev-launch-measure" } +# <- { "return": { "data": "4l8LXeNlSPUDlXPJG5966/8%YZ" } } +# +## +{ 'command': 'query-sev-launch-measure', 'returns': 'SevLaunchMeasureInfo', + 'if': 'defined(TARGET_I386)' } + + +## +# @SevCapability: +# +# The struct describes capability for a Secure Encrypted Virtualization +# feature. +# +# @pdh: Platform Diffie-Hellman key (base64 encoded) +# +# @cert-chain: PDH certificate chain (base64 encoded) +# +# @cbitpos: C-bit location in page table entry +# +# @reduced-phys-bits: Number of physical Address bit reduction when SEV is +# enabled +# +# Since: 2.12 +## +{ 'struct': 'SevCapability', + 'data': { 'pdh': 'str', + 'cert-chain': 'str', + 'cbitpos': 'int', + 'reduced-phys-bits': 'int'}, + 'if': 'defined(TARGET_I386)' } + +## +# @query-sev-capabilities: +# +# This command is used to get the SEV capabilities, and is supported on AMD +# X86 platforms only. +# +# Returns: SevCapability objects. +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "query-sev-capabilities" } +# <- { "return": { "pdh": "8CCDD8DDD", "cert-chain": "888CCCDDDEE", +# "cbitpos": 47, "reduced-phys-bits": 5}} +# ## -{ 'event': 'DUMMY' } +{ 'command': 'query-sev-capabilities', 'returns': 'SevCapability', + 'if': 'defined(TARGET_I386)' } diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index b8622dfb1e..8f88f86952 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -19,7 +19,7 @@ #include "sysemu/kvm.h" #include "sysemu/sev.h" #include "qemu/error-report.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/target-qapi-commands.h" =20 #define SEV_POLICY_NODBG 0x1 #define SEV_POLICY_NOKS 0x2 diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 6f1f723b1f..dd575ffbdf 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -31,7 +31,7 @@ #include "sysemu/replay.h" #include "hw/timer/mc146818rtc.h" #include "qapi/error.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/target-qapi-commands.h" #include "qapi/qapi-events-misc.h" #include "qapi/visitor.h" =20 diff --git a/monitor.c b/monitor.c index 0b96285e94..4ad9225425 100644 --- a/monitor.c +++ b/monitor.c @@ -1157,12 +1157,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObje= ct **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_I386 - qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); - qmp_unregister_command(&qmp_commands, "query-sev"); - qmp_unregister_command(&qmp_commands, "query-sev-launch-measure"); - qmp_unregister_command(&qmp_commands, "query-sev-capabilities"); -#endif #ifndef TARGET_S390X qmp_unregister_command(&qmp_commands, "dump-skeys"); #endif @@ -4709,31 +4703,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_I386 -void qmp_rtc_reset_reinjection(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); -} - -SevInfo *qmp_query_sev(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "query-sev"); - return NULL; -} - -SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "query-sev-launch-measure"); - return NULL; -} - -SevCapability *qmp_query_sev_capabilities(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "query-sev-capabilities"); - return NULL; -} -#endif - #ifndef TARGET_S390X void qmp_dump_skeys(const char *filename, Error **errp) { --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634640019210.7174809551807; Wed, 21 Mar 2018 05:17:20 -0700 (PDT) Received: from localhost ([::1]:54263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyceE-0001K1-3z for importer@patchew.org; Wed, 21 Mar 2018 08:15:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJl-0006ms-GJ for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJj-0000Cn-F5 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42124 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJj-0000Cc-8n for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD8A8406DE12 for ; Wed, 21 Mar 2018 11:54:06 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16812202322F; Wed, 21 Mar 2018 11:54:05 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:05 +0100 Message-Id: <20180321115211.17937-44-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:06 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 43/49] qapi: make s390 commands depend on TARGET_S390X X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Cornelia Huck --- qapi/misc.json | 101 ---------------------- qapi/target.json | 106 ++++++++++++++++++++++++ include/sysemu/arch_init.h | 7 -- hw/s390x/s390-skeys.c | 2 +- monitor.c | 14 ---- qmp.c | 14 ---- stubs/arch-query-cpu-model-baseline.c | 13 --- stubs/arch-query-cpu-model-comparison.c | 13 --- target/s390x/cpu_models.c | 5 +- stubs/Makefile.objs | 2 - 10 files changed, 110 insertions(+), 167 deletions(-) delete mode 100644 stubs/arch-query-cpu-model-baseline.c delete mode 100644 stubs/arch-query-cpu-model-comparison.c diff --git a/qapi/misc.json b/qapi/misc.json index 690eeda41f..1753a81b1e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1821,27 +1821,6 @@ { 'command': 'query-dump-guest-memory-capability', 'returns': 'DumpGuestMemoryCapability' } =20 -## -# @dump-skeys: -# -# Dump guest's storage keys -# -# @filename: the path to the file to dump to -# -# This command is only supported on s390 architecture. -# -# Since: 2.5 -# -# Example: -# -# -> { "execute": "dump-skeys", -# "arguments": { "filename": "/tmp/skeys" } } -# <- { "return": {} } -# -## -{ 'command': 'dump-skeys', - 'data': { 'filename': 'str' } } - ## # @object-add: # @@ -2208,46 +2187,6 @@ } } =20 -## -# @query-cpu-model-comparison: -# -# Compares two CPU models, returning how they compare in a specific -# configuration. The results indicates how both models compare regarding -# runnability. This result can be used by tooling to make decisions if a -# certain CPU model will run in a certain configuration or if a compatible -# CPU model has to be created by baselining. -# -# Usually, a CPU model is compared against the maximum possible CPU model -# of a certain configuration (e.g. the "host" model for KVM). If that CPU -# model is identical or a subset, it will run in that configuration. -# -# The result returned by this command may be affected by: -# -# * QEMU version: CPU models may look different depending on the QEMU vers= ion. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine-type: CPU model may look different depending on the machine-ty= pe. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine options (including accelerator): in some architectures, CPU mo= dels -# may look different depending on machine and accelerator options. (Exce= pt for -# CPU models reported as "static" in query-cpu-definitions.) -# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd -# global properties may affect expansion of CPU models. Using -# query-cpu-model-expansion while using these is not advised. -# -# Some architectures may not support comparing CPU models. s390x supports -# comparing CPU models. -# -# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU model= s is -# not supported, if a model cannot be used, if a model contains -# an unknown cpu definition name, unknown properties or properties -# with wrong types. -# -# Since: 2.8.0 -## -{ 'command': 'query-cpu-model-comparison', - 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, - 'returns': 'CpuModelCompareInfo' } - ## # @CpuModelBaselineInfo: # @@ -2260,46 +2199,6 @@ { 'struct': 'CpuModelBaselineInfo', 'data': { 'model': 'CpuModelInfo' } } =20 -## -# @query-cpu-model-baseline: -# -# Baseline two CPU models, creating a compatible third model. The created -# model will always be a static, migration-safe CPU model (see "static" -# CPU model expansion for details). -# -# This interface can be used by tooling to create a compatible CPU model o= ut -# two CPU models. The created CPU model will be identical to or a subset of -# both CPU models when comparing them. Therefore, the created CPU model is -# guaranteed to run where the given CPU models run. -# -# The result returned by this command may be affected by: -# -# * QEMU version: CPU models may look different depending on the QEMU vers= ion. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine-type: CPU model may look different depending on the machine-ty= pe. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine options (including accelerator): in some architectures, CPU mo= dels -# may look different depending on machine and accelerator options. (Exce= pt for -# CPU models reported as "static" in query-cpu-definitions.) -# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd -# global properties may affect expansion of CPU models. Using -# query-cpu-model-expansion while using these is not advised. -# -# Some architectures may not support baselining CPU models. s390x supports -# baselining CPU models. -# -# Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU mode= ls is -# not supported, if a model cannot be used, if a model contains -# an unknown cpu definition name, unknown properties or properties -# with wrong types. -# -# Since: 2.8.0 -## -{ 'command': 'query-cpu-model-baseline', - 'data': { 'modela': 'CpuModelInfo', - 'modelb': 'CpuModelInfo' }, - 'returns': 'CpuModelBaselineInfo' } - ## # @AddfdInfo: # diff --git a/qapi/target.json b/qapi/target.json index f277b69a2a..b07a8926d8 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -7,6 +7,8 @@ =20 { 'pragma': { 'top-unit': 'target' } } =20 +{ 'include': 'misc.json' } + ## # @rtc-reset-reinjection: # @@ -182,3 +184,107 @@ ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability', 'if': 'defined(TARGET_I386)' } + +## +# @dump-skeys: +# +# Dump guest's storage keys +# +# @filename: the path to the file to dump to +# +# This command is only supported on s390 architecture. +# +# Since: 2.5 +# +# Example: +# +# -> { "execute": "dump-skeys", +# "arguments": { "filename": "/tmp/skeys" } } +# <- { "return": {} } +# +## +{ 'command': 'dump-skeys', + 'data': { 'filename': 'str' }, + 'if': 'defined(TARGET_S390X)' } + +## +# @query-cpu-model-comparison: +# +# Compares two CPU models, returning how they compare in a specific +# configuration. The results indicates how both models compare regarding +# runnability. This result can be used by tooling to make decisions if a +# certain CPU model will run in a certain configuration or if a compatible +# CPU model has to be created by baselining. +# +# Usually, a CPU model is compared against the maximum possible CPU model +# of a certain configuration (e.g. the "host" model for KVM). If that CPU +# model is identical or a subset, it will run in that configuration. +# +# The result returned by this command may be affected by: +# +# * QEMU version: CPU models may look different depending on the QEMU vers= ion. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine-type: CPU model may look different depending on the machine-ty= pe. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine options (including accelerator): in some architectures, CPU mo= dels +# may look different depending on machine and accelerator options. (Exce= pt for +# CPU models reported as "static" in query-cpu-definitions.) +# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd +# global properties may affect expansion of CPU models. Using +# query-cpu-model-expansion while using these is not advised. +# +# Some architectures may not support comparing CPU models. s390x supports +# comparing CPU models. +# +# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU model= s is +# not supported, if a model cannot be used, if a model contains +# an unknown cpu definition name, unknown properties or properties +# with wrong types. +# +# Since: 2.8.0 +## +{ 'command': 'query-cpu-model-comparison', + 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, + 'returns': 'CpuModelCompareInfo', + 'if': 'defined(TARGET_S390X)' } + +## +# @query-cpu-model-baseline: +# +# Baseline two CPU models, creating a compatible third model. The created +# model will always be a static, migration-safe CPU model (see "static" +# CPU model expansion for details). +# +# This interface can be used by tooling to create a compatible CPU model o= ut +# two CPU models. The created CPU model will be identical to or a subset of +# both CPU models when comparing them. Therefore, the created CPU model is +# guaranteed to run where the given CPU models run. +# +# The result returned by this command may be affected by: +# +# * QEMU version: CPU models may look different depending on the QEMU vers= ion. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine-type: CPU model may look different depending on the machine-ty= pe. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine options (including accelerator): in some architectures, CPU mo= dels +# may look different depending on machine and accelerator options. (Exce= pt for +# CPU models reported as "static" in query-cpu-definitions.) +# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd +# global properties may affect expansion of CPU models. Using +# query-cpu-model-expansion while using these is not advised. +# +# Some architectures may not support baselining CPU models. s390x supports +# baselining CPU models. +# +# Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU mode= ls is +# not supported, if a model cannot be used, if a model contains +# an unknown cpu definition name, unknown properties or properties +# with wrong types. +# +# Since: 2.8.0 +## +{ 'command': 'query-cpu-model-baseline', + 'data': { 'modela': 'CpuModelInfo', + 'modelb': 'CpuModelInfo' }, + 'returns': 'CpuModelBaselineInfo', + 'if': 'defined(TARGET_S390X)' } diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 32abdfe6a1..f0ef652b2a 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -36,11 +36,4 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error = **errp); CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, CpuModelInfo *mode, Error **errp); -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp); -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp); - #endif diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 76241c240e..59d28c2358 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -13,7 +13,7 @@ #include "hw/boards.h" #include "hw/s390x/storage-keys.h" #include "qapi/error.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/target-qapi-commands.h" #include "qapi/qmp/qdict.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" diff --git a/monitor.c b/monitor.c index 4ad9225425..bd9a6950cf 100644 --- a/monitor.c +++ b/monitor.c @@ -1157,19 +1157,12 @@ static void qmp_query_qmp_schema(QDict *qdict, QObj= ect **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_S390X - qmp_unregister_command(&qmp_commands, "dump-skeys"); -#endif #ifndef TARGET_ARM qmp_unregister_command(&qmp_commands, "query-gic-capabilities"); #endif #if !defined(TARGET_S390X) && !defined(TARGET_I386) qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); #endif -#if !defined(TARGET_S390X) - qmp_unregister_command(&qmp_commands, "query-cpu-model-baseline"); - qmp_unregister_command(&qmp_commands, "query-cpu-model-comparison"); -#endif #if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); @@ -4703,13 +4696,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_S390X -void qmp_dump_skeys(const char *filename, Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "dump-skeys"); -} -#endif - #ifndef TARGET_ARM GICCapabilityList *qmp_query_gic_capabilities(Error **errp) { diff --git a/qmp.c b/qmp.c index d8f80cb04e..14972b78df 100644 --- a/qmp.c +++ b/qmp.c @@ -601,20 +601,6 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, return arch_query_cpu_model_expansion(type, model, errp); } =20 -CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - return arch_query_cpu_model_comparison(modela, modelb, errp); -} - -CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - return arch_query_cpu_model_baseline(modela, modelb, errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-model-baseline.c b/stubs/arch-query-cpu-m= odel-baseline.c deleted file mode 100644 index 0d066da328..0000000000 --- a/stubs/arch-query-cpu-model-baseline.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/error.h" -#include "qapi/qmp/qerror.h" - -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/stubs/arch-query-cpu-model-comparison.c b/stubs/arch-query-cpu= -model-comparison.c deleted file mode 100644 index 8eb311a26c..0000000000 --- a/stubs/arch-query-cpu-model-comparison.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/error.h" -#include "qapi/qmp/qerror.h" - -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 2741b6803f..ffca1d9a2d 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -25,6 +25,7 @@ #include "sysemu/arch_init.h" #include "hw/pci/pci.h" #endif +#include "qapi/target-qapi-commands.h" =20 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \ { \ @@ -597,7 +598,7 @@ static void list_add_feat(const char *name, void *opaqu= e) *last =3D entry; } =20 -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa, +CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *infoa, CpuModelInfo *infob, Error **errp) { @@ -670,7 +671,7 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(Cp= uModelInfo *infoa, return compare_info; } =20 -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa, +CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *infoa, CpuModelInfo *infob, Error **errp) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 2d59d84091..9a91e49578 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,7 +1,5 @@ stub-obj-y +=3D arch-query-cpu-def.o stub-obj-y +=3D arch-query-cpu-model-expansion.o -stub-obj-y +=3D arch-query-cpu-model-comparison.o -stub-obj-y +=3D arch-query-cpu-model-baseline.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635188568612.5616133886015; Wed, 21 Mar 2018 05:26:28 -0700 (PDT) Received: from localhost ([::1]:54363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycp0-0003pL-UU for importer@patchew.org; Wed, 21 Mar 2018 08:26:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJl-0006mx-Qx for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJl-0000Dc-2t for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42126 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJk-0000DJ-Us for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7773F406DE12 for ; Wed, 21 Mar 2018 11:54:08 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18D51215CDB7; Wed, 21 Mar 2018 11:54:07 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:06 +0100 Message-Id: <20180321115211.17937-45-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:08 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 44/49] target.json: add a note about query-cpu* not being s390x-specific X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Cornelia Huck --- qapi/target.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qapi/target.json b/qapi/target.json index b07a8926d8..be0ff84a6e 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -241,6 +241,9 @@ # an unknown cpu definition name, unknown properties or properties # with wrong types. # +# Note: this command isn't specific to s390x, but is only implemented +# on this architecture currently. +# # Since: 2.8.0 ## { 'command': 'query-cpu-model-comparison', @@ -281,6 +284,9 @@ # an unknown cpu definition name, unknown properties or properties # with wrong types. # +# Note: this command isn't specific to s390x, but is only implemented +# on this architecture currently. +# # Since: 2.8.0 ## { 'command': 'query-cpu-model-baseline', --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635364942994.944424154413; Wed, 21 Mar 2018 05:29:24 -0700 (PDT) Received: from localhost ([::1]:54378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycrr-00072A-E5 for importer@patchew.org; Wed, 21 Mar 2018 08:29:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJo-0006rO-6l for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJm-0000El-Vg for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42128 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJm-0000EX-Rv for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E309406DE12 for ; Wed, 21 Mar 2018 11:54:10 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6B552166BDA; Wed, 21 Mar 2018 11:54:09 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:07 +0100 Message-Id: <20180321115211.17937-46-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:10 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 45/49] qapi: make query-gic-capabilities depend on TARGET_ARM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/misc.json | 43 ------------------------------------------ qapi/target.json | 45 ++++++++++++++++++++++++++++++++++++++++++++ monitor.c | 11 ----------- target/arm/monitor.c | 2 +- 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 1753a81b1e..a0032120da 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2965,49 +2965,6 @@ ## { 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} } =20 -## -# @GICCapability: -# -# The struct describes capability for a specific GIC (Generic -# Interrupt Controller) version. These bits are not only decided by -# QEMU/KVM software version, but also decided by the hardware that -# the program is running upon. -# -# @version: version of GIC to be described. Currently, only 2 and 3 -# are supported. -# -# @emulated: whether current QEMU/hardware supports emulated GIC -# device in user space. -# -# @kernel: whether current QEMU/hardware supports hardware -# accelerated GIC device in kernel. -# -# Since: 2.6 -## -{ 'struct': 'GICCapability', - 'data': { 'version': 'int', - 'emulated': 'bool', - 'kernel': 'bool' } } - -## -# @query-gic-capabilities: -# -# This command is ARM-only. It will return a list of GICCapability -# objects that describe its capability bits. -# -# Returns: a list of GICCapability objects. -# -# Since: 2.6 -# -# Example: -# -# -> { "execute": "query-gic-capabilities" } -# <- { "return": [{ "version": 2, "emulated": true, "kernel": false }, -# { "version": 3, "emulated": false, "kernel": true } ] } -# -## -{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] } - ## # @CpuInstanceProperties: # diff --git a/qapi/target.json b/qapi/target.json index be0ff84a6e..2ab18b38a9 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -294,3 +294,48 @@ 'modelb': 'CpuModelInfo' }, 'returns': 'CpuModelBaselineInfo', 'if': 'defined(TARGET_S390X)' } + +## +# @GICCapability: +# +# The struct describes capability for a specific GIC (Generic +# Interrupt Controller) version. These bits are not only decided by +# QEMU/KVM software version, but also decided by the hardware that +# the program is running upon. +# +# @version: version of GIC to be described. Currently, only 2 and 3 +# are supported. +# +# @emulated: whether current QEMU/hardware supports emulated GIC +# device in user space. +# +# @kernel: whether current QEMU/hardware supports hardware +# accelerated GIC device in kernel. +# +# Since: 2.6 +## +{ 'struct': 'GICCapability', + 'data': { 'version': 'int', + 'emulated': 'bool', + 'kernel': 'bool' }, + 'if': 'defined(TARGET_ARM)' } + +## +# @query-gic-capabilities: +# +# This command is ARM-only. It will return a list of GICCapability +# objects that describe its capability bits. +# +# Returns: a list of GICCapability objects. +# +# Since: 2.6 +# +# Example: +# +# -> { "execute": "query-gic-capabilities" } +# <- { "return": [{ "version": 2, "emulated": true, "kernel": false }, +# { "version": 3, "emulated": false, "kernel": true } ] } +# +## +{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], + 'if': 'defined(TARGET_ARM)' } diff --git a/monitor.c b/monitor.c index bd9a6950cf..67b433f12d 100644 --- a/monitor.c +++ b/monitor.c @@ -1157,9 +1157,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObjec= t **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_ARM - qmp_unregister_command(&qmp_commands, "query-gic-capabilities"); -#endif #if !defined(TARGET_S390X) && !defined(TARGET_I386) qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); #endif @@ -4696,14 +4693,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_ARM -GICCapabilityList *qmp_query_gic_capabilities(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "query-gic-capabilities"); - return NULL; -} -#endif - HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) { MachineState *ms =3D MACHINE(qdev_get_machine()); diff --git a/target/arm/monitor.c b/target/arm/monitor.c index 4cdd2676dd..250405bf4d 100644 --- a/target/arm/monitor.c +++ b/target/arm/monitor.c @@ -23,7 +23,7 @@ #include "qemu/osdep.h" #include "hw/boards.h" #include "kvm_arm.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/target-qapi-commands.h" =20 static GICCapability *gic_cap_new(int version) { --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635881310217.7711496490856; Wed, 21 Mar 2018 05:38:01 -0700 (PDT) Received: from localhost ([::1]:54519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyd0C-0006i8-ER for importer@patchew.org; Wed, 21 Mar 2018 08:38:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJq-0006tr-Bm for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJp-0000HI-0I for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34964 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJo-0000GK-SA for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 701117705E for ; Wed, 21 Mar 2018 11:54:12 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED1CC2022C08; Wed, 21 Mar 2018 11:54:11 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:08 +0100 Message-Id: <20180321115211.17937-47-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:54:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 21 Mar 2018 11:54:12 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 46/49] qapi: make query-cpu-model-expansion depend on s390 or x86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eduardo Habkost Acked-by: Cornelia Huck --- qapi/misc.json | 38 ------------------------- qapi/target.json | 39 ++++++++++++++++++++++++++ include/sysemu/arch_init.h | 3 -- monitor.c | 3 -- qmp.c | 7 ----- stubs/arch-query-cpu-model-expansion.c | 13 --------- target/i386/cpu.c | 3 +- target/s390x/cpu_models.c | 2 +- stubs/Makefile.objs | 1 - 9 files changed, 42 insertions(+), 67 deletions(-) delete mode 100644 stubs/arch-query-cpu-model-expansion.c diff --git a/qapi/misc.json b/qapi/misc.json index a0032120da..602c99b174 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2102,44 +2102,6 @@ 'data': { 'model': 'CpuModelInfo' } } =20 =20 -## -# @query-cpu-model-expansion: -# -# Expands a given CPU model (or a combination of CPU model + additional op= tions) -# to different granularities, allowing tooling to get an understanding wha= t a -# specific CPU model looks like in QEMU under a certain configuration. -# -# This interface can be used to query the "host" CPU model. -# -# The data returned by this command may be affected by: -# -# * QEMU version: CPU models may look different depending on the QEMU vers= ion. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine-type: CPU model may look different depending on the machine-t= ype. -# (Except for CPU models reported as "static" in query-cpu-definitions.) -# * machine options (including accelerator): in some architectures, CPU mo= dels -# may look different depending on machine and accelerator options. (Exce= pt for -# CPU models reported as "static" in query-cpu-definitions.) -# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd -# global properties may affect expansion of CPU models. Using -# query-cpu-model-expansion while using these is not advised. -# -# Some architectures may not support all expansion types. s390x supports -# "full" and "static". -# -# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU mode= ls is -# not supported, if the model cannot be expanded, if the model co= ntains -# an unknown CPU definition name, unknown properties or properties -# with a wrong type. Also returns an error if an expansion type is -# not supported. -# -# Since: 2.8.0 -## -{ 'command': 'query-cpu-model-expansion', - 'data': { 'type': 'CpuModelExpansionType', - 'model': 'CpuModelInfo' }, - 'returns': 'CpuModelExpansionInfo' } - ## # @CpuModelCompareResult: # diff --git a/qapi/target.json b/qapi/target.json index 2ab18b38a9..323994a6ec 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -339,3 +339,42 @@ ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], 'if': 'defined(TARGET_ARM)' } + +## +# @query-cpu-model-expansion: +# +# Expands a given CPU model (or a combination of CPU model + additional op= tions) +# to different granularities, allowing tooling to get an understanding wha= t a +# specific CPU model looks like in QEMU under a certain configuration. +# +# This interface can be used to query the "host" CPU model. +# +# The data returned by this command may be affected by: +# +# * QEMU version: CPU models may look different depending on the QEMU vers= ion. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine-type: CPU model may look different depending on the machine-t= ype. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine options (including accelerator): in some architectures, CPU mo= dels +# may look different depending on machine and accelerator options. (Exce= pt for +# CPU models reported as "static" in query-cpu-definitions.) +# * "-cpu" arguments and global properties: arguments to the -cpu option a= nd +# global properties may affect expansion of CPU models. Using +# query-cpu-model-expansion while using these is not advised. +# +# Some architectures may not support all expansion types. s390x supports +# "full" and "static". +# +# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU mode= ls is +# not supported, if the model cannot be expanded, if the model co= ntains +# an unknown CPU definition name, unknown properties or properties +# with a wrong type. Also returns an error if an expansion type is +# not supported. +# +# Since: 2.8.0 +## +{ 'command': 'query-cpu-model-expansion', + 'data': { 'type': 'CpuModelExpansionType', + 'model': 'CpuModelInfo' }, + 'returns': 'CpuModelExpansionInfo', + 'if': 'defined(TARGET_S390X) || defined(TARGET_I386)' } diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index f0ef652b2a..2497fd3351 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -33,7 +33,4 @@ int kvm_available(void); int xen_available(void); =20 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp); -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, - CpuModelInfo *mode, - Error **errp); #endif diff --git a/monitor.c b/monitor.c index 67b433f12d..63c51ee05d 100644 --- a/monitor.c +++ b/monitor.c @@ -1157,9 +1157,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObjec= t **ret_data, */ static void qmp_unregister_commands_hack(void) { -#if !defined(TARGET_S390X) && !defined(TARGET_I386) - qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); -#endif #if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); diff --git a/qmp.c b/qmp.c index 14972b78df..9ded2f48c4 100644 --- a/qmp.c +++ b/qmp.c @@ -594,13 +594,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error= **errp) return arch_query_cpu_definitions(errp); } =20 -CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType= type, - CpuModelInfo *model, - Error **errp) -{ - return arch_query_cpu_model_expansion(type, model, errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-model-expansion.c b/stubs/arch-query-cpu-= model-expansion.c deleted file mode 100644 index 26273a8b10..0000000000 --- a/stubs/arch-query-cpu-model-expansion.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/error.h" -#include "qapi/qmp/qerror.h" - -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, - CpuModelInfo *mode, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 555ae79d29..563dad644c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -39,6 +39,7 @@ #include "qapi/visitor.h" #include "qom/qom-qobject.h" #include "sysemu/arch_init.h" +#include "qapi/target-qapi-commands.h" =20 #if defined(CONFIG_KVM) #include @@ -3125,7 +3126,7 @@ out: } =20 CpuModelExpansionInfo * -arch_query_cpu_model_expansion(CpuModelExpansionType type, +qmp_query_cpu_model_expansion(CpuModelExpansionType type, CpuModelInfo *model, Error **errp) { diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index ffca1d9a2d..e25034231d 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -559,7 +559,7 @@ static void cpu_info_from_model(CpuModelInfo *info, con= st S390CPUModel *model, } } =20 -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType= type, CpuModelInfo *model, Error **errp) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 9a91e49578..1cd325841c 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,5 +1,4 @@ stub-obj-y +=3D arch-query-cpu-def.o -stub-obj-y +=3D arch-query-cpu-model-expansion.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635352422749.6679201703553; Wed, 21 Mar 2018 05:29:12 -0700 (PDT) Received: from localhost ([::1]:54376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycrX-0006Hh-Uf for importer@patchew.org; Wed, 21 Mar 2018 08:29:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJt-0006xS-Qj for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJr-0000J5-Ah for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51884 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJr-0000Ip-4t for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1EB340267D7 for ; Wed, 21 Mar 2018 11:54:14 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 059A38445E; Wed, 21 Mar 2018 11:54:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:09 +0100 Message-Id: <20180321115211.17937-48-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:54:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:54:14 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 47/49] qapi: make query-cpu-definitions depend on specific targets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It depends on TARGET_PPC || TARGET_ARM || TARGET_I386 || TARGET_S390X. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eduardo Habkost Acked-by: Cornelia Huck --- qapi/misc.json | 10 ---------- qapi/target.json | 12 ++++++++++++ include/sysemu/arch_init.h | 1 - monitor.c | 22 ---------------------- qmp.c | 5 ----- stubs/arch-query-cpu-def.c | 11 ----------- target/arm/helper.c | 3 ++- target/i386/cpu.c | 3 ++- target/ppc/translate_init.c | 3 ++- target/s390x/cpu_models.c | 2 +- stubs/Makefile.objs | 1 - 11 files changed, 19 insertions(+), 54 deletions(-) delete mode 100644 stubs/arch-query-cpu-def.c diff --git a/qapi/misc.json b/qapi/misc.json index 602c99b174..e9538ecae6 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2027,16 +2027,6 @@ ## { 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' } =20 -## -# @query-cpu-definitions: -# -# Return a list of supported virtual CPU definitions -# -# Returns: a list of CpuDefInfo -# -# Since: 1.2.0 -## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] } =20 ## # @CpuModelInfo: diff --git a/qapi/target.json b/qapi/target.json index 323994a6ec..89ba4207b1 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -378,3 +378,15 @@ 'model': 'CpuModelInfo' }, 'returns': 'CpuModelExpansionInfo', 'if': 'defined(TARGET_S390X) || defined(TARGET_I386)' } + +## +# @query-cpu-definitions: +# +# Return a list of supported virtual CPU definitions +# +# Returns: a list of CpuDefInfo +# +# Since: 1.2.0 +## +{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], + 'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386= ) || defined(TARGET_S390X)' } diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 2497fd3351..10cbafe970 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -32,5 +32,4 @@ extern const uint32_t arch_type; int kvm_available(void); int xen_available(void); =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp); #endif diff --git a/monitor.c b/monitor.c index 63c51ee05d..377ea3c98b 100644 --- a/monitor.c +++ b/monitor.c @@ -1143,26 +1143,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObje= ct **ret_data, *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); } =20 -/* - * We used to define commands in qmp-commands.hx in addition to the - * QAPI schema. This permitted defining some of them only in certain - * configurations. query-commands has always reflected that (good, - * because it lets QMP clients figure out what's actually available), - * while query-qmp-schema never did (not so good). This function is a - * hack to keep the configuration-specific commands defined exactly as - * before, even though qmp-commands.hx is gone. - * - * FIXME Educate the QAPI schema on configuration-specific commands, - * and drop this hack. - */ -static void qmp_unregister_commands_hack(void) -{ -#if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ - && !defined(TARGET_S390X) - qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); -#endif -} - static void monitor_init_qmp_commands(void) { /* @@ -1184,8 +1164,6 @@ static void monitor_init_qmp_commands(void) qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, QCO_NO_OPTIONS); =20 - qmp_unregister_commands_hack(); - QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", qmp_marshal_qmp_capabilities, QCO_NO_OPTIONS); diff --git a/qmp.c b/qmp.c index 9ded2f48c4..cafda4417d 100644 --- a/qmp.c +++ b/qmp.c @@ -589,11 +589,6 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const = char *typename, return prop_list; } =20 -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) -{ - return arch_query_cpu_definitions(errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-def.c b/stubs/arch-query-cpu-def.c deleted file mode 100644 index d436f95314..0000000000 --- a/stubs/arch-query-cpu-def.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/error.h" -#include "qapi/qmp/qerror.h" - -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/arm/helper.c b/target/arm/helper.c index 09893e3f72..ab8520f07d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -17,6 +17,7 @@ #include "exec/semihost.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" +#include "qapi/target-qapi-commands.h" =20 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ =20 @@ -5549,7 +5550,7 @@ static void arm_cpu_add_definition(gpointer data, gpo= inter user_data) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 563dad644c..62c0c5b1eb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qapi/qapi-visit-misc.h" #include "qapi/qapi-visit-run-state.h" +#include "qapi/target-qapi-commands.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/visitor.h" @@ -2865,7 +2866,7 @@ static void x86_cpu_definition_entry(gpointer data, g= pointer user_data) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list =3D get_sorted_cpu_model_list(); diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 391b94b97d..e679e8d301 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -39,6 +39,7 @@ #include "qemu/cutils.h" #include "disas/capstone.h" #include "fpu/softfloat.h" +#include "qapi/target-qapi-commands.h" =20 //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR @@ -10298,7 +10299,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpoin= ter user_data) *first =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index e25034231d..c9b5216284 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -425,7 +425,7 @@ static void create_cpu_model_list(ObjectClass *klass, v= oid *opaque) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { struct CpuDefinitionInfoListData list_data =3D { .list =3D NULL, diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 1cd325841c..54f3e7e152 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,4 +1,3 @@ -stub-obj-y +=3D arch-query-cpu-def.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521635527548865.6612463728088; Wed, 21 Mar 2018 05:32:07 -0700 (PDT) Received: from localhost ([::1]:54422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycuQ-0000t5-Lk for importer@patchew.org; Wed, 21 Mar 2018 08:32:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycJw-0006zo-Ax for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJv-0000LB-E5 for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51888 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJv-0000Kz-9X for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C597240267D7 for ; Wed, 21 Mar 2018 11:54:18 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8D0210B0094; Wed, 21 Mar 2018 11:54:15 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:10 +0100 Message-Id: <20180321115211.17937-49-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:54:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Mar 2018 11:54:18 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 48/49] qapi: remove qmp_unregister_command() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This command is no longer needed after the schema is made conditional. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/qmp/dispatch.h | 1 - qapi/qmp-registry.c | 8 -------- 2 files changed, 9 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index ffb4652f71..dba9ee70b3 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -38,7 +38,6 @@ typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpComman= dList; =20 void qmp_register_command(QmpCommandList *cmds, const char *name, QmpCommandFunc *fn, QmpCommandOptions options); -void qmp_unregister_command(QmpCommandList *cmds, const char *name); QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name); QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request); void qmp_disable_command(QmpCommandList *cmds, const char *name); diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 5af484cd9a..ca00f74795 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -27,14 +27,6 @@ void qmp_register_command(QmpCommandList *cmds, const ch= ar *name, QTAILQ_INSERT_TAIL(cmds, cmd, node); } =20 -void qmp_unregister_command(QmpCommandList *cmds, const char *name) -{ - QmpCommand *cmd =3D qmp_find_command(cmds, name); - - QTAILQ_REMOVE(cmds, cmd, node); - g_free(cmd); -} - QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name) { QmpCommand *cmd; --=20 2.16.2.521.g9aa15f885a From nobody Wed May 1 16:39:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521634717506330.7937676776447; Wed, 21 Mar 2018 05:18:37 -0700 (PDT) Received: from localhost ([::1]:54283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eychQ-000429-8y for importer@patchew.org; Wed, 21 Mar 2018 08:18:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycK3-00074U-Ft for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eycJz-0000NY-LW for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42134 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eycJz-0000NF-FX for qemu-devel@nongnu.org; Wed, 21 Mar 2018 07:54:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 074D9406DE12 for ; Wed, 21 Mar 2018 11:54:23 +0000 (UTC) Received: from localhost (ovpn-112-73.ams2.redhat.com [10.36.112.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20D5E50331; Wed, 21 Mar 2018 11:54:20 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 12:52:11 +0100 Message-Id: <20180321115211.17937-50-marcandre.lureau@redhat.com> In-Reply-To: <20180321115211.17937-1-marcandre.lureau@redhat.com> References: <20180321115211.17937-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 21 Mar 2018 11:54:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 49/49] RFC: make RTC_CHANGE per-target X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A few targets don't emit RTC_CHANGE, we could restrict the event to the tagets that do emit it. Note: There is a lot more of events & commands that we could restrict to capable targets, with the cost of some additional complexity, but the benefit of added correctness and better introspection. Note2: The rate limite could perhaps be part of the schema, and the common event emitter code, to simplify the need of custom and #ifdef code in the monitor. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/misc.json | 22 ---------------------- qapi/target.json | 23 +++++++++++++++++++++++ hw/ppc/spapr_rtc.c | 2 +- hw/timer/mc146818rtc.c | 2 +- monitor.c | 4 +++- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index e9538ecae6..6415bbb7fe 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2856,28 +2856,6 @@ { 'event': 'ACPI_DEVICE_OST', 'data': { 'info': 'ACPIOSTInfo' } } =20 -## -# @RTC_CHANGE: -# -# Emitted when the guest changes the RTC time. -# -# @offset: offset between base RTC clock (as specified by -rtc base), and -# new RTC clock value -# -# Note: This event is rate-limited. -# -# Since: 0.13.0 -# -# Example: -# -# <- { "event": "RTC_CHANGE", -# "data": { "offset": 78 }, -# "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } -# -## -{ 'event': 'RTC_CHANGE', - 'data': { 'offset': 'int' } } - ## # @ReplayMode: # diff --git a/qapi/target.json b/qapi/target.json index 89ba4207b1..b9f6741fbf 100644 --- a/qapi/target.json +++ b/qapi/target.json @@ -9,6 +9,29 @@ =20 { 'include': 'misc.json' } =20 +## +# @RTC_CHANGE: +# +# Emitted when the guest changes the RTC time. +# +# @offset: offset between base RTC clock (as specified by -rtc base), and +# new RTC clock value +# +# Note: This event is rate-limited. +# +# Since: 0.13.0 +# +# Example: +# +# <- { "event": "RTC_CHANGE", +# "data": { "offset": 78 }, +# "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } +# +## +{ 'event': 'RTC_CHANGE', + 'data': { 'offset': 'int' }, + 'if': 'defined(TARGET_ALPHA) || defined(TARGET_ARM) || defined(TARGET_HP= PA) || defined(TARGET_I386) || defined(TARGET_MIPS) || defined(TARGET_MIPS6= 4) || defined(TARGET_MOXIE) || defined(TARGET_PPC) || defined(TARGET_PPC64)= || defined(TARGET_S390X) || defined(TARGET_SH4) || defined(TARGET_SPARC)' } + ## # @rtc-reset-reinjection: # diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c index a37360537e..4cb73abf4a 100644 --- a/hw/ppc/spapr_rtc.c +++ b/hw/ppc/spapr_rtc.c @@ -31,7 +31,7 @@ #include "sysemu/sysemu.h" #include "hw/ppc/spapr.h" #include "qapi/error.h" -#include "qapi/qapi-events-misc.h" +#include "qapi/target-qapi-events.h" #include "qemu/cutils.h" =20 void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index dd575ffbdf..7de7562850 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -32,7 +32,7 @@ #include "hw/timer/mc146818rtc.h" #include "qapi/error.h" #include "qapi/target-qapi-commands.h" -#include "qapi/qapi-events-misc.h" +#include "qapi/target-qapi-events.h" #include "qapi/visitor.h" =20 #ifdef TARGET_I386 diff --git a/monitor.c b/monitor.c index 377ea3c98b..3c972206d9 100644 --- a/monitor.c +++ b/monitor.c @@ -635,7 +635,6 @@ monitor_qapi_event_queue(unsigned event, QDict *qdict, = Error **errp) .size =3D QAPI_EVENT__MAX, .rate =3D { /* Limit guest-triggerable events to 1 per second */ - [QAPI_EVENT_RTC_CHANGE] =3D 1000 * SCALE_MS, [QAPI_EVENT_WATCHDOG] =3D 1000 * SCALE_MS, [QAPI_EVENT_BALLOON_CHANGE] =3D 1000 * SCALE_MS, [QAPI_EVENT_QUORUM_REPORT_BAD] =3D 1000 * SCALE_MS, @@ -680,6 +679,9 @@ target_monitor_qapi_event_queue(unsigned event, QDict *= qdict, Error **errp) .size =3D TARGET_QAPI_EVENT__MAX, .rate =3D { /* Limit guest-triggerable events to 1 per second */ +#if defined(TARGET_ALPHA) || defined(TARGET_ARM) || defined(TARGET_HPPA) |= | defined(TARGET_I386) || defined(TARGET_MIPS) | defined(TARGET_MIPS64) || = defined(TARGET_MOXIE) || defined(TARGET_PPC) || defined(TARGET_PPC64) || de= fined(TARGET_S390X) || defined(TARGET_SH4) || defined(TARGET_SPARC) + [TARGET_QAPI_EVENT_RTC_CHANGE] =3D 1000 * SCALE_MS, +#endif [TARGET_QAPI_EVENT__MAX] =3D 0, }, }; --=20 2.16.2.521.g9aa15f885a