From ef7c7ff6d4ca1955278af1bc5025f47044183250 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 18 Jun 2014 17:58:28 +0800 Subject: qom: add object_property_add_alias() Sometimes an object needs to present a property which is actually on another object, or it needs to provide an alias name for an existing property. Examples: a.foo -> b.foo a.old_name -> a.new_name The new 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. Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Crosthwaite --- include/qom/object.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include') diff --git a/include/qom/object.h b/include/qom/object.h index b882ccc..44c513f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1231,6 +1231,26 @@ void object_property_add_uint64_ptr(Object *obj, const char *name, const uint64_t *v, Error **Errp); /** + * object_property_add_alias: + * @obj: the object to add a property to + * @name: the name of the property + * @target_obj: the object to forward property access to + * @target_name: the name of the property on the forwarded object + * @errp: if an error occurs, a pointer to an area to store the error + * + * Add an alias for a property on an object. This function will add a property + * of the same type as the forwarded property. + * + * The caller must ensure that @target_obj stays alive as long as + * this property exists. In the case of a child object or an alias on the same + * object this will be the case. For aliases to other objects the caller is + * responsible for taking a reference. + */ +void object_property_add_alias(Object *obj, const char *name, + Object *target_obj, const char *target_name, + Error **errp); + +/** * object_child_foreach: * @obj: the object whose children will be navigated * @fn: the iterator function to be called -- cgit v1.1 From 64607d088132abdb25bf30d93e97d0c8df7b364c Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 5 Jun 2014 13:11:51 +0200 Subject: qom: add a generic mechanism to resolve paths It may be desirable to have custom link<> properties that do more than just store an object. Even the addition of a "check" function is not enough if setting the link has side effects or if a non-standard reference counting is preferrable. Avoid the assumption that the opaque field of a link<> is a LinkProperty struct, by adding a generic "resolve" callback to ObjectProperty. This fixes aliases of link properties. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/qom/object.h b/include/qom/object.h index 44c513f..8a05a81 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -304,6 +304,25 @@ typedef void (ObjectPropertyAccessor)(Object *obj, Error **errp); /** + * ObjectPropertyResolve: + * @obj: the object that owns the property + * @opaque: the opaque registered with the property + * @part: the name of the property + * + * Resolves the #Object corresponding to property @part. + * + * The returned object can also be used as a starting point + * to resolve a relative path starting with "@part". + * + * Returns: If @path is the path that led to @obj, the function + * returns the #Object corresponding to "@path/@part". + * If "@path/@part" is not a valid object path, it returns #NULL. + */ +typedef Object *(ObjectPropertyResolve)(Object *obj, + void *opaque, + const char *part); + +/** * ObjectPropertyRelease: * @obj: the object that owns the property * @name: the name of the property @@ -321,6 +340,7 @@ typedef struct ObjectProperty gchar *type; ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; + ObjectPropertyResolve *resolve; ObjectPropertyRelease *release; void *opaque; @@ -787,12 +807,16 @@ void object_unref(Object *obj); * destruction. This may be NULL. * @opaque: an opaque pointer to pass to the callbacks for the property * @errp: returns an error if this function fails + * + * Returns: The #ObjectProperty; this can be used to set the @resolve + * callback for child and link properties. */ -void object_property_add(Object *obj, const char *name, const char *type, - ObjectPropertyAccessor *get, - ObjectPropertyAccessor *set, - ObjectPropertyRelease *release, - void *opaque, Error **errp); +ObjectProperty *object_property_add(Object *obj, const char *name, + const char *type, + ObjectPropertyAccessor *get, + ObjectPropertyAccessor *set, + ObjectPropertyRelease *release, + void *opaque, Error **errp); void object_property_del(Object *obj, const char *name, Error **errp); -- cgit v1.1 From b4fefef9d52003b6d09866501275a9a57995c6b0 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Thu, 5 Jun 2014 23:15:52 -0700 Subject: memory: MemoryRegion: QOMify QOMify memory regions as an Object. The former init() and destroy() routines become instance_init() and instance_finalize() resp. memory_region_init() is re-implemented to be: object_initialize() + set fields memory_region_destroy() is re-implemented to call unparent(). Signed-off-by: Peter Crosthwaite [Add newly-created MR as child, unparent on destruction. - Paolo] Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 3d778d7..85b56e2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -32,10 +32,15 @@ #include "qemu/int128.h" #include "qemu/notify.h" #include "qapi/error.h" +#include "qom/object.h" #define MAX_PHYS_ADDR_SPACE_BITS 62 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) +#define TYPE_MEMORY_REGION "qemu:memory-region" +#define MEMORY_REGION(obj) \ + OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION) + typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegionMmio MemoryRegionMmio; @@ -131,6 +136,7 @@ typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; struct MemoryRegion { + Object parent_obj; /* All fields are private - violators will be prosecuted */ const MemoryRegionOps *ops; const MemoryRegionIOMMUOps *iommu_ops; -- cgit v1.1 From 22a893e4f55344f96e1aafc66f5fedc491a5ca97 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Jun 2014 10:58:06 +0200 Subject: memory: MemoryRegion: replace owner field with QOM parent The two are now the same. Reviewed-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 85b56e2..0c7e825 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -141,7 +141,6 @@ struct MemoryRegion { const MemoryRegionOps *ops; const MemoryRegionIOMMUOps *iommu_ops; void *opaque; - struct Object *owner; MemoryRegion *container; Int128 size; hwaddr addr; -- cgit v1.1 From d33382da9abe21cb42f26b55945845b56ce9324a Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Thu, 5 Jun 2014 23:17:01 -0700 Subject: memory: MemoryRegion: Add may-overlap and priority props QOM propertyify the .may-overlap and .priority fields. The setters will re-add the memory as a subregion if needed (i.e. the values change when the memory region is already contained). Signed-off-by: Peter Crosthwaite [Remove setters. - Paolo] Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 0c7e825..e2c8e3e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -157,7 +157,7 @@ struct MemoryRegion { bool flush_coalesced_mmio; MemoryRegion *alias; hwaddr alias_offset; - int priority; + int32_t priority; bool may_overlap; QTAILQ_HEAD(subregions, MemoryRegion) subregions; QTAILQ_ENTRY(MemoryRegion) subregions_link; -- cgit v1.1 From 352e8da743f26948cb12d0ee53c455f328f59bbe Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 26 Jun 2014 15:10:03 +0200 Subject: qdev: correctly send DEVICE_DELETED for recursively-deleted devices When a device is unparented (i.e. made completely hidden from management) we want to send a DEVICE_DELETED event only if the device actually was realized. This avoids raising DEVICE_DELETED events when device_add fails. However, this does not work right for recursively-deleted devices: the whole tree is _first_ unrealized, _then_ unparented. Then device_unparent sees realized==false and fails to trigger the event. The solution is simply to move have_realized into the DeviceState struct. If device_add fails, we never set the new field to true and DEVICE_DELETED is not sent. Fixes qemu-iotests testcase 067 (broken by commit 5942a19, though that commit in turn fixed a possible segfault in the same test). Reported-by: Markus Armbruster Reviewed-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- include/hw/qdev-core.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9221cfc..0799ff2 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -156,6 +156,7 @@ struct DeviceState { const char *id; bool realized; + bool pending_deleted_event; QemuOpts *opts; int hotplugged; BusState *parent_bus; -- cgit v1.1