Commit Graph

463 Commits

Author SHA1 Message Date
Chris Wright
c80651a5ae qemu driver: fix version check typos
* src/qemu/qemu_conf.c (qemudParseHelpStr): Fix errors that made
it impossible to diagnose invalid minor and micro version number
components.

Signed-off-by: Chris Wright <chrisw@redhat.com>
2010-05-20 21:35:36 +02:00
Cole Robinson
ac23d911df qemu: Use ShutdownVMDaemon for all startup cleanup paths
The current cleanup: in StartVMDaemon path is a poor duplication.
qemuShutdownVMDaemon can handle teardown for inactive VMs, so let's use it.

v2: Remove old abort: label, only use cleanup:
2010-05-20 15:11:22 -04:00
Jim Meyering
20beb0c0db qemu_conf.c: also recognize new first line of qemu -help output
* src/qemu/qemu_conf.c (QEMU_VERSION_STR_1, QEMU_VERSION_STR_2):
Define these instead of...
(QEMU_VERSION_STR): ... this.  Remove definition.
(qemudParseHelpStr): Check first for the new, shorter prefix,
"QEMU emulator version", and then for the old one,
"QEMU PC emulator version" when trying to parse the version number.
Based on a patch by Chris Wright.
2010-05-20 19:13:26 +02:00
Cole Robinson
348c6fc0ab qemu: Don't deny ShutdownVMDaemon for non-running VMs
Clients that require this already seem to do so. Calling this function
with pid < 1 also should not cause problems.
2010-05-20 11:45:20 -04:00
Cole Robinson
4da188ea3d qemu: Remove explicit VNC XML cleanup
This only exists for a certain cleanup path in StartVMDaemon, but is
unneeded since domain_conf.c handles this for us automatically.
2010-05-20 11:45:19 -04:00
Cole Robinson
b6992818c6 qemu: Properly cleanup in security startup error path
Everything after hostdev setup needs to jump to cleanup on error.
2010-05-20 11:45:19 -04:00
Alex Williamson
7e1249f259 Rename qemuBuildCommandLine tapfds -> vmfds.
There doesn't seem to be anything specific to tap devices for this
array of file descriptors which need to stay open of the guest to use.
Rename then for others to make use of.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-05-20 10:05:20 -04:00
Jim Meyering
6aacf84a3b qemudDomainMigrateFinish2: handle a case of virDomainSaveStatus failure
* src/qemu/qemu_driver.c (qemudDomainMigrateFinish2): Don't ignore
virDomainSaveStatus failure.
* src/conf/domain_conf.h (virDomainSaveStatus): Use
ATTRIBUTE_RETURN_CHECK, so this doesn't happen again.
2010-05-20 07:51:21 +02:00
Jim Meyering
dcf30d9c25 initialize "meta" in virStorageFileGetMetadata, not in each caller
Do not require each caller of virStorageFileGetMetadata and
virStorageFileGetMetadataFromFD to first clear the storage of the
"meta" buffer.  Instead, initialize that storage in
virStorageFileGetMetadataFromFD.
* src/util/storage_file.c (virStorageFileGetMetadataFromFD): Clear
"meta" here, not before each of the following callers.
* src/qemu/qemu_driver.c (qemuSetupDiskCgroup): Don't clear "meta" here.
(qemuTeardownDiskCgroup): Likewise.
* src/qemu/qemu_security_dac.c (qemuSecurityDACSetSecurityImageLabel):
Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityImageLabel):
Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
2010-05-19 17:07:08 +02:00
Jim Meyering
e638a2461d (qemu*DiskCgroup): avoid dead code
* src/qemu/qemu_driver.c (qemuTeardownDiskCgroup): Remove
bogus empty-body while-loop.
(qemuSetupDiskCgroup): Likewise.
2010-05-19 17:07:08 +02:00
Jim Meyering
c5a2fe243b maint: don't mark VIR_WARN or VIR_WARN0 diagnostics for translation
Approximately 60 messages were marked.  Since these diagnostics are
intended solely for developers and maintainers, encouraging translation
is deemed to be counterproductive:
http://thread.gmane.org/gmane.comp.emulators.libvirt/25050/focus=25052

Run this command:
  git grep -l VIR_WARN|xargs perl -pi -e \
    's/(VIR_WARN0?)\s*\(_\((".*?")\)/$1($2/'
2010-05-19 12:00:18 +02:00
Jim Meyering
49ed0a2e1b do not ignore qemuMonitorAddDrive failure; make uses identical
There were three very similar uses of qemuMonitorAddDrive.
This change makes the three 17-line sequences identical.
* src/qemu/qemu_driver.c (qemudDomainAttachPciDiskDevice): Detect
failure.  Add VIR_WARN and braces.
(qemudDomainAttachSCSIDisk): Add VIR_WARN and braces.
(qemudDomainAttachUsbMassstorageDevice): Likewise.
2010-05-18 19:23:33 +02:00
Jim Meyering
11eeabd71b qemudDomainRestore: handle a case of virDomainSaveStatus failure
* src/qemu/qemu_driver.c (qemudDomainRestore): Don't ignore
virDomainSaveStatus failure.
2010-05-18 19:23:33 +02:00
Jim Meyering
cff218f353 qemuMonitorTextMigrate: avoid leak on OOM-error path
* src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrate): Also
free "safedest" buffer when failing.
2010-05-18 19:23:32 +02:00
Daniel P. Berrange
31e29fe524 Protect against NULL pointer flaws in monitor usage
History has shown that there are frequent bugs in the QEMU driver
code leading to the monitor being invoked with a NULL pointer.
Although the QEMU driver code should always report an error in
this case before invoking the monitor, as a safety net put in a
generic check in the monitor code entry points.

* src/qemu/qemu_monitor.c: Safety net to check for NULL monitor
  object
2010-05-18 06:03:06 -04:00
Daniel P. Berrange
c4b2a93907 Fix multiple potential NULL pointer references in monitor usage
Any method which intends to invoke a monitor command must have
a check for virDomainObjIsActive() before using the monitor to
ensure that priv->mon != NULL.

There is one subtle edge case in this though. If a method invokes
multiple monitor commands, and calls qemuDomainObjExitMonitor()
in between two of these commands then there is no guarentee that
priv->mon != NULL anymore. This is because the QEMU process may
exit or die at any time, and because qemuDomainObjEnterMonitor()
releases the lock on virDomainObj, it is possible for the background
thread to close the monitor handle and thus qemuDomainObjExitMonitor
will release the last reference allowing priv->mon to become NULL.

This affects several methods, most notably migration but also some
hotplug methods. This patch takes a variety of approaches to solve
the problem, depending on the particular usage scenario. Generally
though it suffices to add an extra virDomainObjIsActive() check
if qemuDomainObjExitMonitor() was called during the method.

* src/qemu/qemu_driver.c: Fix multiple potential NULL pointer flaws
  in usage of the monitor
2010-05-18 06:03:06 -04:00
Jim Meyering
20701b17e2 qemudDomainSetVcpus: avoid NULL-deref on failed uuid look-up
* src/qemu/qemu_driver.c (qemudDomainSetVcpus): Upon look-up failure,
i.e., vm==NULL, goto cleanup, rather than to "endjob", superficially
since the latter would dereference vm, but more fundamentally because
we certainly don't want to call qemuDomainObjEndJob before we've
even attempted qemuDomainObjBeginJob.
2010-05-18 07:53:42 +02:00
Eric Blake
f30ccb2458 qemu_conf: fix flag value
(gdb) p/x QEMUD_CMD_FLAG_VNET_HOST
$7 = 0xffffffff80000000

Oops - that meant we were incorrectly setting QEMU_CMD_FLAG_RTC_TD_HACK
for qemu-kvm-0.12.3 (and probably botching a few other settings as well).

Fixes Red Hat BZ#592070

* src/qemu/qemu_conf.h (QEMUD_CMD_FLAG_VNET_HOST): Avoid sign
extension.
* tests/qemuhelpdata/qemu-kvm-0.12.3: New file.
* tests/qemuhelptest.c (mymain): Add another case.
2010-05-17 16:28:02 -06:00
Cole Robinson
07c621d09c qemu: Clarify a couple error messages
A fedora translator filed:

https://bugzilla.redhat.com/show_bug.cgi?id=580816

Pointing out these two error messages as unclear: "write save" sounds
like a typo without context, and lack of a colon made the second message
difficult to parse.
2010-05-17 17:22:08 -04:00
Eric Blake
d533a98ed6 virFileResolveLink: fix return value
virFileResolveLink was returning a positive value on error,
thus confusing callers that assumed failure was < 0.  The
confusion is further evidenced by callers that would have
ended up calling virReportSystemError with a negative value
instead of a valid errno.

Fixes Red Hat BZ #591363.

* src/util/util.c (virFileResolveLink): Live up to documentation.
* src/qemu/qemu_security_dac.c
(qemuSecurityDACRestoreSecurityFileLabel): Adjust callers.
* src/security/security_selinux.c
(SELinuxRestoreSecurityFileLabel): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskDeleteVol): Likewise.
2010-05-17 14:48:27 -06:00
Cole Robinson
83be64034a qemu: Report cmdline output if VM dies early
qemuReadLogOutput early VM death detection is racy and won't always work.
Startup then errors when connecting to the VM monitor. This won't report
the emulator cmdline output which is typically the most useful diagnostic.

Check if the VM has died at the very end of the monitor connection step,
and if so, report the cmdline output.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=581381
2010-05-17 10:15:53 -04:00
Cole Robinson
d536f6b177 qemu: Fix previous commit, use comparision in if() 2010-05-17 09:39:11 -04:00
Jim Meyering
560758c900 qemu_driver: avoid NULL dereference
* src/qemu/qemu_driver.c (qemudDomainStart): After setting vm to NULL,
goto cleanup, rather than dereferencing the NULL pointer.
2010-05-17 13:47:45 +02:00
Daniel P. Berrange
2d665c9e2d Remove debugging fprintf() calls
* src/qemu/qemu_driver.c: Remove debugging fprintf() calls
  accidentally left in code
2010-05-17 10:44:49 +01:00
Jim Meyering
b48fb801dd qemudDomainSetVcpus: avoid NULL-deref
* src/qemu/qemu_driver.c (qemudDomainSetVcpus): Avoid NULL-deref
upon unknown UUID.  Call qemuDomainObjBeginJob(vm) only after
ensuring that vm != NULL, not before.  This potential NULL-deref
was introduced by commit 2c555d87b0.
2010-05-15 09:02:54 +02:00
Stefan Berger
ba99a1b637 nwfilter: Add missing driver lock in qemu driver
This adds a missing driver lock in the qemu driver to protect
the list of domains.
2010-05-14 14:22:39 -04:00
Ryota Ozaki
d6644013d2 Fix a misuse of virAsprintf in qemudDomainMemoryPeek
The code specifies driver->cacheDir as the format string,
but it usually doesn't contain '%s', so the subsequent
argument, "/qemu.mem.XXXXXX", is always ignored.

The patch fixes the misuse.
2010-05-14 10:45:58 -06:00
Daniel P. Berrange
de4d70873a Make domain save work when dynamic_ownership=0
Setting dynamic_ownership=0 in /etc/libvirt/qemu.conf prevents
libvirt's DAC security driver from setting uid/gid on disk
files when starting/stopping QEMU, allowing the admin to manage
this manually. As a side effect it also stopped setting of
uid/gid when saving guests to a file, which completely breaks
save when QEMU is running non-root. Thus saved state labelling
code must ignore the dynamic_ownership parameter

* src/qemu/qemu_security_dac.c: Ignore dynamic_ownership=0 when
  doing save/restore image labelling
2010-05-14 09:21:33 -04:00
Daniel P. Berrange
02ddaddfa8 Don't reset user/group/security label on shared filesystems during migrate
When QEMU runs with its disk on NFS, and as a non-root user, the
disk is chownd to that non-root user. When migration completes
the last step is shutting down the QEMU on the source host. THis
normally resets user/group/security label. This is bad when the
VM was just migrated because the file is still in use on the dest
host. It is thus neccessary to skip the reset step for any files
found to be on a shared filesystem

* src/libvirt_private.syms: Export virStorageFileIsSharedFS
* src/util/storage_file.c, src/util/storage_file.h: Add a new
  method virStorageFileIsSharedFS() to determine if a file is
  on a shared filesystem (NFS, GFS, OCFS2, etc)
* src/qemu/qemu_driver.c: Tell security driver not to reset
  disk labels on migration completion
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_stacked.c,
  src/security/security_selinux.c, src/security/security_driver.h,
  src/security/security_apparmor.c: Add ability to skip disk
  restore step for files on shared filesystems.
2010-05-14 09:21:24 -04:00
Daniel P. Berrange
117d04fb1d Fix handling of disk backing stores with cgroups
The cgroups ACL code was only allowing the primary disk image.
It is possible to chain images together, so we need to search
for backing stores and add them to the ACL too. Since the ACL
only handles block devices, we ignore the EINVAL we get from
plain files. In addition it was missing code to teardown the
cgroup when hot-unplugging a disk

* src/qemu/qemu_driver.c: Allow backing stores in cgroup ACLs
  and add missing teardown code in unplug path
2010-05-14 09:20:13 -04:00
Daniel P. Berrange
ff45b4c26f Add support for NIC hotplug using netdev_add in QEMU
QEMU is gaining a new monitor command netdev_add for hotplugging
NICs using the netdev backend code. We already support this on
the command this, though it is disabled. This adds support for
hotplug too, also to remain disabled until 0.13 QEMU is released

* src/qemu/qemu_driver.c: Support netdev hotplug for NICs
* 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 netdev_add and netdev_remove commands
2010-05-14 09:16:36 -04:00
Jiri Denemark
d84bb6d6a3 Fix monitor ref counting when adding event handle
When closing a monitor using qemuMonitorClose(), we are aware of
the possibility the monitor is still being used somewhere:

    /* NB: ordinarily one might immediately set mon->watch to -1
     * and mon->fd to -1, but there may be a callback active
     * that is still relying on these fields being valid. So
     * we merely close them, but not clear their values and
     * use this explicit 'closed' flag to track this state */

but since we call virEventAddHandle() on that monitor without increasing
its ref counter, the monitor is still freed which makes possible users
of it quite unhappy. The unhappiness can lead to a hang if qemuMonitorIO
tries to lock mutex which no longer exists.
2010-05-12 16:07:42 +02:00
Matthias Bolte
ea8d236b73 qemu: Fix warning about a non-literal format string 2010-05-07 17:47:16 +02:00
Wolfgang Mauerer
6bc4ea5af0 Implement SCSI disk unplugging
With the introduction of the generic qemu device model, unplugging
SCSI disks works like a charm, so support it in libvirt.

* src/qemu/qemu_driver.c: Add qemudDomainDetachSCSIDiskDevice() to do the
  unplugging, extend qemudDomainDetachDeviceAdd().

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2010-05-06 15:55:29 -06:00
Eric Blake
697426e440 qemu: use better types
* src/qemu/qemu_driver.c (qemudFindDisk): Mark parameter const.
(qemudShrinkDisks): Mark parameter unsigned.
2010-05-06 15:32:56 -06:00
Wolfgang Mauerer
dc1a2fcce6 Refactor disk unplugging
We can reuse some of the code for other purposes.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
2010-05-06 15:19:39 -06:00
Eric Blake
062a25f078 build: update gnulib
81 patches to gnulib, picks up several new syntax checks.

* .gnulib: Update to latest.
* .x-sc_prohibit_always_true_header_tests: New file.
* bootstrap.conf (gnulib_modules): Add sched.
* src/util/processinfo.c (includes): <sched.h> is now guaranteed.
* src/network/bridge_driver.c (includes): Drop useless
<strings.h>.
* src/openvz/openvz_conf.c (includes): Likewise.
* src/openvz/openvz_driver.c (includes): Likewise.
* src/phyp/phyp_driver.c (includes): Likewise.
* src/qemu/qemu_driver.c (includes): Likewise.
* src/uml/uml_driver.c (includes): Likewise.
2010-05-06 14:35:38 -06:00
Eric Blake
2256d8b86e build: silence a clang false positive
* src/qemu/qemu_monitor.c (qemuMonitorIOWriteWithFD): Work around
recent clang shortcoming in analysis.
2010-05-05 14:46:41 -06:00
Kenneth Nagin
b0a3f8b6c5 qemu: live migration with non-shared storage for kvm
Support for live migration between hosts that do not share storage was
added to qemu-kvm release 0.12.1.
It supports two flags:
-b migration without shared storage with full disk copy
-i migration without shared storage with incremental copy (same base image
shared between source and destination).

I tested the live migration without shared storage (both flags) for native
and p2p with and without tunnelling.  I also verified that the fix doesn't
affect normal migration with shared storage.
2010-05-04 16:03:36 -06:00
Eric Blake
9f87b631ce build: prefer WIN32 over __MINGW32__ checks
WIN32 is always defined when __MINGW32__ is defined, but the
converse is not true.  WIN32 is more generic, if someone were
to ever attempt porting to a microsoft compiler.  This does
not affect Cygwin, which intentionally does not define WIN32.

* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Use more
generic flag macro.
* src/storage/storage_backend.c
(virStorageBackendUpdateVolTargetInfoFD)
(virStorageBackendRunProgRegex): Likewise.
* tools/console.h (vshRunConsole): Likewise.
2010-05-03 16:03:24 -06:00
Daniel P. Berrange
34dcbbb470 Add support for another explicit IO error event
This introduces a new event type

   VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON

This event is the same as the previous VIR_DOMAIN_ID_IO_ERROR
event, but also includes a string describing the cause of
the event.

Thus there is a new callback definition for this event type

typedef void (*virConnectDomainEventIOErrorReasonCallback)(virConnectPtr conn,
                                                           virDomainPtr dom,
                                                           const char *srcPath,
                                                           const char *devAlias,
                                                           int action,
                                                           const char *reason,
                                                           void *opaque);

This is currently wired up to the QEMU block IO error events

* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
  IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
  and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
  src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
  for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
  events to application
* src/remote/remote_protocol.x: Wire protocol definition for
  IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
  from QEMU monitor
2010-04-30 15:52:59 +01:00
Jim Meyering
5b0aed68b0 qemudDomainSaveFlag: remove dead store
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Remove dead store to "rc".
2010-04-29 22:13:24 +02:00
Daniel P. Berrange
0eecdd685a Fix detection of disk in IO events
When using -device syntax, the IO event will have a different
prefix, 'drive-' that needs to be skipped over before matching
against the libvirt disk alias

* src/qemu/qemu_driver.c: Skip QEMU_DRIVE_HOST_PREFIX in IO event
2010-04-29 17:43:41 +01:00
Daniel P. Berrange
db57a7bed8 Implement virDomainGetBlockInfo in QEMU driver
* src/qemu/qemu_driver.c: Implementation of virDomainGetBlockInfo
* src/util/storage_file.h: Add DEV_BSIZE
* src/storage/storage_backend.c: Remove DEV_BSIZE
2010-04-29 17:21:26 +01:00
Daniel P. Berrange
46bad5121f Internal driver API infrastructure for virDomainGetBlockInfo
This defines the internal driver API and stubs out each driver

* src/driver.h: Define virDrvDomainGetBlockInfo signature
* src/libvirt.c, src/libvirt_public.syms: Glue public API to drivers
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
  src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
  src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
  src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub out driver
2010-04-29 17:20:24 +01:00
Chris Lalancette
87d2e4ba56 Fix a qemuDomainPCIAddressSetFree memory leak
qemuDomainPCIAddressSetFree was freeing up the hash
table for the pci addresses, but not freeing up the addr
structure.  Looking over the callers of this function, it
seems like they expect it to also free up the structure,
so do that here.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-04-29 09:16:14 -04:00
Chris Lalancette
34b3c64a98 Report better error if qemuSnapshotIsAllowed failed.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-04-29 09:15:07 -04:00
Daniel P. Berrange
bdb844e996 Remove unused goto label from qemudDomainCreate
The previous commit changes a goto from 'endjob' to 'cleanup',
leaving the endjob label unused. Remove it to avoid compile
warning.

* src/qemu/qemu_driver.c: Remove 'endjob' label
2010-04-29 12:13:02 +01:00
Jim Meyering
ba1072f0ac qemuDomainSnapshotCreateXML: avoid NULL dereferences
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): When setting
"vm" to NULL, jump over vm-dereferencing code to "cleanup".
(qemuDomainRevertToSnapshot): Likewise.
2010-04-29 11:16:04 +02:00
Jim Meyering
5eec84aaa3 qemudDomainCreate: correct a slightly misdirected goto
* src/qemu/qemu_driver.c (qemudDomainCreate): Goto cleanup,
not "endjob", since we know "vm" is already NULL.  No semantic change.
2010-04-29 11:16:03 +02:00