QAPI/QOM bugfix for QEMU 6.1
[PULL 1/2] qapi: introduce forwarding visitor
In reply to Paolo BonziniThis new adaptor visitor takes a single field of the adaptee, and exposes it with a different name.
This will be used for QOM alias properties. Alias targets can of course have a different name than the alias property itself (e.g. a machine's pflash0 might be an alias of a property named 'drive'). When the target's getter or setter invokes the visitor, it will use a different name than what the caller expects, and the visitor will not be able to find it (or will consume erroneously).
The solution is for alias getters and setters to wrap the incoming visitor, and forward the sole field that the target is expecting while renaming it appropriately.
--- include/qapi/forward-visitor.h | 27 +++ qapi/meson.build | 1 + qapi/qapi-forward-visitor.c | 331 ++++++++++++++++++++++++++++++ tests/unit/meson.build | 1 + tests/unit/test-forward-visitor.c | 193 +++++++++++++++++ 5 files changed, 553 insertions(+) create mode 100644 include/qapi/forward-visitor.h create mode 100644 qapi/qapi-forward-visitor.c create mode 100644 tests/unit/test-forward-visitor.c
include/qapi/forward-visitor.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Forwarding visitor +* +* Copyright Red Hat, Inc. 2021 +* +* Author: Paolo Bonzini <[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 FORWARD_VISITOR_H +#define FORWARD_VISITOR_H + +#include "qapi/visitor.h" + +typedef struct ForwardFieldVisitor ForwardFieldVisitor ; + +/* +* The forwarding visitor only expects a single name, @from, to be passed for +* toplevel fields. It is converted to @to and forwarded to the @target visitor. +* Calls within a struct are forwarded without changing the name. +*/ +Visitor *visitor_forward_field (Visitor *target,const char *from,const char *to); + +#endif
qapi/meson.build +1 -0
@@ -2,6 +2,7 @@ util_ss.add(files( 'opts-visitor.c', 'qapi-clone-visitor.c', 'qapi-dealloc-visitor.c', + 'qapi-forward-visitor.c', 'qapi-util.c', 'qapi-visit-core.c', 'qobject-input-visitor.c',
qapi/qapi-forward-visitor.c new file +331 -0
331 lines not on this page · raw message
tests/unit/meson.build +1 -0
@@ -14,6 +14,7 @@ tests = { 'test-qobject-output-visitor': [testqapi], 'test-clone-visitor': [testqapi], 'test-qobject-input-visitor': [testqapi], + 'test-forward-visitor': [testqapi], 'test-string-input-visitor': [testqapi], 'test-string-output-visitor': [testqapi], 'test-opts-visitor': [testqapi],
tests/unit/test-forward-visitor.c new file +193 -0
193 lines not on this page · raw message
Signature · 1 line
2.31.1
The following changes since commit 143c2e0432859826c9e8d5b2baa307355f1a5332:
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2021-07-19' into staging (2021-07-19 19:06:05 +0100)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream-qapi
for you to fetch changes up to 2f164a6c5e4a9e24a6d33fcd680f322dcf53a44e:
qom: use correct field name when getting/setting alias properties (2021-07-23 11:57:15 +0200)
----------------------------------------------------------------
Fix for QOM alias properties (e.g. -M pflash0).
----------------------------------------------------------------
Paolo Bonzini (2):
qapi: introduce forwarding visitor
qom: use correct field name when getting/setting alias properties
include/qapi/forward-visitor.h | 27 ++++ qapi/meson.build | 1 + qapi/qapi-forward-visitor.c | 331 ++++++++++++++++++++++++++++++++++++++ qom/object.c | 9 +- tests/unit/meson.build | 1 + tests/unit/test-forward-visitor.c | 193 ++++++++++++++++++++++ 6 files changed, 560 insertions(+), 2 deletions(-) create mode 100644 include/qapi/forward-visitor.h create mode 100644 qapi/qapi-forward-visitor.c create mode 100644 tests/unit/test-forward-visitor.c
Signature · 1 line
2.31.1
[PULL 2/2] qom: use correct field name when getting/setting alias properties
Alias targets have a different name than the alias property itself (e.g. a machine's pflash0 might be an alias of a property named 'drive'). When the target's getter or setter invokes the visitor, it will use a different name than what the caller expects, and the visitor will not be able to find it (or will consume erroneously).
The solution is for alias getters and setters to wrap the incoming visitor, and forward the sole field that the target is expecting while renaming it appropriately.
This bug has been there forever, but it was exposed after -M parsing switched from QemuOptions and StringInputVisitor to keyval and QObjectInputVisitor. Before, the visitor ignored the name. Now, it checks "drive" against what was passed on the command line and finds that no such property exists.
--- qom/object.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
qom/object.c +7 -2
@@ -20,6 +20,7 @@#include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" #include "qapi/qobject-input-visitor.h" +#include "qapi/forward-visitor.h" #include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h"
@@ -2683,16 +2684,20 @@ static void property_get_alias(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { AliasProperty *prop = opaque; +Visitor *alias_v =visitor_forward_field (v, prop->target_name, name); -object_property_get (prop->target_obj, prop->target_name, v, errp); +object_property_get (prop->target_obj, prop->target_name, alias_v, errp); +visit_free (alias_v); }static void property_set_alias (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {AliasProperty *prop = opaque; +Visitor *alias_v =visitor_forward_field (v, prop->target_name, name); -object_property_set (prop->target_obj, prop->target_name, v, errp); +object_property_set (prop->target_obj, prop->target_name, alias_v, errp); +visit_free (alias_v); } static Object *property_resolve_alias(Object *obj, void *opaque,
Signature · 1 line
2.31.1
Quoted 13 lines · Paolo Bonzini
The following changes since commit
143c2e0432859826c9e8d5b2baa307355f1a5332:Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2021-07-19' into staging (2021-07-19 19:06:05 +0100)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream-qapi
for you to fetch changes up to
2f164a6c5e4a9e24a6d33fcd680f322dcf53a44e:qom: use correct field name when getting/setting alias properties (2021-07-23 11:57:15 +0200)
Quoted 7 lines
----------------------------------------------------------------
Fix for QOM alias properties (e.g. -M pflash0).----------------------------------------------------------------
Paolo Bonzini (2):
qapi: introduce forwarding visitor
qom: use correct field name when getting/setting alias properties
Hi -- could you check whether this failed gitlab job for build-oss-fuzz is valid or just another flaky CI issue, please?
https://gitlab.com/qemu-project/qemu/-/jobs/1448031475
The backtrace showing the leaks seems to be in the new test case added in this pull, so my guess is it's real...
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 13 lines · Paolo Bonzini
The following changes since commit
143c2e0432859826c9e8d5b2baa307355f1a5332:Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2021-07-19' into staging (2021-07-19 19:06:05 +0100)are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream-qapi
for you to fetch changes up to
2f164a6c5e4a9e24a6d33fcd680f322dcf53a44e:qom: use correct field name when getting/setting alias properties (2021-07-23 11:57:15 +0200)
Quoted 7 lines
----------------------------------------------------------------
Fix for QOM alias properties (e.g. -M pflash0).----------------------------------------------------------------
Paolo Bonzini (2):
qapi: introduce forwarding visitor
qom: use correct field name when getting/setting alias properties
Quoted 7 lines
Hi -- could you check whether this failed gitlab job for build-oss-fuzz is valid or just another flaky CI issue, please?
https://gitlab.com/qemu-project/qemu/-/jobs/1448031475
The backtrace showing the leaks seems to be in the new test case added in this pull, so my guess is it's real...
Yeah, I was about to ask you not to pull this.
Paolo