summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* lib: Use g_clear_pointer() moreMichal Privoznik2022-02-0880-436/+215
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* vbox_common: Drop needless set to NULLMichal Privoznik2022-02-081-2/+0
| | | | | | | | | There are two places where a variable passed to VBOX_RELEASE() macro is set to NULL explicitly. There is no need for that because the macro sets the variable to NULL already. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* libxl: Set auto-allocated graphics ports to used on reconnectJim Fehlig2022-02-071-0/+23
| | | | | | | | | | | | | | | The libxl driver reconnects to all running VMs when libvirtd is restarted, but it failed to mark auto-allocated graphics ports as set in the port allocator. If many VMs are running that use port auto-allocation and libvirtd is restarted, the port allocator is likely to hand out a port already in use when a new VM is created that uses auto-allocation. VM creation will fail due to the port clash. When reconnecting to running VMs after a libvirtd restart, let the port allocator know about previously allocated ports. Signed-off-by: Jim Fehlig <jfehlig@suse.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: process: Don't use hardcoded QOM path for cpu for probing flagsPeter Krempa2022-02-071-3/+11
| | | | | | | | | | | | | Modify 'qemuProcessGetVCPUQOMPath' to take the detected QOM path of the first vCPU which is always present as the QOM path used our code probing CPU flags via 'qom-get'. This is needed as upcoming qemu will change it. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/272 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2051451 Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: process: Move call to qemuProcessRefreshCPU after cpu probePeter Krempa2022-02-071-3/+3
| | | | | | | Similarly to previous commit we need to probe the vcpus first. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: process: Move cpu flag querying after code probing cpusPeter Krempa2022-02-071-4/+4
| | | | | | | | | | | Upcoming changes will require that we have a proper QOM path for cpus when querying the flags as qemu is going to change it. By moving the flag probing code later we'll already probe the QOM paths so no re-query will be needed. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: domain: Store 'qomPath' in qemuDomainVcpuPrivatePeter Krempa2022-02-073-1/+5
| | | | | | | | | | The QOM path will be needed by code which is querying the cpu flags via 'qom-get' and thus needs a valid QOM path to the vCPU. Add it into the private data and transfer from the queried data. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: monitor: Don't hardcode QOM path of first CPUPeter Krempa2022-02-075-23/+53
| | | | | | | | | | | 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>
* qemuProcessUpdateAndVerifyCPU: Refactor cleanupPeter Krempa2022-02-071-12/+6
| | | | | | | Use automatic memory clearing and remove the 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemuMonitorJSONGetCPUx86Data: UnexportPeter Krempa2022-02-072-6/+1
| | | | | | | The function is used only as a helper in src/qemu/qemu_monitor_json.c Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* qemu: Move high-level actions close togetherAndrea Bolognani2022-02-051-117/+128
| | | | Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Move entry points close togetherAndrea Bolognani2022-02-051-62/+71
| | | | Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Move utility functions close togetherAndrea Bolognani2022-02-051-62/+62
| | | | Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Fix description of swtpmStateDirAndrea Bolognani2022-02-051-2/+2
| | | | | | | This directory contains runtime state, not persistent state. The latter goes into swtpmStorageDir. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Call virDomainDefGetShortName() less frequentlyAndrea Bolognani2022-02-051-22/+19
| | | | | | | | When looping over TPM devices for a domain, we can avoid calling this function for each iteration and call it once per domain instead. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Rename path-building functionsAndrea Bolognani2022-02-051-34/+35
| | | | | | | | | | | Using the word "create" can give users the impression that disk operations will be performed, when in reality all these functions do is string formatting. Follow the naming convention established by virBuildPath(), virFileBuildPath() and virPidFileBuildPath(). Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Introduce qemuTPMEmulatorCleanupHost()Andrea Bolognani2022-02-051-2/+15
| | | | | | | This leaves qemuExtTPMCleanupHost() to only deal with looping over TPM devices, same as other qemuExtTPMDoThing() functions. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Introduce qemuExtTPMEmulatorSetupCgroup()Andrea Bolognani2022-02-051-9/+32
| | | | | | | This leaves qemuExtTPMSetupCgroup() to only deal with looping over TPM devices, same as other qemuExtTPMDoThing() functions. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Make qemuTPMEmulatorCreateStorage() take a virDomainTPMDef*Andrea Bolognani2022-02-051-4/+4
| | | | | | | This matches how qemuTPMEmulatorDeleteStorage() expects to be called. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Drop qemuTPMEmulatorInitStorage()Andrea Bolognani2022-02-051-25/+6
| | | | | | Absorb it into qemuTPMEmulatorCreateStorage(), its only caller. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Document qemuTPMEmulatorDeleteStorage()Andrea Bolognani2022-02-051-0/+6
| | | | Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Rename qemuTPM{Create,Delete}EmulatorStorage()Andrea Bolognani2022-02-051-8/+7
| | | | | | | Other functions that operate on a single TPM emulator follow the qemuTPMEmulatorDoThing() naming convention. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Fully document qemuTPMEmulatorStart()Andrea Bolognani2022-02-051-0/+1
| | | | | | The @tpm argument was not mentioned. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* qemu: Rename qemuExtTPMStartEmulator()Andrea Bolognani2022-02-051-9/+8
| | | | | | Its counterpart is qemuTPMEmulatorStop(). Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* nodedev: add parent_addr to mdev nodedev dumpxmlBoris Fiuczynski2022-02-041-0/+2
| | | | | | | | 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>
* qemu: Validate domain definition even on migrationMichal Privoznik2022-02-041-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we are about to spawn QEMU, we validate the domain definition against qemuCaps. Except when domain is/was already running before (i.e. on incoming migration, snapshots, resume from a file). However, especially on incoming migration it may happen that the destination QEMU is different to the source QEMU, e.g. the destination QEMU may have some devices disabled. And we have a function that validates devices/features requested in domain XML against the desired QEMU capabilities (aka qemuCaps) - it's virDomainDefValidate() which calls qemuValidateDomainDef() and qemuValidateDomainDeviceDef() subsequently. But the problem here is that the validation function is explicitly skipped over in specific scenarios (like incoming migration, restore from a snapshot or previously saved file). This in turn means that we may spawn QEMU and request device/features it doesn't support. When that happens QEMU fails to load migration stream: qemu-kvm: ... 'virtio-mem-pci' is not a valid device model name (NB, while the example shows one particular device, the problem is paramount) This problem is easier to run into since we are slowly moving validation from qemu_command.c into said validation functions. The solution is simple: do the validation in all cases. And while it may happen that users would be unable to migrate/restore a guest due to a bug in our validator, spawning QEMU without validation is worse (especially when you consider that users can supply their own XMLs for migrate/restore operations - these were never validated). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2048435 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* qemu: gpu: Get pid without binary validationVasiliy Ulyanov2022-02-041-6/+3
| | | | | | | | | | | | | The binary validation in virPidFileReadPathIfAlive may fail with EACCES if the calling process does not have CAP_SYS_PTRACE capability. Therefore instead do only the check that the pidfile is locked by the correct process. Fixes the same issue as with swtpm. Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* qemu: tpm: Get swtpm pid without binary validationVasiliy Ulyanov2022-02-041-40/+54
| | | | | | | | | | | | | | | | | | | | Access to /proc/[pid]/exe may be restricted in certain environments (e.g. in containers) and any attempt to stat(2) or readlink(2) the file will result in 'permission denied' error if the calling process does not have CAP_SYS_PTRACE capability. According to proc(5) manpage: Permission to dereference or read (readlink(2)) this symbolic link is governed by a ptrace access mode PTRACE_MODE_READ_FSCREDS check; see ptrace(2). The binary validation in virPidFileReadPathIfAlive may fail with EACCES. Therefore instead do only the check that the pidfile is locked by the correct process. To ensure this is always the case the daemonization and pidfile handling of the swtpm command is now controlled by libvirt. Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virpidfile: Add virPidFileReadPathIfLocked funcVasiliy Ulyanov2022-02-043-0/+38
| | | | | | | | | | The function will attempt to read a pid from @path, and store it in @pid. The @pid will only be set, however, if @path is locked by virFileLock() at byte 0 and the pid in @path is running. Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* conf: Fix documentation for virDomainDefGetShortName()Andrea Bolognani2022-02-041-2/+1
| | | | | | | | | | The @unique argument didn't exist even when the function was introduced in a042275a396e, and the @vm argument was not renamed when the function was changed to take a virDomainDef* instead of a virDomainObj* in 7ed6934f3b92. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* Ignore EPERM on implicit clearing of VF VLAN IDDmitrii Shcherbakov2022-02-031-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Allow VF vlanid to be passed as a pointerDmitrii Shcherbakov2022-02-033-18/+31
| | | | | | | | | | | 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>
* Set VF MAC and VLAN ID in two different operationsDmitrii Shcherbakov2022-02-033-66/+205
| | | | | | | | | | | 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>
* ch: virCHProcessSetupIOThreads: use correct type for return valueJán Tomko2022-02-031-2/+4
| | | | | | | | | | | virCHMonitorGetIOThreads returns an int, not size_t. Also return early if it's negative, because promoting it to an unsigned type in the for loop condition could lead to an infinte loop. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
* ch: virCHMonitorGetIOThreads: fix g_steal_pointer usageJán Tomko2022-02-031-1/+1
| | | | | | Fixes: 81226d88034fd460855ac75dd2c985ca91ff6219 Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
* qemu: virtiofs: check whether the supplied binary existsJán Tomko2022-02-031-0/+7
| | | | | | | | | | Report an error upfront if the binary does not exist or is not executable. https://bugzilla.redhat.com/show_bug.cgi?id=1999372 Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
* maint: remove unnecessary virutil.h includesJán Tomko2022-02-036-6/+0
| | | | | Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* virParseVersionString: rename to virStringParseVersionJán Tomko2022-02-0314-21/+22
| | | | | Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* util: virParseVersionString: move to virstring.cJán Tomko2022-02-035-50/+52
| | | | | Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* maint: add required includesJán Tomko2022-02-032-0/+2
| | | | | | | | | | Some files do not include what they use and rely on virutil.h to pull in the necessary header files. Fix it. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* conf: support firmware ISA debug consoleDaniel P. Berrangé2022-02-036-3/+29
| | | | | | | | | | | | | | | | | | | | | | Introduce support for <serial type='pty'> <target type='isa-debug'> <model type='isa-debugcon'/> </target> <address type='isa' iobase='0x402'/> </console> which is used as a way to receive debug messages from the firmware on x86 platforms. Note that the default port is hypervisor specific, with QEMU currently using 0xe9 since that's the original Bochs debug port. For use with SeaBIOS/OVMF, the iobase port needs to be explicitly set to 0x402. Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* conf: validate serial port model in ABI checksDaniel P. Berrangé2022-02-031-0/+8
| | | | | | | | The serial port model cannot be allowed to change across migration as it affects ABI. Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* virnodedeviceobj: Don't unlock virNodeDeviceObj in virNodeDeviceObjListRemove()Michal Privoznik2022-02-032-4/+2
| | | | | | | | | | | | When virNodeDeviceObjListRemove() is called, the passed virNodeDeviceObj is removed from internal list of node devices and then unrefed and unlocked. While the former is warranted (the object was refed at the beginning of the function) the unlock is not. In fact, it's wrong from conceptual POV. We still want threads working on the object tu mutually exclude each other. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
* qemu: Drop qemuAudioDriver enumerationAndrea Bolognani2022-02-023-27/+40
| | | | | | | | | | | | | | | | | | This mostly overlaps with virDomainAudioType, but in a couple of cases the string representations are different. Right now we're doing that in a somewhat sketchy way, in that we store values of one enumeration and then convert them to strings using TypeToString() implementation for the other enumeration; when converting from string, we open-code the handling of the special values mentioned above. Drop the second enumeration and introduce two helpers to deal with conversion. Most calling sites don't need to be changed, and one can even be simplified significantly. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* qemu: Correctly translate QEMU_AUDIO_DRV=wavAndrea Bolognani2022-02-021-0/+2
| | | | | | | | This, along with "pa", is the other case where the libvirt and QEMU names do not match. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* meson: Add missing virt_install_dirsAndrea Bolognani2022-02-0212-1/+51
| | | | | | | | | | We recently started listing these in the spec file and, since we were not creating them during the installation phase, that broke RPM builds. Fixes: 4b43da0bff9b78dcf1189388d4c89e524238b41d Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* meson: Sort virt_install_dirsAndrea Bolognani2022-02-023-6/+6
| | | | | | | This will make subsequent patches nicer. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* qemu_command: Generate memory only after controllersMichal Privoznik2022-02-021-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* qemu: add PCI root to MIPS Malta machineLubomir Rintel2022-02-021-4/+8
| | | | | | | MIPS Malta (and no other supported MIPS machine) has a PCI bus. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* qemu: add qemuDomainIsMipsMalta()Lubomir Rintel2022-02-022-0/+22
| | | | | | | | This identifies various MIPS Malta machines, be it 32-bit or 64-bit, little-endian or big-endian. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>