]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
4 years agoremote: push logic for default netcat binary into common helper
Daniel P. Berrangé [Tue, 21 Jul 2020 11:15:57 +0000 (12:15 +0100)] 
remote: push logic for default netcat binary into common helper

We don't want to repeat the choice of default netcat binary setting in
three different places. This will also make it possible to do better
error reporting in the helper.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agorpc: merge logic for generating remote SSH shell script
Daniel P. Berrangé [Tue, 11 Feb 2020 19:05:53 +0000 (19:05 +0000)] 
rpc: merge logic for generating remote SSH shell script

Three parts of the code all build up the same SSH shell script
snippet for remote tunneling the RPC protocol, but in slightly
different ways. Combine them all into one helper method in the
virNetClient code, since this logic doesn't really belong in
the virNetSocket code.

Note that the this change means the shell snippet is passed to
the SSH binary as a single arg, instead of three separate args,
but this is functionally identical, as the three separate args
were combined into one already when passed to the remote system.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agodisk storage: fix allocation size for pool format dos
Sebastian Mitterle [Sat, 29 Aug 2020 00:49:07 +0000 (00:49 +0000)] 
disk storage: fix allocation size for pool format dos

The changed condition was always false because the function was always
called with boundary values 0.

Use the free extent's start value to get its start offset from the
cylinder boundary and determine if the needed size for allocation
needs to be expanded too in case the offset doesn't fit within extra
bytes for alignment.

This fixes an issue where vol-create-from will call qemu-img convert
to create a destination volume of same capacity as the source volume
and qemu-img will error 'Cannot grow device files' due to the partition
being too small for the source although both destination partition and
source volume have the same capacity.

Signed-off-by: Sebastian Mitterle <smitterl@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodoc: add some examples for IPv6 NAT configuration
Ian Wienand [Wed, 12 Aug 2020 01:21:47 +0000 (11:21 +1000)] 
doc: add some examples for IPv6 NAT configuration

Add some expanded examples for the nat ipv6 introduced with
927acaedec7effbe67a154d8bfa0e67f7d08e6c7.

Unfortunately while for IPv4 it's well-known what addresses ranges are
useful for NAT, with IPv6 unless you enjoy digging through RFC's going
back-and-forth over unique local addresses and the meaning of the word
"site" it's generally much less obvious.  I've tried to add some
details on choosing a range inline with RFC 4193 and then some
pointers for when it maybe doesn't work in the guest as you first
expect despite you doing what the RFC's say!

Signed-off-by: Ian Wienand <iwienand@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoclient: fix memory leak in client msg
Hao Wang [Sat, 18 Jul 2020 07:43:30 +0000 (15:43 +0800)] 
client: fix memory leak in client msg

When closing client->waitDispatch in virNetClientIOEventLoopRemoveAll
or virNetClientIOEventLoopRemoveDone, VIR_FREE() is called to free
call->msg directly, resulting in leak of the memory call->msg->buffer
points to.
Use virNetMessageFree(call->msg) instead of VIR_FREE(call->msg).

Signed-off-by: Hao Wang <wanghao232@huawei.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemuFirmwareFillDomain: Fill NVRAM template on migration too
Michal Privoznik [Tue, 8 Sep 2020 15:42:09 +0000 (17:42 +0200)] 
qemuFirmwareFillDomain: Fill NVRAM template on migration too

In 8e1804f9f66 I've tried to fix the following use case: domain
is started with path to UEFI only and relies on libvirt to figure
out corresponding NVRAM template to create a per-domain copy
from. The fix consisted of having a check tailored exactly for
this use case and if it's hit then using FW autoselection to
figure it out. Unfortunately, the NVRAM template is not saved in
the inactive XML (well, the domain might be transient anyway).
Then, as a part of that check we see whether the per-domain copy
doesn't exist already and if it does then no template is looked
up hence no template will appear in the live XML.

This works, until the domain is migrated. At the destination, the
per-domain copy will not exist so we need to know the template to
create the per-domain copy from. But we don't even get to the
check because we are not starting a fresh new domain and thus the
qemuFirmwareFillDomain() function quits early.

The solution is to switch order of these two checks. That is
evaluate the check for the old style before checking flags.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1852910
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agovirsh: cmdScreenshot: fix cbdata passing to virshStreamSink
Ján Tomko [Wed, 9 Sep 2020 08:55:40 +0000 (10:55 +0200)] 
virsh: cmdScreenshot: fix cbdata passing to virshStreamSink

The changes for sparse stream support started passing
virshStreamCallbackDataPtr to virshStreamSink
instead of passing a simple file descriptor, but
forgot to adjust all the callers.

Fix it in cmdScreenshot as well.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 9e745a97171e10f050962c166082439d6724e245
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agocpu_ppc64: Remove error path in virCPUppc64DriverGetModels
Tim Wiederhake [Wed, 9 Sep 2020 06:37:51 +0000 (08:37 +0200)] 
cpu_ppc64: Remove error path in virCPUppc64DriverGetModels

The call to `g_strfreev` is not required, as in both cases no memory has been allocated.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_map: Use g_auto* in loadData
Tim Wiederhake [Wed, 9 Sep 2020 06:37:50 +0000 (08:37 +0200)] 
cpu_map: Use g_auto* in loadData

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use g_autoptr() whenever possible
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:46 +0000 (17:25 -0300)] 
cpu_ppc64.c: use g_autoptr() whenever possible

Using g_autoptr() in virCPUDef pointers allows for more
cleanups in ppc64Compute() and virCPUppc64Baseline()

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use g_autofree() whenever possible
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:45 +0000 (17:25 -0300)] 
cpu_ppc64.c: use g_autofree() whenever possible

This allows for a label removal in ppc64ModelParse().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use g_autoptr() in virCPUppc64GetHost()
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:44 +0000 (17:25 -0300)] 
cpu_ppc64.c: use g_autoptr() in virCPUppc64GetHost()

We don't need to call virCPUppc64DataFree() in a cleanup label.
This function is already assigned to the 'dataFree' interface
of cpuDriverPPC64, and it will be called by virCPUDataFree(), the
autocleanup function of virCPUDataPtr, via driver->dataFree.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use g_autoptr() with virCPUppc64MapPtr
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:43 +0000 (17:25 -0300)] 
cpu_ppc64.c: use g_autoptr() with virCPUppc64MapPtr

Use autocleanup with virCPUppc64MapPtr to simplify existing
code. Remove labels when possible.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64MapPtr
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:42 +0000 (17:25 -0300)] 
cpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64MapPtr

Next patch will use g_autoptr() in virCPUppc64MapPtr pointers
for some cleanups.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use typedefs for 'struct ppc64_map'
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:41 +0000 (17:25 -0300)] 
cpu_ppc64.c: use typedefs for 'struct ppc64_map'

Introduce virCPUppc64Map and virCPUppc64MapPtr types to
improve code readability.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use g_autoptr() with virCPUppc64ModelPtr
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:40 +0000 (17:25 -0300)] 
cpu_ppc64.c: use g_autoptr() with virCPUppc64ModelPtr

Use autocleanup with virCPUppc64ModelPtr to simplify existing
code. Remove the 'error' label in ppc64ModelCopy() since it is
now obsolete.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64ModelPtr
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:39 +0000 (17:25 -0300)] 
cpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64ModelPtr

Next patch will use g_autoptr() in virCPUppc64ModelPtr pointers
for some cleanups.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use typedefs for 'struct ppc64_model'
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:38 +0000 (17:25 -0300)] 
cpu_ppc64.c: use typedefs for 'struct ppc64_model'

Introduce virCPUppc64Model and virCPUppc64ModelPtr types to
improve code readability.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: modernize ppc64VendorParse()
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:37 +0000 (17:25 -0300)] 
cpu_ppc64.c: modernize ppc64VendorParse()

Use g_autoptr() in virCPUppc64VendorPtr and remove the now
uneeded 'cleanup' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64VendorPtr
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:36 +0000 (17:25 -0300)] 
cpu_ppc64.c: register AUTOPTR_CLEANUP_FUNC for virCPUppc64VendorPtr

Next patch will use g_autoptr() in virCPUppc64VendorPtr pointers
for some cleanups.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_ppc64.c: use typedefs for 'struct ppc64_vendor'
Daniel Henrique Barboza [Wed, 2 Sep 2020 20:25:35 +0000 (17:25 -0300)] 
cpu_ppc64.c: use typedefs for 'struct ppc64_vendor'

Introduce virCPUppc64Vendor and virCPUppc64VendorPtr types to
improve code readability.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoTranslated using Weblate (Indonesian)
Andika Triwidada [Mon, 7 Sep 2020 08:50:01 +0000 (10:50 +0200)] 
Translated using Weblate (Indonesian)

Currently translated at 2.0% (209 of 10366 strings)

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

Co-authored-by: Andika Triwidada <andika@gmail.com>
Signed-off-by: Andika Triwidada <andika@gmail.com>
4 years agocpu: Use g_auto* in virCPUGetHost
Tim Wiederhake [Mon, 7 Sep 2020 14:58:56 +0000 (16:58 +0200)] 
cpu: Use g_auto* in virCPUGetHost

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu: Use g_auto* in virCPUCompareXML
Tim Wiederhake [Mon, 7 Sep 2020 14:58:55 +0000 (16:58 +0200)] 
cpu: Use g_auto* in virCPUCompareXML

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_map: Use g_auto* in loadIncludes
Tim Wiederhake [Mon, 7 Sep 2020 14:58:54 +0000 (16:58 +0200)] 
cpu_map: Use g_auto* in loadIncludes

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agocpu_map: Use g_auto* in cpuMapLoadInclude
Tim Wiederhake [Mon, 7 Sep 2020 14:58:53 +0000 (16:58 +0200)] 
cpu_map: Use g_auto* in cpuMapLoadInclude

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agosrc/storage/meson: fix vir_storage_file_gluster module dependencies
Pavel Hrdina [Tue, 8 Sep 2020 13:45:11 +0000 (15:45 +0200)] 
src/storage/meson: fix vir_storage_file_gluster module dependencies

The correct key for dependencies for virt_modules hash is `deps`.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agocheck for NULL before calling g_regex_unref
Ján Tomko [Tue, 8 Sep 2020 12:57:14 +0000 (14:57 +0200)] 
check for NULL before calling g_regex_unref

g_regex_unref reports an error if called with a NULL argument.

We have two cases in the code where we (possibly) call it on a NULL
argument. The interesting one is in virDomainQemuMonitorEventCleanup.

Based on VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX, we unref
data->regex, which has two problems:

* On the client side, flags is -1 so the comparison is true even if no
  regex was used, reproducible by:
  $ virsh qemu-monitor-event --timeout 1
  which results in an ugly error:
(process:1289846): GLib-CRITICAL **: 14:58:42.631: g_regex_unref: assertion 'regex != NULL' failed
* On the server side, we only create the regex if both the flag and the
  string are present, so it's possible to trigger this message by:
  $ virsh qemu-monitor-event --regex --timeout 1

Use a non-NULL comparison instead of the flag to decide whether we need
to unref the regex. And add a non-NULL check to the unref in the
VirtualBox test too.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 71efb59a4de7c51b1bc889a316f1796ebf55738f
https://bugzilla.redhat.com/show_bug.cgi?id=1876907
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agodocs: Discourage users from using fwcfg
Michal Privoznik [Mon, 7 Sep 2020 13:42:46 +0000 (15:42 +0200)] 
docs: Discourage users from using fwcfg

Even though this was brought up in upstream discussion [1] it
missed my patches: users should prefer <oemStrings/> over fwcfg.
The reason is that fwcfg is considered somewhat internal to QEMU
and it has limited number of slots and neither of these applies
to <oemStrings/>.

While I'm at it, I'm fixing the example too (because it contains
incorrect element name) and clarifying sysfs/ exposure.

1: https://www.redhat.com/archives/libvir-list/2020-May/msg00957.html

Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
4 years agodocs: Rephrase the video 'none' type to clarify the reasoning
Erik Skultety [Tue, 8 Sep 2020 09:55:27 +0000 (11:55 +0200)] 
docs: Rephrase the video 'none' type to clarify the reasoning

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agorpm: Remove pointless explicit dependency on 'readline'
Neal Gompa [Mon, 7 Sep 2020 18:59:39 +0000 (14:59 -0400)] 
rpm: Remove pointless explicit dependency on 'readline'

The 'readline' package only contains the library, which rpm is
already generating the (stricter) correct dependency for.

Signed-off-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirnuma: Report error when NUMA -> CPUs translation fails
Michal Privoznik [Mon, 7 Sep 2020 15:02:08 +0000 (17:02 +0200)] 
virnuma: Report error when NUMA -> CPUs translation fails

When starting a domain with <numatune/> set libvirt translates
given NUMA nodes into a set of host CPUs which is then used to
QEMU process affinity. But, if the numatune contains a
non-existent NUMA node then the translation fails with no error
reported. This is because virNumaNodesetToCPUset() calls
virNumaGetNodeCPUs() and expects it to report an error on
failure. Well, it does except for non-existent NUMA nodes. While
this behaviour might look strange it is actually desired because
of how we construct host capabilities. The virNumaGetNodeCPUs()
is called from virCapabilitiesHostNUMAInitReal() where we do not
want any error reported for non-existent NUMA nodes.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1724866
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agowireshark: Prefer ws_version.h over config.h
Michal Privoznik [Mon, 7 Sep 2020 15:50:24 +0000 (17:50 +0200)] 
wireshark: Prefer ws_version.h over config.h

A wireshark plugin must declare what major and minor version it
was built with as these are checked when wireshark loads plugins.
On the top of that, we use major + minor + micro to adapt to
changed API between releases. So far, we were getting these
version numbers from wireshark/config.h.

And while most distributions install wireshark/config.h file some
don't. On distros shipping it it's hack^Wsaved during built by
packaging system and installed later. But some distros are not
doing that. At least not for new enough wireshark because as of
wireshark's commit v2.9.0~1273 the ws_version.h is installed
which contains the version macros we need and is installed by
wireshark itself.

But of course, some distros which have new enough wireshark
packaged do not ship ws_version.h and stick to the hack. That is
why we can't simply bump the minimal version and switch to the
new header file. We need a configure check and adopt our code to
deal with both ways. At least for the time being.

Based on Andrea's original patch:

https://www.redhat.com/archives/libvir-list/2020-September/msg00156.html

Closes: https://gitlab.com/libvirt/libvirt/-/issues/74
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoqemu_process: Separate VIR_PERF_EVENT_* setting into a function
Michal Privoznik [Mon, 7 Sep 2020 14:44:50 +0000 (16:44 +0200)] 
qemu_process: Separate VIR_PERF_EVENT_* setting into a function

When starting a domain, qemuProcessLaunch() iterates over all
VIR_PERF_EVENT_* values and (possibly) enables them. While there
is nothing wrong with the code, the for loop where it's done makes
it harder to jump onto next block of code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemuBlockStorageSourceCreateDetectSize: Propagate cluster size for 'qcow2'
Peter Krempa [Wed, 26 Aug 2020 14:45:51 +0000 (16:45 +0200)] 
qemuBlockStorageSourceCreateDetectSize: Propagate cluster size for 'qcow2'

Propagate the cluster size from the original image as the user might
have configured a custom cluster size for performance reasons. Propagate
the cluster size of a qcow2 image to the new overlay or copy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
4 years agoqemu: block: Allow specifying cluster size when using 'blockdev-create'
Peter Krempa [Wed, 26 Aug 2020 14:43:29 +0000 (16:43 +0200)] 
qemu: block: Allow specifying cluster size when using 'blockdev-create'

'blockdev-create' allows us to create the image with a custom cluster
size if we wish to. Wire it up for 'qcow2'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
4 years agoqemu: monitor: Detect image cluster size from 'query-named-block-nodes'
Peter Krempa [Wed, 26 Aug 2020 14:41:17 +0000 (16:41 +0200)] 
qemu: monitor: Detect image cluster size from 'query-named-block-nodes'

Configuring the cluster size of an image may have performance
implications. This patch allows us to detect cluster size for existing
images so that we will be able to propagate it to new images which are
based on existing images e.g. during snapshots/block-copy/etc.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
4 years agoRevert "news: qemu: Support TLS for NBD connections for pull mode backup"
Peter Krempa [Mon, 7 Sep 2020 14:42:59 +0000 (16:42 +0200)] 
Revert "news: qemu: Support TLS for NBD connections for pull mode backup"

Incremental backups are not enabled. There's no point documenting
individual patches implementing an incomplete feature.

This reverts commit e6285f84faeacccdef12b69a7bc38975230d6662

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoqemu_namespace: Don't leak mknod items that are being skipped over
Michal Privoznik [Mon, 7 Sep 2020 11:35:50 +0000 (13:35 +0200)] 
qemu_namespace: Don't leak mknod items that are being skipped over

When building and populating domain NS a couple of functions are
called that append paths to a string list. This string list is
then inspected, one item at the time by
qemuNamespacePrepareOneItem() which gathers all the info for
given path (stat buffer, possible link target, ACLs, SELinux
label) using qemuNamespaceMknodItemInit(). If the path needs to
be created in the domain's private /dev then it's added onto this
qemuNamespaceMknodData list which is freed later in the process.
But, if the path does not need to be created in the domain's
private /dev, then the memory allocated by
qemuNamespaceMknodItemInit() is not freed anywhere leading to a
leak.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: Allow setting affinity to fail and don't report error
Martin Kletzander [Mon, 7 Sep 2020 11:00:28 +0000 (13:00 +0200)] 
qemu: Allow setting affinity to fail and don't report error

This is just a clean-up of commit 3791f29b085c using the new parameter of
virProcessSetAffinity() introduced in commit 9514e24984ee so that there is
no error reported in the logs.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoDo not report error when setting affinity is allowed to fail
Martin Kletzander [Sat, 5 Sep 2020 05:53:58 +0000 (07:53 +0200)] 
Do not report error when setting affinity is allowed to fail

Suggested-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: migration: remove unused variable
Ján Tomko [Mon, 7 Sep 2020 09:03:38 +0000 (11:03 +0200)] 
qemu: migration: remove unused variable

../src/qemu/qemu_migration.c:4091:36: error: unused variable 'cfg' [-Werror,-Wunused-variable]
    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: d92c2bbc6597fcb951b303a9122ec1ca71514d10
4 years agolib: Prefer g_autoptr() declaration of virQEMUDriverConfigPtr
Michal Privoznik [Fri, 4 Sep 2020 06:59:08 +0000 (08:59 +0200)] 
lib: Prefer g_autoptr() declaration of virQEMUDriverConfigPtr

In the past we had to declare @cfg and then explicitly unref it.
But now, with glib we can use g_autoptr() which will do the unref
automatically and thus is more bulletproof.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoqemu_interface: Fix @cfg refcounting in qemuInterfacePrepareSlirp()
Michal Privoznik [Fri, 4 Sep 2020 06:55:39 +0000 (08:55 +0200)] 
qemu_interface: Fix @cfg refcounting in qemuInterfacePrepareSlirp()

In the qemuInterfacePrepareSlirp() function, the qemu driver
config is obtained (via virQEMUDriverGetConfig()), but it is
never unrefed leading to mangled refcounter.

Fixes: 9145b3f1cc334e946b3f9ea45d6c24c868301e6f
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: remove unused virThreadPoolNew macro
Nikolay Shirokovskiy [Thu, 9 Jul 2020 08:13:44 +0000 (11:13 +0300)] 
util: remove unused virThreadPoolNew macro

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: cleanup virNetDaemonClose method
Nikolay Shirokovskiy [Thu, 9 Jul 2020 08:13:12 +0000 (11:13 +0300)] 
rpc: cleanup virNetDaemonClose method

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: implement driver's shutdown/shutdown wait methods
Nikolay Shirokovskiy [Thu, 9 Jul 2020 08:12:26 +0000 (11:12 +0300)] 
qemu: implement driver's shutdown/shutdown wait methods

On shutdown we just stop accepting new jobs for worker thread so that on
shutdown wait we can exit worker thread faster. Yes we basically stop
processing of events for VMs but we are going to do so anyway in case of daemon
shutdown.

At the same time synchronous event processing that some API calls may require
are still possible as per VM event loop is still running and we don't need
worker thread for synchronous event processing.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: avoid deadlock in qemuDomainObjStopWorker
Nikolay Shirokovskiy [Thu, 23 Jul 2020 08:02:59 +0000 (11:02 +0300)] 
qemu: avoid deadlock in qemuDomainObjStopWorker

We are dropping the only reference here so that the event loop thread
is going to be exited synchronously. In order to avoid deadlocks we
need to unlock the VM so that any handler being called can finish
execution and thus even loop thread be finished too.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agovireventthread: exit thread synchronously on finalize
Nikolay Shirokovskiy [Thu, 23 Jul 2020 07:23:00 +0000 (10:23 +0300)] 
vireventthread: exit thread synchronously on finalize

It it useful to be sure no thread is running after we drop all references to
virEventThread. Otherwise in order to avoid crashes we need to synchronize some
other way or we make extra references in event handler callbacks to all the
object in use. And some of them are not prepared to be refcounted.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: don't shutdown event thread in monitor EOF callback
Nikolay Shirokovskiy [Thu, 23 Jul 2020 07:10:26 +0000 (10:10 +0300)] 
qemu: don't shutdown event thread in monitor EOF callback

This hunk was introduced in [1] in order to avoid loosing
events from monitor on stopping qemu process. But as explained
in [2] on destroy we won't get neither EOF nor any other
events as monitor is just closed. In case of crash/shutdown
we won't get any more events as well and qemuDomainObjStopWorker
will be called by qemuProcessStop eventually. Thus let's
remove qemuDomainObjStopWorker from qemuProcessHandleMonitorEOF
as it is not useful anymore.

[1] e6afacb0f: qemu: start/stop an event loop thread for domains
[2] d2954c072: qemu: ensure domain event thread is always stopped

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agorpc: finish all threads before exiting main loop
Nikolay Shirokovskiy [Thu, 23 Jul 2020 06:53:04 +0000 (09:53 +0300)] 
rpc: finish all threads before exiting main loop

Currently we have issues like [1] on libvirtd shutdown as we cleanup while RPC
and other threads are still running. Let's finish all threads other then main
before cleanup.

The approach to finish threads is suggested in [2]. In order to finish RPC
threads serving API calls we let the event loop run but stop accepting new API
calls and block processing any pending API calls. We also inform all drivers of
shutdown so they can prepare for shutdown too. Then we wait for all RPC threads
and driver's background thread to finish. If finishing takes more then 15s we
just exit as we can't safely cleanup in time.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1828207
[2] https://www.redhat.com/archives/libvir-list/2020-April/msg01328.html

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agorpc: add shutdown facilities to netserver
Nikolay Shirokovskiy [Thu, 23 Jul 2020 06:50:25 +0000 (09:50 +0300)] 
rpc: add shutdown facilities to netserver

virNetServerClose and virNetServerShutdownWait are used to start net server
threads shutdown and wait net server threads to actually finish respectively
during net daemon shutdown procedure.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: add virNetDaemonSetShutdownCallbacks
Nikolay Shirokovskiy [Thu, 23 Jul 2020 06:43:46 +0000 (09:43 +0300)] 
rpc: add virNetDaemonSetShutdownCallbacks

The function is used to set shutdown prepare and wait callbacks. Prepare
callback is used to inform other threads of the daemon that the daemon will be
closed soon so that they can start to shutdown. Wait callback is used to wait
for other threads to actually finish.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: don't unref service ref on socket behalf twice
Nikolay Shirokovskiy [Thu, 9 Jul 2020 07:59:33 +0000 (10:59 +0300)] 
rpc: don't unref service ref on socket behalf twice

Second unref was added in [1]. We don't need it actually as
we pass free callback to virNetSocketAddIOCallback thus
when we call virNetSocketRemoveIOCallback the extra ref for
callback will be dropped without extra efforts.

[1] 355d8f470f9: virNetServerServiceClose: Don't leak sockets

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoutil: add stop/drain functions to thread pool
Nikolay Shirokovskiy [Thu, 9 Jul 2020 07:58:02 +0000 (10:58 +0300)] 
util: add stop/drain functions to thread pool

Stop just send signal for threads to exit when they finish with
current task. Drain waits when all threads will finish.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoutil: always initialize priority condition
Nikolay Shirokovskiy [Fri, 10 Jul 2020 11:36:54 +0000 (14:36 +0300)] 
util: always initialize priority condition

Even if we have no priority threads on pool creation we can add them thru
virThreadPoolSetParameters later.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agolibvirt: add stateShutdownPrepare/stateShutdownWait to drivers
Nikolay Shirokovskiy [Thu, 9 Jul 2020 07:46:34 +0000 (10:46 +0300)] 
libvirt: add stateShutdownPrepare/stateShutdownWait to drivers

stateShutdownPrepare is supposed to inform driver that it will be closed soon
so that the driver can prepare and finish all background threads quickly on
stateShutdownWait call.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: Fix comment in qemuProcessSetupPid
Martin Kletzander [Sun, 6 Sep 2020 11:44:27 +0000 (13:44 +0200)] 
qemu: Fix comment in qemuProcessSetupPid

This was supposed to be done in commit 3791f29b085c, but I missed a spot.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
4 years agonews: qemu: Allow migration over UNIX sockets
Martin Kletzander [Mon, 24 Aug 2020 21:48:04 +0000 (23:48 +0200)] 
news: qemu: Allow migration over UNIX sockets

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Allow migration over UNIX socket
Martin Kletzander [Wed, 2 Sep 2020 10:06:12 +0000 (12:06 +0200)] 
qemu: Allow migration over UNIX socket

This allows:

 a) migration without access to network

 b) complete control of the migration stream

 c) easy migration between containerised libvirt daemons on the same host

Resolves: https://bugzilla.redhat.com/1638889

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
4 years agonetwork: drop use of dummy tap device in bridges
Daniel P. Berrangé [Mon, 3 Aug 2020 13:52:13 +0000 (14:52 +0100)] 
network: drop use of dummy tap device in bridges

A long time ago we introduced a dummy tap device (e.g. virbr0-nic) that
we attached to the bridge device created for virtual networks:

  commit 5754dbd56d4738112a86776c09e810e32f7c3224
  Author: Laine Stump <laine@redhat.com>
  Date:   Wed Feb 9 03:28:12 2011 -0500

    Give each virtual network bridge its own fixed MAC address

This was a hack to workaround a Linux kernel bug where it would not
honour any attempt to set a MAC address on a bridge. Instead the
bridge would adopt the numerically lowest MAC address of all NICs
attached to the bridge. This lead to the MAC addrss of the bridge
changing over time as NICs were attached/detached.

The Linux bug was actually fixed 3 years before the libvirt
workaround was added in:

  commit 92c0574f11598c8036f81e27d2e8bdd6eed7d76d
  Author: Stephen Hemminger <shemminger@vyatta.com>
  Date:   Tue Jun 17 16:10:06 2008 -0700

    bridge: make bridge address settings sticky

    Normally, the bridge just chooses the smallest mac address as the
    bridge id and mac address of bridge device. But if the administrator
    has explictly set the interface address then don't change it.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
but libvirt needed to support RHEL-5 kernels at that time, so
none the less added the workaround.

We have long since dropped support for RHEL-5 vintage distros,
so there's no reason to keep the dummy tap device for the purpose
of setting the bridge MAC address.

Later the dummy TAP device was used for a second purpose related
to IPv6 DAD (Duplicate Address Detection) in:

  commit db488c79173b240459c7754f38c3c6af9b432970
  Author: Benjamin Cama <benoar@dolka.fr>
  Date:   Wed Sep 26 21:02:20 2012 +0200

    network: fix dnsmasq/radvd binding to IPv6 on recent kernels

This was again dealing with a regression in the Linux kernel, where
if there were no devices attached to the bridge in the UP state,
IPv6 DAD would not be performed. The virbr0-nic was attached but
in the DOWN state, so the above libvirt fix tenporarily brought
the NIC online. The Linux commit causing the problem was in v2.6.38

  commit 1faa4356a3bd89ea11fb92752d897cff3a20ec0e
  Author: stephen hemminger <shemminger@vyatta.com>
  Date:   Mon Mar 7 08:34:06 2011 +0000

    bridge: control carrier based on ports online

A short while later Linux was tweaked so that DAD would still occur
if the bridge had no attached devices at all in 3.1:

  commit b64b73d7d0c480f75684519c6134e79d50c1b341
  Author: stephen hemminger <shemminger@vyatta.com>
  Date:   Mon Oct 3 18:14:45 2011 +0000

    bridge: leave carrier on for empty bridge

IOW, the only reason we need the DAD hack of bringing virbr0-nic
online is because virbr0-nic exists. Once it doesn't exist, then
we hit the "empty bridge" case which works in Linux.

We can rely on distros having Linux kernel >= 3.1, so both things
that the virbr0-nic are doing are redundant.

Fixes https://gitlab.com/libvirt/libvirt/-/issues/53
Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agocpu_map: Use g_auto* in cpuMapLoad
Tim Wiederhake [Fri, 4 Sep 2020 12:26:07 +0000 (14:26 +0200)] 
cpu_map: Use g_auto* in cpuMapLoad

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: add device name in errors from ethtool ioctls
Daniel P. Berrangé [Wed, 2 Sep 2020 18:32:49 +0000 (19:32 +0100)] 
util: add device name in errors from ethtool ioctls

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: Do not error out when setting affinity failed
Martin Kletzander [Fri, 4 Sep 2020 12:17:30 +0000 (14:17 +0200)] 
qemu: Do not error out when setting affinity failed

Consider a host with 8 CPUs. There are the following possible scenarios

1. Bare metal; libvirtd has affinity of 8 CPUs; QEMU should get 8 CPUs

2. Bare metal; libvirtd has affinity of 2 CPUs; QEMU should get 8 CPUs

3. Container has affinity of 8 CPUs; libvirtd has affinity of 8 CPus;
   QEMU should get 8 CPUs

4. Container has affinity of 8 CPUs; libvirtd has affinity of 2 CPus;
   QEMU should get 8 CPUs

5. Container has affinity of 4 CPUs; libvirtd has affinity of 4 CPus;
   QEMU should get 4 CPUs

6. Container has affinity of 4 CPUs; libvirtd has affinity of 2 CPus;
   QEMU should get 4 CPUs

Scenarios 1 & 2 always work unless systemd restricted libvirtd privs.

Scenario 3 works because libvirt checks current affinity first and
skips the sched_setaffinity call, avoiding the SYS_NICE issue

Scenario 4 works only if CAP_SYS_NICE is availalbe

Scenarios 5 & 6 works only if CAP_SYS_NICE is present *AND* the cgroups
cpuset is not set on the container.

If libvirt blindly ignores the sched_setaffinity failure, then scenarios
4, 5 and 6 should all work, but with caveat in case 4 and 6, that
QEMU will only get 2 CPUs instead of the possible 8 and 4 respectively.
This is still better than failing.

Therefore libvirt can blindly ignore the setaffinity failure, but *ONLY*
ignore it when there was no affinity specified in the XML config.
If user specified affinity explicitly, libvirt must report an error if
it can't be honoured.

Resolves: https://bugzilla.redhat.com/1819801

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoutil: re-add conditional for ifi_iqdrops field for macOS
Daniel P. Berrangé [Fri, 4 Sep 2020 09:13:48 +0000 (10:13 +0100)] 
util: re-add conditional for ifi_iqdrops field for macOS

The conditional was removed in

  commit ebbf8ebe4fa6f9d43b40673f0f2dad6bf50e2085
  Author: Ján Tomko <jtomko@redhat.com>
  Date:   Tue Sep 1 22:56:37 2020 +0200

    util: virnetdevtap: stats: fix txdrop on FreeBSD

That commit was correct about this no longer being required for FreeBSD,
but missed that the code is also built on macOS.

Rather than testing for this field in meson though, we can simply use
a platform conditional test in the code.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotools: avoid unused parameter warning when readline is disabled
Daniel P. Berrangé [Fri, 4 Sep 2020 09:17:30 +0000 (10:17 +0100)] 
tools: avoid unused parameter warning when readline is disabled

The vshReadlineHistoryAdd stub method does not use its parameter.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agopeer2peer migration: allow connecting to local sockets
Martin Kletzander [Mon, 24 Aug 2020 22:31:23 +0000 (00:31 +0200)] 
peer2peer migration: allow connecting to local sockets

Local socket connections were outright disabled because there was no "server"
part in the URI.  However, given how requirements and usage scenarios are
evolving, some management apps might need the source libvirt daemon to connect
to the destination daemon over a UNIX socket for peer2peer migration.  Since we
cannot know where the socket leads (whether the same daemon or not) let's decide
that based on whether the socket path is non-standard, or rather explicitly
specified in the URI.  Checking non-standard path would require to ask the
daemon for configuration and the only misuse that it would prevent would be a
pretty weird one.  And that's not worth it.  The assumption is that whenever
someone uses explicit UNIX socket paths in the URI for migration they better
know what they are doing.

Partially resolves: https://bugzilla.redhat.com/1638889

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Allow NBD migration over UNIX socket
Martin Kletzander [Mon, 24 Aug 2020 13:42:31 +0000 (15:42 +0200)] 
qemu: Allow NBD migration over UNIX socket

Adds new typed param for migration and uses this as a UNIX socket path that
should be used for the NBD part of migration.  And also adds virsh support.

Partially resolves: https://bugzilla.redhat.com/1638889

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agotests: Add simple test for virDomainMigrateCheckNotLocal
Martin Kletzander [Thu, 20 Sep 2018 11:33:45 +0000 (13:33 +0200)] 
tests: Add simple test for virDomainMigrateCheckNotLocal

For this we need to make the function accessible (at least privately).  The
behaviour will change in following patches and the test helps explaining the
change.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Rework starting NBD server for migration
Martin Kletzander [Mon, 24 Aug 2020 19:24:13 +0000 (21:24 +0200)] 
qemu: Rework starting NBD server for migration

Clean up the semantics by using one extra self-describing variable.
This also fixes the port allocation when the port is specified.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agovirsh: Reuse existing variable when parsing migrate --disks-port
Martin Kletzander [Mon, 24 Aug 2020 13:43:50 +0000 (15:43 +0200)] 
virsh: Reuse existing variable when parsing migrate --disks-port

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Rework qemuMigrationSrcConnect
Martin Kletzander [Mon, 24 Aug 2020 20:29:14 +0000 (22:29 +0200)] 
qemu: Rework qemuMigrationSrcConnect

Instead of saving some data from a union up front and changing an overlayed
struct before using said data, let's just set the new values after they are
decided.  This will increase the readability of future commit(s).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Use g_autofree in qemuMigrationSrcConnect
Martin Kletzander [Mon, 24 Aug 2020 20:27:30 +0000 (22:27 +0200)] 
qemu: Use g_autofree in qemuMigrationSrcConnect

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu_namespace: Be tolerant to non-existent files when populating /dev
Michal Privoznik [Thu, 3 Sep 2020 16:07:43 +0000 (18:07 +0200)] 
qemu_namespace: Be tolerant to non-existent files when populating /dev

In 6.7.0 release I've changed how domain namespace is built and
populated. Previously it used to be done from a pre-exec hook
(ran in the forked off child, just before dropping all privileges
and exec()-ing QEMU), which not only meant we had to have two
different code paths for creating a node in domain's namespace
(one for this pre-exec hook, the other for hotplug ran from the
daemon), it also proved problematic because it was leaking FDs
into QEMU process.

To mitigate this problem, we've not only ditched libdevmapper
from the NS population process, I've also dropped the pre-exec
code and let the NS be populated from the daemon (using the
hotplug code). But, I was not careful when doing so, because the
pre-exec code was tolerant to files that doesn't exist, while
this new code isn't. For instance, the very first thing that is
done when the new NS is created is it's populated with
@defaultDeviceACL which contain files like /dev/null, /dev/zero,
/dev/random and /dev/kvm (and others).  While the rest will
probably exist every time, /dev/kvm might not and thus the new
code I wrote has to be tolerant to that.

Of course, users can override the @defaultDeviceACL (by setting
cgroup_device_acl in qemu.conf) and remove /dev/kvm (which is
acceptable workaround), but we definitely want libvirt to work
out of the box even on hosts without KVM.

Fixes: 9048dc4e627ddf33996084167bece7b5fb83b0bc
Reported-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: virnetdevtap: stats: fix txdrop on FreeBSD
Ján Tomko [Tue, 1 Sep 2020 20:56:37 +0000 (22:56 +0200)] 
util: virnetdevtap: stats: fix txdrop on FreeBSD

For older FreeBSD, we needed an ifdef guard to use
if_data.ifi_oqdrops, which was introduced by:

commit 61bbdbb94ce3e2f5e969c9bddb443427db07bf61
    Implement interface stats for BSD

But when we dropped the check because we deprecated
building on FreeBSD-10 in:

commit 83131d9714db7ee77ab220186b6b0d8b6c22b09e
    configure: drop check for unsupported FreeBSD

We started building the wrong side of the ifdef.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 83131d9714db7ee77ab220186b6b0d8b6c22b09e
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
4 years agoremote: adapt augeas test case for dynamic polkit config change
Daniel P. Berrangé [Thu, 3 Sep 2020 14:54:28 +0000 (15:54 +0100)] 
remote: adapt augeas test case for dynamic polkit config change

We need to use @default_auth@ in the augeas test case to match
its use in the main libvirtd.conf.in file.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agobuild-aux: use GNU sed for syntax-check on FreeBSD
Roman Bogorodskiy [Wed, 5 Aug 2020 15:49:02 +0000 (19:49 +0400)] 
build-aux: use GNU sed for syntax-check on FreeBSD

BSD sed(1) and GNU sed(1) syntax are not compatible, and as
synax-check.mk uses the GNU flavor, set SED variable to
'gsed' by default.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agovsh: Define HAVE_STDARG_H before including readline
Michal Privoznik [Wed, 2 Sep 2020 14:37:04 +0000 (16:37 +0200)] 
vsh: Define HAVE_STDARG_H before including readline

As it turned out my previous commits which switched from HAVE_ to
WITH_ and dropped stdarg.h detection were a bit too aggressive.
Because of reasons described in 9ea3424a178 we need to define
HAVE_STDARG_H before including readline otherwise macos build
fails. Honestly, I still don't fully understand the problem so I
am not going to bother you with "explanation".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovsh: Introduce wrapper for add_history()
Michal Privoznik [Thu, 3 Sep 2020 08:02:52 +0000 (10:02 +0200)] 
vsh: Introduce wrapper for add_history()

This allows us to drop include of readline header files from
virsh.c and virt-admin.c because they needed it only because of
the add_history() function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agomeson: add -Wall and -Wextra explicitly
Pavel Hrdina [Tue, 1 Sep 2020 12:54:27 +0000 (14:54 +0200)] 
meson: add -Wall and -Wextra explicitly

If someone runs `meson setup --buildtype plain` meson ignores
warning_level=2 that is in our meson.build file. The implication is
that Meson will not automatically add -Wall which enables -Wformat.

This breaks building libvirt from git with the buildtype set to plain.

There is an issue reported [1] to not ignore warning_level silently
and the change to ignore it was done by upstream commit [2].

This change makes Meson print warnings about using warning_level which
as described above doesn't work for all build types.

[1] <https://github.com/mesonbuild/meson/issues/7399>
[2] <https://github.com/mesonbuild/meson/commit/8ee1c9a07a3a35e3ed262fbc358fd86c257a966e>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoremote: use SocketMode=0600 when polkit is not compiled
Daniel P. Berrangé [Fri, 7 Aug 2020 12:37:05 +0000 (13:37 +0100)] 
remote: use SocketMode=0600 when polkit is not compiled

The systemd .socket unit files we ship for libvirt daemons use
SocketMode=0666 on the assumption that libvirt is built with
polkit which provides access control.

Some people, however, may have explicitly turned off polkit at
build time and not realize that leaves them insecure unless
they also change the SocketMode.  This addresses that problem
by making the SocketMode default to 0600 when polkit is
disabled at compile time.

Note we cannot automatically fix the case where the user
compiles polkit, but then overrides the libvirtd.conf defaults
to disable polkit. This is what lead to CVE-2020-15708 in
Ubuntu 20.10.  We can at least improve the inline comments
in the config file to give a clearer warning though, which
may have helped avoid the mistaken config.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agonews: qemu: Support TLS for NBD connections for pull mode backup
Yanqiu Zhang [Thu, 3 Sep 2020 02:56:48 +0000 (02:56 +0000)] 
news: qemu: Support TLS for NBD connections for pull mode backup

Signed-off-by: Yanqiu Zhang <yanqzhan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agotests: change confusing macro agument names
Jonathon Jongsma [Wed, 2 Sep 2020 19:45:38 +0000 (14:45 -0500)] 
tests: change confusing macro agument names

Rather than use the names "fial" and "kep", use "fail" and "keep". In
the DO_TEST() macro, to prevent the preprocessor replacing the struct
member names during assignment, use the names "fail_" and "keep_"
instead.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoqemu_validate: Only allow none address for watchdog ib700
Han Han [Tue, 1 Sep 2020 14:15:27 +0000 (22:15 +0800)] 
qemu_validate: Only allow none address for watchdog ib700

Since QEMU 1.5.3, the ib700 watchdog device has no options for address,
and not address in device tree:

$ /usr/libexec/qemu-kvm -version
QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-175.el7), Copyright (c) 2003-2008 Fabrice Bellard
$ /usr/libexec/qemu-kvm -device ib700,\?
$ virsh qemu-monitor-command seabios --hmp info qtree|grep ib700 -A 2
        dev: ib700, id "watchdog0"
        dev: isa-serial, id "serial0"
          index = 0

So only allow it to use none address.

Fixes: 8a54cc1d08a333283c9cfc3fd7788be2642ca71a
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1509908

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: Fix domfsinfo for non-PCI device information from guest agent
Thomas Huth [Mon, 20 Jul 2020 10:22:33 +0000 (12:22 +0200)] 
qemu: Fix domfsinfo for non-PCI device information from guest agent

qemuAgentFSInfoToPublic() currently only sets the devAlias for PCI devices.
However, the QEMU guest agent could also provide the device name in the
"dev" field of the response for other devices instead (well, at least after
fixing another problem in the current QEMU guest agent...). So if creating
the devAlias from the PCI information failed, let's fall back to the name
provided by the guest agent. This helps to fix the empty "Target" fields
that occur when running "virsh domfsinfo" on s390x where CCW devices are
used for the guest instead of PCI devices.

Also add a proper debug message here in case we completely failed to set the
device alias, since this problem here was very hard to debug: The only two
error messages that I've seen were "Unable to get filesystem information"
and "Unable to encode message payload" - which only indicates that something
went wrong in the RPC call. No debug message indicated the real problem, so
I had to learn the hard way why the RPC call failed (it apparently does not
like devAlias left to be NULL) and where the real problem comes from.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1755075
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
4 years agoqemu: Do not silently allow non-available timers on non-x86 systems
Thomas Huth [Wed, 5 Aug 2020 10:22:26 +0000 (12:22 +0200)] 
qemu: Do not silently allow non-available timers on non-x86 systems

libvirt currently silently allows <timer name="kvmclock"/> and some
other timer tags in the guest XML definition for timers that do not
exist on non-x86 systems. We should not silently ignore these tags
since the users might not get what they expected otherwise.
Note: The error is only generated if the timer is marked with
present="yes" - otherwise we would suddenly refuse XML definitions
that worked without problems before.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1754887
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoAUTHORS: Remove Emacs file variables
Andrea Bolognani [Tue, 25 Aug 2020 16:07:01 +0000 (18:07 +0200)] 
AUTHORS: Remove Emacs file variables

vim seems to be able to process the file just fine without a
modeline, so it's probably fair to assume Emacs doesn't need
any extra help either.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoAUTHORS: Convert to reStructuredText
Andrea Bolognani [Tue, 25 Aug 2020 15:52:24 +0000 (17:52 +0200)] 
AUTHORS: Convert to reStructuredText

Now that we have moved to Meson, we are no longer required to
use a specific name for this file, and since the rest of our
documentation is in reStructuredText format and uses a matching
file extension, we can give the AUTHORS file the same treatment.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agolib: Prefer WITH_* prefix for #if conditionals
Michal Privoznik [Tue, 1 Sep 2020 11:27:44 +0000 (13:27 +0200)] 
lib: Prefer WITH_* prefix for #if conditionals

Currently, we are mixing: #if HAVE_BLAH with #if WITH_BLAH.
Things got way better with Pavel's work on meson, but apparently,
mixing these two lead to confusing and easy to miss bugs (see
31fb929eca for instance). While we were forced to use HAVE_
prefix with autotools, we are free to chose our own prefix with
meson and since WITH_ prefix appears to be more popular let's use
it everywhere.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agonss: Drop needless include of rpc/types.h
Michal Privoznik [Tue, 1 Sep 2020 12:30:42 +0000 (14:30 +0200)] 
nss: Drop needless include of rpc/types.h

In packet-libvirt.c in wireshark dissector we include rpc/types.h
but guard the include with a condition (that is supposed to be
true if we detected during configure phase that the host system
has the header file). Thing is, it looks like we were never doing
the configure check and thus the file was never included and yet,
the NSS plugin works. Drop the include then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agomeson: Drop checks for some functions and header files
Michal Privoznik [Tue, 1 Sep 2020 12:30:34 +0000 (14:30 +0200)] 
meson: Drop checks for some functions and header files

In meson.build, we check for presence of unshare() function
explicitly (even though there is the function usability check a
few hundred lines below), but never have any code depending on
HAVE_UNSHARE. The same applies to stdarg.h and sys/sysctl.h
header files - either we simply include them or guard their
include using different conditionals.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirfile.c: Remove some #endif comments
Michal Privoznik [Tue, 1 Sep 2020 12:23:32 +0000 (14:23 +0200)] 
virfile.c: Remove some #endif comments

There are couple of conditional #includes at the beginning of
virfile.c and they try to be nice and document #endifs. But they
are mostly wrong because either they have the condition in the
comment inverted or the comment refers to a different condition
than they belong to. Just remove the comments as these #includes
are single line mostly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: Check for HAVE_NET_IF_H correctly
Michal Privoznik [Tue, 1 Sep 2020 12:21:41 +0000 (14:21 +0200)] 
util: Check for HAVE_NET_IF_H correctly

There are two places where we try to check whether the host
system has net/if.h before including it. But the check is missing
'_H' suffix.

Fixes: 7f3eb533f44742071366e07a35ab41070956707b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: Add e1000e/vmxnet3 IFF_VNET_HDR support
Patrick Magauran [Sat, 8 Aug 2020 13:59:13 +0000 (09:59 -0400)] 
qemu: Add e1000e/vmxnet3 IFF_VNET_HDR support

Setting IFF_VNET_HDR for a tap device passes the whole packet to the
host, reducing emulation overhead and improving performance.

Libvirt bases its decision about applying IFF_VNET_HDR to the tap
interface on whether or not the model of the emulated network device
is virtio.  Originally, virtio was the only model to support
IFF_VNET_HDR in QEMU; however, the e1000e & vmxnet3 adapters have also
supported it since their introductions - QEMU commit
786fd2b0f87 for vmxnet3, and QEMU commit 6f3fbe4ed0 for e1000e, so it
should be set for those models too.

Signed-off-by: Patrick Magauran <patmagauran.j@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agotests/meson: fix mock library link on MacOS
Scott Shambarger [Fri, 28 Aug 2020 19:35:01 +0000 (12:35 -0700)] 
tests/meson: fix mock library link on MacOS

MacOS can not pre-load modules, so mock libraries must be built
as shared libraries (without asneeded striping, and undefined
symbols allowed).

Signed-off-by: Scott Shambarger <scott-libvirt@shambarger.net>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoconf: fix enum conversion
Ján Tomko [Tue, 1 Sep 2020 21:30:35 +0000 (23:30 +0200)] 
conf: fix enum conversion

../src/conf/domain_conf.c:8144:78: error: result of comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-unsigned-enum-zero-compare]
        if ((def->writeFiltering = virTristateBoolTypeFromString(filtering)) < 0) {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 9d15647dcb96831c93ac8c1d67c47265b5ed9072
4 years agotests: fix license blurb in virsh-undefine
Ján Tomko [Tue, 4 Aug 2020 14:40:34 +0000 (16:40 +0200)] 
tests: fix license blurb in virsh-undefine

Assume commit 0466ff28f2 used case-insensitive replace s/OUT/EXP/
by mistake and this file is still licensed under GPLv2.0+

Undo the change.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
FIxes: 0466ff28f23f4c430906efd5859f87672cf08782
Cc: Cole Robinson <crobinso@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Pino Toscano <ptoscano@redhat.com>
4 years agoNews: Advertise support for writeFiltering attribute of PCI hostdevs
Jim Fehlig [Fri, 14 Aug 2020 21:30:17 +0000 (15:30 -0600)] 
News: Advertise support for writeFiltering attribute of PCI hostdevs

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoXen: Add support for writeFiltering in config converter
Jim Fehlig [Fri, 14 Aug 2020 20:47:09 +0000 (14:47 -0600)] 
Xen: Add support for writeFiltering in config converter

Add support for the writeFiltering attribute in the domXML to native
config converter. Also include a test.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoXen: Add writeFiltering option for PCI devices
Jim Fehlig [Fri, 14 Aug 2020 16:28:38 +0000 (10:28 -0600)] 
Xen: Add writeFiltering option for PCI devices

By default Xen only allows guests to write "known safe" values into PCI
configuration space, yet many devices require writes to other areas of
the configuration space in order to operate properly. To allow writing
any values Xen supports the 'permissive' setting, see xl.cfg(5) man page.

This change models Xen's permissive setting by adding a writeFiltering
attribute on the <source> element of a PCI hostdev. When writeFiltering
is set to 'no', the Xen permissive setting will be enabled and guests
will be able to write any values into the device's configuration space.
The permissive setting remains disabled in the absense of the
writeFiltering attribute, of if it is explicitly set to 'yes'.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Simon Gaiser <simon@invisiblethingslab.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>