]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
11 years agoqemuDomainObjStart: Warn on corrupted image
Michal Privoznik [Mon, 11 Nov 2013 15:37:16 +0000 (16:37 +0100)]
qemuDomainObjStart: Warn on corrupted image

If the managedsave image is corrupted, e.g. the XML part is, we fail to
parse it and throw an error, e.g.:

error: Failed to start domain jms8
error: XML error: missing security model when using multiple labels

This is okay, as we can't really start the machine and avoid undefined
qemu behaviour. On the other hand, the error message doesn't give a
clue to users what should they do. The consensus here would be to thrown
a warning to logs saying "Hey, you've got a corrupted file".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agodocs: fix typos in libvirt.h.in
Chen Hanxiao [Mon, 11 Nov 2013 09:53:17 +0000 (17:53 +0800)]
docs: fix typos in libvirt.h.in

s/repersents/represents

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agovirSecurityLabelDefParseXML: Don't parse label on model='none'
Michal Privoznik [Mon, 11 Nov 2013 08:58:31 +0000 (09:58 +0100)]
virSecurityLabelDefParseXML: Don't parse label on model='none'

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

If there's the following snippet in the domain XML, the domain will be
lost upon the daemon restart (if the domain is started prior restart):

    <seclabel type='dynamic' relabel='yes'/>

The problem is, the 'label', 'imagelabel' and 'baselabel' are parsed
whenever the VIR_DOMAIN_XML_INACTIVE is *not* present or the label is
static. The latter is not our case, obviously. So, when libvirtd starts
up, it finds domain state xml and parse it. During parsing, many XML
flags are enabled but VIR_DOMAIN_XML_INACTIVE. Hence, our parser tries
to extract 'label', 'imagelabel' and 'baselabel' from the XML which
fails for model='none'. Err, this model - even though not specified in
XML - can be taken from qemu wide config file: /etc/libvirtd/qemu.conf.

However, in order to know we are dealing with model='none' the code in
question must be moved forward a bit. Then a new check must be
introduced. This is what the first two chunks are doing.

But this alone is not sufficient. The domain state XML won't contain the
model attribute without slight modification. The model should be
inserted into the XML even if equal to 'none' and the state XML is being
generated - what if the origin (the @security_driver variable in
qemu.conf) changes during libvirtd restarts?

At the end, a test to catch this scenario is introduced.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirsh-domain: Mark --live and --config mutually exclusive in vcpucount
Peter Krempa [Wed, 30 Oct 2013 12:58:09 +0000 (13:58 +0100)]
virsh-domain: Mark --live and --config mutually exclusive in vcpucount

The 'vcpucount' command is a getter command for the vCPUu count. When
one or more of the filtering flags are specified the command returns the
value only for the selected combination. In this case the --live and
--config combination isn't valid. This however didn't cause errors as
the combination of flags was rejected by the libvirt API but then the
fallback code kicked in and requested the count in a way where the clash
of the flags didn't matter.

Mark the flag combination mutually exclusive so that users aren't
confused.

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

11 years agodocs: fix virDomainRestoreFlags description bug
Wang Yufei [Thu, 7 Nov 2013 08:44:04 +0000 (16:44 +0800)]
docs: fix virDomainRestoreFlags description bug

In virDomainRestoreFlags with VIR_DOMAIN_SAVE_BYPASS_CACHE, it risks
slowing restores from NFS, but not saves to NFS.

Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
11 years agodocs: grammar fixes
Eric Blake [Fri, 8 Nov 2013 16:39:25 +0000 (09:39 -0700)]
docs: grammar fixes

Fix some user-visible wording from commits 72aafe9 and 1606d89.

* src/qemu/qemu.conf (migration_address): Better wording.
* include/libvirt/libvirt.h.in (VIR_MIGRATE_PARAM_LISTEN_ADDRESS):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoqemu: Fix SCSI hotplug on pseries guests
Vitor de Lima [Wed, 6 Nov 2013 16:13:55 +0000 (14:13 -0200)]
qemu: Fix SCSI hotplug on pseries guests

This patch moves some code in the qemuDomainAttachSCSIDisk
function. The check for the existence of a PCI address assigned
to the SCSI controller was moved in order to be executed only
when needed. The PCI address of a controller is not necessary
if QEMU_CAPS_DEVICE is supported.

This fixes issues with the hotplug of SCSI disks on pseries guests.

11 years agopci: properly handle out-of-order SRIOV virtual functions
Laine Stump [Tue, 5 Nov 2013 10:13:05 +0000 (12:13 +0200)]
pci: properly handle out-of-order SRIOV virtual functions

This resolves:

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

When virPCIGetVirtualFunctions created the list of an SRIOV Physical
Function's (PF) Virtual Functions (VF), it had assumed that the order
of "virtfn*" links returned by readdir() from the PF's sysfs directory
was already in the correct order. Experience has shown that this is
not always the case - it can be in alphabetical order (which would
e.g. place virtfn11 before virtfn2) or even some seemingly random
order (see the example in the bugzilla report)

This results in 1) incorrect assumptions made by consumers of the
output of the virt_functions list of virsh nodedev-dumpxml, and 2)
setting MAC address and vlan tag on the wrong VF (since libvirt uses
netlink to set mac address and vlan tag, netlink requires the VF#, and
the function virPCIGetVirtualFunctionIndex() returns the wrong index
due to the improperly ordered VF list).

The solution provided by this patch is for virPCIGetVirtualFunctions
to no longer scan the entire device directory in its natural order,
but instead to check for links individually by name "virtfn%d" where
%d starts at 0 and increases with each success. Since VFs are created
contiguously by the kernel, this will guarantee that all VFs are
found, and placed in the arry in the correct order.

One note of use to the uninitiated is that VIR_APPEND_ELEMENT always
either increments *num_virtual_functions or fails, so no this isn't an
endless loop.

(NB: the SRIOV_* defines at the top of virpci.c were removed
because they are unnecessary and/or not used.)

11 years agoutil: use size_t instead of unsigned int for num_virtual_functions
Laine Stump [Fri, 8 Nov 2013 10:39:08 +0000 (12:39 +0200)]
util: use size_t instead of unsigned int for num_virtual_functions

This is a prerequisite to the fix for the fix to:

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

num_virtual_functions needs to be size_t in order to use the
VIR_APPEND_ELEMENT macro.

11 years agoqemu: assign PCI address to primary video card
Vitor de Lima [Wed, 6 Nov 2013 16:13:54 +0000 (14:13 -0200)]
qemu: assign PCI address to primary video card

When adding support for Q35 guests, the code to assign a PCI address
to the primary video card was moved into Q35 and i440fx(PIIX3)
specific functions, but no fallback was kept for other machine types
that might have a video card.

This patch remedies that by assigning a PCI address to the primary
video card if it does not have any kind of address.  In particular,
this fixes issues with pseries guests.

Signed-off-by: Vitor de Lima <vitor.lima@eldorado.org.br>
Signed-off-by: Laine Stump <laine@laine.org>
11 years agoutil: use -w flag when calling iptables
Serge Hallyn [Fri, 1 Nov 2013 17:36:59 +0000 (12:36 -0500)]
util: use -w flag when calling iptables

When supported, ask iptables to wait rather than fail if it is in use
by another caller (like ufw).

(See https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1245322)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoqemu: process: Validate specific CPUID flags of a guest
Peter Krempa [Mon, 14 Oct 2013 09:35:00 +0000 (11:35 +0200)]
qemu: process: Validate specific CPUID flags of a guest

When starting a VM the qemu process may filter out some requested
features of a domain as it's not supported either by the host or by
qemu. Libvirt didn't check if this happened which might end up in
changing of the guest ABI when migrating.

The proof of concept implementation adds the check for the recently
introduced kvm_pv_unhalt cpuid feature bit. This feature depends on both
qemu and host kernel support and thus increase the possibility of guest
ABI breakage.

11 years agoqemu: Add support for paravirtual spinlocks in the guest
Peter Krempa [Mon, 23 Sep 2013 16:32:11 +0000 (18:32 +0200)]
qemu: Add support for paravirtual spinlocks in the guest

The linux kernel recently added support for paravirtual spinlock
handling to avoid performance regressions on overcomitted hosts. This
feature needs to be turned in the hypervisor so that the guest OS is
notified about the possible support.

This patch adds a new feature "paravirt-spinlock" to the XML and
supporting code to enable the "kvm_pv_unhalt" pseudo CPU feature in
qemu.

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

11 years agoconf: Refactor storing and usage of feature flags
Peter Krempa [Mon, 23 Sep 2013 13:02:38 +0000 (15:02 +0200)]
conf: Refactor storing and usage of feature flags

Currently we were storing domain feature flags in a bit field as the
they were either enabled or disabled. New features such as paravirtual
spinlocks however can be tri-state as the default option may depend on
hypervisor version.

To allow storing tri-state feature state in the same place instead of
having to declare dedicated variables for each feature this patch
refactors the bit field to an array.

11 years agocpu: x86: Add internal CPUID features support and KVM feature bits
Peter Krempa [Wed, 9 Oct 2013 09:42:24 +0000 (11:42 +0200)]
cpu: x86: Add internal CPUID features support and KVM feature bits

Some of the emulator features are presented in the <features> element in
the domain XML although they are virtual CPUID feature bits when
presented to the guest. To avoid confusing the users with these
features, as they are not configurable via the <cpu> element, this patch
adds an internal array where those can be stored privately instead of
exposing them in the XML.

Additionaly KVM feature bits are added as example usage of this code.

11 years agoqemu: Add monitor APIs to fetch CPUID data from QEMU
Jiri Denemark [Mon, 22 Jul 2013 11:07:23 +0000 (13:07 +0200)]
qemu: Add monitor APIs to fetch CPUID data from QEMU

The qemu monitor supports retrieval of actual CPUID bits presented to
the guest using QMP monitor. Add APIs to extract these information and
tests for them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
11 years agocpu_x86: Refactor storage of CPUID data to add support for KVM features
Peter Krempa [Mon, 7 Oct 2013 13:26:17 +0000 (15:26 +0200)]
cpu_x86: Refactor storage of CPUID data to add support for KVM features

The CPUID functions were stored in multiple arrays according to a
specified prefix of those. This made it very hard to add another prefix
to store KVM CPUID features (0x40000000). Instead of hardcoding a third
array this patch changes the approach used:

The code is refactored to use a single array where the CPUID functions
are stored ordered by the cpuid function so that they don't depend on
the specific prefix and don't waste memory. The code is also less
complex using this approach. A trateoff to this is the change from O(N)
complexity to O(N^2) in x86DataAdd and x86DataSubtract. The rest of the
functions were already using O(N^2) algorithms.

11 years agostorage: Fix a vol-clone bug on ppc64
Li Zhang [Thu, 7 Nov 2013 08:35:10 +0000 (16:35 +0800)]
storage: Fix a vol-clone bug on ppc64

vol-clone reports out of memory error with disk type on ppc64.

Currently, wbytes is defined as size_t type (8 bytes), but
args's value in ioctl(fd, args..) in kernel is int (4 bytes).
This makes wbytes 2^32 times larger, causing an out of memory error.

This patch changes size_t to int to synchronize with kernel.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/block/ioctl.c?id=5e01dc7b#n363
[2] https://lkml.org/lkml/2013/11/1/620

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
11 years agoqemu: Don't access vm->priv on unlocked domain
Michal Privoznik [Wed, 6 Nov 2013 10:46:06 +0000 (11:46 +0100)]
qemu: Don't access vm->priv on unlocked domain

Since 86d90b3a (yes, my patch; again) we are supporting NBD storage
migration. However, on error recovery path we got the steps reversed.
The correct order is: return NBD port to the virPortAllocator and then
either unlock the vm or remove it from the driver. Not vice versa.

==11192== Invalid write of size 4
==11192==    at 0x11488559: qemuMigrationPrepareAny (qemu_migration.c:2459)
==11192==    by 0x11488EA6: qemuMigrationPrepareDirect (qemu_migration.c:2652)
==11192==    by 0x114D1509: qemuDomainMigratePrepare3Params (qemu_driver.c:10332)
==11192==    by 0x519075D: virDomainMigratePrepare3Params (libvirt.c:7290)
==11192==    by 0x1502DA: remoteDispatchDomainMigratePrepare3Params (remote.c:4798)
==11192==    by 0x12DECA: remoteDispatchDomainMigratePrepare3ParamsHelper (remote_dispatch.h:5741)
==11192==    by 0x5212127: virNetServerProgramDispatchCall (virnetserverprogram.c:435)
==11192==    by 0x5211C86: virNetServerProgramDispatch (virnetserverprogram.c:305)
==11192==    by 0x520A8FD: virNetServerProcessMsg (virnetserver.c:165)
==11192==    by 0x520A9E1: virNetServerHandleJob (virnetserver.c:186)
==11192==    by 0x50DA78F: virThreadPoolWorker (virthreadpool.c:144)
==11192==    by 0x50DA11C: virThreadHelper (virthreadpthread.c:161)
==11192==  Address 0x1368baa0 is 576 bytes inside a block of size 688 free'd
==11192==    at 0x4A07F5C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11192==    by 0x5079A2F: virFree (viralloc.c:580)
==11192==    by 0x11456C34: qemuDomainObjPrivateFree (qemu_domain.c:267)
==11192==    by 0x50F41B4: virDomainObjDispose (domain_conf.c:2034)
==11192==    by 0x50C2991: virObjectUnref (virobject.c:262)
==11192==    by 0x50F4CFC: virDomainObjListRemove (domain_conf.c:2361)
==11192==    by 0x1145C125: qemuDomainRemoveInactive (qemu_domain.c:2087)
==11192==    by 0x11488520: qemuMigrationPrepareAny (qemu_migration.c:2456)
==11192==    by 0x11488EA6: qemuMigrationPrepareDirect (qemu_migration.c:2652)
==11192==    by 0x114D1509: qemuDomainMigratePrepare3Params (qemu_driver.c:10332)
==11192==    by 0x519075D: virDomainMigratePrepare3Params (libvirt.c:7290)
==11192==    by 0x1502DA: remoteDispatchDomainMigratePrepare3Params (remote.c:4798)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agoqemu: Avoid double free of VM
Michal Privoznik [Wed, 6 Nov 2013 10:38:58 +0000 (11:38 +0100)]
qemu: Avoid double free of VM

One of my previous patches (c7ac2519b7f) did try to fix the issue when
domain dies too soon during migration. However, this clumsy approach was
missing removal of qemuProcessHandleMonitorDestroy resulting in double
unrefing of mon->vm and hence producing the daemon crash:

==11843== Invalid read of size 4
==11843==    at 0x50C28C5: virObjectUnref (virobject.c:255)
==11843==    by 0x1148F7DB: qemuMonitorDispose (qemu_monitor.c:258)
==11843==    by 0x50C2991: virObjectUnref (virobject.c:262)
==11843==    by 0x50C2D13: virObjectFreeCallback (virobject.c:388)
==11843==    by 0x509C37B: virEventPollCleanupHandles (vireventpoll.c:583)
==11843==    by 0x509C711: virEventPollRunOnce (vireventpoll.c:652)
==11843==    by 0x509A620: virEventRunDefaultImpl (virevent.c:274)
==11843==    by 0x520D21C: virNetServerRun (virnetserver.c:1112)
==11843==    by 0x11F368: main (libvirtd.c:1513)
==11843==  Address 0x13b88864 is 4 bytes inside a block of size 136 free'd
==11843==    at 0x4A07F5C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11843==    by 0x5079A2F: virFree (viralloc.c:580)
==11843==    by 0x50C29E3: virObjectUnref (virobject.c:270)
==11843==    by 0x114770E4: qemuProcessHandleMonitorDestroy (qemu_process.c:1103)
==11843==    by 0x1148F7CB: qemuMonitorDispose (qemu_monitor.c:257)
==11843==    by 0x50C2991: virObjectUnref (virobject.c:262)
==11843==    by 0x50C2D13: virObjectFreeCallback (virobject.c:388)
==11843==    by 0x509C37B: virEventPollCleanupHandles (vireventpoll.c:583)
==11843==    by 0x509C711: virEventPollRunOnce (vireventpoll.c:652)
==11843==    by 0x509A620: virEventRunDefaultImpl (virevent.c:274)
==11843==    by 0x520D21C: virNetServerRun (virnetserver.c:1112)
==11843==    by 0x11F368: main (libvirtd.c:1513)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agoAllow root directory in filesystem source dir schema
Ján Tomko [Thu, 7 Nov 2013 17:14:32 +0000 (18:14 +0100)]
Allow root directory in filesystem source dir schema

Use absDirPath instead of absFilePath.

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

11 years agoqemuMigrationBeginPhase: Check for 'drive-mirror' for NBD
Michal Privoznik [Thu, 7 Nov 2013 13:08:36 +0000 (14:08 +0100)]
qemuMigrationBeginPhase: Check for 'drive-mirror' for NBD

So far we are checking if qemu supports 'nbd-server-start'. This,
however, makes no sense on the source as nbd-server-* is used on the
destination. On the source the 'drive-mirror' is used instead.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agoconf: fix incorrect error log in virCPUDefIsEqual
Chen Hanxiao [Thu, 7 Nov 2013 03:31:32 +0000 (11:31 +0800)]
conf: fix incorrect error log in virCPUDefIsEqual

A copy-paste error.
s/model/vendor id

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agotests: Distribute virpcitestdata
Michal Privoznik [Thu, 7 Nov 2013 10:57:27 +0000 (11:57 +0100)]
tests: Distribute virpcitestdata

Since 21685c955e5466 we have tests/virpcitestdata dir containing the PCI
config files for some dummy PCI devices that are used int virpcitest.
However, the directory containing the config files is not distributed
making 'make rpm' fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agotests: Fix virtpcitest in VPATH
Jiri Denemark [Wed, 6 Nov 2013 13:42:17 +0000 (14:42 +0100)]
tests: Fix virtpcitest in VPATH

11 years agoconf: Refactor virDomainDiskSourcePoolDefParse
Peter Krempa [Wed, 6 Nov 2013 14:15:18 +0000 (15:15 +0100)]
conf: Refactor virDomainDiskSourcePoolDefParse

For some strange reason virDomainDiskSourcePoolDefParse accessed def of
the disk and allocated the pool object in it. To avoid the need to carry
over the disk definition object, refactor this function to return the
allocated object instead.

11 years agonodeinfo: fix build on non-Linux
Eric Blake [Thu, 7 Nov 2013 00:09:26 +0000 (17:09 -0700)]
nodeinfo: fix build on non-Linux

Commit b0f8546 broke the build on mingw, by exposing code that
had Linux-specific dependencies but which was previously protected
by libnuma ifdef guards:

make[3]: Entering directory `/home/eblake/libvirt-tmp/build/src'
  CC       libvirt_driver_la-nodeinfo.lo
../../src/nodeinfo.c: In function 'virNodeGetSiblingsList':
../../src/nodeinfo.c:1543:30: error: 'SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX' undeclared (first use in this function)
     if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &buf) < 0)
                              ^
../../src/nodeinfo.c:1543:30: note: each undeclared identifier is reported only once for each function it appears in
../../src/nodeinfo.c: In function 'virNodeCapsFillCPUInfo':
../../src/nodeinfo.c:1562:5: error: implicit declaration of function 'virNodeGetCpuValue' [-Werror=implicit-function-declaration]
     if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
     ^
../../src/nodeinfo.c:1562:5: error: nested extern declaration of 'virNodeGetCpuValue' [-Werror=nested-externs]
../../src/nodeinfo.c:1562:35: error: 'SYSFS_CPU_PATH' undeclared (first use in this function)
     if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
                                   ^
cc1: all warnings being treated as errors

* src/nodeinfo.c (virNodeCapsFillCPUInfo): Make conditional.
(virNodeGetSiblingsList): Move into #ifdef linux block.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agostorage: always probe type with buffer
Eric Blake [Tue, 5 Nov 2013 21:12:02 +0000 (14:12 -0700)]
storage: always probe type with buffer

This gets rid of another stat() per volume, as well as cutting
bytes read in half, when populating the volumes of a directory
pool during a pool refresh.  Not to mention that it provides an
interface that can let gluster pools also probe file types.

* src/util/virstoragefile.h (virStorageFileProbeFormatFromFD):
Delete.
(virStorageFileProbeFormatFromBuf): New prototype.
(VIR_STORAGE_MAX_HEADER): New constant, based on...
* src/util/virstoragefile.c (STORAGE_MAX_HEAD): ...old name.
(vmdk4GetBackingStore, virStorageFileGetMetadataInternal)
(virStorageFileProbeFormat): Adjust clients.
(virStorageFileProbeFormatFromFD): Delete.
(virStorageFileProbeFormatFromBuf): Export.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Adjust client.
* src/libvirt_private.syms (virstoragefile.h): Adjust exports.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agostorage: refactor backing chain division of labor
Eric Blake [Tue, 5 Nov 2013 20:50:29 +0000 (13:50 -0700)]
storage: refactor backing chain division of labor

Future patches will want to learn metadata about a file using
a buffer that was already parsed in order to probe the file's
format.  Rather than reopening and re-reading the file, it makes
sense to separate getting file contents from actually parsing
those contents.

* src/util/virstoragefile.c (virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataFromFDInternal): New functions.
(virStorageFileGetMetadataInternal): Hoist fstat() and read() into
callers.
(virStorageFileGetMetadataFromFD)
(virStorageFileGetMetadataRecurse): Rework clients.
* src/util/virstoragefile.h (virStorageFileGetMetadataFromBuf):
New prototype.
* src/libvirt_private.syms (virstoragefile.h): Export it.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agostorage: reduce number of stat calls
Eric Blake [Tue, 5 Nov 2013 15:30:01 +0000 (08:30 -0700)]
storage: reduce number of stat calls

We are calling fstat() at least twice per storage volume in
a directory storage pool; this is rather wasteful.  Refactoring
this is also a step towards making code reusable for gluster,
where gluster can provide struct stat but cannot use fstat().

* src/storage/storage_backend.h
(virStorageBackendVolOpenCheckMode)
(virStorageBackendUpdateVolTargetInfoFD): Update signature.
* src/storage/storage_backend.c
(virStorageBackendVolOpenCheckMode): Pass stat results back.
(virStorageBackendUpdateVolTargetInfoFD): Use existing stats.
(virStorageBackendVolOpen, virStorageBackendUpdateVolTargetInfo):
Update callers.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSIUpdateVolTargetInfo): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathUpdateVolTargetInfo): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agostorage: avoid short reads while chasing backing chain
Eric Blake [Tue, 5 Nov 2013 17:30:56 +0000 (10:30 -0700)]
storage: avoid short reads while chasing backing chain

Our backing file chain code was not very robust to an ill-timed
EINTR, which could lead to a short read causing us to randomly
treat metadata differently than usual.  But the existing
virFileReadLimFD forces an error if we don't read the entire
file, even though we only care about the header of the file.
So add a new virFile function that does what we want.

* src/util/virfile.h (virFileReadHeaderFD): New prototype.
* src/util/virfile.c (virFileReadHeaderFD): New function.
* src/libvirt_private.syms (virfile.h): Export it.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileProbeFormatFromFD): Use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agostorage: use simpler 'char *'
Eric Blake [Tue, 5 Nov 2013 17:44:14 +0000 (10:44 -0700)]
storage: use simpler 'char *'

'unsigned char *' makes sense if you are doing math on bytes and
don't want to worry about wraparound from a signed 'char'; but
since all we are doing is memcmp() or virReadBufInt*[LB]E(), which
are both safe on either type of char, and since read() prefers to
operate on 'char *', it's simpler to avoid casts by just typing
things as 'char *' from the get-go.  [Technically, read can
operate on an 'unsigned char *' thanks to the C rule that any
pointer can be implicitly converted to 'char *' for legacy K&R
compatibility; but where this patch saves us is if we try to use
virfile.h functions that take 'char **' in order to allocate the
buffer, where the compiler would barf on type mismatch.]

* src/util/virstoragefile.c (FileTypeInfo): Avoid unsigned char.
(cowGetBackingStore, qcow2GetBackingStoreFormat)
(qcowXGetBackingStore, qcow1GetBackingStore)
(qcow2GetBackingStore, vmdk4GetBackingStore, qedGetBackingStore)
(virStorageFileMatchesMagic, virStorageFileMatchesVersion)
(virStorageFileProbeFormatFromBuf, qcow2GetFeatures)
(virStorageFileGetMetadataInternal)
(virStorageFileProbeFormatFromFD): Simplify clients.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoadd SystemTap to apps using libvirt
Jonathan Lebon [Wed, 6 Nov 2013 21:52:52 +0000 (16:52 -0500)]
add SystemTap to apps using libvirt

Starting from v2.4 (released today!), SystemTap can use libvirt to
execute scripts inside virtual machines.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agotest driver: add support for .connectBaselineCPU
Giuseppe Scrivano [Wed, 6 Nov 2013 18:27:30 +0000 (19:27 +0100)]
test driver: add support for .connectBaselineCPU

It uses the same functionalities of the qemu driver.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
11 years agoqemuMonitorDispose: Reset lastError
Michal Privoznik [Wed, 6 Nov 2013 10:50:26 +0000 (11:50 +0100)]
qemuMonitorDispose: Reset lastError

Since the 90139a62 commit the error is copied into mon->lastError but
it's never freed from there.

==31989== 395 bytes in 1 blocks are definitely lost in loss record 877 of 978
==31989==    at 0x4A06C2B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31989==    by 0x7EAF129: strdup (in /lib64/libc-2.15.so)
==31989==    by 0x50D586C: virStrdup (virstring.c:554)
==31989==    by 0x50976C1: virCopyError (virerror.c:191)
==31989==    by 0x5097A35: virCopyLastError (virerror.c:312)
==31989==    by 0x114909A9: qemuMonitorIO (qemu_monitor.c:690)
==31989==    by 0x509BEDE: virEventPollDispatchHandles (vireventpoll.c:501)
==31989==    by 0x509C701: virEventPollRunOnce (vireventpoll.c:648)
==31989==    by 0x509A620: virEventRunDefaultImpl (virevent.c:274)
==31989==    by 0x520D21C: virNetServerRun (virnetserver.c:1112)
==31989==    by 0x11F368: main (libvirtd.c:1513)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agodocs: fix a typo in formatnwfilter
Chen Hanxiao [Wed, 6 Nov 2013 07:38:00 +0000 (15:38 +0800)]
docs: fix a typo in formatnwfilter

s/fragement/fragment

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agoqemu: clean up migration ports when migration cancelled
Zeng Junliang [Wed, 6 Nov 2013 03:36:57 +0000 (11:36 +0800)]
qemu: clean up migration ports when migration cancelled

If there's a migration cancelled, the bitmap of migration port should be
cleaned up too.

Signed-off-by: Zeng Junliang <zengjunliang@huawei.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agonetwork: fix connections count in case of allocate failure
Laine Stump [Mon, 4 Nov 2013 15:01:17 +0000 (17:01 +0200)]
network: fix connections count in case of allocate failure

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

If networkAllocateActualDevice() had failed due to a pool of hostdev
or direct devices being depleted, the calling function could still
call networkReleaseActualDevice() as part of its cleanup, and that
function would then unconditionally decrement the connections count
for the network, even though it hadn't been incremented (due to
failure of allocate). This *was* necessary because the .actual member
of the netdef was allocated with a "lazy" algorithm, only being
created if there was a need to store data there (e.g. if a device was
allocated from a pool, or bandwidth was allocated for the device), so
there was no simple way for networkReleaseActualDevice() to tell if
something really had been allocated (i.e. if "connections++" had been
executed).

This patch changes networkAllocateDevice() to *always* allocate an
actual device for any netdef of type='network', even if it isn't
needed for any other reason. This has no ill effects anywhere else in
the code (except for using a small amount of memory), and
networkReleaseActualDevice() can then determine if there was a
previous successful allocate by checking for .actual != NULL (if not,
it skips the "connections--").

11 years agovirpcitest: Introduce testVirPCIDeviceReset
Michal Privoznik [Tue, 5 Nov 2013 14:07:49 +0000 (15:07 +0100)]
virpcitest: Introduce testVirPCIDeviceReset

This addition, however, requires some refactoring to be done.  First of
all, to match the best practice we should detach the device prior
resetting it. That's why testVirPCIDeviceDetach is detaching all devices
within 0000:00:01.0 and 0000:00:03.0 range. Then, the brand new test
will reset the 0000:00:02.0 device, so the last testVirPCIDeviceReattach
can reattach all the devices back.

In order to perform a PCI device reset, the dummy config file is not
sufficient anymore and must be replaced with real PCI config (binary
mess). Such config files are to be stored under tests/virpcitestdata/
and ought to have '.config' suffix.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirt-login-shell: also build virAtomic.h
Guido Günther [Tue, 5 Nov 2013 08:04:43 +0000 (09:04 +0100)]
virt-login-shell: also build virAtomic.h

Needed for architectures that don't use gcc atomic ops but pthread. This
fixes the armel build that otherwise breaks like:

 CCLD     virt-login-shell
 ../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-virobject.o): In function `virClassNew':
 /«PKGBUILDDIR»/debian/build/src/../../../src/util/virobject.c:150: undefined reference to `virAtomicLock'
 ../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-virobject.o): In function `virObjectNew':
 /«PKGBUILDDIR»/debian/build/src/../../../src/util/virobject.c:202: undefined reference to `virAtomicLock'
 ../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-virobject.o): In function `virObjectUnref':
 /«PKGBUILDDIR»/debian/build/src/../../../src/util/virobject.c:274: undefined reference to `virAtomicLock'
 ../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-virobject.o): In function `virObjectRef':
 /«PKGBUILDDIR»/debian/build/src/../../../src/util/virobject.c:295: undefined reference to `virAtomicLock'
 collect2: error: ld returned 1 exit status

See https://buildd.debian.org/status/fetch.php?pkg=libvirt&arch=armel&ver=1.1.4-1&stamp=1383588268

11 years agovirpcitest: Fix variable arguments using in pci_driver_new
Michal Privoznik [Tue, 5 Nov 2013 15:37:38 +0000 (16:37 +0100)]
virpcitest: Fix variable arguments using in pci_driver_new

In the pci_driver_new function it is possible to set a list of
<vendor:device> IDs that the driver knows. These IDs are passed as
variable arguments and are processed  the usual way using va_start() and
va_arg(). However, after all arguments has been processed, we should
call va_end() what we aren't currently doing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agostorage: recognize gluster as networked file
Eric Blake [Mon, 4 Nov 2013 21:27:42 +0000 (14:27 -0700)]
storage: recognize gluster as networked file

A qcow2 file with a backing file of 'gluster://host/vol/file' should
not try to look for a directory named './gluster:/' in the file system.

* src/util/virstoragefile.c (virBackingStoreIsFile): Broaden check
to include all protocols.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoqemu: don't use deprecated -no-kvm-pit-reinjection
Ján Tomko [Mon, 1 Jul 2013 16:28:50 +0000 (18:28 +0200)]
qemu: don't use deprecated -no-kvm-pit-reinjection

Since qemu-kvm 1.1 [1] (since 1.3. in upstream QEMU [2])
'-no-kvm-pit-reinjection' has been deprecated.
Use -global kvm-pit.lost_tick_policy=discard instead.

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

[1] http://git.kernel.org/cgit/virt/kvm/qemu-kvm.git/commit/?id=4e4fa39
[2] http://git.qemu.org/?p=qemu.git;a=commitdiff;h=c21fb4f

11 years agoResolve Coverity issue regarding not checking return value
John Ferlan [Tue, 5 Nov 2013 12:55:54 +0000 (07:55 -0500)]
Resolve Coverity issue regarding not checking return value

Coverity complains that the call to virPCIDeviceDetach() in
qemuPrepareHostdevPCIDevices() doesn't check status return like
other calls.  Seems this just was lurking until a recent change
to this module resulted in Coverity looking harder and finding
the issue.  Introduced by 'a4efb2e33' when function was called
'pciReAttachDevice()'

Just added a ignore_value() since it doesn't appear to matter
if the call fails since we're on a failure path already.

11 years agoSkip any files which are not mounted on the host
Daniel P. Berrange [Mon, 7 Oct 2013 12:12:15 +0000 (13:12 +0100)]
Skip any files which are not mounted on the host

Currently the LXC container tries to skip selinux/securityfs
mounts if the directory does not exist in the filesystem,
or if SELinux is disabled.

The former check is flawed because the /sys/fs/selinux
or /sys/kernel/securityfs directories may exist in sysfs
even if the mount type is disabled. Instead of just doing
an access() check, use an virFileIsMounted() to see if
the FS is actually present in the host OS. This also
avoids the need to check is_selinux_enabled().

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd flag to lxcBasicMounts to control use in user namespaces
Daniel P. Berrange [Mon, 7 Oct 2013 12:03:51 +0000 (13:03 +0100)]
Add flag to lxcBasicMounts to control use in user namespaces

Some mounts must be skipped if running inside a user namespace,
since the kernel forbids their use. Instead of strcmp'ing the
filesystem type in the body of the loop, set an explicit flag
in the lxcBasicMounts table.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove duplicate entries in lxcBasicMounts array
Daniel P. Berrange [Mon, 7 Oct 2013 11:25:00 +0000 (12:25 +0100)]
Remove duplicate entries in lxcBasicMounts array

Currently the lxcBasicMounts array has separate entries for
most mounts, to reflect that we must do a separate mount
operation to make mounts read-only. Remove the duplicate
entries and instead set the MS_RDONLY flag against the main
entry. Then change lxcContainerMountBasicFS to look for the
MS_RDONLY flag, mask it out & do a separate bind mount.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove pointless 'srcpath' variable in lxcContainerMountBasicFS
Daniel P. Berrange [Mon, 7 Oct 2013 11:13:15 +0000 (12:13 +0100)]
Remove pointless 'srcpath' variable in lxcContainerMountBasicFS

The 'srcpath' variable is initialized from 'mnt->src' and never
changed thereafter. Some places continue to use 'mnt->src' and
others use 'srcpath'. Remove the pointless 'srcpath' variable
and use 'mnt->src' everywhere.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove unused 'opts' field from LXC basic mounts struct
Daniel P. Berrange [Mon, 7 Oct 2013 11:08:14 +0000 (12:08 +0100)]
Remove unused 'opts' field from LXC basic mounts struct

The virLXCBasicMountInfo struct contains a 'char *opts'
field passed onto the mount() syscall. Every entry in the
list sets this to NULL though, so it can be removed to
simplify life.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd virFileIsMountPoint function
Daniel P. Berrange [Mon, 7 Oct 2013 11:51:58 +0000 (12:51 +0100)]
Add virFileIsMountPoint function

Add a function for efficiently checking if a path is a filesystem
mount point.

NB will not work for bind mounts, only true filesystem mounts.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agovirpcitest: Introduce check for unbinded devices
Michal Privoznik [Thu, 31 Oct 2013 11:05:20 +0000 (11:05 +0000)]
virpcitest: Introduce check for unbinded devices

This just introduces the test for bug fixed in df4283a55bf.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirpci: Don't error on unbinded devices
Michal Privoznik [Thu, 31 Oct 2013 10:32:58 +0000 (10:32 +0000)]
virpci: Don't error on unbinded devices

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

If a PCI deivce is not binded to any driver (e.g. there's yet no PCI
driver in the linux kernel) but still users want to passthru the device
we fail the whole operation as we fail to resolve the 'driver' link
under the PCI device sysfs tree. Obviously, this is not a fatal error
and it shouldn't be error at all.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirpcitest: Introduce testVirPCIDeviceReattach
Michal Privoznik [Thu, 31 Oct 2013 10:57:56 +0000 (10:57 +0000)]
virpcitest: Introduce testVirPCIDeviceReattach

This test will reattach the PCI device detached in the previous test.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirpcitest: Test virPCIDeviceDetach
Michal Privoznik [Wed, 23 Oct 2013 15:55:02 +0000 (16:55 +0100)]
virpcitest: Test virPCIDeviceDetach

This commit introduces yet another test under virpcitest:
virPCIDeviceDetach. However, in order to be able to do this, the
virpcimock needs to be extended to model the kernel behavior on PCI
device binding and unbinding (create 'driver' symlinks under the device
tree, check for device ID in driver's ID table, etc.)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agotests: Introduce virpcitest
Michal Privoznik [Wed, 23 Oct 2013 13:44:40 +0000 (14:44 +0100)]
tests: Introduce virpcitest

Among with this test introduce virpcimock as we need to mock some
syscalls, e.g. redirect open() of a file under /sys/bus/pci to a
stub sysfs tree.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agocpu: x86: Parse the CPU feature map only once
Peter Krempa [Tue, 8 Oct 2013 16:20:10 +0000 (18:20 +0200)]
cpu: x86: Parse the CPU feature map only once

Until now the map was loaded from the XML definition file every time a
operation on the flags was requested. With the introduciton of one shot
initializers we can store the definition forever (as it will never
change) instead of parsing it over and over again.

11 years agocpu: Export few x86-specific APIs
Jiri Denemark [Tue, 23 Jul 2013 21:54:17 +0000 (23:54 +0200)]
cpu: Export few x86-specific APIs

This makes virCPUx86DataAddCPUID, virCPUx86DataFree, and
virCPUx86MakeData available for direct usage outside of cpu driver in
tests and the new qemu monitor that will request the actual CPU
definition from a running qemu instance.

11 years agonodeinfo: Remove libnuma include
Peter Krempa [Fri, 18 Oct 2013 14:42:38 +0000 (16:42 +0200)]
nodeinfo: Remove libnuma include

Now that all libnuma functions used by libvirt are wrapped in virNuma we
can remove the dependancy from nodeinfo.

11 years agonuma: Add wrapper of numa_node_to_cpus and use it
Peter Krempa [Fri, 18 Oct 2013 14:21:24 +0000 (16:21 +0200)]
numa: Add wrapper of numa_node_to_cpus and use it

11 years agocaps: Fix function docs for virCapabilitiesAddHostNUMACell
Peter Krempa [Fri, 18 Oct 2013 12:53:49 +0000 (14:53 +0200)]
caps: Fix function docs for virCapabilitiesAddHostNUMACell

11 years agonuma: Replace NUMA_MAX_N_CPUS macro with virNumaGetMaxCPUs()
Peter Krempa [Fri, 18 Oct 2013 12:43:34 +0000 (14:43 +0200)]
numa: Replace NUMA_MAX_N_CPUS macro with virNumaGetMaxCPUs()

11 years agonodeinfo: Get rid of nodeGetCellMemory
Peter Krempa [Fri, 18 Oct 2013 10:18:56 +0000 (12:18 +0200)]
nodeinfo: Get rid of nodeGetCellMemory

The function was called in a single place only and was reporting errors
that were later ignored. Use the virNumaGetNodeMemory helper to get the
size of the memory in the NUMA node and remove the helper

11 years agonuma: Introduce virNumaGetNodeMemory and use it instead of numa_node_size64
Peter Krempa [Thu, 17 Oct 2013 16:30:09 +0000 (18:30 +0200)]
numa: Introduce virNumaGetNodeMemory and use it instead of numa_node_size64

11 years agonuma: Introduce virNumaGetMaxNode and use it instead of numa_max_node
Peter Krempa [Thu, 17 Oct 2013 15:42:22 +0000 (17:42 +0200)]
numa: Introduce virNumaGetMaxNode and use it instead of numa_max_node

Avoid necessary checks for the numa library with this helper.

11 years agonodeinfo: Avoid forward declarations of static functions
Peter Krempa [Tue, 15 Oct 2013 13:44:48 +0000 (15:44 +0200)]
nodeinfo: Avoid forward declarations of static functions

linuxNodeGetCPUStats() and linuxNodeGetMemoryStats() are static and
don't need a forward declaration.

11 years agonuma: Introduce virNumaIsAvailable and use it instead of numa_available
Peter Krempa [Thu, 17 Oct 2013 14:57:29 +0000 (16:57 +0200)]
numa: Introduce virNumaIsAvailable and use it instead of numa_available

All functions from libnuma must be protected with ifdefs. Avoid this by
using our own wrapper.

11 years agoRelease of libvirt-1.1.4
Daniel Veillard [Mon, 4 Nov 2013 04:30:41 +0000 (12:30 +0800)]
Release of libvirt-1.1.4

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

11 years agovirnetsocket: fix getsockopt on FreeBSD
Ryota Ozaki [Thu, 24 Oct 2013 15:48:25 +0000 (00:48 +0900)]
virnetsocket: fix getsockopt on FreeBSD

aa0f099 introduced a strict error checking for getsockopt and it
revealed that getting a peer credential of a socket on FreeBSD
didn't work. Libvirtd hits the error:
  error : virNetSocketGetUNIXIdentity:1198 : Failed to get valid
  client socket identity groups

SOL_SOCKET (0xffff) was used as a level of getsockopt for
LOCAL_PEERCRED, however, it was wrong. 0 is correct as well as
Mac OS X.

So for LOCAL_PEERCRED our options are SOL_LOCAL (if defined) or
0 on Mac OS X and FreeBSD. According to the fact, the patch
simplifies the code by removing ifdef __APPLE__.

I tested the patch on FreeBSD 8.4, 9.2 and 10.0-BETA1.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
11 years agoMacOS: Handle changes to xdrproc_t definition
Doug Goldstein [Wed, 30 Oct 2013 16:22:58 +0000 (11:22 -0500)]
MacOS: Handle changes to xdrproc_t definition

With Mac OS X 10.9, xdrproc_t is no longer defined as:

typedef bool_t (*xdrproc_t)(XDR *, ...);

but instead as:

typdef bool_t (*xdrproc_t)(XDR *, void *, unsigned int);

For reference, Linux systems typically define it as:

typedef bool_t (*xdrproc_t)(XDR *, void *, ...);

The rationale explained in the header is that using a vararg is
incorrect and has a potential to change the ABI slightly do to compiler
optimizations taken and the undefined behavior. They decided
to specify the exact number of parameters and for compatibility with old
code decided to make the signature require 3 arguments. The third
argument is ignored for cases that its not used and its recommended to
supply a 0.

11 years agolibxl: fix dubious cpumask handling in libxlDomainSetVcpuAffinities
Jeremy Fitzhardinge [Wed, 30 Oct 2013 17:38:08 +0000 (10:38 -0700)]
libxl: fix dubious cpumask handling in libxlDomainSetVcpuAffinities

Rather than casting the virBitmap pointer to uint8_t* and then using
the structure contents as a byte array, use the virBitmap API to determine
the bitmap size and test each bit.

Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
11 years agoRevert "libxl: Fix possible invalid read"
Jim Fehlig [Fri, 1 Nov 2013 14:22:18 +0000 (08:22 -0600)]
Revert "libxl: Fix possible invalid read"

This reverts commit 394d6e0a95ac91facba06ab43d67ae8600b14b0e.
The real problem is accessing the virtBitmap structure as a byte
array, which was correctly identified and fixed by Jeremy Fitzhardinge

https://www.redhat.com/archives/libvir-list/2013-October/msg01257.html

11 years agofix api changes in xen restore
Bamvor Jian Zhang [Fri, 1 Nov 2013 07:26:26 +0000 (15:26 +0800)]
fix api changes in xen restore

in recently xen commit: 7051d5c8, there is a api changes in
libxl_domain_create_restore.
Author: Andrew Cooper <andrew.cooper3@citrix.com>
Date:   Thu Oct 10 12:23:10 2013 +0100

    tools/migrate: Fix regression when migrating from older version of Xen

use the macro LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS in libxl.h
in order to make libvirt could compile with old and new xen.

the params checkpointed_stream is useful if libvirt libxl driver
support migration. for new, set it as zero.

Signed-off-by: Bamvor Jian Zhang <bjzhang@suse.com>
11 years agoFix race in starting transient VMs
Daniel P. Berrange [Thu, 31 Oct 2013 18:37:37 +0000 (18:37 +0000)]
Fix race in starting transient VMs

When starting a transient VM the first thing done is to check
for duplicates. The check looks if there are any running VMs
with the matching name/uuid. It explicitly allows there to
be inactive VMs, so that a persistent VM can be temporarily
booted with a different config.

There is a race condition, however, where 2 or more clients
try to create the same transient VM. The first client will
cause a virDomainObjPtr to be added to the domain list, and
it is inactive at this stage. The second client may then
come along and see this inactive VM, and mistake it for a
persistent VM.

If the first VM fails to start its transient guest for any
reason, then it'll remove the virDomainObjPtr from the list.
The second client now has a virDomainObjPtr that it can try
to boot, which libvirt no longer has a record of. The result
can be a running QEMU process that is orphaned.

It was also, however, possible for the virDomainObjPtr to be
completely free'd which will cause libvirtd to crash in some
scenarios.

The fix is to only allow an existing inactive VM if it is
marked as persistent.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse a port from the migration range for NBD as well
Ján Tomko [Thu, 31 Oct 2013 12:19:29 +0000 (13:19 +0100)]
Use a port from the migration range for NBD as well

Instead of using a port from the remote display range.

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

11 years agonodedev_hal: fix segfault when virDBusGetSystemBus fails
Ryota Ozaki [Thu, 31 Oct 2013 15:45:12 +0000 (00:45 +0900)]
nodedev_hal: fix segfault when virDBusGetSystemBus fails

Thie patch fixes the segfault:
    error : nodeStateInitialize:658 : DBus not available,
      disabling HAL driver: internal error: Unable to get DBus
      system bus connection: Failed to connect to socket
      /var/run/dbus/system_bus_socket: No such file or directory
    error : nodeStateInitialize:719 :  ?:
    Caught Segmentation violation dumping internal log buffer:

This segfault occurs at the below VIR_ERROR:
  failure:
      if (dbus_error_is_set(&err)) {
          VIR_ERROR(_("%s: %s"), err.name, err.message);

When virDBusGetSystemBus fails, the code jumps to the above failure
path. However, the err variable is not correctly initialized
before calling virDBusGetSystemBus. As a result, dbus_error_is_set
may pass over the uninitialized err variable whose name or
message may point to somewhere unknown memory region, which
causes a segfault on VIR_ERROR.

The new code initializes the err variable before calling
virDBusGetSystemBus.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
11 years agoImprove debugging of QEMU start/stop
Daniel P. Berrange [Thu, 31 Oct 2013 11:28:46 +0000 (11:28 +0000)]
Improve debugging of QEMU start/stop

Include reference of the VM object pointer and name in debug
logs for QEMU start/stop functions. Also make sure we log the
PID that we started, since it isn't available elsewhere in the
logs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoImprove debugging of job enter/exit code
Daniel P. Berrange [Thu, 31 Oct 2013 11:27:10 +0000 (11:27 +0000)]
Improve debugging of job enter/exit code

In debugging a recent oVirt/libvirt race condition, I was very
frustrated by lack of logging in the job enter/exit code. This
patch adds some key data which would have been useful in by
debugging attempts.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoxenapi: fix coding style in xenapi_driver.c
Hongwei Bi [Tue, 22 Oct 2013 18:20:17 +0000 (02:20 +0800)]
xenapi: fix coding style in xenapi_driver.c

Fix the if statement coding style.

Signed-off-by: Hongwei Bi <hwbi2008@gmail.com>
11 years agostorage: use correct type for array count
Eric Blake [Wed, 30 Oct 2013 21:42:31 +0000 (15:42 -0600)]
storage: use correct type for array count

Using size_t counts will let us use VIR_APPEND_ELEMENT and friends.

* src/conf/storage_conf.h (_virStoragePoolObjList)
(_virStorageVolDefList): Track list sizes with size_t.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDRefreshPool): Fix type fallout.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agomaint: avoid further typedef accidents
Eric Blake [Tue, 29 Oct 2013 19:57:19 +0000 (13:57 -0600)]
maint: avoid further typedef accidents

To make it easier to forbid future attempts at a confusing typedef
name ending in Ptr that isn't actually a pointer, insist that we
follow our preferred style of 'typedef foo *fooPtr'.

* cfg.mk (sc_forbid_const_pointer_typedef): Enforce consistent
style, to prevent issue fixed in previous storage patch.
* src/conf/capabilities.h (virCapsPtr): Fix offender.
* src/security/security_stack.c (virSecurityStackItemPtr):
Likewise.
* tests/qemucapabilitiestest.c (testQemuDataPtr): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agodocs: generate links from plain text documentation
Claudio Bley [Mon, 14 Jan 2013 12:37:02 +0000 (13:37 +0100)]
docs: generate links from plain text documentation

There are two forms used throughout libvirt code comments, which
are both supported by this patch.

* plain links like e.g. http://www.libvirt.org/
* links enclosed in <> characters, e.g. <http://www.libvirt.org/>

Signed-off-by: Claudio Bley <cbley@av-test.de>
11 years agolibvirt.c: indent code of virDomainGetMemoryParameters's documentation
Claudio Bley [Wed, 30 Jan 2013 09:42:21 +0000 (10:42 +0100)]
libvirt.c: indent code of virDomainGetMemoryParameters's documentation

By indenting code inside of comments, it gets recognized as a
code block when generating the HTML documentation.

11 years agolibvirt.c: add 2 spaces of indentation to example code of virStreamSend
Claudio Bley [Wed, 30 Jan 2013 15:18:23 +0000 (16:18 +0100)]
libvirt.c: add 2 spaces of indentation to example code of virStreamSend

See libvirt-libvirt.html#virStreamSend for the effect.

11 years agodocs: define style of code blocks inside descriptions
Claudio Bley [Tue, 22 Jan 2013 13:41:58 +0000 (14:41 +0100)]
docs: define style of code blocks inside descriptions

11 years agodocs: add class "description" to div's containing descriptions
Claudio Bley [Tue, 22 Jan 2013 13:39:41 +0000 (14:39 +0100)]
docs: add class "description" to div's containing descriptions

11 years agodocs: process code blocks similar to Markdown
Claudio Bley [Tue, 22 Jan 2013 12:45:11 +0000 (13:45 +0100)]
docs: process code blocks similar to Markdown

Wrap pre-formatted example code in <code> elements. This works
similar to Markdown[1] code blocks[2]:

Every line indented with at least 2 spaces is considered a code
block and gets wrapped in <pre> and <code> tags.

Look at the documentation for e.g. virStreamSend for before-and-after
effects.

[1] http://daringfireball.net/projects/markdown/
[2] http://daringfireball.net/projects/markdown/syntax#precode

11 years agoFix race condition reconnecting to vms & loading configs
Daniel P. Berrange [Mon, 28 Oct 2013 11:49:18 +0000 (11:49 +0000)]
Fix race condition reconnecting to vms & loading configs

The following sequence

 1. Define a persistent QMEU guest
 2. Start the QEMU guest
 3. Stop libvirtd
 4. Kill the QEMU process
 5. Start libvirtd
 6. List persistent guests

At the last step, the previously running persistent guest
will be missing. This is because of a race condition in the
QEMU driver startup code. It does

 1. Load all VM state files
 2. Spawn thread to reconnect to each VM
 3. Load all VM config files

Only at the end of step 3, does the 'virDomainObjPtr' get
marked as "persistent". There is therefore a window where
the thread reconnecting to the VM will remove the persistent
VM from the list.

The easy fix is to simply switch the order of steps 2 & 3.

In addition to this though, we must only attempt to reconnect
to a VM which had a non-zero PID loaded from its state file.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoFix leak of objects when reconnecting to QEMU instances
Daniel P. Berrange [Tue, 29 Oct 2013 13:58:00 +0000 (13:58 +0000)]
Fix leak of objects when reconnecting to QEMU instances

The 'error' cleanup block in qemuProcessReconnect() had a
'return' statement in the middle of it. This caused a leak
of virConnectPtr & virQEMUDriverConfigPtr instances. This
was identified because netcf recently started checking its
refcount in libvirtd shutdown:

netcfStateCleanup:109 : internal error: Attempt to close netcf state driver with open connections

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoDon't update dom->persistent without lock held
Daniel P. Berrange [Mon, 28 Oct 2013 14:07:26 +0000 (14:07 +0000)]
Don't update dom->persistent without lock held

virDomainObjListLoadAllConfigs sets dom->persistent after
having released its lock on the domain object. This exposes
a possible race condition.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agodocs: fix typos in formatnwfilter
Chen Hanxiao [Wed, 30 Oct 2013 01:11:51 +0000 (09:11 +0800)]
docs: fix typos in formatnwfilter

s/initated/initiated

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agoMacOS: Re-add support for QEMU backend
Doug Goldstein [Mon, 28 Oct 2013 18:20:35 +0000 (13:20 -0500)]
MacOS: Re-add support for QEMU backend

The QEMU backend was disabled on Mac OS X without a reason in the code
and due to refactors its difficult to understand when/why it was
disabled. With QEMU being supported on Mac OS X there is no reason to
disable QEMU on this platform.

11 years agoAdd '+' to uid/gid printing for label processing
John Ferlan [Tue, 22 Oct 2013 07:50:08 +0000 (08:50 +0100)]
Add '+' to uid/gid printing for label processing

To ensure proper processing by virGetUserID() and virGetGroupID()
of a uid/gid add a "+" prior to the uid/gid to denote it's really
a uid/gid for the label.

11 years agostorage: fix incorrect typedef
Eric Blake [Tue, 29 Oct 2013 15:56:48 +0000 (09:56 -0600)]
storage: fix incorrect typedef

The rbd code had a confusing typedef ending in Ptr that was not
actually a pointer, which made the rest of the code harder to
read.  This fixes things to actually pass by pointer rather than
by copy.

* src/storage/storage_backend_rbd.c (virStorageBackendStatePtr):
Fix typedef.
(virStorageBackendRBDOpenRADOSConn)
(virStorageBackendRBDCloseRADOSConn)
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDRefreshPool, virStorageBackendRBDDeleteVol)
(virStorageBackendRBDCreateVol, virStorageBackendRBDRefreshVol)
(virStorageBackendRBDResizeVol): Fix fallout.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoapparmor: Fix typo in function name in driver struct initialization
Peter Krempa [Tue, 29 Oct 2013 16:01:22 +0000 (17:01 +0100)]
apparmor: Fix typo in function name in driver struct initialization

Commit 64a68a4a introduced a typo in the initialization of the apparmor
driver structure breaking the build with apparmor enabled.

11 years agoqemu: fix well-formed migration URI formatting
Michael Chapman [Wed, 23 Oct 2013 04:15:12 +0000 (15:15 +1100)]
qemu: fix well-formed migration URI formatting

When adding an automatically allocated port to a well-formed migration
URI, keep it well-formed:

  tcp://1.2.3.4/  ->  tcp://1.2.3.4/:12345   # wrong
  tcp://1.2.3.4/  ->  tcp://1.2.3.4:12345/   # fixed
  tcp://1.2.3.4   ->  tcp://1.2.3.4:12345    # still works
  tcp:1.2.3.4     ->  tcp:1.2.3.4:12345      # still works (old syntax)

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
11 years agoLXC: don't free tty before using it in lxcContainerSetupDevices
Gao feng [Tue, 29 Oct 2013 06:19:35 +0000 (14:19 +0800)]
LXC: don't free tty before using it in lxcContainerSetupDevices

Introduced by commit 0f31f7b.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
11 years agoPush RPM deps down into libvirt-daemon-driver-XXXX sub-RPMs
Daniel P. Berrange [Tue, 29 Oct 2013 11:27:45 +0000 (11:27 +0000)]
Push RPM deps down into libvirt-daemon-driver-XXXX sub-RPMs

For inexplicable reasons, many of the 3rd party package deps
were left against the 'libvirt-daemon' RPM when the drivers
were split out. This makes a minimal install heavier that
it should be. Push them all down into libvirt-daemon-driver-XXX
so they're only pulled in when truly needed

With this change applied, a minimal install of just the
libvirt-daemon-driver-lxc RPM is reduced by 41 MB on a
Fedora 19 host.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agocapabilities: add baselabel per sec driver/virt type to secmodel
Giuseppe Scrivano [Fri, 18 Oct 2013 12:13:21 +0000 (14:13 +0200)]
capabilities: add baselabel per sec driver/virt type to secmodel

Expand the "secmodel" XML fragment of "host" with a sequence of
baselabel's which describe the default security context used by
libvirt with a specific security model and virtualization type:

<secmodel>
  <model>selinux</model>
  <doi>0</doi>
  <baselabel type='kvm'>system_u:system_r:svirt_t:s0</baselabel>
  <baselabel type='qemu'>system_u:system_r:svirt_tcg_t:s0</baselabel>
</secmodel>
<secmodel>
  <model>dac</model>
  <doi>0</doi>
  <baselabel type='kvm'>107:107</baselabel>
  <baselabel type='qemu'>107:107</baselabel>
</secmodel>

"baselabel" is driver-specific information, e.g. in the DAC security
model, it indicates USER_ID:GROUP_ID.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agosecurity: add new internal function "virSecurityManagerGetBaseLabel"
Giuseppe Scrivano [Fri, 18 Oct 2013 12:13:20 +0000 (14:13 +0200)]
security: add new internal function "virSecurityManagerGetBaseLabel"

virSecurityManagerGetBaseLabel queries the default settings used by
a security model.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
11 years agosecurity: use a single function to set DAC user and group
Giuseppe Scrivano [Fri, 18 Oct 2013 12:13:19 +0000 (14:13 +0200)]
security: use a single function to set DAC user and group

Merge the functions 'virSecurityDACSetUser' and
'virSecurityDACSetGroup' into 'virSecurityDACSetUserAndGroup'.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>