aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-02 10:17:19 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-02-07 13:52:41 +0100
commit68ee356941801d0a17fdc43b11ac3e6b72fcd597 (patch)
treee5f1927b37010bcf2c4d03858771826aafe41f4a
parentd822979bdf80c3ea9752615af15f231b4c4ce547 (diff)
qdev: allow reusing get/set for legacy property
In some cases, a legacy property does need a special print method but not a special parse method. In this case, we can reuse the get/set from the static (non-legacy) property. If neither parse nor print is needed, though, do not register the legacy property at all. The previous patch ensures that the right fallback will be used. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--hw/qdev.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index acb7829b5d..0205fe7d7d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -550,21 +550,24 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
* Do not use this is new code! Properties added through this interface will
* be given names and types in the "legacy" namespace.
*
- * Legacy properties are always processed as strings. The format of the string
- * depends on the property type.
+ * Legacy properties are string versions of other OOM properties. The format
+ * of the string depends on the property type.
*/
void qdev_property_add_legacy(DeviceState *dev, Property *prop,
Error **errp)
{
gchar *name, *type;
+ if (!prop->info->print && !prop->info->parse) {
+ return;
+ }
name = g_strdup_printf("legacy-%s", prop->name);
type = g_strdup_printf("legacy<%s>",
prop->info->legacy_name ?: prop->info->name);
object_property_add(OBJECT(dev), name, type,
- prop->info->print ? qdev_get_legacy_property : NULL,
- prop->info->parse ? qdev_set_legacy_property : NULL,
+ prop->info->print ? qdev_get_legacy_property : prop->info->get,
+ prop->info->parse ? qdev_set_legacy_property : prop->info->set,
NULL,
prop, errp);