Commit Graph

35446 Commits

Author SHA1 Message Date
Pavel Hrdina
0a164b74eb qemu_snapshot: correctly update metadata when deleting external snapshot with multiple branches
XML metadata for snapshot contains only single list of disk overlays
from the moment when the snapshot was taken. When user creates multiple
branches of snapshots the parent snapshot will still list only the
original disk overlays. This may cause an issue in a specific scenario:

     s1
      |
      +- s2
      +- s3 (active)

For this snapshot topology when we delete s2 metadata for s1 are not
updated. Now when we delete s1 the code operated with incorrect
overlays from s1 metadata in order to update s3 metadata resulting in no
changes to s3 metadata.

Now when user tries to delete s3 it fails with following error:

    error: Failed to delete snapshot s3
    error: operation failed: snapshot VM disk source and parent disk source are not the same

For the actual deletion there is a code to figure out the correct disk
source but it was not used to update metadata as well. Due to reasons
how block commit in libvirt works we need to create a copy of that disk
source in order to have it available when updating metadata as the
original source will be freed at that point.

Resolves: https://issues.redhat.com/browse/RHEL-26276
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2024-04-02 14:14:26 +02:00
Pavel Hrdina
79654f425c qemu_snapshot: call qemuSnapshotDeleteUpdateDisks only for external snapshots
Calling this function when deleting internal snapshot isn't required
because with internal snapshots all changes are done within the file
itself so there is no file deletion and no need to update snapshot
metadata.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2024-04-02 14:14:26 +02:00
Peter Krempa
0e566614ff pci: Remove error reporting from PCI VPD parsing
The PCI VPD (Vital Product Data) may be missing or the kernel can report
presence but not actually have the data. Also the data is specified by
the device vendor and thus may be invalid in some cases.

To avoid log spamming, since the only usage in the node device driver is
ignoring errors, remove all error reporting.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/607
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2024-03-28 10:11:55 +01:00
Peter Krempa
34f7ca668f virpcivpd: Revert error reporting from PCI VPD parser
The VPD parsing is fragile and depends on hardware vendor's adherance to
standards. Since libvirt only ever uses this data to report it in the
nodedev XML which ignores any errors there's no much point in having
error reporting which I've added recently.

Turn the errors into VIR_DEBUG statements in preparation for upcoming
patch which completely removes the expectation to report errors.

This effectively reverts commits dfc85658bd and f85a382a0e.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2024-03-28 10:11:55 +01:00
Adam Julis
6821271123 qemuDomainChangeNet: Error when boot index changes in live XML
If the original code detected a missing or null boot index in the
new XML, it automatically added the current value. This
autocompletion was incorrect because it was impossible to
distinguish between user intent and user error - changing the
boot order itself is forbidden and should always be an error.

Resolves: https://issues.redhat.com/browse/RHEL-23416
Fixes: aa3e07caec
Signed-off-by: Adam Julis <ajulis@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-22 10:49:40 +01:00
Lennart Fricke
71a604fce6 qemu: warn on pausing of guest due to watchdog or io error
Change the log level for pauses of guests due to watchdog timeouts
or io errors from debug to warn to enhance the visibility of such
events.

Signed-off-by: Lennart Fricke <lennart.fricke@drehpunkt.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-21 15:00:00 +01:00
Xianglai Li
0038b155ec Implement the method of getting host info for loongarch
Implement method for loongarch to get host info, such as
cpu frequency, system info, etc.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2024-03-21 14:42:26 +01:00
Xianglai Li
3243783c32 Support for loongarch64 in the QEMU driver
Implement support for loongarch64 in the QEMU driver.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2024-03-21 14:42:24 +01:00
Xianglai Li
a4e3718981 Add loongarch cpu support
Add loongarch cpu support, Define new cpu type 'loongarch64'
and implement it's driver functions.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2024-03-21 14:42:20 +01:00
Daniel P. Berrangé
8a3f8d9575 remote: check for negative array lengths before allocation
While the C API entry points will validate non-negative lengths
for various parameters, the RPC server de-serialization code
will need to allocate memory for arrays before entering the C
API. These allocations will thus happen before the non-negative
length check is performed.

Passing a negative length to the g_new0 function will usually
result in a crash due to the negative length being treated as
a huge positive number.

This was found and diagnosed by ALT Linux Team with AFLplusplus.

CVE-2024-2494
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Found-by: Alexandr Shashkin <dutyrok@altlinux.org>
Co-developed-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-03-21 08:08:00 +00:00
Andrea Bolognani
5fb47c5bed qemu: Tweak augeas schema
Current entries should always be listed before obsolete ones.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-20 18:37:58 +01:00
Andrea Bolognani
8ca0005ec6 security: Drop virSecurity(DAC|SELinux)SetImageLabelRelative()
The single caller for each function passes the same value
for @src and @parent, which means that we don't really need
the additional API.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-20 18:37:56 +01:00
Andrea Bolognani
94028ebf48 security: Drop virSecurity(DAC|SELinux)RestoreImageLabelSingle()
Each one only has a single, trivial caller.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-20 18:37:55 +01:00
Andrea Bolognani
931990b7c2 security: Fix name for _virSecurityDACChardevCallbackData
It was clearly copied over from the SELinux driver without
updating its name in the process.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-20 18:37:53 +01:00
Andrea Bolognani
24914690c7 security: Fix alignment
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-20 18:37:34 +01:00
Purna Pavan Chandra Aekkaladevi
70aca59616 docs: Update doc for virDomainSave and virDomainRestore
ch_driver expects path to be of a dir for save/restore. So, update
the documentation at global API as well.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:38 +01:00
Purna Pavan Chandra Aekkaladevi
bcd567faa2 ch_driver: Add additional validation for save/restore
Save & Restore are supported without any network and hostdev config
defined. So, add a validation for it before performing save.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:34 +01:00
Purna Pavan Chandra Aekkaladevi
f2d54f42d5 ch_driver: cleanup any stale managed save dir before VM creation
There are chances that libvirt process is killed and it resulting in
stale managed save dirs. So check for it, and cleanup it there's any.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:31 +01:00
Purna Pavan Chandra Aekkaladevi
53ec0fd09d ch_driver: Implement domain restore callbacks
Following callbacks have been implemented
* domainRestore
* domainRestoreFlags
The path parameter to these callbacks has to be of the directory where
libvirt has performed save. Additionally, call restore in `domainCreate`
if the domain has managedsave.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:26 +01:00
Purna Pavan Chandra Aekkaladevi
ed12c63f89 ch_driver: Refactor virCHProcessStart
Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:23 +01:00
Purna Pavan Chandra Aekkaladevi
829340127d ch_driver: Implement more save callbacks
Following callbacks have been implemented
* domainSaveImageGetXMLDesc
* domainManagedSaveRemove
* domainManagedSaveGetXMLDesc
* domainHasManagedSaveImage

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:21 +01:00
Purna Pavan Chandra Aekkaladevi
d07cdc0f48 ch_driver: Add domainManagedSave callback
Create libvirt managed saveDir and pass it to CH to save the VM

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:18 +01:00
Purna Pavan Chandra Aekkaladevi
c22fb87b05 ch_driver: Add domainSave, domainSaveFlags callbacks
Implemented save callbacks. CH's vmm.snapshot API is called to save the
domain state. The path passed to these callbacks has to be of directory
as CH takes dir as input to snapshot and saves multiple files under it.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:16 +01:00
Purna Pavan Chandra Aekkaladevi
13f964a2ef ch_driver: Pass virCHDriverConfig to virCHMonitorNew
Pass virCHDriverConfig to VirCHMonitorNew instead of just stateDir so
that the cfg can be used for any additional purposes.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:14 +01:00
Purna Pavan Chandra Aekkaladevi
6ea6208f35 ch_driver: Support Save, Restore VM actions from monitor
Implement folowing API calls from CH monitor
* vmm.snapshot -> to save a domain
* vmm.restore -> to restore saved domain

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-20 14:05:10 +01:00
Andrea Bolognani
6b7c8fce5a meson: Check for sched_get_priority_min()
virProcessSetScheduler() uses not just sched_setscheduler() but
also sched_get_priority_{min,max}(). Currently we assume that
the former being available implies that the latter are as well,
but that's not the case for at least GNU/Hurd.

Make sure all functions are actually available before
attempting to use them.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 18:38:19 +01:00
Andrea Bolognani
526e7ee15a meson: Restore check for sched_getaffinity()
Commit c07cf0a686 replaced this check with one for the
presence of cpu_set_t.

The idea at the time was that only sched_{get,set}affinity()
were visible by default, while making cpu_set_t visible required
defining _WITH_CPU_SET_T. So libvirt would detect the function
and attempt to use it, but the code would not compile because
the necessary data type had not been made accessible.

The commit in question brought three FreeBSD commits as evidence
of this. While [1] and [2] do indeed seem to support this
explanation, [3] from just a few days later made it so that not
just cpu_set_t, but also the functions, required user action to
be visible. This arguably would have made the change unnecessary.

However, [4] from roughly a month later changed things once
again: it completely removed _WITH_CPU_SET_T, making both the
functions and the data type visible by default.

This is the status quo that seems to have persisted until
today. If one were to check any recent FreeBSD build job
performed as part of our CI pipeline, for example [5] and [6]
for FreeBSD 13 and 14 respectively, they would be able to
confirm that in both cases cpu_set_t is detected as available.

Since there is no longer a difference between the availability
of the functions and that of the data type, go back to what we
had before.

This has the interesting side-effect of fixing a bug
introduced by the commit in question.

When detection was changed from the function to the data type,
most uses of WITH_SCHED_GETAFFINITY were replaced with uses of
WITH_DECL_CPU_SET_T, but not all of them: specifically, those
that decided whether qemuProcessInitCpuAffinity() would be
actually implemented or replaced with a no-op stub were not
updated, which means that we've been running the stub version
everywhere except on FreeBSD ever since.

The code has been copied to the Cloud Hypervisor driver in
the meantime, which is similarly affected. Now that we're
building the actual implementation, we need to add virnuma.h
to the includes.

As a nice bonus this also makes things work correctly on
GNU/Hurd, where cpu_set_t is available but
sched_{get,set}affinity() are non-working stubs.

[1] https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b879b7af2
[2] https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c45993017fbb
[3] https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788dec2546a
[4] https://cgit.freebsd.org/src/commit/?id=5e04571cf3cf4024be926976a6abf19626df30be
[5] https://gitlab.com/libvirt/libvirt/-/jobs/6266401204
[6] https://gitlab.com/libvirt/libvirt/-/jobs/6266401205

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 18:38:13 +01:00
Andrea Bolognani
593da429ff util: Add debug print missing from BSD
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2024-03-19 18:34:33 +01:00
Andrea Bolognani
dc3030cc80 util: Prefer cpuset_{get,set}affinity() on BSD
FreeBSD 14 implements sched_{get,set}affinity() for
compatibility with Linux, but we should still use the native
syscalls instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2024-03-19 18:34:30 +01:00
Andrea Bolognani
dc0dc848ee util: Accept TIDs for virProcess{Get,Set}Affinity() on BSD
Depending on the situation, the IDs that we pass to these
functions can be either referring to processes or threads.

Linux doesn't have separate interfaces for one or the other,
but FreeBSD does and we're explicitly telling it that the ID
refers to a process. When it refers to a thread instead, the
call will fail, and the VM will not be able to start.

Luckily, another possible choice is CPU_WHICH_TIDPID, which
makes things behave the same as Linux.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2024-03-19 18:34:25 +01:00
Rayhan Faizel
c836887a02 qemu_command: Generate command line for MTP filesystem
The source tag sets the rootdir property of the device, which is
the directory exposed to the guest via the MTP device. The target
tag sets the desc property.  This device supports read-only mode
as well. Like virtiofs, it does not support additional access
modes.

Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 17:36:19 +01:00
Rayhan Faizel
5c70a7e328 conf: Introduce support for usb-mtp devices
Expose usb-mtp device as another type of <filesystem/>.

Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 17:36:19 +01:00
Rayhan Faizel
e529b7b5c4 qemu_capabilities: Add QEMU_CAPS_DEVICE_USB_MTP capability
This capability reflects presence of -device usb-mtp.

Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 17:36:19 +01:00
Karim Taha
a7e258d7c9 node_device_driver: use g_autofree instead of VIR_FREE()
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 13:31:29 +01:00
Karim Taha
771bfe0c0d openvz_driver: use g_autofree instead of VIR_FREE()
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-19 13:31:25 +01:00
Ján Tomko
c9de7a1c3b qemu: virtiofs: error out if getting the group or user name fails
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-18 15:20:24 +01:00
Ján Tomko
4c5b2e1e0d qemu: virtiofs: set correct label when creating the socket
Use svirt_t instead of virtd_t, since virtd_t is not available in the
session mode and qemu with svirt_t won't be able to talk to unconfined_t
socket.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-18 15:20:24 +01:00
Ján Tomko
a9da009219 qemu: virtiofs: do not crash if cgroups are missing
On domain startup, qemuSetupCgroupForExtDevices checks
if a cgroup controller is present and skips the setup if not.

Add a similar check to qemuVirtioFSSetupCgroup to prevent
crashing when hotplugging a virtiofs filesystem.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-18 15:20:24 +01:00
Wei Gong
0bb33164d0 virthreadpool: create threads from the newly expanded workers
when the thread pool is dynamically expanded, threads should
not be created from the existing workers; they should be created
from the newly expanded workers

Signed-off-by: Wei Gong <gongwei833x@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-18 15:12:46 +01:00
Rayhan Faizel
eb87d146ea openvz_conf: Use g_autofree
Signed-off-by: Rayhan Faizel <rayhan.faizel@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-03-18 10:36:05 +01:00
Jiri Denemark
6898b7cd8d Add vmx-* features to Westmere*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
64e3c1138a Add vmx-* features to Snowridge
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
aa064b38fd Add vmx-* features to Skylake*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
e67004ec1c Add vmx-* features to SapphireRapids
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
29d492d648 Add vmx-* features to SandyBridge*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
c6fadbb280 Add vmx-* features to Penryn
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
a539910c94 Add vmx-* features to Nehalem*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
1d03f78c5d Add vmx-* features to kvm*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
4b707f8bb0 Add vmx-* features to IvyBridge*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00
Jiri Denemark
a6f3eafc40 Add vmx-* features to Icelake*
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2024-03-14 16:15:06 +01:00