From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLr9J-0005p9-AA for qemu-devel@nongnu.org; Wed, 20 Jan 2016 06:42:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLr9G-0000Sn-0m for qemu-devel@nongnu.org; Wed, 20 Jan 2016 06:42:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33159) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLr9F-0000SW-Op for qemu-devel@nongnu.org; Wed, 20 Jan 2016 06:42:01 -0500 Date: Wed, 20 Jan 2016 11:41:55 +0000 From: "Daniel P. Berrange" Message-ID: <20160120114155.GB13628@redhat.com> References: <1453282958-385-1-git-send-email-valentin.rakush@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1453282958-385-1-git-send-email-valentin.rakush@gmail.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-list for class properties Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Valentin Rakush Cc: armbru@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, asmetanin@virtuozzo.com, den@openvz.org, afaerber@suse.de 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 implemen= t x86_64 cpu properties. >=20 > Additionally object_class_property_iterator_init function is implemente= d for consistency. Please line break your commit messages at approx 72 characters > Signed-off-by: Valentin Rakush > Cc: Luiz Capitulino > Cc: Eric Blake > Cc: Markus Armbruster > Cc: Andreas F=C3=A4rber > Cc: Daniel P. Berrange > --- > 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(+) >=20 > 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 *qdi= ct) > hmp_handle_error(mon, &err); > } > =20 > +void hmp_qom_type_list(Monitor *mon, const QDict *qdict) > +{ > + const char *path =3D qdict_get_try_str(qdict, "path"); > + ObjectPropertyInfoList *list; > + Error *err =3D NULL; > + > + if (path =3D=3D NULL) { > + monitor_printf(mon, "/\n"); > + return; > + } > + > + list =3D qmp_qom_type_list(path, &err); > + if (err =3D=3D NULL) { > + ObjectPropertyInfoList *start =3D list; > + while (list !=3D NULL) { > + ObjectPropertyInfo *value =3D list->value; > + > + monitor_printf(mon, "%s (%s)\n", > + value->name, value->type); > + list =3D list->next; > + } > + qapi_free_ObjectPropertyInfoList(start); > + } > + hmp_handle_error(mon, &err); > +} > + > void hmp_qom_set(Monitor *mon, const QDict *qdict) > { > const char *path =3D 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 *qdic= t); > 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(ObjectPropertyIte= rator *iter, > */ > ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter= ); > =20 > +/** > + * 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 > + * > + * > + * Using object class property iterators > + * > + * ObjectProperty *prop; > + * ObjectPropertyIterator iter; > + * > + * object_class property_iter_init(&iter, obj); > + * while ((prop =3D object_property_iter_next(&iter))) { > + * ... do something with prop ... > + * } > + * > + * > + */ > +void object_class_property_iter_init(ObjectPropertyIterator *iter, > + ObjectClass *klass); > + > void object_unparent(Object *obj); > =20 > /** > 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 > }, > =20 > { > + .name =3D "qom-type-list", > + .args_type =3D "path:s", > + .mhandler.cmd_new =3D qmp_marshal_qom_type_list, > + }, > + > + { > .name =3D "qom-set", > .args_type =3D "path:s,property:s,value:q", > .mhandler.cmd_new =3D 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_im= plements, > return ret; > } > =20 > +ObjectPropertyInfoList *qmp_qom_type_list(const char *path, Error **er= rp) With my earlier change this will become s/path/typename/ > +{ > + ObjectClass *klass; > + ObjectPropertyInfoList *props =3D NULL; > + ObjectProperty* prop; > + ObjectPropertyIterator iter; > + > + klass =3D object_class_by_name(path); > + if (klass =3D=3D 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 =3D object_property_iter_next(&iter))) { > + ObjectPropertyInfoList *entry =3D g_malloc0(sizeof(*entry)); This could be g_new0(ObjectPropertyInfoList, 1) instead of using g_malloc + sizeof directly. > + > + entry->value =3D g_malloc0(sizeof(ObjectPropertyInfo)); > + entry->next =3D props; > + props =3D entry; > + > + entry->value->name =3D g_strdup(prop->name); > + entry->value->type =3D 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 give= n 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; > } > =20 > +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 =3D 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 --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|