summaryrefslogtreecommitdiffstats
path: root/qom
Commit message (Collapse)AuthorAgeFilesLines
* qom: Reimplement InterfacesAnthony Liguori2012-08-131-134/+86Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | The current implementation of Interfaces is poorly designed. Each interface that an object implements ends up being an object that's tracked by the implementing object. There's all sorts of gymnastics to deal with casting between these objects. But an interface shouldn't be associated with an Object. Interfaces are global to a class. This patch moves all Interface knowledge to ObjectClass eliminating the relationship between Object and Interfaces. Interfaces are now abstract (as they should be) but this is okay. Interfaces essentially act as additional parents for the classes and are treated as such. With this new implementation, we should fully support derived interfaces including reimplementing an inherited interface. PC: Rebased against qom-next merge Jun-2012. PC: Removed replication of cast logic for interfaces, i.e. there is only one cast function - object_dynamic_cast() (and object_dynamic_cast_assert()) Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
* qom: Push error reporting to object_property_find()Paolo Bonzini2012-06-181-14/+8Star
| | | | | | | | Avoids duplicated error_set(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Also drop error_set() in object_property_del().] Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Remove qdev_prop_exists()Paolo Bonzini2012-06-181-1/+1
| | | | | | | Can be replaced everywhere with object_property_find(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qbus: Make child devices linksAnthony Liguori2012-06-181-2/+9
| | | | | | | | | | | | Make qbus children show up as link<> properties. There is no stable addressing for qbus children so we use an unstable naming convention. This is okay in QOM though because the composition name is expected to be what's stable. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Push "type" property up to ObjectPaolo Bonzini2012-06-181-0/+11
| | | | | | | | Now that Object is a type, add an instance_init function and push the "type" property from qdev to there. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Assert that public types have a non-NULL parent fieldPaolo Bonzini2012-06-181-4/+10
| | | | | | | | | This protects against unwanted effects of changing TYPE_OBJECT from NULL to a string. Suggested-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Make Object a typePaolo Bonzini2012-06-181-29/+30
| | | | | | | | | | Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Add class_base_initPaolo Bonzini2012-06-181-0/+9
| | | | | | | | | | The class_base_init TypeInfo callback was present in one of the early QOM versions but removed (on my request...) before committing. We will need it soon, add it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Add object_child_foreach()Paolo Bonzini2012-06-181-0/+17
| | | | | | | | | | A utility function that will be used to implement hierarchical realization. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> [AF: Drop unrelated whitespace change, add Returns: in documentation] [AF: Use new object_property_is_child() helper.] Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Introduce object_property_is_{child,link}()Andreas Färber2012-06-181-5/+15
| | | | | | | | Avoids hardcoding partial string comparisons. Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com> Signed-off-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: Add object_class_get_parent()Paolo Bonzini2012-06-181-0/+13
| | | | | | | | | | This simple bit of functionality was missing and we'll need it soon, so add it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> [AF: Document possible NULL return value] Signed-off-by: Andreas Färber <afaerber@suse.de>
* build: adapt qom/Makefile and move it to Makefile.objsPaolo Bonzini2012-06-072-2/+4
| | | | | | | | | qom/ already used a separate makefile. Convert it to use relative paths, and make it declare both common-obj-y and user-obj-y. This way, the upper makefiles do not need to know that some QOM files are compiled twice. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qdev: Use object_property_print() in info qtreePaolo Bonzini2012-05-121-1/+1
| | | | | | | | | Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print() itself. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qom: Fix memory leak in function container_getStefan Weil2012-05-031-0/+2
| | | | | | | | | | | | Valgrind reported this memory leak which occured very often. Test scenario: qemu-system-i386 (no arguments), only BIOS started, terminate with monitor command (quit). Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Andreas Färber <afaerber@suse.de>
* qom: Refine container_get() to allow using a custom rootAndreas Färber2012-04-241-2/+2
| | | | | | | | | | Specify the root to search from as argument. This avoids hardcoding "/machine" in some places and makes it more flexible. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Anthony Liguori <anthony@codemonkey.ws> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: add container_getPaolo Bonzini2012-04-022-16/+40
| | | | | | | | | This is QOM "mkdir -p". It is useful when referring to container objects such as "/machine". Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: Introduce CPU classAndreas Färber2012-03-142-0/+59
| | | | | | | | | | | | | | Reintroduce CPUState as QOM object: It's abstract and derived directly from TYPE_OBJECT for compatibility with the user emulators. The identifier CPUState avoids conflicts between CPU() and the struct. Introduce $(qom-twice-y) to build it separately for system and for user emulators. Prepare a virtual reset method, (re)introduce cpu_reset() as wrapper. Signed-off-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: Introduce object_class_get_list()Andreas Färber2012-03-141-0/+17
| | | | | | | | | This function allows to obtain a singly-linked list of classes, which can be sorted by the caller. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Anthony Liguori <anthony@codemonkey.ws> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom/object.c: rename type_class_init() to type_initialize()Igor Mitsyanko2012-03-141-6/+6
| | | | | | | | | | Function name type_class_init() gave us a wrong impression of separation of type's "class" and "object" entities initialization. Name type_initialize() is more appropriate for type_class_init() function (considering what operations it performs). Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: if @instance_size==0, assign size of object to parent object sizeIgor Mitsyanko2012-03-141-2/+17
| | | | | | | | | | | | | | QOM documentation states that for objects of type with @instance_size == 0 size will be assigned to match parent object's size. But currently this feauture is not implemented and qemu asserts during creation of object with zero instance_size. Set appropriate value for type instance_size during type_class_init() call. object_initialize_with_type() must call type_class_init() before asserting type->instance_size, and object_new_with_type() must call type_class_init() before object allocation. Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: fix device hot-unplugPaolo Bonzini2012-03-121-5/+2Star
| | | | | | | | | | | Property removal modifies the list, so it is not safe to continue iteration. We know anyway that each object can have only one parent (see object_property_add_child), so exit after finding the requested object. Reported-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: In function object_set_link_property(), first call object_ref(), then ↵Alexander Barabash2012-02-221-4/+7
| | | | | | | | | | | | | | object_unref(). In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object. In the new implementation, this is fixed. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: Fix object_initialize_with_type() assertionAndreas Färber2012-02-221-1/+1
| | | | | | | | Assert the object is at least sizeof(Object), not sizeof(ObjectClass). Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: add generic string parsing/printingPaolo Bonzini2012-02-221-0/+25
| | | | | | | | Add generic property accessors that take a string and parse it appropriately for the property type. All the magic here is done by the new string-based visitors. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: Unify type registrationAndreas Färber2012-02-152-4/+4
| | | | | | | | | | | | | Replace device_init() with generalized type_init(). While at it, unify naming convention: type_init([$prefix_]register_types) Also, type_init() is a function, so add preceding blank line where necessary and don't put a semicolon after the closing brace. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Anthony Liguori <anthony@codemonkey.ws> Cc: malc <av1474@comtv.ru> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: add property get/set wrappers for linksPaolo Bonzini2012-02-071-0/+24
| | | | | | | | These can set a link to any object, as long as it is included in the composition tree. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: fix canonical paths vs. interfacesPaolo Bonzini2012-02-071-0/+10
| | | | | Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: use object_resolve_path_type for linksPaolo Bonzini2012-02-071-14/+17
| | | | | | | | | | | | | | | This allows to restrict partial matches to objects of the expected type. It will let people use bare names to reference drives even though their name might be the same as a device's (e.g. -drive id=hd0,if=none,... -device ...,drive=hd0,id=hd0). As a useful byproduct, this fixes a problem with links of interface type. When a link property's type is an interface, the code expects the implementation object (not the parent object) to be stored in the variable. The parent object does not contain the right vtable. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: add object_resolve_path_typePaolo Bonzini2012-02-071-8/+18
| | | | | Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: fix off-by-onePaolo Bonzini2012-02-071-5/+2Star
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: add property get/set wrappers for C typesPaolo Bonzini2012-02-071-9/+110
| | | | | | | Add wrappers that let you get/set properties using normal C data types. Reviewed-by: Anthony Liguori <anthony@aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: add QObject-based property get/set wrappersPaolo Bonzini2012-02-072-1/+45
| | | | | | | | | | | | Move the creation of QmpInputVisitor and QmpOutputVisitor from qmp.c to qom/object.c, since it's the only practical way to access object properties. Keep this isolated such that it's easy to remove. At some point, we need to remove all usage of QObject in the tree and replace it with GVariant. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: do not include qdev header filePaolo Bonzini2012-02-071-2/+0Star
| | | | | Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: avoid useless conversions from string to typePaolo Bonzini2012-02-071-15/+12Star
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: clean up/optimize object_dynamic_castPaolo Bonzini2012-02-071-24/+38
| | | | | | | | | | The interface loop can be performed only on the parent object. It does not need to be done on each interface. Similarly, we can simplify the code by switching early from the implementation object to the parent object. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* container: make a decendent of ObjectAnthony Liguori2012-02-033-6/+32
| | | | | | | Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- v1 -> v2 - Add license (Paolo)
* object: sure up reference countingAnthony Liguori2012-02-031-2/+14
| | | | | | | | | | | | | | | | | | | | | | Now we have the following behavior: 1) object_new() returns an object with ref = 1 2) object_initialize() does not increase the reference count (ref may be 0). 3) object_deref() will finalize the object when ref = 0. it does not free the memory associated with the object. 4) both link and child properties correctly set the reference count. The expected usage is the following: 1) child devices should generally be created via object_initialize() using memory from the parent device. Adding the object as a child property will take ownership of the object and tie the child's life cycle to the parent. 2) If a child device is created via qdev_create() or some other form of object_new(), there must be an object_delete() call in the parent device's finalize function. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: accept any compatible type when setting a link propertyAnthony Liguori2012-02-031-4/+5
| | | | | | | | Links had limited utility before as they only allowed a concrete type to be specified. Now we can support abstract types and interfaces which means it's now possible to have a link<PCIDevice>. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: move properties from qdev to objectAnthony Liguori2012-02-031-0/+468
| | | | | | | | This is mostly code movement although not entirely. This makes properties part of the Object base class which means that we can now start using Object in a meaningful way outside of qdev. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: allow object_class_foreach to take additional parameters to refine searchAnthony Liguori2012-02-031-2/+16
| | | | Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qdev: change ambiguous qdev namesAnthony Liguori2012-01-271-0/+5
| | | | | Reported-by: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qom: add the base Object class (v2)Anthony Liguori2012-01-272-0/+486
This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- v1 -> v2 - remove printf() in type registration - fix typo in comment (Paolo) - make Interface private - move object into a new directory and move header into include/qemu/ - don't make object.h depend on qemu-common.h - remove Type and replace it with TypeImpl * (Paolo) - use hash table to store types (Paolo) - aggressively cache parent type (Paolo) - make a type_register and use it with interfaces (Paolo) - fix interface cast comment (Paolo) - add a few more functions required in later series