QAPI patches for 2018-03-12, 2.12 softfreeze
[Qemu-devel] [PULL v4 06/38] qapi: Add qobject_to()
In reply to Eric BlakeFrom: Max Reitz <[email protected]>
This is a dynamic casting macro that, given a QObject type, returns an object as that type or NULL if the object is of a different type (or NULL itself).
The macro uses lower-case letters because:
1. There does not seem to be a hard rule on whether qemu macros have to be upper-cased,
2. The current situation in qapi/qmp is inconsistent (compare e.g. QINCREF() vs. qdict_put()),
3. qobject_to() will evaluate its @obj parameter only once, thus it is generally not important to the caller whether it is a macro or not,
4. I prefer it aesthetically.
The macro parameter order is chosen with typename first for consistency with other QAPI macros like QAPI_CLONE(), as well as for legibility (read it as "qobject to" type "applied to" obj).
Message-Id: <[email protected]>
[eblake: swap parameter order to list type first, avoid clang ubsan warning on QOBJECT(NULL) and container_of(NULL,type,base)]
--- include/qapi/qmp/qobject.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/qapi/qmp/qobject.h +29 -0
@@ -50,6 +50,21 @@ struct QObject {#define QDECREF (obj) \ qobject_decref(obj ? QOBJECT(obj) : NULL) +/* Required for qobject_to() */ +#define QTYPE_CAST_TO_QNull QTYPE_QNULL +#define QTYPE_CAST_TO_QNum QTYPE_QNUM +#define QTYPE_CAST_TO_QString QTYPE_QSTRING +#define QTYPE_CAST_TO_QDict QTYPE_QDICT +#define QTYPE_CAST_TO_QList QTYPE_QLIST +#define QTYPE_CAST_TO_QBool QTYPE_QBOOL + +QEMU_BUILD_BUG_MSG (QTYPE__MAX !=7 , +"The QTYPE_CAST_TO_* list needs to be extended" ); + +#define qobject_to (type, obj) ({ \ + QObject *_tmp = qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)); \ + _tmp ? container_of(_tmp, type, base) : (type *)NULL; }) +/* Initialize an object to default values */ static inline void qobject_init (QObject *obj,QType type) {
@@ -102,4 +117,18 @@ static inline QType qobject_type(const QObject *obj) return obj->type; } +/** +* qobject_check_type(): Helper function for the qobject_to() macro. +* Return @obj, but only if @obj is not NULL and @type is equal to +* @obj's type. Return NULL otherwise. +*/ +static inline QObject *qobject_check_type (const QObject *obj,QType type) +{ +if (obj &&qobject_type (obj) == type) { +return (QObject *)obj; + }else { +return NULL ; + } +} +#endif /* QOBJECT_H */
Signature · 1 line
2.14.3
The following changes since commit 2c8cfc0b52b5a4d123c26c0b5fdf941be24805be:
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2018-03-19 11:44:26 +0000)
are available in the Git repository at:
git://repo.or.cz/qemu/ericb.git tags/pull-qapi-2018-03-12-v4
for you to fetch changes up to 02e3092db3f9b84ed6aae54e3b71d4dc4196c7eb:
qapi: Pass '-u' when doing non-silent diff (2018-03-19 14:58:38 -0500)
since v3:
silence clang's ubsan warnings about nonportable container_of(NULL) [sending only the one changed patch]
----------------------------------------------------------------
qapi patches for 2018-03-12, 2.12 softfreeze
- Marc-André Lureau: 0/4 qapi: generate a literal qobject for introspection
- Max Reitz: 0/7 block: Handle null backing link
- Daniel P. Berrange: chardev: tcp: postpone TLS work until machine done
- Peter Xu: 00/23 QMP: out-of-band (OOB) execution support
- Vladimir Sementsov-Ogievskiy: 0/2 block latency histogram
- Eric Blake: qapi: Pass '-u' when doing non-silent diff
----------------------------------------------------------------
Daniel P. Berrangé (1):
chardev: tcp: postpone TLS work until machine done
Eric Blake (2):
qmp: add new event "command-dropped"
qapi: Pass '-u' when doing non-silent diff
Marc-André Lureau (4):
qapi2texi: minor python code simplification
qlit: use QType instead of int
qlit: add qobject_from_qlit()
qapi: generate a literal qobject for introspection
Max Reitz (7):
compiler: Add QEMU_BUILD_BUG_MSG() macro
qapi: Add qobject_to()
qapi: Replace qobject_to_X(o) by qobject_to(X, o)
qapi: Remove qobject_to_X() functions
qapi: Make more of qobject_to()
block: Handle null backing link
block: Deprecate "backing": ""
Peter Xu (22):
docs: update QMP documents for OOB commands
qobject: introduce qstring_get_try_str()
qobject: introduce qobject_get_try_str()
qobject: let object_property_get_str() use new API
monitor: move skip_flush into monitor_data_init
monitor: move the cur_mon hack deeper for QMP
monitor: unify global init
monitor: let mon_list be tail queue
monitor: allow using IO thread for parsing
qmp: introduce QMPCapability
monitor: introduce monitor_qmp_respond()
monitor: let suspend_cnt be thread safe
monitor: let suspend/resume work even with QMPs
monitor: separate QMP parser and dispatcher
monitor: send event when command queue full
qapi: introduce new cmd option "allow-oob"
qmp: support out-of-band (oob) execution
qmp: isolate responses into io thread
monitor: enable IO thread for (qmp & !mux) typed
qmp: add command "x-oob-test"
tests: qmp-test: verify command batching
tests: qmp-test: add oob test
Vladimir Sementsov-Ogievskiy (2):
block/accounting: introduce latency histogram
qapi: add block latency histogram interface
docs/devel/qapi-code-gen.txt | 87 ++++- docs/interop/qmp-spec.txt | 36 +- qemu-doc.texi | 7 + qapi/block-core.json | 115 +++++- qapi/introspect.json | 6 +- qapi/misc.json | 87 ++++- scripts/qapi/commands.py | 18 +- scripts/qapi/common.py | 15 +- scripts/qapi/doc.py | 9 +- scripts/qapi/introspect.py | 83 +++-- include/block/accounting.h | 35 ++ include/monitor/monitor.h | 2 +- include/qapi/qmp/dispatch.h | 7 +- include/qapi/qmp/qbool.h | 1 - include/qapi/qmp/qdict.h | 1 - include/qapi/qmp/qlist.h | 1 - include/qapi/qmp/qlit.h | 4 +- include/qapi/qmp/qnum.h | 1 - include/qapi/qmp/qobject.h | 29 ++ include/qapi/qmp/qstring.h | 3 +- include/qemu/compiler.h | 12 +- vl.c | 7 +- tests/libqtest.c | 6 +- block.c | 13 +- block/accounting.c | 91 +++++ block/parallels.c | 2 +- block/qapi.c | 53 ++- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- block/rbd.c | 8 +- block/sheepdog.c | 2 +- block/vhdx.c | 2 +- block/vpc.c | 2 +- blockdev.c | 64 +++- chardev/char-socket.c | 10 + hw/i386/acpi-build.c | 16 +- monitor.c | 706 +++++++++++++++++++++++++++++++----- qapi/qmp-dispatch.c | 35 +- qapi/qobject-input-visitor.c | 24 +- qapi/qobject-output-visitor.c | 4 +- qga/main.c | 2 +- qmp.c | 18 +- qobject/json-parser.c | 13 +- qobject/qbool.c | 15 +- qobject/qdict.c | 65 ++-- qobject/qjson.c | 10 +- qobject/qlist.c | 17 +- qobject/qlit.c | 47 ++- qobject/qnum.c | 17 +- qobject/qstring.c | 38 +- qom/object.c | 15 +- target/i386/cpu.c | 2 +- target/s390x/cpu_models.c | 2 +- tests/check-qdict.c | 20 +- tests/check-qjson.c | 41 ++- tests/check-qlist.c | 4 +- tests/check-qlit.c | 30 +- tests/check-qnum.c | 4 +- tests/check-qobject.c | 2 +- tests/check-qstring.c | 2 +- tests/device-introspect-test.c | 14 +- tests/numa-test.c | 8 +- tests/qmp-test.c | 97 ++++- tests/qom-test.c | 4 +- tests/test-char.c | 2 +- tests/test-keyval.c | 8 +- tests/test-qga.c | 19 +- tests/test-qmp-cmds.c | 12 +- tests/test-qmp-event.c | 16 +- tests/test-qobject-input-visitor.c | 21 +- tests/test-qobject-output-visitor.c | 54 +-- tests/test-x86-cpuid-compat.c | 17 +- util/keyval.c | 4 +- util/qemu-config.c | 2 +- util/qemu-option.c | 6 +- qemu-options.hx | 4 +- tests/Makefile.include | 8 +- tests/qapi-schema/test-qapi.py | 2 +- tests/qemu-iotests/089 | 20 + tests/qemu-iotests/089.out | 8 + trace-events | 3 + 82 files changed, 1809 insertions(+), 494 deletions(-)
Signature · 1 line
2.14.3
Peter Maydell
AppliedQuoted 19 lines · Eric Blake
The following changes since commit
2c8cfc0b52b5a4d123c26c0b5fdf941be24805be:Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2018-03-19 11:44:26 +0000)
are available in the Git repository at:
git://repo.or.cz/qemu/ericb.gittags/pull-qapi-2018-03-12-v4for you to fetch changes up to
02e3092db3f9b84ed6aae54e3b71d4dc4196c7eb:qapi: Pass '-u' when doing non-silent diff (2018-03-19 14:58:38 -0500)
since v3:
silence clang's ubsan warnings about nonportablecontainer_of(NULL)[sending only the one changed patch]----------------------------------------------------------------
qapi patches for 2018-03-12, 2.12 softfreeze
Quoted 7 lines
- Marc-André Lureau: 0/4 qapi: generate a literal qobject for introspection
- Max Reitz: 0/7 block: Handle null backing link
- Daniel P. Berrange: chardev: tcp: postpone TLS work until machine done
- Peter Xu: 00/23 QMP: out-of-band (OOB) execution support
- Vladimir Sementsov-Ogievskiy: 0/2 block latency histogram
- Eric Blake: qapi: Pass '-u' when doing non-silent diff
Applied, thanks.
-- PMM