Skip to contentSkip to conversation

QAPI patches for 2017-09-01

GIT PULL Markus Armbruster 3 participants 51 messages Sep 1, 2017 – Sep 6, 2017

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 223cd0e13f2e46078d7b573f0b8402bfbee339be:

Merge remote-tracking branch 'remotes/elmarco/tags/tidy-pull-request' into staging (2017-08-31 15:52:43 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2017-09-01-v2

for you to fetch changes up to fcff1e3146d4b7930f3b4a7a60091479d6652a5f:

qapi: drop the sentinel in enum array (2017-09-01 17:26:24 +0200)

----------------------------------------------------------------
QAPI patches for 2017-09-01

----------------------------------------------------------------
Eduardo Habkost (1):
qapi: Fix error handling code on alternate conflict

Marc-André Lureau (19):
qdict: Add qdict_put_null() helper, and put it to use
qlit: move qlit from check-qjson to qobject/
qlit: use QLit prefix consistently
qlit: Change compound literals to initializers
qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject()
qlit: make qlit_equal_qobject return a bool
qlit: make qlit_equal_qobject() take const arguments
qlit: add QLIT_QNULL and QLIT_BOOL
qlit: Replace open-coded qnum_get_int() by call tests/check-qlit: New, covering qobject/qlit.c
qlit: Tighten QLit dict vs QDict comparison
qlit: Tighten QLit list vs QList comparison
tpm: Clean up driver registration & lookup
hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()
hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter()
block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()
quorum: Use qapi_enum_parse() in quorum_open()
qapi: Change data type of the FOO_lookup generated for enum FOO
qapi: drop the sentinel in enum array

Markus Armbruster (27):
tests/qmp-test: Add generic, basic test of query commands
qobject: Explain how QNum works, and why
qapi-schema: Document how generated documentation is ordered
qapi-schema: Introspection doc is in the wrong section, fix
qapi-schema: Rocker doc section contains unrelated stuff, fix
qapi-schema: Collect sockets stuff in qapi/sockets.json
qapi-schema: Collect run state stuff in qapi/run-state.json
qapi-schema: Collect char device stuff in qapi/char.json
qapi-schema: Collect net device stuff in qapi/net.json
qapi-schema: Collect UI stuff in qapi/ui.json
qapi-schema: Collect migration stuff in qapi/migration.json
qapi-schema: Collect transaction stuff in qapi/transaction.json
qapi-schema: Collect TPM stuff in qapi/tpm.json
qapi-schema: Move block events from event.json to block.json
qapi-schema: Fold event.json back into qapi-schema.json
qapi-schema: Make block-core.json self-contained
qapi-schema: Move queries from common.json to qapi-schema.json
qapi-schema: Improve section headings
qapi: Update qapi-code-gen.txt examples to match current code
qapi: Drop superfluous qapi_enum_parse() parameter max
tpm: Clean up model registration & lookup
crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()
qapi: Use qapi_enum_parse() in input_type_enum()
qapi: Avoid unnecessary use of enum lookup table's sentinel
qapi: Generate FOO_str() macro for QAPI enum FOO
qapi: Mechanically convert FOO_lookup[...] to FOO_str(...)
qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup()

 MAINTAINERS                                        |   16 +
 Makefile                                           |   15 +-
 backends/hostmem.c                                 |    4 +-
 block.c                                            |    4 +-
 block/backup.c                                     |    2 +-
 block/blkdebug.c                                   |   27 +-
 block/file-posix.c                                 |   20 +-
 block/file-win32.c                                 |    7 +-
 block/gluster.c                                    |   11 +-
 block/iscsi.c                                      |    2 +-
 block/nfs.c                                        |    2 +-
 block/parallels.c                                  |   17 +-
 block/qcow2.c                                      |   15 +-
 block/qed.c                                        |    2 +-
 block/quorum.c                                     |   27 +-
 block/rbd.c                                        |    2 +-
 block/sheepdog.c                                   |    2 +-
 blockdev.c                                         |    8 +-
 blockjob.c                                         |    6 +-
 chardev/char.c                                     |    4 +-
 crypto/block-luks.c                                |   38 +-
 crypto/block.c                                     |    4 +-
 crypto/cipher-afalg.c                              |    2 +-
 crypto/cipher-builtin.c                            |    8 +-
 crypto/cipher-gcrypt.c                             |    4 +-
 crypto/cipher-nettle.c                             |    8 +-
 crypto/hmac-gcrypt.c                               |    2 +-
 crypto/hmac-glib.c                                 |    2 +-
 crypto/hmac-nettle.c                               |    2 +-
 crypto/pbkdf-gcrypt.c                              |    2 +-
 crypto/pbkdf-nettle.c                              |    2 +-
 crypto/secret.c                                    |    2 +-
 crypto/tlscreds.c                                  |    2 +-
 docs/devel/qapi-code-gen.txt                       |   50 +-
 hmp.c                                              |  220 +-
 hw/block/fdc.c                                     |    6 +-
 hw/char/escc.c                                     |    2 +-
 hw/core/qdev-properties.c                          |   17 +-
 hw/input/virtio-input-hid.c                        |    4 +-
 include/hw/qdev-core.h                             |    2 +-
 include/qapi/qmp/qdict.h                           |    4 +-
 include/qapi/qmp/qlit.h                            |   54 +
 include/qapi/qmp/qnum.h                            |   21 +
 include/qapi/util.h                                |   10 +-
 include/qapi/visitor.h                             |    2 +-
 include/qom/object.h                               |    4 +-
 include/sysemu/tpm_backend.h                       |    4 +-
 migration/colo-failover.c                          |    4 +-
 migration/colo.c                                   |   14 +-
 migration/global_state.c                           |    6 +-
 migration/migration.c                              |    1 -
 monitor.c                                          |   20 +-
 net/filter.c                                       |    2 +-
 net/net.c                                          |    4 +-
 qapi-schema.json                                   | 3866 ++------------------
 qapi/block-core.json                               |    5 +-
 qapi/block.json                                    |   73 +-
 qapi/char.json                                     |  538 +++
 qapi/common.json                                   |  132 +-
 qapi/crypto.json                                   |    2 +-
 qapi/event.json                                    |  646 ----
 qapi/introspect.json                               |    6 +-
 qapi/migration.json                                | 1085 ++++++
 qapi/net.json                                      |  706 ++++
 qapi/qapi-util.c                                   |   16 +-
 qapi/qapi-visit-core.c                             |   34 +-
 qapi/qmp-dispatch.c                                |    2 +-
 qapi/run-state.json                                |  352 ++
 qapi/sockets.json                                  |  147 +
 qapi/tpm.json                                      |  137 +
 qapi/trace.json                                    |    2 +-
 qapi/transaction.json                              |  158 +
 qapi/ui.json                                       |  977 +++++
 qemu-img.c                                         |    6 +-
 qemu-nbd.c                                         |    4 +-
 qobject/Makefile.objs                              |    2 +-
 qobject/qlit.c                                     |   84 +
 qom/object.c                                       |   16 +-
 scripts/coccinelle/qobject.cocci                   |    3 +
 scripts/qapi-event.py                              |    1 +
 scripts/qapi-types.py                              |    4 +
 scripts/qapi-visit.py                              |    2 +-
 scripts/qapi.py                                    |   24 +-
 target/i386/cpu.c                                  |    4 +-
 tests/Makefile.include                             |    7 +-
 tests/check-qjson.c                                |  150 +-
 tests/check-qlit.c                                 |   74 +
 tests/check-qom-proplist.c                         |   14 +-
 .../qapi-schema/alternate-conflict-bool-string.err |    1 +
 .../alternate-conflict-bool-string.exit            |    1 +
 .../alternate-conflict-bool-string.json            |    4 +
 .../qapi-schema/alternate-conflict-bool-string.out |    0
 .../qapi-schema/alternate-conflict-num-string.err  |    1 +
 .../qapi-schema/alternate-conflict-num-string.exit |    1 +
 .../qapi-schema/alternate-conflict-num-string.json |    4 +
 .../qapi-schema/alternate-conflict-num-string.out  |    0
 tests/qmp-test.c                                   |  181 +-
 tests/test-qapi-util.c                             |   18 +-
 tests/test-qobject-input-visitor.c                 |    8 +-
 tests/test-qobject-output-visitor.c                |    2 +-
 tests/test-string-input-visitor.c                  |    4 +-
 tests/test-string-output-visitor.c                 |    4 +-
 tpm.c                                              |   81 +-
 ui/input-legacy.c                                  |    6 +-
 ui/input.c                                         |   12 +-
 ui/vnc.c                                           |    6 +-
 util/keyval.c                                      |    1 -
 vl.c                                               |    6 +-
 108 files changed, 5360 insertions(+), 4982 deletions(-)
 create mode 100644 include/qapi/qmp/qlit.h
 create mode 100644 qapi/char.json
 delete mode 100644 qapi/event.json
 create mode 100644 qapi/migration.json
 create mode 100644 qapi/net.json
 create mode 100644 qapi/run-state.json
 create mode 100644 qapi/sockets.json
 create mode 100644 qapi/tpm.json
 create mode 100644 qapi/transaction.json
 create mode 100644 qapi/ui.json
 create mode 100644 qobject/qlit.c
 create mode 100644 tests/check-qlit.c
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.err
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.exit
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.json
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.out
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.err
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.exit
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.json
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.out
Signature · 1 line
2.13.5
#1 lore raw

[Qemu-devel] [PULL v2 01/47] qapi: Fix error handling code on alternate conflict

From: Eduardo Habkost <[email protected]>

The conflict check added by commit c0644771 ("qapi: Reject alternates that can't work with keyval_parse()") doesn't work with the following declaration:

{ 'alternate': 'Alt',

    'data': { 'one': 'bool',
              'two': 'str' } }

It crashes with:

Traceback (most recent call last):
File "./scripts/qapi-types.py", line 295, in <module>
schema = QAPISchema(input_file)
File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 1468, in __init__
self.exprs = check_exprs(parser.exprs)
File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 958, in check_exprs
check_alternate(expr, info)
File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 830, in check_alternate
% (name, key, types_seen[qtype]))
KeyError: 'QTYPE_QSTRING'

This happens because the previously-seen conflicting member ('one') can't be found at types_seen[qtype], but at types_seen['QTYPE_BOOL'].

Fix the bug by moving the error check to the same loop that adds new items to types_seen, raising an exception if types_seen[qt] is already set.

Add two additional test cases that can detect the bug.

Message-Id: <[email protected]>

---
 scripts/qapi.py                                       | 8 ++++----
 tests/Makefile.include                                | 2 ++
 tests/qapi-schema/alternate-conflict-bool-string.err  | 1 +
 tests/qapi-schema/alternate-conflict-bool-string.exit | 1 +
 tests/qapi-schema/alternate-conflict-bool-string.json | 4 ++++
 tests/qapi-schema/alternate-conflict-bool-string.out  | 0
 tests/qapi-schema/alternate-conflict-num-string.err   | 1 +
 tests/qapi-schema/alternate-conflict-num-string.exit  | 1 +
 tests/qapi-schema/alternate-conflict-num-string.json  | 4 ++++
 tests/qapi-schema/alternate-conflict-num-string.out   | 0
 10 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.err
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.exit
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.json
 create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.out
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.err
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.exit
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.json
 create mode 100644 tests/qapi-schema/alternate-conflict-num-string.out
scripts/qapi.py +4 -4
index 8aa2775f12..3693b520da 100644
@@ -825,11 +825,11 @@ def check_alternate(expr, info):
             else:
                 conflicting.add('QTYPE_QNUM')
                 conflicting.add('QTYPE_QBOOL')
-        if conflicting & set(types_seen):
-            raise QAPISemError(info, "Alternate '%s' member '%s' can't "
-                               "be distinguished from member '%s'"
-                               % (name, key, types_seen[qtype]))
         for qt in conflicting:
+            if qt in types_seen:
+                raise QAPISemError(info, "Alternate '%s' member '%s' can't "
+                                   "be distinguished from member '%s'"
+                                   % (name, key, types_seen[qt]))
             types_seen[qt] = key
 
 
tests/Makefile.include +2 -0
index f08b7418f0..00af45ca85 100644
@@ -376,6 +376,8 @@ qapi-schema += alternate-conflict-dict.json
 qapi-schema += alternate-conflict-enum-bool.json
 qapi-schema += alternate-conflict-enum-int.json
 qapi-schema += alternate-conflict-string.json
+qapi-schema += alternate-conflict-bool-string.json
+qapi-schema += alternate-conflict-num-string.json
 qapi-schema += alternate-empty.json
 qapi-schema += alternate-nested.json
 qapi-schema += alternate-unknown.json
tests/qapi-schema/alternate-conflict-bool-string.err new file +1 -0
new file mode 100644
index 0000000000..e52fee7620
@@ -0,0 +1 @@
+tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-bool-string.exit new file +1 -0
new file mode 100644
index 0000000000..d00491fd7e
@@ -0,0 +1 @@
+1
tests/qapi-schema/alternate-conflict-bool-string.json new file +4 -0
new file mode 100644
index 0000000000..0544de10f3
@@ -0,0 +1,4 @@
+# alternate branches of 'str' type conflict with all scalar types
+{ 'alternate': 'Alt',
+  'data': { 'one': 'bool',
+            'two': 'str' } }
tests/qapi-schema/alternate-conflict-bool-string.out new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/qapi-schema/alternate-conflict-num-string.err new file +1 -0
new file mode 100644
index 0000000000..5ba3827dd1
@@ -0,0 +1 @@
+tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-num-string.exit new file +1 -0
new file mode 100644
index 0000000000..d00491fd7e
@@ -0,0 +1 @@
+1
tests/qapi-schema/alternate-conflict-num-string.json new file +4 -0
new file mode 100644
index 0000000000..ae901449af
@@ -0,0 +1,4 @@
+# alternate branches of 'str' type conflict with all scalar types
+{ 'alternate': 'Alt',
+  'data': { 'one': 'number',
+            'two': 'str' } }
tests/qapi-schema/alternate-conflict-num-string.out new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
Signature · 1 line
2.13.5
#2 lore raw

[Qemu-devel] [PULL v2 03/47] qobject: Explain how QNum works, and why

In reply to Markus Armbruster

Message-Id: <[email protected]>

[Comment typos fixed]
---
 include/qapi/qmp/qnum.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
include/qapi/qmp/qnum.h +21 -0
index 09d745c490..d6b0791139 100644
@@ -23,6 +23,27 @@ typedef enum {
     QNUM_DOUBLE
 } QNumKind;
 
+/*
+ * QNum encapsulates how our dialect of JSON fills in the blanks left
+ * by the JSON specification (RFC 7159) regarding numbers.
+ *
+ * Conceptually, we treat number as an abstract type with three
+ * concrete subtypes: floating-point, signed integer, unsigned
+ * integer.  QNum implements this as a discriminated union of double,
+ * int64_t, uint64_t.
+ *
+ * The JSON parser picks the subtype as follows.  If the number has a
+ * decimal point or an exponent, it is floating-point.  Else if it
+ * fits into int64_t, it's signed integer.  Else if it fits into
+ * uint64_t, it's unsigned integer.  Else it's floating-point.
+ *
+ * Any number can serve as double: qnum_get_double() converts under
+ * the hood.
+ *
+ * An integer can serve as signed / unsigned integer as long as it is
+ * in range: qnum_get_try_int() / qnum_get_try_uint() check range and
+ * convert under the hood.
+ */
 typedef struct QNum {
     QObject base;
     QNumKind kind;
Signature · 1 line
2.13.5
#3 lore raw

[Qemu-devel] [PULL v2 04/47] qdict: Add qdict_put_null() helper, and put it to use

In reply to Markus Armbruster

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

Message-Id: <[email protected]>

[Update to qobject.cocci squashed in, commit message tweaked]
---
 include/qapi/qmp/qdict.h         | 4 +++-
 scripts/coccinelle/qobject.cocci | 3 +++
 target/i386/cpu.c                | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
include/qapi/qmp/qdict.h +3 -1
index 363e431106..6588c7f0c8 100644
@@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj);
 #define qdict_put(qdict, key, obj) \
         qdict_put_obj(qdict, key, QOBJECT(obj))
 
-/* Helpers for int, bool, and string */
+/* Helpers for int, bool, null, and string */
 #define qdict_put_int(qdict, key, value) \
         qdict_put(qdict, key, qnum_from_int(value))
 #define qdict_put_bool(qdict, key, value) \
         qdict_put(qdict, key, qbool_from_bool(value))
 #define qdict_put_str(qdict, key, value) \
         qdict_put(qdict, key, qstring_from_str(value))
+#define qdict_put_null(qdict, key) \
+        qdict_put(qdict, key, qnull())
 
 /* High level helpers */
 double qdict_get_double(const QDict *qdict, const char *key);
scripts/coccinelle/qobject.cocci +3 -0
index c518caf7b1..1120eb1a42 100644
@@ -20,6 +20,9 @@ expression Obj, Key, E;
 |
 - qdict_put(Obj, Key, qstring_from_str(E));
 + qdict_put_str(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qnull());
++ qdict_put_null(Obj, Key);
 )
 
 // Use QList macros where they make sense
target/i386/cpu.c +2 -2
index ddc45abd70..bec2009a9c 100644
@@ -2454,7 +2454,7 @@ static QDict *x86_cpu_static_props(void)
 
     d = qdict_new();
     for (i = 0; props[i]; i++) {
-        qdict_put(d, props[i], qnull());
+        qdict_put_null(d, props[i]);
     }
 
     for (w = 0; w < FEATURE_WORDS; w++) {
@@ -2464,7 +2464,7 @@ static QDict *x86_cpu_static_props(void)
             if (!fi->feat_names[bit]) {
                 continue;
             }
-            qdict_put(d, fi->feat_names[bit], qnull());
+            qdict_put_null(d, fi->feat_names[bit]);
         }
     }
 
Signature · 1 line
2.13.5
#4 lore raw

[Qemu-devel] [PULL v2 02/47] tests/qmp-test: Add generic, basic test of query commands

In reply to Markus Armbruster

A command is a query if it has no side effect and yields a result. Such commands are typically named query-FOO, but there are exceptions.

The basic idea is to find candidates with query-qmp-schema, filter out the ones that aren't queries with an explicit blacklist, and test the remaining ones against a QEMU with no special arguments.

The current blacklist is just add-fd.

The test can't do queries with arguments, because it knows nothing about the arguments. No coverage for query-cpu-model-baseline, query-cpu-model-comparison, query-cpu-model-expansion, query-rocker, query-rocker-ports, query-rocker-of-dpa-flows, and query-rocker-of-dpa-groups.

Most tested commands are expected to succeed. The test does not check the return value then.

query-balloon and query-vm-generation-id are expected to fail because they need a virtio-balloon / vmgenid device to succeed, and this test is too dumb to set one up. Could be addressed later.

query-acpi-ospm-status and query-hotpluggable-cpus are expected to fail because they require features provided only by special machine types, and this test is too dumb to set that up. Could also be addressed later.

Several commands may either be functional or stubs that always fail, depending on build configuration. Ideally, the stubs shouldn't be in query-qmp-schema, but that requires QAPI schema compile-time configuration, which we don't have, yet. Until we do, we need to figure out whether a command is a stub. When we have a suitable CONFIG_FOO preprocessor symbol is available, use that. Else, simply blacklist the command for now.

We get basic test coverage for the following commands, except as noted:

qom-list-types
query-acpi-ospm-status (expected to fail)
query-balloon (expected to fail)
query-block
query-block-jobs
query-blockstats
query-chardev
query-chardev-backends
query-command-line-options
query-commands
query-cpu-definitions (blacklisted for now)
query-cpus
query-dump
query-dump-guest-memory-capability
query-events
query-fdsets
query-gic-capabilities (blacklisted for now)
query-hotpluggable-cpus (expected to fail)
query-iothreads
query-kvm
query-machines
query-memdev
query-memory-devices
query-mice
query-migrate
query-migrate-cache-size
query-migrate-capabilities
query-migrate-parameters
query-name
query-named-block-nodes
query-pci (blacklisted for now)
query-qmp-schema
query-rx-filter
query-spice
query-status
query-target
query-tpm
query-tpm-models
query-tpm-types
query-uuid
query-version
query-vm-generation-id (expected to fail)
query-vnc
query-vnc-servers
query-xen-replication-status

Message-Id: <[email protected]>

[Commit message typo fixed]
---
 tests/qmp-test.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 181 insertions(+), 1 deletion(-)
tests/qmp-test.c +181 -1
index 5d0260b2be..e5fb17c201 100644
@@ -15,6 +15,7 @@
 #include "qapi-visit.h"
 #include "qapi/error.h"
 #include "qapi/qobject-input-visitor.h"
+#include "qapi/util.h"
 #include "qapi/visitor.h"
 
 const char common_args[] = "-nodefaults -machine none";
@@ -129,11 +130,190 @@ static void test_qmp_protocol(void)
     qtest_end();
 }
 
+static int query_error_class(const char *cmd)
+{
+    static struct {
+        const char *cmd;
+        int err_class;
+    } fails[] = {
+        /* Success depends on build configuration: */
+#ifndef CONFIG_SPICE
+        "query-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
+#endif
+#ifndef CONFIG_VNC
+        "query-vnc", ERROR_CLASS_GENERIC_ERROR },
+        "query-vnc-servers", ERROR_CLASS_GENERIC_ERROR },
+#endif
+#ifndef CONFIG_REPLICATION
+        "query-xen-replication-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
+#endif
+        /* Likewise, and require special QEMU command-line arguments: */
+        { "query-acpi-ospm-status", ERROR_CLASS_GENERIC_ERROR },
+        { "query-balloon", ERROR_CLASS_DEVICE_NOT_ACTIVE },
+        { "query-hotpluggable-cpus", ERROR_CLASS_GENERIC_ERROR },
+        { "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR },
+        { NULL, -1 }
+    };
+    int i;
+
+    for (i = 0; fails[i].cmd; i++) {
+        if (!strcmp(cmd, fails[i].cmd)) {
+            return fails[i].err_class;
+        }
+    }
+    return -1;
+}
+
+static void test_query(const void *data)
+{
+    const char *cmd = data;
+    int expected_error_class = query_error_class(cmd);
+    QDict *resp, *error;
+    const char *error_class;
+
+    qtest_start(common_args);
+
+    resp = qmp("{ 'execute': %s }", cmd);
+    error = qdict_get_qdict(resp, "error");
+    error_class = error ? qdict_get_str(error, "class") : NULL;
+
+    if (expected_error_class < 0) {
+        g_assert(qdict_haskey(resp, "return"));
+    } else {
+        g_assert(error);
+        g_assert_cmpint(qapi_enum_parse(QapiErrorClass_lookup, error_class,
+                                        QAPI_ERROR_CLASS__MAX, -1,
+                                        &error_abort),
+                        ==, expected_error_class);
+    }
+    QDECREF(resp);
+
+    qtest_end();
+}
+
+static bool query_is_blacklisted(const char *cmd)
+{
+    const char *blacklist[] = {
+        /* Not actually queries: */
+        "add-fd",
+        /* Success depends on target arch: */
+        "query-cpu-definitions",  /* arm, i386, ppc, s390x */
+        "query-gic-capabilities", /* arm */
+        /* Success depends on target-specific build configuration: */
+        "query-pci",              /* CONFIG_PCI */
+        NULL
+    };
+    int i;
+
+    for (i = 0; blacklist[i]; i++) {
+        if (!strcmp(cmd, blacklist[i])) {
+            return true;
+        }
+    }
+    return false;
+}
+
+typedef struct {
+    SchemaInfoList *list;
+    GHashTable *hash;
+} QmpSchema;
+
+static void qmp_schema_init(QmpSchema *schema)
+{
+    QDict *resp;
+    Visitor *qiv;
+    SchemaInfoList *tail;
+
+    qtest_start(common_args);
+    resp = qmp("{ 'execute': 'query-qmp-schema' }");
+
+    qiv = qobject_input_visitor_new(qdict_get(resp, "return"));
+    visit_type_SchemaInfoList(qiv, NULL, &schema->list, &error_abort);
+    visit_free(qiv);
+
+    QDECREF(resp);
+    qtest_end();
+
+    schema->hash = g_hash_table_new(g_str_hash, g_str_equal);
+
+    /* Build @schema: hash table mapping entity name to SchemaInfo */
+    for (tail = schema->list; tail; tail = tail->next) {
+        g_hash_table_insert(schema->hash, tail->value->name, tail->value);
+    }
+}
+
+static SchemaInfo *qmp_schema_lookup(QmpSchema *schema, const char *name)
+{
+    return g_hash_table_lookup(schema->hash, name);
+}
+
+static void qmp_schema_cleanup(QmpSchema *schema)
+{
+    qapi_free_SchemaInfoList(schema->list);
+    g_hash_table_destroy(schema->hash);
+}
+
+static bool object_type_has_mandatory_members(SchemaInfo *type)
+{
+    SchemaInfoObjectMemberList *tail;
+
+    g_assert(type->meta_type == SCHEMA_META_TYPE_OBJECT);
+
+    for (tail = type->u.object.members; tail; tail = tail->next) {
+        if (!tail->value->has_q_default) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+static void add_query_tests(QmpSchema *schema)
+{
+    SchemaInfoList *tail;
+    SchemaInfo *si, *arg_type, *ret_type;
+    const char *test_name;
+
+    /* Test the query-like commands */
+    for (tail = schema->list; tail; tail = tail->next) {
+        si = tail->value;
+        if (si->meta_type != SCHEMA_META_TYPE_COMMAND) {
+            continue;
+        }
+
+        if (query_is_blacklisted(si->name)) {
+            continue;
+        }
+
+        arg_type = qmp_schema_lookup(schema, si->u.command.arg_type);
+        if (object_type_has_mandatory_members(arg_type)) {
+            continue;
+        }
+
+        ret_type = qmp_schema_lookup(schema, si->u.command.ret_type);
+        if (ret_type->meta_type == SCHEMA_META_TYPE_OBJECT
+            && !ret_type->u.object.members) {
+            continue;
+        }
+
+        test_name = g_strdup_printf("qmp/%s", si->name);
+        qtest_add_data_func(test_name, si->name, test_query);
+    }
+}
+
 int main(int argc, char *argv[])
 {
+    QmpSchema schema;
+    int ret;
+
     g_test_init(&argc, &argv, NULL);
 
     qtest_add_func("qmp/protocol", test_qmp_protocol);
+    qmp_schema_init(&schema);
+    add_query_tests(&schema);
 
-    return g_test_run();
+    ret = g_test_run();
+
+    qmp_schema_cleanup(&schema);
+    return ret;
 }
Signature · 1 line
2.13.5
#5 lore raw

[Qemu-devel] [PULL v2 05/47] qlit: move qlit from check-qjson to qobject/

In reply to Markus Armbruster

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

Fix code style issues while at it, to please checkpatch.

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h | 49 +++++++++++++++++++++++++
 qobject/Makefile.objs   |  2 +-
 qobject/qlit.c          | 89 +++++++++++++++++++++++++++++++++++++++++++++
 tests/check-qjson.c     | 96 +------------------------------------------------
 4 files changed, 140 insertions(+), 96 deletions(-)
 create mode 100644 include/qapi/qmp/qlit.h
 create mode 100644 qobject/qlit.c
include/qapi/qmp/qlit.h new file +49 -0
new file mode 100644
index 0000000000..280db5064a
@@ -0,0 +1,49 @@
+/*
+ * Copyright IBM, Corp. 2009
+ * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *  Markus Armbruster <[email protected]>
+ *  Marc-André Lureau <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#ifndef QLIT_H
+#define QLIT_H
+
+#include "qapi-types.h"
+#include "qobject.h"
+
+typedef struct LiteralQDictEntry LiteralQDictEntry;
+typedef struct LiteralQObject LiteralQObject;
+
+struct LiteralQObject {
+    int type;
+    union {
+        int64_t qnum;
+        const char *qstr;
+        LiteralQDictEntry *qdict;
+        LiteralQObject *qlist;
+    } value;
+};
+
+struct LiteralQDictEntry {
+    const char *key;
+    LiteralQObject value;
+};
+
+#define QLIT_QNUM(val) \
+    (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+#define QLIT_QSTR(val) \
+    (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+#define QLIT_QDICT(val) \
+    (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+#define QLIT_QLIST(val) \
+    (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+
+int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
+
+#endif /* QLIT_H */
qobject/Makefile.objs +1 -1
index fc8885c9a4..002d25873a 100644
@@ -1,2 +1,2 @@
-util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o
+util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o qlit.o
 util-obj-y += qjson.o qobject.o json-lexer.o json-streamer.o json-parser.o
qobject/qlit.c new file +89 -0

89 lines not on this page · raw message

tests/check-qjson.c +1 -95

108 lines not on this page · raw message

Signature · 1 line
2.13.5
#6 lore raw

[Qemu-devel] [PULL v2 10/47] qlit: make qlit_equal_qobject() take const arguments

In reply to Markus Armbruster

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

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h | 2 +-
 qobject/qlit.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/qapi/qmp/qlit.h +1 -1
index 35aabbdc9f..fc1a2d845d 100644
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
     { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
+bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
 
 #endif /* QLIT_H */
qobject/qlit.c +1 -1
index a2975bef3f..ae2787ef35 100644
@@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque)
         qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
+bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
     int64_t val;
 
Signature · 1 line
2.13.5
#7 lore raw

[Qemu-devel] [PULL v2 17/47] qapi-schema: Introspection doc is in the wrong section, fix

In reply to Markus Armbruster

Bug: introspection documentation is in section "Tracing commands".

Cause: sub-schema qapi/introspect.json lacks a section header, and therefore goes into whatever section precedes its include.

Fix: add a section header.

Message-Id: <[email protected]>

---
 qapi/introspect.json | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
qapi/introspect.json +4 -2
index cf77ff0669..5b3e6e9d78 100644
@@ -1,7 +1,5 @@
 # -*- Mode: Python -*-
 #
-# QAPI/QMP introspection
-#
 # Copyright (C) 2015 Red Hat, Inc.
 #
 # Authors:
@@ -11,6 +9,10 @@
 # See the COPYING file in the top-level directory.
 
 ##
+# = QMP introspection
+##
+
+##
 # @query-qmp-schema:
 #
 # Command query-qmp-schema exposes the QMP wire ABI as an array of
Signature · 1 line
2.13.5
#8 lore raw

[Qemu-devel] [PULL v2 18/47] qapi-schema: Rocker doc section contains unrelated stuff, fix

In reply to Markus Armbruster

Bug: section "Rocker switch device" starts with the rocker stuff, but then has unrelated stuff, like ReplayMode, xen-load-devices-state, ...

Cause: rocker.json is included in the middle of section "QMP commands".

Fix: include it in a sane place, namely next to the other sub-schemas.

Message-Id: <[email protected]>

---
 qapi-schema.json | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
qapi-schema.json +1 -3
index 3db3d1972f..add4777e9a 100644
@@ -81,6 +81,7 @@
 { 'include': 'qapi/common.json' }
 { 'include': 'qapi/crypto.json' }
 { 'include': 'qapi/block.json' }
+{ 'include': 'qapi/rocker.json' }
 { 'include': 'qapi/event.json' }
 { 'include': 'qapi/trace.json' }
 { 'include': 'qapi/introspect.json' }
@@ -6273,9 +6274,6 @@
 ##
 { 'command': 'rtc-reset-reinjection' }
 
-# Rocker ethernet network switch
-{ 'include': 'qapi/rocker.json' }
-
 ##
 # @ReplayMode:
 #
Signature · 1 line
2.13.5
#9 lore raw

[Qemu-devel] [PULL v2 07/47] qlit: Change compound literals to initializers

In reply to Markus Armbruster

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

The QLIT_QFOO() macros expand into compound literals. Sadly, gcc doesn't recognizes these as constant expressions (clang does), which makes the macros useless for initializing objects with static storage duration.

There is a gcc bug about it:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71713

Change the macros to expand into initializers.

Message-Id: <[email protected]>

[Commit message improved]
---
 include/qapi/qmp/qlit.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/qapi/qmp/qlit.h +4 -4
index a4ad91321b..f1d6eed317 100644
@@ -36,13 +36,13 @@ struct QLitDictEntry {
 };
 
 #define QLIT_QNUM(val) \
-    (QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+    { .type = QTYPE_QNUM, .value.qnum = (val) }
 #define QLIT_QSTR(val) \
-    (QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+    { .type = QTYPE_QSTRING, .value.qstr = (val) }
 #define QLIT_QDICT(val) \
-    (QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+    { .type = QTYPE_QDICT, .value.qdict = (val) }
 #define QLIT_QLIST(val) \
-    (QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+    { .type = QTYPE_QLIST, .value.qlist = (val) }
 
 int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
 
Signature · 1 line
2.13.5
#10 lore raw

[Qemu-devel] [PULL v2 13/47] tests/check-qlit: New, covering qobject/qlit.c

In reply to Markus Armbruster

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

Message-Id: <[email protected]>

[Copyright notice correction squashed in, commit message tweaked]
---
 tests/Makefile.include |  5 +++-
 tests/check-qlit.c     | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 tests/check-qlit.c
tests/Makefile.include +4 -1
index 00af45ca85..fae5715e9c 100644
@@ -43,6 +43,8 @@ check-unit-y += tests/check-qnull$(EXESUF)
 gcov-files-check-qnull-y = qobject/qnull.c
 check-unit-y += tests/check-qjson$(EXESUF)
 gcov-files-check-qjson-y = qobject/qjson.c
+check-unit-y += tests/check-qlit$(EXESUF)
+gcov-files-check-qlit-y = qobject/qlit.c
 check-unit-y += tests/test-qobject-output-visitor$(EXESUF)
 gcov-files-test-qobject-output-visitor-y = qapi/qobject-output-visitor.c
 check-unit-y += tests/test-clone-visitor$(EXESUF)
@@ -541,7 +543,7 @@ GENERATED_FILES += tests/test-qapi-types.h tests/test-qapi-visit.h \
 
 test-obj-y = tests/check-qnum.o tests/check-qstring.o tests/check-qdict.o \
 	tests/check-qlist.o tests/check-qnull.o \
-	tests/check-qjson.o \
+	tests/check-qjson.o tests/check-qlit.o \
 	tests/test-coroutine.o tests/test-string-output-visitor.o \
 	tests/test-string-input-visitor.o tests/test-qobject-output-visitor.o \
 	tests/test-clone-visitor.o \
@@ -575,6 +577,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y)
 tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y)
 tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y)
 tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y)
+tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y)
 tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y)
 tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y)
 
tests/check-qlit.c new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.13.5
#11 lore raw

Re: [Qemu-devel] [PULL v2 13/47] tests/check-qlit: New, covering qobject/qlit.c

Quoted 11 lines · Markus Armbruster

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

Message-Id: <[email protected]>

[Copyright notice correction squashed in, commit message tweaked]
---
 tests/Makefile.include |  5 +++-
 tests/check-qlit.c     | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 tests/check-qlit.c

Adds a new file that is not covered by tests/.gitignore when doing an in-tree build (and is one of our few check-* names that stands out in comparison to the bulk of the tests named test-* or *-test).

Of course, the point may be moot if we take the patch for auto-generating tests/.gitignore on an in-tree build...

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

Re: [Qemu-devel] [PULL v2 13/47] tests/check-qlit: New, covering qobject/qlit.c

Quoted 13 lines · Eric Blake
Quoted 11 lines · Markus Armbruster

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

Message-Id: <[email protected]>

[Copyright notice correction squashed in, commit message tweaked]
---
 tests/Makefile.include |  5 +++-
 tests/check-qlit.c     | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 tests/check-qlit.c
Quoted 2 lines

Adds a new file that is not covered by tests/.gitignore when doing an in-tree build

Easy enough to fix.

Quoted 2 lines

(and is one of our few check-* names that stands out in
comparison to the bulk of the tests named test-* or *-test).

It's called check-lit.c because to match the related tests check-qlit.c check-qdict.c check-qnull.c check-qstring.c check-qjson.c check-qnum.c check-qlist.c.

Quoted 2 lines

Of course, the point may be moot if we take the patch for auto-generating tests/.gitignore on an in-tree build...

#13 lore raw

[Qemu-devel] [PULL v2 14/47] qlit: Tighten QLit dict vs QDict comparison

In reply to Markus Armbruster

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

We check that all members of the QLit dictionary are also in the QDict. We neglect to check the other direction.

Comparing the number of members suffices, because QDict can't contain duplicate members, and putting duplicates in a QLit is a programming error.

Message-Id: <[email protected]>

[Commit message improved]
---
 qobject/qlit.c     | 37 +++++++++++++++++++++++--------------
 tests/check-qlit.c |  7 +++++++
 2 files changed, 30 insertions(+), 14 deletions(-)
qobject/qlit.c +23 -14
index b1d9146220..dc0015f76c 100644
@@ -41,6 +41,27 @@ static void compare_helper(QObject *obj, void *opaque)
         qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
+static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
+{
+    int i;
+
+    for (i = 0; lhs->value.qdict[i].key; i++) {
+        QObject *obj = qdict_get(qdict, lhs->value.qdict[i].key);
+
+        if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
+            return false;
+        }
+    }
+
+    /* Note: the literal qdict must not contain duplicates, this is
+     * considered a programming error and it isn't checked here. */
+    if (qdict_size(qdict) != i) {
+        return false;
+    }
+
+    return true;
+}
+
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
     if (!rhs || lhs->type != qobject_type(rhs)) {
@@ -55,20 +76,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
     case QTYPE_QSTRING:
         return (strcmp(lhs->value.qstr,
                        qstring_get_str(qobject_to_qstring(rhs))) == 0);
-    case QTYPE_QDICT: {
-        int i;
-
-        for (i = 0; lhs->value.qdict[i].key; i++) {
-            QObject *obj = qdict_get(qobject_to_qdict(rhs),
-                                     lhs->value.qdict[i].key);
-
-            if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
-                return false;
-            }
-        }
-
-        return true;
-    }
+    case QTYPE_QDICT:
+        return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
     case QTYPE_QLIST: {
         QListCompareHelper helper;
 
tests/check-qlit.c +7 -0
index d2422bbaf0..d2ecc200d3 100644
@@ -28,6 +28,11 @@ static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
     { },
 }));
 
+static QLitObject qlit_foo = QLIT_QDICT(((QLitDictEntry[]) {
+    { "foo", QLIT_QNUM(42) },
+    { },
+}));
+
 static QObject *make_qobject(void)
 {
     QDict *qdict = qdict_new();
@@ -51,6 +56,8 @@ static void qlit_equal_qobject_test(void)
 
     g_assert(qlit_equal_qobject(&qlit, qobj));
 
+    g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
+
     qobject_decref(qobj);
 }
 
Signature · 1 line
2.13.5
#14 lore raw

[Qemu-devel] [PULL v2 28/47] qapi-schema: Fold event.json back into qapi-schema.json

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 Makefile         |   2 +-
 qapi-schema.json | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 qapi/event.json  | 138 -------------------------------------------------------
 3 files changed, 134 insertions(+), 140 deletions(-)
 delete mode 100644 qapi/event.json
Makefile +1 -1
index 3dde210662..337a1f6f9b 100644
@@ -412,7 +412,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
                $(SRC_PATH)/qapi/char.json \
                $(SRC_PATH)/qapi/crypto.json \
-               $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
+               $(SRC_PATH)/qapi/introspect.json \
                $(SRC_PATH)/qapi/migration.json \
                $(SRC_PATH)/qapi/net.json \
                $(SRC_PATH)/qapi/rocker.json \
qapi-schema.json +133 -1

176 lines not on this page · raw message

qapi/event.json deleted +0 -138

138 lines not on this page · raw message

Signature · 1 line
2.13.5
#15 lore raw

[Qemu-devel] [PULL v2 30/47] qapi-schema: Move queries from common.json to qapi-schema.json

In reply to Markus Armbruster

query-version and query-commands are in common.json for no good reason. Several similar queries are in qapi-schema.json. Move them there.

Message-Id: <[email protected]>

---
 qapi-schema.json | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/common.json | 103 -------------------------------------------------------
 2 files changed, 103 insertions(+), 103 deletions(-)
qapi-schema.json +103 -0
index 80c15dade3..7a393ec3e9 100644
@@ -119,6 +119,109 @@
 { 'command': 'qmp_capabilities' }
 
 ##
+# @VersionTriple:
+#
+# A three-part version number.
+#
+# @major:  The major version number.
+#
+# @minor:  The minor version number.
+#
+# @micro:  The micro version number.
+#
+# Since: 2.4
+##
+{ 'struct': 'VersionTriple',
+  'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} }
+
+
+##
+# @VersionInfo:
+#
+# A description of QEMU's version.
+#
+# @qemu:        The version of QEMU.  By current convention, a micro
+#               version of 50 signifies a development branch.  A micro version
+#               greater than or equal to 90 signifies a release candidate for
+#               the next minor version.  A micro version of less than 50
+#               signifies a stable release.
+#
+# @package:     QEMU will always set this field to an empty string.  Downstream
+#               versions of QEMU should set this to a non-empty string.  The
+#               exact format depends on the downstream however it highly
+#               recommended that a unique name is used.
+#
+# Since: 0.14.0
+##
+{ 'struct': 'VersionInfo',
+  'data': {'qemu': 'VersionTriple', 'package': 'str'} }
+
+##
+# @query-version:
+#
+# Returns the current version of QEMU.
+#
+# Returns:  A @VersionInfo object describing the current version of QEMU.
+#
+# Since: 0.14.0
+#
+# Example:
+#
+# -> { "execute": "query-version" }
+# <- {
+#       "return":{
+#          "qemu":{
+#             "major":0,
+#             "minor":11,
+#             "micro":5
+#          },
+#          "package":""
+#       }
+#    }
+#
+##
+{ 'command': 'query-version', 'returns': 'VersionInfo' }
+
+##
+# @CommandInfo:
+#
+# Information about a QMP command
+#
+# @name: The command name
+#
+# Since: 0.14.0
+##
+{ 'struct': 'CommandInfo', 'data': {'name': 'str'} }
+
+##
+# @query-commands:
+#
+# Return a list of supported QMP commands by this server
+#
+# Returns: A list of @CommandInfo for all supported commands
+#
+# Since: 0.14.0
+#
+# Example:
+#
+# -> { "execute": "query-commands" }
+# <- {
+#      "return":[
+#         {
+#            "name":"query-balloon"
+#         },
+#         {
+#            "name":"system_powerdown"
+#         }
+#      ]
+#    }
+#
+# Note: This example has been shortened as the real response is too long.
+#
+##
+{ 'command': 'query-commands', 'returns': ['CommandInfo'] }
+
+##
 # @LostTickPolicy:
 #
 # Policy for handling lost ticks in timer devices.
qapi/common.json +0 -103

109 lines not on this page · raw message

Signature · 1 line
2.13.5
#16 lore raw

[Qemu-devel] [PULL v2 25/47] qapi-schema: Collect transaction stuff in qapi/transaction.json

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 MAINTAINERS           |   1 +
 Makefile              |   1 +
 qapi-schema.json      | 151 +----------------------------------------------
 qapi/transaction.json | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 150 deletions(-)
 create mode 100644 qapi/transaction.json
MAINTAINERS +1 -0
index baa9859b4a..8cebd798ef 100644
@@ -1231,6 +1231,7 @@ S: Supported
 F: blockdev.c
 F: block/qapi.c
 F: qapi/block*.json
+F: qapi/transaction.json
 T: git git://repo.or.cz/qemu/armbru.git block-next
 
 Dirty Bitmaps
Makefile +1 -0
index 18cf670833..ea6de37197 100644
@@ -419,6 +419,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/run-state.json \
                $(SRC_PATH)/qapi/sockets.json \
                $(SRC_PATH)/qapi/trace.json \
+               $(SRC_PATH)/qapi/transaction.json \
                $(SRC_PATH)/qapi/ui.json
 
 qapi-types.c qapi-types.h :\
qapi-schema.json +1 -150

163 lines not on this page · raw message

qapi/transaction.json new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.13.5
#17 lore raw

[Qemu-devel] [PULL v2 11/47] qlit: add QLIT_QNULL and QLIT_BOOL

In reply to Markus Armbruster

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

As they are going to be used in the following patches.

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h | 5 +++++
 qobject/qlit.c          | 4 ++++
 2 files changed, 9 insertions(+)
include/qapi/qmp/qlit.h +5 -0
index fc1a2d845d..b18406bce9 100644
@@ -23,6 +23,7 @@ typedef struct QLitObject QLitObject;
 struct QLitObject {
     int type;
     union {
+        bool qbool;
         int64_t qnum;
         const char *qstr;
         QLitDictEntry *qdict;
@@ -35,6 +36,10 @@ struct QLitDictEntry {
     QLitObject value;
 };
 
+#define QLIT_QNULL \
+    { .type = QTYPE_QNULL }
+#define QLIT_QBOOL(val) \
+    { .type = QTYPE_QBOOL, .value.qbool = (val) }
 #define QLIT_QNUM(val) \
     { .type = QTYPE_QNUM, .value.qnum = (val) }
 #define QLIT_QSTR(val) \
qobject/qlit.c +4 -0
index ae2787ef35..07ad6b05e8 100644
@@ -50,6 +50,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
     }
 
     switch (lhs->type) {
+    case QTYPE_QBOOL:
+        return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
     case QTYPE_QNUM:
         g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
         return lhs->value.qnum == val;
@@ -81,6 +83,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 
         return helper.result;
     }
+    case QTYPE_QNULL:
+        return true;
     default:
         break;
     }
Signature · 1 line
2.13.5
#18 lore raw

[Qemu-devel] [PULL v2 26/47] qapi-schema: Collect TPM stuff in qapi/tpm.json

In reply to Markus Armbruster

Sadly, we don't have a TPM maintainer, not even a MAINTAINERS entry. Create one, and mark it orphaned.

Message-Id: <[email protected]>

---
 MAINTAINERS      |   8 ++++
 Makefile         |   1 +
 qapi-schema.json | 132 +----------------------------------------------------
 qapi/tpm.json    | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+), 131 deletions(-)
 create mode 100644 qapi/tpm.json
MAINTAINERS +8 -0
index 8cebd798ef..5ec945c9af 100644
@@ -1486,6 +1486,14 @@ F: scripts/tracetool/
 F: docs/tracing.txt
 T: git git://github.com/stefanha/qemu.git tracing
 
+TPM
+S: Orphan
+F: tpm.c
+F: hw/tpm/*
+F: include/hw/acpi/tpm.h
+F: include/sysemu/tpm*
+F: qapi/tpm.json
+
 Checkpatch
 S: Odd Fixes
 F: scripts/checkpatch.pl
Makefile +1 -0
index ea6de37197..3dde210662 100644
@@ -418,6 +418,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/rocker.json \
                $(SRC_PATH)/qapi/run-state.json \
                $(SRC_PATH)/qapi/sockets.json \
+               $(SRC_PATH)/qapi/tpm.json \
                $(SRC_PATH)/qapi/trace.json \
                $(SRC_PATH)/qapi/transaction.json \
                $(SRC_PATH)/qapi/ui.json
qapi-schema.json +1 -131

144 lines not on this page · raw message

qapi/tpm.json new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
2.13.5
#19 lore raw

[Qemu-devel] [PULL v2 42/47] qapi: Avoid unnecessary use of enum lookup table's sentinel

In reply to Markus Armbruster

Currently, the FOO_lookup[] generated for QAPI enum types are terminated by a NULL sentinel.

A future patch will generate enums with "holes". NULL-termination will cease to work then.

To prepare for that, replace "have we reached the sentinel?" predicates by "have we reached the FOO__MAX value?" predicates.

Message-Id: <[email protected]>

---
 monitor.c                          | 4 ++--
 tests/test-qobject-input-visitor.c | 2 +-
 tests/test-string-input-visitor.c  | 2 +-
 ui/input-legacy.c                  | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
monitor.c +2 -2
index 135ec2de8f..86438f4b75 100644
@@ -3249,7 +3249,7 @@ void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
     }
     len = strlen(str);
     readline_set_completion_index(rs, len);
-    for (i = 0; NetClientDriver_lookup[i]; i++) {
+    for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
         add_completion_option(rs, str, NetClientDriver_lookup[i]);
     }
 }
@@ -3537,7 +3537,7 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
         return;
     }
     readline_set_completion_index(rs, strlen(str));
-    for (i = 0; WatchdogExpirationAction_lookup[i]; i++) {
+    for (i = 0; i < WATCHDOG_EXPIRATION_ACTION__MAX; i++) {
         add_completion_option(rs, str, WatchdogExpirationAction_lookup[i]);
     }
 }
tests/test-qobject-input-visitor.c +1 -1
index bcf02617dc..5bbfb65a02 100644
@@ -382,7 +382,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
     Visitor *v;
     EnumOne i;
 
-    for (i = 0; EnumOne_lookup[i]; i++) {
+    for (i = 0; i < ENUM_ONE__MAX; i++) {
         EnumOne res = -1;
 
         v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]);
tests/test-string-input-visitor.c +1 -1
index 79313a7f7a..e7a7b80c92 100644
@@ -279,7 +279,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
     Visitor *v;
     EnumOne i;
 
-    for (i = 0; EnumOne_lookup[i]; i++) {
+    for (i = 0; i < ENUM_ONE__MAX; i++) {
         EnumOne res = -1;
 
         v = visitor_input_test_init(data, EnumOne_lookup[i]);
ui/input-legacy.c +1 -1
index 7159747404..a5f1e829c3 100644
@@ -61,7 +61,7 @@ int index_from_key(const char *key, size_t key_length)
 {
     int i;
 
-    for (i = 0; QKeyCode_lookup[i] != NULL; i++) {
+    for (i = 0; i < Q_KEY_CODE__MAX; i++) {
         if (!strncmp(key, QKeyCode_lookup[i], key_length) &&
             !QKeyCode_lookup[i][key_length]) {
             break;
Signature · 1 line
2.13.5
#20 lore raw

[Qemu-devel] [PULL v2 08/47] qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject()

In reply to Markus Armbruster

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

compare_litqobj_to_qobj() lacks a qlit_ prefix. Moreover, "compare" suggests -1, 0, +1 for less than, equal and greater than. The function actually returns non-zero for equal, zero for unequal. Rename to qlit_equal_qobject().

Its return type will be cleaned up in the next patch.

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h |  2 +-
 qobject/qlit.c          |  6 +++---
 tests/check-qjson.c     | 14 +++++++-------
 3 files changed, 11 insertions(+), 11 deletions(-)
include/qapi/qmp/qlit.h +1 -1
index f1d6eed317..5a180477c8 100644
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
     { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
+int qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H */
qobject/qlit.c +3 -3
index 262d64988d..0c4101898d 100644
@@ -38,10 +38,10 @@ static void compare_helper(QObject *obj, void *opaque)
     }
 
     helper->result =
-        compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
+        qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
+int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
 {
     int64_t val;
 
@@ -63,7 +63,7 @@ int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
             QObject *obj = qdict_get(qobject_to_qdict(rhs),
                                      lhs->value.qdict[i].key);
 
-            if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) {
+            if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
                 return 0;
             }
         }
tests/check-qjson.c +7 -7
index 82b3681327..e5ca273cbc 100644
@@ -1094,13 +1094,13 @@ static void simple_dict(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
         qobject_decref(obj);
         QDECREF(str);
     }
@@ -1203,13 +1203,13 @@ static void simple_list(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
         qobject_decref(obj);
         QDECREF(str);
     }
@@ -1265,13 +1265,13 @@ static void simple_whitespace(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
         qobject_decref(obj);
         QDECREF(str);
@@ -1295,7 +1295,7 @@ static void simple_varargs(void)
     g_assert(embedded_obj != NULL);
 
     obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
-    g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1);
+    g_assert(qlit_equal_qobject(&decoded, obj) == 1);
 
     qobject_decref(obj);
 }
Signature · 1 line
2.13.5
#21 lore raw

[Qemu-devel] [PULL v2 16/47] qapi-schema: Document how generated documentation is ordered

In reply to Markus Armbruster

Documentation generated with qapi2texi.py is in source order, with included sub-schemas inserted at the first include directive (subsequent include directives have no effect). To get a sane and stable order, it's best to include each sub-schema just once, or include it first in qapi-schema.json. Document that.

While there, drop a few redundant comments.

Message-Id: <[email protected]>

---
 qapi-schema.json | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
qapi-schema.json +6 -11
index 802ea53d00..3db3d1972f 100644
@@ -72,22 +72,17 @@
         'q_obj_CpuInfo-base'    # CPU, visible through query-cpu
     ] } }
 
-# QAPI common definitions
+# Documentation generated with qapi2texi.py is in source order, with
+# included sub-schemas inserted at the first include directive
+# (subsequent include directives have no effect).  To get a sane and
+# stable order, it's best to include each sub-schema just once, or
+# include it first in qapi-schema.json.
+
 { 'include': 'qapi/common.json' }
-
-# QAPI crypto definitions
 { 'include': 'qapi/crypto.json' }
-
-# QAPI block definitions
 { 'include': 'qapi/block.json' }
-
-# QAPI event definitions
 { 'include': 'qapi/event.json' }
-
-# Tracing commands
 { 'include': 'qapi/trace.json' }
-
-# QAPI introspection
 { 'include': 'qapi/introspect.json' }
 
 ##
Signature · 1 line
2.13.5
#22 lore raw

[Qemu-devel] [PULL v2 32/47] qapi: Update qapi-code-gen.txt examples to match current code

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 docs/devel/qapi-code-gen.txt | 47 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 9 deletions(-)
docs/devel/qapi-code-gen.txt +38 -9
index 9903ac4c19..ae05327869 100644
@@ -957,6 +957,8 @@ Example:
 
     typedef struct UserDefOneList UserDefOneList;
 
+    typedef struct q_obj_my_command_arg q_obj_my_command_arg;
+
     struct UserDefOne {
         int64_t integer;
         bool has_string;
@@ -972,6 +974,10 @@ Example:
 
     void qapi_free_UserDefOneList(UserDefOneList *obj);
 
+    struct q_obj_my_command_arg {
+        UserDefOneList *arg1;
+    };
+
     #endif
     $ cat qapi-generated/example-qapi-types.c
 [Uninteresting stuff omitted...]
@@ -1036,6 +1042,8 @@ Example:
     void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp);
     void visit_type_UserDefOneList(Visitor *v, const char *name, UserDefOneList **obj, Error **errp);
 
+    void visit_type_q_obj_my_command_arg_members(Visitor *v, q_obj_my_command_arg *obj, Error **errp);
+
     #endif
     $ cat qapi-generated/example-qapi-visit.c
 [Uninteresting stuff omitted...]
@@ -1104,6 +1112,9 @@ Example:
             }
         }
 
+        if (!err) {
+            visit_check_list(v, &err);
+        }
         visit_end_list(v, (void **)obj);
         if (err && visit_is_input(v)) {
             qapi_free_UserDefOneList(*obj);
@@ -1113,6 +1124,19 @@ Example:
         error_propagate(errp, err);
     }
 
+    void visit_type_q_obj_my_command_arg_members(Visitor *v, q_obj_my_command_arg *obj, Error **errp)
+    {
+        Error *err = NULL;
+
+        visit_type_UserDefOneList(v, "arg1", &obj->arg1, &err);
+        if (err) {
+            goto out;
+        }
+
+    out:
+        error_propagate(errp, err);
+    }
+
 === scripts/qapi-commands.py ===
 
 Used to generate the marshaling/dispatch functions for the commands
@@ -1145,9 +1169,12 @@ Example:
 
     #include "example-qapi-types.h"
     #include "qapi/qmp/qdict.h"
+    #include "qapi/qmp/dispatch.h"
     #include "qapi/error.h"
 
+    void example_qmp_init_marshal(QmpCommandList *cmds);
     UserDefOne *qmp_my_command(UserDefOneList *arg1, Error **errp);
+    void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp);
 
     #endif
     $ cat qapi-generated/example-qmp-marshal.c
@@ -1170,19 +1197,19 @@ Example:
         visit_free(v);
     }
 
-    static void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
+    void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
     {
         Error *err = NULL;
         UserDefOne *retval;
         Visitor *v;
-        UserDefOneList *arg1 = NULL;
+        q_obj_my_command_arg arg = {0};
 
         v = qobject_input_visitor_new(QOBJECT(args));
         visit_start_struct(v, NULL, NULL, 0, &err);
         if (err) {
             goto out;
         }
-        visit_type_UserDefOneList(v, "arg1", &arg1, &err);
+        visit_type_q_obj_my_command_arg_members(v, &arg, &err);
         if (!err) {
             visit_check_struct(v, &err);
         }
@@ -1191,7 +1218,7 @@ Example:
             goto out;
         }
 
-        retval = qmp_my_command(arg1, &err);
+        retval = qmp_my_command(arg.arg1, &err);
         if (err) {
             goto out;
         }
@@ -1203,17 +1230,18 @@ Example:
         visit_free(v);
         v = qapi_dealloc_visitor_new();
         visit_start_struct(v, NULL, NULL, 0, NULL);
-        visit_type_UserDefOneList(v, "arg1", &arg1, NULL);
+        visit_type_q_obj_my_command_arg_members(v, &arg, NULL);
         visit_end_struct(v, NULL);
         visit_free(v);
     }
 
-    static void qmp_init_marshal(void)
+    void example_qmp_init_marshal(QmpCommandList *cmds)
     {
-        qmp_register_command("my-command", qmp_marshal_my_command, QCO_NO_OPTIONS);
-    }
+        QTAILQ_INIT(cmds);
 
-    qapi_init(qmp_init_marshal);
+        qmp_register_command(cmds, "my-command",
+                             qmp_marshal_my_command, QCO_NO_OPTIONS);
+    }
 
 === scripts/qapi-event.py ===
 
@@ -1258,6 +1286,7 @@ Example:
         QDict *qmp;
         Error *err = NULL;
         QMPEventFuncEmit emit;
+
         emit = qmp_event_get_func_emit();
         if (!emit) {
             return;
Signature · 1 line
2.13.5
#23 lore raw

[Qemu-devel] [PULL v2 33/47] qapi: Drop superfluous qapi_enum_parse() parameter max

In reply to Markus Armbruster

The lookup tables have a sentinel, no need to make callers pass their size.

Message-Id: <[email protected]>

[Rebased, commit message corrected]
---
 block.c                  |  1 -
 block/file-posix.c       |  7 +++----
 block/file-win32.c       |  2 +-
 block/gluster.c          |  6 ++----
 block/parallels.c        |  3 ++-
 block/qcow2.c            |  6 ++----
 blockdev.c               |  1 -
 hmp.c                    |  2 +-
 include/qapi/util.h      |  2 +-
 migration/global_state.c |  3 +--
 qapi/qapi-util.c         |  4 ++--
 qemu-img.c               |  3 +--
 qemu-nbd.c               |  1 -
 tests/qmp-test.c         |  3 +--
 tests/test-qapi-util.c   | 15 +++++----------
 15 files changed, 22 insertions(+), 37 deletions(-)
block.c +0 -1
index 3308814bba..af48b0d26b 100644
@@ -1335,7 +1335,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
         BlockdevDetectZeroesOptions value =
             qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
                             detect_zeroes,
-                            BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
                             BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                             &local_err);
         if (local_err) {
block/file-posix.c +3 -4
index cb3bfce147..97e8a92e23 100644
@@ -439,7 +439,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
                   ? BLOCKDEV_AIO_OPTIONS_NATIVE
                   : BLOCKDEV_AIO_OPTIONS_THREADS;
     aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
-                          BLOCKDEV_AIO_OPTIONS__MAX, aio_default, &local_err);
+                          aio_default, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
@@ -448,7 +448,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
 
     locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
-                              ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err);
+                              ON_OFF_AUTO_AUTO, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
@@ -1975,8 +1975,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
     nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
     prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
-                               PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
-                               &local_err);
+                               PREALLOC_MODE_OFF, &local_err);
     g_free(buf);
     if (local_err) {
         error_propagate(errp, local_err);
block/file-win32.c +1 -1
index 4706335cff..978d8058fe 100644
@@ -304,7 +304,7 @@ static bool get_aio_option(QemuOpts *opts, int flags, Error **errp)
     aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
                                               : BLOCKDEV_AIO_OPTIONS_THREADS;
     aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
-                          BLOCKDEV_AIO_OPTIONS__MAX, aio_default, errp);
+                          aio_default, errp);
 
     switch (aio) {
     case BLOCKDEV_AIO_OPTIONS_NATIVE:
block/gluster.c +2 -4
index 3064a45047..8367e806d0 100644
@@ -544,8 +544,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
         if (!strcmp(ptr, "tcp")) {
             ptr = "inet";       /* accept legacy "tcp" */
         }
-        type = qapi_enum_parse(SocketAddressType_lookup, ptr,
-                               SOCKET_ADDRESS_TYPE__MAX, -1, NULL);
+        type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL);
         if (type != SOCKET_ADDRESS_TYPE_INET
             && type != SOCKET_ADDRESS_TYPE_UNIX) {
             error_setg(&local_err,
@@ -1002,8 +1001,7 @@ static int qemu_gluster_create(const char *filename,
                           BDRV_SECTOR_SIZE);
 
     tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-    prealloc = qapi_enum_parse(PreallocMode_lookup, tmp,
-                               PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
+    prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
                                &local_err);
     g_free(tmp);
     if (local_err) {
block/parallels.c +2 -1
index e1e06d23cc..eb92366e51 100644
@@ -697,7 +697,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
     s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
     buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
     s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
-            PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err);
+                                       PRL_PREALLOC_MODE_FALLOCATE,
+                                       &local_err);
     g_free(buf);
     if (local_err != NULL) {
         goto fail_options;
block/qcow2.c +2 -4
index a3679c69e8..470a0dedaa 100644
@@ -2917,8 +2917,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
     }
     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
     prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
-                               PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
-                               &local_err);
+                               PREALLOC_MODE_OFF, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
@@ -3608,8 +3607,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
 
     optstr = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
     prealloc = qapi_enum_parse(PreallocMode_lookup, optstr,
-                               PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
-                               &local_err);
+                               PREALLOC_MODE_OFF, &local_err);
     g_free(optstr);
     if (local_err) {
         goto err;
blockdev.c +0 -1
index 02cd69bc21..722a61e3fb 100644
@@ -440,7 +440,6 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
         *detect_zeroes =
             qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
                             qemu_opt_get(opts, "detect-zeroes"),
-                            BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
                             BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                             &local_error);
         if (local_error) {
hmp.c +1 -1
index fd80dce758..03c1a783b6 100644
@@ -1742,7 +1742,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
         if (read_only) {
             read_only_mode =
                 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
-                                read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
+                                read_only,
                                 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
             if (err) {
                 hmp_handle_error(mon, &err);
include/qapi/util.h +1 -1
index 7436ed815c..4eb8a3fe2f 100644
@@ -12,7 +12,7 @@
 #define QAPI_UTIL_H
 
 int qapi_enum_parse(const char * const lookup[], const char *buf,
-                    int max, int def, Error **errp);
+                    int def, Error **errp);
 
 int parse_qapi_name(const char *name, bool complete);
 
migration/global_state.c +1 -2
index dcbbcb28be..88c55f8cdb 100644
@@ -89,8 +89,7 @@ static int global_state_post_load(void *opaque, int version_id)
     s->received = true;
     trace_migrate_global_state_post_load(runstate);
 
-    r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX,
-                                -1, &local_err);
+    r = qapi_enum_parse(RunState_lookup, runstate, -1, &local_err);
 
     if (r == -1) {
         if (local_err) {
qapi/qapi-util.c +2 -2
index 46eda7d196..ee7594ff19 100644
@@ -16,7 +16,7 @@
 #include "qapi/util.h"
 
 int qapi_enum_parse(const char * const lookup[], const char *buf,
-                    int max, int def, Error **errp)
+                    int def, Error **errp)
 {
     int i;
 
@@ -24,7 +24,7 @@ int qapi_enum_parse(const char * const lookup[], const char *buf,
         return def;
     }
 
-    for (i = 0; i < max; i++) {
+    for (i = 0; lookup[i]; i++) {
         if (!strcmp(buf, lookup[i])) {
             return i;
         }
qemu-img.c +1 -2
index 56ef49e214..611ab7ddf3 100644
@@ -3491,8 +3491,7 @@ static int img_resize(int argc, char **argv)
             break;
         case OPTION_PREALLOCATION:
             prealloc = qapi_enum_parse(PreallocMode_lookup, optarg,
-                                       PREALLOC_MODE__MAX, PREALLOC_MODE__MAX,
-                                       NULL);
+                                       PREALLOC_MODE__MAX, NULL);
             if (prealloc == PREALLOC_MODE__MAX) {
                 error_report("Invalid preallocation mode '%s'", optarg);
                 return 1;
qemu-nbd.c +0 -1
index 27164b8205..96e10d62dc 100644
@@ -641,7 +641,6 @@ int main(int argc, char **argv)
             detect_zeroes =
                 qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
                                 optarg,
-                                BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
                                 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                                 &local_err);
             if (local_err) {
tests/qmp-test.c +1 -2
index e5fb17c201..ec99814f79 100644
@@ -182,8 +182,7 @@ static void test_query(const void *data)
     } else {
         g_assert(error);
         g_assert_cmpint(qapi_enum_parse(QapiErrorClass_lookup, error_class,
-                                        QAPI_ERROR_CLASS__MAX, -1,
-                                        &error_abort),
+                                        -1, &error_abort),
                         ==, expected_error_class);
     }
     QDECREF(resp);
tests/test-qapi-util.c +5 -10
index e8697577a5..d72ee8c4e7 100644
@@ -20,25 +20,20 @@ static void test_qapi_enum_parse(void)
     Error *err = NULL;
     int ret;
 
-    ret = qapi_enum_parse(QType_lookup, NULL, QTYPE__MAX, QTYPE_NONE,
-                          &error_abort);
+    ret = qapi_enum_parse(QType_lookup, NULL, QTYPE_NONE, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE_NONE);
 
-    ret = qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1,
-                          NULL);
+    ret = qapi_enum_parse(QType_lookup, "junk", -1, NULL);
     g_assert_cmpint(ret, ==, -1);
 
-    ret = qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1,
-                          &err);
+    ret = qapi_enum_parse(QType_lookup, "junk", -1, &err);
     error_free_or_abort(&err);
 
-    ret = qapi_enum_parse(QType_lookup, "none", QTYPE__MAX, -1,
-                          &error_abort);
+    ret = qapi_enum_parse(QType_lookup, "none", -1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE_NONE);
 
     ret = qapi_enum_parse(QType_lookup, QType_lookup[QTYPE__MAX - 1],
-                          QTYPE__MAX, QTYPE__MAX - 1,
-                          &error_abort);
+                          QTYPE__MAX - 1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE__MAX - 1);
 }
 
Signature · 1 line
2.13.5
#24 lore raw

[Qemu-devel] [PULL v2 39/47] quorum: Use qapi_enum_parse() in quorum_open()

In reply to Markus Armbruster

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

Message-Id: <[email protected]>

[Rebased, qemu_opt_get() factored out, commit message tweaked]
Cc Alberto Garcia <[email protected]>

Message-Id: <[email protected]>

---
 block/quorum.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)
block/quorum.c +9 -19
index d04da4f430..cb6617703c 100644
@@ -22,6 +22,7 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/util.h"
 #include "qapi-event.h"
 #include "crypto/hash.h"
 
@@ -867,30 +868,13 @@ static QemuOptsList quorum_runtime_opts = {
     },
 };
 
-static int parse_read_pattern(const char *opt)
-{
-    int i;
-
-    if (!opt) {
-        /* Set quorum as default */
-        return QUORUM_READ_PATTERN_QUORUM;
-    }
-
-    for (i = 0; i < QUORUM_READ_PATTERN__MAX; i++) {
-        if (!strcmp(opt, QuorumReadPattern_lookup[i])) {
-            return i;
-        }
-    }
-
-    return -EINVAL;
-}
-
 static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
                        Error **errp)
 {
     BDRVQuorumState *s = bs->opaque;
     Error *local_err = NULL;
     QemuOpts *opts = NULL;
+    const char *pattern_str;
     bool *opened;
     int i;
     int ret = 0;
@@ -925,7 +909,13 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
         goto exit;
     }
 
-    ret = parse_read_pattern(qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN));
+    pattern_str = qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN);
+    if (!pattern_str) {
+        ret = QUORUM_READ_PATTERN_QUORUM;
+    } else {
+        ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str,
+                              -EINVAL, NULL);
+    }
     if (ret < 0) {
         error_setg(&local_err, "Please set read-pattern as fifo or quorum");
         goto exit;
Signature · 1 line
2.13.5
#25 lore raw

[Qemu-devel] [PULL v2 27/47] qapi-schema: Move block events from event.json to block.json

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 qapi/block.json | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/event.json | 68 ---------------------------------------------------------
 2 files changed, 68 insertions(+), 68 deletions(-)
qapi/block.json +68 -0
index 414b61bde7..8ce335739f 100644
@@ -277,3 +277,71 @@
 ##
 { 'enum': 'QuorumOpType',
   'data': [ 'read', 'write', 'flush' ] }
+
+##
+# @QUORUM_FAILURE:
+#
+# Emitted by the Quorum block driver if it fails to establish a quorum
+#
+# @reference: device name if defined else node name
+#
+# @sector-num: number of the first sector of the failed read operation
+#
+# @sectors-count: failed read operation sector count
+#
+# Note: This event is rate-limited.
+#
+# Since: 2.0
+#
+# Example:
+#
+# <- { "event": "QUORUM_FAILURE",
+#      "data": { "reference": "usr1", "sector-num": 345435, "sectors-count": 5 },
+#      "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
+#
+##
+{ 'event': 'QUORUM_FAILURE',
+  'data': { 'reference': 'str', 'sector-num': 'int', 'sectors-count': 'int' } }
+
+##
+# @QUORUM_REPORT_BAD:
+#
+# Emitted to report a corruption of a Quorum file
+#
+# @type: quorum operation type (Since 2.6)
+#
+# @error: error message. Only present on failure. This field
+#         contains a human-readable error message. There are no semantics other
+#         than that the block layer reported an error and clients should not
+#         try to interpret the error string.
+#
+# @node-name: the graph node name of the block driver state
+#
+# @sector-num: number of the first sector of the failed read operation
+#
+# @sectors-count: failed read operation sector count
+#
+# Note: This event is rate-limited.
+#
+# Since: 2.0
+#
+# Example:
+#
+# 1. Read operation
+#
+# { "event": "QUORUM_REPORT_BAD",
+#      "data": { "node-name": "node0", "sector-num": 345435, "sectors-count": 5,
+#                "type": "read" },
+#      "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
+#
+# 2. Flush operation
+#
+# { "event": "QUORUM_REPORT_BAD",
+#      "data": { "node-name": "node0", "sector-num": 0, "sectors-count": 2097120,
+#                "type": "flush", "error": "Broken pipe" },
+#      "timestamp": { "seconds": 1456406829, "microseconds": 291763 } }
+#
+##
+{ 'event': 'QUORUM_REPORT_BAD',
+  'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str',
+            'sector-num': 'int', 'sectors-count': 'int' } }
qapi/event.json +0 -68

74 lines not on this page · raw message

Signature · 1 line
2.13.5
#26 lore raw

[Qemu-devel] [PULL v2 31/47] qapi-schema: Improve section headings

In reply to Markus Armbruster

The generated QEMU QMP reference is now structured as follows:

1.1 Introduction
1.2 Stability Considerations
1.3 Common data types
1.4 Socket data types
1.5 VM run state
1.6 Cryptography
1.7 Block devices
1.7.1 Block core (VM unrelated)
1.7.2 QAPI block definitions (vm unrelated)
1.8 Character devices
1.9 Net devices
1.10 Rocker switch device
1.11 TPM (trusted platform module) devices
1.12 Remote desktop
1.12.1 Spice
1.12.2 VNC
1.13 Input
1.14 Migration
1.15 Transactions
1.16 Tracing
1.17 QMP introspection
1.18 Miscellanea

Section "1.18 Miscellanea" is still too big: it documents 134 symbols. Section "1.7.1 Block core (VM unrelated)" is also rather big: 128 symbols. All the others are of reasonable size.

Message-Id: <[email protected]>

---
 qapi-schema.json     | 2 +-
 qapi/block-core.json | 2 +-
 qapi/block.json      | 5 ++---
 qapi/common.json     | 2 +-
 qapi/crypto.json     | 2 +-
 qapi/trace.json      | 2 +-
 6 files changed, 7 insertions(+), 8 deletions(-)
qapi-schema.json +1 -1
index 7a393ec3e9..f3af2cb851 100644
@@ -94,7 +94,7 @@
 { 'include': 'qapi/introspect.json' }
 
 ##
-# = QMP commands
+# = Miscellanea
 ##
 
 ##
qapi/block-core.json +1 -1
index f4caa5c21b..28abb9e6cf 100644
@@ -1,7 +1,7 @@
 # -*- Mode: Python -*-
 
 ##
-# == QAPI block core definitions (vm unrelated)
+# == Block core (VM unrelated)
 ##
 
 { 'include': 'common.json' }
qapi/block.json +2 -3
index 8ce335739f..f093fa3f27 100644
@@ -1,14 +1,13 @@
 # -*- Mode: Python -*-
 
 ##
-# = QAPI block definitions
+# = Block devices
 ##
 
-# QAPI block core definitions
 { 'include': 'block-core.json' }
 
 ##
-# == QAPI block definitions (vm unrelated)
+# == Additional block stuff (VM related)
 ##
 
 ##
qapi/common.json +1 -1
index 0c67e4acf5..6eb01821ef 100644
@@ -1,7 +1,7 @@
 # -*- Mode: Python -*-
 
 ##
-# = QAPI common definitions
+# = Common data types
 ##
 
 ##
qapi/crypto.json +1 -1
index 6b6fde367a..288bc056ef 100644
@@ -2,7 +2,7 @@
 #
 
 ##
-# = QAPI crypto definitions
+# = Cryptography
 ##
 
 ##
qapi/trace.json +1 -1
index de6588d9f7..799b254a18 100644
@@ -6,7 +6,7 @@
 # See the COPYING file in the top-level directory.
 
 ##
-# = Tracing commands
+# = Tracing
 ##
 
 ##
Signature · 1 line
2.13.5
#27 lore raw

[Qemu-devel] [PULL v2 43/47] qapi: Generate FOO_str() macro for QAPI enum FOO

In reply to Markus Armbruster

The next commit will put it to use. May look pointless now, but we're going to change the FOO_lookup's type, and then it'll help.

Message-Id: <[email protected]>

---
 block.c                      | 1 -
 block/blkdebug.c             | 1 -
 block/file-posix.c           | 1 -
 block/file-win32.c           | 1 -
 block/gluster.c              | 1 -
 block/parallels.c            | 1 -
 block/qcow2.c                | 1 -
 block/quorum.c               | 1 -
 blockdev.c                   | 1 -
 crypto/block-luks.c          | 1 -
 docs/devel/qapi-code-gen.txt | 3 +++
 hmp.c                        | 1 -
 include/qapi/util.h          | 1 +
 migration/global_state.c     | 1 -
 migration/migration.c        | 1 -
 qapi/qapi-util.c             | 8 +++++++-
 qapi/qapi-visit-core.c       | 1 -
 qemu-img.c                   | 1 -
 qemu-nbd.c                   | 1 -
 scripts/qapi-event.py        | 1 +
 scripts/qapi-types.py        | 4 ++++
 scripts/qapi.py              | 3 +++
 tests/test-qapi-util.c       | 1 -
 tpm.c                        | 1 -
 util/keyval.c                | 1 -
 25 files changed, 19 insertions(+), 20 deletions(-)
block.c +0 -1
index af48b0d26b..845eff8177 100644
@@ -42,7 +42,6 @@
 #include "qapi-event.h"
 #include "qemu/cutils.h"
 #include "qemu/id.h"
-#include "qapi/util.h"
 
 #ifdef CONFIG_BSD
 #include <sys/ioctl.h>
block/blkdebug.c +0 -1
index f1bbee9497..b370fcedfb 100644
@@ -32,7 +32,6 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include "sysemu/qtest.h"
 
 typedef struct BDRVBlkdebugState {
block/file-posix.c +0 -1
index 97e8a92e23..d81eccc191 100644
@@ -31,7 +31,6 @@
 #include "block/thread-pool.h"
 #include "qemu/iov.h"
 #include "block/raw-aio.h"
-#include "qapi/util.h"
 #include "qapi/qmp/qstring.h"
 
 #if defined(__APPLE__) && (__MACH__)
block/file-win32.c +0 -1
index 978d8058fe..192ea819d9 100644
@@ -31,7 +31,6 @@
 #include "block/thread-pool.h"
 #include "qemu/iov.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include <windows.h>
 #include <winioctl.h>
 
block/gluster.c +0 -1
index 8367e806d0..0614e0c8aa 100644
@@ -12,7 +12,6 @@
 #include "block/block_int.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
 #include "qemu/uri.h"
 #include "qemu/error-report.h"
 #include "qemu/cutils.h"
block/parallels.c +0 -1
index eb92366e51..d812210b4f 100644
@@ -35,7 +35,6 @@
 #include "qemu/module.h"
 #include "qemu/bswap.h"
 #include "qemu/bitmap.h"
-#include "qapi/util.h"
 
 /**************************************************************/
 
block/qcow2.c +0 -1
index 470a0dedaa..3a93983e3f 100644
@@ -30,7 +30,6 @@
 #include "qemu/error-report.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qbool.h"
-#include "qapi/util.h"
 #include "qapi/qmp/types.h"
 #include "qapi-event.h"
 #include "trace.h"
block/quorum.c +0 -1
index cb6617703c..8d1c9f6306 100644
@@ -22,7 +22,6 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include "qapi-event.h"
 #include "crypto/hash.h"
 
blockdev.c +0 -1
index 722a61e3fb..f90bc9399a 100644
@@ -44,7 +44,6 @@
 #include "qapi-visit.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qobject-output-visitor.h"
-#include "qapi/util.h"
 #include "sysemu/sysemu.h"
 #include "block/block_int.h"
 #include "qmp-commands.h"
crypto/block-luks.c +0 -1
index c3cacdb1ed..84d189a426 100644
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "qemu/bswap.h"
 
 #include "crypto/block-luks.h"
docs/devel/qapi-code-gen.txt +3 -0
index ae05327869..f04c63fe82 100644
@@ -1275,6 +1275,9 @@ Example:
         EXAMPLE_QAPI_EVENT__MAX = 1,
     } example_QAPIEvent;
 
+    #define example_QAPIEvent_str(val) \
+        qapi_enum_lookup(example_QAPIEvent_lookup, (val))
+
     extern const char *const example_QAPIEvent_lookup[];
 
     #endif
hmp.c +0 -1
index 2b6e919501..5d980acb1e 100644
@@ -31,7 +31,6 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/string-input-visitor.h"
 #include "qapi/string-output-visitor.h"
-#include "qapi/util.h"
 #include "qapi-visit.h"
 #include "qom/object_interfaces.h"
 #include "ui/console.h"
include/qapi/util.h +1 -0
index 4eb8a3fe2f..5e50d0c1ce 100644
@@ -11,6 +11,7 @@
 #ifndef QAPI_UTIL_H
 #define QAPI_UTIL_H
 
+const char *qapi_enum_lookup(const char *const lookup[], int val);
 int qapi_enum_parse(const char * const lookup[], const char *buf,
                     int def, Error **errp);
 
migration/global_state.c +0 -1
index 88c55f8cdb..76cd3a13d4 100644
@@ -14,7 +14,6 @@
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "migration.h"
 #include "migration/global_state.h"
 #include "migration/vmstate.h"
migration/migration.c +0 -1
index c3fe0ed9ca..1a2b3ebd1a 100644
@@ -31,7 +31,6 @@
 #include "migration/vmstate.h"
 #include "block/block.h"
 #include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
 #include "qemu/rcu.h"
 #include "block.h"
 #include "postcopy-ram.h"
qapi/qapi-util.c +7 -1
index ee7594ff19..7af2f04d36 100644
@@ -13,7 +13,13 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
-#include "qapi/util.h"
+
+const char *qapi_enum_lookup(const char *const lookup[], int val)
+{
+    assert(val >= 0);
+
+    return lookup[val];
+}
 
 int qapi_enum_parse(const char * const lookup[], const char *buf,
                     int def, Error **errp)
qapi/qapi-visit-core.c +0 -1
index ec83ff68f9..f285879d72 100644
@@ -14,7 +14,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "qemu-common.h"
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qerror.h"
qemu-img.c +0 -1
index 611ab7ddf3..a72a2e3133 100644
@@ -26,7 +26,6 @@
 
 #include "qemu-version.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "qapi-visit.h"
 #include "qapi/qobject-output-visitor.h"
 #include "qapi/qmp/qerror.h"
qemu-nbd.c +0 -1
index 96e10d62dc..a97f3f4540 100644
@@ -34,7 +34,6 @@
 #include "qemu/log.h"
 #include "qemu/systemd.h"
 #include "block/snapshot.h"
-#include "qapi/util.h"
 #include "qapi/qmp/qstring.h"
 #include "qom/object_interfaces.h"
 #include "io/channel-socket.h"
scripts/qapi-event.py +1 -0
index bcbef1035f..07b4b70199 100644
@@ -217,6 +217,7 @@ fdef.write(mcgen('''
 
 fdecl.write(mcgen('''
 #include "qapi/error.h"
+#include "qapi/util.h"
 #include "qapi/qmp/qdict.h"
 #include "%(prefix)sqapi-types.h"
 
scripts/qapi-types.py +4 -0
index b45e7b5634..7e3051dbb9 100644
@@ -292,6 +292,10 @@ fdef.write(mcgen('''
 ''',
                  prefix=prefix))
 
+fdecl.write(mcgen('''
+#include "qapi/util.h"
+'''))
+
 schema = QAPISchema(input_file)
 gen = QAPISchemaGenTypeVisitor()
 schema.visit(gen)
scripts/qapi.py +3 -0
index 3693b520da..8736b9c786 100644
@@ -1894,6 +1894,9 @@ typedef enum %(c_name)s {
 
     ret += mcgen('''
 
+#define %(c_name)s_str(val) \\
+    qapi_enum_lookup(%(c_name)s_lookup, (val))
+
 extern const char *const %(c_name)s_lookup[];
 ''',
                  c_name=c_name(name))
tests/test-qapi-util.c +0 -1
index d72ee8c4e7..7e1be1d851 100644
@@ -12,7 +12,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "test-qapi-types.h"
 
 static void test_qapi_enum_parse(void)
tpm.c +0 -1
index 7635fc779b..38f3eb827f 100644
@@ -14,7 +14,6 @@
 #include "qemu/osdep.h"
 
 #include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
 #include "sysemu/tpm_backend.h"
 #include "sysemu/tpm.h"
 #include "qemu/config-file.h"
util/keyval.c +0 -1
index 7dbda62305..7dfc75cf01 100644
@@ -82,7 +82,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include "qemu/cutils.h"
 #include "qemu/option.h"
 
Signature · 1 line
2.13.5
#28 lore raw

[Qemu-devel] [PULL v2 06/47] qlit: use QLit prefix consistently

In reply to Markus Armbruster

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

Rename from LiteralQ to QLit.

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h | 24 ++++++++++++------------
 qobject/qlit.c          |  4 ++--
 tests/check-qjson.c     | 40 ++++++++++++++++++++--------------------
 3 files changed, 34 insertions(+), 34 deletions(-)
include/qapi/qmp/qlit.h +12 -12
index 280db5064a..a4ad91321b 100644
@@ -17,33 +17,33 @@
 #include "qapi-types.h"
 #include "qobject.h"
 
-typedef struct LiteralQDictEntry LiteralQDictEntry;
-typedef struct LiteralQObject LiteralQObject;
+typedef struct QLitDictEntry QLitDictEntry;
+typedef struct QLitObject QLitObject;
 
-struct LiteralQObject {
+struct QLitObject {
     int type;
     union {
         int64_t qnum;
         const char *qstr;
-        LiteralQDictEntry *qdict;
-        LiteralQObject *qlist;
+        QLitDictEntry *qdict;
+        QLitObject *qlist;
     } value;
 };
 
-struct LiteralQDictEntry {
+struct QLitDictEntry {
     const char *key;
-    LiteralQObject value;
+    QLitObject value;
 };
 
 #define QLIT_QNUM(val) \
-    (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+    (QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)}
 #define QLIT_QSTR(val) \
-    (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+    (QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
 #define QLIT_QDICT(val) \
-    (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+    (QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)}
 #define QLIT_QLIST(val) \
-    (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+    (QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)}
 
-int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
+int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H */
qobject/qlit.c +2 -2
index 5917c3584e..262d64988d 100644
@@ -20,7 +20,7 @@
 
 typedef struct QListCompareHelper {
     int index;
-    LiteralQObject *objs;
+    QLitObject *objs;
     int result;
 } QListCompareHelper;
 
@@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque)
         compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
 }
 
-int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
+int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
 {
     int64_t val;
 
tests/check-qjson.c +20 -20
index 525f79e60b..82b3681327 100644
@@ -1065,23 +1065,23 @@ static void simple_dict(void)
     int i;
     struct {
         const char *encoded;
-        LiteralQObject decoded;
+        QLitObject decoded;
     } test_cases[] = {
         {
             .encoded = "{\"foo\": 42, \"bar\": \"hello world\"}",
-            .decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+            .decoded = QLIT_QDICT(((QLitDictEntry[]){
                         { "foo", QLIT_QNUM(42) },
                         { "bar", QLIT_QSTR("hello world") },
                         { }
                     })),
         }, {
             .encoded = "{}",
-            .decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+            .decoded = QLIT_QDICT(((QLitDictEntry[]){
                         { }
                     })),
         }, {
             .encoded = "{\"foo\": 43}",
-            .decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+            .decoded = QLIT_QDICT(((QLitDictEntry[]){
                         { "foo", QLIT_QNUM(43) },
                         { }
                     })),
@@ -1163,11 +1163,11 @@ static void simple_list(void)
     int i;
     struct {
         const char *encoded;
-        LiteralQObject decoded;
+        QLitObject decoded;
     } test_cases[] = {
         {
             .encoded = "[43,42]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(43),
                         QLIT_QNUM(42),
                         { }
@@ -1175,21 +1175,21 @@ static void simple_list(void)
         },
         {
             .encoded = "[43]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(43),
                         { }
                     })),
         },
         {
             .encoded = "[]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         { }
                     })),
         },
         {
             .encoded = "[{}]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
-                        QLIT_QDICT(((LiteralQDictEntry[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
+                        QLIT_QDICT(((QLitDictEntry[]){
                                     {},
                                         })),
                         {},
@@ -1220,11 +1220,11 @@ static void simple_whitespace(void)
     int i;
     struct {
         const char *encoded;
-        LiteralQObject decoded;
+        QLitObject decoded;
     } test_cases[] = {
         {
             .encoded = " [ 43 , 42 ]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(43),
                         QLIT_QNUM(42),
                         { }
@@ -1232,12 +1232,12 @@ static void simple_whitespace(void)
         },
         {
             .encoded = " [ 43 , { 'h' : 'b' }, [ ], 42 ]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(43),
-                        QLIT_QDICT(((LiteralQDictEntry[]){
+                        QLIT_QDICT(((QLitDictEntry[]){
                                     { "h", QLIT_QSTR("b") },
                                     { }})),
-                        QLIT_QLIST(((LiteralQObject[]){
+                        QLIT_QLIST(((QLitObject[]){
                                     { }})),
                         QLIT_QNUM(42),
                         { }
@@ -1245,13 +1245,13 @@ static void simple_whitespace(void)
         },
         {
             .encoded = " [ 43 , { 'h' : 'b' , 'a' : 32 }, [ ], 42 ]",
-            .decoded = QLIT_QLIST(((LiteralQObject[]){
+            .decoded = QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(43),
-                        QLIT_QDICT(((LiteralQDictEntry[]){
+                        QLIT_QDICT(((QLitDictEntry[]){
                                     { "h", QLIT_QSTR("b") },
                                     { "a", QLIT_QNUM(32) },
                                     { }})),
-                        QLIT_QLIST(((LiteralQObject[]){
+                        QLIT_QLIST(((QLitObject[]){
                                     { }})),
                         QLIT_QNUM(42),
                         { }
@@ -1282,10 +1282,10 @@ static void simple_varargs(void)
 {
     QObject *embedded_obj;
     QObject *obj;
-    LiteralQObject decoded = QLIT_QLIST(((LiteralQObject[]){
+    QLitObject decoded = QLIT_QLIST(((QLitObject[]){
             QLIT_QNUM(1),
             QLIT_QNUM(2),
-            QLIT_QLIST(((LiteralQObject[]){
+            QLIT_QLIST(((QLitObject[]){
                         QLIT_QNUM(32),
                         QLIT_QNUM(42),
                         {}})),
Signature · 1 line
2.13.5
#29 lore raw

[Qemu-devel] [PULL v2 12/47] qlit: Replace open-coded qnum_get_int() by call

In reply to Markus Armbruster

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

Bonus: rids us of a side effect in an assertion.

Message-Id: <[email protected]>

---
 qobject/qlit.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
qobject/qlit.c +1 -4
index 07ad6b05e8..b1d9146220 100644
@@ -43,8 +43,6 @@ static void compare_helper(QObject *obj, void *opaque)
 
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
-    int64_t val;
-
     if (!rhs || lhs->type != qobject_type(rhs)) {
         return false;
     }
@@ -53,8 +51,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
     case QTYPE_QBOOL:
         return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
     case QTYPE_QNUM:
-        g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
-        return lhs->value.qnum == val;
+        return lhs->value.qnum ==  qnum_get_int(qobject_to_qnum(rhs));
     case QTYPE_QSTRING:
         return (strcmp(lhs->value.qstr,
                        qstring_get_str(qobject_to_qstring(rhs))) == 0);
Signature · 1 line
2.13.5
#30 lore raw

[Qemu-devel] [PULL v2 15/47] qlit: Tighten QLit list vs QList comparison

In reply to Markus Armbruster

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

We check that all members of the QLit list are also in the QList. We neglect to check the other direction. Fix that.

While there, use QLIST_FOREACH_ENTRY() to simplify the code and break the loop on the first mismatch.

Message-Id: <[email protected]>

[Commit message improved]
---
 qobject/qlit.c     | 53 +++++++++++++++++++----------------------------------
 tests/check-qlit.c |  3 +++
 2 files changed, 22 insertions(+), 34 deletions(-)
qobject/qlit.c +19 -34
index dc0015f76c..3c4882c784 100644
@@ -18,29 +18,6 @@
 #include "qapi/qmp/qlit.h"
 #include "qapi/qmp/types.h"
 
-typedef struct QListCompareHelper {
-    int index;
-    QLitObject *objs;
-    bool result;
-} QListCompareHelper;
-
-static void compare_helper(QObject *obj, void *opaque)
-{
-    QListCompareHelper *helper = opaque;
-
-    if (!helper->result) {
-        return;
-    }
-
-    if (helper->objs[helper->index].type == QTYPE_NONE) {
-        helper->result = false;
-        return;
-    }
-
-    helper->result =
-        qlit_equal_qobject(&helper->objs[helper->index++], obj);
-}
-
 static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
 {
     int i;
@@ -62,6 +39,23 @@ static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
     return true;
 }
 
+static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist)
+{
+    QListEntry *e;
+    int i = 0;
+
+    QLIST_FOREACH_ENTRY(qlist, e) {
+        QObject *obj = qlist_entry_obj(e);
+
+        if (!qlit_equal_qobject(&lhs->value.qlist[i], obj)) {
+            return false;
+        }
+        i++;
+    }
+
+    return !e && lhs->value.qlist[i].type == QTYPE_NONE;
+}
+
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
     if (!rhs || lhs->type != qobject_type(rhs)) {
@@ -78,17 +72,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
                        qstring_get_str(qobject_to_qstring(rhs))) == 0);
     case QTYPE_QDICT:
         return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
-    case QTYPE_QLIST: {
-        QListCompareHelper helper;
-
-        helper.index = 0;
-        helper.objs = lhs->value.qlist;
-        helper.result = true;
-
-        qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
-
-        return helper.result;
-    }
+    case QTYPE_QLIST:
+        return qlit_equal_qlist(lhs, qobject_to_qlist(rhs));
     case QTYPE_QNULL:
         return true;
     default:
tests/check-qlit.c +3 -0
index d2ecc200d3..c59ec1ab88 100644
@@ -58,6 +58,9 @@ static void qlit_equal_qobject_test(void)
 
     g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
 
+    qdict_put(qobject_to_qdict(qobj), "bee", qlist_new());
+    g_assert(!qlit_equal_qobject(&qlit, qobj));
+
     qobject_decref(qobj);
 }
 
Signature · 1 line
2.13.5
#31 lore raw

[Qemu-devel] [PULL v2 29/47] qapi-schema: Make block-core.json self-contained

In reply to Markus Armbruster

Except for block-core.json, the sub-schemas are self-contained: if they use a symbol defined in another sub-schema, they include that sub-schema. To check, feed the sub-schema to qapi2texi (or any other QAPI generator) along with the pragma from qapi-schema.json.

Fix up things to make block-core.json self-contained, too.

Message-Id: <[email protected]>

---
 qapi-schema.json     | 14 --------------
 qapi/block-core.json |  1 +
 qapi/common.json     | 14 ++++++++++++++
 3 files changed, 15 insertions(+), 14 deletions(-)
qapi-schema.json +0 -14
index 4964d927bd..80c15dade3 100644
@@ -2816,20 +2816,6 @@
      'data': { 'info': 'ACPIOSTInfo' } }
 
 ##
-# @IoOperationType:
-#
-# An enumeration of the I/O operation types
-#
-# @read: read operation
-#
-# @write: write operation
-#
-# Since: 2.1
-##
-{ 'enum': 'IoOperationType',
-  'data': [ 'read', 'write' ] }
-
-##
 # @rtc-reset-reinjection:
 #
 # This command will reset the RTC interrupt reinjection backlog.
qapi/block-core.json +1 -0
index 5379674292..f4caa5c21b 100644
@@ -5,6 +5,7 @@
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'crypto.json' }
 { 'include': 'sockets.json' }
 
 ##
qapi/common.json +14 -0
index e2c58564d8..fc72d7ec3d 100644
@@ -132,6 +132,20 @@
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
 ##
+# @IoOperationType:
+#
+# An enumeration of the I/O operation types
+#
+# @read: read operation
+#
+# @write: write operation
+#
+# Since: 2.1
+##
+{ 'enum': 'IoOperationType',
+  'data': [ 'read', 'write' ] }
+
+##
 # @OnOffAuto:
 #
 # An enumeration of three options: on, off, and auto
Signature · 1 line
2.13.5
#32 lore raw

[Qemu-devel] [PULL v2 41/47] qapi: Use qapi_enum_parse() in input_type_enum()

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 qapi/qapi-visit-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
qapi/qapi-visit-core.c +4 -9
index ed6d2af462..ec83ff68f9 100644
@@ -14,6 +14,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/util.h"
 #include "qemu-common.h"
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qerror.h"
@@ -353,7 +354,7 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
                             const char *const strings[], Error **errp)
 {
     Error *local_err = NULL;
-    int64_t value = 0;
+    int64_t value;
     char *enum_str;
 
     visit_type_str(v, name, &enum_str, &local_err);
@@ -362,14 +363,8 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
         return;
     }
 
-    while (strings[value] != NULL) {
-        if (strcmp(strings[value], enum_str) == 0) {
-            break;
-        }
-        value++;
-    }
-
-    if (strings[value] == NULL) {
+    value = qapi_enum_parse(strings, enum_str, -1, NULL);
+    if (value < 0) {
         error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
         g_free(enum_str);
         return;
Signature · 1 line
2.13.5
#33 lore raw

[Qemu-devel] [PULL v2 45/47] qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup()

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 hw/core/qdev-properties.c | 7 +++++--
 qapi/qapi-visit-core.c    | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)
hw/core/qdev-properties.c +5 -2
index 078fc5d239..7512bd4379 100644
@@ -72,7 +72,9 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,
 
 static void set_default_value_enum(Object *obj, const Property *prop)
 {
-    object_property_set_str(obj, prop->info->enum_table[prop->defval.i],
+    object_property_set_str(obj,
+                            qapi_enum_lookup(prop->info->enum_table,
+                                             prop->defval.i),
                             prop->name, &error_abort);
 }
 
@@ -1095,7 +1097,8 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
     Property *prop;
 
     prop = qdev_prop_find(dev, name);
-    object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
+    object_property_set_str(OBJECT(dev),
+                            qapi_enum_lookup(prop->info->enum_table, value),
                             name, &error_abort);
 }
 
qapi/qapi-visit-core.c +1 -1
index f285879d72..30dc85b6f3 100644
@@ -345,7 +345,7 @@ static void output_type_enum(Visitor *v, const char *name, int *obj,
         return;
     }
 
-    enum_str = (char *)strings[value];
+    enum_str = (char *)qapi_enum_lookup(strings, value);
     visit_type_str(v, name, &enum_str, errp);
 }
 
Signature · 1 line
2.13.5
#34 lore raw

[Qemu-devel] [PULL v2 47/47] qapi: drop the sentinel in enum array

In reply to Markus Armbruster

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

Now that all usages have been converted to user lookup helpers.

Message-Id: <[email protected]> [Rebased, superfluous local variable dropped, missing check-qom-proplist.c update added]

Message-Id: <[email protected]>

---
 block/parallels.c          | 1 -
 scripts/qapi.py            | 4 +---
 tests/check-qom-proplist.c | 1 -
 3 files changed, 1 insertion(+), 5 deletions(-)
block/parallels.c +0 -1
index cce7336cac..2b6c6e5709 100644
@@ -72,7 +72,6 @@ static QEnumLookup prealloc_mode_lookup = {
     .array = (const char *const[]) {
         "falloc",
         "truncate",
-        NULL,
     },
     .size = PRL_PREALLOC_MODE__MAX
 };
scripts/qapi.py +1 -3
index 39a67270fc..62dc52ed6e 100644
@@ -1860,14 +1860,12 @@ const QEnumLookup %(c_name)s_lookup = {
 ''',
                      index=index, value=value)
 
-    max_index = c_enum_const(name, '_MAX', prefix)
     ret += mcgen('''
-        [%(max_index)s] = NULL,
     },
     .size = %(max_index)s
 };
 ''',
-                 max_index=max_index)
+                 max_index=c_enum_const(name, '_MAX', prefix))
     return ret
 
 
tests/check-qom-proplist.c +0 -1
index 07e351f950..92898e1520 100644
@@ -51,7 +51,6 @@ const QEnumLookup dummy_animal_map = {
         [DUMMY_FROG] = "frog",
         [DUMMY_ALLIGATOR] = "alligator",
         [DUMMY_PLATYPUS] = "platypus",
-        [DUMMY_LAST] = NULL,
     },
     .size = DUMMY_LAST
 };
Signature · 1 line
2.13.5
#35 lore raw

[Qemu-devel] [PULL v2 35/47] tpm: Clean up model registration & lookup

In reply to Markus Armbruster

We have a strict separation between enum TpmModel and tpm_models[]:

* TpmModel may have any number of members. It just happens to have one.

* tpm_register_model() uses the first empty slot in tpm_models[].

If you register more than tpm_models[] has space, tpn_register_model() fails. Its caller silently ignores the failure.

Register the same TpmModel more than once has no effect other than wasting tpm_models[] slots: tpm_model_is_registered() is happy with the first one it finds.

Since we only ever register one model, and tpm_models[] has space for just that one, this contraption even works.

Turn tpm_models[] into a straight map from enum TpmType to bool. Much simpler.

Message-Id: <[email protected]>

[Commit message typo fixed]
---
 include/sysemu/tpm_backend.h |  2 +-
 tpm.c                        | 37 +++++--------------------------------
 2 files changed, 6 insertions(+), 33 deletions(-)
include/sysemu/tpm_backend.h +1 -1
index 1d21c6b19b..b0a9731aee 100644
@@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
 TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
-int tpm_register_model(enum TpmModel model);
+void tpm_register_model(enum TpmModel model);
 void tpm_register_driver(const TPMDriverOps *tdo);
 
 #endif
tpm.c +5 -32
index 6f39ec9192..7635fc779b 100644
@@ -24,39 +24,12 @@
 static QLIST_HEAD(, TPMBackend) tpm_backends =
     QLIST_HEAD_INITIALIZER(tpm_backends);
 
-
-#define TPM_MAX_MODELS      1
-
 static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
+static bool tpm_models[TPM_MODEL__MAX];
 
-static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
-    TPM_MODEL__MAX,
-};
-
-int tpm_register_model(enum TpmModel model)
+void tpm_register_model(enum TpmModel model)
 {
-    int i;
-
-    for (i = 0; i < TPM_MAX_MODELS; i++) {
-        if (tpm_models[i] == TPM_MODEL__MAX) {
-            tpm_models[i] = model;
-            return 0;
-        }
-    }
-    error_report("Could not register TPM model");
-    return 1;
-}
-
-static bool tpm_model_is_registered(enum TpmModel model)
-{
-    int i;
-
-    for (i = 0; i < TPM_MAX_MODELS; i++) {
-        if (tpm_models[i] == model) {
-            return true;
-        }
-    }
-    return false;
+    tpm_models[model] = true;
 }
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type)
@@ -270,7 +243,7 @@ TPMInfoList *qmp_query_tpm(Error **errp)
     TPMInfoList *info, *head = NULL, *cur_item = NULL;
 
     QLIST_FOREACH(drv, &tpm_backends, list) {
-        if (!tpm_model_is_registered(drv->fe_model)) {
+        if (!tpm_models[drv->fe_model]) {
             continue;
         }
         info = g_new0(TPMInfoList, 1);
@@ -317,7 +290,7 @@ TpmModelList *qmp_query_tpm_models(Error **errp)
     TpmModelList *head = NULL, *prev = NULL, *cur_item;
 
     for (i = 0; i < TPM_MODEL__MAX; i++) {
-        if (!tpm_model_is_registered(i)) {
+        if (!tpm_models[i]) {
             continue;
         }
         cur_item = g_new0(TpmModelList, 1);
Signature · 1 line
2.13.5
#36 lore raw

[Qemu-devel] [PULL v2 37/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter()

In reply to Markus Armbruster

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

The error message on invalid parameter name changes from

Invalid parameter "NAME"

to

invalid parameter value: NAME

Slight degratation, perhaps.

Message-Id: <[email protected]>

[Rebased, assertion added, commit message rewritten]
Cc "Dr. David Alan Gilbert" <[email protected]>

Message-Id: <[email protected]>

---
 hmp.c | 138 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 68 insertions(+), 70 deletions(-)
hmp.c +68 -70
index 7e0bd3d63b..2b6e919501 100644
@@ -1556,84 +1556,82 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
     uint64_t valuebw = 0;
     Error *err = NULL;
-    int i, ret;
+    int val, ret;
 
-    for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
-        if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
-            switch (i) {
-            case MIGRATION_PARAMETER_COMPRESS_LEVEL:
-                p->has_compress_level = true;
-                visit_type_int(v, param, &p->compress_level, &err);
-                break;
-            case MIGRATION_PARAMETER_COMPRESS_THREADS:
-                p->has_compress_threads = true;
-                visit_type_int(v, param, &p->compress_threads, &err);
-                break;
-            case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
-                p->has_decompress_threads = true;
-                visit_type_int(v, param, &p->decompress_threads, &err);
-                break;
-            case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
-                p->has_cpu_throttle_initial = true;
-                visit_type_int(v, param, &p->cpu_throttle_initial, &err);
-                break;
-            case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
-                p->has_cpu_throttle_increment = true;
-                visit_type_int(v, param, &p->cpu_throttle_increment, &err);
-                break;
-            case MIGRATION_PARAMETER_TLS_CREDS:
-                p->has_tls_creds = true;
-                p->tls_creds = g_new0(StrOrNull, 1);
-                p->tls_creds->type = QTYPE_QSTRING;
-                visit_type_str(v, param, &p->tls_creds->u.s, &err);
-                break;
-            case MIGRATION_PARAMETER_TLS_HOSTNAME:
-                p->has_tls_hostname = true;
-                p->tls_hostname = g_new0(StrOrNull, 1);
-                p->tls_hostname->type = QTYPE_QSTRING;
-                visit_type_str(v, param, &p->tls_hostname->u.s, &err);
-                break;
-            case MIGRATION_PARAMETER_MAX_BANDWIDTH:
-                p->has_max_bandwidth = true;
-                /*
-                 * Can't use visit_type_size() here, because it
-                 * defaults to Bytes rather than Mebibytes.
-                 */
-                ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
-                if (ret < 0 || valuebw > INT64_MAX
-                    || (size_t)valuebw != valuebw) {
-                    error_setg(&err, "Invalid size %s", valuestr);
-                    break;
-                }
-                p->max_bandwidth = valuebw;
-                break;
-            case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
-                p->has_downtime_limit = true;
-                visit_type_int(v, param, &p->downtime_limit, &err);
-                break;
-            case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
-                p->has_x_checkpoint_delay = true;
-                visit_type_int(v, param, &p->x_checkpoint_delay, &err);
-                break;
-            case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
-                p->has_block_incremental = true;
-                visit_type_bool(v, param, &p->block_incremental, &err);
-                break;
-            }
+    val = qapi_enum_parse(MigrationParameter_lookup, param, -1, &err);
+    if (val < 0) {
+        goto cleanup;
+    }
 
-            if (err) {
-                goto cleanup;
-            }
-
-            qmp_migrate_set_parameters(p, &err);
+    switch (val) {
+    case MIGRATION_PARAMETER_COMPRESS_LEVEL:
+        p->has_compress_level = true;
+        visit_type_int(v, param, &p->compress_level, &err);
+        break;
+    case MIGRATION_PARAMETER_COMPRESS_THREADS:
+        p->has_compress_threads = true;
+        visit_type_int(v, param, &p->compress_threads, &err);
+        break;
+    case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
+        p->has_decompress_threads = true;
+        visit_type_int(v, param, &p->decompress_threads, &err);
+        break;
+    case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
+        p->has_cpu_throttle_initial = true;
+        visit_type_int(v, param, &p->cpu_throttle_initial, &err);
+        break;
+    case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
+        p->has_cpu_throttle_increment = true;
+        visit_type_int(v, param, &p->cpu_throttle_increment, &err);
+        break;
+    case MIGRATION_PARAMETER_TLS_CREDS:
+        p->has_tls_creds = true;
+        p->tls_creds = g_new0(StrOrNull, 1);
+        p->tls_creds->type = QTYPE_QSTRING;
+        visit_type_str(v, param, &p->tls_creds->u.s, &err);
+        break;
+    case MIGRATION_PARAMETER_TLS_HOSTNAME:
+        p->has_tls_hostname = true;
+        p->tls_hostname = g_new0(StrOrNull, 1);
+        p->tls_hostname->type = QTYPE_QSTRING;
+        visit_type_str(v, param, &p->tls_hostname->u.s, &err);
+        break;
+    case MIGRATION_PARAMETER_MAX_BANDWIDTH:
+        p->has_max_bandwidth = true;
+        /*
+         * Can't use visit_type_size() here, because it
+         * defaults to Bytes rather than Mebibytes.
+         */
+        ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
+        if (ret < 0 || valuebw > INT64_MAX
+            || (size_t)valuebw != valuebw) {
+            error_setg(&err, "Invalid size %s", valuestr);
             break;
         }
+        p->max_bandwidth = valuebw;
+        break;
+    case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
+        p->has_downtime_limit = true;
+        visit_type_int(v, param, &p->downtime_limit, &err);
+        break;
+    case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
+        p->has_x_checkpoint_delay = true;
+        visit_type_int(v, param, &p->x_checkpoint_delay, &err);
+        break;
+    case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
+        p->has_block_incremental = true;
+        visit_type_bool(v, param, &p->block_incremental, &err);
+        break;
+    default:
+        assert(0);
     }
 
-    if (i == MIGRATION_PARAMETER__MAX) {
-        error_setg(&err, QERR_INVALID_PARAMETER, param);
+    if (err) {
+        goto cleanup;
     }
 
+    qmp_migrate_set_parameters(p, &err);
+
  cleanup:
     qapi_free_MigrateSetParameters(p);
     visit_free(v);
Signature · 1 line
2.13.5
#37 lore raw

[Qemu-devel] [PULL v2 40/47] crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()

In reply to Markus Armbruster
Cc "Daniel P. Berrange" <[email protected]>

Message-Id: <[email protected]>

---
 crypto/block-luks.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
crypto/block-luks.c +7 -12
index afb8543108..c3cacdb1ed 100644
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/util.h"
 #include "qemu/bswap.h"
 
 #include "crypto/block-luks.h"
@@ -265,39 +266,33 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
  * make that function emit a more friendly error message */
 static int qcrypto_block_luks_name_lookup(const char *name,
                                           const char *const *map,
-                                          size_t maplen,
                                           const char *type,
                                           Error **errp)
 {
-    size_t i;
-    for (i = 0; i < maplen; i++) {
-        if (g_str_equal(map[i], name)) {
-            return i;
-        }
-    }
+    int ret = qapi_enum_parse(map, name, -1, NULL);
 
-    error_setg(errp, "%s %s not supported", type, name);
-    return 0;
+    if (ret < 0) {
+        error_setg(errp, "%s %s not supported", type, name);
+        return 0;
+    }
+    return ret;
 }
 
 #define qcrypto_block_luks_cipher_mode_lookup(name, errp)               \
     qcrypto_block_luks_name_lookup(name,                                \
                                    QCryptoCipherMode_lookup,            \
-                                   QCRYPTO_CIPHER_MODE__MAX,            \
                                    "Cipher mode",                       \
                                    errp)
 
 #define qcrypto_block_luks_hash_name_lookup(name, errp)                 \
     qcrypto_block_luks_name_lookup(name,                                \
                                    QCryptoHashAlgorithm_lookup,         \
-                                   QCRYPTO_HASH_ALG__MAX,               \
                                    "Hash algorithm",                    \
                                    errp)
 
 #define qcrypto_block_luks_ivgen_name_lookup(name, errp)                \
     qcrypto_block_luks_name_lookup(name,                                \
                                    QCryptoIVGenAlgorithm_lookup,        \
-                                   QCRYPTO_IVGEN_ALG__MAX,              \
                                    "IV generator",                      \
                                    errp)
 
Signature · 1 line
2.13.5
#38 lore raw

[Qemu-devel] [PULL v2 09/47] qlit: make qlit_equal_qobject return a bool

In reply to Markus Armbruster

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

Make it more obvious about the expected return values.

Message-Id: <[email protected]>

---
 include/qapi/qmp/qlit.h |  2 +-
 qobject/qlit.c          | 18 +++++++++---------
 tests/check-qjson.c     | 14 +++++++-------
 3 files changed, 17 insertions(+), 17 deletions(-)
include/qapi/qmp/qlit.h +1 -1
index 5a180477c8..35aabbdc9f 100644
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
     { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-int qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
+bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H */
qobject/qlit.c +9 -9
index 0c4101898d..a2975bef3f 100644
@@ -21,19 +21,19 @@
 typedef struct QListCompareHelper {
     int index;
     QLitObject *objs;
-    int result;
+    bool result;
 } QListCompareHelper;
 
 static void compare_helper(QObject *obj, void *opaque)
 {
     QListCompareHelper *helper = opaque;
 
-    if (helper->result == 0) {
+    if (!helper->result) {
         return;
     }
 
     if (helper->objs[helper->index].type == QTYPE_NONE) {
-        helper->result = 0;
+        helper->result = false;
         return;
     }
 
@@ -41,12 +41,12 @@ static void compare_helper(QObject *obj, void *opaque)
         qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
+bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
 {
     int64_t val;
 
     if (!rhs || lhs->type != qobject_type(rhs)) {
-        return 0;
+        return false;
     }
 
     switch (lhs->type) {
@@ -64,18 +64,18 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
                                      lhs->value.qdict[i].key);
 
             if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
-                return 0;
+                return false;
             }
         }
 
-        return 1;
+        return true;
     }
     case QTYPE_QLIST: {
         QListCompareHelper helper;
 
         helper.index = 0;
         helper.objs = lhs->value.qlist;
-        helper.result = 1;
+        helper.result = true;
 
         qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
 
@@ -85,5 +85,5 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
         break;
     }
 
-    return 0;
+    return false;
 }
tests/check-qjson.c +7 -7
index e5ca273cbc..59227934ce 100644
@@ -1094,13 +1094,13 @@ static void simple_dict(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
         qobject_decref(obj);
         QDECREF(str);
     }
@@ -1203,13 +1203,13 @@ static void simple_list(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
         qobject_decref(obj);
         QDECREF(str);
     }
@@ -1265,13 +1265,13 @@ static void simple_whitespace(void)
         QString *str;
 
         obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
         str = qobject_to_json(obj);
         qobject_decref(obj);
 
         obj = qobject_from_json(qstring_get_str(str), &error_abort);
-        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+        g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
         qobject_decref(obj);
         QDECREF(str);
@@ -1295,7 +1295,7 @@ static void simple_varargs(void)
     g_assert(embedded_obj != NULL);
 
     obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
-    g_assert(qlit_equal_qobject(&decoded, obj) == 1);
+    g_assert(qlit_equal_qobject(&decoded, obj));
 
     qobject_decref(obj);
 }
Signature · 1 line
2.13.5
#39 lore raw

[Qemu-devel] [PULL v2 21/47] qapi-schema: Collect char device stuff in qapi/char.json

In reply to Markus Armbruster
Cc Paolo Bonzini <[email protected]>
Cc Marc-André Lureau <[email protected]>

Message-Id: <[email protected]>

---
 MAINTAINERS      |   1 +
 Makefile         |   1 +
 qapi-schema.json | 511 +---------------------------------------------------
 qapi/char.json   | 538 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/event.json  |  21 ---
 5 files changed, 541 insertions(+), 531 deletions(-)
 create mode 100644 qapi/char.json
MAINTAINERS +1 -0
index 289ea8c575..6a808d33ba 100644
@@ -1253,6 +1253,7 @@ M: Marc-André Lureau <[email protected]>
 S: Maintained
 F: chardev/
 F: include/chardev/
+F: qapi/char.json
 
 Character Devices (Braille)
 M: Samuel Thibault <[email protected]>
Makefile +1 -0
index d3ba41afb8..59ef46cc3e 100644
@@ -410,6 +410,7 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 
 qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
+               $(SRC_PATH)/qapi/char.json \
                $(SRC_PATH)/qapi/crypto.json \
                $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
                $(SRC_PATH)/qapi/rocker.json \
qapi-schema.json +1 -510

529 lines not on this page · raw message

qapi/char.json new file +538 -0

538 lines not on this page · raw message

qapi/event.json +0 -21
index 9c6126d278..b9aa6ed7cf 100644
@@ -397,27 +397,6 @@
             'sector-num': 'int', 'sectors-count': 'int' } }
 
 ##
-# @VSERPORT_CHANGE:
-#
-# Emitted when the guest opens or closes a virtio-serial port.
-#
-# @id: device identifier of the virtio-serial port
-#
-# @open: true if the guest has opened the virtio-serial port
-#
-# Since: 2.1
-#
-# Example:
-#
-# <- { "event": "VSERPORT_CHANGE",
-#      "data": { "id": "channel0", "open": true },
-#      "timestamp": { "seconds": 1401385907, "microseconds": 422329 } }
-#
-##
-{ 'event': 'VSERPORT_CHANGE',
-  'data': { 'id': 'str', 'open': 'bool' } }
-
-##
 # @MEM_UNPLUG_ERROR:
 #
 # Emitted when memory hot unplug error occurs.
Signature · 1 line
2.13.5
#40 lore raw

[Qemu-devel] [PULL v2 20/47] qapi-schema: Collect run state stuff in qapi/run-state.json

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 MAINTAINERS         |   1 +
 Makefile            |   1 +
 qapi-schema.json    | 165 +-----------------------
 qapi/event.json     | 182 ---------------------------
 qapi/run-state.json | 352 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 355 insertions(+), 346 deletions(-)
 create mode 100644 qapi/run-state.json
MAINTAINERS +1 -0
index fb90a19b3d..289ea8c575 100644
@@ -1338,6 +1338,7 @@ F: cpus.c
 F: util/main-loop.c
 F: util/qemu-timer.c
 F: vl.c
+F: qapi/run-state.json
 
 Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
Makefile +1 -0
index ca4a03c376..d3ba41afb8 100644
@@ -413,6 +413,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/crypto.json \
                $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
                $(SRC_PATH)/qapi/rocker.json \
+               $(SRC_PATH)/qapi/run-state.json \
                $(SRC_PATH)/qapi/sockets.json \
                $(SRC_PATH)/qapi/trace.json
 
qapi-schema.json +1 -164

189 lines not on this page · raw message

qapi/event.json +0 -182

200 lines not on this page · raw message

qapi/run-state.json new file +352 -0

352 lines not on this page · raw message

Signature · 1 line
2.13.5
#41 lore raw

[Qemu-devel] [PULL v2 44/47] qapi: Mechanically convert FOO_lookup[...] to FOO_str(...)

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 backends/hostmem.c                  |  2 +-
 block/backup.c                      |  2 +-
 block/file-posix.c                  |  4 +--
 block/file-win32.c                  |  2 +-
 block/gluster.c                     |  4 +--
 block/iscsi.c                       |  2 +-
 block/nfs.c                         |  2 +-
 block/qcow2.c                       |  4 +--
 block/qed.c                         |  2 +-
 block/rbd.c                         |  2 +-
 block/sheepdog.c                    |  2 +-
 blockdev.c                          |  4 +--
 blockjob.c                          |  6 ++---
 chardev/char.c                      |  4 +--
 crypto/block-luks.c                 | 12 ++++-----
 crypto/block.c                      |  4 +--
 crypto/cipher-afalg.c               |  2 +-
 crypto/cipher-builtin.c             |  8 +++---
 crypto/cipher-gcrypt.c              |  4 +--
 crypto/cipher-nettle.c              |  8 +++---
 crypto/hmac-gcrypt.c                |  2 +-
 crypto/hmac-glib.c                  |  2 +-
 crypto/hmac-nettle.c                |  2 +-
 crypto/pbkdf-gcrypt.c               |  2 +-
 crypto/pbkdf-nettle.c               |  2 +-
 hmp.c                               | 54 ++++++++++++++++++-------------------
 hw/block/fdc.c                      |  6 ++---
 hw/char/escc.c                      |  2 +-
 hw/input/virtio-input-hid.c         |  4 +--
 migration/colo-failover.c           |  4 +--
 migration/colo.c                    | 14 +++++-----
 migration/global_state.c            |  2 +-
 monitor.c                           | 16 +++++------
 net/net.c                           |  4 +--
 qapi/qmp-dispatch.c                 |  2 +-
 tests/test-qapi-util.c              |  2 +-
 tests/test-qobject-input-visitor.c  |  4 +--
 tests/test-qobject-output-visitor.c |  2 +-
 tests/test-string-input-visitor.c   |  2 +-
 tests/test-string-output-visitor.c  |  4 +--
 tpm.c                               |  2 +-
 ui/input-legacy.c                   |  4 +--
 ui/input.c                          | 12 ++++-----
 ui/vnc.c                            |  6 ++---
 vl.c                                |  6 ++---
 45 files changed, 121 insertions(+), 121 deletions(-)
backends/hostmem.c +1 -1
index 4606b73849..06e8898e40 100644
@@ -304,7 +304,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
             return;
         } else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
             error_setg(errp, "host-nodes must be set for policy %s",
-                       HostMemPolicy_lookup[backend->policy]);
+                       HostMemPolicy_str(backend->policy));
             return;
         }
 
block/backup.c +1 -1
index 504a089150..517c300a49 100644
@@ -596,7 +596,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
         error_setg(errp,
                    "a sync_bitmap was provided to backup_run, "
                    "but received an incompatible sync_mode (%s)",
-                   MirrorSyncMode_lookup[sync_mode]);
+                   MirrorSyncMode_str(sync_mode));
         return NULL;
     }
 
block/file-posix.c +2 -2
index d81eccc191..bfef91db63 100644
@@ -1724,7 +1724,7 @@ static int raw_regular_truncate(int fd, int64_t offset, PreallocMode prealloc,
     default:
         result = -ENOTSUP;
         error_setg(errp, "Unsupported preallocation mode: %s",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return result;
     }
 
@@ -1759,7 +1759,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Preallocation mode '%s' unsupported for this "
-                   "non-regular file", PreallocMode_lookup[prealloc]);
+                   "non-regular file", PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/file-win32.c +1 -1
index 192ea819d9..f2a1830060 100644
@@ -469,7 +469,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/gluster.c +2 -2
index 0614e0c8aa..29f9427e47 100644
@@ -1047,7 +1047,7 @@ static int qemu_gluster_create(const char *filename,
     default:
         ret = -EINVAL;
         error_setg(errp, "Unsupported preallocation mode: %s",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         break;
     }
 
@@ -1099,7 +1099,7 @@ static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/iscsi.c +1 -1
index d557c99668..8b47d30dcc 100644
@@ -2087,7 +2087,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/nfs.c +1 -1
index bec16b72a6..337fcd9c84 100644
@@ -772,7 +772,7 @@ static int nfs_file_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/qcow2.c +2 -2
index 3a93983e3f..cbe9681fb0 100644
@@ -2715,7 +2715,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
         int64_t prealloc_size =
             qcow2_calc_prealloc_size(total_size, cluster_size, refcount_order);
         qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_abort);
-        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc],
+        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_str(prealloc),
                      &error_abort);
     }
 
@@ -3080,7 +3080,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
         prealloc != PREALLOC_MODE_FALLOC && prealloc != PREALLOC_MODE_FULL)
     {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/qed.c +1 -1
index dc54bf4a93..28e2ec89e8 100644
@@ -1399,7 +1399,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/rbd.c +1 -1
index 9c3aa638e7..144f350e1f 100644
@@ -944,7 +944,7 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
block/sheepdog.c +1 -1
index abb2e79065..1052098ec5 100644
@@ -2176,7 +2176,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset,
 
     if (prealloc != PREALLOC_MODE_OFF) {
         error_setg(errp, "Unsupported preallocation mode '%s'",
-                   PreallocMode_lookup[prealloc]);
+                   PreallocMode_str(prealloc));
         return -ENOTSUP;
     }
 
blockdev.c +2 -2
index f90bc9399a..bfb2a95299 100644
@@ -1466,8 +1466,8 @@ static int action_check_completion_mode(BlkActionState *s, Error **errp)
         error_setg(errp,
                    "Action '%s' does not support Transaction property "
                    "completion-mode = %s",
-                   TransactionActionKind_lookup[s->action->type],
-                   ActionCompletionMode_lookup[s->txn_props->completion_mode]);
+                   TransactionActionKind_str(s->action->type),
+                   ActionCompletionMode_str(s->txn_props->completion_mode));
         return -1;
     }
     return 0;
blockjob.c +3 -3
index 70a78188b7..3a0c49137e 100644
@@ -208,7 +208,7 @@ static char *child_job_get_parent_desc(BdrvChild *c)
 {
     BlockJob *job = c->opaque;
     return g_strdup_printf("%s job '%s'",
-                           BlockJobType_lookup[job->driver->job_type],
+                           BlockJobType_str(job->driver->job_type),
                            job->id);
 }
 
@@ -553,7 +553,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
         return NULL;
     }
     info = g_new0(BlockJobInfo, 1);
-    info->type      = g_strdup(BlockJobType_lookup[job->driver->job_type]);
+    info->type      = g_strdup(BlockJobType_str(job->driver->job_type));
     info->device    = g_strdup(job->id);
     info->len       = job->len;
     info->busy      = job->busy;
@@ -666,7 +666,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
     job->refcnt        = 1;
 
     error_setg(&job->blocker, "block device is in use by block job: %s",
-               BlockJobType_lookup[driver->job_type]);
+               BlockJobType_str(driver->job_type));
     block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
     bs->job = job;
 
chardev/char.c +2 -2
index 5d283b90d3..b6fd5eb6a6 100644
@@ -931,7 +931,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
     ChardevReturn *ret;
     Chardev *chr;
 
-    cc = char_get_class(ChardevBackendKind_lookup[backend->type], errp);
+    cc = char_get_class(ChardevBackendKind_str(backend->type), errp);
     if (!cc) {
         return NULL;
     }
@@ -989,7 +989,7 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
         return NULL;
     }
 
-    cc = char_get_class(ChardevBackendKind_lookup[backend->type], errp);
+    cc = char_get_class(ChardevBackendKind_str(backend->type), errp);
     if (!cc) {
         return NULL;
     }
crypto/block-luks.c +6 -6
index 84d189a426..4e828951d4 100644
@@ -257,7 +257,7 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
     }
 
     error_setg(errp, "Algorithm '%s' not supported",
-               QCryptoCipherAlgorithm_lookup[alg]);
+               QCryptoCipherAlgorithm_str(alg));
     return NULL;
 }
 
@@ -392,7 +392,7 @@ qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm cipher,
         break;
     default:
         error_setg(errp, "Cipher %s not supported with essiv",
-                   QCryptoCipherAlgorithm_lookup[cipher]);
+                   QCryptoCipherAlgorithm_str(cipher));
         return 0;
     }
 }
@@ -962,16 +962,16 @@ qcrypto_block_luks_create(QCryptoBlock *block,
         goto error;
     }
 
-    cipher_mode = QCryptoCipherMode_lookup[luks_opts.cipher_mode];
-    ivgen_alg = QCryptoIVGenAlgorithm_lookup[luks_opts.ivgen_alg];
+    cipher_mode = QCryptoCipherMode_str(luks_opts.cipher_mode);
+    ivgen_alg = QCryptoIVGenAlgorithm_str(luks_opts.ivgen_alg);
     if (luks_opts.has_ivgen_hash_alg) {
-        ivgen_hash_alg = QCryptoHashAlgorithm_lookup[luks_opts.ivgen_hash_alg];
+        ivgen_hash_alg = QCryptoHashAlgorithm_str(luks_opts.ivgen_hash_alg);
         cipher_mode_spec = g_strdup_printf("%s-%s:%s", cipher_mode, ivgen_alg,
                                            ivgen_hash_alg);
     } else {
         cipher_mode_spec = g_strdup_printf("%s-%s", cipher_mode, ivgen_alg);
     }
-    hash_alg = QCryptoHashAlgorithm_lookup[luks_opts.hash_alg];
+    hash_alg = QCryptoHashAlgorithm_str(luks_opts.hash_alg);
 
 
     if (strlen(cipher_alg) >= QCRYPTO_BLOCK_LUKS_CIPHER_NAME_LEN) {
crypto/block.c +2 -2
index b097d451af..c382393d9a 100644
@@ -61,7 +61,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions *options,
     if (options->format >= G_N_ELEMENTS(qcrypto_block_drivers) ||
         !qcrypto_block_drivers[options->format]) {
         error_setg(errp, "Unsupported block driver %s",
-                   QCryptoBlockFormat_lookup[options->format]);
+                   QCryptoBlockFormat_str(options->format));
         g_free(block);
         return NULL;
     }
@@ -92,7 +92,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
     if (options->format >= G_N_ELEMENTS(qcrypto_block_drivers) ||
         !qcrypto_block_drivers[options->format]) {
         error_setg(errp, "Unsupported block driver %s",
-                   QCryptoBlockFormat_lookup[options->format]);
+                   QCryptoBlockFormat_str(options->format));
         g_free(block);
         return NULL;
     }
crypto/cipher-afalg.c +1 -1
index 01343b2b7c..cd72284690 100644
@@ -52,7 +52,7 @@ qcrypto_afalg_cipher_format_name(QCryptoCipherAlgorithm alg,
         return NULL;
     }
 
-    mode_name = QCryptoCipherMode_lookup[mode];
+    mode_name = QCryptoCipherMode_str(mode);
     name = g_strdup_printf("%s(%s)", mode_name, alg_name);
 
     return name;
crypto/cipher-builtin.c +4 -4
index 16a36d4532..d8c811fd33 100644
@@ -247,7 +247,7 @@ qcrypto_cipher_init_aes(QCryptoCipherMode mode,
         mode != QCRYPTO_CIPHER_MODE_ECB &&
         mode != QCRYPTO_CIPHER_MODE_XTS) {
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[mode]);
+                   QCryptoCipherMode_str(mode));
         return NULL;
     }
 
@@ -379,7 +379,7 @@ qcrypto_cipher_init_des_rfb(QCryptoCipherMode mode,
 
     if (mode != QCRYPTO_CIPHER_MODE_ECB) {
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[mode]);
+                   QCryptoCipherMode_str(mode));
         return NULL;
     }
 
@@ -440,7 +440,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
         break;
     default:
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[mode]);
+                   QCryptoCipherMode_str(mode));
         return NULL;
     }
 
@@ -460,7 +460,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
     default:
         error_setg(errp,
                    "Unsupported cipher algorithm %s",
-                   QCryptoCipherAlgorithm_lookup[alg]);
+                   QCryptoCipherAlgorithm_str(alg));
         return NULL;
     }
 
crypto/cipher-gcrypt.c +2 -2
index 0489147398..10d75da75d 100644
@@ -105,7 +105,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
         break;
     default:
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[mode]);
+                   QCryptoCipherMode_str(mode));
         return NULL;
     }
 
@@ -160,7 +160,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
 
     default:
         error_setg(errp, "Unsupported cipher algorithm %s",
-                   QCryptoCipherAlgorithm_lookup[alg]);
+                   QCryptoCipherAlgorithm_str(alg));
         return NULL;
     }
 
crypto/cipher-nettle.c +4 -4
index c51f119cbc..3848cb3b3a 100644
@@ -281,7 +281,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
         break;
     default:
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[mode]);
+                   QCryptoCipherMode_str(mode));
         return NULL;
     }
 
@@ -420,7 +420,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
 
     default:
         error_setg(errp, "Unsupported cipher algorithm %s",
-                   QCryptoCipherAlgorithm_lookup[alg]);
+                   QCryptoCipherAlgorithm_str(alg));
         goto error;
     }
 
@@ -491,7 +491,7 @@ qcrypto_nettle_cipher_encrypt(QCryptoCipher *cipher,
 
     default:
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[cipher->mode]);
+                   QCryptoCipherMode_str(cipher->mode));
         return -1;
     }
     return 0;
@@ -537,7 +537,7 @@ qcrypto_nettle_cipher_decrypt(QCryptoCipher *cipher,
 
     default:
         error_setg(errp, "Unsupported cipher mode %s",
-                   QCryptoCipherMode_lookup[cipher->mode]);
+                   QCryptoCipherMode_str(cipher->mode));
         return -1;
     }
     return 0;
crypto/hmac-gcrypt.c +1 -1
index 76ca61ba24..0c6f979711 100644
@@ -52,7 +52,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg,
 
     if (!qcrypto_hmac_supports(alg)) {
         error_setg(errp, "Unsupported hmac algorithm %s",
-                   QCryptoHashAlgorithm_lookup[alg]);
+                   QCryptoHashAlgorithm_str(alg));
         return NULL;
     }
 
crypto/hmac-glib.c +1 -1
index 8cf6b221ed..a6c1730291 100644
@@ -58,7 +58,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg,
 
     if (!qcrypto_hmac_supports(alg)) {
         error_setg(errp, "Unsupported hmac algorithm %s",
-                   QCryptoHashAlgorithm_lookup[alg]);
+                   QCryptoHashAlgorithm_str(alg));
         return NULL;
     }
 
crypto/hmac-nettle.c +1 -1
index 1d5a915f03..ec2d61bdde 100644
@@ -106,7 +106,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg,
 
     if (!qcrypto_hmac_supports(alg)) {
         error_setg(errp, "Unsupported hmac algorithm %s",
-                   QCryptoHashAlgorithm_lookup[alg]);
+                   QCryptoHashAlgorithm_str(alg));
         return NULL;
     }
 
crypto/pbkdf-gcrypt.c +1 -1
index 40289858bf..54ca0d9c75 100644
@@ -68,7 +68,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash,
         hash_map[hash] == GCRY_MD_NONE) {
         error_setg_errno(errp, ENOSYS,
                          "PBKDF does not support hash algorithm %s",
-                         QCryptoHashAlgorithm_lookup[hash]);
+                         QCryptoHashAlgorithm_str(hash));
         return -1;
     }
 
crypto/pbkdf-nettle.c +1 -1
index 6fb2671656..212b3e816b 100644
@@ -110,7 +110,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash,
     default:
         error_setg_errno(errp, ENOSYS,
                          "PBKDF does not support hash algorithm %s",
-                         QCryptoHashAlgorithm_lookup[hash]);
+                         QCryptoHashAlgorithm_str(hash));
         return -1;
     }
     return 0;
hmp.c +27 -27

170 lines not on this page · raw message

hw/block/fdc.c +3 -3
index 401129073b..db40e174c9 100644
@@ -392,9 +392,9 @@ static int pick_geometry(FDrive *drv)
             FLOPPY_DPRINTF("User requested floppy drive type '%s', "
                            "but inserted medium appears to be a "
                            "%"PRId64" sector '%s' type\n",
-                           FloppyDriveType_lookup[drv->drive],
+                           FloppyDriveType_str(drv->drive),
                            nb_sectors,
-                           FloppyDriveType_lookup[parse->drive]);
+                           FloppyDriveType_str(parse->drive));
         }
         match = type_match;
     }
@@ -403,7 +403,7 @@ static int pick_geometry(FDrive *drv)
     if (match == -1) {
         error_setg(&error_abort, "No candidate geometries present in table "
                    " for floppy drive type '%s'",
-                   FloppyDriveType_lookup[drv->drive]);
+                   FloppyDriveType_str(drv->drive));
     }
 
     parse = &(fd_formats[match]);
hw/char/escc.c +1 -1
index 1aca564e33..3ab831a6a7 100644
@@ -848,7 +848,7 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,
     assert(evt->type == INPUT_EVENT_KIND_KEY);
     key = evt->u.key.data;
     qcode = qemu_input_key_value_to_qcode(key->key);
-    trace_escc_sunkbd_event_in(qcode, QKeyCode_lookup[qcode],
+    trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode),
                                key->down);
 
     if (qcode == Q_KEY_CODE_CAPS_LOCK) {
hw/input/virtio-input-hid.c +2 -2
index 46c038110c..4d3afc1b14 100644
@@ -209,7 +209,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
         } else {
             if (key->down) {
                 fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__,
-                        qcode, QKeyCode_lookup[qcode]);
+                        qcode, QKeyCode_str(qcode));
             }
         }
         break;
@@ -224,7 +224,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
             if (btn->down) {
                 fprintf(stderr, "%s: unmapped button: %d [%s]\n", __func__,
                         btn->button,
-                        InputButton_lookup[btn->button]);
+                        InputButton_str(btn->button));
             }
         }
         break;
migration/colo-failover.c +2 -2
index f9914869c5..6563862b36 100644
@@ -34,7 +34,7 @@ static void colo_failover_bh(void *opaque)
                                    FAILOVER_STATUS_ACTIVE);
     if (old_state != FAILOVER_STATUS_REQUIRE) {
         error_report("Unknown error for failover, old_state = %s",
-                    FailoverStatus_lookup[old_state]);
+                    FailoverStatus_str(old_state));
         return;
     }
 
@@ -64,7 +64,7 @@ FailoverStatus failover_set_state(FailoverStatus old_state,
 
     old = atomic_cmpxchg(&failover_state, old_state, new_state);
     if (old == old_state) {
-        trace_colo_failover_set_state(FailoverStatus_lookup[new_state]);
+        trace_colo_failover_set_state(FailoverStatus_str(new_state));
     }
     return old;
 }
migration/colo.c +7 -7
index a4255432ac..dee3aa8bf7 100644
@@ -61,7 +61,7 @@ static void secondary_vm_do_failover(void)
                         FAILOVER_STATUS_RELAUNCH);
         if (old_state != FAILOVER_STATUS_ACTIVE) {
             error_report("Unknown error while do failover for secondary VM,"
-                         "old_state: %s", FailoverStatus_lookup[old_state]);
+                         "old_state: %s", FailoverStatus_str(old_state));
         }
         return;
     }
@@ -91,7 +91,7 @@ static void secondary_vm_do_failover(void)
                                    FAILOVER_STATUS_COMPLETED);
     if (old_state != FAILOVER_STATUS_ACTIVE) {
         error_report("Incorrect state (%s) while doing failover for "
-                     "secondary VM", FailoverStatus_lookup[old_state]);
+                     "secondary VM", FailoverStatus_str(old_state));
         return;
     }
     /* Notify COLO incoming thread that failover work is finished */
@@ -126,7 +126,7 @@ static void primary_vm_do_failover(void)
                                    FAILOVER_STATUS_COMPLETED);
     if (old_state != FAILOVER_STATUS_ACTIVE) {
         error_report("Incorrect state (%s) while doing failover for Primary VM",
-                     FailoverStatus_lookup[old_state]);
+                     FailoverStatus_str(old_state));
         return;
     }
     /* Notify COLO thread that failover work is finished */
@@ -222,7 +222,7 @@ static void colo_send_message(QEMUFile *f, COLOMessage msg,
     if (ret < 0) {
         error_setg_errno(errp, -ret, "Can't send COLO message");
     }
-    trace_colo_send_message(COLOMessage_lookup[msg]);
+    trace_colo_send_message(COLOMessage_str(msg));
 }
 
 static void colo_send_message_value(QEMUFile *f, COLOMessage msg,
@@ -242,7 +242,7 @@ static void colo_send_message_value(QEMUFile *f, COLOMessage msg,
     ret = qemu_file_get_error(f);
     if (ret < 0) {
         error_setg_errno(errp, -ret, "Failed to send value for message:%s",
-                         COLOMessage_lookup[msg]);
+                         COLOMessage_str(msg));
     }
 }
 
@@ -261,7 +261,7 @@ static COLOMessage colo_receive_message(QEMUFile *f, Error **errp)
         error_setg(errp, "%s: Invalid message", __func__);
         return msg;
     }
-    trace_colo_receive_message(COLOMessage_lookup[msg]);
+    trace_colo_receive_message(COLOMessage_str(msg));
     return msg;
 }
 
@@ -299,7 +299,7 @@ static uint64_t colo_receive_message_value(QEMUFile *f, uint32_t expect_msg,
     ret = qemu_file_get_error(f);
     if (ret < 0) {
         error_setg_errno(errp, -ret, "Failed to get value for COLO message: %s",
-                         COLOMessage_lookup[expect_msg]);
+                         COLOMessage_str(expect_msg));
     }
     return value;
 }
migration/global_state.c +1 -1
index 76cd3a13d4..8db2f19459 100644
@@ -41,7 +41,7 @@ int global_state_store(void)
 
 void global_state_store_running(void)
 {
-    const char *state = RunState_lookup[RUN_STATE_RUNNING];
+    const char *state = RunState_str(RUN_STATE_RUNNING);
     strncpy((char *)global_state.runstate,
            state, sizeof(global_state.runstate));
 }
monitor.c +8 -8
index 86438f4b75..9239f7adde 100644
@@ -928,7 +928,7 @@ EventInfoList *qmp_query_events(Error **errp)
     QAPIEvent e;
 
     for (e = 0 ; e < QAPI_EVENT__MAX ; e++) {
-        const char *event_name = QAPIEvent_lookup[e];
+        const char *event_name = QAPIEvent_str(e);
         assert(event_name != NULL);
         info = g_malloc0(sizeof(*info));
         info->value = g_malloc0(sizeof(*info->value));
@@ -3250,7 +3250,7 @@ void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
     len = strlen(str);
     readline_set_completion_index(rs, len);
     for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
-        add_completion_option(rs, str, NetClientDriver_lookup[i]);
+        add_completion_option(rs, str, NetClientDriver_str(i));
     }
 }
 
@@ -3434,8 +3434,8 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
     len = strlen(str);
     readline_set_completion_index(rs, len);
     for (i = 0; i < Q_KEY_CODE__MAX; i++) {
-        if (!strncmp(str, QKeyCode_lookup[i], len)) {
-            readline_add_completion(rs, QKeyCode_lookup[i]);
+        if (!strncmp(str, QKeyCode_str(i), len)) {
+            readline_add_completion(rs, QKeyCode_str(i));
         }
     }
 }
@@ -3538,7 +3538,7 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
     }
     readline_set_completion_index(rs, strlen(str));
     for (i = 0; i < WATCHDOG_EXPIRATION_ACTION__MAX; i++) {
-        add_completion_option(rs, str, WatchdogExpirationAction_lookup[i]);
+        add_completion_option(rs, str, WatchdogExpirationAction_str(i));
     }
 }
 
@@ -3552,7 +3552,7 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
     if (nb_args == 2) {
         int i;
         for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-            const char *name = MigrationCapability_lookup[i];
+            const char *name = MigrationCapability_str(i);
             if (!strncmp(str, name, len)) {
                 readline_add_completion(rs, name);
             }
@@ -3573,7 +3573,7 @@ void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
     if (nb_args == 2) {
         int i;
         for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
-            const char *name = MigrationParameter_lookup[i];
+            const char *name = MigrationParameter_str(i);
             if (!strncmp(str, name, len)) {
                 readline_add_completion(rs, name);
             }
@@ -3852,7 +3852,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
         qdict = qdict_get_qdict(qobject_to_qdict(rsp), "error");
         if (qdict
             && !g_strcmp0(qdict_get_try_str(qdict, "class"),
-                    QapiErrorClass_lookup[ERROR_CLASS_COMMAND_NOT_FOUND])) {
+                    QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND))) {
             /* Provide a more useful error message */
             qdict_del(qdict, "desc");
             qdict_put_str(qdict, "desc", "Expecting capabilities negotiation"
net/net.c +2 -2
index 0e28099554..2fa99c0497 100644
@@ -1064,7 +1064,7 @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp)
         /* FIXME drop when all init functions store an Error */
         if (errp && !*errp) {
             error_setg(errp, QERR_DEVICE_INIT_FAILED,
-                       NetClientDriver_lookup[netdev->type]);
+                       NetClientDriver_str(netdev->type));
         }
         return -1;
     }
@@ -1288,7 +1288,7 @@ void print_net_client(Monitor *mon, NetClientState *nc)
 
     monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
                    nc->queue_index,
-                   NetClientDriver_lookup[nc->info->type],
+                   NetClientDriver_str(nc->info->type),
                    nc->info_str);
     if (!QTAILQ_EMPTY(&nc->filters)) {
         monitor_printf(mon, "filters:\n");
qapi/qmp-dispatch.c +1 -1
index 5ad36f8a09..b41fa174fe 100644
@@ -118,7 +118,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
 QObject *qmp_build_error_object(Error *err)
 {
     return qobject_from_jsonf("{ 'class': %s, 'desc': %s }",
-                              QapiErrorClass_lookup[error_get_class(err)],
+                              QapiErrorClass_str(error_get_class(err)),
                               error_get_pretty(err));
 }
 
tests/test-qapi-util.c +1 -1
index 7e1be1d851..0992bdb218 100644
@@ -31,7 +31,7 @@ static void test_qapi_enum_parse(void)
     ret = qapi_enum_parse(QType_lookup, "none", -1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE_NONE);
 
-    ret = qapi_enum_parse(QType_lookup, QType_lookup[QTYPE__MAX - 1],
+    ret = qapi_enum_parse(QType_lookup, QType_str(QTYPE__MAX - 1),
                           QTYPE__MAX - 1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE__MAX - 1);
 }
tests/test-qobject-input-visitor.c +2 -2
index 5bbfb65a02..f8720aa5eb 100644
@@ -385,7 +385,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
     for (i = 0; i < ENUM_ONE__MAX; i++) {
         EnumOne res = -1;
 
-        v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]);
+        v = visitor_input_test_init(data, "%s", EnumOne_str(i));
 
         visit_type_EnumOne(v, NULL, &res, &error_abort);
         g_assert_cmpint(i, ==, res);
@@ -699,7 +699,7 @@ static void test_native_list_integer_helper(TestInputVisitorData *data,
         }
     }
     g_string_append_printf(gstr_union,  "{ 'type': '%s', 'data': [ %s ] }",
-                           UserDefNativeListUnionKind_lookup[kind],
+                           UserDefNativeListUnionKind_str(kind),
                            gstr_list->str);
     v = visitor_input_test_init_raw(data,  gstr_union->str);
 
tests/test-qobject-output-visitor.c +1 -1
index 7eb162059c..d375100a52 100644
@@ -133,7 +133,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
 
         qstr = qobject_to_qstring(visitor_get(data));
         g_assert(qstr);
-        g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]);
+        g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_str(i));
         visitor_reset(data);
     }
 }
tests/test-string-input-visitor.c +1 -1
index e7a7b80c92..4f9c36bef1 100644
@@ -282,7 +282,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
     for (i = 0; i < ENUM_ONE__MAX; i++) {
         EnumOne res = -1;
 
-        v = visitor_input_test_init(data, EnumOne_lookup[i]);
+        v = visitor_input_test_init(data, EnumOne_str(i));
 
         visit_type_EnumOne(v, NULL, &res, &err);
         g_assert(!err);
tests/test-string-output-visitor.c +2 -2
index e736db3af8..385cddb5d9 100644
@@ -194,12 +194,12 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
 
         str = visitor_get(data);
         if (data->human) {
-            char *str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]);
+            char *str_human = g_strdup_printf("\"%s\"", EnumOne_str(i));
 
             g_assert_cmpstr(str, ==, str_human);
             g_free(str_human);
         } else {
-            g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
+            g_assert_cmpstr(str, ==, EnumOne_str(i));
         }
         visitor_reset(data);
     }
tpm.c +1 -1
index 38f3eb827f..111f1ca63f 100644
@@ -62,7 +62,7 @@ static void tpm_display_backend_drivers(void)
             continue;
         }
         fprintf(stderr, "%12s   %s\n",
-                TpmType_lookup[i], be_drivers[i]->desc());
+                TpmType_str(i), be_drivers[i]->desc());
     }
     fprintf(stderr, "\n");
 }
ui/input-legacy.c +2 -2
index a5f1e829c3..6bc3525499 100644
@@ -62,8 +62,8 @@ int index_from_key(const char *key, size_t key_length)
     int i;
 
     for (i = 0; i < Q_KEY_CODE__MAX; i++) {
-        if (!strncmp(key, QKeyCode_lookup[i], key_length) &&
-            !QKeyCode_lookup[i][key_length]) {
+        if (!strncmp(key, QKeyCode_str(i), key_length) &&
+            !QKeyCode_str(i)[key_length]) {
             break;
         }
     }
ui/input.c +6 -6
index af05f06368..3422d4a8ef 100644
@@ -151,7 +151,7 @@ void qmp_input_send_event(bool has_device, const char *device,
         if (!qemu_input_find_handler(1 << event->type, con)) {
             error_setg(errp, "Input handler not found for "
                              "event type %s",
-                            InputEventKind_lookup[event->type]);
+                            InputEventKind_str(event->type));
             return;
         }
     }
@@ -213,12 +213,12 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
         switch (key->key->type) {
         case KEY_VALUE_KIND_NUMBER:
             qcode = qemu_input_key_number_to_qcode(key->key->u.number.data);
-            name = QKeyCode_lookup[qcode];
+            name = QKeyCode_str(qcode);
             trace_input_event_key_number(idx, key->key->u.number.data,
                                          name, key->down);
             break;
         case KEY_VALUE_KIND_QCODE:
-            name = QKeyCode_lookup[key->key->u.qcode.data];
+            name = QKeyCode_str(key->key->u.qcode.data);
             trace_input_event_key_qcode(idx, name, key->down);
             break;
         case KEY_VALUE_KIND__MAX:
@@ -228,17 +228,17 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
         break;
     case INPUT_EVENT_KIND_BTN:
         btn = evt->u.btn.data;
-        name = InputButton_lookup[btn->button];
+        name = InputButton_str(btn->button);
         trace_input_event_btn(idx, name, btn->down);
         break;
     case INPUT_EVENT_KIND_REL:
         move = evt->u.rel.data;
-        name = InputAxis_lookup[move->axis];
+        name = InputAxis_str(move->axis);
         trace_input_event_rel(idx, name, move->value);
         break;
     case INPUT_EVENT_KIND_ABS:
         move = evt->u.abs.data;
-        name = InputAxis_lookup[move->axis];
+        name = InputAxis_str(move->axis);
         trace_input_event_abs(idx, name, move->value);
         break;
     case INPUT_EVENT_KIND__MAX:
ui/vnc.c +3 -3
index fd43f9b983..0b5dbc62e4 100644
@@ -131,7 +131,7 @@ static void vnc_init_basic_info(SocketAddress *addr,
     case SOCKET_ADDRESS_TYPE_VSOCK:
     case SOCKET_ADDRESS_TYPE_FD:
         error_setg(errp, "Unsupported socket address type %s",
-                   SocketAddressType_lookup[addr->type]);
+                   SocketAddressType_str(addr->type));
         break;
     default:
         abort();
@@ -416,7 +416,7 @@ VncInfo *qmp_query_vnc(Error **errp)
         case SOCKET_ADDRESS_TYPE_VSOCK:
         case SOCKET_ADDRESS_TYPE_FD:
             error_setg(errp, "Unsupported socket address type %s",
-                       SocketAddressType_lookup[addr->type]);
+                       SocketAddressType_str(addr->type));
             goto out_error;
         default:
             abort();
@@ -1839,7 +1839,7 @@ static void vnc_release_modifiers(VncState *vs)
 
 static const char *code2name(int keycode)
 {
-    return QKeyCode_lookup[qemu_input_key_number_to_qcode(keycode)];
+    return QKeyCode_str(qemu_input_key_number_to_qcode(keycode));
 }
 
 static void key_event(VncState *vs, int down, uint32_t sym)
vl.c +3 -3
index 8e247cc2a2..0b45e1b6fa 100644
@@ -688,7 +688,7 @@ bool runstate_check(RunState state)
 
 bool runstate_store(char *str, size_t size)
 {
-    const char *state = RunState_lookup[current_run_state];
+    const char *state = RunState_str(current_run_state);
     size_t len = strlen(state) + 1;
 
     if (len > size) {
@@ -721,8 +721,8 @@ void runstate_set(RunState new_state)
 
     if (!runstate_valid_transitions[current_run_state][new_state]) {
         error_report("invalid runstate transition: '%s' -> '%s'",
-                     RunState_lookup[current_run_state],
-                     RunState_lookup[new_state]);
+                     RunState_str(current_run_state),
+                     RunState_str(new_state));
         abort();
     }
     trace_runstate_set(new_state);
Signature · 1 line
2.13.5
#42 lore raw

[Qemu-devel] [PULL v2 19/47] qapi-schema: Collect sockets stuff in qapi/sockets.json

In reply to Markus Armbruster
Cc "Daniel P. Berrange" <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Paolo Bonzini <[email protected]>

Message-Id: <[email protected]>

---
 MAINTAINERS          |   1 +
 Makefile             |   4 +-
 qapi-schema.json     | 152 +--------------------------------------------------
 qapi/block-core.json |   2 +-
 qapi/common.json     |  11 ++++
 qapi/sockets.json    | 147 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 164 insertions(+), 153 deletions(-)
 create mode 100644 qapi/sockets.json
MAINTAINERS +1 -0
index ccee28b12d..fb90a19b3d 100644
@@ -1535,6 +1535,7 @@ M: Paolo Bonzini <[email protected]>
 S: Maintained
 F: include/qemu/sockets.h
 F: util/qemu-sockets.c
+F: qapi/sockets.json
 
 Throttling infrastructure
 M: Alberto Garcia <[email protected]>
Makefile +3 -1
index 81447b1f08..ca4a03c376 100644
@@ -410,8 +410,10 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 
 qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
+               $(SRC_PATH)/qapi/crypto.json \
                $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
-               $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \
+               $(SRC_PATH)/qapi/rocker.json \
+               $(SRC_PATH)/qapi/sockets.json \
                $(SRC_PATH)/qapi/trace.json
 
 qapi-types.c qapi-types.h :\
qapi-schema.json +1 -151

176 lines not on this page · raw message

qapi/block-core.json +1 -1
index 833c602150..5379674292 100644
@@ -4,8 +4,8 @@
 # == QAPI block core definitions (vm unrelated)
 ##
 
-# QAPI common definitions
 { 'include': 'common.json' }
+{ 'include': 'sockets.json' }
 
 ##
 # @SnapshotInfo:
qapi/common.json +11 -0
index 8355d5a2f3..862e73f982 100644
@@ -162,3 +162,14 @@
 ##
 { 'enum': 'OnOffSplit',
   'data': [ 'on', 'off', 'split' ] }
+
+##
+# @String:
+#
+# A fat type wrapping 'str', to be embedded in lists.
+#
+# Since: 1.2
+##
+{ 'struct': 'String',
+  'data': {
+    'str': 'str' } }
qapi/sockets.json new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.13.5
#43 lore raw

[Qemu-devel] [PULL v2 46/47] qapi: Change data type of the FOO_lookup generated for enum FOO

In reply to Markus Armbruster

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

Currently, a FOO_lookup is an array of strings terminated by a NULL sentinel.

A future patch will generate enums with "holes". NULL-termination will cease to work then.

To prepare for that, store the length in the FOO_lookup by wrapping it in a struct and adding a member for the length.

The sentinel will be dropped next.

Message-Id: <[email protected]>

[Basically redone]

Message-Id: <[email protected]> [Rebased]

---
 backends/hostmem.c                 |  2 +-
 block.c                            |  2 +-
 block/blkdebug.c                   |  4 ++--
 block/file-posix.c                 |  8 +++++---
 block/file-win32.c                 |  2 +-
 block/gluster.c                    |  4 ++--
 block/parallels.c                  | 14 ++++++++------
 block/qcow2.c                      |  4 ++--
 block/quorum.c                     |  2 +-
 blockdev.c                         |  2 +-
 crypto/block-luks.c                |  8 ++++----
 crypto/secret.c                    |  2 +-
 crypto/tlscreds.c                  |  2 +-
 hmp.c                              |  6 +++---
 hw/core/qdev-properties.c          | 10 +++++-----
 include/hw/qdev-core.h             |  2 +-
 include/qapi/util.h                |  9 +++++++--
 include/qapi/visitor.h             |  2 +-
 include/qom/object.h               |  4 ++--
 migration/global_state.c           |  2 +-
 net/filter.c                       |  2 +-
 qapi/qapi-util.c                   | 12 ++++++------
 qapi/qapi-visit-core.c             | 24 +++++++++++++-----------
 qemu-img.c                         |  2 +-
 qemu-nbd.c                         |  2 +-
 qom/object.c                       | 16 ++++++++--------
 scripts/qapi-visit.py              |  2 +-
 scripts/qapi.py                    | 13 ++++++++-----
 tests/check-qom-proplist.c         | 15 +++++++++------
 tests/qmp-test.c                   |  2 +-
 tests/test-qapi-util.c             | 10 +++++-----
 tests/test-qobject-input-visitor.c |  2 +-
 tpm.c                              |  2 +-
 33 files changed, 106 insertions(+), 89 deletions(-)
backends/hostmem.c +1 -1
index 06e8898e40..217cff6766 100644
@@ -395,7 +395,7 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
         host_memory_backend_set_host_nodes,
         NULL, NULL, &error_abort);
     object_class_property_add_enum(oc, "policy", "HostMemPolicy",
-        HostMemPolicy_lookup,
+        &HostMemPolicy_lookup,
         host_memory_backend_get_policy,
         host_memory_backend_set_policy, &error_abort);
     object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
block.c +1 -1
index 845eff8177..b749bd6404 100644
@@ -1332,7 +1332,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
     detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
     if (detect_zeroes) {
         BlockdevDetectZeroesOptions value =
-            qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
+            qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
                             detect_zeroes,
                             BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                             &local_err);
block/blkdebug.c +2 -2
index b370fcedfb..8e385acf54 100644
@@ -169,7 +169,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
         error_setg(errp, "Missing event name for rule");
         return -1;
     }
-    event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp);
+    event = qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp);
     if (event < 0) {
         return -1;
     }
@@ -732,7 +732,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
     struct BlkdebugRule *rule;
     int blkdebug_event;
 
-    blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL);
+    blkdebug_event = qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, NULL);
     if (blkdebug_event < 0) {
         return -ENOENT;
     }
block/file-posix.c +5 -3
index bfef91db63..6acbd56238 100644
@@ -437,7 +437,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO)
                   ? BLOCKDEV_AIO_OPTIONS_NATIVE
                   : BLOCKDEV_AIO_OPTIONS_THREADS;
-    aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
+    aio = qapi_enum_parse(&BlockdevAioOptions_lookup,
+                          qemu_opt_get(opts, "aio"),
                           aio_default, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
@@ -446,7 +447,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
     s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
 
-    locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
+    locking = qapi_enum_parse(&OnOffAuto_lookup,
+                              qemu_opt_get(opts, "locking"),
                               ON_OFF_AUTO_AUTO, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
@@ -1973,7 +1975,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
                           BDRV_SECTOR_SIZE);
     nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-    prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
+    prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
                                PREALLOC_MODE_OFF, &local_err);
     g_free(buf);
     if (local_err) {
block/file-win32.c +1 -1
index f2a1830060..9e02214a69 100644
@@ -302,7 +302,7 @@ static bool get_aio_option(QemuOpts *opts, int flags, Error **errp)
 
     aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
                                               : BLOCKDEV_AIO_OPTIONS_THREADS;
-    aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
+    aio = qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
                           aio_default, errp);
 
     switch (aio) {
block/gluster.c +2 -2
index 29f9427e47..0f4265a3a4 100644
@@ -543,7 +543,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
         if (!strcmp(ptr, "tcp")) {
             ptr = "inet";       /* accept legacy "tcp" */
         }
-        type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL);
+        type = qapi_enum_parse(&SocketAddressType_lookup, ptr, -1, NULL);
         if (type != SOCKET_ADDRESS_TYPE_INET
             && type != SOCKET_ADDRESS_TYPE_UNIX) {
             error_setg(&local_err,
@@ -1000,7 +1000,7 @@ static int qemu_gluster_create(const char *filename,
                           BDRV_SECTOR_SIZE);
 
     tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-    prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
+    prealloc = qapi_enum_parse(&PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
                                &local_err);
     g_free(tmp);
     if (local_err) {
block/parallels.c +8 -6
index d812210b4f..cce7336cac 100644
@@ -68,13 +68,15 @@ typedef enum ParallelsPreallocMode {
     PRL_PREALLOC_MODE__MAX = 2,
 } ParallelsPreallocMode;
 
-static const char *prealloc_mode_lookup[] = {
-    "falloc",
-    "truncate",
-    NULL,
+static QEnumLookup prealloc_mode_lookup = {
+    .array = (const char *const[]) {
+        "falloc",
+        "truncate",
+        NULL,
+    },
+    .size = PRL_PREALLOC_MODE__MAX
 };
 
-
 typedef struct BDRVParallelsState {
     /** Locking is conservative, the lock protects
      *   - image file extending (truncate, fallocate)
@@ -695,7 +697,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
         qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
     s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
     buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
-    s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
+    s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf,
                                        PRL_PREALLOC_MODE_FALLOCATE,
                                        &local_err);
     g_free(buf);
block/qcow2.c +2 -2
index cbe9681fb0..2ec399663e 100644
@@ -2915,7 +2915,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
         goto finish;
     }
     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-    prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
+    prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
                                PREALLOC_MODE_OFF, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
@@ -3605,7 +3605,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
     }
 
     optstr = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-    prealloc = qapi_enum_parse(PreallocMode_lookup, optstr,
+    prealloc = qapi_enum_parse(&PreallocMode_lookup, optstr,
                                PREALLOC_MODE_OFF, &local_err);
     g_free(optstr);
     if (local_err) {
block/quorum.c +1 -1
index 8d1c9f6306..272f9a5b77 100644
@@ -912,7 +912,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
     if (!pattern_str) {
         ret = QUORUM_READ_PATTERN_QUORUM;
     } else {
-        ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str,
+        ret = qapi_enum_parse(&QuorumReadPattern_lookup, pattern_str,
                               -EINVAL, NULL);
     }
     if (ret < 0) {
blockdev.c +1 -1
index bfb2a95299..796beaed94 100644
@@ -437,7 +437,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
 
     if (detect_zeroes) {
         *detect_zeroes =
-            qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
+            qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
                             qemu_opt_get(opts, "detect-zeroes"),
                             BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                             &local_error);
crypto/block-luks.c +4 -4
index 4e828951d4..36bc856084 100644
@@ -264,7 +264,7 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
 /* XXX replace with qapi_enum_parse() in future, when we can
  * make that function emit a more friendly error message */
 static int qcrypto_block_luks_name_lookup(const char *name,
-                                          const char *const *map,
+                                          const QEnumLookup *map,
                                           const char *type,
                                           Error **errp)
 {
@@ -279,19 +279,19 @@ static int qcrypto_block_luks_name_lookup(const char *name,
 
 #define qcrypto_block_luks_cipher_mode_lookup(name, errp)               \
     qcrypto_block_luks_name_lookup(name,                                \
-                                   QCryptoCipherMode_lookup,            \
+                                   &QCryptoCipherMode_lookup,           \
                                    "Cipher mode",                       \
                                    errp)
 
 #define qcrypto_block_luks_hash_name_lookup(name, errp)                 \
     qcrypto_block_luks_name_lookup(name,                                \
-                                   QCryptoHashAlgorithm_lookup,         \
+                                   &QCryptoHashAlgorithm_lookup,        \
                                    "Hash algorithm",                    \
                                    errp)
 
 #define qcrypto_block_luks_ivgen_name_lookup(name, errp)                \
     qcrypto_block_luks_name_lookup(name,                                \
-                                   QCryptoIVGenAlgorithm_lookup,        \
+                                   &QCryptoIVGenAlgorithm_lookup,       \
                                    "IV generator",                      \
                                    errp)
 
crypto/secret.c +1 -1
index 285ab7a63c..388abd7df5 100644
@@ -378,7 +378,7 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data)
                                    NULL);
     object_class_property_add_enum(oc, "format",
                                    "QCryptoSecretFormat",
-                                   QCryptoSecretFormat_lookup,
+                                   &QCryptoSecretFormat_lookup,
                                    qcrypto_secret_prop_get_format,
                                    qcrypto_secret_prop_set_format,
                                    NULL);
crypto/tlscreds.c +1 -1
index a8965531b6..3cd41035bb 100644
@@ -233,7 +233,7 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data)
                                   NULL);
     object_class_property_add_enum(oc, "endpoint",
                                    "QCryptoTLSCredsEndpoint",
-                                   QCryptoTLSCredsEndpoint_lookup,
+                                   &QCryptoTLSCredsEndpoint_lookup,
                                    qcrypto_tls_creds_prop_get_endpoint,
                                    qcrypto_tls_creds_prop_set_endpoint,
                                    NULL);
hmp.c +3 -3
index 30819fe602..cd046c6d71 100644
@@ -1528,7 +1528,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
     MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
     int val;
 
-    val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
+    val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
     if (val < 0) {
         goto end;
     }
@@ -1557,7 +1557,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
     int val, ret;
 
-    val = qapi_enum_parse(MigrationParameter_lookup, param, -1, &err);
+    val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
     if (val < 0) {
         goto cleanup;
     }
@@ -1735,7 +1735,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
     } else {
         if (read_only) {
             read_only_mode =
-                qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
+                qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
                                 read_only,
                                 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
             if (err) {
hw/core/qdev-properties.c +5 -5
index 7512bd4379..1dc80fcea2 100644
@@ -587,7 +587,7 @@ const PropertyInfo qdev_prop_macaddr = {
 const PropertyInfo qdev_prop_on_off_auto = {
     .name = "OnOffAuto",
     .description = "on/off/auto",
-    .enum_table = OnOffAuto_lookup,
+    .enum_table = &OnOffAuto_lookup,
     .get = get_enum,
     .set = set_enum,
     .set_default_value = set_default_value_enum,
@@ -599,7 +599,7 @@ QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
 
 const PropertyInfo qdev_prop_losttickpolicy = {
     .name  = "LostTickPolicy",
-    .enum_table  = LostTickPolicy_lookup,
+    .enum_table  = &LostTickPolicy_lookup,
     .get   = get_enum,
     .set   = set_enum,
     .set_default_value = set_default_value_enum,
@@ -613,7 +613,7 @@ const PropertyInfo qdev_prop_blockdev_on_error = {
     .name = "BlockdevOnError",
     .description = "Error handling policy, "
                    "report/ignore/enospc/stop/auto",
-    .enum_table = BlockdevOnError_lookup,
+    .enum_table = &BlockdevOnError_lookup,
     .get = get_enum,
     .set = set_enum,
     .set_default_value = set_default_value_enum,
@@ -627,7 +627,7 @@ const PropertyInfo qdev_prop_bios_chs_trans = {
     .name = "BiosAtaTranslation",
     .description = "Logical CHS translation algorithm, "
                    "auto/none/lba/large/rechs",
-    .enum_table = BiosAtaTranslation_lookup,
+    .enum_table = &BiosAtaTranslation_lookup,
     .get = get_enum,
     .set = set_enum,
     .set_default_value = set_default_value_enum,
@@ -639,7 +639,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {
     .name = "FdcDriveType",
     .description = "FDC drive type, "
                    "144/288/120/none/auto",
-    .enum_table = FloppyDriveType_lookup,
+    .enum_table = &FloppyDriveType_lookup,
     .get = get_enum,
     .set = set_enum,
     .set_default_value = set_default_value_enum,
include/hw/qdev-core.h +1 -1
index ae317286a4..089146197f 100644
@@ -249,7 +249,7 @@ struct Property {
 struct PropertyInfo {
     const char *name;
     const char *description;
-    const char * const *enum_table;
+    const QEnumLookup *enum_table;
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
     void (*set_default_value)(Object *obj, const Property *prop);
     void (*create)(Object *obj, Property *prop, Error **errp);
include/qapi/util.h +7 -2
index 5e50d0c1ce..a7c3c64148 100644
@@ -11,8 +11,13 @@
 #ifndef QAPI_UTIL_H
 #define QAPI_UTIL_H
 
-const char *qapi_enum_lookup(const char *const lookup[], int val);
-int qapi_enum_parse(const char * const lookup[], const char *buf,
+typedef struct QEnumLookup {
+    const char *const *array;
+    int size;
+} QEnumLookup;
+
+const char *qapi_enum_lookup(const QEnumLookup *lookup, int val);
+int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
                     int def, Error **errp);
 
 int parse_qapi_name(const char *name, bool complete);
include/qapi/visitor.h +1 -1
index 0f3b8cb459..62a51a54cb 100644
@@ -469,7 +469,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present);
  * that visit_type_str() must have no unwelcome side effects.
  */
 void visit_type_enum(Visitor *v, const char *name, int *obj,
-                     const char *const strings[], Error **errp);
+                     const QEnumLookup *lookup, Error **errp);
 
 /*
  * Check if visitor is an input visitor.
include/qom/object.h +2 -2
index 1b828994fa..f3e5cff37a 100644
@@ -1415,14 +1415,14 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name,
  */
 void object_property_add_enum(Object *obj, const char *name,
                               const char *typename,
-                              const char * const *strings,
+                              const QEnumLookup *lookup,
                               int (*get)(Object *, Error **),
                               void (*set)(Object *, int, Error **),
                               Error **errp);
 
 void object_class_property_add_enum(ObjectClass *klass, const char *name,
                                     const char *typename,
-                                    const char * const *strings,
+                                    const QEnumLookup *lookup,
                                     int (*get)(Object *, Error **),
                                     void (*set)(Object *, int, Error **),
                                     Error **errp);
migration/global_state.c +1 -1
index 8db2f19459..dfdaf63910 100644
@@ -88,7 +88,7 @@ static int global_state_post_load(void *opaque, int version_id)
     s->received = true;
     trace_migrate_global_state_post_load(runstate);
 
-    r = qapi_enum_parse(RunState_lookup, runstate, -1, &local_err);
+    r = qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err);
 
     if (r == -1) {
         if (local_err) {
net/filter.c +1 -1
index 1dfd2caa23..2fd7d7d663 100644
@@ -179,7 +179,7 @@ static void netfilter_init(Object *obj)
                             netfilter_get_netdev_id, netfilter_set_netdev_id,
                             NULL);
     object_property_add_enum(obj, "queue", "NetFilterDirection",
-                             NetFilterDirection_lookup,
+                             &NetFilterDirection_lookup,
                              netfilter_get_direction, netfilter_set_direction,
                              NULL);
     object_property_add_str(obj, "status",
qapi/qapi-util.c +6 -6
index 7af2f04d36..e9b266bb70 100644
@@ -14,14 +14,14 @@
 #include "qapi/error.h"
 #include "qemu-common.h"
 
-const char *qapi_enum_lookup(const char *const lookup[], int val)
+const char *qapi_enum_lookup(const QEnumLookup *lookup, int val)
 {
-    assert(val >= 0);
+    assert(val >= 0 && val < lookup->size);
 
-    return lookup[val];
+    return lookup->array[val];
 }
 
-int qapi_enum_parse(const char * const lookup[], const char *buf,
+int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
                     int def, Error **errp)
 {
     int i;
@@ -30,8 +30,8 @@ int qapi_enum_parse(const char * const lookup[], const char *buf,
         return def;
     }
 
-    for (i = 0; lookup[i]; i++) {
-        if (!strcmp(buf, lookup[i])) {
+    for (i = 0; i < lookup->size; i++) {
+        if (!strcmp(buf, lookup->array[i])) {
             return i;
         }
     }
qapi/qapi-visit-core.c +13 -11
index 30dc85b6f3..3dcb968867 100644
@@ -333,24 +333,26 @@ void visit_type_null(Visitor *v, const char *name, QNull **obj,
 }
 
 static void output_type_enum(Visitor *v, const char *name, int *obj,
-                             const char *const strings[], Error **errp)
+                             const QEnumLookup *lookup, Error **errp)
 {
-    int i = 0;
     int value = *obj;
     char *enum_str;
 
-    while (strings[i++] != NULL);
-    if (value < 0 || value >= i - 1) {
+    /*
+     * TODO why is this an error, not an assertion?  If assertion:
+     * delete, and rely on qapi_enum_lookup()
+     */
+    if (value < 0 || value >= lookup->size) {
         error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null");
         return;
     }
 
-    enum_str = (char *)qapi_enum_lookup(strings, value);
+    enum_str = (char *)qapi_enum_lookup(lookup, value);
     visit_type_str(v, name, &enum_str, errp);
 }
 
 static void input_type_enum(Visitor *v, const char *name, int *obj,
-                            const char *const strings[], Error **errp)
+                            const QEnumLookup *lookup, Error **errp)
 {
     Error *local_err = NULL;
     int64_t value;
@@ -362,7 +364,7 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
         return;
     }
 
-    value = qapi_enum_parse(strings, enum_str, -1, NULL);
+    value = qapi_enum_parse(lookup, enum_str, -1, NULL);
     if (value < 0) {
         error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
         g_free(enum_str);
@@ -374,16 +376,16 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
 }
 
 void visit_type_enum(Visitor *v, const char *name, int *obj,
-                     const char *const strings[], Error **errp)
+                     const QEnumLookup *lookup, Error **errp)
 {
-    assert(obj && strings);
+    assert(obj && lookup);
     trace_visit_type_enum(v, name, obj);
     switch (v->type) {
     case VISITOR_INPUT:
-        input_type_enum(v, name, obj, strings, errp);
+        input_type_enum(v, name, obj, lookup, errp);
         break;
     case VISITOR_OUTPUT:
-        output_type_enum(v, name, obj, strings, errp);
+        output_type_enum(v, name, obj, lookup, errp);
         break;
     case VISITOR_CLONE:
         /* nothing further to do, scalar value was already copied by
qemu-img.c +1 -1
index a72a2e3133..df984b11b9 100644
@@ -3489,7 +3489,7 @@ static int img_resize(int argc, char **argv)
             image_opts = true;
             break;
         case OPTION_PREALLOCATION:
-            prealloc = qapi_enum_parse(PreallocMode_lookup, optarg,
+            prealloc = qapi_enum_parse(&PreallocMode_lookup, optarg,
                                        PREALLOC_MODE__MAX, NULL);
             if (prealloc == PREALLOC_MODE__MAX) {
                 error_report("Invalid preallocation mode '%s'", optarg);
qemu-nbd.c +1 -1
index a97f3f4540..d75ca51482 100644
@@ -638,7 +638,7 @@ int main(int argc, char **argv)
             break;
         case QEMU_NBD_OPT_DETECT_ZEROES:
             detect_zeroes =
-                qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
+                qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
                                 optarg,
                                 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                                 &local_err);
qom/object.c +8 -8
index fe6e744b4d..3e18537e9b 100644
@@ -1246,7 +1246,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
 }
 
 typedef struct EnumProperty {
-    const char * const *strings;
+    const QEnumLookup *lookup;
     int (*get)(Object *, Error **);
     void (*set)(Object *, int, Error **);
 } EnumProperty;
@@ -1284,7 +1284,7 @@ int object_property_get_enum(Object *obj, const char *name,
     visit_complete(v, &str);
     visit_free(v);
     v = string_input_visitor_new(str);
-    visit_type_enum(v, name, &ret, enumprop->strings, errp);
+    visit_type_enum(v, name, &ret, enumprop->lookup, errp);
 
     g_free(str);
     visit_free(v);
@@ -1950,7 +1950,7 @@ static void property_get_enum(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    visit_type_enum(v, name, &value, prop->strings, errp);
+    visit_type_enum(v, name, &value, prop->lookup, errp);
 }
 
 static void property_set_enum(Object *obj, Visitor *v, const char *name,
@@ -1960,7 +1960,7 @@ static void property_set_enum(Object *obj, Visitor *v, const char *name,
     int value;
     Error *err = NULL;
 
-    visit_type_enum(v, name, &value, prop->strings, &err);
+    visit_type_enum(v, name, &value, prop->lookup, &err);
     if (err) {
         error_propagate(errp, err);
         return;
@@ -1977,7 +1977,7 @@ static void property_release_enum(Object *obj, const char *name,
 
 void object_property_add_enum(Object *obj, const char *name,
                               const char *typename,
-                              const char * const *strings,
+                              const QEnumLookup *lookup,
                               int (*get)(Object *, Error **),
                               void (*set)(Object *, int, Error **),
                               Error **errp)
@@ -1985,7 +1985,7 @@ void object_property_add_enum(Object *obj, const char *name,
     Error *local_err = NULL;
     EnumProperty *prop = g_malloc(sizeof(*prop));
 
-    prop->strings = strings;
+    prop->lookup = lookup;
     prop->get = get;
     prop->set = set;
 
@@ -2002,7 +2002,7 @@ void object_property_add_enum(Object *obj, const char *name,
 
 void object_class_property_add_enum(ObjectClass *klass, const char *name,
                                     const char *typename,
-                                    const char * const *strings,
+                                    const QEnumLookup *lookup,
                                     int (*get)(Object *, Error **),
                                     void (*set)(Object *, int, Error **),
                                     Error **errp)
@@ -2010,7 +2010,7 @@ void object_class_property_add_enum(ObjectClass *klass, const char *name,
     Error *local_err = NULL;
     EnumProperty *prop = g_malloc(sizeof(*prop));
 
-    prop->strings = strings;
+    prop->lookup = lookup;
     prop->get = get;
     prop->set = set;
 
scripts/qapi-visit.py +1 -1
index bd0b742236..7e1cfc13f0 100644
@@ -153,7 +153,7 @@ def gen_visit_enum(name):
 void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, Error **errp)
 {
     int value = *obj;
-    visit_type_enum(v, name, &value, %(c_name)s_lookup, errp);
+    visit_type_enum(v, name, &value, &%(c_name)s_lookup, errp);
     *obj = value;
 }
 ''',
scripts/qapi.py +8 -5
index 8736b9c786..39a67270fc 100644
@@ -1849,19 +1849,22 @@ def guardend(name):
 def gen_enum_lookup(name, values, prefix=None):
     ret = mcgen('''
 
-const char *const %(c_name)s_lookup[] = {
+const QEnumLookup %(c_name)s_lookup = {
+    .array = (const char *const[]) {
 ''',
                 c_name=c_name(name))
     for value in values:
         index = c_enum_const(name, value, prefix)
         ret += mcgen('''
-    [%(index)s] = "%(value)s",
+        [%(index)s] = "%(value)s",
 ''',
                      index=index, value=value)
 
     max_index = c_enum_const(name, '_MAX', prefix)
     ret += mcgen('''
-    [%(max_index)s] = NULL,
+        [%(max_index)s] = NULL,
+    },
+    .size = %(max_index)s
 };
 ''',
                  max_index=max_index)
@@ -1895,9 +1898,9 @@ typedef enum %(c_name)s {
     ret += mcgen('''
 
 #define %(c_name)s_str(val) \\
-    qapi_enum_lookup(%(c_name)s_lookup, (val))
+    qapi_enum_lookup(&%(c_name)s_lookup, (val))
 
-extern const char *const %(c_name)s_lookup[];
+extern const QEnumLookup %(c_name)s_lookup;
 ''',
                  c_name=c_name(name))
     return ret
tests/check-qom-proplist.c +9 -6
index c51e6e734d..07e351f950 100644
@@ -46,11 +46,14 @@ enum DummyAnimal {
     DUMMY_LAST,
 };
 
-static const char *const dummy_animal_map[DUMMY_LAST + 1] = {
-    [DUMMY_FROG] = "frog",
-    [DUMMY_ALLIGATOR] = "alligator",
-    [DUMMY_PLATYPUS] = "platypus",
-    [DUMMY_LAST] = NULL,
+const QEnumLookup dummy_animal_map = {
+    .array = (const char *const[]) {
+        [DUMMY_FROG] = "frog",
+        [DUMMY_ALLIGATOR] = "alligator",
+        [DUMMY_PLATYPUS] = "platypus",
+        [DUMMY_LAST] = NULL,
+    },
+    .size = DUMMY_LAST
 };
 
 struct DummyObject {
@@ -142,7 +145,7 @@ static void dummy_class_init(ObjectClass *cls, void *data)
                                   NULL);
     object_class_property_add_enum(cls, "av",
                                    "DummyAnimal",
-                                   dummy_animal_map,
+                                   &dummy_animal_map,
                                    dummy_get_av,
                                    dummy_set_av,
                                    NULL);
tests/qmp-test.c +1 -1
index ec99814f79..ed8f45ad82 100644
@@ -181,7 +181,7 @@ static void test_query(const void *data)
         g_assert(qdict_haskey(resp, "return"));
     } else {
         g_assert(error);
-        g_assert_cmpint(qapi_enum_parse(QapiErrorClass_lookup, error_class,
+        g_assert_cmpint(qapi_enum_parse(&QapiErrorClass_lookup, error_class,
                                         -1, &error_abort),
                         ==, expected_error_class);
     }
tests/test-qapi-util.c +5 -5
index 0992bdb218..4b5e4f8bd3 100644
@@ -19,19 +19,19 @@ static void test_qapi_enum_parse(void)
     Error *err = NULL;
     int ret;
 
-    ret = qapi_enum_parse(QType_lookup, NULL, QTYPE_NONE, &error_abort);
+    ret = qapi_enum_parse(&QType_lookup, NULL, QTYPE_NONE, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE_NONE);
 
-    ret = qapi_enum_parse(QType_lookup, "junk", -1, NULL);
+    ret = qapi_enum_parse(&QType_lookup, "junk", -1, NULL);
     g_assert_cmpint(ret, ==, -1);
 
-    ret = qapi_enum_parse(QType_lookup, "junk", -1, &err);
+    ret = qapi_enum_parse(&QType_lookup, "junk", -1, &err);
     error_free_or_abort(&err);
 
-    ret = qapi_enum_parse(QType_lookup, "none", -1, &error_abort);
+    ret = qapi_enum_parse(&QType_lookup, "none", -1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE_NONE);
 
-    ret = qapi_enum_parse(QType_lookup, QType_str(QTYPE__MAX - 1),
+    ret = qapi_enum_parse(&QType_lookup, QType_str(QTYPE__MAX - 1),
                           QTYPE__MAX - 1, &error_abort);
     g_assert_cmpint(ret, ==, QTYPE__MAX - 1);
 }
tests/test-qobject-input-visitor.c +1 -1
index f8720aa5eb..fe591814e4 100644
@@ -1110,7 +1110,7 @@ static void test_visitor_in_fail_struct_missing(TestInputVisitorData *data,
     error_free_or_abort(&err);
     visit_optional(v, "optional", &present);
     g_assert(!present);
-    visit_type_enum(v, "enum", &en, EnumOne_lookup, &err);
+    visit_type_enum(v, "enum", &en, &EnumOne_lookup, &err);
     error_free_or_abort(&err);
     visit_type_int(v, "i64", &i64, &err);
     error_free_or_abort(&err);
tpm.c +1 -1
index 111f1ca63f..2d830d072a 100644
@@ -33,7 +33,7 @@ void tpm_register_model(enum TpmModel model)
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type)
 {
-    int i = qapi_enum_parse(TpmType_lookup, type, -1, NULL);
+    int i = qapi_enum_parse(&TpmType_lookup, type, -1, NULL);
 
     return i >= 0 ? be_drivers[i] : NULL;
 }
Signature · 1 line
2.13.5
#44 lore raw

[Qemu-devel] [PULL v2 22/47] qapi-schema: Collect net device stuff in qapi/net.json

In reply to Markus Armbruster

Message-Id: <[email protected]>

---
 MAINTAINERS      |   1 +
 Makefile         |   1 +
 qapi-schema.json | 675 +---------------------------------------------------
 qapi/event.json  |  24 --
 qapi/net.json    | 706 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 709 insertions(+), 698 deletions(-)
 create mode 100644 qapi/net.json
MAINTAINERS +1 -0
index 6a808d33ba..aecde6585e 100644
@@ -1356,6 +1356,7 @@ S: Maintained
 F: net/
 F: include/net/
 T: git git://github.com/jasowang/qemu.git net
+F: qapi/net.json
 
 Netmap network backend
 M: Luigi Rizzo <[email protected]>
Makefile +1 -0
index 59ef46cc3e..75f3ffedd7 100644
@@ -413,6 +413,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/char.json \
                $(SRC_PATH)/qapi/crypto.json \
                $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
+               $(SRC_PATH)/qapi/net.json \
                $(SRC_PATH)/qapi/rocker.json \
                $(SRC_PATH)/qapi/run-state.json \
                $(SRC_PATH)/qapi/sockets.json \
qapi-schema.json +1 -674

705 lines not on this page · raw message

qapi/event.json +0 -24
index b9aa6ed7cf..4b327739d7 100644
@@ -51,30 +51,6 @@
   'data': { '*device': 'str', 'path': 'str' } }
 
 ##
-# @NIC_RX_FILTER_CHANGED:
-#
-# Emitted once until the 'query-rx-filter' command is executed, the first event
-# will always be emitted
-#
-# @name: net client name
-#
-# @path: device path
-#
-# Since: 1.6
-#
-# Example:
-#
-# <- { "event": "NIC_RX_FILTER_CHANGED",
-#      "data": { "name": "vnet0",
-#                "path": "/machine/peripheral/vnet0/virtio-backend" },
-#      "timestamp": { "seconds": 1368697518, "microseconds": 326866 } }
-#    }
-#
-##
-{ 'event': 'NIC_RX_FILTER_CHANGED',
-  'data': { '*name': 'str', 'path': 'str' } }
-
-##
 # @VNC_CONNECTED:
 #
 # Emitted when a VNC client establishes a connection
qapi/net.json new file +706 -0

706 lines not on this page · raw message

Signature · 1 line
2.13.5
#45 lore raw

[Qemu-devel] [PULL v2 36/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()

In reply to Markus Armbruster

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

The error message on invalid capability name changes from

Invalid parameter "NAME"

to

invalid parameter value: NAME

No worse than before.

Message-Id: <[email protected]>

[Rebased, commit message rewritten]
Cc "Dr. David Alan Gilbert" <[email protected]>

Message-Id: <[email protected]>

---
 hmp.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
hmp.c +10 -13
index 03c1a783b6..7e0bd3d63b 100644
@@ -1527,23 +1527,20 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
     bool state = qdict_get_bool(qdict, "state");
     Error *err = NULL;
     MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
-    int i;
+    int val;
 
-    for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
-            caps->value = g_malloc0(sizeof(*caps->value));
-            caps->value->capability = i;
-            caps->value->state = state;
-            caps->next = NULL;
-            qmp_migrate_set_capabilities(caps, &err);
-            break;
-        }
+    val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
+    if (val < 0) {
+        goto end;
     }
 
-    if (i == MIGRATION_CAPABILITY__MAX) {
-        error_setg(&err, QERR_INVALID_PARAMETER, cap);
-    }
+    caps->value = g_malloc0(sizeof(*caps->value));
+    caps->value->capability = val;
+    caps->value->state = state;
+    caps->next = NULL;
+    qmp_migrate_set_capabilities(caps, &err);
 
+end:
     qapi_free_MigrationCapabilityStatusList(caps);
 
     if (err) {
Signature · 1 line
2.13.5
#46 lore raw

[Qemu-devel] [PULL v2 38/47] block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()

In reply to Markus Armbruster

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

The error message on invalid blkdebug events changes from

qemu-system-x86_64: LOCATION: Invalid event name "VALUE"

to

qemu-system-x86_64: LOCATION: invalid parameter value: VALUE

Slight degradation, but the message is sub-par even before the patch. When complaining about a parameter value, both parameter name and value should be mentioned, as the value may well not be unique. Left for another day.

Also left is the error message's unhelpful location: it points to the config=FILENAME rather than into that file.

Message-Id: <[email protected]>

[Rebased, commit message rewritten]
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>

Message-Id: <[email protected]>

---
 block/blkdebug.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
block/blkdebug.c +8 -20
index c19ab28f07..f1bbee9497 100644
@@ -32,6 +32,7 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/util.h"
 #include "sysemu/qtest.h"
 
 typedef struct BDRVBlkdebugState {
@@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] = {
     NULL
 };
 
-static int get_event_by_name(const char *name, BlkdebugEvent *event)
-{
-    int i;
-
-    for (i = 0; i < BLKDBG__MAX; i++) {
-        if (!strcmp(BlkdebugEvent_lookup[i], name)) {
-            *event = i;
-            return 0;
-        }
-    }
-
-    return -1;
-}
-
 struct add_rule_data {
     BDRVBlkdebugState *s;
     int action;
@@ -173,7 +160,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
     struct add_rule_data *d = opaque;
     BDRVBlkdebugState *s = d->s;
     const char* event_name;
-    BlkdebugEvent event;
+    int event;
     struct BlkdebugRule *rule;
     int64_t sector;
 
@@ -182,8 +169,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
     if (!event_name) {
         error_setg(errp, "Missing event name for rule");
         return -1;
-    } else if (get_event_by_name(event_name, &event) < 0) {
-        error_setg(errp, "Invalid event name \"%s\"", event_name);
+    }
+    event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp);
+    if (event < 0) {
         return -1;
     }
 
@@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
 {
     BDRVBlkdebugState *s = bs->opaque;
     struct BlkdebugRule *rule;
-    BlkdebugEvent blkdebug_event;
+    int blkdebug_event;
 
-    if (get_event_by_name(event, &blkdebug_event) < 0) {
+    blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL);
+    if (blkdebug_event < 0) {
         return -ENOENT;
     }
 
-
     rule = g_malloc(sizeof(*rule));
     *rule = (struct BlkdebugRule) {
         .event  = blkdebug_event,
Signature · 1 line
2.13.5
#47 lore raw

[Qemu-devel] [PULL v2 23/47] qapi-schema: Collect UI stuff in qapi/ui.json

In reply to Markus Armbruster

UI stuff is remote desktop stuff (Spice, VNC) and input stuff (mouse, keyboard).

Message-Id: <[email protected]>

---
 MAINTAINERS      |   2 +
 Makefile         |   3 +-
 qapi-schema.json | 784 +-------------------------------------------
 qapi/event.json  | 175 ----------
 qapi/ui.json     | 977 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 982 insertions(+), 959 deletions(-)
 create mode 100644 qapi/ui.json
MAINTAINERS +2 -0
index aecde6585e..24c5105b12 100644
@@ -1320,12 +1320,14 @@ F: include/ui/spice-display.h
 F: ui/spice-*.c
 F: audio/spiceaudio.c
 F: hw/display/qxl*
+F: qapi/ui.json
 
 Graphics
 M: Gerd Hoffmann <[email protected]>
 S: Odd Fixes
 F: ui/
 F: include/ui/
+F: qapi/ui.json
 
 Cocoa graphics
 M: Peter Maydell <[email protected]>
Makefile +2 -1
index 75f3ffedd7..c7b6fd1a1c 100644
@@ -417,7 +417,8 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/rocker.json \
                $(SRC_PATH)/qapi/run-state.json \
                $(SRC_PATH)/qapi/sockets.json \
-               $(SRC_PATH)/qapi/trace.json
+               $(SRC_PATH)/qapi/trace.json \
+               $(SRC_PATH)/qapi/ui.json
 
 qapi-types.c qapi-types.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
qapi-schema.json +1 -783

820 lines not on this page · raw message

qapi/event.json +0 -175

181 lines not on this page · raw message

qapi/ui.json new file +977 -0

977 lines not on this page · raw message

Signature · 1 line
2.13.5
#48 lore raw

[Qemu-devel] [PULL v2 24/47] qapi-schema: Collect migration stuff in qapi/migration.json

In reply to Markus Armbruster
Cc Juan Quintela <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>

Message-Id: <[email protected]>

---
 MAINTAINERS         |    1 +
 Makefile            |    1 +
 qapi-schema.json    | 1056 +------------------------------------------------
 qapi/common.json    |   16 +
 qapi/event.json     |   38 --
 qapi/migration.json | 1085 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1104 insertions(+), 1093 deletions(-)
 create mode 100644 qapi/migration.json
MAINTAINERS +1 -0
index 24c5105b12..baa9859b4a 100644
@@ -1498,6 +1498,7 @@ F: migration/
 F: scripts/vmstate-static-checker.py
 F: tests/vmstate-static-checker-data/
 F: docs/migration.txt
+F: qapi/migration.json
 
 Seccomp
 M: Eduardo Otubo <[email protected]>
Makefile +1 -0
index c7b6fd1a1c..18cf670833 100644
@@ -413,6 +413,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
                $(SRC_PATH)/qapi/char.json \
                $(SRC_PATH)/qapi/crypto.json \
                $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
+               $(SRC_PATH)/qapi/migration.json \
                $(SRC_PATH)/qapi/net.json \
                $(SRC_PATH)/qapi/rocker.json \
                $(SRC_PATH)/qapi/run-state.json \
qapi-schema.json +1 -1055

1,092 lines not on this page · raw message

qapi/common.json +16 -0
index 862e73f982..e2c58564d8 100644
@@ -173,3 +173,19 @@
 { 'struct': 'String',
   'data': {
     'str': 'str' } }
+
+##
+# @StrOrNull:
+#
+# This is a string value or the explicit lack of a string (null
+# pointer in C).  Intended for cases when 'optional absent' already
+# has a different meaning.
+#
+# @s: the string value
+# @n: no string value
+#
+# Since: 2.10
+##
+{ 'alternate': 'StrOrNull',
+  'data': { 's': 'str',
+            'n': 'null' } }
qapi/event.json +0 -38
index f49bd3d564..a043de4cd8 100644
@@ -51,44 +51,6 @@
   'data': { '*device': 'str', 'path': 'str' } }
 
 ##
-# @MIGRATION:
-#
-# Emitted when a migration event happens
-#
-# @status: @MigrationStatus describing the current migration status.
-#
-# Since: 2.4
-#
-# Example:
-#
-# <- {"timestamp": {"seconds": 1432121972, "microseconds": 744001},
-#     "event": "MIGRATION",
-#     "data": {"status": "completed"} }
-#
-##
-{ 'event': 'MIGRATION',
-  'data': {'status': 'MigrationStatus'}}
-
-##
-# @MIGRATION_PASS:
-#
-# Emitted from the source side of a migration at the start of each pass
-# (when it syncs the dirty bitmap)
-#
-# @pass: An incrementing count (starting at 1 on the first pass)
-#
-# Since: 2.6
-#
-# Example:
-#
-# { "timestamp": {"seconds": 1449669631, "microseconds": 239225},
-#   "event": "MIGRATION_PASS", "data": {"pass": 2} }
-#
-##
-{ 'event': 'MIGRATION_PASS',
-  'data': { 'pass': 'int' } }
-
-##
 # @ACPI_DEVICE_OST:
 #
 # Emitted when guest executes ACPI _OST method.
qapi/migration.json new file +1085 -0

1,085 lines not on this page · raw message

Signature · 1 line
2.13.5
#49 lore raw

[Qemu-devel] [PULL v2 34/47] tpm: Clean up driver registration & lookup

In reply to Markus Armbruster

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

We have a strict separation between enum TpmType and be_drivers[]:

* TpmType may have any number of members. It just happens to have one.

* tpm_register_driver() uses the first empty slot in be_drivers[].

If you register more than tpm_models[] has space, tpm_register_driver() fails. Its caller silently ignores the failure.

If you register more than one with a given TpmType, tpm_display_backend_drivers() will shows all of them, but tpm_driver_find_by_type() and tpm_get_backend_driver() will find only the one one that registered first.

Since we only ever register one driver, and be_drivers[] has space for just that one, this contraption even works.

Turn be_drivers[] into a straight map from enum TpmType to driver. Much simpler, and has a decent chance to actually work should we ever acquire additional drivers.

While there, use qapi_enum_parse() in tpm_get_backend_driver().

Message-Id: <[email protected]>

[Rebased, superfluous initializer dropped, commit message rewritten]
Cc Stefan Berger <[email protected]>

Message-Id: <[email protected]>

---
 include/sysemu/tpm_backend.h |  2 +-
 tpm.c                        | 45 +++++++++++++-------------------------------
 2 files changed, 14 insertions(+), 33 deletions(-)
include/sysemu/tpm_backend.h +1 -1
index b58f52d39f..1d21c6b19b 100644
@@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
 int tpm_register_model(enum TpmModel model);
-int tpm_register_driver(const TPMDriverOps *tdo);
+void tpm_register_driver(const TPMDriverOps *tdo);
 
 #endif
tpm.c +13 -32

84 lines not on this page · raw message

Signature · 1 line
2.13.5
#50 lore raw
In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

The following changes since commit 223cd0e13f2e46078d7b573f0b8402bfbee339be:

Merge remote-tracking branch 'remotes/elmarco/tags/tidy-pull-request' into staging (2017-08-31 15:52:43 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2017-09-01-v2

Quoted 8 lines

for you to fetch changes up to fcff1e3146d4b7930f3b4a7a60091479d6652a5f:

qapi: drop the sentinel in enum array (2017-09-01 17:26:24 +0200)

----------------------------------------------------------------
QAPI patches for 2017-09-01

----------------------------------------------------------------

Hi -- I get some compile issues here:

PPC:

/home/pm215/qemu/tests/qmp-test.c: In function ‘query_error_class’:
/home/pm215/qemu/tests/qmp-test.c:141:9: error: missing braces around initializer [-Werror=missing-braces]

         "query-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
         ^

/home/pm215/qemu/tests/qmp-test.c:141:9: error: (near initialization for ‘fails[0]’) [-Werror=missing-braces]

S390, aarch64:

/home/linux1/qemu/tests/qmp-test.c: In function ‘query_error_class’:
/home/linux1/qemu/tests/qmp-test.c:151:9: error: missing braces around initializer [-Werror=missing-braces]
{ "query-acpi-ospm-status", ERROR_CLASS_GENERIC_ERROR }, ^
/home/linux1/qemu/tests/qmp-test.c:151:9: note: (near initialization for ‘fails[1]’)
/home/linux1/qemu/tests/qmp-test.c:152:9: error: missing braces around initializer [-Werror=missing-braces]
{ "query-balloon", ERROR_CLASS_DEVICE_NOT_ACTIVE }, ^
/home/linux1/qemu/tests/qmp-test.c:152:9: note: (near initialization for ‘fails[2]’)
/home/linux1/qemu/tests/qmp-test.c:153:9: error: missing braces around initializer [-Werror=missing-braces]
{ "query-hotpluggable-cpus", ERROR_CLASS_GENERIC_ERROR }, ^
/home/linux1/qemu/tests/qmp-test.c:153:9: note: (near initialization for ‘fails[3]’)
/home/linux1/qemu/tests/qmp-test.c:154:9: error: missing braces around initializer [-Werror=missing-braces]
{ "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR }, ^
/home/linux1/qemu/tests/qmp-test.c:154:9: note: (near initialization for ‘fails[4]’)
/home/linux1/qemu/tests/qmp-test.c:155:9: error: missing braces around initializer [-Werror=missing-braces]

         { NULL, -1 }
         ^

/home/linux1/qemu/tests/qmp-test.c:155:9: note: (near initialization for ‘fails[5]’) /home/linux1/qemu/tests/qmp-test.c:138:17: error: missing braces around initializer [-Werror=missing-braces]

     } fails[] = {
                 ^

/home/linux1/qemu/tests/qmp-test.c:138:17: note: (near initialization for ‘fails’)
cc1: all warnings being treated as errors

OSX, FreeBSD, OpenBSD:

/Users/pm215/src/qemu-for-merges/tests/qmp-test.c:141:9: error:
suggest braces around initialization of subobject [-Werror,-Wmissing-braces]

        "query-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        {                                           }

thanks
-- PMM