Commit Graph

335 Commits

Author SHA1 Message Date
Dustin Xiong
269556e557 qemu: Check for IA64 kvm
ACPI feature bit dropped: I asked internally if the -no-acpi option
had any meaning for IA64, and was told 'probably not'.
2010-02-19 10:56:06 -05:00
Chris Lalancette
b97c24b2e1 Better error reporting for failed migration
If the hostname as returned by "gethostname" resolves
to "localhost" (as it does with the broken Fedora-12
installer), then live migration will fail because the
source will try to migrate to itself.  Detect this
situation up-front and abort the live migration before
we do any real work.

* src/util/util.h src/util/util.c: add a new virGetHostnameLocalhost
  with an optional localhost check, and rewire virGetHostname() to use
  it
* src/libvirt_private.syms: expose the new function
* src/qemu/qemu_driver.c: use it in qemudDomainMigratePrepare2()
2010-02-19 16:15:21 +01:00
Stefan Berger
b3e7890ada macvtap mac_filter support
This patch adds the mac_filter support to the macvtap device.
2010-02-19 15:41:30 +01:00
Stefan Berger
e52687e88f macvtap IFF_VNET_HDR configuration
This patch sets or unsets the IFF_VNET_HDR flag depending on what device
is used in the VM. The manipulation of the flag is done in the open
function and is only fatal if the IFF_VNET_HDR flag could not be cleared
although it has to be (or if an ioctl generally fails). In that case the
macvtap tap is closed again and the macvtap interface torn.

* src/qemu/qemu_conf.c src/qemu/qemu_conf.h: pass qemuCmdFlags to
  qemudPhysIfaceConnect()
* src/util/macvtap.c src/util/macvtap.h: add vnet_hdr boolean to
  openMacvtapTap(), and private function configMacvtapTap()
* src/qemu/qemu_driver.c: add extra qemuCmdFlags when calling
  qemudPhysIfaceConnect()
2010-02-19 11:38:57 +01:00
Matthew Booth
3ec09478de Add QEMU support for virtio channel
Support virtio-serial controller and virtio channel in QEMU backend.
Will output
the following for virtio-serial controller:

-device
virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4,max_ports=16,vectors=4

and the following for a virtio channel:

-chardev pty,id=channel0 \
-device
virtserialport,bus=virtio-serial0.0,chardev=channel0,name=org.linux-kvm.port.0

* src/qemu/qemu_conf.c: Add argument output for virtio
* tests/qemuxml2argvtest.c
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args: Add test for
  QEMU command line generation
2010-02-18 17:56:50 +01:00
Matthew Booth
7813a0f81c Add domain support for virtio channel
Add support for virtio-serial by defining a new 'virtio' channel target type
and a virtio-serial controller. Allows the following to be specified in a
domain:

<controller type='virtio-serial' index='0' ports='16' vectors='4'/>
<channel type='pty'>
  <target type='virtio' name='org.linux-kvm.port.0'/>
  <address type='virtio-serial' controller='0' bus='0'/>
</channel>

* docs/schemas/domain.rng: Add virtio-serial controller and virtio
  channel type.
* src/conf/domain_conf.[ch]: Domain parsing/serialization for
  virtio-serial controller and virtio channel.
* tests/qemuxml2xmltest.c
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.xml: add domain xml
  parsing test
* src/libvirt_private.syms src/qemu/qemu_conf.c:
  virDomainDefAddDiskControllers() renamed to
  virDomainDefAddImplicitControllers()
2010-02-18 17:52:03 +01:00
Matthew Booth
27e63c0037 Fix typo in comment
* src/qemu/qemu_driver.c: qemudStartVMDaemon() fix typo in comment
2010-02-18 16:40:48 +01:00
Cole Robinson
3f745ebe9f qemu: Explicitly error if guest virtual network is inactive
Currently we just error with ex. 'virbr0: No such device'.

Since we are using public API calls here, we need to ensure that any
raised error is properly saved and restored, since API entry points
always reset messages.
2010-02-18 09:23:05 -05:00
Stefan Berger
f162252e25 macvtap teardown rework
Rework and simplification of teardown of the macvtap device.

Basically all devices with the same MAC address and link device are kept
alive and not attempted to be torn down. If a macvtap device linked to a
physical interface with a certain MAC address 'M' is to be created it
will automatically fail if the interface is 'up'ed and another macvtap
with the same properties (MAC addr 'M', link dev) happens to be 'up'.
This will prevent the VM from starting or the device from being attached
to a running VM. Stale interfaces are assumed to be there for some
reason and not stem from libvirt.

In the VM shutdown path, it's assuming that an interface name is always
available so that if the device type is DIRECT it can be torn down
using its name.

* src/util/macvtap.h src/libvirt_macvtap.syms: change of deleting routine
* src/util/macvtap.c: cleanups and change of deleting routine
* src/qemu/qemu_driver.c: change cleanup on shutdown
* src/qemu/qemu_conf.c: don't delete Macvtap in qemudPhysIfaceConnect()
2010-02-18 15:13:48 +01:00
Daniel P. Berrange
6fe15e357d Update QEMU JSON balloon command handling
The QEMU JSON monitor changed balloon commands to return/accept
bytes instead of kilobytes. Update libvirt to cope with this

* src/qemu/qemu_monitor_json.c: Expect/use bytes for ballooning
2010-02-18 11:17:14 +00:00
Jim Meyering
7ac2787019 qemuMonitorTextAddUSBDisk: avoid unconditional leak
* src/qemu/qemu_monitor_text.c (qemuMonitorTextAddUSBDisk): Free
command output buffer.
2010-02-16 18:09:13 +01:00
Jim Meyering
309647c81f qemuInitPasswords: avoid unconditional leak
* src/qemu/qemu_driver.c (qemuInitPasswords): Free pass-phrase buffer.
2010-02-16 18:09:13 +01:00
Jim Meyering
bc6a48c6cf qemuMonitorTextAddDevice: avoid unconditional leak
* src/qemu/qemu_monitor_text.c (qemuMonitorTextAddDevice): Free the
device name buffer.
2010-02-16 17:49:05 +01:00
Cole Robinson
8c38b5dc2e qemu: Make SetVcpu command hotplug only
Similar to the Set*Mem commands, this implementation was bogus and
misleading. Make it clear this is a hotplug only operation, and that the
hotplug piece isn't even implemented.

Also drop the overkill maxvcpus validation: we don't perform this check
at XML define time so clearly no one is missing it, and there is
always the risk that our info will be out of date, possibly preventing
legitimate CPU values.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2010-02-16 11:10:40 -05:00
Cole Robinson
09a33fd8a9 qemu: Make Set*Mem commands hotplug only
SetMem and SetMaxMem are hotplug only APIs, any persistent config
changes are supposed to go via XML definition. The original implementation
of these calls were incorrect and had the nasty side effect of making
a psuedo persistent change that would be lost after libvirtd restart
(I didn't know any better).

Fix these APIs to rightly reject non running domains.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2010-02-16 11:10:40 -05:00
Daniel P. Berrange
535db41be8 Treat missing QEMU 'thread_id' as non-fatal in JSON monitor
The plain QEMU tree does not include 'thread_id' in the JSON
output. Thus we need to treat it as non-fatal if missing.

* src/qemu/qemu_monitor_json.c: Treat missing thread_id as non-fatal
2010-02-16 14:33:34 +00:00
Daniel P. Berrange
9ab3fac841 Fix check for primary IDE controller in QEMU PCI slot assignment
A typo in the check for the primary IDE controller could cause
a crash on restore depending on the exact guest config.

* src/qemu/qemu_conf.c: Fix s/video/controller/ typo & slot
  number typo
2010-02-16 14:33:29 +00:00
Daniel P. Berrange
b6b8009548 Make error reporting for QEMU JSON mode more friendly
Current error reporting for JSON mode returns the full JSON
command string and full JSON error string. This is not very
user friendly, so this change makes the error report only
contain the basic command name, and friendly error message
description string. The full JSON data is logged instead.

* src/qemu/qemu_monitor_json.c: Always return the 'desc' field from
  the JSON error message to users.
2010-02-16 14:33:23 +00:00
Daniel P. Berrange
5d72a89442 Run 'qmp_capabilities' command at QEMU monitor startup
When in JSON mode, QEMU requires that 'qmp_capabilities' is run as
the first command in the monitor. This is a no-op when run in the
text mode monitor

* src/qemu/qemu_driver.c: Run capabilities negotiation when
  connecting to the monitor
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h: Add
  support for the 'qmp_capabilities' command, no-op in text mode.
2010-02-16 14:21:25 +00:00
Stefan Berger
a1b1ab1478 macvtap support for libvirt -- qemu support
This part adds support for qemu making a macvtap tap device available
via file descriptor passed to qemu command line. This also attempts to
tear down the macvtap device when a VM terminates. This includes support
for attachment and detachment to/from running VM.
* src/qemu/qemu_conf.[ch] src/qemu/qemu_driver.c: add support in the
  QEmu driver
2010-02-15 17:47:29 +01:00
Daniel P. Berrange
141dea6bc7 Add persistence of PCI addresses to QEMU
Current PCI addresses are allocated at time of VM startup.
To make them truely persistent, it is neccessary to do this
at time of virDomainDefine/virDomainCreate. The code in
qemuStartVMDaemon still remains in order to cope with upgrades
from older libvirt releases

* src/qemu/qemu_driver.c: Rename existing qemuAssignPCIAddresses
  to qemuDetectPCIAddresses. Add new qemuAssignPCIAddresses which
  does auto-allocation upfront. Call qemuAssignPCIAddresses from
  qemuDomainDefine and qemuDomainCreate to assign PCI addresses that
  can then be persisted. Don't clear PCI addresses at shutdown if
  they are intended to be persistent
2010-02-12 17:25:52 +00:00
Daniel P. Berrange
c31a116b72 Support 'block_passwd' command for QEMU disk encryption
The old text mode monitor prompts for a password when disks are
encrypted. This interactive approach doesn't work for JSON mode
monitor. Thus there is a new 'block_passwd' command that can be
used.

* src/qemu/qemu_driver.c: Split out code for looking up a disk
  secret from findVolumeQcowPassphrase, into a new method
  getVolumeQcowPassphrase. Enhance qemuInitPasswords() to also
  set the disk encryption password via the monitor
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
  support for the 'block_passwd' monitor command.
2010-02-12 17:25:02 +00:00
Jiri Denemark
dfab48ac54 Implement cpuBaseline in remote and qemu drivers 2010-02-12 14:30:42 +01:00
Jiri Denemark
53c05341d4 Internal driver API for virConnectBaselineCPU 2010-02-12 14:23:53 +01:00
Jim Meyering
618e1ab349 qemu_driver.c: honor dname parameter once again
Since c26cb9234f, the dname
parameter has been ignored by these two functions.  Use it.
* src/qemu/qemu_driver.c (qemudDomainMigratePrepareTunnel): Honor dname
parameter once again.
(qemudDomainMigratePrepare2): Likewise.
2010-02-11 17:22:56 +01:00
Jiri Denemark
8efec111fc Swap position of nmodels and models parameters in cpuDecode()
All other libvirt functions use array first and then number of elements
in that array. Let's make cpuDecode follow this rule.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-02-11 16:46:20 +01:00
Chris Lalancette
6daa19da9a Fix up a misspelled comment.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-02-11 09:02:24 -05:00
Daniel P. Berrange
7357975000 Fix disk stats retrieval with QEMU >= 0.12
With QEMU >= 0.12 the host and guest side of disks no longer have
the same naming convention. Specifically the host side will now
get a 'drive-' prefix added to its name. The 'info blockstats'
monitor command returns the host side name, so it is neccessary
to strip this off when looking up stats since libvirt stores the
guest side name !

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Move 'drive-' prefix
  string to a defined constant
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_text.c: Strip
  off 'drive-' prefix (if found) when looking up disk stats
2010-02-11 12:07:23 +00:00
Cole Robinson
d3024a2cce qemu: Increase guest startup timeout to 30 seconds
Currently the timeout for reading startup output is 3 seconds. If the
host is under any sort of load, we can easily trigger this. Lets bump
it to 30 seconds.

Since the polling loop checks to see if the process has died, we shouldn't
erroneously hit this timeout if qemu bombs (only if it is stuck in some
infinite loop).
2010-02-10 10:51:47 -05:00
Cole Robinson
b65490a312 qemu: Properly report a startup timeout error
The timeout errors were unconditionally being overwritten by the less
helpful 'unable to start guest' error.
2010-02-10 10:51:46 -05:00
Daniel P. Berrange
38536d6f7f Annotate some virConnectPtr as mandatory non-null
Use the ATTRIBUTE_NONNULL annotation to mark some virConnectPtr
args as mandatory non-null so the compiler can warn of mistakes

* src/conf/domain_event.h: All virConnectPtr args must be non-null
* src/qemu/qemu_conf.h: qemudBuildCommandLine and
  qemudNetworkIfaceConnect() must be given non-null connection
* tests/qemuxml2argvtest.c: Provide a non-null (dummy) connection to
  qemudBuildCommandLine()
2010-02-10 13:33:06 +00:00
Daniel P. Berrange
f430ddb624 Remove virConnectPtr from CPU XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in cpu_conf.{h,c} and update all callers to
match
2010-02-10 13:32:38 +00:00
Daniel P. Berrange
99edc443e9 Remove virConnectPtr from all node device XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in node_device_conf.{h,c} and update all callers to
match
2010-02-10 13:32:01 +00:00
Daniel P. Berrange
ce71b8654d Remove virConnectPtr from USB/PCI device iterators
All callers now pass a NULL virConnectPtr into the USB/PCi device
iterator functions. Therefore the virConnectPtr arg can now be
removed from these functions

* src/util/hostusb.h, src/util/hostusb.c: Remove virConnectPtr
  from usbDeviceFileIterate
* src/util/pci.c, src/util/pci.h: Remove virConnectPtr arg from
  pciDeviceFileIterate
* src/qemu/qemu_security_dac.c, src/security/security_selinux.c: Update
  to drop redundant virConnectPtr arg
2010-02-10 13:29:57 +00:00
Daniel P. Berrange
9f013d5779 Fix generation of floppy disk arg for QEMU's -global arg
* src/qemu/qemu_conf.c: Fix ',' vs '.' typo in floppy disk arg
2010-02-10 12:51:53 +00:00
Daniel P. Berrange
910b019f93 Convert qemu command line flags to 64-bit int
The QEMU flags are commonly stored as a signed or unsigned int,
allowing only 31 flags. This limit is rather close, so to aid
future patches, change it to a 64-bit int

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h, src/qemu/qemu_driver.c,
  tests/qemuargv2xmltest.c, tests/qemuhelptest.c, tests/qemuxml2argvtest.c:
  Use 'unsigned long long' for QEMU flags
2010-02-10 12:09:41 +00:00
Daniel P. Berrange
d6126f764f Remove use of virConnectPtr from security driver APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in security_driver.{h,c} and update all callers to
match
2010-02-10 11:49:24 +00:00
Daniel P. Berrange
65842bf669 Remove virConnectPtr from all domain XML parsing/formatting APIs 2010-02-10 11:49:23 +00:00
Daniel P. Berrange
caa805ea64 Remove passing of virConnectPtr throughout QEMU driver 2010-02-10 11:49:23 +00:00
Daniel P. Berrange
d47ef780f2 Fix security driver configuration
The security driver was mistakenly initialized before the QEMU
config file was loaded. This prevents it being turned off again.
The capabilities XML was also getting the wrong security driver
name, due to the stacked driver arrangement.

* src/qemu/qemu_driver.c: Fix initialization order and capabilities
  model name
2010-02-10 11:49:23 +00:00
Matthias Bolte
314ced3951 Remove conn parameter from USB functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
9140756d30 Remove conn parameter from PCI functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
0a5befc4c0 Remove conn parameter from Linux stats functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
fe46a7e686 Remove conn parameter from storage file functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
f972dc2d5c Remove conn parameter from util functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Matthias Bolte
d5c6183def Remove conn parameter from virXPath* functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Matthias Bolte
a5ab900d26 Remove conn parameter from virReportSystemError 2010-02-09 01:04:54 +01:00
Matthias Bolte
8ce5e2c1ab Remove conn parameter from virReportOOMError 2010-02-09 01:04:54 +01:00
Jim Fehlig
ed9c14a7ef domain{Attach,Detach}DeviceFlags handler for drivers
Implementation of domain{Attach,Detach}DeviceFlags handlers
in the drivers.
2010-02-08 10:49:43 -07:00
Daniel P. Berrange
83acdeaf17 Fix restore of QEMU guests with PCI device reservation
When restoring from a saved guest image, the XML would already
contain the PCI slot ID of the IDE controller & video card.
The attempt to explicitly reserve this upfront would thus fail
everytime.

* src/qemu/qemu_conf.c: Reserve IDE controller / video card
  slot at time of need, rather than upfront
2010-02-03 16:45:26 +00:00
Daniel P. Berrange
9120f00446 Ensure QEMU DAC security driver is activated at all times
If the primary security driver (SELinux/AppArmour) was disabled
then the secondary QEMU DAC security driver was also disabled.
This is mistaken, because the latter must be active at all times

* src/qemu/qemu_driver.c: Ensure DAC driver is always active
2010-02-02 19:14:31 +00:00
Daniel P. Berrange
719c50caf8 Fix QEMU hotplug device alias assignment
To allow devices to be hot(un-)plugged it is neccessary to ensure
they all have a unique device aliases. This fixes the hotplug
methods to assign device aliases before invoking the monitor
commands which need them

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Expose methods
  for assigning device aliases for disks, host devices and
  controllers
* src/qemu/qemu_driver.c: Assign device aliases when hotplugging
  all types of device
* tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args:
  Update for changed hostdev naming scheme
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
db0b9e7d52 Disable QEMU monitor IO debugging by default 2010-02-02 16:31:47 +00:00
Daniel P. Berrange
16478459da Re-arrange QEMU device alias assignment code
This patch re-arranges the QEMU device alias assignment code to
make it easier to call into the same codeblock when performing
device hotplug. The new code has the ability to skip over already
assigned names to facilitate hotplug

* src/qemu/qemu_driver.c: Call qemuAssignDeviceNetAlias()
  instead of qemuAssignNetNames
* src/qemu/qemu_conf.h: Export qemuAssignDeviceNetAlias()
  instead of qemuAssignNetNames
* src/qemu/qemu_driver.c: Merge the legacy disk/network alias
  assignment code into the main methods
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
0943048ad0 Remove direct storage of hostnet_name & vlan
The current way of assigning names to the host network backend and
NIC device in QEMU was over complicated, by varying naming scheme
based on the NIC model and backend type. This simplifies the naming
to simply be 'net0' and 'hostnet0', allowing code to easily determine
the host network name and vlan based off the primary device alias
name 'net0'. This in turn allows removal of alot of QEMU specific
code from the XML parser, and makes it easier to assign new unique
names for NICs that are hotplugged

* src/conf/domain_conf.c, src/conf/domain_conf.h: Remove hostnet_name
  and vlan fields from virNetworkDefPtr
* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h, src/qemu/qemu_driver.c:
  Use a single network alias naming scheme regardless of NIC type
  or backend type. Determine VLANs from the alias name.
* tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args: Update
  for new simpler naming scheme
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
49a0f6cd99 Remove use of -netdev arg with QEMU
The QEMU 0.12.x tree has the -netdev command line argument, but not
corresponding monitor command. We can't enable the former, without
the latter since it will break hotplug/unplug.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Disable -netdev usage
  until 0.13 at earliest
* tests/qemuxml2argvtest.c: Add test for -netdev syntax
* tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml: Test
  data files for -netdev syntax
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
d8acc44672 Assign PCI addresses before hotplugging devices
PCI disk, disk controllers, net devices and host devices need to
have PCI addresses assigned before they are hot-plugged

* src/qemu/qemu_conf.c: Add APIs for ensuring a device has an
  address and releasing unused addresses
* src/qemu/qemu_driver.c: Ensure all devices have addresses
  when hotplugging.
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
9258ec0a2e Rewrite way QEMU PCI addresses are allocated
The current QEMU code allocates PCI addresses incrementally starting
at 4. This is not satisfactory because the user may have given some
addresses in their XML config, which need to be skipped over when
allocating addresses to remaining devices.

It is thus neccessary to maintain a list of already allocated PCI
addresses and then only allocate ones that remain unused. This is
also required for domain device hotplug to work properly later.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Add APIs for creating
  list of existing PCI addresses, and allocating new addresses.
  Refactor address assignment to use this code
* src/qemu/qemu_driver.c: Pull PCI address assignment up into the
  qemuStartVMDaemon() method, as a prelude to moving it into the
  'define' method. Update list of allocated addresses when connecting
  to a running VM at daemon startup.
* tests/qemuxml2argvtest.c, tests/qemuargv2xmltest.c,
  tests/qemuxml2xmltest.c: Remove USB product test since all
  passthrough is done based on address
* tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args,
  tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml: Kil
  unused data files
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
264e98d6a8 Make hotplug use new device_add where possible
Since QEMU startup uses the new -device argument, the hotplug
code needs todo the same. This converts disk, network and
host device hotplug to use the device_add command

* src/qemu/qemu_driver.c: Use new device_add monitor APIs
  whereever possible
2010-02-02 16:31:46 +00:00
Daniel P. Berrange
5ec6cf7fb8 Introduce internal QEMU monitor APIs for drive + device hotadd
The way QEMU is started has been changed to use '-device' and
the new style '-drive' syntax. This needs to be mirrored in
the hotplug code, requiring addition of two new APIs.

* src/qemu/qemu_monitor.h, src/qemu/qemu_monitor.c: Define APIs
  qemuMonitorAddDevice() and qemuMonitorAddDrive()
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
  Implement the new monitor APIs
2010-02-02 16:31:42 +00:00
Daniel P. Berrange
96c8608dc5 Split out QEMU code for building PCI/USB hostdev arg values
To allow for better code reuse from hotplug methods, the code for
generating PCI/USB hostdev arg values is split out into separate
methods

* qemu/qemu_conf.h, qemu/qemu_conf.c: Introduce new APis for
  qemuBuildPCIHostdevPCIDevStr, qemuBuildUSBHostdevUsbDevStr
  and qemuBuildUSBHostdevDevStr
2010-02-02 15:41:29 +00:00
Daniel P. Berrange
c129d4fe45 Standard internal API syntax for building QEMU command line arguments
All the helper functions for building command line arguments
now return a 'char *', instead of acepting a 'char **' or
virBufferPtr argument

* qemu/qemu_conf.c: Standardize syntax for building args
* qemu/qemu_conf.h: Export all functions for building args
* qemu/qemu_driver.c: Update for changed syntax for building
  NIC/hostnet args
2010-02-02 15:41:25 +00:00
Jim Meyering
9344e6ad1a avoid a probable EINVAL from lseek
* src/qemu/qemu_driver.c (qemudLogReadFD): Don't pass a negative
offset (from a preceding failed attempt to seek to EOF) to this use
of lseek.
2010-02-02 10:35:52 +01:00
Jim Meyering
4cd188d4d5 avoid format-related warnings
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetAllPCIAddresses):
Use %s.
* src/storage/storage_backend_iscsi.c (virStorageBackendCreateIfaceIQN):
Likewise.
* tools/virsh.c (cmdSecretSetValue): Likewise.
2010-02-01 18:25:23 +01:00
Chris Lalancette
29727bacd7 Fix PCI host reattach on domain detach.
Similar to the race fixed by
be34c3c7ef, make sure
to wait around for KVM to release the resources from
a hot-detached PCI device before attempting to
rebind that device to the host driver.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-02-01 10:14:39 -05:00
Matthew Booth
09080c38d1 Clarify controllers -device string in QEMU driver
The QEMU driver contained code to generate a -device string for piix4-ide, but
wasn't using it. This change removes this string generation. It also adds a
comment explaining why IDE and FDC controllers don't generate -device strings.

The change also generates an error if a sata controller is specified for a QEMU
domain, as this isn't supported.

* src/qemu/qemu_conf.c: Remove VIR_DOMAIN_CONTROLLER_TYPE_IDE handler in
  qemuBuildControllerDevStr(). Ignore IDE and FDC controllers. Error if
  SATA controller is discovered. Add comments.
2010-02-01 16:08:36 +01:00
Chris Lalancette
b16cd226a2 Look in /usr/libexec for the qemu-kvm binary.
On RHEL-5 the qemu-kvm binary is located in /usr/libexec.
To reduce confusion for people trying to run upstream libvirt
on RHEL-5 machines, make the qemu driver look in /usr/libexec
for the qemu-kvm binary.

To make this work, I modified virFindFileInPath to handle an
absolute path correctly.  I also ran into an issue where
NULL was sometimes being passed for the file parameter
to virFindFileInPath; it didn't crash prior to this patch
since it was building paths like /usr/bin/(null).  This
is non-standard behavior, though, so I added a NULL
check at the beginning.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-02-01 09:39:42 -05:00
Chris Lalancette
7cc5410bfd Fix a crash when restarting libvirtd.
If you shutdown libvirtd while a domain with PCI
devices is running, then try to restart libvirtd,
libvirtd will crash.

This happens because qemuUpdateActivePciHostdevs() is calling
pciDeviceListSteal() with a dev of 0x0 (NULL), and then trying
to dereference it.  This patch fixes it up so that
qemuUpdateActivePciHostdevs() steals the devices after first
Get()'ting them, avoiding the crash.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-01-25 16:25:47 -05:00
Jim Meyering
1af75828a0 qemuMonitorTextAttachDrive: avoid two leaks
* src/qemu/qemu_monitor_text.c (qemuMonitorTextAttachDrive): Most other
failures in this function would "goto cleanup", but one mistakenly
returned directly, skipping the cleanup and resulting in a leak.
In addition, iterating the "try_command" loop would clobber, and
thus leak, the "cmd" allocated on the first iteration,
so be careful to free it in addition to "reply" beforehand.
2010-01-25 22:06:47 +01:00
Matthias Bolte
731c738652 qemu: Search binaries in PATH instead of hardcoding /usr/bin 2010-01-25 21:38:28 +01:00
Daniel P. Berrange
72a8405a47 Implement QMP support for extracting CPU thread ID
The KVM build of QEMU includs the thread ID of each vCPU in the
'query-cpus' output. This is required for pinning guests to
particular host CPUs

* src/qemu/qemu_monitor_json.c: Extract 'thread_id' from CPU info
2010-01-25 17:08:37 +00:00
Daniel P. Berrange
2c7f5ca662 Misc fixes to QMP monitor support for QEMU
* src/util/json.c, src/util/json.h: Declare returned strings
  to be const
* src/qemu/qemu_monitor.c: Wire up JSON mode for qemuMonitorGetPtyPaths
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h: Fix
  const correctness. Add missing error message in the function
  qemuMonitorJSONGetAllPCIAddresses. Add implementation of the
  qemuMonitorGetPtyPaths function calling 'query-chardev'.
2010-01-25 17:08:37 +00:00
Jim Meyering
9827e0a42c qemuMonitorTextGetMemoryStats: plug a leak on an error path
* src/qemu/qemu_monitor_text.c (qemuMonitorCommandWithHandler):
Always free *reply, upon failure.
2010-01-25 17:04:27 +01:00
Chris Lalancette
be34c3c7ef qemu: Fix race between device rebind and kvm cleanup
Certain hypervisors (like qemu/kvm) map the PCI bar(s) on
the host when doing device passthrough.  This can lead to a race
condition where the hypervisor is still cleaning up the device while
libvirt is trying to re-attach it to the host device driver.  To avoid
this situation, we look through /proc/iomem, and if the hypervisor is
still holding onto the bar (denoted by the string in the matcher variable),
then we can wait around a bit for that to clear up.

v2: Thanks to review by DV, make sure we wait the full timeout per-device

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-01-22 12:03:49 -05:00
Chris Lalancette
db2ae2044a Remove unused PROC_MOUNT_BUF_LEN #define 2010-01-22 10:25:44 +01:00
Adam Litke
80b4d20dfe domMemoryStats / qemu: Fix parsing of unknown stats
Fix a small problem with the qemu memory stats parsing algorithm.  If qemu
reports a stat that libvirt does not recognize, skip past it so parsing can
continue.  This corrects a potential infinite loop in the parsing code that can
only be triggered if new statistics are added to qemu.

* src/qemu/qemu_monitor_text.c: qemuMonitorParseExtraBalloonInfo add a
  skip for extra ','
2010-01-21 16:28:50 +01:00
Jim Meyering
d47b6e54fd avoid more format-related warnings
* src/qemu/qemu_conf.c (qemuBuildDriveStr): Use "%s".
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetGuestPCIAddress):
(qemuMonitorJSONGetGuestDriveAddress): Likewise.
2010-01-21 15:12:12 +01:00
Daniel P. Berrange
6512d09cf8 Fix off-by-1 in SCSI drive hotplug
The loop looking for the controller associated with a SCI drive had
an off by one, causing it to miss the last controller.

* src/qemu/qemu_driver.c: Fix off-by-1 in searching for SCSI
  drive hotplug
2010-01-21 14:00:17 +00:00
Daniel P. Berrange
e3a0c80f1d Fix leak in hotplug code in QEMU driver
The hotplug code in QEMU was leaking memory because although the
inner device object was being moved into the main virDomainDefPtr
config object, the outer container virDomainDeviceDefPtr was not.

 * src/qemu/qemu_driver.c: Clarify code to show that the inner
   device object is owned by the main domain config upon
   successfull attach.
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
5b6782f941 Add configuration option to turn off dynamic permissions management
Add the ability to turn off dynamic management of file permissions
for libvirt guests.

* qemu/libvirtd_qemu.aug: Support 'dynamic_ownership' flag
* qemu/qemu.conf: Document 'dynamic_ownership' flag.
* qemu/qemu_conf.c: Load 'dynamic_ownership' flag
* qemu/test_libvirtd_qemu.aug: Test 'dynamic_ownership' flag
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
2df1657686 Fix security driver calls in hotplug cleanup paths
The hotplug code was not correctly invoking the security driver
in error paths. If a hotplug attempt failed, the device would
be left with VM permissions applied, rather than restored to the
original permissions. Also, a CDROM media that is ejected was
not restored to original permissions. Finally there was a bogus
call to set hostdev permissions in the hostdev unplug code

* qemu/qemu_driver.c: Fix security driver usage in hotplug/unplug
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
b2a2ba71b4 Add missing call to re-attach host devices if VM startup fails
If there is a problem with VM startup, PCI devices may be left
assigned to pci-stub / pci-back. Adding a call to reattach
host devices in the cleanup path is required.

* qemu/qemu_driver.c: qemuDomainReAttachHostDevices() when
  VM startup fails
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
3812c7b42d Switch QEMU driver over to use the DAC security driver
Remove all the QEMU driver calls for setting file ownership and
process uid/gid. Instead wire in the QEMU DAC security driver,
stacking it ontop of the primary SELinux/AppArmour driver.

* qemu/qemu_driver.c: Switch over to new DAC security driver
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
15f5eaa098 Introduce a new DAC security driver for QEMU
This new security driver is responsible for managing UID/GID changes
to the QEMU process, and any files/disks/devices assigned to it.

* qemu/qemu_conf.h: Add flag for disabling automatic file permission
  changes
* qemu/qemu_security_dac.h, qemu/qemu_security_dac.c: New DAC driver
  for QEMU guests
* Makefile.am: Add new files
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
80fd73ca09 Introduce a stacked security driver impl for QEMU
* qemu/qemu_conf.h: Add securityPrimaryDriver and
  securitySecondaryDriver fields to 'struct qemud_driver'
* Makefile.am: Add new files
* qemu/qemu_security_stacked.c, qemu/qemu_security_stacked.h: A
  simple stacked security driver
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
08fd20b04a Pull initial disk labelling out into libvirtd instead of exec hook
Pulling the disk labelling code out of the exec hook, and into
libvirtd will allow it to access shared state in the daemon. It
will also make debugging & error reporting easier / more reliable.

* qemu/qemu_driver.c: Move initial disk labelling calls up into
  libvirtd. Add cleanup of disk labels upon failure
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
9c48360b1a Fix leak of allocated security label
If a VM fails to start, we can't simply free the security label
strings, we must call the domainReleaseSecurityLabel() method
otherwise the reserved 'mcs' level will be leaked in SElinux

* src/qemu/qemu_driver.c: Invoke domainReleaseSecurityLabel()
  when domain fails to start
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
0c0e0d0263 Refactor setup & cleanup of security labels in security driver
The current security driver architecture has the following
split of logic

 * domainGenSecurityLabel

    Allocate the unique label for the domain about to be started

 * domainGetSecurityLabel

    Retrieve the current live security label for a process

 * domainSetSecurityLabel

    Apply the previously allocated label to the current process
    Setup all disk image / device labelling

 * domainRestoreSecurityLabel

    Restore the original disk image / device labelling.
    Release the unique label for the domain

The 'domainSetSecurityLabel' method is special because it runs
in the context of the child process between the fork + exec.

This is require in order to set the process label. It is not
required in order to label disks/devices though. Having the
disk labelling code run in the child process limits what it
can do.

In particularly libvirtd would like to remember the current
disk image label, and only change shared image labels for the
first VM to start. This requires use & update of global state
in the libvirtd daemon, and thus cannot run in the child
process context.

The solution is to split domainSetSecurityLabel into two parts,
one applies process label, and the other handles disk image
labelling. At the same time domainRestoreSecurityLabel is
similarly split, just so that it matches the style. Thus the
previous 4 methods are replaced by the following 6 new methods

 * domainGenSecurityLabel

    Allocate the unique label for the domain about to be started
    No actual change here.

 * domainReleaseSecurityLabel

   Release the unique label for the domain

 * domainGetSecurityProcessLabel

   Retrieve the current live security label for a process
   Merely renamed for clarity.

 * domainSetSecurityProcessLabel

   Apply the previously allocated label to the current process

 * domainRestoreSecurityAllLabel

    Restore the original disk image / device labelling.

 * domainSetSecurityAllLabel

    Setup all disk image / device labelling

The SELinux and AppArmour drivers are then updated to comply with
this new spec. Notice that the AppArmour driver was actually a
little different. It was creating its profile for the disk image
and device labels in the 'domainGenSecurityLabel' method, where as
the SELinux driver did it in 'domainSetSecurityLabel'. With the
new method split, we can have consistency, with both drivers doing
that in the domainSetSecurityAllLabel method.

NB, the AppArmour changes here haven't been compiled so may not
build.
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
81fbb4cb23 Make security drivers responsible for checking dynamic vs static labelling
The QEMU driver is doing 90% of the calls to check for static vs
dynamic labelling. Except it is forgetting todo so in many places,
in particular hotplug is mistakenly assigning disk labels. Move
all this logic into the security drivers themselves, so the HV
drivers don't have to think about it.

* src/security/security_driver.h: Add virDomainObjPtr parameter
  to virSecurityDomainRestoreHostdevLabel and to
  virSecurityDomainRestoreSavedStateLabel
* src/security/security_selinux.c, src/security/security_apparmor.c:
  Add explicit checks for VIR_DOMAIN_SECLABEL_STATIC and skip all
  chcon() code in those cases
* src/qemu/qemu_driver.c: Remove all checks for VIR_DOMAIN_SECLABEL_STATIC
  or VIR_DOMAIN_SECLABEL_DYNAMIC. Add missing checks for possibly NULL
  driver entry points.
2010-01-21 14:00:16 +00:00
Laine Stump
623bc48ad8 Fix uses of virFileMakePath
* src/lxc/lxc_container.c src/lxc/lxc_controller.c src/lxc/lxc_driver.c
  src/network/bridge_driver.c src/qemu/qemu_driver.c
  src/uml/uml_driver.c: virFileMakePath returns 0 for success, or the
  value of errno on failure, so error checking should be to test
  if non-zero, not if lower than 0
2010-01-21 00:52:13 +01:00
Matthias Bolte
1671b64702 Unset copied environment variables in qemuxml2argvtest
The test expected all environment variables copied in qemudBuildCommandLine
to have known values. So all of them have to be either set to a known value
or be unset. SDL_VIDEODRIVER and QEMU_AUDIO_DRV are not handled at all but
should be handled. Unset both, otherwise the test will fail if they are set
in the testing environment.

* src/qemu/qemu_conf.c: add a comment about copied environment variables
  and qemuxml2argvtest
* tests/qemuxml2argvtest.c: unset SDL_VIDEODRIVER and QEMU_AUDIO_DRV
2010-01-20 23:22:15 +01:00
Matthias Bolte
aef969499f qemu: Don't allocate zero bytes 2010-01-20 22:50:35 +01:00
Daniel P. Berrange
ed00e45dba Fix QEMU driver custom domain status XML extensions
Invoking the virConnectGetCapabilities() method causes the QEMU
driver to rebuild its internal capabilities object. Unfortunately
it was forgetting to register the custom domain status XML hooks
again.

To avoid this kind of error in the future, the code which builds
capabilities is refactored into one single method, which can be
called from all locations, ensuring reliable rebuilds.

* src/qemu/qemu_driver.c: Fix rebuilding of capabilities XML and
  guarentee it is always consistent
2010-01-20 16:33:02 +00:00
Jiri Denemark
4bc3bd7b18 Remove superfluous new lines from messages
I noticed some debug messages are printed with an empty lines after
them. This patch removes these empty lines from all invocations of the
following macros:
    VIR_DEBUG
    VIR_DEBUG0
    VIR_ERROR
    VIR_ERROR0
    VIR_INFO
    VIR_WARN
    VIR_WARN0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-01-19 17:30:41 +01:00
Jiri Denemark
a3e1f04b76 Use pciDeviceIsAssignable in qemu driver
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-01-19 17:30:41 +01:00
Jiri Denemark
5d462bd0b3 Implement CPU topology support for QEMU driver
QEMU's command line equivalent for the following domain XML fragment
    <vcpus>2</vcpus>
    <cpu ...>
        ...
        <topology sockets='1' cores='2', threads='1'/>
    </cpu>

is

    -smp 2,sockets=1,cores=2,threads=1

This syntax was introduced in QEMU-0.12.

Version 2 changes:
- -smp argument build split into a separate function
- always add ",sockets=S,cores=C,threads=T" to -smp if qemu supports it
- use qemuParseCommandLineKeywords for command line parsing

Version 3 changes:
- ADD_ARG_LIT => ADD_ARG and line reordering in qemudBuildCommandLine
- rebased

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-01-19 11:40:09 +01:00
Jiri Denemark
014c9f3196 Enhance qemuParseCommandLineKeywords
Current version expects name=value,... list and when an incorrect string
such as "a,b,c=d" would be parsed as "a,b,c" keyword with "d" value
without reporting any error, which is probably not the expected
behavior.

This patch adds an extra argument called allowEmptyValue, which if
non-zero will permit keywords with no value; "a,b=c,,d=" will be parsed
as follows:
    keyword value
    "a"     NULL
    "b"     "c"
    ""      NULL
    "d"     ""

In case allowEmptyValue is zero, the string is required to contain
name=value pairs only; retvalues is guaranteed to contain non-NULL
pointers. Now, "a,b,c=d" will result in an error.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-01-19 11:23:03 +01:00
Daniel P. Berrange
b66924148a Convert VirtIO balloon over to -device syntax
Replace

   -balloon virtio

With

   -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3

This allows it to get correct assigned PCI address as declared in
previous patch

 * src/qemu/qemu_conf.c: Convert Virtio ballon to -device and
   give it an explicit PCI address
 * tests/qemuxml2argvdata/qemuxml2argv-*args: Add in virtio balloon
   where appropriate
2010-01-18 13:55:57 +00:00
Daniel P. Berrange
a44d0dc26c Auto-assign PCI addresses
Instead of relying on QEMU to assign PCI addresses and then querying
them with 'info pci', manually assign all PCI addresses before starting
the guest.  These addresses are not stable across reboots. That will
come in a later patch

NB, the PIIX3 (IDE, FDC, ISA-Bridge) will always have slot 1 and
VGA will always have slot 2. We declare the Virtio Balloon gets
slot 3, and then all remaining slots are for configured devices.

* src/qemu/qemu_conf.c: If -device is supported, then assign all PCI
  addresses when building the command line
* src/qemu/qemu_driver.c: Don't query monitor for PCI addresses if
  they have already been assigned
* tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-sound-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.args: Update
  to include PCI slot/bus information
2010-01-18 13:55:57 +00:00
Daniel P. Berrange
febc591683 Pass -vga none if no video card specified
QEMU always configures a VGA card. If no video card is included in
the libvirt XML, it is neccessary to explicitly turn off the default
using -vga none

* src/qemu/qemu_conf.c: Pass -vga none if no video card is configured
* tests/qemuargv2xmltest.c, tests/qemuxml2argvtest.c: Test for
  handling -vga none.
* tests/qemuxml2argvdata/qemuxml2argv-nographics-vga.args,
  tests/qemuxml2argvdata/qemuxml2argv-nographics-vga.xml: Test
  data files
2010-01-18 13:55:57 +00:00