]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
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)

12 years agoselinux: Don't fail RestoreAll if file doesn't have a default label
Cole Robinson [Sat, 20 Oct 2012 19:57:28 +0000 (15:57 -0400)] 
selinux: Don't fail RestoreAll if file doesn't have a default label

When restoring selinux labels after a VM is stopped, any non-standard
path that doesn't have a default selinux label causes the process
to stop and exit early. This isn't really an error condition IMO.

Of course the selinux API could be erroring for some other reason
but hopefully that's rare enough to not need explicit handling.

Common example here is storing disk images in a non-standard location
like under /mnt.
(cherry picked from commit 767be8be7226abe9a242c812ba5ff28108d2955c)

12 years agostorage: don't shadow global 'wait' declaration
Ján Tomko [Tue, 23 Oct 2012 11:33:21 +0000 (13:33 +0200)] 
storage: don't shadow global 'wait' declaration

Rename the 'wait' parameter to 'loop'.
This silences the warning:
storage/storage_backend.c:1348:34: error: declaration of 'wait' shadows
a global declaration [-Werror=shadow]
and fixes the build with -Werror.
--
Note: loop is pool backwards.
(cherry picked from commit b326765c801ef5c291cbd9ab2c51b20128047b56)

12 years agoRemove a couple duplicates from AUTHORS.in
Cole Robinson [Mon, 22 Oct 2012 20:19:38 +0000 (16:19 -0400)] 
Remove a couple duplicates from AUTHORS.in
(cherry picked from commit 2e99fa0385eea0084c520b4a3798a8663fb11b7a)

12 years agostorage: Don't do wait loops from VolLookupByPath
Cole Robinson [Sun, 21 Oct 2012 16:53:20 +0000 (12:53 -0400)] 
storage: Don't do wait loops from VolLookupByPath

virStorageVolLookupByPath is an API call that virt-manager uses
quite a bit when dealing with storage. This call use BackendStablePath
which has several usleep() heuristics that can be tripped up
and hang virt-manager for a while.

Current example: an empty mpath pool pointing to /dev/mapper makes
_any_ calls to virStorageVolLookupByPath take 5 seconds.

The sleep heuristics are actually only needed in certain cases
when we are waiting for new storage to appear, so let's skip the
timeout steps when calling from LookupByPath.
(cherry picked from commit 77eff5eeb2d2aada3c670d325d04a35b54428988)

12 years agostorage: Add timeout for iscsi volume's stable path discovery
Osier Yang [Mon, 24 Sep 2012 08:44:20 +0000 (16:44 +0800)] 
storage: Add timeout for iscsi volume's stable path discovery

It might need some time till the LUN's stable path shows up on
initiator host, and although the time window is not foreseeable,
as a better than nothing fix, this patch adds timeout for the
stable path discovery process.
(cherry picked from commit de7f0774c34547776723378bf844ec5d0866bba3)

12 years agospec: Fix multilib issue with systemtap tapsets
Cole Robinson [Sun, 21 Oct 2012 02:46:58 +0000 (22:46 -0400)] 
spec: Fix multilib issue with systemtap tapsets

If building on a 64bit host, rename the affected tapsets to <name>-64.stp.
This is similar to what the python package does in fedora.

https://bugzilla.redhat.com/show_bug.cgi?id=831425
(cherry picked from commit 18d0632dc7c4b7c0930da32ed5a64f971c028452)

12 years agodocs: Fix installation of internals/*.html
Cole Robinson [Sun, 21 Oct 2012 00:29:47 +0000 (20:29 -0400)] 
docs: Fix installation of internals/*.html

We were just installing them in the top level html directory, which
broke navigation and overwrote other pages.

https://bugzilla.redhat.com/show_bug.cgi?id=837825
(cherry picked from commit 7146d41634b5a13ce148c2dc94838ff62bc7c1ed)

12 years agovirsh: Fix segfault of snapshot-list
Osier Yang [Mon, 22 Oct 2012 14:28:59 +0000 (22:28 +0800)] 
virsh: Fix segfault of snapshot-list

'snaps' is used after free()'ed.
(cherry picked from commit e0ad4669834d44763f7201ae97b997e9c64e8940)

12 years agodocs: virsh: clarify behavior of send-key
Cole Robinson [Sat, 20 Oct 2012 23:55:24 +0000 (19:55 -0400)] 
docs: virsh: clarify behavior of send-key

https://bugzilla.redhat.com/show_bug.cgi?id=860004
(cherry picked from commit 2143ced7f557db6486623c8ce0ca296aeb7b8392)

12 years agodaemon: Avoid 'Could not find keytab file' in syslog
Cole Robinson [Sat, 20 Oct 2012 18:10:03 +0000 (14:10 -0400)] 
daemon: Avoid 'Could not find keytab file' in syslog

On F17 at least, every time libvirtd starts we get this in syslog:

libvirtd: Could not find keytab file: /etc/libvirt/krb5.tab: No such file or directory

This comes from cyrus-sasl, and happens regardless of whether the
gssapi plugin is requested, which is what actually uses
/etc/libvirt/krb5.tab.

While cyrus-sasl shouldn't complain, we can easily make it shut up by
commenting out the keytab value by default.

Also update the keytab comment to the more modern one from qemu's
sasl config file.
(cherry picked from commit fe772f24a6809b3d937ed6547cbaa9d820e514b6)

12 years agonetwork: don't allow multiple default portgroups
Laine Stump [Sat, 20 Oct 2012 08:39:18 +0000 (04:39 -0400)] 
network: don't allow multiple default portgroups

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

virNetworkUpdate, virNetworkDefine, and virNetworkCreate all three
allow network definitions to contain multiple <portgroup> elements
with default='yes'. Only a single default portgroup should be allowed
for each network.

This patch updates networkValidate() (called by both
virNetworkCreate() and virNetworkDefine()) and
virNetworkDefUpdatePortGroup (called by virNetworkUpdate() to not
allow multiple default portgroups.
(cherry picked from commit 6f8a8b30c9a0123d8c6f49c946084b94c580811b)

12 years agonetwork: always create dnsmasq hosts and addnhosts files, even if empty
Laine Stump [Fri, 19 Oct 2012 20:15:44 +0000 (16:15 -0400)] 
network: always create dnsmasq hosts and addnhosts files, even if empty

This fixes the problem reported in:

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

Previously, the dnsmasq hosts file (used for static dhcp entries, and
addnhosts file (used for additional dns host entries) were only
created/referenced on the dnsmasq commandline if there was something
to put in them at the time the network was started. Once we can update
a network definition while it's active (which is now possible with
virNetworkUpdate), this is no longer a valid strategy - if there were
0 dhcp static hosts (resulting in no reference to the hosts file on the
commandline), then one was later added, the commandline wouldn't have
linked dnsmasq up to the file, so even though we create it, dnsmasq
doesn't pay any attention.

The solution is to just always create these files and reference them
on the dnsmasq commandline (almost always, anyway). That way dnsmasq
can notice when a new entry is added at runtime (a SIGHUP is sent to
dnsmasq by virNetworkUdpate whenever a host entry is added or removed)

The exception to this is that the dhcp static hosts file isn't created
if there are no lease ranges *and* no static hosts. This is because in
this case dnsmasq won't be setup to listen for dhcp requests anyway -
in that case, if the count of dhcp hosts goes from 0 to 1, dnsmasq
will need to be restarted anyway (to get it listening on the dhcp
port). Likewise, if the dhcp hosts count goes from 1 to 0 (and there
are no dhcp ranges) we need to restart dnsmasq so that it will stop
listening on port 67. These special situations are handled in the
bridge driver's networkUpdate() by checking for ((bool)
nranges||nhosts) both before and after the update, and triggering a
dnsmasq restart if the before and after don't match.
(cherry picked from commit 1cb1f9dabf8e9c9fc8dfadbb3097776ca5f2c68c)

12 years agonetwork: free/null newDef if network fails to start
Laine Stump [Fri, 19 Oct 2012 16:13:49 +0000 (12:13 -0400)] 
network: free/null newDef if network fails to start

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

pointed out a crash due to virNetworkObjAssignDef free'ing
network->newDef without NULLing it afterward. A fix for this is in
upstream commit b7e9202401ebaa039b8f05acdefda8c24081537a. While the
NULLing of newDef was a legitimate fix, newDef should have already
been empty (NULL) anyway (as indicated in the comment that was deleted
by that commit).

The reason that newDef had a non-NULL value (i.e. the root cause) was
that networkStartNetwork() had failed after populating
network->newDef, but then neglected to free/NULL newDef in the
cleanup.

(A bit of background here: network->newDef should contain the
persistent config of a network when a network is active (and of course
only when it is persisten), and NULL at all other times. There is also
a network->def which should contain the persistent definition of the
network when it is inactive, and the current live state at all other
times. The idea is that you can make changes to network->newDef which
will take effect the next time the network is restarted, but won't
mess with the current state of the network (virDomainObj has a similar
pair of virDomainDefs that behave in the same fashion). Personally I
think there should be a network->live and network->config, and the
location of the persistent config should *always* be in
network->config, but that's for a later cleanup).

Since I love things to be symmetric, I created a new function called
virNetworkObjUnsetDefTransient(), which reverses the effects of
virNetworkObjSetDefTransient(). I don't really like the name of the
new function, but then I also didn't really like the name of the old
one either (it's just named that way to match a similar function in
the domain conf code).
(cherry picked from commit 78fab2770b19097fe5e92ec339a9dd2d62d04bdb)

12 years agoAutogenerate AUTHORS
Cole Robinson [Fri, 12 Oct 2012 23:50:19 +0000 (19:50 -0400)] 
Autogenerate AUTHORS

AUTHORS.in tracks the maintainers, as well as some folks who were
previously in AUTHORS but don't have a git commit with proper
attribution.

Generated output is sorted alphabetically and lacks pretty spacing, so
tweak AUTHORS.in to follow the same format.

Additionally, drop the syntax-check rule that previously validated
AUTHORS against git log.
(cherry picked from commit 7b21981cdb4f5d6c492edb2face8a8159dcc212e)

Conflicts:
.mailmap
AUTHORS

12 years agobuild: avoid infinite autogen loop
Eric Blake [Mon, 1 Oct 2012 15:10:20 +0000 (09:10 -0600)] 
build: avoid infinite autogen loop

Several people have reported that if the .gnulib submodule is dirty,
then 'make' will go into an infinite loop attempting to rerun bootstrap,
because that never cleans up the dirty submodule.  By default, we
should halt and make the user investigate, but if the user doesn't
know why or care that the submodule is dirty, I also added the ability
to 'make CLEAN_SUBMODULE=1' to get things going again.

Also, while testing this, I noticed that when a submodule update was
needed, 'make' would first run autoreconf, then bootstrap (which
reruns autoreconf); adding a strategic dependency allows for less work.

* .gnulib: Update to latest, for maint.mk improvements.
* cfg.mk (_autogen): Also hook maint.mk, to run before autoreconf.
* autogen.sh (bootstrap): Refuse to run if gnulib is dirty, unless
user requests discarding gnulib changes.
(cherry picked from commit c5f162200c32a078fd68507f26a15f84f7d65e9e)

12 years agoselinux: relabel tapfd in qemuPhysIfaceConnect
Guannan Ren [Fri, 19 Oct 2012 08:44:30 +0000 (16:44 +0800)] 
selinux: relabel tapfd in qemuPhysIfaceConnect

Relabeling tapfd right after the tap device is created.
qemuPhysIfaceConnect is common function called both for static
netdevs and for hotplug netdevs.
(cherry picked from commit 4492ef7f485a7d42d84a714d2150e648b11e2740)

12 years agonetwork: Set to NULL after virNetworkDefFree()
Michal Privoznik [Thu, 18 Oct 2012 14:28:35 +0000 (16:28 +0200)] 
network: Set to NULL after virNetworkDefFree()

which frees all allocated memory but doesn't set the passed pointer to
NULL.  Therefore, we must do it ourselves. This is causing actual
libvirtd crash: Basically, when doing 'virsh net-edit' the newDef should
be dropped.  And the memory is freed, indeed. However, the pointer is
not set to NULL but kept instead. And the next duo of calls 'virsh
net-start' and 'virsh net-destroy' starts the disaster. The latter one
does the same as 'virsh destroy'; it sees that newDef is nonNULL so it
replaces def with newDef (which has been freed already as said a few
lines above). Therefore any subsequent call accessing def will hit the ground.
(cherry picked from commit b7e9202401ebaa039b8f05acdefda8c24081537a)

12 years agoselinux: remove unused variables in socket labelling
Guannan Ren [Wed, 17 Oct 2012 03:28:28 +0000 (11:28 +0800)] 
selinux: remove unused variables in socket labelling
(cherry picked from commit d37a3a1d6c6508f235965185453602ba310cc66e)

12 years agoselinux: fix wrong tapfd relablling
Guannan Ren [Wed, 17 Oct 2012 03:23:19 +0000 (11:23 +0800)] 
selinux: fix wrong tapfd relablling

It should relabel tapfd of virtual network of type VIR_DOMAIN_NET_TYPE_DIRECT
rather than VIR_DOMAIN_NET_TYPE_NETWORK and VIR_DOMAIN_NET_TYPE_BRIDGE
(commit ae368ebfcc4923d0b32e83d4ca96a6f599625785 introduced this bug)

Caution: The context of the two hunks is identical other than indentation.
Please be extremely cautious of where the patch gets applied.
(cherry picked from commit 89b63f0ad448a0442f4afc5489748e2cc829e527)

12 years agoselinux: Use raw contexts 2
Martin Kletzander [Mon, 15 Oct 2012 12:04:36 +0000 (14:04 +0200)] 
selinux: Use raw contexts 2

In commit 9674f2c637114fa6ac0680fe5658a41a62bb34a8, I forgot to change
selabel_lookup with the other functions, so this one-liner does exactly
that.
(cherry picked from commit 6676c1fc8fb297de998f96862cbe2396355b2777)

12 years agoselinux: add security selinux function to label tapfd
Guannan Ren [Mon, 15 Oct 2012 09:03:49 +0000 (17:03 +0800)] 
selinux: add security selinux function to label tapfd

BZ:https://bugzilla.redhat.com/show_bug.cgi?id=851981
When using macvtap, a character device gets first created by
kernel with name /dev/tapN, its selinux context is:
system_u:object_r:device_t:s0

Shortly, when udev gets notification when new file is created
in /dev, it will then jump in and relabel this file back to the
expected default context:
system_u:object_r:tun_tap_device_t:s0

There is a time gap happened.
Sometimes, it will have migration failed, AVC error message:
type=AVC msg=audit(1349858424.233:42507): avc:  denied  { read write } for
pid=19926 comm="qemu-kvm" path="/dev/tap33" dev=devtmpfs ino=131524
scontext=unconfined_u:system_r:svirt_t:s0:c598,c908
tcontext=system_u:object_r:device_t:s0 tclass=chr_file

This patch will label the tapfd device before qemu process starts:
system_u:object_r:tun_tap_device_t:MCS(MCS from seclabel->label)
(cherry picked from commit ae368ebfcc4923d0b32e83d4ca96a6f599625785)

12 years agoselinux: Use raw contexts
Martin Kletzander [Fri, 5 Oct 2012 14:41:22 +0000 (16:41 +0200)] 
selinux: Use raw contexts

We are currently able to work only with non-translated SELinux
contexts, but we are using functions that work with translated
contexts throughout the code.  This patch swaps all SELinux context
translation relative calls with their raw sisters to avoid parsing
problems.

The problems can be experienced with mcstrans for example.  The
difference is that if you have translations enabled (yum install
mcstrans; service mcstrans start), fgetfilecon_raw() will get you
something like 'system_u:object_r:virt_image_t:s0', whereas
fgetfilecon() will return 'system_u:object_r:virt_image_t:SystemLow'
that we cannot parse.

I was trying to confirm that the _raw variants were here since the dawn of
time, but the only thing I see now is that it was imported together in
the upstream repo [1] from svn, so before 2008.

Thanks Laurent Bigonville for finding this out.

[1] http://oss.tresys.com/git/selinux.git
(cherry picked from commit 9674f2c637114fa6ac0680fe5658a41a62bb34a8)

12 years agonetwork: fix dnsmasq/radvd binding to IPv6 on recent kernels
Benjamin Cama [Wed, 26 Sep 2012 19:02:20 +0000 (21:02 +0200)] 
network: fix dnsmasq/radvd binding to IPv6 on recent kernels

I hit this problem recently when trying to create a bridge with an IPv6
address on a 3.2 kernel: dnsmasq (and, further, radvd) would not bind to
the given address, waiting 20s and then giving up with -EADDRNOTAVAIL
(resp. exiting immediately with "error parsing or activating the config
file", without libvirt noticing it, BTW). This can be reproduced with (I
think) any kernel >= 2.6.39 and the following XML (to be used with
"virsh net-create"):

        <network>
          <name>test-bridge</name>
          <bridge name='testbr0' />
          <ip family='ipv6' address='fd00::1' prefix='64'>
          </ip>
        </network>

(it happens even when you have an IPv4, too)

The problem is that since commit [1] (which, ironically, was made to
“help IPv6 autoconfiguration”) the linux bridge code makes bridges
behave like “real” devices regarding carrier detection. This makes the
bridges created by libvirt, which are started without any up devices,
stay with the NO-CARRIER flag set, and thus prevents DAD (Duplicate
address detection) from happening, thus letting the IPv6 address flagged
as “tentative”. Such addresses cannot be bound to (see RFC 2462), so
dnsmasq fails binding to it (for radvd, it detects that "interface XXX
is not RUNNING", thus that "interface XXX does not exist, ignoring the
interface" (sic)). It seems that this behavior was enhanced somehow with
commit [2] by avoiding setting NO-CARRIER on empty bridges, but I
couldn't reproduce this behavior on my kernel. Anyway, with the “dummy
tap to set MAC address” trick, this wouldn't work.

To fix this, the idea is to get the bridge's attached device to be up so
that DAD can happen (deactivating DAD altogether is not a good idea, I
think). Currently, libvirt creates a dummy TAP device to set the MAC
address of the bridge, keeping it down. But even if we set this device
up, it is not RUNNING as soon as the tap file descriptor attached to it
is closed, thus still preventing DAD. So, we must modify the API a bit,
so that we can get the fd, keep the tap device persistent, run the
daemons, and close it after DAD has taken place. After that, the bridge
will be flagged NO-CARRIER again, but the daemons will be running, even
if not happy about the device's state (but we don't really care about
the bridge's daemons doing anything when no up interface is connected to
it).

Other solutions that I envisioned were:
      * Keeping the *-nic interface up: this would waste an fd for each
        bridge during all its life. May be acceptable, I don't really
        know.
      * Stop using the dummy tap trick, and set the MAC address directly
        on the bridge: it is possible since quite some time it seems,
        even if then there is the problem of the bridge not being
        RUNNING when empty, contrary to what [2] says, so this will need
        fixing (and this fix only happened in 3.1, so it wouldn't work
        for 2.6.39)
      * Using the --interface option of dnsmasq, but I saw somewhere
        that it's not used by libvirt for backward compatibility. I am
        not sure this would solve this problem, though, as I don't know
        how dnsmasq binds itself to it with this option.

This is why this patch does what's described earlier.

This patch also makes radvd start even if the interface is
“missing” (i.e. it is not RUNNING), as it daemonizes before binding to
it, and thus sometimes does it after the interface has been brought down
by us (by closing the tap fd), and then originally stops. This also
makes it stop yelling about it in the logs when the interface is down at
a later time.

[1]
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=1faa4356a3bd89ea11fb92752d897cff3a20ec0e
[2]
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=b64b73d7d0c480f75684519c6134e79d50c1b341
(cherry picked from commit db488c79173b240459c7754f38c3c6af9b432970)

12 years agoqemu: Clear async job when p2p migration fails early
Jiri Denemark [Wed, 17 Oct 2012 12:08:17 +0000 (14:08 +0200)] 
qemu: Clear async job when p2p migration fails early

When p2p migration fails early because qemuMigrationIsAllowed or
qemuMigrationIsSafe say migration should be cancelled, we fail to clear
the migration-out async job. As a result of that, further APIs called
for the same domain may fail with Timed out during operation: cannot
acquire state change lock.

Reported by Guido Winkelmann.
(cherry picked from commit 837993d845a32bb222959a84d1c03a0c47f785be)

12 years agostorage: lvm: lvcreate fails with allocation=0, don't do that
Cole Robinson [Wed, 17 Oct 2012 00:30:23 +0000 (20:30 -0400)] 
storage: lvm: lvcreate fails with allocation=0, don't do that

On F17 at least, this command fails:

$ sudo /usr/sbin/lvcreate --name sparsetest -L 0K --virtualsize 16384K vgvirt
  Unable to create new logical volume with no extents

Which is unfortunate since allocation=0 is what virt-manager tries to use
by default.

Rather than telling the user 'don't do that', let's just give them the
smallest allocation possible if alloc=0 is requested.

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

12 years agostorage: lvm: Don't overwrite lvcreate errors
Cole Robinson [Wed, 17 Oct 2012 00:25:41 +0000 (20:25 -0400)] 
storage: lvm: Don't overwrite lvcreate errors

Before:
$ sudo virsh vol-create-as --pool vgvirt sparsetest --capacity 16M --allocation 0
error: Failed to create vol sparsetest
error: internal error Child process (/usr/sbin/lvchange -aln vgvirt/sparsetest) unexpected exit status 5:   One or more specified logical volume(s) not found.

After:
$ sudo virsh vol-create-as --pool vgvirt sparsetest --capacity 16M --allocation 0
error: Failed to create vol sparsetest
error: internal error Child process (/usr/sbin/lvcreate --name sparsetest -L 0K --virtualsize 16384K vgvirt) unexpected exit status 5:   Unable to create new logical volume with no extents
(cherry picked from commit 01df6f2bff98d8fc68350ab90c212780ef9db67a)

12 years agospec: Add runtime requirement for libssh2
Peter Krempa [Tue, 16 Oct 2012 12:34:35 +0000 (14:34 +0200)] 
spec: Add runtime requirement for libssh2

libssh2 unfortunately doesn't support symbol versioning so RPM can't
figure out what version is needed for the currently installed libvirt
package. This patch adds a runtime requirement, so that the correct
version of libssh2 can be installed along with libvirt.
(cherry picked from commit cb4f41b8d0a2dc4258f1b097dff2ca2b34fbd086)

12 years agospec: Add support for libssh2 transport
Peter Krempa [Fri, 12 Oct 2012 14:50:42 +0000 (16:50 +0200)] 
spec: Add support for libssh2 transport

Libssh2 transport support was enabled lately but the spec file wasn't
updated to take this into account. This caused libvirt to be built
without libssh2 support in Red Hat based OSes.
(cherry picked from commit 1e25c54f66b46223e8e31843cec9a825fd02c735)

12 years agoconf: Fix crash with cleanup
Martin Kletzander [Tue, 16 Oct 2012 09:15:04 +0000 (11:15 +0200)] 
conf: Fix crash with cleanup

There was a crash possible when both <boot dev... and <boot
order... were specified due to virDomainDefParseBootXML() erroring out
before setting *tmp (which was free'd in cleanup).  As a fix, I
created this cleanup that uses one pointer for all the temporary
stored XPath strings and values, plus this pointer is correctly
initialized to NULL.
(cherry picked from commit 280b8c9e7c94db1decdca08d169c88554c09fa19)

12 years agoProperly parse (unsigned) long long
Guido Günther [Fri, 12 Oct 2012 23:05:40 +0000 (01:05 +0200)] 
Properly parse (unsigned) long long

This fixes problems on platforms where sizeof(long) != sizeof(long long)
like ia32.
(cherry picked from commit d78035d06aab73a76a82c525f41580cf986cce7b)

12 years agoCorrect name of domain/pm/suspend-to-mem in docs
Zeeshan Ali (Khattak) [Wed, 10 Oct 2012 19:44:35 +0000 (22:44 +0300)] 
Correct name of domain/pm/suspend-to-mem in docs
(cherry picked from commit 0ec6aebb6461b3d6ef71322114cf160ae2d3de19)

12 years agostorage: Report UUID/name consistently in driver errors
Cole Robinson [Mon, 8 Oct 2012 22:37:22 +0000 (18:37 -0400)] 
storage: Report UUID/name consistently in driver errors

Done with:

sed -i -e "s/no pool with matching uuid/no storage pool with matching uuid/g" src/storage/storage_driver.c
sed -i -e 's/"%s", _("no storage pool with matching uuid")/_("no storage pool with matching uuid %s"), obj->uuid/g' src/storage/storage_driver.c
sed -i -e 's/"%s", _("storage pool is not active")/_("storage pool '%s' is not active"), pool->def->name/g' src/storage/storage_driver.c

And a couple fixups before, during, and after, and a manual inspection
pass to make sure nothing was wonky.
(cherry picked from commit 3af8280baf2e706562ba55a8bdff788ffa40ee36)

12 years agoChange qemuSetSchedularParameters to use AFFECT_CURRENT
Daniel P. Berrange [Wed, 26 Sep 2012 11:14:42 +0000 (12:14 +0100)] 
Change qemuSetSchedularParameters to use AFFECT_CURRENT

When adding variants of parameter setting APIs which accepted
flags, the existing APIs were all adapted internally to pass
VIR_DOMAIN_AFFECT_CURRENT to the new API. The QEMU impl
qemuSetSchedularParameters was an exception, which instead
used VIR_DOMAIN_AFFECT_LIVE. Change this to match other
compatibility scenarios, so that calling

   virDomainSetSchedularParameters(dom, params, nparams);

Has the same semantics as

   virDomainSetSchedularParametersFlags(dom, params, nparams, 0);

And

   virDomainSetSchedularParametersFlags(dom, params, nparams, VIR_DOMAIN_AFFECT_CURRENT);

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

12 years agonodeinfo: Fully convert to new virReportError
Michal Privoznik [Tue, 9 Oct 2012 09:46:48 +0000 (11:46 +0200)] 
nodeinfo: Fully convert to new virReportError

With our latest s/[a-z]+ReportError/virReportError/ rewrite
(47ab34e2) we forgot to update arm part of the code.
(cherry picked from commit 84a8917b8a1b0d083564e9649269fdd6c0bb45a2)

12 years agoCall curl_global_init from virInitialize to avoid thread-safety issues
Matthias Bolte [Sat, 6 Oct 2012 18:09:20 +0000 (20:09 +0200)] 
Call curl_global_init from virInitialize to avoid thread-safety issues

curl_global_init is not thread-safe. curl_easy_init might call
curl_global_init when it was no called before. But curl_easy_init
can be called from different threads by the ESX driver. Therefore,
call curl_global_init from virInitialize to stop curl_easy_init from
calling it.

Reported by Benjamin Wang.
(cherry picked from commit 458c499841505c340a0774914998891b48985d39)

12 years agofix kvm_pv_eoi with kvmclock
Martin Kletzander [Mon, 8 Oct 2012 16:51:57 +0000 (18:51 +0200)] 
fix kvm_pv_eoi with kvmclock

When both kvmclock and kvm_pv_eoi are configured (either disabled or
enabled) libvirt will generate invalid CPU specification due to the
fact that even though kvmclock causes the CPU to be specified, it
doesn't set have_cpu flag to true (and the new kvm_pv_eoi as well).
This patch fixes the issue and adds a test exactly for that to show
that it is fixed correctly (and also to keep it that way in the future
of course).
(cherry picked from commit 5d692cc7143084d841de79888fc249040ff40061)

12 years agoesx: Disable libcurl's use of signals to fix a segfault
Matthias Bolte [Sat, 29 Sep 2012 20:16:30 +0000 (22:16 +0200)] 
esx: Disable libcurl's use of signals to fix a segfault

libcurl uses a SIGALRM in combination with sigsetjmp/siglongjmp to be
able to abort a DNS lookup when it takes too long. The problem with this
in a multi-threaded application is that the signal handler for SIGALRM
and the call to siglongjmp can be executed on a thread that is different
from the one that initially did the SIGALRM setup and the call to
sigsetjmp. In the reported case this triggered a segfault.

Disable libcurl's use of signals to avoid this situation. This has the
disadvantage of losing the ability to abort synchronous DNS lookups which
might result in libcurl getting stuck in a DNS lookup in the worst case.
When libcurl was build with an asynchronous DNS backend such as c-ares
then there is no problem because the timeout mechanism works without
signals here anyway.

Reported by Benjamin Wang.
(cherry picked from commit 0821ea6b3cf318a9fe4657d5cf77095f96154db8)

12 years agoS390: Buffer too small for large CPU numbers.
Viktor Mihajlovski [Fri, 5 Oct 2012 13:59:08 +0000 (15:59 +0200)] 
S390: Buffer too small for large CPU numbers.

The output buffer for virFileReadAll was too small for systems with
more than 30 CPUs which leads to a log entry and incorrect behavior.
The new size will be sufficient for the current
architectural limits.

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

12 years agospec: prefer canonical name of util-linux
Eric Blake [Thu, 4 Oct 2012 16:02:02 +0000 (10:02 -0600)] 
spec: prefer canonical name of util-linux

I noticed that in two places, we require util-linux, and in a third,
we require util-linux-ng.  On Fedora (I tested F15 through rawhide),
util-linux-ng is obsoleted by util-linux; on RHEL 6, util-linux
is obsoleted by util-linux-ng.  That is, on either platform, either
name will get you the correct package installed (where the preferred
name on fedora is util-linux, and on RHEL 6 is util-linux-ng).  But
on RHEL 5, there is no util-linux-ng

* libvirt.spec.in (Requires): Use util-linux, not util-linux-ng.
(cherry picked from commit a9087ad16dc23fc57de16017e05e85e26cf9813d)

12 years agodocs: fix links in migration.html TOC
Eric Blake [Thu, 4 Oct 2012 22:57:27 +0000 (16:57 -0600)] 
docs: fix links in migration.html TOC

Use of the wrong attribute name caused the table of contents to
be useless.  Fix suggested by Daniel P. Berrange.

* docs/migration.html.in: Use correct anchoring attribute.
(cherry picked from commit eeb8c924ce2ab21d3a4aa77d1de826cda4a274c7)

12 years agoCorrect checking of virStrcpyStatic() return value
Kyle Mestery [Wed, 3 Oct 2012 19:46:55 +0000 (15:46 -0400)] 
Correct checking of virStrcpyStatic() return value

Correct the check for the return value of virStrcpyStatic()
when copying port-profile names. Fixes Open vSwitch ports
which utilize port-profiles from network definitions.

Signed-off-by: Kyle Mestery <kmestery@cisco.com>
(cherry picked from commit 83aebf6de4e2902c621edcba65de1d1556bee454)

12 years agobuild: avoid -Wno-format on new-enough gcc
Eric Blake [Tue, 2 Oct 2012 14:37:00 +0000 (08:37 -0600)] 
build: avoid -Wno-format on new-enough gcc

Commit c579d6b added a sledgehammer to silence spurious warnings from
gcc 4.2, but in the process, it also silenced useful warnings from
gcc 4.3 through 4.5.  As a result, a bug slipped in to commit 0caccb58.

Tested with FreeBSD (gcc 4.2.1), RHEL 6.3 (gcc 4.4), and F17 (gcc 4.7.2),
where the former didn't trip on spurious warnings, and where the latter
two detected a revert of 2b804cf.

* m4/virt-compile-warnings.m4 (-Wno-format): Probe for the actual
spurious message, to once again allow gcc 4.4 to use -Wformat.
(cherry picked from commit 814a8deaa1529e1bc09b5c38e6cd625f9c2fed6b)

12 years agoqemu: Use proper agent entering function when freezing filesystems
Peter Krempa [Mon, 1 Oct 2012 15:58:29 +0000 (17:58 +0200)] 
qemu: Use proper agent entering function when freezing filesystems

When doing snapshots, the filesystem freeze function used the agent
entering function that expects the qemud_driver unlocked. This might
cause a deadlock of the qemu driver if the agent does not respond.

The only call path of this function has the qemud_driver locked, so this
patch changes the entering functions to those expecting the driver
locked.
(cherry picked from commit e0316b5ebd85ca7c20db9a3fe8f6062b4b5e051d)

12 years agolxc: Correctly report active cgroups
Michal Privoznik [Mon, 1 Oct 2012 12:22:42 +0000 (14:22 +0200)] 
lxc: Correctly report active cgroups

There was an inverted return value in lxcCgroupControllerActive().
The function assumes cgroups are active and do couple of checks
to prove that. If any of them fails, false is returned. Therefore,
at the end, after all checks are done we must return true, not false.
(cherry picked from commit 0dddd680c267eecfb0eeaa7b3a52f563089c6301)

12 years agobuild: fix bitmap conversion when !CPU_ALLOC
Eric Blake [Mon, 1 Oct 2012 23:00:58 +0000 (17:00 -0600)] 
build: fix bitmap conversion when !CPU_ALLOC

Commit f1a43a8 missed one side of an #if/#else.

* src/util/processinfo.c (virProcessInfoGetAffinity): Use correct
bitmap operation.
(cherry picked from commit 9038ac65dafde5a404daf0b416e1f8bf80af683a)

12 years agoAdd note about numeric domain names to manpage
Dave Allan [Mon, 1 Oct 2012 18:01:36 +0000 (14:01 -0400)] 
Add note about numeric domain names to manpage

Clarify that domains with numeric names can only be identified by
their domain id.
(cherry picked from commit 13c69cd0b446669dc53417cb5207c51167a9c14f)

12 years agobuild: default selinuxfs mount point to /sys/fs/selinux
Daniel J Walsh [Fri, 28 Sep 2012 18:11:43 +0000 (14:11 -0400)] 
build: default selinuxfs mount point to /sys/fs/selinux

Currently if you build on a machine that does not support SELinux we end up
with the default mount point being /selinux, since this is moved to
/sys/fs/selinux, we should start defaulting there.

I believe this is causing a bug in libvirt-lxc when /selinux does not exists,
even though /sys/fs/selinux exists.
(cherry picked from commit aa696e1846c9ddfcc25654dc4ea8762df4fd38ab)

12 years agoARMHF: implement /proc/cpuinfo parsing
Chuck Short [Thu, 26 Jul 2012 13:32:07 +0000 (08:32 -0500)] 
ARMHF: implement /proc/cpuinfo parsing

Minimal CPU "parser" for armhf to avoid compile time warning.

Signed-off-by: Chuck Short <chuck.short@canonical.com>
(cherry picked from commit 2d0a777b3dc16cd85eac95d7b52c36b16c7a1d2c)

12 years agopython: return error if PyObject obj is NULL for unwrapper helper functions
Guannan Ren [Wed, 26 Sep 2012 17:33:50 +0000 (01:33 +0800)] 
python: return error if PyObject obj is NULL for unwrapper helper functions

The result is indeterminate for NULL argument to python
functions as follows. It's better to return negative value in
these situations.

PyObject_IsTrue will segfault if the argument is NULL
PyFloat_AsDouble(NULL) is -1.000000
PyLong_AsUnsignedLongLong(NULL) is 0.000000
(cherry picked from commit 4c6be02a3e502027a819e20b6f5add8f63c20291)

12 years agoFix compilation of legacy xen driver with Xen 4.2
Jim Fehlig [Wed, 26 Sep 2012 21:20:35 +0000 (15:20 -0600)] 
Fix compilation of legacy xen driver with Xen 4.2

In Xen 4.2, xs.h is deprecated in favor of xenstore.h.  xs.h now
contains

#warning xs.h is deprecated use xenstore.h instead
#include <xenstore.h>

which fails compilation when warnings are treated as errors.

Introduce a configure-time check for xenstore.h and if found,
use it instead of xs.h.
(cherry picked from commit 416eca189b1934cfa8575ab72d142ec77600fcf9)

12 years agoFix handling of itanium arch name in QEMU driver
Daniel P. Berrange [Wed, 26 Sep 2012 12:48:31 +0000 (13:48 +0100)] 
Fix handling of itanium arch name in QEMU driver

For historical compat we use 'itanium' as the arch name, so
if the QEMU binary suffix is 'ia64' we need to translate it

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

12 years agoFix potential deadlock when agent is closed
Daniel P. Berrange [Wed, 26 Sep 2012 15:23:24 +0000 (16:23 +0100)] 
Fix potential deadlock when agent is closed

If the qemuAgentClose method is called from a place which holds
the domain lock, it is theoretically possible to get a deadlock
in the agent destroy callback. This has not been observed, but
the equivalent code in the QEMU monitor destroy callback has seen
a deadlock.

Remove the redundant locking while unrefing the object and the
bogus assignment

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

12 years agoFix (rare) deadlock in QEMU monitor callbacks
Daniel P. Berrange [Wed, 26 Sep 2012 14:54:58 +0000 (15:54 +0100)] 
Fix (rare) deadlock in QEMU monitor callbacks

Some users report (very rarely) seeing a deadlock in the QEMU
monitor callbacks

 Thread 10 (Thread 0x7fcd11e20700 (LWP 26753)):
 #0  0x00000030d0e0de4d in __lll_lock_wait () from /lib64/libpthread.so.0
 #1  0x00000030d0e09ca6 in _L_lock_840 () from /lib64/libpthread.so.0
 #2  0x00000030d0e09ba8 in pthread_mutex_lock () from /lib64/libpthread.so.0
 #3  0x00007fcd162f416d in virMutexLock (m=<optimized out>)
     at util/threads-pthread.c:85
 #4  0x00007fcd1632c651 in virDomainObjLock (obj=<optimized out>)
     at conf/domain_conf.c:14256
 #5  0x00007fcd0daf05cc in qemuProcessHandleMonitorDestroy (mon=0x7fcccc0029e0,
     vm=0x7fcccc00a850) at qemu/qemu_process.c:1026
 #6  0x00007fcd0db01710 in qemuMonitorDispose (obj=0x7fcccc0029e0)
     at qemu/qemu_monitor.c:249
 #7  0x00007fcd162fd4e3 in virObjectUnref (anyobj=<optimized out>)
     at util/virobject.c:139
 #8  0x00007fcd0db027a9 in qemuMonitorClose (mon=<optimized out>)
     at qemu/qemu_monitor.c:860
 #9  0x00007fcd0daf61ad in qemuProcessStop (driver=driver@entry=0x7fcd04079d50,
     vm=vm@entry=0x7fcccc00a850,
     reason=reason@entry=VIR_DOMAIN_SHUTOFF_DESTROYED, flags=flags@entry=0)
     at qemu/qemu_process.c:4057
 #10 0x00007fcd0db323cf in qemuDomainDestroyFlags (dom=<optimized out>,
     flags=<optimized out>) at qemu/qemu_driver.c:1977
 #11 0x00007fcd1637ff51 in virDomainDestroyFlags (
     domain=domain@entry=0x7fccf00c1830, flags=1) at libvirt.c:2256

At frame #10 we are holding the domain lock, we call into
qemuProcessStop() to cleanup QEMU, which triggers the monitor
to close, which invokes qemuProcessHandleMonitorDestroy() which
tries to obtain the domain lock again. This is a non-recursive
lock, hence hang.

Since qemuMonitorPtr is a virObject, the unref call in
qemuProcessHandleMonitorDestroy no longer needs mutex
protection. The assignment of priv->mon = NULL, can be
instead done by the caller of qemuMonitorClose(), thus
removing all need for locking.

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

12 years agoDon't skip over socket label cleanup
Daniel P. Berrange [Wed, 26 Sep 2012 14:46:47 +0000 (15:46 +0100)] 
Don't skip over socket label cleanup

If QEMU quits immediately after we opened the monitor it was
possible we would skip the clearing of the SELinux process
socket context

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

12 years agoDon't ignore return value of qemuProcessKill
Daniel P. Berrange [Thu, 27 Sep 2012 09:07:03 +0000 (10:07 +0100)] 
Don't ignore return value of qemuProcessKill

When calling qemuProcessKill from the virDomainDestroy impl
in QEMU, do not ignore the return value. This ensures that
if QEMU fails to respond to SIGKILL, the caller will know
about the failure.

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

12 years agoFix deadlock in handling EOF in LXC monitor
Daniel P. Berrange [Wed, 26 Sep 2012 14:08:20 +0000 (15:08 +0100)] 
Fix deadlock in handling EOF in LXC monitor

Depending on the scenario in which LXC containers exit, it is
possible for the EOF callback of the LXC monitor to deadlock
the driver.

  #0  0x00000038a0a0de4d in __lll_lock_wait () from /lib64/libpthread.so.0
  #1  0x00000038a0a09ca6 in _L_lock_840 () from /lib64/libpthread.so.0
  #2  0x00000038a0a09ba8 in pthread_mutex_lock () from /lib64/libpthread.so.0
  #3  0x00007f4bd9579d55 in virMutexLock (m=<optimized out>) at util/threads-pthread.c:85
  #4  0x00007f4bcacc7597 in lxcDriverLock (driver=0x7f4bc40c8290) at lxc/lxc_conf.h:81
  #5  virLXCProcessMonitorEOFNotify (mon=<optimized out>, vm=0x7f4bb4000b00) at lxc/lxc_process.c:581
  #6  0x00007f4bd9645c91 in virNetClientCloseLocked (client=client@entry=0x7f4bb4009e60)
      at rpc/virnetclient.c:554
  #7  0x00007f4bd96460f8 in virNetClientIOEventLoopPassTheBuck (thiscall=0x0, client=0x7f4bb4009e60)
      at rpc/virnetclient.c:1306
  #8  virNetClientIOEventLoopPassTheBuck (client=0x7f4bb4009e60, thiscall=0x0)
      at rpc/virnetclient.c:1287
  #9  0x00007f4bd96467a2 in virNetClientCloseInternal (reason=3, client=0x7f4bb4009e60)
      at rpc/virnetclient.c:589
  #10 virNetClientCloseInternal (client=0x7f4bb4009e60, reason=3) at rpc/virnetclient.c:561
  #11 0x00007f4bcacc4a82 in virLXCMonitorClose (mon=0x7f4bb4000a00) at lxc/lxc_monitor.c:201
  #12 0x00007f4bcacc55ac in virLXCProcessCleanup (reason=<optimized out>, vm=0x7f4bb4000b00,
      driver=0x7f4bc40c8290) at lxc/lxc_process.c:240
  #13 virLXCProcessStop (driver=0x7f4bc40c8290, vm=vm@entry=0x7f4bb4000b00,
      reason=reason@entry=VIR_DOMAIN_SHUTOFF_DESTROYED) at lxc/lxc_process.c:735
  #14 0x00007f4bcacc5bd2 in virLXCProcessAutoDestroyDom (payload=<optimized out>,
      name=0x7f4bb4003c80, opaque=0x7fff41af2df0) at lxc/lxc_process.c:94
  #15 0x00007f4bd9586649 in virHashForEach (table=0x7f4bc409b270,
      iter=iter@entry=0x7f4bcacc5ab0 <virLXCProcessAutoDestroyDom>, data=data@entry=0x7fff41af2df0)
      at util/virhash.c:514
  #16 0x00007f4bcacc52d7 in virLXCProcessAutoDestroyRun (driver=driver@entry=0x7f4bc40c8290,
      conn=conn@entry=0x7f4bb8000ab0) at lxc/lxc_process.c:120
  #17 0x00007f4bcacca628 in lxcClose (conn=0x7f4bb8000ab0) at lxc/lxc_driver.c:128
  #18 0x00007f4bd95e67ab in virReleaseConnect (conn=conn@entry=0x7f4bb8000ab0) at datatypes.c:114

When the driver calls virLXCMonitorClose, there is really no
need for the EOF callback to be invoked in this case, since
the caller can easily handle events itself. In changing this,
the monitor needs to take a deep copy of the callback list,
not merely a reference.

Also adds debug statements in various places to aid
troubleshooting

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

12 years agoSupport Xen sysctl version 9 in Xen 4.2
Jim Fehlig [Wed, 26 Sep 2012 16:34:17 +0000 (10:34 -0600)] 
Support Xen sysctl version 9 in Xen 4.2

Xen upstream c/s 24102:dc8e55c9 bumped the sysctl version to 9.
Support this sysctl version in the xen_hypervisor sub-driver.
(cherry picked from commit 371ddc98664cbbd8542593e5452115ea7918dae2)

12 years agobuild: avoid older gcc warning
Eric Blake [Wed, 26 Sep 2012 17:16:36 +0000 (11:16 -0600)] 
build: avoid older gcc warning

Jim Fehlig reported a compilation error with older gcc 4.3.4:

libvirt.c: In function 'virDomainGetEmulatorPinInfo':
libvirt.c:9111: error: logical '&&' with non-zero constant will always evaluate as true [-Wlogical-op]

It looks like someone programmed via too much copy-and-paste.

* src/libvirt.c (virDomainGetEmulatorPinInfo): Multiplying by 1 is
a no-op, and thus will never overflow.
(cherry picked from commit 3da355e8c418c6db4023cc35512c7f47a78851ce)

12 years agoparallels: don't give null pointers to virBitmapEqual
Dmitry Guryanov [Wed, 26 Sep 2012 12:30:02 +0000 (16:30 +0400)] 
parallels: don't give null pointers to virBitmapEqual

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
(cherry picked from commit adae5cf733b19c77db137ff6f6e1e0c9524d23dc)

12 years agoparallels: fix memory allocation
Dmitry Guryanov [Wed, 26 Sep 2012 12:30:00 +0000 (16:30 +0400)] 
parallels: fix memory allocation

size of videos array must be increased.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
(cherry picked from commit 9ca569dedff55451070be58362747cf6ea3d800d)

12 years agoDon't use O_TRUNC when opening QEMU logfiles
Daniel P. Berrange [Fri, 21 Sep 2012 09:37:53 +0000 (10:37 +0100)] 
Don't use O_TRUNC when opening QEMU logfiles

SELinux wants all log files opened with O_APPEND. When
running non-root though, libvirtd likes to use O_TRUNC
to avoid log files growing in size indefinitely. Instead
of using O_TRUNC though, we can use O_APPEND and then
call ftruncate() which keeps SELinux happier.

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

12 years agoSimplify some redundant locking while unref'ing objects
Daniel P. Berrange [Mon, 24 Sep 2012 14:19:34 +0000 (15:19 +0100)] 
Simplify some redundant locking while unref'ing objects

There is no need to hold the mutex when unref'ing
virObject instances

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

12 years agoRemove pointless virLXCProcessMonitorDestroy method
Daniel P. Berrange [Mon, 24 Sep 2012 14:13:10 +0000 (15:13 +0100)] 
Remove pointless virLXCProcessMonitorDestroy method

Asynchronously setting priv->mon to NULL was pointless,
just remove the destroy callback entirely.

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

12 years agoConvert virLXCMonitor to use virObject
Daniel P. Berrange [Fri, 21 Sep 2012 14:09:42 +0000 (15:09 +0100)] 
Convert virLXCMonitor to use virObject

Remove custom reference counting from virLXCMonitor, using
virObject instead

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

12 years agoMove virProcess{Kill,Abort,TranslateStatus} into virprocess.{c,h}
Daniel P. Berrange [Mon, 24 Sep 2012 17:10:37 +0000 (18:10 +0100)] 
Move virProcess{Kill,Abort,TranslateStatus} into virprocess.{c,h}

Continue consolidation of process functions by moving some
helpers out of command.{c,h} into virprocess.{c,h}

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

12 years agoMove virProcessKill into virprocess.{h,c}
Daniel P. Berrange [Mon, 24 Sep 2012 16:54:51 +0000 (17:54 +0100)] 
Move virProcessKill into virprocess.{h,c}

There are a number of process related functions spread
across multiple files. Start to consolidate them by
creating a virprocess.{c,h} file

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

12 years agoRename virCommandTranslateStatus to virProcessTranslateStatus
Daniel P. Berrange [Mon, 24 Sep 2012 17:01:26 +0000 (18:01 +0100)] 
Rename virCommandTranslateStatus to virProcessTranslateStatus

The virCommand prefix was inappropriate because the API
does not use any virCommandPtr object instance. This
API closely related to waitpid/exit, so use virProcess
as the prefix

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

12 years agoRename virPid{Abort,Wait} to virProcess{Abort,Wait}
Daniel P. Berrange [Mon, 24 Sep 2012 16:59:31 +0000 (17:59 +0100)] 
Rename virPid{Abort,Wait} to virProcess{Abort,Wait}

Change "Pid" to "Process" to align with the virProcessKill
API naming prefix

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

12 years agoRename virKillProcess to virProcessKill
Daniel P. Berrange [Mon, 24 Sep 2012 15:29:20 +0000 (16:29 +0100)] 
Rename virKillProcess to virProcessKill

Changing naming to follow the convention of "object" followed
by "action"

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

12 years agoFix start of containers with custom root filesystem
Daniel P. Berrange [Tue, 25 Sep 2012 15:24:10 +0000 (16:24 +0100)] 
Fix start of containers with custom root filesystem

A prefix change to unmount the SELinux filesystem broke starting
of LXC containers with a custom root filesystem
(cherry picked from commit 1532bd498a879494bb1e4757a54fce796eab368c)

12 years agoUpdate how to compile with -Werror
Doug Goldstein [Mon, 24 Sep 2012 23:44:34 +0000 (18:44 -0500)] 
Update how to compile with -Werror

--enable-compile-warnings=error has been renamed to --enable-werror so
update the HACKING and the hacking.html to reflect that.
(cherry picked from commit 07cbb610ba6c116af6c81c2b53fa74f4fe1e5aba)

12 years agobuild: fix detection of netcf linked with libnl1
Christophe Fergeau [Wed, 19 Sep 2012 15:00:55 +0000 (17:00 +0200)] 
build: fix detection of netcf linked with libnl1

Commit 9298bfbcb introduced code to detect if netcf is linked with
libnl1, and to prefer libnl1 over libnl3 when this is the case.
This behaviour can be disabled by setting LIBNL_CFLAGS to any value,
including the empty string.
However, configure.ac sets LIBNL_CFLAGS to "" before attempting
libnl detection, so the libnl1 detection code is always disabled.
This caused issues on my f17 system where netcf is linked with libnl1
but libvirt got built with libnl3.

This commit removes the setting of the LIBNL_* variables to "" as
this does not appear to be needed. After this change, libnl1 is
used when building libvirt on my f17 system.
(cherry picked from commit f6c295156672fe15b32d2baddb68957bb7bddd8e)

12 years agocommand: Change virCommandAddEnv so it replaces existing environment variables.
Richard W.M. Jones [Mon, 24 Sep 2012 16:35:47 +0000 (17:35 +0100)] 
command: Change virCommandAddEnv so it replaces existing environment variables.
(cherry picked from commit 2b32735af480055e27400068d27364d521071117)

12 years agocommand: Move environ-adding code to common function virCommandAddEnv.
Richard W.M. Jones [Mon, 24 Sep 2012 16:30:18 +0000 (17:30 +0100)] 
command: Move environ-adding code to common function virCommandAddEnv.

This is just code motion.  The semantics of the code should be
identical after this change.
(cherry picked from commit f644361b1eeb78fd59be4cd7ec85567bbf300506)

12 years agoRelease of libvirt-0.10.2 v0.10.2
Daniel Veillard [Mon, 24 Sep 2012 04:06:05 +0000 (12:06 +0800)] 
Release of libvirt-0.10.2

* configure.ac docs/news.html.in libvirt.spec.in: update for the release
* po/*.po*: update from transifex and regenerate

12 years agoFix another rpmbuild failure
Daniel Veillard [Mon, 24 Sep 2012 04:41:56 +0000 (12:41 +0800)] 
Fix another rpmbuild failure

without systemd we should not try to package the non-installed
%{_sysconfdir}/rc.d/init.d/libvirtd

12 years agoFix an rpmbuild failure
Daniel Veillard [Mon, 24 Sep 2012 04:37:02 +0000 (12:37 +0800)] 
Fix an rpmbuild failure

$RPM_BUILD_ROOT was embedded in /etc/rc.d/init.d/libvirt-guests

12 years agoDon't install legacy initscripts at same time as systemd ones
Daniel P. Berrange [Fri, 21 Sep 2012 10:24:31 +0000 (11:24 +0100)] 
Don't install legacy initscripts at same time as systemd ones

The Fedora policies don't want us installing the legacy initscripts
in parallel with the systemd ones, so switch to only install the
systemd unit

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agonetwork: log error for unknown virNetworkUpdate command codes
Laine Stump [Fri, 21 Sep 2012 16:11:51 +0000 (12:11 -0400)] 
network: log error for unknown virNetworkUpdate command codes

Every level of the code for virNetworkUpdate was assuming that some
other level was checking for validity of the "command" arg, but none
actually were. The result was that an invalid command code would do
nothing, but also report success.

Since the command code isn't used until the very lowest level backend
functions, that's where I put the check. I made a separate one-line
function to log the error. The compiler would have combined the
identical strings used by multiple calls if I'd just called
virReportError directly in each location, but sending them all to the
same string in the source guards against inadvertant divergence (which
would lead to extra work for translators.)

12 years agonetwork: make virNetworkObjUpdate error detection/recovery better
Laine Stump [Fri, 21 Sep 2012 18:48:17 +0000 (14:48 -0400)] 
network: make virNetworkObjUpdate error detection/recovery better

1) virNetworkObjUpdate should be an all or none operation, but in the
case that we want to update both the live state and persistent config
versions of the network, it was committing the update to the live
state before starting to update the persistent config. If update of
the persistent config failed, we would leave with things in an
inconsistent state - the live state would be updated (even though an
error was returned), but persistent config unchanged.

This patch changed virNetworkObjUpdate to use a separate pointer for
each copy of the virNetworkDef, and not commit either of them in the
virNetworkObj until both live and config parts of the update have
successfully completed.

2) The parsers for various pieces of the virNetworkDef have all sorts
of subtle limitations on them that may not be known by the
Update[section] function, making it possible for one of these
functions to make a modification directly to the object that may not
pass the scrutiny of a subsequent parse. But normally another parse
wouldn't be done on the data until the *next* time the object was
updated (which could leave the network definition in an unusable
state).

Rather than fighting the losing battle of trying to duplicate all the
checks from the parsers into the update functions as well, the more
foolproof solution to this is to simply do an extra
virNetworkDefCopy() operation on the updated networkdef -
virNetworkDefCopy() does a virNetworkFormat() followed by a
virNetworkParseString(), so it will do all the checks we need. If this
fails, then we don't commit the changed def.

12 years agonetwork: don't "refresh" iptables rules on rule-less networks
Laine Stump [Fri, 21 Sep 2012 19:28:11 +0000 (15:28 -0400)] 
network: don't "refresh" iptables rules on rule-less networks

The bridge driver implementation of virNetworkUpdate() removes and
re-adds iptables rules any time a network has an <ip>, <forward>, or
<forward>/<interface> element updated. There are some types of
networks that have those elements and yet have no iptables rules
associated with them, and unfortunately the functions that remove/add
iptables rules don't check the type of network before attempting to
remove/add the rules, sometimes leading to an erroneous failure of the
entire update operation.

Under normal circumstances I would refactor the lower level functions
to be more robust, but to avoid code churn as much as possible, I've
just added extra checks directly to networkUpdate().

12 years agoDrop unused return value of virLogOutputFunc
Miloslav Trmač [Thu, 20 Sep 2012 18:24:00 +0000 (20:24 +0200)] 
Drop unused return value of virLogOutputFunc

Nothing uses the return value, and creating it requries otherwise
unnecessary strlen () calls.

This cleanup is conceptually independent from the rest of the series
(although the later patches won't apply without it).  This just seems
a good opportunity to clean this up, instead of entrenching the unnecessary
return value in the virLogOutputFunc instance that will be added in this
series.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>