Commit Graph

323 Commits

Author SHA1 Message Date
Mark McLoughlin
e8ad339312 Maintain a list of active PCI hostdevs and use it in pciResetDevice()
As we start/shutdown guests, or hotplug/hot-unplug devices, we can add
or delete devices as appropriate from a list of active devices.

Then, in pciReset(), we can use this to determine whether its safe to
reset a device as a side effect of resetting another device.

* src/qemu_conf.h: add activePciHostdevs to qemud_driver

* src/qemu_driver.c: maintain the activePciHostdevs list, and pass it
  to pciResetDevice()

* src/pci.[ch]: pass the activeDevs list to pciResetDevice() and use
  it to determine whether a Secondary Bus Reset is safe
2009-08-18 09:41:57 +01:00
Mark McLoughlin
78675b228b Simplify PCI hostdev prepare/re-attach using a pciDeviceList type
The qemuPrepareHostDevices() and qemuDomainReAttachHostDevices()
functions are clutter with a bunch of calls to pciGetDevice() and
pciFreeDevice() obscuring the basic logic.

Add a pciDeviceList type and add a qemuGetPciHostDeviceList() function
to build a list from a domain definition. Use this in prepare/re-attach
fto simplify things and eliminate the multiple pciGetDevice calls.

This is especially useful because in the next patch we need to iterate
the hostdevs list a third time and we also need a list type for keeping
track of active devices.

* src/pci.[ch]: add pciDeviceList type and also a per-device 'managed'
  property

* src/libvirt_private.syms: export the new functions

* src/qemu_driver.c: add qemuGetPciHostDeviceList() and re-write
  qemuPrepareHostDevices() and qemuDomainReAttachHostDevices() to use it
2009-08-18 09:41:57 +01:00
Mark McLoughlin
60ff07585c Use pci_addr=auto with QEMU's pci_add monitor command
Newer versions of QEMU accept 'pci_add auto', but older versions require
'pci_add pci_addr=auto'

* src/qemu_driver.c: use pci_addr= in qemudDomainAttachHostPciDevice()
  for older versions of QEMU
2009-08-18 09:41:57 +01:00
Mark McLoughlin
457e050628 Fix thinko in PCI hostdev detach
* src/qemu_driver.c: Add missing break statement in
  qemudDomainDetachHostDevice()
2009-08-18 09:41:57 +01:00
Mark McLoughlin
12edef9a6a Reset PCI host devices after hot-unplug
When we hot-unplug a PCI host device from a guest, we should reset it.

Both managed and unmanaged devices should be reset, but only managed
devices should be re-attached.

* src/qemu_driver.c: reset devices in qemudDomainDetachHostPciDevice()
2009-08-18 09:41:57 +01:00
Mark McLoughlin
4dbecff9fb Reset unmanaged PCI host devices before hotplug
Right now we're only resetting managed devices before hotplug, but we
should reset them irrespective of whether they are managed.

* src/qemu_driver.c: reset all PCI hostdevs before hotplug
2009-08-18 09:41:57 +01:00
Mark McLoughlin
4954e079c8 Revert changes to allow pciResetDevice() reset multiple devices
It turns out that the previous attempt at this doesn't work well
in the case of hotplug. We need qemuCheckPciHostDevice() to
disallow the reset affecting devices already attach to the guest,
but we still need to avoid double locking the virDomainObjPtr.

This is all getting messy, I've a better idea.

This reverts commit 6318808270 and
c106c8a18c.

* src/qemu_driver.c, src/pci.[ch], src/xen_unified.c,
  src/libvirt_private.syms: revert a bunch of stuff.
2009-08-18 09:41:56 +01:00
Mark McLoughlin
0b973381dc Fix list updating after disk/network/hostdev hot-unplug
The current code makes a poor effort at updating the device arrays after
hot-unplug. Fix that and combine the two code paths into one.

* src/qemu_driver.c: fix list updating in qemudDomainDetachNetDevice(),
  qemudDomainDetachPciDiskDevice() and qemudDomainDetachHostPciDevice()
2009-08-18 09:41:56 +01:00
Chris Lalancette
2d6a581960 Compressed save image format for Qemu.
Implement a compressed save image format for qemu.  While ideally
we would have the choice between compressed/non-compressed
available to the libvirt API, unfortunately there is no "flags"
parameter to the virDomainSave() API.  Therefore, implement this
as a qemu.conf option.  gzip, bzip2, and lzma are implemented, and
it should be very easy to implement additional compression
methods.

One open question is if/how we should detect the compression
binaries.  One way to do it is to do compile-time setting of the
paths (via configure.in), but that doesn't seem like a great thing
to do.  My preferred solution is not to detect at all;
when we go to run the commands that need them, if they
aren't available, or aren't available in one of the standard paths,
then we'll fail.  That's also the solution implemented in this patch.

In the future, we'll have a more robust (managed) save/restore API,
at which time we can expose this functionality properly in the API.

V2: get rid of redundant dd command and just use >> to append data.
V3: Add back the missing pieces for the enum and bumping the save version.
V4: Make the compressed field in the save_header an int.
    Implement LZMA compression.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-17 09:00:19 +02:00
Mark McLoughlin
c106c8a18c Check active domain hostdevs before allowing PCI reset
If a PCI device reset causes other devices to be reset, allow it so long
as those other devices are note assigned to another active domain.

Note, we need to take the driver lock qemudNodeDeviceReset() because the
check function will iterate over the domain list.

* src/qemu_conf.c: add qemuCheckPciHostDevice() to iterate over active
  domains checking whether the affected device is assigned

* src/pci.[ch]: add pciDeviceEquals() helper
2009-08-14 08:31:11 +01:00
Mark McLoughlin
6318808270 Allow pciResetDevice() to reset multiple devices
When using a Secondary Bus Reset, all devices on the bus are reset.

Extend the pciResetDevice() API so that a 'check' callback can be
supplied which will verify that it is safe to reset the other devices
on the bus.

The virDomainObjPtr parameter is needed so that when the check function
iterates over the domain list, it can avoid double locking.

* src/pci.[ch]: add a 'check' callback to pciResetDevice(), re-work
  pciIterDevices() to pass the check function to the iter functions,
  use the check function in the bus iterator, return the first unsafe
  device from pciBusCheckOtherDevices() and include its details in
  the bus reset error message.

* src/qemu_driver.c, src/xen_uninified.c: just pass NULL as the
  check function for now
2009-08-14 08:31:11 +01:00
Mark McLoughlin
ebea341856 Improve PCI host device reset error message
Currently, if we are unable to reset a PCI device we return a fairly
generic 'No PCI reset capability available' error message.

Fix that by returning an error from the individual reset messages and
using that error to construct the higher level error mesage.

* src/pci.c: set errors in pciTryPowerManagementReset() and
  pciTrySecondaryBusReset() on failure; use those error messages
  in pciResetDevice(), or explain that no reset support is available
2009-08-14 08:31:11 +01:00
Mark McLoughlin
4035152a87 Reset and re-attach PCI host devices on guest shutdown
When the guest shuts down, we should attempt to restore all PCI host
devices to a sane state.

In the case of managed hostdevs, we should reset and re-attach the
devices. In the case of unmanaged hostdevs, we should just reset them.

Note, KVM will already reset assigned devices when the guest shuts
down using whatever means it can, so we are only doing it to cover the
cases the kernel can't handle.

* src/qemu_driver.c: add qemuDomainReAttachHostDevices() and call
  it from qemudShutdownVMDaemon()
2009-08-14 08:31:11 +01:00
Mark McLoughlin
0c5b7b93a3 Add host PCI device hotplug support
Attaching a host PCI device to a qemu guest is done with a
straightforward 'pci_add auto host host=XX:XX.X' command.

Like with NIC and disk hotplug, we need to retain the guest PCI address
assigned by qemu so that we can use it for hot-unplug.

Identifying a device for detach is done using the host PCI address.

Managed mode is handled by detaching/resetting the device before
attaching it to the guest and re-attaching it after detaching it from
the guest.

* src/qemu_driver.c: add qemudDomainAttachHostPciDevice() and
  qemudDomainDetachHostPciDevice()

* src/domain_conf.h: add somewhere to store the guest PCI address

* src/domain_conf.c: handle formatting and parsing the guest PCI
  address
2009-08-14 08:31:10 +01:00
Mark McLoughlin
7636ef4630 Re-factor hostdev hotplug
Re-factor the hostdev hotplug code so that we can easily add PCI
hostdev hotplug to qemudDomainAttachHostDevice().

* src/qemu_driver.c: rename qemudDomainAttachHostDevice() to
  qemudDomainAttachHostUsbDevice(); make qemudDomainAttachHostDevice()
  handle all hostdev types

* src/libvirt_private.syms: export a couple of hostdev related
  ToString() functions
2009-08-14 08:31:10 +01:00
Chris Lalancette
d1ec4d7a5a Run 'cont' on successful migration finish.
As of qemu 0.10.6, qemu now honors the -S flag on incoming migration.
That means that when the migration completes, we have to issue a
'cont' command to get the VM running again.  We do it unconditionally
since it won't hurt on older qemu.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-11 13:29:10 +02:00
Chris Lalancette
cbcf5ba7d4 Fix QEMU domain status after restore.
When doing a restore, we were forgetting to update the state file
for the VM.  That means that if you do a save/restore, then shut
down libvirtd, then start it back up, you'll see the state of the
guest as "paused", even though it is really running.  We were
just forgetting a "virDomainSaveStatus" call in the restor path.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-11 13:27:07 +02:00
Mark McLoughlin
c42b397845 chown kernel/initrd before spawning qemu
If we're running qemu unprivileged, we need to chown any supplied kernel
or initrd before spawning it.

* src/qemu_driver.c: rename qemuDomainSetDiskOwnership() to
  qemuDomainSetFileOwnership(), pass it a path string instead of a disk
  definition and use it for chowning the kernel/initrd in
  qemuDomainSetAllDeviceOwnership()
2009-08-10 09:00:01 +01:00
Chris Lalancette
7a4769bbdb Remove ATTRIBUTE_UNUSED from flags to qemudDomainMigratePerform.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-02 12:08:11 +02:00
Chris Lalancette
1fdb582a09 Add a comment about setting errors after qemudStartVMDaemon().
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-02 12:08:00 +02:00
Chris Lalancette
067c00f533 Fix an erroneous debug error to KVM; it should read QEMU/KVM.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-02 12:07:45 +02:00
Chris Lalancette
1a94521770 Remove a stray semicolon in qemudDomainMigratePrepare2.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-02 12:07:33 +02:00
Chris Lalancette
180ca598c4 Use virGetHostname instead of gethostname.
Fix up qemudDomainMigratePrepare2 to use virGetHostname instead of
gethostname.  Besides the fact that virGetHostname is far more clever,
there was a latent bug in the handling that could cause a buffer overflow
on a very long hostname.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-02 12:07:02 +02:00
Daniel P. Berrange
e170af3ac0 Protected against potential crash scenarios
* src/qemu_driver.c: Check that monitor device is not NULL
  before runing a command to protect against bugs in caller
2009-07-31 17:06:44 +01:00
Daniel P. Berrange
5d3e02aaa2 Fix crash when attempting to shutdown inactive QEMU vm
* src/qemu_driver.c: Add check that QEMU is active before attemting
  to shutdown. Fix error code for check in destroy method
2009-07-31 17:06:44 +01:00
Daniel P. Berrange
9a152d481b Fix problem writing QEMU pidfile
* src/util.c: Don't drop capabilities until after the PID file has
  been written. Kill off child if writing the PID file fails
* src/qemu_driver.c: Remove bogus trailing '/' in state dir
2009-07-30 17:47:34 +01:00
Ryota Ozaki
abe3ee9cc5 qemu: fix monitor socket reconnection
* src/qemu_driver.c: fix qemudOpenMonitorUnix() to retry on ENOENT
  instead of EACCES which is the error one receive when the socket
  error hasn't shown up yet
2009-07-29 16:13:05 +02:00
Daniel P. Berrange
c4a04dc024 Fill in vCPU <-> pCPU current mapping, and vCPU cpuTime for QEMU
* src/qemu_driver.c: implement missing features in qemudDomainGetVcpus
  for 'cpu' and 'cpuTime' fields
2009-07-27 16:30:25 +01:00
Mark McLoughlin
85453c4247 Add support for attaching network/bridge NICs in QEMU driver
In order to hotplug a network/bridge backed NIC, we need to first create
the tap file descriptor, add the tap interface to the bridge and then
pass the file descriptor to the qemu process using the 'getfd' monitor
command.

Once the tapfd has been accepted, we create the network backend using
host_net_add, supplying the name assigned to the tapfd. If this fails,
we need to close the tapfd in qemu using the 'closefd' monitor command.

If the version of qemu does not support the getfd/closefd monitor
commands we detect "unknown command" in the getfd reply and fail the
attach operation.

* src/qemu_driver.c: add support for tapfd based hotplug in
  qemudDomainAttachNetDevice()
2009-07-27 15:31:52 +01:00
Mark McLoughlin
1daaebfa0c Add SCM_RIGHTS support to QEMU monitor code
Add qemudMonitorCommandWithFd() which allows a file descriptor to be
sent to qemu over a unix monitor socket using SCM_RIGHTS. See the
unix(7) and cmsg(3) man pages.

* src/qemu_conf.c: add a scm_fd param to qemudMonitorCommandExtra(),
  add qemudMonitorCommandWithFd(), implement SCM_RIGHTS support in
  qemudMonitorSendUnix()
2009-07-27 15:31:51 +01:00
Mark McLoughlin
7d9576edcb Use sendmsg() on QEMU monitor socket
Switch from using write() to using sendmsg() on QEMU's monitor socket
so that we can add support for SCM_RIGHTS.

* src/qemu_driver.c: add sendmsg() based qemudMonitorSendUnix() and use
  it when the monitor fd is a unix socket
2009-07-27 15:31:51 +01:00
Mark McLoughlin
9de2972c30 Factor qemudMonitorSend() out of qemudMonitorCommandExtra()
Add a little helper function to write the monitor command followed by
carriage return in a single write.

This doesn't make any real difference, but allows us to more easily
switch to using sendmsg() when using the monitor over a unix socket.

* src/qemu_conf.c: split qemudMonitorSend() out
2009-07-27 15:31:51 +01:00
Mark McLoughlin
be44cabd7f Clean up error handling in qemudDomainAttachNetDevice()
In subsequent patches we're going to have a file descriptor to close
too, so centralize the error handling cleanups to make things easier.

* src/qemu_conf.c: in qemudDomainAttachNetDevice() consolidate the
  error handling cleanups together
2009-07-27 15:31:51 +01:00
Mark McLoughlin
32db8dd75b Make qemuBuildHostNetStr() take tapfd as a string
With hotplug, we're going to want to pass a tapfd name rather than an
actual file descriptor, so prepare the way by passing a string tapfd to
qemuBuildHostNetStr().

* src/qemu_conf.h: qemuBuildHostNetStr() takes a string tapfd now

* src/qemu_conf.c: pass qemuBuildHostNetStr() a string rather than an
  actual file descriptor

* src/qemu_driver.c: update qemudDomainAttachNetDevice() for change
2009-07-27 15:31:51 +01:00
Mark McLoughlin
707302b2cf Only probe qemu for machine types when binary changes
By probing for qemu machine types, we increased the time of a
GetCapabilities call from 100us to a whopping 60ms.

This patch takes the approach of only probing for machine types
when the mtime of the emulator binary changed since the last time
the capabilities were generated.

* src/capabilities.h: cache the emulator binary mtime

* src/qemu_conf.c: add qemudGetOldMachines() to copy the machine
  types from the old caps struct if the mtime for the binary hasn't
  changed

* src/qemu_conf.h, src/qemu_driver.c: pass the old caps pointer to
  qemudCapsInit()
2009-07-27 15:30:35 +01:00
Mark McLoughlin
c14c6b083e Probe QEMU directly for machine aliases if not found in capabilties
Not all possible emulators are actually in the capabilities, so if we
don't find the supplied emulator we should probe it directly for machine
types.

* src/qemu_driver.c: add qemudCanonicalizeMachineDirect() to directly
  probe an emulator for the canonical machine type
2009-07-27 15:17:55 +01:00
Mark McLoughlin
be291b330a Canonicalize qemu machine types
In qemu-0.11 there is a 'pc-0.10' machine type which allows you to run
guests with a machine which is compatible with the pc machine in
qemu-0.10 - e.g. using the original PCI class for virtio-blk and
virtio-console and disabling MSI support in virtio-net. The idea here
is that we don't want to suprise guests by changing the hardware when
qemu is updated.

I've just posted some patches for qemu-0.11 which allows libvirt to
canonicalize the 'pc' machine alias to the latest machine version.

This patches makes us use that so that when a guest is configured to
use the 'pc' machine type, we resolve that to 'pc-0.11' machine and
save that in the guest XML.

See also:

  https://fedoraproject.org/wiki/Features/KVM_Stable_Guest_ABI

* src/qemu_conf.c: add qemudCanonicalizeMachine() to canonicalize
  the machine type according to the machine aliases in capabilities

* src/qemu_driver.c: parse aliases in qemudParseMachineTypesStr()
2009-07-27 15:17:55 +01:00
Cole Robinson
13f3d40cbf Don't allow NULL paths for BlockStats and InterfaceStats
Do the check in libvirt.c, to save drivers from the burden. This changes
behavior slightly in the qemu driver: we no longer explictly error if
passed an empty string. An error will still be thrown when the device
lookup fails.
2009-07-26 17:25:20 -04:00
Daniel P. Berrange
f4c3acdf35 Make QEMU cgroups use configurable
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug,
   src/qemu.conf: Add 'cgroups_controllers' and 'cgroups_device_acl'
   parameters
 * src/qemu_conf.h, src/qemu_conf.c: Load & parse configuration params
   for cgroups
 * src/qemu_driver.c: Only use cgroups controllers that are activated,
   and use configured device whitelist instead of default, if set.
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
e88d638ac6 Use cgroups for block device whitelisting in QEMU guests
* src/qemu_driver.c: Set a restrictive block device whitelist for
  all QEMU guests. Update whitelist when hotplugging disks.
* src/cgroup.h, src/cgroup.c: Add some more convenience methods
  for dealing with block device whitelists.
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
55bc5090b9 Implement schedular tunables API using cgroups
* src/qemu_driver.c:  Add driver methods qemuGetSchedulerType,
  qemuGetSchedulerParameters, qemuSetSchedulerParameters
* src/lxc_driver.c: Fix to use unsigned long long consistently
  for schedular parameters
* src/cgroup.h, src/cgroup.c: Fix cpu_shares to take unsigned
  long long
* src/util.c, src/util.h, src/libvirt_private.syms: Add a
  virStrToDouble helper
* src/virsh.c: Fix handling of --set arg to schedinfo command
  to honour the designated data type of each schedular tunable
  as declared by the driver
2009-07-23 17:38:06 +01:00
Daniel P. Berrange
38f6f47be9 Place every QEMU guest in a private cgroup
* src/qemu_driver.c: Place guest in cgroup upon startup. Remove
  cgroup upon shutdown
2009-07-23 17:38:06 +01:00
Laine Stump
165ed4a00e Add bare format string to printf-derivatives troubles
* src/datatypes.c src/domain_conf.c src/interface_conf.c
  src/lxc_driver.c src/qemu_driver.c src/storage_backend.c src/virsh.c:
  add bare %s format string to printf-derivatives called with no format
  string
2009-07-23 18:27:47 +02:00
Nguyen Anh Quynh
e4c48e02b4 Add support for physical memory access for QEmu
* include/libvirt/libvirt.h include/libvirt/libvirt.h.in: adds the new
  flag VIR_MEMORY_PHYSICAL for virDomainMemoryPeek
* src/libvirt.c: update the front-end checking
* src/qemu_driver.c: extend the QEmu driver
2009-07-22 16:29:38 +02:00
Mark McLoughlin
c2709cdaaa Add support for network device detach
qemu network devices are hot-unplugged in two stages - first the PCI NIC
is removed using 'pci_del <pci_addr>' and then the backend is removed
using 'host_net_remove <vlan> <name>'.

In order to perform these operations we need to have retained the
PCI address, backend name and vlan number.

* src/qemu_driver.c: add qemudDomainDetachNetDevice()
2009-07-22 11:34:07 +01:00
Mark McLoughlin
4e21a95afe Retain PCI address from NIC attach
When we pci_add a NIC, we need to retain the PCI address assigned by
qemu for using during detach.

* src/qemu_driver.c: use qemudParsePciAddReply() to pull the PCI
  address from the pci_add reply

* src/domain_conf.c: handle storing and parsing the PCI address in the
  domain state XML file
2009-07-22 11:34:07 +01:00
Mark McLoughlin
ffec099e75 Re-factor pci_add reply parsing and parse domain/bus numbers
The current code for parsing pci_add replies ignores the the domain and
bus numbers. Re-write the code to rectify that.

Also, since pci_add is used for NIC hotplug as well ask disk hotplug,
re-factor the code into a separate function.

* src/qemu_driver.c: add qemudParsePciAddReply() function which can
  handle parsing domain and bus numbers
2009-07-22 11:34:07 +01:00
Mark McLoughlin
d06f261cb1 Remove the network backend if NIC hotplug fails
If we fail to pci_add a NIC, we should remove the network backend and
leave things the way we found them. To do that, we pre-allocate a
host_net_remove monitor command and issue that if the pci_add fails.
If the remove fails, we just log a warning.

We can only do this if we have a name for the network backend and
we know the vlan number its associated with.

* src/qemu_driver.c: host_net_remove the network backend if the
  pci_add fails
2009-07-22 11:34:07 +01:00
Mark McLoughlin
35153940e3 Basic qemu NIC hotplug support
Implement basic NIC hotplug support using the 'host_net_add' and
'pci_add' qemu monitor commands.

For now, we don't support 'bridge' or 'network' types.

Also, if pci_add fails, we currently fail to remove the backend
which we added.

Finally, NIC hot-unplug support is missing.

* src/qemu_driver.c: add qemudDomainAttachNetDevice()

* src/qemu_conf.[ch]: export qemuBuildNicStr(), qemuBuildHostNetStr()
  and qemuAssignNames()

* src/libvirt_private.syms: export virDomainNetTypeToString()
2009-07-22 11:34:06 +01:00
Mark McLoughlin
423af1977f Make qemuCmdFlags available in qemudDomainAttachDevice()
qemudDomainChangeEjectableMedia() currently extracts the qemu command
line flags, but other device attaching code might need it, so move
the qemudExtractVersionInfo() call up a frame.

* src/qemu_driver.c: move the qemudExtractVersionInfo() call from
  qemudDomainChangeEjectableMedia() to qemudDomainAttachDevice()
2009-07-22 11:34:06 +01:00