]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
12 years agoFix race condition when destroying guests
Daniel P. Berrange [Fri, 18 Jan 2013 14:33:51 +0000 (14:33 +0000)] 
Fix race condition when destroying guests

When running virDomainDestroy, we need to make sure that no other
background thread cleans up the domain while we're doing our work.
This can happen if we release the domain object while in the
middle of work, because the monitor might detect EOF in this window.
For this reason we have a 'beingDestroyed' flag to stop the monitor
from doing its normal cleanup. Unfortunately this flag was only
being used to protect qemuDomainBeginJob, and not qemuProcessKill

This left open a race condition where either libvirtd could crash,
or alternatively report bogus error messages about the domain already
having been destroyed to the caller

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 81621f3e6e45e8681cc18ae49404736a0e772a11)

Conflicts:

  src/qemu/qemu_driver.c - virReportError had been removed from
      upstream in cases where qemuProcessKill failed, creating
      different context.

12 years agobuild: move file deleting action from %files list to %install
Yufang Zhang [Wed, 9 Jan 2013 12:18:35 +0000 (20:18 +0800)] 
build: move file deleting action from %files list to %install

When building libvirt rpms on rhel5, I got the following error:

    File must begin with "/": rm
    File must begin with "/": -f
    File must begin with "/": $RPM_BUILD_ROOT/etc/sysctl.d/libvirtd
    Installed (but unpackaged) file(s) found:
   /etc/sysctl.d/libvirtd

It is triggerd by the %files list of libvirt daemon:

    %if 0%{?fedora} >= 14 || 0%{?rhel} >= 6
    %config(noreplace) %{_prefix}/lib/sysctl.d/libvirtd.conf
    %else
    rm -f $RPM_BUILD_ROOT%{_prefix}/lib/sysctl.d/libvirtd.conf
    %endif

After checking document of rpm spec file, I think it would be better
to move the file deleting line from %files list to %install script.

Bug introduced in commit a1fd56c.
(cherry picked from commit daef7c9e9c5abef65e77116a1cabad37c0c0a897)

12 years agobuild: libvirt-guests files misplaced in specfile
Viktor Mihajlovski [Tue, 8 Jan 2013 16:18:13 +0000 (17:18 +0100)] 
build: libvirt-guests files misplaced in specfile

In a non-systemd environment the post and preun scripts of libvirt-client
fail, since the required files are in libvirt-daemon. Moved them to client.
Doing that I noticed %{_unitdir}/libvirt-guests.service was contained in
both libvirt-client and libvirt-daemon, which I don't think was intended.
Removed the extra copy from daemon.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
(cherry picked from commit b7159dca8b1b653e342584fb33225190bb772fd8)

Conflicts:
libvirt.spec.in - no virtlockd service

12 years agoqemu: Relax hard RSS limit
Michal Privoznik [Tue, 8 Jan 2013 09:15:49 +0000 (10:15 +0100)] 
qemu: Relax hard RSS limit

Currently, if there's no hard memory limit defined for a domain,
libvirt tries to calculate one, based on domain definition and magic
equation and set it upon the domain startup. The rationale behind was,
if there's a memory leak or exploit in qemu, we should prevent the
host system trashing. However, the equation was too tightening, as it
didn't reflect what the kernel counts into the memory used by a
process. Since many hosts do have a swap, nobody hasn't noticed
anything, because if hard memory limit is reached, process can
continue allocating memory on a swap. However, if there is no swap on
the host, the process gets killed by OOM killer. In our case, the qemu
process it is.

To prevent this, we need to relax the hard RSS limit. Moreover, we
should reflect more precisely the kernel way of accounting the memory
for process. That is, even the kernel caches are counted within the
memory used by a process (within cgroups at least). Hence the magic
equation has to be changed:

  limit = 1.5 * (domain memory + total video memory) + (32MB for cache
          per each disk) + 200MB
(cherry picked from commit 3c83df679e8feab939c08b1f97c48f9290a5b8cd)

12 years agoutil: fix botched check for new netlink request filters
Laine Stump [Fri, 21 Dec 2012 20:09:33 +0000 (15:09 -0500)] 
util: fix botched check for new netlink request filters

This is an adjustment to the fix for

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

to account for two bonehead mistakes I made.

commit ac2797cf2af2fd0e64c58a48409a8175d24d6f86 attempted to fix a
problem with netlink in newer kernels requiring an extra attribute
with a filter flag set in order to receive an IFLA_VFINFO_LIST from
netlink. Unfortunately, the #ifdef that protected against compiling it
in on systems without the new flag went a bit too far, assuring that
the new code would *never* be compiled, and even if it had, the code
was incorrect.

The first problem was that, while some IFLA_* enum values are also
their existence at compile time, IFLA_EXT_MASK *isn't* #defined, so
checking to see if it's #defined is not a valid method of determining
whether or not to add the attribute. Fortunately, the flag that is
being set (RTEXT_FILTER_VF) *is* #defined, and it is never present if
IFLA_EXT_MASK isn't, so it's sufficient to just check for that flag.

And to top it off, due to the code not actually compiling when I
thought it did, I didn't realize that I'd been given the wrong arglist
to nla_put() - you can't just send a const value to nla_put, you have
to send it a pointer to memory containing what you want to add to the
message, along with the length of that memory.

This time I've actually sent the patch over to the other machine
that's experiencing the problem, applied it to the branch being used
(0.10.2) and verified that it works properly, i.e. it does fix the
problem it's supposed to fix. :-/
(cherry picked from commit 7c36650699f33e54361720f824efdf164bc6e65d)

12 years agoutil: add missing error log messages when failing to get netlink VFINFO
Laine Stump [Thu, 20 Dec 2012 19:52:41 +0000 (14:52 -0500)] 
util: add missing error log messages when failing to get netlink VFINFO

This patch fixes the lack of error messages when libvirt fails to find
VFINFO in a returned netlinke response message.

https://bugzilla.redhat.com/show_bug.cgi?id=827519#c10 is an example
of the error message that was previously logged when the
IFLA_VFINFO_LIST object was missing from the netlink response. The
reason for this failure is detailed in

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

Even though that root problem has been fixed, the experience of
finding the root cause shows us how important it is to properly log an
error message in these cases. This patch *seems* to replace the entire
function, but really most of the changes are due to moving code that
was previously inside an if() statement out to the top level of the
function (the original if() was reversed and made to log an error and
return).
(cherry picked from commit 846770e5ff959f7819e2c32857598cb88e2e2f0e)

12 years agoutil: fix functions that retrieve SRIOV VF info
Laine Stump [Thu, 20 Dec 2012 18:22:17 +0000 (13:22 -0500)] 
util: fix functions that retrieve SRIOV VF info

This patch resolves:

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

When assigning an SRIOV virtual function to a guest using "intelligent
PCI passthrough" (<interface type='hostdev'>, which sets the MAC
address and vlan tag of the VF before passing its info to qemu),
libvirt first learns the current MAC address and vlan tag by sending
an NLM_F_REQUEST message for the VF's PF (physical function) to the
kernel via a NETLINK_ROUTE socket (see virNetDevLinkDump()); the
response message's IFLA_VFINFO_LIST section is examined to extract the
info for the particular VF being assigned.

This worked fine with kernels up until kernel commit
115c9b81928360d769a76c632bae62d15206a94a (first appearing in upstream
kernel 3.3) which changed the ABI to not return IFLA_VFINFO_LIST in
the response until a newly introduced IFLA_EXT_MASK field was included
in the request, with the (newly introduced, of course) RTEXT_FILTER_VF
flag set.

The justification for this ABI change was that new fields had been
added to the VFINFO, causing NLM_F_REQUEST messages to fail on systems
with large numbers of VFs if the requesting application didn't have a
large enough buffer for all the info. The idea is that most
applications doing an NLM_F_REQUEST don't care about VFINFO anyway, so
eliminating it from the response would lower the requirements on
buffer size. Apparently, the people who pushed this patch made the
mistaken assumption that iproute2 (the "ip" command) was the only
package that used IFLA_VFINFO_LIST, so it wouldn't break anything else
(and they made sure that iproute2 was fixed.

The logic of this "fix" is debatable at best (one could claim that the
proper fix would be for the applications in question to be fixed so
that they properly sized the buffer, which is what libvirt does
(purely by virtue of using libnl), but it is what it is and we have to
deal with it.

In order for <interface type='hostdev'> to work properly on systems
with a kernel 3.3 or later, libvirt needs to add the afore-mentioned
IFLA_EXT_MASK field with RTEXT_FILTER_VF set.

Of course we also need to continue working on systems with older
kernels, so that one bit of code is compiled conditionally. The one
time this could cause problems is if the libvirt binary was built on a
system without IFLA_EXT_MASK which was subsequently updated to a
kernel that *did* have it. That could be solved by manually providing
the values of IFLA_EXT_MASK and RTEXT_FILTER_VF and adding it to the
message anyway, but I'm uncertain what that might actually do on a
system that didn't support the message, so for the time being we'll
just fail in that case (which will very likely never happen anyway).
(cherry picked from commit ac2797cf2af2fd0e64c58a48409a8175d24d6f86)

12 years agovirsh: Fix POD syntax
Jiri Denemark [Fri, 26 Oct 2012 10:25:14 +0000 (12:25 +0200)] 
virsh: Fix POD syntax

The first two hunks fix "Unterminated I<...> sequence" error and the
last one fixes "’=item’ outside of any ’=over’" error.
(cherry picked from commit 61299a1c983a64c7e0337b94232fdd2d42c1f4f2)

12 years agobuild: install libvirt sysctl file correctly
Eric Blake [Fri, 4 Jan 2013 21:21:59 +0000 (14:21 -0700)] 
build: install libvirt sysctl file correctly

https://bugzilla.redhat.com/show_bug.cgi?id=887017 reports that
even though libvirt attempts to set fs.aio-max-nr via sysctl,
the file was installed with the wrong name and gets ignored by
sysctl.  Furthermore, 'man systcl.d' recommends that packages
install into hard-coded /usr/lib/sysctl.d (even when libdir is
/usr/lib64), so that sysadmins can use /etc/sysctl.d for overrides.

* daemon/Makefile.am (install-sysctl, uninstall-sysctl): Use
correct location.
* libvirt.spec.in (network_files): Reflect this.
(cherry picked from commit a1fd56cb3057c45cffbf5d41eaf70a26d2116b20)

12 years agobuild: .service files don't need to be executable
Eric Blake [Fri, 4 Jan 2013 20:50:39 +0000 (13:50 -0700)] 
build: .service files don't need to be executable

See also commit 66ff2dd, where we avoided installing these files
as executables.

* daemon/Makefile.am (libvirtd.service): Drop chmod.
* tools/Makefile.am (libvirt-guests.service): Likewise.
* src/Makefile.am (virtlockd.service, virtlockd.socket):
Likewise.
(cherry picked from commit 5ec4b22b777b4505d159c6e8d1631d4d774a7be7)

Conflicts:
src/Makefile.am - virtlockd.service not present in 0.10.2

12 years agobuild: use common .in replacement mechanism
Eric Blake [Fri, 4 Jan 2013 20:35:04 +0000 (13:35 -0700)] 
build: use common .in replacement mechanism

We had several different styles of .in conversion in our Makefiles:
ALLCAPS, @ALLCAPS@, @lower@, ::lower::
Canonicalize on one form, to make it easier to copy and paste
between .in files.

Also, we were using some non-portable sed constructs: \@ is an
undefined escape sequence (it happens to be @ itself in GNU sed,
but POSIX allows it to mean something else), as well as risky
behavior (failure to consistently quote things means a space
in $(sysconfdir) could throw things off; also, Autoconf recommends
using | rather than , or ! in the s||| operator, because | has to
be quoted in shell and is therefore less likely to appear in file
names than , or !).

Fix all of these uses to follow the same syntax.

* daemon/libvirtd.8.in: Switch to @var@.
* tools/virt-xml-validate.in: Likewise.
* tools/virt-pki-validate.in: Likewise.
* src/locking/virtlockd.init.in: Likewise.
* daemon/Makefile.am: Prefer | over ! in sed.
(libvirtd.8): Prefer consistent substitution.
(libvirtd.init, libvirtd.service): Avoid non-portable sed.
* tools/Makefile.am (libvirt-guests.sh, libvirt-guests.init)
(libvirt-guests.service): Likewise.
(virt-xml-validate, virt-pki-validate, virt-sanlock-cleanup):
Prefer consistent capitalization.
* src/Makefile.am (virtlockd.init, virtlockd.service)
(virtlockd.socket): Prefer consistent substitution.
(cherry picked from commit 462a69621e232c83990dbe6a711326b671262d47)

Conflicts:
daemon/Makefile.am - drop files not present in 0.10.2
src/Makefile.am - likewise
src/locking/virtlockd.init.in - likewise

12 years agotools: Only install guests init script if --with-init=script=redhat
Cole Robinson [Sun, 21 Oct 2012 02:29:51 +0000 (22:29 -0400)] 
tools: Only install guests init script if --with-init=script=redhat

Most of this deals with moving the libvirt-guests.sh script which
does all the work to /usr/libexec, so it can be shared by both
systemd and traditional init. Previously systemd depended on
the script being in /etc/init.d

Required to fix https://bugzilla.redhat.com/show_bug.cgi?id=789747
(cherry picked from commit d13155c20c0df9595e33c120a68b3544192d6740)

12 years agobuild: fix syntax-check tab violation
Eric Blake [Fri, 26 Oct 2012 21:27:25 +0000 (15:27 -0600)] 
build: fix syntax-check tab violation

* tools/Makefile.am: Fix tab damage in previous patch.
(cherry picked from commit 07049e4c39186368d6851df9707a53525a3f06a0)

12 years agobuild: check for pod errors
Eric Blake [Fri, 26 Oct 2012 15:06:54 +0000 (09:06 -0600)] 
build: check for pod errors

Patch 61299a1c fixed a long-standing pod error in the man page.
But we should be preventing these up front.
See also https://bugzilla.redhat.com/show_bug.cgi?id=870273

* tools/Makefile.am (virt-xml-validate.1, virt-pki-validate.1)
(virt-host-validate.1, virt-sanlock-cleanup.8, virsh.1): Reject
pod conversion errors.
* daemon/Makefile.am ($(srcdir)/libvirtd.8.in): Likewise.
(cherry picked from commit 2639949abe732cf683bec48f87ff6c243b608b76)

12 years agodaemon: Use $(AM_V_GEN) in a few more places
Cole Robinson [Sat, 13 Oct 2012 14:12:04 +0000 (10:12 -0400)] 
daemon: Use $(AM_V_GEN) in a few more places

(cherry picked from commit 0801c149080b6c7760bc794bc6ab00a8cdbdaed2)

12 years agobuild: Add libxenctrl to LIBXL_LIBS
Jim Fehlig [Mon, 7 Jan 2013 17:15:56 +0000 (10:15 -0700)] 
build: Add libxenctrl to LIBXL_LIBS

Commit dfa1e1dd removed libxenctrl from LIBXL_LIBS, but the libxl
driver uses a symbol from this library.  Explicitly link with
libxenctrl instead of relying on the build system to support
implicit DSO linking.
(cherry picked from commit 68e7bc4561783d742d1e266b7f1f0e3516d5117e)

12 years agoConvert libxl driver to Xen 4.2
Jim Fehlig [Mon, 26 Nov 2012 16:28:56 +0000 (09:28 -0700)] 
Convert libxl driver to Xen 4.2

Based on a patch originally authored by Daniel De Graaf

  http://lists.xen.org/archives/html/xen-devel/2012-05/msg00565.html

This patch converts the Xen libxl driver to support only Xen >= 4.2.
Support for Xen 4.1 libxl is dropped since that version of libxl is
designated 'technology preview' only and is incompatible with Xen 4.2
libxl.  Additionally, the default toolstack in Xen 4.1 is still xend,
for which libvirt has a stable, functional driver.
(cherry picked from commit dfa1e1dd5325f3a6bc8865312cde557044bf0b93)

Conflicts:
src/libxl/libxl_conf.c - commit e5e8d5 not backported
src/libxl/libxl_driver.c - commit 1c04f99 not backported

12 years agoIntroduce APIs for splitting/joining strings
Daniel P. Berrange [Fri, 30 Nov 2012 15:21:02 +0000 (15:21 +0000)] 
Introduce APIs for splitting/joining strings

This introduces a few new APIs for dealing with strings.
One to split a char * into a char **, another to join a
char ** into a char *, and finally one to free a char **

There is a simple test suite to validate the edge cases
too. No more need to use the horrible strtok_r() API,
or hand-written code for splitting strings.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 76c1fd33c8093d6a7173a85486e1e6f51a832135)

Conflicts:
tests/Makefile.am - commit eca72d4 not backported

12 years agonetwork: prevent dnsmasq from listening on localhost
Laine Stump [Thu, 13 Dec 2012 06:46:40 +0000 (01:46 -0500)] 
network: prevent dnsmasq from listening on localhost

This patch resolves the problem reported in:

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

The source of the problem was the fix for CVE 2011-3411:

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

which was originally committed upstream in commit
753ff83a50263d6975f88d6605d4b5ddfcc97560. That commit improperly
removed the "--except-interface lo" from dnsmasq commandlines when
--bind-dynamic was used (based on comments in the latter bug).

It turns out that the problem reported in the CVE could be eliminated
without removing "--except-interface lo", and removing it actually
caused each instance of dnsmasq to listen on localhost on port 53,
which created a new problem:

If another instance of dnsmasq using "bind-interfaces" (instead of
"bind-dynamic") had already been started (or if another instance
started later used "bind-dynamic"), this wouldn't have any immediately
visible ill effects, but if you tried to start another dnsmasq
instance using "bind-interfaces" *after* starting any libvirt
networks, the new dnsmasq would fail to start, because there was
already another process listening on port 53.

This patch changes the network driver to *always* add
"except-interface=lo" to dnsmasq conf files, regardless of whether we use
bind-dynamic or bind-interfaces. This way no libvirt dnsmasq instances
are listening on localhost (and the CVE is still fixed).

The actual code change is miniscule, but must be propogated through all
of the test files as well.

(This is *not* a cherry-pick of the upstream commit that fixes the bug
(commit d66eb7866757dd371560c288dc6201fb9348792a), because subsequent
to the CVE fix, another patch changed the network driver to put
dnsmasq options in a conf file rather than directly on the dnsmasq
commandline preserving the same options), so a cherry-pick is just one
very large conflict.)

12 years agoPrep for release 0.10.2.2 v0.10.2.2
Cole Robinson [Sun, 9 Dec 2012 23:21:26 +0000 (18:21 -0500)] 
Prep for release 0.10.2.2

12 years agodnsmasq: Fix parsing of the version number
Michal Privoznik [Thu, 6 Dec 2012 12:48:11 +0000 (13:48 +0100)] 
dnsmasq: Fix parsing of the version number

If debugging is enabled, the debug messages are sent to stderr.
Moreover, if a command has catching of stderr set, the messages
gets mixed with stdout output (assuming both outputs are stored
in the same variable). The resulting string then doesn't
necessarily have to start with desired prefix then. This bug
exposes itself when parsing dnsmasq output:

2012-12-06 11:18:11.445+0000: 18491: error :
dnsmasqCapsSetFromBuffer:664 : internal error cannot parse
/usr/sbin/dnsmasq version number in '2012-12-06
11:11:02.232+0000: 18492: debug : virFileClose:72 : Closed fd 22'

We can clearly see that the output of dnsmasq --version doesn't
start with expected "Dnsmasq version " string but a libvirt debug
output.
(cherry picked from commit ff33f807739dc2950e4df8c1d4007ce9f8b290c0)

12 years agodnsmasq: Fix parsing of the version number
Michal Privoznik [Thu, 6 Dec 2012 11:25:50 +0000 (12:25 +0100)] 
dnsmasq: Fix parsing of the version number

If the debugging is enabled, the virCommand subsystem catches debug
messages in the command output as well. In that case, we can't assume
the string corresponding to command's stdout will start with specific
prefix. But the prefix can be moved deeper in the string. This bug
shows itself when parsing dnsmasq output:

2012-12-06 11:18:11.445+0000: 18491: error :
dnsmasqCapsSetFromBuffer:664 : internal error cannot parse
/usr/sbin/dnsmasq version number in '2012-12-06 11:11:02.232+0000:
18492: debug : virFileClose:72 : Closed fd 22'

We can clearly see that the output of dnsmasq --version
doesn't start with expected "Dnsmasq version " string but a libvirt
debug output.
(cherry picked from commit 5114431396fd125b6ebe4d1a20a981111f948ee7)

12 years agostorage: Error out earlier if the volume target path already exists
Osier Yang [Wed, 5 Dec 2012 04:44:11 +0000 (12:44 +0800)] 
storage: Error out earlier if the volume target path already exists

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

It's odd to fall through to buildVol, and the existed file is
removed when buildVol fails. This checks if the volume target
path already exists in createVol. The reason for not using
error like "Volume already exists" is that there isn't volume
maintained by libvirt for the path until a operation like
pool-refresh, using error like that will just cause confusion.
(cherry picked from commit d1f3d14974b4213193130d4b01d4449ad1533cbb)

12 years agoremote: Avoid the thread race condition
Daniel P. Berrange [Wed, 5 Dec 2012 14:48:43 +0000 (22:48 +0800)] 
remote: Avoid the thread race condition

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

Since the virConnect object is not locked wholely when doing
virConenctDispose, a thread can get the lock and thus might
cause the race.

Detected by valgrind:

==23687== Invalid read of size 4
==23687==    at 0x38BAA091EC: pthread_mutex_lock (pthread_mutex_lock.c:61)
==23687==    by 0x3FBA919E36: remoteClientCloseFunc (remote_driver.c:337)
==23687==    by 0x3FBA936BF2: virNetClientCloseLocked (virnetclient.c:688)
==23687==    by 0x3FBA9390D8: virNetClientIncomingEvent (virnetclient.c:1859)
==23687==    by 0x3FBA851AAE: virEventPollRunOnce (event_poll.c:485)
==23687==    by 0x3FBA850846: virEventRunDefaultImpl (event.c:247)
==23687==    by 0x40CD61: vshEventLoop (virsh.c:2128)
==23687==    by 0x3FBA8626F8: virThreadHelper (threads-pthread.c:161)
==23687==    by 0x38BAA077F0: start_thread (pthread_create.c:301)
==23687==    by 0x33F68E570C: clone (clone.S:115)
==23687==  Address 0x4ca94e0 is 144 bytes inside a block of size 312 free'd
==23687==    at 0x4A0595D: free (vg_replace_malloc.c:366)
==23687==    by 0x3FBA8588B8: virFree (memory.c:309)
==23687==    by 0x3FBA86AAFC: virObjectUnref (virobject.c:145)
==23687==    by 0x3FBA8EA767: virConnectClose (libvirt.c:1458)
==23687==    by 0x40C8B8: vshDeinit (virsh.c:2584)
==23687==    by 0x41071E: main (virsh.c:3022)

The above race is caused by the eventLoop thread tries to handle
the net client event by calling the callback set by:
    virNetClientSetCloseCallback(priv->client,
                                 remoteClientCloseFunc,
                                 conn, NULL);

I.E. remoteClientCloseFunc, which lock/unlock the virConnect object.

This patch is to fix the bug by setting the callback to NULL when
doRemoteClose.
(cherry picked from commit b362938e579573017a2250f49e24dce6c837b5a6)

12 years agoqemu: Don't free PCI device if adding it to activePciHostdevs fails
Jiri Denemark [Fri, 30 Nov 2012 15:52:03 +0000 (16:52 +0100)] 
qemu: Don't free PCI device if adding it to activePciHostdevs fails

The device is still referenced from pcidevs and freeing it would leave
an invalid pointer there.
(cherry picked from commit ea1a9b5fddd1562abf31eb5c2502879bfd25903e)

12 years agobuild: fix incremental autogen.sh when no AUTHORS is present
Eric Blake [Mon, 3 Dec 2012 20:12:09 +0000 (13:12 -0700)] 
build: fix incremental autogen.sh when no AUTHORS is present

Commit 71d1256 tried to fix a problem where rebasing an old
branch on top of newer libvirt.git resulted in automake failing
because of a missing AUTHORS file.  However, while the fix
worked for an incremental 'make', it did not work for someone
that directly reran './autogen.sh'.  Reported by Laine Stump.

* autogen.sh (autoreconf): Check for same conditions as cfg.mk.
* cfg.mk (_update_required): Add comments.
(cherry picked from commit 55dc872bd85e0756a13fc24693c4eed31d0c202f)

12 years agoconf: prevent crash with no uuid in cephx auth secret
Ján Tomko [Mon, 3 Dec 2012 12:35:05 +0000 (13:35 +0100)] 
conf: prevent crash with no uuid in cephx auth secret

Fix the null pointer access when UUID is not specified.
Introduce a bool 'uuidUsable' to virStoragePoolAuthCephx that indicates
if uuid was specified or not and use it instead of the pointless
comparison of the static UUID array to NULL.
Add an error message if both uuid and usage are specified.

Fixes:
Error: FORWARD_NULL (CWE-476):
libvirt-0.10.2/src/conf/storage_conf.c:461: var_deref_model: Passing
    null pointer "uuid" to function "virUUIDParse(char const *, unsigned
    char *)", which dereferences it. (The dereference is assumed on the
    basis of the 'nonnull' parameter attribute.)
Error: NO_EFFECT (CWE-398):
    libvirt-0.10.2/src/conf/storage_conf.c:979: array_null: Comparing an
    array to null is not useful: "src->auth.cephx.secret.uuid != NULL".
(cherry picked from commit bc680e1381be7eeb5ae7d898ebab598df819b672)

12 years agoAllow duration=0 for virsh nodesuspend
Daniel P. Berrange [Fri, 30 Nov 2012 18:43:40 +0000 (18:43 +0000)] 
Allow duration=0 for virsh nodesuspend

The virNodeSuspend API allows for a duration of 0, to mean no
timed wakup. virsh needlessly forbids this though

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 1cad5ebae6074318ca22789b1e38d4594d54f883)

12 years agoQuote client identity in SASL whitelist log message
Daniel P. Berrange [Fri, 30 Nov 2012 15:05:48 +0000 (15:05 +0000)] 
Quote client identity in SASL whitelist log message

When seeing a message

 virNetSASLContextCheckIdentity:146 : SASL client admin not allowed in whitelist

it isn't immediately obvious that 'admin' is the identity
being checked. Quote the string to make it more obvious
(cherry picked from commit 07da0a6b54057f48238e35f1756d137c10e0bef5)

12 years agoFix uninitialized variables
Guido Günther [Fri, 30 Nov 2012 17:51:28 +0000 (18:51 +0100)] 
Fix uninitialized variables

detecet by

http://honk.sigxcpu.org:8001/job/libvirt-build/348/console
(cherry picked from commit d01e427e01e272825d3c60acbace11c7e3154ca5)

12 years agonwfilter: report an error on OOM
Ján Tomko [Fri, 30 Nov 2012 14:07:50 +0000 (15:07 +0100)] 
nwfilter: report an error on OOM

Also removed some unreachable code found by coverity:
libvirt-0.10.2/src/nwfilter/nwfilter_driver.c:259: unreachable: This
code cannot be reached: "nwfilterDriverUnlock(driver...".
(cherry picked from commit 4f9af0857c1547d19610e5c59efe45a8d847b67f)

12 years agovirsh: check the return value of virStoragePoolGetAutostart
Ján Tomko [Fri, 30 Nov 2012 12:09:21 +0000 (13:09 +0100)] 
virsh: check the return value of virStoragePoolGetAutostart

On error, virStoragePoolGetAutostart would return -1 leaving autostart
untouched.

Removed the misleading debug message as well.

Error: CHECKED_RETURN (CWE-252):
libvirt-0.10.2/tools/virsh-pool.c:1386: unchecked_value: No check of the
    return value of "virStoragePoolGetAutostart(pool, &autostart)".
(cherry picked from commit e9d74a7a8238f082cf0f0285ce4d2547a72eaa01)

12 years agoconf: fix uninitialized variable in virDomainListSnapshots
Ján Tomko [Thu, 29 Nov 2012 10:55:54 +0000 (11:55 +0100)] 
conf: fix uninitialized variable in virDomainListSnapshots

If allocation of names fails, list is uninitialized.
(cherry picked from commit 892582f9deb1a4c4200a3d0bdfe6a2a94b039ef2)

12 years agorpc: don't destroy xdr before creating it in virNetMessageEncodeHeader
Ján Tomko [Thu, 29 Nov 2012 10:50:09 +0000 (11:50 +0100)] 
rpc: don't destroy xdr before creating it in virNetMessageEncodeHeader

On OOM, xdr_destroy got called even though it wasn't created yet.

Found by coverity:
Error: UNINIT (CWE-457):
    libvirt-0.10.2/src/rpc/virnetmessage.c:214: var_decl: Declaring
    variable "xdr" without initializer.
    libvirt-0.10.2/src/rpc/virnetmessage.c:219: cond_true: Condition
    "virReallocN(&msg->buffer, 1UL /* sizeof (*msg->buffer) */,
    msg->bufferLength) < 0", taking true branch
    libvirt-0.10.2/src/rpc/virnetmessage.c:221: goto: Jumping to label
    "cleanup"
    libvirt-0.10.2/src/rpc/virnetmessage.c:257: label: Reached label
    "cleanup"
    libvirt-0.10.2/src/rpc/virnetmessage.c:258: uninit_use: Using
    uninitialized value "xdr.x_ops".
(cherry picked from commit 6e1fc35546bda31a27e9adb8a23c761cffc1aae6)

12 years agovirsh: do timing even for unusable connections
Ján Tomko [Thu, 29 Nov 2012 10:46:00 +0000 (11:46 +0100)] 
virsh: do timing even for unusable connections

Time values were uninitialized if the connection wasn't usable.
(cherry picked from commit 8b235d40576d5b5077a4ab2ee52a1897211f5e4d)

12 years agovirsh: use correct sizeof when allocating cpumap
Ján Tomko [Thu, 29 Nov 2012 10:23:06 +0000 (11:23 +0100)] 
virsh: use correct sizeof when allocating cpumap

Found by coverity:
Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4754: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.

Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4942: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.
(cherry picked from commit dc04b2a737c8c4240d0d412080ce798b977068a1)

12 years agoutil: fix virBitmap allocation in virProcessInfoGetAffinity
Ján Tomko [Thu, 29 Nov 2012 09:56:56 +0000 (10:56 +0100)] 
util: fix virBitmap allocation in virProcessInfoGetAffinity

Found by coverity:
Error: REVERSE_INULL (CWE-476):
    libvirt-0.10.2/src/util/processinfo.c:141: deref_ptr: Directly
    dereferencing pointer "map".
    libvirt-0.10.2/src/util/processinfo.c:142: check_after_deref:
    Null-checking "map" suggests that it may be null, but it has already
    been dereferenced on all paths leading to the check.
(cherry picked from commit 7730257db30972a6f4db8d582b232b240b2a06b8)

12 years agonetwork: fix crash when portgroup has no name
Laine Stump [Wed, 28 Nov 2012 04:59:17 +0000 (23:59 -0500)] 
network: fix crash when portgroup has no name

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=879473

The name attribute is required for portgroup elements (yes, the RNG
specifies that), and there is code in libvirt that assumes it is
non-null.  Unfortunately, the portgroup parsing function wasn't
checking for lack of portgroup. One adverse result of this was that
attempts to update a network by adding a portgroup with no name would
cause libvirtd to segfault. For example:

   virsh net-update default add portgroup "<portgroup default='yes'/>"

This patch causes virNetworkPortGroupParseXML to fail if no name is
specified, thus avoiding any later problems.
(cherry picked from commit 012d69dff1e031f8079a9952e886a31795e589b2)

12 years agoFix leak of virNetworkPtr in LXC startup failure path
Daniel P. Berrange [Tue, 27 Nov 2012 12:57:57 +0000 (12:57 +0000)] 
Fix leak of virNetworkPtr in LXC startup failure path

When starting an LXC guest with a virNetwork based NIC device,
if the network was not active, the virNetworkPtr device would
be leaked

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 509ce9437ff77db84b5b035ad6b778fa8548a684)

12 years agoFix error reporting in virNetDevVethDelete
Daniel P. Berrange [Tue, 27 Nov 2012 12:35:49 +0000 (12:35 +0000)] 
Fix error reporting in virNetDevVethDelete

In virNetDevVethDelete the virRun method will properly report
errors, but when checking the exit status for non-zero exit
code no error is reported

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 0584d6626b07a55ede81d7ffde9565e9a305c172)

12 years agoEnsure transient def is removed if LXC start fails
Daniel P. Berrange [Fri, 23 Nov 2012 16:40:16 +0000 (16:40 +0000)] 
Ensure transient def is removed if LXC start fails

When starting a container, newDef is initialized to a
copy of 'def', but when startup fails newDef is never
removed. This cause later attempts to use 'virDomainDefine'
to lose the new data being defined.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 9d2bfc1ca78eb7106e5d189b9d21ad47e1826e50)

12 years agoEnsure failure to create macvtap device aborts LXC start
Daniel P. Berrange [Fri, 23 Nov 2012 16:38:01 +0000 (16:38 +0000)] 
Ensure failure to create macvtap device aborts LXC start

A mistaken initialization of 'ret' caused failure to create
macvtap devices to be ignored. The libvirt_lxc process
would later fail to start due to missing devices

Also make sure code checks '< 0' and not '!= 0' since only
-1 is considered an error condition

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 43db9cf4ed72e20021907073a656b5f3d7fd1f28)

12 years agoAvoid crash when LXC start fails with no interface target
Daniel P. Berrange [Fri, 23 Nov 2012 16:36:52 +0000 (16:36 +0000)] 
Avoid crash when LXC start fails with no interface target

If the <interface> device did not contain any <target>
element, LXC would crash on a NULL pointer if starting
the container failed

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 68dceb635d8d8f68e36caf4054c32f0f9cb13c22)

12 years agoSpecify name of target interface with macvlan error
Daniel P. Berrange [Fri, 23 Nov 2012 16:34:10 +0000 (16:34 +0000)] 
Specify name of target interface with macvlan error

When failing to create a macvlan interface, make sure the
error message contains the name of the host interface

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit e11daa2b602e69708d86ada8f7167bf68ee102cd)

12 years agoTreat missing driver cgroup as fatal in LXC driver
Daniel P. Berrange [Fri, 23 Nov 2012 10:44:39 +0000 (10:44 +0000)] 
Treat missing driver cgroup as fatal in LXC driver

The LXC driver relies on use of cgroups to kill off LXC processes
in shutdown. If cgroups aren't available, we're unable to kill
off processes, so we must treat lack of cgroups as a fatal startup
error.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 7c5ba648f7bab628b2965f699ad1fed524f6141a)

12 years agoEnsure LXC container exits if cgroups setup fails
Daniel P. Berrange [Fri, 23 Nov 2012 10:42:18 +0000 (10:42 +0000)] 
Ensure LXC container exits if cgroups setup fails

The code setting up LXC cgroups used an 'rc' variable both
for capturing the return value of methods it calls, and
its own return status. The result was that several failures
in setting up cgroups would actually result in success being
returned.

Use a separate 'ret' for tracking return value as per normal
code design in other parts of libvirt

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 8e1f0c38fa7ffbfb1f266e6bdb865c3ad807c473)

12 years agolxc: Don't crash if no security driver is specified in libvirt_lxc
Peter Krempa [Mon, 26 Nov 2012 14:17:58 +0000 (15:17 +0100)] 
lxc: Don't crash if no security driver is specified in libvirt_lxc

When no security driver is specified libvirt_lxc segfaults as a debug
message tries to access security labels for the container that are not
present.

This problem was introduced in commit 6c3cf57d6cb27cf10064baf8cca0f39.
(cherry picked from commit 99a388e612d82a6bcd3462e4b98463fb32931520)

12 years agolxc: Avoid segfault of libvirt_lxc helper on early cleanup paths
Peter Krempa [Mon, 26 Nov 2012 11:13:56 +0000 (12:13 +0100)] 
lxc: Avoid segfault of libvirt_lxc helper on early cleanup paths

Early jumps to the cleanup label caused a crash of the libvirt_lxc
container helper as the cleanup section called
virLXCControllerDeleteInterfaces(ctrl) without checking the ctrl argument
for NULL. The argument was de-referenced soon after.

$ /usr/libexec/libvirt_lxc
/usr/libexec/libvirt_lxc: missing --name argument for configuration
Segmentation fault
(cherry picked from commit 81efb13b4a33f58c28e0e65dcc9521b983592683)

12 years agostorage: fix logical volume cloning
Ján Tomko [Sun, 25 Nov 2012 01:59:33 +0000 (02:59 +0100)] 
storage: fix logical volume cloning

Commit 258e06c removed setting of the volume type to
VIR_STORAGE_VOL_BLOCK, which leads to failures in
storageVolumeCreateXMLFrom.

The type (and target.format) of the volume was set to zero. In
virStorageBackendGetBuildVolFromFunction, this gets interpreted as
VIR_STORAGE_FILE_NONE and the qemu-img tool is called with unknown
"none" format.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=879780
(cherry picked from commit 70f0bbe8e046dae1b811378f735872d3e61f4609)

12 years agoSkip deleted timers when calculting next timeout
Daniel P. Berrange [Thu, 22 Nov 2012 16:43:57 +0000 (16:43 +0000)] 
Skip deleted timers when calculting next timeout

It is possible for there to be deleted timers when we
calculate the next timeout, and they must be skipped.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit afbd96678e40449ae72cb326a98f9123e53e4aa3)

12 years agoWarn if requesting update to non-existent timer/handle watch
Daniel P. Berrange [Thu, 22 Nov 2012 16:42:30 +0000 (16:42 +0000)] 
Warn if requesting update to non-existent timer/handle watch

The event code is a no-op if requested to update a non-existent
timer/handle watch. This makes it hard to detect bugs in the
caller who have passed bogus data. Add a VIR_WARN output in
such cases, since the API does not allow for return errors.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 39064f0ff9dca13aeea61f663a2bf538e90d6357)

12 years agoFix virDiskNameToIndex to actually ignore partition numbers
Daniel P. Berrange [Thu, 22 Nov 2012 14:56:08 +0000 (14:56 +0000)] 
Fix virDiskNameToIndex to actually ignore partition numbers

The docs for virDiskNameToIndex claim it ignores partition
numbers. In actual fact though, a code ordering bug means
that a partition number will cause the code to accidentally
multiply the result by 26.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 81d6c4defe2b72f34b02884bb78f924165998771)

12 years agoconf: Report sensible error for invalid disk name
Martin Kletzander [Tue, 20 Nov 2012 13:45:56 +0000 (14:45 +0100)] 
conf: Report sensible error for invalid disk name

The error "... but the cause is unknown" appeared for XMLs similar to
this:

 <disk type='file' device='cdrom'>
   <driver name='qemu' type='raw'/>
   <source file='/dev/zero'/>
   <target dev='sr0'/>
 </disk>

Notice unsupported disk type (for the driver), but also no address
specified. The first part is not a problem and we should not abort
immediately because of that, but the combination with the address
unknown was causing an unspecified error.

While fixing this, I added an error to one place where this return
value was not managed properly.
(cherry picked from commit 03cd6e4ae8d86682986249f05f7de8eb405a12da)

12 years agoUse virNetServerRun instead of custom main loop
Daniel P. Berrange [Fri, 16 Nov 2012 09:11:23 +0000 (09:11 +0000)] 
Use virNetServerRun instead of custom main loop

The LXC controller code currently directly invokes the
libvirt main loop code. The problem is that this misses
the cleanup of virNetServerClient connections that
virNetServerRun takes care of.

The result is that when libvirtd is stopped, the
libvirt_lxc controller process gets stuck in a I/O loop.
When libvirtd is then started again, it fails to connect
to the controller and thus kills off the entire domain.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit f33e43c2353cc10065b8a5f9965d5a57cfe8991f)

12 years agostorage: Fix bug of fs pool destroying
Osier Yang [Wed, 21 Nov 2012 03:22:39 +0000 (11:22 +0800)] 
storage: Fix bug of fs pool destroying

Regression introduced by commit 258e06c85b7, "ret" could be set to 1
or 0 by virStorageBackendFileSystemIsMounted before goto cleanup.
This could mislead the callers (up to the public API
virStoragePoolDestroy) to return success even the underlying umount
command fails.
(cherry picked from commit f4ac06569a8ffce24fb8c07a0fc01574e38de6e4)

12 years agoconf: add support for booting from redirected USB devices
Ján Tomko [Tue, 20 Nov 2012 18:47:07 +0000 (19:47 +0100)] 
conf: add support for booting from redirected USB devices

Commit a4c19459aa8634c43b51e8138fb1d7eec4c17824 only added the
QEMU capability flag, command line option and added the boot element
for redirdev's in the XML schema.

This patch adds support for parsing and writing the XML with redirdevs
with the boot flag. It also ignores unknown XML elements in redirdev
instead of failing with:
"error: An error occurred, but the cause is unknown"

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=805414
(cherry picked from commit cc244e24416b7785258c69995483015bbf8927dd)

12 years agoqemu: allow larger discrepency between memory & currentMemory in domain xml
Laine Stump [Fri, 16 Nov 2012 15:53:04 +0000 (10:53 -0500)] 
qemu: allow larger discrepency between memory & currentMemory in domain xml

This resolves:

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

The reported problem is that an attempt to restore a saved domain that
was configured with <currentMemory> and <memory> set to some (same for
both) number that's not a multiple of 4096KiB results in an error like
this:

  error: Failed to start domain libvirt_test_api
  error: XML error: current memory '4001792k' exceeds maximum '4000768k'

(in this case, currentMemory was set to 4000000KiB).

The reason for this failure is:

1) a saved image contains the "live xml" of the domain at the time of
the save.

2) the live xml of a running domain gets its currentMemory
(a.k.a. cur_balloon) directly from the qemu monitor rather than from
the configuration of the domain.

3) the value reported by qemu is (sometimes) not exactly what was
originally given to qemu when the domain was started, but is rounded
up to [some indeterminate granularity] - in some versions of qemu that
granularity is apparently 1MiB, and in others it is 4MiB.

4) When the XML is parsed to setup the state of the restored domain,
the XML parser for <currentMemory> compares it to <memory> (which is
the maximum allowed memory size for the domain) and if <currentMemory>
is greater than the next 1024KiB boundary above <memory>, it spits out
an error and fails.

For example (from the BZ) if you start qemu on RHEL6 with both
<currentMemory> and <memory> of 4000000 (this number is in KiB),
libvirt's dominfo or dumpxml will report "4001792" back (rounded up to
next 4MiB) for 10-20 seconds after the start, then revert to reporting
"4000000". On Fedora 16 (which uses qemu-1.0), it will instead report
"4000768" (rounded up to next 1MiB). On Fedora 17 (qemu-1.2), it seems
to always report "4000000". ("4000000" is of course okay, and
"4000768" is also okay since that's the next 1024KiB boundary above
"4000000" and the parser was already allowing for that. But "4001792
is *not* okay and produces the error message.)

This patch solves the problem by changing the allowed "fudge factor"
when parsing from 1024KiB to 4096KiB to match the maximum up-rounding
that could be done in qemu.

(I had earlier thought to fix this by up-rounding <memory> in the
dumpxml that's put into the saved image, but that wouldn't have fixed
the case where the save image was produced by an "unfixed"
libvirtd.)
(cherry picked from commit 89204fca7f193c7cf48f941bf2917c1a0e71096c)

12 years agonodeinfo: support kernels that lack socket information
Eric Blake [Thu, 1 Nov 2012 22:20:09 +0000 (16:20 -0600)] 
nodeinfo: support kernels that lack socket information

On RHEL 5, I was getting a segfault trying to start libvirtd,
because we were failing virNodeParseSocket but not checking
for errors, and then calling CPU_SET(-1, &sock_map) as a result.
But if you don't have a topology/physical_package_id file,
then you can just assume that the cpu belongs to socket 0.

* src/nodeinfo.c (virNodeGetCpuValue): Change bool into
default_value.
(virNodeParseSocket): Allow for default value when file is missing,
different from fatal error on reading file.
(virNodeParseNode): Update call sites to fail on error.
(cherry picked from commit 47976b484cfae6ff0dd9e6fcbd45d377aaeaa8f4)

12 years agovirsh: save: report an error if XML file can't be read
Ján Tomko [Thu, 15 Nov 2012 13:25:09 +0000 (14:25 +0100)] 
virsh: save: report an error if XML file can't be read

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=876868
(cherry picked from commit 58110b48870b4e8efd1d833e3ecbef41b62d1877)

12 years agoDoug Goldstein gained commit capability
Daniel Veillard [Thu, 15 Nov 2012 01:34:01 +0000 (09:34 +0800)] 
Doug Goldstein gained commit capability
(cherry picked from commit bf60b6b33fd8e989b56c5a5cd4ea9660cbd0e556)

12 years agobuild: rerun bootstrap if AUTHORS is missing
Eric Blake [Wed, 14 Nov 2012 20:20:55 +0000 (13:20 -0700)] 
build: rerun bootstrap if AUTHORS is missing

Ever since commit 7b21981c started generating AUTHORS, we now have
the situation that if you flip between two branches in the same
git repository that cross that commit boundary, then 'make' will
fail due to automake complaining about AUTHORS not existing.  The
simplest solution is to realize that if AUTHORS does not exist,
then we flipped branches so we will need to rerun bootstrap
anyways; and rerunning bootstrap ensures AUTHORS will exist in time.

* cfg.mk (_update_required): Also depend on AUTHORS.
(cherry picked from commit 71d125620d0d88f15288aa7c2570988cc908ed11)

12 years agoFix uninitialized variable in virLXCControllerSetupDevPTS
Daniel P. Berrange [Wed, 14 Nov 2012 15:39:48 +0000 (15:39 +0000)] 
Fix uninitialized variable in virLXCControllerSetupDevPTS

The lack of initialization of 'opts' caused a SEGV in the
cleanup: path if the root->src directory did not exist
(cherry picked from commit 3782814d4ad787d815e56382b6f809fe9020f14b)

12 years agoqemu: Don't force port=0 for SPICE
Michal Privoznik [Mon, 12 Nov 2012 17:03:24 +0000 (18:03 +0100)] 
qemu: Don't force port=0 for SPICE

If domain uses only TLS port we don't want to add
'port=0' explicitly to command line.
(cherry picked from commit 9f872472357cc014f6aa6068c26d7cf971343439)

12 years agoFix "virsh create" example
Guido Günther [Wed, 7 Nov 2012 20:35:55 +0000 (21:35 +0100)] 
Fix "virsh create" example

We require a file and don't accept standard input:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=692322
(cherry picked from commit d49adae2e261d2736b22be37ef8d4fe0460df0ad)

12 years agoesx: Yet another connection fix for 5.1
Martin Kletzander [Tue, 6 Nov 2012 09:08:43 +0000 (10:08 +0100)] 
esx: Yet another connection fix for 5.1

After the connection to ESX 5.1 being broken since g1e7cd39, the fix
in bab7752c helped a bit, but still missed a spot, so the connection
is now successful, but some APIs (for example defineXML) don't work.
Two cases missing are added in this patch to avoid that.
(cherry picked from commit 9c294e6f9a2ae23f4fbfc98d0dc2aec1ce9eba0b)

12 years agoqemu: Add controllers in specified order
Michal Privoznik [Mon, 5 Nov 2012 10:51:44 +0000 (11:51 +0100)] 
qemu: Add controllers in specified order

qemu is sensitive to the order of arguments passed. Hence, if a
device requires a controller, the controller cmd string must
precede device cmd string. The same apply for controllers, when
for instance ccid controller requires usb controller. So
controllers create partial ordering in which they should be added
to qemu cmd line.
(cherry picked from commit 0f720ab35a1a836aa23b66ef4bafbc5e57290357)

12 years agoqemu: Wrap controllers code into dummy loop
Michal Privoznik [Mon, 5 Nov 2012 10:42:51 +0000 (11:42 +0100)] 
qemu: Wrap controllers code into dummy loop

which just re-indent code and prepare it for next patch.
(cherry picked from commit 77b93dbc3e5fdffec60f631cd52c4dba0f2e0f29)

12 years agospec: replace scriptlets with new systemd macros
Václav Pavlín [Thu, 25 Oct 2012 10:10:55 +0000 (12:10 +0200)] 
spec: replace scriptlets with new systemd macros

https://bugzilla.redhat.com/850186

I added %with_systemd_macros so it should now work in F17 with old
scriptlets and in F18+/RHEL7+ with systemd macros
(see https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd)

I missed libvirt-guests.service because there is no systemctl call for
it. So I only added systemd macros calls.
(cherry picked from commit ec02d49dfd98313d1c8c4179e88754f10a82ca46)

12 years agoiohelper: Don't report errors on special FDs
Michal Privoznik [Mon, 5 Nov 2012 14:42:53 +0000 (15:42 +0100)] 
iohelper: Don't report errors on special FDs

Some FDs may not implement fdatasync() functionality,
e.g.  pipes. In that case EINVAL or EROFS is returned.
We don't want to fail then nor report any error.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
(cherry picked from commit 46325e51310344872597453ba5d621afa88d44c1)

12 years agoqemu: Fix possible race when pausing guest
Peter Krempa [Thu, 1 Nov 2012 14:45:47 +0000 (15:45 +0100)] 
qemu: Fix possible race when pausing guest

When pausing the guest while migration is running (to speed up
convergence) the virDomainSuspend API checks if the migration job is
active before entering the job. This could cause a possible race if the
virDomainSuspend is called while the job is active but ends before the
Suspend API enters the job (this would require that the migration is
aborted). This would cause a incorrect event to be emitted.
(cherry picked from commit d0fc6dc8315b3172501e6fe09c8aed12598de47e)

12 years agonet: Remove dnsmasq and radvd files also when destroying transient nets
Peter Krempa [Thu, 25 Oct 2012 14:13:57 +0000 (16:13 +0200)] 
net: Remove dnsmasq and radvd files also when destroying transient nets

The network driver didn't care about config files when a network was
destroyed, just when it was undefined leaving behind files for transient
networks.

This patch splits out the cleanup code to a helper function that handles
the cleanup if the inactive network object is being removed and re-uses
this code when getting rid of inactive networks.
(cherry picked from commit e87af617fc3e5a69fb19319d43f58262e5e624ea)

12 years agonet: Move creation of dnsmasq hosts file to function starting dnsmasq
Peter Krempa [Thu, 25 Oct 2012 12:41:28 +0000 (14:41 +0200)] 
net: Move creation of dnsmasq hosts file to function starting dnsmasq

The hosts file was created in the network definition function. This
patch moves the place the file is being created to the point where
dnsmasq is being started.
(cherry picked from commit 23ae3fe4256ba634babc6818b8cb7bbd3664a95a)

12 years agoconf: net: Fix deadlock if assignment of network def fails
Peter Krempa [Fri, 26 Oct 2012 12:33:13 +0000 (14:33 +0200)] 
conf: net: Fix deadlock if assignment of network def fails

When the assignment fails, the network object is not unlocked and next
call that would use it deadlocks.
(cherry picked from commit f8230891243f86e920d04a0751512cc31055ff8c)

12 years agoconf: net: Fix helper for applying new network definition
Peter Krempa [Thu, 25 Oct 2012 15:06:04 +0000 (17:06 +0200)] 
conf: net: Fix helper for applying new network definition

When there's no new definition the helper overwrote the old one with
NULL.
(cherry picked from commit 947230fb56325c86d318215a3e6c9cdb379dc966)

12 years agoLinux Containers are not allowed to create device nodes.
Dan Walsh [Thu, 1 Nov 2012 18:54:39 +0000 (14:54 -0400)] 
Linux Containers are not allowed to create device nodes.

This needs to be done before the container starts. Turning
off the mknod capability is noticed by systemd, which will
no longer attempt to create device nodes.

This eliminates SELinux AVC messages and ugly failure messages in the journal.
(cherry picked from commit 2e03b08ead603c38c244aa9a1ecef6d73bb306be)

12 years agonet-update docs: s/domain/network/
Michal Privoznik [Thu, 1 Nov 2012 14:51:28 +0000 (15:51 +0100)] 
net-update docs: s/domain/network/

A leftover from copy paste.
(cherry picked from commit d1236faa17581c8bf33ef20e71e7b7bba49423fc)

12 years agoiohelper: fdatasync() at the end
Michal Privoznik [Tue, 30 Oct 2012 18:15:48 +0000 (19:15 +0100)] 
iohelper: fdatasync() at the end

Currently, when we are doing (managed) save, we insert the
iohelper between the qemu and OS. The pipe is created, the
writing end is passed to qemu and the reading end to the
iohelper. It reads data and write them into given file. However,
with write() being asynchronous data may still be in OS
caches and hence in some (corner) cases, all migration data
may have been read and written (not physically though). So
qemu will report success, as well as iohelper. However, with
some non local filesystems, where ENOSPACE is polled every X
time units, we may get into situation where all operations
succeeded but data hasn't reached the disk. And in fact will
never do. Therefore we ought sync caches to make sure data
has reached the block device on remote host.
(cherry picked from commit f32e3a2dd686f3692cd2bd3147c03e90f82df987)

12 years agoqemu: Fix EmulatorPinInfo without emulatorpin
Martin Kletzander [Wed, 31 Oct 2012 14:49:08 +0000 (15:49 +0100)] 
qemu: Fix EmulatorPinInfo without emulatorpin

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

Recent fixes made almost all the right steps to make emulator pinned
to the cpuset of the whole domain in case <emulatorpin> isn't
specified, but qemudDomainGetEmulatorPinInfo still reports all the
CPUs even when cpuset is specified.  This patch fixes that.
(cherry picked from commit 10c5212b108e8395a6cab2dd449f2b1c0f1442d0)

12 years agobugfix: ip6tables rule removal
Gene Czarcinski [Tue, 30 Oct 2012 21:18:34 +0000 (17:18 -0400)] 
bugfix: ip6tables rule removal

Three FORWARD chain rules are added and two INPUT chain rules
are added when a network is started but only the FORWARD chain
rules are removed when the network is destroyed.
(cherry picked from commit adaa7ab653b0f841aa549e9f47f9e63ee1d15b37)

12 years agoCreate temporary dir for socket
Guido Günther [Mon, 29 Oct 2012 08:28:15 +0000 (09:28 +0100)] 
Create temporary dir for socket

to avoid ENAMETOOLONG:

https://buildd.debian.org/status/fetch.php?pkg=libvirt&arch=amd64&ver=1.0.0~rc1-1&stamp=1351453521
(cherry picked from commit 0e7fd31fb52482903ebd34764c065867d26f93b5)

12 years agoutil: do a better job of matching up pids with their binaries
Laine Stump [Mon, 29 Oct 2012 22:05:41 +0000 (18:05 -0400)] 
util: do a better job of matching up pids with their binaries

This patch resolves: https://bugzilla.redhat.com/show_bug.cgi?id=871201

If libvirt is restarted after updating the dnsmasq or radvd packages,
a subsequent "virsh net-destroy" will fail to kill the dnsmasq/radvd
process.

The problem is that when libvirtd restarts, it re-reads the dnsmasq
and radvd pidfiles, then does a sanity check on each pid it finds,
including checking that the symbolic link in /proc/$pid/exe actually
points to the same file as the path used by libvirt to execute the
binary in the first place. If this fails, libvirt assumes that the
process is no longer alive.

But if the original binary has been replaced, the link in /proc is set
to "$binarypath (deleted)" (it literally has the string " (deleted)"
appended to the link text stored in the filesystem), so even if a new
binary exists in the same location, attempts to resolve the link will
fail.

In the end, not only is the old dnsmasq/radvd not terminated when the
network is stopped, but a new dnsmasq can't be started when the
network is later restarted (because the original process is still
listening on the ports that the new process wants).

The solution is, when the initial "use stat to check for identical
inodes" check for identity between /proc/$pid/exe and $binpath fails,
to check /proc/$pid/exe for a link ending with " (deleted)" and if so,
truncate that part of the link and compare what's left with the
original binarypath.

A twist to this problem is that on systems with "merged" /sbin and
/usr/sbin (i.e. /sbin is really just a symlink to /usr/sbin; Fedora
17+ is an example of this), libvirt may have started the process using
one path, but /proc/$pid/exe lists a different path (indeed, on F17
this is the case - libvirtd uses /sbin/dnsmasq, but /proc/$pid/exe
shows "/usr/sbin/dnsmasq"). The further bit of code to resolve this is
to call virFileResolveAllLinks() on both the original binarypath and
on the truncated link we read from /proc/$pid/exe, and compare the
results.

The resulting code still succeeds in all the same cases it did before,
but also succeeds if the binary was deleted or replaced after it was
started.
(cherry picked from commit 7bafe009d93f8b26330d52dc3289643699cf74f0)

12 years agoqemu: pass -usb and usb hubs earlier, so USB disks with static address are handled...
Vladislav Bogdanov [Fri, 26 Oct 2012 09:09:22 +0000 (09:09 +0000)] 
qemu: pass -usb and usb hubs earlier, so USB disks with static address are handled properly
(cherry picked from commit 81af5336acf4c765ef1201e7762d003ae0b0011e)

Conflicts:
tests/qemuxml2argvdata/qemuxml2argv-bios.args
tests/qemuxml2argvdata/qemuxml2argv-disk-copy_on_read.args
tests/qemuxml2argvdata/qemuxml2argv-disk-ioeventfd.args
tests/qemuxml2argvdata/qemuxml2argv-event_idx.args
tests/qemuxml2argvdata/qemuxml2argv-hyperv.args
tests/qemuxml2argvdata/qemuxml2argv-virtio-lun.args

12 years agoqemu: Do not ignore address for USB disks
Vladislav Bogdanov [Fri, 26 Oct 2012 09:09:21 +0000 (09:09 +0000)] 
qemu: Do not ignore address for USB disks
(cherry picked from commit 8f708761c0d0e4eaf36bcb274d4f49fc3e0c3874)

12 years agoesx: Fix connection to ESX 5.1
Martin Kletzander [Tue, 30 Oct 2012 07:32:37 +0000 (08:32 +0100)] 
esx: Fix connection to ESX 5.1

After separating 5.x and 5.1 versions of ESX, we forgot to add 5.1
into the list of allowed connections, so connections to 5.1 fail since
v1.0.0-rc1-5-g1e7cd39
(cherry picked from commit bab7752c0c6e82139f704b83f381a4c34a7b0f39)

12 years agoconf: fix virDomainNetGetActualDirect*() and BridgeName()
Laine Stump [Mon, 3 Dec 2012 17:24:46 +0000 (12:24 -0500)] 
conf: fix virDomainNetGetActualDirect*() and BridgeName()

This resolves:

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

These three functions:

  virDomainNetGetActualBridgeName
  virDomainNetGetActualDirectDev
  virDomainNetGetActualDirectMode

return attributes that are in a union whose contents are interpreted
differently depending on the actual->type and so they should only
return non-0 when actual->type is 'bridge' (in the first case) or
'direct' (in the other two cases, but I had neglected to do that, so
...DirectDev() was returning bridge.brname (which happens to share the
same spot in the union with direct.linkdev) if actual->type was
'bridge', and ...BridgeName was returning direct.linkdev when
actual->type was 'direct'.

How does this involve Bug 881480 (which was about the inability to
switch between two networks that both have "<forward mode='bridge'/>
<bridge name='xxx'/>"? Whenever the return value of
virDomainNetGetActualDirectDev() for the new and old network
definitions doesn't match, qemuDomainChangeNet() requires a "complete
reconnect" of the device, which qemu currently doesn't
support. ...DirectDev() *should* have been returning NULL for old and
new, but was instead returning the old and new bridge names, which
differ.

(The other two functions weren't causing any behavioral problems in
virDomainChangeNet(), but their problem and fix was identical, so I
included them in this same patch).
(cherry picked from commit 3738cf41f1012eca419e8fa0fa0575cb1e0552e3)

12 years agonetwork: use dnsmasq --bind-dynamic when available
Laine Stump [Thu, 22 Nov 2012 02:21:02 +0000 (21:21 -0500)] 
network: use dnsmasq --bind-dynamic when available

This bug resolves CVE-2012-3411, which is described in the following
bugzilla report:

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

The following report is specifically for libvirt on Fedora:

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

In short, a dnsmasq instance run with the intention of listening for
DHCP/DNS requests only on a libvirt virtual network (which is
constructed using a Linux host bridge) would also answer queries sent
from outside the virtualization host.

This patch takes advantage of a new dnsmasq option "--bind-dynamic",
which will cause the listening socket to be setup such that it will
only receive those requests that actually come in via the bridge
interface. In order for this behavior to actually occur, not only must
"--bind-interfaces" be replaced with "--bind-dynamic", but also all
"--listen-address" options must be replaced with a single
"--interface" option. Fully:

   --bind-interfaces --except-interface lo --listen-address x.x.x.x ...

(with --listen-address possibly repeated) is replaced with:

   --bind-dynamic --interface virbrX

Of course libvirt can't use this new option if the host's dnsmasq
doesn't have it, but we still want libvirt to function (because the
great majority of libvirt installations, which only have mode='nat'
networks using RFC1918 private address ranges (e.g. 192.168.122.0/24),
are immune to this vulnerability from anywhere beyond the local subnet
of the host), so we use the new dnsmasqCaps API to check if dnsmasq
supports the new option and, if not, we use the "old" option style
instead. In order to assure that this permissiveness doesn't lead to a
vulnerable system, we do check for non-private addresses in this case,
and refuse to start the network if both a) we are using the old-style
options, and b) the network has a publicly routable IP
address. Hopefully this will provide the proper balance of not being
disruptive to those not practically affected, and making sure that
those who *are* affected get their dnsmasq upgraded.

(--bind-dynamic was added to dnsmasq in upstream commit
54dd393f3938fc0c19088fbd319b95e37d81a2b0, which was included in
dnsmasq-2.63)

12 years agoutil: new virSocketAddrIsPrivate function
Laine Stump [Thu, 22 Nov 2012 02:17:30 +0000 (21:17 -0500)] 
util: new virSocketAddrIsPrivate function

This new function returns true if the given address is in the range of
any "private" or "local" networks as defined in RFC1918 (IPv4) or
RFC3484/RFC4193 (IPv6), otherwise they return false.

These ranges are:

   192.168.0.0/16
   172.16.0.0/16
   10.0.0.0/24
   FC00::/7
   FEC0::/10

12 years agoutil: capabilities detection for dnsmasq
Laine Stump [Tue, 20 Nov 2012 17:22:15 +0000 (12:22 -0500)] 
util: capabilities detection for dnsmasq

In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.

This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.

bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.

networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.

12 years agoadd ppc64 and s390x to arches where qemu-kvm exists
Dan Horák [Fri, 16 Nov 2012 17:50:20 +0000 (18:50 +0100)] 
add ppc64 and s390x to arches where qemu-kvm exists

QEMU in Fedora >= 18 is configured with ppc64 and s390x as architectures
where KVM is enabled.

https://bugzilla.redhat.com/show_bug.cgi?id=872545
(cherry picked from commit 041b1ff26ac5bf569ca26049e85b8e73eb54c441)

12 years agoqemu: Always format CPU topology
Jiri Denemark [Tue, 16 Oct 2012 19:11:29 +0000 (21:11 +0200)] 
qemu: Always format CPU topology

When libvirt cannot find a suitable CPU model for host CPU (easily
reproducible by running libvirt in a guest), it would not provide CPU
topology in capabilities XML either. Even though CPU topology is known
and can be queried by virNodeGetInfo. With this patch, CPU topology will
always be provided in capabilities XML regardless on the presence of CPU
model.
(cherry picked from commit f1c70100409562c3f402392aa667732e5f89a2c4)

Conflicts:

    src/qemu/qemu_capabilities.c
    src/qemu/qemu_command.c

    The new code uses capabilities caching.

12 years agospec: don't enable cgconfig under systemd
Eric Blake [Mon, 5 Nov 2012 16:48:28 +0000 (09:48 -0700)] 
spec: don't enable cgconfig under systemd

In Fedora 16, we quit enabling cgconfig because systemd set up
default cgroups that were good enough for our use.  But in F17,
when we switched to systemd, we reverted and started up cgconfig
again.  See also the tail of this thread:
https://www.redhat.com/archives/libvir-list/2012-October/msg01657.html

* libvirt.spec.in (with_systemd): Rely on systemd for cgroups.
(cherry picked from commit b61eadf3c62be4dfa452e04bf851aa5f2e0acb4b)

12 years agoqemu: Fix name comparison in qemuMonitorJSONBlockIoThrottleInfo()
Stefan Hajnoczi [Thu, 1 Nov 2012 17:20:56 +0000 (18:20 +0100)] 
qemu: Fix name comparison in qemuMonitorJSONBlockIoThrottleInfo()

The string comparison logic was inverted and matched the first drive
that does *not* have the name we search for.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 23d47b33a2f8b524c32d556d6d55a7ccb0c5903a)

12 years agoqemu: Keep QEMU host drive prefix in BlkIoTune
Stefan Hajnoczi [Thu, 1 Nov 2012 17:20:55 +0000 (18:20 +0100)] 
qemu: Keep QEMU host drive prefix in BlkIoTune

The QEMU -drive id= begins with libvirt's QEMU host drive prefix
("drive-"), which is stripped off in several places two convert between
host ("-drive") and guest ("-device") device names.

In the case of BlkIoTune it is unnecessary to strip the QEMU host drive
prefix because we operate on "info block"/"query-block" output that uses
host drive names.

Stripping the prefix incorrectly caused string comparisons to fail since
we were comparing the guest device name against the host device name.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 04ee70bfda21bfdb48b55f074aed25fc75bb9226)

12 years agoPrep for release 0.10.2.1 v0.10.2.1
Cole Robinson [Sat, 27 Oct 2012 20:57:20 +0000 (16:57 -0400)] 
Prep for release 0.10.2.1

12 years agoqemu: Fix domxml-to-native network model conversion
Cole Robinson [Sun, 21 Oct 2012 02:28:34 +0000 (22:28 -0400)] 
qemu: Fix domxml-to-native network model conversion

https://bugzilla.redhat.com/show_bug.cgi?id=636832
(cherry picked from commit 9a2975786b74aa0fe75e3eadb39aa0f9b37e57bb)

12 years agoparallels: fix build for some older compilers
Laine Stump [Fri, 26 Oct 2012 17:23:56 +0000 (13:23 -0400)] 
parallels: fix build for some older compilers

Found this when building on RHEL5:

parallels/parallels_storage.c: In function 'parallelsStorageOpen':
parallels/parallels_storage.c:180: error: 'for' loop initial declaration used outside C99 mode

(and similar error in parallels_driver.c). This was in spite of
configuring with "-Wno-error".
(cherry picked from commit 73ebd86d7318960b22c3b0f1262cbbd770265c9c)

12 years agodocumentation: HTML tag fix
Philipp Hahn [Fri, 26 Oct 2012 08:38:02 +0000 (10:38 +0200)] 
documentation: HTML tag fix

Replace '%' by '&' for correct escaping of '>' in Domain specification.

Signed-off-by: Philipp Hahn <hahn@univention.de>
(cherry picked from commit 7083cdc7bd069c8dcfce8e3b1afb6af04f417086)

12 years agonetwork: fix networkValidate check for default portgroup and vlan
Laine Stump [Thu, 25 Oct 2012 15:13:52 +0000 (11:13 -0400)] 
network: fix networkValidate check for default portgroup and vlan

This was found during testing of the fix for:

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

networkValidate was supposed to check for the existence of multiple
portgroups and report an error if this was encountered. It did, but
there were two problems:

1) even though it logged an error, it still returned success, allowing
the operation to continue.

2) It could exit the portgroup checking loop early (or possibly not
even do it once) if a vlan tag was supplied in the base network config
or one of the portgroups.

This patch fixes networkValidate to return failure in addition to
logging the error, and also changes it to not exit the portgroup
checking loop early. The logic was a bit off in the checking for vlan
anyway, and it's intertwined with fixing the early loop exit, so I
fixed that as well. Now it correctly checks for combinations where a
<virtualport> is specified in the base network def and <vlan> is given
in a portgroup, as well as the opposite (<vlan> in base network def
and <virtualport> in portgroup), and ignores the case of a disallowed
vlan when using *no* portgroup if there is a default portgroup (since
in that case there is no way to not use any portgroup).
(cherry picked from commit d8aae15aa1ab173fd3c57f5806b6febae6b640af)

12 years agoesx: Update version checks for vSphere 5.1
Matthias Bolte [Wed, 24 Oct 2012 17:50:15 +0000 (19:50 +0200)] 
esx: Update version checks for vSphere 5.1

Also remove warnings for upcoming versions. There hadn't been any
compatibility problems with new ESX version over the whole lifetime
of the ESX driver, so I don't expect any in the future.

Update documentation to mention vSphere 5.x support.
(cherry picked from commit 1e7cd39511f023a0a1251ff5da1da262a8270be3)

12 years agoFix detection of Xen sysctl version 9
Jim Fehlig [Tue, 23 Oct 2012 17:18:20 +0000 (11:18 -0600)] 
Fix detection of Xen sysctl version 9

In commit 371ddc98, I mistakenly added the check for sysctl
version 9 after setting the hypercall version to 1, which will
fail with

error : xenHypervisorDoV1Op:967 : Unable to issue hypervisor
ioctl 3166208: Function not implemented

This check should be included along with the others that use
hypercall version 2.
(cherry picked from commit 9785f2b6f203ad5f153e68829b95f0e8c30a1560)