]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agoqemu: set default name for SPICE agent channel when generating command
Laine Stump [Fri, 30 Mar 2012 07:16:23 +0000 (03:16 -0400)]
qemu: set default name for SPICE agent channel when generating command

commit b0e2bb33 set a default value for the SPICE agent channel by
inserting it during parsing of the channel XML. That method of setting
a default is problematic because it makes a format/parse roundtrip
unclean, and experience with setting other values as a side effect of
parsing has led to headaches (e.g. automatically setting a MAC address
in the parser when one isn't specified in the input XML).

This patch does not revert commit b0e2bb33 (it will be reverted in a
separate patch) but adds the alternate implementation of simply
inserting the default value in the appropriate place on the qemu
commandline when no value is provided.

13 years agoqemu_agent: Issue guest-sync prior to every command
Michal Privoznik [Wed, 1 Feb 2012 14:44:53 +0000 (15:44 +0100)]
qemu_agent: Issue guest-sync prior to every command

If we issue guest command and GA is not running, the issuing thread
will block endlessly. We can check for GA presence by issuing
guest-sync with unique ID (timestamp). We don't want to issue real
command as even if GA is not running, once it is started, it process
all commands written to GA socket.

13 years agovirnetdevtap: Don't check for flags in virNetDevTapCreateFlags
Michal Privoznik [Fri, 30 Mar 2012 11:37:13 +0000 (13:37 +0200)]
virnetdevtap: Don't check for flags in virNetDevTapCreateFlags

With latest gnulib we are checking even the lowest level functions
whether they check flags. Moreover, we are shadowing the real error
on system without TUNSETIFF support.

13 years agoFix typo in previous patch
Daniel P. Berrange [Fri, 30 Mar 2012 11:44:28 +0000 (12:44 +0100)]
Fix typo in previous patch

* src/remote/remote_driver.c: s/sizeof(ret)2/sizeof(ret2)/

13 years agoConsistent style for usage of sizeof operator
Daniel P. Berrange [Thu, 29 Mar 2012 09:52:04 +0000 (10:52 +0100)]
Consistent style for usage of sizeof operator

The code is splattered with a mix of

  sizeof foo
  sizeof (foo)
  sizeof(foo)

Standardize on sizeof(foo) and add a syntax check rule to
enforce it

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoDisable build of commandhelper & ssh on Win32
Daniel P. Berrange [Thu, 29 Mar 2012 09:50:00 +0000 (10:50 +0100)]
Disable build of commandhelper & ssh on Win32

The commandhelper.c & ssh.c programs rely on various APIs not present
on Win32. Disable them, since the tests that uses these helpers are
already disabled

* tests/commandhelper.c, tests/ssh.c: Disable on WIN32

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoDon't redefine the CPU comparison constants in CPU test
Daniel P. Berrange [Thu, 29 Mar 2012 09:47:07 +0000 (10:47 +0100)]
Don't redefine the CPU comparison constants in CPU test

Defining an enum with names like "ERROR" causes  a world of
hurt on Win32 whose headers have such symbol names already

* tests/cputest.c: Remove redefinition of CPU constants

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoFix some format specifiers for size_t vs ssize_t
Daniel P. Berrange [Thu, 29 Mar 2012 09:01:07 +0000 (10:01 +0100)]
Fix some format specifiers for size_t vs ssize_t

A handful of places used %zd for format specifiers even
though the args was size_t, not ssize_t.

* src/remote/remote_driver.c, src/util/xml.c: s/%zd/%zu/

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoconf: Prevent crash of libvirtd without channel target name
Alex Jia [Fri, 30 Mar 2012 09:10:31 +0000 (17:10 +0800)]
conf: Prevent crash of libvirtd without channel target name

* src/conf/domain_conf.c (virDomainChannelDefCheckABIStability): avoid
  crashing libvirtd due to derefing a NULL pointer.

For details, please see bug:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=808371

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agofix a deadlock when qemu cannot start
Wen Congyang [Fri, 30 Mar 2012 06:21:49 +0000 (14:21 +0800)]
fix a deadlock when qemu cannot start

When qemu cannot start, we may call qemuProcessStop() twice.
We have check whether the vm is running at the beginning of
qemuProcessStop() to avoid libvirt deadlock. We call
qemuProcessStop() with driver and vm locked. It seems that
we can avoid libvirt deadlock. But unfortunately we may
unlock driver and vm in the function qemuProcessKill() while
vm->def->id is not -1. So qemuProcessStop() will be run twice,
and monitor will be freed unexpectedly. So we should set
vm->def->id to -1 at the beginning of qemuProcessStop().

13 years agobuild: silence recent syntax check violations
Eric Blake [Fri, 30 Mar 2012 03:17:30 +0000 (21:17 -0600)]
build: silence recent syntax check violations

An upstream gnulib bug[1] meant that some of our syntax checks
weren't being run.  Fix up our offenders before we upgrade to
a newer gnulib.

[1] https://lists.gnu.org/archive/html/bug-gnulib/2012-03/msg00194.html

* src/util/virnetdevtap.c (virNetDevTapCreate): Use flags.
* tests/lxcxml2xmltest.c (mymain): Strip useless ().

13 years agobuild: avoid 'devname' for BSD
Eric Blake [Thu, 29 Mar 2012 23:08:27 +0000 (17:08 -0600)]
build: avoid 'devname' for BSD

Commit 21b5daa1 was the last time we cleaned this up.

* tools/virt-host-validate-common.c (virHostValidateDevice):
Rename local variable.

13 years agoprivate.syms: Add virNetDevMacVLanRestartWithVPortProfile
Zhou Peng [Thu, 29 Mar 2012 12:55:04 +0000 (20:55 +0800)]
private.syms: Add virNetDevMacVLanRestartWithVPortProfile

virNetDevMacVLanRestartWithVPortProfile is omitted in src/libvirt_private.syms,
which causes link err.

13 years agoqemu: Make migration fail when port profile association fails on the dst host
Christian Benvenuti [Tue, 27 Mar 2012 20:00:01 +0000 (13:00 -0700)]
qemu: Make migration fail when port profile association fails on the dst host

In the current V3 migration protocol, Libvirt does not
check the result of the function

  qemuMigrationVPAssociatePortProfiles

This means that it is possible for a migration to complete
successfully even when the VM loses network connectivity on
the destination host.

With this change libvirt aborts the migration
(during the "finish" step) when the above function fails, that
is to say when at least one of the port profile associations fails.

Signed-off by: Christian Benvenuti <benve@cisco.com>

13 years agoSet default name for SPICE agent channel
Christophe Fergeau [Fri, 23 Mar 2012 10:04:13 +0000 (11:04 +0100)]
Set default name for SPICE agent channel

libvirt documentation for channels with type 'spicevmc' says that the
'target' child node has:
"an optional attribute name controls how the guest will have access
 to the channel, and defaults to name='com.redhat.spice.0'."

However, this default value is never set in libvirt code base,
there's only a check in qemu_command.c to error out if the name
attribute doesn't have the expected value (if it's set).

This commit sets a default target name for spicevmc channels during
the domain configuration parsing so that the code agrees with the
documentation.

13 years agovirsh: plug memory leaks on failure path
Alex Jia [Wed, 28 Mar 2012 08:15:49 +0000 (16:15 +0800)]
virsh: plug memory leaks on failure path

Leaks are introduced in commit 1cf0e3d and fe383bb.

Fixing memory leaks, in addition, the patch also fixes a potential missing
return value issue in 'if (from)' statement, without the fixing, although
the programming met a error, the subsequent codes will be executed
continually.

* tools/virsh.c (cmdSnapshotList): fix memory leaks and missing return value.

* How to reproduce?

% virsh snapshot-list <domain> --parent --roots
% virsh snapshot-list <domain> --parent --tree
% virsh snapshot-list <domain> --roots --tree

actual result:
error: --parent and --roots are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

error: --parent and --tree are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

error: --roots and --tree are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

% virsh snapshot-create-as <domain> --name "hello"
% virsh snapshot-create-as <domain> --name "libvirt"
% virsh snapshot-list <domain> --roots --from "hello"

actual result:
error: --roots and --from are mutually exclusive
 Name                 Creation Time             State
------------------------------------------------------------
 libvirt              2012-03-28 13:46:51 +0800 running

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agopython: make python APIs use these helper functions
Guannan Ren [Tue, 27 Mar 2012 06:06:47 +0000 (14:06 +0800)]
python: make python APIs use these helper functions

    *setPyVirTypedParameter
    *libvirt_virDomainGetCPUStats

13 years agopython: Add new helper functions for python to C integral conversion
Guannan Ren [Tue, 27 Mar 2012 06:06:10 +0000 (14:06 +0800)]
python: Add new helper functions for python to C integral conversion

    int libvirt_intUnwrap(PyObject *obj, int *val);
    int libvirt_uintUnwrap(PyObject *obj, unsigned int *val);
    int libvirt_longUnwrap(PyObject *obj, long *val);
    int libvirt_ulongUnwrap(PyObject *obj, unsigned long *val);
    int libvirt_longlongUnwrap(PyObject *obj, long long *val);
    int libvirt_ulonglongUnwrap(PyObject *obj, unsigned long long *val);
    int libvirt_doubleUnwrap(PyObject *obj, double *val);
    int libvirt_boolUnwrap(PyObject *obj, bool *val);

13 years agosnapshot: fix virsh docs
Eric Blake [Wed, 28 Mar 2012 02:22:49 +0000 (20:22 -0600)]
snapshot: fix virsh docs

Commit d42a2ff forgot to touch up virsh documentation, and commit
4e9953a mis-spelled the option name.

* tools/virsh.pod (snapshot-create, snapshot-create-as): Fix typo
and match recent change in flag meaning.

13 years agoEnable all warnings permanently & default to -Werror for GIT builds
Daniel P. Berrange [Tue, 27 Mar 2012 15:47:11 +0000 (16:47 +0100)]
Enable all warnings permanently & default to -Werror for GIT builds

Given that we auto-detect whether each -Wxxxx flag is supported by
GCC, and we are warning-free and use automake silent rules, there
is no compelling reason to allow compile warnings to be disabled.

Replace the --enable-compile-warnings flag with a simpler
--enable-werror flag, which defaults to 'yes' if building
from GIT, or 'no' if building from tar.gz

This helps ensure that everyone writing patches for libvirt will
take care to fix their warning problems before submitting for
review

* autobuild.sh: Force -Werror
* configure.ac: Update for LIBVIRT_COMPILE_WARNINGS macro change
* m4/virt-compile-warnings.m4: Permanently enable all warnings,
  auto-enable Werror for GIT builds

13 years agoEnable build of test suite programs by default for GIT checkouts
Daniel P. Berrange [Tue, 27 Mar 2012 15:35:01 +0000 (16:35 +0100)]
Enable build of test suite programs by default for GIT checkouts

Add a new flag '--with-test-suite' to configure to control whether
the test suite binaries are built by default. ie built with a
plain 'make', as opposed to delayed until 'make check'

For builds from tar.gz tests will not be built by default. For
builds from GIT, tests with be on by default, to try and ensure
that patch developers don't accidentally break the test suites
without noticing.

* configure.ac: Add --with-test-suite
* tests/Makefile.am: Use noinst_PROGRAMS instead of check_PROGRAMS
  if building tests by default. Consolidate setting of TESTS and
  {noinst,check}_PROGRAMS to avoid duplication

13 years agoChange the default of mdns_adv to false
Stef Walter [Tue, 27 Mar 2012 14:20:54 +0000 (16:20 +0200)]
Change the default of mdns_adv to false

 * Don't advertise information on the network without consent of
   the user, either through manual configuration, or a user
   interface that drives this option.
 * Since libvirtd must be configured for network access anyway
   (for all but ssh), this setting was not useful "out of the box",
   so changing this default setting does not remove "out of the box"
   functionality.

13 years agosnapshot: don't pass NULL to QMP command creation
Eric Blake [Tue, 27 Mar 2012 14:33:23 +0000 (08:33 -0600)]
snapshot: don't pass NULL to QMP command creation

Commit d42a2ff caused a regression in creating a disk-only snapshot
of a qcow2 disk; by passing the wrong variable to the monitor call,
libvirt ended up creating JSON that looked like "format":null instead
of the intended "format":"qcow2".

To make it easier to diagnose this in the future, make JSON creation
error out if "s:arg" is paired with NULL (it is still possible to
use "n:arg" in the rare cases where qemu will accept a null).

* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Pass correct value.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMakeCommandRaw):
Improve error message.

13 years agoAdd LXC XML files to schema test & fix problems this uncovers
Daniel P. Berrange [Mon, 26 Mar 2012 17:11:09 +0000 (18:11 +0100)]
Add LXC XML files to schema test & fix problems this uncovers

* docs/schemas/domaincommon.rng: Add missing lxc & openvz
  console target types. Allow arch on LXC <os> type element
* tests/domainschematest: Include tests/lxcxml2xmldata/

13 years agoAdd support for setting init argv for LXC
Daniel P. Berrange [Mon, 26 Mar 2012 17:09:31 +0000 (18:09 +0100)]
Add support for setting init argv for LXC

Pass argv to the init binary of LXC, using a new <initarg> element.

* docs/formatdomain.html.in: Document <os> usage for containers
* docs/schemas/domaincommon.rng: Add <initarg> element
* src/conf/domain_conf.c, src/conf/domain_conf.h: parsing and
  formatting of <initarg>
* src/lxc/lxc_container.c: Setup LXC argv
* tests/Makefile.am, tests/lxcxml2xmldata/lxc-systemd.xml,
  tests/lxcxml2xmltest.c, tests/testutilslxc.c,
  tests/testutilslxc.h: Test parsing/formatting of LXC related
  XML parts

13 years agoDetect location fo selinux mount point
Daniel P. Berrange [Mon, 26 Mar 2012 15:39:30 +0000 (16:39 +0100)]
Detect location fo selinux mount point

The SELinux mount point moved from /selinux to /sys/fs/selinux
when systemd came along.

* configure.ac: Probe for SELinux mount point
* src/lxc/lxc_container.c: Use SELinux mount point determined
  by configure.ac

13 years agoExpand docs for timer tick policy
Daniel P. Berrange [Mon, 26 Mar 2012 12:29:41 +0000 (13:29 +0100)]
Expand docs for timer tick policy

13 years agoqemu,util: on restart of libvirt restart vepa callbacks
D. Herrendoerfer [Tue, 27 Mar 2012 12:38:33 +0000 (14:38 +0200)]
qemu,util: on restart of libvirt restart vepa callbacks

When libvirtd is restarted, also restart the netlink event
message callbacks for existing VEPA connections and send
a message to lldpad for these existing links, so it learns
the new libvirtd pid.

Signed-off-by: D. Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
13 years agoqemu: Avoid entering monitor with locked driver
Jiri Denemark [Tue, 27 Mar 2012 11:32:43 +0000 (13:32 +0200)]
qemu: Avoid entering monitor with locked driver

This avoids possible deadlock of the qemu driver in case a domain is
begin migrated (in Begin phase) and unrelated connection to qemu driver
is closed at the right time.

I checked all callers of qemuDomainCheckEjectableMedia() and they are
calling this function with qemu driver locked.

13 years agobuild: fix "missing initializer" error in qemu_process.c
Laine Stump [Mon, 26 Mar 2012 16:39:03 +0000 (12:39 -0400)]
build: fix "missing initializer" error in qemu_process.c

Found when attempting to build on Fedora 17 alpha with:

   ./autogen.sh --system --enable-compile-warnings=error

(this same build command works without problem on Fedora 16). Since
the consumer of the qemuProcessReconnectData doesn't assume that the
other fields of the struct are initialized (although it uses them
internally), the simpler solution is to just switch to C99-style
struct initialization (which doesn't require specification of all
fields).

13 years agobuild: fix "missing initializer" errors in virsh.c
Laine Stump [Mon, 26 Mar 2012 16:58:05 +0000 (12:58 -0400)]
build: fix "missing initializer" errors in virsh.c

Found when attempting to build on Fedora 17 alpha with:

   ./autogen.sh --system --enable-compile-warnings=error

(this same build command works without problem on Fedora 16). All
other struct initializers for this struct have the extra field filled
in (almost always to 0), so the two errant ones were fixed by adding
in the extra 0 field.

13 years agobuild: avoid frame size error when building without -O2
Laine Stump [Mon, 26 Mar 2012 18:42:22 +0000 (14:42 -0400)]
build: avoid frame size error when building without -O2

libvirt always adds -Werror-frame-larger-than=4096 to the flags when
it builds. When building on Fedora 17, two functions with multiple
1024 buffers declared inside if {} blocks would generate frame size
errors; apparently the version of gcc on Fedora 16 will merge these
multiple buffers into a single buffer even when optimization is off,
but Fedora 17 won't.

The fix is to declare a single 1024 buffer at the top of the two
offending functions, and reuse the single buffer throughout the
functions.

13 years agoAdded syntax-check rule for return with parentheses
Martin Kletzander [Fri, 23 Mar 2012 07:34:09 +0000 (08:34 +0100)]
Added syntax-check rule for return with parentheses

After cleanup introduced with previous commit, there is a need for
syntax-check rule taking care of return(). Regexp used in 'prohibit'
parameter is taken from the cleanup commit and modified so it fits
'grep -E' format. Semicolon at the end is needed, otherwise the regexp
could match return with cast.

Exception is created for python source files because we don't have any
documentation restricting the use of return that matches this case.

13 years agoCleanup for a return statement in source files
Martin Kletzander [Thu, 22 Mar 2012 11:33:35 +0000 (12:33 +0100)]
Cleanup for a return statement in source files

Return statements with parameter enclosed in parentheses were modified
and parentheses were removed. The whole change was scripted, here is how:

List of files was obtained using this command:
git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
grep -e '\.[ch]$' -e '\.py$'

Found files were modified with this command:
sed -i -e                                                                 \
's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
-e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'

Then checked for nonsense.

The whole command looks like this:
git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
grep -e '\.[ch]$' -e '\.py$' | xargs sed -i -e                            \
's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
-e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'

13 years agoFix and test round-trip of query parameters
Eric Blake [Mon, 26 Mar 2012 10:23:45 +0000 (11:23 +0100)]
Fix and test round-trip of query parameters

When qparams support was dropped in commit bc1ff160, we forgot
to add tests to ensure that viruri can do the same round trip
handling of a URI. This round trip was broken, due to use
of the old 'query' field of xmlUriPtr, instead of the new
'query_raw'

Also, we forgot to report an OOM error.

* tests/viruritest.c (mymain): Add tests based on just-deleted
qparamtest.
(testURIParse): Allow difference in input and expected output.
* src/util/viruri.c (virURIFormat): Add missing error. Use
  query_raw, instead of query for xmlUriPtr object.

13 years agospec: Add missed dependancy for numad
Osier Yang [Sat, 24 Mar 2012 01:35:20 +0000 (09:35 +0800)]
spec: Add missed dependancy for numad

numad is available since Fedora 17 and RHEL6.X. And it's not supported
on s390[x] and ARM.

13 years agosnapshot: improve qemu handling of reused snapshot targets
Eric Blake [Tue, 20 Mar 2012 21:03:45 +0000 (15:03 -0600)]
snapshot: improve qemu handling of reused snapshot targets

The oVirt developers have stated that the real reasons they want
to have qemu reuse existing volumes when creating a snapshot are:
1. the management framework is set up so that creation has to be
done from a central node for proper resource tracking, and having
libvirt and/or qemu create things violates the framework, and
2. qemu defaults to creating snapshots with an absolute path to
the backing file, but oVirt wants to manage a backing chain that
uses just relative names, to allow for easier migration of a chain
across storage locations.

When 0.9.10 added VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT (commit
4e9953a4), it only addressed point 1, but libvirt was still using
O_TRUNC which violates point 2.  Meanwhile, the new qemu
'transaction' monitor command includes a new optional mode argument
that will force qemu to reuse the metadata of the file it just
opened (with the burden on the caller to have valid metadata there
in the first place).  So, this tweaks the meaning of the flag to
cover both points as intended for use by oVirt.  It is not strictly
backward-compatible to 0.9.10 behavior, but it can be argued that
the O_TRUNC of 0.9.10 was a bug.

Note that this flag is all-or-nothing, and only selects between
'existing' and the default 'absolute-paths'.  A more flexible
approach that would allow per-disk selections, as well as adding
support for the 'no-backing-file' mode, would be possible by
extending the <domainsnapshot> xml to have a per-disk mode, but
until we have a management application expressing a need for that
additional complexity, it is not worth doing.

* src/libvirt.c (virDomainSnapshotCreateXML): Tweak documentation.
* src/qemu/qemu_monitor.h (qemuMonitorDiskSnapshot): Add
parameters.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskSnapshot): Pass them
through.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot): Use
new monitor command arguments.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): Adjust callers.
(qemuDomainSnapshotDiskPrepare): Allow qed, modify rules on reuse.

13 years agosnapshot: wire up qemu transaction command
Eric Blake [Sat, 17 Mar 2012 20:16:25 +0000 (14:16 -0600)]
snapshot: wire up qemu transaction command

The hardest part about adding transactions is not using the new
monitor command, but undoing the partial changes we made prior
to a failed transaction.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive): Use
transaction when available.
(qemuDomainSnapshotUndoSingleDiskActive): New function.
(qemuDomainSnapshotCreateSingleDiskActive): Pass through actions.
(qemuDomainSnapshotCreateXML): Adjust caller.

13 years agosnapshot: add support for qemu transaction command
Eric Blake [Sat, 17 Mar 2012 04:17:28 +0000 (22:17 -0600)]
snapshot: add support for qemu transaction command

QEmu 1.1 is adding a 'transaction' command to the JSON monitor.
Each element of a transaction corresponds to a top-level command,
with the additional guarantee that the transaction flushes all
pending I/O, then guarantees that all actions will be successful
as a group or that failure will roll back the state to what it
was before the monitor command.  The difference between a
top-level command:

{ "execute": "blockdev-snapshot-sync", "arguments":
  { "device": "virtio0", ... } }

and a transaction:

{ "execute": "transaction", "arguments":
  { "actions": [
    { "type": "blockdev-snapshot-sync", "data":
      { "device": "virtio0", ... } } ] } }

is just a couple of changed key names and nesting the shorter
command inside a JSON array to the longer command.  This patch
just adds the framework; the next patch will actually use a
transaction.

* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMakeCommand): Move
guts...
(qemuMonitorJSONMakeCommandRaw): ...into new helper.  Add support
for array element.
(qemuMonitorJSONTransaction): New command.
(qemuMonitorJSONDiskSnapshot): Support use in a transaction.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskSnapshot): Add
argument.
(qemuMonitorJSONTransaction): New declaration.
* src/qemu/qemu_monitor.h (qemuMonitorTransaction): Likewise.
(qemuMonitorDiskSnapshot): Add argument.
* src/qemu/qemu_monitor.c (qemuMonitorTransaction): New wrapper.
(qemuMonitorDiskSnapshot): Pass argument on.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Update caller.

13 years agosnapshot: rudimentary qemu support for atomic disk snapshot
Eric Blake [Fri, 16 Mar 2012 21:17:13 +0000 (15:17 -0600)]
snapshot: rudimentary qemu support for atomic disk snapshot

Taking an external snapshot of just one disk is atomic, without having
to pause and resume the VM.  This also paves the way for later patches
to interact with the new qemu 'transaction' monitor command.

The various scenarios when requesting atomic are:
online, 1 disk, old qemu - safe, allowed by this patch
online, more than 1 disk, old qemu - failure, this patch
offline snapshot - safe, once a future patch implements offline disk snapshot
online, 1 or more disks, new qemu - safe, once future patch uses transaction

Taking an online system checkpoint snapshot is atomic, since it is
done via a single 'savevm' monitor command.  Taking an offline system
checkpoint snapshot is atomic, thanks to the previous patch.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Support
new flag for single-disk setups.
(qemuDomainSnapshotDiskPrepare): Check for atomic here.
(qemuDomainSnapshotCreateDiskActive): Skip pausing the VM when
atomic supported.
(qemuDomainSnapshotIsAllowed): Use bool instead of int.

13 years agosnapshot: make offline qemu snapshots atomic
Eric Blake [Sat, 17 Mar 2012 15:54:44 +0000 (09:54 -0600)]
snapshot: make offline qemu snapshots atomic

Offline internal snapshots can be rolled back with just a little
bit of refactoring, meaning that we are now automatically atomic.

* src/qemu/qemu_domain.c (qemuDomainSnapshotForEachQcow2): Move
guts...
(qemuDomainSnapshotForEachQcow2Raw): ...to new helper, to allow
rollbacks.

13 years agosnapshot: add atomic create flag
Eric Blake [Fri, 16 Mar 2012 21:23:00 +0000 (15:23 -0600)]
snapshot: add atomic create flag

Right now, it is appallingly easy to cause qemu disk snapshots
to alter a domain then fail; for example, by requesting a two-disk
snapshot where the second disk name resides on read-only storage.
In this failure scenario, libvirt reports failure, but modifies
the live domain XML in-place to record that the first disk snapshot
was taken; and places a difficult burden on the management app
to grab the XML and reparse it to see which disks, if any, were
altered by the partial snapshot.

This patch adds a new flag where implementations can request that
the hypervisor make snapshots atomically; either no changes to
XML occur, or all disks were altered as a group.  If you request
the flag, you either get outright failure up front, or you take
advantage of hypervisor abilities to make an atomic snapshot. Of
course, drivers should prefer the atomic means even without the
flag explicitly requested.

There's no way to make snapshots 100% bulletproof - even if the
hypervisor does it perfectly atomic, we could run out of memory
during the followup tasks of updating our in-memory XML, and report
a failure.  However, these sorts of catastrophic failures are rare
and unlikely, and it is still nicer to know that either all
snapshots happened or none of them, as that is an easier state to
recover from.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC): New flag.
* src/libvirt.c (virDomainSnapshotCreateXML): Document it.
* tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Expose it.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
it.

13 years agosnapshot: add qemu capability for 'transaction' command
Eric Blake [Wed, 14 Mar 2012 22:29:21 +0000 (16:29 -0600)]
snapshot: add qemu capability for 'transaction' command

We need a capability bit to gracefully error out if some of the
additions in future patches can't be implemented by the running qemu.

* src/qemu/qemu_capabilities.h (QEMU_CAPS_TRANSACTION): New cap.
* src/qemu/qemu_capabilities.c (qemuCaps): Name it.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
it.

13 years agobuild: drop obsolete qparams test
Eric Blake [Fri, 23 Mar 2012 22:04:18 +0000 (16:04 -0600)]
build: drop obsolete qparams test

Otherwise, 'make check' breaks since commit bc1ff160 deleted
qparams.h.  A later patch will ensure that viruri takes over
what qparams used to do.

* tests/qparamtest.c (mymain): Delete, now that we have viruri.
* tests/Makefile.am (check_PROGRAMS, TESTS, qparamtest_SOURCES):
Delete old test.
* .gitignore: Add recent test additions.

13 years agobuild: fix incorrect enum declaration
Eric Blake [Fri, 23 Mar 2012 20:23:43 +0000 (14:23 -0600)]
build: fix incorrect enum declaration

Recent changes have caused build failures on systems where pdwtags works:
commit a26a196 mistakenly exported a public variable
commits a26a19657ddcc2487c063 all had copy-paste bugs in
hand-updating the golden API rather than rerunning pdwtags

* include/libvirt/libvirt.h.in (virDomainEventTrayChangeReason):
Make this a typedef, not external storage.
* src/remote_protocol-structs (remote_procedure): Fix spelling.

13 years agoAdd qemu support for ppc64 on FC16 or above for rpm packaging
Li Zhang [Fri, 23 Mar 2012 04:29:00 +0000 (12:29 +0800)]
Add qemu support for ppc64 on FC16 or above for rpm packaging

On Fedora16 or above, qemu is supported now. So it is added
in rpm packaging.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
13 years agoFix typo s/virURIFormatQuery/virURIFormatParams/
Daniel P. Berrange [Fri, 23 Mar 2012 14:27:03 +0000 (14:27 +0000)]
Fix typo s/virURIFormatQuery/virURIFormatParams/

13 years agoqemu: Update domain status to running while wakeup event is emitted
Osier Yang [Wed, 14 Mar 2012 15:26:55 +0000 (23:26 +0800)]
qemu: Update domain status to running while wakeup event is emitted

This introduces a new running reason VIR_DOMAIN_RUNNING_WAKEUP,
and new suspend event type VIR_DOMAIN_EVENT_STARTED_WAKEUP.

While a wakeup event is emitted, the domain which entered into
VIR_DOMAIN_PMSUSPENDED will be transferred to "running"
with reason VIR_DOMAIN_RUNNING_WAKEUP, and a new domain lifecycle
event emitted with type VIR_DOMAIN_EVENT_STARTED_WAKEUP.

13 years agoqemu: Update domain state to pmsuspended while suspend event occurs
Osier Yang [Wed, 14 Mar 2012 15:26:54 +0000 (23:26 +0800)]
qemu: Update domain state to pmsuspended while suspend event occurs

13 years agoNew domain state pmsuspended
Osier Yang [Wed, 14 Mar 2012 15:26:53 +0000 (23:26 +0800)]
New domain state pmsuspended

This introduces a new domain state pmsuspended to represent
the domain which has been suspended by guest power management,
e.g. (entered itno s3 state). Because a "running" state could
be confused in this case, one will see the guest is paused
actually while playing. And state "paused" is for the domain
which was paused by virDomainSuspend.

13 years agoAdd support for the suspend event
Osier Yang [Fri, 23 Mar 2012 14:50:36 +0000 (22:50 +0800)]
Add support for the suspend event

This patch introduces a new event type for the QMP event
SUSPEND:

    VIR_DOMAIN_EVENT_ID_PMSUSPEND

The event doesn't take any data, but considering there might
be reason for wakeup in future, the callback definition is:

typedef void
(*virConnectDomainEventSuspendCallback)(virConnectPtr conn,
                                        virDomainPtr dom,
                                        int reason,
                                        void *opaque);

"reason" is unused currently, always passes "0".

13 years agoAdd support for the wakeup event
Osier Yang [Fri, 23 Mar 2012 14:43:14 +0000 (22:43 +0800)]
Add support for the wakeup event

This patch introduces a new event type for the QMP event
WAKEUP:

    VIR_DOMAIN_EVENT_ID_PMWAKEUP

The event doesn't take any data, but considering there might
be reason for wakeup in future, the callback definition is:

typedef void
(*virConnectDomainEventWakeupCallback)(virConnectPtr conn,
                                       virDomainPtr dom,
                                       int reason,
                                       void *opaque);

"reason" is unused currently, always passes "0".

13 years agoqemu: Update tray status while tray moved event is emitted
Osier Yang [Wed, 14 Mar 2012 15:26:50 +0000 (23:26 +0800)]
qemu: Update tray status while tray moved event is emitted

With this patch, libvirt won't start the guest with the medium
source which already ejected by guest when doing migration, or
saving/restoring.

13 years agoqemu: Prohibit setting tray status as open for block type disk
Osier Yang [Wed, 14 Mar 2012 15:26:49 +0000 (23:26 +0800)]
qemu: Prohibit setting tray status as open for block type disk

13 years agoqemu: Do not start with source for removable disks if tray is open
Osier Yang [Wed, 14 Mar 2012 15:26:48 +0000 (23:26 +0800)]
qemu: Do not start with source for removable disks if tray is open

This is similiar with physical world, one will be surprised if the
box starts with medium exists while the tray is open.

New tests are added, tests disk-{cdrom,floppy}-tray are for the qemu
supports "-device" flag, and disk-{cdrom,floppy}-no-device-cap are
for old qemu, i.e. which doesn't support "-device" flag.

13 years agoconf: Parse and for the tray attribute
Osier Yang [Fri, 23 Mar 2012 14:21:09 +0000 (22:21 +0800)]
conf: Parse and for the tray attribute

The "tray" is only allowed for removable disks, i.e. CDROM and
Floppy disks.

13 years agodocs: Add documentation for new attribute tray of disk target
Osier Yang [Wed, 14 Mar 2012 15:26:46 +0000 (23:26 +0800)]
docs: Add documentation for new attribute tray of disk target

Example XML:

    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/cdrom.img'/>
      <target dev='hdd' bus='ide' tray='open'/>
    </disk>

13 years agoAdd support for event tray moved of removable disks
Osier Yang [Fri, 23 Mar 2012 13:44:50 +0000 (21:44 +0800)]
Add support for event tray moved of removable disks

This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

    VIR_DOMAIN_EVENT_ID_TRAY_CHANGE

The event's data includes the device alias and the reason
for tray status' changing, which indicates why the tray
status was changed. Thus the callback definition for the event
is:

enum {
    VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN = 0,
    VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE,

\#ifdef VIR_ENUM_SENTINELS
    VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
\#endif
} virDomainEventTrayChangeReason;

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

13 years agoImplement sysinfo on PowerPC.
Prerna Saxena [Thu, 15 Mar 2012 10:35:26 +0000 (16:05 +0530)]
Implement sysinfo on PowerPC.

Libvirt on x86 parses 'dmidecode' to gather characteristics of host
system. On PowerPC, this is now implemented by reading /proc/cpuinfo
NOTE: memory-DIMM information is not presently implemented.

Acked-by: Daniel Veillard <veillard@redhat.com>
Acked-by: Daniel P Berrange <berrange@redhat.com>
Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
13 years agoLookup auth credentials in config file before prompting
Daniel P. Berrange [Tue, 20 Mar 2012 11:11:10 +0000 (11:11 +0000)]
Lookup auth credentials in config file before prompting

When SASL requests auth credentials, try to look them up in the
config file first. If any are found, remove them from the list
that the user is prompted for

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoRefactor code prompting for SASL credentials
Daniel P. Berrange [Mon, 19 Mar 2012 17:26:21 +0000 (17:26 +0000)]
Refactor code prompting for SASL credentials

SASL may prompt for credentials after either a 'start' or 'step'
invocation. In both cases the code to handle this is the same.
Refactor this code into a separate method to reduce the duplication,
since the complexity is about to grow

* src/remote/remote_driver.c: Refactor interaction with SASL

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoAdd helper API for finding auth file path
Daniel P. Berrange [Tue, 20 Mar 2012 15:40:05 +0000 (15:40 +0000)]
Add helper API for finding auth file path

* src/util/virauth.c, src/util/virauth.h: Add virAuthGetConfigFilePath
* include/libvirt/virterror.h, src/util/virterror.c: Add
  VIR_FROM_AUTH error domain

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoRename virRequest{Username,Password} to virAuthGet{Username,Password}
Daniel P. Berrange [Mon, 19 Mar 2012 16:23:47 +0000 (16:23 +0000)]
Rename virRequest{Username,Password} to virAuthGet{Username,Password}

Ensure that the functions in virauth.h have names matching the file
prefix, by renaming  virRequest{Username,Password} to
virAuthGet{Username,Password}

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoRename src/util/authhelper.[ch] to src/util/virauth.[ch]
Daniel P. Berrange [Mon, 19 Mar 2012 16:21:12 +0000 (16:21 +0000)]
Rename src/util/authhelper.[ch] to src/util/virauth.[ch]

To follow latest naming conventions, rename src/util/authhelper.[ch]
to src/util/virauth.[ch].

* src/util/authhelper.[ch]: Rename to src/util/virauth.[ch]
* src/esx/esx_driver.c, src/hyperv/hyperv_driver.c,
  src/phyp/phyp_driver.c, src/xenapi/xenapi_driver.c: Update
  for renamed include files

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoAdd a virKeyfilePtr object for parsing '.ini' files
Daniel P. Berrange [Fri, 16 Mar 2012 16:29:49 +0000 (16:29 +0000)]
Add a virKeyfilePtr object for parsing '.ini' files

The '.ini' file format is a useful alternative to the existing
config file style, when you need to have config files which
are hashes of hashes. The 'virKeyFilePtr' object provides a
way to parse these file types.

* src/Makefile.am, src/util/virkeyfile.c,
  src/util/virkeyfile.h: Add .ini file parser
* tests/Makefile.am, tests/virkeyfiletest.c: Test
  basic parsing capabilities

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoConvert drivers over to use virURIPtr for query params
Daniel P. Berrange [Tue, 20 Mar 2012 14:11:10 +0000 (14:11 +0000)]
Convert drivers over to use virURIPtr for query params

Convert drivers currently using the qparams APIs, to instead
use the virURIPtr query parameters directly.

* src/esx/esx_util.c, src/hyperv/hyperv_util.c,
  src/remote/remote_driver.c, src/xenapi/xenapi_utils.c: Remove
  use of qparams
* src/util/qparams.h, src/util/qparams.c: Delete
* src/Makefile.am, src/libvirt_private.syms: Remove qparams

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoStore parsed query parameters directly in the virURIPtr struct
Daniel P. Berrange [Tue, 20 Mar 2012 13:59:32 +0000 (13:59 +0000)]
Store parsed query parameters directly in the virURIPtr struct

Avoid the need for each driver to parse query parameters itself
by storing them directly in the virURIPtr struct. The parsing
code is a copy of that from src/util/qparams.c  The latter will
be removed in a later patch

* src/util/viruri.h: Add query params to virURIPtr
* src/util/viruri.c: Parse query parameters when creating virURIPtr
* tests/viruritest.c: Expand test to cover params

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoUse a libvirt custom struct for virURIPtr
Daniel P. Berrange [Tue, 20 Mar 2012 13:33:41 +0000 (13:33 +0000)]
Use a libvirt custom struct for virURIPtr

Instead of just typedef'ing the xmlURIPtr struct for virURIPtr,
use a custom libvirt struct. This allows us to fix various
problems with libxml2. This initially just fixes the query vs
query_raw handling problems.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoCentralize error reporting for URI parsing/formatting problems
Daniel P. Berrange [Tue, 20 Mar 2012 12:16:54 +0000 (12:16 +0000)]
Centralize error reporting for URI parsing/formatting problems

Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.

* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
  src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
  src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
  src/remote/remote_driver.c, src/uml/uml_driver.c,
  src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
  src/xen/xend_internal.c, tests/viruritest.c: Remove error
  reporting

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agos/xmlURIPtr/virURIPtr/ in virURIFormat impl
Daniel P. Berrange [Tue, 20 Mar 2012 13:37:55 +0000 (13:37 +0000)]
s/xmlURIPtr/virURIPtr/ in virURIFormat impl

The parameter in the virURIFormat impl mistakenly used the
xmlURIPtr type, instead of virURIPtr. Since they will soon
cease to be identical, this needs fixing

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoUse virURIFree instead of xmlFreeURI
Daniel P. Berrange [Tue, 20 Mar 2012 11:59:42 +0000 (11:59 +0000)]
Use virURIFree instead of xmlFreeURI

Since we defined a custom virURIPtr type, we should use a
virURIFree method instead of assuming it will always be
a typedef for xmlURIPtr

* src/util/viruri.c, src/util/viruri.h, src/libvirt_private.syms:
  Add a virURIFree method
* src/datatypes.c, src/esx/esx_driver.c, src/libvirt.c,
  src/qemu/qemu_migration.c, src/vmx/vmx.c, src/xen/xend_internal.c,
  tests/viruritest.c: s/xmlFreeURI/virURIFree/

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoAdd test case for virURIPtr classs
Daniel P. Berrange [Tue, 20 Mar 2012 11:55:11 +0000 (11:55 +0000)]
Add test case for virURIPtr classs

To ensure we properly escape & unescape IPv6 numeric addresses,
add a test case

* tests/Makefile.am, tests/viruritest.c: URI parsing test

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoLeave all child processes running when stopping systemd service
Daniel P. Berrange [Thu, 22 Mar 2012 14:01:12 +0000 (14:01 +0000)]
Leave all child processes running when stopping systemd service

Currently the libvirt.service unit file for systemd does not
specify any kill mode. So systemd kills off every process
inside its cgroup. ie all dnsmasq processes, all virtual
machines. This obviously not what we want. Set KillMode=process
so that it only kills the top level process of libvirtd

* daemon/libvirtd.service.in: Add KillMode=process

Reported-By: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoClarify virsh freecell manpage entry
Dave Allan [Thu, 22 Mar 2012 20:49:07 +0000 (16:49 -0400)]
Clarify virsh freecell manpage entry

13 years agodocs: fix typo
Zhou Peng [Fri, 23 Mar 2012 02:40:09 +0000 (10:40 +0800)]
docs: fix typo

Bogus <code/>, and incorrect use of it's instead of its.

13 years agoClarify what documentation is being referenced
Dave Allan [Thu, 22 Mar 2012 02:07:51 +0000 (22:07 -0400)]
Clarify what documentation is being referenced

virsh.pod had several instances in which it referred to "the
documentation" which was a little puzzling to me since it is
documentation.  Reading the document from end to end makes it clear
that it means a specific URI which was noted previously in the text,
but I had never noticed those URIs in several years of referring to
the man page.  This patch adds those URIs to several additional places
in the text.

13 years agopython: add virDomainGetCPUStats python binding API
Guannan Ren [Tue, 20 Mar 2012 04:34:06 +0000 (12:34 +0800)]
python: add virDomainGetCPUStats python binding API

    dom.getCPUStats(True, 0)
      [{'cpu_time': 24699446159L, 'system_time': 10870000000L, 'user_time': 950000000L}]
    dom.getCPUStats(False, 0)
      [{'cpu_time': 8535292289L}, {'cpu_time': 1005395355L}, {'cpu_time': 9351766377L}, {'cpu_time': 5813545649L}]

    *generator.py Add a new naming rule
    *libvirt-override-api.xml The API function description
    *libvirt-override.c Implement it.

13 years agopython: Avoid memory leaks on libvirt_virNodeGetCPUStats
Alex Jia [Wed, 21 Mar 2012 16:25:22 +0000 (00:25 +0800)]
python: Avoid memory leaks on libvirt_virNodeGetCPUStats

Detected by valgrind. Leaks are introduced in commit 4955602.

* python/libvirt-override.c (libvirt_virNodeGetCPUStats): fix memory leaks
and improve codes return value.

For details, please see the following link:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770943

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agobuild: drop a painfully long gnulib test
Eric Blake [Tue, 20 Mar 2012 23:04:38 +0000 (17:04 -0600)]
build: drop a painfully long gnulib test

On machines with massive amounts of CPUs, the gnulib 'test-lock'
could take minutes, or even appear to deadlock, because of poor
scaling of timing interactions between multiple cores.

See https://bugzilla.redhat.com/show_bug.cgi?id=797284.
For precedence, note that iwhd has done the same:
https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00311.html

We can re-enable things if gnulib ever analyzes and improves the
situation.

* bootstrap.conf (gnulib_tool_option_extras): Avoid lock-tests.

13 years agoqemu: Avoid dangling migration-out job when client dies
Jiri Denemark [Mon, 19 Mar 2012 15:48:43 +0000 (16:48 +0100)]
qemu: Avoid dangling migration-out job when client dies

When a client which started non-p2p migration dies in a bad time, the
source libvirtd never clears the migration job and almost nothing can be
done with the domain without restarting the daemon. This patch makes use
of connection close callbacks and ensures that migration job is properly
discarded when the client disconnects.

13 years agoqemu: Make autodestroy utilize connection close callbacks
Jiri Denemark [Mon, 19 Mar 2012 13:31:41 +0000 (14:31 +0100)]
qemu: Make autodestroy utilize connection close callbacks

13 years agoqemu: Add connection close callbacks
Jiri Denemark [Mon, 19 Mar 2012 13:28:10 +0000 (14:28 +0100)]
qemu: Add connection close callbacks

Add support for registering arbitrary callback to be called for a domain
when a connection gets closed.

13 years agoqemu: Avoid dangling migration-in job on shutoff domains
Jiri Denemark [Fri, 16 Mar 2012 06:56:19 +0000 (07:56 +0100)]
qemu: Avoid dangling migration-in job on shutoff domains

Destination daemon should not rely on the client or source daemon
(depending on the type of migration) to call Finish when migration
fails, because the client may crash before it can do so. The domain
prepared for incoming migration is set to be destroyed (and migration
job cleaned up) when connection with the client closes but this is not
enough. If the associated qemu process crashes after Prepare step and
the domain is cleaned up before the connection gets closed, autodestroy
is not called for the domain and migration jobs remains set. In case the
domain is defined on destination host (i.e., it is not completely
removed once destroyed) we keep the job set for ever. To fix this, we
register a cleanup callback which is responsible to clean migration-in
job when a domain dies anywhere between Prepare and Finish steps. Note
that we can't blindly clean any job when spotting EOF on monitor since
normally an API is running at that time.

13 years agoqemu: Add support for domain cleanup callbacks
Jiri Denemark [Fri, 16 Mar 2012 06:52:26 +0000 (07:52 +0100)]
qemu: Add support for domain cleanup callbacks

Add support for registering cleanup callbacks to be run when a domain
transitions to shutoff state.

13 years agoqemu: Use unlimited speed when migrating to file
Jiri Denemark [Tue, 20 Mar 2012 15:56:29 +0000 (16:56 +0100)]
qemu: Use unlimited speed when migrating to file

This reverts commit 61f2b6ba5fdef0613d6351b99913b5ef468144ce and most of
commit d8916dc8e2f612ab3ce46f32c4bfeb0bd73f6007, which effectively
brings back commit ef1065cf5acad13767c054758cbe7f4e8af5d241 written by
Jim Fehlig:

The qemu migration speed default is 32MiB/s as defined in migration.c

/* Migration speed throttling */
static int64_t max_throttle = (32 << 20);

There's no need to throttle migration when targeting a file, so set
migration speed to unlimited prior to migration, and restore to libvirt
default value after migration.

Default units is MB for migrate_set_speed monitor command, so
(INT64_MAX / (1024 * 1024)) is used for unlimited migration speed.

This was reverted because migration to file could not be canceled and
even monitored since qemu was not processing any monitor commands until
the migration finished. This is now different as we make sure the
file descriptor we pass to qemu is able to properly report EAGAIN.
Recent qemu changes might have helped as well.

I tested managedsave with this patch in and indeed, it is 10x faster
while I can still monitor its progress.

13 years agopython: Avoid memory leaks on libvirt_virNodeGetMemoryStats
Alex Jia [Wed, 21 Mar 2012 15:30:03 +0000 (23:30 +0800)]
python: Avoid memory leaks on libvirt_virNodeGetMemoryStats

Detected by valgrind. Leaks are introduced in commit 17c7795.

* python/libvirt-override.c (libvirt_virNodeGetMemoryStats): fix memory leaks
and improve codes return value.

For details, please see the following link:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770944

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agopython: always include config.h first
Eric Blake [Tue, 20 Mar 2012 22:44:39 +0000 (16:44 -0600)]
python: always include config.h first

On RHEL 5.7, I got this compilation failure:

In file included from /usr/include/python2.4/pyport.h:98,
                 from /usr/include/python2.4/Python.h:55,
                 from libvirt.c:3:
../gnulib/lib/time.h:468: error: expected ';', ',' or ')' before '__timer'

Turns out that our '#define restrict __restrict' from config.h wasn't
being picked up.  Gnulib _requires_ that all .c files include <config.h>
first, otherwise the gnulib header overrides tend to misbehave.

Problem introduced by patch c700613b8.

* python/generator.py (buildStubs): Include <config.h> first.

13 years agoMinor docs fix
Martin Kletzander [Mon, 19 Mar 2012 21:52:29 +0000 (22:52 +0100)]
Minor docs fix

End tag for "host" element was missing in example configuration

13 years agoconf: forbid use of multicast mac addresses
Laine Stump [Mon, 19 Mar 2012 16:49:17 +0000 (12:49 -0400)]
conf: forbid use of multicast mac addresses

A few times libvirt users manually setting mac addresses have
complained of a networking failure that ends up being due to a multicast
mac address being used for a guest interface. This patch prevents that
by logging an error and failing if a multicast mac address is
encountered in each of the three following cases:

1) domain xml <interface> mac address.
2) network xml bridge mac address.
3) network xml dhcp/host mac address.

There are several other places where a mac address can be input that
aren't controlled in this manner because failure to do so has no
consequences (e.g., if the address will be used to search through
existing interfaces for a match).

The RNG has been updated to add multiMacAddr and uniMacAddr along with
the existing macAddr, and macAddr was switched to uniMacAddr where
appropriate.

13 years agoconf: return immediately on error in dhcp host element
Laine Stump [Mon, 19 Mar 2012 03:57:50 +0000 (23:57 -0400)]
conf: return immediately on error in dhcp host element

If an error was encountered parsing a dhcp host entry mac address or
name, parsing would continue and log a less descriptive error that
might make it more difficult to notice the true nature of the problem.

This patch returns immediately on logging the first error.

13 years agoutil: fail attempts to use same mac address for guest and tap
Laine Stump [Mon, 5 Mar 2012 00:21:16 +0000 (19:21 -0500)]
util: fail attempts to use same mac address for guest and tap

This patch is in response to:

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

If a guest's tap device is created using the same MAC address the
guest uses for its own network card (which connects to the tap
device), the Linux kernel will log the following message and traffic
will not pass:

 kernel: vnet9: received packet with own address as source address

This patch disallows MAC addresses with a first byte of 0xFE, but only in
the case that the MAC address is used for a guest interface that's
connected by way of a standard tap device. (In other words, the
validation is done at runtime at the same place the MAC address is
modified for the tap device, rather than when mac address is parsed,
the idea being that it is then we know for sure the address will be
problematic.)

13 years agoCpu mapping cleanup
Martin Kletzander [Mon, 19 Mar 2012 12:29:05 +0000 (13:29 +0100)]
Cpu mapping cleanup

Using inheritance, this patch cleans up the cpu_map.xml file and also
sorts all CPU features according to the feature and registry
values. Model features are sorted the same way as foeatures in the
specification.
Also few models that are related were organized together and parts of
the XML are marked with comments

13 years agosnapshot: make quiesce a bit safer
Eric Blake [Fri, 16 Mar 2012 20:43:58 +0000 (14:43 -0600)]
snapshot: make quiesce a bit safer

If a guest is paused, we were silently ignoring the quiesce flag,
which results in unclean snapshots, contrary to the intent of the
flag.  Since we can't quiesce without guest agent support, we should
instead fail if the guest is not running.

Meanwhile, if we attempt a quiesce command, but the guest agent
doesn't respond, and we time out, we may have left the command
pending on the guest's queue, and when the guest resumes parsing
commands, it will freeze even though our command is no longer
around to issue a thaw.  To be safe, we must _always_ pair every
quiesce call with a counterpart thaw, even if the quiesce call
failed due to a timeout, so that if a guest wakes up and starts
processing a command backlog, it will not get stuck in a frozen
state.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive):
Always issue thaw after a quiesce, even if quiesce failed.
(qemuDomainSnapshotFSThaw): Add a parameter.

13 years agovirConfGetValue: Fixed NULL pointer check
Martin Kletzander [Mon, 19 Mar 2012 10:05:30 +0000 (11:05 +0100)]
virConfGetValue: Fixed NULL pointer check

This patch fixes a NULL pointer check that was causing SegFault on
some specific configurations. It also reverts commit 59d0c9801c1ab
that was checking for this value in one place.

13 years agovirsh: trim aliases from -h output
Eric Blake [Fri, 16 Mar 2012 19:23:00 +0000 (13:23 -0600)]
virsh: trim aliases from -h output

Commit af3f9aab taught 'virsh help' to ignore command aliases,
but forgot 'virsh -h'.

* tools/virsh.c (vshUsage): Handle aliases.

13 years agoFix handling of blkio deviceWeight empty string
Daniel P. Berrange [Fri, 16 Mar 2012 11:05:31 +0000 (11:05 +0000)]
Fix handling of blkio deviceWeight empty string

A common coding pattern for changing blkio parameters is

  1. virDomainGetBlkioParameters

  2. change one or more params

  3. virDomainSetBlkioParameters

For this to work, it must be possible to roundtrip through
the methods without error. Unfortunately virDomainGetBlkioParameters
will return "" for the deviceWeight parameter for guests by default,
which virDomainSetBlkioParameters will then reject as invalid.

This fixes the handling of "" to be a no-op, and also improves the
error message to tell you what was invalid

13 years agoremote: Fix migration leaks
Osier Yang [Fri, 16 Mar 2012 11:37:05 +0000 (19:37 +0800)]
remote: Fix migration leaks

How to reproduce:

% valgrind -v --leak-check=full virsh migrate mig \
  qemu+ssh://$dest/system --unsafe

== 8 bytes in 1 blocks are definitely lost in loss record 1 of 28
==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==    by 0x3EB7115FB8: xdr_reference (in /lib64/libc-2.12.so)
==    by 0x3EB7115F10: xdr_pointer (in /lib64/libc-2.12.so)
==    by 0x4D1EA84: xdr_remote_string (remote_protocol.c:40)
==    by 0x4D1EAD8: xdr_remote_domain_migrate_prepare3_ret (remote_protocol.c:4772)
==    by 0x4D2FFD2: virNetMessageDecodePayload (virnetmessage.c:382)
==    by 0x4D2789C: virNetClientProgramCall (virnetclientprogram.c:382)
==    by 0x4D0707D: callWithFD (remote_driver.c:4549)
==    by 0x4D070FB: call (remote_driver.c:4570)
==    by 0x4D12AEE: remoteDomainMigratePrepare3 (remote_driver.c:4138)
==    by 0x4CF7BE9: virDomainMigrateVersion3 (libvirt.c:4815)
==    by 0x4CF9432: virDomainMigrate2 (libvirt.c:5454)
==
== LEAK SUMMARY:
==    definitely lost: 8 bytes in 1 blocks
==    indirectly lost: 0 bytes in 0 blocks
==      possibly lost: 0 bytes in 0 blocks
==    still reachable: 126,995 bytes in 1,343 blocks
==         suppressed: 0 bytes in 0 blocks

This patch also fixes the leaks in remoteDomainMigratePrepare and
remoteDomainMigratePrepare2.

13 years agolibvirt: fix comment typo
Alex Jia [Fri, 16 Mar 2012 09:49:11 +0000 (17:49 +0800)]
libvirt: fix comment typo

* src/libvirt.c (virStorageVolResize): correct comment typo according to
  virStorageVolResizeFlags enum definition.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoAdd support for forcing a private network namespace for LXC guests
Daniel P. Berrange [Wed, 18 Jan 2012 11:38:49 +0000 (11:38 +0000)]
Add support for forcing a private network namespace for LXC guests

If no <interface> elements are included in an LXC guest XML
description, then the LXC guest will just see the host's
network interfaces. It is desirable to be able to hide the
host interfaces, without having to define any guest interfaces.

This patch introduces a new feature flag <privnet/> to allow
forcing of a private network namespace for LXC. In the future
I also anticipate that we will add <privuser/> to force a
private user ID namespace.

* src/conf/domain_conf.c, src/conf/domain_conf.h: Add support
  for <privnet/> feature. Auto-set <privnet> if any <interface>
  devices are defined
* src/lxc/lxc_container.c: Honour request for private network
  namespace

13 years agolib: Don't access configuration if none is present
Peter Krempa [Thu, 15 Mar 2012 16:10:22 +0000 (17:10 +0100)]
lib: Don't access configuration if none is present

Commit e457d5ef2015e6106094b85f8bbd1582002edc4d adds ability to pass the
default URI using the client configuration file. If the file is not
present, it still accesses the NULL config object causing a segfault.

Caught running "make check".