]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
2 years agoqemu: refresh internal domain state after reset
Kristina Hanicova [Tue, 6 Dec 2022 13:58:18 +0000 (14:58 +0100)]
qemu: refresh internal domain state after reset

Internal domain state may change during the reset and qemu does
not always send events about it.  In case it happens, internal
state of the domain in libvirt would be inconsistent with the
internal state in qemu which could cause additional problems
(e.g. cdrom tray state can change from open to closed).  The
solution is to refresh state after a successful reset to query
qemu about the current internal domain state.

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

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu: Init ext devices paths on reconnect
Michal Privoznik [Mon, 5 Dec 2022 12:08:39 +0000 (13:08 +0100)]
qemu: Init ext devices paths on reconnect

Paths for external devices (well, so far only vTPM) are not
stored in the status XML. Therefore, we need to regenerate them
after we've been restarted and reconnecting to a running domain.
Otherwise these will remain NULL which may later lead to a NULL
dereference.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2150760
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_extdevice: Expose qemuExtDevicesInitPaths()
Michal Privoznik [Mon, 5 Dec 2022 12:08:25 +0000 (13:08 +0100)]
qemu_extdevice: Expose qemuExtDevicesInitPaths()

This function is going to be called outside of qemu_extdevice.c.
Expose it to the rest of the driver.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_extdevice: Init paths in qemuExtDevicesPrepareDomain()
Michal Privoznik [Mon, 5 Dec 2022 11:27:24 +0000 (12:27 +0100)]
qemu_extdevice: Init paths in qemuExtDevicesPrepareDomain()

The path generation phase belongs conceptually into domain
preparation phase and not host preparation. Move
qemuExtDevicesInitPaths() call from qemuExtDevicesPrepareHost()
into qemuExtDevicesPrepareDomain().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_process: Document qemuProcessPrepare{Domain,Host}() order
Michal Privoznik [Mon, 5 Dec 2022 11:18:50 +0000 (12:18 +0100)]
qemu_process: Document qemuProcessPrepare{Domain,Host}() order

The domain startup process is split into multiple phases. One of
them is preparing the domain (at that point live) XML, private
data, various paths, etc - see qemuProcessPrepareDomain(); the
other prepares the host - see qemuProcessPrepareHost(). It's
obvious that the domain XML preparation function must be called
before the host preparation function (e.g. the host preparation
might try to create a file which path is generated in the domain
preparation phase). Nevertheless, let's document this
expectation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoconf: domain: Remove virDomainDeviceDefCopy
Peter Krempa [Tue, 22 Nov 2022 19:54:45 +0000 (20:54 +0100)]
conf: domain: Remove virDomainDeviceDefCopy

The function is now unused. Remove it to dissuade anybody from trying to
use it in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agolxcDomainDetachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy
Peter Krempa [Tue, 22 Nov 2022 16:01:31 +0000 (17:01 +0100)]
lxcDomainDetachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy

'virDomainDeviceDefCopy' formats the definition and parses it back.
Since we already are parsing the XML here, we're better off parsing it
twice and save the formatting step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agolxcDomainAttachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy
Peter Krempa [Tue, 22 Nov 2022 16:01:31 +0000 (17:01 +0100)]
lxcDomainAttachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy

'virDomainDeviceDefCopy' formats the definition and parses it back.
Since we already are parsing the XML here, we're better off parsing it
twice and save the formatting step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemuDomainDetachDeviceLiveAndConfig: Refactor cleanup
Peter Krempa [Tue, 22 Nov 2022 16:07:58 +0000 (17:07 +0100)]
qemuDomainDetachDeviceLiveAndConfig: Refactor cleanup

Remove the 'cleanup' label and 'ret' variable as we can now directly
return form all cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemuDomainDetachDeviceLiveAndConfig: Parse XML twice rather than use virDomainDeviceD...
Peter Krempa [Tue, 22 Nov 2022 16:01:31 +0000 (17:01 +0100)]
qemuDomainDetachDeviceLiveAndConfig: Parse XML twice rather than use virDomainDeviceDefCopy

'virDomainDeviceDefCopy' formats the definition and parses it back.
Since we already are parsing the XML here, we're better off parsing it
twice and save the formatting step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemuDomainUpdateDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy
Peter Krempa [Tue, 22 Nov 2022 16:01:31 +0000 (17:01 +0100)]
qemuDomainUpdateDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy

'virDomainDeviceDefCopy' formats the definition and parses it back.
Since we already are parsing the XML here, we're better off parsing it
twice and save the formatting step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu: driver: Fix formatting of function headers around qemuDomainAttachDevice
Peter Krempa [Tue, 22 Nov 2022 15:56:38 +0000 (16:56 +0100)]
qemu: driver: Fix formatting of function headers around qemuDomainAttachDevice

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agodocs: drvqemu: Remove inaccuate limitations statement
Peter Krempa [Mon, 21 Nov 2022 12:47:52 +0000 (13:47 +0100)]
docs: drvqemu: Remove inaccuate limitations statement

We don't refuse override definitions for device which doesn't exist and
the same way don't care about 'remove' being used on a property which is
not actually formatted by libvirt. Drop the paragraph claiming the
contrary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agodocs: drvqemu: Give example how to query device properties for overriding
Peter Krempa [Mon, 21 Nov 2022 12:46:29 +0000 (13:46 +0100)]
docs: drvqemu: Give example how to query device properties for overriding

Add an example of invoking qemu with '-device TYPE,?' to query
properties of a given type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agodocs: drvqemu: Fix and improve docs about device override types
Peter Krempa [Mon, 21 Nov 2022 12:44:54 +0000 (13:44 +0100)]
docs: drvqemu: Fix and improve docs about device override types

The 'number' override type didn't exist in the final version so change
it to the corresponding 'signed' and 'unsigned'.

Additionally clarify which override type is used for a corresponding
qemu type and also that we use base 10 numbers so users will need to
convert the numbers if needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu: Don't report spurious errors from vCPU tid validation on hotunplug timeout
Shaleen Bathla [Fri, 11 Nov 2022 09:24:38 +0000 (14:54 +0530)]
qemu: Don't report spurious errors from vCPU tid validation on hotunplug timeout

Use of qemuDomainValidateVcpuInfo in the helpers for hotplug and unplug
of vCPUs can lead to spurious errors reported such as:

  internal error: qemu didn't report thread id for vcpu 'XX'"

The reason for this is that qemuDomainValidateVcpuInfo validates the
state of all vCPUs against the expected state of vCPUs. If an unplug
operation completed before libvirt was unable to process it yet the
expected state could not reflect the current state.

To avoid spurious errors the qemuDomainHotplugAddVcpu and
qemuDomainRemoveVcpu functions are modified to do localized validation
only for the vCPUs they actually modify.

We also now ensure that the cgroups are modified before bailing out on
error for any vCPUs which passed validation.

Additionally in order for qemuDomainRemoveVcpuAlias to be able to find
the unplugged vCPU we must ensure that qemuDomainRefreshVcpuInfo does
not clear out the alias in case when the vCPU is no longer reported by
qemu.

Co-authored-by: Partha Satapathy <partha.satapathy@oracle.com>
Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_tpm: Set log file label on migration
Michal Privoznik [Fri, 2 Dec 2022 15:09:37 +0000 (16:09 +0100)]
qemu_tpm: Set log file label on migration

Recently, the QEMU driver gained support for migration with TPM
state on a shared volume (e.g. NFS). As a part of that, the
destination side avoids setting seclabels on it to avoid cutting
off the source while it is still using it. Makes sense, except
for a wee bit: the secdriver API does a bit more - it also sets
label on the swtpm log file. And this one definitely needs to be
labeled (it lives under /var/log/swtpm/libvirt/qemu/..., i.e. not
on a shared volume).

Previously, qemuSecurityStartTPMEmulator() took care of that. But
during rework to shared volume migration, the code was changed so
now plain qemuSecurityCommandRun() would be run (i.e. no
relabelling).

But after previous commits, we can now chose whether the TPM
state should be relabelled or just the log file.

Fixes: 2e669ec789231d39e0d5f5f6a201d2a661b8070c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2130192#c7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_tpm: Extend start/stop APIs
Michal Privoznik [Fri, 2 Dec 2022 15:04:41 +0000 (16:04 +0100)]
qemu_tpm: Extend start/stop APIs

This is basically just a continuation of the previous commit.
Now that the security driver APIs have a boolean flag that
controls setting/restoring seclabel of either both TPM state and
log files, or just the log file, propagate this boolean into
those APIs that start/stop swtpm emulator. For now, just pass
true. The juicy bits are soon to come.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agosecurity: Extend TPM label APIs
Michal Privoznik [Fri, 2 Dec 2022 14:59:28 +0000 (15:59 +0100)]
security: Extend TPM label APIs

The virSecurityDomainSetTPMLabels() and
virSecurityDomainRestoreTPMLabels() APIs set/restore label on two
files/directories:

  1) the TPM state (tpm->data.emulator.storagepath), and
  2) the TPM log file (tpm->data.emulator.logfile).

Soon there will be a need to set the label on the log file but
not on the state. Therefore, extend these APIs for a boolean flag
that when set does both, but when unset does only 2).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoTranslated using Weblate (Chinese (Simplified) (zh_CN))
Yang Yulin [Sat, 3 Dec 2022 13:19:57 +0000 (14:19 +0100)]
Translated using Weblate (Chinese (Simplified) (zh_CN))

Currently translated at 99.2% (10294 of 10368 strings)

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

Co-authored-by: Yang Yulin <yylteam@icloud.com>
Signed-off-by: Yang Yulin <yylteam@icloud.com>
2 years agovirshFindDisk: Sanitize use of 'tmp' variable
Peter Krempa [Wed, 19 Oct 2022 11:59:17 +0000 (13:59 +0200)]
virshFindDisk: Sanitize use of 'tmp' variable

The return value of virXMLPropString was assigned into 'tmp' multiple
times and to prevent static analyzers moaning about a potential leak a
short-circuited if logic or was used.

Replace the code by having a helper variable for each possibility and
also replace the for-loop to iterate elements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoutil: xml: Introduce virXMLNodeGetSubelement
Peter Krempa [Fri, 2 Dec 2022 09:35:13 +0000 (10:35 +0100)]
util: xml: Introduce virXMLNodeGetSubelement

Introduce a simple helper fetching a sub-element node by name. This is
meant as a simple replacement for either open-coded versions of this or
use of XPath for this trivial lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirshFindDisk: Sanitize removable media check
Peter Krempa [Wed, 19 Oct 2022 11:31:00 +0000 (13:31 +0200)]
virshFindDisk: Sanitize removable media check

The XPath lookup guarantees that the top level element is always 'disk'
so there's no need to check that it actually is. We can also remove the
two unnecessary temporary variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirshFindDisk: Use virXPathNodeSet instead of xmlXPathEval
Peter Krempa [Wed, 19 Oct 2022 11:21:23 +0000 (13:21 +0200)]
virshFindDisk: Use virXPathNodeSet instead of xmlXPathEval

Don't open-code the XPath lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: cmdChangeMedia: Refactor cleanup
Peter Krempa [Fri, 2 Dec 2022 09:14:09 +0000 (10:14 +0100)]
virsh: cmdChangeMedia: Refactor cleanup

Use automatic pointer freeing for the 'disk_node' variable and remove
the 'cleanup' label and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: cmdDetachDisk: Refactor cleanup
Peter Krempa [Fri, 2 Dec 2022 09:14:09 +0000 (10:14 +0100)]
virsh: cmdDetachDisk: Refactor cleanup

Use automatic pointer freeing for the 'disk_node' variable and remove
the 'cleanup' label and 'functionReturn' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: virshMakeCloneXML: Use virXPathNode instead of xmlXPathEval
Peter Krempa [Thu, 1 Dec 2022 08:39:30 +0000 (09:39 +0100)]
virsh: virshMakeCloneXML: Use virXPathNode instead of xmlXPathEval

Refactor the code to use the XPath helpers instead of open-coding them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: Add --print-xml flag for 'vol-clone' command
Peter Krempa [Wed, 30 Nov 2022 15:48:23 +0000 (16:48 +0100)]
virsh: Add --print-xml flag for 'vol-clone' command

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: Refactor cleanup in 'cmdVolClone'
Peter Krempa [Wed, 30 Nov 2022 15:40:14 +0000 (16:40 +0100)]
virsh: Refactor cleanup in 'cmdVolClone'

Automatically free 'newxml' and remove the 'cleanup' label and 'ret'
variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: cmdDomIfSetLink: Use virXPathNodeSet instead of xmlXpathEval
Peter Krempa [Wed, 19 Oct 2022 08:39:33 +0000 (10:39 +0200)]
virsh: cmdDomIfSetLink: Use virXPathNodeSet instead of xmlXpathEval

Refactor the XPath lookup to use the internal helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: Add --print-xml option for 'domif-setlink'
Peter Krempa [Wed, 30 Nov 2022 15:04:03 +0000 (16:04 +0100)]
virsh: Add --print-xml option for 'domif-setlink'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirshDomainDetachInterface: Use virXPathNodeSet instead of xmlXpathEval
Peter Krempa [Tue, 18 Oct 2022 13:00:59 +0000 (15:00 +0200)]
virshDomainDetachInterface: Use virXPathNodeSet instead of xmlXpathEval

Refactor the XPath lookup to use the internal helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: Add --print-xml option for 'detach-interface'
Peter Krempa [Wed, 30 Nov 2022 09:49:26 +0000 (10:49 +0100)]
virsh: Add --print-xml option for 'detach-interface'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoutil: json: Remove unused virJSONValueObjectGetStringArray wrapper
Peter Krempa [Thu, 1 Dec 2022 16:08:44 +0000 (17:08 +0100)]
util: json: Remove unused virJSONValueObjectGetStringArray wrapper

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemuAgentSSHGetAuthorizedKeys: Convert last use ofvirJSONValueObjectGetStringArray
Peter Krempa [Thu, 1 Dec 2022 16:07:12 +0000 (17:07 +0100)]
qemuAgentSSHGetAuthorizedKeys: Convert last use ofvirJSONValueObjectGetStringArray

Use virJSONValueObjectGetArray + virJSONValueArrayToStringList instead
so that the ofvirJSONValueObjectGetStringArray wrapper can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Use qemuMonitorJSONGetReply in conjunction with virJSONValueArrayToStr...
Peter Krempa [Thu, 1 Dec 2022 16:19:50 +0000 (17:19 +0100)]
qemu: monitor: Use qemuMonitorJSONGetReply in conjunction with virJSONValueArrayToStringList

In two instances (qemuMonitorJSONGetStringListProperty,
qemuMonitorJSONGetStringArray) the return value is checked by
qemuMonitorJSONCheckReply and extracted by
virJSONValueObjectGetStringArray.

We can use qemuMonitorJSONGetReply which returns it directly and then
virJSONValueArrayToStringList to convert it without the additional
lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object
Peter Krempa [Thu, 1 Dec 2022 15:13:41 +0000 (16:13 +0100)]
qemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object

Using 'virJSONValueObjectHasKey' when we want to access the value
afterwards is wasteful. Fetch the JSON value right away.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemuMonitorJSONGetCPUDefinitions: Rework lookup of 'unavailable-features'
Peter Krempa [Thu, 1 Dec 2022 15:13:05 +0000 (16:13 +0100)]
qemuMonitorJSONGetCPUDefinitions: Rework lookup of 'unavailable-features'

Rather than checking that the object has the correct key and then
fetching it again use fetch the array first and then use
virJSONValueArrayToStringList to directly convert it.

Additionally we can avoid the conversion if there are no members
simplifying the surrounding logic.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray for optional data
Peter Krempa [Thu, 1 Dec 2022 16:02:42 +0000 (17:02 +0100)]
qemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray for optional data

The 'dependencies' field in the return data may be missing in some
cases. Historically 'virJSONValueObjectGetStringArray' didn't report
error in such case, but later refactor (commit 043b50b948ef3c2 ) added
an error in order to use it in other places too.

Unfortunately this results in the error log being spammed with an
irrelevant error in case when qemuAgentGetDisks is invoked on a VM
running windows.

Replace the use of virJSONValueObjectGetStringArray by fetching the
array first and calling virJSONValueArrayToStringList only when we have
an array.

Fixes: 043b50b948ef3c2a4adf5fa32a93ec2589851ac6
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149752
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoutil: json: Split out array->strinlist conversion from virJSONValueObjectGetStringArray
Peter Krempa [Thu, 1 Dec 2022 12:32:07 +0000 (13:32 +0100)]
util: json: Split out array->strinlist conversion from virJSONValueObjectGetStringArray

Introduce virJSONValueArrayToStringList which does only the conversion
from an array to a stringlist.

This will allow refactoring the callers to be more careful in case when
they want to handle the existance of the member in the parent object
differently.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Unify and refactor 'PTY' case in qemuMonitorJSONAttachCharDev
Peter Krempa [Thu, 1 Dec 2022 15:47:29 +0000 (16:47 +0100)]
qemu: monitor: Unify and refactor 'PTY' case in qemuMonitorJSONAttachCharDev

Use qemuMonitorJSONGetReply and unify the two blocks with the same
condition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Use qemuMonitorJSONGetReply when the value is extracted directly
Peter Krempa [Thu, 1 Dec 2022 15:43:18 +0000 (16:43 +0100)]
qemu: monitor: Use qemuMonitorJSONGetReply when the value is extracted directly

Use qemuMonitorJSONGetReply in cases where qemuMonitorJSONCheckReply
is followed by virJSONValueObjectGet*(reply, "return").

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Use qemuMonitorJSONGetReply for VIR_JSON_TYPE_ARRAY
Peter Krempa [Thu, 1 Dec 2022 15:27:13 +0000 (16:27 +0100)]
qemu: monitor: Use qemuMonitorJSONGetReply for VIR_JSON_TYPE_ARRAY

Replace usage of the following pattern with the new helper:

  if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
      return -1;

  data = virJSONValueObjectGetArray(reply, "return");

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Use qemuMonitorJSONGetReply for VIR_JSON_TYPE_OBJECT
Peter Krempa [Thu, 1 Dec 2022 15:27:13 +0000 (16:27 +0100)]
qemu: monitor: Use qemuMonitorJSONGetReply for VIR_JSON_TYPE_OBJECT

Replace usage of the following pattern with the new helper:

  if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
      return -1;

  data = virJSONValueObjectGetObject(reply, "return");

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoqemu: monitor: Introduce qemuMonitorJSONGetReply, a better qemuMonitorJSONCheckReply
Peter Krempa [Thu, 1 Dec 2022 15:18:52 +0000 (16:18 +0100)]
qemu: monitor: Introduce qemuMonitorJSONGetReply, a better qemuMonitorJSONCheckReply

Rather than simply checking that the 'return' field is of the expected
type we can directly return it as the caller is very likely going to use
it. Extract the code into the new function and add a wrapper to preserve
old functionality.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agolibxl: migration: Use 'unsigned int' for flags
Peter Krempa [Tue, 22 Nov 2022 12:03:39 +0000 (13:03 +0100)]
libxl: migration: Use 'unsigned int' for flags

Fix the type for few internal functions. Externally the APIs were
already limiting 'flags' to 'unsigned int'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu: migration: Use 'unsigned int' for flags
Peter Krempa [Tue, 22 Nov 2022 10:50:13 +0000 (11:50 +0100)]
qemu: migration: Use 'unsigned int' for flags

Don't continue with the historical mistake and fix all internal
functions to use a sane type for flags.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu: processGuestPanicEvent: Use 'unsigned int' for flags
Peter Krempa [Tue, 22 Nov 2022 12:04:02 +0000 (13:04 +0100)]
qemu: processGuestPanicEvent: Use 'unsigned int' for flags

No need to use 'long'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agovirsh: vol-create-as: Use 'unsigned int' for flags
Peter Krempa [Tue, 22 Nov 2022 12:04:21 +0000 (13:04 +0100)]
virsh: vol-create-as: Use 'unsigned int' for flags

The API itself uses 'unsigned int' so use the same type for the local
variable in virsh.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agointernal: Refuse values exceeding range of 'unsigned int' in virCheckFlags
Peter Krempa [Tue, 22 Nov 2022 10:44:50 +0000 (11:44 +0100)]
internal: Refuse values exceeding range of 'unsigned int' in virCheckFlags

Historically our migration APIs declare 'unsigned long flags'. Since
it's baked into our API we can't change that but we can avoid
compatibility problems by preemptively refusing the extra range on
certain arches to prevent future surprise.

Modify the macro to verify that value passed inside 'flags' doesn't
exceed the range of 'unsigned int'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agospec: Remove use of %{name} macro
Jim Fehlig [Fri, 2 Dec 2022 00:08:38 +0000 (17:08 -0700)]
spec: Remove use of %{name} macro

The spec file uses both "libvirt" and "%{name}", but in reality the
expanded value of %{name} will never change. Drop the macro in favor
of the explicit and more readable "libvirt".

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoTranslated using Weblate (Chinese (Simplified) (zh_CN))
Daniel P. Berrangé [Fri, 2 Dec 2022 13:09:34 +0000 (14:09 +0100)]
Translated using Weblate (Chinese (Simplified) (zh_CN))

Currently translated at 99.2% (10292 of 10368 strings)

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

Co-authored-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2 years agoTranslated using Weblate (Chinese (Simplified) (zh_CN))
Yang Yulin [Fri, 2 Dec 2022 13:09:34 +0000 (14:09 +0100)]
Translated using Weblate (Chinese (Simplified) (zh_CN))

Currently translated at 99.2% (10292 of 10368 strings)

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

Co-authored-by: Yang Yulin <yylteam@icloud.com>
Signed-off-by: Yang Yulin <yylteam@icloud.com>
2 years agospec: Remove daemon postun trigger
Jim Fehlig [Tue, 22 Nov 2022 23:18:27 +0000 (16:18 -0700)]
spec: Remove daemon postun trigger

Remove %triggerpostun for the daemon package. Upgrades from
libvirt < 1.3.0 are now unlikely.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2 years agospec: Remove redundant with_libxl
Jim Fehlig [Tue, 22 Nov 2022 03:56:38 +0000 (20:56 -0700)]
spec: Remove redundant with_libxl

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2 years agocommandtest: Comply with FreeBSD poll()
Michal Privoznik [Thu, 1 Dec 2022 15:23:55 +0000 (16:23 +0100)]
commandtest: Comply with FreeBSD poll()

In one of recent commits I've introduced a new test case to
commandtest. In the test case I'm using poll() to wait for data
on a pipe (the write end is passed to commandhelper). However, on
FreeBSD the POLLIN semantic is a bit different:

  POLLIN        Data other than high priority data may be read
                without blocking.

Well, the pipe is non-blocking, so even if there's no data to be
read the flag is set (and subsequent read() returns 0). On the
other hand, POLLHUP is set too, BUT, if the commandhelper manages
to write everything into the pipe and die right after we'd get
both POLLIN and POLLHUP after the very first time poll() returns.
That's very unfortunate, but okay - we can just check whether
read() returned zero and break from the reading loop.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2 years agotests: Use virTestCompareToString() more
Michal Privoznik [Wed, 30 Nov 2022 08:57:49 +0000 (09:57 +0100)]
tests: Use virTestCompareToString() more

Instead of using:

  if (STRNEQ(a, b)) {
      virTestDifference(stderr, a, b);
      ...
  }

we can use:

  if (virTestCompareToString(a, b) < ) {
      ...
  }

Generated by the following spatch:

  @@
  expression a, b;
  @@

  - if (STRNEQ(a, b)) {
  + if (virTestCompareToString(a, b) < 0) {
      ...
  -   virTestDifference(stderr, a, b);
      ...
      }

and its variations (STRNEQ_NULLABLE() instead of STRNEQ(), then
in some cases variables passed to STRNEQ() are in reversed order
when compared to virTestCompareToString()).

However, coccinelle failed to recognize the pattern in
testNWFilterEBIPTablesAllTeardown() so I had to fix it manually.
Also, I manually fixed testFormat() in tests/sockettest.c as I
didn't bother writing another spatch rule just for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agotests: Don't wrap virTestDifference() arguments in NULLSTR()
Michal Privoznik [Wed, 30 Nov 2022 08:47:08 +0000 (09:47 +0100)]
tests: Don't wrap virTestDifference() arguments in NULLSTR()

The virTestDifference() is perfectly capable of handling NULL
arguments. There's no need to wrap arguments in NULLSTR().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agovirbuftest: Cleanup code around virTestDifference()
Michal Privoznik [Wed, 30 Nov 2022 08:39:46 +0000 (09:39 +0100)]
virbuftest: Cleanup code around virTestDifference()

Two things are happening here:

1) Call to virTestDifference() is guarded by '!result ||
   STRNEQ(result, _)' check. This is suboptimal since we have
   STRNEQ_NULLABLE().

2) There are couple of VIR_TEST_DEBUG() printings, which are
   useless. If debug is off they don't print anything, and if it
   is on, then much more information is printed by subsequent
   virTestDifference().

This makes the STRNEQ() + virTestDifference() combo look similar
to the rest of tests and thus can be picked up by spatch later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agocommandtest: Use virTestCompareToFile() in checkoutput()
Michal Privoznik [Tue, 22 Mar 2022 12:36:38 +0000 (13:36 +0100)]
commandtest: Use virTestCompareToFile() in checkoutput()

In the commandtest there is checkoutput() function which checks
the latest log of commandhelper (containing things like cmd line
arguments, env vars, FDs, CWD, etc.) and compares that against
expected output. Well, the way this function implements that is
effectively by open coding virTestCompareToFile() except for the
nice feature that the virTestCompareToFile() has:
VIR_TEST_OUTPUT_REGENERATE.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agocommandtest: Test virCommandSetSendBuffer() with virCommandDoAsyncIO()
Michal Privoznik [Tue, 22 Mar 2022 11:06:22 +0000 (12:06 +0100)]
commandtest: Test virCommandSetSendBuffer() with virCommandDoAsyncIO()

Introduce a test case which ensures that a daemonized process can
work with virCommandSetSendBuffer() when async IO is enabled.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agovirCommandSetSendBuffer: Take double pointer of @buffer
Michal Privoznik [Tue, 22 Mar 2022 11:12:02 +0000 (12:12 +0100)]
virCommandSetSendBuffer: Take double pointer of @buffer

The virCommandSetSendBuffer() function consumes passed @buffer,
but takes it only as plain pointer. Switch to a double pointer to
make this obvious. This allows us then to drop all
g_steal_pointer() in callers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agocommandtest: Use unsigned char in test27()
Michal Privoznik [Tue, 22 Mar 2022 11:11:44 +0000 (12:11 +0100)]
commandtest: Use unsigned char in test27()

In test27() the virCommandSetSendBuffer() is used, which expects
unsigned char. Use that type for variables which are passed to
the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agovirCommandDoAsyncIO: Drop misleading statement about main event loop
Michal Privoznik [Tue, 29 Nov 2022 15:55:16 +0000 (16:55 +0100)]
virCommandDoAsyncIO: Drop misleading statement about main event loop

Back in v1.0.3-rc1~235 when I was adding virCommandDoAsyncIO(),
the main event loop was used to poll() on the pipe to the child
process. But this was promptly changed to a separate thread
handling I/O in v1.0.3-rc1~127. However, the corresponding
comment to virCommandDoAsyncIO() still documents the original
state.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agovircommand: Document virCommandSetSendBuffer() behaviour wrt daemonize
Michal Privoznik [Tue, 22 Mar 2022 10:03:10 +0000 (11:03 +0100)]
vircommand: Document virCommandSetSendBuffer() behaviour wrt daemonize

When virCommandSetSendBuffer() is used over a virCommand that is
(or will be) daemonized, then the command must have
VIR_EXEC_ASYNC_IO flag set no later than at virCommandRunAsync()
phase so that the thread that's doing IO is spawned and thus
buffers can be sent to the process.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2 years agoconf: report no NUMA nodes when attaching memory device
Kristina Hanicova [Fri, 25 Nov 2022 13:20:53 +0000 (14:20 +0100)]
conf: report no NUMA nodes when attaching memory device

Error message reports that the guest has '0' NUMA nodes
configured when trying to attach a memory device to a guest with
no NUMA nodes. This may be a little misleading because '0' can
also be node's id.  A more friendly way is to directly report
that the guest has no NUMA nodes.

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

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoqemu: Reindent qemuMigrationCookieParse prototype arguments
Jiri Denemark [Wed, 30 Nov 2022 15:10:08 +0000 (16:10 +0100)]
qemu: Reindent qemuMigrationCookieParse prototype arguments

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agoqemu: Replace priv with qemuCaps in qemuMigrationCookieParse
Jiri Denemark [Wed, 30 Nov 2022 15:05:56 +0000 (16:05 +0100)]
qemu: Replace priv with qemuCaps in qemuMigrationCookieParse

QEMU capabilities is the only thing we use from priv so we can just pass
that directly.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agoqemu: Reorder qemuMigrationCookieParse arguments
Jiri Denemark [Wed, 30 Nov 2022 14:47:15 +0000 (15:47 +0100)]
qemu: Reorder qemuMigrationCookieParse arguments

When an internal API takes a vm pointer, it's usually just after the
driver argument.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agoPost-release version bump to 9.0.0
Jiri Denemark [Thu, 1 Dec 2022 09:59:27 +0000 (10:59 +0100)]
Post-release version bump to 9.0.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoRelease of libvirt-8.10.0
Jiri Denemark [Thu, 1 Dec 2022 09:55:15 +0000 (10:55 +0100)]
Release of libvirt-8.10.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoqemu: Pass vm to qemuMigrationCookieParse if it exists
Jiri Denemark [Wed, 30 Nov 2022 13:29:55 +0000 (14:29 +0100)]
qemu: Pass vm to qemuMigrationCookieParse if it exists

The vm object is used inside qemuMigrationCookieParse based on the flags
passed to qemuMigrationCookieParse and the content of the cookie. The
callers should not just blindly guess and pass NULL if they
(incorrectly) think the vm object is not needed. We should always pass
the vm object unless it does not exist yet.

This fixes a bug when statistics of a completed migration reported
"Unknown" operation instead of "Incoming migration" on the destination
host.

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

Fixes: v8.7.0-79-g0150f7a8c1
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agonode_device_conf: Avoid memleak in virNodeDeviceGetPCIVPDDynamicCap()
Michal Privoznik [Wed, 30 Nov 2022 13:53:21 +0000 (14:53 +0100)]
node_device_conf: Avoid memleak in virNodeDeviceGetPCIVPDDynamicCap()

The virNodeDeviceGetPCIVPDDynamicCap() function is called from
virNodeDeviceGetPCIDynamicCaps() and therefore has to be a wee
bit more clever about adding VPD capability. Namely, it has to
remove the old one before adding a new one. This is how other
functions called from virNodeDeviceGetPCIDynamicCaps() behave
as well.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2143235
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agoFix couple of comment typos
Martin Kletzander [Wed, 30 Nov 2022 11:18:01 +0000 (12:18 +0100)]
Fix couple of comment typos

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2 years agoTranslated using Weblate (Ukrainian) osstest/frozen/xen-4.17-testing
Yuri Chornoivan [Tue, 29 Nov 2022 08:38:49 +0000 (09:38 +0100)]
Translated using Weblate (Ukrainian)

Currently translated at 100.0% (10368 of 10368 strings)

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

Co-authored-by: Yuri Chornoivan <yurchor@ukr.net>
Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
2 years agoTranslated using Weblate (Korean)
김인수 [Tue, 29 Nov 2022 08:38:48 +0000 (09:38 +0100)]
Translated using Weblate (Korean)

Currently translated at 100.0% (10368 of 10368 strings)

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

Co-authored-by: 김인수 <simmon@nplob.com>
Signed-off-by: 김인수 <simmon@nplob.com>
2 years agoUpdate translation files
Weblate [Tue, 29 Nov 2022 08:38:46 +0000 (09:38 +0100)]
Update translation files

Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

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

Co-authored-by: Weblate <noreply@weblate.org>
Signed-off-by: Fedora Weblate Translation <i18n@lists.fedoraproject.org>
2 years agoTranslated using Weblate (Swedish)
Göran Uddeborg [Tue, 29 Nov 2022 08:38:40 +0000 (09:38 +0100)]
Translated using Weblate (Swedish)

Currently translated at 51.8% (5371 of 10368 strings)

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

Translated using Weblate (Swedish)

Currently translated at 51.1% (5316 of 10386 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>
2 years agoselinux: Reflect context_str() type change
Michal Privoznik [Tue, 29 Nov 2022 09:49:07 +0000 (10:49 +0100)]
selinux: Reflect context_str() type change

As of [1]. libselinux changed the type of context_str() - it now
returns a const string. Follow this change in our code base.

1: https://github.com/SELinuxProject/selinux/commit/dd98fa322766760c4e1f029cf19d2515a583304f

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemu_tpm: Check for qemuTPMSetupEncryption() errors
Michal Privoznik [Tue, 22 Nov 2022 11:18:35 +0000 (12:18 +0100)]
qemu_tpm: Check for qemuTPMSetupEncryption() errors

Inside of qemuTPMEmulatorBuildCommand() there are two calls to
qemuTPMSetupEncryption() which simply ignore returned error. This
is suboptimal because then we rely on swtpm binary reporting a
generic error (something among invalid command line arguments)
while an error reported by qemuTPMSetupEncryption() is more
specific.

However, since virCommandSetSendBuffer() only sets an error
inside of virCommand structure (the error is then reported in
virCommandRun()), we need to exempt its retval from error
checking. Thus, the signature of qemuTPMSetupEncryption() is
changed a bit so that -1/0 can be returned to indicate error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoDocument caveats of hypervisor-specific stats in 'VIR_DOMAIN_STATS_VCPU' group
Peter Krempa [Mon, 28 Nov 2022 16:09:23 +0000 (17:09 +0100)]
Document caveats of hypervisor-specific stats in 'VIR_DOMAIN_STATS_VCPU' group

In commit c43718ef67944 I've added a disclaimer that the new stats which
are fetched from qemu and passed directly to the user are not guaranteed
by libvirt. I didn't notice that per-vcpu hypervisor specific stats are
also snuck into the VIR_DOMAIN_STATS_VCPU group along with other
pre-existing stats we do guarantee.

Extend the disclaimer for VIR_DOMAIN_STATS_VCPU too.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoNEWS: Update for 8.10.0
Peter Krempa [Mon, 28 Nov 2022 10:08:18 +0000 (11:08 +0100)]
NEWS: Update for 8.10.0

Mention 'virt-qemu-sev-validate', SGX EPC, vTPM migration, cpu flag
additions and other notable changes in this release.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agopo: Refresh potfile for v8.10.0
Jiri Denemark [Thu, 24 Nov 2022 15:26:09 +0000 (16:26 +0100)]
po: Refresh potfile for v8.10.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2 years agovirnetdevbandwidth: Unbreak tc filter update on Linux-4.20+
Michal Privoznik [Thu, 24 Nov 2022 11:34:56 +0000 (12:34 +0100)]
virnetdevbandwidth: Unbreak tc filter update on Linux-4.20+

Guests are allowed to change their MAC addresses. Subsequently,
we may respond to that with tweaking that part of host side
configuration that depends on it. In this particular case: QoS.

Some parts of QoS are in fact set on corresponding bridge, where
overall view on traffic can be seen. Here, TC filters are used to
place incoming packets into qdiscs. These filters match source
MAC address. Therefore, upon guest changing its MAC address, the
corresponding TC filter needs to be updated too. This is done by
simply removing the old one and instantiating a new one, with new
MAC address.

Now, u32 filters (which we use) use a hash table for matching,
internally. And when deleting the old filter, we used to remove
the hash table (ID = 800::) and let the new filter instantiate
new hash table. This used to work, until kernel release 4.20
(specifically commit v4.20-rc1~27^2~131^2~11 and its friends)
where this practice was turned into error.

But that's okay - we can delete the specific filter we are after
and not touch the hash table at all.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoconf: Make VIR_DOMAIN_NET_TYPE_ETHERNET not share 'host view'
Michal Privoznik [Thu, 24 Nov 2022 09:28:59 +0000 (10:28 +0100)]
conf: Make VIR_DOMAIN_NET_TYPE_ETHERNET not share 'host view'

When setting up QoS for a domain <interface/>, or when reporting
its statistics we may need to swap TX/RX values. This is all
explained in comment to virDomainNetTypeSharesHostView().
However, this function claims that VIR_DOMAIN_NET_TYPE_ETHERNET
also shares the 'host view', meaning the TX/RX values must be
swapped. But that's not true.

An easy reproducer is to start a domain with two <interface/>-s:
one type of network, the other of type ethernet and configure the
same <bandwidth/> for both. Reversed setting can then be observed
(e.g. via tc).

Reported-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agovirsh: Report iSCSI-direct backend in long version
Michal Privoznik [Thu, 24 Nov 2022 07:52:25 +0000 (08:52 +0100)]
virsh: Report iSCSI-direct backend in long version

We already report whether iSCSI backend was enabled at compile
time, but we don't do the same with iSCSI-direct backend.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agovirsh: Format -V output properly
Michal Privoznik [Thu, 24 Nov 2022 07:50:41 +0000 (08:50 +0100)]
virsh: Format -V output properly

When displaying long version (virsh -V), the 'Virtuozzo Storage'
substring lacks leading space and thus produces awful output.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2 years agoTranslated using Weblate (Swedish)
Göran Uddeborg [Wed, 23 Nov 2022 09:20:02 +0000 (10:20 +0100)]
Translated using Weblate (Swedish)

Currently translated at 50.9% (5296 of 10386 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>
2 years agorpc: Mark close callback (un-)register as high priority
Michal Privoznik [Wed, 23 Nov 2022 08:50:29 +0000 (09:50 +0100)]
rpc: Mark close callback (un-)register as high priority

Our RPC calls can be divided into two groups: regular and high
priority. The latter can be then processed by so called high
priority worker threads. This is our way of defeating a
'deadlock' and allowing some RPCs to be processed even when all
(regular) worker threads are stuck. For instance: if all regular
worker threads get stuck when talking to QEMU on monitor, the
virDomainDestroy() can be processed by a high priority worker
thread(s) and thus unstuck those threads.

Now, this is all fine, except if users want to use virsh
non interactively:

  virsh destroy $dom

This does a bit more - it needs to open a connection. And that
consists of multiple RPC calls: AUTH_LIST,
CONNECT_SUPPORTS_FEATURE, CONNECT_OPEN, and finally
CONNECT_REGISTER_CLOSE_CALLBACK. All of them are marked as high
priority except the last one. Therefore, virsh just sits there
with a partially open connection.

There's one requirement for high priority calls though: they can
not get stuck. Hopefully, the reason is obvious by now. And
looking into the server side implementation the
CONNECT_REGISTER_CLOSE_CALLBACK processing can't ever get stuck.
The only driver that implements the callback for public API is
Parallels (vz). And that can't block really.

And for virConnectUnregisterCloseCallback() it's the same story.

Therefore, both can be marked as high priority.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2143840
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2 years agokbase: virtiofs: Add 'queue' setting to example
Lu Ke [Mon, 14 Nov 2022 15:00:09 +0000 (15:00 +0000)]
kbase: virtiofs: Add 'queue' setting to example
The setting is needed for the windows driver to work properly and doesn't have negative effects on other usage.
Signed-off-by: Lukas Ke nicelukas@hotmail.com
2 years agolib: Use the same style in the 'struct option'
Jiang Jiacheng [Tue, 22 Nov 2022 01:50:01 +0000 (09:50 +0800)]
lib: Use the same style in the 'struct option'

Use same style in the 'struct option' as:
    struct option opt[] = {
        { a, b },
        { a, b },
        ...
        { a, b },
    };

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agoapparmor: allow getattr on usb devices
Christian Ehrhardt [Thu, 17 Nov 2022 08:35:05 +0000 (09:35 +0100)]
apparmor: allow getattr on usb devices

For the handling of usb we already allow plenty of read access,
but so far /sys/bus/usb/devices only needed read access to the directory
to enumerate the symlinks in there that point to the actual entries via
relative links to ../../../devices/.

But in more recent systemd with updated libraries a program might do
getattr calls on those symlinks. And while symlinks in apparmor usually
do not matter, as it is the effective target of an access that has to be
allowed, here the getattr calls are on the links themselves.

On USB hostdev usage that causes a set of denials like:
 apparmor="DENIED" operation="getattr" class="file"
 name="/sys/bus/usb/devices/usb1" comm="qemu-system-x86"
 requested_mask="r" denied_mask="r" ...

It is safe to read the links, therefore add a rule to allow it to
the block of rules that covers the usb related access.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Reviewed-by: Michal Privoznik <mprivozn at redhat.com>
2 years agoqemu: fix memlock without vIOMMU
Jonathon Jongsma [Thu, 17 Nov 2022 18:15:23 +0000 (12:15 -0600)]
qemu: fix memlock without vIOMMU

When there is no vIOMMU, vfio devices don't need to lock the entire guest
memory per-device, but they still need to lock the entire guest memory to
share between all vfio devices. This memory accounting is not shared
with vDPA devices, so it should be added to the memlock limit separately.

Commit 8d5704e2 added support for multiple vfio/vdpa devices but
calculated the limits incorrectly when there were both vdpa and vfio
devices and no vIOMMU. In this case, the memory lock limit was not
increased separately for the vfio devices.

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2 years agoqemu: Ignore failure in post-copy migration when QEMU says completed
Jiri Denemark [Fri, 18 Nov 2022 15:19:33 +0000 (16:19 +0100)]
qemu: Ignore failure in post-copy migration when QEMU says completed

When post-copy migration is running in Finish phase we already did
everything needed and we're just waiting for all the memory to transfer
to the destination. The domain is already running on there at this
point. Once all data is transferred (QEMU sends a MIGRATION completed
event) we're done. So in this specific post-copy case the source does
not need to care about the result of the Finish call as long as QEMU
says migration completed. The Finish call to the destination daemon may
fail for reasons that do not affect QEMU, e.g., libvirt daemon was
restarted there or the libvirt connection broke.

Currently we just mark the post-copy migration as failed on the source
and keep the domain paused there. But when libvirt daemon is restarted
at this point, it will detect migration finished successfully and kill
the domain as migrated. It make sense to do this even without having to
restart the daemon.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/338
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agoqemu: Always restore post-copy migration job on reconnect
Jiri Denemark [Fri, 18 Nov 2022 15:19:16 +0000 (16:19 +0100)]
qemu: Always restore post-copy migration job on reconnect

We need the restored job even in case the migration already finished
even though we will stop it just a few lines below as the functions we
call in between require an existing migration job.

This fixes a crash on reconnect when post-copy migration finished while
the daemon was not running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2 years agovirmockstathelpers: Load aliases for 64-bit time
Michal Privoznik [Fri, 18 Nov 2022 16:13:22 +0000 (17:13 +0100)]
virmockstathelpers: Load aliases for 64-bit time

On 32-bit arches, it's possible not only to request
-D_FILE_OFFSET_BITS=64 (which is always done with meson) but also
-D_TIME_BITS=64. With glibc, both of these affect what variant of
stat() or lstat() is called. With 64 bit time it's:
__stat64_time64() or __lstat64_time64(), respectively.

Fortunately, no other variant (__xstat(), __xstat64()) has
_time64 alternative and thus does not need similar treatment.

Similarly, musl is not affected by this.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/404
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agotests: Drop needless virrandom mock from two tests
Michal Privoznik [Mon, 21 Nov 2022 11:40:21 +0000 (12:40 +0100)]
tests: Drop needless virrandom mock from two tests

Nothing in virnettlscontexttest nor virnettlssessiontest calls
any of random number generator functions overridden
virrandommock. GnuTLS handles RNG within itself.

Therefore, there's no need to preload the mock.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2 years agoqemucapabilitiesdata: Update caps for qemu-7.2.0 rc1 on x86_64
Peter Krempa [Fri, 11 Nov 2022 08:45:12 +0000 (09:45 +0100)]
qemucapabilitiesdata: Update caps for qemu-7.2.0 rc1 on x86_64

Update to v7.2.0-rc1

Notable changes:
 - 'virtio-blk-vfio-pci' blockdev backend added
 - 'cryptodev-backend-lkcf' object added
 - new options/parameters for virtio-*-pci, virtio-*-device, and
   vhost-user-* devices:
    - 'queue_reset'
     - use-started
     - use-disabled-flags
 - 'dma-translation' option for 'intel-iommu' device
 - 'zpcii-disable' commandline parameter removed (not applicable on x86)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2 years agocpu_arm: fix the compile warning of unexpected format
Jiang Jiacheng [Thu, 17 Nov 2022 02:11:03 +0000 (10:11 +0800)]
cpu_arm: fix the compile warning of unexpected format

These format are left unchanged when convert 'unsigned long' to
'unsigned long long', which caused compile warning.

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2 years agoTranslated using Weblate (Swedish)
Göran Uddeborg [Thu, 17 Nov 2022 07:30:41 +0000 (08:30 +0100)]
Translated using Weblate (Swedish)

Currently translated at 49.8% (5177 of 10386 strings)

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

Translated using Weblate (Swedish)

Currently translated at 49.6% (5157 of 10386 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>