* [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties
@ 2016-01-20 9:42 Valentin Rakush
2016-01-20 11:41 ` Daniel P. Berrange
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Valentin Rakush @ 2016-01-20 9:42 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru, lcapitulino, asmetanin, den, Valentin Rakush, afaerber
This patch adds support for qom-type-list command that supposed to list object class properties. Will use this functionality further to implement x86_64 cpu properties.
Additionally object_class_property_iterator_init function is implemented for consistency.
Signed-off-by: Valentin Rakush <valentin.rakush@gmail.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Andreas Färber <afaerber@suse.de>
Cc: Daniel P. Berrange <berrange@redhat.com>
---
hmp.c | 26 ++++++++++++++++++++++++++
hmp.h | 1 +
include/qom/object.h | 31 +++++++++++++++++++++++++++++++
qapi-schema.json | 19 +++++++++++++++++++
qmp-commands.hx | 6 ++++++
qmp.c | 29 +++++++++++++++++++++++++++++
qom/object.c | 8 ++++++++
7 files changed, 120 insertions(+)
diff --git a/hmp.c b/hmp.c
index 54f2620..64aa991 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2052,6 +2052,32 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, &err);
}
+void hmp_qom_type_list(Monitor *mon, const QDict *qdict)
+{
+ const char *path = qdict_get_try_str(qdict, "path");
+ ObjectPropertyInfoList *list;
+ Error *err = NULL;
+
+ if (path == NULL) {
+ monitor_printf(mon, "/\n");
+ return;
+ }
+
+ list = qmp_qom_type_list(path, &err);
+ if (err == NULL) {
+ ObjectPropertyInfoList *start = list;
+ while (list != NULL) {
+ ObjectPropertyInfo *value = list->value;
+
+ monitor_printf(mon, "%s (%s)\n",
+ value->name, value->type);
+ list = list->next;
+ }
+ qapi_free_ObjectPropertyInfoList(start);
+ }
+ hmp_handle_error(mon, &err);
+}
+
void hmp_qom_set(Monitor *mon, const QDict *qdict)
{
const char *path = qdict_get_str(qdict, "path");
diff --git a/hmp.h b/hmp.h
index a8c5b5a..d81cd4c 100644
--- a/hmp.h
+++ b/hmp.h
@@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);
void hmp_info_memdev(Monitor *mon, const QDict *qdict);
void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
void hmp_qom_list(Monitor *mon, const QDict *qdict);
+void hmp_qom_type_list(Monitor *mon, const QDict *qdict);
void hmp_qom_set(Monitor *mon, const QDict *qdict);
void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
diff --git a/include/qom/object.h b/include/qom/object.h
index d0dafe9..f8ca725 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1013,6 +1013,37 @@ void object_property_iter_init(ObjectPropertyIterator *iter,
*/
ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
+/**
+ * object_class_property_iter_init:
+ * @klass: the klass to iter properties for
+ *
+ * Initializes an iterator for traversing all properties
+ * registered against a klass type and all parent classes.
+ *
+ * It is forbidden to modify the property list while iterating,
+ * whether removing or adding properties.
+ *
+ * NB For getting next property in the list the object related
+ * function object_property_iter_next is still used.
+ *
+ * Typical usage pattern would be
+ *
+ * <example>
+ * <title>Using object class property iterators</title>
+ * <programlisting>
+ * ObjectProperty *prop;
+ * ObjectPropertyIterator iter;
+ *
+ * object_class property_iter_init(&iter, obj);
+ * while ((prop = object_property_iter_next(&iter))) {
+ * ... do something with prop ...
+ * }
+ * </programlisting>
+ * </example>
+ */
+void object_class_property_iter_init(ObjectPropertyIterator *iter,
+ ObjectClass *klass);
+
void object_unparent(Object *obj);
/**
diff --git a/qapi-schema.json b/qapi-schema.json
index b3038b2..c50d24c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4081,3 +4081,22 @@
##
{ 'enum': 'ReplayMode',
'data': [ 'none', 'record', 'play' ] }
+
+##
+# @qom-type-list:
+#
+# This command will list any properties of a object class
+# given a path in the object class model.
+#
+# @path: the path within the object class model. See @qom-list-types
+# to check available object class names.
+#
+# Returns: a list of @ObjectPropertyInfo that describe the properties of the
+# object class.
+#
+# Since: 2.6
+##
+{ 'command': 'qom-type-list',
+ 'data': { 'path': 'str' },
+ 'returns': [ 'ObjectPropertyInfo' ] }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index db072a6..4e5dd48 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3789,6 +3789,12 @@ EQMP
},
{
+ .name = "qom-type-list",
+ .args_type = "path:s",
+ .mhandler.cmd_new = qmp_marshal_qom_type_list,
+ },
+
+ {
.name = "qom-set",
.args_type = "path:s,property:s,value:q",
.mhandler.cmd_new = qmp_marshal_qom_set,
diff --git a/qmp.c b/qmp.c
index 3ff6db7..86dd1f2 100644
--- a/qmp.c
+++ b/qmp.c
@@ -448,6 +448,35 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
return ret;
}
+ObjectPropertyInfoList *qmp_qom_type_list(const char *path, Error **errp)
+{
+ ObjectClass *klass;
+ ObjectPropertyInfoList *props = NULL;
+ ObjectProperty* prop;
+ ObjectPropertyIterator iter;
+
+ klass = object_class_by_name(path);
+ if (klass == NULL) {
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+ "Object class '%s' not found", path);
+ return NULL;
+ }
+
+ object_class_property_iter_init(&iter, klass);
+ while ((prop = object_property_iter_next(&iter))) {
+ ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
+
+ entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+ entry->next = props;
+ props = entry;
+
+ entry->value->name = g_strdup(prop->name);
+ entry->value->type = g_strdup(prop->type);
+ }
+
+ return props;
+}
+
/* Return a DevicePropertyInfo for a qdev property.
*
* If a qdev property with the given name does not exist, use the given default
diff --git a/qom/object.c b/qom/object.c
index 5ff97ab..a158076 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -994,6 +994,14 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
return NULL;
}
+void object_class_property_iter_init(ObjectPropertyIterator *iter,
+ ObjectClass *klass)
+{
+ g_hash_table_iter_init(&iter->iter, klass->properties);
+ iter->nextclass = object_class_get_parent(klass);
+
+}
+
void object_property_iter_init(ObjectPropertyIterator *iter,
Object *obj)
{
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties
2016-01-20 9:42 [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties Valentin Rakush
@ 2016-01-20 11:41 ` Daniel P. Berrange
2016-01-20 16:38 ` Eric Blake
2016-01-20 18:15 ` Daniel P. Berrange
2 siblings, 0 replies; 4+ messages in thread
From: Daniel P. Berrange @ 2016-01-20 11:41 UTC (permalink / raw)
To: Valentin Rakush; +Cc: armbru, qemu-devel, lcapitulino, asmetanin, den, afaerber
On Wed, Jan 20, 2016 at 12:42:38PM +0300, Valentin Rakush wrote:
> This patch adds support for qom-type-list command that supposed to list object class properties. Will use this functionality further to implement x86_64 cpu properties.
>
> Additionally object_class_property_iterator_init function is implemented for consistency.
Please line break your commit messages at approx 72 characters
> Signed-off-by: Valentin Rakush <valentin.rakush@gmail.com>
> Cc: Luiz Capitulino <lcapitulino@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Cc: Daniel P. Berrange <berrange@redhat.com>
> ---
> hmp.c | 26 ++++++++++++++++++++++++++
> hmp.h | 1 +
> include/qom/object.h | 31 +++++++++++++++++++++++++++++++
> qapi-schema.json | 19 +++++++++++++++++++
> qmp-commands.hx | 6 ++++++
> qmp.c | 29 +++++++++++++++++++++++++++++
> qom/object.c | 8 ++++++++
> 7 files changed, 120 insertions(+)
>
> diff --git a/hmp.c b/hmp.c
> index 54f2620..64aa991 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -2052,6 +2052,32 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
> hmp_handle_error(mon, &err);
> }
>
> +void hmp_qom_type_list(Monitor *mon, const QDict *qdict)
> +{
> + const char *path = qdict_get_try_str(qdict, "path");
> + ObjectPropertyInfoList *list;
> + Error *err = NULL;
> +
> + if (path == NULL) {
> + monitor_printf(mon, "/\n");
> + return;
> + }
> +
> + list = qmp_qom_type_list(path, &err);
> + if (err == NULL) {
> + ObjectPropertyInfoList *start = list;
> + while (list != NULL) {
> + ObjectPropertyInfo *value = list->value;
> +
> + monitor_printf(mon, "%s (%s)\n",
> + value->name, value->type);
> + list = list->next;
> + }
> + qapi_free_ObjectPropertyInfoList(start);
> + }
> + hmp_handle_error(mon, &err);
> +}
> +
> void hmp_qom_set(Monitor *mon, const QDict *qdict)
> {
> const char *path = qdict_get_str(qdict, "path");
> diff --git a/hmp.h b/hmp.h
> index a8c5b5a..d81cd4c 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);
> void hmp_info_memdev(Monitor *mon, const QDict *qdict);
> void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
> void hmp_qom_list(Monitor *mon, const QDict *qdict);
> +void hmp_qom_type_list(Monitor *mon, const QDict *qdict);
> void hmp_qom_set(Monitor *mon, const QDict *qdict);
> void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
> void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
> diff --git a/include/qom/object.h b/include/qom/object.h
> index d0dafe9..f8ca725 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1013,6 +1013,37 @@ void object_property_iter_init(ObjectPropertyIterator *iter,
> */
> ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
>
> +/**
> + * object_class_property_iter_init:
> + * @klass: the klass to iter properties for
> + *
> + * Initializes an iterator for traversing all properties
> + * registered against a klass type and all parent classes.
> + *
> + * It is forbidden to modify the property list while iterating,
> + * whether removing or adding properties.
> + *
> + * NB For getting next property in the list the object related
> + * function object_property_iter_next is still used.
> + *
> + * Typical usage pattern would be
> + *
> + * <example>
> + * <title>Using object class property iterators</title>
> + * <programlisting>
> + * ObjectProperty *prop;
> + * ObjectPropertyIterator iter;
> + *
> + * object_class property_iter_init(&iter, obj);
> + * while ((prop = object_property_iter_next(&iter))) {
> + * ... do something with prop ...
> + * }
> + * </programlisting>
> + * </example>
> + */
> +void object_class_property_iter_init(ObjectPropertyIterator *iter,
> + ObjectClass *klass);
> +
> void object_unparent(Object *obj);
>
> /**
> diff --git a/qapi-schema.json b/qapi-schema.json
> index b3038b2..c50d24c 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4081,3 +4081,22 @@
> ##
> { 'enum': 'ReplayMode',
> 'data': [ 'none', 'record', 'play' ] }
> +
> +##
> +# @qom-type-list:
I realize you're following the pattern of 'qom-list' but that
in itself is a misleading name really.
So i'd suggest we call this 'qom-type-prop-list' to more
accurately describe what it is doing.
> +#
> +# This command will list any properties of a object class
> +# given a path in the object class model.
> +#
> +# @path: the path within the object class model. See @qom-list-types
> +# to check available object class names.
> +#
> +# Returns: a list of @ObjectPropertyInfo that describe the properties of the
> +# object class.
> +#
> +# Since: 2.6
> +##
> +{ 'command': 'qom-type-list',
> + 'data': { 'path': 'str' },
This should be called 'typename' really, as this is not
an object path.
> + 'returns': [ 'ObjectPropertyInfo' ] }
> +
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index db072a6..4e5dd48 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3789,6 +3789,12 @@ EQMP
> },
>
> {
> + .name = "qom-type-list",
> + .args_type = "path:s",
> + .mhandler.cmd_new = qmp_marshal_qom_type_list,
> + },
> +
> + {
> .name = "qom-set",
> .args_type = "path:s,property:s,value:q",
> .mhandler.cmd_new = qmp_marshal_qom_set,
> diff --git a/qmp.c b/qmp.c
> index 3ff6db7..86dd1f2 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -448,6 +448,35 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
> return ret;
> }
>
> +ObjectPropertyInfoList *qmp_qom_type_list(const char *path, Error **errp)
With my earlier change this will become s/path/typename/
> +{
> + ObjectClass *klass;
> + ObjectPropertyInfoList *props = NULL;
> + ObjectProperty* prop;
> + ObjectPropertyIterator iter;
> +
> + klass = object_class_by_name(path);
> + if (klass == NULL) {
> + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
> + "Object class '%s' not found", path);
> + return NULL;
> + }
> +
> + object_class_property_iter_init(&iter, klass);
> + while ((prop = object_property_iter_next(&iter))) {
> + ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
This could be g_new0(ObjectPropertyInfoList, 1) instead
of using g_malloc + sizeof directly.
> +
> + entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
> + entry->next = props;
> + props = entry;
> +
> + entry->value->name = g_strdup(prop->name);
> + entry->value->type = g_strdup(prop->type);
> + }
> +
> + return props;
> +}
> +
> /* Return a DevicePropertyInfo for a qdev property.
> *
> * If a qdev property with the given name does not exist, use the given default
> diff --git a/qom/object.c b/qom/object.c
> index 5ff97ab..a158076 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -994,6 +994,14 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
> return NULL;
> }
>
> +void object_class_property_iter_init(ObjectPropertyIterator *iter,
> + ObjectClass *klass)
Vertically align the 'ObjectClass' with 'ObjectPropertyIterator'
> +{
> + g_hash_table_iter_init(&iter->iter, klass->properties);
> + iter->nextclass = object_class_get_parent(klass);
> +
Can kil this extra blank line
> +}
> +
> void object_property_iter_init(ObjectPropertyIterator *iter,
> Object *obj)
> {
Overall the code looks good - just bikeshedding over some naming and
a few other minor points.
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] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties
2016-01-20 9:42 [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties Valentin Rakush
2016-01-20 11:41 ` Daniel P. Berrange
@ 2016-01-20 16:38 ` Eric Blake
2016-01-20 18:15 ` Daniel P. Berrange
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2016-01-20 16:38 UTC (permalink / raw)
To: Valentin Rakush, qemu-devel; +Cc: armbru, lcapitulino, asmetanin, den, afaerber
[-- Attachment #1: Type: text/plain, Size: 3128 bytes --]
On 01/20/2016 02:42 AM, Valentin Rakush wrote:
> This patch adds support for qom-type-list command that supposed to list object class properties. Will use this functionality further to implement x86_64 cpu properties.
In addition to Dan's comments,
s/that supposed//
s/Will use/A later patch will use/
>
> Additionally object_class_property_iterator_init function is implemented for consistency.
Starting a paragraph with "Also" or "Additionally" can be a sign that
the patch may be worth splitting into two smaller pieces. It's not
always the case, but worth thinking about.
>
>
> Signed-off-by: Valentin Rakush <valentin.rakush@gmail.com>
> Cc: Luiz Capitulino <lcapitulino@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Cc: Daniel P. Berrange <berrange@redhat.com>
> ---
> hmp.c | 26 ++++++++++++++++++++++++++
> hmp.h | 1 +
> include/qom/object.h | 31 +++++++++++++++++++++++++++++++
> qapi-schema.json | 19 +++++++++++++++++++
> qmp-commands.hx | 6 ++++++
> qmp.c | 29 +++++++++++++++++++++++++++++
> qom/object.c | 8 ++++++++
> 7 files changed, 120 insertions(+)
>
> diff --git a/hmp.c b/hmp.c
> index 54f2620..64aa991 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -2052,6 +2052,32 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
> hmp_handle_error(mon, &err);
> }
>
> +void hmp_qom_type_list(Monitor *mon, const QDict *qdict)
> +{
> + const char *path = qdict_get_try_str(qdict, "path");
> + ObjectPropertyInfoList *list;
> + Error *err = NULL;
> +
> + if (path == NULL) {
I'd write '(!path)', but that's cosmetic.
> + monitor_printf(mon, "/\n");
> + return;
> + }
> +
> + list = qmp_qom_type_list(path, &err);
> + if (err == NULL) {
> + ObjectPropertyInfoList *start = list;
> + while (list != NULL) {
Again, this could be 'if (!err)' and 'while (list)'.
> +++ b/include/qom/object.h
> @@ -1013,6 +1013,37 @@ void object_property_iter_init(ObjectPropertyIterator *iter,
> */
> ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
>
> +/**
> + * object_class_property_iter_init:
> + * @klass: the klass to iter properties for
Reads awkwardly; maybe:
@klass: the class owning the properties to be iterated over
> +++ b/qapi-schema.json
> @@ -4081,3 +4081,22 @@
> ##
> { 'enum': 'ReplayMode',
> 'data': [ 'none', 'record', 'play' ] }
> +
> +##
> +# @qom-type-list:
> +#
> +# This command will list any properties of a object class
s/a object/an object/
> +# given a path in the object class model.
If you change the parameter name to 'typename' as suggested by Dan, then
this sentence needs tweaking as well.
> +#
> +# @path: the path within the object class model. See @qom-list-types
> +# to check available object class names.
> +#
--
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] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties
2016-01-20 9:42 [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties Valentin Rakush
2016-01-20 11:41 ` Daniel P. Berrange
2016-01-20 16:38 ` Eric Blake
@ 2016-01-20 18:15 ` Daniel P. Berrange
2 siblings, 0 replies; 4+ messages in thread
From: Daniel P. Berrange @ 2016-01-20 18:15 UTC (permalink / raw)
To: Valentin Rakush; +Cc: armbru, qemu-devel, lcapitulino, asmetanin, den, afaerber
On Wed, Jan 20, 2016 at 12:42:38PM +0300, Valentin Rakush wrote:
> This patch adds support for qom-type-list command that supposed to list object class properties. Will use this functionality further to implement x86_64 cpu properties.
>
> Additionally object_class_property_iterator_init function is implemented for consistency.
>
>
> Signed-off-by: Valentin Rakush <valentin.rakush@gmail.com>
> Cc: Luiz Capitulino <lcapitulino@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Cc: Daniel P. Berrange <berrange@redhat.com>
> ---
> hmp.c | 26 ++++++++++++++++++++++++++
> hmp.h | 1 +
You also need to change hmp-commands.hx to register the new
command
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] 4+ messages in thread
end of thread, other threads:[~2016-01-20 18:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 9:42 [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties Valentin Rakush
2016-01-20 11:41 ` Daniel P. Berrange
2016-01-20 16:38 ` Eric Blake
2016-01-20 18:15 ` Daniel P. Berrange
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).