Commit Graph

44082 Commits

Author SHA1 Message Date
Pavel Hrdina 74ea062be6 test: snapshot revert: drop unused code
Now that we always emulate VM process stop we can drop the unused code
and simply the logic.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:42:00 +01:00
Pavel Hrdina 5bed5db990 test: snapshot revert: always emulate VM process stop
Reflect the same change in test driver as in QEMU driver because the
compatibility check code isn't perfect.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:57 +01:00
Pavel Hrdina 2ef6b1cecf test: snapshot revert: properly emulate starting CPUs
When active snapshot is reverted we stop CPUs in order to load the
snapshot but we never start the CPUs again.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:55 +01:00
Pavel Hrdina ca04290be3 test: snapshot revert: always error out if VM XML is missing
We should have this check even if FORCE flag is used because later we
unconditionally copy the `snap->def->dom` and error out if there is no
copy created. The test driver will always save the VM XML when creating
new snapshot.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:52 +01:00
Pavel Hrdina 6c86b92f14 qemu_snapshot: revert: drop error that QEMU process must be restarted
This will always happen so there is no need to error out and require
usage of FORCE flag.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:50 +01:00
Pavel Hrdina d8a4acab96 qemu_snapshot: revert: fix emitting events
Now that we always restart the QEMU process events are emitted
differently so we need to update the code and the comment as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:48 +01:00
Pavel Hrdina f33ce12e9c qemu_snapshot: revert: drop unused loadvm code
Now that we always restart QEMU process the loadvm code is unused and
can be dropped.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:45 +01:00
Pavel Hrdina 3bec4ce049 qemu_snapshot: revert: always restart QEMU process for running VM
Our compatibility check code isn't complete and there are cases where it
fails to detect incompatible configuration and the revert fails. In
addition future support for external snapshot will always require
restarting the QEMU process.

To unify the behavior drop the compatibility check code and always
restart the QEMU process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:43 +01:00
Pavel Hrdina 649bd34c28 qemu_snapshot: revert: always error out if VM XML is missing
The support to revert snapshots was introduced in libvirt 0.8.0 but
saving the whole VM XML was implemented later in libvirt 0.9.5.

That is more then 10 years ago so we can safely assume that nobody will
try reverting to snapshot created by that old libvirt. In the unlikely
scenario where someone would actually did it we would simply error out.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:38 +01:00
Pavel Hrdina 23b99623ee util: fix various ATTRIBUTE_NONNULL calls
Git bisect took me to commit where incorrect usage of ATTRIBUTE_NONNULL
was introduced and caused coverity scan to fail. This patch fixes the
issue where the index starts from 1 and not 0 and two other different
cases.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 09:59:00 +01:00
Michal Privoznik d20ebdda28 qemu: Switch to -accel
We currently use -machine accel=XXX which is just a syntax sugar
for -accel XXX. The former doesn't allow specifying arguments for
accelerator, because all arguments passed to -machine are
treated as arguments of machine itself.

The -accel argument was introduced in QEMU commit
v2.9.0-rc0~70^2~19 and since our minimum required version is
newer (2.11.0) we can safely assume its existence and use it
without any capability.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/233
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-22 13:06:54 +01:00
Michal Privoznik 69f2f63299 qemu_command: Don't validate accelerator when building cmd line
The domain accelerator was validated in qemuValidateDomainDef()
which calls virQEMUCapsIsVirtTypeSupported() which reports proper
error if QEMU is not capable of KVM/TCG. There is no point in
doing the validation again when building command line.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-22 13:06:54 +01:00
Peter Krempa d5643e73da qemuMonitorJSONAttachCharDevGetProps: Modernize construction of JSON objects
Use 'virJSONValueObjectAdd' instead of the step-by-step manual JSON
object building.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Peter Krempa 03cab99ca5 qemuMonitorJSONBuildChrChardevReconnect: Unify with qemuBuildChrChardevReconnectStr
When formatting the commandline we explicitly set the reconnect timeout
to 0 when it's disabled even when that's the default. Do the same in
the monitor/hotplug code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Peter Krempa dd138ea402 qemuMonitorJSONAttachCharDevGetProps: Rename 'backend_type' and 'data'
Rename 'data' to 'backendData' so that it's more clear what the object
represents and 'backend_type' to 'backendType' to go with the common
camel case notation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Michal Privoznik 784e9e2b62 lib: Drop needless one line labels
In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-22 12:39:59 +01:00
Michal Privoznik 3010a69226 qemu_command: Generate -mem-prealloc in one corner case more
When guest has NUMA nodes and QEMU is new enough to report
default RAM ID then ideally we would use -numa memdev= combined
with memory-backend-* combo becasue -mem-path/-mem-prealloc/-numa
mem are deprecated. Well, there is one problem - the .memdev=
attribute is machine type dependent (just look at arguments of
virQEMUCapsGetMachineNumaMemSupported()) and to ensure backwards
compatibility we prefer -numa mem= over -numa memdev=.

But there was one corner case when -mem-prealloc was requested
but not generated on the cmd line. It all starts with
qemuBuildMemCommandLine() which generates just '-m XXX' and
because it sees defaultRAMid and guest NUMA nodes greater than
zero it does nothing more.

Then, qemuBuildNumaCommandLine() sees that -numa mem= is still
supported for given machine type and nothing else set
@needBackend thus qemuBuildMemPathStr() is called which output
-mem-prealloc only in a few cases assuming it was outputted
earlier.

Reported-by: Jing Qi <jinqi@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:27:29 +01:00
Michal Privoznik 3f390db2e2 qemuxml2argvtest: Introduce another numa-topology test
This test shows a bug we have: even though the XML says:

  <allocation mode='immediate'/>

there is no -mem-prealloc nor .prealloc=yes anywhere on the cmd
line. This will be fixed in the next commit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:27:19 +01:00
Daniel Henrique Barboza c7820f1509 qemu_capabilities.c: del 'cleanup' label in virQEMUCapsLoadHostCPUModelInfo()
Create extra g_autofree strings and use them in an adequate scope to
eliminate the need for VIR_FREE() calls and the 'cleanup' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:59 -03:00
Daniel Henrique Barboza 0e2b546166 cpu_ppc64.c: remove 'guest' param from ppc64Compute()
ppc64Compute() is used only once, by virCPUppc64Compare(), which
doesn't use the 'guest' parameter. It was last used by an API
called 'cpuGuestData' that was dropped by commit 03fa904c0c.

Removing the 'guest' parameter will not only remove unused code from
ppc64Compute() but also remove the ppc64MakeCPUData() entirely.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:59 -03:00
Daniel Henrique Barboza 294e92145e qemu_capabilities.c: remove cleanup label from virQEMUCapsLoadCache()
'str' is no longer being used and the 'cleanup' label can be removed
together with the 'ret' variable.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza 484c6e2ca4 qemu_capabilities.c: add virQEMUCapsValidateArch()
Create a new helper to remove the arch validation logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza 8ccf9444b9 qemu_capabilities.c: add virQEMUCapsValidateEmulator()
Create a new helper to remove the emulator validation logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza 89120dddbe qemu_capabilities.c: del 'nodes' var from virQEMUCapsLoadCache()
The 'nodes' var is not being used.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza a0eafbf250 qemu_capabilities.c: add virQEMUCapsParseGIC()
Create a new helper to remove the GIC parse logic from the body of
virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza 9041fa5d53 qemu_capabilities.c: add virQEMUCapsParseFlags()
Create a new helper to remove the parse capabilities flag logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Vasiliy Ulyanov 4f3120d70c qemu: Fix the check of AMD secure guest support
The content of /sys/module/kvm_amd/parameters/sev may vary depending on
the kernel version. Check also for 'Y' and 'y' in addition to '1' to
cover several possible variants. The fix is similar to the one
introduced in commit 3f9c1a4bb8

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 14:59:00 +01:00
Ján Tomko 28bb7266a0 conf: match by network alias only if aliases are assigned
Commit 114e3b4232 added matching by
aliases for interfaces with same MAC address.
( https://bugzilla.redhat.com/show_bug.cgi?id=1926190 )

However, unless the domain is using user aliases (prefixed ua-),
there are no aliases in the persistent definition.

Only match by MAC/PCI/other addresses in that case, to fix update-device
with --persistent flag (AFFECT_LIVE | AFFECT_CONFIG).

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

Fixes: 114e3b4232
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-11-19 14:06:17 +01:00
Peter Krempa 1e085019ca qemuDomainPrepareStorageSourceBlockdev: Set default encryption engine also when preparing virStorageSource
Originally the default encryption engine is populated in the disk
post-parse callback code. This works for disks but for any additional
images introduced either via the block copy API or via the backup API we
don't populate the default.

In case when the backup or block copy is requested on an encrypted image
this would then lead to an error:

 error: internal error: Unexpected enum value 0 for virStorageEncryptionEngine

This patch adds another point where we populate the default which is
when setting up a virStorageSource for actual usage.

We keep the original setting in the post-parse callback as that's the
only point that is recorded in the XML file after definition.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2023674
Fixes: ab1d46d612
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:41:36 +01:00
Peter Krempa 84d1347dbe qemuxml2argvtest: Add device with 'ramfb=off' to 'hostdev-mdev-display-ramfb'
Add a test case where 'ramfb' is explicitly disabled for a mediated
device to prevent regressing again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:40:41 +01:00
Peter Krempa c3bf7f5e62 qemuBuildHostdevMediatedDevProps: Format 'ramfb' only when enabled
Before commit 73c352ab8c which converted the hostdev commandline
formatter to JSON the 'ramfb' property was formatted only if it was
enabled.

The main reason for that is that enabling 'ramfb' switches the device
model to 'vfio-pci-nohotplug' which actually has the property, while
'vfio-pci' (used when 'ramfb' is disabled or absent) doesn't have it.

Restore the logic to format 'ramfb' only when it's enabled and add a
comment that it's deliberate.

Fixes: 73c352ab8c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2024435
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:40:41 +01:00
Peter Krempa 2cb53c61cf qemuxml2argvtest: Fix type for faked chardev backing a TPM
The test filled the chardev type to VIR_DOMAIN_CHR_TYPE_FILE and thus
set the 'data.emulator.source->data.file.path' pointer, but the
commandline formatter is unconditionally expecting VIR_DOMAIN_CHR_TYPE_UNIX
and thus reading 'data.emulator.source->data.nix.path'. Since it's an
union it happened to land in the correct place. Fix the faked data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:35 +01:00
Peter Krempa 42b0000699 conf: Properly instantiate virDomainChrSourceDef in virDomainTPMDef
'virDomainChrSourceDef' contains private data so 'virDomainChrSourceDefNew'
must be used to allocate it. 'virDomainTPMDef' was using it directly
which won't work with the chardev helper functions.

Convert it to a pointer to properly allocate private data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:35 +01:00
Peter Krempa 5dc77b7d32 qemuBuildStorageSourceAttachPrepare(Drive|Chardev): Unexport
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 15e769bd9b qemuDomainAttachChrDevice: Drop 'dev' variable
It's referenced only once and it's a shortcut to the chardev source thus
can be used directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa a9d16dea49 qemuDomainAttachChrDeviceAssignAddr: Simplify return value handling
Rather than returning a different error code if the device address needs
to be released pass in the 'need_release' flag via a pointer.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa b01183a9b9 qemuDomainEnsurePCIAddress: Don't pass virQEMUDriver explicitly
The function is already getting 'virDomainObj' which has already the
driver pointer present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa b04ebc1626 qemuDomainAddChardevTLSObjects: Refactor cleanup
Switch to automatic memory clearing for the two virJSONValues and remove
the 'cleanup' label and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 3c558f56f8 conf: Convert 'chr' in virDomainShmemDef to proper pointer
The main reason is to ensure that the private data are properly
allocated for every instance.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 876f19c19e qemuBuildChrChardevStr: Use proper type for the switch statement
Add the missing cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa a6577204d7 qemu: command: Rename qemuBuildHostNetStr -> qemuBuildHostNetProps
The function is already returning JSON properties, rename it
accordingly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 1dbb7cef70 qemuMonitorJSONAttachCharDevGetProps: Simplify handling of unsupported types
Use 'virReportEnumRangeError' for the invalid cases and keep the
original error for known but unsupported chardevs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa d3af4392f7 qemuMonitorJSONAttachCharDevCommand: Format only the properties
Move the addition of the command wrapper to qemuMonitorJSONAttachCharDev
and rename the function to qemuMonitorJSONAttachCharDevGetProps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa ab85f52c38 qemuMonitorJSONAddDeviceProps: Simplify construction of the command
Use 'qemuMonitorJSONMakeCommandInternal' instead of
'qemuMonitorJSONMakeCommand' + 'virJSONValueObjectAppend'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 2c1e3aa6f9 qemu: hotplug: Add wrapper for qemuMonitorAttachCharDev
Add a simple wrapper for 'qemuMonitorAttachCharDev' named
'qemuHotplugChardevAttach' which will simplify the moving of the
character device property generator out of the monitor code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Peter Krempa 4c7e733e79 qemuBuildCommandLine: Properly check return value of qemuBuildShmemCommandLine
Use the customary '< 0' check for return value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:34 +01:00
Daniel Henrique Barboza 748c4a6b74 qemu_process.c: use g_autoptr() in qemuProcessQMPInitMonitor
The 'xmlopt' parameter can be auto-unref by using g_autoptr().

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-18 14:51:29 -03:00
Daniel Henrique Barboza d103db0460 domain_conf.h: add autoptr cleanup func to virDomainXMLOptionPtr
This will enable code cleanups on code that still relies on
virObjectUnref() this pointer manually.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-18 14:51:22 -03:00
Daniel Henrique Barboza a0ae3bd5d7 cpu_x86.c: remove 'guest' param from x86Compute()
x86Compute() is a static function called only by virCPUx86Compare()
which passes NULL to the 'guest' parameter of x86Compute().

The last caller of x86Compute() that used it with 'guest' != NULL
was an API called 'cpuGuestData'. This API was dropped by commit
03fa904c0c a few years ago. Since then all callers of x86Compute()
uses it with 'guest' = NULL.

Removing the 'guest' parameter allow us to remove a good chunk of
logic that isn't being used for awhile.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-18 14:50:58 -03:00
Andrea Bolognani c5dc658ea8 spec: Explicitly provide locations for QEMU data
These are the defaults, but we prefer to be explicit.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-18 15:49:02 +01:00