]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
3 years agoconf: add encryption engine property
Or Ozeri [Sun, 24 Oct 2021 09:51:28 +0000 (04:51 -0500)] 
conf: add encryption engine property

This commit extends libvirt XML configuration to support a custom encryption engine.
This means that <encryption format="luks" engine="qemu">  becomes valid.
The only engine for now is qemu. However, a new engine (librbd) will be added in an upcoming commit.
If no engine is specified, qemu will be used (assuming qemu driver is used).

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: capablities: Detect presence of 'rbd-encryption' as QEMU_CAPS_RBD_ENCRYPTION
Or Ozeri [Sun, 24 Oct 2021 09:51:27 +0000 (04:51 -0500)] 
qemu: capablities: Detect presence of 'rbd-encryption' as QEMU_CAPS_RBD_ENCRYPTION

rbd encryption is new in qemu 6.1.0.
This commit adds capability probing for it.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: add disk post parse to qemublocktest
Or Ozeri [Sun, 24 Oct 2021 09:51:26 +0000 (04:51 -0500)] 
qemu: add disk post parse to qemublocktest

The post parse callback is part of the real (non-test) processing flow.
This commit adds it (for disks) to the qemublocktest flow as well.
Specifically, this will be needed for tests that use luks encryption,
so that the default encryption engine (which is added in an upcoming commit)
will be overridden by qemu.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoci: regenerate container from manifest
Daniel P. Berrangé [Mon, 25 Oct 2021 11:45:31 +0000 (12:45 +0100)] 
ci: regenerate container from manifest

This removes the libnetcf-dev package from Debian Sid, as it is no
longer available in that distro stream.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu_monitor_json: Drop pointless error labels
Michal Privoznik [Fri, 22 Oct 2021 07:59:51 +0000 (09:59 +0200)] 
qemu_monitor_json: Drop pointless error labels

After previous cleanups, some 'error' labels were rendered
needless - they contain nothing more than a return statement.
Well, those labels can be dropped and 'goto error' can be
replaced with return statement directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Drop pointless cleanup labels
Michal Privoznik [Thu, 21 Oct 2021 08:33:51 +0000 (10:33 +0200)] 
qemu_monitor_json: Drop pointless cleanup labels

After previous cleanups, some 'cleanup' labels were rendered
needless - they contain nothing more than a return statement.
Well, those labels can be dropped and 'goto cleanup' can be
replaced with return statement directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Use g_autofree
Michal Privoznik [Thu, 21 Oct 2021 08:21:24 +0000 (10:21 +0200)] 
qemu_monitor_json: Use g_autofree

Let's replace VIR_FREE() calls with g_autofree. Not all calls can
be replaced though - the legitimate ones are kept (e.g. those
which free array, or which free a struct for which we don't have
g_autoptr() yet, and so on).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Use g_autoptr() for virJSONValue
Michal Privoznik [Thu, 21 Oct 2021 08:14:47 +0000 (10:14 +0200)] 
qemu_monitor_json: Use g_autoptr() for virJSONValue

A lot of explicit free calls can be saved when virJSONValue
variables are declared with g_autoptr(). There's one caveat:
there was a slight deviation from our usual pattern such that
@cmd variable was not initialized to NULL but as the very first
step it was assigned a value using qemuMonitorJSONMakeCommand().
While this works in theory it upset my GCC-11.2 (but only when
building with -O2). So I had to initialize the variable in such
case too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemuMonitorJSONExtractPRManagerInfo: Declare @entry inside the loop
Michal Privoznik [Fri, 22 Oct 2021 05:44:03 +0000 (07:44 +0200)] 
qemuMonitorJSONExtractPRManagerInfo: Declare @entry inside the loop

The reason why @entry variable in qemuMonitorJSONExtractPRManagerInfo()
was declared at the top most level was that the variable is used under
the cleanup label.  However, if declared using g_autofree then the
variable can be declared inside the loop it is used in.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Use g_autoptr() for qemuMonitorCPUModelInfo
Michal Privoznik [Fri, 22 Oct 2021 07:58:48 +0000 (09:58 +0200)] 
qemu_monitor_json: Use g_autoptr() for qemuMonitorCPUModelInfo

There's one place (specifically qemuMonitorJSONParseCPUModel())
where we can avoid explicit free call for qemuMonitorCPUModelInfo
struct.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Use g_autoptr() for virCPUData
Michal Privoznik [Fri, 22 Oct 2021 07:57:39 +0000 (09:57 +0200)] 
qemu_monitor_json: Use g_autoptr() for virCPUData

We have g_autoptr() for virCPUData struct defined already. Let's
use it in qemu_monitor_json.c and drop explicit free calls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo
Michal Privoznik [Fri, 22 Oct 2021 07:31:22 +0000 (09:31 +0200)] 
qemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemuMonitorJSONQueryRxFilterParse: Set *filter only on success
Michal Privoznik [Fri, 22 Oct 2021 05:17:03 +0000 (07:17 +0200)] 
qemuMonitorJSONQueryRxFilterParse: Set *filter only on success

The qemuMonitorJSONQueryRxFilterParse() function is called to
parse the output of 'query-rx-filter' and store results into
passed virNetDevRxFilter structure. However, it is doing so in a
bit clumsy way - the return pointer is set in all cases (i.e.
even in case of error) and thus the cleanup label is more
complicated than it needs to be. With a help of g_autoptr() and
g_steal_pointer() the return pointer can be set only in case of
success - which is what callers expect anyway.

The same applies to qemuMonitorJSONQueryRxFilter().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemuMonitorJSONGetMigrationStats: Don't clear @stats on failure
Michal Privoznik [Fri, 22 Oct 2021 05:07:09 +0000 (07:07 +0200)] 
qemuMonitorJSONGetMigrationStats: Don't clear @stats on failure

In the qemuMonitorJSONGetMigrationStats() there's a code under
cleanup label that's clearing returned @stats if the function
returns with an error. However, transitively there's just one
caller - qemuMigrationAnyFetchStats() - and it doesn't care for
this behaviour. Drop the code to simplify the cleanup label.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemuMonitorJSONHumanCommand: Require @reply_str
Michal Privoznik [Fri, 22 Oct 2021 08:08:35 +0000 (10:08 +0200)] 
qemuMonitorJSONHumanCommand: Require @reply_str

All callers of qemuMonitorJSONHumanCommand() pass a non-NULL pointer
as @reply_str therefore there's no need to check whether it is NULL.
NB, the sister function (qemuMonitorJSONArbitraryCommand()) doesn't
check for NULL either.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Don't transfer ownership to @msg
Michal Privoznik [Thu, 21 Oct 2021 10:53:35 +0000 (12:53 +0200)] 
qemu_monitor_json: Don't transfer ownership to @msg

In qemuMonitorJSONCommandWithFd() given command (represented by
virJSONValue struct) is translated to string (represented by
virBuffer). The ownership of the string is then transferred to
the message which is then sent. The downside of this approach is
we have to have an explicit call to free the string from the
message. But if the message just "borrowed" the string (which it
can safely do because it is just reading from the string) then
automatic free of the buffer takes care of freeing the string.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agoqemu_monitor_json: Don't check for qemuMonitorNextCommandID() retval
Michal Privoznik [Thu, 21 Oct 2021 10:52:14 +0000 (12:52 +0200)] 
qemu_monitor_json: Don't check for qemuMonitorNextCommandID() retval

The qemuMonitorNextCommandID() function can never fail. There's
no need to check for its retval then. Moreover, the temporary
variable used to hold the retval can be declared in the inner
most block.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
3 years agolib: Drop intermediary return variables
Michal Privoznik [Fri, 22 Oct 2021 08:56:01 +0000 (10:56 +0200)] 
lib: Drop intermediary return variables

In a few places we declare a variable (which is optionally
followed by a code not touching it) then set the variable to a
value and return the variable immediately. It's obvious that the
variable is needless and the value can be returned directly
instead.

This patch was generated using this semantic patch:

  @@
  type T;
  identifier ret;
  expression E;
  @@
  - T ret;
  ... when != ret
      when strict
  - ret = E;
  - return ret;
  + return E;

After that I fixed couple of formatting issues because coccinelle
formatted some lines differently than our coding style.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONGetMigrationCapabilities: Don't return early on CommandNotFound
Michal Privoznik [Wed, 20 Oct 2021 07:03:04 +0000 (09:03 +0200)] 
qemuMonitorJSONGetMigrationCapabilities: Don't return early on CommandNotFound

The qemuMonitorJSONGetMigrationCapabilities() command executes
'query-migrate-capabilities' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 1.2 (specifically in commit v1.2.0-rc0~29^2~11) and
since the minimum required version is 2.11.0 we can be sure that
command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONGetMemoryDeviceInfo: Don't return early on CommandNotFound
Michal Privoznik [Thu, 21 Oct 2021 08:50:09 +0000 (10:50 +0200)] 
qemuMonitorJSONGetMemoryDeviceInfo: Don't return early on CommandNotFound

The qemuMonitorJSONGetMemoryDeviceInfo() command executes
'query-memory-devices' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 2.1 (specifically in commit v2.1.0-rc0~41^2~9) and
since the minimum required version is 2.11.0 we can be sure that
command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONGetKVMState: Don't return early on CommandNotFound
Michal Privoznik [Thu, 21 Oct 2021 08:46:09 +0000 (10:46 +0200)] 
qemuMonitorJSONGetKVMState: Don't return early on CommandNotFound

The qemuMonitorJSONGetKVMState() command executes 'query-kvm'
command and returns early if QEMU doesn't know the command. Well,
the command was introduced in QEMU release 0.14 and since the
minimum required version is 2.11.0 we can be sure that command
will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONGetDumpGuestMemoryCapability: Don't return early on CommandNotFound
Michal Privoznik [Thu, 21 Oct 2021 08:42:20 +0000 (10:42 +0200)] 
qemuMonitorJSONGetDumpGuestMemoryCapability: Don't return early on CommandNotFound

The qemuMonitorJSONGetDumpGuestMemoryCapability() command
executes 'query-dump-guest-memory-capability' command and returns
early if QEMU doesn't know the command. Well, the command was
introduced in QEMU release 2.0 (specifically in commit
v2.0.0-rc0~43^2~16) and since the minimum required version is
2.11.0 we can be sure that command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONGetMigrationParams: Don't return early on CommandNotFound
Michal Privoznik [Thu, 21 Oct 2021 08:37:17 +0000 (10:37 +0200)] 
qemuMonitorJSONGetMigrationParams: Don't return early on CommandNotFound

The qemuMonitorJSONGetMigrationParams() function executes
'query-migrate-parameters' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 2.4 (specifically in commit v2.4.0-rc0~147^2~3) and
since the minimum required version is 2.11.0 we can be sure that
the command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemumigparamstest: Drop "unsupported" test case
Michal Privoznik [Thu, 21 Oct 2021 09:01:03 +0000 (11:01 +0200)] 
qemumigparamstest: Drop "unsupported" test case

The aim of "unsupported" test case is to check whether our code
handles 'CommandNotFound' error returned for
'query-migrate-parameters' monitor command. Well, the command is
pretty old and every QEMU that we are dealing with supports it.
Thus this test case is useless. Drop it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agonews: Add PCI VPD parser & capability notes
Dmitrii Shcherbakov [Wed, 20 Oct 2021 08:30:35 +0000 (11:30 +0300)] 
news: Add PCI VPD parser & capability notes

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
3 years agoAdd PCI VPD Capability Documentation
Dmitrii Shcherbakov [Wed, 20 Oct 2021 08:30:34 +0000 (11:30 +0300)] 
Add PCI VPD Capability Documentation

Describes the format of the newly added VPD capability and gives and
example for a real-world device.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
3 years agoAdd PCI VPD Capability Support
Dmitrii Shcherbakov [Wed, 20 Oct 2021 08:30:33 +0000 (11:30 +0300)] 
Add PCI VPD Capability Support

* XML serialization and deserialization of PCI VPD;
* PCI VPD capability flags added and used in relevant places;
* XML to XML tests for the added capability.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
3 years agoAdd PCI VPD-related helper functions to virpci
Dmitrii Shcherbakov [Wed, 20 Oct 2021 08:30:32 +0000 (11:30 +0300)] 
Add PCI VPD-related helper functions to virpci

Add helper functions to virpci to provide means of checking for a VPD
file presence and for VPD resource retrieval using the PCI VPD parser.

The added test assesses the basic functionality of VPD retrieval while
the full parser is tested by virpcivpdtest.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
3 years agoAdd a PCI/PCIe device VPD Parser
Dmitrii Shcherbakov [Wed, 20 Oct 2021 08:30:31 +0000 (11:30 +0300)] 
Add a PCI/PCIe device VPD Parser

Add support for deserializing the binary PCI/PCIe VPD format and storing
results in memory.

The VPD format is specified in "I.3. VPD Definitions" in PCI specs
(2.2+) and "6.28.1 VPD Format" PCIe 4.0. As section 6.28 in PCIe 4.0
notes, the PCI Local Bus and PCIe VPD formats are binary compatible
and PCIe 4.0 merely started incorporating what was already present in
PCI specs.

Linux kernel exposes a binary blob in the VPD format via sysfs since
v2.6.26 (commit 94e6108803469a37ee1e3c92dafdd1d59298602f) which requires
a parser to interpret.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
3 years agoNEWS: document virtiofs hotplug
Ján Tomko [Tue, 12 Oct 2021 12:45:01 +0000 (14:45 +0200)] 
NEWS: document virtiofs hotplug

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoconf: Add new/free functions for virDomainIOMMUDef
Andrea Bolognani [Thu, 23 Sep 2021 13:20:25 +0000 (15:20 +0200)] 
conf: Add new/free functions for virDomainIOMMUDef

This will make it possible to limit changes to a single spot
later on, and is also just an overall nicer way to create and
destroy objects.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoconf: Add IOMMU support to virDomainDeviceDefCopy()
Andrea Bolognani [Thu, 23 Sep 2021 16:59:13 +0000 (18:59 +0200)] 
conf: Add IOMMU support to virDomainDeviceDefCopy()

There doesn't seem to be a reason for IOMMUs not to be handled
by this function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Make qemuBuildVirtioDevProps() const correct
Andrea Bolognani [Wed, 20 Oct 2021 10:01:03 +0000 (12:01 +0200)] 
qemu: Make qemuBuildVirtioDevProps() const correct

This involves a bit of a hack, but is overall preferable to
forcing callers to pass non-const devdata as argument.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Make qemuBuildDeviceAddressProps() const correct
Andrea Bolognani [Wed, 20 Oct 2021 10:16:41 +0000 (12:16 +0200)] 
qemu: Make qemuBuildDeviceAddressProps() const correct

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoconf: Make virDomainDeviceInfoFormat() const correct
Andrea Bolognani [Thu, 23 Sep 2021 13:43:26 +0000 (15:43 +0200)] 
conf: Make virDomainDeviceInfoFormat() const correct

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotests: Add replies for QEMU 6.2.0 on aarch64
Andrea Bolognani [Wed, 6 Oct 2021 16:22:51 +0000 (18:22 +0200)] 
tests: Add replies for QEMU 6.2.0 on aarch64

These were generated using a QEMU binary built from commit
v6.1.0-1552-g362534a643

Notably, this causes the arguments of -device to be generated
in JSON format.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agorpc: Temporarily stop accept()-ing new clients on EMFILE
Michal Privoznik [Tue, 12 Oct 2021 07:55:38 +0000 (09:55 +0200)] 
rpc: Temporarily stop accept()-ing new clients on EMFILE

This commit is related to 5de203f879 which I pushed a few days
ago. While that commit prioritized closing clients socket over
the rest of I/O process, this one goes one step further and
temporarily suspends processing new connection requests.

A brief recapitulation of the problem:

1) assume that libvirt is at the top of RLIMIT_NOFILE (that is no
   new FDs can be opened).

2) we have a client trying to connect to a UNIX/TCP socket

Because of 2) our event loop sees POLLIN on the socket and thus
calls virNetServerServiceAccept(). But since no new FDs can be
opened (because of 1)) the request is not handled and we will get
the same event on next iteration. The poll() will exit
immediately because there is an event on the socket.  Thus we end
up in an endless loop.

To break the loop and stop burning CPU cycles we can stop
listening for events on the socket and set up a timer tho enable
listening again after some time (I chose 5 seconds because of no
obvious reason).

There's another area where we play with temporarily suspending
accept() of new clients - when a client disconnects and we check
max_clients against number of current clients. Problem here is
that max_clients can be orders of magnitude larger than
RLIMIT_NOFILE but more importantly, what this code considers
client disconnect is not equal to closing client's FD.
A client disconnecting means that the corresponding client
structure is removed from the internal list of clients. Closing
of the client's FD is done from event loop - asynchronously.

To avoid this part stepping on the toes of my fix, let's make the
code NOP if socket timer (as described above) is active.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoSwitch to new GitHub repo-lockdown configuration
Daniel P. Berrangé [Mon, 18 Oct 2021 13:45:25 +0000 (14:45 +0100)] 
Switch to new GitHub repo-lockdown configuration

The repo-lockdown service used to run as a bot outside GitHub, but has
now switched to using the GitHub Actions workflow framework. This
requires use of a new configuration file.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu: remove use of implicit boolean syntax for guest features
Daniel P. Berrangé [Tue, 5 Oct 2021 17:00:41 +0000 (18:00 +0100)] 
qemu: remove use of implicit boolean syntax for guest features

Some guest features that map to the -cpu arg are still added using
implicit syntax "feature" which is a deprecated shorthand for
"feature=on".

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu: inline the qemuBuildCpuFeature code
Daniel P. Berrangé [Tue, 5 Oct 2021 16:46:17 +0000 (17:46 +0100)] 
qemu: inline the qemuBuildCpuFeature code

With the previous refactorings, there's no real benefit from the
qemuBuildCpuFeature helper method. Only one of the callers really
needs the CPU feature name re-writing logic, the others can just
use the right name directly.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu: remove use of (+|-)name syntax for -cpu featres
Daniel P. Berrangé [Tue, 5 Oct 2021 16:46:17 +0000 (17:46 +0100)] 
qemu: remove use of (+|-)name syntax for -cpu featres

The -cpu arg gained support for feature=on|off syntax for the x86
emulator in 2.4.0

  commit 38e5c119c2925812bd441450ab9e5e00fc79e662
  Author: Eduardo Habkost <ehabkost@redhat.com>
  Date:   Mon Mar 23 17:29:32 2015 -0300

    target-i386: Register QOM properties for feature flags

Most other targets gained this syntax even earlier in 1.4.1

  commit 1590bbcb02921dfe8e3cf66e3a3aafd31193babf
  Author: Andreas Färber <afaerber@suse.de>
  Date:   Mon Mar 3 23:33:51 2014 +0100

    cpu: Implement CPUClass::parse_features() for the rest of CPUs

    CPUs who do not provide their own implementation of feature parsing
    will treat each option as a QOM property and set it to the supplied
    value.

There appears no reason to keep supporting "+|-feature" syntax,
given the current minimum QEMU version.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu: always use hyphens in hyperv feature names
Daniel P. Berrangé [Thu, 7 Oct 2021 14:33:35 +0000 (15:33 +0100)] 
qemu: always use hyphens in hyperv feature names

QEMU switched from using underscores in x86 CPU features to hyphens
in the 2.8.0 series with two commits

  commit fc7dfd205f3287893c436d932a167bffa30579c8 (HEAD, refs/bisect/bad)
  Author: Eduardo Habkost <ehabkost@redhat.com>
  Date:   Fri Sep 30 15:49:40 2016 -0300

    target-i386: Remove underscores from feat_names arrays

  commit 54b8dc7c19cd781e96f1e9b001ca6001d804eb19
  Author: Eduardo Habkost <ehabkost@redhat.com>
  Date:   Fri Sep 30 15:49:38 2016 -0300

    target-i386: Register aliases for feature names with underscores

Libvirt names use underscores so we conditionally tranlate the
names when talking to new QEMU. Since the min QEMU was raised to
version 2.11.0, all QEMU versions we talk to expect hypens, so
the translation can be done unconditionally.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemu: always translate underscores to hyphens in CPU features
Daniel P. Berrangé [Thu, 7 Oct 2021 14:25:54 +0000 (15:25 +0100)] 
qemu: always translate underscores to hyphens in CPU features

QEMU switched from using underscores in x86 CPU features to hyphens
in the 2.8.0 series with two commits

  commit fc7dfd205f3287893c436d932a167bffa30579c8 (HEAD, refs/bisect/bad)
  Author: Eduardo Habkost <ehabkost@redhat.com>
  Date:   Fri Sep 30 15:49:40 2016 -0300

    target-i386: Remove underscores from feat_names arrays

  commit 54b8dc7c19cd781e96f1e9b001ca6001d804eb19
  Author: Eduardo Habkost <ehabkost@redhat.com>
  Date:   Fri Sep 30 15:49:38 2016 -0300

    target-i386: Register aliases for feature names with underscores

Libvirt names use underscores so we conditionally tranlate the
names when talking to new QEMU. Since the min QEMU was raised to
version 2.11.0, all QEMU versions we talk to expect hypens, so
the translation can be done unconditionally.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoci: switch all non-released distros to be non-gating
Daniel P. Berrangé [Wed, 20 Oct 2021 10:43:37 +0000 (11:43 +0100)] 
ci: switch all non-released distros to be non-gating

The non-released distros have reasonably frequent package installation
failures that can last for days at a time. This makes them unsuitable
for use as gating CI jobs.

This ensures all of the jobs in Debian Sid, Fedora Rawhide, openSUSE
Tumbleweed and FreeBSD Current are marked "allow-failure: true".

This means the jobs still run, but any failure will not be considered
fatal to the pipeline.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoci: refresh configuration from manifest
Daniel P. Berrangé [Wed, 20 Oct 2021 10:37:16 +0000 (11:37 +0100)] 
ci: refresh configuration from manifest

The layering of the cross containers is fixed to move arch specific
ccache setup out of the common base layer.

A missing Cirrus CI variable substitution is added, though this is
irrelevant given libvirt's package list.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemuMonitorBlockStatsUpdateCapacity: Remove 'backingChain' argument
Peter Krempa [Tue, 19 Oct 2021 13:57:25 +0000 (15:57 +0200)] 
qemuMonitorBlockStatsUpdateCapacity: Remove 'backingChain' argument

Always fetch the stats for all backing chain members. Callers from
qemu_driver.c already always passed 'true' and the caller from the
migration code won't mind when we fetch all stats.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuMonitorGetAllBlockStatsInfo: Remove 'backingChain' argument
Peter Krempa [Tue, 19 Oct 2021 13:25:46 +0000 (15:25 +0200)] 
qemuMonitorGetAllBlockStatsInfo: Remove 'backingChain' argument

All (proper) callers pass true so we can remove the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuMonitorJSONQueryBlockstats: Refactor cleanup
Peter Krempa [Tue, 19 Oct 2021 13:05:21 +0000 (15:05 +0200)] 
qemuMonitorJSONQueryBlockstats: Refactor cleanup

Use automatic memory clearing and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuDomainGetStatsBlock: Refactor cleanup
Peter Krempa [Tue, 19 Oct 2021 12:48:16 +0000 (14:48 +0200)] 
qemuDomainGetStatsBlock: Refactor cleanup

Use automatic memory clearing for the temporary variables and remove the
cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuMonitorJSONBlockStatsUpdateCapacityOne: Refactor cleanup
Peter Krempa [Tue, 19 Oct 2021 12:48:16 +0000 (14:48 +0200)] 
qemuMonitorJSONBlockStatsUpdateCapacityOne: Refactor cleanup

Use automatic memory clearing for the temporary variable and remove the
cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuMonitorJSONBlockStatsUpdateCapacity: Refactor cleanup
Peter Krempa [Tue, 19 Oct 2021 12:48:16 +0000 (14:48 +0200)] 
qemuMonitorJSONBlockStatsUpdateCapacity: Refactor cleanup

Use automatic memory clearing for the temporary variable and remove the
cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuDomainGetStatsBlock: Always fetch stats for the full backing chain
Peter Krempa [Tue, 19 Oct 2021 13:12:36 +0000 (15:12 +0200)] 
qemuDomainGetStatsBlock: Always fetch stats for the full backing chain

Similarly to the fix to 'qemuDomainBlocksStatsGather' we should be
always fetching the full backing chain so that we can avoid any
automatic filter notes which would prevent us from fetching the stats
for the correct nodename.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemuDomainBlocksStatsGather: Always fetch stats for the full backing chain
Peter Krempa [Tue, 19 Oct 2021 12:32:09 +0000 (14:32 +0200)] 
qemuDomainBlocksStatsGather: Always fetch stats for the full backing chain

In certain cases such as when running a backup blockjob qemu installs a
filter node between the frontend and the top node of the backend of the
disk. The stats gathering code didn't instruct the monitor code to fetch
the stats for all the layers, so since the top layer now doesn't have
stats we were reporting wrong stats such as allocation.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2015281
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu: tpm: Run swtpm_setup --create-config-files in session mode
Stefan Berger [Tue, 19 Oct 2021 13:43:20 +0000 (09:43 -0400)] 
qemu: tpm: Run swtpm_setup --create-config-files in session mode

Using swtpm v0.7.0 we can run swtpm_setup to create default config files
for swtpm_setup and swtpm-localca in session mode. Now a user can start
a VM with an attached TPM without having to run this program on the
command line before. This program needs to run once.

This patch addresses the issue raised in
https://bugzilla.redhat.com/show_bug.cgi?id=2010649

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
3 years agoqemu: Move pid file of virtiofsd to stateDir
Peng Liang [Mon, 18 Oct 2021 09:20:12 +0000 (17:20 +0800)] 
qemu: Move pid file of virtiofsd to stateDir

Libvirt will put the pid file of virtiofsd to per-domain directory.
However, the ownership of the per-domain directory is the user to run
the QEMU process and the user has the write permission of the directory.
If VM escape occurs, the attacker can
1. write arbitrary content to the pid file (if running QEMU using root),
   then the attacker can kill any process by writing appropriate pid to
   the pid file;
2. spoof the pid file (if running QEMU using a regular user), then the
   virtiofsd process will never be cleared even if the VM is destroyed.

So, move the pid file of virtiofsd from per-domain directory to
stateDir.

Signed-off-by: Peng Liang <liangpeng10@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu: Move pid file of pr-helper to stateDir
Peng Liang [Mon, 18 Oct 2021 09:20:11 +0000 (17:20 +0800)] 
qemu: Move pid file of pr-helper to stateDir

Libvirt will put the pid file of pr-helper to per-domain directory.
However, the ownership of the per-domain directory is the user to run
the QEMU process and the user has the write permission of the directory.
If VM escape occurs, the attacker can
1. write arbitrary content to the pid file (if running QEMU using root),
   then the attacker can kill any process by writing appropriate pid to
   the pid file;
2. spoof the pid file (if running QEMU using a regular user), then the
   pr-helper process will never be cleared even if the VM is destroyed.

So, move the pid file of pr-helper from per-domain directory to
stateDir.

Signed-off-by: Peng Liang <liangpeng10@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirNodeDeviceDefParse: Don't call post-parse callbacks with NULL def
Peter Krempa [Mon, 18 Oct 2021 07:54:08 +0000 (09:54 +0200)] 
virNodeDeviceDefParse: Don't call post-parse callbacks with NULL def

When parsing of the node device XML fails we'd still call the post-parse
and validation callbacks which makes no sense. Additionally the
callbacks were expecting a non-NULL pointer which leads to a crash.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2014139
Fixes: d5ae634ba28
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
3 years agovirsh: Add QMP command wrapping for 'qemu-monitor-command'
Peter Krempa [Thu, 12 Dec 2019 11:13:21 +0000 (12:13 +0100)] 
virsh: Add QMP command wrapping for 'qemu-monitor-command'

Issuing simple QMP commands is pain as they need to be wrapped by the
JSON wrapper:

 { "execute": "COMMAND" }

and optionally also:

 { "execute": "COMMAND", "arguments":...}

For simple commands without arguments we can add syntax sugar to virsh
which allows simple usage of QMP and additionally prepares also for
passing through of the 'arguments' section:

 virsh qemu-monitor-command $VM query-status

is equivalent to

 virsh qemu-monitor-command $VM '{"execute":"query-status"}'

and

 virsh qemu-monitor-command $VM query-named-block-nodes '{"flat":true}'
 or
 virsh qemu-monitor-command $VM query-named-block-nodes '"flat":true'

is equivalent to

 virsh qemu-monitor-command $VM '{"execute":"query-named-block-nodes", "arguments":{"flat":true}}'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoNEWS: Mention conversion of '-device' to JSON starting with QEMU-6.2
Peter Krempa [Mon, 18 Oct 2021 07:29:38 +0000 (09:29 +0200)] 
NEWS: Mention conversion of '-device' to JSON starting with QEMU-6.2

Normally this would be considered an internal detail which we don't
document in the news, but in this case I'd like to make people aware of
the change so that they preferrably report them ASAP.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotestCompareXMLToArgvValidateSchemaCommand: Add validation for '-device'
Peter Krempa [Fri, 15 Oct 2021 10:21:06 +0000 (12:21 +0200)] 
testCompareXMLToArgvValidateSchemaCommand: Add validation for '-device'

Now that we use JSON with -device we can validate it at least partially
(since the schema for 'device_add' is for now incomplete) against the
QMP schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Use JSON directly for '-device'
Peter Krempa [Fri, 15 Oct 2021 09:42:19 +0000 (11:42 +0200)] 
qemu: Use JSON directly for '-device'

Starting with QEMU-6.2 started accepting a JSON object as argument for
'-device' which will also become the only syntax considered stable by
qemu in the future.

Since libvirt was recently converted to generate the properties via JSON
to begin wit we can start using it on the commandline as well, by simply
enabling the QEMU_CAPS_DEVICE_JSON capability, which we do by probing
for the 'json-cli' feature flag of 'device_add'.

Normally a change which changes a commandline output should be happening
only after the impacted real-caps test files are forked in the version
preceding the change, but in this case it's not necessary as the logic
for generating the device properties stays identical and we just change
the output format (avoid conversion). Additionally we still have a lot
of tests validating the conversion to the old commandline options.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorTestProcessCommandDefaultValidate: Partially validate 'device_add'
Peter Krempa [Fri, 15 Oct 2021 10:18:00 +0000 (12:18 +0200)] 
qemuMonitorTestProcessCommandDefaultValidate: Partially validate 'device_add'

Use the 'allowIncomplete' argument of testQEMUSchemaValidateCommand to
validate at least properties which are already described by the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotestQEMUSchemaValidateCommand: Add possibility for partial QMP validation
Peter Krempa [Fri, 15 Oct 2021 10:06:14 +0000 (12:06 +0200)] 
testQEMUSchemaValidateCommand: Add possibility for partial QMP validation

The QMP schema for 'device_add' is not complete yet. Allow validation of
incomplete schema so that we can enable at least some validation. Once
there's more schema in the future all present members are still
validated.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemucapabilitiestest: Update qemu-6.2 cycle capability test data
Peter Krempa [Fri, 15 Oct 2021 09:40:05 +0000 (11:40 +0200)] 
qemucapabilitiestest: Update qemu-6.2 cycle capability test data

Update to v6.1.0-1510-gc148a05721 which most notably adds the 'json-cli'
feature for 'device_add' QMP command meaning that -device accepts JSON.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Decrease scope of variables in qemuConnectGetAllDomainStats()
Michal Privoznik [Mon, 18 Oct 2021 08:52:47 +0000 (10:52 +0200)] 
qemu: Decrease scope of variables in qemuConnectGetAllDomainStats()

There are two variables (@vm and @domflags) in qemuConnectGetAllDomainStats()
that are used only within the for() loop but declared for entire function.
Bring them into the loop to make it obvious they are not used outside of it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
3 years agoobjecteventtest: Don't overwrite @ret on failure
Michal Privoznik [Thu, 7 Oct 2021 15:47:31 +0000 (17:47 +0200)] 
objecteventtest: Don't overwrite @ret on failure

Our general pattern is to initialize @ret to -1 and set it to 0
only at the end of a function. Some functions in
objecteventtest.c do not follow this pattern.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
3 years agoobjecteventtest: Drop lifecycleEventCounter_reset()
Michal Privoznik [Thu, 7 Oct 2021 15:29:17 +0000 (17:29 +0200)] 
objecteventtest: Drop lifecycleEventCounter_reset()

The sole purpose of the lifecycleEventCounter_reset() function is
to zero out given lifecycleEventCounter struct. Well, we can let
the compiler zero it out when declaring a variable and just
remove the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
3 years agoNEWS: document bug fix about virsh domstats on qemu < 5.2.0
Hiroki Narukawa [Fri, 15 Oct 2021 09:49:20 +0000 (18:49 +0900)] 
NEWS: document bug fix about virsh domstats on qemu < 5.2.0

I think that virsh domstats problem on qemu < 5.2.0 is what users want
to find which version fixes.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_driver: add check for qemu capabilities requirements
Hiroki Narukawa [Fri, 15 Oct 2021 09:49:19 +0000 (18:49 +0900)] 
qemu_driver: add check for qemu capabilities requirements

query-dirty-rate command is used for virsh domstats by default, but this
is available only on qemu >=5.2.0.

By this commit, qemu domain stats will check capabilities requirements before issuing actual query.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_driver: add required capabilities to qemuDomainGetStatsWorkers
Hiroki Narukawa [Fri, 15 Oct 2021 09:49:18 +0000 (18:49 +0900)] 
qemu_driver: add required capabilities to qemuDomainGetStatsWorkers

One of qemuDomainGetStatsWorkers requires capabilities to run.

This commit adds capability information to qemuDomainGetStatsWorkers.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_capabilities: Add QEMU_CAPS_QUERY_DIRTY_RATE capability
Hiroki Narukawa [Fri, 15 Oct 2021 09:49:17 +0000 (18:49 +0900)] 
qemu_capabilities: Add QEMU_CAPS_QUERY_DIRTY_RATE capability

query-dirty-rate command is used for virsh domstats by default, but this
is available only on qemu >=5.2.0.

In this commit, add capability flag for query-dirty-rate first.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu: Do not report eof when processing monitor IO
Jim Fehlig [Wed, 6 Oct 2021 04:23:51 +0000 (22:23 -0600)] 
qemu: Do not report eof when processing monitor IO

There have been countless reports from users concerned about the following
error reported by libvirtd when qemu domains are shutdown

internal error: End of file from qemu monitor

While the error is harmless, users often mistaken it for real problem with
their deployments. EOF from the monitor can't be entirely ignored since
other threads may be using the monitor and must be able to detect the EOF
condition.

One potential fix is to delay reporting EOF until the monitor is used
after EOF is detected. This patch adds a 'goteof' member to the
qemuMonitor structure, which is set when EOF is detected on the monitor
socket. If another thread later tries to send data on the monitor, the
EOF error is reported.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsocket: Use g_auto* more
Michal Privoznik [Fri, 15 Oct 2021 11:41:12 +0000 (13:41 +0200)] 
virnetsocket: Use g_auto* more

There are few functions in virnetsocket.c where an object/memory
is freed by explicit call. Use g_autoptr()/g_autofree/VIR_AUTOCLOSE
to do that automatically.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirnetsocket: Don't free virCommand in virNetSocketNewConnectCommand()
Michal Privoznik [Fri, 15 Oct 2021 11:39:36 +0000 (13:39 +0200)] 
virnetsocket: Don't free virCommand in virNetSocketNewConnectCommand()

The aim of virNetSocketNewConnectCommand() is to execute passed
command and attach socket pair/pipe to it so that client socket
can be opened (this is used for connections with alternative
transports, e.g. ssh). The virCommand is created in a caller and
then passed to virNetSocketNewConnectCommand() where it is freed
using virCommandFree(). This approach is wrong on two levels:

1) The deallocation happens on a different level than allocation,
2) There's a WIN32 stub that just reports an error and doesn't
   free the command.

However, with g_autoptr() trickery the command can be freed in
caller.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu_validate: Fix capability check for disk queue_size
Hiroki Narukawa [Fri, 15 Oct 2021 10:11:49 +0000 (19:11 +0900)] 
qemu_validate: Fix capability check for disk queue_size

Commit ad209e7d adds QEMU_CAPS_VIRTIO_BLK_QUEUE_SIZE capability, but
the following commit 2d6d67e1 missed to use it and uses
QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES instead.

This commit fixes the mistake.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu: capabilities: Retire QEMU_CAPS_VIRTIO_PCI_ATS
Michal Privoznik [Fri, 15 Oct 2021 08:47:54 +0000 (10:47 +0200)] 
qemu: capabilities: Retire QEMU_CAPS_VIRTIO_PCI_ATS

The capability reflects whether QEMU is capable of -device
virtio-*,ats=. Since the property was introduced in QEMU commit
v2.9.0-rc0~162^2~32 we can safely assume the property is always
present as the minimal version required is 2.11.0.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemuxml2argvtest: Drop negative virtio-*-ats tests
Michal Privoznik [Fri, 15 Oct 2021 08:56:34 +0000 (10:56 +0200)] 
qemuxml2argvtest: Drop negative virtio-*-ats tests

There are some tests cases in qemuxml2argvtest that aim to check
whether our validator rejects <driver ats=''/> when
QEMU_CAPS_VIRTIO_PCI_ATS capability is not present.  Well, such
scenario can't happen really because the capability will always
be present.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: capabilities: Retire QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM
Michal Privoznik [Fri, 15 Oct 2021 07:48:48 +0000 (09:48 +0200)] 
qemu: capabilities: Retire QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM

The capability reflects whether QEMU is capable of -device
virtio-*,iommu_platform=. Since the property was introduced in
QEMU commit v2.9.0-rc0~162^2~37 we can safely assume the property
is always present as the minimal version required is 2.11.0.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemuxml2argvtest: Drop negative virtio-*-iommu tests
Michal Privoznik [Fri, 15 Oct 2021 08:55:49 +0000 (10:55 +0200)] 
qemuxml2argvtest: Drop negative virtio-*-iommu tests

There are some tests cases in qemuxml2argvtest that aim to check
whether our validator rejects <driver iommu=''/> when
QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM capability is not present.
Well, such scenario can't happen really because the capability
will always be present.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agotest: Drop unused .args or .xml files
Michal Privoznik [Fri, 15 Oct 2021 08:10:42 +0000 (10:10 +0200)] 
test: Drop unused .args or .xml files

There are a few files containing expected output for test cases
that no longer exist. Remove them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: Add support for virtio device option page-per-vq
Han Han [Fri, 15 Oct 2021 06:09:30 +0000 (14:09 +0800)] 
qemu: Add support for virtio device option page-per-vq

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

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoconf: Add page_per_vq for driver element
Han Han [Fri, 15 Oct 2021 06:09:29 +0000 (14:09 +0800)] 
conf: Add page_per_vq for driver element

Signed-off-by: Han Han <hhan@redhat.com>
Signed-off-by: Gavi Teitz <gavi@nvidia.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_migration: drop unnecessary 'migrate_speed' variable
Kristina Hanicova [Fri, 8 Oct 2021 08:19:05 +0000 (10:19 +0200)] 
qemu_migration: drop unnecessary 'migrate_speed' variable

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoqemu_migration: set bandwidth in priv during migration
Kristina Hanicova [Fri, 8 Oct 2021 08:19:04 +0000 (10:19 +0200)] 
qemu_migration: set bandwidth in priv during migration

We did not set priv->migMaxBandwidth if '--bandwidth' was
specified as an option in the 'migrate' virsh command. This
caused in printing the wrong value if virsh command
'migrate-getspeed' was called during the migration. This patch
first sets the value to the given bandwidth (if one was
specified) and restores the previous value after the migration.

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

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoqemuBuildFloppyCommandLineControllerOptionsExplicit: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 19:45:25 +0000 (21:45 +0200)] 
qemuBuildFloppyCommandLineControllerOptionsExplicit: Generate via JSON

QEMU declares the bootindex types as:

  bootindexA=<int32>
  bootindexB=<int32>

The driveA/driveB parameters were deprecated and removed in qemu-6.0.
We'll keep them for compatibility, but they are not used with -blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildFloppyCommandLineControllerOptions: Extract formatting of implicit/explicit fdc
Peter Krempa [Mon, 11 Oct 2021 17:01:28 +0000 (19:01 +0200)] 
qemuBuildFloppyCommandLineControllerOptions: Extract formatting of implicit/explicit fdc

qemuBuildFloppyCommandLineControllerOptions was generating config for
both the implicit and explicit fdc. The explicit FDC is using '-device'
and thus will need to be converted to JSON.

Split up the lookup of the floppy drive configs from the actual command
generation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildSmartcardCommandLine: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 15:08:58 +0000 (17:08 +0200)] 
qemuBuildSmartcardCommandLine: Generate via JSON

QEMU declares the props we control as:

'ccid-card-emulated'
  backend=<str>
  cert1=<str>
  cert2=<str>
  cert3=<str>
  db=<str>

'ccid-card-passthru'
  chardev=<str>          - ID of a chardev to use as a backend

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildIOMMUCommandLine: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 14:29:49 +0000 (16:29 +0200)] 
qemuBuildIOMMUCommandLine: Generate via JSON

QEMU declares the following types for fields we control:

  intremap=<OnOffAuto>   - on/off/auto (default: "auto")
  caching-mode=<bool>    -  (default: false)
  eim=<OnOffAuto>        - on/off/auto (default: "auto")
  device-iotlb=<bool>    -  (default: false)
  aw-bits=<uint8>        -  (default: 39)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVMCoreInfoCommandLine: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 14:21:31 +0000 (16:21 +0200)] 
qemuBuildVMCoreInfoCommandLine: Generate via JSON

While this device doesn't have any properties it must be converted to
use qemuBuildDeviceCommandlineFromJSON so that we can validate it in the
future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildTPMProxyCommandLine: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 14:12:52 +0000 (16:12 +0200)] 
qemuBuildTPMProxyCommandLine: Generate via JSON

All properties are strings according to QEMU.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVMGenIDCommandLine: Generate via JSON
Peter Krempa [Mon, 11 Oct 2021 14:08:24 +0000 (16:08 +0200)] 
qemuBuildVMGenIDCommandLine: Generate via JSON

QEMU declares the 'guid' property as:

  guid=<str>             - UUID (aka GUID) or "auto" for random value (default) (default: "auto")

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainSmartcardDef: Move validation of smartcard count
Peter Krempa [Mon, 11 Oct 2021 14:49:34 +0000 (16:49 +0200)] 
qemuValidateDomainSmartcardDef: Move validation of smartcard count

Move it into the validator. Note that the placement into the device
validation part is intentional so that it also covers hotplug code
paths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildSmartcardCommandLine: Replace qemuBuildSmartcardFindCCIDController
Peter Krempa [Mon, 11 Oct 2021 15:01:53 +0000 (17:01 +0200)] 
qemuBuildSmartcardCommandLine: Replace qemuBuildSmartcardFindCCIDController

We have a commonly used helper virDomainControllerAliasFind, which does
the same thing and also reports errors internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirDomainSmartcardDef: Declare 'type' as virDomainSmartcardType
Peter Krempa [Mon, 11 Oct 2021 14:47:59 +0000 (16:47 +0200)] 
virDomainSmartcardDef: Declare 'type' as virDomainSmartcardType

Use 'virXMLPropEnum' to parse it and fix all switch statements which
didn't include the VIR_DOMAIN_SMARTCARD_TYPE_LAST case.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainSmartcardDef: Move chardev validation under VIR_DOMAIN_SMARTCARD_TY...
Peter Krempa [Mon, 11 Oct 2021 14:37:56 +0000 (16:37 +0200)] 
qemuValidateDomainSmartcardDef: Move chardev validation under VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH

Don't check the type twice, move the chardev validation into the
switch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainSmartcardDef: Unbreak error messages
Peter Krempa [Mon, 11 Oct 2021 14:33:56 +0000 (16:33 +0200)] 
qemuValidateDomainSmartcardDef: Unbreak error messages

https://www.libvirt.org/coding-style.html#error-message-format

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceCommandlineFromJSON: Remove unused keyword
Peter Krempa [Mon, 11 Oct 2021 14:23:51 +0000 (16:23 +0200)] 
qemuBuildDeviceCommandlineFromJSON: Remove unused keyword

Now that the code was converted to use this helper we can remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildStorageSourceAttachPrepareDrive: Fix function comment
Peter Krempa [Mon, 11 Oct 2021 14:22:53 +0000 (16:22 +0200)] 
qemuBuildStorageSourceAttachPrepareDrive: Fix function comment

Remove mention of argument which no longer exists.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotools: add virt-host-validate-ch for ch driver
Praveen K Paladugu [Thu, 7 Oct 2021 21:49:37 +0000 (21:49 +0000)] 
tools: add virt-host-validate-ch for ch driver

Signed-off-by: Wei-Chen Chen <weicche@microsoft.com>
Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agospec: change the ownership of cache directory
Peng Liang [Mon, 11 Oct 2021 11:47:20 +0000 (19:47 +0800)] 
spec: change the ownership of cache directory

In a50c473ad6c9 ("qemu: move temp file of screenshot and memorypeek to
per-domain dir") and c4f3c955d578 ("qemu: don't change ownership of
cache directory"), I move the temporary files of screenshot and
memorypeek from the cache directory to per-domain directory, and the
only user of the cache directory is the domain capabilities currently.
Since the domain capabilities are used by libvirtd, no need to set the
ownership of the cache directory to qemu_user and qemu_group.

Signed-off-by: Peng Liang <liangpeng10@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>