aboutsummaryrefslogtreecommitdiffstats
path: root/hw/qdev-properties.c
AgeCommit message (Collapse)AuthorFilesLines
2012-02-22qdev: drop unnecessary parse/print methodsPaolo Bonzini1-134/+0
More qdev printers could have been removed in the previous series, and object_property_parse also made several parsers unnecessary. In fact, the new code is even more robust with respect to overflows, so clean them up! Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-22qdev: use built-in QOM string parserPaolo Bonzini1-2/+2
object_property_parse lets us drop the legacy setters when their task is done just as well by the string visitors. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-22qdev: accept hex properties only if prefixed by 0xPaolo Bonzini1-0/+12
Hex properties are an obstacle to removal of old qdev string parsing, but even here we can lay down the foundations for future simplification. In general, they are rarely used and their printed form is more interesting than the parsing. For example you'd usually set isa-serial.index instead of isa-serial.iobase. And luckily our main client, libvirt only cares about few of these, and always sets them with a 0x prefix. So the series stops accepting bare hexadecimal numbers, preparing for making legacy properties read-only in 1.3 or so. The read side will stay as long as "info qtree" is with us. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-22qdev: accept both strings and integers for PCI addressesPaolo Bonzini1-11/+25
Visitors allow a limited form of polymorphism. Exploit it to support setting the non-legacy PCI address property both as a DD.F string and as an 8-bit integer. The 8-bit integer form is just too clumsy, it is unlikely that we will ever drop it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-14qdev: print error message before abortingPaolo Bonzini1-13/+13
qdev_prop_set_* functions are always called by machine init functions that should know what they're doing, so they abort on error. Still, an assert(!errp) does not aid debugging. Print an error before aborting. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-02-14qdev: allow setting properties to NULLPaolo Bonzini1-6/+9
SPARC and PPC set properties to NULL. This can be done with an empty string value. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-02-07qdev: remove unused fields from PropertyInfoPaolo Bonzini1-37/+1
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: initialize properties via QOMPaolo Bonzini1-15/+14
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-07qdev: inline qdev_prop_set into qdev_prop_set_ptrPaolo Bonzini1-19/+7
qdev_prop_set is not needed anymore except for hacks, simplify it and inline it. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: access properties via QOMPaolo Bonzini1-24/+54
Do not poke anymore in the struct when accessing qdev properties. Instead, ask the object to set the right value. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: fix off-by-onePaolo Bonzini1-3/+3
Integer properties did not work. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: let QOM free propertiesPaolo Bonzini1-7/+12
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-07qdev: remove parse/print methods for pointer propertiesPaolo Bonzini1-56/+72
Pointer properties (except for PROP_PTR of course) should not need a legacy counterpart. In the future, relative paths will ensure that QEMU will support the same syntax as now for drives etc.. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: make the non-legacy pci address property accept an integerPaolo Bonzini1-19/+9
PCI addresses are set with qdev_prop_uint32. Thus we make the QOM property accept a device and function encoded in an 8-bit integer, instead of the magic dd.f hex string. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: remove parse/print methods for mac propertiesPaolo Bonzini1-19/+42
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: remove print/parse methods from LostTickPolicy propertiesPaolo Bonzini1-31/+31
Also generalize the code so that we can have more enum properties in the future. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: remove parse method for string propertiesPaolo Bonzini1-11/+0
We need the print method to put double quotes, but parsing is not special. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: remove direct calls to print/parsePaolo Bonzini1-16/+10
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-03qom: move properties from qdev to objectAnthony Liguori1-18/+35
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-03qdev: make DeviceInfo privateAnthony Liguori1-2/+2
Introduce accessors and remove any code that directly accesses DeviceInfo members. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-01qdev: Introduce lost tick policy propertyJan Kiszka1-0/+55
Potentially tick-generating timer devices will gain a common property: lock_tick_policy. It allows to encode 4 different ways how to deal with tick events the guest did not process in time: discard - ignore lost ticks (e.g. if the guest compensates for them already) delay - replay all lost ticks in a row once the guest accepts them again merge - if multiple ticks are lost, all of them are merged into one which is replayed once the guest accepts it again slew - lost ticks are gradually replayed at a higher frequency than the original tick Not all timer device will need to support all modes. However, all need to accept the configuration via this common property. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27qdev: don't access name through infoAnthony Liguori1-8/+8
We already have a QOM interface for this so let's use it. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27qdev: move qdev->info to classAnthony Liguori1-10/+10
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-27qdev-property: Make bit property parsing stricterJan Kiszka1-2/+2
By using strncasecmp, we allow for arbitrary characters after the "on"/"off" string. Fix this by switching to strcasecmp. Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-01-13qdev: Add a 'free' method to disassociate chardev from qdev deviceAmit Shah1-0/+11
When a device is removed, remove the association with a chardev, if any, so that the chardev can be re-used later for other devices. Reported-by: Qunfang Zhang <qzhang@redhat.com> Fix-suggested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-19qom: distinguish "legacy" property type name from QOM type namePaolo Bonzini1-4/+8
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-19qom: introduce get/set methods for PropertyPaolo Bonzini1-0/+354
This patch adds a visitor interface to Property. This way, QOM will be able to expose Properties that access a fixed field in a struct without exposing also the everything-is-a-string "feature" of qdev properties. Whenever the printed representation in both QOM and qdev (which is typically the case for device backends), parse/print code can be reused via get_generic/set_generic. Dually, whenever multiple PropertyInfos have the same representation in both the struct and the visitors the code can be reused (for example among all of int32/uint32/hex32). 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-19qom: interpret the return value when setting legacy propertiesPaolo Bonzini1-15/+26
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-16qdev: Add HEX8 propertyJan Kiszka1-0/+29
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-09-23pci-devfn: check that device/slot number is within rangeDonald Dutile1-0/+2
Need to check that guest slot/device number is not > 31 or walk off the devfn table when checking if a devfn is available or not in a guest. before this fix, passing in an addr=abc or addr=34, can crash qemu, sometimes fail gracefully if data past end of devfn table fails the availability test. with this fix, get clean error: Property 'pci-assign.addr' doesn't take value '34' also tested when no addr= param passed for guest (pcicfg) address, and that worked as well. Signed-off-by: Don Dutile <ddutile@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-09-06block: Attach non-qdev devices as wellMarkus Armbruster1-3/+3
For now, this just protects against programming errors like having the same drive back multiple non-qdev devices, or untimely bdrv_delete(). Later commits will add other interesting uses. While there, rename BlockDriverState member peer to dev, bdrv_attach() to bdrv_attach_dev(), bdrv_detach() to bdrv_detach_dev(), and bdrv_get_attached() to bdrv_get_attached_dev(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-4/+4
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-04-28char: Allow devices to use a single multiplexed chardev.Kusanagi Kouichi1-2/+2
This fixes regression caused by commit 2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6 ("char: Prevent multiple devices opening same chardev"): -nodefaults -nographic -chardev stdio,id=stdio,mux=on,signal=off \ -mon stdio -device virtio-serial-pci \ -device virtconsole,chardev=stdio -device isa-serial,chardev=stdio fails with: qemu-system-x86_64: -device isa-serial,chardev=stdio: Property 'isa-serial.chardev' can't take value 'stdio', it's in use Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp> Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-03-21char: Prevent multiple devices opening same chardevAmit Shah1-1/+6
Prevent: -chardev socket,path=/tmp/foo,server,nowait,id=c0 \ -device virtserialport,chardev=c0,id=vs0 \ -device virtserialport,chardev=c0,id=vs1 Reported-by: Mike Cao <bcao@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-02-20qdev: Fix printout of bit device properties with bit index >= 8David 'Digit' Turner1-1/+1
Signed-off-by: David 'Digit' Turner <digit@google.com> Acked-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-08-24Rearrange block headersBlue Swirl1-0/+1
Changing block.h or blockdev.h resulted in recompiling most objects. Move DriveInfo typedef and BlockInterfaceType enum definitions to qemu-common.h and rearrange blockdev.h use to decrease churn. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-08-22QemuOpts: make most qemu_*_opts staticGerd Hoffmann1-1/+1
Switch tree to lookup-by-name using qemu_find_opts(). Also hook up virtfs options so qemu_find_opts works for them too. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-07-11qdev: implement qdev_prop_set_bit().Isaku Yamahata1-0/+5
implement qdev_prop_set_bit(). Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-07-02block: Catch attempt to attach multiple devices to a blockdevMarkus Armbruster1-1/+21
For instance, -device scsi-disk,drive=foo -device scsi-disk,drive=foo happily creates two SCSI disks connected to the same block device. It's all downhill from there. Device usb-storage deliberately attaches twice to the same blockdev, which fails with the fix in place. Detach before the second attach there. Also catch attempt to delete while a guest device model is attached. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02qdev: Decouple qdev_prop_drive from DriveInfoMarkus Armbruster1-9/+12
Make the property point to BlockDriverState, cutting out the DriveInfo middleman. This prepares the ground for block devices that don't have a DriveInfo. Currently all user-defined ones have a DriveInfo, because the only way to define one is -drive & friends (they go through drive_init()). DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. I'm working towards a new way to define block devices, with clean host/guest separation, and I need to get DriveInfo out of the way for that. Fortunately, the device models are perfectly happy with BlockDriverState, except for two places: ide_drive_initfn() and scsi_disk_initfn() need to check the DriveInfo for a serial number set with legacy -drive serial=... Use drive_get_by_blockdev() there. Device model code should now use DriveInfo only when explicitly dealing with drives defined the old way, i.e. without -device. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02blockdev: Clean up automatic drive deletionMarkus Armbruster1-0/+10
We automatically delete blockdev host parts on unplug of the guest device. Too much magic, but we can't change that now. The delete happens early in the guest device teardown, before the connection to the host part is severed. Thus, the guest part's pointer to the host part dangles for a brief time. No actual harm comes from this, but we'll catch such dangling pointers a few commits down the road. Clean up the dangling pointers by delaying the automatic deletion until the guest part's pointer is gone. Device usb-storage deliberately makes two qdev properties refer to the same drive, because it automatically creates a second device. Again, too much magic we can't change now. Multiple references worked okay before, but now free_drive() dies for the second one. Zap the extra reference. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-30qdev-properties: Fix (u)intXX parsersKevin Wolf1-15/+35
scanf calls must not use PRI constants, they have probably the wrong size and corrupt memory. We could replace them by SCN ones, but strtol is simpler than scanf here anyway. While at it, also fix the parsers to reject garbage after the number ("4096xyz" was accepted before). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Richard Henderson <rth@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-06-04blockdev: Collect block device code in new blockdev.cMarkus Armbruster1-1/+0
Anything that moves hundreds of lines out of vl.c can't be all bad. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-04qdev: Don't leak string property value on hot unplugMarkus Armbruster1-0/+6
parse_string() qemu_strdup()s the property value. It is never freed. It needs to be freed along with the device. Otherwise, the value of scsi-disk property "ver" gets leaked when hot-unplugging the disk, for instance. Call new PropertyInfo method free() from qdev_free(). Implement it for qdev_prop_string. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-04qdev: New qdev_prop_set_string()Markus Armbruster1-0/+5
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-04-23Make qemu-config available for toolsKevin Wolf1-1/+18
To be able to use config files for blkdebug, we need to make these functions available in the tools. This involves moving two functions that can only be built in the context of the emulator. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-03-27error: Trim includes after "Move qemu_error & friends..."Markus Armbruster1-0/+1
Missed in commit 2f792016. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-03-16qdev: convert setting device properties to QErrorMarkus Armbruster1-8/+7
2010-03-16qdev: Hide "ptr" properties from usersMarkus Armbruster1-13/+8
Users can't set them, so qdev_device_help() shouldn't list them. Fix that. Also make qdev_prop_parse() hide them instead of printing a meaningless "has no parser" error message. Their value means nothing to users, so qdev_print_props() shouldn't print it. Fix by removing their print method. Their only use is dirty hacks. Document that.
2010-03-09qdev: Catch attempt to attach more than one device to a netdevMarkus Armbruster1-0/+7
Guest device and host netdev are peers, i.e. it's a 1:1 relation. However, we fail to enforce that: $ qemu -nodefaults --nographic -netdev user,id=net0 -device e1000,netdev=net0 -device virtio-net-pci,netdev=net0 -monitor stdio QEMU 0.12.50 monitor - type 'help' for more information (qemu) info network Devices not on any VLAN: net0: net=10.0.2.0, restricted=n peer=virtio-net-pci.0 e1000.0: model=e1000,macaddr=52:54:00:12:34:56 peer=net0 virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:57 peer=net0 It's all downhill from there. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>