Skip to contentSkip to conversation

qapi: add #if pre-processor conditions to generated code (part 3)

PATCH Superseded Markus Armbruster 5 participants 36 messages Feb 6, 2019 – Feb 8, 2019 Kbuild

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover qapi: add #if pre-processor conditions to generated code (part 3)

Marc-André posted a v1 that relies on a QAPI schema language extension 'top-unit' to permit splitting the generated code. Here is his cover letter:

The thrid and last part (of "[PATCH v2 00/54] qapi: add #if pre-processor conditions to generated code") is about adding schema conditions based on the target.

For now, the qapi code is compiled in common objects (common to all targets). This makes it impossible to add #if TARGET_ARM for example.

The patch "RFC: qapi: learn to split the schema by 'top-unit'" proposes to split the schema by "top-unit", so that generated code can be built either in common objects or per-target. That patch is a bit rough, I would like to get some feedback about the approach before trying to improve it. The following patches demonstrate usage of target-based #if conditions, and getting rid of the qmp_unregister_command() hack.

We already have a way to split generated code: QAPI modules. I took the liberty to rework Marc-André's series to use a target module instead. Less code, no change to the QAPI language.

v3:
* PATCH v2 01+02 have been merged
* PATCH 01-04: New
* PATCH 05: Rebase of PATCH v2 03
* PATCH 06-17: Trivially rebased, R-by and such retained

Marc-André Lureau (9):
build-sys: move qmp-introspect per target
qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386
qapi: make s390 commands depend on TARGET_S390X target.json: add a note about query-cpu* not being s390x-specific
qapi: make query-gic-capabilities depend on TARGET_ARM
qapi: make query-cpu-model-expansion depend on s390 or x86
qapi: make query-cpu-definitions depend on specific targets
qapi: remove qmp_unregister_command()
qapi: move RTC_CHANGE to the target schema

Markus Armbruster (8):
qapi: Belatedly document modular code generation
qapi: Fix up documentation for recent commit a95291007b2
qapi: Clean up modular built-in code generation a bit
qapi: Prepare for system modules other than 'builtin'
qapi: Generate QAPIEvent stuff into separate files
qapi: New module target.json
Revert "qapi-events: add 'if' condition to implicit event enum"
qmp: Deprecate query-events in favor of query-qmp-schema

 .gitignore                               |   1 +
 Makefile                                 |   1 +
 Makefile.objs                            |  23 +-
 Makefile.target                          |  12 +
 docs/devel/qapi-code-gen.txt             |  82 +++-
 hw/ppc/spapr_rtc.c                       |   2 +-
 hw/s390x/s390-skeys.c                    |   2 +-
 hw/timer/mc146818rtc.c                   |   4 +-
 include/qapi/qmp/dispatch.h              |   1 -
 include/sysemu/arch_init.h               |  11 -
 monitor.c                                |  88 +---
 qapi/misc.json                           | 485 +--------------------
 qapi/qapi-schema.json                    |   1 +
 qapi/qmp-registry.c                      |   8 -
 qapi/target.json                         | 514 +++++++++++++++++++++++
 qemu-deprecated.texi                     |   5 +
 qmp.c                                    |  26 --
 scripts/qapi/commands.py                 |   2 +-
 scripts/qapi/common.py                   |  55 ++-
 scripts/qapi/events.py                   |  38 +-
 scripts/qapi/types.py                    |   4 +-
 scripts/qapi/visit.py                    |   4 +-
 stubs/Makefile.objs                      |   4 -
 stubs/arch-query-cpu-def.c               |  11 -
 stubs/arch-query-cpu-model-baseline.c    |  13 -
 stubs/arch-query-cpu-model-comparison.c  |  13 -
 stubs/arch-query-cpu-model-expansion.c   |  13 -
 stubs/monitor.c                          |   2 +-
 target/arm/helper.c                      |   3 +-
 target/arm/monitor.c                     |   2 +-
 target/i386/cpu.c                        |   7 +-
 target/i386/sev_i386.h                   |   2 +-
 target/ppc/translate_init.inc.c          |   3 +-
 target/s390x/cpu_models.c                |   9 +-
 tests/qapi-schema/comments.out           |   1 +
 tests/qapi-schema/doc-bad-section.out    |   1 +
 tests/qapi-schema/doc-good.out           |   1 +
 tests/qapi-schema/empty.out              |   1 +
 tests/qapi-schema/event-case.out         |   1 +
 tests/qapi-schema/ident-with-escape.out  |   1 +
 tests/qapi-schema/include-relpath.out    |   1 +
 tests/qapi-schema/include-repetition.out |   1 +
 tests/qapi-schema/include-simple.out     |   1 +
 tests/qapi-schema/indented-expr.out      |   1 +
 tests/qapi-schema/qapi-schema-test.out   |   1 +
 tests/test-qmp-event.c                   |   1 +
 tests/test-qobject-input-visitor.c       |   1 -
 ui/vnc.c                                 |   3 +-
 48 files changed, 730 insertions(+), 737 deletions(-)
 create mode 100644 qapi/target.json
 delete mode 100644 stubs/arch-query-cpu-def.c
 delete mode 100644 stubs/arch-query-cpu-model-baseline.c
 delete mode 100644 stubs/arch-query-cpu-model-comparison.c
 delete mode 100644 stubs/arch-query-cpu-model-expansion.c
Signature · 1 line
2.17.2
#1 lore raw

PATCH v3 1/17 qapi: Belatedly document modular code generation

We generate code for built-ins and sub-modules into separate files since commit cdb6610ae42 and 252dc3105fc (v2.12.0). Both commits neglected to update documentation. Do that now.

---
 docs/devel/qapi-code-gen.txt | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
docs/devel/qapi-code-gen.txt +38 -0
index 87183d3a09..b91bde647c 100644
@@ -1113,6 +1113,19 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-types-SUBMODULE.h
+SUBDIR/$(prefix)qapi-types-SUBMODULE.c
+
+If qapi-gen.py is run with option --builtins, additional files are
+created:
+
+qapi-builtin-types.h - C types corresponding to built-in types
+
+qapi-builtin-types.c - Cleanup functions for the above C types
+
 === Code generated for visiting QAPI types ===
 
 These are the visitor functions used to walk through and convert
@@ -1244,6 +1257,19 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
+SUBDIR/$(prefix)qapi-visit-SUBMODULE.c
+
+If qapi-gen.py is run with option --builtins, additional files are
+created:
+
+qapi-builtin-visit.h - Visitor functions for built-in types
+
+qapi-builtin-visit.c - Declarations for these visitor functions
+
 === Code generated for commands ===
 
 These are the marshaling/dispatch functions for the commands defined
@@ -1342,6 +1368,12 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
+SUBDIR/$(prefix)qapi-commands-SUBMODULE.c
+
 === Code generated for events ===
 
 This is the code related to events defined in the schema, providing
@@ -1402,6 +1434,12 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-events-SUBMODULE.h
+SUBDIR/$(prefix)qapi-events-SUBMODULE.c
+
 === Code generated for introspection ===
 
 The following files are created:
Signature · 1 line
2.17.2
Reviewed-by on v3 1/17
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/17] qapi: Belatedly document modular code generation

Quoted 6 lines · Markus Armbruster

We generate code for built-ins and sub-modules into separate files since commit cdb6610ae42 and 252dc3105fc (v2.12.0). Both commits neglected to update documentation. Do that now.

Quoted 77 lines
---
 docs/devel/qapi-code-gen.txt | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
docs/devel/qapi-code-gen.txt +38 -1
index 87183d3a09..b91bde647c 100644
@@ -1113,6 +1113,19 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-types-SUBMODULE.h
+SUBDIR/$(prefix)qapi-types-SUBMODULE.c
+
+If qapi-gen.py is run with option --builtins, additional files are
+created:
+
+qapi-builtin-types.h - C types corresponding to built-in types
+
+qapi-builtin-types.c - Cleanup functions for the above C types
+
 === Code generated for visiting QAPI types ===
 
 These are the visitor functions used to walk through and convert
@@ -1244,6 +1257,19 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
+SUBDIR/$(prefix)qapi-visit-SUBMODULE.c
+
+If qapi-gen.py is run with option --builtins, additional files are
+created:
+
+qapi-builtin-visit.h - Visitor functions for built-in types
+
+qapi-builtin-visit.c - Declarations for these visitor functions
+
 === Code generated for commands ===
 
 These are the marshaling/dispatch functions for the commands defined
@@ -1342,6 +1368,12 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
+SUBDIR/$(prefix)qapi-commands-SUBMODULE.c
+
 === Code generated for events ===
 
 This is the code related to events defined in the schema, providing
@@ -1402,6 +1434,12 @@ Example:
 
 [Uninteresting stuff omitted...]
 
+For a modular QAPI schema (see section Include directives), code for
+each sub-module SUBDIR/SUBMODULE.json is actually generated into
+
+SUBDIR/$(prefix)qapi-events-SUBMODULE.h
+SUBDIR/$(prefix)qapi-events-SUBMODULE.c
+
 === Code generated for introspection ===
 
 The following files are created:
--

2.17.2

#3 lore raw

PATCH v3 2/17 qapi: Fix up documentation for recent commit a95291007b2

In reply to Markus Armbruster
---
 docs/devel/qapi-code-gen.txt | 2 ++
 1 file changed, 2 insertions(+)
docs/devel/qapi-code-gen.txt +2 -0
index b91bde647c..c9ba8ddb2e 100644
@@ -1410,6 +1410,8 @@ Example:
 
     extern const QEnumLookup example_QAPIEvent_lookup;
 
+    void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
+
     #endif /* EXAMPLE_QAPI_EVENTS_H */
     $ cat qapi-generated/example-qapi-events.c
 [Uninteresting stuff omitted...]
Signature · 1 line
2.17.2
Reviewed-by on v3 2/17
#4 lore raw

Re: [Qemu-devel] [PATCH v3 02/17] qapi: Fix up documentation for recent commit a95291007b2

Quoted 2 lines · Markus Armbruster
Quoted 21 lines
---
 docs/devel/qapi-code-gen.txt | 2 ++
 1 file changed, 2 insertions(+)
docs/devel/qapi-code-gen.txt +2 -1
index b91bde647c..c9ba8ddb2e 100644
@@ -1410,6 +1410,8 @@ Example:
 
     extern const QEnumLookup example_QAPIEvent_lookup;
 
+    void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
+
     #endif /* EXAMPLE_QAPI_EVENTS_H */
     $ cat qapi-generated/example-qapi-events.c
 [Uninteresting stuff omitted...]
--

2.17.2

Signature · 1 line
Marc-André Lureau
#5 lore raw

PATCH v3 3/17 qapi: Clean up modular built-in code generation a bit

In reply to Markus Armbruster

We neglect to call .visit_module() for the special module we use for built-ins. Harmless, but clean it up anyway. The tests/qapi-schema/*.out now show the built-in module as 'module None'.

Subclasses of QAPISchemaModularCVisitor need to ._add_module() this special module to enable code generation for built-ins. When this hasn't been done, QAPISchemaModularCVisitor.visit_module() does nothing for the special module. That looks like built-ins could accidentally be generated into the wrong module when a subclass neglects to call ._add_module(). Can't happen, because built-ins are all visited before any other module. But that's non-obvious. Switch off code generation explicitly.

Split QAPISchemaModularCVisitor._add_module() into ._add_user_module() and ._add_system_module(), for clarity.

Rename QAPISchemaModularCVisitor._begin_module() to ._begin_user_module().

New QAPISchemaModularCVisitor._is_builtin_module(), for clarity.

---
 scripts/qapi/commands.py                 |  2 +-
 scripts/qapi/common.py                   | 24 ++++++++++++++++++------
 scripts/qapi/events.py                   |  2 +-
 scripts/qapi/types.py                    |  2 +-
 scripts/qapi/visit.py                    |  2 +-
 tests/qapi-schema/comments.out           |  1 +
 tests/qapi-schema/doc-bad-section.out    |  1 +
 tests/qapi-schema/doc-good.out           |  1 +
 tests/qapi-schema/empty.out              |  1 +
 tests/qapi-schema/event-case.out         |  1 +
 tests/qapi-schema/ident-with-escape.out  |  1 +
 tests/qapi-schema/include-relpath.out    |  1 +
 tests/qapi-schema/include-repetition.out |  1 +
 tests/qapi-schema/include-simple.out     |  1 +
 tests/qapi-schema/indented-expr.out      |  1 +
 tests/qapi-schema/qapi-schema-test.out   |  1 +
 16 files changed, 33 insertions(+), 10 deletions(-)
scripts/qapi/commands.py +1 -1
index 0f3c991918..ebf488953d 100644
@@ -242,7 +242,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
         self._regy = QAPIGenCCode()
         self._visited_ret_types = {}
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         self._visited_ret_types[self._genc] = set()
         commands = self._module_basename('qapi-commands', name)
         types = self._module_basename('qapi-types', name)
scripts/qapi/common.py +18 -6
index c89edc0cb0..0e3ec598a4 100644
@@ -1868,6 +1868,7 @@ class QAPISchema(object):
     def visit(self, visitor):
         visitor.visit_begin(self)
         module = None
+        visitor.visit_module(module)
         for entity in self._entity_list:
             if visitor.visit_needed(entity):
                 if entity.module != module:
@@ -2321,9 +2322,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         self._what = what
         self._blurb = blurb
         self._pydoc = pydoc
+        self._genc = None
+        self._genh = None
         self._module = {}
         self._main_module = None
 
+    @staticmethod
+    def _is_builtin_module(name):
+        return not name
+
     def _module_basename(self, what, name):
         if name is None:
             return re.sub(r'-', '-builtin-', what)
@@ -2334,7 +2341,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         return basename + '-' + os.path.splitext(os.path.basename(name))[0]
 
     def _add_module(self, name, blurb):
-        if self._main_module is None and name is not None:
+        if self._main_module is None and not self._is_builtin_module(name):
             self._main_module = name
         genc = QAPIGenC(blurb, self._pydoc)
         genh = QAPIGenH(blurb, self._pydoc)
@@ -2346,22 +2353,27 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
 
     def write(self, output_dir, opt_builtins=False):
         for name in self._module:
-            if name is None and not opt_builtins:
+            if self._is_builtin_module(name) and not opt_builtins:
                 continue
             basename = self._module_basename(self._what, name)
             (genc, genh) = self._module[name]
             genc.write(output_dir, basename + '.c')
             genh.write(output_dir, basename + '.h')
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         pass
 
     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)
+        elif self._is_builtin_module(name):
+            # The built-in module has not been created.  No code may
+            # be generated.
+            self._genc = None
+            self._genh = None
+        else:
+            self._add_module(name, self._blurb)
+            self._begin_user_module(name)
 
     def visit_include(self, name, info):
         basename = self._module_basename(self._what, name)
scripts/qapi/events.py +1 -1
index d86a2d2b3e..6f39cf8196 100644
@@ -142,7 +142,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
         self._event_enum_members = []
         self._event_emit_name = c_name(prefix + 'qapi_event_emit')
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.add(mcgen('''
scripts/qapi/types.py +1 -1
index 62d4cf9f95..9fa510f7df 100644
@@ -194,7 +194,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
 #include "qapi/util.h"
 '''))
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.preamble_add(mcgen('''
scripts/qapi/visit.py +1 -1
index 82eab72b21..ca86009398 100644
@@ -298,7 +298,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
 ''',
                                       prefix=prefix))
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.preamble_add(mcgen('''
tests/qapi-schema/comments.out +1 -0
index d1abc4b5a1..273f0f54e1 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/doc-bad-section.out +1 -0
index db8014eed0..367e2a1c3e 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/doc-good.out +1 -0
index 21bf345ff0..d3bca343eb 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/empty.out +1 -0
index 5483cb7bc6..5b53d00702 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/event-case.out +1 -0
index f69d4ffe4e..ec8a1406e4 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/ident-with-escape.out +1 -0
index 7f891f7e90..39754eba8c 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-relpath.out +1 -0
index 783ccfc855..cf8636b78f 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-repetition.out +1 -0
index d45977ee56..5423983239 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-simple.out +1 -0
index 1afe20802a..061f81e509 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/indented-expr.out +1 -0
index c0cf3243f3..bffdf6756d 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/qapi-schema-test.out +1 -0
index 9464101d26..d8aec17115 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
Signature · 1 line
2.17.2
Reviewed-by on v3 3/17
#6 lore raw

Re: [Qemu-devel] [PATCH v3 03/17] qapi: Clean up modular built-in code generation a bit

Hi

Quoted 14 lines · Markus Armbruster

We neglect to call .visit_module() for the special module we use for built-ins. Harmless, but clean it up anyway. The tests/qapi-schema/*.out now show the built-in module as 'module None'.

Subclasses of QAPISchemaModularCVisitor need to ._add_module() this special module to enable code generation for built-ins. When this hasn't been done, QAPISchemaModularCVisitor.visit_module() does nothing for the special module. That looks like built-ins could accidentally be generated into the wrong module when a subclass neglects to call ._add_module(). Can't happen, because built-ins are all visited before any other module. But that's non-obvious. Switch off code generation explicitly.

Quoted 2 lines

Split QAPISchemaModularCVisitor._add_module() into ._add_user_module() and ._add_system_module(), for clarity.

That's in next patch.

Quoted 7 lines

Rename QAPISchemaModularCVisitor._begin_module() to ._begin_user_module().

New QAPISchemaModularCVisitor._is_builtin_module(), for clarity.

Quoted 243 lines
---
 scripts/qapi/commands.py                 |  2 +-
 scripts/qapi/common.py                   | 24 ++++++++++++++++++------
 scripts/qapi/events.py                   |  2 +-
 scripts/qapi/types.py                    |  2 +-
 scripts/qapi/visit.py                    |  2 +-
 tests/qapi-schema/comments.out           |  1 +
 tests/qapi-schema/doc-bad-section.out    |  1 +
 tests/qapi-schema/doc-good.out           |  1 +
 tests/qapi-schema/empty.out              |  1 +
 tests/qapi-schema/event-case.out         |  1 +
 tests/qapi-schema/ident-with-escape.out  |  1 +
 tests/qapi-schema/include-relpath.out    |  1 +
 tests/qapi-schema/include-repetition.out |  1 +
 tests/qapi-schema/include-simple.out     |  1 +
 tests/qapi-schema/indented-expr.out      |  1 +
 tests/qapi-schema/qapi-schema-test.out   |  1 +
 16 files changed, 33 insertions(+), 10 deletions(-)
scripts/qapi/commands.py +1 -1
index 0f3c991918..ebf488953d 100644
@@ -242,7 +242,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
         self._regy = QAPIGenCCode()
         self._visited_ret_types = {}
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         self._visited_ret_types[self._genc] = set()
         commands = self._module_basename('qapi-commands', name)
         types = self._module_basename('qapi-types', name)
scripts/qapi/common.py +18 -6
index c89edc0cb0..0e3ec598a4 100644
@@ -1868,6 +1868,7 @@ class QAPISchema(object):
     def visit(self, visitor):
         visitor.visit_begin(self)
         module = None
+        visitor.visit_module(module)
         for entity in self._entity_list:
             if visitor.visit_needed(entity):
                 if entity.module != module:
@@ -2321,9 +2322,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         self._what = what
         self._blurb = blurb
         self._pydoc = pydoc
+        self._genc = None
+        self._genh = None
         self._module = {}
         self._main_module = None
 
+    @staticmethod
+    def _is_builtin_module(name):
+        return not name
+
     def _module_basename(self, what, name):
         if name is None:
             return re.sub(r'-', '-builtin-', what)
@@ -2334,7 +2341,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         return basename + '-' + os.path.splitext(os.path.basename(name))[0]
 
     def _add_module(self, name, blurb):
-        if self._main_module is None and name is not None:
+        if self._main_module is None and not self._is_builtin_module(name):
             self._main_module = name
         genc = QAPIGenC(blurb, self._pydoc)
         genh = QAPIGenH(blurb, self._pydoc)
@@ -2346,22 +2353,27 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
 
     def write(self, output_dir, opt_builtins=False):
         for name in self._module:
-            if name is None and not opt_builtins:
+            if self._is_builtin_module(name) and not opt_builtins:
                 continue
             basename = self._module_basename(self._what, name)
             (genc, genh) = self._module[name]
             genc.write(output_dir, basename + '.c')
             genh.write(output_dir, basename + '.h')
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         pass
 
     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)
+        elif self._is_builtin_module(name):
+            # The built-in module has not been created.  No code may
+            # be generated.
+            self._genc = None
+            self._genh = None
+        else:
+            self._add_module(name, self._blurb)
+            self._begin_user_module(name)
 
     def visit_include(self, name, info):
         basename = self._module_basename(self._what, name)
scripts/qapi/events.py +1 -1
index d86a2d2b3e..6f39cf8196 100644
@@ -142,7 +142,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
         self._event_enum_members = []
         self._event_emit_name = c_name(prefix + 'qapi_event_emit')
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.add(mcgen('''
scripts/qapi/types.py +1 -1
index 62d4cf9f95..9fa510f7df 100644
@@ -194,7 +194,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
 #include "qapi/util.h"
 '''))
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.preamble_add(mcgen('''
scripts/qapi/visit.py +1 -1
index 82eab72b21..ca86009398 100644
@@ -298,7 +298,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
 ''',
                                       prefix=prefix))
 
-    def _begin_module(self, name):
+    def _begin_user_module(self, name):
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.preamble_add(mcgen('''
tests/qapi-schema/comments.out +1 -0
index d1abc4b5a1..273f0f54e1 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/doc-bad-section.out +1 -0
index db8014eed0..367e2a1c3e 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/doc-good.out +1 -0
index 21bf345ff0..d3bca343eb 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/empty.out +1 -0
index 5483cb7bc6..5b53d00702 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/event-case.out +1 -0
index f69d4ffe4e..ec8a1406e4 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/ident-with-escape.out +1 -0
index 7f891f7e90..39754eba8c 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-relpath.out +1 -0
index 783ccfc855..cf8636b78f 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-repetition.out +1 -0
index d45977ee56..5423983239 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/include-simple.out +1 -0
index 1afe20802a..061f81e509 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/indented-expr.out +1 -0
index c0cf3243f3..bffdf6756d 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
tests/qapi-schema/qapi-schema-test.out +1 -1
index 9464101d26..d8aec17115 100644
@@ -1,3 +1,4 @@
+module None
 object q_empty
 enum QType
     prefix QTYPE
--

2.17.2

#7 lore raw

Re: [Qemu-devel] [PATCH v3 03/17] qapi: Clean up modular built-in code generation a bit

Quoted 17 lines · Marc-André Lureau

Hi

Quoted 14 lines · Markus Armbruster

We neglect to call .visit_module() for the special module we use for built-ins. Harmless, but clean it up anyway. The tests/qapi-schema/*.out now show the built-in module as 'module None'.

Subclasses of QAPISchemaModularCVisitor need to ._add_module() this special module to enable code generation for built-ins. When this hasn't been done, QAPISchemaModularCVisitor.visit_module() does nothing for the special module. That looks like built-ins could accidentally be generated into the wrong module when a subclass neglects to call ._add_module(). Can't happen, because built-ins are all visited before any other module. But that's non-obvious. Switch off code generation explicitly.

Quoted 4 lines
Quoted 2 lines

Split QAPISchemaModularCVisitor._add_module() into ._add_user_module() and ._add_system_module(), for clarity.

That's in next patch.

You caught me fiddling with the patch split after having written the commit messages. Will fix.

Quoted 8 lines
Quoted 6 lines

Rename QAPISchemaModularCVisitor._begin_module() to ._begin_user_module().

New QAPISchemaModularCVisitor._is_builtin_module(), for clarity.

Thanks!

#8 lore raw

PATCH v3 4/17 qapi: Prepare for system modules other than 'builtin'

In reply to Markus Armbruster

The next commit wants to generate qapi-emit-events.{c.h}. To support that, extend QAPISchemaModularCVisitor to support additional "system modules", i.e. modules that don't correspond to a (user-defined) QAPI schema module.

---
 scripts/qapi/common.py | 35 +++++++++++++++++++++++++----------
 scripts/qapi/types.py  |  2 +-
 scripts/qapi/visit.py  |  2 +-
 3 files changed, 27 insertions(+), 12 deletions(-)
scripts/qapi/common.py +25 -10
index 0e3ec598a4..c327ae5036 100644
@@ -2327,27 +2327,42 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         self._module = {}
         self._main_module = None
 
+    @staticmethod
+    def _is_user_module(name):
+        return name and not name.startswith('./')
+
     @staticmethod
     def _is_builtin_module(name):
         return not name
 
     def _module_basename(self, what, name):
-        if name is None:
-            return re.sub(r'-', '-builtin-', what)
-        basename = os.path.join(os.path.dirname(name),
-                                self._prefix + what)
-        if name == self._main_module:
-            return basename
-        return basename + '-' + os.path.splitext(os.path.basename(name))[0]
+        ret = '' if self._is_builtin_module(name) else self._prefix
+        if self._is_user_module(name):
+            dirname, basename = os.path.split(name)
+            ret += what
+            if name != self._main_module:
+                ret += '-' + os.path.splitext(basename)[0]
+            ret = os.path.join(dirname, ret)
+        else:
+            name = name[2:] if name else 'builtin'
+            ret += re.sub(r'-', '-' + name + '-', what)
+        return ret
 
     def _add_module(self, name, blurb):
-        if self._main_module is None and not self._is_builtin_module(name):
-            self._main_module = name
         genc = QAPIGenC(blurb, self._pydoc)
         genh = QAPIGenH(blurb, self._pydoc)
         self._module[name] = (genc, genh)
         self._set_module(name)
 
+    def _add_user_module(self, name, blurb):
+        assert self._is_user_module(name)
+        if self._main_module is None:
+            self._main_module = name
+        self._add_module(name, blurb)
+
+    def _add_system_module(self, name, blurb):
+        self._add_module(name and './' + name, blurb)
+
     def _set_module(self, name):
         self._genc, self._genh = self._module[name]
 
@@ -2372,7 +2387,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
             self._genc = None
             self._genh = None
         else:
-            self._add_module(name, self._blurb)
+            self._add_user_module(name, self._blurb)
             self._begin_user_module(name)
 
     def visit_include(self, name, info):
scripts/qapi/types.py +1 -1
index 9fa510f7df..2bd6fcd44f 100644
@@ -183,7 +183,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
         QAPISchemaModularCVisitor.__init__(
             self, prefix, 'qapi-types', ' * Schema-defined QAPI types',
             __doc__)
-        self._add_module(None, ' * Built-in QAPI types')
+        self._add_system_module(None, ' * Built-in QAPI types')
         self._genc.preamble_add(mcgen('''
 #include "qemu/osdep.h"
 #include "qapi/dealloc-visitor.h"
scripts/qapi/visit.py +1 -1
index ca86009398..826b8066e1 100644
@@ -284,7 +284,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
         QAPISchemaModularCVisitor.__init__(
             self, prefix, 'qapi-visit', ' * Schema-defined QAPI visitors',
             __doc__)
-        self._add_module(None, ' * Built-in QAPI visitors')
+        self._add_system_module(None, ' * Built-in QAPI visitors')
         self._genc.preamble_add(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
Signature · 1 line
2.17.2
Reviewed-by on v3 4/17
#9 lore raw

Re: [Qemu-devel] [PATCH v3 04/17] qapi: Prepare for system modules other than 'builtin'

Quoted 7 lines · Markus Armbruster

The next commit wants to generate qapi-emit-events.{c.h}. To support that, extend QAPISchemaModularCVisitor to support additional "system modules", i.e. modules that don't correspond to a (user-defined) QAPI schema module.

Quoted 100 lines
---
 scripts/qapi/common.py | 35 +++++++++++++++++++++++++----------
 scripts/qapi/types.py  |  2 +-
 scripts/qapi/visit.py  |  2 +-
 3 files changed, 27 insertions(+), 12 deletions(-)
scripts/qapi/common.py +25 -10
index 0e3ec598a4..c327ae5036 100644
@@ -2327,27 +2327,42 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         self._module = {}
         self._main_module = None
 
+    @staticmethod
+    def _is_user_module(name):
+        return name and not name.startswith('./')
+
     @staticmethod
     def _is_builtin_module(name):
         return not name
 
     def _module_basename(self, what, name):
-        if name is None:
-            return re.sub(r'-', '-builtin-', what)
-        basename = os.path.join(os.path.dirname(name),
-                                self._prefix + what)
-        if name == self._main_module:
-            return basename
-        return basename + '-' + os.path.splitext(os.path.basename(name))[0]
+        ret = '' if self._is_builtin_module(name) else self._prefix
+        if self._is_user_module(name):
+            dirname, basename = os.path.split(name)
+            ret += what
+            if name != self._main_module:
+                ret += '-' + os.path.splitext(basename)[0]
+            ret = os.path.join(dirname, ret)
+        else:
+            name = name[2:] if name else 'builtin'
+            ret += re.sub(r'-', '-' + name + '-', what)
+        return ret
 
     def _add_module(self, name, blurb):
-        if self._main_module is None and not self._is_builtin_module(name):
-            self._main_module = name
         genc = QAPIGenC(blurb, self._pydoc)
         genh = QAPIGenH(blurb, self._pydoc)
         self._module[name] = (genc, genh)
         self._set_module(name)
 
+    def _add_user_module(self, name, blurb):
+        assert self._is_user_module(name)
+        if self._main_module is None:
+            self._main_module = name
+        self._add_module(name, blurb)
+
+    def _add_system_module(self, name, blurb):
+        self._add_module(name and './' + name, blurb)
+
     def _set_module(self, name):
         self._genc, self._genh = self._module[name]
 
@@ -2372,7 +2387,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
             self._genc = None
             self._genh = None
         else:
-            self._add_module(name, self._blurb)
+            self._add_user_module(name, self._blurb)
             self._begin_user_module(name)
 
     def visit_include(self, name, info):
scripts/qapi/types.py +1 -1
index 9fa510f7df..2bd6fcd44f 100644
@@ -183,7 +183,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
         QAPISchemaModularCVisitor.__init__(
             self, prefix, 'qapi-types', ' * Schema-defined QAPI types',
             __doc__)
-        self._add_module(None, ' * Built-in QAPI types')
+        self._add_system_module(None, ' * Built-in QAPI types')
         self._genc.preamble_add(mcgen('''
 #include "qemu/osdep.h"
 #include "qapi/dealloc-visitor.h"
scripts/qapi/visit.py +1 -2
index ca86009398..826b8066e1 100644
@@ -284,7 +284,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
         QAPISchemaModularCVisitor.__init__(
             self, prefix, 'qapi-visit', ' * Schema-defined QAPI visitors',
             __doc__)
-        self._add_module(None, ' * Built-in QAPI visitors')
+        self._add_system_module(None, ' * Built-in QAPI visitors')
         self._genc.preamble_add(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
--

2.17.2

#10 lore raw

PATCH v3 5/17 qapi: Generate QAPIEvent stuff into separate files

In reply to Markus Armbruster

Having to include qapi-events.h just for QAPIEvent is suboptimal, but quite tolerable now. It'll become problematic when we have events conditional on the target, because then qapi-events.h won't be usable from target-independent code anymore. Avoid that by generating it into separate files.

---
 .gitignore                   |  1 +
 Makefile                     |  1 +
 Makefile.objs                |  1 +
 docs/devel/qapi-code-gen.txt | 48 ++++++++++++++++++++++++------------
 monitor.c                    |  2 +-
 scripts/qapi/events.py       | 32 +++++++++++++++---------
 stubs/monitor.c              |  2 +-
 tests/test-qmp-event.c       |  1 +
 ui/vnc.c                     |  3 ++-
 9 files changed, 61 insertions(+), 30 deletions(-)
.gitignore +1 -0
index 0430257313..6d66daf713 100644
@@ -32,6 +32,7 @@
 /qapi/qapi-builtin-visit.[ch]
 /qapi/qapi-commands-*.[ch]
 /qapi/qapi-commands.[ch]
+/qapi/qapi-emit-events.[ch]
 /qapi/qapi-events-*.[ch]
 /qapi/qapi-events.[ch]
 /qapi/qapi-introspect.[ch]
Makefile +1 -0
index 1278a3eb52..cd13e26c88 100644
@@ -101,6 +101,7 @@ GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-visit-%.c)
 GENERATED_QAPI_FILES += qapi/qapi-commands.h qapi/qapi-commands.c
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.h)
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.c)
+GENERATED_QAPI_FILES += qapi/qapi-emit-events.h qapi/qapi-emit-events.c
 GENERATED_QAPI_FILES += qapi/qapi-events.h qapi/qapi-events.c
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.h)
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.c)
Makefile.objs +1 -0
index 67a054b08a..c463899df3 100644
@@ -12,6 +12,7 @@ util-obj-y += $(QAPI_MODULES:%=qapi/qapi-types-%.o)
 util-obj-y += qapi/qapi-builtin-visit.o
 util-obj-y += qapi/qapi-visit.o
 util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
+util-obj-y += qapi/qapi-emit-events.o
 util-obj-y += qapi/qapi-events.o
 util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
 util-obj-y += qapi/qapi-introspect.o
docs/devel/qapi-code-gen.txt +32 -16

73 lines not on this page · raw message

monitor.c +1 -1
index c09fa63940..20d8e2e2aa 100644
@@ -75,7 +75,7 @@
 #include "qemu/thread.h"
 #include "block/qapi.h"
 #include "qapi/qapi-commands.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
 #include "qapi/error.h"
 #include "qapi/qmp-event.h"
 #include "qapi/qapi-introspect.h"
scripts/qapi/events.py +21 -11
index 6f39cf8196..28bbc3745d 100644
@@ -143,12 +143,14 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
         self._event_emit_name = c_name(prefix + 'qapi_event_emit')
 
     def _begin_user_module(self, name):
+        events = self._module_basename('qapi-events', name)
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.add(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
-#include "%(prefix)sqapi-events.h"
+#include "%(prefix)sqapi-emit-events.h"
+#include "%(events)s.h"
 #include "%(visit)s.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
@@ -156,26 +158,34 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
 #include "qapi/qmp-event.h"
 
 ''',
-                             visit=visit, prefix=self._prefix))
+                             events=events, visit=visit,
+                             prefix=self._prefix))
         self._genh.add(mcgen('''
 #include "qapi/util.h"
 #include "%(types)s.h"
-
 ''',
                              types=types))
 
     def visit_end(self):
-        (genc, genh) = self._module[self._main_module]
-        genh.add(gen_enum(self._event_enum_name,
-                          self._event_enum_members))
-        genc.add(gen_enum_lookup(self._event_enum_name,
-                                 self._event_enum_members))
-        genh.add(mcgen('''
+        self._add_system_module('emit', ' * QAPI Events emission')
+        self._genc.preamble_add(mcgen('''
+#include "qemu/osdep.h"
+#include "%(prefix)sqapi-emit-events.h"
+''',
+                                      prefix=self._prefix))
+        self._genh.preamble_add(mcgen('''
+#include "qapi/util.h"
+'''))
+        self._genh.add(gen_enum(self._event_enum_name,
+                                self._event_enum_members))
+        self._genc.add(gen_enum_lookup(self._event_enum_name,
+                                       self._event_enum_members))
+        self._genh.add(mcgen('''
 
 void %(event_emit)s(%(event_enum)s event, QDict *qdict);
 ''',
-                       event_emit=self._event_emit_name,
-                       event_enum=self._event_enum_name))
+                             event_emit=self._event_emit_name,
+                             event_enum=self._event_enum_name))
 
     def visit_event(self, name, info, ifcond, arg_type, boxed):
         with ifcontext(ifcond, self._genh, self._genc):
stubs/monitor.c +1 -1
index 32bd7012c3..b57fe6c32f 100644
@@ -1,6 +1,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
 #include "qemu-common.h"
 #include "monitor/monitor.h"
 
tests/test-qmp-event.c +1 -0
index bf900f14f4..eee7e08ab6 100644
@@ -21,6 +21,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qapi/qmp-event.h"
 #include "test-qapi-events.h"
+#include "test-qapi-emit-events.h"
 
 typedef struct TestEventData {
     QDict *expect;
ui/vnc.c +2 -1
index 6002d09407..284ea824d0 100644
@@ -35,7 +35,8 @@
 #include "qemu/timer.h"
 #include "qemu/acl.h"
 #include "qemu/config-file.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
+#include "qapi/qapi-events-ui.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "ui/input.h"
Signature · 1 line
2.17.2
Reviewed-by on v3 5/17
#11 lore raw

Re: [Qemu-devel] [PATCH v3 05/17] qapi: Generate QAPIEvent stuff into separate files

Quoted 8 lines · Markus Armbruster

Having to include qapi-events.h just for QAPIEvent is suboptimal, but quite tolerable now. It'll become problematic when we have events conditional on the target, because then qapi-events.h won't be usable from target-independent code anymore. Avoid that by generating it into separate files.

Quoted 247 lines
---
 .gitignore                   |  1 +
 Makefile                     |  1 +
 Makefile.objs                |  1 +
 docs/devel/qapi-code-gen.txt | 48 ++++++++++++++++++++++++------------
 monitor.c                    |  2 +-
 scripts/qapi/events.py       | 32 +++++++++++++++---------
 stubs/monitor.c              |  2 +-
 tests/test-qmp-event.c       |  1 +
 ui/vnc.c                     |  3 ++-
 9 files changed, 61 insertions(+), 30 deletions(-)
.gitignore +1 -0
index 0430257313..6d66daf713 100644
@@ -32,6 +32,7 @@
 /qapi/qapi-builtin-visit.[ch]
 /qapi/qapi-commands-*.[ch]
 /qapi/qapi-commands.[ch]
+/qapi/qapi-emit-events.[ch]
 /qapi/qapi-events-*.[ch]
 /qapi/qapi-events.[ch]
 /qapi/qapi-introspect.[ch]
Makefile +1 -0
index 1278a3eb52..cd13e26c88 100644
@@ -101,6 +101,7 @@ GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-visit-%.c)
 GENERATED_QAPI_FILES += qapi/qapi-commands.h qapi/qapi-commands.c
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.h)
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.c)
+GENERATED_QAPI_FILES += qapi/qapi-emit-events.h qapi/qapi-emit-events.c
 GENERATED_QAPI_FILES += qapi/qapi-events.h qapi/qapi-events.c
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.h)
 GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.c)
Makefile.objs +1 -0
index 67a054b08a..c463899df3 100644
@@ -12,6 +12,7 @@ util-obj-y += $(QAPI_MODULES:%=qapi/qapi-types-%.o)
 util-obj-y += qapi/qapi-builtin-visit.o
 util-obj-y += qapi/qapi-visit.o
 util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
+util-obj-y += qapi/qapi-emit-events.o
 util-obj-y += qapi/qapi-events.o
 util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
 util-obj-y += qapi/qapi-introspect.o
docs/devel/qapi-code-gen.txt +32 -16
index c9ba8ddb2e..b517b0cfbf 100644
@@ -1381,11 +1381,15 @@ qapi_event_send_EVENT().
 
 The following files are created:
 
-$(prefix)qapi-events.h - Function prototypes for each event type, plus an
-                        enumeration of all event names
+$(prefix)qapi-events.h - Function prototypes for each event type
 
 $(prefix)qapi-events.c - Implementation of functions to send an event
 
+$(prefix)qapi-emit-events.h - Enumeration of all event names, and
+                              common event code declarations
+
+$(prefix)qapi-emit-events.c - Common event code definitions
+
 Example:
 
     $ cat qapi-generated/example-qapi-events.h
@@ -1397,9 +1401,32 @@ Example:
     #include "qapi/util.h"
     #include "example-qapi-types.h"
 
-
     void qapi_event_send_my_event(void);
 
+    #endif /* EXAMPLE_QAPI_EVENTS_H */
+    $ cat qapi-generated/example-qapi-events.c
+[Uninteresting stuff omitted...]
+
+    void qapi_event_send_my_event(void)
+    {
+        QDict *qmp;
+
+        qmp = qmp_event_build_dict("MY_EVENT");
+
+        example_qapi_event_emit(EXAMPLE_QAPI_EVENT_MY_EVENT, qmp);
+
+        qobject_unref(qmp);
+    }
+
+[Uninteresting stuff omitted...]
+    $ cat qapi-generated/example-qapi-emit-events.h
+[Uninteresting stuff omitted...]
+
+    #ifndef EXAMPLE_QAPI_EMIT_EVENTS_H
+    #define EXAMPLE_QAPI_EMIT_EVENTS_H
+
+    #include "qapi/util.h"
+
     typedef enum example_QAPIEvent {
         EXAMPLE_QAPI_EVENT_MY_EVENT,
         EXAMPLE_QAPI_EVENT__MAX,
@@ -1412,21 +1439,10 @@ Example:
 
     void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
 
-    #endif /* EXAMPLE_QAPI_EVENTS_H */
-    $ cat qapi-generated/example-qapi-events.c
+    #endif /* EXAMPLE_QAPI_EMIT_EVENTS_H */
+    $ cat qapi-generated/example-qapi-emit-events.c
 [Uninteresting stuff omitted...]
 
-    void qapi_event_send_my_event(void)
-    {
-        QDict *qmp;
-
-        qmp = qmp_event_build_dict("MY_EVENT");
-
-        example_qapi_event_emit(EXAMPLE_QAPI_EVENT_MY_EVENT, qmp);
-
-        qobject_unref(qmp);
-    }
-
     const QEnumLookup example_QAPIEvent_lookup = {
         .array = (const char *const[]) {
             [EXAMPLE_QAPI_EVENT_MY_EVENT] = "MY_EVENT",
monitor.c +1 -1
index c09fa63940..20d8e2e2aa 100644
@@ -75,7 +75,7 @@
 #include "qemu/thread.h"
 #include "block/qapi.h"
 #include "qapi/qapi-commands.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
 #include "qapi/error.h"
 #include "qapi/qmp-event.h"
 #include "qapi/qapi-introspect.h"
scripts/qapi/events.py +21 -11
index 6f39cf8196..28bbc3745d 100644
@@ -143,12 +143,14 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
         self._event_emit_name = c_name(prefix + 'qapi_event_emit')
 
     def _begin_user_module(self, name):
+        events = self._module_basename('qapi-events', name)
         types = self._module_basename('qapi-types', name)
         visit = self._module_basename('qapi-visit', name)
         self._genc.add(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
-#include "%(prefix)sqapi-events.h"
+#include "%(prefix)sqapi-emit-events.h"
+#include "%(events)s.h"
 #include "%(visit)s.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
@@ -156,26 +158,34 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
 #include "qapi/qmp-event.h"
 
 ''',
-                             visit=visit, prefix=self._prefix))
+                             events=events, visit=visit,
+                             prefix=self._prefix))
         self._genh.add(mcgen('''
 #include "qapi/util.h"
 #include "%(types)s.h"
-
 ''',
                              types=types))
 
     def visit_end(self):
-        (genc, genh) = self._module[self._main_module]
-        genh.add(gen_enum(self._event_enum_name,
-                          self._event_enum_members))
-        genc.add(gen_enum_lookup(self._event_enum_name,
-                                 self._event_enum_members))
-        genh.add(mcgen('''
+        self._add_system_module('emit', ' * QAPI Events emission')
+        self._genc.preamble_add(mcgen('''
+#include "qemu/osdep.h"
+#include "%(prefix)sqapi-emit-events.h"
+''',
+                                      prefix=self._prefix))
+        self._genh.preamble_add(mcgen('''
+#include "qapi/util.h"
+'''))
+        self._genh.add(gen_enum(self._event_enum_name,
+                                self._event_enum_members))
+        self._genc.add(gen_enum_lookup(self._event_enum_name,
+                                       self._event_enum_members))
+        self._genh.add(mcgen('''
 
 void %(event_emit)s(%(event_enum)s event, QDict *qdict);
 ''',
-                       event_emit=self._event_emit_name,
-                       event_enum=self._event_enum_name))
+                             event_emit=self._event_emit_name,
+                             event_enum=self._event_enum_name))
 
     def visit_event(self, name, info, ifcond, arg_type, boxed):
         with ifcontext(ifcond, self._genh, self._genc):
stubs/monitor.c +1 -1
index 32bd7012c3..b57fe6c32f 100644
@@ -1,6 +1,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
 #include "qemu-common.h"
 #include "monitor/monitor.h"
 
tests/test-qmp-event.c +1 -0
index bf900f14f4..eee7e08ab6 100644
@@ -21,6 +21,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qapi/qmp-event.h"
 #include "test-qapi-events.h"
+#include "test-qapi-emit-events.h"
 
 typedef struct TestEventData {
     QDict *expect;
ui/vnc.c +2 -2
index 6002d09407..284ea824d0 100644
@@ -35,7 +35,8 @@
 #include "qemu/timer.h"
 #include "qemu/acl.h"
 #include "qemu/config-file.h"
-#include "qapi/qapi-events.h"
+#include "qapi/qapi-emit-events.h"
+#include "qapi/qapi-events-ui.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "ui/input.h"
--

2.17.2

#12 lore raw

PATCH v3 6/17 build-sys: move qmp-introspect per target

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

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.

---
 Makefile.objs                      | 2 --
 Makefile.target                    | 2 ++
 tests/test-qobject-input-visitor.c | 1 -
 3 files changed, 2 insertions(+), 3 deletions(-)
Makefile.objs +0 -2
index c463899df3..70ee51742f 100644
@@ -15,7 +15,6 @@ util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
 util-obj-y += qapi/qapi-emit-events.o
 util-obj-y += qapi/qapi-events.o
 util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
-util-obj-y += qapi/qapi-introspect.o
 
 chardev-obj-y = chardev/
 slirp-obj-$(CONFIG_SLIRP) = slirp/
@@ -95,7 +94,6 @@ common-obj-$(CONFIG_FDT) += device_tree.o
 
 common-obj-y += qapi/qapi-commands.o
 common-obj-y += $(QAPI_MODULES:%=qapi/qapi-commands-%.o)
-common-obj-y += qapi/qapi-introspect.o
 common-obj-y += qmp.o hmp.o
 endif
 
Makefile.target +2 -0
index 401dc1ea6f..d8af835890 100644
@@ -164,6 +164,8 @@ endif
 
 GENERATED_FILES += hmp-commands.h hmp-commands-info.h
 
+obj-y += qapi/qapi-introspect.o
+
 endif # CONFIG_SOFTMMU
 
 dummy := $(call unnest-vars,,obj-y)
tests/test-qobject-input-visitor.c +0 -1
index caa90b3d7e..609334adf6 100644
@@ -1271,7 +1271,6 @@ static void test_visitor_in_qmp_introspect(TestInputVisitorData *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);
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.17.2
#13 lore raw

PATCH v3 7/17 qapi: New module target.json

In reply to Markus Armbruster

We can't add appropriate target-specific conditionals to misc.json, because that would make all of misc.json unusable in target-independent code. To keep misc.json target-independent, we need to split off target-dependent target.json.

This commit doesn't actually split off anything, it merely creates the empty module. The next few patches will move stuff from misc.json there.

---
 Makefile.objs         | 20 +++++++++-----------
 Makefile.target       | 10 ++++++++++
 qapi/qapi-schema.json |  1 +
 qapi/target.json      | 13 +++++++++++++
 4 files changed, 33 insertions(+), 11 deletions(-)
 create mode 100644 qapi/target.json
Makefile.objs +9 -11
index 70ee51742f..5f0a7a8ca5 100644
@@ -1,20 +1,19 @@
-QAPI_MODULES = block-core block char common crypto introspect job migration
-QAPI_MODULES += misc net rdma rocker run-state sockets tpm trace transaction
-QAPI_MODULES += ui
+QAPI_COMMON_MODULES = block-core block char common crypto introspect
+QAPI_COMMON_MODULES += job migration misc net rdma rocker run-state
+QAPI_COMMON_MODULES += sockets tpm trace transaction ui
+QAPI_TARGET_MODULES = target
+QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
 
 #######################################################################
 # Common libraries for tools and emulators
 stub-obj-y = stubs/ crypto/
 util-obj-y = util/ qobject/ qapi/
 util-obj-y += qapi/qapi-builtin-types.o
-util-obj-y += qapi/qapi-types.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-types-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-types-%.o)
 util-obj-y += qapi/qapi-builtin-visit.o
-util-obj-y += qapi/qapi-visit.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-visit-%.o)
 util-obj-y += qapi/qapi-emit-events.o
-util-obj-y += qapi/qapi-events.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-events-%.o)
 
 chardev-obj-y = chardev/
 slirp-obj-$(CONFIG_SLIRP) = slirp/
@@ -92,8 +91,7 @@ common-obj-$(CONFIG_FDT) += device_tree.o
 ######################################################################
 # qapi
 
-common-obj-y += qapi/qapi-commands.o
-common-obj-y += $(QAPI_MODULES:%=qapi/qapi-commands-%.o)
+common-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-commands-%.o)
 common-obj-y += qmp.o hmp.o
 endif
 
Makefile.target +10 -0
index d8af835890..f908477040 100644
@@ -164,6 +164,16 @@ endif
 
 GENERATED_FILES += hmp-commands.h hmp-commands-info.h
 
+# FIXME duplicates Makefile.obj's
+QAPI_TARGET_MODULES = target
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-types-%.o)
+obj-y += qapi/qapi-types.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-visit-%.o)
+obj-y += qapi/qapi-visit.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-events-%.o)
+obj-y += qapi/qapi-events.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-commands-%.o)
+obj-y += qapi/qapi-commands.o
 obj-y += qapi/qapi-introspect.o
 
 endif # CONFIG_SOFTMMU
qapi/qapi-schema.json +1 -0
index 1845aa78ff..db61bfd688 100644
@@ -97,3 +97,4 @@
 { 'include': 'trace.json' }
 { 'include': 'introspect.json' }
 { 'include': 'misc.json' }
+{ 'include': 'target.json' }
qapi/target.json new file +13 -0
new file mode 100644
index 0000000000..8054926293
@@ -0,0 +1,13 @@
+# -*- Mode: Python -*-
+#
+
+##
+# = Target-specific commands & events
+##
+
+##
+# @TARGET-TEMPORARY-DUMMY:
+# Will go away in the next commit.  Needed in this one because empty
+# modules don't generate anything, defeating this commit's purpose.
+##
+{ 'event': 'TARGET-TEMPORARY-DUMMY' }
Signature · 1 line
2.17.2
Reviewed-by on v3 7/17
#14 lore raw

Re: [Qemu-devel] [PATCH v3 07/17] qapi: New module target.json

Quoted 11 lines · Markus Armbruster

We can't add appropriate target-specific conditionals to misc.json, because that would make all of misc.json unusable in target-independent code. To keep misc.json target-independent, we need to split off target-dependent target.json.

This commit doesn't actually split off anything, it merely creates the empty module. The next few patches will move stuff from misc.json there.

Quoted 103 lines
---
 Makefile.objs         | 20 +++++++++-----------
 Makefile.target       | 10 ++++++++++
 qapi/qapi-schema.json |  1 +
 qapi/target.json      | 13 +++++++++++++
 4 files changed, 33 insertions(+), 11 deletions(-)
 create mode 100644 qapi/target.json
Makefile.objs +9 -11
index 70ee51742f..5f0a7a8ca5 100644
@@ -1,20 +1,19 @@
-QAPI_MODULES = block-core block char common crypto introspect job migration
-QAPI_MODULES += misc net rdma rocker run-state sockets tpm trace transaction
-QAPI_MODULES += ui
+QAPI_COMMON_MODULES = block-core block char common crypto introspect
+QAPI_COMMON_MODULES += job migration misc net rdma rocker run-state
+QAPI_COMMON_MODULES += sockets tpm trace transaction ui
+QAPI_TARGET_MODULES = target
+QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
 
 #######################################################################
 # Common libraries for tools and emulators
 stub-obj-y = stubs/ crypto/
 util-obj-y = util/ qobject/ qapi/
 util-obj-y += qapi/qapi-builtin-types.o
-util-obj-y += qapi/qapi-types.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-types-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-types-%.o)
 util-obj-y += qapi/qapi-builtin-visit.o
-util-obj-y += qapi/qapi-visit.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-visit-%.o)
 util-obj-y += qapi/qapi-emit-events.o
-util-obj-y += qapi/qapi-events.o
-util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
+util-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-events-%.o)
 
 chardev-obj-y = chardev/
 slirp-obj-$(CONFIG_SLIRP) = slirp/
@@ -92,8 +91,7 @@ common-obj-$(CONFIG_FDT) += device_tree.o
 ######################################################################
 # qapi
 
-common-obj-y += qapi/qapi-commands.o
-common-obj-y += $(QAPI_MODULES:%=qapi/qapi-commands-%.o)
+common-obj-y += $(QAPI_COMMON_MODULES:%=qapi/qapi-commands-%.o)
 common-obj-y += qmp.o hmp.o
 endif
 
Makefile.target +10 -0
index d8af835890..f908477040 100644
@@ -164,6 +164,16 @@ endif
 
 GENERATED_FILES += hmp-commands.h hmp-commands-info.h
 
+# FIXME duplicates Makefile.obj's
+QAPI_TARGET_MODULES = target
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-types-%.o)
+obj-y += qapi/qapi-types.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-visit-%.o)
+obj-y += qapi/qapi-visit.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-events-%.o)
+obj-y += qapi/qapi-events.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-commands-%.o)
+obj-y += qapi/qapi-commands.o
 obj-y += qapi/qapi-introspect.o
 
 endif # CONFIG_SOFTMMU
qapi/qapi-schema.json +1 -0
index 1845aa78ff..db61bfd688 100644
@@ -97,3 +97,4 @@
 { 'include': 'trace.json' }
 { 'include': 'introspect.json' }
 { 'include': 'misc.json' }
+{ 'include': 'target.json' }
qapi/target.json new file +13 -1
new file mode 100644
index 0000000000..8054926293
@@ -0,0 +1,13 @@
+# -*- Mode: Python -*-
+#
+
+##
+# = Target-specific commands & events
+##
+
+##
+# @TARGET-TEMPORARY-DUMMY:
+# Will go away in the next commit.  Needed in this one because empty
+# modules don't generate anything, defeating this commit's purpose.
+##
+{ 'event': 'TARGET-TEMPORARY-DUMMY' }
--

2.17.2

#15 lore raw

Re: [Qemu-devel] [PATCH v3 07/17] qapi: New module target.json

In reply to Markus Armbruster
Quoted 20 lines · Markus Armbruster

We can't add appropriate target-specific conditionals to misc.json, because that would make all of misc.json unusable in target-independent code. To keep misc.json target-independent, we need to split off target-dependent target.json.

This commit doesn't actually split off anything, it merely creates the empty module. The next few patches will move stuff from misc.json there.

---
 Makefile.objs         | 20 +++++++++-----------
 Makefile.target       | 10 ++++++++++
 qapi/qapi-schema.json |  1 +
 qapi/target.json      | 13 +++++++++++++
 4 files changed, 33 insertions(+), 11 deletions(-)
 create mode 100644 qapi/target.json

+++ b/Makefile.target

Makefile.target endif · line 167

Quoted 4 lines
Makefile.target +1 -0
@@ -164,6 +164,16 @@ endif
 
 GENERATED_FILES += hmp-commands.h hmp-commands-info.h
 
+# FIXME duplicates Makefile.obj's

Is this addressed later in the series, or should the commit message call it out?

Quoted 11 lines
Makefile.target +9 -0
+QAPI_TARGET_MODULES = target
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-types-%.o)
+obj-y += qapi/qapi-types.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-visit-%.o)
+obj-y += qapi/qapi-visit.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-events-%.o)
+obj-y += qapi/qapi-events.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-commands-%.o)
+obj-y += qapi/qapi-commands.o
 obj-y += qapi/qapi-introspect.o
 
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#16 lore raw

Re: [Qemu-devel] [PATCH v3 07/17] qapi: New module target.json

Quoted 22 lines · Eric Blake
Quoted 21 lines · Markus Armbruster

We can't add appropriate target-specific conditionals to misc.json, because that would make all of misc.json unusable in target-independent code. To keep misc.json target-independent, we need to split off target-dependent target.json.

This commit doesn't actually split off anything, it merely creates the empty module. The next few patches will move stuff from misc.json there.

---
 Makefile.objs         | 20 +++++++++-----------
 Makefile.target       | 10 ++++++++++
 qapi/qapi-schema.json |  1 +
 qapi/target.json      | 13 +++++++++++++
 4 files changed, 33 insertions(+), 11 deletions(-)
 create mode 100644 qapi/target.json

+++ b/Makefile.target

(quoted diff) +0 -0
@@ -164,6 +164,16 @@ endif
 
Quoted 6 lines

Makefile.target endif · line 167

Quoted 3 lines
Makefile.target +1 -0
 GENERATED_FILES += hmp-commands.h hmp-commands-info.h
 
+# FIXME duplicates Makefile.obj's

Is this addressed later in the series, or should the commit message call it out?

It's not addressed.

I added the FIXME for my RFC v2, which went out in a bit of a hurry right before my Christmas break. I promptly forgot it exists.

Either I find a way to avoid the duplication, or I mention the FIXME in my commit message.

Thanks!

Quoted 11 lines
Quoted 11 lines
Makefile.target +9 -0
+QAPI_TARGET_MODULES = target
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-types-%.o)
+obj-y += qapi/qapi-types.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-visit-%.o)
+obj-y += qapi/qapi-visit.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-events-%.o)
+obj-y += qapi/qapi-events.o
+obj-y += $(QAPI_TARGET_MODULES:%=qapi/qapi-commands-%.o)
+obj-y += qapi/qapi-commands.o
 obj-y += qapi/qapi-introspect.o
 
#17 lore raw

PATCH v3 8/17 qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

Move rtc-reset-reinjection and SEV in target.json and make them conditional on TARGET_I386.

---
 hw/timer/mc146818rtc.c |   2 +-
 monitor.c              |  31 --------
 qapi/misc.json         | 166 --------------------------------------
 qapi/target.json       | 177 ++++++++++++++++++++++++++++++++++++++++-
 target/i386/sev_i386.h |   2 +-
 5 files changed, 175 insertions(+), 203 deletions(-)
hw/timer/mc146818rtc.c +1 -1
index 69483152c3..bc1862b6fc 100644
@@ -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/qapi-commands-target.h"
 #include "qapi/qapi-events-misc.h"
 #include "qapi/visitor.h"
 #include "exec/address-spaces.h"
monitor.c +0 -31
index 20d8e2e2aa..1fc48df46c 100644
@@ -1145,12 +1145,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **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
@@ -4671,31 +4665,6 @@ QemuOptsList qemu_mon_opts = {
     },
 };
 
-#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)
 {
qapi/misc.json +0 -166

178 lines not on this page · raw message

qapi/target.json +173 -4

181 lines not on this page · raw message

target/i386/sev_i386.h +1 -1
index b8622dfb1e..c0f9373beb 100644
@@ -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/qapi-commands-target.h"
 
 #define SEV_POLICY_NODBG        0x1
 #define SEV_POLICY_NOKS         0x2
Signature · 1 line
2.17.2
#18 lore raw

PATCH v3 9/17 qapi: make s390 commands depend on TARGET_S390X

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

---
 hw/s390x/s390-skeys.c                   |   2 +-
 include/sysemu/arch_init.h              |   7 --
 monitor.c                               |  14 ---
 qapi/misc.json                          | 137 -----------------------
 qapi/target.json                        | 142 ++++++++++++++++++++++++
 qmp.c                                   |  14 ---
 stubs/Makefile.objs                     |   2 -
 stubs/arch-query-cpu-model-baseline.c   |  13 ---
 stubs/arch-query-cpu-model-comparison.c |  13 ---
 target/s390x/cpu_models.c               |   5 +-
 10 files changed, 146 insertions(+), 203 deletions(-)
 delete mode 100644 stubs/arch-query-cpu-model-baseline.c
 delete mode 100644 stubs/arch-query-cpu-model-comparison.c
hw/s390x/s390-skeys.c +1 -1
index 15f7ab0e53..daac936698 100644
@@ -14,7 +14,7 @@
 #include "hw/boards.h"
 #include "hw/s390x/storage-keys.h"
 #include "qapi/error.h"
-#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-commands-target.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
include/sysemu/arch_init.h +0 -7
index 32abdfe6a1..f0ef652b2a 100644
@@ -36,11 +36,4 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
 CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType 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
monitor.c +0 -14
index 1fc48df46c..45b37bc982 100644
@@ -1145,19 +1145,12 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **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");
@@ -4665,13 +4658,6 @@ QemuOptsList qemu_mon_opts = {
     },
 };
 
-#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)
 {
qapi/misc.json +0 -137

149 lines not on this page · raw message

qapi/target.json +142 -0

151 lines not on this page · raw message

qmp.c +0 -14
index 4c819dd8cf..8a613bf7c7 100644
@@ -617,20 +617,6 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
     return arch_query_cpu_model_expansion(type, model, errp);
 }
 
-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 tls,
                     Error **errp)
stubs/Makefile.objs +0 -2
index 5dd0aeeec6..48eb080bfb 100644
@@ -1,7 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
 stub-obj-y += arch-query-cpu-model-expansion.o
-stub-obj-y += arch-query-cpu-model-comparison.o
-stub-obj-y += arch-query-cpu-model-baseline.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
stubs/arch-query-cpu-model-baseline.c deleted +0 -13
deleted file mode 100644
index 0d066da328..0000000000
@@ -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;
-}
stubs/arch-query-cpu-model-comparison.c deleted +0 -13
deleted file mode 100644
index 8eb311a26c..0000000000
@@ -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;
-}
target/s390x/cpu_models.c +3 -2
index 7c253ff308..b532cd8d10 100644
@@ -25,6 +25,7 @@
 #include "sysemu/arch_init.h"
 #include "hw/pci/pci.h"
 #endif
+#include "qapi/qapi-commands-target.h"
 
 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
     {                                                                    \
@@ -605,7 +606,7 @@ static void list_add_feat(const char *name, void *opaque)
     *last = entry;
 }
 
-CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
+CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *infoa,
                                                      CpuModelInfo *infob,
                                                      Error **errp)
 {
@@ -678,7 +679,7 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
     return compare_info;
 }
 
-CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,
+CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *infoa,
                                                     CpuModelInfo *infob,
                                                     Error **errp)
 {
Signature · 1 line
2.17.2
#19 lore raw

PATCH v3 10/17 target.json: add a note about query-cpu* not being s390x-specific

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

---
 qapi/target.json | 6 ++++++
 1 file changed, 6 insertions(+)
qapi/target.json +6 -0
index 17671d77c1..010df35ebb 100644
@@ -275,6 +275,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',
@@ -315,6 +318,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',
Signature · 1 line
2.17.2
#20 lore raw

PATCH v3 11/17 qapi: make query-gic-capabilities depend on TARGET_ARM

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

---
 monitor.c            | 11 -----------
 qapi/misc.json       | 43 ------------------------------------------
 qapi/target.json     | 45 ++++++++++++++++++++++++++++++++++++++++++++
 target/arm/monitor.c |  2 +-
 4 files changed, 46 insertions(+), 55 deletions(-)
monitor.c +0 -11
index 45b37bc982..377d3d4d8d 100644
@@ -1145,9 +1145,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **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
@@ -4658,14 +4655,6 @@ QemuOptsList qemu_mon_opts = {
     },
 };
 
-#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 = MACHINE(qdev_get_machine());
qapi/misc.json +0 -43

49 lines not on this page · raw message

qapi/target.json +45 -0

48 lines not on this page · raw message

target/arm/monitor.c +1 -1
index 4cdd2676dd..41b32b94b2 100644
@@ -23,7 +23,7 @@
 #include "qemu/osdep.h"
 #include "hw/boards.h"
 #include "kvm_arm.h"
-#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-commands-target.h"
 
 static GICCapability *gic_cap_new(int version)
 {
Signature · 1 line
2.17.2
#21 lore raw

PATCH v3 12/17 qapi: make query-cpu-model-expansion depend on s390 or x86

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

---
 include/sysemu/arch_init.h             |  3 --
 monitor.c                              |  3 --
 qapi/misc.json                         | 51 -------------------------
 qapi/target.json                       | 52 ++++++++++++++++++++++++++
 qmp.c                                  |  7 ----
 stubs/Makefile.objs                    |  1 -
 stubs/arch-query-cpu-model-expansion.c | 13 -------
 target/i386/cpu.c                      |  5 ++-
 target/s390x/cpu_models.c              |  2 +-
 9 files changed, 57 insertions(+), 80 deletions(-)
 delete mode 100644 stubs/arch-query-cpu-model-expansion.c
include/sysemu/arch_init.h +0 -3
index f0ef652b2a..2497fd3351 100644
@@ -33,7 +33,4 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
-CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
-                                                      CpuModelInfo *mode,
-                                                      Error **errp);
 #endif
monitor.c +0 -3
index 377d3d4d8d..7a228ff6ea 100644
@@ -1145,9 +1145,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **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");
qapi/misc.json +0 -51

57 lines not on this page · raw message

qapi/target.json +52 -0

55 lines not on this page · raw message

qmp.c +0 -7
index 8a613bf7c7..c81af9d23f 100644
@@ -610,13 +610,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     return arch_query_cpu_definitions(errp);
 }
 
-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 tls,
                     Error **errp)
stubs/Makefile.objs +0 -1
index 48eb080bfb..e28f443b7b 100644
@@ -1,5 +1,4 @@
 stub-obj-y += arch-query-cpu-def.o
-stub-obj-y += arch-query-cpu-model-expansion.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
stubs/arch-query-cpu-model-expansion.c deleted +0 -13
deleted file mode 100644
index 26273a8b10..0000000000
@@ -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(CpuModelExpansionType type,
-                                                      CpuModelInfo *mode,
-                                                      Error **errp)
-{
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
-}
target/i386/cpu.c +4 -1
index 7483daef58..22c8533066 100644
@@ -41,6 +41,7 @@
 #include "qapi/visitor.h"
 #include "qom/qom-qobject.h"
 #include "sysemu/arch_init.h"
+#include "qapi/qapi-commands-target.h"
 
 #include "standard-headers/asm-x86/kvm_para.h"
 
@@ -3921,6 +3922,7 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
 }
 
+#ifndef CONFIG_USER_ONLY
 /* Return a QDict containing keys for all properties that can be included
  * in static expansion of CPU models. All properties set by x86_cpu_load_def()
  * must be included in the dictionary.
@@ -4068,7 +4070,7 @@ out:
 }
 
 CpuModelExpansionInfo *
-arch_query_cpu_model_expansion(CpuModelExpansionType type,
+qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                       CpuModelInfo *model,
                                                       Error **errp)
 {
@@ -4123,6 +4125,7 @@ out:
     }
     return ret;
 }
+#endif  /* !CONFIG_USER_ONLY */
 
 static gchar *x86_gdb_arch_name(CPUState *cs)
 {
target/s390x/cpu_models.c +1 -1
index b532cd8d10..cf87488bfc 100644
@@ -567,7 +567,7 @@ static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model,
     }
 }
 
-CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
+CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                       CpuModelInfo *model,
                                                       Error **errp)
 {
Signature · 1 line
2.17.2
#22 lore raw

PATCH v3 13/17 qapi: make query-cpu-definitions depend on specific targets

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

It depends on TARGET_PPC || TARGET_ARM || TARGET_I386 || TARGET_S390X.

---
 include/sysemu/arch_init.h      |  1 -
 monitor.c                       | 22 ------------
 qapi/misc.json                  | 58 ------------------------------
 qapi/target.json                | 64 +++++++++++++++++++++++++++++++++
 qmp.c                           |  5 ---
 stubs/Makefile.objs             |  1 -
 stubs/arch-query-cpu-def.c      | 11 ------
 target/arm/helper.c             |  3 +-
 target/i386/cpu.c               |  2 +-
 target/ppc/translate_init.inc.c |  3 +-
 target/s390x/cpu_models.c       |  2 +-
 11 files changed, 70 insertions(+), 102 deletions(-)
 delete mode 100644 stubs/arch-query-cpu-def.c
include/sysemu/arch_init.h +0 -1
index 2497fd3351..10cbafe970 100644
@@ -32,5 +32,4 @@ extern const uint32_t arch_type;
 int kvm_available(void);
 int xen_available(void);
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
 #endif
monitor.c +0 -22
index 7a228ff6ea..eeec289aae 100644
@@ -1131,26 +1131,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
     *ret_data = qobject_from_qlit(&qmp_schema_qlit);
 }
 
-/*
- * 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)
 {
     /*
@@ -1169,8 +1149,6 @@ static void monitor_init_qmp_commands(void)
     qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add,
                          QCO_NO_OPTIONS);
 
-    qmp_unregister_commands_hack();
-
     QTAILQ_INIT(&qmp_cap_negotiation_commands);
     qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
                          qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
qapi/misc.json +0 -58

70 lines not on this page · raw message

qapi/target.json +64 -0

67 lines not on this page · raw message

qmp.c +0 -5
index c81af9d23f..b92d62cd5f 100644
@@ -605,11 +605,6 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
     return prop_list;
 }
 
-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 tls,
                     Error **errp)
stubs/Makefile.objs +0 -1
index e28f443b7b..4eb2947371 100644
@@ -1,4 +1,3 @@
-stub-obj-y += arch-query-cpu-def.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
stubs/arch-query-cpu-def.c deleted +0 -11
deleted file mode 100644
index d436f95314..0000000000
@@ -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;
-}
target/arm/helper.c +2 -1
index d070879894..f05495d771 100644
@@ -19,6 +19,7 @@
 #include "sysemu/kvm.h"
 #include "fpu/softfloat.h"
 #include "qemu/range.h"
+#include "qapi/qapi-commands-target.h"
 
 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
 
@@ -6656,7 +6657,7 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data)
     *cpu_list = entry;
 }
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
 {
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list;
target/i386/cpu.c +1 -1
index 22c8533066..92f9a898c4 100644
@@ -3794,7 +3794,7 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
     *cpu_list = entry;
 }
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
 {
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list = get_sorted_cpu_model_list();
target/ppc/translate_init.inc.c +2 -1
index 59e0b86762..f393a408ac 100644
@@ -38,6 +38,7 @@
 #include "qemu/cutils.h"
 #include "disas/capstone.h"
 #include "fpu/softfloat.h"
+#include "qapi/qapi-commands-target.h"
 
 //#define PPC_DUMP_CPU
 //#define PPC_DEBUG_SPR
@@ -10201,7 +10202,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
     *first = entry;
 }
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
 {
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list;
target/s390x/cpu_models.c +1 -1
index cf87488bfc..5ef34abbf1 100644
@@ -433,7 +433,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)
     *cpu_list = entry;
 }
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
 {
     struct CpuDefinitionInfoListData list_data = {
         .list = NULL,
Signature · 1 line
2.17.2
#23 lore raw

PATCH v3 14/17 qapi: remove qmp_unregister_command()

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

This command is no longer needed, the schema has compile-time configuration conditions.

---
 include/qapi/qmp/dispatch.h | 1 -
 qapi/qmp-registry.c         | 8 --------
 2 files changed, 9 deletions(-)
include/qapi/qmp/dispatch.h +0 -1
index 68a528a9aa..9aa426a398 100644
@@ -39,7 +39,6 @@ typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList;
 
 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);
 void qmp_disable_command(QmpCommandList *cmds, const char *name);
 void qmp_enable_command(QmpCommandList *cmds, const char *name);
qapi/qmp-registry.c +0 -8
index 5af484cd9a..ca00f74795 100644
@@ -27,14 +27,6 @@ void qmp_register_command(QmpCommandList *cmds, const char *name,
     QTAILQ_INSERT_TAIL(cmds, cmd, node);
 }
 
-void qmp_unregister_command(QmpCommandList *cmds, const char *name)
-{
-    QmpCommand *cmd = qmp_find_command(cmds, name);
-
-    QTAILQ_REMOVE(cmds, cmd, node);
-    g_free(cmd);
-}
-
 QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name)
 {
     QmpCommand *cmd;
Signature · 1 line
2.17.2
#24 lore raw

PATCH v3 15/17 Revert "qapi-events: add 'if' condition to implicit event enum"

In reply to Markus Armbruster

This reverts commit 7bd263490590ee6fcf34ecb6203437e22f6e5a9c.

The commit applied the events' conditions to the members of enum QAPIEvent. Awkward, because it renders QAPIEvent unusable in target-independent code as soon as we make an event target-dependent. Reverting this has the following effects:

* ui/vnc.c can remain target independent.

* monitor_qapi_event_conf[] doesn't have to muck around with #ifdef.

* query-events again doesn't reflect conditionals. I'm going to deprecate it in favor of query-qmp-schema.

---
 scripts/qapi/events.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/qapi/events.py +3 -1
index 28bbc3745d..2067660be4 100644
@@ -193,7 +193,9 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict);
             self._genc.add(gen_event_send(name, arg_type, boxed,
                                           self._event_enum_name,
                                           self._event_emit_name))
-        self._event_enum_members.append(QAPISchemaMember(name, ifcond))
+        # Note: we generate the enum member regardless of @ifcond, to
+        # keep the enumeration usable in target-independent code.
+        self._event_enum_members.append(QAPISchemaMember(name))
 
 
 def gen_events(schema, output_dir, prefix):
Signature · 1 line
2.17.2
Reviewed-by on v3 15/17
#25 lore raw

Re: [Qemu-devel] [PATCH v3 15/17] Revert "qapi-events: add 'if' condition to implicit event enum"

Hi

Quoted 6 lines · Markus Armbruster

This reverts commit 7bd263490590ee6fcf34ecb6203437e22f6e5a9c.

The commit applied the events' conditions to the members of enum QAPIEvent. Awkward, because it renders QAPIEvent unusable in target-independent code as soon as we make an event target-dependent.

Well, my solution didn't have this problem iirc. You could mention that by having target-specific event enums, we could solve this. It might be worth a FIXME too.

Quoted 10 lines

Reverting this has the following effects:

* ui/vnc.c can remain target independent.

* monitor_qapi_event_conf[] doesn't have to muck around with #ifdef.

* query-events again doesn't reflect conditionals. I'm going to deprecate it in favor of query-qmp-schema.

But that's ok for now:

Quoted 22 lines
---
 scripts/qapi/events.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/qapi/events.py +3 -2
index 28bbc3745d..2067660be4 100644
@@ -193,7 +193,9 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict);
             self._genc.add(gen_event_send(name, arg_type, boxed,
                                           self._event_enum_name,
                                           self._event_emit_name))
-        self._event_enum_members.append(QAPISchemaMember(name, ifcond))
+        # Note: we generate the enum member regardless of @ifcond, to
+        # keep the enumeration usable in target-independent code.
+        self._event_enum_members.append(QAPISchemaMember(name))
 
 
 def gen_events(schema, output_dir, prefix):
--

2.17.2

#26 lore raw

Re: [Qemu-devel] [PATCH v3 15/17] Revert "qapi-events: add 'if' condition to implicit event enum"

Quoted 4 lines · Marc-André Lureau

Hi

Quoted 1 line · Markus Armbruster
Quoted 8 lines
Quoted 5 lines

This reverts commit 7bd263490590ee6fcf34ecb6203437e22f6e5a9c.

The commit applied the events' conditions to the members of enum QAPIEvent. Awkward, because it renders QAPIEvent unusable in target-independent code as soon as we make an event target-dependent.

Well, my solution didn't have this problem iirc. You could mention that by having target-specific event enums, we could solve this.

What about appending:

Another option would be to split target-dependent parts off enum QAPIEvent into a target-dependent enum. Doesn't seem worthwhile right now.

Quoted 1 line

It might be worth a FIXME too.

Well, the only thing that's broken is query-events, and I propose to delete it instead of fixing it.

Quoted 6 lines
Quoted 6 lines

Reverting this has the following effects:

* ui/vnc.c can remain target independent.

* monitor_qapi_event_conf[] doesn't have to muck around with #ifdef.

Quoted 7 lines
Quoted 4 lines

* query-events again doesn't reflect conditionals. I'm going to deprecate it in favor of query-qmp-schema.

But that's ok for now:

Thanks!

#27 lore raw

PATCH v3 16/17 qmp: Deprecate query-events in favor of query-qmp-schema

In reply to Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)
monitor.c +5 -0
index eeec289aae..9f27621ed1 100644
@@ -1099,6 +1099,11 @@ CommandInfoList *qmp_query_commands(Error **errp)
 
 EventInfoList *qmp_query_events(Error **errp)
 {
+    /*
+     * TODO This deprecated command is the only user of
+     * QAPIEvent_str() and QAPIEvent_lookup[].  When the command goes,
+     * they should go, too.
+     */
     EventInfoList *info, *ev_list = NULL;
     QAPIEvent e;
 
qapi/misc.json +5 -2
index 82f9147353..98f59f828a 100644
@@ -318,12 +318,15 @@
 ##
 # @query-events:
 #
-# Return a list of supported QMP events by this server
+# Return information on QMP events.
 #
-# Returns: A list of @EventInfo for all supported events
+# Returns: A list of @EventInfo.
 #
 # Since: 1.2.0
 #
+# Note: This command is deprecated, because its output doesn't reflect
+# compile-time configuration.  Use query-qmp-schema instead.
+#
 # Example:
 #
 # -> { "execute": "query-events" }
qemu-deprecated.texi +5 -0
index 9cc20b365c..3288e102d6 100644
@@ -103,6 +103,11 @@ Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
 documentation of ``query-hotpluggable-cpus'' for additional
 details.
 
+@subsection query-events (since 4.0)
+
+The ``query-events'' command has been superseded by the more powerful
+and accurate ``query-qmp-schema'' command.
+
 @section Human Monitor Protocol (HMP) commands
 
 @subsection The hub_id parameter of 'hostfwd_add' / 'hostfwd_remove' (since 3.1)
Signature · 1 line
2.17.2
#28 lore raw

Re: [Qemu-devel] [PATCH v3 16/17] qmp: Deprecate query-events in favor of query-qmp-schema

Adding libvirt in cc

Quoted 9 lines · Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)

Libvirt uses query-events; we'll need to patch libvirt to start relying on query-qmp-schema before this deprecation cycle can complete (although I'm in favor of making the change).

Quoted 56 lines
monitor.c +5 -0
index eeec289aae..9f27621ed1 100644
@@ -1099,6 +1099,11 @@ CommandInfoList *qmp_query_commands(Error **errp)
 
 EventInfoList *qmp_query_events(Error **errp)
 {
+    /*
+     * TODO This deprecated command is the only user of
+     * QAPIEvent_str() and QAPIEvent_lookup[].  When the command goes,
+     * they should go, too.
+     */
     EventInfoList *info, *ev_list = NULL;
     QAPIEvent e;
 
qapi/misc.json +5 -2
index 82f9147353..98f59f828a 100644
@@ -318,12 +318,15 @@
 ##
 # @query-events:
 #
-# Return a list of supported QMP events by this server
+# Return information on QMP events.
 #
-# Returns: A list of @EventInfo for all supported events
+# Returns: A list of @EventInfo.
 #
 # Since: 1.2.0
 #
+# Note: This command is deprecated, because its output doesn't reflect
+# compile-time configuration.  Use query-qmp-schema instead.
+#
 # Example:
 #
 # -> { "execute": "query-events" }
qemu-deprecated.texi +5 -0
index 9cc20b365c..3288e102d6 100644
@@ -103,6 +103,11 @@ Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
 documentation of ``query-hotpluggable-cpus'' for additional
 details.
 
+@subsection query-events (since 4.0)
+
+The ``query-events'' command has been superseded by the more powerful
+and accurate ``query-qmp-schema'' command.
+
 @section Human Monitor Protocol (HMP) commands
 
 @subsection The hub_id parameter of 'hostfwd_add' / 'hostfwd_remove' (since 3.1)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#29 lore raw

Re: [Qemu-devel] [libvirt] [PATCH v3 16/17] qmp: Deprecate query-events in favor of query-qmp-schema

Quoted 13 lines · Eric Blake

Adding libvirt in cc

Quoted 9 lines · Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)
Quoted 3 lines

Libvirt uses query-events; we'll need to patch libvirt to start relying on query-qmp-schema before this deprecation cycle can complete (although I'm in favor of making the change).

Patches to use 'query-qmp-schema' output rather than 'query-events' in libvirt:

https://www.redhat.com/archives/libvir-list/2019-February/msg00298.html

You can start the deprecation clock.

#30 lore raw

Re: [Qemu-devel] [libvirt] [PATCH v3 16/17] qmp: Deprecate query-events in favor of query-qmp-schema

Quoted 18 lines · Peter Krempa
Quoted 13 lines · Eric Blake

Adding libvirt in cc

Quoted 9 lines · Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)
Quoted 3 lines

Libvirt uses query-events; we'll need to patch libvirt to start relying on query-qmp-schema before this deprecation cycle can complete (although I'm in favor of making the change).

Quoted 6 lines

Patches to use 'query-qmp-schema' output rather than 'query-events' in libvirt:

https://www.redhat.com/archives/libvir-list/2019-February/msg00298.html

You can start the deprecation clock.

Awesome!

#31 lore raw

Re: [Qemu-devel] [libvirt] [PATCH v3 16/17] qmp: Deprecate query-events in favor of query-qmp-schema

Quoted 20 lines · Markus Armbruster
Quoted 18 lines · Peter Krempa
Quoted 16 lines · Eric Blake

Adding libvirt in cc

Quoted 9 lines · Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)

Libvirt uses query-events; we'll need to patch libvirt to start relying on query-qmp-schema before this deprecation cycle can complete (although I'm in favor of making the change).

Quoted 8 lines
Quoted 6 lines

Patches to use 'query-qmp-schema' output rather than 'query-events' in libvirt:

https://www.redhat.com/archives/libvir-list/2019-February/msg00298.html

You can start the deprecation clock.

Awesome!

It's now pushed. Thankfully our existing infrastructure for querying schema was able to handle it without any changes.

Reviewed-by on v3 16/17
#32 lore raw

Re: [Qemu-devel] [PATCH v3 16/17] qmp: Deprecate query-events in favor of query-qmp-schema

In reply to Markus Armbruster

Hi

Quoted 5 lines · Markus Armbruster

query-events doesn't reflect compile-time configuration. Instead of fixing that, deprecate the command in favor of query-qmp-schema.

sounds good to me (regardless on when the command is actually removed, depending on libvirt needs).

Quoted 63 lines
---
 monitor.c            | 5 +++++
 qapi/misc.json       | 7 +++++--
 qemu-deprecated.texi | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)
monitor.c +5 -0
index eeec289aae..9f27621ed1 100644
@@ -1099,6 +1099,11 @@ CommandInfoList *qmp_query_commands(Error **errp)
 
 EventInfoList *qmp_query_events(Error **errp)
 {
+    /*
+     * TODO This deprecated command is the only user of
+     * QAPIEvent_str() and QAPIEvent_lookup[].  When the command goes,
+     * they should go, too.
+     */
     EventInfoList *info, *ev_list = NULL;
     QAPIEvent e;
 
qapi/misc.json +5 -2
index 82f9147353..98f59f828a 100644
@@ -318,12 +318,15 @@
 ##
 # @query-events:
 #
-# Return a list of supported QMP events by this server
+# Return information on QMP events.
 #
-# Returns: A list of @EventInfo for all supported events
+# Returns: A list of @EventInfo.
 #
 # Since: 1.2.0
 #
+# Note: This command is deprecated, because its output doesn't reflect
+# compile-time configuration.  Use query-qmp-schema instead.
+#
 # Example:
 #
 # -> { "execute": "query-events" }
qemu-deprecated.texi +5 -1
index 9cc20b365c..3288e102d6 100644
@@ -103,6 +103,11 @@ Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
 documentation of ``query-hotpluggable-cpus'' for additional
 details.
 
+@subsection query-events (since 4.0)
+
+The ``query-events'' command has been superseded by the more powerful
+and accurate ``query-qmp-schema'' command.
+
 @section Human Monitor Protocol (HMP) commands
 
 @subsection The hub_id parameter of 'hostfwd_add' / 'hostfwd_remove' (since 3.1)
--

2.17.2

#33 lore raw

PATCH v3 17/17 qapi: move RTC_CHANGE to the target schema

In reply to Markus Armbruster

From: Marc-André Lureau <[email protected]>

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.

---
 hw/ppc/spapr_rtc.c     |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 qapi/misc.json         | 23 -----------------------
 qapi/target.json       | 23 +++++++++++++++++++++++
 4 files changed, 25 insertions(+), 25 deletions(-)
hw/ppc/spapr_rtc.c +1 -1
index cd049f389d..eb95a7077d 100644
@@ -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/qapi-events-target.h"
 #include "qemu/cutils.h"
 
 void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns)
hw/timer/mc146818rtc.c +1 -1
index bc1862b6fc..513f105e62 100644
@@ -32,7 +32,7 @@
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-target.h"
-#include "qapi/qapi-events-misc.h"
+#include "qapi/qapi-events-target.h"
 #include "qapi/visitor.h"
 #include "exec/address-spaces.h"
 
qapi/misc.json +0 -23
index 98f59f828a..8b3ca4fdd3 100644
@@ -2876,29 +2876,6 @@
 { 'event': 'ACPI_DEVICE_OST',
      'data': { 'info': 'ACPIOSTInfo' } }
 
-##
-# @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 that value will be different depending
-#          on clock chosen to drive RTC (specified by -rtc clock).
-#
-# 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:
 #
qapi/target.json +23 -0
index 5c41a0aee7..da7b4be51e 100644
@@ -7,6 +7,29 @@
 
 { 'include': 'misc.json' }
 
+##
+# @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_HPPA) || defined(TARGET_I386) || defined(TARGET_MIPS) || defined(TARGET_MIPS64) || defined(TARGET_MOXIE) || defined(TARGET_PPC) || defined(TARGET_PPC64) || defined(TARGET_S390X) || defined(TARGET_SH4) || defined(TARGET_SPARC)' }
+
 ##
 # @rtc-reset-reinjection:
 #
Signature · 1 line
2.17.2
#34 lore raw

Re: [Qemu-devel] [PATCH v3 17/17] qapi: move RTC_CHANGE to the target schema

Quoted 4 lines · Markus Armbruster

From: Marc-André Lureau <[email protected]>

A few targets don't emit RTC_CHANGE, we could restrict the event to the tagets that do emit it.

s/tagets/targets/

Quoted 2 lines

Note: There is a lot more of events & commands that we could restrict

s/is a lot more of/are a lot more/

Quoted 7 lines

to capable targets, with the cost of some additional complexity, but the benefit of added correctness and better introspection.

---

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#35 lore raw

Re: [Qemu-devel] [PATCH v3 17/17] qapi: move RTC_CHANGE to the target schema

Quoted 6 lines · Eric Blake
Quoted 4 lines · Markus Armbruster

From: Marc-André Lureau <[email protected]>

A few targets don't emit RTC_CHANGE, we could restrict the event to the tagets that do emit it.

Quoted 14 lines

s/tagets/targets/

Quoted 2 lines

Note: There is a lot more of events & commands that we could restrict

s/is a lot more of/are a lot more/

Quoted 7 lines

to capable targets, with the cost of some additional complexity, but the benefit of added correctness and better introspection.

---

Will fix, thanks!