On Mon, Sep 15, 2014 at 10:44:39PM +0800, arei.gong...@huawei.com wrote: > From: Gonglei <arei.gong...@huawei.com> > > In this way, we can get the real legacy_name for > alias properties, and avoide confusing people because of > property type. People have no way to know they should > have a specific format. > > Example: > > before output: > > virtio-blk-pci.physical_block_size=uint16 > virtio-blk-pci.logical_block_size=uint16 > virtio-blk-pci.drive=str > > after output applied this patch: > > virtio-blk-pci.physical_block_size=blocksize > virtio-blk-pci.logical_block_size=blocksize > virtio-blk-pci.drive=drive > > Cc: Stefan Hajnoczi <stefa...@redhat.com> > Cc: Paolo Bonzini <pbonz...@redhat.com> > Cc: Michael S. Tsirkin <m...@redhat.com> > Signed-off-by: Gonglei <arei.gong...@huawei.com>
Acked-by: Michael S. Tsirkin <m...@redhat.com> > --- > qmp.c | 68 > ++++++++++++++++++++++++++++++++++++++++++++++--------------------- > 1 file changed, 47 insertions(+), 21 deletions(-) > > diff --git a/qmp.c b/qmp.c > index c6767c4..9338bd4 100644 > --- a/qmp.c > +++ b/qmp.c > @@ -433,6 +433,40 @@ ObjectTypeInfoList *qmp_qom_list_types(bool > has_implements, > return ret; > } > > +static bool find_device_property_info(ObjectClass *klass, > + const char *name, > + DevicePropertyInfo **info) > +{ > + Property *prop; > + bool found = false; > + > + for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { > + if (strcmp(name, prop->name) != 0) { > + continue; > + } > + > + /* > + * TODO Properties without a parser are just for dirty hacks. > + * qdev_prop_ptr is the only such PropertyInfo. It's marked > + * for removal. This conditional should be removed along with > + * it. > + */ > + if (!prop->info->set) { > + found = true; > + goto out; /* no way to set it, don't show */ > + } > + > + *info = g_malloc0(sizeof(**info)); > + (*info)->name = g_strdup(prop->name); > + (*info)->type = g_strdup(prop->info->legacy_name ?: > prop->info->name); > + > + found = true; > + goto out; > + } > +out: > + return found; > +} > + > /* Return a DevicePropertyInfo for a qdev property. > * > * If a qdev property with the given name does not exist, use the given > default > @@ -442,30 +476,21 @@ ObjectTypeInfoList *qmp_qom_list_types(bool > has_implements, > */ > static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, > const char *name, > - const char > *default_type) > + const char > *default_type, > + bool is_alias, > + Object *target_obj) > { > DevicePropertyInfo *info; > - Property *prop; > - > - do { > - for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { > - if (strcmp(name, prop->name) != 0) { > - continue; > - } > > - /* > - * TODO Properties without a parser are just for dirty hacks. > - * qdev_prop_ptr is the only such PropertyInfo. It's marked > - * for removal. This conditional should be removed along with > - * it. > - */ > - if (!prop->info->set) { > - return NULL; /* no way to set it, don't show */ > - } > + if (is_alias) { > + ObjectClass *class = object_get_class(target_obj); > + if (find_device_property_info(class, name, &info)) { > + return info; > + } > + } > > - info = g_malloc0(sizeof(*info)); > - info->name = g_strdup(prop->name); > - info->type = g_strdup(prop->info->legacy_name ?: > prop->info->name); > + do { > + if (find_device_property_info(klass, name, &info)) { > return info; > } > klass = object_class_get_parent(klass); > @@ -521,7 +546,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const > char *typename, > continue; > } > > - info = make_device_property_info(klass, prop->name, prop->type); > + info = make_device_property_info(klass, prop->name, prop->type, > + prop->is_alias, prop->target_obj); > if (!info) { > continue; > } > -- > 1.7.12.4 >