]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
9 years agoqemu: Let empty default VNC password work as documented v1.2.14-maint
Jiri Denemark [Tue, 28 Jun 2016 12:39:58 +0000 (14:39 +0200)] 
qemu: Let empty default VNC password work as documented

CVE-2016-5008

Setting an empty graphics password is documented as a way to disable
VNC/SPICE access, but QEMU does not always behaves like that. VNC would
happily accept the empty password. Let's enforce the behavior by setting
password expiration to "now".

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit bb848feec0f3f10e92dd8e5231ae7aa89b5598f3)

9 years agoCVE-2015-5313: storage: don't allow '/' in filesystem volume names
Eric Blake [Wed, 9 Dec 2015 00:46:31 +0000 (17:46 -0700)] 
CVE-2015-5313: storage: don't allow '/' in filesystem volume names

The libvirt file system storage driver determines what file to
act on by concatenating the pool location with the volume name.
If a user is able to pick names like "../../../etc/passwd", then
they can escape the bounds of the pool.  For that matter,
virStoragePoolListVolumes() doesn't descend into subdirectories,
so a user really shouldn't use a name with a slash.

Normally, only privileged users can coerce libvirt into creating
or opening existing files using the virStorageVol APIs; and such
users already have full privilege to create any domain XML (so it
is not an escalation of privilege).  But in the case of
fine-grained ACLs, it is feasible that a user can be granted
storage_vol:create but not domain:write, and it violates
assumptions if such a user can abuse libvirt to access files
outside of the storage pool.

Therefore, prevent all use of volume names that contain "/",
whether or not such a name is actually attempting to escape the
pool.

This changes things from:

$ virsh vol-create-as default ../../../../../../etc/haha --capacity 128
Vol ../../../../../../etc/haha created
$ rm /etc/haha

to:

$ virsh vol-create-as default ../../../../../../etc/haha --capacity 128
error: Failed to create vol ../../../../../../etc/haha
error: Requested operation is not valid: volume name '../../../../../../etc/haha' cannot contain '/'

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 034e47c338b13a95cf02106a3af912c1c5f818d7)

9 years agoremoteClientCloseFunc: Don't mangle connection object refcount
Michal Privoznik [Thu, 3 Sep 2015 10:11:53 +0000 (12:11 +0200)] 
remoteClientCloseFunc: Don't mangle connection object refcount

Well, in 8ad126e6 we tried to fix a memory corruption problem.
However, the fix was not as good as it could be. I mean, the
commit has one line more than it should. I've noticed this output
just recently:

  # ./run valgrind --leak-check=full --show-reachable=yes ./tools/virsh domblklist gentoo
  ==17019== Memcheck, a memory error detector
  ==17019== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
  ==17019== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
  ==17019== Command: /home/zippy/work/libvirt/libvirt.git/tools/.libs/virsh domblklist gentoo
  ==17019==
  Target     Source
  ------------------------------------------------
  fda        /var/lib/libvirt/images/fd.img
  vda        /var/lib/libvirt/images/gentoo.qcow2
  hdc        /home/zippy/tmp/install-amd64-minimal-20150402.iso

  ==17019== Thread 2:
  ==17019== Invalid read of size 4
  ==17019==    at 0x4EFF5B4: virObjectUnref (virobject.c:258)
  ==17019==    by 0x5038CFF: remoteClientCloseFunc (remote_driver.c:552)
  ==17019==    by 0x5069D57: virNetClientCloseLocked (virnetclient.c:685)
  ==17019==    by 0x506C848: virNetClientIncomingEvent (virnetclient.c:1852)
  ==17019==    by 0x5082136: virNetSocketEventHandle (virnetsocket.c:1913)
  ==17019==    by 0x4ECD64E: virEventPollDispatchHandles (vireventpoll.c:509)
  ==17019==    by 0x4ECDE02: virEventPollRunOnce (vireventpoll.c:658)
  ==17019==    by 0x4ECBF00: virEventRunDefaultImpl (virevent.c:308)
  ==17019==    by 0x130386: vshEventLoop (vsh.c:1864)
  ==17019==    by 0x4F1EB07: virThreadHelper (virthread.c:206)
  ==17019==    by 0xA8462D3: start_thread (in /lib64/libpthread-2.20.so)
  ==17019==    by 0xAB441FC: clone (in /lib64/libc-2.20.so)
  ==17019==  Address 0x139023f4 is 4 bytes inside a block of size 240 free'd
  ==17019==    at 0x4C2B1F0: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==17019==    by 0x4EA8949: virFree (viralloc.c:582)
  ==17019==    by 0x4EFF6D0: virObjectUnref (virobject.c:273)
  ==17019==    by 0x4FE74D6: virConnectClose (libvirt.c:1390)
  ==17019==    by 0x13342A: virshDeinit (virsh.c:406)
  ==17019==    by 0x134A37: main (virsh.c:950)

The problem is, when registering remoteClientCloseFunc(), it's
conn->closeCallback which is ref'd. But in the function itself
it's conn->closeCallback->conn what is unref'd. This is causing
imbalance in reference counting. Moreover, there's no need for
the remote driver to increase/decrease conn refcount since it's
not used anywhere. It's just merely passed to client registered
callback. And for that purpose it's correctly ref'd in
virConnectRegisterCloseCallback() and then unref'd in
virConnectUnregisterCloseCallback().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit e68930077034f786e219bdb015f8880dbc5a246f)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9 years agostorage: Handle failure from refreshVol
John Ferlan [Mon, 24 Aug 2015 16:38:13 +0000 (12:38 -0400)] 
storage: Handle failure from refreshVol

Commit id '155ca616' added the 'refreshVol' API. In an NFS root-squash
environment it was possible that if the just created volume from XML wasn't
properly created with the right uid/gid and/or mode, then the followup
refreshVol will fail to open the volume in order to get the allocation/
capacity values. This would leave the volume still on the server and
cause a libvirtd crash because 'voldef' would be in the pool list, but
the cleanup code would free it.

9 years agovirfile: Introduce virFileUnlink
John Ferlan [Mon, 24 Aug 2015 21:00:02 +0000 (17:00 -0400)] 
virfile: Introduce virFileUnlink

In an NFS root-squashed environment the 'vol-delete' command will fail to
'unlink' the target volume since it was created under a different uid:gid.

This code continues the concepts introduced in virFileOpenForked and
virDirCreate[NoFork] with respect to running the unlink command under
the uid/gid of the child. Unlike the other two, don't retry on EACCES
(that's why we're here doing this now).

9 years agoRevert "LXC: show used memory as 0 when domain is not active"
Jim Fehlig [Mon, 10 Aug 2015 18:49:55 +0000 (12:49 -0600)] 
Revert "LXC: show used memory as 0 when domain is not active"

This reverts commit 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e,
which introduced a significant semantic change to the
virDomainGetInfo() API. Additionally, the change was only
made to 2 of the 15 virt drivers.

Conflicts:
src/qemu/qemu_driver.c

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
(cherry picked from commit 60acb38abbee1636a9cddf8d296f700d115c8f77)

10 years agolxc: Don't pass a local variable address randomly
Michal Privoznik [Wed, 1 Jul 2015 15:21:28 +0000 (17:21 +0200)] 
lxc: Don't pass a local variable address randomly

So, recently I was testing the LXC driver. You know, startup some
domains. But to my surprise, I was not able to start a single one:

  virsh # start --console test
  error: Reconnected to the hypervisor
  error: Failed to start domain test
  error: internal error: guest failed to start: unexpected exit status 125

So I've start digging. It turns out, that in virExec(), when I printed
out the @cmd, I got strange values: *(cmd->outfdptr) was certainly not
valid FD number: it has random value of several millions. This
obviously made prepareStdFd(childout, STDOUT_FILENO) fail (line 611).
But outfdptr is set in virCommandSetOutputFD(). The only place within
LXC driver where the function is called is in
virLXCProcessBuildControllerCmd(). If you take a closer look at the
function it looks like this:

static virCommandPtr
virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
                                ..
                                int logfd,
                                const char *pidfile)
{
    ...
    virCommandSetOutputFD(cmd, &logfd);
    virCommandSetErrorFD(cmd, &logfd);
    ...
}

Yes, you guessed it. @logfd is passed into the function by value.
However, in the function we try to get its address (an address of a
local variable) which is no longer valid once function is finished and
stack is cleaned. Therefore when cmd->outfdptr is evaluated at any
point after this function, we may get a random number, depending on
what's currently on the stack. Of course, this may work sometimes too
- it depends on the compiler how it arranges the code, when the stack
is wiped out.

In order to fix this, lets pass a pointer to @logfd instead of
figuring out (wrong) its value in a function.

The bug was introduced in e1de5521.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 302146b16d204e3feb8f04a9f81b8f587c827302)

10 years agolxc: set nosuid+nodev+noexec flags on /proc/sys mount
Eric W. Biederman [Tue, 16 Jun 2015 13:44:36 +0000 (14:44 +0100)] 
lxc: set nosuid+nodev+noexec flags on /proc/sys mount

Future kernels will mandate the use of nosuid+nodev+noexec
flags when mounting the /proc/sys filesystem. Unconditionally
add them now since they don't harm things regardless and could
mitigate future security attacks.

(cherry picked from commit 24710414d403f1040794299f5304fee160d0fc23)

10 years agovirsh: fix regression in 'virsh event' by domain
Eric Blake [Tue, 14 Apr 2015 22:15:06 +0000 (16:15 -0600)] 
virsh: fix regression in 'virsh event' by domain

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

Commit a0670ae caused a regression in 'virsh event' and
'virsh qemu-monitor-event' - if a user tries to filter the
command to a specific domain, an error message is printed:

$ virsh event dom --loop
error: internal error: virsh qemu-monitor-event: no domain VSH_OT_DATA option

and then the command continues as though no domain had been
supplied (giving events for ALL domains, instead of the
requested one).  This is because the code was incorrectly
assuming that all "domain" options would be supplied via a
mandatory VSH_OT_DATA, even though "domain" is optional for
these two commands, so we had changed them to VSH_OT_STRING
to quit failing for other reasons (ever since it was decided
that VSH_OT_DATA and VSH_OT_STRING should no longer be
synonyms).

In looking at the situation, though, the code for looking up
a domain was making a pointless check for whether the option
exists prior to finding the option's string value, as
vshCommandOptStringReq does just fine at reporting any errors
when looking up a string whether or not the option was present.

So this is a case of regression fixing by pure code deletion :)

* tools/virsh-domain.c (vshCommandOptDomainBy): Drop useless filter.
* tools/virsh-interface.c (vshCommandOptInterfaceBy): Likewise.
* tools/virsh-network.c (vshCommandOptNetworkBy): Likewise.
* tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise.
* tools/virsh-secret.c (vshCommandOptSecret): Likewise.
* tools/virsh.h (vshCmdHasOption): Drop unused function.
* tools/virsh.c (vshCmdHasOption): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 31ef0836a73ed8583ff93613d2759e28965103ef)

10 years agoRelease of libvirt-1.2.14 v1.2.14
Daniel Veillard [Thu, 2 Apr 2015 07:48:08 +0000 (15:48 +0800)] 
Release of libvirt-1.2.14

- docs/news.html.in libvirt.spec.in: update for the release
- po/*.po*: regenerated localization

10 years agotests: nodeinfo: Add test for RHELSA on APM mustang
Cole Robinson [Tue, 31 Mar 2015 20:40:28 +0000 (14:40 -0600)] 
tests: nodeinfo: Add test for RHELSA on APM mustang

This would have caught the bug fixed by Wei's commit c13de016

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agotests: nodeinfo: Test F21 aarch64 on APM mustang
Cole Robinson [Tue, 31 Mar 2015 20:38:41 +0000 (14:38 -0600)] 
tests: nodeinfo: Test F21 aarch64 on APM mustang

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu: blockjob: Synchronously update backing chain in XML on ABORT/PIVOT v1.2.14-rc2
Peter Krempa [Mon, 30 Mar 2015 09:26:20 +0000 (11:26 +0200)] 
qemu: blockjob: Synchronously update backing chain in XML on ABORT/PIVOT

When the synchronous pivot option is selected, libvirt would not update
the backing chain until the job was exitted. Some applications then
received invalid data as their job serialized first.

This patch removes polling to wait for the ABORT/PIVOT job completion
and replaces it with a condition. If a synchronous operation is
requested the update of the XML is executed in the job of the caller of
the synchronous request. Otherwise the monitor event callback uses a
separate worker to update the backing chain with a new job.

This is a regression since 1a92c719101e5bfa6fe2b78006ad04c7f075ea28

When the ABORT job is finished synchronously you get the following call
stack:
 #0  qemuBlockJobEventProcess
 #1  qemuDomainBlockJobImpl
 #2  qemuDomainBlockJobAbort
 #3  virDomainBlockJobAbort

While previously or while using the _ASYNC flag you'd get:
 #0  qemuBlockJobEventProcess
 #1  processBlockJobEvent
 #2  qemuProcessEventHandler
 #3  virThreadPoolWorker

10 years agoqemu: Extract internals of processBlockJobEvent into a helper
Peter Krempa [Mon, 30 Mar 2015 09:26:19 +0000 (11:26 +0200)] 
qemu: Extract internals of processBlockJobEvent into a helper

Later on I'll be adding a condition that will allow to synchronise a
SYNC block job abort. The approach will require this code to be called
from two different places so it has to be extracted into a helper.

10 years agoqemu: processBlockJob: Don't unlock @vm twice
Peter Krempa [Mon, 30 Mar 2015 09:26:18 +0000 (11:26 +0200)] 
qemu: processBlockJob: Don't unlock @vm twice

Commit 1a92c719 moved code to handle block job events to a different
function that is executed in a separate thread. The caller of
processBlockJob handles locking and unlocking of @vm, so the we should
not do it in the function itself.

10 years agoqemu: blockCopy: Pass adjusted bandwidth when called via blockRebase
Peter Krempa [Mon, 30 Mar 2015 15:34:13 +0000 (17:34 +0200)] 
qemu: blockCopy: Pass adjusted bandwidth when called via blockRebase

The block copy API takes the speed in bytes/s rather than MiB/s that was
the prior approach in virDomainBlockRebase. We correctly converted the
speed to bytes/s in the old API but we still called the common helper
virDomainBlockCopyCommon with the unadjusted variable.

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

10 years agovirsh: blockCopy: Add missing jump on error path
Luyao Huang [Fri, 27 Mar 2015 09:56:29 +0000 (17:56 +0800)] 
virsh: blockCopy: Add missing jump on error path

The overflow check for the bandwidth parameter did not jump to the
cleanup label.

Additionally virsh should use vshError instead of virReportError.

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemuDomainGetNumaParameters: Check for the correct CGroup controller
Michal Privoznik [Fri, 27 Mar 2015 14:16:43 +0000 (15:16 +0100)] 
qemuDomainGetNumaParameters: Check for the correct CGroup controller

When getting info on NUMA parameters for domain,
virCgroupGetCpusetMems() may be called. However, as of 43b67f2e
the call is guarded by check if memory controller is present.
Even though it may be not obvious instantly, NUMA parameters are
stored under cpuset controller. Therefore the check needs to look
like this:

  if (!virCgroupHasController(priv->cgroup,
                              VIR_CGROUP_CONTROLLER_CPUSET) ||
      virCgroupGetCpusetMems(priv->cgroup, &nodeset) < 0) {

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupController: Check the enum fits into 'int'
Michal Privoznik [Fri, 27 Mar 2015 12:45:33 +0000 (13:45 +0100)] 
virCgroupController: Check the enum fits into 'int'

Throughout our code, the virCgroupController enum is used in two ways.
First as an index to an array of cgroup controllers:

struct virCgroup {
    char *path;

    struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
};

Second way is that when calling virCgroupNew() a bitmask of the enum
items can be passed to selectively detect only some controllers. For
instance:

int
virCgroupNewVcpu(virCgroupPtr domain,
                 int vcpuid,
                 bool create,
                 virCgroupPtr *group)
{
    ...
    controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUSET));

    if (virCgroupNew(-1, name, domain, controllers, group) < 0)
        goto cleanup;
}

Even though it's highly unlikely that so many new controllers will be
invented so that we would overflow when constructing the bitmask, it
doesn't hurt to check at compile time either.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupNew: Enhance debug message
Michal Privoznik [Fri, 27 Mar 2015 10:29:25 +0000 (11:29 +0100)] 
virCgroupNew: Enhance debug message

When creating new internal representation of cgroups, all passed
arguments are logged. Well, except for two: pid and pointer for
return value. Lets log them too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupNewPartition: Fix comment
Michal Privoznik [Fri, 27 Mar 2015 10:24:16 +0000 (11:24 +0100)] 
virCgroupNewPartition: Fix comment

The function has no argument named @name rather than @path
instead.  The comment is, however, referring to @name while it
should have been referring to @path really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agobuild: avoid variable named 'interface', for mingw
Eric Blake [Sat, 28 Mar 2015 20:04:27 +0000 (14:04 -0600)] 
build: avoid variable named 'interface', for mingw

Commit 2f36e6944 (re-)introduced a use of an identifier 'interface',
which causes this build failure on mingw:

../../tools/virsh-domain-monitor.c: In function 'cmdDomIfAddr':
../../tools/virsh-domain-monitor.c:2233:17: error: expected identifier or '(' before 'struct'
     const char *interface = NULL;
                      ^

See also commit 6512c8b.  Sadly, I'm not quite sure how to write a
syntax check that can poison the use of this identifier.

* tools/virsh-domain-monitor.c (cmdDomIfAddr): Use ifacestr instead.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovircgroup: Fix build issue mingw cross compile
John Ferlan [Fri, 27 Mar 2015 16:36:04 +0000 (12:36 -0400)] 
vircgroup: Fix build issue mingw cross compile

Commit id '2dbfa716' exposed virCgroupDetectMountsFromFile, but did not
add the corresponding entry in the "#else /* !VIR_CGROUP_SUPPORTED */"
section of the module.

10 years agovircgroup: Fix build issue on mingw cross compile
John Ferlan [Fri, 27 Mar 2015 16:13:56 +0000 (12:13 -0400)] 
vircgroup: Fix build issue on mingw cross compile

Commit id 'ba1dfc5' added virCgroupSetCpusetMemoryMigrate and
virCgroupGetCpusetMemoryMigrate, but did not add the corresponding
entry points into the "#else /* !VIR_CGROUP_SUPPORTED */" section

10 years agotests: introduce qemucaps2xmlmock
Pavel Hrdina [Wed, 25 Mar 2015 14:35:46 +0000 (15:35 +0100)] 
tests: introduce qemucaps2xmlmock

We need to mock virFileExists to return true for "/dev/kvm" because the
test should not depend on host system.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoRevert "qemucaps2xmltest: fix test to successfully run without kvm support"
Pavel Hrdina [Wed, 25 Mar 2015 14:17:13 +0000 (15:17 +0100)] 
Revert "qemucaps2xmltest: fix test to successfully run without kvm support"

This reverts commit 49bf09d16cb7050795f6963a2746d686a2fbaece.  That
commit is wrong and doesn't fix the issue.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agovirnetlink: fix build error
Pavel Hrdina [Fri, 27 Mar 2015 10:06:05 +0000 (11:06 +0100)] 
virnetlink: fix build error

Commint 0473b45cc introduced new function virNetlinkDelLink, but in
it's counterpart for non-linux platform there should be ATTRIBUTE_UNUSED
instead of ATTRIBUTE_UNSUPPORTED.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: end the job when try to blockcopy to non-file destination
Shanzhi Yu [Fri, 27 Mar 2015 09:16:41 +0000 (17:16 +0800)] 
qemu: end the job when try to blockcopy to non-file destination

Blockcopy to non-file destination is not supported according the code,
but a 'goto endjob' is missed after checking the destination.

This leads to calling drive-mirror with wrong parameters.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1206406
Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agonodeinfo: Increase the num of CPU thread siblings to a larger value
Wei Huang [Thu, 26 Mar 2015 04:48:13 +0000 (00:48 -0400)] 
nodeinfo: Increase the num of CPU thread siblings to a larger value

Current libvirt can only handle up to 1023 bytes when it
reads Linux sysfs topology/thread_siblings. This isn't enough for
Linux distributions that support a large value. This patch fixes
the problem by using VIR_ALLOC()/VIR_FREE(), instead of using a
fixed-size (1024) local char array. In the meanwhile
SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX is increased to 8192 which
should be large enough for a foreseeable future.

Signed-off-by: Wei Huang <wei@redhat.com>
10 years agorelaxng: allow : in /dev/disk/by-path names v1.2.14-rc1
Eric Blake [Thu, 26 Mar 2015 22:48:07 +0000 (16:48 -0600)] 
relaxng: allow : in /dev/disk/by-path names

On IRC, Hydrar pointed a problem where 'virsh edit' failed on
his domain created through an ISCSI pool managed by virt-manager,
all because the XML included a block device with colons in the
name.

* docs/schemas/basictypes.rng (absFilePath): Add colon as safe.
* tests/qemuxml2argvdata/qemuxml2argv-disk-iscsi.xml: New file.
* tests/qemuxml2argvdata/qemuxml2argv-disk-iscsi.args: Likewise.
* tests/qemuxml2argvtest.c (mymain): Test it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agolibxl: Fix memory leak if pthread_create fails.
Konrad Rzeszutek Wilk [Thu, 26 Mar 2015 01:35:11 +0000 (21:35 -0400)] 
libxl: Fix memory leak if pthread_create fails.

If we fail to create the thread we leak the shutdown_info
structure.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10 years agoutil: use netlink to create bridge devices
Laine Stump [Mon, 23 Mar 2015 18:17:44 +0000 (14:17 -0400)] 
util: use netlink to create bridge devices

Just as it is possible to delete a bridge device with the netlink
RTM_DELLINK message, one can be created with the RTM_NEWLINK
message. Because of differences in the format of the message, it's not
as straightforward as with virNetlinkDelLink() to create a single
utility function that can be used to create any type of interface, so
the new netlink version of virNetDevBridgeCreate() does its own
construction of the netlink message and calls virNetlinkCommand()
itself.

This doesn't provide any extra functionality, just provides symmetry
with the previous commit.

NB: We *could* alter the API of virNetDevBridgeCreate() to take a MAC
address, and directly program that mac address into the bridge (by
adding an IFLA_ADDRESS attribute, as is done in
virNetDevMacVLanCreate()) rather than separately creating the "dummy
tap" (e.g. virbr0-nic) to maintain a fixed mac address on the bridge,
but the commit history of virnetdevbridge.c shows that the presence of
this dummy tap is essential in some older versions of the kernel
(between 2.6.39 and 3.1 or 3.2, possibly?) to proper operation of IPv6
DAD, and I don't want to take the chance of breaking something that I
don't have the time/setup to test (my RHEL6 box is at kernel
2.6.32-544, and the next lowest kernel I have is 3.17)

10 years agoutil: use netlink to delete bridge devices
Laine Stump [Tue, 17 Mar 2015 19:45:01 +0000 (15:45 -0400)] 
util: use netlink to delete bridge devices

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

reported that a stray bridge device was left on the system when a
libvirt network failed to start due to an illegal iptables rule caused
by bad config. Apparently the reason this was happening was that
NetworkManager was noticing immediately when the bridge device was
created and automatically setting it IFF_UP. libvirt would then try to
setup the iptables rules, get an error back, and since libvirt had
never IFF_UPed the bridge, it didn't expect that it needed to set it
~IFF_UP before deleting it during the cleanup process. But the
ioctl(SIOCBRDELBR) ioctl will fail to delete a bridge if it is IFF_UP.

Since that bug was reported, NetworkManager has gotten a bit more
polite in this respect, but just in case something similar happens in
the future, this patch switches to using the netlink RTM_DELLINK
message to delete the bridge - unlike SIOCBRDELBR, it will delete the
requested bridge no matter what the setting of IFF_UP.

10 years agoutil: replace body of virNetDevMacVLanDelete() with virNetlinkDelLink()
Laine Stump [Tue, 17 Mar 2015 18:42:24 +0000 (14:42 -0400)] 
util: replace body of virNetDevMacVLanDelete() with virNetlinkDelLink()

These two functions are identical, so no sense in having the
duplication. I resisted the temptation to replace calls to
virNetDevMacVLanDelete() with calls to virNetlinkDelLink() just in
case some mythical future platform has macvtap devices that aren't
managed with netlink (or in case we some day need to do more than just
tell the kernel to delete the device).

10 years agoutil: netlink function to delete any network device
Laine Stump [Tue, 17 Mar 2015 18:27:21 +0000 (14:27 -0400)] 
util: netlink function to delete any network device

libvirt has always used the netlink RTM_DELLINK message to delete
macvtap/macvlan devices, but it can actually be used to delete other
types of network devices, such as bonds and bridges. This patch makes
virNetDevMacVLanDelete() available as a generic function so it can
intelligibly be called to delete these other types of interfaces.

10 years agomaint: update to latest gnulib
Eric Blake [Tue, 24 Feb 2015 15:58:46 +0000 (08:58 -0700)] 
maint: update to latest gnulib

Usual update to latest gnulib status.  In particular this update
fixes at least one issue that can be seen in libvirt, by silencing
a valgrind detection of uninitialized memory:
https://bugzilla.redhat.com/show_bug.cgi?id=1174147

* .gnulib: Update to latest.
* bootstrap: Resync to gnulib.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoRename DomainGetIOThreadsInfo to DomainGetIOThreadInfo
Ján Tomko [Wed, 25 Mar 2015 16:02:26 +0000 (17:02 +0100)] 
Rename DomainGetIOThreadsInfo to DomainGetIOThreadInfo

While it returns info about multiple threads, the version
without the plural is easier to read.

10 years agoRename qemuMonitorIOThreadsInfo* to qemuMonitorIOThreadInfo*
Ján Tomko [Wed, 25 Mar 2015 15:59:37 +0000 (16:59 +0100)] 
Rename qemuMonitorIOThreadsInfo* to qemuMonitorIOThreadInfo*

It only deals with a single thread.

10 years agoRename virDomainIOThreadsInfoFree to virDomainIOThreadInfoFree
Ján Tomko [Wed, 25 Mar 2015 15:47:49 +0000 (16:47 +0100)] 
Rename virDomainIOThreadsInfoFree to virDomainIOThreadInfoFree

This function only frees the info for one thread.

10 years agovirsh: rename iothreadsinfo to iothreadinfo
Ján Tomko [Wed, 25 Mar 2015 16:15:04 +0000 (17:15 +0100)] 
virsh: rename iothreadsinfo to iothreadinfo

The plural seems unnecessary.

10 years agoqemu: command: Fix property name for start address of a pc-dimm module
Luyao Huang [Thu, 26 Mar 2015 06:30:56 +0000 (14:30 +0800)] 
qemu: command: Fix property name for start address of a pc-dimm module

Starting a qemu VM with a memory module that has the base address
specified results in the following error:

 error: internal error: early end of file from monitor: possible problem:
 2015-03-26T03:45:52.338891Z qemu-kvm: -device pc-dimm,node=0,memdev=memdimm0,
 id=dimm0,slot=0,base=4294967296: Property '.base' not found

The correct property name for the base address is 'addr'.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemu: Give hint about -noTSX CPU model
Jiri Denemark [Tue, 24 Mar 2015 13:12:07 +0000 (14:12 +0100)] 
qemu: Give hint about -noTSX CPU model

Because of the microcode update to Haswell/Broadwell CPUs, existing
domains using these CPUs may fail to start even though they used to run
just fine. To help users solve this issue we try to suggest switching to
-noTSX variant of the CPU model:

    virsh # start cd
    error: Failed to start domain cd
    error: unsupported configuration: guest and host CPU are not
    compatible: Host CPU does not provide required features: rtm, hle;
    try using 'Haswell-noTSX' CPU model

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agocpu: Add {Haswell,Broadwell}-noTSX CPU models
Jiri Denemark [Mon, 23 Mar 2015 16:19:28 +0000 (17:19 +0100)] 
cpu: Add {Haswell,Broadwell}-noTSX CPU models

QEMU 2.3 adds these new models to cover Haswell and Broadwell CPUs with
updated microcode. Luckily, they also reverted former the machine type
specific changes to existing models. And since these changes were never
released, we don't need to hack around them in libvirt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoqemu: command: Check for empty network source when formatting drive cmd
Peter Krempa [Tue, 24 Mar 2015 15:16:29 +0000 (16:16 +0100)] 
qemu: command: Check for empty network source when formatting drive cmd

Use the virStorageSourceIsEmpty helper to determine whether the drive
source is empty rather than checking for src->path. This will fix start
of VM with empty network cdrom that would not report any error.

10 years agoqemu: command: Report error when formatting network source with protocol _NONE
Peter Krempa [Tue, 24 Mar 2015 15:13:41 +0000 (16:13 +0100)] 
qemu: command: Report error when formatting network source with protocol _NONE

The function that formats the string for network drives would return
error code but did not set the error message when called on storage
source with VIR_STORAGE_NET_PROTOCOL_LAST or _NONE.

Report an error in this case if it would ever be called in that way.

10 years agobuild: fix race when creating the cpu_map.xml symlink
Amy Fong [Mon, 23 Mar 2015 17:44:03 +0000 (13:44 -0400)] 
build: fix race when creating the cpu_map.xml symlink

In some circumstances where the build tree differs from the source,
libvirt's compile will try to create the symlink for cpu_map.xml before
creating the directory $(abs_builddir)/cpu:

'src/cpu/cpu_map.xml': No such file or directory'

Do not create the symlink, it is no longer needed after
commit e562e82f
    Load CPU map from builddir when run uninstalled

Signed-off-by: Amy Fong <amy.fong@windriver.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agotests: qemuxml2xml: Test status XML formatting and parsing
Peter Krempa [Tue, 24 Mar 2015 12:25:27 +0000 (13:25 +0100)] 
tests: qemuxml2xml: Test status XML formatting and parsing

Recently we've fixed a bug where the status XML could not be parsed as
the parser used absolute path XPath queries. This test enhancement tests
all XML files used in the qemu-xml-2-xml test as a part of a status XML
snippet to see whether they are parsed correctly. The status XML-2-XML is
currently tested in 223 cases with this patch.

10 years agoutil: buffer: Add support for adding text blocks with indentation
Peter Krempa [Tue, 24 Mar 2015 09:53:29 +0000 (10:53 +0100)] 
util: buffer: Add support for adding text blocks with indentation

The current auto-indentation buffer code applies indentation only on
complete strings. To allow adding a string containing newlines and
having it properly indented this patch adds virBufferAddStr.

10 years agoDon't validata filesystem target type
Guido Günther [Sat, 21 Mar 2015 10:37:12 +0000 (11:37 +0100)] 
Don't validata filesystem target type

When using QEMU's 9pfs the target "dir" element is not necessarily an
absolute path but merely an arbitrary identifier. So validation in that
case currently fails with the misleading

   $ virt-xml-validate /tmp/test.xml
   Relax-NG validity error : Extra element devices in interleave
   /tmp/test.xml:24: element devices: Relax-NG validity error : Element domain failed to validate content
   /tmp/test.xml fails to validate

10 years agorpc: Don't unref identity object while callbacks still can be executed
Peter Krempa [Wed, 25 Mar 2015 07:56:07 +0000 (08:56 +0100)] 
rpc: Don't unref identity object while callbacks still can be executed

While this thread is cleaning up the client and connection objects:
 #2  virFileReadAll (path=0x7f28780012b0 "/proc/1319/stat", maxlen=maxlen@entry=1024, buf=buf@entry=0x7f289c60fc40) at util/virfile.c:1287
 #3  0x00007f28adbb1539 in virProcessGetStartTime (pid=<optimized out>, timestamp=timestamp@entry=0x7f289c60fc98) at util/virprocess.c:838
 #4  0x00007f28adb91981 in virIdentityGetSystem () at util/viridentity.c:151
 #5  0x00007f28ae73f17c in remoteClientFreeFunc (data=<optimized out>) at remote.c:1131
 #6  0x00007f28adcb7f33 in virNetServerClientDispose (obj=0x7f28aecad180) at rpc/virnetserverclient.c:858
 #7  0x00007f28adba8eeb in virObjectUnref (anyobj=<optimized out>) at util/virobject.c:265
 #8  0x00007f28ae74ad05 in virNetServerHandleJob (jobOpaque=<optimized out>, opaque=0x7f28aec93ff0) at rpc/virnetserver.c:205
 #9  0x00007f28adbbef4e in virThreadPoolWorker (opaque=opaque@entry=0x7f28aec88030) at util/virthreadpool.c:145

In stack frame #6 the client->identity object got unref'd, but the code
that removes the event callbacks in frame #5 did not run yet as we are
trying to obtain the system identity (frames #4, #3, #2).

In other thead:
 #0  virObjectUnref (anyobj=anyobj@entry=0x7f288c162c60) at util/virobject.c:264
        klass = 0xdeadbeef
        obj = 0x7f288c162c60
 #1  0x00007f28ae71c709 in remoteRelayDomainEventCheckACL (client=<optimized out>, conn=<optimized out>, dom=dom@entry=0x7f28aecaafc0) at remote.c:164
 #2  0x00007f28ae71fc83 in remoteRelayDomainEventTrayChange (conn=<optimized out>, dom=0x7f28aecaafc0, ... ) at remote.c:717
 #3  0x00007f28adc04e53 in virDomainEventDispatchDefaultFunc (conn=0x7f287c0009a0, event=0x7f28aecab1a0, ...) at conf/domain_event.c:1455
 #4  0x00007f28adc03831 in virObjectEventStateDispatchCallbacks (callbacks=<optimized out>, ....) at conf/object_event.c:724
 #5  virObjectEventStateQueueDispatch (callbacks=0x7f288c083730, queue=0x7fff51f90030, state=0x7f288c18da20) at conf/object_event.c:738
 #6  virObjectEventStateFlush (state=0x7f288c18da20) at conf/object_event.c:816
 #7  virObjectEventTimer (timer=<optimized out>, opaque=0x7f288c18da20) at conf/object_event.c:562
 #8  0x00007f28adb859cd in virEventPollDispatchTimeouts () at util/vireventpoll.c:459

Frame #0 is unrefing an invalid identity object while frame #2 hints
that the client is still dispatching the event.

For untrimmed backtrace see the bugzilla attachment.

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

10 years agodaemon: Clear fake domain def object that is used to check ACL prior to use
Peter Krempa [Wed, 25 Mar 2015 07:52:26 +0000 (08:52 +0100)] 
daemon: Clear fake domain def object that is used to check ACL prior to use

The fake object is used to pass the domain name and UUID to the ACL code
for events where we don't have the full domain def when dispatching
events. The rest of the entries would be left uninitialized. While this
is not a problem code-wise as the used fields are initialized it looks
ugly in the debugger.

10 years agoutil: identity: Harden virIdentitySetCurrent()
Peter Krempa [Wed, 25 Mar 2015 07:25:45 +0000 (08:25 +0100)] 
util: identity: Harden virIdentitySetCurrent()

Don't unref the old identity unless we set the new one correctly and
unref the new one on failure to set it so that we don't leak any
references or use invalid pointers.

10 years agotests: qemuxml2xml: Refactor the qemuxml2xml test
Peter Krempa [Mon, 23 Mar 2015 16:24:43 +0000 (17:24 +0100)] 
tests: qemuxml2xml: Refactor the qemuxml2xml test

To allow adding more tests, refactor the XML-2-XML test so that the
files are not reloaded always and clarify the control flow.

Result of this changes is that the active and inactive portions of the
XML are tested in separate steps rather than one test step.

10 years agoqemu: domain: Don't leak device alias list
Peter Krempa [Tue, 24 Mar 2015 13:52:11 +0000 (14:52 +0100)] 
qemu: domain: Don't leak device alias list

While adding tests for status XML parsing and formatting I've noticed
that the device alias list is leaked.

==763001== 81 (48 direct, 33 indirect) bytes in 1 blocks are definitely lost in loss record 414 of 514
==763001==    at 0x4C2B8F0: calloc (vg_replace_malloc.c:623)
==763001==    by 0x6ACF70F: virAllocN (viralloc.c:191)
==763001==    by 0x447B64: qemuDomainObjPrivateXMLParse (qemu_domain.c:727)
==763001==    by 0x6B848F9: virDomainObjParseXML (domain_conf.c:15491)
==763001==    by 0x6B84CAC: virDomainObjParseNode (domain_conf.c:15608)

10 years agoqemucaps2xmltest: fix test to successfully run without kvm support
Pavel Hrdina [Wed, 25 Mar 2015 09:40:57 +0000 (10:40 +0100)] 
qemucaps2xmltest: fix test to successfully run without kvm support

Function virQEMUCapsInitGuestFromBinary detect kvm support by testing
whether /dev/kvm exists or whether we pass path to kvmbin.  Provide the
path we are testing via kvmbin for testing purpose instead of detecting
presence of /dev/kvm to successfully run the tests on all hosts.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: Report better error when memory device source has wrong NUMA node
Luyao Huang [Wed, 25 Mar 2015 06:34:04 +0000 (14:34 +0800)] 
qemu: Report better error when memory device source has wrong NUMA node

When starting a VM with hotpluggable memory devices the user may specify
an invalid source NUMA node. Libvirt would pass through the error from
qemu:

 # virsh start test3
 error: Failed to start domain test3
 error: internal error: process exited while connecting to monitor:
 2015-03-25T01:12:17.205913Z qemu-kvm: -object memory-backend-ram,id=memdimm0
 ,size=536870912,host-nodes=1-3,policy=bind: cannot bind memory to host NUMA nodes:
 Invalid argument

This patch adds a check that allows to report better error:

 # virsh start test3
 error: Failed to start domain test3
 error: configuration unsupported: NUMA node 1 is unavailable

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoutil: NUMA: Change error code in virNumaNodesetIsAvailable()
Peter Krempa [Wed, 25 Mar 2015 09:05:58 +0000 (10:05 +0100)] 
util: NUMA: Change error code in virNumaNodesetIsAvailable()

An invalid nodeset is a configuration problem rather than an internal
error.

10 years agoconf: Add missing apostrophe to error message
Luyao Huang [Tue, 24 Mar 2015 14:12:37 +0000 (22:12 +0800)] 
conf: Add missing apostrophe to error message

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoMakefile: fix typo
Pavel Hrdina [Wed, 25 Mar 2015 10:30:38 +0000 (11:30 +0100)] 
Makefile: fix typo

Commit 95695388 introduced new util/virthreadjob.c/h files but the
makefile has type that breaks rpm build.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agodocs: route element must specify network address
Chen Fan [Wed, 25 Mar 2015 03:48:04 +0000 (11:48 +0800)] 
docs: route element must specify network address

because network address is required by route, so
here we should add one avoid user misunderstand.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
10 years agodocs: no 'via' attribute in route element
Chen Fan [Wed, 25 Mar 2015 03:48:03 +0000 (11:48 +0800)] 
docs: no 'via' attribute in route element

via -> gateway

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
10 years agoqemu: Add timing to domain jobs
Jiri Denemark [Mon, 23 Mar 2015 11:46:45 +0000 (12:46 +0100)] 
qemu: Add timing to domain jobs

Whenever we fail to acquire a job, we can report how long ago it was
locked by another API.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoqemu: Track the API which started the current job
Jiri Denemark [Mon, 16 Mar 2015 17:18:46 +0000 (18:18 +0100)] 
qemu: Track the API which started the current job

This is very helpful when we want to log and report why we could not
acquire a state change lock. Reporting what job keeps it locked helps
with understanding the issue. Moreover, after calling
virDomainGetControlInfo, it's possible to tell whether libvirt is just
stuck somewhere within the API (or it just forgot to cleanup the job) or
whether libvirt is waiting for QEMU to reply.

The error message will look like the following:

    # virsh resume cd
    error: Failed to resume domain cd
    error: Timed out during operation: cannot acquire state change lock
    (held by remoteDispatchDomainSuspend)

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoSet thread job for every RPC call
Jiri Denemark [Wed, 11 Mar 2015 12:58:42 +0000 (13:58 +0100)] 
Set thread job for every RPC call

Since all APIs are also RPC calls, we automatically get all APIs covered
with thread jobs.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agovirThreadPool: Set thread worker name
Jiri Denemark [Fri, 20 Mar 2015 16:44:25 +0000 (17:44 +0100)] 
virThreadPool: Set thread worker name

Every thread created as a worker thread within a pool gets a name
according to virThreadPoolJobFunc name.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agovirThread: Set thread job
Jiri Denemark [Fri, 20 Mar 2015 16:43:55 +0000 (17:43 +0100)] 
virThread: Set thread job

Automatically assign a job to every thread created by virThreadCreate.
The name of the virThreadFunc function passed to virThreadCreate is used
as the job or worker name in case no name is explicitly passed.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoForce usage of virThreadCreate
Jiri Denemark [Fri, 20 Mar 2015 15:25:15 +0000 (16:25 +0100)] 
Force usage of virThreadCreate

We want all threads to be set as workers or to have a job assigned to
them, which can easily be achieved in virThreadCreate wrapper to
pthread_create. Let's make sure we always use the wrapper.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoAdd support for tracking thread jobs
Jiri Denemark [Mon, 8 Jul 2013 10:27:34 +0000 (12:27 +0200)] 
Add support for tracking thread jobs

Each thread can use a thread local variable to keep the name of a job
which is currently running in the job.

The virThreadJobSetWorker API is supposed to be called once by any
thread which is used as a worker, i.e., it is waiting in a pool, woken
up to do a job, and returned back to the pool.

The virThreadJobSet/virThreadJobClear APIs are to be called at the
beginning/end of each job.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoPOTFILES.in: Sort
Jiri Denemark [Wed, 11 Mar 2015 09:24:09 +0000 (10:24 +0100)] 
POTFILES.in: Sort

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoDocument that USB hostdevs do not need nodeDettach
Ján Tomko [Fri, 20 Mar 2015 09:25:13 +0000 (10:25 +0100)] 
Document that USB hostdevs do not need nodeDettach

The virNodeDeviceDettach API only works on PCI devices.

Originally added by commit 10d3272e, but the API never
supported USB devices.

Reported by: Martin Polednik <mpolednik@redhat.com>

10 years agorpc: serverclient: Clear pointer with NULL instead of 0
Peter Krempa [Wed, 25 Mar 2015 07:11:12 +0000 (08:11 +0100)] 
rpc: serverclient: Clear pointer with NULL instead of 0

10 years agolibxl: remove per-domain libxl_ctx
Jim Fehlig [Wed, 11 Feb 2015 23:40:07 +0000 (16:40 -0700)] 
libxl: remove per-domain libxl_ctx

Although needed in the Xen 4.1 libxl days, there is no longer any
benefit to having per-domain libxl_ctx.  On the contrary, their use
makes the code unecessarily complicated and prone to deadlocks under
load.  As suggested by the libxl maintainers, use a single libxl_ctx
as a handle to libxl instead of per-domain ctx's.

One downside to using a single libxl_ctx is there are no longer
per-domain log files for log messages emitted by libxl.  Messages
for all domains will be sent to /var/log/libvirt/libxl/libxl-driver.log.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: make libxlDomainFreeMem static
Jim Fehlig [Wed, 11 Feb 2015 21:47:42 +0000 (14:47 -0700)] 
libxl: make libxlDomainFreeMem static

libxlDomainFreeMem() is only used in libxl_domain.c and thus should
be declared static.  While at it, change the signature to take a
libxl_ctx instead of libxlDomainObjPrivatePtr, since only the
libxl_ctx is needed.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: remove unnecessary libxlDomainEventsRegister
Jim Fehlig [Thu, 12 Feb 2015 19:02:27 +0000 (12:02 -0700)] 
libxl: remove unnecessary libxlDomainEventsRegister

This function now only enables domain death events.  Simply call
libxl_evenable_domain_death() instead of an unnecessary wrapper.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: use global libxl_ctx in event handler
Jim Fehlig [Wed, 11 Feb 2015 22:22:05 +0000 (15:22 -0700)] 
libxl: use global libxl_ctx in event handler

Change the domain event handler code to use the driver-wide
libxl_ctx instead of the domain-specific one.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: move event registration to driver initialization
Jim Fehlig [Thu, 12 Feb 2015 18:37:46 +0000 (11:37 -0700)] 
libxl: move event registration to driver initialization

Register a domain event handler with the driver-wide libxl_ctx
during driver initialization.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: Move setup of child processing code to driver initialization
Jim Fehlig [Mon, 2 Feb 2015 23:19:34 +0000 (16:19 -0700)] 
libxl: Move setup of child processing code to driver initialization

Informing libxl how to handle its child proceses should be done once
during driver initialization, not once for each domain-specific
libxl_ctx object.  The related libxl documentation in
$xen-src/tools/libxl/libxl_event.h even mentions that "it is best to
call this at initialisation".

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: use driver-wide ctx in fd and timer event handling
Jim Fehlig [Mon, 2 Feb 2015 21:12:58 +0000 (14:12 -0700)] 
libxl: use driver-wide ctx in fd and timer event handling

Long ago I incorrectly associated libxl fd and timer registrations
with per-domain libxl_ctx objects.  When creating a libxlDomainObjPrivate,
a libxl_ctx is allocated, and libxl_osevent_register_hooks is called
passing a pointer to the libxlDomainObjPrivate.  When an fd or timer
registration occurred, the registration callback received the
libxlDomainObjPrivate, containing the per-domain libxl_ctx.  This
libxl_ctx was then used when informing libxl about fd events or
timer expirations.

The problem with this approach is that fd and timer registrations do not
share the same lifespan as libxlDomainObjPrivate, and hence the per-domain
libxl_ctx ojects.  The result is races between per-domain libxl_ctx's being
destoryed and events firing on associated fds/timers, typically manifesting
as an assert in libxl

libxl_internal.h:2788: libxl__ctx_unlock: Assertion `!r' failed

There is no need to associate libxlDomainObjPrivate objects with libxl's
desire to use libvirt's event loop.  Instead, the driver-wide libxl_ctx can
be used for the fd and timer registrations.

This patch moves the fd and timer handling code away from the
domain-specific code in libxl_domain.c into libxl_driver.c.  While at it,
function names were changed a bit to better describe their purpose.

The unnecessary locking was also removed since the code simply provides a
wrapper over the event loop interface.  Indeed the locks may have been
causing some deadlocks when repeatedly creating/destroying muliple domains.
There have also been rumors about such deadlocks during parallel OpenStack
Tempest runs.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agoqemu: fix set vcpus on host without NUMA
Pavel Hrdina [Fri, 20 Mar 2015 14:01:53 +0000 (15:01 +0100)] 
qemu: fix set vcpus on host without NUMA

We don't have to modify cpuset.mems on hosts without NUMA.  It also
fixes an error message that you get instead of success if you trying
update vcpus of a guest on a host without NUMA.

error: internal error: NUMA isn't available on this host

Signer-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: cleanup setvcpus
Pavel Hrdina [Tue, 24 Mar 2015 17:22:27 +0000 (18:22 +0100)] 
qemu: cleanup setvcpus

Remove unnecessary maximum variable.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: move virDomainLiveConfigHelperMethod right after BeginJob
Pavel Hrdina [Tue, 24 Mar 2015 17:14:12 +0000 (18:14 +0100)] 
qemu: move virDomainLiveConfigHelperMethod right after BeginJob

We should call virDomainLiveConfigHelperMethod ASAP because this
function transfers VIR_DOMAIN_AFFECT_CURRENT to VIR_DOMAIN_AFFECT_LIVE
or VIR_DOMAIN_AFFECT_CONFIG.  All other additional checks for those two
flags should consider that the user give us VIR_DOMAIN_AFFECT_CURRENT.

Remove the unnecessary check whether the domain is live in case of
VIR_DOMAIN_VCPU_GUEST because this check is done by
virDomainLiveConfigHelperMethod.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoDocument behavior of compat when creating qcow2 volumes
Ján Tomko [Tue, 24 Mar 2015 16:13:24 +0000 (17:13 +0100)] 
Document behavior of compat when creating qcow2 volumes

Commit bab2eda changed the behavior for missing compat attribute,
but failed to update the documentation.

Before, the option was omitted from qemu-img command line and the
qemu-img default was used. Now we always specify the compat value
and the default is 0.10.

Reported by Christophe Fergeau
https://bugzilla.gnome.org/show_bug.cgi?id=746660#c4

10 years agoFix typo in error message
Ján Tomko [Mon, 16 Mar 2015 14:55:21 +0000 (15:55 +0100)] 
Fix typo in error message

by rewriting it completely from:
error: unsupported configuration: virtio only support device address
type 'PCI'

to:

error: unsupported configuration: virtio disk cannot have an address of type
drive

Since we now support CCW addresses as well.

10 years agoqemu: change accidental VIR_WARNING back to VIR_DEBUG
Laine Stump [Tue, 24 Mar 2015 14:45:09 +0000 (10:45 -0400)] 
qemu: change accidental VIR_WARNING back to VIR_DEBUG

While debugging the support for responding to qemu RX_FILTER_CHANGED
events, I had changed the "ignoring this event" log message from
VIR_DEBUG to VIR_WARN, but forgot to change it back before
pushing. Since many guest OSes make enough changes to multicast lists
and/or promiscuous mode settings to trigger this message, it's
starting to show up as a red herring in bug reports.

10 years agoqemucaps2xmltest: fix the test to correspond to new domain formatting
Pavel Hrdina [Tue, 24 Mar 2015 14:22:16 +0000 (15:22 +0100)] 
qemucaps2xmltest: fix the test to correspond to new domain formatting

Commit 2360fe5d updated formating of <domain> element but forgot to
update qemucaps2xmldata xml files.  In addition the test code was broken
too.  Update the xml files and return -1 if testCompareXMLToXML fails
together with indentation fix.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoconf: fix parsing of NUMA settings in VM status XML
Luyao Huang [Thu, 19 Mar 2015 10:13:04 +0000 (18:13 +0800)] 
conf: fix parsing of NUMA settings in VM status XML

Commit 5bba61f changed the XPath strings to be absolute when parsing
the VM NUMA configuration. Unfortunately the <domain> element is not a
top level element when parsing the domain status XML thus the absolute
XPath string doesn't match.

Use the relative string so that the <numa> settings are not lost.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemu: Implement memory device hotunplug
Peter Krempa [Wed, 21 Jan 2015 16:45:54 +0000 (17:45 +0100)] 
qemu: Implement memory device hotunplug

Add code to hot-remove memory devices from qemu. Unfortunately QEMU
doesn't support this right now, so this is just for completenes.

10 years agoqemu: Implement memory device hotplug
Peter Krempa [Sun, 12 Oct 2014 22:28:58 +0000 (00:28 +0200)] 
qemu: Implement memory device hotplug

Add code to hot-add memory devices to running qemu instances.

10 years agoqemu: conf: Add support for memory device cold(un)plug
Peter Krempa [Wed, 21 Jan 2015 14:49:44 +0000 (15:49 +0100)] 
qemu: conf: Add support for memory device cold(un)plug

Add a few helpers that allow to operate with memory device definitions
on the domain config and use them to implement memory device coldplug in
the qemu driver.

10 years agoqemu: add support for memory devices
Peter Krempa [Fri, 9 Jan 2015 09:40:37 +0000 (10:40 +0100)] 
qemu: add support for memory devices

Add support to start qemu instance with 'pc-dimm' device. Thanks to the
refactors we are able to reuse the existing function to determine the
parameters.

10 years agoqemu: migration: Forbid migration with memory modules lacking info
Peter Krempa [Mon, 19 Jan 2015 13:28:14 +0000 (14:28 +0100)] 
qemu: migration: Forbid migration with memory modules lacking info

Make sure that libvirt has all vital information needed to reliably
represent configuration of guest's memory devices in case of a
migration.

This patch forbids migration in case the required slot number and module
base address are not present (failed to be loaded from qemu via
monitor).

10 years agoqemu: memdev: Add infrastructure to load memory device information
Peter Krempa [Mon, 19 Jan 2015 12:21:09 +0000 (13:21 +0100)] 
qemu: memdev: Add infrastructure to load memory device information

When using 'dimm' memory devices with qemu, some of the information
like the slot number and base address need to be reloaded from qemu
after process start so that it reflects the actual state. The state then
allows to use memory devices across migrations.

10 years agoconf: Add interface to parse and format memory device information
Peter Krempa [Mon, 29 Sep 2014 17:02:04 +0000 (19:02 +0200)] 
conf: Add interface to parse and format memory device information

This patch adds code that parses and formats configuration for memory
devices.

A simple configuration would be:
<memory model='dimm'>
  <target>
    <size unit='KiB'>524287</size>
    <node>0</node>
  </target>
</memory>

A complete configuration of a memory device:
<memory model='dimm'>
  <source>
    <pagesize unit='KiB'>4096</pagesize>
    <nodemask>1-3</nodemask>
  </source>
  <target>
    <size unit='KiB'>524287</size>
    <node>1</node>
  </target>
</memory>

This patch preemptively forbids use of the <memory> device in individual
drivers so the users are warned right away that the device is not
supported.

10 years agoconf: Add device address type for dimm devices
Peter Krempa [Tue, 7 Oct 2014 16:11:47 +0000 (18:11 +0200)] 
conf: Add device address type for dimm devices

Dimm devices are described by the slot and base address. Add a new
address type to be able to describe such address.

10 years agoqemu: Implement setup of memory hotplug parameters
Peter Krempa [Mon, 6 Oct 2014 12:18:37 +0000 (14:18 +0200)] 
qemu: Implement setup of memory hotplug parameters

To enable memory hotplug the maximum memory size and slot count need to
be specified. As qemu supports now other units than mebibytes when
specifying memory, use the new interface in this case.

10 years agoconf: Add support for parsing and formatting max memory and slot count
Peter Krempa [Mon, 11 Aug 2014 15:40:32 +0000 (17:40 +0200)] 
conf: Add support for parsing and formatting max memory and slot count

Add a XML element that will allow to specify maximum supportable memory
and the count of memory slots to use with memory hotplug.

To avoid possible confusion and misuse of the new element this patch
also explicitly forbids the use of the maxMemory setting in individual
drivers's post parse callbacks. This limitation will be lifted when the
support is implemented.

10 years agolibxl: Refactor logic in domain post parse callback
Peter Krempa [Mon, 16 Mar 2015 14:33:45 +0000 (15:33 +0100)] 
libxl: Refactor logic in domain post parse callback

With the current control flow the post parse callback returned success
right away for fully virtualized VMs. To allow adding additional checks
into the post parse callback tweak the conditions so that the function
doesn't return early except for error cases.

To clarify the original piece of code borrow the wording from the commit
message for the patch that introduced the code.

10 years agoqemu: monitor: Don't leak @props with non-JSON in qemuMonitorAddObject
Peter Krempa [Mon, 16 Mar 2015 14:25:58 +0000 (15:25 +0100)] 
qemu: monitor: Don't leak @props with non-JSON in qemuMonitorAddObject

The function comment states that @props is always consumed, even on
failure. This was not true with the failure if the monitor is not using
QMP.

10 years agoqemu: Don't return memory device config on error in qemuBuildMemoryBackendStr
Peter Krempa [Mon, 23 Mar 2015 13:17:42 +0000 (14:17 +0100)] 
qemu: Don't return memory device config on error in qemuBuildMemoryBackendStr

In the last section if the function determines that the config is
invalid when QEMU doesn't support the memory device the JSON config
object would be returned even if it doesn't make sense.

Assign the object to be returned only on success.

10 years agoqemu: Set default SCSI controller model for S390 arch
Boris Fiuczynski [Fri, 20 Mar 2015 15:01:10 +0000 (16:01 +0100)] 
qemu: Set default SCSI controller model for S390 arch

When no model is specified in the domain definition for
a scsi controller and the architectur is s390 than virtio-scsi
is set as default model.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Daniel Hansel <daniel.hansel@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>