Commit Graph

44829 Commits

Author SHA1 Message Date
Michal Privoznik
b1e7807711 ch_driver: Don't lock driver when looking up domains
There is no need to lock whole driver when accessing
virDomainObjList. Those APIs were specifically tailored to be
thread safe (when we were dropping QEMU driver lock). Don't
resurrect old history.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:47:48 +01:00
Michal Privoznik
31ef66f12e ch_driver: Don't lock driver when getting version
In chConnectGetVersion() the CH driver is locked in order to read
driver->version. This is needless, because not only is the
version set with driver unlocked (chStateInitialize() calls
chExtractVersion() which sets the version), but the version is
practically immutable. Once driver initialized itself it's never
changed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:46:49 +01:00
Michal Privoznik
d192e522ef qemuFirmwareFillDomain: Use FW descriptors to lookup template when resetting NVRAM
If VIR_QEMU_PROCESS_START_RESET_NVRAM flag is passed when
starting a domain, then user requested to overwrite the domain
specific NVRAM with the one from template. But it is very likely
that the path to the template is not stored in the domain
definition, which in turn makes the copy function
(qemuPrepareNVRAM()) fail.

The solution is simple - when preparing domain, specifically when
deciding whether the path to the template should be autofilled,
ignore any existing NVRAM file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-11 09:03:20 +01:00
Michal Privoznik
f21166c814 qemu_process: Accept VIR_QEMU_PROCESS_START_RESET_NVRAM flag when starting a domain
In one of my previous commits I've fixed the value of
VIR_QEMU_PROCESS_START_RESET_NVRAM flag (which was masking
another value). But what I forgot to do is update virCheckFlags()
calls in two places where the flag is passed: qemuProcessLaunch()
and qemuProcessStart().

Fixes: 1b636593c7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-11 09:03:16 +01:00
Andrea Bolognani
2ac78307af docs: Clarify our stance on backported packages
The repositories containing them are usually offered with lower
guarantees, so we don't consider them when it comes to figuring
out the minimum targeted version of our dependencies.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-10 22:39:58 +01:00
Peter Krempa
775cd951e2 qemuMonitorOpen: Refactor cleanup
Use VIR_AUTOCLOSE to avoid a 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-10 13:13:28 +01:00
Peter Krempa
0e01846dbf qemuMonitorOpenUnix: Refactor cleanup
Use VIR_AUTOFREE for the temp socket so that the 'error:' label can be
removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-10 13:13:28 +01:00
Peter Krempa
ee51ab86c2 virNetDevOpenvswitchUpdateVlan: Use space for indentation
Breaks syntax-check:

TAB_in_indentation
/home/pipo/libvirt/src/util/virnetdevopenvswitch.c:610:	if (virtVlan && virtVlan->nTags > 0)
/home/pipo/libvirt/src/util/virnetdevopenvswitch.c:611:		virCommandAddArgList(cmd, "--", "--if-exists", "set", "Port", ifname, NULL);
make: Leaving directory '/home/pipo/build/libvirt/gcc/build-aux'

Fixes: 21c55a45ef
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2022-02-10 13:10:35 +01:00
tuqiang
21c55a45ef virNetDevOpenvswitchUpdateVlan: fix vlan tag update error
We try to update vlan tag by running virsh update-device command,
libvirtd will report ovs-vsctl arguments error. Vlan tag update
funtion does't consider the xml with no vlan configured circumstances.

The steps to reproduce the problem:
1 define and start domain with its vlan configured as:
    <interface type='bridge'>
      <mac address='52:54:00:9e:bb:ac'/>
      <source bridge='ovs-br0'/>
      <vlan>
        <tag id='10'/>
      </vlan>
      <virtualport type='openvswitch'>
      </virtualport>
      <target dev='vnet4.0'/>
      <model type='virtio'/>
      <driver name='vhost'/>
    </interface>
2 define and run virsh update-device command with no vlan configured as:
    <interface type='bridge'>
      <mac address='52:54:00:9e:bb:ac'/>
      <source bridge='ovs-br0'/>
      <virtualport type='openvswitch'>
      </virtualport>
      <target dev='vnet4.0'/>
      <model type='virtio'/>
      <driver name='vhost'/>
    </interface>
   #virsh update-device dom-id novlan.xml
3 virsh command returned error, and we got an error in libvirtd.log:
  error : virCommandWait:2584 : internal error: exit status 1: ovs-vsctl: 'set' command requires at least 3 arguments
  . Child process (ovs-vsctl --timeout=5 -- --if-exists clear Port vnet4.0 tag -- --if-exists clear Port vnet4.0 trunk
  -- --if-exists clear Port vnet4.0 vlan_mode -- --if-exists set Port vnet4.0) unexpected
  error : virNetDevOpenvswitchUpdateVlan:540 : internal error: Unable to set vlan configuration on port vnet4.0

Signed-off-by: Tu Qiang <tu.qiang35@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-10 13:02:10 +01:00
Jing Qi
89b8b3662e docs: Fix HMAT example
There are dupliacated and non-continuous CPU IDs used in HMAT
example. Fix that.

Signed-off-by: Jing Qi <jinqi@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-10 12:43:36 +01:00
Jiri Denemark
558f00397a qemu: Ignore missing vm.unprivileged_userfaultfd sysctl
Older kernels did not support this sysctl, but they did not restrict
userfaultfd in any way so everything worked as if
vm.unprivileged_userfaultfd was set to 1. Thus we can safely ignore
errors when setting the value.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-09 13:03:33 +01:00
Michal Privoznik
da393034c9 qemu_process: Fix theoretical overflow in uint to bool typecast
The qemuPrepareNVRAM() function accepts three arguments and the
last one being a boolean type. However, when the function is
called from qemuProcessPrepareHost() the argument passed is a
result of logical and of @flags (unsigned int) and
VIR_QEMU_PROCESS_START_RESET_NVRAM value. In theory this is
unsafe to do because if the value of the flag is ever changed
then this expression might overflow. Do what we do elsewhere:
double negation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-09 09:31:54 +01:00
Michal Privoznik
1b636593c7 qemu_process.c: Fix VIR_QEMU_PROCESS_START_RESET_NVRAM value
In one of recent commits qemuProcessStartFlags enum gained new
value: VIR_QEMU_PROCESS_START_RESET_NVRAM but due to a typo it
has the same value as another member of the enum. Fix that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-09 09:30:15 +01:00
Jim Fehlig
18ec405a36 libxl: Release auto-allocated spice ports
While VNC ports auto-allocated by the libxl driver are released in
libxlDomainCleanup, spice ports are overlooked. Rework the existing
logic to release any auto-allocated graphics ports, not just the VNC
port of the first graphics device.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-08 10:40:40 -07: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
Daniel P. Berrangé
7904e521b2 tools: add --reset-nvram arg to several virsh commands
This wires up support for resetting NVRAM for all APIs that allow
this feature.

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
Daniel P. Berrangé
5413608dc2 qemu: wire up support for resetting NVRAM
We can now replace the existing NVRAM file on startup when
the API requests this.

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
Daniel P. Berrangé
12a658ecf7 include: define constants for resetting NVRAM state
When starting a guest with pflash based firmware, we will initialize
NVRAM from a template if it does not already exist. In theory if the
firmware code file is updated, the existing NVRAM variables should
continue to work correctly. It is inevitable that this could break
accidentally one day. Or a bug in the firmware might corrupt the
NVRAM storage. Or user might make bad changes to the settings that
prevent booting. Or the user might have re-configured the XML to
point to a different firmware file incompatible with the current
variables.

In all these cases it would be useful to delete the existing NVRAM
and initialize it from the pristine template.

To support this introduce a VIR_DOMAIN_START_RESET_NVRAM constant
for use with virDomainCreate / virDomainCreateXML, along with
VIR_DOMAIN_SAVE_RESET_NVRAM for use with virDomainRestore and
VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM for use with
virDomainSnapshotRevert.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-08 13:04:11 +00:00
Daniel P. Berrangé
5e3498744e qemu: do crash safe creation of NVRAM file
If we crash part way through writing the NVRAM file we end up with an
unusable NVRAM on file. To avoid this we need to write to a temporary
file and fsync(2) at the end, then rename to the real NVRAM file path.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-08 13:01:24 +00:00
Göran Uddeborg
2df9031a0e Translated using Weblate (Swedish)
Currently translated at 32.4% (3394 of 10455 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/sv/

Co-authored-by: Göran Uddeborg <goeran@uddeborg.se>
Signed-off-by: Göran Uddeborg <goeran@uddeborg.se>
2022-02-08 12:38:48 +01:00
Michal Privoznik
a58ff73644 cpu_conf: unbreak XPath in virCPUDefParseXML()
In one of my previous commits, I've changed an XPath in
virCPUDefParseXML() from "boolean(./counter...)" to
"./counter...)". Notice the dangling closing bracket? Well, I
didn't back then.

Fixes: 0fe2d8dd33
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-08 12:38:01 +01: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
Michal Privoznik
1688d2527f vbox_common: Drop needless set to NULL
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>
2022-02-08 08:41:56 +01:00
Jim Fehlig
e0241f334d libxl: Set auto-allocated graphics ports to used on reconnect
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>
2022-02-07 13:30:35 -07:00
Peter Krempa
a7743c6026 qemu: process: Don't use hardcoded QOM path for cpu for probing flags
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>
2022-02-07 18:04:52 +01:00
Peter Krempa
068aaa9795 qemu: process: Move call to qemuProcessRefreshCPU after cpu probe
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>
2022-02-07 18:04:52 +01:00
Peter Krempa
2f498b5980 qemu: process: Move cpu flag querying after code probing cpus
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>
2022-02-07 18:04:52 +01:00
Peter Krempa
f0a4951616 qemu: domain: Store 'qomPath' in qemuDomainVcpuPrivate
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>
2022-02-07 18:04:52 +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
Peter Krempa
476e864186 qemuProcessUpdateAndVerifyCPU: Refactor cleanup
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>
2022-02-07 18:04:52 +01:00
Peter Krempa
3ac3b3e8fb qemuMonitorJSONGetCPUx86Data: Unexport
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>
2022-02-07 18:04:52 +01:00
Andrea Bolognani
e7be6be775 qemu: Move high-level actions close together
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
cc132636fc qemu: Move entry points close together
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
e74d87c43b qemu: Move utility functions close together
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
8367ad8a38 qemu: Fix description of swtpmStateDir
This directory contains runtime state, not persistent state.
The latter goes into swtpmStorageDir.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
a0dedd64d4 qemu: Call virDomainDefGetShortName() less frequently
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>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
f3a40a7d20 qemu: Rename path-building functions
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>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
c2c8cf3ed4 qemu: Introduce qemuTPMEmulatorCleanupHost()
This leaves qemuExtTPMCleanupHost() to only deal with looping
over TPM devices, same as other qemuExtTPMDoThing() functions.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
5d35e2f2cc qemu: Introduce qemuExtTPMEmulatorSetupCgroup()
This leaves qemuExtTPMSetupCgroup() to only deal with looping
over TPM devices, same as other qemuExtTPMDoThing() functions.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
a9763e8e38 qemu: Make qemuTPMEmulatorCreateStorage() take a virDomainTPMDef*
This matches how qemuTPMEmulatorDeleteStorage() expects to be
called.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
b12779dc80 qemu: Drop qemuTPMEmulatorInitStorage()
Absorb it into qemuTPMEmulatorCreateStorage(), its only caller.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
4d0cff4221 qemu: Document qemuTPMEmulatorDeleteStorage()
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
de69ad16ac qemu: Rename qemuTPM{Create,Delete}EmulatorStorage()
Other functions that operate on a single TPM emulator follow
the qemuTPMEmulatorDoThing() naming convention.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
806f5b5d42 qemu: Fully document qemuTPMEmulatorStart()
The @tpm argument was not mentioned.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +01:00
Andrea Bolognani
5d9d9943a7 qemu: Rename qemuExtTPMStartEmulator()
Its counterpart is qemuTPMEmulatorStop().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2022-02-05 14:36:11 +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
Michal Privoznik
517b8c12b9 qemu: Validate domain definition even on migration
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>
2022-02-04 13:49:39 +01:00
Vasiliy Ulyanov
e3dfa52d26 qemu: gpu: Get pid without binary validation
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>
2022-02-04 10:27:43 +01:00