]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
4 years agoqemu: Move qemuAgentFSInfo array free into qemuDomainGetFSInfo()
Michal Privoznik [Tue, 16 Feb 2021 10:27:56 +0000 (11:27 +0100)]
qemu: Move qemuAgentFSInfo array free into qemuDomainGetFSInfo()

When qemuDomainGetFSInfo() is called it calls
qemuDomainGetFSInfoAgent() which executes 'guest-get-fsinfo'
guest agent command, parses returned JSON and returns an array of
qemuAgentFSInfo structures (well, pointers to those structs).
Then it grabs a domain job and tries to do some matching of guest
returned info against domain definition. This matching is done in
virDomainFSInfoFormat() which also frees the array of
qemuAgentFSInfo structures allocated earlier.

But this is not just. If acquiring the domain job fails (or
domain activeness check executed right after that fails) then
virDomainFSInfoFormat() is not called, leaking the array of
structs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: Drop needless check in virDomainFSInfoFormat()
Michal Privoznik [Mon, 15 Feb 2021 16:13:22 +0000 (17:13 +0100)]
qemu: Drop needless check in virDomainFSInfoFormat()

As the very first thing, this function checks whether the number
of items inside @agentinfo array is not negative. This is
redundant as the only caller - qemuDomainGetFSInfo() already
checked for that and would not even call this function if that
was the case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: use long on|off syntax for -spice boolean option values
Daniel P. Berrangé [Tue, 16 Feb 2021 11:29:24 +0000 (11:29 +0000)]
qemu: use long on|off syntax for -spice boolean option values

The preferred syntax for boolean options is to set the value "on" or
"off". QEMU 7.1.0 will deprecate the short format we currently use.

The long format has been supported with -spice since at least 1.5.3,
so we don't need to check for it.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: use long on|off syntax for -chardev boolean option values
Daniel P. Berrangé [Tue, 16 Feb 2021 11:29:24 +0000 (11:29 +0000)]
qemu: use long on|off syntax for -chardev boolean option values

The preferred syntax for boolean options is to set the value "on" or
"off". QEMU 7.1.0 will deprecate the short format we currently use.

The long format has been supported with -chardev since at least 1.5.3,
so we don't need to check for it.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemuSnapshotFSFreeze: Don't return -2
Peter Krempa [Mon, 15 Feb 2021 17:12:29 +0000 (18:12 +0100)]
qemuSnapshotFSFreeze: Don't return -2

The -2 value is misleading because if 'qemuAgentFSFreeze' fails it
doesn't necessarily mean that the command was sent to the agent.

Since callers don't care about the -2 value specifically, remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuSnapshotCreateActiveExternal: Don't thaw filesystems when freeze fails
Peter Krempa [Mon, 15 Feb 2021 16:52:24 +0000 (17:52 +0100)]
qemuSnapshotCreateActiveExternal: Don't thaw filesystems when freeze fails

If we didn't freeze any filesystems we should not even attempt thawing
them. Additionally 'guest-fsfreeze-freeze' fails if the filesystems are
already frozen, where thawing them may break users data integrity if
they used VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE accidentally after an
explicit virDomainFSFreeze and the next snapshot without that flag would
be taken with already thawed filesystems.

This effectively reverts 7c736bab06479ccec59df69fb79a5c06d112d8fb .
Libvirt nowadays checks whether the guest agent is connected and pings
it before issuing an command so it's very unlikely that we'd end up in a
situation where qemuSnapshotCreateActiveExternal froze filesystems and
didn't thaw them.

Additionally we now discourage the use of
VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE since users have better control if
they freeze the FS themselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoapi: Discourage use of VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE
Peter Krempa [Mon, 15 Feb 2021 16:50:56 +0000 (17:50 +0100)]
api: Discourage use of VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE

The flag creates additional points of failure which are hard to recover
from, such as when thawing of the filesystems fails after an otherwise
successful snapshot.

Encourage use of explicit virDomainFSFreeze/virDomainFSThaw.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agostoragevolxml2argvdata: Rewrap all output files
Peter Krempa [Mon, 8 Feb 2021 09:23:45 +0000 (10:23 +0100)]
storagevolxml2argvdata: Rewrap all output files

Use scripts/test-wrap-argv.py to rewrap the output files so that any
further changes don't introduce churn since we are rewrapping the output
automatically now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agotestutils: virTestRewrapFile: Rewrap also '.argv' files
Peter Krempa [Mon, 8 Feb 2021 09:12:00 +0000 (10:12 +0100)]
testutils: virTestRewrapFile: Rewrap also '.argv' files

The suffix is used for output files of 'storagevolxml2argvtest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemuMigrationSrcPerformPeer2Peer3: Don't leak 'dom_xml' on cleanup
Peter Krempa [Wed, 10 Feb 2021 17:39:11 +0000 (18:39 +0100)]
qemuMigrationSrcPerformPeer2Peer3: Don't leak 'dom_xml' on cleanup

Use g_autofree for 'dom_xml' to free it on some of the (unlikely) code
paths jumping to cleanup prior to the deallocation which is done right
after it's not needed any more since it's a big string.

Noticed when running under valgrind:

==2204780== 8,192 bytes in 1 blocks are definitely lost in loss record 2,539 of 2,551
==2204780==    at 0x483BCE8: realloc (vg_replace_malloc.c:834)
==2204780==    by 0x4D890DF: g_realloc (in /usr/lib64/libglib-2.0.so.0.6600.4)
==2204780==    by 0x4DA3AF0: g_string_append_vprintf (in /usr/lib64/libglib-2.0.so.0.6600.4)
==2204780==    by 0x4917293: virBufferAsprintf (virbuffer.c:307)
==2204780==    by 0x49B0B75: virDomainChrDefFormat (domain_conf.c:26109)
==2204780==    by 0x49E25EF: virDomainDefFormatInternalSetRootName (domain_conf.c:28956)
==2204780==    by 0x15F81D24: qemuDomainDefFormatBufInternal (qemu_domain.c:6204)
==2204780==    by 0x15F8270D: qemuDomainDefFormatXMLInternal (qemu_domain.c:6229)
==2204780==    by 0x15F8270D: qemuDomainDefFormatLive (qemu_domain.c:6279)
==2204780==    by 0x15FD8100: qemuMigrationSrcBeginPhase (qemu_migration.c:2395)
==2204780==    by 0x15FE0F0D: qemuMigrationSrcPerformPeer2Peer3 (qemu_migration.c:4640)
==2204780==    by 0x15FE0F0D: qemuMigrationSrcPerformPeer2Peer (qemu_migration.c:5093)
==2204780==    by 0x15FE0F0D: qemuMigrationSrcPerformJob (qemu_migration.c:5168)
==2204780==    by 0x15FE280E: qemuMigrationSrcPerform (qemu_migration.c:5372)
==2204780==    by 0x15F9BA3D: qemuDomainMigratePerform3Params (qemu_driver.c:11841)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agovirDomainMigrateVersion3Full: Don't set 'cancelled' to the same value
Peter Krempa [Tue, 19 Jan 2021 17:07:04 +0000 (18:07 +0100)]
virDomainMigrateVersion3Full: Don't set 'cancelled' to the same value

It's already initialized to '1'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoci: Build on macOS 11 instead of macOS 10.15
Andrea Bolognani [Mon, 15 Feb 2021 14:13:39 +0000 (15:13 +0100)]
ci: Build on macOS 11 instead of macOS 10.15

macOS builder capacity on Cirrus CI is quite limited, and so we
can't afford to keep the old build job around after adding the
new one like we do for FreeBSD.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoci: Update package list on Cirrus CI
Andrea Bolognani [Mon, 15 Feb 2021 14:29:52 +0000 (15:29 +0100)]
ci: Update package list on Cirrus CI

While pkgng on FreeBSD updates the package list automatically
when it's run, homebrew on macOS doesn't do the same thing, which
can result in stale packages being installed. Explicitly call
'brew update' before 'brew install' to avoid that scenario.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_hotplug: Don't dereference NULL pointer @newb in qemuDomainChangeNet()
Michal Privoznik [Mon, 15 Feb 2021 17:30:41 +0000 (18:30 +0100)]
qemu_hotplug: Don't dereference NULL pointer @newb in qemuDomainChangeNet()

In one of my previous commits I've made an attempt to restore the
noqueue qdisc on a TAP corresponding to domain's <interface/> if
QoS is cleared out. The commit consisted of two almost identical
hunks. In both the pointer is dereferenced. But in one of them,
the pointer to new bandwidth can't be NULL while in the other it
can leading to a crash.

Fixes: d53b09235398c1320ed2f1b45b640823171467ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1919619
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodocs: tlscerts: Fix a few broken links
Ville Skyttä [Sat, 13 Feb 2021 06:36:29 +0000 (08:36 +0200)]
docs: tlscerts: Fix a few broken links

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agovircgroup: correctly free nested virCgroupPtr
Pavel Hrdina [Mon, 15 Feb 2021 17:20:09 +0000 (18:20 +0100)]
vircgroup: correctly free nested virCgroupPtr

Fixes: 184245f53b94fc84f727eb6e8a2aa52df02d69c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoci: Build on FreeBSD 12.2
Andrea Bolognani [Thu, 11 Feb 2021 11:15:45 +0000 (12:15 +0100)]
ci: Build on FreeBSD 12.2

The FreeBSD 12.1 image on Cirrus CI is currently broken, but
that's okay because a FreeBSD 12.2 image is also available and
we'd rather build on the more up-to-date target anyway.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agoci: Refresh Dockerfiles
Andrea Bolognani [Thu, 11 Feb 2021 11:13:48 +0000 (12:13 +0100)]
ci: Refresh Dockerfiles

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agonews: Mention Apple Silicon support
Andrea Bolognani [Mon, 15 Feb 2021 09:58:29 +0000 (10:58 +0100)]
news: Mention Apple Silicon support

After the recent fixes, it's now confirmed to work.

https://gitlab.com/libvirt/libvirt/-/issues/121

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Sat, 13 Feb 2021 09:40:13 +0000 (10:40 +0100)]
Translated using Weblate (Finnish)

Currently translated at 14.6% (1530 of 10451 strings)

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

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agovmware: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:28:04 +0000 (12:28 -0500)]
vmware: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:27:39 +0000 (12:27 -0500)]
util: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:26:30 +0000 (12:26 -0500)]
qemu: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoremote: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:25:52 +0000 (12:25 -0500)]
remote: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoopenvz: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:25:31 +0000 (12:25 -0500)]
openvz: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agolocking: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:24:34 +0000 (12:24 -0500)]
locking: convert VIR_FREE to g_free in other functions that free their arg

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: convert VIR_FREE to g_free in other functions that free their arg
Laine Stump [Tue, 9 Feb 2021 17:20:57 +0000 (12:20 -0500)]
conf: convert VIR_FREE to g_free in other functions that free their arg

Previous patches have converted VIR_FREE to g_free in functions with
names ending in Free() and Dispose(), but there are a few similar
functions with names that don't fit that pattern, but server the same
purpose (and thus can survive the same conversion). in particular
*Free*(), and *Unref().

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoesx: replace VIR_FREE with g_free in any ESX_VI__TEMPLATE__FREE
Laine Stump [Fri, 5 Feb 2021 05:46:24 +0000 (00:46 -0500)]
esx: replace VIR_FREE with g_free in any ESX_VI__TEMPLATE__FREE

Invocations of the macro ESX_VI__TEMPLATE__FREE() will free the main
object (referenced as "item") that's pointing to all the things being
VIR_FREEd in the body, so it is safe for all the pointers in item to
just be g_freed rather that VIR_FREEd.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu_shim: URI escape root directory
Michal Privoznik [Fri, 12 Feb 2021 16:27:26 +0000 (17:27 +0100)]
qemu_shim: URI escape root directory

The root directory can be provided by user (or a temporary one is
generated) and is always formatted into connection URI for both
secret driver and QEMU driver, like this:

  qemu:///embed?root=$root

But if it so happens that there is an URI unfriendly character in
root directory or path to it (say a space) then invalid URI is
formatted which results in unexpected results. We can trust
g_dir_make_tmp() to generate valid URI but we can't trust user.
Escape user provided root directory. Always.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1920400
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Makefile: Expose the CI_USER_LOGIN variable for users to use
Erik Skultety [Wed, 10 Feb 2021 07:27:29 +0000 (08:27 +0100)]
ci: Makefile: Expose the CI_USER_LOGIN variable for users to use

More often than not I find myself debugging in the containers which
means that I need to have root inside, but without manually tweaking
the Makefile each time the execution would simply fail thanks to the
uid/gid mapping we do. What if we expose the CI_USER_LOGIN variable, so
that when needed, the root can be simply passed with this variable and
voila - you have a root shell inside the container with CWD=~root.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoci: Drop the prepare.sh script
Erik Skultety [Wed, 10 Feb 2021 06:06:19 +0000 (07:06 +0100)]
ci: Drop the prepare.sh script

The purpose of this script was to prepare a customized environment in
the container, but was actually never used and it required the usage of
sudo to switch the environment from root's context to a regular user's
one.
The thing is that once someone needs a custom script they would very
likely to debug something and would also benefit from root privileges
in general, so the usage of 'sudo' in such case was a bit cumbersome.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoci: Run podman command directly without wrapping it with prepare.sh
Erik Skultety [Wed, 10 Feb 2021 06:22:18 +0000 (07:22 +0100)]
ci: Run podman command directly without wrapping it with prepare.sh

The prepare.sh script isn't currently used and forces us to make use
of sudo to switch the user inside the container from root to $USER
which created a problem on our Debian Slim-based containers which don't
have the 'sudo' package installed.
This patch removes the sudo invocation and instead runs the CMD
directly with podman.

Summary of the changes:
- move the corresponding env variables which we need to be set in the
  environment from the sudo invocation to the podman invocation
- pass --workdir to podman to retain the original behaviour we had with
  sudo spawning a login shell.
- MESON_OPTS env variable doesn't need to propagated to the execution
  environment anymore (like we had to do with sudo), because it's
  defined in the Dockerfile

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoci: Specify the shebang sequence for build.sh
Erik Skultety [Wed, 10 Feb 2021 06:27:49 +0000 (07:27 +0100)]
ci: Specify the shebang sequence for build.sh

This is necessary for the follow up patch, because the default
entrypoint for a Dockerfile is exec.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoci: Move ppc64le build from Debian sid to Debian 10
Andrea Bolognani [Thu, 11 Feb 2021 11:45:53 +0000 (12:45 +0100)]
ci: Move ppc64le build from Debian sid to Debian 10

Debian sid is currently broken on ppc64le, so move the build to
Debian 10; do the opposite for the aarch64 and mips64el builds to
try and restore the 10/sid balance.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Mark container build jobs as required/optional correctly
Andrea Bolognani [Thu, 11 Feb 2021 11:55:37 +0000 (12:55 +0100)]
ci: Mark container build jobs as required/optional correctly

Whether a container build job is considered required depends on
whether the corresponding cross-build job exists, and in a few
cases the two got out of sync over time.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Shuffle cross-building jobs around
Andrea Bolognani [Thu, 11 Feb 2021 11:57:51 +0000 (12:57 +0100)]
ci: Shuffle cross-building jobs around

Keep them ordered by architecture, the same way the corresponding
container jobs are, to make it easier to jump between the two
sections and compare them.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotools: report messages for 'dominfo' command
Daniel P. Berrangé [Fri, 22 Jan 2021 15:06:52 +0000 (15:06 +0000)]
tools: report messages for 'dominfo' command

$ virsh dominfo demo
Id:             2
Name:           demo
UUID:           eadf8ef0-bf14-4c5f-9708-4a19bacf9e81
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       15.8s
Max memory:     1536000 KiB
Used memory:    1536000 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: unconfined_u:unconfined_r:svirt_t:s0:c443,c956 (permissive)
Messages:       tainted: custom monitor control commands issued
                tainted: use of deprecated configuration settings
                deprecated configuration: machine type 'pc-1.2'

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: implement virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 15:06:35 +0000 (15:06 +0000)]
qemu: implement virDomainGetMessages API

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoremote: add RPC support for the virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 14:50:10 +0000 (14:50 +0000)]
remote: add RPC support for the virDomainGetMessages API

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agosrc: define virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 14:48:49 +0000 (14:48 +0000)]
src: define virDomainGetMessages API

This API allows fetching a list of informational messages recorded
against the domain. This provides a way to give information about
tainting of the guest due to undesirable actions/configs, as well
as provide details of deprecated features.

The output of this API is explicitly targetted at humans, not
machines, so it is inappropriate to attempt to pattern match on
the strings and take action off them, not least because the messages
are marked for translation.

Should there be a demand for machine targetted information, this
would have to be addressed via a new API, and is not planned at
this point in time.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: record deprecation messages against the domain
Daniel P. Berrangé [Fri, 22 Jan 2021 14:48:03 +0000 (14:48 +0000)]
qemu: record deprecation messages against the domain

These messages are only valid while the domain is running.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: record deprecation messages against the domain
Daniel P. Berrangé [Fri, 22 Jan 2021 14:47:32 +0000 (14:47 +0000)]
conf: record deprecation messages against the domain

These messages will be stored in the live status XML.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agonews: document support for <teaming> in <hostdev>
Laine Stump [Thu, 11 Feb 2021 07:47:29 +0000 (02:47 -0500)]
news: document support for <teaming> in <hostdev>

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: plug <teaming> config from <hostdev> into qemu commandline
Laine Stump [Thu, 11 Feb 2021 07:05:15 +0000 (02:05 -0500)]
qemu: plug <teaming> config from <hostdev> into qemu commandline

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: parse/format <teaming> element in plain <hostdev>
Laine Stump [Thu, 11 Feb 2021 05:58:29 +0000 (00:58 -0500)]
conf: parse/format <teaming> element in plain <hostdev>

The <teaming> element in <interface> allows pairing two interfaces
together as a simple "failover bond" network device in a guest. One of
the devices is the "transient" interface - it will be preferred for
all network traffic when it is present, but may be removed when
necessary, in particular during migration, when traffic will instead
go through the other interface of the pair - the "persistent"
interface. As it happens, in the QEMU implementation of this teaming
pair (called "virtio failover" in QEMU) the transient interface is
always a host network device assigned to the guest using VFIO (aka
"hostdev"); the persistent interface is always an emulated virtio NIC.

When support was initially added for <teaming>, it was written to
require that the transient/hostdev device be defined using <interface
type='hostdev'>; this was done because the virtio failover
implementation in QEMU and the virtio guest driver demands that the
two interfaces in the pair have matching MAC addresses, and the only
way libvirt can guarantee the MAC address of a hostdev network device
is to use <interface type='hostdev'>, whose main purpose is to
configure the device's MAC address before handing the device to
QEMU. (note that <interface type='hostdev'> in turn requires that the
network device be an SRIOV VF (Virtual Function), as that is the only
type of network device whose MAC address we can set in a way that will
survive the device's driver init in the guest).

It has recently come up that some users are unable to use <teaming>
because they are running in a container environment where libvirt
doesn't have the necessary privileges or resources to set the VF's MAC
address (because setting the VF MAC is done via the same device's PF
(Physical Function), and the PF is not exposed to libvirt's container).

At the same time, these users *are* able to set the VF's MAC address
themselves in advance of staring up libvirt in the container. So they
could theoretically use the <teaming> feature if libvirt just skipped
the "setting the MAC address" part.

Fortunately, that is *exactly* the difference between <interface
type='hostdev'> (which must be a "hostdev VF") and <hostdev> (a "plain
hostdev" - it could be *any* PCI device; libvirt doesn't know what type
of PCI device it is, and doesn't care).

But what is still needed is for libvirt to provide a small bit of
information on the QEMU commandline argument for the hostdev, telling
QEMU that this device will be part of a team ("failover pair"), and
the id of the other device in the pair.

To make both of those goals simultaneously possible, this patch adds
support for the <teaming> element to plain <hostdev> - libvirt doesn't
try to set any MAC addresses, and QEMU gets the extra commandline
argument it needs)

(actually, this patch adds only the parsing/formatting of the
<teaming> element in <hostdev>. The next patch will actually wire that
into the qemu driver.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoschema: separate teaming element definition from interface element
Laine Stump [Thu, 11 Feb 2021 03:59:31 +0000 (22:59 -0500)]
schema: separate teaming element definition from interface element

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: separate Parse/Format functions for virDomainNetTeamingInfo
Laine Stump [Thu, 11 Feb 2021 03:44:08 +0000 (22:44 -0500)]
conf: separate Parse/Format functions for virDomainNetTeamingInfo

In preparation for using the same element in two places, split the
parsing/formating for that subelement out of the virDomainNetDef
functions into their own functions.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo
Laine Stump [Thu, 11 Feb 2021 02:09:58 +0000 (21:09 -0500)]
conf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo

To make it easier to split out the parsing/formatting of the <teaming>
element into separate functions (so we can more easily add the
<teaming> element to <hostdev>, change its virDomainNetDef so that it
points to a virDomainNetTeamingInfo rather than containing one.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: make teaming info an official type
Laine Stump [Thu, 11 Feb 2021 01:08:29 +0000 (20:08 -0500)]
conf: make teaming info an official type

This struct was previously defined only within virDomainNetDef where
it was used, but I need to also use it in virDomainHostdevDef, so move
the internal struct out to its own "official" struct and give it the
standard typedef duo and *Free() function.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: match alias when looking for proper <interface> to detach.
Laine Stump [Wed, 10 Feb 2021 19:52:25 +0000 (14:52 -0500)]
qemu: match alias when looking for proper <interface> to detach.

Previously we only checked MAC address and PCI address (or CCW
address). This is not enough information in cases where PCI address
isn't provided and multiple interfaces have the same MAC address (for
example, a virtio + hostdev "teaming" pair - their MAC addresses are
always the same).

Resolves: https://bugzilla.redhat.com/1926190
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agoqemu: Validate TPM TIS device
Jim Fehlig [Tue, 9 Feb 2021 22:47:30 +0000 (15:47 -0700)]
qemu: Validate TPM TIS device

TPM devices with model='tpm-tis' are only valid with x86 and aarch64
virt machines. Add a check to qemuValidateDomainDeviceDefTPM() to
ensure VIR_DOMAIN_TPM_MODEL_TIS is only used with these architectures.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoqemu: Fix swtpm device with aarch64
Jim Fehlig [Tue, 9 Feb 2021 21:57:22 +0000 (14:57 -0700)]
qemu: Fix swtpm device with aarch64

Starting a VM with swtpm device fails with qemu-system-aarch64.
E.g. with TPM device config

     <tpm model='tpm-tis'>
       <backend type='emulator' version='2.0'/>
      </tpm>

QEMU reports the following error

error: internal error: process exited while connecting to monitor:
2021-02-07T05:15:35.378927Z qemu-system-aarch64: -device
tpm-tis,tpmdev=tpm-tpm0,id=tpm0: 'tpm-tis' is not a valid device model name

Indeed the TPM device name is 'tpm-tis-device' [1][2] for aarch64,
versus the shorter 'tpm-tis' for x86. The devices are the same from
a functional POV, i.e. they both emulate a TPM device conforming to
the TIS specification. Account for the unfortunate name difference
when building the TPM device option in qemuBuildTPMDevStr(). Also
include a test case for 'tpm-tis-device'.

[1] https://qemu.readthedocs.io/en/latest/specs/tpm.html
[2] https://github.com/qemu/qemu/commit/c294ac327ca99342b90bd3a83d2cef9b447afaa7

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agovirstringtest: Remove testing of virStringSplitCount
Peter Krempa [Fri, 5 Feb 2021 20:36:53 +0000 (21:36 +0100)]
virstringtest: Remove testing of virStringSplitCount

The function is a wrapper on top of glibs g_strsplit, so is covered by
glibs testing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListJoin
Peter Krempa [Fri, 5 Feb 2021 20:35:21 +0000 (21:35 +0100)]
util: virstring: Remove virStringListJoin

The glib alternative is now used everywhere.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListJoin by g_strjoinv
Peter Krempa [Fri, 5 Feb 2021 20:33:47 +0000 (21:33 +0100)]
Replace virStringListJoin by g_strjoinv

Our implementation was inspired by glib anyways. The difference is only
the order of arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStringSplitCount: Reimplement using g_strsplit and g_strv_length
Peter Krempa [Tue, 6 Oct 2020 10:04:22 +0000 (12:04 +0200)]
virStringSplitCount: Reimplement using g_strsplit and g_strv_length

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringSplit
Peter Krempa [Fri, 5 Feb 2021 17:39:19 +0000 (18:39 +0100)]
util: virstring: Remove virStringSplit

Callers were replaced by g_strsplit.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringSplit with g_strsplit
Peter Krempa [Fri, 5 Feb 2021 17:35:07 +0000 (18:35 +0100)]
Replace virStringSplit with g_strsplit

Our implementation was heavily inspired by the glib version so it's a
drop-in replacement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListLength
Peter Krempa [Fri, 5 Feb 2021 17:29:58 +0000 (18:29 +0100)]
util: virstring: Remove virStringListLength

glib provides g_strv_length.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListLength by g_strv_length
Peter Krempa [Fri, 5 Feb 2021 17:03:26 +0000 (18:03 +0100)]
Replace virStringListLength by g_strv_length

The glib implementation doesn't tolerate NULL but in most cases we check
before anyways. The rest of the callers adds a NULL check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirPolkitCheckAuth: Avoid virStringListLength in loop condition
Peter Krempa [Fri, 5 Feb 2021 16:53:05 +0000 (17:53 +0100)]
virPolkitCheckAuth: Avoid virStringListLength in loop condition

Don't re-calculate the string list length on every iteration. Convert
the loop to NULL-terminated iteration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListLength where actual lenght is not needed
Peter Krempa [Fri, 5 Feb 2021 16:39:52 +0000 (17:39 +0100)]
Replace virStringListLength where actual lenght is not needed

Some callers don't need to know the actual lenght of the list but only
care whether the required element is present or the list is non-empty.
Don't calculate the list length in those cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuvhostusertest: Base iteration on string lists
Peter Krempa [Fri, 5 Feb 2021 16:34:13 +0000 (17:34 +0100)]
qemuvhostusertest: Base iteration on string lists

Remove the need to calculate list lengths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemufirmwaretest: Base iteration on string lists
Peter Krempa [Fri, 5 Feb 2021 16:34:13 +0000 (17:34 +0100)]
qemufirmwaretest: Base iteration on string lists

Remove the need to calculate list lengths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageBackendSheepdogAddVolume: Clean up memory handling
Peter Krempa [Fri, 5 Feb 2021 16:03:14 +0000 (17:03 +0100)]
virStorageBackendSheepdogAddVolume: Clean up memory handling

'cells' can be pushed into the loop removing the need for manual
cleanup, the check whether 'line' is NULL inside of the loop is always
false since the loop checks it right before and 'line' variable is
unnecessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListHasString
Peter Krempa [Wed, 3 Feb 2021 17:39:32 +0000 (18:39 +0100)]
util: virstring: Remove virStringListHasString

All callers were converted to the glib alternative. Providing our own
just to have NULL tolerance doesn't make sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListHasString by g_strv_contains
Peter Krempa [Wed, 3 Feb 2021 17:39:47 +0000 (18:39 +0100)]
Replace virStringListHasString by g_strv_contains

The glib variant doesn't accept NULL list, but there's just one caller
where it wasn't checked explicitly, thus there's no need for our own
wrapper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuProcessUpdateDevices: Refactor cleanup and memory handling
Peter Krempa [Wed, 3 Feb 2021 17:39:01 +0000 (18:39 +0100)]
qemuProcessUpdateDevices: Refactor cleanup and memory handling

Use automatic memory freeing and remove the 'cleanup' label. Also make
it a bit more obvious that nothing happens if the 'old' list wasn't
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovz: Replace virStringSplitCount(, , , NULL) with virStringSplit
Peter Krempa [Tue, 20 Oct 2020 08:08:43 +0000 (10:08 +0200)]
vz: Replace virStringSplitCount(, , , NULL) with virStringSplit

The caller doesn't care about the number of tokens so use the function
which doesn't return it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStringListGetFirstWithPrefix: Remove unused helper
Peter Krempa [Fri, 5 Feb 2021 13:34:31 +0000 (14:34 +0100)]
virStringListGetFirstWithPrefix: Remove unused helper

This is a uncommon and trivial operation, so having an utility function
for it is pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirCgroupGetValueForBlkDev: Rewrite lookup of returned string
Peter Krempa [Fri, 5 Feb 2021 13:33:12 +0000 (14:33 +0100)]
virCgroupGetValueForBlkDev: Rewrite lookup of returned string

Lookup the string with prefix locally so that we can remove the helper
which isn't universal at all.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListAdd and virStringListRemove
Peter Krempa [Fri, 5 Feb 2021 13:26:57 +0000 (14:26 +0100)]
util: virstring: Remove virStringListAdd and virStringListRemove

virStringListAdd hides the fact that a O(n) count of elements is
performed every time it's called which makes it inefficient.

Stop supporting such semantics and remove the helpers. Users have a
choice of using GSList or an array with a counter variable rather than
repeated lookups.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemusecuritytest: Store 'notRestored' files in a hash table
Peter Krempa [Fri, 5 Feb 2021 08:53:36 +0000 (09:53 +0100)]
qemusecuritytest: Store 'notRestored' files in a hash table

The validation code looks whether certain paths are in the 'notRestored'
list. For the purpose of lookup it's better to use a hash table rather
than a string list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirfirewalltest: Avoid use of 'virStringListAdd'
Peter Krempa [Thu, 4 Feb 2021 21:43:40 +0000 (22:43 +0100)]
virfirewalltest: Avoid use of 'virStringListAdd'

To allow later removal of 'virStringListAdd' add an arbitrary upper
limit on the number of args we care about and don't store more than
that until necessary later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirfirewalltest: Shuffle the code around to remove a loop
Peter Krempa [Fri, 5 Feb 2021 14:45:52 +0000 (15:45 +0100)]
virfirewalltest: Shuffle the code around to remove a loop

We are already looping over the arguments to construct the list, so we
can add them to fwBuf right away rather than in an extra loop if we move
some of the 'fwBuf' parts earlier and merge the two loops.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoxenParseXLNamespaceData: Pre-calculate the length of array
Peter Krempa [Thu, 4 Feb 2021 21:53:45 +0000 (22:53 +0100)]
xenParseXLNamespaceData: Pre-calculate the length of array

Precalculate the lenght to avoid use of 'virStringListAdd' in a loop.
The code is also simplified by using APIs which don't return errors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: macmap: Convert to use GSList for storing macs instead of string lists
Peter Krempa [Fri, 5 Feb 2021 13:25:16 +0000 (14:25 +0100)]
util: macmap: Convert to use GSList for storing macs instead of string lists

Since adding and removing is the main use case for the macmap module,
convert the code to a more efficient data structure.

The refactor also optimizes the loading from file where previously we'd
do a hash lookup + list lenght calculation for every entry.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: Convert 'priv->dbusVMStateIds' to a GSList
Peter Krempa [Fri, 5 Feb 2021 09:48:51 +0000 (10:48 +0100)]
qemu: Convert 'priv->dbusVMStateIds' to a GSList

The conversion removes the use of virStringListAdd/virStringListRemove
which try to add dynamic properties to a string list which is really
inefficient.

Storing the dbus VMState ids in a GSList is pretty straightforward and
the slightly increased complexity of the code will be paid back by
removing the string list helpers later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlMonitorGetStats: Don't use 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:30:02 +0000 (15:30 +0100)]
virResctrlMonitorGetStats: Don't use 'virStringListAdd'

The iner loop copies the 'resources' array multiple times using
'virStringListAdd' which has O(n^2) complexity.

Pre-calculate the length so we can allocate the array upfront and just
copy the strings in the loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:28:46 +0000 (15:28 +0100)]
virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list

Pre-allocate a buffer for the upper limit and shrink it afterwards to
avoid use of 'virStringListAdd' in a loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agox86ModelParseFeatures: Don't construct list using 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:20:44 +0000 (15:20 +0100)]
x86ModelParseFeatures: Don't construct list using 'virStringListAdd'

Pre-allocate the list to the upper bound and fill it gradually. Since
the data is kept long-term and the list won't be populated much shrink
it to the actual size after parsing.

While using 'virStringListAdd' here wouldn't be as expensive as this
function is used just once, the removal will allow to remove
'virStringListAdd' altogether to discourage the antipattern it promotes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:13:28 +0000 (15:13 +0100)]
virCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list

We already know the upper bound of items we might need so we can
allocate the array upfront and avoid the quadratic complexity of
'virStringListAdd'.

In this instance the returned data is kept only temporarily so a
potential unused space due to filtered-out entries doesn't impose a
long-term burden on memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:09:12 +0000 (15:09 +0100)]
qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list

'virHashGetItems' already returns the number of entries which will be
considered for addition to the list so we can allocate it to the upper
bound upfront rather than growing it in a loop. This avoids the
quadratic complexity of 'virStringListAdd'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirHookCall: Don't use 'virStringListAdd' to construct list in loop
Peter Krempa [Thu, 4 Feb 2021 19:27:05 +0000 (20:27 +0100)]
virHookCall: Don't use 'virStringListAdd' to construct list in loop

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: namespace: Don't use 'virStringListAdd' inside loops
Peter Krempa [Thu, 4 Feb 2021 13:10:42 +0000 (14:10 +0100)]
qemu: namespace: Don't use 'virStringListAdd' inside loops

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Use a GSList which has cheap insertion and iteration and doesn't need
failure handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: Add helpers for auto-freeing GSList filled with strings
Peter Krempa [Thu, 4 Feb 2021 16:58:23 +0000 (17:58 +0100)]
util: Add helpers for auto-freeing GSList filled with strings

glib's 'g_autoslist()' doesn't support lists of 'char *' strings. Add a
type alias 'virGSListString' so that we can register an 'autoptr'
function for it for simple usage of GSList with strings.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling
Peter Krempa [Thu, 4 Feb 2021 14:12:57 +0000 (15:12 +0100)]
qemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling

Some code paths return -1 directly while others jump to 'cleanup' which
cleans the list of mounts. Since qemuDomainGetPreservedMounts now
returns a NULL-terminated list, convert devMountsPath to g_auto(GStrv)
and remove the cleanup altoghether.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix wrong use of iterator variable
Peter Krempa [Thu, 4 Feb 2021 13:27:19 +0000 (14:27 +0100)]
qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable

'i' is used in both outer and inner loop. Since 'devMountsPath' is now a
NULL-terminated list, we can use a GStrv to iterate it;

Additionally rewrite the conditional of adding to the 'unlinkPaths'
array so that it's more clear what's happening.

Fixes: 5c86fbb72d6e90025481db7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists
Peter Krempa [Thu, 4 Feb 2021 14:09:57 +0000 (15:09 +0100)]
qemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists

Refactor the handling of internals so that NULL-terminated lists are
always returned.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: macmap: Remove unused cleanup labels and 'ret' variables
Peter Krempa [Fri, 5 Feb 2021 10:14:43 +0000 (11:14 +0100)]
util: macmap: Remove unused cleanup labels and 'ret' variables

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virmacmap: Use g_autofree for virJSONValue
Peter Krempa [Fri, 5 Feb 2021 10:14:09 +0000 (11:14 +0100)]
util: virmacmap: Use g_autofree for virJSONValue

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Jan Kuparinen [Thu, 11 Feb 2021 07:45:28 +0000 (08:45 +0100)]
Translated using Weblate (Finnish)

Currently translated at 14.0% (1468 of 10451 strings)

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

Translated using Weblate (Finnish)

Currently translated at 13.8% (1447 of 10451 strings)

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

Co-authored-by: Jan Kuparinen <copper_fin@hotmail.com>
Signed-off-by: Jan Kuparinen <copper_fin@hotmail.com>
4 years agoqemu: Do not Use canonical path for system memory
Michal Privoznik [Fri, 8 Jan 2021 15:35:26 +0000 (16:35 +0100)]
qemu: Do not Use canonical path for system memory

In commit 88957116c9d3cb4705380c3702c9d4315fb500bb I've adapted
libvirt to QEMU's deprecation of -mem-path and -mem-prealloc and
switched to memory-backend-* even for system memory. My claim was
that that's what QEMU does under the hood anyway. And indeed it
was: see QEMU commit 900c0ba373aada4c13d47d95330aa72ec4067ba5 and
look at function create_default_memdev().

However, then commit d96c4d5f193e0e45beec80a6277728b32875bddb was
merged into QEMU. While it was fixing a bug, it also changed the
create_default_memdev() function in which it started turning off
use of canonical path (by setting
"x-use-canonical-path-for-ramblock-id" attribute to false). This
wasn't documented until QEMU commit
8db0b20415c129cf5e577a593a4a0372d90b7cc9. The path affects
migration - the same path has to be used on the source and on the
destination. Therefore, if there is old guest started with '-m X'
it has "pc.ram" block which doesn't use canonical path and thus
when migrating to newer QEMU which uses memory-backend-* we have
to turn off the canonical path explicitly. Otherwise,
"/objects/pc.ram" path would be expected by QEMU which doesn't
match the source.

Ideally, we would need to set it only for some machine types
(4.0 and older) because newer machine types already do what we
are doing. However, we treat machine types as opaque strings and
therefore we don't want to parse nor inspect their versions. But
then again, newer machine types already do what we are doing in
this commit, so when old machine types are deprecated and removed
we can remove our hack and forget it ever happened.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1912201
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID
Michal Privoznik [Mon, 11 Jan 2021 17:15:57 +0000 (18:15 +0100)]
qemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID

This capability tracks whether memory-backend-file has
"x-use-canonical-path-for-ramblock-id" attribute. Introduced into
QEMU by commit fa0cb34d2210cc749b9a70db99bb41c56ad20831. As of
QEMU commit 8db0b20415c129cf5e577a593a4a0372d90b7cc9 the property
is considered stable by qemu despite the 'x-' prefix to preserve
compatibility with released qemu versions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agobuild: Remove unused 'conflicts' key from virt_daemon_unit
Jim Fehlig [Tue, 9 Feb 2021 18:21:04 +0000 (11:21 -0700)]
build: Remove unused 'conflicts' key from virt_daemon_unit

The 'conflict' key in a virt_daemon_unit dictionary is not used when
generating systemd service and socket files. The comment associated
with the key claims the default is 'true', and a few build files
needlessly set it to 'true' when defining their virt_daemon_unit.
Remove the 'conflict' key and its use in the affect build files.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoschemas: Add support for maximum CPU mode
Jiri Denemark [Wed, 10 Feb 2021 13:08:49 +0000 (14:08 +0100)]
schemas: Add support for maximum CPU mode

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotests: add cgroup nested tests
Pavel Hrdina [Thu, 5 Nov 2020 17:39:10 +0000 (18:39 +0100)]
tests: add cgroup nested tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce nested cgroup to properly work with systemd
Pavel Hrdina [Tue, 9 Feb 2021 11:33:53 +0000 (12:33 +0100)]
vircgroup: introduce nested cgroup to properly work with systemd

When running on host with systemd we register VMs with machined.
In this case systemd creates the root VM cgroup for us. This has some
implications where one of them is that systemd owns all files inside
the root VM cgroup and we should not touch them.

We already use DBus calls for some of the APIs but for the remaining
ones we will continue accessing the files directly. Systemd doesn't
support threaded cgroups so we need to do this.

The reason why we don't use DBus for most of the APIs is that we already
have a code that works with files and we would have to check if systemd
supports each API.

This change introduces new topology on systemd hosts:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- libvirt
           |
           +- emulator
           +- vcpu0
           +- vcpu0

compared to the previous topology:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- emulator
        +- vcpu0
        +- vcpu0

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce virCgroupV1Exists and virCgroupV2Exists
Pavel Hrdina [Tue, 9 Feb 2021 11:31:13 +0000 (12:31 +0100)]
vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists

This will check if the cgroup actually exists on the system.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroupv2: move task into cgroup before enabling controllers
Pavel Hrdina [Wed, 4 Nov 2020 18:55:44 +0000 (19:55 +0100)]
vircgroupv2: move task into cgroup before enabling controllers

When we create a new child cgroup and the parent cgroup has any process
attached to it enabling controllers for the child cgroup fails with
error. We need to move the process into the child cgroup first before
enabling any controllers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>