Commit Graph

7616 Commits

Author SHA1 Message Date
Michal Privoznik
5cba53db57 tests: Drop domcaps test data for qemu < 2.11
The minimal supported version of QEMU is 2.11. And after capabilities
for older QEMUs were dropped in v7.3.0-17-g184de10c1d we have some
domaincapsdata/ files that are never read. This is because
domaincapstest uses testQemuCapsIterate() which iterates over
qemucapabilitiesdata/caps_*.xml files.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2022-02-15 16:33:45 +01:00
Peter Krempa
874b00f750 qemuhotplugtest: Assume QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE
All modern QEMU versions use FD passing for listening unix sockets so
the test should reflect this. This will later help when removing the
legacy code paths when we drop support for old QEMUs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Peter Krempa
5b5162072c qemuhotplugmock: Mock fd passing to qemu via 'SCM_RIGHTS'
We don't want to be dealing with real FDs thus we mock
'qemuMonitorIOWriteWithFD' to do the same thing as when no FD is being
passed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Peter Krempa
654486bd57 syntax-check: sc_avoid_write: Don't use blanket file exceptions
Adding an exception for the whole file usually defeats the purpose of a
syntax check and is also likely to get forgotten once the file is
removed.

In case of the suggestion of using 'safewrite' instead of write even the
comment for safewrite states that the function needs to be used only in
certain cases.

Remove the blanket exceptions for files and use an exclude string
instead. The only instance where we keep the full file exception is for
src/libvirt-stream.c as there are multiple uses in example code in
comments where I couldn't find a nicer targetted wapproach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Peter Krempa
f9ae469a6e qemu: Make 'struct _qemuMonitorMessage' private
Move the declaration of the struct into 'qemu_monitor_priv.h' as other
code has no business in peeking into the monitor messages.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Peter Krempa
c82887a323 qemuxml2argvtest: Add newer variant of 'launch-security-sev-missing-platform-info'
Upcoming patches will remove support for qemu-2.12. Since tests of
'sev' use hacked data we need to use our capability dump of qemu-6.0 as
it has the required fields.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:30:40 +01:00
Peter Krempa
4392617724 qemuxml2argvtest: Bump versioned test variants for pre-blockdev disk tests to 4.1.0
Originally when I started working on '-blockdev' support I added version
locked variants of all the relevant disk tests locked to qemu-2.12, but
blockdev was finally enabled with qemu-4.2.

This patch bumps the rest of the test cases with no functional changes
related to disks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:29:39 +01:00
Peter Krempa
94f8c8873f qemuxml2argvtest: Update disk test cases having 'device_id' argument of SCSI disk
The 'device_id' property was added in qemu-4.0. Since upcoming patch
will be modernizing all disk test cases we specifically want to preserve
the instance of 'device_id' not being used with qemu-3.1 and earlier.

Change the 'disk-cache' and 'disk-shared' cases to have a qemu-3.1 and a
qemu-4.1 version for testing pre-'device_id' and pre-blockdev scenarios.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:29:17 +01:00
Peter Krempa
2fd1262bf1 qemuxml2argvtest: Add pre-blockdev post-werror-move version of 'disk-error-policy'
Starting with qemu-3.0 release we use the 'werror' and 'rerror'
properties with the frontend (device) rather than the storage backend
(with a minor caveat of s390, where we use it earlier as it doesn't
 support USB disks, and other disk types supported it earlier).

Add specific test cases after the change, but before '-blockdev' was
enabled.

This is done separately from the changes in the next commit which simply
moves all other disk tests to the last pre-blockdev qemu as we have a
semantic change happening after 2.12.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:28:57 +01:00
Peter Krempa
f923620031 qemuBuildTPMCommandLine: Use 'qemuPassFD' infrastructure
Remove the last code path using hardcoded fdsets.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
4225de7c73 qemuBuildTPMOpenBackendFDs: Construct 'cancel_path' internally
Since 'cancel_path' is constructed from the 'tpmdev' argument, we can
push it down into the function opening the FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
ad81aa8ad0 qemu: Honour 'virtlogd' use when hotplugging chardevs
Setup the chardev similarly to how we do it on startup so that virtlogd
is properly used with chardevs which are hotplugged to a VM.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
f22e372de2 qemuMonitorJSONTestAttachChardev: Add tests for FD passing of file backend
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
39bf220221 tests: Move testPrepareHostBackendChardevOne into test utils
Move the function doing the fake setup of chardev backend for FD passing
into the collection of qemu test helpers so that it can be used in
qemumonitorjsontest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
52d38e3274 qemuMonitorJSONTestAttachChardev: Add logfile to some tests
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
84dfd6e4cd qemuMonitorJSONTestAttachChardev: Add test for TLS-secured TCP chardev
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
128f5c3383 qemumonitorjsontest: Refactor chardev hotplug testing
The main objective of this patch is to use a proper instance of
virDomainChrSourceDef allocated with the private data.

To achieve this the test cases are grouped into blocks by how much they
fill in the chardev definition. Some test cases are moved around so
that the resulting sequence doesn't need extra clearing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
e6f837f611 qemumonitorjsontest: chardev: Remove need to allow unused commands
Don't add the command to the test monitor when we don't expect to invoke
it rather than bypassing the test monitor.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
22d5ce0252 qemuDomainRemoveChrDevice: Detach fdset after chardev hot-unplug
Our code uses fdsets for the pipe passed from virtlogd to qemu, but the
chardev hot-unplug code neglected to detach the fdset after the chardev
was removed. This kept the FDs open by qemu even after they were not
used any more.

After the refactor to use qemuFDPass for chardevs we now configure the
'opaque' field for fdsets used for chardevs so we can use
qemuHotplugRemoveFDSet to remove the unused fdset.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
6d161bcc60 qemu: Rewrite chardev startup code to use qemuFDPass
Rewrite the parts which already pass FDs via fdset or directly to use
the new infrastructure.

Apart from simpler code this also adds the appropriate names to the fds
in the fdsets which will allow us to properly remove the fdsets won
hot-unplug of chardevs, which we didn't do for now and resulted in
leaking the FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
38edcca114 qemuBuildInterfaceCommandLine: Use new pattern for naming the VDPA fdset
Prefix the file descriptor name with the alias of the network device so
that it's similar to other upcoming use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
9aab7acfe0 qemuProcessPrepareHostBackendChardevFileHelper: Always use FD passing
Code paths which don't wish to use FD passing are supposed to not call
the function which sets up the chardev for FD passing.

This is ensured by calling it only in the host prepare step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:13:59 +01:00
Andrea Bolognani
6901d92ec4 virnetsockettest: Increase coverage
Add test cases for quotes appearing in the netcat parameter,
for the default behavior of proxy=auto where virt-ssh-helper
is used if available, and for proxy=native.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:24 +01:00
Andrea Bolognani
5068a76493 virnetsockettest: Allow changing the proxy parameter
Currently the test cases all follow the proxy=auto behavior, but
we want to add coverage for other proxy modes as well.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:15 +01:00
Andrea Bolognani
02c9948e36 virnetsockettest: Tweak input for test 7
The important part of the value we assign to "netcat" is that it
contains whitespace, so drop everything else to highlight this
fact.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:09 +01:00
Andrea Bolognani
709d190a82 virnetsockettest: Improve indentation
Having the actual script indented and the closing quote on a
separate line, like

  sh -c '
    if foo; then
      bar;
    fi
  '

makes things more readable and easier to scan visually.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:06 +01:00
Andrea Bolognani
a280b9282f virnetsockettest: Move opening quote
Make this test case consistent with all the other ones.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:05 +01:00
Andrea Bolognani
5bf9902012 virnetsockettest: Drop unnecessary backslash
No need to escape a single quote.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:32:03 +01:00
Andrea Bolognani
f375533e07 virbuftest: Increase coverage
Test the behavior of virBufferEscapeShell for different types of
quotes as well as the empty string.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-14 11:31:56 +01:00
Peter Krempa
2a273072b6 qemucapabilitiestest: Hack/fix version in qemu-3.1 tests
The test dumps for x86_64 and ppc64 were generated from pre-release
qemu-3.0-rc1/rc2 and thus wouldn't pass our minimum version check.

As these are very old, fix the version info we use for our check to 3.1
without re-generating them and keep the version tag intact.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 09:45:29 +01:00
Peter Krempa
e51c0ac891 qemuxml2xmltest: Remove unnecessary versioned invocation of 'disk-cache'
The 'disk-cache' output file is identical in the interesting parts
(everything besides CPU config) to the '-latest' version, so the
versioned invocation can be dropped.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 09:45:28 +01:00
Tim Wiederhake
6ccafcb53e qemumonitortestutils: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:35 +01:00
Tim Wiederhake
8e5b04e332 qemusecuritymock: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:32 +01:00
Jiri Denemark
6752bfdbc4 tests: Fix fd leaks in virpcivpdtest
Tests testVirPCIVPDReadVPDBytes and testVirPCIVPDParseFullVPDInvalid
failed to properly close open fildescriptors in some cases. Let's fix it
by switching to VIR_AUTOCLOSE in the whole file.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 15:06:19 +01:00
Daniel P. Berrangé
3ef9b51b10 qemu: fix formatting of pflash readonly attribute
When the <loader> had an explicit readonly='no' attribute we
accidentally still marked the plfash as readonly due to the
bad conversion from virTristateBool to bool. This was missed
because the test cases run with no capabilities set and thus
are validated the -drive approach for pflash configuration,
not the -blockdev approach.

This affected the following config:

  <os>
    <loader readonly='no' type='pflash'>/var/lib/libvirt/qemu/nvram/test-bios.fd</loader>
  </os>

for the sake of completeness, we also add a test XML config
with no readonly attribute at all, to demonstrate that the
default for pflash is intended to be r/w.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-08 13:04:20 +00:00
Michal Privoznik
87a43a907f lib: Use g_clear_pointer() more
This change was generated using the following spatch:

  @ rule1 @
  expression a;
  identifier f;
  @@
    <...
  - f(*a);
    ... when != a;
  - *a = NULL;
  + g_clear_pointer(a, f);
    ...>

  @ rule2 @
  expression a;
  identifier f;
  @@
    <...
  - f(a);
    ... when != a;
  - a = NULL;
  + g_clear_pointer(&a, f);
    ...>

Then, I left some of the changes out, like tools/nss/ (which
doesn't link with glib) and put back a comment in
qemuBlockJobProcessEventCompletedActiveCommit() which coccinelle
decided to remove (I have no idea why).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-08 08:42:07 +01:00
Peter Krempa
715846b6ea qemu: monitor: Don't hardcode QOM path of first CPU
Convert all code using the 'QOM_CPU_PATH' macro to accept the QOM path
as an argument.

For now the new helper for fetching the path 'qemuProcessGetVCPUQOMPath'
will always return the same hard-coded value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-07 18:04:52 +01:00
Boris Fiuczynski
f087335034 nodedev: add parent_addr to mdev nodedev dumpxml
As the parent address is part of the mdev nodedev name lets expose the
internally available parent address in the XML.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-04 17:50:57 +01:00
Boris Fiuczynski
609836e2b2 tests: adding vfio-ccw to nodedev tests
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-04 17:50:53 +01:00
Boris Fiuczynski
37ce3da14e tests: correct formating in mdevctl test
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-04 17:50:18 +01:00
Dmitrii Shcherbakov
09cdd16a9b Ignore EPERM on implicit clearing of VF VLAN ID
SmartNIC DPUs may not expose some privileged eswitch operations
to the hypervisor hosts. For example, this happens with Bluefield
devices running in the ECPF (default) mode for security reasons. While
VF MAC address programming is possible via an RTM_SETLINK operation,
trying to set a VLAN ID in the same operation will fail with EPERM.

The equivalent ip link commands below provide an illustration:

1. This works:

sudo ip link set enp130s0f0 vf 2 mac de:ad:be:ef:ca:fe

2. Setting (or clearing) a VLAN fails with EPERM:

sudo ip link set enp130s0f0 vf 2 vlan 0
RTNETLINK answers: Operation not permitted

3. This is what Libvirt attempts to do today (when trying to clear a
   VF VLAN at the same time as programming a VF MAC).

sudo ip link set enp130s0f0 vf 2 vlan 0 mac de:ad:be:ef:ca:fe
RTNETLINK answers: Operation not permitted

If setting an explicit VLAN ID results in an EPERM, clearing a VLAN
(setting a VLAN ID to 0) can be handled gracefully by ignoring the
EPERM error with the rationale being that if we cannot set this state
in the first place, we cannot clear it either.

In order to keep explicit clearing of VLAN ID working as it used to
be passing a NULL pointer for VLAN ID is used.

Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-03 16:52:05 +01:00
Dmitrii Shcherbakov
73961771a1 Allow VF vlanid to be passed as a pointer
There should be a way to show no intent in programming a VLAN at all
(including clearing it). This allows handling error conditions
differently when VLAN clearing is explicit (vlan id == 0) vs implicit
(vlanid == NULL - try to clear it if possible).

Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-03 16:52:05 +01:00
Dmitrii Shcherbakov
86fc0c2576 Set VF MAC and VLAN ID in two different operations
This has a benefit of being able to handle error codes for those
operations separately which is useful when drivers allow setting a MAC
address but do not allow setting a VLAN (which is the case with some
SmartNIC DPUs).

Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-03 16:52:05 +01:00
Ján Tomko
baa779ea9c maint: remove unnecessary virutil.h includes
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-02-03 14:10:04 +01:00
Ján Tomko
8eb7d869ed virParseVersionString: rename to virStringParseVersion
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-02-03 14:10:03 +01:00
Daniel P. Berrangé
7714034ecd qemu: add tests for the ISA debug console command line
The XML-to-XML test validates that we don't accidentally copy the
isa-debug <serial> into a <console>.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-03 10:59:03 +00:00
Andrea Bolognani
41e878859a tests: Cover virtio-mem being plugged into a bridge
This is a perfectly valid configuration that we need to keep
working, so add test coverage for it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-02 16:32:41 +01:00
Michal Privoznik
af23241cfe qemu_command: Generate memory only after controllers
Currently, memory device (def->mems) part of cmd line is
generated before any controller. In majority of cases it doesn't
matter because neither of memory devices live on a bus that's
created by an exposed controller (e.g. there's no DIMM
controller, at least not exposed). Except for virtio-mem and
virtio-pmem, which do have a PCI address. And if it so happens
that the device goes onto non-default bus (pci.0) starting such
guest fails, because the controller that creates the desired bus
wasn't processed yet. QEMU processes arguments in order.

For instance, if virtio-mem has address with bus='0x01' QEMU
refuses to start with the following message:

  Bus 'pci.1' not found

Similarly for virtio-pmem. I've successfully tested migration and
changing the order does not affect migration stream.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2047271
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-02-02 14:22:47 +01:00
Michal Privoznik
a7c016e4cb virpcivpdtest: Fix potential double-free()
Inside the testPCIVPDResourceCustomCompareIndex() function we
have two variables @a and @b, both marked as g_autoptr(). Then,
towards the end of the function b->value is freed and set to
a->value. This is to make sure
virPCIVPDResourceCustomCompareIndex() works correctly even if
->value member is the same for both arguments.

Nevertheless, if the function returns anything else than 0 then
the control executes subsequent return statement and since
b->value points to the very same string as a->value a double free
will occur. Avoid this by setting b->value to NULL explicitly,
just like we are already doing for the successful path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2022-02-01 17:37:06 +01:00
Michal Privoznik
ce880ad8ba lib: Don't set variable to NULL after VIR_FREE()
There are a few places where a variable is VIR_FREE()-d and then
explicitly set to NULL. This is not necessary since VIR_FREE()
does that for us.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2022-02-01 17:37:06 +01:00