]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/log
people/liuw/libxenctrl-split/libvirt.git
12 years agoqemu: Avoid NULL dereference in qemuSharedDiskEntryFree
Jiri Denemark [Tue, 12 Mar 2013 08:10:41 +0000 (09:10 +0100)]
qemu: Avoid NULL dereference in qemuSharedDiskEntryFree

At least one caller may call qemuSharedDiskEntryFree with NULL as the
first argument. Let's make the function similar to other *Free functions
and do nothing in such case.

12 years agodocs: Clarify semantics of sparse storage volumes
Jiri Denemark [Mon, 11 Mar 2013 13:42:40 +0000 (14:42 +0100)]
docs: Clarify semantics of sparse storage volumes

Sparse LVM volumes do not behave in the way one would naively expect.
The allocation does not automatically increase (which is different from
how sparse files work).

12 years agoqemu: Fix retrieval of maximum number of vCPUs on KVM hosts
Peter Krempa [Mon, 11 Mar 2013 13:50:54 +0000 (14:50 +0100)]
qemu: Fix retrieval of maximum number of vCPUs on KVM hosts

The detection of the maximum number of cpus used incorrect ioctl
argument value. This flaw caused that on kvm hosts this returns always
"160" as the maximum. This is just a recommended maximum value. The real
value is higher than that.

This patch tweaks the detection function to behave as described by the
kernel docs:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/virtual/kvm/api.txt?id=refs/tags/v3.9-rc2#n199

12 years agonodeinfo: don't define nodeGetCellMemory if it isn't ever used
Hu Tao [Mon, 11 Mar 2013 08:57:26 +0000 (16:57 +0800)]
nodeinfo: don't define nodeGetCellMemory if it isn't ever used

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
12 years agovirsh: fix snapshot-create with no xmlfile
Ján Tomko [Mon, 11 Mar 2013 12:22:21 +0000 (13:22 +0100)]
virsh: fix snapshot-create with no xmlfile

Properly check the return value of vshCommandOptStringReq for xmlfile:
* error out on incorrect input (--xmlfile '')
* use default XML <domainsnapshot/> with no --xmlfile specified

(Broken by commit b2e8585)

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

12 years agoConvert HAVE_SELINUX to WITH_SELINUX
Guido Günther [Sat, 9 Mar 2013 14:56:11 +0000 (15:56 +0100)]
Convert HAVE_SELINUX to WITH_SELINUX

these were missed by 63f18f378693cac6b6e33f4a8c15c20cb191c7c8

12 years agolxc: Init activeUsbHostdevs
Guido Günther [Sat, 9 Mar 2013 13:51:25 +0000 (14:51 +0100)]
lxc: Init activeUsbHostdevs

otherwise we crash with

 #0  virUSBDeviceListFind (list=0x0, dev=dev@entry=0x8193d70) at util/virusb.c:526
 #1  0xb1a4995b in virLXCPrepareHostdevUSBDevices (driver=driver@entry=0x815d9a0, name=0x815dbf8 "debian-700267", list=list@entry=0x81d8f08) at lxc/lxc_hostdev.c:88
 #2  0xb1a49fce in virLXCPrepareHostUSBDevices (def=0x8193af8, driver=0x815d9a0) at lxc/lxc_hostdev.c:261
 #3  virLXCPrepareHostDevices (driver=driver@entry=0x815d9a0, def=0x8193af8) at lxc/lxc_hostdev.c:328
 #4  0xb1a4c5b1 in virLXCProcessStart (conn=0x817d3f8, driver=driver@entry=0x815d9a0, vm=vm@entry=0x8190908, autoDestroy=autoDestroy@entry=false, reason=reason@entry=VIR_DOMAIN_RUNNING_BOOTED)
     at lxc/lxc_process.c:1068
 #5  0xb1a57e00 in lxcDomainStartWithFlags (dom=dom@entry=0x815e460, flags=flags@entry=0) at lxc/lxc_driver.c:1014
 #6  0xb1a57fc3 in lxcDomainStart (dom=0x815e460) at lxc/lxc_driver.c:1046
 #7  0xb79c8375 in virDomainCreate (domain=domain@entry=0x815e460) at libvirt.c:8450
 #8  0x08078959 in remoteDispatchDomainCreate (args=0x81920a0, rerr=0xb65c21d0, client=0xb0d00490, server=<optimized out>, msg=<optimized out>) at remote_dispatch.h:1066
 #9  remoteDispatchDomainCreateHelper (server=0x80c4928, client=0xb0d00490, msg=0xb0d005b0, rerr=0xb65c21d0, args=0x81920a0, ret=0x815d208) at remote_dispatch.h:1044
 #10 0xb7a36901 in virNetServerProgramDispatchCall (msg=0xb0d005b0, client=0xb0d00490, server=0x80c4928, prog=0x80c6438) at rpc/virnetserverprogram.c:432
 #11 virNetServerProgramDispatch (prog=0x80c6438, server=server@entry=0x80c4928, client=0xb0d00490, msg=0xb0d005b0) at rpc/virnetserverprogram.c:305
 #12 0xb7a300a7 in virNetServerProcessMsg (msg=<optimized out>, prog=<optimized out>, client=<optimized out>, srv=0x80c4928) at rpc/virnetserver.c:162
 #13 virNetServerHandleJob (jobOpaque=0xb0d00510, opaque=0x80c4928) at rpc/virnetserver.c:183
 #14 0xb7924f98 in virThreadPoolWorker (opaque=opaque@entry=0x80a94b0) at util/virthreadpool.c:144
 #15 0xb7924515 in virThreadHelper (data=0x80a9440) at util/virthreadpthread.c:161
 #16 0xb7887c39 in start_thread (arg=0xb65c2b70) at pthread_create.c:304
 #17 0xb77eb78e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

when adding a domain with a usb device. This is Debian bug

    http://bugs.debian.org/700267

12 years agobandwidth: Require network QoS if interface uses 'floor'
Michal Privoznik [Thu, 7 Mar 2013 09:53:21 +0000 (10:53 +0100)]
bandwidth: Require network QoS if interface uses 'floor'

By current implementation, network inbound is required in order
to use 'floor' for guaranteeing  minimal throughput. This is so,
because we want user to tell us the maximal throughput of the
network instead of finding out ourselves (and detect bogus values
in case of virtual interfaces). However, we are nowadays
requiring this only on documentation level. So if user starts a
domain with 'floor' set on one its interfaces, we silently ignore
the setting. We should error out instead.

12 years agovirsh-domain: Remove unused vshCompleteXMLFromDomain
Peter Krempa [Fri, 8 Mar 2013 09:08:26 +0000 (10:08 +0100)]
virsh-domain: Remove unused vshCompleteXMLFromDomain

The function is marked as unused and breaks compilation on RHEL4. Remove
it from the tree until a new use case can be found.

12 years agoRevert "Ensure xmlSaveToBuffer is always defined"
Peter Krempa [Fri, 8 Mar 2013 09:04:55 +0000 (10:04 +0100)]
Revert "Ensure xmlSaveToBuffer is always defined"

The commit originally fixed code that isn't being used. Revert
it and remove the unused code as a real fix.

This reverts commit a66b32d9295ed87698ffd98d82e9e5818ff799e5.

12 years agocapabilities: add NUMA memory information
Dusty Mabe [Thu, 7 Mar 2013 16:03:36 +0000 (11:03 -0500)]
capabilities: add NUMA memory information

'virsh capabilities' will now include a new <memory> element
per <cell> of the topology, as in:

    <topology>
      <cells num='2'>
        <cell id='0'>
          <memory unit='KiB'>12572412</memory>
          <cpus num='12'>
          ...
        </cell>

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agolxc: include sys/stat.h
Guido Günther [Fri, 8 Mar 2013 16:28:37 +0000 (17:28 +0100)]
lxc: include sys/stat.h

This fixes the build on Debian Wheezy which otherwise fails with:

  CC     libvirt_driver_lxc_impl_la-lxc_process.lo
  lxc/lxc_process.c: In function 'virLXCProcessGetNsInode':
  lxc/lxc_process.c:648:5: error: implicit declaration of function 'stat' [-Werror=implicit-function-declaration]
  lxc/lxc_process.c:648:5: error: nested extern declaration of 'stat' [-Werror=nested-externs]
  cc1: all warnings being treated as errors

12 years agoqemuDomainBlockStatsFlags: Guard disk lookup with a domain job
Michal Privoznik [Fri, 8 Mar 2013 12:09:32 +0000 (13:09 +0100)]
qemuDomainBlockStatsFlags: Guard disk lookup with a domain job

When there are two concurrent threads, we may dereference a NULL
pointer, even though it has been checked before:

1. Thread1: starts executing qemuDomainBlockStatsFlags() with nparams != 0.
            It finds given disk and successfully pass check for disk->info.alias
            not being NULL.
2. Thread2: starts executing qemuDomainDetachDeviceFlags() on the very same
            disk as Thread1 is working on.
3. Thread1: gets to qemuDomainObjBeginJob() where it sets a job on a
            domain.
4. Thread2: also tries to set a job. However, we are not guaranteed which
            thread wins. So assume it's Thread2 who can continue.
5. Thread2: does the actual detach and frees disk->info.alias
6. Thread2: quits the job
7. Thread1: now successfully acquires the job, and accesses a NULL pointer.

12 years agoapparmor: use AppArmorSetFDLabel for both imageFD and tapFD
Guannan Ren [Thu, 7 Mar 2013 16:16:59 +0000 (00:16 +0800)]
apparmor: use AppArmorSetFDLabel for both imageFD and tapFD

Rename AppArmorSetImageFDLabel to AppArmorSetFDLabel which could
be used as a common function for *ALL* fd relabelling in Linux.

In apparmor profile for specific vm with uuid cdbebdfa-1d6d-65c3-be0f-fd74b978a773
Path: /etc/apparmor.d/libvirt/libvirt-cdbebdfa-1d6d-65c3-be0f-fd74b978a773.files
The last line is for the tapfd relabelling.

 # DO NOT EDIT THIS FILE DIRECTLY. IT IS MANAGED BY LIBVIRT.
  "/var/log/libvirt/**/rhel6qcow2.log" w,
  "/var/lib/libvirt/**/rhel6qcow2.monitor" rw,
  "/var/run/libvirt/**/rhel6qcow2.pid" rwk,
  "/run/libvirt/**/rhel6qcow2.pid" rwk,
  "/var/run/libvirt/**/*.tunnelmigrate.dest.rhel6qcow2" rw,
  "/run/libvirt/**/*.tunnelmigrate.dest.rhel6qcow2" rw,
  "/var/lib/libvirt/images/rhel6u3qcow2.img" rw,
  "/dev/tap45" rw,

12 years agoInclude pid namespace inode in LXC audit messages
Daniel P. Berrange [Wed, 6 Mar 2013 14:56:49 +0000 (14:56 +0000)]
Include pid namespace inode in LXC audit messages

To allow the efficient correlation of container audit messages
with host hosts, include the pid namespace inode in audit
messages.

12 years agoAdd support for disks backed by plain files in LXC
Daniel P. Berrange [Mon, 4 Mar 2013 18:09:23 +0000 (18:09 +0000)]
Add support for disks backed by plain files in LXC

By using a loopback device, disks backed by plain files can
be made available to LXC containers. We make no attempt to
auto-detect format if <driver type="raw"/> is not set,
instead we unconditionally treat that as meaning raw. This
is to avoid the security issues inherent with format
auto-detection

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRefactor loop device setup code in LXC
Daniel P. Berrange [Mon, 4 Mar 2013 18:02:42 +0000 (18:02 +0000)]
Refactor loop device setup code in LXC

Minor re-factoring of code for setting up loop devices in
the LXC controller

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoConvert QEMU driver to use virLogProbablyLogMessage
Daniel P. Berrange [Mon, 4 Mar 2013 20:50:42 +0000 (20:50 +0000)]
Convert QEMU driver to use virLogProbablyLogMessage

The current QEMU code for skipping log messages only skips over
'debug' message, switch to virLogProbablyLogMessage to make sure
it skips over all of them

12 years agoImprove LXC startup error reporting
Daniel P. Berrange [Mon, 4 Mar 2013 20:47:37 +0000 (20:47 +0000)]
Improve LXC startup error reporting

Currently we rely on a VIR_ERROR message being logged by the
virRaiseError function to report LXC startup errors. This gives
the right message, but is rather ugly and can be truncated
if lots of log messages are written. Change the LXC controller
to explicitly print any virErrorPtr message to stderr. Then
change the driver to skip over anything that looks like a log
message.

The result is that this

error: Failed to start domain busy
error: internal error guest failed to start: 2013-03-04 19:46:42.846+0000: 1734: info : libvirt version: 1.0.2
2013-03-04 19:46:42.846+0000: 1734: error : virFileLoopDeviceAssociate:600 : Unable to open /root/disk.raw: No such file or directory

changes to

error: Failed to start domain busy
error: internal error guest failed to start: Unable to open /root/disk.raw: No such file or directory
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd method for checking if a string is (probably) a log message
Daniel P. Berrange [Mon, 4 Mar 2013 20:46:32 +0000 (20:46 +0000)]
Add method for checking if a string is (probably) a log message

When reading log output from QEMU/LXC we need to skip over any
libvirt log messages. Currently the QEMU driver checks for a
fixed string, but this is better done with a regex. Add a method
virLogProbablyLogMessage to do a regex check

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoUse VIR_MASS_CLOSE in LXC container startup
Daniel P. Berrange [Thu, 7 Mar 2013 16:39:33 +0000 (16:39 +0000)]
Use VIR_MASS_CLOSE in LXC container startup

In the LXC container startup code when switching stdio
streams, we call VIR_FORCE_CLOSE on all FDs. This triggers
a huge number of warnings, but we don't see them because
stdio is closed at this point. strace() however shows them
which can confuse people debugging the code. Switch to
VIR_MASS_CLOSE to avoid this

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoEnsure xmlSaveToBuffer is always defined
Daniel P. Berrange [Thu, 7 Mar 2013 16:38:56 +0000 (16:38 +0000)]
Ensure xmlSaveToBuffer is always defined

RHEL4 vintage libxml2 header files are missing xmlSaveToBuffer
despite the symbol existing in the binary

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix conditional build of virNetDevSetupControlFull
Daniel P. Berrange [Thu, 7 Mar 2013 16:36:57 +0000 (16:36 +0000)]
Fix conditional build of virNetDevSetupControlFull

The virNetDevSetupControlFull function was protected by a
conditional on SIOCBRADDBR, which is bogus since it does
not use that symbol. Update the conditionals around all
callers to do stricter checks to ensure we always build
succesfully

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoEnsure GET_VLAN_VID_CMD is always defined
Daniel P. Berrange [Thu, 7 Mar 2013 16:35:59 +0000 (16:35 +0000)]
Ensure GET_VLAN_VID_CMD is always defined

The RHEL4 vintage header files do not define GET_VLAN_VID_CMD.
Conditionally define it in our source, since the kernel can
raise a runtime error if it isn't supported

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoDon't import loop.h unless HAVE_DECL_LO_FLAGS_AUTOCLEAR is defined
Daniel P. Berrange [Thu, 7 Mar 2013 16:34:54 +0000 (16:34 +0000)]
Don't import loop.h unless HAVE_DECL_LO_FLAGS_AUTOCLEAR is defined

The loop.h on RHEL4 is broken and cannot be imported. We already
detect this in configure as a side-effect of looking for whether
LO_FLAGS_AUTOCLEAR is available. We protected the impl with
HAVE_DECL_LO_FLAGS_AUTOCLEAR, but not the header import

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRename 'daemon' param to 'binary' in virNetClientNewUNIX
Daniel P. Berrange [Thu, 7 Mar 2013 16:33:33 +0000 (16:33 +0000)]
Rename 'daemon' param to 'binary' in virNetClientNewUNIX

To avoid a clash with daemon() libc API, rename the
'daemon' param in the header file to 'binary'. The
source file already uses the name 'binary'.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRename 'clone' to 'clonevol' to avoid name clash with clone() syscall
Daniel P. Berrange [Thu, 7 Mar 2013 16:32:27 +0000 (16:32 +0000)]
Rename 'clone' to 'clonevol' to avoid name clash with clone() syscall

On RHEL-4 vintage one of the header files is polluted causing a
clash between the clone() syscall and the 'clone' parameter in
a libvirt driver API

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoviralloc: use consistent naming
Eric Blake [Thu, 7 Mar 2013 14:53:42 +0000 (07:53 -0700)]
viralloc: use consistent naming

Commit 0df3e89 only touched the header, but the .c file had the
same shadowing potential.

* src/util/viralloc.c (virDeleteElementsN): s/remove/toremove/ to
match the header.

12 years agorng: allow default device in RNG grammar
Eric Blake [Thu, 7 Mar 2013 14:06:53 +0000 (07:06 -0700)]
rng: allow default device in RNG grammar

This matches the documentation of commit 4932ef4, and the
C code changes of commit 75e656a.

* docs/schemas/domaincommon.rng: Allow default entry.

12 years agobuild: avoid shadowing a function name
Eric Blake [Thu, 7 Mar 2013 13:38:37 +0000 (06:38 -0700)]
build: avoid shadowing a function name

Make the same fix as in commit de53eff.

* src/util/viralloc.h (virDeleteElementsN): Cater to old glibc.

12 years agoFix crash parsing RNG device specification
Daniel P. Berrange [Thu, 7 Mar 2013 11:50:14 +0000 (11:50 +0000)]
Fix crash parsing RNG device specification

Code that validates the whitelist for the RNG device filename
didn't account for fact that filename may be NULL. This led
to a NULL reference crash. This wasn't caught since the test
suite was not covering this XML syntax

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoResolve valgrind error
John Ferlan [Wed, 6 Mar 2013 04:43:56 +0000 (23:43 -0500)]
Resolve valgrind error

Resolves the following valgrind error from qemuxml2argvtest:

==20393== 5 bytes in 1 blocks are definitely lost in loss record 2 of 60
==20393==    at 0x4A0883C: malloc (vg_replace_malloc.c:270)
==20393==    by 0x38D690A167: __vasprintf_chk (in /usr/lib64/libc-2.16.so)
==20393==    by 0x4CB0D97: virVasprintf (stdio2.h:210)
==20393==    by 0x4CB0E53: virAsprintf (virutil.c:2017)
==20393==    by 0x428DC5: qemuAssignDeviceAliases (qemu_command.c:791)
==20393==    by 0x41DF93: testCompareXMLToArgvHelper (qemuxml2argvtest.c:151)
==20393==    by 0x41F53F: virtTestRun (testutils.c:157)
==20393==    by 0x41DA9B: mymain (qemuxml2argvtest.c:885)
==20393==    by 0x41FB7A: virtTestMain (testutils.c:719)
==20393==    by 0x38D6821A04: (below main) (in /usr/lib64/libc-2.16.so)
==20393==

From qemu_command.c/line 791:

    if (def->rng) {
        if (virAsprintf(&def->rng->info.alias, "rng%d", 0) < 0)
            goto no_memory;
    }

12 years agostorage: Cleanup logical volume creation code
Jiri Denemark [Wed, 6 Mar 2013 11:57:40 +0000 (12:57 +0100)]
storage: Cleanup logical volume creation code

This patch plugs two memory leaks, removes some useless and confusing
constructs and renames renames "cleanup" label as "error" since it is
only used for error path rather then being common for both success and
error paths.

12 years agosheepdog: Adjust logic to break while loop to avoid Coverity error
John Ferlan [Tue, 5 Mar 2013 12:28:04 +0000 (07:28 -0500)]
sheepdog: Adjust logic to break while loop to avoid Coverity error

Change the various "return -1" to "break".  Avoids Coverity error and
perhaps other/future analyzer issues.

12 years agolibxl_driver: Resolve Coverity errors
John Ferlan [Thu, 28 Feb 2013 14:48:16 +0000 (09:48 -0500)]
libxl_driver: Resolve Coverity errors

1. The virObjectLock() call was unconditional, but Unlock was conditional
   on vm being valid.  Removed the check

2. A call to virDomainEventNewFromObj() isn't guaranteed to return an
   event - that check needs to be made prior to libxlDomainEventQueue()
   of the event. Did not add libxlDriverLock/Unlock around the call since
   some callers already have lock taken

3. Need to initialize fd = -1 in libxlDoDomainSave() since we can jump
   to cleanup before it's set.

4. Missing break;'s in libxlDomainModifyDeviceFlags() for case
   LIBXL_DEVICE_UPDATE.  The default: case would report an error

12 years agolibxl_conf: Resolve Coverity issue with call to regcomp()
John Ferlan [Thu, 28 Feb 2013 14:46:34 +0000 (09:46 -0500)]
libxl_conf: Resolve Coverity issue with call to regcomp()

12 years agoqemu: update domain live xml for virsh memtune with --live flag
Guannan Ren [Tue, 5 Mar 2013 16:24:57 +0000 (00:24 +0800)]
qemu: update domain live xml for virsh memtune with --live flag

virsh subcommand memtune forgot updating domain live xml
after setting cgroup value.

12 years agoutil: fix a integer boundary error
Guannan Ren [Tue, 5 Mar 2013 15:13:21 +0000 (23:13 +0800)]
util: fix a integer boundary error

A value which is equal to a integer maximum such as LLONG_MAX is
a valid integer value.

The patch fix the following error:
1, virsh memtune vm --swap-hard-limit -1
2, virsh start vm
In debug mode, it shows error like:
virScaleInteger:1813 : numerical overflow:\
                       value too large: 9007199254740991KiB

12 years agoconf: Report errors on cputune parameter parsing
Peter Krempa [Wed, 20 Feb 2013 15:15:34 +0000 (16:15 +0100)]
conf: Report errors on cputune parameter parsing

This patch adds proper error reporting if parsing of cputune parameters
fails due to incorrect values provided by the user. Previously no errors
were reported in such a case and the failure was silently ignored.

12 years agoconf: Make virDomainDeviceInfoIterate usable without os type
Peter Krempa [Wed, 20 Feb 2013 13:06:52 +0000 (14:06 +0100)]
conf: Make virDomainDeviceInfoIterate usable without os type

Make the iterator function usable in the next patches. Also refactor
some parts to avoid strcmp if not necessary.

This commit tweaks and shadows the change that was done in commit
babe7dada0f90bfde74a716e8fc963b049d76f96 and was needed after the
support for multiple console devices was added. Historically the first
<console> element is alias for the <serial> device.

12 years agoconf: whitespace cleanups and refactors with no semantic impact
Peter Krempa [Tue, 19 Feb 2013 10:55:27 +0000 (11:55 +0100)]
conf: whitespace cleanups and refactors with no semantic impact

This patch changes many unrelated places to simplify the code or update
code style. This patch should not have any semantic impact on the code.

12 years agovirsh-snapshot: Add ability to print only snapshot names
Peter Krempa [Fri, 1 Mar 2013 14:42:25 +0000 (15:42 +0100)]
virsh-snapshot: Add ability to print only snapshot names

Help script creators by not having to parse the names from the table.

12 years agoRelease of libvirt 1.0.3
Daniel Veillard [Tue, 5 Mar 2013 04:00:53 +0000 (12:00 +0800)]
Release of libvirt 1.0.3

- configure.ac docs/news.html.in libvirt.spec.in: update for the release
- po/*.po*: merged in transifex updates for fr,hi,pl,ja,uk,it and
  regenerated

12 years agorng: restrict passthrough names to known-good files
Eric Blake [Mon, 4 Mar 2013 22:42:07 +0000 (15:42 -0700)]
rng: restrict passthrough names to known-good files

There is some controversy[1] on the qemu list on whether qemu should
have ever allowed arbitrary file name passthrough, or whether it
should be restricted to JUST /dev/random and /dev/hwrng.  It is
always easier to add support for additional filenames than it is
to remove support for something once released, so this patch
restricts libvirt 1.0.3 (where the virtio-random backend was first
supported) to just the two uncontroversial names, letting us defer
to a later date any decision on whether supporting arbitrary files
makes sense. Additionally, since qemu 1.4 does NOT support
/dev/fdset/nnn fd passthrough for the backend, limiting to just
two known names means that we don't get tempted to try fd
passthrough where it won't work.

[1]https://lists.gnu.org/archive/html/qemu-devel/2013-03/threads.html#00023

* src/conf/domain_conf.c (virDomainRNGDefParseXML): Only allow
/dev/random and /dev/hwrng.
* docs/schemas/domaincommon.rng: Flag invalid files.
* docs/formatdomain.html.in (elementsRng): Document this.
* tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args:
Update test to match.
* tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml:
Likewise.

12 years agointernals: Update to include RPC and Lock links and add new data
John Ferlan [Sat, 16 Feb 2013 12:43:31 +0000 (07:43 -0500)]
internals: Update to include RPC and Lock links and add new data

Added a picture and explanation describing the virConnectOpen processing
at a "higher" level, but with some source code references.

12 years agoAdd references for phyp and parallels
John Ferlan [Thu, 14 Feb 2013 15:06:58 +0000 (10:06 -0500)]
Add references for phyp and parallels

12 years agoapi: Add text and references for daemon
John Ferlan [Thu, 14 Feb 2013 15:04:13 +0000 (10:04 -0500)]
api: Add text and references for daemon

12 years agoapi: Add text and references for drivers section
John Ferlan [Tue, 12 Feb 2013 19:01:49 +0000 (14:01 -0500)]
api: Add text and references for drivers section

12 years agoapi: Complete list of function and naming conventions
John Ferlan [Tue, 12 Feb 2013 17:58:42 +0000 (12:58 -0500)]
api: Complete list of function and naming conventions

12 years agoapi: Reword and clean lists for object description
John Ferlan [Tue, 12 Feb 2013 17:53:59 +0000 (12:53 -0500)]
api: Reword and clean lists for object description

12 years agoapi: Reword objects exposed section
John Ferlan [Tue, 12 Feb 2013 17:48:46 +0000 (12:48 -0500)]
api: Reword objects exposed section

12 years agohellolibvirt: Adjust code to use new APIs
John Ferlan [Tue, 26 Feb 2013 14:11:10 +0000 (09:11 -0500)]
hellolibvirt: Adjust code to use new APIs

Change the order of some conditions and use the AllDomains API to get
a list of all the active and defined domains, then use the Active and
Name API's in order to print.

This changes here adjust the output from:

Attempting to connect to hypervisor
Connected to hypervisor at "qemu:///system"
Hypervisor: "QEMU" version: 0.32.656
There are 0 active and 2 inactive domains
Inactive domains:
  foo
  bar
Disconnected from hypervisor

to

Attempting to connect to hypervisor
Connected to hypervisor at "qemu:///system"
Hypervisor: "QEMU" version: 0.32.656
There are 0 active and 2 inactive domains
       foo (non-active)
       bar (non-active)
Disconnected from hypervisor

12 years agolibvirt: Update headers for doc
John Ferlan [Tue, 12 Feb 2013 17:50:16 +0000 (12:50 -0500)]
libvirt: Update headers for doc

Update the function prototypes to include a message about the client needing
to free() returned name fields.  Fix the all domains example flags values.

12 years agoFix TLS tests with gnutls 3
Daniel P. Berrange [Mon, 4 Mar 2013 17:27:38 +0000 (17:27 +0000)]
Fix TLS tests with gnutls 3

When given a CA cert with basic constraints to set non-critical,
and key usage of 'key signing', this should be rejected. Version
of GNUTLS < 3 do not rejecte it though, so we never noticed the
test case was broken

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoqemu: fix wrong evaluation in qemuDomainSetMemoryParameters
Satoru Moriya [Mon, 4 Mar 2013 17:27:45 +0000 (17:27 +0000)]
qemu: fix wrong evaluation in qemuDomainSetMemoryParameters

19c6ad9a (qemu: Refactor qemuDomainSetMemoryParameters) introduced
a new macro, VIR_GET_LIMIT_PARAMETER(PARAM, VALUE). But if statement
in the macro is not correct and so set_XXXX flags are set to false
in the wrong. As a result, libvirt ignores all memtune parameters.
This patch fixes the conditional expression to work correctly.

Signed-off-by: Satoru Moriya <satoru.moriya@hds.com>
12 years agoutil: use string libvirt to prefix error message instead of libvir
Guannan Ren [Mon, 4 Mar 2013 12:38:18 +0000 (20:38 +0800)]
util: use string libvirt to prefix error message instead of libvir

BZ:https://bugzilla.redhat.com/show_bug.cgi?id=912021
Without error handler set, virDefaultErrorFunc will be called, the
error message is prefixed with "libvir:". It become a little better
by using prefix "libvirt:" when working with upper application.

For example:
1, stop libvirtd daemon
2, run virt-top.
libvir: XML-RPC error : Failed to connect \
        socket to '/var/run/libvirt/libvirt-sock-ro': \
        No such file or directory
libvirt: VIR_ERR_SYSTEM_ERROR: VIR_FROM_RPC: \
        Failed to connect socket to '/var/run/libvirt/libvirt-sock-ro': \
        No such file or directory

12 years agolibvirt does not logout of iscsi targets, causing system hang on shutdown
Fritz Elfert [Thu, 28 Feb 2013 20:46:19 +0000 (21:46 +0100)]
libvirt does not logout of iscsi targets, causing system hang on shutdown

There's a quite old bug entry here:

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

I just stumbled over that very issue on F18. Doing a little bit
debugging of the shutdown sequence, it turns out that - at least on my
F18 installation - libvirtd is shutdown *after* iscsid, which makes it
impossible for libvirt to perform the logout of the iscsi session properly.

This patch simply adds another startup dependancy on iscsid.service
which in turn delays iscsid shutdown until after libvirtd has stopped.
Having that applied, the system shuts down properly again.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agoqemu: Remove managed save flag from VM when starting with --force-boot
Peter Krempa [Mon, 4 Mar 2013 11:10:28 +0000 (12:10 +0100)]
qemu: Remove managed save flag from VM when starting with --force-boot

At the start of the guest after the image is unlinked the state wasn't
touched up to match the state on disk.

12 years agoqemu: Use -1 as unpriviledged uid/gid
Christophe Fergeau [Sat, 2 Mar 2013 14:19:47 +0000 (15:19 +0100)]
qemu: Use -1 as unpriviledged uid/gid

Commit f506a4c1 changed virSetUIDGID() to be a noop
when uid/gid are -1, while it used to be a noop when
they are <= 0.

The changes in this commit broke creating new VMs in GNOME Boxes
as qemuDomainCheckDiskPresence gets called during domain creation/startup,
which in turn calls virFileAccessibleAs which fails after calling
virSetUIDGID(0, 0) (Boxes uses session libvirtd). virSetUIDGID is called with
(0, 0) as these are the default user/group values in virQEMUDriverConfig
for session libvirtd.

This commit changes virQEMUDriverConfigNew to use -1 as the unpriviledged
uid/gid. I've also looked at the various places where cfg->user is used,
and they all seem to handle -1 correctly.

12 years agohook: log the exit status of the hook not 256
Guido Günther [Sun, 24 Feb 2013 18:43:04 +0000 (19:43 +0100)]
hook: log the exit status of the hook not 256

Adjust the docs accordingly. See http://bugs.debian.org/701570.

12 years agovirnetdevmacvlan.c: Introduce mutex for macvlan creation
Michal Privoznik [Thu, 28 Feb 2013 14:59:01 +0000 (15:59 +0100)]
virnetdevmacvlan.c: Introduce mutex for macvlan creation

Currently, after we removed the qemu driver lock, it may happen
that two or more threads will start up a machine with macvlan and
race over virNetDevMacVLanCreateWithVPortProfile(). However,
there's a racy section in which we are generating a sequence of
possible device names and detecting if they exits. If we found
one which doesn't we try to create a device with that name.
However, the other thread is doing just the same. Assume it will
succeed and we must therefore fail. If this happens more than 5
times (which in massive parallel startup surely will) we return
-1 without any error reported. This patch is a simple hack to
both of these problems. It introduces a mutex, so only one thread
will enter the section, and if it runs out of possibilities,
error is reported. Moreover, the number of retries is raised to 20.

12 years agoRevert hack for autodestroy in qemuProcessStop
Daniel P. Berrange [Thu, 28 Feb 2013 16:43:43 +0000 (16:43 +0000)]
Revert hack for autodestroy in qemuProcessStop

This reverts the hack done in

commit 568a6cda277f04ab9baaeb97490e548b7b608aa6
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Fri Feb 15 15:11:47 2013 +0100

    qemu: Avoid deadlock in autodestroy

since we now have a fix which avoids the deadlock scenario
entirely

12 years agoFix deadlock in QEMU close callback APIs
Daniel P. Berrange [Thu, 28 Feb 2013 13:30:49 +0000 (13:30 +0000)]
Fix deadlock in QEMU close callback APIs

There is a lock ordering problem in the QEMU close callback
APIs.

When starting a guest we have a lock on the VM. We then
set a autodestroy callback, which acquires a lock on the
close callbacks.

When running auto-destroy, we obtain a lock on the close
callbacks, then run each callbacks - which obtains a lock
on the VM.

This causes deadlock if anyone tries to start a VM, while
autodestroy is taking place.

The fix is to do autodestroy in 2 phases. First obtain
all the callbacks and remove them from the list under
the close callback lock. Then invoke each callback
from outside the close callback lock.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix crash in QEMU auto-destroy with transient guests
Daniel P. Berrange [Thu, 28 Feb 2013 12:18:48 +0000 (12:18 +0000)]
Fix crash in QEMU auto-destroy with transient guests

When the auto-destroy callback runs it is supposed to return
NULL if the virDomainObjPtr is no longer valid. It was not
doing this for transient guests, so we tried to virObjectUnlock
a mutex which had been freed. This often led to a crash.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agopython: fix fd leak in generator.py
Guannan Ren [Thu, 28 Feb 2013 10:03:46 +0000 (18:03 +0800)]
python: fix fd leak in generator.py

12 years agopython: fix typoes and repeated global vars references
Guannan Ren [Thu, 28 Feb 2013 10:03:44 +0000 (18:03 +0800)]
python: fix typoes and repeated global vars references

12 years agoqemu: Make sure qemuProcessStart is run within a job
Jiri Denemark [Thu, 28 Feb 2013 11:48:01 +0000 (12:48 +0100)]
qemu: Make sure qemuProcessStart is run within a job

qemuProcessStart expects to be run with a job already set and every
caller except for qemuMigrationPrepareAny use it correctly. This bug can
be observed in libvirtd logs during incoming migration as

    warning : qemuDomainObjEnterMonitorInternal:979 : This thread seems
    to be the async job owner; entering monitor without asking for a
    nested job is dangerous

12 years agoFix starting qemu instances when apparmor driver is enabled
Jim Fehlig [Wed, 27 Feb 2013 23:32:35 +0000 (16:32 -0700)]
Fix starting qemu instances when apparmor driver is enabled

With the apparmor security driver enabled, qemu instances fail
to start

# grep ^security_driver /etc/libvirt/qemu.conf
security_driver = "apparmor"
# virsh start test-kvm
error: Failed to start domain test-kvm
error: internal error security label already defined for VM

The model field of virSecurityLabelDef object is always populated
by virDomainDefGetSecurityLabelDef(), so remove the check for a
NULL model when verifying if a label is already defined for the
instance.

Checking for a NULL model and populating it later in
AppArmorGenSecurityLabel() has been left in the code to be
consistent with virSecuritySELinuxGenSecurityLabel().

12 years agoFix a message typo
Serge Hallyn [Thu, 28 Feb 2013 22:08:43 +0000 (16:08 -0600)]
Fix a message typo

As pointed out in
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1034661
The sentence

"The function of PCI device addresses must less than 8"

does not quite make sense.  Update that to read

"The function of PCI device addresses must be less than 8"

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
12 years agoqemu: Don't fail to shutdown domains with unresponsive agent
Michal Privoznik [Mon, 25 Feb 2013 17:52:12 +0000 (18:52 +0100)]
qemu: Don't fail to shutdown domains with unresponsive agent

Currently, qemuDomainShutdownFlags() chooses the agent method of
shutdown whenever the agent is configured. However, this
assumption is not enough as the guest agent may be unresponsive
at the moment. So unless guest agent method has been explicitly
requested, we should fall back to the ACPI method.

12 years agoqemu: virConnectGetVersion returns bogus value
Viktor Mihajlovski [Thu, 28 Feb 2013 10:11:17 +0000 (11:11 +0100)]
qemu: virConnectGetVersion returns bogus value

The unitialized local variable qemuVersion can cause an random value
to be returned for the hypervisor version, observable with virsh version.
Introduced by commit b46f7f4a0b96c2d2d01d64d960bd7bc90dc16b0c

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoqemu: fix use-after-free when parsing NBD disk
Paolo Bonzini [Mon, 25 Feb 2013 17:44:20 +0000 (18:44 +0100)]
qemu: fix use-after-free when parsing NBD disk

disk->src is still used for disks->hosts->name, do not free it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agomaint: fix typo in network docs
Eric Blake [Thu, 28 Feb 2013 04:18:04 +0000 (21:18 -0700)]
maint: fix typo in network docs

* docs/formatnetwork.html.in: Spell variation correctly.

12 years agoDon't try to add non-existant devices to ACL
Daniel P. Berrange [Wed, 27 Feb 2013 16:57:16 +0000 (16:57 +0000)]
Don't try to add non-existant devices to ACL

The QEMU driver has a list of devices nodes that are whitelisted
for all guests. The kernel has recently started returning an
error if you try to whitelist a device which does not exist.
This causes a warning in libvirt logs and an audit error for
any missing devices. eg

2013-02-27 16:08:26.515+0000: 29625: warning : virDomainAuditCgroup:451 : success=no virt=kvm resrc=cgroup reason=allow vm="vm031714" uuid=9d8f1de0-44f4-a0b1-7d50-e41ee6cd897b cgroup="/sys/fs/cgroup/devices/libvirt/qemu/vm031714/" class=path path=/dev/kqemu rdev=? acl=rw

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix typo in internal VIR_QEMU_PROCESS_START_AUTODESROY constant
Daniel P. Berrange [Wed, 27 Feb 2013 16:53:08 +0000 (16:53 +0000)]
Fix typo in internal VIR_QEMU_PROCESS_START_AUTODESROY constant

s/VIR_QEMU_PROCESS_START_AUTODESROY/VIR_QEMU_PROCESS_START_AUTODESTROY/

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAvoid spamming logs with cgroups warnings
Daniel P. Berrange [Wed, 27 Feb 2013 16:51:04 +0000 (16:51 +0000)]
Avoid spamming logs with cgroups warnings

The code for putting the emulator threads in a separate cgroup
would spam the logs with warnings

2013-02-27 16:08:26.731+0000: 29624: warning : virCgroupMoveTask:887 : no vm cgroup in controller 3
2013-02-27 16:08:26.731+0000: 29624: warning : virCgroupMoveTask:887 : no vm cgroup in controller 4
2013-02-27 16:08:26.732+0000: 29624: warning : virCgroupMoveTask:887 : no vm cgroup in controller 6

This is because it has only created child cgroups for 3 of the
controllers, but was trying to move the processes from all the
controllers. The fix is to only try to move threads in the
controllers we actually created. Also remove the warning and
make it return a hard error to avoid such lazy callers in the
future.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix autodestroy of QEMU guests
Daniel P. Berrange [Wed, 27 Feb 2013 16:23:16 +0000 (16:23 +0000)]
Fix autodestroy of QEMU guests

The virQEMUCloseCallbacksRunOne method was passing a uuid string
to virDomainObjListFindByUUID, when it actually expected to get
a raw uuid buffer. This was not caught by the compiler because
the method was using a 'void *uuid' instead of first casting
it to the expected type.

This regression was accidentally caused by refactoring in

  commit 568a6cda277f04ab9baaeb97490e548b7b608aa6
  Author: Jiri Denemark <jdenemar@redhat.com>
  Date:   Fri Feb 15 15:11:47 2013 +0100

    qemu: Avoid deadlock in autodestroy

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoqemu: -numa doesn't (yet) support disjoint range
Eric Blake [Wed, 27 Feb 2013 00:43:12 +0000 (17:43 -0700)]
qemu: -numa doesn't (yet) support disjoint range

https://bugzilla.redhat.com/show_bug.cgi?id=896092 mentions that
qemu 1.4 and earlier only accept a simple start-stop range for
the cpu=... argument of -numa.  Libvirt would attempt to use
-numa cpu=1,3 for a disjoint range, which did not work as intended.

Upstream qemu will be adding a new syntax for disjoint cpu ranges
in 1.5; but the design for that syntax is still under discussion
at the time of this patch.  So for libvirt 1.0.3, it is safest to
just reject attempts to build an invalid qemu command line; in the
future, we can add a capability bit and translate to the final
accepted design for selecting a disjoint cpu range in numa.

* src/qemu/qemu_command.c (qemuBuildNumaArgStr): Reject disjoint
ranges.

12 years agoRevert "Add support for <option> tag in network config"
Laine Stump [Wed, 27 Feb 2013 15:55:24 +0000 (10:55 -0500)]
Revert "Add support for <option> tag in network config"

This reverts commit 383ebc46947b0119123880c1ff9ae345fdb8d5f6.

We decided the xml for this feature needed more thought to make sure
we are doing it the best way, in particular wrt option values that
have multiple items.

12 years agoutil: Add docs for virXMLProp string
Peter Krempa [Thu, 21 Feb 2013 10:07:55 +0000 (11:07 +0100)]
util: Add docs for virXMLProp string

To avoid confusion about usage of this function explicitly document that
this function returns copy of the attribute string.

12 years agotests: Test XML entities in source path for RNG device
Peter Krempa [Mon, 25 Feb 2013 22:18:44 +0000 (23:18 +0100)]
tests: Test XML entities in source path for RNG device

Users may want to specify XML entities in paths to devices. Ensure they
are parsed and used properly.

12 years agodocs: Fix attribute name for virtio-rng backend
Peter Krempa [Mon, 25 Feb 2013 22:03:21 +0000 (23:03 +0100)]
docs: Fix attribute name for virtio-rng backend

12 years agotests: fix leaks in storagevolxml2argvtest
Ján Tomko [Wed, 27 Feb 2013 09:11:52 +0000 (10:11 +0100)]
tests: fix leaks in storagevolxml2argvtest

Reported by John Ferlan.

12 years agolibvirt.c: Make VIR_MIGRATE_NON_SHARED_{INC,DISK} mutually exclusive
Michal Privoznik [Tue, 26 Feb 2013 16:18:08 +0000 (17:18 +0100)]
libvirt.c: Make VIR_MIGRATE_NON_SHARED_{INC,DISK} mutually exclusive

These two flags in fact are mutually exclusive. Requesting them both
doesn't make any sense regardless of hypervisor driver. Hence, we have
to make it within libvirt.c file instead of fixing it in each driver.

12 years agodoc: document new storage volume/pool types
Philipp Hahn [Tue, 26 Feb 2013 12:41:21 +0000 (13:41 +0100)]
doc: document new storage volume/pool types

Add qed for dirfs pool.
Add ocfs2 for disk pool.
Add lvm2 for disk and logical pool.
Add cifs and glusterfs for netfs pool.

Note: POOL_DISK_LVM2 can not be created by "parted mklabel", but is only
returned from auto-detection on disk pools.

Signed-off-by: Philipp Hahn <hahn@univention.de>
12 years agobuild: don't use gcrypt.h without gnutls support
Eric Blake [Tue, 26 Feb 2013 23:43:03 +0000 (16:43 -0700)]
build: don't use gcrypt.h without gnutls support

Eugene Marcotte reported that if gcrypt-devel (a prereq of
gnutls-devel) is not present, then compilation fails due to
an unconditional use of <gcrypt.h>.

* src/libvirt.c (includes): Properly guard use of gcrypt.h.

12 years agoRevert "S390: domain_conf support for CCW"
Eric Blake [Tue, 26 Feb 2013 23:32:15 +0000 (16:32 -0700)]
Revert "S390: domain_conf support for CCW"

This reverts commit 0bbbd42c30543d8251536c2fa11166834c886ada.

The design for this feature is not complete, and may change the
name of the 'schid' attribute.  Revert requested by Viktor Mihajlovski.

12 years agoRevert "S390: Documentation for CCW address type"
Eric Blake [Tue, 26 Feb 2013 23:31:27 +0000 (16:31 -0700)]
Revert "S390: Documentation for CCW address type"

This reverts commit 24aa7f8d11054b7b2e643cf3cd5c80a199764af0.

The implementation to match the documentation is not complete yet,
and the final design might change the name of the 'schid' attribute.

12 years agoschema: Restrict mode to octal
Philipp Hahn [Tue, 26 Feb 2013 08:14:20 +0000 (09:14 +0100)]
schema: Restrict mode to octal

virStrToLong(..., 8, ...) already requires the mode to be octal.
Change the relax-ng schema to check for octal as well.

Signed-off-by: Philipp Hahn <hahn@univention.de>
12 years agotests: skip virstoragetest on RHEL 5
Eric Blake [Tue, 26 Feb 2013 19:45:38 +0000 (12:45 -0700)]
tests: skip virstoragetest on RHEL 5

virstoragetest was failing on RHEL 5, but with no good error message:

TEST: virstoragetest
                                        0   FAIL

It turns out that qemu-img was so old, that it lacked support for
-o backing_file.  It didn't help that the test was also using
qemu-img from PATH, even after first probing for kvm-img.

* tests/virstoragetest.c (testPrepImages): Consistently use
discovered binary.  Skip instead of fail if qemu-img fails during
setup.

12 years agointerface: udev backend coverity NULL deref
Doug Goldstein [Tue, 26 Feb 2013 06:27:19 +0000 (00:27 -0600)]
interface: udev backend coverity NULL deref

This fixes a potential NULL deref identified by John Ferlan
<jferlan@redhat.com> if scandir() didn't return an expected value.

12 years agoRemove some C99 variable decls in parallels driver
Daniel P. Berrange [Tue, 26 Feb 2013 17:52:40 +0000 (17:52 +0000)]
Remove some C99 variable decls in parallels driver

The parallels storage driver declared some loop variables
inside the for(;;). This is not allowed by libvirt coding
standards

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix crash changing CDROM media
Daniel P. Berrange [Mon, 25 Feb 2013 17:22:14 +0000 (17:22 +0000)]
Fix crash changing CDROM media

This change tried to fix a crash with changing CDROM media but
failed to actually do so

  commit d0172d2b1b5d865aaa042070d7c2d00effb2ff8c
  Author: Osier Yang <jyang@redhat.com>
  Date:   Tue Feb 19 20:27:45 2013 +0800

    qemu: Remove the shared disk entry if the operation is ejecting or updating

It was still accessing disk->src, when the entire 'disk' object
has been free'd already. Even if it weren't free'd, accessing
the 'src' value of virDomainDiskDef is not allowed without
first validating disk->type is file or block. Just remove the
broken code entirely.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agotests: old automake lacks abs_builddir
Eric Blake [Tue, 26 Feb 2013 16:40:38 +0000 (09:40 -0700)]
tests: old automake lacks abs_builddir

On RHEL 5, 'make check' included failures such as:

TEST: virstoragetest
unable to create directory /virstoragedata/sub
unable to return to correct directory, refusing to clean up /virstoragedata

It turns out that with automake 1.9.x, $(abs_builddir) is not
automatically provided.  We have previously worked around this
by using `pwd` before, but because we did not do it everywhere,
we had a number of broken tests.

This patch brings RHEL 5 from 8 failed tests down to 5 (the
remaining failures may be due to bugs in the older libxml2 and
RNG schema validation available in RHEL 5, so I'm not sure if
they can be fixed in libvirt, but I'm still investigating).

* tests/Makefile.am (AM_CFLAGS): Reliably set abs_builddir.
(*_la_CFLAGS): Factor out common settings; delete when nothing
remains to be added.

12 years agotests: consistent skip messages
Eric Blake [Tue, 26 Feb 2013 16:36:27 +0000 (09:36 -0700)]
tests: consistent skip messages

On RHEL 5, I noticed this test failure message:

TEST: qemumonitorjsontest
libvirt not compiled with yajl, skippingSKIP: qemumonitorjsontest

* tests/virstoragetest.c (testPrepImages): Use simpler fputs.
* tests/qemumonitorjsontest.c (mymain): Ensure trailing newline.

12 years agolibvirt: fix error message when connection can't be opened
Ján Tomko [Tue, 26 Feb 2013 12:00:08 +0000 (13:00 +0100)]
libvirt: fix error message when connection can't be opened

VIR_ERR_NO_CONNECT already contains "no connection driver available".

This patch changes:
no connection driver available for No connection for URI hello
to:
no connection driver available for hello

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

12 years agoqemu: do not set unpriv_sgio if neither supported nor requested
Paolo Bonzini [Mon, 25 Feb 2013 16:38:32 +0000 (17:38 +0100)]
qemu: do not set unpriv_sgio if neither supported nor requested

Currently we call virSetDeviceUnprivSGIO with val == 0 if a block device
has an sgio attribute.  But for sgio='filtered', we know that a
kernel with no unpriv_sgio support will always behave as the user
wanted.  In this case, there is no need to call the function and
report a (bogus) error.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12 years agotests: uniformly report test failures
Eric Blake [Fri, 22 Feb 2013 22:42:39 +0000 (15:42 -0700)]
tests: uniformly report test failures

testutils.c likes to print summaries after a test completes,
including if it failed.  But if the test outright exit()s,
this summary is skipped.  Enforce that we return instead of exit.

* cfg.mk (sc_prohibit_exit_in_tests): New syntax check.
* tests/commandhelper.c (main): Fix offenders.
* tests/qemumonitorjsontest.c (mymain): Likewise.
* tests/seclabeltest.c (main): Likewise.
* tests/securityselinuxlabeltest.c (mymain): Likewise.
* tests/securityselinuxtest.c (mymain): Likewise.
* tests/testutils.h (VIRT_TEST_MAIN_PRELOAD): Likewise.
* tests/testutils.c (virtTestMain): Likewise.
(virtTestCaptureProgramOutput): Use symbolic name.

12 years agotests: don't test json when not compiled in
Eric Blake [Fri, 22 Feb 2013 22:28:53 +0000 (15:28 -0700)]
tests: don't test json when not compiled in

Now that the segfault is solved, we can skip instead of fail
the test when yajl is not present.

* tests/qemumonitorjsontest.c (mymain): Skip if no yajl.

12 years agotests: avoid segfault if json monitor not present
Eric Blake [Fri, 22 Feb 2013 21:56:21 +0000 (14:56 -0700)]
tests: avoid segfault if json monitor not present

On a machine without yajl headers, I was seeing random segfaults
from qemumonitorjsontest (about 90% of the runs on my particular
machine).  The segfault was inside virClassIsDerivedFrom, which
points to a case of a race leading to unreferencing a stale
pointer to an object that had already been freed.  I also noticed
that if I got the segfault, I was seeing messages such as:

2013-02-22 16:12:37.504+0000: 19833: error : virNetSocketWriteWire:1361 : Cannot write data: Bad file descriptor

which is also evidence of deferencing a stale pointer.  I traced it
to a race where qemuMonitorTestIO could execute late, after the
main thread had already called qemuMonitorTestFree and called
virNetSocketClose(test->client) but not clearing it out to NULL.
Sure enough, after test->client has been closed, fd is -1, which
causes an attempt to write to the socket to fail, which in turn
triggers the error code of qemuMonitorTestIO that tries to re-close
test->client.

* tests/qemumonitortestutils.c (qemuMonitorTestIO): Don't attempt
to free client again if test already quit.