]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
6 years agoapi: disallow virConnectGetDomainCapabilities on read-only connections v3.2-maint
Ján Tomko [Fri, 14 Jun 2019 07:16:14 +0000 (09:16 +0200)] 
api: disallow virConnectGetDomainCapabilities on read-only connections

This API can be used to execute arbitrary emulators.
Forbid it on read-only connections.

Fixes: CVE-2019-10167
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 8afa68bac0cf99d1f8aaa6566685c43c22622f26)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoapi: disallow virDomainSaveImageGetXMLDesc on read-only connections
Ján Tomko [Fri, 14 Jun 2019 06:47:42 +0000 (08:47 +0200)] 
api: disallow virDomainSaveImageGetXMLDesc on read-only connections

The virDomainSaveImageGetXMLDesc API is taking a path parameter,
which can point to any path on the system. This file will then be
read and parsed by libvirtd running with root privileges.

Forbid it on read-only connections.

Fixes: CVE-2019-10161
Reported-by: Matthias Gerstner <mgerstner@suse.de>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit aed6a032cead4386472afb24b16196579e239580)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Conflicts:
  src/libvirt-domain.c
  src/remote/remote_protocol.x

Upstream commit 12a51f372 which introduced the VIR_DOMAIN_SAVE_IMAGE_XML_SECURE
alias for VIR_DOMAIN_XML_SECURE is not backported.
Just skip the commit since we now disallow the whole API on read-only
connections, regardless of the flag.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
7 years agovbox: fix SEGV during dumpxml of a serial port
Laine Stump [Sun, 21 Jan 2018 02:11:05 +0000 (21:11 -0500)] 
vbox: fix SEGV during dumpxml of a serial port

commit 77a12987a48 changed the "virDomainChrSourceDef source" inside
virDomainChrDef to "virDomainChrSourceDefPtr source", and started
allocating source inside virDomainChrDefNew(), but vboxDumpSerial()
was allocating a virDomainChrDef with a simple VIR_ALLOC() (i.e. never
calling virDomainChrDefNew()), so source was never initialized,
leading to a SEGV any time a serial port was present. The same problem
was created in vboxDumpParallel().

This patch changes vboxDumpSerial() and vboxDumpParallel() to use
virDomainChrDefNew() instead of VIR_ALLOC(), and changes both of those
functions to return an error if virDomainChrDef() (or any other
allocation) fails.

This resolves: https://bugzilla.redhat.com/1536649

(cherry picked from commit 9c27e464e3b4603cbe13c00787f4c89e5b1e7a68)

7 years agoqemu: ensure TLS clients always verify the server certificate
Daniel P. Berrange [Thu, 5 Oct 2017 16:54:28 +0000 (17:54 +0100)] 
qemu: ensure TLS clients always verify the server certificate

The default_tls_x509_verify (and related) parameters in qemu.conf
control whether the QEMU TLS servers request & verify certificates
from clients. This works as a simple access control system for
servers by requiring the CA to issue certs to permitted clients.
This use of client certificates is disabled by default, since it
requires extra work to issue client certificates.

Unfortunately the code was using this configuration parameter when
setting up both TLS clients and servers in QEMU. The result was that
TLS clients for character devices and disk devices had verification
turned off, meaning they would ignore errors while validating the
server certificate.

This allows for trivial MITM attacks between client and server,
as any certificate returned by the attacker will be accepted by
the client.

This is assigned CVE-2017-1000256  / LSN-2017-0002

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 441d3eb6d1be940a67ce45a286602a967601b157)

7 years agotpm: Use /dev/null for cancel path if none was found
Stefan Berger [Thu, 29 Jun 2017 18:01:11 +0000 (14:01 -0400)] 
tpm: Use /dev/null for cancel path if none was found

TPM 2 does not implement sysfs files for cancellation of commands.
We therefore use /dev/null for the cancel path passed to QEMU.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Tested-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit dfbb15b75433e520fb1b905c1c3e28753e53e4a5)

7 years agoqemuDomainBuildNamespace: Move /dev/* mountpoints later
Michal Privoznik [Thu, 27 Apr 2017 14:29:21 +0000 (16:29 +0200)] 
qemuDomainBuildNamespace: Move /dev/* mountpoints later

When setting up mount namespace for a qemu domain the following
steps are executed:

1) get list of mountpoints under /dev/
2) move them to /var/run/libvirt/qemu/$domName.ext
3) start constructing new device tree under /var/run/libvirt/qemu/$domName.dev
4) move the mountpoint of the new device tree to /dev
5) restore original mountpoints from step 2)

Note the problem with this approach is that if some device in step
3) requires access to a mountpoint from step 2) it will fail as
the mountpoint is not there anymore. For instance consider the
following domain disk configuration:

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/dev/shm/vhostmd0'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>

In this case operation fails as we are unable to create vhostmd0
in the new device tree because after step 2) there is no /dev/shm
anymore. Leave aside fact that we shouldn't try to create devices
living in other mountpoints. That's a separate bug that will be
addressed later.

Currently, the order described above is rearranged to:

1) get list of mountpoints under /dev/
2) start constructing new device tree under /var/run/libvirt/qemu/$domName.dev
3) move them to /var/run/libvirt/qemu/$domName.ext
4) move the mountpoint of the new device tree to /dev
5) restore original mountpoints from step 3)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cedric Bosdonnat <cbosdonnat@suse.com>
(cherry picked from commit a7cc039dc796f541793955598377807af48341fb)

7 years agodocs: schema: make disk driver name attribute optional
Jim Fehlig [Tue, 18 Jul 2017 16:20:35 +0000 (10:20 -0600)] 
docs: schema: make disk driver name attribute optional

/domain/devices/disk/driver/@name is not a required or mandatory
attribute according to formatdomain, and indeed it was agreed on
IRC that the attribute is "optional for input, recommended (but
not required) for output". Currently the schema requires the
attribute, causing virt-xml-validate to fail on disk config where
the driver name is not explicitly specified. E.g.

# cat test.xml | grep -A 5 cdrom
    <disk type='file' device='cdrom'>
      <driver type='raw'/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>

# virt-xml-validate test.xml
Relax-NG validity error : Extra element devices in interleave
test.xml:21: element devices: Relax-NG validity error : Element domain failed to validate content
test.xml fails to validate

Relaxing the name attribute to be optional fixes the validation

# virt-xml-validate test.xml
test.xml validates

(cherry picked from commit b494e09d058f09b48d0fd8855edd557101294671)

7 years agoAvoid hidden cgroup mount points
Juan Hernandez [Thu, 6 Jul 2017 15:03:31 +0000 (17:03 +0200)] 
Avoid hidden cgroup mount points

Currently the scan of the /proc/mounts file used to find cgroup mount
points doesn't take into account that mount points may hidden by other
mount points. For, example in certain Kubernetes environments the
/proc/mounts contains the following lines:

  cgroup /sys/fs/cgroup/net_prio,net_cls cgroup ...
  tmpfs /sys/fs/cgroup tmpfs ...
  cgroup /sys/fs/cgroup/net_cls,net_prio cgroup ...

In this particular environment the first mount point is hidden by the
second one. The correct mount point is the third one, but libvirt will
never process it because it only checks the first mount point for each
controller (net_cls in this case). So libvirt will try to use the first
mount point, which doesn't actually exist, and the complete detection
process will fail.

To avoid that issue this patch changes the virCgroupDetectMountsFromFile
function so that when there are duplicates it takes the information from
the last line in /proc/mounts. This requires removing the previous
explicit condition to skip duplicates, and adding code to free the
memory used by the processing of duplicated lines.

Related-To: https://bugzilla.redhat.com/1468214
Related-To: https://github.com/kubevirt/libvirt/issues/4
Signed-off-by: Juan Hernandez <jhernand@redhat.com>
(cherry picked from commit dacd160d7479e0ec2d8a63f102145fd30636a1c8)

8 years agoqemuDomainChangeNet: Forbid changing MTU
Michal Privoznik [Thu, 8 Jun 2017 11:45:31 +0000 (13:45 +0200)] 
qemuDomainChangeNet: Forbid changing MTU

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

Currently, any attempt to change MTU on an interface that is
plugged to a running domain is silently ignored. We should either
do what's asked or error out. Well, we can update the host side
of the interface, but we cannot change 'host_mtu' attribute for
the virtio-net device. Therefore we have to error out.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
(cherry picked from commit 5f44d7e357f61f7be636a0e2e6d35453cbc3b589)

8 years agoqemu: Set iface MTU on hotplug
Michal Privoznik [Thu, 8 Jun 2017 08:14:36 +0000 (10:14 +0200)] 
qemu: Set iface MTU on hotplug

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

While implementing MTU (572eda12ad and friends), I've forgotten
to actually set MTU on the host NIC in case of hotplug. We
correctly tell qemu on the monitor what the MTU should be, but we
are not actually setting it on the host NIC.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
(cherry picked from commit f00e6f8bc9081f158b7d6a1dcfa82218b1dbfb4d)

8 years agoRevert "qemu: propagate bridge MTU into qemu "host_mtu" option"
Laine Stump [Thu, 18 May 2017 18:16:27 +0000 (14:16 -0400)] 
Revert "qemu: propagate bridge MTU into qemu "host_mtu" option"

This reverts commit 2841e675.

It turns out that adding the host_mtu field to the PCI capabilities in
the guest bumps the length of PCI capabilities beyond the 32 byte
boundary, so the virtio-net device gets 64 bytes of ioport space
instead of 32, which offsets the address of all the other following
devices. Migration doesn't work very well when the location and length
of PCI capabilities of devices is changed between source and
destination.

This means that we need to make sure that the absence/presence of
host_mtu on the qemu commandline always matches between source and
destination, which means that we need to make setting of host_mtu an
opt-in thing (it can't happen automatically when the bridge being used
has a non-default MTU, which is what commit 2841e675 implemented).

I do want to re-implement this feature with an <mtu auto='on'/>
setting, but probably won't backport that to any stable branches, so
I'm first reverting the original commit, and that revert can be pushed
to the few releases that have been made since the original (3.1.0 -
3.3.0)

Resolves: https://bugzilla.redhat.com/1449346
(cherry picked from commit 77780a29edace958a1f931d3281b962be4f5290e)

8 years agoDo not release unreserved address in qemuDomainAttachRNGDevice
Ján Tomko [Fri, 19 May 2017 12:14:32 +0000 (14:14 +0200)] 
Do not release unreserved address in qemuDomainAttachRNGDevice

Only set releaseaddr to true after the address has been
reserved successfully.

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit f25f30aff548636d0c8782d3eaee049c77548dd5)

8 years agoPrep for release 3.2.1 v3.2.1
Cole Robinson [Wed, 10 May 2017 22:37:26 +0000 (18:37 -0400)] 
Prep for release 3.2.1

8 years agospec: Update version check for maint Source URL
Cole Robinson [Fri, 5 May 2017 00:08:55 +0000 (20:08 -0400)] 
spec: Update version check for maint Source URL

New maint release version numbers of just A.B.C format, not the old
A.B.C.D format. Adjust the check that dynamically changes the Source
URL for maint releases

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Andrea Bolognani <abologna@redhat.com>
(cherry picked from commit 1d07a5bf3c03309642068d20698a1f55739dafa2)

8 years agomdev: Cleanup code after commits @daf5081b and @2739a983
Erik Skultety [Thu, 4 May 2017 13:36:37 +0000 (15:36 +0200)] 
mdev: Cleanup code after commits @daf5081b and @2739a983

So, because mingw is somehow OK with dereferencing a pointer within a
VIR_DEBUG macro, compared to outside of it to which it complained with a
"potential NULL pointer dereference" error (still a false positive), we
can make the code a tiny bit cleaner.

Sighed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
(cherry picked from commit 8fc72e1c72a930fb8e9fa11f18d8c38ec9b31a31)

8 years agoDon't use ceph-devel on Fedora
Daniel P. Berrange [Mon, 8 May 2017 09:54:08 +0000 (10:54 +0100)] 
Don't use ceph-devel on Fedora

A previous commit changed the spec to use librbd1-devel on
RHEL-7, since this replaces ceph-devel from RHEL-6:

  commit 6cfc8834c858849cc74c3082078dc91fb1cbae38
  Author: Peter Krempa <pkrempa@redhat.com>
  Date:   Thu Mar 5 11:40:54 2015 +0100

    spec: Enable RBD storage driver in RHEL-7

    Use correct package names too as they differ.

RHEL-7 inherited this rename from Fedora though, so it should
have also made Fedora use the new names.

This was missed, because Fedora still provides a (deprecated)
back-compat RPM for ceph-devel that just pulls in librbd1-devel
(and others).

Fixing this stops libvirt pulling Java into the build root in
Fedora.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 472759407870678e629ba40759a24ea350f1874f)

8 years agomdev: Fix mingw build by adding a check for non-NULL pointer
Erik Skultety [Thu, 4 May 2017 09:26:10 +0000 (11:26 +0200)] 
mdev: Fix mingw build by adding a check for non-NULL pointer

This patch fixes the following MinGW error (although actually being a
false positive):

../../src/util/virmdev.c: In function 'virMediatedDeviceListMarkDevices':
../../src/util/virmdev.c:453:21: error: potential null pointer
dereference [-Werror=null-dereference]
          const char *mdev_path = mdev->path;
                      ^~~~~~~~~

Signed-off-by: Erik Skultety <eskultet@redhat.com>
(cherry picked from commit 574718d366170b22227eda640ad94f414e9c7e2f)

8 years agoclient: Report proper close reason
Jiri Denemark [Tue, 2 May 2017 14:39:57 +0000 (16:39 +0200)] 
client: Report proper close reason

When we get a POLLHUP or VIR_EVENT_HANDLE_HANGUP event for a client, we
still want to read from the socket to process any accumulated data. But
doing so inevitably results in an error and a call to
virNetClientMarkClose before we get to processing the hangup event (and
another call to virNetClientMarkClose). However the close reason passed
to the second virNetClientMarkClose call is ignored because another one
was already set. We need to pass the correct close reason when marking
the socket to be closed for the first time.

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

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

8 years agoqemu: Fix persistent migration of transient domains
Jiri Denemark [Tue, 2 May 2017 16:01:04 +0000 (18:01 +0200)] 
qemu: Fix persistent migration of transient domains

While fixing a bug with incorrectly freed memory in commit
v3.1.0-399-g5498aa29a, I accidentally broke persistent migration of
transient domains. Before adding qemuDomainDefCopy in the path, the code
just took NULL from vm->newDef and used it as the persistent def, which
resulted in no persistent XML being sent in the migration cookie. This
scenario is perfectly valid and the destination correctly handles it by
using the incoming live definition and storing it as the persistent one.

After the mentioned commit libvirtd would just segfault in the described
scenario.

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

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

8 years agoFix padding of encrypted data
Daniel P. Berrange [Tue, 2 May 2017 10:32:43 +0000 (11:32 +0100)] 
Fix padding of encrypted data

If we are encoding a block of data that is 16 bytes in length,
we cannot leave it as 16 bytes, we must pad it out to the next
block boundary, 32 bytes. Without this padding, the decoder will
incorrectly treat the last byte of plain text as the padding
length, as it can't distinguish padded from non-padded data.

The problem exhibited itself when using a 16 byte passphrase
for a LUKS volume

  $ virsh secret-set-value 55806c7d-8e93-456f-829b-607d8c198367 \
       $(echo -n 1234567812345678 | base64)
  Secret value set

  $ virsh start demo
  error: Failed to start domain demo
  error: internal error: process exited while connecting to monitor: >>>>>>>>>>Len 16
  2017-05-02T10:35:40.016390Z qemu-system-x86_64: -object \
    secret,id=virtio-disk1-luks-secret0,data=SEtNi5vDUeyseMKHwc1c1Q==,\
    keyid=masterKey0,iv=zm7apUB1A6dPcH53VW960Q==,format=base64: \
    Incorrect number of padding bytes (56) found on decrypted data

Notice how the padding '56' corresponds to the ordinal value of
the character '8'.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 71890992daf37ec78b00b4ce873369421dc99731)

8 years agonetwork: better log message when network is inactive during reconnect
Laine Stump [Tue, 25 Apr 2017 16:26:43 +0000 (12:26 -0400)] 
network: better log message when network is inactive during reconnect

If the network isn't active during networkNotifyActualDevice(), we
would log an error message stating that the bridge device didn't
exist. This patch adds a check to see if the network is active, making
the logs more useful in the case that it isn't.

Partially resolves: https://bugzilla.redhat.com/1442700

(cherry picked from commit 7949de960eaba07661c1e0ab6e4aa945db8c1b25)

8 years agoqemu: don't kill qemu process on restart if networkNotify fails
Laine Stump [Tue, 25 Apr 2017 16:20:30 +0000 (12:20 -0400)] 
qemu: don't kill qemu process on restart if networkNotify fails

Nothing that could happen during networkNotifyActualDevice() could
justify unceremoniously killing the qemu process, but that's what we
were doing.

In particular, new code added in commit 85bcc022 (first appearred in
libvirt-3.2.0) attempts to reattach tap devices to their assigned
bridge devices when libvirtd restarts (to make it easier to recover
from a restart of a libvirt network). But if the network has been
stopped and *not* restarted, the bridge device won't exist and
networkNotifyActualDevice() will fail.

This patch changes networkNotifyActualDevice() and
qemuProcessNotifyNets() to return void, so that qemuProcessReconnect()
will soldier on regardless of what happens (any errors will still be
logged though).

Partially resolves: https://bugzilla.redhat.com/1442700

(cherry picked from commit cb182eb11d3a99adb06e188989899dcd488c43fc)

8 years agoconf: format only relevant attributes for graphics based on listen type
Pavel Hrdina [Wed, 26 Apr 2017 10:47:49 +0000 (12:47 +0200)] 
conf: format only relevant attributes for graphics based on listen type

This patch changes following output:

    ...
    <graphics type='vnc' port='-1' autoport='yes'>
      <listen type='none'/>
    </graphics>
    ...

into this output:

    ...
    <graphics type='vnc'>
      <listen type='none'/>
    </graphics>
    ...

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 2b7d516434190ae4da44aee3b9ae98f776d912a0)

8 years agoqemu: Move freeing of PCI address list to qemuProcessStop
Peter Krempa [Wed, 26 Apr 2017 08:27:49 +0000 (10:27 +0200)] 
qemu: Move freeing of PCI address list to qemuProcessStop

Rather than freeing the list before starting a new VM clear it after
stopping the old instance when the data becomes invalid.

(cherry picked from commit 44f8e00b6b8e575ee09f301d209c1586b527f8c1)

8 years agoqemu: process: Clean up priv->migTLSAlias
Peter Krempa [Wed, 26 Apr 2017 10:46:03 +0000 (12:46 +0200)] 
qemu: process: Clean up priv->migTLSAlias

The alias would be leaked, since it's not freed on the vm stop path.

(cherry picked from commit 8c1fee5f12e607a775199b65915715bb5a2b581d)

8 years agoqemu: process: Don't leak priv->usbaddrs after VM restart
Peter Krempa [Wed, 26 Apr 2017 07:57:39 +0000 (09:57 +0200)] 
qemu: process: Don't leak priv->usbaddrs after VM restart

Since the private data structure is not freed upon stopping a VM, the
usbaddrs pointer would be leaked:

==15388== 136 (16 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 893 of 1,019
==15388==    at 0x4C2CF55: calloc (vg_replace_malloc.c:711)
==15388==    by 0x54BF64A: virAlloc (viralloc.c:144)
==15388==    by 0x5547588: virDomainUSBAddressSetCreate (domain_addr.c:1608)
==15388==    by 0x144D38A2: qemuDomainAssignUSBAddresses (qemu_domain_address.c:2458)
==15388==    by 0x144D38A2: qemuDomainAssignAddresses (qemu_domain_address.c:2515)
==15388==    by 0x144ED1E3: qemuProcessPrepareDomain (qemu_process.c:5398)
==15388==    by 0x144F51FF: qemuProcessStart (qemu_process.c:5979)
[...]

(cherry picked from commit 3ab802d689796ebac6545267d5db248e13a9a0e6)

8 years agoqemu: process: Clean automatic NUMA/cpu pinning information on shutdown
Peter Krempa [Tue, 25 Apr 2017 13:17:34 +0000 (15:17 +0200)] 
qemu: process: Clean automatic NUMA/cpu pinning information on shutdown

Clean the stale data after shutting down the VM. Otherwise the data
would be leaked on next VM start. This happens due to the fact that the
private data object is not freed on destroy of the VM.

(cherry picked from commit 1730cdc665a499afc28683a4ce21493f967411b7)

8 years agoqemu: Remove extra messages for vhost-scsi hotplug
Eric Farman [Wed, 26 Apr 2017 21:10:01 +0000 (17:10 -0400)] 
qemu: Remove extra messages for vhost-scsi hotplug

As with virtio-scsi, the "internal error" messages after
preparing a vhost-scsi hostdev overwrites more meaningful
error messages deeper in the callchain.  Remove it too.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
(cherry picked from commit 6ff38cee609ea30288b2fcd6bbdc37ae0d528c36)

8 years agoqemu: Remove extra messages from virtio-scsi hotplug
Eric Farman [Wed, 26 Apr 2017 21:10:00 +0000 (17:10 -0400)] 
qemu: Remove extra messages from virtio-scsi hotplug

I tried to attach a SCSI LUN to two different guests, and forgot
to specify "shareable" in the hostdev XML.  Attaching the device
to the second guest failed, but the message was not helpful in
telling me what I was doing wrong:

  $ cat scsi_scratch_disk.xml
    <hostdev mode='subsystem' type='scsi'>
      <source>
        <adapter name='scsi_host3'/>
        <address bus='0' target='15' unit='1074151456'/>
      </source>
    </hostdev>

  $ virsh attach-device dasd_sles_d99c scsi_scratch_disk.xml
  Device attached successfully

  $ virsh attach-device dasd_fedora_0e1e scsi_scratch_disk.xml
  error: Failed to attach device from scsi_scratch_disk.xml
  error: internal error: Unable to prepare scsi hostdev: scsi_host3:0:15:1074151456

I eventually discovered my error, but thought it was weird that
Libvirt doesn't provide something more helpful in this case.
Looking over the code we had just gone through, I commented out
the "internal error" message, and got something more useful:

  $ virsh attach-device dasd_fedora_0e1e scsi_scratch_disk.xml
  error: Failed to attach device from scsi_scratch_disk.xml
  error: Requested operation is not valid: SCSI device 3:0:15:1074151456 is already in use by other domain(s) as 'non-shareable'

Looking over the error paths here, we seem to issue better
messages deeper in the callchain so these "internal error"
messages overwrite any of them.  Remove them, so that the
more detailed errors are seen.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
(cherry picked from commit 33c1fc430d33f596233c5a86438ef4ca07f2dc17)

8 years agoqemu: Check return code from qemuHostdevPrepareSCSIDevices
Eric Farman [Wed, 26 Apr 2017 21:09:59 +0000 (17:09 -0400)] 
qemu: Check return code from qemuHostdevPrepareSCSIDevices

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
(cherry picked from commit 2dc94c3c6b3c3d759233e92efb71bb679e1e8257)

8 years agoqemu: numa: Don't return automatic nodeset for inactive domain
Peter Krempa [Wed, 26 Apr 2017 07:01:30 +0000 (09:01 +0200)] 
qemu: numa: Don't return automatic nodeset for inactive domain

qemuDomainGetNumaParameters would return the automatic nodeset even for
the persistent config if the domain was running. This is incorrect since
the automatic nodeset will be re-queried upon starting the vm.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1445325
(cherry picked from commit 135c56e2b876e4cdf8d96de85b32bea3f10d81ce)

8 years agoqemu: Ignore missing query-migrate-parameters
Jiri Denemark [Wed, 26 Apr 2017 21:18:35 +0000 (23:18 +0200)] 
qemu: Ignore missing query-migrate-parameters

Migration with old QEMU which does not support query-migrate-parameters
would fail because the QMP command is called unconditionally since the
introduction of TLS migration. Previously it was only called if the user
explicitly requested a feature which uses QEMU migration parameters. And
even then the situation was not ideal, instead of reporting an
unsupported feature we'd just complain about missing QMP command.

Trivially no migration parameters are supported when
query-migrate-parameters QMP command is missing. There's no need to
report an error if it is missing, the callers will report better error
if needed.

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

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

8 years agodaemon: Fix domain name leak in error path
Wang King [Mon, 24 Apr 2017 04:05:24 +0000 (12:05 +0800)] 
daemon: Fix domain name leak in error path

Domain name is duplicated in make_nonnull_domain, but not freed when
virTypedParamsSerialize returns error.

(cherry picked from commit f69340472cf71c11313ad0018c918d702b08d155)

8 years agoqemu: fix argument of virDomainNetGetActualDirectMode
ZhiPeng Lu [Tue, 25 Apr 2017 06:16:20 +0000 (14:16 +0800)] 
qemu: fix argument of virDomainNetGetActualDirectMode

it should be a comparison of modes between new and old devices. So
the argument of the second virDomainNetGetActualDirectMode should be
newdev.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
(cherry picked from commit c77bc47f43dff2ceb2b95e1aee6fbe1ec9e32fa3)

8 years agorpc: fix keep alive timer segfault
Yi Wang [Tue, 18 Apr 2017 01:55:29 +0000 (09:55 +0800)] 
rpc: fix keep alive timer segfault

ka maybe have been freeed in virObjectUnref, application using
virKeepAliveTimer will segfault when unlock ka. We should keep
ka's refs positive before using it.

#0  0x00007fd8f79970e8 in virClassIsDerivedFrom (klass=0xdeadbeef, parent=0x7fd8e8001b80) at util/virobject.c:169
#1  0x00007fd8f799742e in virObjectIsClass (anyobj=anyobj entry=0x7fd8e800b9c0, klass=<optimized out>) at util/virobject.c:365
#2  0x00007fd8f79974e4 in virObjectUnlock (anyobj=0x7fd8e800b9c0) at util/virobject.c:338
#3  0x00007fd8f7ac477e in virKeepAliveTimer (timer=<optimized out>, opaque=0x7fd8e800b9c0) at rpc/virkeepalive.c:177
#4  0x00007fd8f7e5c9cf in libvirt_virEventInvokeTimeoutCallback () from /usr/lib64/python2.7/site-packages/libvirtmod.so
#5  0x00007fd8ff64db94 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#6  0x00007fd8ff64f1ad in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0
#7  0x00007fd8ff64d85f in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#8  0x00007fd8ff64d950 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#9  0x00007fd8ff64d950 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#10 0x00007fd8ff64f1ad in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0
#11 0x00007fd8ff5dc098 in function_call () from /lib64/libpython2.7.so.1.0
#12 0x00007fd8ff5b7073 in PyObject_Call () from /lib64/libpython2.7.so.1.0
#13 0x00007fd8ff5c6085 in instancemethod_call () from /lib64/libpython2.7.so.1.0
#14 0x00007fd8ff5b7073 in PyObject_Call () from /lib64/libpython2.7.so.1.0
#15 0x00007fd8ff648ff7 in PyEval_CallObjectWithKeywords () from /lib64/libpython2.7.so.1.0
#16 0x00007fd8ff67d7e2 in t_bootstrap () from /lib64/libpython2.7.so.1.0
#17 0x00007fd8ff358df3 in start_thread () from /lib64/libpthread.so.0
#18 0x00007fd8fe97d3ed in clone () from /lib64/libc.so.6

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit ab5bb6f3465aa8608cdf8e7b7bbeda8500bada17)

8 years agoutil: allow ignoring SIOCSIFHWADDR when errno is EPERM
Laine Stump [Mon, 17 Apr 2017 14:50:48 +0000 (10:50 -0400)] 
util: allow ignoring SIOCSIFHWADDR when errno is EPERM

Commit f4ef3a71 made a variation of virNetDevSetMAC that would return
without logging an error message if errno was set to
EADDRNOTAVAIL. This errno is set by some SRIOV VF drivers (in
particular igbvf) when they fail to set the device's MAC address due
to the PF driver refusing the request. This is useful if we want to
try a different method of setting the VF MAC address before giving up
(Commit 86556e16 actually does this, setting the desired MAC address
to the "admin MAC in the PF, then detaching and reattaching the VF
netdev driver to force a reinit of the MAC address).

During testing of Bug 1442040 t was discovered that the ixgbe driver
returns EPERM in this situation, so this patch changes the exception
case for silent+non-terminal failure to account for this difference.

Completes resolution to: https://bugzilla.redhat.com/1415609 (RHEL 7.4)
                         https://bugzilla.redhat.com/1442040 (RHEL 7.3.z)

(cherry picked from commit 997134fb8b17eef6eba439303b382b239996208b)

8 years agoutil: check ifa_addr pointer before accessing its elements
Pavel Hrdina [Fri, 21 Apr 2017 08:50:12 +0000 (10:50 +0200)] 
util: check ifa_addr pointer before accessing its elements

Reported by Rafał Wojciechowski <it@rafalwojciechowski.pl>.

Thread 1 (Thread 0x7f194b99d700 (LWP 5631)):
0  virNetDevGetifaddrsAddress (addr=0x7f194b99c7c0, ifname=0x7f193400e2b0 "ovirtmgmt") at util/virnetdevip.c:738
1  virNetDevIPAddrGet (ifname=0x7f193400e2b0 "ovirtmgmt", addr=addr@entry=0x7f194b99c7c0) at util/virnetdevip.c:795
2  0x00007f19467800d6 in networkGetNetworkAddress (netname=<optimized out>, netaddr=netaddr@entry=0x7f1924013f18) at network/bridge_driver.c:4780
3  0x00007f193e43a33c in qemuProcessGraphicsSetupNetworkAddress (listenAddr=0x7f19340f7650 "127.0.0.1", glisten=0x7f1924013f10) at qemu/qemu_process.c:4062
4  qemuProcessGraphicsSetupListen (vm=<optimized out>, graphics=0x7f1924014f10, cfg=0x7f1934119f00) at qemu/qemu_process.c:4133
5  qemuProcessSetupGraphics (flags=17, vm=0x7f19240155d0, driver=0x7f193411f1d0) at qemu/qemu_process.c:4196
6  qemuProcessPrepareDomain (conn=conn@entry=0x7f192c00ab50, driver=driver@entry=0x7f193411f1d0, vm=vm@entry=0x7f19240155d0, flags=flags@entry=17) at qemu/qemu_process.c:4969
7  0x00007f193e4417c0 in qemuProcessStart (conn=conn@entry=0x7f192c00ab50, driver=driver@entry=0x7f193411f1d0, vm=0x7f19240155d0,asyncJob=asyncJob@entry=QEMU_ASYNC_JOB_START, migrateFrom=migrateFrom@entry=0x0, migrateFd=migrateFd@entry=-1, migratePath=migratePath@entry=0x0,snapshot=snapshot@entry=0x0, vmop=vmop@entry=VIR_NETDEV_VPORT_PROFILE_OP_CREATE, flags=17, flags@entry=1) at qemu/qemu_process.c:5553

Man page for getifaddrs also states that the "ifa_addr" may contain
a null pointer which happens if there is an existing network interface
on the host without IP address.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 42000bf7e554b3732a569db633824302d5ec2867)

8 years agoIncrease default task limit for libvirtd
Jim Fehlig [Wed, 19 Apr 2017 18:54:33 +0000 (12:54 -0600)] 
Increase default task limit for libvirtd

libvirtd can spawn threads/tasks when creating new domains for
some hypervisors such as Xen's libxl driver, quickly reaching
the cgroups pids controller default TasksMax setting of 512. When
the limit is reached, attempting to create additional domains
results in an error from the cgroups pids controller, e.g.

kernel: [71282.213347] cgroup: fork rejected by pids controller in
/system.slice/libvirtd.service

Depending on domain type and configuration, anywhere from 4-7
threads/tasks may be created by libxl when starting a domain.
In order to support 4096 domains, similar to commit 27cd763500,
increase the TasksMax setting in libvirtd.service to
4096 * 8 = 32768 tasks.

(cherry picked from commit 6b3fb86b391da731d1a0667c35a8e9f8b5c1d6c5)

8 years agoFix error reporting when poll returns POLLHUP/POLLERR
Daniel P. Berrange [Tue, 18 Apr 2017 15:57:06 +0000 (16:57 +0100)] 
Fix error reporting when poll returns POLLHUP/POLLERR

In the RPC client event loop code, if poll() returns only a POLLHUP
or POLLERR status, then we end up reporting a bogus error message:

  error: failed to connect to the hypervisor
  error: An error occurred, but the cause is unknown

We do actually report an error, but we virNetClientMarkClose method
has already captured the error status before we report it, so the
real error gets thrown away. The key fix is to report the error
before calling virNetClientMarkClose(). In changing this, we also
split out reporting of POLLHUP vs POLLERR to make any future bugs
easier to diagnose.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 234ac4e18db3a3acb7d8e792260ec0dabed7c36d)

8 years agospec: Avoid RPM verification errors on nwfilter XMLs
Jiri Denemark [Wed, 12 Apr 2017 19:36:01 +0000 (21:36 +0200)] 
spec: Avoid RPM verification errors on nwfilter XMLs

/etc/libvirt/nwfilter/*.xml files are installed with no UUID, which
means libvirtd will automatically alter all of them once it starts. Thus
RPM verification will always fail on them. Let's use a trick similar to
the default network XML and store nwfilter XMLs in /usr/share. They will
be copied into /etc in %post. Additionally the /etc files are marked as
%ghost so that they are uninstalled if the RPM package is removed.

Note that the %post script overwrites existing files with new ones on
upgrade, which is what has always been happening.

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

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

8 years agoxenconfig: avoid double free on OOM testing
Jim Fehlig [Thu, 13 Apr 2017 16:39:52 +0000 (10:39 -0600)] 
xenconfig: avoid double free on OOM testing

Fix xlconfig channel tests when OOM testing is enabled.

TEST: xlconfigtest
32) Xen XL-2-XML Format channel-unix                                  ... OK
    Test OOM for nalloc=55 ................................................*** Error in `/home/jfehlig/virt/upstream/libvirt/tests/.libs/xlconfigtest': double free or corruption (fasttop): 0x0000000000679550 ***
...
(gdb) bt
#0  0x00007ffff36875af in raise () from /lib64/libc.so.6
#1  0x00007ffff36889aa in abort () from /lib64/libc.so.6
#2  0x00007ffff36c5150 in __libc_message () from /lib64/libc.so.6
#3  0x00007ffff36cb4f6 in malloc_printerr () from /lib64/libc.so.6
#4  0x00007ffff36cbcee in _int_free () from /lib64/libc.so.6
#5  0x00007ffff782babf in virFree (ptrptr=0x7fffffffdca8) at util/viralloc.c:582
#6  0x000000000042f2f3 in xenParseXLChannel (conf=0x677350, def=0x6815b0) at xenconfig/xen_xl.c:788
#7  0x000000000042f44e in xenParseXL (conf=0x677350, caps=0x6832b0, xmlopt=0x67f6e0) at xenconfig/xen_xl.c:828
#8  0x00000000004105a3 in testCompareFormatXML (
    xlcfg=0x6811e0 "/home/jfehlig/virt/upstream/libvirt/tests/xlconfigdata/test-channel-unix.cfg",
    xml=0x681110 "/home/jfehlig/virt/upstream/libvirt/tests/xlconfigdata/test-channel-unix.xml", replaceVars=false)
    at xlconfigtest.c:152

When a channel is successfully parsed and its path and name fields
assigned from local variables, set the local variables to NULL to
prevent a double free on error.

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

8 years agoxenFormatXLDomainDisks: avoid double free on OOM testing
Wim ten Have [Mon, 27 Mar 2017 20:20:19 +0000 (22:20 +0200)] 
xenFormatXLDomainDisks: avoid double free on OOM testing

Fix xlconfigtest runs build for --enable-test-oom on
        Xen XL-2-XML Parse  new-disk

    #0  0x00007ffff3bd791f in raise () from /lib64/libc.so.6
    #1  0x00007ffff3bd951a in abort () from /lib64/libc.so.6
    #2  0x00007ffff3c1b200 in __libc_message () from /lib64/libc.so.6
    #3  0x00007ffff3c2488a in _int_free () from /lib64/libc.so.6
    #4  0x00007ffff3c282bc in free () from /lib64/libc.so.6
    #5  0x00007ffff7864fcb in virFree (ptrptr=ptrptr@entry=0x7fffffffd868) at util/viralloc.c:582
    #6  0x00007ffff78776e5 in virConfFreeValue (val=<optimized out>) at util/virconf.c:178
==> #7  0x0000000000425759 in xenFormatXLDomainDisks (def=0x7fffffffd8c0, def=0x7fffffffd8c0, conf=0x658220)
        at xenconfig/xen_xl.c:1159
    #8  xenFormatXL (def=def@entry=0x66ec20, conn=conn@entry=0x668cf0) at xenconfig/xen_xl.c:1558
    #9  0x000000000040ea1d in testCompareParseXML (replaceVars=<optimized out>,
        xml=0x65f5e0 "/home/wtenhave/WORK/libvirt/history/libvirt/tests/xlconfigdata/test-fullvirt-ovmf.xml",
        xlcfg=0x65f6b0 "/home/wtenhave/WORK/libvirt/history/libvirt/tests/xlconfigdata/test-fullvirt-ovmf.cfg")
        at xlconfigtest.c:105
    #10 testCompareHelper (data=<optimized out>) at xlconfigtest.c:205
    #11 0x000000000041079a in virTestRun (title=title@entry=0x431cf0 "Xen XL-2-XML Parse  fullvirt-ovmf",
        body=body@entry=0x40e720 <testCompareHelper>, data=data@entry=0x7fffffffda50) at testutils.c:247
    #12 0x000000000040ebc2 in mymain () at xlconfigtest.c:256
    #13 0x0000000000411070 in virTestMain (argc=1, argv=0x7fffffffdc08, func=0x40f2c0 <mymain>) at testutils.c:992
    #14 0x00007ffff3bc2401 in __libc_start_main () from /lib64/libc.so.6
    #15 0x000000000040e5da in _start ()

symmetry seems missing its sibbling coded functionality
demonstrated under functions;
        xenFormatXLUSBController()
        xenFormatXLUSB()
        xenFormatXLDomainChannels()
        xenFormatXMDisks

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
(cherry picked from commit 2c1a31a375e1f765e1e53e863feb18864a38ed9f)

8 years agovirConfSaveValue: protect against a NULL pointer reference
Wim ten Have [Mon, 27 Mar 2017 20:20:43 +0000 (22:20 +0200)] 
virConfSaveValue: protect against a NULL pointer reference

Fix xlconfigtest runs build for --enable-test-oom on
        Xen XL-2-XML Parse  channel-pty

Program received signal SIGSEGV, Segmentation fault.

    #0  0x00007ffff3c2b373 in __strchr_sse2 () from /lib64/libc.so.6
==> #1  0x00007ffff7875701 in virConfSaveValue (buf=buf@entry=0x7fffffffd8a0, val=val@entry=0x674750) at util/virconf.c:290
    #2  0x00007ffff7875668 in virConfSaveValue (buf=buf@entry=0x7fffffffd8a0, val=<optimized out>) at util/virconf.c:306
    #3  0x00007ffff78757ef in virConfSaveEntry (buf=buf@entry=0x7fffffffd8a0, cur=cur@entry=0x674780) at util/virconf.c:338
    #4  0x00007ffff78783eb in virConfWriteMem (memory=0x665570 "", len=len@entry=0x7fffffffd910, conf=conf@entry=0x65b940)
        at util/virconf.c:1543
    #5  0x000000000040eccb in testCompareParseXML (replaceVars=<optimized out>, xml=<optimized out>,
        xlcfg=0x662c00 "/home/wtenhave/WORK/libvirt/OOMtesting/libvirt-devel/tests/xlconfigdata/test-channel-pty.cfg")
        at xlconfigtest.c:108
    #6  testCompareHelper (data=<optimized out>) at xlconfigtest.c:205
    #7  0x0000000000410b3a in virTestRun (title=title@entry=0x432cc0 "Xen XL-2-XML Parse  channel-pty",
        body=body@entry=0x40e9b0 <testCompareHelper>, data=data@entry=0x7fffffffd9f0) at testutils.c:247
    #8  0x000000000040f322 in mymain () at xlconfigtest.c:278
    #9  0x0000000000411410 in virTestMain (argc=1, argv=0x7fffffffdba8, func=0x40f660 <mymain>) at testutils.c:992
    #10 0x00007ffff3bc0401 in __libc_start_main () from /lib64/libc.so.6
    #11 0x000000000040e86a in _start ()

    (gdb) frame 1
    #1  0x00007ffff7875701 in virConfSaveValue (buf=buf@entry=0x7fffffffd8a0, val=val@entry=0x674750) at util/virconf.c:290
    290                 if (strchr(val->str, '\n') != NULL) {
    (gdb) print *val
    $1 = {type = VIR_CONF_STRING, next = 0x0, l = 0, str = 0x0, list = 0x0}

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
(cherry picked from commit ae5d758209b27274ae944660c65fe89e6610bc47)

8 years agoconf: Add check for non scsi_host parent during vport delete
John Ferlan [Tue, 4 Apr 2017 18:06:42 +0000 (14:06 -0400)] 
conf: Add check for non scsi_host parent during vport delete

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

If the parent is not a scsi_host, then we can just happily return since
we won't be removing a vport.

Fixes a bug with the following output:

$ virsh pool-destroy host4_hba_pool
error: Failed to destroy pool host4_hba_pool
error: internal error: Invalid adapter name 'pci_0000_10_00_1' for SCSI pool

$

(cherry picked from commit 84f178bdc7ab38011cc1f76759b0a41335285a4f)

8 years agoutil: Fix resource leak
Wang King [Wed, 12 Apr 2017 08:44:04 +0000 (16:44 +0800)] 
util: Fix resource leak

The virRotatingFileWriterAppend method leaks the file->entry
on the virRotatingFileWriterEntryNew failing path.

(cherry picked from commit 123770cd4e2d8a0a6166ec93175ddd96c9029947)

8 years agotest: Remove unused variate @maxcpu in testDomainGetVcpus
Wang King [Thu, 13 Apr 2017 02:16:07 +0000 (10:16 +0800)] 
test: Remove unused variate @maxcpu in testDomainGetVcpus

Since refactoring by commit id '3dd859c0', @maxcpu is no longer used.

(cherry picked from commit b2641b43920917b17e3c10b6a9898c3ff1c82543)

8 years agoesx: Fix memory leak
Wang King [Wed, 12 Apr 2017 10:06:44 +0000 (18:06 +0800)] 
esx: Fix memory leak

Variable def going out of scope leaks the storage def.source.hosts points to.

(cherry picked from commit d76267b2e4fb7a2388625b7cd4037d7b69db23d9)

8 years agoesx: Fix incorrect memory compare size in esxStoragePoolLookupByUUID
Wang King [Thu, 13 Apr 2017 02:15:45 +0000 (10:15 +0800)] 
esx: Fix incorrect memory compare size in esxStoragePoolLookupByUUID

Use MD5_DIGEST_SIZE or VIR_UUID_BUFLEN rather than VIR_UUID_STRING_BUFLEN
when compare @uuid with @md5.

(cherry picked from commit 77cc51a4820e27c42636c7072724d5eac73ead53)

8 years agoqemu: snapshot: Skip empty drives with internal snapshots
Peter Krempa [Fri, 7 Apr 2017 14:56:49 +0000 (16:56 +0200)] 
qemu: snapshot: Skip empty drives with internal snapshots

The code that validates whether an internal snapshot is possible would
reject an empty but not-readonly drive. Since floppies can have this
property, add a check for emptiness.

(cherry picked from commit eee3b4b9493a0b4e5e5fb473893a55320b4f83b1)

8 years agoqemu: do not crash on USB address with no port and invalid bus
Ján Tomko [Wed, 12 Apr 2017 10:40:57 +0000 (12:40 +0200)] 
qemu: do not crash on USB address with no port and invalid bus

Properly error out when the user requests a port from a bus
that does not have a controller present in the domain XML.

https://bugzilla.redhat.com/show_bug.cgi?id=1441589
(cherry picked from commit b003b9781b6ae633cfe4fdf6b9620ca246fa2432)

8 years agoman: Align vol-resize arguments with the output of help
Martin Kletzander [Wed, 12 Apr 2017 06:43:49 +0000 (08:43 +0200)] 
man: Align vol-resize arguments with the output of help

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit c3d1df7b850b6a2d15b8f770bdf78bb0089404d5)

8 years agoqemu: conf: Don't leak snapshot image format conf variable
Peter Krempa [Wed, 12 Apr 2017 12:54:04 +0000 (14:54 +0200)] 
qemu: conf: Don't leak snapshot image format conf variable

==20406== 4 bytes in 1 blocks are definitely lost in loss record 6 of 1,059
==20406==    at 0x4C2AF3F: malloc (vg_replace_malloc.c:299)
==20406==    by 0x8F17D39: strdup (in /lib64/libc-2.24.so)
==20406==    by 0x552C0E0: virStrdup (virstring.c:784)
==20406==    by 0x54D3622: virConfGetValueString (virconf.c:945)
==20406==    by 0x144E4692: virQEMUDriverConfigLoadFile (qemu_conf.c:687)
==20406==    by 0x1452A744: qemuStateInitialize (qemu_driver.c:664)
==20406==    by 0x55DB585: virStateInitialize (libvirt.c:770)
==20406==    by 0x124570: daemonRunStateInit (libvirtd.c:881)
==20406==    by 0x5532990: virThreadHelper (virthread.c:206)
==20406==    by 0x8C82493: start_thread (in /lib64/libpthread-2.24.so)
==20406==    by 0x8F7FA1E: clone (in /lib64/libc-2.24.so)

(cherry picked from commit 2ef3aa8f636065ad5d668b70526717651fd19e34)

8 years agoqemu: Fix mdev checking for VFIO support
Erik Skultety [Wed, 12 Apr 2017 08:46:35 +0000 (10:46 +0200)] 
qemu: Fix mdev checking for VFIO support

Commit a4a39d90 added a check that checks for VFIO support with mediated
devices. The problem is that the hostdev preparing functions behave like
a fallthrough if device of that specific type doesn't exist. However,
the check for VFIO support was independent of the existence of a mdev
device which caused the guest to fail to start with any device to be
directly assigned if VFIO was disabled/unavailable in the kernel.
The proposed change first ensures that it makes sense to check for VFIO
support in the first place, and only then performs the VFIO support check
itself.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
(cherry picked from commit b4c2ac8d56124428d9329643a68625465094c5a7)

8 years agoutil: systemd: Don't strlen a possibly NULL string
Wang King [Wed, 12 Apr 2017 08:22:57 +0000 (16:22 +0800)] 
util: systemd: Don't strlen a possibly NULL string

Coverity complains about virBufferCurrentContent might be return null
when calling strlen, so check virBufferError first before calling
strlen.

(cherry picked from commit c5ca209f5848c68334c06cb2955758bd486fd149)

8 years agointerface: Fix resource leak in netcfConnectListAllInterfaces error path
Wang King [Wed, 12 Apr 2017 07:58:23 +0000 (15:58 +0800)] 
interface: Fix resource leak in netcfConnectListAllInterfaces error path

On virGetInterface failure, call virInterfaceDefFree for the @def.

(cherry picked from commit 1b1b045915bec4cbc6ed087c96be4b1de8953002)

8 years agovirsh: don't leak @cpumap in virshVcpuPinQuery
Wang King [Wed, 12 Apr 2017 07:36:09 +0000 (15:36 +0800)] 
virsh: don't leak @cpumap in virshVcpuPinQuery

==18591== 16 bytes in 1 blocks are definitely lost in loss record 41 of 183
==18591==    at 0x4C2B934: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18591==    by 0x54EBB1C: virAllocN (viralloc.c:191)
==18591==    by 0x1628CA: _vshMalloc (vsh.c:136)
==18591==    by 0x1344C4: virshVcpuPinQuery (virsh-domain.c:6603)
==18591==    by 0x1344C4: cmdVcpuPin (virsh-domain.c:6707)
==18591==    by 0x1631BF: vshCommandRun (vsh.c:1312)
==18591==    by 0x12DBB1: main (virsh.c:961)

(cherry picked from commit b1aa4613a7f0b81c70fed01613e9c2624511fa8e)

8 years agotests: fix some resource leaks
Pavel Hrdina [Sun, 9 Apr 2017 11:28:07 +0000 (13:28 +0200)] 
tests: fix some resource leaks

Found by running valgrind for these tests.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 9005a64b5cd2a064418572ec295532efb3df2798)

8 years agorpc: fix resource leak
Pavel Hrdina [Sun, 9 Apr 2017 10:55:09 +0000 (12:55 +0200)] 
rpc: fix resource leak

Commit 252610f7dd1 switched to use hash to store servers.
Function virHashGetItems returns allocated array which needs
to be freed also for successful path, not only if there is
an error.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit ab0a461b8c873e9b4999ed627bc8ce01d0105268)

8 years agosrc: fix multiple resource leaks in loops
Pavel Hrdina [Sun, 9 Apr 2017 10:49:24 +0000 (12:49 +0200)] 
src: fix multiple resource leaks in loops

All of the variables are filled inside a loop and therefore
needs to be also freed in every cycle.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit ffc810b7c7cad514fe362c5b42877bca7eee88b3)

8 years agoconf/domain_capabilities: fix resource leak
Pavel Hrdina [Sun, 9 Apr 2017 10:43:45 +0000 (12:43 +0200)] 
conf/domain_capabilities: fix resource leak

Commit 14319c81a0 introduced CPU host model in domain capabilities
and the *hostmodel* variable is always filled by virCPUDefCopy()
and needs to be freed.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 87d97a9d0a75f7d948312b233c12da3a69d9513b)

8 years agoqemu: Fix two use-after-free situations
Marc Hartmayer [Mon, 3 Apr 2017 08:24:35 +0000 (10:24 +0200)] 
qemu: Fix two use-after-free situations

There were multiple race conditions that could lead to segmentation
faults. The first precondition for this is qemuProcessLaunch must fail
sometime shortly after starting the new QEMU process. The second
precondition for the segmentation faults is that the new QEMU process
dies - or to be more precise the QEMU monitor has to be closed
irregularly. If both happens during qemuProcessStart (starting a
domain) there are race windows between the thread with the event
loop (T1) and the thread that is starting the domain (T2).

First segmentation fault scenario:
If qemuProcessLaunch fails during qemuProcessStart the code branches
to the 'stop' path where 'qemuMonitorSetDomainLog(priv->mon, NULL,
NULL, NULL)' will set the log function of the monitor to NULL (done in
T2). In the meantime the event loop of T1 will wake up with an EOF
event for the QEMU monitor because the QEMU process has died. The
crash occurs if T1 has checked 'mon->logFunc != NULL' in qemuMonitorIO
just before the logFunc was set to NULL by T2. If this situation
occurs T1 will try to call mon->logFunc which leads to the
segmentation fault.

Solution:
Require the monitor lock for setting the log function.

Backtrace:
0  0x0000000000000000 in ?? ()
1  0x000003ffe9e45316 in qemuMonitorIO (watch=<optimized out>,
fd=<optimized out>, events=<optimized out>, opaque=0x3ffe08aa860) at
../../src/qemu/qemu_monitor.c:727
2  0x000003fffda2e1a4 in virEventPollDispatchHandles (nfds=<optimized
out>, fds=0x2aa000fd980) at ../../src/util/vireventpoll.c:508
3  0x000003fffda2e398 in virEventPollRunOnce () at
../../src/util/vireventpoll.c:657
4  0x000003fffda2ca10 in virEventRunDefaultImpl () at
../../src/util/virevent.c:314
5  0x000003fffdba9366 in virNetDaemonRun (dmn=0x2aa000cc550) at
../../src/rpc/virnetdaemon.c:818
6  0x000002aa00024668 in main (argc=<optimized out>, argv=<optimized
out>) at ../../daemon/libvirtd.c:1541

Second segmentation fault scenario:
If qemuProcessLaunch fails it will unref the log context and with
invoking qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL)
qemuDomainLogContextFree() will be invoked. qemuDomainLogContextFree()
invokes virNetClientClose() to close the client and cleans everything
up (including unref of _virLogManager.client) when virNetClientClose()
returns. When T1 is now trying to report 'qemu unexpectedly closed the
monitor' libvirtd will crash because the client has already been
freed.

Solution:
As the critical section in qemuMonitorIO is protected with the monitor
lock we can use the same solution as proposed for the first
segmentation fault.

Backtrace:
0  virClassIsDerivedFrom (klass=0x3100979797979797,
parent=0x2aa000d92f0) at ../../src/util/virobject.c:169
1  0x000003fffda659e6 in virObjectIsClass (anyobj=<optimized out>,
klass=<optimized out>) at ../../src/util/virobject.c:365
2  0x000003fffda65a24 in virObjectLock (anyobj=0x3ffe08c1db0) at
../../src/util/virobject.c:317
3  0x000003fffdba4688 in
virNetClientIOEventLoop (client=client@entry=0x3ffe08c1db0,
thiscall=thiscall@entry=0x2aa000fbfa0) at
../../src/rpc/virnetclient.c:1668
4  0x000003fffdba4b4c in
virNetClientIO (client=client@entry=0x3ffe08c1db0,
thiscall=0x2aa000fbfa0) at ../../src/rpc/virnetclient.c:1944
5  0x000003fffdba4d42 in
virNetClientSendInternal (client=client@entry=0x3ffe08c1db0,
msg=msg@entry=0x2aa000cc710, expectReply=expectReply@entry=true,
nonBlock=nonBlock@entry=false) at ../../src/rpc/virnetclient.c:2116
6  0x000003fffdba6268 in
virNetClientSendWithReply (client=0x3ffe08c1db0, msg=0x2aa000cc710) at
../../src/rpc/virnetclient.c:2144
7  0x000003fffdba6e8e in virNetClientProgramCall (prog=0x3ffe08c1120,
client=<optimized out>, serial=<optimized out>, proc=<optimized out>,
noutfds=<optimized out>, outfds=0x0, ninfds=0x0, infds=0x0,
args_filter=0x3fffdb64440
<xdr_virLogManagerProtocolDomainReadLogFileArgs>, args=0x3ffffffe010,
ret_filter=0x3fffdb644c0
<xdr_virLogManagerProtocolDomainReadLogFileRet>, ret=0x3ffffffe008) at
../../src/rpc/virnetclientprogram.c:329
8  0x000003fffdb64042 in
virLogManagerDomainReadLogFile (mgr=<optimized out>, path=<optimized
out>, inode=<optimized out>, offset=<optimized out>, maxlen=<optimized
out>, flags=0) at ../../src/logging/log_manager.c:272
9  0x000003ffe9e0315c in qemuDomainLogContextRead (ctxt=0x3ffe08c2980,
msg=0x3ffffffe1c0) at ../../src/qemu/qemu_domain.c:4422
10 0x000003ffe9e280a8 in qemuProcessReadLog (logCtxt=<optimized out>,
msg=msg@entry=0x3ffffffe288) at ../../src/qemu/qemu_process.c:1800
11 0x000003ffe9e28206 in qemuProcessReportLogError (logCtxt=<optimized
out>, msgprefix=0x3ffe9ec276a "qemu unexpectedly closed the monitor")
at ../../src/qemu/qemu_process.c:1836
12 0x000003ffe9e28306 in
qemuProcessMonitorReportLogError (mon=mon@entry=0x3ffe085cf10,
msg=<optimized out>, opaque=<optimized out>) at
../../src/qemu/qemu_process.c:1856
13 0x000003ffe9e452b6 in qemuMonitorIO (watch=<optimized out>,
fd=<optimized out>, events=<optimized out>, opaque=0x3ffe085cf10) at
../../src/qemu/qemu_monitor.c:726
14 0x000003fffda2e1a4 in virEventPollDispatchHandles (nfds=<optimized
out>, fds=0x2aa000fd980) at ../../src/util/vireventpoll.c:508
15 0x000003fffda2e398 in virEventPollRunOnce () at
../../src/util/vireventpoll.c:657
16 0x000003fffda2ca10 in virEventRunDefaultImpl () at
../../src/util/virevent.c:314
17 0x000003fffdba9366 in virNetDaemonRun (dmn=0x2aa000cc550) at
../../src/rpc/virnetdaemon.c:818
18 0x000002aa00024668 in main (argc=<optimized out>, argv=<optimized
out>) at ../../daemon/libvirtd.c:1541

Other code parts where the same problem was possible to occur are
fixed as well (qemuMigrationFinish, qemuProcessStart, and
qemuDomainSaveImageStartVM).

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reported-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
(cherry picked from commit 20e95cb7c8653b02016ab9a7118c6de8c9866ea9)

8 years agodisk: Force usage of parted when checking disk format for "bsd"
John Ferlan [Fri, 7 Apr 2017 13:38:44 +0000 (09:38 -0400)] 
disk: Force usage of parted when checking disk format for "bsd"

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

Add "bsd" to the list of format types to not checked during blkid
processing even though it supposedly knows the format - for some
(now unknown) reason it's returning partition table not found. So
let's just let PARTED handle "bsd" too.

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 98f424d5038b362d1b62549930d0b9253106bdca)

8 years agodisk: Resolve issues with disk partition build/start checks
John Ferlan [Fri, 7 Apr 2017 11:02:40 +0000 (07:02 -0400)] 
disk: Resolve issues with disk partition build/start checks

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

Commit id 'a48c674fb' added a check for format types "dvh" and "pc98"
to use the parted print processing instead of using blkid processing
in order to validate the label on the disk was what is expected for
disk pool startup. However, commit id 'a4cb4a74f' really messed things
up by missing an else condition causing PARTEDFindLabel to always
return DIFFERENT.

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit f2a123203105b4fe010aea866e87f8bcf5f31193)

8 years agoconf: create new RemovalFailed event using correct class
Pavel Hrdina [Fri, 7 Apr 2017 12:00:22 +0000 (14:00 +0200)] 
conf: create new RemovalFailed event using correct class

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit be193c4dc6f2837a4abb279ee62b039448e0aa5e)

8 years agoqemu: fix memory leak and check mdevPath
Pavel Hrdina [Fri, 7 Apr 2017 11:43:25 +0000 (13:43 +0200)] 
qemu: fix memory leak and check mdevPath

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit d58c146a4f083c2d86ac5a4dd450f63751a36913)

8 years agoqemu: Properly reset TLS in qemuProcessRecoverMigrationIn
Jiri Denemark [Tue, 4 Apr 2017 17:43:13 +0000 (19:43 +0200)] 
qemu: Properly reset TLS in qemuProcessRecoverMigrationIn

There is no async job running when a freshly started libvirtd is trying
to recover from an interrupted incoming migration. While at it, let's
call qemuMigrationResetTLS every time we don't kill the domain. This is
not strictly necessary since TLS is not supported when v2 migration
protocol is used, but doing so makes more sense.

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

8 years agoProperly ignore files in build-aux directory
Jiri Denemark [Fri, 7 Apr 2017 06:50:21 +0000 (08:50 +0200)] 
Properly ignore files in build-aux directory

We want to ignore all files except *.pl in build-aux directory, however
the unignore pattern "!/build-aux/*.pl" doesn't have any effect because
a previous "/build-aux/" pattern ignores the directory itself rather
than individual files in it.

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

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

8 years agoconf: Fix possible memleak in capabilities
Martin Kletzander [Wed, 29 Mar 2017 11:36:15 +0000 (13:36 +0200)] 
conf: Fix possible memleak in capabilities

If formatting NUMA topology fails, the function returns immediatelly,
but the buffer structure allocated on the stack references lot of
heap-allocated memory and that would get lost in such case.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 6369ee0483b99ec4d2e624e9a32e35b7bdd9ab8a)

8 years agoSplit out -Wframe-larger-than warning from WARN_CLFAGS
Ján Tomko [Wed, 29 Jun 2016 13:19:18 +0000 (15:19 +0200)] 
Split out -Wframe-larger-than warning from WARN_CLFAGS

Introduce STRICT_FRAME_LIMIT_CFLAGS that will be used for
production code and RELAXED_FRAME_LIMIT_CFLAGS for tests.

Raising the limit for tests allows building them with clang
with optimizations disabled.

(cherry picked from commit e73889b6311f5b43d859caa4bae84bfdb299967a)

8 years agovirISCSIGetSession: Don't leak memory
Michal Privoznik [Wed, 5 Apr 2017 08:48:10 +0000 (10:48 +0200)] 
virISCSIGetSession: Don't leak memory

This function runs an iscsi command and parses its output.
However, due to the nature of things, virISCSIExtractSession()
callback can be called multiple times. In each run it would
allocate new memory and overwrite the variable where we keep
pointer to it and thus leaking old allocations.

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

8 years agovirStorageSourceClear: Don't leave dangling pointers behind
Michal Privoznik [Wed, 5 Apr 2017 07:59:25 +0000 (09:59 +0200)] 
virStorageSourceClear: Don't leave dangling pointers behind

Imagine that this function is called twice over the same disk
source. While in the first run all allocated memory is freed, not
all pointers are set to NULL (e.g. def->srcpool). So when called
again, these poitners are freed again resulting in double free.

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

8 years agoqemu: Break endless loop if qemuMigrationResetTLS fails
Jiri Denemark [Tue, 4 Apr 2017 10:46:37 +0000 (12:46 +0200)] 
qemu: Break endless loop if qemuMigrationResetTLS fails

Jumping to "endjob" label from a code after this label is not a very
good idea.

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

8 years agostorage: gluster: Implement 'checkPool' method so that state is restored
Peter Krempa [Thu, 30 Mar 2017 11:18:43 +0000 (13:18 +0200)] 
storage: gluster: Implement 'checkPool' method so that state is restored

After restart of libvirtd the 'checkPool' method is supposed to validate
that the pool is online. Since libvirt then refreshes the pool contents
anyways just return whether the pool was supposed to be online so that
the code can be reached. This is necessary since if a pool does not
implement the method it's automatically considered as inactive.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1436065
(cherry picked from commit a200ebbc6f2cc5835daf0ddda9a347b7311a7877)

8 years agodocs: Document limitation of maximum vcpu count used with <topology>
Peter Krempa [Tue, 4 Apr 2017 14:02:21 +0000 (16:02 +0200)] 
docs: Document limitation of maximum vcpu count used with <topology>

qemu requires that the topology equals to the maximum vcpu count.
Document this along with the API to set maximum vcpu count and the XML
element.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1426220
(cherry picked from commit 4661a1868bb4d918e43ed96c4ae14f5ecd37b3f7)

8 years agoqemu: Fix resource leak in qemuDomainAddChardevTLSObjects error path
John Ferlan [Mon, 3 Apr 2017 16:53:33 +0000 (12:53 -0400)] 
qemu: Fix resource leak in qemuDomainAddChardevTLSObjects error path

On any failure, call virJSONValueFree for the *Props.

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 2e8c60958ac32624296eee263bf34bb21a32360c)

8 years agoqemu: Initialize 'data' argument
John Ferlan [Mon, 3 Apr 2017 16:53:32 +0000 (12:53 -0400)] 
qemu: Initialize 'data' argument

Initialize stack variable to {0}

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 83c58ea39622d732097d377cae9e87650f5df960)

8 years agostorage: util: Pass pool type to virStorageBackendFindGlusterPoolSources
Peter Krempa [Thu, 30 Mar 2017 13:08:06 +0000 (15:08 +0200)] 
storage: util: Pass pool type to virStorageBackendFindGlusterPoolSources

The native gluster pool source list data differs from the data used for
attaching gluster volumes as netfs pools. Currently the only difference
was the format. Since native pools don't use it and later there will be
more differences add a more deterministic way to switch between the
types instead.

(cherry picked from commit a92160dbd5416b093c0d99991afe300b9b8572c4)

8 years agoutil: ignore -Wcast-align in virNetlinkDumpCommand
Ján Tomko [Tue, 4 Apr 2017 10:51:47 +0000 (12:51 +0200)] 
util: ignore -Wcast-align in virNetlinkDumpCommand

Similar to commit b202c39 ignore the warning that breaks the build
with clang:
util/virnetlink.c:365:52: error: cast from 'char *' to 'struct nlmsghdr *'
 increases required alignment from 1 to 4 [-Werror,-Wcast-align]
        for (msg = resp; NLMSG_OK(msg, len); msg = NLMSG_NEXT(msg, len)) {
                                                   ^~~~~~~~~~~~~~~~~~~~
/usr/include/linux/netlink.h:87:7: note: expanded from macro 'NLMSG_NEXT'
         (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(cherry picked from commit 04be4111d90193016a390ecdd144bc80fa5667ef)

8 years agoqemu: hotplug: Clear vcpu ordering for coldplug of vcpus
Peter Krempa [Fri, 31 Mar 2017 11:05:47 +0000 (13:05 +0200)] 
qemu: hotplug: Clear vcpu ordering for coldplug of vcpus

Vcpu order is required to stay sequential. Clear the order on cpu
coldplug to avoid issues with removing vcpus out of sequence.

(cherry picked from commit b416a33a6f49b7755a65d0de4ee09c770b79cc8d)

8 years agoqemu: hotplug: Fix formatting strings in qemuDomainFilterHotplugVcpuEntities
Peter Krempa [Fri, 31 Mar 2017 11:28:19 +0000 (13:28 +0200)] 
qemu: hotplug: Fix formatting strings in qemuDomainFilterHotplugVcpuEntities

'next' is declared as 'ssize_t' so use '%zd'

(cherry picked from commit 86d69c309181ed7782427261abd85a4b3fdc704f)

8 years agoqemu: hotplug: Iterate over vcpu 0 in individual vcpu hotplug code
Peter Krempa [Fri, 31 Mar 2017 11:02:14 +0000 (13:02 +0200)] 
qemu: hotplug: Iterate over vcpu 0 in individual vcpu hotplug code

Buggy condition meant that vcpu0 would not be iterated in the checks.
Since it's not hotpluggable anyways we would not be able to break the
configuration of a live VM.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1437013
(cherry picked from commit 315f443dbb9f821fb207c30585e01dfbaac01878)

8 years agoqemu: Add device id for mediated devices on qemu command line
Erik Skultety [Mon, 3 Apr 2017 14:10:00 +0000 (16:10 +0200)] 
qemu: Add device id for mediated devices on qemu command line

Like all devices, add the 'id' option for mdevs as well. Patch also
adjusts the test accordingly.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
(cherry picked from commit c3272e5e12e0bfd43b8101b73ae13d264c13337f)

8 years agostorage: Fix capacity value for LUKS encrypted volumes
John Ferlan [Fri, 24 Mar 2017 13:26:17 +0000 (09:26 -0400)] 
storage: Fix capacity value for LUKS encrypted volumes

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

The 'capacity' value (e.g. guest logical size) for a LUKS volume is
smaller than the 'physical' value of the file in the file system, so
we need to account for that.

When peeking at the encryption information about the volume add a fetch
of the payload_offset which is described as the offset to the start of
the volume data (in 512 byte sectors) in QEMU's QCryptoBlockLUKSHeader.

Then adjust the ->capacity appropriately when we determine that the
volume target encryption has a payload_offset value.

(cherry picked from commit b7d44f450c06803df7df3ad380f7a5c97425c1e6)

8 years agovirNetDevIPCheckIPv6ForwardingCallback fixes
Cédric Bosdonnat [Tue, 28 Mar 2017 14:00:24 +0000 (16:00 +0200)] 
virNetDevIPCheckIPv6ForwardingCallback fixes

Add check for more than one RTA_OIF, even though this is rather
unlikely.

Get rid of the buggy switch / break as this code won't need to
handle more attributes.

Use VIR_WARNINGS_NO_CAST_ALIGN to fix impossible to fix
util/virnetdevip.c:560:17: error: cast increases required alignment of target type [-Werror=cast-align]

(cherry picked from commit b202c39adc5c512037bd38c195585a1b93fe136f)

8 years agostorage: driver: Remove unavailable transient pools after restart
Peter Krempa [Thu, 30 Mar 2017 11:47:45 +0000 (13:47 +0200)] 
storage: driver: Remove unavailable transient pools after restart

If a transient storage pool is deemed inactive after libvirtd restart it
would not be deleted from the list. Reuse virStoragePoolUpdateInactive
along with a refactor necessary to properly update the state.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1242801
(cherry picked from commit f3a8e80c130513c2b488df5a561c788133148685)

8 years agostorage: driver: Split out code fixing pool state after deactivation
Peter Krempa [Thu, 30 Mar 2017 11:45:45 +0000 (13:45 +0200)] 
storage: driver: Split out code fixing pool state after deactivation

After a pool is made inactive the definition objects need to be updated
(if a new definition is prepared) and transient pools need to be
completely removed. Split out the code doing these steps into a separate
function for later reuse.

(cherry picked from commit aced6b23560b7d697069b0d81cfab230e2b20c47)

8 years agostorage: backend: Use correct stringifier for pool type
Peter Krempa [Thu, 30 Mar 2017 08:13:36 +0000 (10:13 +0200)] 
storage: backend: Use correct stringifier for pool type

When registering a storage poll backend, the code would use
virStorageTypeToString instead of virStoragePoolTypeToString. The
following message would be logged:

virDriverLoadModuleFunc:71 : Lookup function 'virStorageBackendSCSIRegister'
virStorageBackendRegister:174 : Registering storage backend '(null)'
(cherry picked from commit 894133a3bd88fadb950042aec1e9edda0a640f83)

8 years agomdev: Fix daemon crash on domain shutdown after reconnect
Erik Skultety [Fri, 28 Apr 2017 07:24:31 +0000 (09:24 +0200)] 
mdev: Fix daemon crash on domain shutdown after reconnect

The problem resides in virHostdevUpdateActiveMediatedDevices which gets
called during qemuProcessReconnect. The issue here is that
virMediatedDeviceListAdd takes a pointer to the item to be added to the
list to which VIR_APPEND_ELEMENT is used, which also clears the pointer.
However, in this case only the local copy of the pointer got cleared,
leaving the original pointing to valid memory. To sum it up, during
cleanup phase, the original pointer is freed and the daemon crashes
basically any time it would access it.

Backtrace:
0x00007ffff3ccdeba in __strcmp_sse2_unaligned
0x00007ffff72a444a in virMediatedDeviceListFindIndex
0x00007ffff7241446 in virHostdevReAttachMediatedDevices
0x00007fffc60215d9 in qemuHostdevReAttachMediatedDevices
0x00007fffc60216dc in qemuHostdevReAttachDomainDevices
0x00007fffc6046e6f in qemuProcessStop
0x00007fffc6091596 in processMonitorEOFEvent
0x00007fffc6091793 in qemuProcessEventHandler
0x00007ffff7294bf5 in virThreadPoolWorker
0x00007ffff7294184 in virThreadHelper
0x00007ffff3fdc3c4 in start_thread () from /lib64/libpthread.so.0
0x00007ffff3d269cf in clone () from /lib64/libc.so.6

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

(cherry picked from commit 92e30a4dace54d06433f763e1acba0a81bb5c82e)
Signed-off-by: Erik Skultety <eskultet@redhat.com>
8 years agoutil: mdev: Use a local variable instead of a direct pointer access
Erik Skultety [Fri, 28 Apr 2017 05:52:52 +0000 (07:52 +0200)] 
util: mdev: Use a local variable instead of a direct pointer access

Use a local variable to hold data, rather than accessing the pointer
after calling virMediatedDeviceListAdd (therefore VIR_APPEND_ELEMENT).
Although not causing an issue at the moment, this change is a necessary
prerequisite for tweaking virMediatedDeviceListAdd in a separate patch,
which will take a reference for the source pointer (instead of pointer
value) and will clear it along the way.

(cherry picked from commit 2739a983f235f0d92d210800d61bd1a195f01850)
Signed-off-by: Erik Skultety <eskultet@redhat.com>
8 years agoqemu: Fix regression when hyperv/vendor_id feature is used
Jiri Denemark [Thu, 6 Apr 2017 11:52:30 +0000 (13:52 +0200)] 
qemu: Fix regression when hyperv/vendor_id feature is used

qemuProcessVerifyHypervFeatures is supposed to check whether all
requested hyperv features were actually honored by QEMU/KVM. This is
done by checking the corresponding CPUID bits reported by the virtual
CPU. In other words, it doesn't work for string properties, such as
VIR_DOMAIN_HYPERV_VENDOR_ID (there is no CPUID bit we could check). We
could theoretically check all 96 bits corresponding to the vendor
string, but luckily we don't have to check the feature at all. If QEMU
is too old to support hyperv features, the domain won't even start.
Otherwise, it is always supported.

Without this patch, libvirt refuses to start a domain which contains

  <features>
    <hyperv>
      <vendor_id state='on' value='...'/>
    </hyperv>
  </features>

reporting internal error: "unknown CPU feature __kvm_hv_vendor_id.

This regression was introduced by commit v3.1.0-186-ge9dbe7011, which
(by fixing the virCPUDataCheckFeature condition in
qemuProcessVerifyHypervFeatures) revealed an old bug in the feature
verification code. It's been there ever since the verification was
implemented by commit v1.3.3-rc1-5-g95bbe4bf5, which effectively did not
check VIR_DOMAIN_HYPERV_VENDOR_ID at all.

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

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

8 years agovz: fix typo that breaks build
Nikolay Shirokovskiy [Tue, 4 Apr 2017 10:02:21 +0000 (13:02 +0300)] 
vz: fix typo that breaks build

(cherry picked from commit 609cc5a8807f321f5805ca41fc16b56637e2bc66)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agoRelease of libvirt-3.2.0 v3.2.0
Daniel Veillard [Sun, 2 Apr 2017 14:59:37 +0000 (16:59 +0200)] 
Release of libvirt-3.2.0

* docs/news.xml: update for release
* po/*.po*: regenerated

8 years agodocs: bhyve: fix typo
Roman Bogorodskiy [Sat, 1 Apr 2017 14:27:29 +0000 (18:27 +0400)] 
docs: bhyve: fix typo

USB tables -> USB tablet.

8 years agohyperv: fixed typo in function name
Dawid Zamirski [Thu, 30 Mar 2017 16:47:18 +0000 (12:47 -0400)] 
hyperv: fixed typo in function name

that is: s/hyperyVerifyResponse/hypervVerifyResponse/

8 years agoDocument virDomainAbortJob behavior for post-copy migration
Jiri Denemark [Fri, 31 Mar 2017 18:41:39 +0000 (20:41 +0200)] 
Document virDomainAbortJob behavior for post-copy migration

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
8 years agoadmin: Throw a system error when 'open' fails on user-provided output
Erik Skultety [Fri, 31 Mar 2017 08:05:08 +0000 (10:05 +0200)] 
admin: Throw a system error when 'open' fails on user-provided output

There was an unhandled 'open' call which resulted in:

"error: Library function returned error but did not set virError"

Even if this happens during the daemon's start when we still don't have
any set of outputs defined yet, we can safely report an error, since we
automatically fallback to stderr which is fine even for both
running as a daemonized process, since this happens before the daemon
forks into the background, and running as a systemd service, since
systemd re-directs std outputs to journald by default.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
8 years agonews: Add template for a <release> section
Peter Krempa [Fri, 31 Mar 2017 07:48:42 +0000 (09:48 +0200)] 
news: Add template for a <release> section

After the release it's necessary to add a new <release> section for the
upcoming release. Add a template so that it does not have to be
compiled over and over again.

8 years agoqemuDomainSnapshotPrepare: Don't always assume vm->def->os.loader
Michal Privoznik [Thu, 30 Mar 2017 12:03:45 +0000 (14:03 +0200)] 
qemuDomainSnapshotPrepare: Don't always assume vm->def->os.loader

In 9e2465834 a check that denies internal snapshots when pflash
based loader is configured for the domain. However, if there's
none and an user tries to do an internal snapshot they will
witness daemon crash as in that case vm->def->os.loader is NULL
and we dereference it unconditionally.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agoqemu: Check non-migratable host CPU features v3.2.0-rc2
Jiri Denemark [Wed, 29 Mar 2017 09:00:32 +0000 (11:00 +0200)] 
qemu: Check non-migratable host CPU features

CPU features which change their value from disabled to enabled between
two calls to query-cpu-model-expansion (the first with no extra
properties set and the second with 'migratable' property set to false)
can be marked as enabled and non-migratable in qemuMonitorCPUModelInfo.

Since the code consuming qemuMonitorCPUModelInfo currently ignores the
migratable flag, this change is effectively changing the CPU model
advertised in domain capabilities to contain all features (even those
which block migration). And this matches what we do for QEMU older than
2.9.0, when we detect all CPUID bits ourselves without asking QEMU.

As a result of this change

    <cpu mode='host-model'>
      <feature name='invtsc' policy='require'/>
    </cpu>

will work with all QEMU versions. Such CPU definition would be forbidden
with QEMU >= 2.9.0 without this patch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
8 years agoqemu: Check migratable host CPU features
Jiri Denemark [Wed, 29 Mar 2017 08:58:41 +0000 (10:58 +0200)] 
qemu: Check migratable host CPU features

If calling query-cpu-model-expansion on the 'host'/'max' CPU model with
'migratable' property set to false succeeds, we know QEMU is able to
tell us which features would disable migration. Thus we can mark all
enabled features as migratable.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>