]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
7 years agoqemu: hot-plug of watchdog
Michal Privoznik [Fri, 1 Sep 2017 11:39:15 +0000 (13:39 +0200)]
qemu: hot-plug of watchdog

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

Since domain can have at most one watchdog it simplifies things a
bit. However, since we must be able to set the watchdog action as
well, new monitor command needs to be used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoqemuDomainDeviceDefValidate: Validate watchdog
Michal Privoznik [Wed, 27 Sep 2017 11:45:07 +0000 (13:45 +0200)]
qemuDomainDeviceDefValidate: Validate watchdog

Currently we don't do it. Therefore we accept senseless
combinations of models and buses they are attached to.
Moreover, diag288 watchdog is exclusive to s390(x).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agodocs,rng: Adjust storage pool name grammar checks
John Ferlan [Tue, 3 Oct 2017 11:14:04 +0000 (07:14 -0400)]
docs,rng: Adjust storage pool name grammar checks

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

It's possible to define and start a pool with a '.' in the
name; however, when trying to add a volume to a domain using
the storage pool source with a '.' in the storage pool name,
the domain RNG validation fails because RNG uses 'genericName'
which does not allow a '.' in the name.

Domain XML def parsing has a virXMLValidateAgainstSchema which
generates the error. The Storage Pool XML def parsing has no
call to virXMLValidateAgainstSchema. The only Storage Pool name
validation occurs in virStoragePoolDefParseXML to ensure the
name doesn't have a '/' in it and in storagePoolDefineXML to
call virXMLCheckIllegalChars using the same parameter "\n" as
qemuDomainDefineXMLFlags would check after the RNG check
could be succesful.

In order to resolve this, create a poolName definition in
storagecommon.rng that will mimic the domain name regex that
disallows a newline character, but add the "/" in the exclude
list. Then modify the pool and volume source name definitions
to key off that poolName.

7 years agotests: qemuxml2xml: Simplify adding to the status XML expect string generator
Peter Krempa [Tue, 26 Sep 2017 15:11:16 +0000 (17:11 +0200)]
tests: qemuxml2xml: Simplify adding to the status XML expect string generator

Unindent the static XML block and move around the autoindent calls so
that further additions don't have to add more of them.

Also rename the string holding the static XML section.

7 years agoqemu: driver: Save status XML when starting a block job
Peter Krempa [Wed, 27 Sep 2017 15:50:31 +0000 (17:50 +0200)]
qemu: driver: Save status XML when starting a block job

Few jobs (which don't) use the 'mirror' element did not save the status
XML. It will be helpful to do so once we start tracking jobs fully.

7 years agoqemu: blockjob: Always save config XML when a blockjob is finished
Peter Krempa [Mon, 28 Aug 2017 13:36:05 +0000 (15:36 +0200)]
qemu: blockjob: Always save config XML when a blockjob is finished

For VMs with persistent config the config may change upon successful
completion of a job. Save it always if a persistent VM finishes a
blockjob. This will simplify further additions.

7 years agoqemu: blockjob: Always save status XML after block event
Peter Krempa [Mon, 28 Aug 2017 13:21:06 +0000 (15:21 +0200)]
qemu: blockjob: Always save status XML after block event

The status XML would be saved only for the copy job (in case of success)
or on failure even for other jobs. As the status contains the backing
chain data, which change after success we should always save it on
block job completion.

7 years agonews: Document domifstat and QoS changes made recently
Michal Privoznik [Thu, 5 Oct 2017 07:29:35 +0000 (09:29 +0200)]
news: Document domifstat and QoS changes made recently

In cea3715b2e9 and d86fd2402e9d2 I've fixed domifstat and QoS
that was reversed for some types of interfaces. Document this
in the news file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agospec: Enable qemu driver on s390x on RHEL/CentOS
Jiri Denemark [Thu, 5 Oct 2017 07:17:06 +0000 (09:17 +0200)]
spec: Enable qemu driver on s390x on RHEL/CentOS

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoqemu: process: move disk presence checking to host setup function
Peter Krempa [Tue, 3 Oct 2017 10:38:19 +0000 (12:38 +0200)]
qemu: process: move disk presence checking to host setup function

Checking of disk presence accesses storage on the host so it should be
done from the host setup function. Move the code to new function called
qemuProcessPrepareHostStorage and remove qemuDomainCheckDiskPresence.

7 years agoqemu: process: Move TLS setup for storage source to qemuProcessPrepareDomainStorage
Peter Krempa [Tue, 3 Oct 2017 11:16:05 +0000 (13:16 +0200)]
qemu: process: Move TLS setup for storage source to qemuProcessPrepareDomainStorage

7 years agoqemu: process: Move 'volume' translation to domain prepare stage
Peter Krempa [Tue, 3 Oct 2017 10:38:23 +0000 (12:38 +0200)]
qemu: process: Move 'volume' translation to domain prepare stage

Introduce a new function to prepare domain disks which will also do the
volume source to actual disk source translation.

The 'pretend' condition is not transferred to the new location since it
does not help in writing tests and also no tests abuse it.

7 years agoqemu: domain: Document and export qemuDomainCheckDiskStartupPolicy
Peter Krempa [Tue, 3 Oct 2017 10:51:47 +0000 (12:51 +0200)]
qemu: domain: Document and export qemuDomainCheckDiskStartupPolicy

7 years agoqemu: process: Pass flags to qemuProcessPrepareHost
Peter Krempa [Tue, 3 Oct 2017 08:14:21 +0000 (10:14 +0200)]
qemu: process: Pass flags to qemuProcessPrepareHost

Pass flags to the function rather than just whether we have incoming
migration. This also enforces correct startup policy for USB devices
when reverting from a snapshot.

7 years agoqemu: migration: Extract flags for starting VM into a variable
Peter Krempa [Tue, 3 Oct 2017 07:59:03 +0000 (09:59 +0200)]
qemu: migration: Extract flags for starting VM into a variable

qemuMigrationPrepareAny called multiple of the functions starting the
qemu process for incoming migration by adding the flags explicitly.
Extract them to a variable so that they can be easily used for other
calls or changed in the future.

7 years agoqemu: process: document parameters for startup preparing functions
Peter Krempa [Tue, 3 Oct 2017 07:51:27 +0000 (09:51 +0200)]
qemu: process: document parameters for startup preparing functions

Document mainly what flag values are passed in.

7 years agoqemu: command: Move PPC fdc check to domain validation
Peter Krempa [Tue, 3 Oct 2017 12:06:15 +0000 (14:06 +0200)]
qemu: command: Move PPC fdc check to domain validation

Apart from not littering the command line generator, the added benefit
is that new configs with a FDC will be rejected at define stage.

7 years agoqemu: command: Separate validation from command line building for -drive
Peter Krempa [Mon, 2 Oct 2017 15:13:44 +0000 (17:13 +0200)]
qemu: command: Separate validation from command line building for -drive

Remove validation code into a separate function so that it's not
interleaved with actual building of the command line.

7 years agolibvirt-domain: Document interface stats POV
Michal Privoznik [Mon, 2 Oct 2017 14:31:30 +0000 (16:31 +0200)]
libvirt-domain: Document interface stats POV

Interestingly enough, we don't document the point of view of the
interface statistics. Therefore it's unknown to users if for
instance rx_packets is the number of packets received by domain or
received by host (from domain). Document this explicitly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agoQoS: Set classes and filters in proper direction
Michal Privoznik [Mon, 2 Oct 2017 12:12:44 +0000 (14:12 +0200)]
QoS: Set classes and filters in proper direction

Similarly to previous patch, for some types of interface domain
and host are on the same side of RX/TX barrier. In that case, we
need to set up the QoS differently. Well, swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agovirNetDevTapInterfaceStats: Allow caller to not swap the statistics
Michal Privoznik [Mon, 2 Oct 2017 11:36:56 +0000 (13:36 +0200)]
virNetDevTapInterfaceStats: Allow caller to not swap the statistics

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

The comment in virNetDevTapInterfaceStats() implementation for
Linux states that packets transmitted by domain are received by
the host and vice versa. Well, this is true but not for all types
of interfaces. For instance, for macvtaps when TAP device is
hooked right onto a physical device any packet that domain sends
looks also like a packet sent to the host. Therefore, we should
allow caller to chose if the stats returned should be straight
copy or swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agosrc: Use virDomainNetFindByName
Michal Privoznik [Mon, 2 Oct 2017 13:24:39 +0000 (15:24 +0200)]
src: Use virDomainNetFindByName

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoconf: Introduce virDomainNetFindByName
Michal Privoznik [Mon, 2 Oct 2017 13:04:14 +0000 (15:04 +0200)]
conf: Introduce virDomainNetFindByName

Small wrapper to lookup interface in domain definition by its
name.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoqemuDomainInterfaceStats: Check for the actual type of interface
Michal Privoznik [Mon, 2 Oct 2017 11:12:43 +0000 (13:12 +0200)]
qemuDomainInterfaceStats: Check for the actual type of interface

Users might have configured interface so that it's type of
network, but the corresponding network plugs interfaces into an
OVS bridge. Therefore, we have to check for the actual type of
the interface instead of the configured one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agolxc: Drop useless ifdef __linux__
Michal Privoznik [Mon, 2 Oct 2017 13:19:19 +0000 (15:19 +0200)]
lxc: Drop useless ifdef __linux__

This code compiles only on Linux. Therefore the condition we
check is always true.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agotests: Fix build with clang
Jiri Denemark [Thu, 5 Oct 2017 07:06:03 +0000 (09:06 +0200)]
tests: Fix build with clang

clang doesn't like mode_t type as an argument to va_arg():

error: second argument to 'va_arg' is of promotable type 'mode_t' (aka
'unsigned short'); this va_arg has undefined behavior because arguments
will be promoted to 'int'

    mode = va_arg(ap, mode_t);
                      ^~~~~~

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agostorage: Fix incorrect parenthesis placement
Pavel Hrdina [Wed, 4 Oct 2017 14:33:06 +0000 (16:33 +0200)]
storage: Fix incorrect parenthesis placement

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoqemu: Support multiqueue virtio-blk
Lin Ma [Sat, 30 Sep 2017 17:15:36 +0000 (01:15 +0800)]
qemu: Support multiqueue virtio-blk

qemu 2.7.0 introduces multiqueue virtio-blk(commit 2f27059).
This patch introduces a new attribute "queues". An example of
the XML:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' queues='4'/>

The corresponding QEMU command line:

-device virtio-blk-pci,scsi=off,num-queues=4,id=virtio-disk0

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
7 years agoqemucapstest: Update test data for 'num-queues' property of virtio-blk
Lin Ma [Sat, 30 Sep 2017 17:15:35 +0000 (01:15 +0800)]
qemucapstest: Update test data for 'num-queues' property of virtio-blk

Signed-off-by: Lin Ma <lma@suse.com>
7 years agovirDomainNetFindIdx: Ignore auto generated MAC addresses
Michal Privoznik [Mon, 2 Oct 2017 10:43:04 +0000 (12:43 +0200)]
virDomainNetFindIdx: Ignore auto generated MAC addresses

When detaching an <interface/> from a domain, the MAC address is
parsed and if not present one is generated. If no corresponding
interface is found in the domain, the following error is
reported:

error: operation failed: no device matching mac address 52:54:00:75:32:5b found

where the MAC address is the auto generated one. This might be
very confusing. Solution to this is to ignore auto generated MAC
address when looking up the device.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
7 years agovirmacaddr: Track if MAC address is autogenerated
Michal Privoznik [Mon, 2 Oct 2017 08:47:27 +0000 (10:47 +0200)]
virmacaddr: Track if MAC address is autogenerated

It will come handy to know if the MAC address was generated (e.g.
during XML parse) or if it was parsed since provided by user in
the XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
7 years agoqemuParseCommandLineNet: Make it more readable
Michal Privoznik [Fri, 29 Sep 2017 14:12:19 +0000 (16:12 +0200)]
qemuParseCommandLineNet: Make it more readable

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
7 years agonwfilter: Fix memory leak and error path
John Ferlan [Fri, 29 Sep 2017 13:21:47 +0000 (09:21 -0400)]
nwfilter: Fix memory leak and error path

Found by Coverity. If virNWFilterHashTablePut, then the 3rd arg @val
must be free'd since it would be leaked.

This also fixes potential problem on the error path where the caller
could assume the virNWFilterHashTablePut was successful when in fact
it failed leading to other issues.

7 years agonwfilter: Clean up virNWFilterDetermineMissingVarsRec returns
John Ferlan [Fri, 29 Sep 2017 13:18:53 +0000 (09:18 -0400)]
nwfilter: Clean up virNWFilterDetermineMissingVarsRec returns

Rather than using loop break;'s in order to force a return
of rc = -1, let's just return -1 immediately on the various
error paths and then return 0 on the success path.

7 years agotests: Do not ignore mode parameter in mocked open()
Luyao Huang [Mon, 25 Sep 2017 18:27:07 +0000 (20:27 +0200)]
tests: Do not ignore mode parameter in mocked open()

This is normally not an issue since the tests which use mocked open() do
not create files. But once coverage build is enabled, gcov_open will use
O_CREATE and real_open will read random data rather than the actual mode
argument.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoutil: Free a pointer in virPolkitCheckAuth
Kothapally Madhu Pavan [Wed, 4 Oct 2017 08:38:45 +0000 (14:08 +0530)]
util: Free a pointer in virPolkitCheckAuth

Free DBusMessage pointer in virPolkitCheckAuth

Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
7 years agoconf: Split out parsing of network disk source XML elements
Peter Krempa [Tue, 9 May 2017 12:25:02 +0000 (14:25 +0200)]
conf: Split out parsing of network disk source XML elements

virDomainDiskSourceParse got to the point of being an ugly spaghetti
mess by adding more and more stuff into it. Split out parsing of network
disk information into a separate function so that it stays contained.

7 years agoPost-release version bump to 3.9.0
Peter Krempa [Wed, 4 Oct 2017 08:35:18 +0000 (10:35 +0200)]
Post-release version bump to 3.9.0

7 years agoRelease of libvirt-3.8.0
Daniel Veillard [Wed, 4 Oct 2017 08:20:23 +0000 (10:20 +0200)]
Release of libvirt-3.8.0

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

7 years agospec: Delay supported_platform check
Jiri Denemark [Tue, 3 Oct 2017 11:41:05 +0000 (13:41 +0200)]
spec: Delay supported_platform check

Building RPM should only be allowed on a supported platform, but
unpacking the source and applying all patches can be done anywhere.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agodocs: Document the real behaviour of suspend-to-{mem,disk}
Martin Kletzander [Fri, 29 Sep 2017 12:26:53 +0000 (14:26 +0200)]
docs: Document the real behaviour of suspend-to-{mem,disk}

We get a question every now and then about why hibernation works when
suspend-to-disk is disabled and similar.  Let's hope that, by documenting the
obvious more blatantly, people will get more informed.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
7 years agonwfilter: Don't have virNWFilterIPAddrMapAddIPAddr consume input
John Ferlan [Fri, 29 Sep 2017 19:55:29 +0000 (15:55 -0400)]
nwfilter: Don't have virNWFilterIPAddrMapAddIPAddr consume input

On pure success paths, virNWFilterIPAddrMapAddIPAddr was validly
consuming the input @addr; however, on failure paths it was possible
that virNWFilterVarValueCreateSimple succeed, but virNWFilterHashTablePut
failed resulting in virNWFilterVarValueFree being called to clean
up @val which also cleaned up the input @addr. Thus the caller had
no way to determine on failure whether it too should clean up the
passed parameter.

Instead, let's create a copy of the input @addr, then handle that
properly in the API allowing/forcing the caller to free it's own
copy of the input parameter.

7 years agoRevert "nwfilter: Fix possible segfault on sometimes consumed variable"
John Ferlan [Thu, 28 Sep 2017 19:13:46 +0000 (15:13 -0400)]
Revert "nwfilter: Fix possible segfault on sometimes consumed variable"

This reverts commit 6209bb32e5b6d8c15d55422bb4716b3b31c1c7b2.

This turns out to be the wrong adjustment

7 years agodocs: Add some changes to news.xml for this release
Martin Kletzander [Fri, 29 Sep 2017 14:48:35 +0000 (16:48 +0200)]
docs: Add some changes to news.xml for this release

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
7 years agoFix vxhs test to have stable certificate dir
Daniel P. Berrange [Thu, 28 Sep 2017 17:41:21 +0000 (18:41 +0100)]
Fix vxhs test to have stable certificate dir

The test suite has hardcoded /etc/pki/qemu as the cert dir, but this
only works if configure has --sysconfdir=/etc passed. We must set the
vxhs cert dir to a stable path in the test suite.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
7 years agoqemu: Add TLS support for Veritas HyperScale (VxHS)
Ashish Mittal [Wed, 30 Aug 2017 15:06:00 +0000 (11:06 -0400)]
qemu: Add TLS support for Veritas HyperScale (VxHS)

Alter qemu command line generation in order to possibly add TLS for
a suitably configured domain.

Sample TLS args generated by libvirt -

    -object tls-creds-x509,id=objvirtio-disk0_tls0,dir=/etc/pki/qemu,\
    endpoint=client,verify-peer=yes \
    -drive file.driver=vxhs,file.tls-creds=objvirtio-disk0_tls0,\
    file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc251,\
    file.server.type=tcp,file.server.host=192.168.0.1,\
    file.server.port=9999,format=raw,if=none,\
    id=drive-virtio-disk0,cache=none \
    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\
    id=virtio-disk0

Update the qemuxml2argvtest with a couple of examples. One for a
simple case and the other a bit more complex where multiple VxHS disks
are added where at least one uses a VxHS that doesn't require TLS
credentials and thus sets the domain disk source attribute "tls = 'no'".

Update the hotplug to be able to handle processing the tlsAlias whether
it's to add the TLS object when hotplugging a disk or to remove the TLS
object when hot unplugging a disk.  The hot plug/unplug code is largely
generic, but the addition code does make the VXHS specific checks only
because it needs to grab the correct config directory and generate the
object as the command line would do.

Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agoqemu: Introduce qemuDomainPrepareDiskSource
John Ferlan [Wed, 30 Aug 2017 19:29:59 +0000 (15:29 -0400)]
qemu: Introduce qemuDomainPrepareDiskSource

Introduce a function to setup any TLS needs for a disk source.

If there's a configuration or other error setting up the disk source
for TLS, then cause the domain startup to fail.

For VxHS, follow the chardevTLS model where if the src->haveTLS hasn't
been configured, then take the system/global cfg->haveTLS setting for
the storage source *and* mark that we've done so via the tlsFromConfig
setting in storage source.

Next, if we are using TLS, then generate an alias into a virStorageSource
'tlsAlias' field that will be used to create the TLS object and added to
the disk object in order to link the two together for QEMU.

Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agoutil: Add TLS attributes to virStorageSource
Ashish Mittal [Wed, 30 Aug 2017 15:35:34 +0000 (11:35 -0400)]
util: Add TLS attributes to virStorageSource

Add an optional virTristateBool haveTLS to virStorageSource to
manage whether a storage source will be using TLS.

Sample XML for a VxHS disk:

<disk type='network' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source protocol='vxhs' name='eb90327c-8302-4725-9e1b-4e85ed4dc251' tls='yes'>
    <host name='192.168.0.1' port='9999'/>
  </source>
  <target dev='vda' bus='virtio'/>
</disk>

Additionally add a tlsFromConfig boolean to control whether the TLS
setting was due to domain configuration or qemu.conf global setting
in order to decide whether to Format the haveTLS setting for either
a live or saved domain configuration file.

Update the qemuxml2xmltest in order to add a test to show the proper
parsing.

Also update the docs to describe the tls attribute.

Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agodocs: Clean up the description for network disk protocol options
John Ferlan [Wed, 27 Sep 2017 13:42:33 +0000 (09:42 -0400)]
docs: Clean up the description for network disk protocol options

Clean up the description a bit to make it more readable and not
appear as one long run-on paragraph.

7 years agoconf: Introduce TLS options for VxHS block device clients
Ashish Mittal [Wed, 30 Aug 2017 15:32:33 +0000 (11:32 -0400)]
conf: Introduce TLS options for VxHS block device clients

Add a new TLS X.509 certificate type - "vxhs". This will handle the
creation of a TLS certificate capability for properly configured
VxHS network block device clients.

The following describes the behavior of TLS for VxHS block device:

  (1) Two new options have been added in /etc/libvirt/qemu.conf
      to control TLS behavior with VxHS block devices
      "vxhs_tls" and "vxhs_tls_x509_cert_dir".
  (2) Setting "vxhs_tls=1" in /etc/libvirt/qemu.conf will enable
      TLS for VxHS block devices.
  (3) "vxhs_tls_x509_cert_dir" can be set to the full path where the
      TLS CA certificate and the client certificate and keys are saved.
      If this value is missing, the "default_tls_x509_cert_dir" will be
      used instead. If the environment is not configured properly the
      authentication to the VxHS server will fail.

Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agonwfilter: Fix possible segfault on sometimes consumed variable
John Ferlan [Wed, 27 Sep 2017 14:06:50 +0000 (10:06 -0400)]
nwfilter: Fix possible segfault on sometimes consumed variable

The virNWFilterIPAddrMapAddIPAddr code can consume the @addr parameter
on success when the @ifname is found in the ipAddressMap->hashTable
hash table in the call to virNWFilterVarValueAddValue; however, if
not found in the hash table, then @addr is formatted into a @val
which is stored in the table and on return the caller would be
expected to free @addr.

Thus, the caller has no way to determine on success whether @addr was
consumed, so in order to fix this create a @tmp variable which will
be stored/consumed when virNWFilterVarValueAddValue succeeds. That way
the caller can free @addr whether the function returns success or failure.

7 years agorpc: for messages with FDs always decode count of FDs from the message
Pavel Hrdina [Tue, 26 Sep 2017 14:47:20 +0000 (16:47 +0200)]
rpc: for messages with FDs always decode count of FDs from the message

The packet with passed FD has the following format:

    --------------------------
    | len | header | payload |
    --------------------------

where "payload" has an additional count of FDs before the actual data:

    ------------------
    | nfds | payload |
    ------------------

When the packet is received we parse the "header", which as a side
effect updates msg->bufferOffset to point to the beginning of "payload".
If the message call contains FDs, we need to also parse the count of
FDs, which also updates the msg->bufferOffset.

The issue here is that when we attempt to read the FDs data from the
socket and we receive EAGAIN we finish the reading and call poll()
to wait for the data the we need.  When the data arrives we already have
the packet in our buffer so we read the "header" again but this time
we don't read the count of FDs because we already have it stored.

That means that the msg->bufferOffset is not updated to point to the
actual beginning of the payload data, but it points to the count of
FDs.  After all FDs are processed we dispatch the message to process
it and decode the payload.  Since the msg->bufferOffset points to wrong
data, we decode the wrong payload and the API call fails with
error messages:

    Domain not found: no domain with matching uuid '67656e65-7269-6300-0c87-5003ca6941f2' ()

Broken by commit 133c511b527 which fixed a FD and memory leak.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoqemu: domain: Extract common clearing of VM private data
Peter Krempa [Wed, 23 Aug 2017 12:19:36 +0000 (14:19 +0200)]
qemu: domain: Extract common clearing of VM private data

VM private data is cleared when the VM is turned off and also when the
VM object is being freed. Some of the clearing code was duplicated.
Extract it to a separate function.

This also removes the now unnecessary function
qemuDomainClearPrivatePaths.

7 years agodocs: Add the closing </address> tag for mdev example
Erik Skultety [Wed, 27 Sep 2017 13:08:53 +0000 (15:08 +0200)]
docs: Add the closing </address> tag for mdev example

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agoShrink volume even with ALLOCATE flag
Ján Tomko [Tue, 16 Aug 2016 10:29:05 +0000 (12:29 +0200)]
Shrink volume even with ALLOCATE flag

Calling fallocate on the new (smaller) capacity ensures
that the whole file is allocated, but it does not reduce
the file size.

Also call ftruncate after fallocate.

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

7 years agovirStorageFileResize: fallocate the whole capacity
Ján Tomko [Mon, 25 Sep 2017 14:35:42 +0000 (16:35 +0200)]
virStorageFileResize: fallocate the whole capacity

We have been trying to implement the ALLOCATE flag to mean
"the volume should be fully allocated after the resize".

Since commit b0579ed9 we do not allocate from the existing
capacity, but from the existing allocation value.
However this value is a total of all the allocated bytes,
not an offset.

For a sparsely allocated file:
$ perl -e 'print "x"x8192;' > vol1
$ fallocate -p -o 0 -l 4096 vol1
$ virsh vol-info vol1 default
Capacity:       8.00 KiB
Allocation:     4.00 KiB

Treating allocation as an offset would result in an incompletely
allocated file:
$ virsh vol-resize vol1 --pool default 16384 --allocate
Capacity:       16.00 KiB
Allocation:     12.00 KiB

Call fallocate from zero on the whole requested capacity to fully
allocate the file. After that, the volume is fully allocated
after the resize:
$ virsh vol-resize vol1 --pool default 16384 --allocate
$ virsh vol-info vol1 default
Capacity:       16.00 KiB
Allocation:     16.00 KiB

7 years agouse virFileAllocate in virStorageFileResize
Ján Tomko [Mon, 25 Sep 2017 14:29:34 +0000 (16:29 +0200)]
use virFileAllocate in virStorageFileResize

Introduce a new function virFileAllocate that will call the
non-destructive variants of safezero, essentially reverting
my commit 1390c268
    safezero: fall back to writing zeroes even when resizing
back to the state as of commit 18f0316
    virstoragefile: Have virStorageFileResize use safezero

This means that _ALLOCATE flag will no longer work on platforms
without the allocate syscalls, but it will not overwrite data
either.

7 years agovirsh: Add/allow secret-uuid for pool-{define|create}-as
John Ferlan [Tue, 5 Sep 2017 17:44:15 +0000 (13:44 -0400)]
virsh: Add/allow secret-uuid for pool-{define|create}-as

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

For the virsh pool-{define|create}-as command, let's allow using
--secret-uuid on the command line as an alternative to --secret-usage
(added for commit id '8932580'), but ensure that they are mutually
 exclusive.

7 years agonwfilter: Fix memory leak in learnIPAddressThread
ZhiPeng Lu [Wed, 27 Sep 2017 01:01:39 +0000 (09:01 +0800)]
nwfilter: Fix memory leak in learnIPAddressThread

Don't leak @inetaddr within the done: processing when attempting
to instantiate the filter.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
7 years agonwfilter: Fix memory leak in virNWFilterIPAddrMapAddIPAddr
ZhiPeng Lu [Wed, 27 Sep 2017 08:53:50 +0000 (16:53 +0800)]
nwfilter: Fix memory leak in virNWFilterIPAddrMapAddIPAddr

If virNWFilterHashTablePut fails, then the @val was leaked.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
7 years agoqemu: fix hotplug of udp device with no connect host
Ján Tomko [Tue, 26 Sep 2017 11:56:36 +0000 (13:56 +0200)]
qemu: fix hotplug of udp device with no connect host

Use an empty string to let qemu fill out the default.
This matches what's done in qemuBuildChrChardevStr.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoRevert "vhost-user: add support reconnect for vhost-user ports"
Pavel Hrdina [Wed, 20 Sep 2017 13:59:18 +0000 (15:59 +0200)]
Revert "vhost-user: add support reconnect for vhost-user ports"

This reverts commit edaf4ebe95a5995585c8ab7bc5b92887286d4431.

This uses "reconnect" as attribute for <source> element, but we already
have a <reconnect> element for <source> element for chardev devices.

Since this is the same feature for different device it should be
presented in XML the same way.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoqemu: process: Refresh data from qemu monitor after migration
Peter Krempa [Mon, 25 Sep 2017 14:16:08 +0000 (16:16 +0200)]
qemu: process: Refresh data from qemu monitor after migration

Some values we read from the qemu monitor may be changed with the actual
state by the incoming migration. This means that we should refresh
certain things only after the migration has finished.

This is mostly visible in the cdrom tray state, which is by default
closed but may be opened by the guest OS. This would be refreshed before
qemu transferred the actual state and thus libvirt would think that the
tray is closed.

Note that this patch moves only a few obvious query commands. Others may
be moved later after individual assessment.

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

7 years agoqemu: hotplug: Ignore cgroup errors when hot-unplugging vcpus
Peter Krempa [Mon, 25 Sep 2017 20:34:44 +0000 (22:34 +0200)]
qemu: hotplug: Ignore cgroup errors when hot-unplugging vcpus

When the vcpu is successfully removed libvirt would remove the cgroup.
In cases when removal of the cgroup fails libvirt would report an error.

This does not make much sense, since the vcpu was removed and we can't
really do anything with the cgroup. This patch silences the errors from
cgroup removal.

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

7 years agoqemu: adjust indentation of qemuDomainObjPrivateXMLFormatAutomaticPlacement
Ján Tomko [Tue, 26 Sep 2017 15:10:51 +0000 (17:10 +0200)]
qemu: adjust indentation of qemuDomainObjPrivateXMLFormatAutomaticPlacement

Commit 6801da94 fixed the typo in the function name, but forgot
to adjust the indentation level of the next line.

7 years agoqemu: domain: Fix typo in qemuDomainObjPtrivateXMLFormatAutomaticPlacement
Peter Krempa [Tue, 26 Sep 2017 14:36:48 +0000 (16:36 +0200)]
qemu: domain: Fix typo in qemuDomainObjPtrivateXMLFormatAutomaticPlacement

7 years agoconf: fix formatting of udp chardev attributes
Ján Tomko [Tue, 26 Sep 2017 11:30:10 +0000 (13:30 +0200)]
conf: fix formatting of udp chardev attributes

It is possible (although possibly not very useful) to leave out
the service attribute when using <source mode='bind'/>

Fix the formatter bug introduced by commit 4a0da34 and format
the host when its present (checked for non-NULL inside
virBufferEscapeString) instead of basing it on the presence
of the service attribute.

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

7 years agoqemu: block: Use correct alias when extracting disk node names
Peter Krempa [Mon, 25 Sep 2017 09:44:00 +0000 (11:44 +0200)]
qemu: block: Use correct alias when extracting disk node names

The alias recorded in disk->info.alias is the alias for the frontend
device but we are interested in the backend drive. This messed up the
disk node name extraction code as qemu reports the drive alias in the
block query commands. This was broken in the node name detector
refactoring done in commit 0175dc6ea024d

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

7 years agoqemu: block: Don't lookup node names if they are already known
Peter Krempa [Mon, 25 Sep 2017 09:39:55 +0000 (11:39 +0200)]
qemu: block: Don't lookup node names if they are already known

Move the check that skips node name detection if they are already
present earlier so that the hash table lookup is skipped.

7 years agoPrint hex values with '0x' prefix and octal with '0' in debug messages
Daniel P. Berrange [Mon, 25 Sep 2017 10:43:33 +0000 (11:43 +0100)]
Print hex values with '0x' prefix and octal with '0' in debug messages

Seeing a log message saying 'flags=93' is ambiguous & confusing unless
you happen to know that libvirt always prints flags as hex.  Change our
debug messages so that they always add a '0x' prefix when printing flags,
and '0' prefix when printing mode. A few other misc places gain a '0x'
prefix in error messages too.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
7 years agoapparmor: support ptrace checks
Jim Fehlig [Fri, 22 Sep 2017 23:02:42 +0000 (17:02 -0600)]
apparmor: support ptrace checks

Kernel 4.13 introduced finer-grained ptrace checks

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?h=v4.13.2&id=290f458a4f16f9cf6cb6562b249e69fe1c3c3a07

With kernel 4.13 and apparmor 2.11, simply starting libvirtd
results in the following apparmor denial

type=AVC msg=audit(1506112085.645:954): apparmor="DENIED"
operation="ptrace" profile="/usr/sbin/libvirtd" pid=6984
comm="libvirtd" requested_mask="trace" denied_mask="trace"
peer="unconfined"

Attempting to start an unconfined domain results in

type=AVC msg=audit(1506112301.227:1112): apparmor="DENIED"
operation="ptrace" profile="/usr/sbin/libvirtd" pid=7498
comm="libvirtd" requested_mask="trace" denied_mask="trace"
peer="/usr/sbin/libvirtd"

And attempting to start a confined domain results in

type=AVC msg=audit(1506112631.408:1312): apparmor="DENIED"
operation="open" profile="virt-aa-helper" name="/etc/libnl/classid"
pid=8283 comm="virt-aa-helper" requested_mask="r" denied_mask="r"
fsuid=0 ouid=0
type=AVC msg=audit(1506112631.530:1319): apparmor="DENIED"
operation="open" profile="virt-aa-helper" name="/etc/libnl/classid"
pid=8289 comm="virt-aa-helper" requested_mask="r" denied_mask="r"
fsuid=0 ouid=0
type=AVC msg=audit(1506112632.186:1324): apparmor="DENIED"
operation="ptrace" profile="/usr/sbin/libvirtd" pid=8342
comm="libvirtd" requested_mask="trace" denied_mask="trace"
peer="libvirt-66154842-e926-4f92-92f0-1c1bf61dd1ff"

Add ptrace rules to allow the trace operations.

Resolves: https://bugzilla.suse.com/show_bug.cgi?id=1058847
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Guido Günther <agx@sigxcpu.org>
7 years agonews: remove kernel version reference from switchdev entry
Ján Tomko [Wed, 20 Sep 2017 13:23:47 +0000 (15:23 +0200)]
news: remove kernel version reference from switchdev entry

The functionality was added in 4.8, but due to a rename of
the DEVLINK_CMD_ESWITCH_GET constant in the kernel headers,
the headers from kernel 4.11 are required by the libvirt code.

Remove the reference from the news entry, since it could be
misleading.

7 years agoqemu: capabilities: Remove support for downstream-only QMP monitor backport
Peter Krempa [Wed, 20 Sep 2017 08:45:23 +0000 (10:45 +0200)]
qemu: capabilities: Remove support for downstream-only QMP monitor backport

Some distros (see diff) chose to backport QMP support rather than rebase
to newer version of qemu. As a hack they added the string 'libvirt' to
the qemu -help output. Remove this as downstream-only hacks should be
carried by downstream and not litter upstream.

This effectively reverts commit ff88cd590572277f10ecee4ebb1174d9b70fc0d7

7 years agoqemu: Use qemuDomainDefFormatXML in qemuDomainDefCopy
Jiri Denemark [Fri, 15 Sep 2017 14:32:00 +0000 (16:32 +0200)]
qemu: Use qemuDomainDefFormatXML in qemuDomainDefCopy

Because qemuDomainDefCopy needs a string representation of a domain
definition, there's no reason for calling the lower level
qemuDomainDefFormatBuf API.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoqemu: Fix error checking in qemuDomainDefFormatXMLInternal
Jiri Denemark [Fri, 15 Sep 2017 14:41:18 +0000 (16:41 +0200)]
qemu: Fix error checking in qemuDomainDefFormatXMLInternal

virDomainDefFormatInternal (called by qemuDomainDefFormatXMLInternal)
already checks for buffer errors and properly resets the buffer on
failure.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agolibvirt_nss.c: Fix typo in aiforaf()
Michal Privoznik [Fri, 22 Sep 2017 10:41:51 +0000 (12:41 +0200)]
libvirt_nss.c: Fix typo in aiforaf()

In my previous commit of b1d87f9ad96f I've made a typo breaking
the FreeBSD build. s/ipAaddr/ipAddr/

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agoapparmor: delete profile on VM shutdown
Guido Günther [Mon, 18 Sep 2017 19:23:25 +0000 (21:23 +0200)]
apparmor: delete profile on VM shutdown

instead of only unloading it. This makes sure old profiles don't pile up
in /etc/apparmor.d/libvirt and we get updates to modified templates on
VM restart.

Reviewed-by: Jim Fehlig <jfehlig@suse.com>
7 years agoutil: Fix stack smashing in virNetDevGetFamilyId
Laine Stump [Thu, 21 Sep 2017 17:57:30 +0000 (13:57 -0400)]
util: Fix stack smashing in virNetDevGetFamilyId

After commit 8708ca01c0d libvirtd consistently aborts with "stack
 smashing detected" when nodedev driver is initialized.

This is caused by nlmsg_parse() being told that its array of nlattr*
has CTRL_CMD_MAX (10) entries, when in fact it is declared to have
CTRL_ATTR_MAX (8) entries. Since all the entries are initialized to
NULL, the result is that nlmsg_parse is overwriting 2*(sizof(nlattr*))
bytes outside the array.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agonss: Don't leak @ipAddr
Michal Privoznik [Thu, 21 Sep 2017 15:47:45 +0000 (17:47 +0200)]
nss: Don't leak @ipAddr

In aiforaf() (which exists only when building for BSD) the
@ipAddr may be leaked.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agoutil: Fix secret generation in virStorageSourceParseRBDColonString
John Ferlan [Fri, 15 Sep 2017 19:21:35 +0000 (15:21 -0400)]
util: Fix secret generation in virStorageSourceParseRBDColonString

Commit id '5604c056' used the wrong API to generate the
<secret type='%s'..." field. The previous code used the
correct API as was done in commit id '6887af39'. The data
is actually a usage type not an auth type even though the
result is the same.

7 years agoutil: Move virSecretUsageType to virsecret.h
John Ferlan [Fri, 15 Sep 2017 18:55:46 +0000 (14:55 -0400)]
util: Move virSecretUsageType to virsecret.h

Move the virSecretUsageType into the util.

7 years agoqemu: Avoid a possible NULL pointer deref in qemuDomainGetTLSObjects
Ashish Mittal [Wed, 20 Sep 2017 12:32:29 +0000 (05:32 -0700)]
qemu: Avoid a possible NULL pointer deref in qemuDomainGetTLSObjects

Passing a NULL value for the argument secAlias to the function
qemuDomainGetTLSObjects would cause a segmentation fault in
libvirtd.

Changed code to check before dereferencing a NULL secAlias.

Signed-off-by: Ashish Mittal <ashmit602@gmail.com>
7 years agotests: Add QEMU 2.10.0 capabilities test for s390x
Boris Fiuczynski [Tue, 19 Sep 2017 14:06:11 +0000 (16:06 +0200)]
tests: Add QEMU 2.10.0 capabilities test for s390x

Adding s390x qemu caps test for qemu version 2.10.0.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
7 years agoqemu: Introduce a wrapper over virFileWrapperFdClose
Michal Privoznik [Thu, 14 Sep 2017 14:28:34 +0000 (16:28 +0200)]
qemu: Introduce a wrapper over virFileWrapperFdClose

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

When migrating to a file (e.g. when doing 'virsh save file'),
couple of things are happening in the thread that is executing
the API:

1) the domain obj is locked
2) iohelper is spawned as a separate process to handle all I/O
3) the thread waits for iohelper to finish
4) the domain obj is unlocked

Now, the problem is that while the thread waits in step 3 for
iohelper to finish this may take ages because iohelper calls
fdatasync(). And unfortunately, we are waiting the whole time
with the domain locked. So if another thread wants to jump in and
say copy the domain name ('virsh list' for instance), they are
stuck.

The solution is to unlock the domain whenever waiting for I/O and
lock it back again when it finished.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoqemu: Be more selective when determining cdrom for taint messaging
John Ferlan [Mon, 11 Sep 2017 12:35:05 +0000 (08:35 -0400)]
qemu: Be more selective when determining cdrom for taint messaging

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

Commit id '99a2d6af2' was a bit too aggressive with determining whether
the provided path was a "physical" cd-rom in order to generate a taint
message due to the possibility of some guest and host trying to control
the tray. For cd-rom guest devices backed to some VIR_STORAGE_TYPE_FILE
storage, this wouldn't be a problem and as such it shouldn't be a problem
for guest devices using some sort of block device on the host such as
iSCSI, LVM, or a Disk pool would present.

So before issuing a taint message, let's check if the provided path of
the VIR_STORAGE_TYPE_BLOCK backed device is a "known" physical cdrom name
by comparing the beginning of the path w/ "/dev/cdrom" and "/dev/sr".
Also since it's possible the provided path could resolve to some /dev/srN
device, let's get that path as well and perform the same check.

Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agoqemuBuildHostNetStr: Don't leak @addr
Michal Privoznik [Thu, 21 Sep 2017 12:52:58 +0000 (14:52 +0200)]
qemuBuildHostNetStr: Don't leak @addr

The virSocketAddrFormat() allocates the string and it's caller
responsibility to free it afterwards.

==28857== 11 bytes in 1 blocks are definitely lost in loss record 37 of 168
==28857==    at 0x4C2BEDF: malloc (vg_replace_malloc.c:299)
==28857==    by 0x9A81D79: strdup (in /lib64/libc-2.23.so)
==28857==    by 0x5DA3BF0: virStrdup (virstring.c:902)
==28857==    by 0x5D96182: virSocketAddrFormatFull (virsocketaddr.c:427)
==28857==    by 0x5D95E13: virSocketAddrFormat (virsocketaddr.c:352)
==28857==    by 0x5706890: qemuBuildHostNetStr (qemu_command.c:3891)
==28857==    by 0x57138D3: qemuBuildInterfaceCommandLine (qemu_command.c:8597)
==28857==    by 0x5713D6A: qemuBuildNetCommandLine (qemu_command.c:8699)
==28857==    by 0x57176F6: qemuBuildCommandLine (qemu_command.c:10027)
==28857==    by 0x5769D61: qemuProcessCreatePretendCmd (qemu_process.c:6004)
==28857==    by 0x4056EC: testCompareXMLToArgv (qemuxml2argvtest.c:502)
==28857==    by 0x41DF40: virTestRun (testutils.c:180)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
7 years agoqemu: Don't update CPU when formatting live def
Jiri Denemark [Fri, 30 Jun 2017 14:55:20 +0000 (16:55 +0200)]
qemu: Don't update CPU when formatting live def

Since commit v2.2.0-199-g7ce711a30e libvirt stores an updated guest CPU
in domain's live definition and there's no need to update it every time
we want to format the definition. The commit itself tried to address
this in qemuDomainFormatXML, but forgot to fix qemuDomainDefFormatLive.
Not to mention that masking a previously set flag is only acceptable if
the flag was set by a public API user. Internally, libvirt should have
never set the flag in the first place.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoqemu: Use correct host model for updating guest cpu
Jiri Denemark [Fri, 30 Jun 2017 15:05:22 +0000 (17:05 +0200)]
qemu: Use correct host model for updating guest cpu

When a user requested a domain XML description with
VIR_DOMAIN_XML_UPDATE_CPU flag, libvirt would use the host CPU
definition from host capabilities rather than the one which will
actually be used once the domain is started.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoconf: Drop unused VIR_DOMAIN_DEF_FORMAT_UPDATE_CPU
Jiri Denemark [Fri, 30 Jun 2017 14:09:06 +0000 (16:09 +0200)]
conf: Drop unused VIR_DOMAIN_DEF_FORMAT_UPDATE_CPU

The only real usage of this flag was removed by "cpu_conf: Drop
updateCPU from virCPUDefFormat".

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agocpu_conf: Simplify formatting of guest CPU attributes
Jiri Denemark [Fri, 30 Jun 2017 14:05:28 +0000 (16:05 +0200)]
cpu_conf: Simplify formatting of guest CPU attributes

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agocpu_conf: Drop updateCPU from virCPUDefFormat
Jiri Denemark [Fri, 30 Jun 2017 13:47:23 +0000 (15:47 +0200)]
cpu_conf: Drop updateCPU from virCPUDefFormat

In the past we updated host-model CPUs with host CPU data by adding a
model and features, but keeping the host-model mode. And since the CPU
model is not normally formatted for host-model CPU defs, we had to pass
the updateCPU flag to the formatting code to be able to properly output
updated host-model CPUs. Libvirt doesn't do this anymore, host-model
CPUs are turned into custom mode CPUs once updated with host CPU data
and thus there's no reason for keeping the hacks inside CPU XML
formatters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoqemuxml2xmltest: Add tests for Power CPUs
Jiri Denemark [Mon, 18 Sep 2017 07:59:18 +0000 (09:59 +0200)]
qemuxml2xmltest: Add tests for Power CPUs

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoqemu: reject parallel ports for pseries machines
Pino Toscano [Thu, 7 Sep 2017 12:19:40 +0000 (14:19 +0200)]
qemu: reject parallel ports for pseries machines

They are simply not supported on that machine type.

Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1487499

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
7 years agoqemu: reject parallel ports for s390 archs
Pino Toscano [Thu, 7 Sep 2017 12:19:39 +0000 (14:19 +0200)]
qemu: reject parallel ports for s390 archs

They are simply not supported on those architectures.

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

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
7 years agoqemu: pass the virDomainDef to qemuDomainChrDefValidate
Pino Toscano [Thu, 7 Sep 2017 12:19:38 +0000 (14:19 +0200)]
qemu: pass the virDomainDef to qemuDomainChrDefValidate

This will be used to improve the validation for this type of devices.

The former @def parameter is renamed to @dev, leaving @def for the
virDomainDef (following the style used elsewhere).

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
7 years agotests: qemuxml2argv: fail also on unexpected pass
Pino Toscano [Thu, 7 Sep 2017 12:19:37 +0000 (14:19 +0200)]
tests: qemuxml2argv: fail also on unexpected pass

If a test expects either a parse error or a failure but then there is
neither a parse error nor a failure, then properly mark the test as
failing, instead of failing later on (e.g. trying to open a
non-existing .args file).

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
7 years agotests: qemuxml2argv: fix expected type for usb-bus-missing
Pino Toscano [Thu, 7 Sep 2017 12:19:36 +0000 (14:19 +0200)]
tests: qemuxml2argv: fix expected type for usb-bus-missing

The guest of usb-bus-missing does not cause a parse error, but a
validation issue -- hence, switch from DO_TEST_PARSE_ERROR to
DO_TEST_FAILURE.

Fixes commit b003b9781b6ae633cfe4fdf6b9620ca246fa2432.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
7 years agoFix commandhelper build on win32
Daniel P. Berrange [Thu, 21 Sep 2017 07:55:07 +0000 (08:55 +0100)]
Fix commandhelper build on win32

For win32 we need EXIT_AM_SKIP which is in testutils.h. We must
define NO_LIBVIRT to prevent replacement of fprintf with
virFilePrintf as we can't link to libvirt_util.la

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
7 years agoiohelper: avoid calling read() with misaligned buffers for O_DIRECT
Daniel P. Berrange [Wed, 20 Sep 2017 15:25:56 +0000 (16:25 +0100)]
iohelper: avoid calling read() with misaligned buffers for O_DIRECT

The iohelper currently calls saferead() to get data from the
underlying file. This has a problem with O_DIRECT when hitting
end-of-file. saferead() is asked to read 1MB, but the first
read() it does may return only a few KB, so it'll try another
read() to fill the remaining buffer. Unfortunately the buffer
pointer passed into this 2nd read() is likely not aligned
to the extent that O_DIRECT requires, so rather than seeing
'0' for end-of-file, we'll get -1 + EINVAL due to misaligned
buffer.

The way the iohelper is currently written, it already handles
getting short reads, so there is actually no need to use
saferead() at all. We can simply call read() directly. The
benefit of this is that we can now write() the data immediately
so when we go into the subsequent reads() we'll always have a
correctly aligned buffer.

Technically the file position ought to be aligned for O_DIRECT
too, but this does not appear to matter when at end-of-file.

Tested-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
7 years agoStop linking tests/commandhelper to libvirt code
Daniel P. Berrange [Wed, 20 Sep 2017 11:03:47 +0000 (12:03 +0100)]
Stop linking tests/commandhelper to libvirt code

The commandhelper binary is a helper for commandtest that
validates what file handles were inherited. For this to
work reliably we must not have any libraries that leak
file descriptors into commandhelper. Unfortunately some
versions of gnutls will intentionally open file handles
at library load time via a constructor function.

We previously hacked around this in

  commit 4cbc15d037e1cd8abf5c4aa6acc30d83ae13e34d
  Author: Martin Kletzander <mkletzan@redhat.com>
  Date:   Fri May 2 09:55:52 2014 +0200

    tests: don't fail with newer gnutls

    gnutls-3.3.0 and newer leaves 2 FDs open in order to be backwards
    compatible when it comes to chrooted binaries [1].  Linking
    commandhelper with gnutls then leaves these two FDs open and
    commandtest fails thanks to that.  This patch does not link
    commandhelper with libvirt.la, but rather only the utilities making
    the test pass.

    Based on suggestion from Daniel [2].

    [1] http://lists.gnutls.org/pipermail/gnutls-help/2014-April/003429.html
    [2] https://www.redhat.com/archives/libvir-list/2014-April/msg01119.html

That fix relied on fact that while libvirt.so linked with
gnutls, libvirt_util.la did not link to it.  With the
introduction of the util/vircrypto.c file that assumption
is no longer valid. We must not link to libvirt_util.la
at all - only gnulib and libc can (hopefully) be relied
on not to open random file descriptors in constructors.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>