[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 3/3] qmp: print real legacy_name for alias proper
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH v2 3/3] qmp: print real legacy_name for alias property |
Date: |
Tue, 16 Sep 2014 13:51:20 +0800 |
From: Gonglei <address@hidden>
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.
Note: we should also consider the scenario that
source and target names are different because
object_property_add_alias() API allows objects to alias a
property on the same object or another object. The source
and target names can be different.
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 <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Signed-off-by: Gonglei <address@hidden>
Acked-by: Michael S. Tsirkin <address@hidden>
---
qmp.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 23 deletions(-)
diff --git a/qmp.c b/qmp.c
index c6767c4..a52ad0e 100644
--- a/qmp.c
+++ b/qmp.c
@@ -433,6 +433,44 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
return ret;
}
+static bool find_device_property_info(ObjectClass *klass,
+ const char *name,
+ DevicePropertyInfo **info,
+ bool is_alias,
+ AliasProperty *alias_property)
+{
+ Property *prop;
+ bool found = false;
+ const char *compared_name = is_alias ? alias_property->target_name : name;
+
+ for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
+ if (strcmp(compared_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(name); /* use original 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
@@ -440,32 +478,26 @@ ObjectTypeInfoList *qmp_qom_list_types(bool
has_implements,
*
* The caller must free the return value.
*/
-static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
- const char *name,
- const char *default_type)
+static
+DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
+ const char *name,
+ const char *default_type,
+ bool is_alias,
+ AliasProperty *alias_property)
{
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(alias_property->target_obj);
+ if (find_device_property_info(class, name, &info,
+ is_alias, alias_property)) {
+ 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,
+ is_alias, alias_property)) {
return info;
}
klass = object_class_get_parent(klass);
@@ -521,7 +553,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->alias_property);
if (!info) {
continue;
}
--
1.7.12.4