* [Qemu-devel] [PATCH] qmp: fix object-add assert() without props
@ 2016-09-21 19:41 Marc-André Lureau
2016-09-21 19:53 ` Eric Blake
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Marc-André Lureau @ 2016-09-21 19:41 UTC (permalink / raw)
To: qemu-devel; +Cc: eblake, armbru, qemu-stable, Marc-André Lureau
Since commit ad739706bbadee49, user_creatable_add_type() expects to be
given a qdict. However, if object-add is called without props, you reach
the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
Assertion `qdict' failed.", because the qdict isn't created in this
case (it's optional).
Furthermore, qmp_input_visitor_new() is not meant to be called without a
dict, and a further commit will assert in this situation.
If none given, create an empty qdict in qmp to avoid the
user_creatable_add_type() assert(qdict).
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
qmp.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/qmp.c b/qmp.c
index 6733463..8078038 100644
--- a/qmp.c
+++ b/qmp.c
@@ -665,7 +665,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
void qmp_object_add(const char *type, const char *id,
bool has_props, QObject *props, Error **errp)
{
- const QDict *pdict = NULL;
+ QDict *pdict;
Visitor *v;
Object *obj;
@@ -675,14 +675,19 @@ void qmp_object_add(const char *type, const char *id,
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
return;
}
+ } else {
+ pdict = qdict_new();
}
- v = qmp_input_visitor_new(props, true);
+ v = qmp_input_visitor_new(QOBJECT(pdict), true);
obj = user_creatable_add_type(type, id, pdict, v, errp);
visit_free(v);
if (obj) {
object_unref(obj);
}
+ if (!props) {
+ qobject_decref(QOBJECT(pdict));
+ }
}
void qmp_object_del(const char *id, Error **errp)
--
2.10.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp: fix object-add assert() without props
2016-09-21 19:41 [Qemu-devel] [PATCH] qmp: fix object-add assert() without props Marc-André Lureau
@ 2016-09-21 19:53 ` Eric Blake
2016-09-21 20:05 ` Paolo Bonzini
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Blake @ 2016-09-21 19:53 UTC (permalink / raw)
To: Marc-André Lureau, qemu-devel; +Cc: armbru, qemu-stable
[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]
On 09/21/2016 02:41 PM, Marc-André Lureau wrote:
> Since commit ad739706bbadee49, user_creatable_add_type() expects to be
> given a qdict. However, if object-add is called without props, you reach
> the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
> Assertion `qdict' failed.", because the qdict isn't created in this
> case (it's optional).
>
> Furthermore, qmp_input_visitor_new() is not meant to be called without a
> dict, and a further commit will assert in this situation.
>
> If none given, create an empty qdict in qmp to avoid the
> user_creatable_add_type() assert(qdict).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> qmp.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> if (obj) {
> object_unref(obj);
> }
> + if (!props) {
> + qobject_decref(QOBJECT(pdict));
This can be written:
QDECREF(pdict);
With that simplification,
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp: fix object-add assert() without props
2016-09-21 19:41 [Qemu-devel] [PATCH] qmp: fix object-add assert() without props Marc-André Lureau
2016-09-21 19:53 ` Eric Blake
@ 2016-09-21 20:05 ` Paolo Bonzini
2016-09-22 8:03 ` Daniel P. Berrange
2016-09-22 9:42 ` Markus Armbruster
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-09-21 20:05 UTC (permalink / raw)
To: Marc-André Lureau, qemu-devel; +Cc: armbru, qemu-stable
On 21/09/2016 21:41, Marc-André Lureau wrote:
> Since commit ad739706bbadee49, user_creatable_add_type() expects to be
> given a qdict. However, if object-add is called without props, you reach
> the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
> Assertion `qdict' failed.", because the qdict isn't created in this
> case (it's optional).
>
> Furthermore, qmp_input_visitor_new() is not meant to be called without a
> dict, and a further commit will assert in this situation.
>
> If none given, create an empty qdict in qmp to avoid the
> user_creatable_add_type() assert(qdict).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> qmp.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/qmp.c b/qmp.c
> index 6733463..8078038 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -665,7 +665,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
> void qmp_object_add(const char *type, const char *id,
> bool has_props, QObject *props, Error **errp)
> {
> - const QDict *pdict = NULL;
> + QDict *pdict;
> Visitor *v;
> Object *obj;
>
> @@ -675,14 +675,19 @@ void qmp_object_add(const char *type, const char *id,
> error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
> return;
> }
> + } else {
> + pdict = qdict_new();
> }
>
> - v = qmp_input_visitor_new(props, true);
> + v = qmp_input_visitor_new(QOBJECT(pdict), true);
> obj = user_creatable_add_type(type, id, pdict, v, errp);
> visit_free(v);
> if (obj) {
> object_unref(obj);
> }
> + if (!props) {
> + qobject_decref(QOBJECT(pdict));
Or QDECREF(pdict).
In any case,
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> + }
> }
>
> void qmp_object_del(const char *id, Error **errp)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp: fix object-add assert() without props
2016-09-21 19:41 [Qemu-devel] [PATCH] qmp: fix object-add assert() without props Marc-André Lureau
2016-09-21 19:53 ` Eric Blake
2016-09-21 20:05 ` Paolo Bonzini
@ 2016-09-22 8:03 ` Daniel P. Berrange
2016-09-22 9:42 ` Markus Armbruster
3 siblings, 0 replies; 5+ messages in thread
From: Daniel P. Berrange @ 2016-09-22 8:03 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel, armbru, qemu-stable
On Wed, Sep 21, 2016 at 11:41:26PM +0400, Marc-André Lureau wrote:
> Since commit ad739706bbadee49, user_creatable_add_type() expects to be
> given a qdict. However, if object-add is called without props, you reach
> the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
> Assertion `qdict' failed.", because the qdict isn't created in this
> case (it's optional).
>
> Furthermore, qmp_input_visitor_new() is not meant to be called without a
> dict, and a further commit will assert in this situation.
>
> If none given, create an empty qdict in qmp to avoid the
> user_creatable_add_type() assert(qdict).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> qmp.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/qmp.c b/qmp.c
> index 6733463..8078038 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -665,7 +665,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
> void qmp_object_add(const char *type, const char *id,
> bool has_props, QObject *props, Error **errp)
> {
> - const QDict *pdict = NULL;
> + QDict *pdict;
> Visitor *v;
> Object *obj;
>
> @@ -675,14 +675,19 @@ void qmp_object_add(const char *type, const char *id,
> error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
> return;
> }
> + } else {
> + pdict = qdict_new();
> }
>
> - v = qmp_input_visitor_new(props, true);
> + v = qmp_input_visitor_new(QOBJECT(pdict), true);
> obj = user_creatable_add_type(type, id, pdict, v, errp);
> visit_free(v);
> if (obj) {
> object_unref(obj);
> }
> + if (!props) {
> + qobject_decref(QOBJECT(pdict));
> + }
> }
>
> void qmp_object_del(const char *id, Error **errp)
I'd like to see us add a unit test case to cover this scenario.
AFAICT, we don't currently have unit tests for specific QMP commands, just
the command framework, but we could still do it in tests/test-qmp-commands.c
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp: fix object-add assert() without props
2016-09-21 19:41 [Qemu-devel] [PATCH] qmp: fix object-add assert() without props Marc-André Lureau
` (2 preceding siblings ...)
2016-09-22 8:03 ` Daniel P. Berrange
@ 2016-09-22 9:42 ` Markus Armbruster
3 siblings, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2016-09-22 9:42 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel, qemu-stable
Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> Since commit ad739706bbadee49, user_creatable_add_type() expects to be
> given a qdict. However, if object-add is called without props, you reach
> the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
> Assertion `qdict' failed.", because the qdict isn't created in this
> case (it's optional).
>
> Furthermore, qmp_input_visitor_new() is not meant to be called without a
> dict, and a further commit will assert in this situation.
>
> If none given, create an empty qdict in qmp to avoid the
> user_creatable_add_type() assert(qdict).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> qmp.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/qmp.c b/qmp.c
> index 6733463..8078038 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -665,7 +665,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
> void qmp_object_add(const char *type, const char *id,
> bool has_props, QObject *props, Error **errp)
> {
> - const QDict *pdict = NULL;
> + QDict *pdict;
> Visitor *v;
> Object *obj;
>
> @@ -675,14 +675,19 @@ void qmp_object_add(const char *type, const char *id,
> error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
> return;
> }
> + } else {
> + pdict = qdict_new();
> }
>
> - v = qmp_input_visitor_new(props, true);
> + v = qmp_input_visitor_new(QOBJECT(pdict), true);
> obj = user_creatable_add_type(type, id, pdict, v, errp);
> visit_free(v);
> if (obj) {
> object_unref(obj);
> }
> + if (!props) {
> + qobject_decref(QOBJECT(pdict));
> + }
> }
>
> void qmp_object_del(const char *id, Error **errp)
The reference counting here is needlessly complex.
Case props != NULL:
* The caller holds a reference to props
* pdict = qobject_to_qdict(props) is a weak reference (not counted)
Case props == NULL:
* pdict = qdict_new() is a counted reference
* When it goes out of scope, we need to decrement the reference count.
I recommend to avoid the dual nature of pdict, by converting the weak
reference into a strong one, then decrement the reference count
unconditionally:
if (props) {
pdict = qobject_to_qdict(props);
if (!pdict) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
return;
}
QINCREF(pdict);
} else {
pdict = qdict_new();
}
v = qmp_input_visitor_new(QOBJECT(pdict), true);
obj = user_creatable_add_type(type, id, pdict, v, errp);
visit_free(v);
if (obj) {
object_unref(obj);
}
QDECREF(pdict);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-22 9:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-21 19:41 [Qemu-devel] [PATCH] qmp: fix object-add assert() without props Marc-André Lureau
2016-09-21 19:53 ` Eric Blake
2016-09-21 20:05 ` Paolo Bonzini
2016-09-22 8:03 ` Daniel P. Berrange
2016-09-22 9:42 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).