]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agoopenvz: determine kb/pages only once
Guido Günther [Mon, 7 May 2012 21:00:28 +0000 (23:00 +0200)]
openvz: determine kb/pages only once

to save some syscalls (as suggested by Eric Blake)

12 years agolibvirt-guests: Remove LISTFILE if it's empty when stopping service
Osier Yang [Tue, 15 May 2012 08:22:28 +0000 (16:22 +0800)]
libvirt-guests: Remove LISTFILE if it's empty when stopping service

$LISTFILE is created even no domain is running, and the empty
$LISTFILE could cause improper service status.

    stopped ,with saved guests

Which is not right, as there is no domain was saved.

12 years agonodeinfo: Get the correct CPU number on AMD Magny Cours platform
Osier Yang [Mon, 14 May 2012 13:12:53 +0000 (21:12 +0800)]
nodeinfo: Get the correct CPU number on AMD Magny Cours platform

"Instead of developing one CPU with 12 cores, the Magny Cours is
actually two 6 core “Bulldozer” CPUs combined in to one package"

I.e, each package has two NUMA nodes, and the two numa nodes share
the same core ID set (0-6), which means parsing the cores number
from sysfs doesn't work in this case.

And the wrong CPU number could cause three problems for libvirt:

1) performance lost

  A domain without "cpuset" or "placement='auto'" (to drive numad)
specified will be only pinned to part of the CPUs.

2) domain can be started

  If a domain uses numad, and the advisory nodeset returned from
numad contains node which exceeds the range of wrong total CPU
number. The domain will fail to start, as the bitmask passed to
sched_setaffinity could be fully filled with zero.

3) wrong CPU number affects lots of stuffs.

  E.g. for command "virsh vcpuinfo", "virsh vcpupin", it will always
output with the truncated CPU list.

For more details:

https://www.redhat.com/archives/libvir-list/2012-May/msg00607.html

This patch is to fix the problem by parsing /proc/cpuinfo to get
the value of field "cpu cores", and use it as nodeinfo->cores if
it's greater than the cores number from sysfs.

12 years agoqemu: Set memory policy using cgroup if placement is auto
Osier Yang [Sat, 12 May 2012 12:53:15 +0000 (20:53 +0800)]
qemu: Set memory policy using cgroup if placement is auto

Like for 'static' placement, when the memory policy mode is
'strict', set the memory policy by writing the advisory nodeset
returned from numad to cgroup file cpuset.mems,

12 years agoqemu: Use the CPU index in capabilities to map NUMA node to cpu list.
Osier Yang [Sat, 12 May 2012 12:52:45 +0000 (20:52 +0800)]
qemu: Use the CPU index in capabilities to map NUMA node to cpu list.

On some of the NUMA platforms, the CPU index in each NUMA node
grows non-consecutive. While on other platforms, it can be inconsecutive,
E.g.

% numactl --hardware
available: 4 nodes (0-3)
node 0 cpus: 0 4 8 12 16 20 24 28
node 0 size: 131058 MB
node 0 free: 86531 MB
node 1 cpus: 1 5 9 13 17 21 25 29
node 1 size: 131072 MB
node 1 free: 127070 MB
node 2 cpus: 2 6 10 14 18 22 26 30
node 2 size: 131072 MB
node 2 free: 127758 MB
node 3 cpus: 3 7 11 15 19 23 27 31
node 3 size: 131072 MB
node 3 free: 127226 MB
node distances:
node   0   1   2   3
  0:  10  20  20  20
  1:  20  10  20  20
  2:  20  20  10  20
  3:  20  20  20  10

This patch is to fix the problem by using the CPU index in
caps->host.numaCell[i]->cpus[i] to set the bitmask instead of
assuming the CPU index of the NUMA nodes are always sequential.

12 years agoAssign spapr-vio bus address to ibmvscsi controller
Li Zhang [Mon, 14 May 2012 06:16:37 +0000 (14:16 +0800)]
Assign spapr-vio bus address to ibmvscsi controller

For pseries guest, the default controller model is
ibmvscsi controller, this controller only can work
on spapr-vio address.

This patch is to assign spapr-vio address type to
ibmvscsi controller and correct vscsi test case.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
12 years agosanlock: fix locking for readonly devices
David Weber [Mon, 14 May 2012 09:53:02 +0000 (09:53 +0000)]
sanlock: fix locking for readonly devices

Add ignore param for readonly and shared disk in sanlock

12 years agonodeinfo: add some more tests
Eric Blake [Fri, 11 May 2012 20:30:05 +0000 (14:30 -0600)]
nodeinfo: add some more tests

Test 2 data grabbed from a 2-core 1-node laptop.
Test 3 data grabbed from a 48-cpu AMD Magny Cours box.

* tests/nodeinfodata/linux-nodeinfo-sysfs-test-2*: New test data.
* tests/nodeinfodata/linux-nodeinfo-sysfs-test-3*: Likewise.
* tests/nodeinfotest.c (mymain): Run them.
* cfg.mk
(exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF): Exempt
new test files.

12 years agonodeinfo: avoid probing host filesystem during test
Eric Blake [Fri, 11 May 2012 19:59:59 +0000 (13:59 -0600)]
nodeinfo: avoid probing host filesystem during test

We had previously weakened our nodeinfotest in order to ignore parsed
node values, because the parse function was mistakenly relying on
host files.  A better fix is to avoid using the numactl library, but
to instead parse the same files that numactl would read, all while
allowing the files to be relative to our choice of directory.

* src/nodeinfo.c (CPU_SYS_PATH, NODE_SYS_PATH): Replace with...
(SYSFS_SYSTEM_PATH): ...parent directory.
(linuxNodeInfoCPUPopulate): Check NUMA nodes from requested
directory (by inlining numactl code).
(nodeGetCPUmap, nodeGetMemoryStats): Adjust macro use.
* tests/nodeinfotest.c (linuxTestCompareFiles, linuxTestNodeInfo):
Update test to match.

12 years agonodeinfo: drop static variable
Eric Blake [Fri, 11 May 2012 18:50:08 +0000 (12:50 -0600)]
nodeinfo: drop static variable

We were wasting time to malloc a copy of a constant string, then
copy it into static storage, for every call to nodeGetInfo.  At
least we were lucky that it was a constant source, and thus not
subject to even worse issues with one thread clobbering the static
storage while another was using it.  This gets rid of the waste,
by passing the string through the stack instead, as well as renaming
internal functions to better match our conventions.

* src/nodeinfo.c (sysfs_path): Delete.
(get_cpu_value, count_thread_siblings, parse_socket): Add
parameter, and rename...
(virNodeGetCpuValue, virNodeCountThreadSiblings)
(virNodeParseSocket): ... into a common namespace.
(cpu_online, parse_core): Inline into callers.
(linuxNodeInfoCPUPopulate): Update caller.
(nodeGetInfo): Drop a useless malloc.

12 years agobuild: really silence the 32-bit warning
Eric Blake [Sat, 12 May 2012 13:24:08 +0000 (07:24 -0600)]
build: really silence the 32-bit warning

Commit cdce2f42d tried to silence a compiler warning on 32-bit builds,
but the gcc shipped with RHEL 5 is old enough that the type conversion
via multiplication by 1 was insufficient for the task.

* src/qemu/qemu_monitor.c (qemuMonitorBlockJob): Previous attempt
didn't get past all gcc versions.

12 years agomaint: fix AUTHORS
Eric Blake [Mon, 14 May 2012 15:14:19 +0000 (09:14 -0600)]
maint: fix AUTHORS

Use the address specified in the actual commit, to placate
'make syntax-check'.

12 years agoUse XDG Base Directories instead of storing in home directory
William Jon McCann [Thu, 3 May 2012 16:36:27 +0000 (12:36 -0400)]
Use XDG Base Directories instead of storing in home directory

As defined in:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

This offers a number of advantages:
 * Allows sharing a home directory between different machines, or
sessions (eg. using NFS)
 * Cleanly separates cache, runtime (eg. sockets), or app data from
user settings
 * Supports performing smart or selective migration of settings
between different OS versions
 * Supports reseting settings without breaking things
 * Makes it possible to clear cache data to make room when the disk
is filling up
 * Allows us to write a robust and efficient backup solution
 * Allows an admin flexibility to change where data and settings are stored
 * Dramatically reduces the complexity and incoherence of the
system for administrators

12 years agoRelease of libvirt-0.9.12
Daniel Veillard [Mon, 14 May 2012 02:52:04 +0000 (10:52 +0800)]
Release of libvirt-0.9.12

* configure.ac docs/news.html.in libvirt.spec.in: updates for the release
* po/*.po: pushed new sources and synchronized new languages translations

12 years agoesx: Fix memory leaks in error paths related to transferred ownership
Matthias Bolte [Sun, 6 May 2012 17:33:59 +0000 (19:33 +0200)]
esx: Fix memory leaks in error paths related to transferred ownership

Appending an item to a list transfers ownership of that item to the
list owner. But an error can occur in between item allocation and
appending it to the list. In this case the item has to be freed
explicitly. This was not done in some special cases resulting in
possible memory leaks.

Reported by Coverity.

12 years agoqemu: Don't skip detection of virtual cpu's on non KVM targets
Peter Krempa [Mon, 7 May 2012 11:58:22 +0000 (13:58 +0200)]
qemu: Don't skip detection of virtual cpu's on non KVM targets

This patch lifts the limit of calling thread detection code only on KVM
guests. With upstream qemu the thread mappings are reported also on
non-KVM machines.

QEMU adopted the thread_id information from the kvm branch.

To remain compatible with older upstream versions of qemu the check is
attempted but the failure to detect threads (or even run the monitor
command - on older versions without SMP support) is treated non-fatal
and the code reports one vCPU with pid of the hypervisor (in same
fashion this was done on non-KVM guests).

12 years agoqemu: Re-detect virtual cpu threads after cpu hot (un)plug.
Peter Krempa [Mon, 7 May 2012 11:56:17 +0000 (13:56 +0200)]
qemu: Re-detect virtual cpu threads after cpu hot (un)plug.

After a cpu hotplug the qemu driver did not refresh information about
virtual processors used by qemu and their corresponding threads. This
patch forces a re-detection as is done on start of QEMU.

This ensures that correct information is reported by the
virDomainGetVcpus API and "virsh vcpuinfo".

A failure to obtain the thread<->vcpu mapping is treated non-fatal and
the mapping is not updated in a case of failure as not all versions of
QEMU report this in the info cpus command.

12 years agoqemu: Refactor qemuDomainSetVcpusFlags
Peter Krempa [Mon, 7 May 2012 11:53:20 +0000 (13:53 +0200)]
qemu: Refactor qemuDomainSetVcpusFlags

This patch changes a switch statement into ifs when handling live vs.
configuration modifications getting rid of redundant code in case when
both live and persistent configuration gets changed.

12 years agobuild: fix stamp file name
Eric Blake [Fri, 11 May 2012 14:20:34 +0000 (08:20 -0600)]
build: fix stamp file name

Ever since commit c964b6a, make was trying to find the timestamp
of '""./apibuild.py".stamp"', but only touching 'apibuild.py.stamp',
and thus always rebuilding.  Reported by Daniel P. Berrange.

* docs/Makefile.am (APIBUILD, APIBUILD_STAMP): Omit bogus quotes.

12 years agousb: fix crash when failing to attach a second usb device
Guannan Ren [Fri, 11 May 2012 06:29:15 +0000 (14:29 +0800)]
usb: fix crash when failing to attach a second usb device

when failing to attach another usb device to a domain for some reason
which has one use device attached before, the libvirtd crashed.
The crash is caused by null-pointer dereference error in invoking
usbDeviceListSteal passed in NULL value usb variable.
commit 05abd1507d66aabb6cad12eeafeb4c4d1911c585 introduces the bug.

13 years agodocs: mention migration issue of which credentials are used
Eric Blake [Mon, 30 Apr 2012 20:51:07 +0000 (14:51 -0600)]
docs: mention migration issue of which credentials are used

Based on a report by Seth Vidal.  Just because _you_ can use virsh
to connect to both source and destinations does not mean that libvirtd
on the source (aka _root_) can likewise connect to the destination;
this matters when setting up a peer-to-peer migration instead of a
native one.

* docs/migration.html.in: Mention that in peer-to-peer, the owner
of the source libvirtd (usually root) must be able to connect to
the destination.

13 years agobuild: Fix the typo in configure.ac
Osier Yang [Thu, 10 May 2012 02:25:22 +0000 (10:25 +0800)]
build: Fix the typo in configure.ac

s/nuamd/numad/,

13 years agoconf: Fix memory leaks in virStoragePoolDefParseSource
Alex Jia [Wed, 9 May 2012 10:48:46 +0000 (18:48 +0800)]
conf: Fix memory leaks in virStoragePoolDefParseSource

Detected by valgrind. Leaks are introduced in commit 122fa379.

src/conf/storage_conf.c: fix memory leaks.

How to reproduce?
$ make && make -C tests check TESTS=storagepoolxml2xmltest
$ cd tests && valgrind -v --leak-check=full ./storagepoolxml2xmltest

actual result:
==28571== LEAK SUMMARY:
==28571==    definitely lost: 40 bytes in 5 blocks
==28571==    indirectly lost: 0 bytes in 0 blocks
==28571==      possibly lost: 0 bytes in 0 blocks
==28571==    still reachable: 1,054 bytes in 21 blocks
==28571==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoqemu: fix build when !HAVE_NUMACTL
Eric Blake [Wed, 9 May 2012 23:55:31 +0000 (17:55 -0600)]
qemu: fix build when !HAVE_NUMACTL

Commit 97010eb1f forgot to change the other side of an #ifdef.

* src/qemu/qemu_process.c (qemuProcessInitNumaMemoryPolicy): Add
argument.

13 years agoReport error when parsing character device target type
Jim Fehlig [Wed, 9 May 2012 17:12:38 +0000 (11:12 -0600)]
Report error when parsing character device target type

No useful error was being reported when an invalid character device
target type is specified in the domainXML. E.g.

    ...
    <console type="pty">
      <source path="/dev/pts/2"/>
      <target type="kvm" port="0"/>
    </console>
    ...

resulted in

error: Failed to define domain from x.xml
error: An error occurred, but the cause is unknown

With this small patch, the error is more helpful

error: Failed to define domain from x.xml
error: XML error: unknown target type 'kvm' specified for character device

13 years agonetlink: Fix build with libnl-3
Jiri Denemark [Wed, 9 May 2012 09:57:44 +0000 (11:57 +0200)]
netlink: Fix build with libnl-3

Commit 642973135c54b93242c4548ef27d591b52b0994c added three direct
references to nl_handle_* instead of using our aliases which hide
differences between libnl-3 and libnl-1.

13 years agonumad: Update comments in libvirt.spec.in
Osier Yang [Wed, 9 May 2012 04:26:36 +0000 (12:26 +0800)]
numad: Update comments in libvirt.spec.in

Not only support CPU placement now.

13 years agonumad: Check numactl-devel if compiled with numad support
Osier Yang [Wed, 9 May 2012 04:22:58 +0000 (12:22 +0800)]
numad: Check numactl-devel if compiled with numad support

Since now we pre-set memory policy using libnuma to fully
drive numad, it needs to check numactl-devel if "with_numad"
is "yes".

configure with groups "--with-numad=yes --with-numactl=yes",
"--with-numad=no --with-numactl=yes", "--with-numad=yes
--with-numactl=yes" works fine after the change.

13 years agonumad: Divide cur_balloon by 1024 before passing it to numad
Osier Yang [Tue, 8 May 2012 16:04:37 +0000 (00:04 +0800)]
numad: Divide cur_balloon by 1024 before passing it to numad

Numad expects MB by default.

13 years agonumad: Always output 'placement' of <vcpu>
Osier Yang [Tue, 8 May 2012 16:04:36 +0000 (00:04 +0800)]
numad: Always output 'placement' of <vcpu>

<vcpu> is not an optional node. The value for its 'placement'
actually always defaults to 'static' in the underlying codes.
(Even no 'cpuset' and 'placement' is specified, the domain
process will be pinned to all the available pCPUs).

13 years agonumad: Copy 'placement' of <numatune> to <vcpu> by default
Osier Yang [Tue, 8 May 2012 16:04:35 +0000 (00:04 +0800)]
numad: Copy 'placement' of <numatune> to <vcpu> by default

With this patch, one can also fully drive numad by:

  <vcpu>2</vcpu>
  <numatune>
    <memory placement='auto'/>
  </numatune>

New tests are added.

13 years agonumad: Set memory policy from numad advisory nodeset
Osier Yang [Tue, 8 May 2012 16:04:34 +0000 (00:04 +0800)]
numad: Set memory policy from numad advisory nodeset

Though numad will manage the memory allocation of task dynamically,
it wants management application (libvirt) to pre-set the memory
policy according to the advisory nodeset returned from querying numad,
(just like pre-bind CPU nodeset for domain process), and thus the
performance could benefit much more from it.

This patch introduces new XML tag 'placement', value 'auto' indicates
whether to set the memory policy with the advisory nodeset from numad,
and its value defaults to the value of <vcpu> placement, or 'static'
if 'nodeset' is specified. Example of the new XML tag's usage:

  <numatune>
    <memory placement='auto' mode='interleave'/>
  </numatune>

Just like what current "numatune" does, the 'auto' numa memory policy
setting uses libnuma's API too.

If <vcpu> "placement" is "auto", and <numatune> is not specified
explicitly, a default <numatume> will be added with "placement"
set as "auto", and "mode" set as "strict".

The following XML can now fully drive numad:

1) <vcpu> placement is 'auto', no <numatune> is specified.

   <vcpu placement='auto'>10</vcpu>

2) <vcpu> placement is 'auto', no 'placement' is specified for
   <numatune>.

   <vcpu placement='auto'>10</vcpu>
   <numatune>
     <memory mode='interleave'/>
   </numatune>

And it's also able to control the CPU placement and memory policy
independently. e.g.

1) <vcpu> placement is 'auto', and <numatune> placement is 'static'

   <vcpu placement='auto'>10</vcpu>
   <numatune>
     <memory mode='strict' nodeset='0-10,^7'/>
   </numatune>

2) <vcpu> placement is 'static', and <numatune> placement is 'auto'

   <vcpu placement='static' cpuset='0-24,^12'>10</vcpu>
   <numatune>
     <memory mode='interleave' placement='auto'/>
   </numatume>

A follow up patch will change the XML formatting codes to always output
'placement' for <vcpu>, even it's 'static'.

13 years agosnapshot: allow block devices past cgroup
Eric Blake [Mon, 7 May 2012 22:56:08 +0000 (16:56 -0600)]
snapshot: allow block devices past cgroup

It turns out that when cgroups are enabled, the use of a block device
for a snapshot target was failing with EPERM due to libvirt failing
to add the block device to the cgroup whitelist.  See also
https://bugzilla.redhat.com/show_bug.cgi?id=810200

* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Account for cgroup.
(qemuDomainSnapshotCreateDiskActive): Update caller.

13 years agotests: add some self-documentation to tests
Alon Levy [Tue, 8 May 2012 17:46:45 +0000 (20:46 +0300)]
tests: add some self-documentation to tests

Alon tried './qemuxml2argvtest --help' to figure out a test failure,
but it didn't help.  The information is in HACKING, but it doesn't
hurt to make the tests also provide their own help.

Signed-off-by: Alon Levy <alevy@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agodomain_conf: add "default" to list of valid spice channels
Alon Levy [Tue, 8 May 2012 17:42:44 +0000 (20:42 +0300)]
domain_conf: add "default" to list of valid spice channels

qemu's behavior in this case is to change the spice server behavior to
require secure connection to any channel not otherwise specified as
being in plaintext mode. libvirt doesn't currently allow requesting this
(via plaintext-channel=<channel name>).

RHBZ: 819499

Signed-off-by: Alon Levy <alevy@redhat.com>
13 years agodomain_conf: add "usbredir" to list of valid spice channels
Alon Levy [Tue, 8 May 2012 13:00:28 +0000 (16:00 +0300)]
domain_conf: add "usbredir" to list of valid spice channels

Add "usbredir" channel to list of recognized spice channels.

RHBZ: 819498

Signed-off-by: Alon Levy <alevy@redhat.com>
13 years agobuild: avoid link failure on Windows
Eric Blake [Wed, 2 May 2012 18:53:04 +0000 (12:53 -0600)]
build: avoid link failure on Windows

We only know -lpthread exists on platforms where we build
threads-pthread.c; but when we build threads-win32.c, LIB_PTHREAD
is empty.

* tests/Makefile.am (shunloadtest_LDADD): Use correct library.

13 years agovirsh: avoid heap corruption leading to virsh abort
Jim Meyering [Mon, 7 May 2012 19:22:09 +0000 (21:22 +0200)]
virsh: avoid heap corruption leading to virsh abort

* tools/virsh.c (vshParseSnapshotDiskspec): Fix off-by-3 memmove
that would corrupt heap when parsing escaped --diskspec comma.
Bug introduced via commit v0.9.4-260-g35d52b5.

13 years agoutil: set src_pid for virNetlinkCommand when appropriate
Laine Stump [Fri, 4 May 2012 17:48:20 +0000 (13:48 -0400)]
util: set src_pid for virNetlinkCommand when appropriate

Until now, the nl_pid of the source address of every message sent by
virNetlinkCommand has been set to the value of getpid(). Most of the
time this doesn't matter, and in the one case where it does
(communication with lldpad), it previously was the proper thing to do,
because the netlink event service (which listens on a netlink socket
for unsolicited messages from lldpad) coincidentally always happened
to bind with a local nl_pid == getpid().

With the fix for:

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

that particular nl_pid is now effectively a reserved value, so the
netlink event service will always bind to something else
(coincidentally "getpid() + (1 << 22)", but it really could be
anything). The result is that communication between lldpad and
libvirtd is broken (lldpad gets a "disconnected" error when it tries
to send a directed message).

The solution to this problem caused by a solution, is to query the
netlink event service's nlhandle for its "local_port", and send that
as the source nl_pid (but only when sending to lldpad, of course - in
other cases we maintain the old behavior of sending getpid()).

There are two cases where a message is being directed at lldpad - one
in virNetDevLinkDump, and one in virNetDevVPortProfileOpSetLink.

The case of virNetDevVPortProfileOpSetLink is simplest to explain -
only if !nltarget_kernel, i.e. the message isn't targetted for the
kernel, is the dst_pid set (by calling
virNetDevVPortProfileGetLldpadPid()), so only in that case do we call
virNetlinkEventServiceLocalPid() to set src_pid.

For virNetDevLinkDump, it's a bit more complicated. The call to
virNetDevVPortProfileGetLldpadPid() was effectively up one level (in
virNetDevVPortProfileOpCommon), although obscured by an unnecessary
passing of a function pointer. This patch removes the function
pointer, and calls virNetDevVPortProfileGetLldpadPid() directly in
virNetDevVPortProfileOpCommon - if it's doing this, it knows that it
should also call virNetlinkEventServiceLocalPid() to set src_pid too;
then it just passes src_pid and dst_pid down to
virNetDevLinkDump. Since (src_pid == 0 && dst_pid == 0) implies that
the kernel is the destination, there is no longer any need to send
nltarget_kernel as an arg to virNetDevLinkDump, so it's been removed.

The disparity between src_pid being int and dst_pid being uint32_t may
be a bit disconcerting to some, but I didn't want to complicate
virNetlinkEventServiceLocalPid() by having status returned separately
from the value.

13 years agoutil: function to get local nl_pid used by netlink event socket
Laine Stump [Fri, 4 May 2012 17:19:51 +0000 (13:19 -0400)]
util: function to get local nl_pid used by netlink event socket

This value will be needed to set the src_pid when sending netlink
messages to lldpad. It is part of the solution to:

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

Note that libnl's port generation algorithm guarantees that the
nl_socket_get_local_port() will always be > 0 (since it is "getpid() +
(n << 22>" where n is always < 1024), so it is okay to cast the
uint32_t to int (thus allowing us to use -1 as an error sentinel).

13 years agoutil: allow specifying both src and dst pid in virNetlinkCommand
Laine Stump [Fri, 4 May 2012 16:58:36 +0000 (12:58 -0400)]
util: allow specifying both src and dst pid in virNetlinkCommand

Until now, virNetlinkCommand has assumed that the nl_pid in the source
address of outgoing netlink messages should always be the return value
of getpid(). In most cases it actually doesn't matter, but in the case
of communication with lldpad, lldpad saves this info and later uses it
to send netlink messages back to libvirt. A recent patch to fix Bug
816465 changed the order of the universe such that the netlink event
service socket is no longer bound with nl_pid == getpid(), so lldpad
could no longer send unsolicited messages to libvirtd. Adding src_pid
as an argument to virNetlinkCommand() is the first step in notifying
lldpad of the proper address of the netlink event service socket.

13 years agoutil: fix libvirtd startup failure due to netlink error
Laine Stump [Thu, 3 May 2012 14:39:04 +0000 (10:39 -0400)]
util: fix libvirtd startup failure due to netlink error

This is part of the solution to the problem detailed in:

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

and further detailed in

  https://www.redhat.com/archives/libvir-list/2012-May/msg00202.htm

A short explanation is included in the comments of the patch itself.

Note that this patch by itself breaks communication between lldpad and
libvirtd, so the other 3 patches in the series must be applied at the
same time as this patch.

13 years agoopenvz: simplify openvzDomainDefineCmd by using virCommandPtr
Guido Günther [Sat, 5 May 2012 06:47:05 +0000 (08:47 +0200)]
openvz: simplify openvzDomainDefineCmd by using virCommandPtr

13 years agoqemu: call usb search function for hostdev initialization and hotplug
Guannan Ren [Sun, 6 May 2012 14:45:05 +0000 (22:45 +0800)]
qemu: call usb search function for hostdev initialization and hotplug

src/qemu/qemu_hostdev.c:
refactor qemuPrepareHostdevUSBDevices function, make it focus on
adding usb device to activeUsbHostdevs after check. After that,
the usb hotplug function qemuDomainAttachHostDevice also could use
it.
expand qemuPrepareHostUSBDevices to perform the usb search,
rollback on failure.

src/qemu/qemu_hotplug.c:
If there are multiple usb devices available with same vendorID and productID,
but with different value of "bus, device", we give an error to let user
use <address> to specify the desired one.

13 years agousb: create functions to search usb device accurately
Guannan Ren [Fri, 4 May 2012 07:49:58 +0000 (15:49 +0800)]
usb: create functions to search usb device accurately

usbFindDevice():get usb device according to
                idVendor, idProduct, bus, device
                it is the exact match of the four parameters

usbFindDeviceByBus():get usb device according to bus, device
                  it returns only one usb device same as usbFindDevice

usbFindDeviceByVendor():get usb device according to idVendor,idProduct
                     it probably returns multiple usb devices.

usbDeviceSearch(): a helper function to do the actual search

13 years agorpm: Handle different source URLs for maint releases
Cole Robinson [Sun, 6 May 2012 18:09:22 +0000 (14:09 -0400)]
rpm: Handle different source URLs for maint releases

13 years agodocs: Add 'maintenance releases' link in 'News' sidebar
Cole Robinson [Sun, 6 May 2012 17:50:22 +0000 (13:50 -0400)]
docs: Add 'maintenance releases' link in 'News' sidebar

13 years agoqemu: Emit compatible XML when migrating a domain
Jiri Denemark [Fri, 4 May 2012 19:23:17 +0000 (21:23 +0200)]
qemu: Emit compatible XML when migrating a domain

When we added the default USB controller into domain XML, we efficiently
broke migration to older versions of libvirt that didn't support USB
controllers at all (0.9.4 and earlier) even for domains that don't use
anything that the older libvirt can't provide. We still want to present
the default USB controller in any XML seen by a user/app but we can
safely remove it from the domain XML used during migration. If we are
migrating to a new enough libvirt, it will add the controller XML back,
while older libvirt won't be confused with it although it will still
tell qemu to create the controller.

Similar approach can be used in the future whenever we find out we
always enabled some kind of device without properly advertising it in
domain XML.

13 years agoqemu: Don't use virDomainDefFormat* directly
Jiri Denemark [Fri, 4 May 2012 19:00:13 +0000 (21:00 +0200)]
qemu: Don't use virDomainDefFormat* directly

Always use appropriate qemuDomain{,Def}Format wrapper since it may do
some additional magic based on the flags.

13 years agoqemu: reject blockiotune if qemu too old
Eric Blake [Fri, 4 May 2012 16:24:17 +0000 (10:24 -0600)]
qemu: reject blockiotune if qemu too old

Commit 4c82f09e added a capability check for qemu per-device io
throttling, but only applied it to domain startup.  As mentioned
in the previous commit (98cec05), the user can still get an 'internal
error' message during a hotplug attempt, when the monitor command
doesn't exist.  It is confusing to allow tuning on inactive domains
only to then be rejected when starting the domain.

* src/qemu/qemu_driver.c (qemuDomainSetBlockIoTune): Reject
offline tuning if online can't match it.

13 years agoqemu: don't modify domain on failed blockiotune
Eric Blake [Fri, 4 May 2012 15:43:23 +0000 (09:43 -0600)]
qemu: don't modify domain on failed blockiotune

If you have a qemu build that lacks the blockio tune monitor command,
then this command:

$ virsh blkdeviotune rhel6u2 hda --total_bytes_sec 1000
error: Unable to change block I/O throttle
error: internal error Unexpected error

fails as expected (well, the error message is lousy), but the next
dumpxml shows that the domain was modified anyway.  Worse, that means
if you save the domain then restore it, the restore will likely fail
due to throttling being unsupported, even though no throttling should
even be active because the monitor command failed in the first place.

* src/qemu/qemu_driver.c (qemuDomainSetBlockIoTune): Check for
error before making modification permanent.

13 years agoutil: remove error log from stubs of virNetlinkEventServiceStart|Stop
Laine Stump [Thu, 3 May 2012 15:52:17 +0000 (11:52 -0400)]
util: remove error log from stubs of virNetlinkEventServiceStart|Stop

These two functions are called from main() on all platforms, and
always return success on platforms that don't support libnl. They
still log an error message, though, which doesn't make sense - they
should just be NOPs on those platforms. (Per a suggestion during
review, I've turned the logs into debug messages rather than removing
them completely).

13 years agonode_device: fix possible non-terminated string
Stefan Berger [Fri, 4 May 2012 17:22:22 +0000 (13:22 -0400)]
node_device: fix possible non-terminated string

Error: STRING_NULL:
/libvirt/src/node_device/node_device_linux_sysfs.c:80:
string_null_argument: Function "saferead" does not terminate string "*buf".
/libvirt/src/util/util.c:101:
string_null_argument: Function "read" fills array "*buf" with a non-terminated string.
/libvirt/src/node_device/node_device_linux_sysfs.c:87:
string_null: Passing unterminated string "buf" to a function expecting a null-terminated string.

13 years agouuid: fix possible non-terminated string
Stefan Berger [Fri, 4 May 2012 17:22:22 +0000 (13:22 -0400)]
uuid: fix possible non-terminated string

Error: STRING_NULL:
/libvirt/src/util/uuid.c:273:
string_null_argument: Function "getDMISystemUUID" does not terminate string "*dmiuuid".
/libvirt/src/util/uuid.c:241:
string_null_argument: Function "saferead" fills array "*uuid" with a non-terminated string.
/libvirt/src/util/util.c:101:
string_null_argument: Function "read" fills array "*buf" with a non-terminated string.
/libvirt/src/util/uuid.c:274:
string_null: Passing unterminated string "dmiuuid" to a function expecting a null-terminated string.
/libvirt/src/util/uuid.c:138:
var_assign_parm: Assigning: "cur" = "uuidstr". They now point to the same thing.
/libvirt/src/util/uuid.c:164:
string_null_sink_loop: Searching for null termination in an unterminated array "cur".

13 years agotests: fix resource leak
Stefan Berger [Fri, 4 May 2012 14:42:09 +0000 (10:42 -0400)]
tests: fix resource leak

Error: RESOURCE_LEAK:
/libvirt/tests/qemuxml2argvtest.c:47:
alloc_arg: Calling allocation function "virAlloc" on "ret".
/libvirt/src/util/memory.c:101:
alloc_fn: Storage is returned from allocation function "calloc".
/libvirt/src/util/memory.c:101:
var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/libvirt/tests/qemuxml2argvtest.c:54:
leaked_storage: Variable "ret" going out of scope leaks the storage it points to.

13 years agoqemu: fix resource leak
Stefan Berger [Fri, 4 May 2012 14:42:09 +0000 (10:42 -0400)]
qemu: fix resource leak

Error: RESOURCE_LEAK:
/libvirt/src/qemu/qemu_driver.c:6968:
alloc_fn: Calling allocation function "calloc".
/libvirt/src/qemu/qemu_driver.c:6968:
var_assign: Assigning: "nodeset" =  storage returned from "calloc(1UL, 1UL)".
/libvirt/src/qemu/qemu_driver.c:6977:
noescape: Variable "nodeset" is not freed or pointed-to in function "virTypedParameterAssign".
/libvirt/src/qemu/qemu_driver.c:6997:
leaked_storage: Variable "nodeset" going out of scope leaks the storage it points to.

13 years agovmx: fix resource leak
Stefan Berger [Fri, 4 May 2012 14:42:09 +0000 (10:42 -0400)]
vmx: fix resource leak

Error: RESOURCE_LEAK:
/libvirt/src/vmx/vmx.c:2431:
alloc_fn: Calling allocation function "calloc".
/libvirt/src/vmx/vmx.c:2431:
var_assign: Assigning: "networkName" =  storage returned from "calloc(1UL, 1UL)".
/libvirt/src/vmx/vmx.c:2495:
leaked_storage: Variable "networkName" going out of scope leaks the storage it points to.

13 years agoopenvz: read vmguarpages/privvmpages to set memory tunables
Guido Günther [Wed, 25 Apr 2012 19:18:16 +0000 (21:18 +0200)]
openvz: read vmguarpages/privvmpages to set memory tunables

13 years agoCoverity: Fix resource leak in virnetlink.c
Osier Yang [Wed, 2 May 2012 14:51:38 +0000 (22:51 +0800)]
Coverity: Fix resource leak in virnetlink.c

13 years agoCoverity: Fix resource leak in nodeinfo.c
Osier Yang [Wed, 2 May 2012 15:18:03 +0000 (23:18 +0800)]
Coverity: Fix resource leak in nodeinfo.c

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: alloc_fn: Calling allocation function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: var_assign: Assigning: "cpuinfo" =  storage returned from "fopen("/proc/cpuinfo", "r")".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:638: leaked_storage: Variable "cpuinfo" going out of scope leaks the storage it points to.

13 years agoCoverity: Fix resource leak in test driver
Osier Yang [Wed, 2 May 2012 14:51:36 +0000 (22:51 +0800)]
Coverity: Fix resource leak in test driver

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/test/test_driver.c:1041: alloc_arg: Calling allocation function "virXPathNodeSet" on "devs".
/builddir/build/BUILD/libvirt-0.9.10/src/util/xml.c:621: alloc_arg: "virAllocN" allocates memory that is stored into "*list".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:129: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:129: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(count, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/util/xml.c:625: noescape: Variable "*list" is not freed or pointed-to in function "memcpy".
/builddir/build/BUILD/libvirt-0.9.10/src/test/test_driver.c:1098: leaked_storage: Variable "devs" going out of scope leaks the storage it points to.

13 years agoCoverity: Fix resource leak in xen driver
Osier Yang [Wed, 2 May 2012 14:51:35 +0000 (22:51 +0800)]
Coverity: Fix resource leak in xen driver

Coverity logs:

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_inotify.c:103: alloc_fn: Calling allocation function "xenDaemonLookupByUUID".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xend_internal.c:2534: alloc_fn: Storage is returned from allocation function "virGetDomain".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:191: alloc_arg: "virAlloc" allocates memory that is stored into "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:210: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xend_internal.c:2534: var_assign: Assigning: "ret" = "virGetDomain(conn, name, uuid)".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xend_internal.c:2541: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_inotify.c:103: var_assign: Assigning: "dom" =  storage returned from "xenDaemonLookupByUUID(conn, rawuuid)".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_inotify.c:126: leaked_storage: Variable "dom" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2742: alloc_fn: Calling allocation function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2742: var_assign: Assigning: "cpuinfo" =  storage returned from "fopen("/proc/cpuinfo", "r")".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2763: noescape: Variable "cpuinfo" is not freed or pointed-to in function "xenHypervisorMakeCapabilitiesInternal".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2574:45: noescape: "xenHypervisorMakeCapabilitiesInternal" does not free or save its pointer parameter "cpuinfo".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2768: leaked_storage: Variable "cpuinfo" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2752: alloc_fn: Calling allocation function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2752: var_assign: Assigning: "capabilities" =  storage returned from "fopen("/sys/hypervisor/properties/capabilities", "r")".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2763: noescape: Variable "capabilities" is not freed or pointed-to in function "xenHypervisorMakeCapabilitiesInternal".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2574:60: noescape: "xenHypervisorMakeCapabilitiesInternal" does not free or save its pointer parameter "capabilities".
/builddir/build/BUILD/libvirt-0.9.10/src/xen/xen_hypervisor.c:2768: leaked_storage: Variable "capabilities" going out of scope leaks the storage it points to.

13 years agoCoverity: Fix resource leaks in phyp driver
Osier Yang [Fri, 4 May 2012 02:25:58 +0000 (10:25 +0800)]
Coverity: Fix resource leaks in phyp driver

Coverity logs:

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:523: alloc_fn: Calling allocation function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:523: var_assign: Assigning: "fd" =  storage returned from "fopen(local_file, "rb")".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:540: noescape: Variable "fd" is not freed or pointed-to in function "fread".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:542: noescape: Variable "fd" is not freed or pointed-to in function "feof".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:575: leaked_storage: Variable "fd" going out of scope leaks the storage it points to.
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:585: leaked_storage: Variable "fd" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2088: alloc_fn: Calling allocation function "phypVolumeLookupByName".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2026: alloc_fn: Storage is returned from allocation function "virGetStorageVol".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:724: alloc_arg: "virAlloc" allocates memory that is stored into "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:753: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2026: var_assign: Assigning: "vol" = "virGetStorageVol(pool->conn, pool->name, volname, key)".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2030: return_alloc: Returning allocated memory "vol".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2088: leaked_storage: Failing to save storage allocated by "phypVolumeLookupByName(pool, voldef->name)" leaks it.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2725: alloc_fn: Calling allocation function "phypGetStoragePoolLookUpByUUID".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2689: alloc_fn: Storage is returned from allocation function "virGetStoragePool".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:592: alloc_arg: "virAlloc" allocates memory that is stored into "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:610: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2689: var_assign: Assigning: "sp" = "virGetStoragePool(conn, pools[i], uuid)".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2694: return_alloc: Returning allocated memory "sp".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2725: leaked_storage: Failing to save storage allocated by "phypGetStoragePoolLookUpByUUID(conn, def->uuid)" leaks it.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2719: alloc_fn: Calling allocation function "phypStoragePoolLookupByName".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2254: alloc_fn: Storage is returned from allocation function "virGetStoragePool".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:592: alloc_arg: "virAlloc" allocates memory that is stored into "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:610: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2254: return_alloc_fn: Directly returning storage allocated by "virGetStoragePool".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2719: leaked_storage: Failing to save storage allocated by "phypStoragePoolLookupByName(conn, def->name)" leaks it.

Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2270: alloc_fn: Calling allocation function "phypStoragePoolLookupByName".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2254: alloc_fn: Storage is returned from allocation function "virGetStoragePool".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:592: alloc_arg: "virAlloc" allocates memory that is stored into "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: alloc_fn: Storage is returned from allocation function "calloc".
/builddir/build/BUILD/libvirt-0.9.10/src/util/memory.c:101: var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
/builddir/build/BUILD/libvirt-0.9.10/src/datatypes.c:610: return_alloc: Returning allocated memory "ret".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2254: return_alloc_fn: Directly returning storage allocated by "virGetStoragePool".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2270: var_assign: Assigning: "sp" =  storage returned from "phypStoragePoolLookupByName(vol->conn, vol->pool)".
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2324: leaked_storage: Variable "sp" going out of scope leaks the storage it points to.
/builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:2327: leaked_storage: Variable "sp" going out of scope leaks the storage it points t

13 years agoCoverity: Fix the forward_null error in Python binding codes
Osier Yang [Wed, 2 May 2012 15:05:59 +0000 (23:05 +0800)]
Coverity: Fix the forward_null error in Python binding codes

Related coverity log:

Error: FORWARD_NULL:
/builddir/build/BUILD/libvirt-0.9.10/python/libvirt-override.c:355:
assign_zero: Assigning: "params" = 0.
/builddir/build/BUILD/libvirt-0.9.10/python/libvirt-override.c:458:
var_deref_model: Passing null variable "params" to function
"getPyVirTypedParameter", which dereferences it. (The dereference is assumed on
the basis of the 'nonnull' parameter attribute.)

13 years agoqemu: avoid 32-bit compiler warning
Eric Blake [Thu, 3 May 2012 23:04:34 +0000 (17:04 -0600)]
qemu: avoid 32-bit compiler warning

On 32-bit platforms, gcc warns that the comparison between a long
and (ULLONG_MAX/1024/1024) is always false; throwing in a type
conversion shuts up the warning.

* src/qemu/qemu_monitor.c (qemuMonitorBlockJob): Shut gcc up.

13 years agobuild: support libnl-3
Serge Hallyn [Thu, 3 May 2012 16:10:50 +0000 (11:10 -0500)]
build: support libnl-3

configure.ac: check for libnl-3 in addition to libnl-1

src/Makefile.am: link against libnl when needed

src/util/virnetlink.c:
support libnl3 api.  To minimize impact on code flow, wrap the
differences under the virNetlink* namespace.

Unfortunately libnl3 moves netlink/msg.h to
/usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added
to a bunch of places where they weren't needed with libnl1.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agobuild: fix build on cygwin
Eric Blake [Thu, 3 May 2012 20:39:19 +0000 (14:39 -0600)]
build: fix build on cygwin

On cygwin, <rpc/rpc.h> lives in a different directory than
/usr/include, so anything that uses it must modify CFLAGS.  This
previously tripped up just 'make check', but now that we build
all test programs unconditionally, it also trips up 'make'.

* tests/Makefile.am (virnetmessagetest_CFLAGS): Find rpc headers.

13 years agoutil: add functions for interating over json object
Dmitry Guryanov [Wed, 2 May 2012 18:32:37 +0000 (22:32 +0400)]
util: add functions for interating over json object

Add function virJSONValueObjectKeysNumber, virJSONValueObjectGetKey
and virJSONValueObjectGetValue, which allow you to iterate over all
fields of json object: you can get number of fields and then get
name and value, stored in field with that name by index.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
13 years agoCorrect indent errors in the function qemuDomainNetsRestart
Li Zhang [Thu, 3 May 2012 05:52:44 +0000 (13:52 +0800)]
Correct indent errors in the function qemuDomainNetsRestart

qemuDomainNetsRestart indents with 3 spaces.

This patch is to correct it.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
13 years agobuild: update pid_t type static check
Marc-André Lureau [Fri, 20 Apr 2012 13:13:52 +0000 (15:13 +0200)]
build: update pid_t type static check

The code uses long long for pid_t now.
It fails on mingw64 without this change.

13 years agobuild: fix output of pid values
Marc-André Lureau [Fri, 20 Apr 2012 13:13:51 +0000 (15:13 +0200)]
build: fix output of pid values

Fix a few more places where pid_t is printed with wrong type

13 years agoAdded Snooze cloud manager to the IaaS section
Eugen Feller [Wed, 2 May 2012 17:53:41 +0000 (19:53 +0200)]
Added Snooze cloud manager to the IaaS section

13 years agovirsh: output scaled values with correct units
Eric Blake [Mon, 30 Apr 2012 20:27:56 +0000 (14:27 -0600)]
virsh: output scaled values with correct units

The recent push to use correct scaling terms (kB for 1000, KiB for
1024 - such as commit 9dfdead) missed some places in virsh.

* tools/virsh.c (prettyCapacity, cmdDominfo, cmdFreecell)
(cmdNodeinfo, cmdNodeMemStats, cmdMigrateSetMaxSpeed)
(cmdBlockCopy, cmdBlockPull, cmdBlockJob): Use KiB, not kB, when
referring to multiples of 1024.
* tests/virshtest.c: Update expected output to match.

13 years agovirsh: make -h always give help
Eric Blake [Mon, 30 Apr 2012 20:19:11 +0000 (14:19 -0600)]
virsh: make -h always give help

https://bugzilla.redhat.com/show_bug.cgi?id=817244 mentions that
unlike most other tools, where --help or --version prevent all
further parsing of all later options, virsh was strange in that
--version stopped parsing but --help tried to plow on to the end.
There was no rationale for this original implementation (since
2005!), so I think we can safely conform to common usage patterns.

* tools/virsh.c (main): Drop useless 'help' variable.

13 years agobuild: make ATTRIBUTE_NONNULL() a NOP unless STATIC_ANALYSIS is on
Laine Stump [Wed, 25 Apr 2012 20:10:01 +0000 (16:10 -0400)]
build: make ATTRIBUTE_NONNULL() a NOP unless STATIC_ANALYSIS is on

The ATTRIBUTE_NONNULL(m) macro normally resolves to the gcc builtin
__attribute__((__nonnull__(m))). The effect of this in gcc is
unfortunately only to make gcc believe that "m" can never possibly be
NULL, *not* to add in any checks to guarantee that it isn't ever NULL
(i.e. it is an optimization aid, *not* something to verify code
correctness.) - see the following gcc bug report for more details:

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308

Static source analyzers such as clang and coverity apparently can use
ATTRIBUTE_NONNULL(), though, to detect dead code (in the case that the
arg really is guaranteed non-NULL), as well as situations where an
obviously NULL arg is given to the function.

https://bugzilla.redhat.com/show_bug.cgi?id=815270 is a good example
of a bug caused by erroneous application of ATTRIBUTE_NONNULL().
Several people spent a long time staring at this code and not finding
the problem, because the problem wasn't in the function itself, but in
the prototype that specified ATTRIBUTE_NONNULL() for an arg that
actually *wasn't* always non-NULL, and caused a segv when dereferenced
(even though the code that dereferenced the pointer was inside an if()
that checked for a NULL pointer, that code was optimized out by gcc).

There may be some very small gain to be had from the optimizations
that can be inferred from ATTRIBUTE_NONNULL(), but it seems safer to
err on the side of generating code that behaves as expected, while
turning on the attribute for static analyzers.

13 years agoMake lxcContainerSetStdio the last thing to be called in container startup
Daniel P. Berrange [Tue, 1 May 2012 09:48:52 +0000 (10:48 +0100)]
Make lxcContainerSetStdio the last thing to be called in container startup

Once lxcContainerSetStdio is invoked, logging will not work as
expected in libvirt_lxc. So make sure this is the last thing to
be called, in particular after setting the security process label

13 years agoEnsure logging is initialized early in libvirt_lxc
Daniel P. Berrange [Tue, 1 May 2012 09:47:53 +0000 (10:47 +0100)]
Ensure logging is initialized early in libvirt_lxc

The virLogSetFromEnv call was done too late in startup to
catch many log messages (eg from security driver initialization).
To assist debugging also explicitly log the security details
at startup

13 years agoEnsure LXC security driver is set unconditonally
Daniel P. Berrange [Tue, 1 May 2012 09:46:08 +0000 (10:46 +0100)]
Ensure LXC security driver is set unconditonally

The driver->securityDriverName field may be NULL, if automatic
probing is used to determine security driver. This meant that
unless selinux was explicitly requested in lxc.conf, it was
not being sent to the libvirt_lxc process.

The driver->securityManager field is guaranteed non-NULL, since
there will always be the 'none' security driver present if
nothing else exists. So use that to set the driver name for
libvirt_lxc

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoEnsure libvirt_lxc process loads the live XML config
Daniel P. Berrange [Mon, 30 Apr 2012 14:48:57 +0000 (15:48 +0100)]
Ensure libvirt_lxc process loads the live XML config

Currently the libvirt_lxc process uses VIR_DOMAIN_XML_INACTIVE
when loading the XML for the container. This means it loses
any dynamic data such as the, just allocated, SELinux label.

Further there is an inconsistency in the libvirt LXC driver
whereby it saves the live config XML and then later overwrites
the file with the live status XML instead. Add a comment about
this for future reference.

* src/lxc/lxc_controller.c: Remove VIR_DOMAIN_XML_INACTIVE
  when loading XML
* src/lxc/lxc_driver.c: Add comment about inconsistent
  config file formats

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agomaint: avoid false positives on unmarked diagnostics
Eric Blake [Mon, 30 Apr 2012 21:55:13 +0000 (15:55 -0600)]
maint: avoid false positives on unmarked diagnostics

Otherwise, a string such as _("Don't use \"" VAR "\".") would
complain about unmarked diagnostics.

* cfg.mk (sc_libvirt_unmarked_diagnostics): Handle \" in message.

13 years agoqemu: allow snapshotting of sheepdog and rbd disks
Josh Durgin [Tue, 1 May 2012 05:55:22 +0000 (22:55 -0700)]
qemu: allow snapshotting of sheepdog and rbd disks

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
13 years agoqemu: change rbd auth_supported separation character to ;
Josh Durgin [Tue, 1 May 2012 05:56:08 +0000 (22:56 -0700)]
qemu: change rbd auth_supported separation character to ;

This works with newer qemu that doesn't allow escaping spaces.
It's backwards compatible as well.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
13 years agoutil: Avoid libvirtd crash in virNetDevTapCreate
Alex Jia [Sat, 28 Apr 2012 11:01:40 +0000 (19:01 +0800)]
util: Avoid libvirtd crash in virNetDevTapCreate

In fact, the 'tapfd' is always NULL, the function 'virNetDevTapCreate()' hasn't
assign 'fd' to 'tapfd', when the function 'virNetDevSetMAC()' is failed then
goto 'error' label, finally, the VIR_FORCE_CLOSE() will deref a NULL 'tapfd'.

* util/virnetdevtap.c (virNetDevTapCreateInBridgePort): fix a NULL pointer derefing.

* How to reproduce?

$ cat > /tmp/net.xml <<EOF
<network>
  <name>test</name>
  <forward mode='nat'/>
  <bridge name='br1' stp='off' delay='1' />
  <mac address='00:00:00:00:00:00'/>
  <ip address='192.168.100.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.100.2' end='192.168.100.254' />
    </dhcp>
  </ip>
</network>
EOF

$ virsh net-define /tmp/net.xml

$ virsh net-start test
error: Failed to start network brTest
error: End of file while reading data: Input/output error

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agostorage: fix build with iscsi
Eric Blake [Mon, 30 Apr 2012 16:36:44 +0000 (10:36 -0600)]
storage: fix build with iscsi

The previous storage patch missed an instance affected by the struct
member rename.  It also had some botched whitespace detected by
'make check'.

* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIFindPoolSources): Adjust to new struct.
* src/conf/storage_conf.c (virStoragePoolSourceFormat): Fix
indentation.

13 years agostorage: Break out the loop if duplicate pool is found
Osier Yang [Sat, 28 Apr 2012 08:18:44 +0000 (16:18 +0800)]
storage: Break out the loop if duplicate pool is found

It doesn't break out the "for" loop even if duplicate pool is
found, and thus the "matchpool" could be overriden as NULL again
if there is different pool afterwards.

To address the problem in libvirt-user list:

https://www.redhat.com/archives/libvirt-users/2012-April/msg00150.html

13 years agostorage: Allow multiple hosts for a storage pool
Wido den Hollander [Wed, 25 Apr 2012 10:43:09 +0000 (12:43 +0200)]
storage: Allow multiple hosts for a storage pool

The current storage pools for NFS and iSCSI only require one host to
connect to. Future storage pools like RBD and Sheepdog will require
multiple hosts.

This patch allows multiple source hosts and rewrites the current
storage drivers.

Signed-off-by: Wido den Hollander <wido@widodh.nl>
13 years agoqemu: Make sure qemu can access its directory in hugetlbfs
Jiri Denemark [Fri, 27 Apr 2012 13:50:22 +0000 (15:50 +0200)]
qemu: Make sure qemu can access its directory in hugetlbfs

When libvirtd is started, we create "libvirt/qemu" directories under
hugetlbfs mount point. Only the "qemu" subdirectory is chowned to qemu
user and "libvirt" remains owned by root. If umask was too restrictive
when libvirtd started, qemu user may lose access to "qemu"
subdirectory. Let's explicitly grant search permissions to "libvirt"
directory for all users.

13 years agoqemu_agent: Report error class at least
Michal Privoznik [Thu, 12 Apr 2012 14:35:24 +0000 (16:35 +0200)]
qemu_agent: Report error class at least

Currently, qemu GA is not providing 'desc' field for errors like
we are used to from qemu monitor. Therefore, we fall back to this
general 'unknown error' string. However, GA is reporting 'class' which
is not perfect, but much more helpful than generic error string.
Thus we should fall back to class firstly and if even no class
is presented, then we can fall back to that generic string.

Before this patch:
virsh # dompmsuspend --target mem f16
error: Domain f16 could not be suspended
error: internal error unable to execute QEMU command
'guest-suspend-ram': unknown QEMU command error

After this patch:
virsh # dompmsuspend --target mem f16
error: Domain f16 could not be suspended
error: internal error unable to execute QEMU command
'guest-suspend-ram': The command has not been found

13 years agoMore coverity findings addressed
Stefan Berger [Fri, 27 Apr 2012 21:25:35 +0000 (17:25 -0400)]
More coverity findings addressed

More bug extermination in the category of:

Error: CHECKED_RETURN:

/libvirt/src/conf/network_conf.c:595:
check_return: Calling function "virAsprintf" without checking return value (as is done elsewhere 515 out of 543 times).

/libvirt/src/qemu/qemu_process.c:2780:
unchecked_value: No check of the return value of "virAsprintf(&msg, "was paused (%s)", virDomainPausedReasonTypeToString(reason))".

/libvirt/tests/commandtest.c:809:
check_return: Calling function "setsid" without checking return value (as is done elsewhere 4 out of 5 times).

/libvirt/tests/commandtest.c:830:
unchecked_value: No check of the return value of "virTestGetDebug()".

/libvirt/tests/commandtest.c:831:
check_return: Calling function "virTestGetVerbose" without checking return value (as is done elsewhere 41 out of 42 times).

/libvirt/tests/commandtest.c:833:
check_return: Calling function "virInitialize" without checking return value (as is done elsewhere 18 out of 21 times).

One note about the error in commandtest line 809: setsid() seems to fail when running the test -- could be removed ?

13 years agoblockjob: fix block-stream bandwidth race
Eric Blake [Wed, 25 Apr 2012 22:49:44 +0000 (16:49 -0600)]
blockjob: fix block-stream bandwidth race

With RHEL 6.2, virDomainBlockPull(dom, dev, bandwidth, 0) has a race
with non-zero bandwidth: there is a window between the block_stream
and block_job_set_speed monitor commands where an unlimited amount
of data was let through, defeating the point of a throttle.

This race was first identified in commit a9d3495e, and libvirt was
able to reduce the size of the window for that race.  In the meantime,
the qemu developers decided to fix things properly; per this message:
https://lists.gnu.org/archive/html/qemu-devel/2012-04/msg03793.html
the fix will be in qemu 1.1, and changes block-job-set-speed to use
a different parameter name, as well as adding a new optional parameter
to block-stream, which eliminates the race altogether.

Since our documentation already mentioned that we can refuse a non-zero
bandwidth for some hypervisors, I think the best solution is to do
just that for RHEL 6.2 qemu, so that the race is obvious to the user
(anyone using stock RHEL 6.2 binaries won't have this patch, and anyone
building their own libvirt with this patch for RHEL can also rebuild
qemu to get the modern semantics, so it is no real loss in behavior).

Meanwhile the code must be fixed to honor actual qemu 1.1 naming.
Rename the parameter to 'modern', since the naming difference now
covers more than just 'async' block-job-cancel.  And while at it,
fix an unchecked integer overflow.

* src/qemu/qemu_monitor.h (enum BLOCK_JOB_CMD): Drop unused value,
rename enum to match conventions.
* src/qemu/qemu_monitor.c (qemuMonitorBlockJob): Reflect enum rename.
* src/qemu_qemu_monitor_json.h (qemuMonitorJSONBlockJob): Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockJob): Likewise,
and support difference between RHEL 6.2 and qemu 1.1 block pull.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Reject
bandwidth during pull with too-old qemu.
* src/libvirt.c (virDomainBlockPull, virDomainBlockRebase):
Document this.

13 years agolxc: Fix coverity findings
Stefan Berger [Fri, 27 Apr 2012 18:39:17 +0000 (14:39 -0400)]
lxc: Fix coverity findings

Error: UNINIT:
/libvirt/src/lxc/lxc_driver.c:1412:
var_decl: Declaring variable "fd" without initializer.
/libvirt/src/lxc/lxc_driver.c:1460:
uninit_use_in_call: Using uninitialized value "fd" when calling "virFileClose".
/libvirt/src/util/virfile.c:50:
read_parm: Reading a parameter value.

Error: DEADCODE:
/libvirt/src/lxc/lxc_controller.c:960:
dead_error_condition: On this path, the condition "ret == 4" cannot be true.
/libvirt/src/lxc/lxc_controller.c:959:
at_most: After this line, the value of "ret" is at most -1.
/libvirt/src/lxc/lxc_controller.c:959:
new_values: Noticing condition "ret < 0".
/libvirt/src/lxc/lxc_controller.c:961:
dead_error_line: Execution cannot reach this statement "continue;".

Error: UNINIT:
/libvirt/src/lxc/lxc_controller.c:1104:
var_decl: Declaring variable "consoles" without initializer.
/libvirt/src/lxc/lxc_controller.c:1237:
uninit_use: Using uninitialized value "consoles".

13 years agopython: Fix doc directory name for stable releases
Cole Robinson [Fri, 27 Apr 2012 16:06:34 +0000 (12:06 -0400)]
python: Fix doc directory name for stable releases

We were using the libvirt release version (like 0.9.11) and not
the configure version (which for stable releases is 0.9.11.X)

Most other places got this right so hopefully that's all the fallout
from the version format change :)

Signed-off-by: Cole Robinson <crobinso@redhat.com>
13 years agodocs: Serialize running apibuild.py
Cole Robinson [Fri, 27 Apr 2012 16:05:12 +0000 (12:05 -0400)]
docs: Serialize running apibuild.py

Use a witness file approach like we do for python/generator.py,
as suggested by Eric. Fixes the build issue reported here:

https://www.redhat.com/archives/libvir-list/2012-April/msg01435.html

Signed-off-by: Cole Robinson <crobinso@redhat.com>
13 years agoconfigure: Use ustar format for dist tarball
Cole Robinson [Fri, 27 Apr 2012 16:03:44 +0000 (12:03 -0400)]
configure: Use ustar format for dist tarball

Since for stable releases, some test files were over the 99 char
limit for traditional tar filenames.

Suggested by Osier here:
https://www.redhat.com/archives/libvir-list/2012-April/msg01435.html

Signed-off-by: Cole Robinson <crobinso@redhat.com>
13 years agoqemu: Use common helper when probing qemu capabilities
Jiri Denemark [Thu, 26 Apr 2012 13:10:22 +0000 (15:10 +0200)]
qemu: Use common helper when probing qemu capabilities

QEMU binary is called several times when we probe different kinds of
capabilities the binary supports. This patch introduces new common
helper so that all probes use a consistent way of invoking qemu.

13 years agoqemu: improve errors related to offline domains
Eric Blake [Thu, 26 Apr 2012 19:36:01 +0000 (13:36 -0600)]
qemu: improve errors related to offline domains

https://bugzilla.redhat.com/show_bug.cgi?id=816662 pointed out
that attempting 'virsh blockpull' on an offline domain gave a
misleading error message about qemu lacking support for the
operation, even when qemu was specifically updated to support it.
The real problem is that we have several capabilities that are
only determined when starting a domain, and therefore are still
clear when first working with an inactive domain (namely, any
capability set by qemuMonitorJSONCheckCommands).

While this patch was able to hoist an existing check in one of the
three culprits, it had to add redundant checks in the other two
places (because you always have to check for an active domain after
obtaining a VM job lock, but the capability bits were being checked
prior to obtaining the job lock).

Someday it would be nice to patch libvirt to cache the set of
capabilities per qemu binary (as determined by inode and timestamp),
rather than re-probing the binary every time a domain is started,
and to teach the cache how to query the monitor during the one
time the probe is made rather than having to wait until a guest
is started; then, a capability probe would succeed even for offline
guests because it just refers to the cache, and the single check for
an active domain after grabbing the job lock would be sufficient.
But since that will involve a lot more coding, I'm happy to go
with this simpler solution for an immediate solution.

* src/qemu/qemu_driver.c (qemuDomainPMSuspendForDuration)
(qemuDomainSnapshotCreateXML, qemuDomainBlockJobImpl): Check for
offline state before checking an online-only cap.

13 years agomacvtap: fix a typo
Stefan Berger [Thu, 26 Apr 2012 22:32:58 +0000 (18:32 -0400)]
macvtap: fix a typo

Below patch fixes the following coverity findings

Error: OVERRUN_STATIC:
/libvirt/src/qemu/qemu_command.c:152:
overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
/libvirt/src/util/virnetdevmacvlan.c:948:
access_dbuff_const: Calling "virNetDevMacVLanVPortProfileRegisterCallback" indexes array "macaddress" at byte position 15.
/libvirt/src/util/virnetdevmacvlan.c:773:
access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.

Error: OVERRUN_STATIC:
/libvirt/src/qemu/qemu_migration.c:2744:
overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
/libvirt/src/util/virnetdevmacvlan.c:773:
access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.

Error: OVERRUN_STATIC:
/libvirt/src/qemu/qemu_driver.c:435:
overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
/libvirt/src/util/virnetdevmacvlan.c:1036:
access_dbuff_const: Calling "virNetDevMacVLanVPortProfileRegisterCallback" indexes array "macaddress" at byte position 15.
/libvirt/src/util/virnetdevmacvlan.c:773:
access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.

13 years agonwfilter: address more coverity findings
Stefan Berger [Thu, 26 Apr 2012 20:45:36 +0000 (16:45 -0400)]
nwfilter: address more coverity findings

This patch addresses the following coverity findings:

/libvirt/src/conf/nwfilter_params.c:390:
var_assigned: Assigning: "varValue" = null return value from "virHashLookup".

/libvirt/src/conf/nwfilter_params.c:392:
dereference: Dereferencing a pointer that might be null "varValue" when calling "virNWFilterVarValueGetNthValue".

/libvirt/src/conf/nwfilter_params.c:399:
dereference: Dereferencing a pointer that might be null "tmp" when calling "virNWFilterVarValueGetNthValue".

13 years agonwfilter: address coverity findings
Stefan Berger [Thu, 26 Apr 2012 20:45:36 +0000 (16:45 -0400)]
nwfilter: address coverity findings

This patch addresses the following coverity findings:

/libvirt/src/conf/nwfilter_params.c:157:
deref_parm: Directly dereferencing parameter "val".

/libvirt/src/conf/nwfilter_params.c:473:
negative_returns: Using variable "iterIndex" as an index to array "res->iter".

/libvirt/src/nwfilter/nwfilter_ebiptables_driver.c:2891:
unchecked_value: No check of the return value of "virAsprintf(&protostr, "-d 01:80:c2:00:00:00 ")".

/libvirt/src/nwfilter/nwfilter_ebiptables_driver.c:2894:
unchecked_value: No check of the return value of "virAsprintf(&protostr, "-p 0x%04x ", l3_protocols[protoidx].attr)".

/libvirt/src/nwfilter/nwfilter_ebiptables_driver.c:3590:
var_deref_op: Dereferencing null variable "inst".

13 years agoutil: fix error messages in virNetlinkEventServiceStart
Laine Stump [Thu, 26 Apr 2012 18:35:26 +0000 (14:35 -0400)]
util: fix error messages in virNetlinkEventServiceStart

Some of the error messages in this function should have been
virReportSystemError (since they have an errno they want to log), but
were mistakenly written as netlinkError, which expects a libvirt error
code instead. The result was that when one of the errors was
encountered, "No error message provided" would be printed instead of
something meaningful (see
https://bugzilla.redhat.com/show_bug.cgi?id=816465 for an example).