]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
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>
11 years agovirsh: new environment variable VIRSH_HISTSIZE
Pavel Raiskup [Mon, 28 Oct 2013 13:38:46 +0000 (14:38 +0100)]
virsh: new environment variable VIRSH_HISTSIZE

Allow adjust the number of commands to remember in the command
history.

* tools/virsh.c (vshReadlineInit): Read and sanity the
VIRSH_HISTSIZE variable.
(VIRSH_HISTSIZE_MAX): New constant.
* tools/virsh.pod: Document VIRSH_HISTSIZE variable.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agomaint: update to latest gnulib
Eric Blake [Mon, 28 Oct 2013 21:47:20 +0000 (15:47 -0600)]
maint: update to latest gnulib

Since we haven't quite frozen yet, it's time to pick up some
gnulib fixes.  I know at least cygwin benefits from this update.

* .gnulib: Update to latest, in part for cygwin compilation.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoSkip debug message in lxcContainerSetID if no map is set.
Chen Hanxiao [Mon, 28 Oct 2013 11:18:26 +0000 (11:18 +0000)]
Skip debug message in lxcContainerSetID if no map is set.

The lxcContainerSetID() method prints a misleading log
message about setting the uid/gid when no ID map is
present in the XML config. Skip the debug message in
this case.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agodoc: fix a typo in formatdomain
Chen Hanxiao [Fri, 25 Oct 2013 03:51:06 +0000 (11:51 +0800)]
doc: fix a typo in formatdomain

s/no/not

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agoAvoid Coverity DEADCODE warning
John Ferlan [Fri, 18 Oct 2013 10:43:47 +0000 (06:43 -0400)]
Avoid Coverity DEADCODE warning

Commit '922b7fda' resulted in two DEADCODE warnings from Coverity in
remoteDispatchAuthPolkit and virAccessDriverPolkitFormatProcess.
Commit '604ae657' modified the daemon.c code to remove the deadcode
issue, but did not do so for viracessdriverpolkit.c. This just mimics
the same changes

11 years agovirsh: undocument --shareable (--mode already covers it)
Eric Blake [Thu, 24 Oct 2013 07:15:56 +0000 (08:15 +0100)]
virsh: undocument --shareable (--mode already covers it)

Commit e962a57 added 'attach-disk --shareable', even though we
already had 'attach-disk --mode=shareable'.  Worse, if the user
types 'attach-disk --mode=readonly --shareable', we create
non-sensical XML.  The best solution is just to undocument the
duplicate spelling, by having it fall back to the preferred
spelling.

* tools/virsh-domain.c (cmdAttachDisk): Let alias handling fix our
mistake in exposing a second spelling for an existing option.
* tools/virsh.pod: Fix documentation.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agovirsh: allow alias to expand to opt=value pair
Eric Blake [Thu, 24 Oct 2013 07:06:29 +0000 (08:06 +0100)]
virsh: allow alias to expand to opt=value pair

We want to treat 'attach-disk --shareable' as an undocumented
alias for 'attach-disk --mode=shareable'.  By improving our
alias handling, we can allow all such --bool -> --opt=value
replacements, and guarantee up front that the alias is not
mixed with its replacement.

* tools/virsh.c (vshCmddefOptParse, vshCmddefGetOption): Add
support for expanding bool alias to --opt=value.
(opts_echo): Add another alias to test it.
* tests/virshtest.c (mymain): Test it.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agolibxl: Fix possible invalid read
Martin Kletzander [Thu, 24 Oct 2013 09:21:07 +0000 (10:21 +0100)]
libxl: Fix possible invalid read

According to the following valgrind output, there seems to be a
invalid limit for the iterator (captured on Fedora 19):

==3945== Invalid read of size 1
==3945==    at 0x1E1FA410: libxlVmStart (libxl_driver.c:475)
==3945==    by 0x1E1FAD9A: libxlDomainCreateWithFlags (libxl_driver.c:2633)
==3945==    by 0x5187D46: virDomainCreate (libvirt.c:9439)
==3945==    by 0x13BAA6: remoteDispatchDomainCreateHelper (remote_dispatch.h:2910)
==3945==    by 0x51DE5B9: virNetServerProgramDispatch (virnetserverprogram.c:435)
==3945==    by 0x51D93E7: virNetServerHandleJob (virnetserver.c:165)
==3945==    by 0x50F5BF4: virThreadPoolWorker (virthreadpool.c:144)
==3945==    by 0x50F5670: virThreadHelper (virthreadpthread.c:161)
==3945==    by 0x8046C52: start_thread (pthread_create.c:308)
==3945==    by 0x8758E1C: clone (clone.S:113)
==3945==  Address 0x23424d81 is 0 bytes after a block of size 1 alloc'd
==3945==    at 0x4A08121: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3945==    by 0x50B1F8C: virAllocN (viralloc.c:189)
==3945==    by 0x1E1FA3CA: libxlVmStart (libxl_driver.c:468)
==3945==    by 0x1E1FAD9A: libxlDomainCreateWithFlags (libxl_driver.c:2633)
==3945==    by 0x5187D46: virDomainCreate (libvirt.c:9439)
==3945==    by 0x13BAA6: remoteDispatchDomainCreateHelper (remote_dispatch.h:2910)
==3945==    by 0x51DE5B9: virNetServerProgramDispatch (virnetserverprogram.c:435)
==3945==    by 0x51D93E7: virNetServerHandleJob (virnetserver.c:165)
==3945==    by 0x50F5BF4: virThreadPoolWorker (virthreadpool.c:144)
==3945==    by 0x50F5670: virThreadHelper (virthreadpthread.c:161)
==3945==    by 0x8046C52: start_thread (pthread_create.c:308)
==3945==    by 0x8758E1C: clone (clone.S:113)
==3945==

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1013045
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agovirsh: fix doc typos
Eric Blake [Thu, 24 Oct 2013 08:57:20 +0000 (09:57 +0100)]
virsh: fix doc typos

Reported in https://bugzilla.redhat.com/show_bug.cgi?id=1022872

* tools/virsh.pod: s/COMMMANDS/COMMANDS/

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoIgnore GNU Global tag files
Martin Kletzander [Wed, 23 Oct 2013 08:58:55 +0000 (09:58 +0100)]
Ignore GNU Global tag files

... the same way we ignore other TAGS

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agobuild: Fix prohibit_int_ijk (and iijjkk) on RHEL 5
Martin Kletzander [Tue, 22 Oct 2013 16:09:57 +0000 (17:09 +0100)]
build: Fix prohibit_int_ijk (and iijjkk) on RHEL 5

On RHEL 5, make syntax-check was failing because even strings like
'int isTempChain' matched the 'int i' rule.  To be honest, I haven't
found the root cause, but the change added makes it work as expected
and keeps the proper behavior on newer systems as well.

11 years agopython: Fix Create*WithFiles filefd passing
Marian Neagul [Tue, 22 Oct 2013 15:03:39 +0000 (16:03 +0100)]
python: Fix Create*WithFiles filefd passing

Commit d76227be added functions virDomainCreateWithFiles and
virDomainCreateXMLWithFiles, but there was a little piece missing in
python bindings.  This patch fixes proper passing of file descriptors
in the overwrites of these functions.

11 years agonetworkStartDhcpDaemon: Check for dnsmasqCapsRefresh failure
Hongwei Bi [Tue, 22 Oct 2013 13:38:01 +0000 (21:38 +0800)]
networkStartDhcpDaemon: Check for dnsmasqCapsRefresh failure

Currently, we ignore whether dnsmasqCapsRefresh succeeds or fails. We
shouldn't do that as we may generate wrong dnsmasq command line (what
is done just a few lines below).

Signed-off-by: Hongwei Bi <hwbi2008@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agorpc: Retrieve peer PID via new getsockopt() for Mac
Doug Goldstein [Sat, 12 Oct 2013 17:06:27 +0000 (12:06 -0500)]
rpc: Retrieve peer PID via new getsockopt() for Mac

While LOCAL_PEERCRED on the BSDs does not return the pid information of
the peer, Mac OS X 10.8 added LOCAL_PEERPID to retrieve the pid so we
should use that when its available to get that information.

11 years agomaint: typo fixes
Eric Blake [Tue, 22 Oct 2013 15:48:18 +0000 (16:48 +0100)]
maint: typo fixes

* ChangeLog-old: s/guarentee/guarantee/

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agobuild: fix build of virt-login-shell on systems with older gnutls
Jim Fehlig [Tue, 22 Oct 2013 05:12:22 +0000 (23:12 -0600)]
build: fix build of virt-login-shell on systems with older gnutls

On systems where gnutls uses libgcrypt, I'm seeing the following
build failure

libvirt.c:314: error: variable 'virTLSThreadImpl' has initializer but incomplete type
libvirt.c:319: error: 'GCRY_THREAD_OPTION_PTHREAD' undeclared here (not in a function)
...

Fix by undefining WITH_GNUTLS_GCRYPT in config-post.h

11 years agoGet rid of shadowed booleans
Michal Privoznik [Tue, 22 Oct 2013 09:33:06 +0000 (10:33 +0100)]
Get rid of shadowed booleans

There are still two places where we are using 1bit width unsigned
integer to store a boolean. There's no real need for this and these
occurrences can be replaced with 'bool'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agobuild: fix linking virt-login-shell
Jim Fehlig [Mon, 21 Oct 2013 21:36:11 +0000 (15:36 -0600)]
build: fix linking virt-login-shell

After commit 3e2f27e1, I've noticed build failures of virt-login-shell
when libapparmor-devel is installed on the build host

CCLD     virt-login-shell
../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-vircommand.o):
In function `virExec':
/home/jfehlig/virt/upstream/libvirt/src/util/vircommand.c:653: undefined
reference to `aa_change_profile'
collect2: error: ld returned 1 exit status

I was about to commit an easy fix under the build-breaker rule
(build-fix-1.patch), but thought to extend the notion of SECDRIVER_LIBS
to SECDRIVER_CFLAGS, and use both throughout src/Makefile.am where it
makes sense (build-fix-2.patch).

Should I just stick with the simple fix, or is something along the lines
of patch 2 preferred?

Regards,
Jim

>From a0f35945f3127ab70d051101037e821b1759b4bb Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Mon, 21 Oct 2013 15:30:02 -0600
Subject: [PATCH] build: fix virt-login-shell build with apparmor

With libapparmor-devel installed, virt-login-shell fails to link

CCLD     virt-login-shell
../src/.libs/libvirt-setuid-rpc-client.a(libvirt_setuid_rpc_client_la-vircommand.o): In function `virExec':
/home/jfehlig/virt/upstream/libvirt/src/util/vircommand.c:653: undefined reference to `aa_change_profile'
collect2: error: ld returned 1 exit status

Fix by linking libvirt_setuid_rpc_client with previously determined
SECDRIVER_LIBS in src/Makefile.am.  While at it, introduce SECDRIVER_CFLAGS
and use both throughout src/Makefile.am where it makes sense.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
11 years agovircgroupmock: Mock access() to some more files
Michal Privoznik [Tue, 22 Oct 2013 12:15:21 +0000 (13:15 +0100)]
vircgroupmock: Mock access() to some more files

Currently, if access(path, mode) is invoked, we check if @path has this
special prefix SYSFS_PREFIX. If it does, we modify the path a bit and
call realaccess. If it doesn't we act just like a wrapper and call
realaccess directly. However, we are mocking fopen() as well. And as one
can clearly see there, fopen("/proc/cgroups") will succeed. Hence, we
have an error in our mocked access(): We need to check whether @path is
not equal to /proc/cgroups as it may not exists on real system we're
running however we definitely know how to fopen() it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agotests: Use lv_abs_top_builddir instead of bare abs_top_builddir
Michal Privoznik [Tue, 22 Oct 2013 11:29:13 +0000 (12:29 +0100)]
tests: Use lv_abs_top_builddir instead of bare abs_top_builddir

As stated in the comment above introduction of the lv_abs_top_builddir
variable, older automake doesn't provide abs_top_builddir variable.
Hence, we are creating our own one with lv_ prefix. However, when
exporting env variables to the tests, the variables are not evaluated
but only substituted. Hence:

  LIBVIRT_DRIVER_DIR="$(abs_top_builddir)/src/.libs"

is set to "/src/.libs" with old automake (even though we *think* we've
set the $abs_top_builddir variable just a few line above).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agovirsh: Fix job watching when STDIN is not a tty
Peter Krempa [Tue, 22 Oct 2013 14:01:26 +0000 (15:01 +0100)]
virsh: Fix job watching when STDIN is not a tty

In commit b46c4787dde79b015dad67dedda4ccf6ff1a3082 I changed the code to
watch long running jobs in virsh. Unfortunately I didn't take into
account that poll may get a hangup if the terminal is not a TTY and will
be closed.

This patch avoids polling the STDIN fd when there's no TTY.

11 years agodocs: fix some typos about 'informations'
Chen Hanxiao [Tue, 22 Oct 2013 03:02:43 +0000 (11:02 +0800)]
docs: fix some typos about 'informations'

s/informations/information

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
11 years agonodeinfo: fix physical memory size on Mac OS X
Ryota Ozaki [Sun, 20 Oct 2013 15:14:52 +0000 (00:14 +0900)]
nodeinfo: fix physical memory size on Mac OS X

HW_PHYSMEM is available on Mac OS X as well as FreeBSD, however,
its resulting value for Mac OS X is 32 bits. Mac OS X provides
HW_MEMSIZE that is 64 bits version of HW_PHYSMEM. We have to use it.

I tested the patch on Mac OS X 10.6.8, 10.7.4, 10.8.5 and FreeBSD 9.2.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
11 years agoqemu: fix removal of <interface type='hostdev'>
Laine Stump [Fri, 18 Oct 2013 09:34:53 +0000 (12:34 +0300)]
qemu: fix removal of <interface type='hostdev'>

This patch (and the two patches that precede it) resolve:

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

When libvirt was changed to delay the final cleanup of device removal
until the qemu process had signaled it with a DEVICE_DELETED event for
that device, the hostdev removal function
(qemuDomainRemoveHostDevice()) was written to properly handle the
removal of a hostdev that was actually an SRIOV virtual function
(defined with <interface type='hostdev'>). However, the function used
to search for a device matching the alias name provided in the
DEVICE_DELETED message (virDomainDefFindDevice()) would search through
the list of netdevs before hostdevs, so qemuDomainRemoveHostDevice()
was never called; instead the netdev function,
qemuDomainRemoveNetDevice() (which *doesn't* properly cleanup after
removal of <interface type='hostdev'>), was called.

(As a reminder - each <interface type='hostdev'> results in a
virDomainNetDef which contains a virDomainHostdevDef having a parent
type of VIR_DOMAIN_DEVICE_NET, and parent.data.net pointing back to
the virDomainNetDef; both Defs point to the same device info object
(and the info contains the device's "alias", which is used by qemu to
identify the device). The virDomainHostdevDef is added to the domain's
hostdevs list *and* the virDomainNetDef is added to the domain's nets
list, so searching either list for a particular alias will yield a
positive result.)

This function modifies the qemuDomainRemoveNetDevice() to short
circuit itself and call qemu DomainRemoveHostDevice() instead when the
actual device is a VIR_DOMAIN_NET_TYPE_HOSTDEV (similar logic to what
is done in the higher level qemuDomainDetachNetDevice())

Note that even if virDomainDefFindDevice() changes in the future so
that it finds the hostdev entry first, the current code will continue
to work properly.

11 years agoqemu: move qemuDomainRemoveNetDevice to avoid forward reference
Laine Stump [Fri, 18 Oct 2013 09:28:40 +0000 (12:28 +0300)]
qemu: move qemuDomainRemoveNetDevice to avoid forward reference

pure code movement to setup for next patch.

11 years agoqemu: simplify calling qemuDomainHostdevNetConfigRestore
Laine Stump [Fri, 18 Oct 2013 08:39:08 +0000 (11:39 +0300)]
qemu: simplify calling qemuDomainHostdevNetConfigRestore

This function was called in three places, and in each the call was
qualified by a slightly different conditional. In reality, this
function should only be called for a hostdev if all of the following
are true:

  1) mode='subsystem'
  2) type='pci'
  3) there is a parent device definition which is an <interface>
     (VIR_DOMAIN_DEVICE_NET)

We can simplify the callers and make them more consistent by checking
these conditions at the top ov qemuDomainHostdevNetConfigRestore and
returning 0 if one of them isn't satisfied.

The location of the call to qemuDomainHostdevNetConfigRestore() has
also been changed in the hot-plug case - it is moved into the caller
of its previous location (i.e. from qemuDomainRemovePCIHostDevice() to
qemuDomainRemoveHostDevice()). This was done to be more consistent
about which functions pay attention to whether or not this is one of
the special <interface> hostdevs or just a normal hostdev -
qemuDomainRemoveHostDevice() already contained a call to
networkReleaseActualDevice() and virDomainNetDefFree(), so it makes
sense for it to also handle the resetting of the device's MAC address
and vlan tag (which is what's done by
qemuDomainHostdevNetConfigRestore()).

11 years agoMove virt-login-shell into libvirt-login-shell sub-RPM
Daniel P. Berrange [Thu, 17 Oct 2013 13:18:18 +0000 (14:18 +0100)]
Move virt-login-shell into libvirt-login-shell sub-RPM

Many people will not want the setuid virt-login-shell binary
installed by default, so move it into a separate sub-RPM
named libvirt-login-shell. This RPM is only generated if
LXC is enabled

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoBlock all use of libvirt.so in setuid programs
Daniel P. Berrange [Thu, 10 Oct 2013 16:45:14 +0000 (17:45 +0100)]
Block all use of libvirt.so in setuid programs

Avoid people introducing security flaws in their apps by
forbidding the use of libvirt.so in setuid programs, with
a check in virInitialize.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove (nearly) all use of getuid()/getgid()
Daniel P. Berrange [Wed, 9 Oct 2013 11:13:45 +0000 (12:13 +0100)]
Remove (nearly) all use of getuid()/getgid()

Most of the usage of getuid()/getgid() is in cases where we are
considering what privileges we have. As such the code should be
using the effective IDs, not real IDs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd stub getegid impl for platforms lacking it
Daniel P. Berrange [Thu, 17 Oct 2013 13:51:32 +0000 (14:51 +0100)]
Add stub getegid impl for platforms lacking it

We already have stubs for getuid, geteuid, getgid but
not for getegid. Something in gnulib already does a
check for it during configure, so we already have the
HAVE_GETEGID macro defined.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoDon't allow remote driver daemon autostart when running setuid
Daniel P. Berrange [Wed, 9 Oct 2013 10:47:13 +0000 (11:47 +0100)]
Don't allow remote driver daemon autostart when running setuid

We don't want setuid programs automatically spawning libvirtd,
so disable any use of autostart when setuid.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoOnly allow the UNIX transport in remote driver when setuid
Daniel P. Berrange [Wed, 9 Oct 2013 10:44:50 +0000 (11:44 +0100)]
Only allow the UNIX transport in remote driver when setuid

We don't know enough about quality of external libraries used
for non-UNIX transports, nor do we want to spawn external
commands when setuid. Restrict to the bare minimum which is
UNIX transport for local usage. Users shouldn't need to be
running setuid if connecting to remote hypervisors in any
case.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoBlock all use of getenv with syntax-check
Daniel P. Berrange [Wed, 9 Oct 2013 10:19:27 +0000 (11:19 +0100)]
Block all use of getenv with syntax-check

The use of getenv is typically insecure, and we want people
to use our wrappers, to force them to think about setuid
needs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove all direct use of getenv
Daniel P. Berrange [Wed, 9 Oct 2013 10:18:15 +0000 (11:18 +0100)]
Remove all direct use of getenv

Unconditional use of getenv is not secure in setuid env.
While not all libvirt code runs in a setuid env (since
much of it only exists inside libvirtd) this is not always
clear to developers. So make all the code paranoid, even
if it only ever runs inside libvirtd.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoMake virCommand env handling robust in setuid env
Daniel P. Berrange [Wed, 9 Oct 2013 10:03:02 +0000 (11:03 +0100)]
Make virCommand env handling robust in setuid env

When running setuid, we must be careful about what env vars
we allow commands to inherit from us. Replace the
virCommandAddEnvPass function with two new ones which do
filtering

  virCommandAddEnvPassAllowSUID
  virCommandAddEnvPassBlockSUID

And make virCommandAddEnvPassCommon use the appropriate
ones

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoSet a sane $PATH for virt-login-shell
Daniel P. Berrange [Wed, 9 Oct 2013 10:19:52 +0000 (11:19 +0100)]
Set a sane $PATH for virt-login-shell

The virt-login-shell binary shouldn't need to execute programs
relying on $PATH, but just in case set a fixed $PATH value
of /bin:/usr/bin

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoDon't link virt-login-shell against libvirt.so (CVE-2013-4400)
Daniel P. Berrange [Thu, 10 Oct 2013 12:09:08 +0000 (13:09 +0100)]
Don't link virt-login-shell against libvirt.so (CVE-2013-4400)

The libvirt.so library has far too many library deps to allow
linking against it from setuid programs. Those libraries can
do stuff in __attribute__((constructor) functions which is
not setuid safe.

The virt-login-shell needs to link directly against individual
files that it uses, with all library deps turned off except
for libxml2 and libselinux.

Create a libvirt-setuid-rpc-client.la library which is linked
to by virt-login-shell. A config-post.h file allows this library
to disable all external deps except libselinux and libxml2.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoClose all non-stdio FDs in virt-login-shell (CVE-2013-4400)
Daniel P. Berrange [Wed, 9 Oct 2013 14:14:34 +0000 (15:14 +0100)]
Close all non-stdio FDs in virt-login-shell (CVE-2013-4400)

We don't want to inherit any FDs in the new namespace
except for the stdio FDs. Explicitly close them all,
just in case some do not have the close-on-exec flag
set.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoOnly allow 'stderr' log output when running setuid (CVE-2013-4400)
Daniel P. Berrange [Wed, 9 Oct 2013 09:59:36 +0000 (10:59 +0100)]
Only allow 'stderr' log output when running setuid (CVE-2013-4400)

We must not allow file/syslog/journald log outputs when running
setuid since they can be abused to do bad things. In particular
the 'file' output can be used to overwrite files.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd helpers for getting env vars in a setuid environment
Daniel P. Berrange [Wed, 9 Oct 2013 09:52:39 +0000 (10:52 +0100)]
Add helpers for getting env vars in a setuid environment

Care must be taken accessing env variables when running
setuid. Introduce a virGetEnvAllowSUID for env vars which
are safe to use in a setuid environment, and another
virGetEnvBlockSUID for vars which are not safe. Also add
a virIsSUID helper method for any other non-env var code
to use.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoFix perms for virConnectDomainXML{To,From}Native (CVE-2013-4401)
Daniel P. Berrange [Thu, 3 Oct 2013 15:37:57 +0000 (16:37 +0100)]
Fix perms for virConnectDomainXML{To,From}Native (CVE-2013-4401)

The virConnectDomainXMLToNative API should require 'connect:write'
not 'connect:read', since it will trigger execution of the QEMU
binaries listed in the XML.

Also make virConnectDomainXMLFromNative API require a full
read-write connection and 'connect:write' permission. Although the
current impl doesn't trigger execution of QEMU, we should not
rely on that impl detail from an API permissioning POV.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agodocs: fix a typo in formatdomain
Chen Hanxiao [Mon, 21 Oct 2013 01:35:11 +0000 (09:35 +0800)]
docs: fix a typo in formatdomain

s/effect/affect

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>