]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoconf: Drop unused virDomainCapsCPUModelsFilter
Jiri Denemark [Fri, 20 Sep 2019 21:00:14 +0000 (23:00 +0200)]
conf: Drop unused virDomainCapsCPUModelsFilter

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Switch qemuCaps to use qemuMonitorCPUDefs
Jiri Denemark [Tue, 24 Sep 2019 14:38:05 +0000 (16:38 +0200)]
qemu: Switch qemuCaps to use qemuMonitorCPUDefs

We will need to keep some QEMU-specific data for each CPU model
supported by a QEMU binary. Instead of complicating the generic
virDomainCapsCPUModelsPtr, we can just directly store
qemuMonitorCPUDefsPtr returned by the capabilities probing code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Split virQEMUCapsFetchCPUModels
Jiri Denemark [Wed, 9 Oct 2019 08:16:17 +0000 (10:16 +0200)]
qemu: Split virQEMUCapsFetchCPUModels

Most of the code moved to a new virQEMUCapsFetchCPUDefinitions function
and the existing virQEMUCapsFetchCPUModels just becomes a small wrapper
around virQEMUCapsFetchCPUDefinitions and virQEMUCapsCPUDefsToModels.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions
Jiri Denemark [Wed, 9 Oct 2019 08:14:59 +0000 (10:14 +0200)]
qemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions

The functions return virDomainCapsCPUModelsPtr and thus they should be
called *CPUModels for consistency. Functions called *CPUDefinitions will
work on qemuMonitorCPUDefsPtr.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce virQEMUCapsCPUDefsToModels
Jiri Denemark [Tue, 24 Sep 2019 13:59:34 +0000 (15:59 +0200)]
qemu: Introduce virQEMUCapsCPUDefsToModels

The function translates qemuMonitorCPUDefsPtr (used by QEMU caps probing
code) into virDomainCapsCPUModelsPtr used by domain capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virDomainCapsCPUUsable in qemuMonitorCPUDefInfo
Jiri Denemark [Tue, 29 Oct 2019 13:36:11 +0000 (14:36 +0100)]
qemu: Use virDomainCapsCPUUsable in qemuMonitorCPUDefInfo

While virDomainCapsCPUModel structure contains 'usable' field with
virDomainCapsCPUUsable type, the lower level structure specific to QEMU
driver used virTriStateBool for the same thing and we had to translate
between them.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use g_autofree in virQEMUCapsLoadCPUModels
Jiri Denemark [Tue, 24 Sep 2019 12:55:26 +0000 (14:55 +0200)]
qemu: Use g_autofree in virQEMUCapsLoadCPUModels

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add qemuMonitorCPUDefsCopy
Jiri Denemark [Tue, 24 Sep 2019 15:12:34 +0000 (17:12 +0200)]
qemu: Add qemuMonitorCPUDefsCopy

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Flatten qemuMonitorCPUDefs.cpus
Jiri Denemark [Tue, 24 Sep 2019 11:45:37 +0000 (13:45 +0200)]
qemu: Flatten qemuMonitorCPUDefs.cpus

Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in
qemuMonitorCPUDefs rather then using an array of pointers.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce qemuMonitorCPUDefs struct
Jiri Denemark [Tue, 24 Sep 2019 11:42:00 +0000 (13:42 +0200)]
qemu: Introduce qemuMonitorCPUDefs struct

It is a container for a CPU models list (qemuMonitorCPUDefInfo) and a
number of elements in this list.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Change return type of virQEMUCapsFetchCPUDefinitions
Jiri Denemark [Thu, 10 Oct 2019 14:44:40 +0000 (16:44 +0200)]
qemu: Change return type of virQEMUCapsFetchCPUDefinitions

The function would return a valid virDomainCapsCPUModelsPtr with empty
CPU models list if query-cpu-definitions exists in QEMU, but returns
GenericError meaning it's not in fact implemented. This behaviour is a
bit strange especially after such virDomainCapsCPUModels structure is
stored in capabilities XML and parsed back, which will result in NULL
virDomainCapsCPUModelsPtr rather than a structure containing nothing.

Let's just keep virDomainCapsCPUModelsPtr NULL if the QMP command is not
implemented and change the return value to int so that callers can
easily check for failure or success.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use g_autoptr in qemuMonitorJSONGetCPUDefinitions
Jiri Denemark [Tue, 24 Sep 2019 11:20:49 +0000 (13:20 +0200)]
qemu: Use g_autoptr in qemuMonitorJSONGetCPUDefinitions

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virQEMUCapsGetCPUDefinitions more
Jiri Denemark [Fri, 20 Sep 2019 20:54:13 +0000 (22:54 +0200)]
qemu: Use virQEMUCapsGetCPUDefinitions more

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Filter models in virQEMUCapsGetCPUDefinitions
Jiri Denemark [Fri, 20 Sep 2019 20:48:13 +0000 (22:48 +0200)]
qemu: Filter models in virQEMUCapsGetCPUDefinitions

Some callers of virQEMUCapsGetCPUDefinitions will need to filter the
returned list of CPU models. Let's add the filtering parameters directly
to virQEMUCapsGetCPUDefinitions to avoid copying the CPU models list
twice.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Copy CPU models in virQEMUCapsGetCPUDefinitions
Jiri Denemark [Fri, 20 Sep 2019 20:41:34 +0000 (22:41 +0200)]
qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions

Rather than returning a direct pointer the list stored in qemuCaps the
function now creates a new copy of the CPU models list.

The main purpose of this seemingly useless change is to update callers
to free the result returned by virQEMUCapsGetCPUDefinitions because the
internals of this function will change significantly in the following
patches.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: Update 4.2.0 capabilities data on ppc64
Jiri Denemark [Thu, 31 Oct 2019 14:47:09 +0000 (15:47 +0100)]
tests: Update 4.2.0 capabilities data on ppc64

Generated with "spapr/kvm: Set default cpu model for all machine
classes" fix for QEMU applied.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: Add capabilities for QEMU 4.2.0 on s390x
Jiri Denemark [Tue, 15 Oct 2019 11:48:34 +0000 (13:48 +0200)]
tests: Add capabilities for QEMU 4.2.0 on s390x

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agosrc: rewrite polkit ACL generator in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite polkit ACL generator in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the genpolkit.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite ACL rule checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite ACL rule checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-aclrules.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite driver impl checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite driver impl checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-driverimpls.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite driver name checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite driver name checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-drivername.pl tool in Python.

This was mostly a straight conversion, manually going line-by-line
to change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

In testing though it was discovered the existing code was broken
since it hadn't been updated after driver.h was split into many
files. Since the old code is being thrown away, the fix was done
as part of the rewrite rather than split into a separate commit.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite systemtap function generator in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite systemtap function generator in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the gensystemtap.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite systemtap probe generator in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite systemtap probe generator in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the dtrace2systemtap.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

The "--with-modules" flag was dropped because this functionality
is not implicitly always enabled.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite symfile library checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite symfile library checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-symfile.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite symfile sorting checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite symfile sorting checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-symsorting.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: rewrite ACL permissions checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
src: rewrite ACL permissions checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the check-aclperms.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobuild-aux: rewrite header ifdef checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
build-aux: rewrite header ifdef checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the header-ifdef.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobuild-aux: rewrite mock inline checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
build-aux: rewrite mock inline checker in Python

As part of a goal to eliminate Perl from libvirt build tools,
rewrite the mock-noinline.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: checkpoint: Use qemuMonitorTransactionBitmapMergeSourceAddBitmap
Peter Krempa [Mon, 7 Oct 2019 14:33:49 +0000 (16:33 +0200)]
qemu: checkpoint: Use qemuMonitorTransactionBitmapMergeSourceAddBitmap

Use the new helper in qemuCheckpointDiscard rather than constructing the
array manually.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Forcibly mknod() even if it exists
Michal Privoznik [Fri, 8 Nov 2019 08:41:35 +0000 (09:41 +0100)]
qemu: Forcibly mknod() even if it exists

Another weird bug appeared concerning qemu namespaces. Basically
the problem is as follows:

1) Issue an API that causes libvirt to create a node in domain's
   namespace, say /dev/nvme0n1 with 8:0 as major:minor (the API can
   be attach-disk for instance). Or simply create the node from a
   console by hand.

2) Detach the disk from qemu.

3) Do something that makes /dev/nvme0n1 change it's minor number.

4) Try to attach the disk again.

The problem is, in a few cases - like disk-detach - we don't
remove the corresponding /dev node from the mount namespace
(because it may be used by some other disk's backing chain). But
this creates a problem, because if the node changes its MAJ:MIN
numbers we don't propagate the change into the domain's
namespace. We do plain mknod() and ignore EEXIST which obviously
is not enough because it doesn't guarantee that the node has
updated MAJ:MIN pair.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agognulib: remove mk*temp modules
Ján Tomko [Wed, 20 Nov 2019 12:07:18 +0000 (13:07 +0100)]
gnulib: remove mk*temp modules

After commits 4ac47730408eaf91683f6502ec10541f4f711a5c and
ef88698668e4a87c794d70879eeffefb52aa0017, we use the GLib versions
of these functions.

Remove the corresponding gnulib modules.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agobootstrap.conf: drop c-strcasestr gnulib module
Pavel Hrdina [Tue, 19 Nov 2019 14:22:58 +0000 (15:22 +0100)]
bootstrap.conf: drop c-strcasestr gnulib module

Last usage was removed by commit
<41f88886198e231285cc813f8c0687c8ec5c9488> and commit
<0f4d31720430b4e3735064cc0d8f88a1a438e154> forgot to drop include.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agognulib: Remove use of 'strsep' module
Peter Krempa [Thu, 14 Nov 2019 09:31:53 +0000 (10:31 +0100)]
gnulib: Remove use of 'strsep' module

We don't use strsep any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agobootstrap: remove regex module
Ján Tomko [Wed, 13 Nov 2019 15:57:53 +0000 (16:57 +0100)]
bootstrap: remove regex module

Now that we use GRegex everywhere, there is no need for this module.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agosyntax-check: forbid usage of snprintf
Pavel Hrdina [Wed, 13 Nov 2019 16:33:27 +0000 (17:33 +0100)]
syntax-check: forbid usage of snprintf

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agosyntax-check: update of sprintf rule to mention g_snprintf
Pavel Hrdina [Wed, 13 Nov 2019 16:33:26 +0000 (17:33 +0100)]
syntax-check: update of sprintf rule to mention g_snprintf

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agobootstrap.conf: remove usage of snprintf gnulib module
Pavel Hrdina [Wed, 13 Nov 2019 16:33:25 +0000 (17:33 +0100)]
bootstrap.conf: remove usage of snprintf gnulib module

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agognulib: remove use of 'vsnprintf' module
Ján Tomko [Wed, 13 Nov 2019 13:18:18 +0000 (14:18 +0100)]
gnulib: remove use of 'vsnprintf' module

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agognulib: remove use of 'byteswap' module
Ján Tomko [Wed, 13 Nov 2019 13:17:31 +0000 (14:17 +0100)]
gnulib: remove use of 'byteswap' module

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agognulib: remove 'areadlink' module
Peter Krempa [Wed, 13 Nov 2019 13:16:42 +0000 (14:16 +0100)]
gnulib: remove 'areadlink' module

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Remove non-transaction based dirty bitmap APIs
Peter Krempa [Thu, 26 Sep 2019 15:00:44 +0000 (17:00 +0200)]
qemu: monitor: Remove non-transaction based dirty bitmap APIs

We replaced them by use of transaction to simplify possible failure
scenarios.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: checkpoint: Fix rollback and access to unlocked 'vm' when deleting checkpoints
Peter Krempa [Thu, 26 Sep 2019 14:56:16 +0000 (16:56 +0200)]
qemu: checkpoint: Fix rollback and access to unlocked 'vm' when deleting checkpoints

Delete/merge bitmaps when deleting checkpoints using a 'transaction' so
that we don't have to deal with halfway-failed scenarios and also fix
access to 'vm' while in the monitor lock.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: virschema: Propagate errors from directory traversal in testSchemaDir
Peter Krempa [Tue, 19 Nov 2019 10:55:05 +0000 (11:55 +0100)]
tests: virschema: Propagate errors from directory traversal in testSchemaDir

testSchemaDir is a helper which invokes the schema test using virTestRun
on all schema files. Since the function itself is not called inside
virTestRun any helper function call is not dispatched to the user and
thus it's hard to debug the test. Propagate errors from the directory
traversal.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: utils: Introduce helper for dispatching libvirt errors
Peter Krempa [Tue, 19 Nov 2019 10:52:40 +0000 (11:52 +0100)]
tests: utils: Introduce helper for dispatching libvirt errors

In cases when we call a libvirt helper which reports an error the error
would be hidden unless libvirt library debug is on. This produces a lot
of output and is hard to debug.

The helper provides a way to dispatch the libvirt error in specific
cases sice we do already dispatch it in case when virTestRun is used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: schema: Simplify memory handling using g_autofree
Peter Krempa [Tue, 19 Nov 2019 10:16:34 +0000 (11:16 +0100)]
tests: schema: Simplify memory handling using g_autofree

Refactor various functions to avoid multiple freeing function calls.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolib: fix documentation typo in virDomainGetGuestInfo()
Jonathon Jongsma [Tue, 19 Nov 2019 19:59:06 +0000 (13:59 -0600)]
lib: fix documentation typo in virDomainGetGuestInfo()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agoremote_daemon_stream: Fix @client locking in daemonStreamFilter()
LanceLiu [Tue, 19 Nov 2019 11:39:50 +0000 (19:39 +0800)]
remote_daemon_stream: Fix @client locking in daemonStreamFilter()

When dispatching a message read from client it is first passed
through registered filters. If one of the filters consumes the
message no further processing of the message is done. However,
the filter callbacks are called with the client object locked.
This breaks lock ordering in case of virStream filter, we always
acquire stream private data lock without the client object
locked. In other words, the daemonStreamFilter() does not follow
the lock ordering.

Signed-off-by: LanceLiu <liu.lance.89@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:29 +0000 (17:46 -0300)]
tests: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovbox: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:28 +0000 (17:46 -0300)]
vbox: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:27 +0000 (17:46 -0300)]
qemu: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonetwork: Check for QOS before blindly using it
John Ferlan [Tue, 12 Nov 2019 23:36:22 +0000 (18:36 -0500)]
network: Check for QOS before blindly using it

If networkAllocatePort calls networkPlugBandwidth eventually the
port->bandwidth would be passed to virNetDevBandwidthPlug which
requires that the parameter is non-NULL.  Coverity additionally
notes that since (!port->bandwidth) is checked earlier in the
networkAllocatePort method that the subsequent call to blindly
use if for a function that requires it needs to check.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agonetwork: Use local variables in networkUpdatePortBandwidth
John Ferlan [Tue, 12 Nov 2019 21:15:04 +0000 (16:15 -0500)]
network: Use local variables in networkUpdatePortBandwidth

We go through the trouble of checking {old|new}Bandwidth[->in] and
storing the result in local @old_floor and @new_floor, but then
we don't use them. Instead we make derefs to the longer name. This
caused Coverity to note dereferencing newBandwidth->in without first
checking @newBandwidth like was done for new_floor could cause a
NULL dereference.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoutil: Remove unnecessary check in virFileRewrite
John Ferlan [Tue, 12 Nov 2019 21:10:12 +0000 (16:10 -0500)]
util: Remove unnecessary check in virFileRewrite

Since g_strdup_printf will abort, we know @newfile won't be NULL.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemuProcessStop: Set @def early
Michal Privoznik [Mon, 18 Nov 2019 16:39:46 +0000 (17:39 +0100)]
qemuProcessStop: Set @def early

The @def variable holds pointer to the domain defintion, but is
set only somewhere in the middle of the function. This is
suboptimal.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoAdd news for virDomainAgentSetResponseTimeout()
Jonathon Jongsma [Mon, 18 Nov 2019 22:38:49 +0000 (16:38 -0600)]
Add news for virDomainAgentSetResponseTimeout()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agog_mkstemp_full: pass O_RDWR
Ján Tomko [Mon, 18 Nov 2019 16:45:54 +0000 (17:45 +0100)]
g_mkstemp_full: pass O_RDWR

This flag is not implied by g_mkstemp_full, only by g_mkstemp.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Bjoern Walk <bwalk@linux.ibm.com>
Fixes: 4ac47730408eaf91683f6502ec10541f4f711a5c
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agobuild-aux: rewrite duplicate header checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
build-aux: rewrite duplicate header checker in Python

As part of an goal to eliminate Perl from libvirt build tools,
rewrite the prohibit-duplicate-header.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Fix NULL ptr dereference caused by qemuDomainDefFormatBufInternal
Erik Skultety [Mon, 18 Nov 2019 12:46:14 +0000 (13:46 +0100)]
qemu: Fix NULL ptr dereference caused by qemuDomainDefFormatBufInternal

qemuDomainDefFormatBufInternal function wasn't testing whether the CPU
was actually defined in the XML and saving such a domain resulted in the
following backtrace:

0 in qemuDomainMakeCPUMigratable (cpu=0x0)
1 in qemuDomainDefFormatBufInternal()
2 in qemuDomainDefFormatXMLInternal()
3 in qemuDomainDefFormatLive()
4 in qemuDomainSaveInternal()
5 in qemuDomainSaveFlags()
6 in qemuDomainSave()
7 in virDomainSave()

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_process: fix starting VMs if machine group has limited cpuset.cpus
Pavel Hrdina [Thu, 7 Nov 2019 21:23:04 +0000 (22:23 +0100)]
qemu_process: fix starting VMs if machine group has limited cpuset.cpus

Commit <f136b83139c63f20de0df3285d9e82df2fb97bfc> reworked process
affinity setting but did not take cgroups into account which introduced
an issue when starting VM with custom cpuset.cpus for the whole machine
group.

If the machine group is limited to some pCPUs libvirt should not try to
set a VM to run on all pCPUs as it will result in permission denied when
writing to cpuset.cpus.

To fix this the affinity has to be set separately from cgroups cpuset.

Resolves: <https://bugzilla.redhat.com/show_bug.cgi?id=1746517>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirbpf: Fix typecast to __aligned_u64 type
Michal Privoznik [Mon, 18 Nov 2019 07:33:40 +0000 (08:33 +0100)]
virbpf: Fix typecast to __aligned_u64 type

In functions implemented here we fill this attr union (type of
bpf_attr) and just pass it to syscall(2). Thing is that some of
the union members are type of __aligned_u64. This is not regular
uint64_t. This one is explicitly aligned to 8 bytes, while
uint64_t can be aligned to 4 bytes (on 32 bits). We've used
explicit typecast to uint64_t to shut compiler which would
otherwise complain of assigning a pointer into an integer. Well,
we have uintptr_t just for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovircgroupv2devices: Fix format string for size_t variable
Michal Privoznik [Mon, 18 Nov 2019 07:10:15 +0000 (08:10 +0100)]
vircgroupv2devices: Fix format string for size_t variable

In virCgroupV2DevicesReallocMap() we are debug printing both
arguments passed to the function. However, the @size argument is
type of size_t but '%lu' is used to format it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonews: mention 'ramfb' mdev attribute
Jonathon Jongsma [Fri, 15 Nov 2019 15:58:52 +0000 (09:58 -0600)]
news: mention 'ramfb' mdev attribute

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agovirbpf: Check if syscall() is available
Michal Privoznik [Fri, 15 Nov 2019 15:08:51 +0000 (16:08 +0100)]
virbpf: Check if syscall() is available

There are some OSes which don't have syscall() nor
<sys/syscall.h>. We already check for the header file in
configure phase, so we just need to add check for
HAVE_SYS_SYSCALL_H to HAVE_DECL_BPF_PROG_QUERY.

While I'm at it, some header files we are including are not
needed, so their includes can be safely dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agospec: Remove build-time list of edk2 firmwares
Jim Fehlig [Thu, 14 Nov 2019 16:06:43 +0000 (09:06 -0700)]
spec: Remove build-time list of edk2 firmwares

Fedora now advertises supported firmwares via descriptor files.
Since the upstream spec file assumes recent Fedora, remove the
build-time list of firmwares, which can produce a warning after
commit 75597f022a.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: validate video resolution
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:17 +0000 (15:59 -0600)]
conf: validate video resolution

Ensure that both x and y are non-zero when resolution is specified for a
video device.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: report errors when parsing video acceleration
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:16 +0000 (15:59 -0600)]
conf: report errors when parsing video acceleration

Since this function is now only called when an 'acceleration' element is
present in the xml, any failure to parse the element will be considered
an error.

Previously, we detected some types of errors, but we would only log an
error (virReportError()), but still return a partially-specified accel
object to the caller. This patch returns NULL for all parsing errors and
reports that error back up to the caller.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: report errors when parsing video resolution
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:15 +0000 (15:59 -0600)]
conf: report errors when parsing video resolution

The current code doesn't properly handle errors when parsing a video
device's resolution.  We were returning a NULL structure for the case
where 'x' or 'y' were missing. But for the other error cases, we were
logging an error (virReportError()), but still returning an
under-specified structure. That under-specified structure was used by
the calling function rather than properly reporting an error.

This patch changes the parse function to return NULL on any parsing
error and changes the calling function to report an error when NULL is
returned.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: iterate video model children in parent function
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:14 +0000 (15:59 -0600)]
conf: iterate video model children in parent function

Previously, we were passing the video "model" node to the "acceleration"
and "resolution" parsing functions and requiring them to iterate over
the children to discover and parse the appropriate node. It makes more
sense to move this responsibility up to the parent function and just
pass these functions the node that needs to be parsed.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agovircgroup: Ensure /machine group is associated with its parent
Miguel Ángel Arruga Vivas [Mon, 4 Nov 2019 14:55:23 +0000 (15:55 +0100)]
vircgroup: Ensure /machine group is associated with its parent

Call first virCgroupNew on the parent group virCgroupNewPartition if
it is available on before the creation of the child group.  This
ensures that the creation of a first level group on the unified
architecture, as the check at virCgroupV2ParseControllersFile as the
parent file is there.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1760233
Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodoc: cgroups: Remove unwanted references to systemd
Miguel Ángel Arruga Vivas [Mon, 4 Nov 2019 14:55:22 +0000 (15:55 +0100)]
doc: cgroups: Remove unwanted references to systemd

The non-systemd configurations do not create system neither user
control groups.  The title of the diagram referenced systemd too.

Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoAllow a zfs pool or dataset as source for zfs storage backend
Gregor Kopka [Thu, 7 Nov 2019 04:03:14 +0000 (04:03 +0000)]
Allow a zfs pool or dataset as source for zfs storage backend

Enables hosting a pool on an existing zfs pool without affecting
other datasets there.
Specify dataset instead of pool as source to use.
Parent of dataset must exist for pool-build to succeed.
Beware that pool-delete destroys the source dataset and all children.

Solves: https://www.redhat.com/archives/libvirt-users/2017-April/msg00041.html

Signed-off-by: Gregor Kopka <gregor@kopka.net>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoreplace use of gnulib snprintf by g_snprintf
Pavel Hrdina [Wed, 13 Nov 2019 13:53:42 +0000 (14:53 +0100)]
replace use of gnulib snprintf by g_snprintf

Glib implementation follows the ISO C99 standard so it's safe to replace
the gnulib implementation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovircgroupmock: mock virCgroupV2DevicesAvailable
Pavel Hrdina [Mon, 24 Jun 2019 13:13:37 +0000 (15:13 +0200)]
vircgroupmock: mock virCgroupV2DevicesAvailable

We need to mock virCgroupV2DevicesAvailable() in order to remove any
dependency on kernel as BPF devices might not be available.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: workaround devices in hybrid mode
Pavel Hrdina [Thu, 14 Nov 2019 10:44:42 +0000 (11:44 +0100)]
vircgroup: workaround devices in hybrid mode

So the issue here is that you can end up with configuration where
you have cgroup v1 and v2 enabled at the same time and the devices
controllers is enabled for cgroup v1.

In cgroup v2 there is no devices controller, the device access is
controlled using BPF and since it is not a cgroup controller both
of them can exists at the same time and both of them are applied while
resolving access to devices.

In order to avoid configuring both BPF and cgroup v1 devices we will
use BPF if possible and otherwise fallback to cgroup v1 devices.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DenyAllDevices
Pavel Hrdina [Fri, 11 Jan 2019 13:56:48 +0000 (14:56 +0100)]
vircgroup: introduce virCgroupV2DenyAllDevices

If we want to deny all devices we just need to replace any existing
program with new program with empty map.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2AllowAllDevices
Pavel Hrdina [Fri, 11 Jan 2019 13:56:17 +0000 (14:56 +0100)]
vircgroup: introduce virCgroupV2AllowAllDevices

If we want to allow all devices with all permissions we need to replace
any existing program that has any rule configured, otherwise we just
need to add new rule which will for example allow read access to all
devices.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DenyDevice
Pavel Hrdina [Fri, 11 Jan 2019 13:55:49 +0000 (14:55 +0100)]
vircgroup: introduce virCgroupV2DenyDevice

In order to deny device we need to check if there is any entry in BPF
map and we need to load the current value from map if there is already
entry for that device.  If both values are same we can remove that entry
but if they are different we need to update the entry because we don't
have to deny all access, but for example only write access.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2AllowDevice
Pavel Hrdina [Wed, 24 Apr 2019 10:10:08 +0000 (12:10 +0200)]
vircgroup: introduce virCgroupV2AllowDevice

In order to allow device we need to create key and value which will be
used to update BPF map.  virBPFUpdateElem() can override existing
entries in BPF map so we need to check if that entry exists in order to
track number of entries in our map.

This can add rule for specific device but major and minor can be both
-1 which follows the same behavior as in cgroup v1.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesGetKey
Pavel Hrdina [Mon, 24 Jun 2019 12:46:53 +0000 (14:46 +0200)]
vircgroup: introduce virCgroupV2DevicesGetKey

Device rules are stored in BPF map that is a hash type, this function
will create a key based on major and minor id of device.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DeviceGetPerms
Pavel Hrdina [Mon, 24 Jun 2019 12:41:50 +0000 (14:41 +0200)]
vircgroup: introduce virCgroupV2DeviceGetPerms

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesRemoveProg
Pavel Hrdina [Mon, 24 Jun 2019 12:39:23 +0000 (14:39 +0200)]
vircgroup: introduce virCgroupV2DevicesRemoveProg

We need to close our FD that we have for BPF program and map in order
to let kernel remove all resources once the cgroup is removed as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesPrepareProg
Pavel Hrdina [Mon, 24 Jun 2019 12:34:51 +0000 (14:34 +0200)]
vircgroup: introduce virCgroupV2DevicesPrepareProg

This function will be called for every virCgroup(Allow|Deny)* API in
order to prepare BPF program for guest.  Since libvirtd can be restarted
at any point we will first try to detect existing progam, if there is
none we will create a new empty BPF program and lastly if we don't have
any space left in the existing BPF map we will create a new copy of the
BPF map with more space and attach a new program with that map into the
guest cgroup.

This solution allows us to start with reasonably small BPF map consuming
only small amount of memory and if needed we can easily extend the BPF
map if there is a lot of host devices used in guest or if user wants to
hot-plug a lot of devices once the guest is running.

Since there is no way how to reallocate existing BPF map we need to
create a new copy if we run out of space in current BPF map.

This overcomes all the limitations in BPF:

    - map used in program has to be created before the program is loaded
      into kernel

    - once map is created you cannot change its size

    - you cannot replace map in existing program

    - you cannot use an array of maps because it can store FD to maps
      of one specific size so we would not be able to use it to overcome
      the second issue

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesCreateProg
Pavel Hrdina [Mon, 24 Jun 2019 12:30:59 +0000 (14:30 +0200)]
vircgroup: introduce virCgroupV2DevicesCreateProg

This function creates new BPF program with new empty BPF map with the
default size and attaches it to the guest cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesDetectProg
Pavel Hrdina [Mon, 24 Jun 2019 12:25:04 +0000 (14:25 +0200)]
vircgroup: introduce virCgroupV2DevicesDetectProg

This function will be called if libvirtd was restarted while some
domains were running.  It will try to detect existing programs attached
to the guest cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesAttachProg
Pavel Hrdina [Mon, 24 Jun 2019 12:15:31 +0000 (14:15 +0200)]
vircgroup: introduce virCgroupV2DevicesAttachProg

This function loads the BPF prog with prepared map into kernel and
attaches it into guest cgroup.  It can be also used to replace existing
program in the cgroup if we need to resize BPF map to store more rules
for devices. The old program will be closed and removed from kernel.

There are two possible ways how to create BPF program:

    - One way is to write simple C-like code which can by compiled into
      BPF object file which can be loaded into kernel using elfutils.

    - The second way is to define macros which look like assembler
      instructions and can be used directly to create BPF program that
      can be directly loaded into kernel.

Since the program is not too complex we can use the second option.

If there is no program, all devices are allowed, if there is some
program it is executed and based on the exit status the access is
denied for 0 and allowed for 1.

Our program will follow these rules:

    - first it will try to look for the specific key using major and
      minor to see if there is any rule for that specific device

    - if there is no specific rule it will try to look for any rule that
      matches only major of the device

    - if there is no match with major it will try the same but with
      minor of the device

    - as the last attempt it will try to look for rule for all devices
      and if there is no match it will return 0 to deny that access

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesAvailable
Pavel Hrdina [Mon, 9 Sep 2019 07:40:06 +0000 (09:40 +0200)]
vircgroup: introduce virCgroupV2DevicesAvailable

There is no exact way how to figure out whether BPF devices support is
compiled into kernel.  One way is to check kernel configure options but
this is not reliable as it may not be available.  Let's try to do
syscall to which will list BPF cgroup device programs.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: introduce virbpf helpers
Pavel Hrdina [Mon, 9 Sep 2019 07:37:32 +0000 (09:37 +0200)]
util: introduce virbpf helpers

In order to implement devices controller with cgroup v2 we need to
add support for BPF programs, cgroup v2 doesn't have devices controller.

This introduces required helpers wrapping linux syscalls.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: Mock access to /dev/kvm
Michal Privoznik [Fri, 15 Nov 2019 10:56:46 +0000 (11:56 +0100)]
tests: Mock access to /dev/kvm

Some of our tests try to validate domain XMLs they are working
with (not intentionally, simply because they call top level
domain XML parse function). Anyway, this implies that we build
domain capabilities also - see
virQEMUDriverGetDomainCapabilities(). And since some domain XMLs
are type of 'kvm' the control gets through
virQEMUCapsFillDomainCaps() and virHostCPUGetKVMMaxVCPUs() to
opening /dev/kvm which may be missing on the machine we're
running 'make check'.

Previously, we did not see this issue, because it was masked. If
building domain capabilities failed for whatever reason, we
ignored the failure. Only v5.9.0-207-gc69e6edea3 uncovered the
problem (it changed reval from 0 to -1 if
virQEMUDriverGetDomainCapabilities() fails). Since the referenced
commit is correct, we need to mock access to /dev/kvm in our
tests.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirsh: Fix typo in the man page
Jiri Denemark [Fri, 15 Nov 2019 08:34:20 +0000 (09:34 +0100)]
virsh: Fix typo in the man page

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoAdd API to change qemu agent response timeout
Jonathon Jongsma [Wed, 13 Nov 2019 22:06:09 +0000 (16:06 -0600)]
Add API to change qemu agent response timeout

Some layered products such as oVirt have requested a way to avoid being
blocked by guest agent commands when querying a loaded vm. For example,
many guest agent commands are polled periodically to monitor changes,
and rather than blocking the calling process, they'd prefer to simply
time out when an agent query is taking too long.

This patch adds a way for the user to specify a custom agent timeout
that is applied to all agent commands.

One special case to note here is the 'guest-sync' command. 'guest-sync'
is issued internally prior to calling any other command. (For example,
when libvirt wants to call 'guest-get-fsinfo', we first call
'guest-sync' and then call 'guest-get-fsinfo').

Previously, the 'guest-sync' command used a 5-second timeout
(VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT), whereas the actual command that
followed always blocked indefinitely
(VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK). As part of this patch, if a
custom timeout is specified that is shorter than
5 seconds,  this new timeout is also used for 'guest-sync'. If there is
no custom timeout or if the custom timeout is longer than 5 seconds, we
will continue to use the 5-second timeout.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: prefer g_mkstemp_full and g_mkdtemp
Ján Tomko [Thu, 14 Nov 2019 13:44:24 +0000 (14:44 +0100)]
syntax-check: prefer g_mkstemp_full and g_mkdtemp

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoUse g_mkdtemp instead of mkdtemp
Ján Tomko [Wed, 13 Nov 2019 21:35:47 +0000 (22:35 +0100)]
Use g_mkdtemp instead of mkdtemp

Prefer the GLib version to the one from gnulib.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoUse g_mkstemp_full instead of mkostemp(s)
Ján Tomko [Wed, 13 Nov 2019 21:30:26 +0000 (22:30 +0100)]
Use g_mkstemp_full instead of mkostemp(s)

With g_mkstemp_full, there is no need to distinguish between
mkostemp and mkostemps (no suffix vs. a suffix of a fixed length),
because the GLib function looks for the XXXXXX pattern everywhere
in the string.

Use S_IRUSR | S_IWUSR for the permissions and do not pass O_RDWR
in flags since it's implied.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agotests: use GRegex in vboxsnapshotxmltest
Ján Tomko [Wed, 13 Nov 2019 15:06:45 +0000 (16:06 +0100)]
tests: use GRegex in vboxsnapshotxmltest

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virStringMatch
Ján Tomko [Wed, 13 Nov 2019 15:01:19 +0000 (16:01 +0100)]
util: use GRegex in virStringMatch

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virStringSearch
Ján Tomko [Wed, 13 Nov 2019 14:54:43 +0000 (15:54 +0100)]
util: use GRegex in virStringSearch

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex for virLogRegex
Ján Tomko [Wed, 13 Nov 2019 14:38:58 +0000 (15:38 +0100)]
util: use GRegex for virLogRegex

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virCommandRunRegex
Ján Tomko [Wed, 13 Nov 2019 14:09:28 +0000 (15:09 +0100)]
util: use GRegex in virCommandRunRegex

This saves us from allocating vars upfront, since GLib deals with
that for us.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agostorage: use GRegex virStorageBackendLogicalParseVolExtents
Ján Tomko [Wed, 13 Nov 2019 13:32:19 +0000 (14:32 +0100)]
storage: use GRegex virStorageBackendLogicalParseVolExtents

Using GRegex simplifies the code since g_match_info_fetch will
copy the matched substring for us.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: remove 'ret' from xenParseSxprVifRate
Ján Tomko [Wed, 13 Nov 2019 12:09:11 +0000 (13:09 +0100)]
libxl: remove 'ret' from xenParseSxprVifRate

Now that the cleanup section is empty, the ret variable is no longer
necessary.

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