Commit Graph

346 Commits

Author SHA1 Message Date
Daniel P. Berrange
c42c1b8a5e Port QEMU driver to use USB/PCI device helpers
* src/qemu_driver.c: Remove usbfs/sysfs iterator code and call
  into generic helper APIs instead when setting device permissions
2009-09-10 14:34:07 +01:00
Daniel P. Berrange
5c8d3d3bca Fix misc thread locking bugs / bogus warnings
Fix all thread locking bugs reported by object-locking test
case.

NB, some of the driver locking is getting too coarse. Driver
mutexes really need to be turned into RW locks instead to
significantly increase concurrency.

* src/lxc_driver.c: Fix useof driver when unlocked in the methods
  lxcDomainGetInfo, lxcSetSchedulerParameters, and
  lxcGetSchedulerParameters
* src/opennebula/one_driver.c: Fix missing unlock in oneDomainUndefine.
  Fix use of driver when unlocked in oneDomainGetInfo,
  oneGetOSType, oneDomainShutdown
* src/qemu_driver.c: Fix use of driver when unlocked in
  qemudDomainSavem, qemuGetSchedulerType, qemuSetSchedulerParameters
  and qemuGetSchedulerParameters
* src/storage_driver.c: Re-work storagePoolCreate to avoid bogus
  lock checking warning. Re-work storageVolumeCreateXMLFrom to
  remove a potential NULL de-reference & avoid bogus lock check
  warnings
* src/test.c: Remove testDomainAssignDef since it break lock chekc
  warnings.
* tests/object-locking.ml: Add oneDriverLock, oneDriverUnlock
  and one_driver_t methods/types to allow lock checking on the
   OpenNebula drivers
2009-09-10 14:26:56 +01:00
Mark McLoughlin
6ab16aaf63 Simplify and fix qemudCanonicalizeMachine()
The algorithm is quite simple:

  If the emulator matches a guest's domain:
    if domain has machine type info:
      check the domain's machine type info
    else
      check the guest's default machine type info
  else if the emulator matches the guest's default emulator:
     check the guest's default machine type info

The previous implementation was incorrectly falling back to the default
machine type info if the domain's machine type info didn't have an
alias.

* src/qemu_driver.c: simplify and fix qemudCanonicalizeMachine()
2009-09-10 12:37:42 +01:00
Mark McLoughlin
6e7ab46106 Canonicalize the qemu machine type in qemuxml2argvtest
This doesn't have any affect on the current tests because we don't have
any machine aliases in the current test data.

* src/qemu_conf.h, src/qemu_driver.c: expose qemudCanonicalizeMachine()
  for the tests

* tests/qemuxml2argvtest.c: canonicalize the machine type
2009-09-10 12:37:42 +01:00
Chris Lalancette
100cae7359 Fix regression from "Avoid polling on FDs with no events"
After the mentioned patch was applied, I noticed that
shutting down a kvm guest from inside (i.e. poweroff) caused
the guest to shutdown, but not removed from the list of
active guests.  DanB pointed out that the problem is that
the virEventAddHandle() call in the qemu driver was asking
to watch for 0 events, not HANGUP | ERROR as it should.  Add
these events so that shutdown works again.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-09-10 13:15:26 +02:00
Jim Meyering
f238709304 qemu_driver.c: factor out more duplication
* src/qemu_driver.c (qemudDomainRestore): Use the new ...TypeToString
function here, too.
2009-09-10 11:56:50 +02:00
Ryota Ozaki
32456779a1 Close logfile fd after spawning qemu
* src/qemu_driver.c: avoid a leak of file descriptor when exec'ing qemu
2009-09-10 11:34:14 +02:00
Charles Duffy
8d4ed2ad3d Reintroduce support for lzop compression
lzop was removed due to some confusion over whether it provided functional
advantages distinct from xz. This has been addressed in the mailing list post
archived at http://permalink.gmane.org/gmane.comp.emulators.libvirt/16487, and
support for lzop is re-added here.

* libvirt.spec.in: add dependancy on lzop
* src/qemu.conf: update documentation of save_image_format
* src/qemu_driver.c: re-add lzop compression option
2009-09-10 11:13:33 +02:00
Daniel Veillard
c5a305584f Deprecate lzma and lzop in favor of xz, add dep
* src/qemu_driver.c: drop lzma and lzop images compression options
  as they are deprecated by xz
* libvirt.spec.in: add requires for xz/bzip2/gzip as they are needed
  to implement the compression options
2009-09-09 16:44:44 +02:00
Jim Meyering
aec22258ef qemu_driver.c: factor out duplication in compression-type handling
* src/qemu_driver.c (QEMUD_SAVE_FORMAT_LAST): Define.
(qemudSaveCompressionTypeFromString): Declare.
(qemudSaveCompressionTypeToString): Declare.
(qemudDomainSave): Use those functions rather than open-coding them.
Use "cat >> '%s' ..." in place of equivalent
"dd of='%s' oflag=append conv=notrunc ...".
2009-09-09 12:11:34 +02:00
Jim Meyering
1aec7d8606 also allow use of XZ for Qemu image compression
* src/qemu_driver.c (enum qemud_save_formats) [QEMUD_SAVE_FORMAT_XZ]:
New member.
[QEMUD_SAVE_FORMAT_LZMA]: Mark as deprecated.
Use an explicit value for each member.
(qemudDomainSave, qemudDomainRestore): Handle the new member.
* src/qemu.conf: Mention xz, too.
2009-09-09 12:11:34 +02:00
Matthias Bolte
166c03f31b Some close/fclose/closedir calls are missing
* src/openvz_conf.c src/qemu_driver.c src/storage_backend_scsi.c
  src/xen_inotify.c: closes various file descriptors leaks
2009-09-07 16:47:13 +02:00
Daniel P. Berrange
e1424a97a9 Fix memory leak of monitor character device
* src/qemu_driver.c: Free the vm->monitor_chr field at VM shutdown.
  Unlink the UNIX domain socket at VM shutdown to avoid littering
  FS with old sockets
2009-09-03 18:10:16 +01:00
Daniel P. Berrange
2a6825c393 Automatically set correct ownership of QEMU state directories
* src/qemu_driver.c: Change ownership of /var/{lib,cache}/libvirt/qemu
  to match user/group that QEMU VMs are configured to run as.
2009-09-03 18:10:16 +01:00
Daniel P. Berrange
182a80b922 Move QEMU monitor socket in /var/lib/libvirt/qemu
Separate the guest created QEMU monitor socket location
from the libvirtd create XML / PID data files, to improve
security separation when running QEMU non-root

* libvirt.spec.in: Leave /var/run/libvirt/qemu as root:root
* src/qemu_conf.h: Add libDir and cacheDir directory paths
* src/qemu_driver.c: Move QEMU monitor socket from
  stateDir to libDir to avoid making security critical directory
  accessible to QEMU guests.
* src/util.c: Delay running hook till after damonizing to
  ensure pidfile is still written before changing UID/GID
2009-09-03 18:10:16 +01:00
Daniel P. Berrange
d823a05aef Support configuration of huge pages in guests
Add option to domain XML for

     <memoryBacking>
        <hugepages/>
     </memoryBacking>

* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
  Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
  and pass it when hugepages are requested.
  Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
  Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
  helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
  handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
  tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
  hugepage tests
2009-09-03 13:51:55 +01:00
Chris Lalancette
6dfc042c21 Fix bugs in virDomainMigrate v2 code.
Paolo Bonzini points out that in my refactoring of the code for
virDomainMigrate(), I added a check for the return value from
virDomainMigratePerform().  The problem is that we don't want to
exit if we fail, we actually want to go on and do
virDomainMigrateFinish2() with a non-0 return code to clean things
up.  Remove the check.

While reproducing this issue, I also noticed that we wouldn't
always properly propagate an error message.  In particular, I
found that if you blocked off the migration ports (with iptables)
and then tried the migration, it would actually fail but we would
get no failure output from Qemu.  Therefore, we would think we
succeeded, and leave a huge mess behind us.  Execute the monitor
command "info migrate", and look for a failure string in there
as well.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-09-02 17:23:06 +02:00
Daniel P. Berrange
2d6adabd53 Don't blindly reorder disk drives
Calling qsort() on the disks array causes disk to be
unneccessarily re-ordered, potentially breaking the
ability to boot if the boot disk gets moved later in
the list. The new algorithm will insert a new disk as
far to the end of the list as possible, while being
ordered correctly wrt other disks on the same bus.

* src/domain_conf.c, src/domain_conf.h: Remove disk sorting
  routines. Add API to insert a disk into existing list at
  the optimal position, without resorting disks
* src/libvirt_private.syms: Export virDomainDiskInsert
* src/xend_internal.c, src/xm_internal.c: Remove calls to
  qsort, use virDomainDiskInsert instead.
* src/qemu_driver.c: Remove calls to qsort, use virDoaminDiskInsert
  instead. Fix reordering bugs when hotunplugging disks and
  networks. Fix memory leak in disk/net unplug
2009-09-02 15:19:34 +01:00
Miloslav Trmač
28b8cc31f6 Make handling of monitor prompts more general.
* src/qemu_driver.c: Support arbitrary callbacks for "secondary
  prompts".  Reimplement qemudMonitorCommandExtra using such a
  callback.
2009-09-01 18:37:06 +01:00
Miloslav Trmač
077cd91773 Don't assume buffered output echoes the command.
The if ((nlptr...)) implicitly assumes commptr != NULL (and that "buf"
starts with "cmd").  Make the assumption explicit, it will be broken in
a future patch.

* src/qemu_driver.c: Don't assume buffered monitor output echoes the
  command.
2009-09-01 18:36:59 +01:00
Charles Duffy
cc76cf31d7 support lzop save compression for qemu
Per prior discussion -- this was, indeed, trivial.

I'm a little disappointed to be breaking the ordering characteristics of
the enum (as it had been ordered by increasing time requirements and
decreasing output size), but breaking any save files with the old
constants in the headers would of course be worse.

>From 2a9cdcfc88de091a8d34aa3fc3b1208d7681790e Mon Sep 17 00:00:00 2001
From: Charles Duffy <Charles_Duffy@dell.com>
Date: Fri, 28 Aug 2009 11:49:54 -0500
Subject: [PATCH] support lzop save compression for qemu

One of the larger disincentives towards use of compression for migrated-out save
files is performance impact. This patch adds support for lzop; CPU time for
compression is about 5x faster than gzip (the next most performant algorithm)
and decompression is about 3x faster.

Signed-off-by: Charles Duffy <Charles_Duffy@dell.com>
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-31 21:11:51 +02:00
Chris Lalancette
776f527926 Remove use of strncpy in qemudExtractMonitorPath.
qemudExtractMonitorPath() was doing a VIR_ALLOC_N followed by a
strncpy.  However, this isn't necessary; we can do the same thing
using strndup, which is much safer.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-31 21:01:36 +02:00
Chris Lalancette
2e7c8b0b6f Small fixes for qemu save compression.
Fix up a small memory leak pointed out by DanB; I was forgetting
to release memory allocated to driver->saveImageFormat.
Also add the "save_image_format" and "security" entries to
the augeas lens.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-20 09:27:03 +02:00
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