Commit Graph

13937 Commits

Author SHA1 Message Date
John Ferlan
e91f14cb87 valgrind.supp: Add more valgrind suppression paths
Update based on recent run/failures seen
2013-07-23 19:04:48 -04:00
John Ferlan
33aef5dbb3 domain_event: Resolve memory leak found by Valgrind
Commit id '4421e257' strdup'd devAlias, but didn't free

Running qemuhotplugtest under valgrind resulted in the following:

==7375== 9 bytes in 1 blocks are definitely lost in loss record 11 of 70
==7375==    at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==7375==    by 0x37C1085D71: strdup (strdup.c:42)
==7375==    by 0x4CBBD5F: virStrdup (virstring.c:554)
==7375==    by 0x4CFF9CB: virDomainEventDeviceRemovedNew (domain_event.c:1174)
==7375==    by 0x427791: qemuDomainRemoveChrDevice (qemu_hotplug.c:2508)
==7375==    by 0x42C65D: qemuDomainDetachChrDevice (qemu_hotplug.c:3357)
==7375==    by 0x41C94F: testQemuHotplug (qemuhotplugtest.c:115)
==7375==    by 0x41D817: virtTestRun (testutils.c:168)
==7375==    by 0x41C400: mymain (qemuhotplugtest.c:322)
==7375==    by 0x41DF3A: virtTestMain (testutils.c:764)
==7375==    by 0x37C1021A04: (below main) (libc-start.c:225)
2013-07-23 19:04:48 -04:00
John Ferlan
8134b37d34 lxc: Resolve Coverity warning
Commit 'c8695053' resulted in the following:

Coverity error seen in the output:
    ERROR: REVERSE_INULL
    FUNCTION: lxcProcessAutoDestroy

Due to the 'dom' being checked before 'dom->persistent' since 'dom'
is already dereferenced prior to that.
2013-07-23 19:04:48 -04:00
Daniel P. Berrange
da704c8782 Create + setup cgroups atomically for LXC process
Currently the LXC driver creates the VM's cgroup prior to
forking, and then libvirt_lxc moves the child process
into the cgroup. This won't work with systemd whose APIs
do the creation of cgroups + attachment of processes atomically.

Fortunately we simply move the entire cgroups setup into
the libvirt_lxc child process. We make it take place before
fork'ing into the background, so by the time virCommandRun
returns in the LXC driver, the cgroup is guaranteed to be
present.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:46:31 +01:00
Daniel P. Berrange
2049ef9942 Create + setup cgroups atomically for QEMU process
Currently the QEMU driver creates the VM's cgroup prior to
forking, and then uses a virCommand hook to move the child
into the cgroup. This won't work with systemd whose APIs
do the creation of cgroups + attachment of processes atomically.

Fortunately we have a handshake taking place between the
QEMU driver and the child process prior to QEMU being exec()d,
which was introduced to allow setup of disk locking. By good
fortune this synchronization point can be used to enable the
QEMU driver to do atomic setup of cgroups removing the use
of the hook script.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:46:31 +01:00
Daniel P. Berrange
d64e852b5a Remove obsolete cgroups creation apis
The virCgroupNewDomainDriver and virCgroupNewDriver methods
are obsolete now that we can auto-detect existing cgroup
placement. Delete them to reduce code bloat.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:46:31 +01:00
Daniel P. Berrange
87b2e6fa84 Auto-detect existing cgroup placement
Use the new virCgroupNewDetect function to determine cgroup
placement of existing running VMs. This will allow the legacy
cgroups creation APIs to be removed entirely

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:46:31 +01:00
Daniel P. Berrange
e638778eb3 Add API for checking if a cgroup is valid for a domain
Add virCgroupIsValidMachine API to check whether an auto
detected cgroup is valid for a machine. This lets us
check if a VM has just been placed into some generic
shared cgroup, or worse, the root cgroup

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:46:31 +01:00
Daniel P. Berrange
66a7f857f3 Add a virCgroupNewDetect API for finding cgroup placement
Add a virCgroupNewDetect API which is used to initialize a
cgroup object with the placement of an arbitrary process.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:35:26 +01:00
Daniel P. Berrange
666bff4faf Add logic for handling systemd-machined non-existance
If systemd machine does not exist, return -2 instead of -1,
so that applications don't need to repeat the tedious error
checking code

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:35:26 +01:00
Daniel P. Berrange
c64904b745 Fix handling of DBus errors emitted by the bus itself
Current code for handling dbus errors only works for errors
received from the remote application itself. We must also
handle errors emitted by the bus itself, for example, when
it fails to spawn the target service.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-23 22:35:26 +01:00
John Ferlan
a873b496da storage: Add connection for autostart storage pool
Add a privileged field to storageDriverState

Use the privileged value in order to generate a connection which could
be passed to the various storage backend drivers.

In particular, the iSCSI driver will need a connect in order to perform
pool authentication using the 'chap' secrets and the RBD driver utilizes
the connection during pool refresh for pools using 'ceph' secrets.

For now that connection will be to be to qemu driver until a mechanism
is devised to get a connection to just the secret driver without qemu.
2013-07-23 12:56:10 -04:00
John Ferlan
c2257d2ef9 Adjust 'ceph' authentication secret usage for rbd pool.
Update virStorageBackendRBDOpenRADOSConn() to use the internal API to the
secret driver in order to get the secret value instead of the external
virSecretGetValue() path. Without the flag VIR_SECRET_GET_VALUE_INTERNAL_CALL
there is no way to get the value of private secret.

This also requires ensuring there is a connection which wasn't true for
for the refreshPool() path calls from storageDriverAutostart() prior to
adding support for the connection to a qemu driver. It seems calls to
virSecretLookupByUUIDString() and virSecretLookupByUsage() from the
refreshPool() path would have failed with no way to find the secret - that is
theoretically speaking since the 'conn' was NULL the failure would have been
"failed to find the secret".
2013-07-23 10:49:02 -04:00
John Ferlan
249409e765 storage: Support "chap" authentication for iscsi pool
Although the XML for CHAP authentication with plain "password"
was introduced long ago, the function was never implemented. This
patch replaces the login/password mechanism by following the
'ceph' (or RBD) model of using a 'username' with a 'secret' which
has the authentication information.

This patch performs the authentication during startPool() processing
of pools with an authType of VIR_STORAGE_POOL_AUTH_CHAP specified
for iSCSI pools.

There are two types of CHAP configurations supported for iSCSI
authentication:

  * Initiator Authentication
      Forward, one-way; The initiator is authenticated by the target.

  * Target Authentication
      Reverse, Bi-directional, mutual, two-way; The target is authenticated
      by the initiator; This method also requires Initiator Authentication

This only supports the "Initiator Authentication". (I don't have any
enterprise iSCSI env for testing, only have a iSCSI target setup with
tgtd, which doesn't support "Target Authentication").

"Discovery authentication" is not supported by tgt yet too. So this only
setup the session authentication by executing 3 iscsiadm commands, E.g:

% iscsiadm -m node --target "iqn.2013-05.test:iscsi.foo" --name \
  "node.session.auth.authmethod" -v "CHAP" --op update

% iscsiadm -m node --target "iqn.2013-05.test:iscsi.foo" --name \
  "node.session.auth.username" -v "Jim" --op update

% iscsiadm -m node --target "iqn.2013-05.test:iscsi.foo" --name \
  "node.session.auth.password" -v "Jimsecret" --op update
2013-07-23 10:49:02 -04:00
John Ferlan
200ed39d0d qemu_common: Create qemuBuildVolumeString() to process storage pool
Split out into its own separate routine
2013-07-23 10:49:02 -04:00
John Ferlan
7fa4a88afa qemu: Create a common qemuGetSecretString
Make the secret fetching code common for qemuBuildRBDString() and
qemuBuildDriveURIString() using the virDomainDiskDef.
2013-07-23 10:49:02 -04:00
John Ferlan
b83556d8e7 qemu: Add source pool auth info to virDomainDiskDef for iSCSI
During qemuTranslateDiskSourcePool() execution, if the srcpool has been
defined with authentication information, then for iSCSI pools copy the
authentication and host information to virDomainDiskDef.
2013-07-23 10:49:02 -04:00
Peter Krempa
29c2208c04 qemu: Take error path if acquiring of job fails in qemuDomainSaveInternal
Due to a goto statement missed when refactoring in 2771f8b74c
when acquiring of a domain job failed the error path was not taken. This
resulted into a crash afterwards as an extra reference was removed from a
domain object leading to it being freed. An attempt to list the domains
leaded to a crash of the daemon afterwards.

https://bugzilla.redhat.com/show_bug.cgi?id=928672
2013-07-23 16:27:56 +02:00
Laine Stump
e4acc1e969 build: fix make rpm failure
util/virdbuspriv.h needed to be added to UTIL_SOURCES in the makefile.
2013-07-23 09:40:06 -04:00
Roman Bogorodskiy
73cf5b9634 bridge driver: use more general function names
Continue preparation for extracting platform-specific
parts from bridge_driver: s/Iptables/Firewall/ for
firewall related function names.
2013-07-23 13:22:25 +02:00
Roman Bogorodskiy
ac26b2b0e8 Add virDBusMessage(Encode,Decode) stubs
Commit 834c9c94 introduced virDBusMessageEncode and
virDBusMessageDecode functions, however corresponding stubs
were not added to !WITH_DBUS section, therefore 'make check'
started to fail when compiled w/out dbus support like that:

Expected symbol virDBusMessageDecode is not in ELF library
2013-07-23 13:22:17 +02:00
Guannan Ren
7729a16814 virsh: fix change-media bug on disk block type
Resolves:https://bugzilla.redhat.com/show_bug.cgi?id=923053
When cdrom is block type, the virsh change-media failed to insert
source info because virsh uses "<source block='/dev/sdb'/>" while
the correct name of the attribute for block disks is "dev".
2013-07-23 14:20:56 +08:00
Osier Yang
b6c162d3bb qemu: Translate the volume type disk source before cgroup setting
The translation must be done before both of cgroup and security
setting, otherwise since the disk source is not translated yet,
it might be skipped on cgroup and security setting.
2013-07-22 14:03:31 -04:00
Osier Yang
985843586f conf: Ignore the volume type disk if its mode is "direct"
virDomainDiskDefForeachPath is not only used by the security
setting helpers, also used by cgroup setting helpers, so this
is to ignore the volume type disk with mode="direct" for cgroup
setting.
2013-07-22 14:03:31 -04:00
John Ferlan
1b4eaa6195 qemu: Translate the iscsi pool/volume disk source
The difference with already supported pool types (dir, fs, block)
is: there are two modes for iscsi pool (or network pools in future),
one can specify it either to use the volume target path (the path
showed up on host) with mode='host', or to use the remote URI qemu
supports (e.g. file=iscsi://example.org:6000/iqn.1992-01.com.example/1)
with mode='direct'.

For 'host' mode, it copies the volume target path into disk->src. For
'direct' mode, the corresponding info in the *one* pool source host def
is copied to disk->hosts[0].
2013-07-22 14:01:04 -04:00
John Ferlan
1f49b05a82 conf: Introduce virDomainDiskSourceIsBlockType
Introduce a new helper to check if the disk source is of block type
2013-07-22 14:01:04 -04:00
John Ferlan
c00b2f0dd1 conf: Introduce new XML tag "mode" for disk source
There are two ways to use a iSCSI LUN as disk source for qemu.

 * The LUN's path as it shows up on host, e.g.
   /dev/disk/by-path/ip-$ip:3260-iscsi-$iqn-fc18:iscsi.iscsi0-lun-1

 * The libiscsi URI from the storage pool source element host attribute, e.g.
   iscsi://demo.org:6000/iqn.1992-01.com.example/1

For a "volume" type disk, if the specified "pool" is of iscsi
type, we should support to use the LUN in either of above 2 ways.
That's why to introduce a new XML tag "mode" for the disk source
(libvirt should support iscsi pool with libiscsi, but it's another
new feature, which should be done later).

The "mode" can be either of "host" or "direct". Use "host" to indicate
use of the LUN with the path as it shows up on host. Use "direct" to
indicate to use it with the source pool host URI (future patches may support
to use network type libvirt storage too, e.g. Ceph)
2013-07-22 14:01:04 -04:00
John Ferlan
5c62d5ea07 storage_iscsi: Reflect the default target port
Make sure default iSCSI target is 3260.
2013-07-22 14:01:04 -04:00
Jiri Denemark
c9150d3747 tests: Free test at the end of GetDeviceAliases JSON test
Commit 58b147ad07 added a test for
qemuMonitorGetDeviceAliases but forgot to free the test object at the
end which causes all sort of weird errors and failures when new tests
are added after the GetDeviceAliases.
2013-07-22 16:59:14 +02:00
Philipp Hahn
ada5f9ceb8 doc: Fix copy-paste-error in virNodeGetMemoryStats
The description seems to be copied from virNodeGetCpuState.
Change wrong 'cpu' to 'memory'.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2013-07-22 16:53:44 +02:00
Roman Bogorodskiy
162e47795d bridge driver: s/network_driver/virNetworkDriverState/
This is another cleanup before extracting platform-specific
parts from bridge_driver.

Rename struct network_driver to _virNetworkDriverState and
add appropriate typedefs: virNetworkDriverState and
virNetworkDriverStatePtr.

This will help us to avoid potential problems when moving
this struct to the .h file.
2013-07-22 14:16:12 +02:00
Daniel P. Berrange
0d7f45aea7 Convert remainder of cgroups code to report errors
Convert the remaining methods in vircgroup.c to report errors
instead of returning errno values.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Daniel P. Berrange
3260fdfab0 Convert the virCgroupKill* APIs to report errors
Instead of returning errno values, change the virCgroupKill*
APIs to fully report errors.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Daniel P. Berrange
b64dabff27 Report full errors from virCgroupNew*
Instead of returning raw errno values, report full libvirt
errors in virCgroupNew* functions.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Daniel P. Berrange
f5384eed3f Add helpers for dealing with system errors
Add virErrorSetErrnoFromLastError and virLastErrorIsSystemErrno
to simplify code which wants to handle system errors in a more
graceful fashion.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Daniel P. Berrange
dff93f8cab Add API for calling systemd-machined's DBus API
To register virtual machines and containers with systemd-machined,
and thus have cgroups auto-created, we need to talk over DBus.
This is somewhat tedious code, so introduce a dedicated function
to isolate the DBus call in one place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Daniel P. Berrange
834c9c9459 Introduce virDBusCallMethod & virDBusMessageRead methods
Doing DBus method calls using libdbus.so is tedious in the
extreme. systemd developers came up with a nice high level
API for DBus method calls (sd_bus_call_method). While
systemd doesn't use libdbus.so, their API design can easily
be ported to libdbus.so.

This patch thus introduces methods virDBusCallMethod &
virDBusMessageRead, which are based on the code used for
sd_bus_call_method and sd_bus_message_read. This code in
systemd is under the LGPLv2+, so we're license compatible.

This code is probably pretty unintelligible unless you are
familiar with the DBus type system. So I added some API
docs trying to explain how to use them, as well as test
cases to validate that I didn't screw up the adaptation
from the original systemd code.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 13:09:58 +01:00
Jiri Denemark
67dfc772d1 cpu: Let explicit features override model features
Until now CPU features inherited from a specified CPU model could only
be overridden with 'disable' policy. With this patch, any explicitly
specified feature always overrides the same feature inherited from a CPU
model regardless on the specified policy.

The CPU in x86-exact-force-Haswell.xml would previously be incompatible
with x86-host-SandyBridge.xml CPU even though x86-host-SandyBridge.xml
provides all features required by x86-exact-force-Haswell.xml.
2013-07-22 13:57:53 +02:00
Jiri Denemark
0c81eaba9e vmware: Fix bogus CPU arch copy 2013-07-22 13:56:54 +02:00
Jiri Denemark
1dfa174ad2 cpu: Store arch in virCPUData 2013-07-22 13:56:54 +02:00
Jiri Denemark
57d52b244b Replace union cpuData with virCPUData 2013-07-22 13:54:46 +02:00
Jiri Denemark
d87ca6ef39 cpu_x86: Use x86-specific CPU data structure 2013-07-22 13:54:46 +02:00
Daniel P. Berrange
3aac4e5632 LXC: Set default driver for image backed filesystems
If no explicit driver is set for an image backed filesystem,
set it to use the loop driver (if raw) or nbd driver (if
non-raw)

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 12:32:25 +01:00
Daniel P. Berrange
2e832b18d6 LXC: Fix some error reporting in filesystem setup
A couple of places in LXC setup for filesystems did not do
a "goto cleanup" after reporting errors. While fixing this,
also add in many more debug statements to aid troubleshooting

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-22 12:32:07 +01:00
Viktor Mihajlovski
1a82e01c97 qemu: Shorten SCSI hostdev alias to avoid QEMU failure
The alias for hostdevs of type SCSI can be too long for QEMU if
larger LUNs are encountered. Here's a real life example:

    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source>
        <adapter name='scsi_host0'/>
        <address bus='0' target='19' unit='1088634913'/>
      </source>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

this results in a too long drive id, resulting in QEMU yelling

Property 'scsi-generic.drive' can't find value 'drive-hostdev-scsi_host0-0-19-1088634913'

This commit changes the alias back to the default hostdev$(index)
scheme.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2013-07-22 13:16:29 +02:00
Jiri Denemark
0dfb8a1b9e qemu: Unplug devices that disappeared when libvirtd was down
In case libvirtd is asked to unplug a device but the device is actually
unplugged later when libvirtd is not running, we need to detect that and
remove such device when libvirtd starts again and reconnects to running
domains.
2013-07-19 18:45:48 +02:00
Jiri Denemark
58b147ad07 qemu: Introduce qemuMonitorGetDeviceAliases
This API provides a NULL-terminated list of devices which are currently
attached to a QEMU domain.
2013-07-19 18:45:47 +02:00
Jiri Denemark
d327ac5328 conf: Make error reporting in virDomainDefFindDevice optional 2013-07-19 17:59:47 +02:00
Jiri Denemark
09e9f28118 util: Non-existent string array does not contain any string
Make virStringArrayHasString return false when called on a non-existent
string array.
2013-07-19 17:59:47 +02:00
Eric Blake
bfc183c1e3 security: fix deadlock with prefork
Attempts to start a domain with both SELinux and DAC security
modules loaded will deadlock; latent problem introduced in commit
fdb3bde and exposed in commit 29fe5d7.  Basically, when recursing
into the security manager for other driver's prefork, we have to
undo the asymmetric lock taken at the manager level.

Reported by Jiri Denemark, with diagnosis help from Dan Berrange.

* src/security/security_stack.c (virSecurityStackPreFork): Undo
extra lock grabbed during recursion.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-07-19 09:15:22 -06:00