1. 13 6月, 2019 1 次提交
    • K
      qapi: Add feature flags to struct types · 6a8c0b51
      Kevin Wolf 提交于
      Sometimes, the behaviour of QEMU changes without a change in the QMP
      syntax (usually by allowing values or operations that previously
      resulted in an error). QMP clients may still need to know whether
      they can rely on the changed behavior.
      
      Let's add feature flags to the QAPI schema language, so that we can make
      such changes visible with schema introspection.
      
      An example for a schema definition using feature flags looks like this:
      
          { 'struct': 'TestType',
            'data': { 'number': 'int' },
            'features': [ 'allow-negative-numbers' ] }
      
      Introspection information then looks like this:
      
          { "name": "TestType", "meta-type": "object",
            "members": [
                { "name": "number", "type": "int" } ],
            "features": [ "allow-negative-numbers" ] }
      
      This patch implements feature flags only for struct types. We'll
      implement them more widely as needed.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Message-Id: <20190606153803.5278-2-armbru@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      6a8c0b51
  2. 12 6月, 2019 2 次提交
    • M
      Include qemu-common.h exactly where needed · a8d25326
      Markus Armbruster 提交于
      No header includes qemu-common.h after this commit, as prescribed by
      qemu-common.h's file comment.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-5-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      include/hw/arm/xlnx-zynqmp.h hw/arm/nrf51_soc.c hw/arm/msf2-soc.c
      block/qcow2-refcount.c block/qcow2-cluster.c block/qcow2-cache.c
      target/arm/cpu.h target/lm32/cpu.h target/m68k/cpu.h target/mips/cpu.h
      target/moxie/cpu.h target/nios2/cpu.h target/openrisc/cpu.h
      target/riscv/cpu.h target/tilegx/cpu.h target/tricore/cpu.h
      target/unicore32/cpu.h target/xtensa/cpu.h; bsd-user/main.c and
      net/tap-bsd.c fixed up]
      a8d25326
    • M
      Include qemu/module.h where needed, drop it from qemu-common.h · 0b8fa32f
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-4-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      hw/usb/dev-hub.c hw/misc/exynos4210_rng.c hw/misc/bcm2835_rng.c
      hw/misc/aspeed_scu.c hw/display/virtio-vga.c hw/arm/stm32f205_soc.c;
      ui/cocoa.m fixed up]
      0b8fa32f
  3. 05 3月, 2019 3 次提交
    • M
      qapi: Fix array first used in a different module · 56a46895
      Markus Armbruster 提交于
      We generally put implicitly defined types in whatever module triggered
      their definition.  This is wrong for array types, as the included test
      case demonstrates.  Let's have a closer look at it.
      
      Type 'Status' is defined sub-sub-module.json.  Array type ['Status']
      occurs in main module qapi-schema-test.json and in
      include/sub-module.json.  The main module's use is first, so the array
      type gets put into the main module.
      
      The generated C headers define StatusList in qapi-types.h.  But
      include/qapi-types-sub-module.h uses it without including
      qapi-types.h.  Oops.
      
      To fix that, put the array type into its element type's module.
      
      Now StatusList gets generated into qapi-types-sub-module.h, which all
      its users include.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190301154051.23317-8-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      56a46895
    • M
      qapi: Fix code generation for sub-modules in other directories · 709395f8
      Markus Armbruster 提交于
      The #include directives to pull in sub-modules use file names relative
      to the main module.  Works only when all modules are in the same
      directory, or the main module's output directory is in the compiler's
      include path.  Use relative file names instead.
      
      The dummy variable we generate to avoid empty .o files has an invalid
      name for sub-modules in other directories.  Fix that.
      
      Both messed up in commit 252dc310 "qapi: Generate separate .h, .c
      for each module".  Escaped testing because tests/qapi-schema-test.json
      doesn't cover sub-modules in other directories, only
      tests/qapi-schema/include-relpath.json does, and we generate and
      compile C code only for the former, not the latter.  Fold the latter
      into the former.  This would have caught the mistakes fixed in this
      commit.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190301154051.23317-5-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      709395f8
    • M
      qapi: Pass file name to QAPIGen constructor instead of methods · dddee4d7
      Markus Armbruster 提交于
      Not much of an improvement now, but the next commit will profit.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190301154051.23317-4-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      dddee4d7
  4. 18 2月, 2019 4 次提交
    • M
      Revert "qapi-events: add 'if' condition to implicit event enum" · 093e3679
      Markus Armbruster 提交于
      This reverts commit 7bd26349.
      
      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.
      
      Another option would be to split target-dependent parts off enum
      QAPIEvent into a target-dependent enum.  Doesn't seem worthwhile right
      now.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20190214152251.2073-17-armbru@redhat.com>
      093e3679
    • M
      qapi: Generate QAPIEvent stuff into separate files · 5d75648b
      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.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20190214152251.2073-6-armbru@redhat.com>
      5d75648b
    • M
      qapi: Prepare for system modules other than 'builtin' · c2e196a9
      Markus Armbruster 提交于
      The next commit wants to generate qapi-emit-events.{c.h}.  To enable
      that, extend QAPISchemaModularCVisitor to support additional "system
      modules", i.e. modules that don't correspond to a (user-defined) QAPI
      schema module.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20190214152251.2073-5-armbru@redhat.com>
      c2e196a9
    • M
      qapi: Clean up modular built-in code generation a bit · dcac6471
      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.
      
      Rename QAPISchemaModularCVisitor._begin_module() to
      ._begin_user_module().
      
      New QAPISchemaModularCVisitor._is_builtin_module(), for clarity.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20190214152251.2073-4-armbru@redhat.com>
      dcac6471
  5. 24 1月, 2019 1 次提交
    • M
      qapi: Eliminate indirection through qmp_event_get_func_emit() · a9529100
      Markus Armbruster 提交于
      The qapi_event_send_FOO() functions emit events like this:
      
          QMPEventFuncEmit emit;
      
          emit = qmp_event_get_func_emit();
          if (!emit) {
              return;
          }
      
          qmp = qmp_event_build_dict("FOO");
          [put event arguments into @qmp...]
      
          emit(QAPI_EVENT_FOO, qmp);
      
      The value of qmp_event_get_func_emit() depends only on the program:
      
      * In qemu-system-FOO, it's always monitor_qapi_event_queue.
      
      * In tests/test-qmp-event, it's always event_test_emit.
      
      * In all other programs, it's always null.
      
      This is exactly the kind of dependence the linker is supposed to
      resolve; we don't actually need an indirection.
      
      Note that things would fall apart if we linked more than one QAPI
      schema into a single program: each set of qapi_event_send_FOO() uses
      its own event enumeration, yet they share a single emit function.
      Which takes the event enumeration as an argument.  Which one if
      there's more than one?
      
      More seriously: how does this work even now?  qemu-system-FOO wants
      QAPIEvent, and passes a function taking that to
      qmp_event_set_func_emit().  test-qmp-event wants test_QAPIEvent, and
      passes a function taking that to qmp_event_set_func_emit().
      
      It works by type trickery, of course:
      
          typedef void (*QMPEventFuncEmit)(unsigned event, QDict *dict);
      
          void qmp_event_set_func_emit(QMPEventFuncEmit emit);
      
          QMPEventFuncEmit qmp_event_get_func_emit(void);
      
      We use unsigned instead of the enumeration type.  Relies on both
      enumerations boiling down to unsigned, which happens to be true for
      the compilers we use.
      
      Clean this up as follows:
      
      * Generate qapi_event_send_FOO() that call PREFIX_qapi_event_emit()
        instead of the value of qmp_event_set_func_emit().
      
      * Generate a prototype for PREFIX_qapi_event_emit() into
        qapi-events.h.
      
      * PREFIX_ is empty for qapi/qapi-schema.json, and test_ for
        tests/qapi-schema/qapi-schema-test.json.  It's qga_ for
        qga/qapi-schema.json, and doc-good- for
        tests/qapi-schema/doc-good.json, but those don't define any events.
      
      * Rename monitor_qapi_event_queue() to qapi_event_emit() instead of
        passing it to qmp_event_set_func_emit().  This takes care of
        qemu-system-FOO.
      
      * Rename event_test_emit() to test_qapi_event_emit() instead of
        passing it to qmp_event_set_func_emit().  This takes care of
        tests/test-qmp-event.
      
      * Add a qapi_event_emit() that does nothing to stubs/monitor.c.  This
        takes care of all other programs that link code emitting QMP events.
      
      * Drop qmp_event_set_func_emit(), qmp_event_get_func_emit().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20181218182234.28876-3-armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      [Commit message typos fixed]
      a9529100
  6. 18 12月, 2018 1 次提交
  7. 14 12月, 2018 16 次提交
  8. 29 8月, 2018 5 次提交
    • E
      qapi: Add comments to aid debugging generated introspection · 8c643361
      Eric Blake 提交于
      We consciously chose in commit 1a9a507b to hide QAPI type names
      from the introspection output on the wire, but added a command
      line option -u to unmask the type name when doing a debug build.
      The unmask option still remains useful to some other forms of
      automated analysis, so it will not be removed; however, when it
      is not in use, the generated .c file can be hard to read.  At
      the time when we first introduced masking, the generated file
      consisted only of a monolithic C string, so there was no clean
      way to inject any comments.
      
      Later, in commit 7d0f982b, we switched the generation to output
      a QLit object, in part to make it easier for future addition of
      conditional compilation.  In fact, commit d626b6c1 took advantage
      of this by passing a tuple instead of a bare object for encoding
      the output of conditionals.  By extending that tuple, we can now
      interject strategic comments.
      
      For now, type name debug aid comments are only output once per
      meta-type, rather than at all uses of the number used to encode
      the type within the introspection data.  But this is still a lot
      more convenient than having to regenerate the file with the
      unmask operation temporarily turned on - merely search the
      generated file for '"NNN" =' to learn the corresponding source
      name and associated definition of type NNN.
      
      The generated qapi-introspect.c changes only with the addition
      of comments, such as:
      
      | @@ -14755,6 +15240,7 @@
      |          { "name", QLIT_QSTR("[485]"), },
      |          {}
      |      })),
      | +    /* "485" = QCryptoBlockInfoLUKSSlot */
      |      QLIT_QDICT(((QLitDictEntry[]) {
      |          { "members", QLIT_QLIST(((QLitObject[]) {
      |              QLIT_QDICT(((QLitDictEntry[]) {
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20180827213943.33524-3-eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [Rebased, update to qapi-code-gen.txt corrected]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      8c643361
    • E
      qapi: Minor introspect.py cleanups · 1aa806cc
      Eric Blake 提交于
      Commit 7d0f982b changed generated introspection output to no longer
      produce long lines in the generated .c file, but failed to adjust
      comments to match.  Add some clarity that the shorter length that
      matters most is the overall QMP response on the wire.
      
      Commit 25b1ef31 triggers a pep8 formatting nit.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20180827213943.33524-2-eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      1aa806cc
    • M
      qapi: Emit a blank line before dummy declaration · 5f1450f5
      Markus Armbruster 提交于
      We emit a dummy variable in each .c file "to shut up OSX toolchain
      warnings about empty .o files" (commit 252dc310).  Separate it from
      the code preceding it (if any) with a blank line.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20180828120736.32323-2-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      5f1450f5
    • P
      qapi: Drop qapi_event_send_FOO()'s Error ** argument · 3ab72385
      Peter Xu 提交于
      The generated qapi_event_send_FOO() take an Error ** argument.  They
      can't actually fail, because all they do with the argument is passing it
      to functions that can't fail: the QObject output visitor, and the
      @qmp_emit callback, which is either monitor_qapi_event_queue() or
      event_test_emit().
      
      Drop the argument, and pass &error_abort to the QObject output visitor
      and @qmp_emit instead.
      Suggested-by: NEric Blake <eblake@redhat.com>
      Suggested-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Message-Id: <20180815133747.25032-4-peterx@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [Commit message rewritten, update to qapi-code-gen.txt corrected]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      3ab72385
    • M
      qapi: Fix build_params() for empty parameter list · bdd2d42b
      Markus Armbruster 提交于
      build_params() returns '' instead of 'void' when there are no
      parameters.  Can't happen now, but the next commit will change that.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      [peterx: compose the patch from email replies]
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Message-Id: <20180815133747.25032-3-peterx@redhat.com>
      bdd2d42b
  9. 15 8月, 2018 1 次提交
    • M
      qapi: Fix some pycodestyle-3 complaints · b736e25a
      Markus Armbruster 提交于
      Fix the following issues:
      
          common.py:873:13: E129 visually indented line with same indent as next logical line
          common.py:1766:5: E741 ambiguous variable name 'l'
          common.py:1784:1: E305 expected 2 blank lines after class or function definition, found 1
          common.py:1833:1: E305 expected 2 blank lines after class or function definition, found 1
          common.py:1843:1: E305 expected 2 blank lines after class or function definition, found 1
          visit.py:181:18: E127 continuation line over-indented for visual indent
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NPhilippe Mathieu-Daudé <f4bug@amsat.org>
      Message-Id: <20180621083551.775-1-armbru@redhat.com>
      [Fixup squashed in:]
      Message-ID: <871sd0nzw9.fsf@dusky.pond.sub.org>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      b736e25a
  10. 23 7月, 2018 1 次提交
  11. 16 7月, 2018 1 次提交
    • M
      qapi: Do not expose "allow-preconfig" in query-qmp-schema · 1f214ee1
      Markus Armbruster 提交于
      According to commit 047f7038, option --preconfig
      
          [...] allows pausing QEMU in the new RUN_STATE_PRECONFIG state,
          allowing the configuration of QEMU from QMP before the machine
          jumps into board initialization code of machine_run_board_init()
      
          The intent is to allow management to query machine state and
          additionally configure it using previous query results within one
          QEMU instance (i.e. eliminate the need to start QEMU twice, 1st to
          query board specific parameters and 2nd for actual VM start using
          query results for additional parameters).
      
      The implementation is a bit of a hack: it splices in an additional
      main loop before machine creation, in special runstate preconfig.  New
      command exit-preconfig exits that main loop.  QEMU continues
      initializing, creates the machine, and runs the good old main loop.
      The replacement of the main loop is transparent to monitors.
      
      Sadly, some commands expect initialization to be complete.  Running
      them in --preconfig's main loop violates their preconditions.  Since
      we don't really know which commands are safe, we use a whitelist.
      This drags the concept of run state into the QMP core.
      
      The whitelist is done as a command flag in the QAPI schema (commit
      d6fe3d02).  Drags the concept of run state further into the QAPI
      language.
      
      The command flag is exposed in query-qmp-schema (also commit
      d6fe3d02).  This makes it ABI.
      
      I consider the whole thing an offensively ugly hack, but sometimes an
      ugly hack is the best we can do to solve a problem people have.
      
      The need described by the commit message quote above is genuine.  The
      proper solution would be a main loop that permits complete
      configuration via QMP.  This is out of reach, thus the hack.
      
      However, even though the need is genuine, it isn't urgent: libvirt is
      not going to use this anytime soon.  Baking a hack into ABI before it
      has any users is a bad idea.
      
      This commit reverts the parts of commit d6fe3d02 that affect ABI
      via query-qmp-schema.  The commit did the following:
      
      (1) Add command flag 'allow-preconfig' to the QAPI schema language
      
      (2) Pass it to code generators
      
      (3) Have the commands.py code generator pass it to the command
          registry (so commit 047f7038 can use it as whitelist)
      
      (4) Add 'allow-preconfig' to SchemaInfoCommand (neglecting to update
          qapi-code-gen.txt section "Client JSON Protocol introspection")
      
      (5) Set 'allow-preconfig': true for commands qmp_capabilities,
          query-commands, query-command-line-options, query-status
      
      Revert exactly (4), plus a bit of documentation added to
      qemu-tech.info in commit 047f7038.
      
      Shrinks query-qmp-schema's output from 126.5KiB to 121.8KiB for me.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20180705091402.26244-2-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Acked-by: NEduardo Habkost <ehabkost@redhat.com>
      Acked-by: NIgor Mammedov <imammedo@redhat.com>
      [Straightforward conflict with commit d626b6c1 resolved]
      1f214ee1
  12. 04 7月, 2018 4 次提交