]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
3 years agoqemuxml2argvtest: Remove 'debug-threads' case
Peter Krempa [Tue, 10 Aug 2021 15:04:17 +0000 (17:04 +0200)] 
qemuxml2argvtest: Remove 'debug-threads' case

The test is now pointless since we always assume that this option is
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Add alternative detection of QEMU_CAPS_NUMA
Peter Krempa [Tue, 10 Aug 2021 14:28:15 +0000 (16:28 +0200)] 
qemu: capabilities: Add alternative detection of QEMU_CAPS_NUMA

'set-numa-node' is the command which can set the equivalent parameters
to '-numa' in preconfig mode, so we can use it as witness to see that
-numa is supported.

To ensure that the old detection method is removed once we'll be bumping
qemu support add a comment with the appropriate version check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorSetBlockIoThrottle: Remove booleans controlling used fields
Peter Krempa [Tue, 10 Aug 2021 13:27:29 +0000 (15:27 +0200)] 
qemuMonitorSetBlockIoThrottle: Remove booleans controlling used fields

All supported QEMU versions have all the fields so we can remove the
booleans controlling which fields are used on the monitor.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONSetBlockIoThrottle: Switch to standard error reporting
Peter Krempa [Tue, 10 Aug 2021 13:14:08 +0000 (15:14 +0200)] 
qemuMonitorJSONSetBlockIoThrottle: Switch to standard error reporting

Use qemuMonitorJSONCheckError instead of handcrafted error reporting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONSetBlockIoThrottle: Refactor cleanup
Peter Krempa [Tue, 10 Aug 2021 13:12:14 +0000 (15:12 +0200)] 
qemuMonitorJSONSetBlockIoThrottle: Refactor cleanup

Switch to automatic memory freeing and remove the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilties: Retire QEMU_CAPS_DRIVE_IOTUNE_* caps
Peter Krempa [Tue, 10 Aug 2021 13:00:42 +0000 (15:00 +0200)] 
qemu: capabilties: Retire QEMU_CAPS_DRIVE_IOTUNE_* caps

They are no longer used as we now assume that all tuning caps are
present and in case some will be removed we'll need to use different
probing methods.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Always assume that qemu supports drive throttling
Peter Krempa [Tue, 10 Aug 2021 12:56:31 +0000 (14:56 +0200)] 
qemu: Always assume that qemu supports drive throttling

All currently supported qemu versions support all throttling
capabilities. It is unlikely that any of the fields will be removed in
the future and if it will we will need to do specific probing which is
possible via the 'throttle' object which is the replacement for the
legacy way to configure throttling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Probe QEMU_CAPS_SMP_DIES from the QMP schema
Peter Krempa [Mon, 26 Jul 2021 12:03:07 +0000 (14:03 +0200)] 
qemu: capabilities: Probe QEMU_CAPS_SMP_DIES from the QMP schema

The configurability of the number of dies in a CPU can be inferred from
the presence of the 'die-id' field in 'query-hotpluggable-cpus'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Probe 'discard' and 'detect-zeroes' from 'blockdev-add'
Peter Krempa [Mon, 26 Jul 2021 12:03:07 +0000 (14:03 +0200)] 
qemu: capabilities: Probe 'discard' and 'detect-zeroes' from 'blockdev-add'

Probing QEMU_CAPS_DRIVE_DISCARD and QEMU_CAPS_DRIVE_DETECT_ZEROES can be
replaced by looking into the QMP schema rather than looking at -drive
which isn't in use any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Rename QEMU_CAPS_CHARDEV_FD_PASS to QEMU_CAPS_CHARDEV_FD_PASS_COM...
Peter Krempa [Mon, 26 Jul 2021 12:31:45 +0000 (14:31 +0200)] 
qemu: capabilities: Rename QEMU_CAPS_CHARDEV_FD_PASS to QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE

Make it more obvious that we care about passing FDs on the commandline
before startup of qemu, which is used to avoid startup monitor polling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Probe 'reconnect', 'logfile' and 'append' from 'chardev-add'
Peter Krempa [Mon, 26 Jul 2021 12:03:07 +0000 (14:03 +0200)] 
qemu: capabilities: Probe 'reconnect', 'logfile' and 'append' from 'chardev-add'

QEMU_CAPS_CHARDEV_RECONNECT, QEMU_CAPS_CHARDEV_LOGFILE and
QEMU_CAPS_CHARDEV_FILE_APPEND can be probed from the appropriate fields
in 'chardev-add' probed via the QMP schema instead of the command line
parameters.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Note that basing probing on 'query-command-line-options' should...
Peter Krempa [Mon, 26 Jul 2021 12:01:15 +0000 (14:01 +0200)] 
qemu: capabilities: Note that basing probing on 'query-command-line-options' should be avoided

Add a comment that will attempt to discourage adding new capabilities
based on 'query-command-line-options'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoscripts: group-qemu-caps: Add capability name as comment to capability string
Peter Krempa [Tue, 27 Jul 2021 11:14:51 +0000 (13:14 +0200)] 
scripts: group-qemu-caps: Add capability name as comment to capability string

Add a cross reference of the enum value name with the string
representation. This allows a quick cross-reference of the values
without having to open the header and implementation files separately.

To achieve this the checker code at first obtains a list of the
flags and cross-references them when checking the grouping in
syntax-check, thus we are guaranteed to stay in sync.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUCapsQMPSchemaQueries: Group by queried object name
Peter Krempa [Fri, 6 Aug 2021 12:02:56 +0000 (14:02 +0200)] 
virQEMUCapsQMPSchemaQueries: Group by queried object name

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUCapsCommandLine: Group by commandline argument name alphabetically
Peter Krempa [Fri, 6 Aug 2021 07:43:47 +0000 (09:43 +0200)] 
virQEMUCapsCommandLine: Group by commandline argument name alphabetically

Further commits will be refactoring and minimizing capabilities being
parsed from 'query-command-line-options'. Group the struct driving the
detection by argument name so it's easier to spot options belonging
together.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Remove negative tests for (aes|dea)keywrap (s390) property
Peter Krempa [Thu, 22 Jul 2021 08:27:11 +0000 (10:27 +0200)] 
qemuxml2argvtest: Remove negative tests for (aes|dea)keywrap (s390) property

Upcoming commit will always add the property so the negative tests would
stop working.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoRemove redundant labels
Ján Tomko [Tue, 17 Aug 2021 10:17:31 +0000 (12:17 +0200)] 
Remove redundant labels

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoUse g_autofree in affected functions
Ján Tomko [Tue, 17 Aug 2021 10:21:56 +0000 (12:21 +0200)] 
Use g_autofree in affected functions

Add g_autofree to functions changed in previous commits doing
g_auto cleanup for libxml2-related variables, where it could
lead to removal of a label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoUse g_auto for xmlFreeDoc everywhere
Ján Tomko [Wed, 11 Aug 2021 11:57:18 +0000 (13:57 +0200)] 
Use g_auto for xmlFreeDoc everywhere

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoUse g_auto for xmlXPathContext everywhere
Ján Tomko [Wed, 11 Aug 2021 11:30:26 +0000 (13:30 +0200)] 
Use g_auto for xmlXPathContext everywhere

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoconf: refactor virNetworkLoadState
Ján Tomko [Tue, 17 Aug 2021 10:45:13 +0000 (12:45 +0200)] 
conf: refactor virNetworkLoadState

Use g_auto where possible, reducing variable scope where applicable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoconf: virCPUDefListParse: reduce scope of variables
Ján Tomko [Wed, 11 Aug 2021 11:31:32 +0000 (13:31 +0200)] 
conf: virCPUDefListParse: reduce scope of variables

Move 'ctxt' and 'doc' inside the loop and mark them with g_auto.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agovircgroup: fix build on non-linux systems
Pavel Hrdina [Tue, 17 Aug 2021 12:44:44 +0000 (14:44 +0200)] 
vircgroup: fix build on non-linux systems

virCgroupGetInode needs to be in '#ifdef __linux__'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: implement support for Fibre Channel VMID
Pavel Hrdina [Mon, 2 Aug 2021 18:26:57 +0000 (20:26 +0200)] 
qemu: implement support for Fibre Channel VMID

Based on kernel commit messages the interface is

    /sys/class/fc/fc_udev_device/appid_store

where we need to write the following string "$INODE:$APPID".

$INODE is the VM root cgroup inode in hexadecimal and $APPID is user
provided string that will be attached to each FC frame for the VM
within the cgroup identified by inode and has limit 128 bytes.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agoconf: introduce support for Fibre Channel VMID
Pavel Hrdina [Thu, 5 Aug 2021 13:43:58 +0000 (15:43 +0200)] 
conf: introduce support for Fibre Channel VMID

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agoconf: refactor virDomainResourceDefFormat
Pavel Hrdina [Thu, 5 Aug 2021 13:29:45 +0000 (15:29 +0200)] 
conf: refactor virDomainResourceDefFormat

Prepare the function for additional sub-elements where all of the
sub-elements are optional.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agoconf: refactor virDomainResourceDefParse
Pavel Hrdina [Thu, 5 Aug 2021 13:27:17 +0000 (15:27 +0200)] 
conf: refactor virDomainResourceDefParse

There is no need to error out for empty <partition></partition> element
as we can just simply ignore it. This allows to simplify the function
and prepare it for new sub-elements of <resource>.

It makes the <partition> element optional so we need to reflect the
change in schema as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agovircgroup: introduce virCgroupGetInode function
Pavel Hrdina [Thu, 29 Jul 2021 15:13:39 +0000 (17:13 +0200)] 
vircgroup: introduce virCgroupGetInode function

For new feature Fibre Channel VMID we will need to get inode of the
VM root cgroup as it is used in the new kernel API together with VMID.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agosecurity: fix use-after-free in virSecuritySELinuxReserveLabel
Zhenyu Ye [Tue, 17 Aug 2021 02:55:24 +0000 (10:55 +0800)] 
security: fix use-after-free in virSecuritySELinuxReserveLabel

commit 2e668a61d5ae4("Fix error handling when adding MCS labels") uses
the 'pctx' in virReportError after it has been freed. Fix it.

Fixes: 2e668a61d5ae4cbd6f79e096d0c394f186e132bd
Signed-off-by: Zhenyu Ye <yezhenyu2@huawei.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agovmx: Support super wide SCSI bus
Michal Privoznik [Thu, 29 Jul 2021 14:09:58 +0000 (16:09 +0200)] 
vmx: Support super wide SCSI bus

Since its 6.7 release, vSphere allows up to 64 units on a SCSI
bus [1]. The release version translates to virtualHW_version 13
and thus if we are dealing with sufficiently new version we can
enable the feature.

1: https://configmax.vmware.com/guest?vmwareproduct=vSphere&release=vSphere%206.7&categories=1-0

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1738392
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoconf: Store SCSI bus length in virDomainDef
Michal Privoznik [Tue, 3 Aug 2021 09:00:48 +0000 (11:00 +0200)] 
conf: Store SCSI bus length in virDomainDef

Libvirt assumes that a SCSI bus can fit up to 8 devices
(including controller itself), except for so called wide bus
which can accommodate up to 16 devices (again, including
controller). This plays important role when computing 'drive'
address in virDomainDiskDefAssignAddress(). So far, the only
driver that enables wide SCSI bus is VMX. But with newer
releases, ESX is capable of "super wide" bus (64 devices).

We can blindly bump the limit in our code because then we would
compute address that's invalid for older ESX versions that we
still want to support.

Unfortunately, I haven't found a better place where to store this
than virDomainDef.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovmx: Drop needless check in virVMXParseDisk()
Michal Privoznik [Thu, 29 Jul 2021 13:41:51 +0000 (15:41 +0200)] 
vmx: Drop needless check in virVMXParseDisk()

After previous patch it can no longer happen that @def will be
NULL and *def won't be.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovmx: Rework disk def allocation
Michal Privoznik [Thu, 29 Jul 2021 13:39:08 +0000 (15:39 +0200)] 
vmx: Rework disk def allocation

The way we parse VMX configuration is rather unfortunate,
especially when it comes to disks. We allocate an array that can
handle all possible disks but leave the array counter (ndisks) at
zero and increase it only after successful parsing. But, we never
size the array down to release unneeded chunks of memory.

We can do better: we can use VIR_APPEND_ELEMENT() to allocate
array as needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovmx2xmltest: Add a test case
Michal Privoznik [Thu, 29 Jul 2021 13:38:59 +0000 (15:38 +0200)] 
vmx2xmltest: Add a test case

This is an attachment from the following bug:

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

Notice that .vmx file has two scsi disks, but only one is
reported in the XML. This will be fixed later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovmx: Fill virtualHW.version to ESX version mapping
Michal Privoznik [Fri, 30 Jul 2021 09:06:04 +0000 (11:06 +0200)] 
vmx: Fill virtualHW.version to ESX version mapping

At the beginning of vmx.c we have a comment that maps
virtualHW.version field onto ESX version. However, it wasn't
updated in a while. Fill it in using the following kbase article:

  https://kb.vmware.com/s/article/1003746

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotools: virsh: remove redundant labels
Ján Tomko [Thu, 12 Aug 2021 07:59:20 +0000 (09:59 +0200)] 
tools: virsh: remove redundant labels

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use g_autofree
Ján Tomko [Wed, 11 Aug 2021 13:25:15 +0000 (15:25 +0200)] 
tools: virsh: use g_autofree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for char **
Ján Tomko [Wed, 11 Aug 2021 13:45:02 +0000 (15:45 +0200)] 
tools: virsh: use automatic cleanup for char **

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: reduce variable scope to use automatic cleanup
Ján Tomko [Wed, 11 Aug 2021 13:25:20 +0000 (15:25 +0200)] 
tools: virsh: reduce variable scope to use automatic cleanup

Some variables are used in a loop and only freed in the cleanup
section because we need to be able to jump out of the loop.

Reduce their scope and free them automatically.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for vshTable
Ján Tomko [Wed, 11 Aug 2021 13:12:02 +0000 (15:12 +0200)] 
tools: virsh: use automatic cleanup for vshTable

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for xmlDoc
Ján Tomko [Wed, 11 Aug 2021 11:57:15 +0000 (13:57 +0200)] 
tools: virsh: use automatic cleanup for xmlDoc

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for xmlXPathObject
Ján Tomko [Wed, 11 Aug 2021 11:50:23 +0000 (13:50 +0200)] 
tools: virsh: use automatic cleanup for xmlXPathObject

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for xmlXPathContext
Ján Tomko [Wed, 11 Aug 2021 11:21:18 +0000 (13:21 +0200)] 
tools: virsh: use automatic cleanup for xmlXPathContext

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: use automatic cleanup for virDomainObj
Ján Tomko [Wed, 11 Aug 2021 09:33:50 +0000 (11:33 +0200)] 
tools: virsh: use automatic cleanup for virDomainObj

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: cmdDominfo: rename 'ostype' variable
Ján Tomko [Wed, 11 Aug 2021 14:16:39 +0000 (16:16 +0200)] 
tools: virsh: cmdDominfo: rename 'ostype' variable

Use 'ostype' instead of generic 'str', to discourage
reuse. Also mark it as autofree.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agotools: virsh: split variable declarations
Ján Tomko [Wed, 11 Aug 2021 13:45:59 +0000 (15:45 +0200)] 
tools: virsh: split variable declarations

One variable per line.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agoqemu: Open chardev logfile on behalf of QEMU
Michal Privoznik [Fri, 6 Aug 2021 08:25:29 +0000 (10:25 +0200)] 
qemu: Open chardev logfile on behalf of QEMU

If the QEMU driver is configured to use the old "file" stdio
handler (meaning virtlogd is out of the picture) and a chardev
has a log file configured we rely on QEMU being able to create
the file itself. This may not be always possible (e.g. if the
logfile is set to a directory that QEMU process can't reach).
In such case we should create the file and just pass its FD to
QEMU.

We could do that unconditionally and just either pass FD from
virtlogd or the one we opened, because we bumped QEMU version
and are now requiring new enough QEMU. However, I'm keeping the
old style where logfile is appended on the cmd line for the tests
sake.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1989457
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDomainOpenFile: Take @cfg instead of driver
Michal Privoznik [Fri, 6 Aug 2021 08:48:50 +0000 (10:48 +0200)] 
qemuDomainOpenFile: Take @cfg instead of driver

Again, we don't need full driver, just its config.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDomainOpenFile: Take virDomainDef instead of virDomainObj
Michal Privoznik [Fri, 6 Aug 2021 08:31:22 +0000 (10:31 +0200)] 
qemuDomainOpenFile: Take virDomainDef instead of virDomainObj

The function doesn't really need domain object, but domain
definition from which it takes seclabels.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
3 years agovirDomainDefGetSecurityLabelDef: Fix const correctness
Michal Privoznik [Fri, 6 Aug 2021 08:30:59 +0000 (10:30 +0200)] 
virDomainDefGetSecurityLabelDef: Fix const correctness

The function doesn't write to domain definition really so make
@def argument as const. This allows us to call it from functions
where the domain definition is already const.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
3 years agolibxl: remove conditionals from discard configuration
Olaf Hering [Fri, 13 Aug 2021 14:03:11 +0000 (16:03 +0200)] 
libxl: remove conditionals from discard configuration

LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE exists since Xen 4.5.0

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
3 years agoutil: xml: clean up unnecessary ret variables
Ján Tomko [Wed, 11 Aug 2021 12:05:42 +0000 (14:05 +0200)] 
util: xml: clean up unnecessary ret variables

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoutil: xml: use g_auto for xmlXPathObject
Ján Tomko [Wed, 11 Aug 2021 11:48:13 +0000 (13:48 +0200)] 
util: xml: use g_auto for xmlXPathObject

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoutil: define cleanup func for xmlXPathObject
Ján Tomko [Wed, 11 Aug 2021 11:34:32 +0000 (13:34 +0200)] 
util: define cleanup func for xmlXPathObject

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoconf: replace validation with variables passed to virXMLParse()
Kristina Hanicova [Wed, 11 Aug 2021 12:36:48 +0000 (14:36 +0200)] 
conf: replace validation with variables passed to virXMLParse()

virXMLParse() now allows validating xml against schema directly,
eliminating the need to do it individually in each function.

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>
3 years agodomain_conf: Remove redundant variable
Kristina Hanicova [Wed, 11 Aug 2021 12:36:47 +0000 (14:36 +0200)] 
domain_conf: Remove redundant variable

xmlDocPtr is no longer needed, because validation against schema
was moved to another function.

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>
3 years agodomain_conf: replace validation with variables passed to virXMLParse()
Kristina Hanicova [Wed, 11 Aug 2021 12:36:46 +0000 (14:36 +0200)] 
domain_conf: replace validation with variables passed to virXMLParse()

virXMLParse() now allows to validate xml against schema directly,
eliminating the need to do it individually.

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>
3 years agoutil: add xml validation against schema in virXMLParseHelper()
Kristina Hanicova [Wed, 11 Aug 2021 12:36:45 +0000 (14:36 +0200)] 
util: add xml validation against schema in virXMLParseHelper()

We need this in order to validate XML against schema at one
place, rather than have the same code for validation in different
functions.
I will add '--validate' option to more virsh commands soon and
this makes it easier as virXMLParse() is called in every one I
plan to change.

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>
3 years agosrc: add 'schema' and 'validate' variable to virXMLParseHelper()
Kristina Hanicova [Wed, 11 Aug 2021 12:36:44 +0000 (14:36 +0200)] 
src: add 'schema' and 'validate' variable to virXMLParseHelper()

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>
3 years agovsh: steal pointer in vshEditWriteToTempFile
Ján Tomko [Thu, 12 Aug 2021 09:45:03 +0000 (11:45 +0200)] 
vsh: steal pointer in vshEditWriteToTempFile

Fixes: 13896b5ad1d7f157273b6e49106df1f33958a9ed
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3 years agovirsh: refactor cmdDomblkinfo
Ján Tomko [Wed, 11 Aug 2021 14:04:45 +0000 (16:04 +0200)] 
virsh: refactor cmdDomblkinfo

Use automatic memory cleanup to get rid of the cleanup section,
and of the memory leak that happens inside the loop, because
cap, alloc and phy are only freed once per function.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
3 years agoqemu: save status xml after generating taint message
Kristina Hanicova [Tue, 27 Jul 2021 12:36:00 +0000 (14:36 +0200)] 
qemu: save status xml after generating taint message

We didn't always save status xml after generating new taint message
which resulted in it being deleted in case of a libvirtd restart.
Some taint messages were preserved thanks to saving status xml
separately at the end of the calling functions. With this, every taint
message is saved, regardless of the calling functions.

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

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agorun: set abs_builddir variables
Ján Tomko [Wed, 11 Aug 2021 07:41:02 +0000 (09:41 +0200)] 
run: set abs_builddir variables

test-lib.sh needs these to be set.

Export them so that the virsh-* tests can be run using:
  builddir$ ./run srcdir/tests/virsh-snapshot

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirsh: snapshot: remove pointless cleanup labels
Ján Tomko [Tue, 10 Aug 2021 16:18:40 +0000 (18:18 +0200)] 
virsh: snapshot: remove pointless cleanup labels

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: snapshot: use g_auto where possible
Ján Tomko [Tue, 10 Aug 2021 15:57:15 +0000 (17:57 +0200)] 
virsh: snapshot: use g_auto where possible

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: checkpoint: remove pointless cleanup labels
Ján Tomko [Tue, 10 Aug 2021 15:47:59 +0000 (17:47 +0200)] 
virsh: checkpoint: remove pointless cleanup labels

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: checkpoint: use g_auto where possible
Ján Tomko [Tue, 10 Aug 2021 15:07:38 +0000 (17:07 +0200)] 
virsh: checkpoint: use g_auto where possible

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: cmdCheckpointInfo: delete unused variables
Ján Tomko [Tue, 10 Aug 2021 15:38:49 +0000 (17:38 +0200)] 
virsh: cmdCheckpointInfo: delete unused variables

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: snapshot: move variables inside the loop
Ján Tomko [Tue, 10 Aug 2021 17:20:30 +0000 (19:20 +0200)] 
virsh: snapshot: move variables inside the loop

Use g_auto to free them, instead of open-coding it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: checkpoint: move variables inside the loop
Ján Tomko [Tue, 10 Aug 2021 17:26:45 +0000 (19:26 +0200)] 
virsh: checkpoint: move variables inside the loop

Use g_auto to free them instead of open-coding it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: add cleanup function for virshDomainSnapshot
Ján Tomko [Tue, 10 Aug 2021 15:15:49 +0000 (17:15 +0200)] 
virsh: add cleanup function for virshDomainSnapshot

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovirsh: add cleanup function for virshDomainCheckpoint
Ján Tomko [Tue, 10 Aug 2021 15:15:40 +0000 (17:15 +0200)] 
virsh: add cleanup function for virshDomainCheckpoint

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: table: define cleanup function
Ján Tomko [Tue, 10 Aug 2021 17:28:03 +0000 (19:28 +0200)] 
vsh: table: define cleanup function

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: use g_clear_pointer
Ján Tomko [Tue, 10 Aug 2021 15:09:30 +0000 (17:09 +0200)] 
vsh: use g_clear_pointer

Replace remaining uses of VIR_FREE with g_clear_pointer.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: remove pointless cleanup labels
Ján Tomko [Tue, 10 Aug 2021 15:12:02 +0000 (17:12 +0200)] 
vsh: remove pointless cleanup labels

Remove cleanup sections that are no longer needed, as well
as unnecessary 'ret' variables.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: use g_auto where possible
Ján Tomko [Tue, 10 Aug 2021 15:09:07 +0000 (17:09 +0200)] 
vsh: use g_auto where possible

Excluding vshCommandParse.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: cmdEcho: use separate variable for argument
Ján Tomko [Tue, 10 Aug 2021 15:10:34 +0000 (17:10 +0200)] 
vsh: cmdEcho: use separate variable for argument

Do not use 'arg' which is later used for an allocated string.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agovsh: do not cast away const
Ján Tomko [Tue, 10 Aug 2021 16:56:18 +0000 (18:56 +0200)] 
vsh: do not cast away const

Instead of using the same variable to store either a const pointer
or an allocated string, always make a copy.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agomeson: Always use the / operator to join paths
Andrea Bolognani [Tue, 10 Aug 2021 14:46:07 +0000 (16:46 +0200)] 
meson: Always use the / operator to join paths

This is the preferred way to do it, but there were a few
instances in which some of the path components had embedded
slashes instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agomeson: Use 'rst2html5' instead of 'rst2html' everywhere
Andrea Bolognani [Mon, 9 Aug 2021 14:48:58 +0000 (16:48 +0200)] 
meson: Use 'rst2html5' instead of 'rst2html' everywhere

We only use the HTML5 version these days.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agodomain_conf: Fix memory leak when free'ing virDomainObj
Luke Yue [Tue, 10 Aug 2021 13:47:21 +0000 (21:47 +0800)] 
domain_conf: Fix memory leak when free'ing virDomainObj

Free dom->deprecations when free'ing virDomainObj

Signed-off-by: Luke Yue <lukedyue@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3 years agoutil: virstring: Remove unused virStringListFreeCount
Peter Krempa [Wed, 4 Aug 2021 11:30:39 +0000 (13:30 +0200)] 
util: virstring: Remove unused virStringListFreeCount

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agolxcContainerSetReadOnly: Refactor cleanup handling
Peter Krempa [Tue, 3 Aug 2021 13:46:46 +0000 (15:46 +0200)] 
lxcContainerSetReadOnly: Refactor cleanup handling

Turn 'mounts' into a proper GStrv after sorting so that automatic
cleanup can be used and shuffle around the cleanup steps so that jumps
can be avoided in favor of direct return of error code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDomainUnshareNamespace: Use automatic memory clearing for string lists
Peter Krempa [Tue, 3 Aug 2021 11:01:04 +0000 (13:01 +0200)] 
qemuDomainUnshareNamespace: Use automatic memory clearing for string lists

'devMountsPath' and 'devMountsSavePath' are NULL terminated.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuNamespaceMknodPaths: Remove 'ndevMountsPath'
Peter Krempa [Tue, 3 Aug 2021 10:45:37 +0000 (12:45 +0200)] 
qemuNamespaceMknodPaths: Remove 'ndevMountsPath'

'devMountsPath' can be converted to an auto-cleared stringlist and thus
asking for the number of entries is not necessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuNamespacePrepareOneItem: Don't pass count of elements
Peter Krempa [Tue, 3 Aug 2021 10:43:19 +0000 (12:43 +0200)] 
qemuNamespacePrepareOneItem: Don't pass count of elements

The only caller is passing a NULL terminated string list as
'devMountsPath' thus we don't need to get the count of elements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuNamespacePrepareOneItem: Restructure code to avoid temporary variables
Peter Krempa [Thu, 5 Aug 2021 15:00:45 +0000 (17:00 +0200)] 
qemuNamespacePrepareOneItem: Restructure code to avoid temporary variables

The value of 'next' is copied into 'item.file' so we can move the update
to the 'next' pointer earlier and move the VIR_APPEND_ELEMENT call to
where we figure out that we need to append the value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agonetwork: bridge: Store dnsmasq passthrough options in NULL-terminated string list
Peter Krempa [Mon, 21 Jun 2021 12:54:24 +0000 (14:54 +0200)] 
network: bridge: Store dnsmasq passthrough options in NULL-terminated string list

We always process the full list so there's no value in storing the count
separately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Store passthrough arguments in NULL-terminated string list
Peter Krempa [Mon, 21 Jun 2021 12:54:24 +0000 (14:54 +0200)] 
qemu: domain: Store passthrough arguments in NULL-terminated string list

We always process the full list so there's no value in storing the count
separately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Store capability overrides in NULL-terminated string list
Peter Krempa [Mon, 21 Jun 2021 12:54:24 +0000 (14:54 +0200)] 
qemu: domain: Store capability overrides in NULL-terminated string list

We always process the full list so there's no value in storing the count
separately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Store passthrough environment variables in a struct
Peter Krempa [Mon, 21 Jun 2021 12:43:01 +0000 (14:43 +0200)] 
qemu: domain: Store passthrough environment variables in a struct

Previously they were stored in two separate arrays. This way it's
obvious when referencing the same one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: firmware: Store machine types as a NULL-terminated string list
Peter Krempa [Wed, 16 Jun 2021 07:29:01 +0000 (09:29 +0200)] 
qemu: firmware: Store machine types as a NULL-terminated string list

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoremote: dispatch: Don't use virStringListFreeCount for NULL terminated lists
Peter Krempa [Mon, 14 Jun 2021 12:56:15 +0000 (14:56 +0200)] 
remote: dispatch: Don't use virStringListFreeCount for NULL terminated lists

Both virDomainAuthorizedSSHKeysGet and virDomainGetMessages return a
NULL-terminated string-list, so we can use g_auto(GStrv) to clear the
used memory on failures.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotestQemuAgentSSHKeys: Refactor cleanup
Peter Krempa [Mon, 14 Jun 2021 11:51:17 +0000 (13:51 +0200)] 
testQemuAgentSSHKeys: Refactor cleanup

Use automatic memory freeing for the 'qemuMonitorTest' object and the
list of keys so that the cleanup section can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirNetDevGetVirtualFunctions: Directly return virPCIVirtualFunctionList
Peter Krempa [Wed, 4 Aug 2021 15:37:50 +0000 (17:37 +0200)] 
virNetDevGetVirtualFunctions: Directly return virPCIVirtualFunctionList

Remove the conversion from virPCIVirtualFunctionList which encapsulates
the list of virtual functions to two disjunct arrays.

This greatly simplifies the fetching of the parameters as well as
cleanup in the caller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirPCIGetVirtualFunctions: Fetch also network interface name if needed
Peter Krempa [Wed, 4 Aug 2021 15:37:44 +0000 (17:37 +0200)] 
virPCIGetVirtualFunctions: Fetch also network interface name if needed

'virNetDevGetVirtualFunctions' calls 'virPCIGetVirtualFunctions' and
then re-iterates the returned list to fetch the interface names for the
returned virtual functions.

If we move the fetching of the interface name into
virPCIGetVirtualFunctions we can simplify the code and remove a bunch of
impossible error states.

To accomplish this the function is renamed to
'virPCIGetVirtualFunctionsFull' while keeping a wrapper with original
name and if the physical port ID is passed the interface name is fetched
too without the need to re-convert the address into a sysfs link.

For now 'virNetDevGetVirtualFunctions' still converts the returned data
into two lists.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirPCIGetNetName: Make 'physPortID' argument const
Peter Krempa [Wed, 4 Aug 2021 15:54:42 +0000 (17:54 +0200)] 
virPCIGetNetName: Make 'physPortID' argument const

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirPCIGetVirtualFunctionIndex: Refactor cleanup
Peter Krempa [Wed, 4 Aug 2021 14:35:31 +0000 (16:35 +0200)] 
virPCIGetVirtualFunctionIndex: Refactor cleanup

The 'ret' variable and 'out' label can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirPCIGetVirtualFunctions: Simplify cleanup of returned data
Peter Krempa [Tue, 3 Aug 2021 14:45:36 +0000 (16:45 +0200)] 
virPCIGetVirtualFunctions: Simplify cleanup of returned data

Introduce a struct for holding the list of VFs returned by
virPCIGetVirtualFunctions so that we can employ automatic memory
clearing and also allow querying more information at once.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirNetDevGetVirtualFunctions: Remove 'max_vfs' argument
Peter Krempa [Wed, 4 Aug 2021 15:27:56 +0000 (17:27 +0200)] 
virNetDevGetVirtualFunctions: Remove 'max_vfs' argument

The only caller doesn't use it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>