]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agotools: replace wcwidth() with g_unichar_* APIs
Daniel P. Berrangé [Fri, 17 Jan 2020 13:40:54 +0000 (13:40 +0000)]
tools: replace wcwidth() with g_unichar_* APIs

The combination of g_unichar_iszerowidth and
g_unichar_iswide is sufficient to replicate the logic
of wcwidth() for libvirt.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: use getgrouplist() directly instead of mgetgroups
Daniel P. Berrangé [Fri, 17 Jan 2020 12:33:37 +0000 (12:33 +0000)]
util: use getgrouplist() directly instead of mgetgroups

The mgetgroups function is a GNULIB custom wrapper around
getgrouplist(). This implements a simplified version of
that code directly.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobuild: generate configmake.h in root directory
Daniel P. Berrangé [Fri, 17 Jan 2020 11:32:09 +0000 (11:32 +0000)]
build: generate configmake.h in root directory

Currently we rely on gnulib creating configmake.h, but we
can easily create it ourselves instead.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: remove usage of strchrnul function
Daniel P. Berrangé [Tue, 14 Jan 2020 10:43:37 +0000 (10:43 +0000)]
src: remove usage of strchrnul function

The strchrnul function doesn't exist on Windows and rather
than attempt to implement it, it is simpler to just avoid
its usage, as any callers are easily adapted.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: add API for reading password from the console
Daniel P. Berrangé [Tue, 14 Jan 2020 10:40:52 +0000 (10:40 +0000)]
util: add API for reading password from the console

This imports a simpler version of GNULIB's getpass() function
impl for Windows. Note that GNULIB's impl was buggy as it
returned a static string on UNIX, and a heap allocated string
on Windows. This new impl always heap allocates.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: add a virArchFromHost() impl for Windows
Daniel P. Berrangé [Thu, 16 Jan 2020 10:51:35 +0000 (10:51 +0000)]
util: add a virArchFromHost() impl for Windows

Instead of relying on GNULIb's uname() impl, directly use the
Windows API for determining CPU architecture.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: stop setting $SHELL env variable
Daniel P. Berrangé [Thu, 16 Jan 2020 10:50:35 +0000 (10:50 +0000)]
tests: stop setting $SHELL env variable

None of the tests appear to reference a SHELL env variable
explicitly and they all succeeed when it is not set. This
eliminates the only use of the gnulib posix-shell module.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: add warning about virt-qemu-run being experimental
Daniel P. Berrangé [Wed, 29 Jan 2020 11:17:54 +0000 (11:17 +0000)]
docs: add warning about virt-qemu-run being experimental

We currently note that the QEMU embedded driver is experimental
in the drvqemu.html file, but we should do the same in the
virt-qemu-run man page.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosecurity: do not remember/recall labels for VFIO
Daniel Henrique Barboza [Mon, 27 Jan 2020 18:23:21 +0000 (15:23 -0300)]
security: do not remember/recall labels for VFIO

Files inside /dev/vfio/ can't be opened more than once, meaning
that any subsequent open calls will fail. This behavior was
introduced in kernel v3.11, commit 6d6768c61b39.

When using the VFIO driver, we open a FD to /dev/vfio/N and
pass it to QEMU. If any other call attempt for the same
/dev/vfio/N happens while QEMU is still using the file, we are
unable to open it and QEMU will report -EBUSY. This can happen
if we hotplug a PCI hostdev that belongs to the same IOMMU group
of an existing domain hostdev.

The problem and solution is similar to what we already dealt
with for TPM in commit 4e95cdcbb3. This patch changes both
DAC and SELinux drivers to disable 'remember' for VFIO hostdevs
in virSecurityDACSetHostdevLabelHelper() and
virSecurityDACSetHostdevLabel(), and 'recall'
in virSecurityDACRestoreHostdevLabel() and
virSecuritySELinuxRestoreHostdevSubsysLabel().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosecurity: Allow 'remember' to be set for HostdevLabelHelper
Daniel Henrique Barboza [Mon, 27 Jan 2020 18:23:20 +0000 (15:23 -0300)]
security: Allow 'remember' to be set for HostdevLabelHelper

There is a case in which we do not want 'remember' to be
set to true in SetOwnership() calls inside the
HostdevLabelHelper() functions of both DAC and SELinux drivers.
Next patch will explain and handle that scenario.

For now, let's make virSecurityDACSetOwnership() and
virSecuritySELinuxSetHostdevLabelHelper() accept a 'remember'
flag, which will be used to set the 'remember' parameter
of their respective SetOwnership() calls. No functional
change is made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: use --strict arg when processing rst docs
Daniel P. Berrangé [Wed, 29 Jan 2020 10:17:45 +0000 (10:17 +0000)]
docs: use --strict arg when processing rst docs

The --strict arg forces the rst tools to abort with an error instead
of printing warnings to stderr, or the output document.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: fix various duplicate link targets in virsh.rst
Daniel P. Berrangé [Wed, 29 Jan 2020 10:16:03 +0000 (10:16 +0000)]
docs: fix various duplicate link targets in virsh.rst

You can't have two links with the same text when using named
link references (a single "_"). If you need multiple links
with the same text you must use anonymous link references
(a double "_").

There are also some duplicate section headers causing the
same problem with duplicate link targets.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: when leaving iotune group update xml properly
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:31 +0000 (09:49 +0300)]
qemu: when leaving iotune group update xml properly

Currently when disk is removed from iotune group (by setting
all tunables to zero) group name is leaved in config. Let's fix
it.

Given iotune defaults are taken from the destination group setting
tunables to zero may require different set of zero settings in API
call. Let's prohibit removing from group while specifying different
group name then current for the sanity sake.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: get defaults from iotune group we move disk into
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:30 +0000 (09:49 +0300)]
qemu: get defaults from iotune group we move disk into

For example if disk is not in the group and we want to move it
there then it makes sense to specify only the group name in API call.
Currently the destination group iotune settings will be overwritten
with the disk settings which I would say is not what one would expect.
Thus let's get defaults from the group we are moving to.

And if we are moving the brand new group then is makes sense to
copy the current disk iotune settings to the group.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: fix using defaults when setting persistent iotune params
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:28 +0000 (09:49 +0300)]
qemu: fix using defaults when setting persistent iotune params

virDomainSetBlockIoTune not simply sets the iotune params given in API
but use current settings for all the omitted params. Unfortunately
it uses current settings for active config when setting inactive
params. Let's fix it.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: check iotune params same for all disk in group
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:27 +0000 (09:49 +0300)]
qemu: check iotune params same for all disk in group

Currently it is possible to start a domain which have disks
in same iotune group and at the same time having different iotune
params. Both params set are passed to qemu in command line and the one
that is passed later down command line is get actually set.
Let's prohibit such configurations.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: propagate iotune settings to all disks in the group
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:29 +0000 (09:49 +0300)]
qemu: propagate iotune settings to all disks in the group

Currently upon successfull call to qemu's implementation of
virDomainSetBlockIoTune iotune settings are changed only for the
disk given in API if the disk is in iotune group while we need
to change the settings for all disks in the group.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: expand iotune params if only group name is given
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:26 +0000 (09:49 +0300)]
conf: expand iotune params if only group name is given

Currently, if only iotune group name is given for some disk and
no any params then later start of domain will fail. I guess it
will be convenient to allow such configuration if there is
another disk in the same iotune group with iotune params set. The
meaning is that the first disk have same iotunes and the latter.
Thus one can easily add a disk to iotune group - just add group
name parameter and no need to copy all the params.

Also let's expand iotunes params in the described case so we don't
need to refer to another disk to know iotunes and this will make
logic in many places simple.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Move qemuDiskConfigBlkdeviotuneHas* to conf
Nikolay Shirokovskiy [Wed, 8 Jan 2020 06:49:25 +0000 (09:49 +0300)]
qemu: Move qemuDiskConfigBlkdeviotuneHas* to conf

And introduce virDomainBlockIoTuneInfoHasAny.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: secret: Unify and sanitize examples on how to set secret value
Peter Krempa [Fri, 10 Jan 2020 15:35:11 +0000 (16:35 +0100)]
docs: secret: Unify and sanitize examples on how to set secret value

Discourage passing secrets as commandline arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: virsh: Add --interactive flag for secret-set-value command
Peter Krempa [Fri, 24 Jan 2020 15:37:27 +0000 (16:37 +0100)]
tools: virsh: Add --interactive flag for secret-set-value command

Simplify human usage of secret-set-value by adding --interactive which
will read the value of the secret from the terminal.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Add --plain switch for secret-set-value
Peter Krempa [Fri, 24 Jan 2020 15:28:19 +0000 (16:28 +0100)]
virsh: secret: Add --plain switch for secret-set-value

Allow using the contents of --file without base64 decoding.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Print warning that passing secret on command-line is insecure
Peter Krempa [Fri, 24 Jan 2020 15:16:27 +0000 (16:16 +0100)]
virsh: secret: Print warning that passing secret on command-line is insecure

Print a warning if users pass in secrets as command line arguments and
mention it in the man page.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Add --file 'filename' support for secret-set-value
Peter Krempa [Fri, 10 Jan 2020 14:54:05 +0000 (15:54 +0100)]
virsh: secret: Add --file 'filename' support for secret-set-value

The necessity to specify the secret value as command argument is
insecure. Allow reading the secret from a file.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Add --plain flag for secret-get-value
Peter Krempa [Fri, 10 Jan 2020 14:12:16 +0000 (15:12 +0100)]
virsh: secret: Add --plain flag for secret-get-value

Users might want to get the raw value instead of dealing with base64
encoding. This might be useful for redirection to file and also for
simple human-readable secrets.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Refactor cleanup in cmdSecretGetValue
Peter Krempa [Fri, 24 Jan 2020 14:42:02 +0000 (15:42 +0100)]
virsh: secret: Refactor cleanup in cmdSecretGetValue

Automatically clean the secret object and get rid of the cleanup label
and 'ret' valiable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: secret: Refactor cleanup in cmdSecretSetValue
Peter Krempa [Fri, 24 Jan 2020 14:42:02 +0000 (15:42 +0100)]
virsh: secret: Refactor cleanup in cmdSecretSetValue

Automatically clean the secret object and get rid of the cleanup label
and 'ret' valiable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: Work around virSecretFree quirks
Peter Krempa [Fri, 24 Jan 2020 14:24:49 +0000 (15:24 +0100)]
virsh: Work around virSecretFree quirks

Similarly to other libvirt object freeing APIs the function resets the
libvirt error when called and doesn't take NULL gracefully. Install the
workaround and g_autoptr handlers similarly to the 'virshDomain' type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovz: fix typos of 'explicitly'
Ján Tomko [Fri, 24 Jan 2020 20:32:03 +0000 (21:32 +0100)]
vz: fix typos of 'explicitly'

Also add a space before ending a comment.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoinclude: add a space before ending a comment
Ján Tomko [Fri, 24 Jan 2020 20:28:00 +0000 (21:28 +0100)]
include: add a space before ending a comment

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoconf: unmark xmlopt as unused in virDomainDeviceInfoParseXML
Ján Tomko [Fri, 24 Jan 2020 19:53:02 +0000 (20:53 +0100)]
conf: unmark xmlopt as unused in virDomainDeviceInfoParseXML

It is used by the user-alias handling code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoconf: remove outdated comments
Ján Tomko [Fri, 24 Jan 2020 19:49:00 +0000 (20:49 +0100)]
conf: remove outdated comments

Some *ParseXML functions have comments stating what kind of device
they parse with an outdated list of parameters, with the exception
of virDomainFSDefParseXML which claims to parse a disk.

Remove them, assuming the function names are descriptive enough.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: eliminate ret in qemuExtDevicesStart
Ján Tomko [Fri, 24 Jan 2020 18:43:18 +0000 (19:43 +0100)]
qemu: eliminate ret in qemuExtDevicesStart

All the callees return either 0 or -1 so there is no need
for propagating the value. And we bail on the first error.

Remove the variable to make the function simpler.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: use def instead of vm->def in qemuExtDevicesStart
Ján Tomko [Fri, 24 Jan 2020 18:41:45 +0000 (19:41 +0100)]
qemu: use def instead of vm->def in qemuExtDevicesStart

We have a helper variable to make the code more concise,
use it consistently.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: eliminate ret variable in qemuExtTPMStart
Ján Tomko [Fri, 24 Jan 2020 18:36:26 +0000 (19:36 +0100)]
qemu: eliminate ret variable in qemuExtTPMStart

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: eliminate ret variable in qemuExtTPMStartEmulator
Ján Tomko [Fri, 24 Jan 2020 18:34:07 +0000 (19:34 +0100)]
qemu: eliminate ret variable in qemuExtTPMStartEmulator

Now that the cleanup section is empty, eliminate the cleanup
label as well as the 'ret' variable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: use g_auto in qemuExtTPMStartEmulator
Ján Tomko [Fri, 24 Jan 2020 18:32:21 +0000 (19:32 +0100)]
qemu: use g_auto in qemuExtTPMStartEmulator

Use the g_auto macros wherever possible to eliminate the cleanup
section.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoconf: use virXMLFormatElement in virDomainFSDefFormat
Ján Tomko [Wed, 15 Jan 2020 14:16:45 +0000 (15:16 +0100)]
conf: use virXMLFormatElement in virDomainFSDefFormat

Use the virXMLFormatElement helper to format the driver element
to simplify adding further sub-elements.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agogitdm: Add missing entries
Andrea Bolognani [Mon, 13 Jan 2020 16:01:26 +0000 (17:01 +0100)]
gitdm: Add missing entries

A few new companies and individuals contributed to libvirt since
the last time the gitdm configuration was updated.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu_shim: Update temporary directory template
Andrea Bolognani [Mon, 27 Jan 2020 16:48:17 +0000 (17:48 +0100)]
qemu_shim: Update temporary directory template

The template still references libvirt-qemu-shim, which was at one
point the name used to refer to what we now know as virt-qemu-run.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu_shim: Fix typos
Andrea Bolognani [Mon, 27 Jan 2020 16:45:37 +0000 (17:45 +0100)]
qemu_shim: Fix typos

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
5 years agodocs: Fix link to virt-qemu-run(1)
Andrea Bolognani [Mon, 27 Jan 2020 16:47:02 +0000 (17:47 +0100)]
docs: Fix link to virt-qemu-run(1)

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu: snapshot: go through cleanup on error
Ján Tomko [Mon, 27 Jan 2020 15:42:47 +0000 (16:42 +0100)]
qemu: snapshot: go through cleanup on error

A recent commit added an error check for too-nested backing chains
followed by a return, even though errors above jump to cleanup.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: b168fa88b85dec181882816ab65a59a6c4500667
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu_shim: cosmetic fixes
Ján Tomko [Mon, 27 Jan 2020 15:39:47 +0000 (16:39 +0100)]
qemu_shim: cosmetic fixes

Remove bogus G_GNUC_UNUSED attribute and add a missing space.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: d6006672788ec0f0290d35c76ceb9672476d1ea8
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agodocs: fix since version in driver documentation
Ján Tomko [Mon, 27 Jan 2020 15:38:19 +0000 (16:38 +0100)]
docs: fix since version in driver documentation

Also one stray angle bracket.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 068efae5b1a9efeea4a9c3bc0ae80747da5024fb
Fixes: 3e9076e777aff2f4b08330ed17e559fcfb6b3529
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agodocs: fix virt-qemu-run man page
Ján Tomko [Mon, 27 Jan 2020 15:35:58 +0000 (16:35 +0100)]
docs: fix virt-qemu-run man page

Fix a documentation generation error:
System Message: WARNING/2 (<stdin>, line 15); backlink
Inline literal start-string without end-string.

As well as the 'independant' typo.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: d6006672788ec0f0290d35c76ceb9672476d1ea8
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu: checkpoint: Extract calculation of bitmap merging for checkpoint deletion
Peter Krempa [Wed, 8 Jan 2020 09:25:33 +0000 (10:25 +0100)]
qemu: checkpoint: Extract calculation of bitmap merging for checkpoint deletion

This will allow some testing before refactoring.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Introduce helper to find checkpoint disk definition in parents
Peter Krempa [Wed, 8 Jan 2020 08:55:18 +0000 (09:55 +0100)]
qemu: checkpoint: Introduce helper to find checkpoint disk definition in parents

The algorithm is used in two places to find the parent checkpoint object
which contains given disk and then uses data from the disk. Additionally
the code is written in a very non-obvious way. Factor out the lookup of
the disk into a function which also simplifies the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: domain: Remove unused qemuDomainDiskNodeFormatLookup
Peter Krempa [Wed, 8 Jan 2020 07:19:42 +0000 (08:19 +0100)]
qemu: domain: Remove unused qemuDomainDiskNodeFormatLookup

The function has no users now and there's no need for it as the common
pattern is to look up the whole disk object anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: tolerate missing disks on checkpoint deletion
Peter Krempa [Wed, 8 Jan 2020 07:18:51 +0000 (08:18 +0100)]
qemu: checkpoint: tolerate missing disks on checkpoint deletion

If a disk is unplugged and then the user tries to delete a checkpoint
the code would try to use NULL node name as it was not checked.

Fix this by fetching the whole disk definition object and verifying it
was found.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Use disk definition directly when creating checkpoint
Peter Krempa [Wed, 8 Jan 2020 07:10:35 +0000 (08:10 +0100)]
qemu: checkpoint: Use disk definition directly when creating checkpoint

Lookup the whole disk definition rather than just the node name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: rename disk->chkdisk in qemuCheckpointAddActions
Peter Krempa [Wed, 8 Jan 2020 06:55:18 +0000 (07:55 +0100)]
qemu: checkpoint: rename disk->chkdisk in qemuCheckpointAddActions

Upcoming patches will also use the domain disk definition. Rename disk
to chkdisk for clarity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: rename disk->chkdisk in qemuCheckpointDiscardBitmaps
Peter Krempa [Wed, 8 Jan 2020 06:55:18 +0000 (07:55 +0100)]
qemu: checkpoint: rename disk->chkdisk in qemuCheckpointDiscardBitmaps

Upcoming patches will also use the domain disk definition. Rename disk
to chkdisk for clarity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: split out checkpoint deletion bitmaps
Peter Krempa [Tue, 7 Jan 2020 14:15:38 +0000 (15:15 +0100)]
qemu: checkpoint: split out checkpoint deletion bitmaps

qemuCheckpointDiscard is a massive function that can be separated into
smaller bits. Extract the part that actually modifies the disk from the
metadata handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Store whether deleted checkpoint is current in a variable
Peter Krempa [Tue, 7 Jan 2020 14:01:41 +0000 (15:01 +0100)]
qemu: checkpoint: Store whether deleted checkpoint is current in a variable

Avoid two computations by using a boolean.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agotests: qemu: Remove prehistoric machine types from faked data tests
Peter Krempa [Thu, 23 Jan 2020 09:37:08 +0000 (10:37 +0100)]
tests: qemu: Remove prehistoric machine types from faked data tests

qemu-5.0 will drop pre pc-1.0 machine types. Remove them from our
faked capabilities test suite. If a feature depends on a machine type it
shall be tested with real data and not with this hack.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2xml: Remove prehistoric machine types from legacy tests
Peter Krempa [Thu, 23 Jan 2020 09:39:47 +0000 (10:39 +0100)]
tests: qemuxml2xml: Remove prehistoric machine types from legacy tests

None of the tests depend on anything that the machine type would
influence. This will allow us to drop the very old machine type from the
non-real-data tests. If something depends on the machine type it should
be tested with real data rather than this hack.

Note that these tests are run only in the XML->XML suite because the
XML->argv suite doesn't work with the network driver.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml: Remove prehistoric machine types from legacy tests
Peter Krempa [Thu, 23 Jan 2020 09:39:47 +0000 (10:39 +0100)]
tests: qemuxml: Remove prehistoric machine types from legacy tests

None of the tests depend on anything that the machine type would
influence. This will allow us to drop the very old machine type from the
non-real-data tests. If something depends on the machine type it should
be tested with real data rather than this hack.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: Add caps for upcoming qemu-5.0
Peter Krempa [Fri, 13 Dec 2019 13:37:25 +0000 (14:37 +0100)]
tests: Add caps for upcoming qemu-5.0

Based on upstream commit 3e08b2b9cb64. This version already dropped the
pre-historic machine types and supports only machine types starting from
'pc-1.0'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml: Purge prehistoric machine type 'pc-0.13' from "latest" tests
Peter Krempa [Thu, 23 Jan 2020 09:17:28 +0000 (10:17 +0100)]
tests: qemuxml: Purge prehistoric machine type 'pc-0.13' from "latest" tests

Remove the old machine type which will be dropped in the upcomming
qemu-5.0 release from tests used against the most recent capabilities
data.

None of the modified tests really cares about the actual machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemu: Don't add fake machine types when testing with real data
Peter Krempa [Thu, 23 Jan 2020 12:23:35 +0000 (13:23 +0100)]
tests: qemu: Don't add fake machine types when testing with real data

Skip the step of adding all of the fake machine types which are required
for the legacy tests in case when we are testing with real capabilities.

Faking any data in the real capabilities undermines the point of testing
with real capabilities.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: capabilities: Add accessor to qemu caps machine types presence
Peter Krempa [Thu, 23 Jan 2020 12:21:47 +0000 (13:21 +0100)]
qemu: capabilities: Add accessor to qemu caps machine types presence

Test code will need to know whether the virQEMUCaps object contains any
machine types already. Add a helper and expose it via 'qemu_capspriv.h'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: capabilities: Replace aliased machine type by copy of the canonical machine
Peter Krempa [Thu, 23 Jan 2020 12:20:25 +0000 (13:20 +0100)]
qemu: capabilities: Replace aliased machine type by copy of the canonical machine

The previous approac of just purging the alias combined with the fact
that we filled in fake machine types in the test data meant that if a
test case used an alias machine type such as 'pc' or 'q35' it would not
properly resolve to the actual data returned by qemu.

This started to be a problem since the CPU driver now looks at the
default CPU reported with the machine type.

This patch replaces the original approach of just removing the alias by
replacing it with a copy of the machine type data which the type would
alias to. This means that we are using the real data while we don't
modify the test output after every qemu upgrade.

Additionally this change will allow us to drop adding the fake machine
types later.

The test fallout is from actually excercising the CPU driver with
actual data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: capabilities: Extract code from virQEMUCapsStripMachineAliases
Peter Krempa [Thu, 23 Jan 2020 12:11:08 +0000 (13:11 +0100)]
qemu: capabilities: Extract code from virQEMUCapsStripMachineAliases

Separate out the internals as they will become more complex soon.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: domain: Validate that machine type is supported by qemu
Peter Krempa [Wed, 22 Jan 2020 09:06:53 +0000 (10:06 +0100)]
qemu: domain: Validate that machine type is supported by qemu

Every supported qemu is able to return the list of machine types it
supports so we can start validating it against that list. The advantage
is a better error message, and the change will also prevent having stale
test data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemu: Add machine types used by the test code to fake capabilities
Peter Krempa [Wed, 22 Jan 2020 16:46:57 +0000 (17:46 +0100)]
tests: qemu: Add machine types used by the test code to fake capabilities

Enumerate all missing machine types for all missing architectures for
the fake capabilities used in many existing tests. This will allow
stricter validation whether qemu actually supports given machine type
since we already have some behaviour dependant on the actual machine
type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml: Use existing machine type in 'iothreads-virtio-scsi-ccw' case
Peter Krempa [Thu, 23 Jan 2020 09:11:12 +0000 (10:11 +0100)]
tests: qemuxml: Use existing machine type in 'iothreads-virtio-scsi-ccw' case

Use the 's390-ccw-virtio' machine type which is actually supported by
the qemu we gathered the test data from.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Use proper replacement for 'pc-i440fx-wily' machine
Peter Krempa [Wed, 22 Jan 2020 16:45:12 +0000 (17:45 +0100)]
tests: qemuxml2argv: Use proper replacement for 'pc-i440fx-wily' machine

This machine type comes from downstream ubuntu 15.10. Replace it with a
somewhat equivalent qemu-2.3 machine type as we do have test data for
that.

The change allows the CPU code to pick a proper default CPU in the
'-latest' cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Use existing non-virt machine in 'aarch64-gic-not-virt'
Peter Krempa [Wed, 22 Jan 2020 16:43:45 +0000 (17:43 +0100)]
tests: qemuxml2argv: Use existing non-virt machine in 'aarch64-gic-not-virt'

Use 'versatilepb' instead of a fake 'non-virt' machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Remove downstream machine type in 'controller-order' case
Peter Krempa [Wed, 22 Jan 2020 16:42:42 +0000 (17:42 +0100)]
tests: qemuxml2argv: Remove downstream machine type in 'controller-order' case

Use 'pc' instead of ancient 'rhel-6.1'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Use existing machine type for 'numatune-distances' case
Peter Krempa [Wed, 22 Jan 2020 16:41:15 +0000 (17:41 +0100)]
tests: qemuxml2argv: Use existing machine type for 'numatune-distances' case

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemu: Unify fake machine types filled in for KVM and TCG caps of x86_64
Peter Krempa [Wed, 22 Jan 2020 09:28:19 +0000 (10:28 +0100)]
tests: qemu: Unify fake machine types filled in for KVM and TCG caps of x86_64

For testing with synthetic capabilities we pre-fill the qemu
capabilities with some machine types. Historically there were two arrays
for KVM and TCG but that's not necessary. Make both instances of x86_64
data share the same array as the other architectures do.

This will later on simplify filling in all the other machine types which
are required for the test suite.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml: Fix and enable default-video-type* tests
Peter Krempa [Wed, 22 Jan 2020 10:56:09 +0000 (11:56 +0100)]
tests: qemuxml: Fix and enable default-video-type* tests

The tests prefixed default-video* were enabled only for the xml2xml
testing and used impossible configurations.

Enable them for xml2argv testing fix them:
1) aarch64: remove pointless cpu mode
2) s390x: remove pointless cpu and use existing machine type
3) riscv: remove pointless cpu
4) x86: remove pointless cpu and use existing machine type
5) ppc65: use correct machine type and enable USB

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Modernize tpm-passthrough tests
Peter Krempa [Thu, 23 Jan 2020 09:26:12 +0000 (10:26 +0100)]
tests: qemuxml2argv: Modernize tpm-passthrough tests

XML->XML testing uses DO_TEST_CAPS_LATEST so use it also for the
XML->argv testing. Additionally use the same more modern machine type
in both tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2xml: Modernize 'disk-cache' test
Peter Krempa [Wed, 22 Jan 2020 16:15:35 +0000 (17:15 +0100)]
tests: qemuxml2xml: Modernize 'disk-cache' test

Mirror what's done in the xml2argv test and use recent capabilities.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: qemuxml2argv: Use 64 bit qemu binary and 1.5 machine type in 'disk-cache'...
Peter Krempa [Wed, 22 Jan 2020 16:11:52 +0000 (17:11 +0100)]
tests: qemuxml2argv: Use 64 bit qemu binary and 1.5 machine type in 'disk-cache' case

The data is tested against the latest qemu binaries so we should use the
proper architecture. Also the test is used against data from qemu 1.5.3
and thus we should use a machine type that qemu supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: fix linking virt-qemu-run on some distros
Daniel P. Berrangé [Mon, 27 Jan 2020 12:42:04 +0000 (12:42 +0000)]
qemu: fix linking virt-qemu-run on some distros

Debian/Ubuntu linkers are more strict that other distros requiring glib
to be linked explicitly.

macOS needs -export-dynamic instead of -Wl,--export-dynamic

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobhyve: add 'root' parameter to driver initializer
Daniel P. Berrangé [Mon, 27 Jan 2020 12:41:48 +0000 (12:41 +0000)]
bhyve: add 'root' parameter to driver initializer

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: snapshot: Prevent too-nested domain XML when doing inactive snapshot
Peter Krempa [Mon, 20 Jan 2020 15:04:56 +0000 (16:04 +0100)]
qemu: snapshot: Prevent too-nested domain XML when doing inactive snapshot

Similarly to 510d154a0b41aa70aadabc0918d16dee22882394 we need to prevent
doing too deeply nested backing chains and reject them with a sane error
message.

Add a loop to go through the snapshots prior to attempting actually
creating them to prevent some possible inconsistent scenarios.

We don't need to do it when reusing backing chains as we'll be
re-detecting the backing chain in that case anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: snapshot: Always rewrite backingStore data when reusing existing images
Peter Krempa [Fri, 24 Jan 2020 13:14:58 +0000 (14:14 +0100)]
qemu: snapshot: Always rewrite backingStore data when reusing existing images

Don't adopt the backing store data when reusing images provided by the
user. This will force a backing chain re-probe as users might have
passed in something unexpected in the overlay where our view of the
backing chain would not correspond.

This is done only for inactive snapshots as there we have way less
verification.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agodocs: add pages to support Go module package resolution
Daniel P. Berrangé [Mon, 16 Dec 2019 10:06:50 +0000 (10:06 +0000)]
docs: add pages to support Go module package resolution

Currently the libvirt Go modules are accessed by applications using
their github repository URLs. This is undesirable as we don't want
applications to have a direct dependancy on a specific source repo
location. We want to enable applications to use the Go packages via
the libvirt.org namespace.

When you do "go get libvirt.org/libvirt-go", the Go client will do an
HTTPS request to that URL, and parse the HTML content to look for a
<meta> tag which tells it where to the find the GIT repository.

   https://golang.org/cmd/go/#hdr-Remote_import_paths

This adds two pages to support this Go module resolution. They are
not linked from anywhere as we don't expect users to actually look
at them. If someone does happen upon them, there's some boilerplate
text to send them off to godoc.org for API documentation.

Since the pages we're adding have a .html extension, we will also
use a small apache config tweak on the server

    RewriteEngine on
    RewriteRule ^/libvirt-go$ /libvirt-go.html [L]
    RewriteRule ^/libvirt-go-xml$ /libvirt-go-xml.html [L]

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: introduce a new "virt-qemu-run" program
Daniel P. Berrangé [Fri, 17 May 2019 12:01:59 +0000 (13:01 +0100)]
qemu: introduce a new "virt-qemu-run" program

The previous "QEMU shim" proof of concept was taking an approach of only
caring about initial spawning of the QEMU process. It was then
registered with the libvirtd daemon who took over management of it. The
intent was that later libvirtd would be refactored so that the shim
retained control over the QEMU monitor and libvirt just forwarded APIs
to each shim as needed. This forwarding of APIs would require quite alot
of significant refactoring of libvirtd to achieve.

This impl thus takes a quite different approach, explicitly deciding to
keep the VMs completely separate from those seen & managed by libvirtd.
Instead it uses the new "qemu:///embed" URI scheme to embed the entire
QEMU driver in the shim, running with a custom root directory.

Once the driver is initialization, the shim starts a VM and then waits
to shutdown automatically when QEMU shuts down, or should kill QEMU if
it is terminated itself. This ought to use the AUTO_DESTROY feature but
that is not yet available in embedded mode, so we rely on installing a
few signal handlers to gracefully kill QEMU. This isn't reliable if
we crash of course, but you can restart with the same root dir.

Note this program does not expose any way to manage the QEMU process,
since there's no RPC interface enabled. It merely starts the VM and
cleans up when the guest shuts down at the end. This program is
installed to /usr/bin/virt-qemu-run enabling direct use by end users.
Most use cases will probably want to integrate the concept directly
into their respective application codebases. This standalone binary
serves as a nice demo though, and also provides a way to measure
performance of the startup process quite simply.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosecrets: add support for running secret driver in embedded mode
Daniel P. Berrangé [Fri, 17 May 2019 11:35:57 +0000 (12:35 +0100)]
secrets: add support for running secret driver in embedded mode

This enables support for running the secret driver embedded to the
calling application process using a URI:

   secret:///embed?root=/some/path

When using the embedded mode with a root=/var/tmp/embed, the
driver will use the following paths:

       configDir: /var/tmp/embed/etc/secrets
        stateDir: /var/tmp/embed/run/secrets

These are identical whether the embedded driver is privileged
or unprivileged.

This compares with the system instance which uses

       configDir: /etc/libvirt/secrets
        stateDir: /var/lib/libvirt/secrets

When an embedded instance of the secret driver is open, any other
embedded drivers will automatically use the embedded secret driver.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: add support for running QEMU driver in embedded mode
Daniel P. Berrangé [Fri, 17 May 2019 11:35:57 +0000 (12:35 +0100)]
qemu: add support for running QEMU driver in embedded mode

This enables support for running QEMU embedded to the calling
application process using a URI:

   qemu:///embed?root=/some/path

Note that it is important to keep the path reasonably short to
avoid risk of hitting the limit on UNIX socket path names
which is 108 characters.

When using the embedded mode with a root=/var/tmp/embed, the
driver will use the following paths:

                logDir: /var/tmp/embed/log/qemu
           swtpmLogDir: /var/tmp/embed/log/swtpm
         configBaseDir: /var/tmp/embed/etc/qemu
              stateDir: /var/tmp/embed/run/qemu
         swtpmStateDir: /var/tmp/embed/run/swtpm
              cacheDir: /var/tmp/embed/cache/qemu
                libDir: /var/tmp/embed/lib/qemu
       swtpmStorageDir: /var/tmp/embed/lib/swtpm
 defaultTLSx509certdir: /var/tmp/embed/etc/pki/qemu

These are identical whether the embedded driver is privileged
or unprivileged.

This compares with the system instance which uses

                logDir: /var/log/libvirt/qemu
           swtpmLogDir: /var/log/swtpm/libvirt/qemu
         configBaseDir: /etc/libvirt/qemu
              stateDir: /run/libvirt/qemu
         swtpmStateDir: /run/libvirt/qemu/swtpm
              cacheDir: /var/cache/libvirt/qemu
                libDir: /var/lib/libvirt/qemu
       swtpmStorageDir: /var/lib/libvirt/swtpm
 defaultTLSx509certdir: /etc/pki/qemu

At this time all features present in the QEMU driver are available when
running in embedded mode, availability matching whether the embedded
driver is privileged or unprivileged.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agolibvirt: support an "embed" URI path selector for opening drivers
Daniel P. Berrangé [Fri, 17 May 2019 11:42:04 +0000 (12:42 +0100)]
libvirt: support an "embed" URI path selector for opening drivers

The driver URI scheme:

  "$drivername:///embed?root=/some/path"

enables a new way to use the drivers by embedding them directly in the
calling process. To use this the process must have a thread running the
libvirt event loop. This URI will then cause libvirt to dynamically load
the driver module and call its global initialization function. This
syntax is applicable to any driver, but only those will have been
modified to support a custom root directory and embed URI path will
successfully open.

The application can now make normal libvirt API calls which are all
serviced in-process with no RPC layer involved.

It is required to specify an explicit root directory, and locks will be
acquired on this directory to avoid conflicting with another app that
might accidentally pick the same directory.

Use of '/' is not explicitly forbidden, but note that the file layout
used underneath the embedded driver root does not match the file
layout used by system/session mode drivers. So this cannot be used as
a backdoor to interact with, or fake, the system/session mode drivers.

Libvirt will create arbitrary files underneath this root directory. The
root directory can be kept untouched across connection open attempts if
the application needs persistence. The application is responsible for
purging everything underneath this root directory when finally no longer
required.

Even when a virt driver is used in embedded mode, it is still possible
for it to in turn use functionality that calls out to other secondary
drivers in libvirtd. For example an embedded instance of QEMU can open
the network, secret or storage drivers in the system libvirtd.

That said, the application would typically want to at least open an
embedded secret driver ("secret:///embed?root=/some/path"). Note that
multiple different embedded drivers can use the same root prefix and
co-operate just as they would inside a normal libvirtd daemon.

A key thing to note is that for this to work, the application that links
to libvirt *MUST* be built with -Wl,--export-dynamic to ensure that
symbols from libvirt.so are exported & thus available to the dynamically
loaded driver module. If libvirt.so itself was dynamically loaded then
RTLD_GLOBAL must be passed to dlopen().

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agolibvirt: pass a directory path into drivers for embedded usage
Daniel P. Berrangé [Fri, 17 May 2019 11:30:45 +0000 (12:30 +0100)]
libvirt: pass a directory path into drivers for embedded usage

The intent here is to allow the virt drivers to be run directly embedded
in an arbitrary process without interfering with libvirtd. To achieve
this they need to store all their configuration & state in a separate
directory tree from the main system or session libvirtd instances.

This can be useful for doing testing of the virt drivers in "make check"
without interfering with the user's own libvirtd instances.

It can also be used for applications using KVM/QEMU as a piece of
infrastructure to build an service, rather than for general purpose
OS hosting. A long standing example is libguestfs, which would prefer
if its temporary VMs did show up in the main libvirtd VM list, because
this confuses apps such as OpenStack Nova. A more recent example would
be Kata which is using KVM as a technology to build containers.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: add helper API for getting URI parameters
Daniel P. Berrangé [Fri, 20 Dec 2019 14:59:47 +0000 (14:59 +0000)]
util: add helper API for getting URI parameters

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: explicitly disable virgl when requested
Jonathon Jongsma [Fri, 24 Jan 2020 23:12:26 +0000 (17:12 -0600)]
qemu: explicitly disable virgl when requested

If a domain is configured to have an egl-headless display and a virtio
video device, virgl will be enabled automatically within the guest, even
if the video device is configured with accel3d='no'.

In this case we should explicitly pass 'virgl=off' to qemu.

See https://bugzilla.redhat.com/show_bug.cgi?id=1791236 for more
information.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonews: Update news for rng backend type builtin
Han Han [Thu, 9 Jan 2020 08:00:09 +0000 (16:00 +0800)]
news: Update news for rng backend type builtin

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Implement builtin rng backend
Han Han [Thu, 9 Jan 2020 08:00:08 +0000 (16:00 +0800)]
qemu: Implement builtin rng backend

Since v4.2-rc0, QEMU introduced a builtin rng backend that uses
getrandom() syscall to generate random. Add it to libvirt with the
backend model 'builtin'.

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

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: Add rng backend model builtin
Han Han [Thu, 9 Jan 2020 08:00:07 +0000 (16:00 +0800)]
conf: Add rng backend model builtin

The 'builtin' rng backend model can be used as following:
  <rng model='virtio'>
    <backend model='builtin'/>
  </rng>

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: Do not assume comma after object id
Han Han [Thu, 9 Jan 2020 08:00:06 +0000 (16:00 +0800)]
util: Do not assume comma after object id

For qemu object like rng-builtin, there are no properties after id
property. We should always set comma after object id. Otherwise it will
cause trailing comma on object:
    -object rng-builtin,id=ID,

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu_capabilities: Introduce QEMU_CAPS_OBJECT_RNG_BUILTIN
Han Han [Thu, 9 Jan 2020 08:00:05 +0000 (16:00 +0800)]
qemu_capabilities: Introduce QEMU_CAPS_OBJECT_RNG_BUILTIN

It is used to check if qemu is capable of rng-builtin object.

This object is added since qemu-4.2.0-rc0, commit 6c4e9d48.

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu_capabilities: Rework domain caps cache
Michal Privoznik [Fri, 24 Jan 2020 09:43:29 +0000 (10:43 +0100)]
qemu_capabilities: Rework domain caps cache

Since v5.6.0-48-g270583ed98 we try to cache domain capabilities,
i.e. store filled virDomainCaps in a hash table in virQEMUCaps
for future use. However, there's a race condition in the way it's
implemented. We use virQEMUCapsGetDomainCapsCache() to obtain the
pointer to the hash table, then we search the hash table for
cached data and if none is found the domcaps is constructed and
put into the table. Problem is that this is all done without any
locking, so if there are two threads trying to do the same, one
will succeed and the other will fail inserting the data into the
table.

Also, the API looks a bit fishy - obtaining pointer to the hash
table is dangerous.

The solution is to use a mutex that guards the whole operation
with the hash table. Then, the API can be changes to return
virDomainCapsPtr directly.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu_conf: Avoid dereferencing NULL in virQEMUDriverGetHost{NUMACaps,CPU}
Michal Privoznik [Fri, 24 Jan 2020 09:24:45 +0000 (10:24 +0100)]
qemu_conf: Avoid dereferencing NULL in virQEMUDriverGetHost{NUMACaps,CPU}

When fixing [1] I've ran attached reproducer and had it spawn
1024 threads and query capabilities XML in each one of them. This
lead libvirtd to hit the RLIMIT_NOFILE limit which was kind of
expected. What wasn't expected was a subsequent segfault. It
happened because virCPUProbeHost failed and returned NULL. We've
taken the NULL and passed it to virCapabilitiesHostNUMARef()
which dereferenced it. Code inspection showed the same flas in
virQEMUDriverGetHostNUMACaps(), so I'm fixing both places.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agocpu.c: Check properly for virCapabilitiesGetNodeInfo() retval
Michal Privoznik [Fri, 24 Jan 2020 09:22:13 +0000 (10:22 +0100)]
cpu.c: Check properly for virCapabilitiesGetNodeInfo() retval

The virCapabilitiesGetNodeInfo() function has the usual return
value semantics for integeres: a negative value means an error,
zero or a positive value means success. However, the function
call done in virCPUProbeHost() doesn't check for the return value
accordingly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: monitor: Improve error message when QEMU reply is too large
Peter Krempa [Mon, 20 Jan 2020 15:06:42 +0000 (16:06 +0100)]
qemu: monitor: Improve error message when QEMU reply is too large

Don't use ERANGE as it doesn't make much sense in the error message.
Also point out that the reply from qemu was too large which is not
obvious from the original error:

 error: No complete monitor response found in 10485760 bytes: Numerical result out of range

The new message will read:

 error: internal error: QEMU monitor reply exceeds buffer size (10485760 bytes)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoqemu: block: Don't skip creation of 'luks' formatted images
Peter Krempa [Mon, 20 Jan 2020 12:02:58 +0000 (13:02 +0100)]
qemu: block: Don't skip creation of 'luks' formatted images

libvirt treats 'luks' images as raw+encryption. The logic in
qemuBlockStorageSourceCreateFormat skipped the creation if the requested
image was raw but didn't take into account the encryption.

This manifested itself e.g. when attempting to do a virsh blockcopy with
the following XML:

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/enccpy'>
        <encryption format='luks'>
          <secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f'/>
        </encryption>
      </source>
    </disk>

Where qemu would report the following error:

 unable to execute QEMU command 'blockdev-add': Volume is not in LUKS format

rather than actually formatting the image first.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agotests: hash: Test case for adding duplicate hash entry
Peter Krempa [Thu, 16 Jan 2020 14:30:53 +0000 (15:30 +0100)]
tests: hash: Test case for adding duplicate hash entry

Test that adding a duplicate entry is rejected properly. This also
allows to see the error message of the duplicate key addition in verbose
mode.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: hash: Improve debugability of "Duplicate key" error message
Peter Krempa [Thu, 16 Jan 2020 14:13:06 +0000 (15:13 +0100)]
util: hash: Improve debugability of "Duplicate key" error message

If we get a user reporting this error message being shown it's pretty
useless in terms of actually debugging it since we don't know which hash
and which key are actually subject to the error.

This patch adds a new hash table callback which formats the
user-readable version of the hash key and reports it in the new message
which will look like:

"Duplicate hash table key 'blah'"

That way we will at least have an anchor point where to start the
search.

There are two special implementations of keys which are numeric so we
add specific printer functions for them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>