]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoqemu: add mac address to error messages in qemuDomainValidateActualNetDef
Laine Stump [Fri, 27 Sep 2019 15:47:21 +0000 (11:47 -0400)]
qemu: add mac address to error messages in qemuDomainValidateActualNetDef

This makes it easier to understand which interface's config caused the
error.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_capabilities: Use proper free function for caps->cpuModels
Michal Privoznik [Mon, 25 Nov 2019 15:35:27 +0000 (16:35 +0100)]
qemu_capabilities: Use proper free function for caps->cpuModels

The cpuModels member of _virQEMUCapsAccel struct is not a
virObject but regular struct with a free function defined:
qemuMonitorCPUDefsFree(). Use that when clearing parent structure
instead of virObjectUnref() to avoid a memleak:

==212322== 57,275 (48 direct, 57,227 indirect) bytes in 3 blocks are definitely lost in loss record 623 of 627
==212322==    at 0x4838B86: calloc (vg_replace_malloc.c:762)
==212322==    by 0x554A158: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6000.6)
==212322==    by 0x17B14BF5: qemuMonitorCPUDefsNew (qemu_monitor.c:3587)
==212322==    by 0x17B27BA7: qemuMonitorJSONGetCPUDefinitions (qemu_monitor_json.c:5616)
==212322==    by 0x17B14B0B: qemuMonitorGetCPUDefinitions (qemu_monitor.c:3559)
==212322==    by 0x17A6AFBB: virQEMUCapsFetchCPUDefinitions (qemu_capabilities.c:2571)
==212322==    by 0x17A6B2CC: virQEMUCapsProbeQMPCPUDefinitions (qemu_capabilities.c:2629)
==212322==    by 0x17A70C00: virQEMUCapsInitQMPMonitorTCG (qemu_capabilities.c:4769)
==212322==    by 0x17A70DDF: virQEMUCapsInitQMPSingle (qemu_capabilities.c:4820)
==212322==    by 0x17A70E99: virQEMUCapsInitQMP (qemu_capabilities.c:4848)
==212322==    by 0x17A71044: virQEMUCapsNewForBinaryInternal (qemu_capabilities.c:4891)
==212322==    by 0x17A7119C: virQEMUCapsNewData (qemu_capabilities.c:4923)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoqemu: Use host-model CPU on s390 by default
Jiri Denemark [Tue, 12 Nov 2019 14:28:33 +0000 (15:28 +0100)]
qemu: Use host-model CPU on s390 by default

On s390 machines host-passthrough and host-model CPUs result in the same
guest ABI (with QEMU new enough to be able to tell us what "host" CPU is
expanded to, which was implemented around 2.9.0). So instead of using
host-passthrough CPU when there's no CPU specified in a domain XML we
can safely use host-model and benefit from CPU compatibility checks
during migration, snapshot restore and similar operations.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu_s390: Don't check match attribute for host-model CPUs
Jiri Denemark [Tue, 12 Nov 2019 14:27:45 +0000 (15:27 +0100)]
cpu_s390: Don't check match attribute for host-model CPUs

The match attribute is only relevant for custom mode CPUs. Reporting
failure when match == 'minimum' regardless on CPU mode can cause
unexpected failures. We should only report the error for custom CPUs. In
fact, calling virCPUs390Update on a custom mode CPU should always report
an error as optional features are not supported on s390 either.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu_conf: Don't format empty model for host-model CPUs
Jiri Denemark [Tue, 12 Nov 2019 14:54:12 +0000 (15:54 +0100)]
cpu_conf: Don't format empty model for host-model CPUs

Most likely for historical reasons our CPU def formatting code is
happily adding useless <model fallback='allow'/> for host-model CPUs. We
can just drop it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu_conf: Fix default value for CPU match attribute
Jiri Denemark [Tue, 12 Nov 2019 14:26:23 +0000 (15:26 +0100)]
cpu_conf: Fix default value for CPU match attribute

Commit v0.8.4-66-g95ff6b18ec (9 years ago) changed the default value for
the cpu/@match attribute to 'exact' in a rather complicated way. It did
so only if <model> subelement was present and set -1 otherwise (which is
not expected to ever happen). Thus the following two equivalent XML
elements:

    <cpu mode='host-model'/>

and

    <cpu mode='host-model'>
      <model/>
    </cpu>

would be parsed differently. The former would end up with match == -1
while the latter would have match == 1 ('exact'). This is not a big deal
since the match attribute is ignored for host-model CPUs, but we can
simplify the code and make it a little bit saner anyway.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: added tests of the new default video type selection algorithm
Pavel Mores [Mon, 25 Nov 2019 10:54:26 +0000 (11:54 +0100)]
qemu: added tests of the new default video type selection algorithm

The test case for x86_64 and neither cirrus nor vga capability is of the
xml2argv type because it actually fails to parse the XML at all [*] which
is something that xml2xml tests don't seem to handle.  xml2argv test fails
to produce a qemu argv for this case which xml2argv tests can handle.

[*] This is a consequence of the decision not to have a fallback if the
obvious choices (cirrus and vga) aren't viable due to missing QEMU caps.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
5 years agoqemu: the actual change of default video devide type selection algorithm
Pavel Mores [Mon, 25 Nov 2019 10:54:25 +0000 (11:54 +0100)]
qemu: the actual change of default video devide type selection algorithm

If a graphics device was added to XML that had no video device, libvirt
automatically added a video device which was always of type 'cirrus' on
x86_64, even if the underlying qemu didn't support cirrus.

This patch refines a bit the decision about the type of the video device.
Based on QEMU capabilities, cirrus is still preferred but only added if
QEMU supports it, otherwise VGA is used if supported by QEMU.  There is now
no fallback as libvirt only aspires to generate a basic working config and
leaves anything more specific up to higher-level management tools.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
5 years agoqemu: prepare existing test for change of the default video device type
Pavel Mores [Mon, 25 Nov 2019 10:54:24 +0000 (11:54 +0100)]
qemu: prepare existing test for change of the default video device type

The test relied implicitly on default video device being cirrus.  As we're
about to change that the test would start failing.  To avoid this, just make
the test's requirement explicit.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
5 years agoqemu: default video device type selection algoritm moved into its own function
Pavel Mores [Mon, 25 Nov 2019 10:54:23 +0000 (11:54 +0100)]
qemu: default video device type selection algoritm moved into its own function

The default video device type selection algorithm we're about to deploy will
increase the amount of code dedicated to the task by amount enough to warrant
factoring the whole thing into its own function so as not to pollute the
caller qemuDomainDeviceVideoDefPostParse().  Do it now so that the actual
algorithm change later on is in a clean commit by itself and easy to review.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
5 years agotravis: add fedora-31 & fedora-rawhide to the build images
Daniel P. Berrangé [Fri, 22 Nov 2019 14:24:01 +0000 (14:24 +0000)]
travis: add fedora-31 & fedora-rawhide to the build images

The CentOS7 distro is quite old and the Ubuntu 18.04 distro
is already a year & half old. Adding a Fedora 31 image gives
us coverage of the newest stable distro release, and
fedora-rawhide gives us the cutting edge.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoRevert "network: Check for QOS before blindly using it"
Erik Skultety [Fri, 22 Nov 2019 15:21:33 +0000 (16:21 +0100)]
Revert "network: Check for QOS before blindly using it"

This reverts commit f4db846c32c0a1e99a0f62b340273e48f8a98ed3.

This patch results in the following error when trying to start
essentially any VM with default network:

unsupported configuration: QOS must be defined for network 'default'

Coverity didn't see that the bandwidth == NULL it complained about in
virNetDevBandwidthPlug was already checked properly in
networkCheckBandwidth, thus causing networkPlugBandwidth to return 0
and finish before a call to virNetDevBandwidthPlug would have been even
made.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: consolidate on one free callback for hash data
Daniel P. Berrangé [Thu, 21 Nov 2019 19:27:58 +0000 (19:27 +0000)]
util: consolidate on one free callback for hash data

This previous commit introduced a simpler free callback for
hash data with only 1 arg, the value to free:

  commit 49288fac965f0ee23db45d83ae4ef3a9a71dafd0
  Author: Peter Krempa <pkrempa@redhat.com>
  Date:   Wed Oct 9 15:26:37 2019 +0200

    util: hash: Add possibility to use simpler data free function in virHash

It missed two functions in the hash table code which need
to call the alternate data free function, virHashRemoveEntry
and virHashRemoveSet.

After the previous patch though, there is no code that
makes functional use of the 2nd key arg in the data
free function. There is merely one log message that can
be dropped.

We can thus purge the current virHashDataFree callback
entirely, and rename virHashDataFreeSimple to replace
it.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: stop using hash key when free'ing hash entries
Daniel P. Berrangé [Fri, 22 Nov 2019 10:49:27 +0000 (10:49 +0000)]
conf: stop using hash key when free'ing hash entries

The virChrdevHashEntryFree method uses the hash 'key'
as the name of the logfile it has to remove. By storing
a struct as the value which contains the stream and
the dev path, we can avoid relying on the hash key
when free'ing entries.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: enable blockdev support
Peter Krempa [Mon, 7 Jan 2019 10:45:19 +0000 (11:45 +0100)]
qemu: enable blockdev support

Now that all pieces are in place (hopefully) let's enable -blockdev.

We base the capability on presence of the fix for 'auto-read-only' on
files so that blockdev works properly, mandate that qemu supports
explicit SCSI id strings to avoid ABI regression and that the fix for
'savevm' is present so that internal snapshots work.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: capabilities: Add detection of the 'savevm' fix for -blockdev
Peter Krempa [Tue, 17 Sep 2019 15:10:08 +0000 (17:10 +0200)]
qemu: capabilities: Add detection of the 'savevm' fix for -blockdev

The 'savevm' HMP command didn't work properly with blockdev as it tried
to do snapshot of everything including the protocol nodes accessing
files which are not snapshottable. Qemu fixed this bug so now we need to
detect it to allow enabling blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: qapi: Add support for command features
Peter Krempa [Tue, 17 Sep 2019 15:08:56 +0000 (17:08 +0200)]
qemu: qapi: Add support for command features

The top level commands now can have 'feature' flags for fixes so add
support for querying those as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: caps: Add capability for dynamic 'auto-read-only' support for files
Peter Krempa [Mon, 8 Apr 2019 15:10:37 +0000 (17:10 +0200)]
qemu: caps: Add capability for dynamic 'auto-read-only' support for files

Initial implementation of 'auto-read-only' didn't reopen the backing
files when needed. For '-blockdev' to work we need to be able to tel
qemu to open a file read-only and change it during blockjobs as we label
backing chains with a sVirt label which does not allow writing. The
dynamic auto-read-only supports this as it reopens files when writing
is demanded.

Add a capability to detect that the posix file based backends support
the dynamic part.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: qemucapabilities: Refresh data for unreleased qemu-4.2 on x86_64
Peter Krempa [Fri, 25 Oct 2019 09:58:39 +0000 (11:58 +0200)]
tests: qemucapabilities: Refresh data for unreleased qemu-4.2 on x86_64

The data is captured from qemu v4.2.0-rc2-19-g2061735ff0

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: caps: Base support of 'backingStoreInput' domain feature on QEMU_CAPS_BLOCKDEV
Peter Krempa [Mon, 18 Nov 2019 15:56:51 +0000 (16:56 +0100)]
qemu: caps: Base support of 'backingStoreInput' domain feature on QEMU_CAPS_BLOCKDEV

The qemu driver will obey <backingStore> when we support blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: Document support for obeying <backingStore> of <disk> on input
Peter Krempa [Mon, 18 Nov 2019 15:51:20 +0000 (16:51 +0100)]
docs: Document support for obeying <backingStore> of <disk> on input

Until now we've only supported <backingStore> in an output mode. The
documentation for the element states that hypervisor drivers may start
to obey it in the future.

Update the documentation so that it mentions the recently added
'backingStoreInput' domain capability and explain what happens if it is
supported and <backingStore> is present on input.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: domcaps: Add 'backingStoreInput' domain capability
Peter Krempa [Wed, 30 Oct 2019 15:54:56 +0000 (16:54 +0100)]
conf: domcaps: Add 'backingStoreInput' domain capability

Historically we've only supported the <backingStore> as an output-only
element for domain disks. The documentation states that it may become
supported on input. To allow management apps detectin once that happens
add a domain capability which will be asserted if the hypervisor driver
will be able to obey the <backingStore> as configured on input.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: fix include of ACL permissions files
Daniel P. Berrangé [Wed, 20 Nov 2019 15:24:18 +0000 (15:24 +0000)]
docs: fix include of ACL permissions files

The XSL generator loads included HTML files relative to the source dir
but we need to tell it to load them from the build dir instead.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: fix ability to view web pages from build tree
Daniel P. Berrangé [Wed, 20 Nov 2019 15:17:22 +0000 (15:17 +0000)]
docs: fix ability to view web pages from build tree

Some of the web content is only present in the source tree, thus when
viewing pages from the build tree they appear missing.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: remove unused make targets
Daniel P. Berrangé [Wed, 20 Nov 2019 15:12:36 +0000 (15:12 +0000)]
docs: remove unused make targets

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: generate API reference pages for admin, qemu & lxc libraries
Daniel P. Berrangé [Wed, 20 Nov 2019 14:49:26 +0000 (14:49 +0000)]
docs: generate API reference pages for admin, qemu & lxc libraries

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: use variable for referencing API XML filenames
Daniel P. Berrangé [Wed, 20 Nov 2019 14:37:41 +0000 (14:37 +0000)]
docs: use variable for referencing API XML filenames

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: drop building of API -refs.xml files
Daniel P. Berrangé [Wed, 20 Nov 2019 14:29:52 +0000 (14:29 +0000)]
docs: drop building of API -refs.xml files

The API cross reference files are not used since

  commit d3043afe5ceebd5002bff45db38bb33e090bb4af
  Author: Daniel Veillard <veillard@redhat.com>
  Date:   Mon Jan 21 08:08:33 2008 +0000

    Remove docs/API*.html
    * docs/API* docs/api.xsl docs/site.xsl docs/Makefile.am: remove the
      generation of the API*.html files as it's not really useful here

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: stop using custom rules for building / installing web pages
Daniel P. Berrangé [Wed, 20 Nov 2019 14:23:04 +0000 (14:23 +0000)]
docs: stop using custom rules for building / installing web pages

Define automake variables for all the data we need built and installed
and let automake generate the install rules normally.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoscripts: use in even more
Ján Tomko [Wed, 20 Nov 2019 19:10:13 +0000 (20:10 +0100)]
scripts: use in even more

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoscripts: check-aclrules: use regular expressions less often
Ján Tomko [Wed, 20 Nov 2019 18:13:29 +0000 (19:13 +0100)]
scripts: check-aclrules: use regular expressions less often

Use a simple
  if "substr" in line
before running a regular expression, which saves time,
especially if the regex has a capture group.

This reduces runtime of the check by almost 78 % for me.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoscripts: check-aclrules: use in instead of find
Ján Tomko [Wed, 20 Nov 2019 18:05:13 +0000 (19:05 +0100)]
scripts: check-aclrules: use in instead of find

For checking whether a substring is present in a string,
using the pattern:
    "str" in string
is slightly faster than:
    string.find("str") != -1

Use it to shave off 4 % of the runtime of this script that
processes quite a few long source files.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoscripts: speedup prohibit-duplicate-header
Ján Tomko [Wed, 9 Oct 2019 19:02:38 +0000 (21:02 +0200)]
scripts: speedup prohibit-duplicate-header

Running regular expressions with capture groups is expensive.
Bail out early if the line does not start with a '#'.

This reduces the runtime of the check by two thirds.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agovirsh: limit completion of 'domhostname' to active domains
Pino Toscano [Wed, 20 Nov 2019 13:24:33 +0000 (14:24 +0100)]
virsh: limit completion of 'domhostname' to active domains

Getting the hostname of a guest usually requires a in-guest agent,
or generally can be determined only on active domains.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemuProcessStop: Remove image metadata for running mirror jobs
Michal Privoznik [Mon, 18 Nov 2019 16:40:01 +0000 (17:40 +0100)]
qemuProcessStop: Remove image metadata for running mirror jobs

If user starts a blockcommit or a blockcopy then we modify access
for qemu on both images and leave it like that until the job
terminates.  So far so good. Problem is, if user instead of
terminating the job (where we would modify the access again so
that the state before the job is restored) calls destroy on the
domain or if qemu dies whilst executing the block job.  In this
case we don't ever clear the access we granted at the beginning.
To fix this, maybe a bit harsh approach is used, but it works:
after all labels were restored (that is after
qemuSecurityRestoreAllLabel() was called), we iterate over each
disk in the domain and remove XATTRs from the whole backing chain
and also from any file the disk is being mirrored to.

This would have been done at the time of pivot, but it isn't
because user decided to kill the domain instead. If we don't do
this and leave some XATTRs behind the domain might be unable to
start.

Also, secdriver can't do this because it doesn't know if there is
any job running. It's outside of its scope - the hypervisor
driver is responsible for calling secdriver's APIs.

Moreover, this is safe to call because we don't remember labels
for any member of a backing chain except of the top layer. But
that one was restored in qemuSecurityRestoreAllLabel() call done
earlier. Therefore, not only we don't remember labels (and thus
this is basically a NOP for other images in the backing chain) it
is also safe to call this when no blockjob was started in the
first place, or if some parts of the backing chain are shared
with some other domains - this is NOP, unless a block job is
active at the time of domain destroy.

https://bugzilla.redhat.com/show_bug.cgi?id=1741456#c19

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: Separate image metadata removal into a function
Michal Privoznik [Tue, 19 Nov 2019 07:43:58 +0000 (08:43 +0100)]
qemu: Separate image metadata removal into a function

There are four places where we remove image XATTRs and in all of
them we have the same for() loop with the same body. Move it into
a separate function because I'm about to introduce fifth place
where the same needs to be done.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: Instantiate pflash via -machine when using blockdev
Peter Krempa [Fri, 15 Nov 2019 11:27:42 +0000 (12:27 +0100)]
qemu: Instantiate pflash via -machine when using blockdev

Install the convertor function which enables the internals that will use
-blockdev to make qemu open the firmware image and stop using -drive.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: command: Build the 'pflash' drives via -machine
Peter Krempa [Fri, 15 Nov 2019 12:36:53 +0000 (13:36 +0100)]
qemu: command: Build the 'pflash' drives via -machine

The old way to instantiate a pflash device via -drive was a hack since
it's a platform device.

The modern approach calls for configuring it via -machine and takes the
node name as an argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: command: Build -blockdev-s for backing of pflash
Peter Krempa [Fri, 15 Nov 2019 13:41:56 +0000 (14:41 +0100)]
qemu: command: Build  -blockdev-s for backing of pflash

As a first step we will build the blockdevs which will be supposed to
back the pflash drives when moving away from -drive.

This code is similar to the way we build the blockdevs for the disk, but
skips the copy-on-read layer and doesn't implement any legacy approach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: domain: Introduce helper to convert <loader> into virStorageSource
Peter Krempa [Fri, 15 Nov 2019 15:25:26 +0000 (16:25 +0100)]
qemu: domain: Introduce helper to convert <loader> into virStorageSource

Add a helper which will covert the PFLASH code file and variable file
into the virStorageSource objects stored in private data so that we can
use them with -blockdev while keeping the infrastructure to determine
the path to the loaders intact.

This is a temporary solution until we will want to do snapshots of the
pflash where we will be forced do track the full backing chain in the
XML.

In the meanwhile just convert it partially so that we can stop using
-drive.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: domain: Store virStorageSources representing pflash backing
Peter Krempa [Fri, 15 Nov 2019 15:23:44 +0000 (16:23 +0100)]
qemu: domain: Store virStorageSources representing pflash backing

To allow converting the pflash drives to blockdev we will need a
virStorageSource to allow using our helpers. Temporarily prior to
coverting loader data to a virStorageSoruce add private data which will
house this.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: command: Extract formatting of -drive for pflash
Peter Krempa [Fri, 1 Nov 2019 11:14:43 +0000 (12:14 +0100)]
qemu: command: Extract formatting of -drive for pflash

Extract the old way to instantiate pflash devices to hold the firmware
via -drive to a separate function so that it can later be conditionally
disabled when -blockdev will be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodomcaps: Remove function initializing domain caps as unsupported
Peter Krempa [Thu, 21 Nov 2019 08:52:24 +0000 (09:52 +0100)]
domcaps: Remove function initializing domain caps as unsupported

Commit 5751a0b6b1968bb2354b2ac21cc5938b93009590 added a helper function
called virDomainCapsFeaturesInitUnsupported which initialized all domain
capability features as unsupported.

When adding a new feature this would initialize it as unsupported also
for hypervisor drivers which the original author possibly didn't intend
to modify. To prevent accidental wrong value being reported in such case
revert back to initializing individual features in the hypervisor
drivers themselves.

This is not a straight revert as additonal patches modified how we store
the capabilities.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolibvirt-<module>: Check caller-provided buffers to be NULL with size > 0
Erik Skultety [Mon, 18 Nov 2019 11:04:16 +0000 (12:04 +0100)]
libvirt-<module>: Check caller-provided buffers to be NULL with size > 0

Pre-Glib era which used malloc allowed the size of the client-side
buffers to be declared as 0, because malloc documents that it can either
return 0 or a unique pointer on 0 size allocations.
With glib this doesn't work anymore, because glib documents that for
such allocation requests NULL is always returned which results in an
error in our public API checks server-side.
This patch complements the fix in the RPC layer by explicitly erroring
out on the following combination of args used by our legacy APIs (their
moder equivalents don't suffer from this):

function(caller-allocated-array, size, ...) {
    if (!caller-allocated-array && size > 0)
        return error;
}

treating everything else as a valid input and potentially let that fail
on the server-side rather than client-side.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agorpc: gendispatch: Fix a couple of places adding trailing spaces
Erik Skultety [Mon, 18 Nov 2019 09:30:20 +0000 (10:30 +0100)]
rpc: gendispatch: Fix a couple of places adding trailing spaces

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: remove NULL check from virDomainQemuMonitorEventNew
Ján Tomko [Mon, 11 Nov 2019 09:21:03 +0000 (10:21 +0100)]
conf: remove NULL check from virDomainQemuMonitorEventNew

The qemu_domain_monitor_event_msg struct in qemu_protocol.x
defines event as a nonnull_string and qemuMonitorJSONIOProcessEvent
also errors out on a non-NULL event.

Drop the check to fix the build with static analysis.

This essentially reverts commit d343e8203d248635f5e7a0d86dd077f74d49e3af

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirt-aa-helper: testcase for shmem devices
Christian Ehrhardt [Tue, 22 Oct 2019 10:13:41 +0000 (12:13 +0200)]
virt-aa-helper: testcase for shmem devices

Adding build time self tests for basic (deprecated), doorbell and plain mode.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agovirt-aa-helper: add rules for shmem devices
Christian Ehrhardt [Thu, 17 Oct 2019 10:48:10 +0000 (12:48 +0200)]
virt-aa-helper: add rules for shmem devices

Shared memory devices need qemu to be able to access certain paths
either for the shared memory directly (mostly ivshmem-plain) or for a
socket (mostly ivshmem-doorbell).

Add logic to virt-aa-helper to render those apparmor rules based
on the domain configuration.

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

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agoapparmor: let AppArmorSetSecurityImageLabel append rules
Christian Ehrhardt [Wed, 16 Oct 2019 07:35:27 +0000 (09:35 +0200)]
apparmor: let AppArmorSetSecurityImageLabel append rules

There are currently broken use cases, e.g. snapshotting more than one disk at
once like:
 $ virsh snapshot-create-as --domain eoan --disk-only --atomic
   --diskspec vda,snapshot=no  --diskspec vdb,snapshot=no
   --diskspec vdc,file=/test/disk1.snapshot1.qcow,snapshot=external
   --diskspec vdd,file=/test/disk2.snapshot1.qcow,snapshot=external
The command above will iterate from qemuDomainSnapshotCreateDiskActive and
eventually add /test/disk1.snapshot1.qcow first (appears in the rules)
to then later add /test/disk2.snapshot1.qcow and while doing so throwing
away the former rule causing it to fail.

All other calls to (re)load_profile already use append=true when adding
rules append=false is only used when restoring rules [1].

Fix this by letting AppArmorSetSecurityImageLabel use append=true as well.

Since this is removing a (unintentional) trigger to revoke all rules
appended so far we agreed on review to do some tests, but in the tests
no rules came back on:
- hot-plug
- hot-unplug
- snapshotting

Bugs:
https://bugs.launchpad.net/libvirt/+bug/1845506
https://bugzilla.redhat.com/show_bug.cgi?id=1746684

[1]: https://bugs.launchpad.net/libvirt/+bug/1845506/comments/13

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agoapparmor: refactor AppArmorSetSecurityImageLabel
Christian Ehrhardt [Wed, 16 Oct 2019 07:32:52 +0000 (09:32 +0200)]
apparmor: refactor AppArmorSetSecurityImageLabel

A lot of the code in AppArmorSetSecurityImageLabel is a duplicate of
what is in reload_profile, this refactors AppArmorSetSecurityImageLabel
to use reload_profile instead.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agoapparmor: drop useless call to get_profile_name
Christian Ehrhardt [Wed, 16 Oct 2019 07:15:14 +0000 (09:15 +0200)]
apparmor: drop useless call to get_profile_name

reload_profile calls get_profile_name for no particular gain, lets
remove that call. The string isn't used in that function later on
and not registered/passed anywhere.

It can only fail if it either can't allocate or if the
virDomainDefPtr would have no uuid set (which isn't allowed).

Thereby the only "check" it really provides is if it can allocate the
string to then free it again.

This was initially added in [1] when the code was still in
AppArmorRestoreSecurityImageLabel (later moved) and even back then had
no further effect than described above.

[1]: https://libvirt.org/git/?p=libvirt.git;a=blob;f=src/security/security_apparmor.c;h=16de0f26f41689e0c50481120d9f8a59ba1f4073;hb=bbaecd6a8f15345bc822ab4b79eb0955986bb2fd#l487

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agovirt-aa-helper: clarify command line options
Christian Ehrhardt [Wed, 16 Oct 2019 06:47:36 +0000 (08:47 +0200)]
virt-aa-helper: clarify command line options

While only used internally from libvirt the options still are misleading
enough to cause issues every now and then.
Group modes, options and an adding extra file and extend the wording of
the latter which had the biggest lack of clarity.
Both add a file to the end of the rules, but one re-generates the
rules from XML and the other keeps the existing rules as-is not
considering the XML content.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agoqemu: Store default CPU in domain XML
Jiri Denemark [Thu, 26 Sep 2019 16:42:02 +0000 (18:42 +0200)]
qemu: Store default CPU in domain XML

When starting a domain without a CPU model specified in the domain XML,
QEMU will choose a default one. Which is fine unless the domain gets
migrated to another host because libvirt doesn't perform any CPU ABI
checks and the virtual CPU provided by QEMU on the destination host can
differ from the one on the source host.

With QEMU 4.2.0 we can probe for the default CPU model used by QEMU for
a particular machine type and store it in the domain XML. This way the
chosen CPU model is more visible to users and libvirt will make sure
the guest will see the exact same CPU after migration.

Architecture specific notes
- aarch64: We only set the default CPU for TCG domains as KVM requires
  explicit "-cpu host" to work.

- ppc64: The default CPU for KVM is "host" thanks to some hacks in QEMU,
  we will translate the default model to the model corresponding to the
  host CPU ("POWER8" on a Power8 host, "POWER9" on Power9 host, etc.).
  This is not a problem as the corresponding CPU model is in fact an
  alias for "host". This is probably not ideal, but it's not wrong and
  the default virtual CPU configured by libvirt is the same QEMU would
  use. TCG uses various CPU models depending on machine type and its
  version.

- s390x: The default CPU for KVM is "host" while TCG defaults to "qemu".

- x86_64: The default CPU model (qemu64) is not runnable on any host
  with KVM, but QEMU just disables unavailable features and starts
  happily.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2*test: Add test cases for default CPU models on x86_64
Jiri Denemark [Fri, 11 Oct 2019 18:15:03 +0000 (20:15 +0200)]
qemuxml2*test: Add test cases for default CPU models on x86_64

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2*test: Add test cases for default CPU models on s390x
Jiri Denemark [Fri, 11 Oct 2019 18:15:03 +0000 (20:15 +0200)]
qemuxml2*test: Add test cases for default CPU models on s390x

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2*test: Add test cases for default CPU models on ppc64
Jiri Denemark [Fri, 11 Oct 2019 18:15:03 +0000 (20:15 +0200)]
qemuxml2*test: Add test cases for default CPU models on ppc64

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2*test: Add test cases for default CPU models on aarch64
Jiri Denemark [Fri, 11 Oct 2019 18:15:03 +0000 (20:15 +0200)]
qemuxml2*test: Add test cases for default CPU models on aarch64

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2argvtest: Update host arch for DO_TEST*ARCH* tests
Jiri Denemark [Thu, 24 Oct 2019 15:51:42 +0000 (17:51 +0200)]
qemuxml2argvtest: Update host arch for DO_TEST*ARCH* tests

To avoid mismatch between host and QEMU capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Define g_autoptr cleanup function for virCPUDef
Jiri Denemark [Thu, 26 Sep 2019 16:41:42 +0000 (18:41 +0200)]
conf: Define g_autoptr cleanup function for virCPUDef

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use g_autoptr in qemuDomainDefPostParse
Jiri Denemark [Thu, 26 Sep 2019 15:47:53 +0000 (17:47 +0200)]
qemu: Use g_autoptr in qemuDomainDefPostParse

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsGetMachineDefaultCPU
Jiri Denemark [Thu, 26 Sep 2019 13:22:38 +0000 (15:22 +0200)]
qemu: Introduce virQEMUCapsGetMachineDefaultCPU

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Probe for default CPU types
Jiri Denemark [Thu, 18 Jul 2019 17:21:55 +0000 (19:21 +0200)]
qemu: Probe for default CPU types

QEMU 4.2.0 will report default CPU types used by each machine type and
we will want to start using it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Probe machine types for both KVM and TCG
Jiri Denemark [Thu, 24 Oct 2019 12:21:46 +0000 (14:21 +0200)]
qemu: Probe machine types for both KVM and TCG

Almost all TCG query-machines replies match KVM. The only exceptions are
4.2.0 replies on s390x which differ in the reported default CPU type.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Make probed machine types depend on accelerator
Jiri Denemark [Thu, 24 Oct 2019 12:19:38 +0000 (14:19 +0200)]
qemu: Make probed machine types depend on accelerator

Some specifics of machine types may depend on the accelerator and thus
the data should be moved to virQEMUCapsAccel. The TCG machine types are
just copied from the ones probed for KVM to simplify the changes to
qemucapabilitiestest data files.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsCopyMachineTypes
Jiri Denemark [Thu, 24 Oct 2019 09:35:10 +0000 (11:35 +0200)]
qemu: Introduce virQEMUCapsCopyMachineTypes

The function copies machine type data from one QEMU caps structure to
another.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use typedef for virQEMUCapsMachineType
Jiri Denemark [Wed, 30 Oct 2019 00:04:06 +0000 (01:04 +0100)]
qemu: Use typedef for virQEMUCapsMachineType

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Move machine type data in capabilities cache
Jiri Denemark [Thu, 24 Oct 2019 07:04:58 +0000 (09:04 +0200)]
qemu: Move machine type data in capabilities cache

In preparation for making machine types dependent on the accelerator,
the <machine> elements are formatted between <cpu type='kvm'> and
<cpu type='tcg'>.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Pass virDomainVirtType to APIs dealing with machine types
Jiri Denemark [Thu, 24 Oct 2019 06:52:21 +0000 (08:52 +0200)]
qemu: Pass virDomainVirtType to APIs dealing with machine types

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Split out virQEMUCapsFormatCache
Jiri Denemark [Wed, 23 Oct 2019 16:29:39 +0000 (18:29 +0200)]
qemu: Split out virQEMUCapsFormatCache

All the code for formatting machine type data was moved to a standalone
virQEMUCapsFormatMachines function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Split out virQEMUCapsLoadCache
Jiri Denemark [Wed, 23 Oct 2019 16:05:45 +0000 (18:05 +0200)]
qemu: Split out virQEMUCapsLoadCache

All the code for loading machine type data was moved to a standalone
virQEMUCapsLoadMachines function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Make virQEMUCapsIsMachineSupported static
Jiri Denemark [Wed, 23 Oct 2019 15:51:50 +0000 (17:51 +0200)]
qemu: Make virQEMUCapsIsMachineSupported static

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Make virQEMUCapsGetMachineTypesCaps static
Jiri Denemark [Wed, 23 Oct 2019 15:08:57 +0000 (17:08 +0200)]
qemu: Make virQEMUCapsGetMachineTypesCaps static

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Refactor probing of accelerator dependent data
Jiri Denemark [Wed, 23 Oct 2019 14:48:17 +0000 (16:48 +0200)]
qemu: Refactor probing of accelerator dependent data

To avoid duplicating code which selects the right virQEMUCapsAccel data
to be filled during probing.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsProbeCPUDefinitionsTest
Jiri Denemark [Wed, 23 Oct 2019 12:08:16 +0000 (14:08 +0200)]
qemu: Introduce virQEMUCapsProbeCPUDefinitionsTest

It is a tiny wrapper around virQEMUCapsProbeQMPCPUDefinitions which will
soon get private parameters and thus it cannot be exposed outside
qemu_capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Refactor virQEMUCapsFormatAccel
Jiri Denemark [Wed, 23 Oct 2019 11:00:31 +0000 (13:00 +0200)]
qemu: Refactor virQEMUCapsFormatAccel

And make it use virQEMUCapsGetAccel once rather than repeating the same
code in all functions called from virQEMUCapsFormatAccel.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Refactor virQEMUCapsLoadAccel
Jiri Denemark [Wed, 23 Oct 2019 10:59:43 +0000 (12:59 +0200)]
qemu: Refactor virQEMUCapsLoadAccel

And make it use virQEMUCapsGetAccel once rather than repeating the same
code in all functions called from virQEMUCapsLoadAccel.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Drop virQEMUCapsGetHostCPUData
Jiri Denemark [Wed, 23 Oct 2019 10:57:20 +0000 (12:57 +0200)]
qemu: Drop virQEMUCapsGetHostCPUData

It was very similar to virQEMUCapsGetAccel.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce and use virQEMUCapsGetAccel
Jiri Denemark [Wed, 23 Oct 2019 10:46:28 +0000 (12:46 +0200)]
qemu: Introduce and use virQEMUCapsGetAccel

The function can be used to get the pointer to all data which depend on
the accelerator.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsAccelClear
Jiri Denemark [Wed, 23 Oct 2019 10:42:54 +0000 (12:42 +0200)]
qemu: Introduce virQEMUCapsAccelClear

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsAccelCopy
Jiri Denemark [Wed, 23 Oct 2019 10:41:31 +0000 (12:41 +0200)]
qemu: Introduce virQEMUCapsAccelCopy

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsAccel structure
Jiri Denemark [Wed, 23 Oct 2019 10:29:52 +0000 (12:29 +0200)]
qemu: Introduce virQEMUCapsAccel structure

This is container for capabilities data that depend on the accelerator.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add virQEMUCaps{Load,Format}Accel
Jiri Denemark [Wed, 23 Oct 2019 08:24:46 +0000 (10:24 +0200)]
qemu: Add virQEMUCaps{Load,Format}Accel

The new functions are designed to load and format capabilities which
depend on the accelerator (host CPU expansion and CPU models).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Drop unused virQEMUCapsGetDefaultMachine
Jiri Denemark [Thu, 26 Sep 2019 13:26:45 +0000 (15:26 +0200)]
qemu: Drop unused virQEMUCapsGetDefaultMachine

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Store typename from query-cpu-definitions in qemuCaps
Jiri Denemark [Thu, 19 Sep 2019 18:47:37 +0000 (20:47 +0200)]
qemu: Store typename from query-cpu-definitions in qemuCaps

We need to create a mapping between CPU model names and their
corresponding QOM types.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Drop virDomainCapsCPUModelsAddSteal
Jiri Denemark [Fri, 20 Sep 2019 21:08:55 +0000 (23:08 +0200)]
conf: Drop virDomainCapsCPUModelsAddSteal

Both virDomainCapsCPUModelsAdd and virDomainCapsCPUModelsAddSteal are so
simple we can just squash the code in a single function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Drop unused virDomainCapsCPUModelsFilter
Jiri Denemark [Fri, 20 Sep 2019 21:00:14 +0000 (23:00 +0200)]
conf: Drop unused virDomainCapsCPUModelsFilter

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Switch qemuCaps to use qemuMonitorCPUDefs
Jiri Denemark [Tue, 24 Sep 2019 14:38:05 +0000 (16:38 +0200)]
qemu: Switch qemuCaps to use qemuMonitorCPUDefs

We will need to keep some QEMU-specific data for each CPU model
supported by a QEMU binary. Instead of complicating the generic
virDomainCapsCPUModelsPtr, we can just directly store
qemuMonitorCPUDefsPtr returned by the capabilities probing code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Split virQEMUCapsFetchCPUModels
Jiri Denemark [Wed, 9 Oct 2019 08:16:17 +0000 (10:16 +0200)]
qemu: Split virQEMUCapsFetchCPUModels

Most of the code moved to a new virQEMUCapsFetchCPUDefinitions function
and the existing virQEMUCapsFetchCPUModels just becomes a small wrapper
around virQEMUCapsFetchCPUDefinitions and virQEMUCapsCPUDefsToModels.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions
Jiri Denemark [Wed, 9 Oct 2019 08:14:59 +0000 (10:14 +0200)]
qemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions

The functions return virDomainCapsCPUModelsPtr and thus they should be
called *CPUModels for consistency. Functions called *CPUDefinitions will
work on qemuMonitorCPUDefsPtr.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsCPUDefsToModels
Jiri Denemark [Tue, 24 Sep 2019 13:59:34 +0000 (15:59 +0200)]
qemu: Introduce virQEMUCapsCPUDefsToModels

The function translates qemuMonitorCPUDefsPtr (used by QEMU caps probing
code) into virDomainCapsCPUModelsPtr used by domain capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virDomainCapsCPUUsable in qemuMonitorCPUDefInfo
Jiri Denemark [Tue, 29 Oct 2019 13:36:11 +0000 (14:36 +0100)]
qemu: Use virDomainCapsCPUUsable in qemuMonitorCPUDefInfo

While virDomainCapsCPUModel structure contains 'usable' field with
virDomainCapsCPUUsable type, the lower level structure specific to QEMU
driver used virTriStateBool for the same thing and we had to translate
between them.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use g_autofree in virQEMUCapsLoadCPUModels
Jiri Denemark [Tue, 24 Sep 2019 12:55:26 +0000 (14:55 +0200)]
qemu: Use g_autofree in virQEMUCapsLoadCPUModels

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add qemuMonitorCPUDefsCopy
Jiri Denemark [Tue, 24 Sep 2019 15:12:34 +0000 (17:12 +0200)]
qemu: Add qemuMonitorCPUDefsCopy

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Flatten qemuMonitorCPUDefs.cpus
Jiri Denemark [Tue, 24 Sep 2019 11:45:37 +0000 (13:45 +0200)]
qemu: Flatten qemuMonitorCPUDefs.cpus

Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in
qemuMonitorCPUDefs rather then using an array of pointers.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce qemuMonitorCPUDefs struct
Jiri Denemark [Tue, 24 Sep 2019 11:42:00 +0000 (13:42 +0200)]
qemu: Introduce qemuMonitorCPUDefs struct

It is a container for a CPU models list (qemuMonitorCPUDefInfo) and a
number of elements in this list.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Change return type of virQEMUCapsFetchCPUDefinitions
Jiri Denemark [Thu, 10 Oct 2019 14:44:40 +0000 (16:44 +0200)]
qemu: Change return type of virQEMUCapsFetchCPUDefinitions

The function would return a valid virDomainCapsCPUModelsPtr with empty
CPU models list if query-cpu-definitions exists in QEMU, but returns
GenericError meaning it's not in fact implemented. This behaviour is a
bit strange especially after such virDomainCapsCPUModels structure is
stored in capabilities XML and parsed back, which will result in NULL
virDomainCapsCPUModelsPtr rather than a structure containing nothing.

Let's just keep virDomainCapsCPUModelsPtr NULL if the QMP command is not
implemented and change the return value to int so that callers can
easily check for failure or success.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use g_autoptr in qemuMonitorJSONGetCPUDefinitions
Jiri Denemark [Tue, 24 Sep 2019 11:20:49 +0000 (13:20 +0200)]
qemu: Use g_autoptr in qemuMonitorJSONGetCPUDefinitions

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virQEMUCapsGetCPUDefinitions more
Jiri Denemark [Fri, 20 Sep 2019 20:54:13 +0000 (22:54 +0200)]
qemu: Use virQEMUCapsGetCPUDefinitions more

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Filter models in virQEMUCapsGetCPUDefinitions
Jiri Denemark [Fri, 20 Sep 2019 20:48:13 +0000 (22:48 +0200)]
qemu: Filter models in virQEMUCapsGetCPUDefinitions

Some callers of virQEMUCapsGetCPUDefinitions will need to filter the
returned list of CPU models. Let's add the filtering parameters directly
to virQEMUCapsGetCPUDefinitions to avoid copying the CPU models list
twice.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Copy CPU models in virQEMUCapsGetCPUDefinitions
Jiri Denemark [Fri, 20 Sep 2019 20:41:34 +0000 (22:41 +0200)]
qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions

Rather than returning a direct pointer the list stored in qemuCaps the
function now creates a new copy of the CPU models list.

The main purpose of this seemingly useless change is to update callers
to free the result returned by virQEMUCapsGetCPUDefinitions because the
internals of this function will change significantly in the following
patches.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>