Commit graph

174 commits

Author SHA1 Message Date
Andreas Färber dfe47e7029 qom: Refine container_get() to allow using a custom root
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>
2012-04-24 09:50:31 -05:00
Luiz Capitulino 56f9107e43 qdev: qdev_unplug(): use error_set()
It currently uses qerror_report(), but next commit will convert
the drive_del command to the QAPI and this requires using
error_set().

One particularity of qerror_report() is that it knows when it's
running on monitor context or command-line context and prints the
error message accordingly. error_set() doesn't do this, so we
have to be careful not to drop error messages.

qdev_unplug() has three kinds of usages:

 1. It's called when hot adding a device fails, to undo anything
    that has been done before hitting the error

 2. It's called by function monitor functions like device_del(),
    to unplug a device

 3. It's used by xen_platform.c in a way that doesn't _seem_ to
    be in monitor context

Only item 2 can print an error message to the user, this commit
maintains that.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-04-09 14:35:25 -03:00
Paolo Bonzini f05f6b4adb qdev: put all devices under /machine
Avoid cluttering too much the QOM root.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-04-02 15:04:15 -05:00
Paolo Bonzini da57febfed qdev: give all devices a canonical path
A strong limitation of QOM right now is that unconverted ports
(e.g. all...) do not give a canonical path to devices that are
part of the board.  This in turn makes it impossible to replace
PROP_PTR with a QOM link for example.

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>
2012-04-02 15:04:15 -05:00
Andreas Färber 4ed658ca92 qdev: Fix qdev_try_create() semantics
Since QOM'ification, qdev_try_create() uses object_new() internally,
which asserts "type != NULL" when the type is not registered.
This was revealed by the combination of kvmclock's kvm_enabled() check
and early QOM type registration.

Check whether the class exists before calling object_new(), so that
the caller (e.g., qdev_create) can fail gracefully, telling us which
device could not be created.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <aliguori@codemonkey.ws>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-17 09:58:21 -06:00
Andreas Färber 83f7d43a9e qom: Unify type registration
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>
2012-02-15 09:39:21 -06:00
Paolo Bonzini 4f2d3d705c qdev: initialize properties via QOM
Similarly, use the object properties also to set the default
values of the qdev properties.  This requires reordering
registration and initialization.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07 13:52:42 +01:00
Paolo Bonzini dd0ba250ca qdev: let QOM free properties
Drop the special free callback.  Instead, register a "regular"
release method in the non-legacy property.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07 13:52:42 +01:00
Paolo Bonzini 68ee356941 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>
2012-02-07 13:52:41 +01:00
Paolo Bonzini d822979bdf qdev: remove direct calls to print/parse
There's no need to call into ->parse and ->print manually.  The
QOM legacy properties do that for us.

Furthermore, in some cases legacy and static properties have exactly
the same behavior, and we could drop the legacy properties right away.
Add an appropriate fallback to prepare for this.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07 13:52:41 +01:00
Anthony Liguori 60adba3769 qdev: implement cleanup logic in finalize
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:08 -06:00
Anthony Liguori 57c9fafe0f qom: move properties from qdev to object
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>
2012-02-03 10:41:08 -06:00
Anthony Liguori 0beb494207 qdev: nuke qdev_init_chardev()
I'm sure the intentions were good here, but there's no reason this should be in
qdev.  Move it to qemu-char where it belongs.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:08 -06:00
Anthony Liguori ee46d8a503 qdev: split out UI portions into a new function
qdev-monitor.c deals with the -device, device_add, and info qdm/qtree
interfaces.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:08 -06:00
Anthony Liguori 9fbe61277f qdev: refactor away qdev_create_from_info
Note that the FIXME gets fixed in series 4/4.  We need to convert BusState to
QOM before we can make parent_bus a link.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:08 -06:00
Anthony Liguori 9674bfe420 qdev: split out common init to instance_init
This gets us closer to being able to object_new() a qdev type and have a
functioning object verses having to call qdev_create().

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:08 -06:00
Anthony Liguori 6acbe4c6f1 qdev: remove baked in notion of aliases (v2)
Limit them to the device_add functionality.  Device aliases were a hack based
on the fact that virtio was modeled the wrong way.  The mechanism for aliasing
is very limited in that only one alias can exist for any device.

We have to support it for the purposes of compatibility but we only need to
support it in device_add so restrict it to that piece of code.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
 - Use a table for aliases (Paolo)
2012-02-03 10:41:07 -06:00
Anthony Liguori d307af795d qdev: kill off DeviceInfo
It is no longer used in the tree since everything is done natively through
QEMU Object Model.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:06 -06:00
Anthony Liguori 212ad11168 qdev: kill off DeviceInfo list
Teach the various bits of code that need to walk through available devices to
do so via QOM.

Signed-off-by: Anthony Liguori
2012-02-03 10:41:06 -06:00
Anthony Liguori 18b6dade8c qdev: refactor device creation to allow bus_info to be set only in class
As we use class_init to set class members, DeviceInfo no longer holds this
information.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:05 -06:00
Anthony Liguori d253e09619 qdev: allow classes to overload qdev functions
This allows us to drop per-Device registration functions by allowing the
class_init functions to overload qdev methods.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:05 -06:00
Anthony Liguori 6e008585eb qdev: remove info from class
Now DeviceInfo is no longer used after object construction.  All of the
relevant members have been moved to DeviceClass.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:05 -06:00
Anthony Liguori 4be9f0d11c qdev: make DeviceInfo private
Introduce accessors and remove any code that directly accesses DeviceInfo
members.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:04 -06:00
Anthony Liguori 40021f0888 pci: convert to QEMU Object Model
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:50 -06:00
Anthony Liguori 3dde52d2fe qdev: add class_init to DeviceInfo
Since we are still dynamically creating TypeInfo, we need to chain the
class_init function in order to be able to make use of it within subclasses of
TYPE_DEVICE.

This will disappear once we register TypeInfos directly.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:46 -06:00
Anthony Liguori 3cc90eb2b7 qdev: add a interface to register subclasses
In order to introduce inheritance while still using the qdev registration
interfaces, we need to be able to use a parent other than TYPE_DEVICE.  Add a
new interface that allows this.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:46 -06:00
Anthony Liguori 94afdadcb3 qdev: use a wrapper to access reset and promote reset to a class method
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:46 -06:00
Anthony Liguori f79f2bfc6a qdev: don't access name through info
We already have a QOM interface for this so let's use it.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:39 -06:00
Anthony Liguori 30fbb9fc7c qdev: move qdev->info to class
Right now, DeviceInfo acts as the class for qdev.  In order to switch to a
proper ObjectClass derivative, we need to ween all of the callers off of
interacting directly with the info pointer.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:34 -06:00
Anthony Liguori 32fea4025b qdev: integrate with QEMU Object Model (v2)
This is a very shallow integration.  We register a TYPE_DEVICE but only use
QOM as basically a memory allocator.  This will make all devices show up as
QOM objects but they will all carry the TYPE_DEVICE.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
 - update for new location of object.h
2012-01-27 10:28:30 -06:00
Blue Swirl a369da5f31 vga: improve VGA logic
Improve VGA selection logic, push check for device availabilty to vl.c.
Create the devices at board level unconditionally.

Remove now unused pci_try_create*() functions.

Make PCI VGA devices optional.

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-01-22 07:27:06 +00:00
Anthony Liguori 024a6fbdb9 qdev: fix device_del by refactoring reference counting
Commit 8eb0283 broken device_del by having too overzealous reference counting
checks.  Move the reference count checks to qdev_free(), make sure to remove
the parent link on free, and decrement the reference count on property removal.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-13 10:20:49 -06:00
Anthony Liguori 1de81d2832 qdev: fix hotplug when no -device is specified
The peripheral[-anon] containers are initialized lazily but since they sit on
sysbus, they can not be created after realize.  This was causing an abort() to
occur during hotplug if no -device option was used.

This was spotted by qemu-test::device-add.sh

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-19 16:39:16 -06:00
Paolo Bonzini ca2cc78888 qom: register qdev properties also as non-legacy properties
Push legacy properties into a "legacy-..." namespace, and make them
available with correct types too.

For now, all properties come in both variants.  This need not be the
case for string properties.  We will revisit this after -device is
changed to actually use the legacy properties.

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>
2011-12-19 10:27:34 -06:00
Paolo Bonzini cafe5bdb9a qom: distinguish "legacy" property type name from QOM type name
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>
2011-12-19 10:27:34 -06:00
Paolo Bonzini 7db4c4e8e5 qom: interpret the return value when setting legacy properties
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-19 10:27:33 -06:00
Paolo Bonzini e3cb6ba65d qom: push permission checks up into qdev_property_add_legacy
qdev_property_get and qdev_property_set can generate permission
denied errors themselves.  Do not duplicate this functionality in
qdev_get/set_legacy_property, and clean up excessive indentation.

Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-19 10:27:33 -06:00
Paolo Bonzini 0d41d9aabb qom: fix swapped parameters
Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-19 10:27:33 -06:00
Anthony Liguori cd34d667d4 qdev: add a qdev_get_type() function and expose as a 'type' property
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:49 -06:00
Anthony Liguori 6a146eba33 qom: add string property type
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:49 -06:00
Anthony Liguori b2b6c39a79 qom: optimize qdev_get_canonical_path using a parent link
The full tree search was a bit unreasonable.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:49 -06:00
Anthony Liguori 8eb02831af dev: add an anonymous peripheral container
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:48 -06:00
Anthony Liguori 1bdaacb18f qdev: add explicitly named devices to the root complex
We first add a 'peripheral' container to the root device that we add user
created devices to.  This provides all user created devices with a unique and
isolated namespace.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:48 -06:00
Anthony Liguori 83e94fb8d5 qom: add link properties (v2)
Links represent an ephemeral relationship between devices.  They are meant to
replace the qdev concept of busses by allowing more informal relationships
between devices.

Links are fairly limited in their usefulness without implementing QOM-style
subclassing and interfaces.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:48 -06:00
Anthony Liguori 3de1c3e82d qom: add child properties (composition) (v3)
Child properties express a relationship of composition.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:48 -06:00
Anthony Liguori dc45c21f39 qdev: provide a path resolution (v2)
There are two types of supported paths--absolute paths and partial paths.

Absolute paths are derived from the root device and can follow child<> or
link<> properties.  Since they can follow link<> properties, they can be
arbitrarily long.  Absolute paths look like absolute filenames and are prefixed
with a leading slash.

Partial paths are look like relative filenames.  They do not begin with a
prefix.  The matching rules for partial paths are subtle but designed to make
specifying devices easy.  At each level of the composition tree, the partial
path is matched as an absolute path.  The first match is not returned.  At
least two matches are searched for.  A successful result is only returned if
only one match is founded.  If more than one match is found, a flag is returned
to indicate that the match was ambiguous.

At the end of the day, partial path support means that if you create a device
called 'ide0', you can just say 'ide0' as the path name and it will Just Work.
If we internally create a device called 'i440fx', you can just say 'i440fx' and
it will Just Work and long as you don't do anything silly.

A management tool should probably always use absolute paths since then they
don't have to deal with the possibility of ambiguity.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:48 -06:00
Anthony Liguori f9fbd2fd0e qdev: provide an interface to return canonical path from root (v2)
The canonical path is the path in the composition tree from the root to the
device.  This is effectively the name of the device.

This is an incredibly unefficient implementation that will be optimized in
a future patch.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:47 -06:00
Anthony Liguori a10f07a7d0 qom: introduce root device
This is based on Jan's suggestion for how to do unique naming.  The root device
is the root of composition.  All devices are reachable via child<> links from
this device.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:47 -06:00
Anthony Liguori a5296ca9df qom: register legacy properties as new style properties (v2)
Expose all legacy properties through the new QOM property mechanism.  The qdev
property types are exposed through the 'legacy<>' namespace.  They are always
visited as strings since they do their own string parsing.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:47 -06:00
Anthony Liguori 44677ded43 qom: add new dynamic property infrastructure based on Visitors (v2)
qdev properties are settable only during construction and static to classes.
This isn't flexible enough for QOM.

This patch introduces a property interface for qdev that provides dynamic
properties that are tied to objects, instead of classes.  These properties are
Visitor based instead of string based too.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-15 09:20:47 -06:00