]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
4 years agodocs: Document qemu.conf locations
Michal Privoznik [Thu, 4 Mar 2021 19:32:29 +0000 (20:32 +0100)] 
docs: Document qemu.conf locations

Surprisingly, we never documented the relationship between
connection URI and the location of qemu.conf. Users might wonder
what qemu.conf is loaded when they are connecting to the session
daemon or embed URI. And what to do if the file doesn't exist for
the URI they're using.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoglib: Use safe glib event workaround in other event loops
Martin Kletzander [Thu, 4 Mar 2021 09:00:06 +0000 (10:00 +0100)] 
glib: Use safe glib event workaround in other event loops

Similarly to the crash workaround:

  commit 0db4743645b7a0611a3c0687f834205c9956f7fc
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Tue Jul 28 16:52:47 2020 +0100

    util: avoid crash due to race in glib event loop code

we need to do this in the other event loop as crash in that one was also
reported:

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoutil: Move glib event loop workaround to glibcompat
Martin Kletzander [Thu, 4 Mar 2021 08:34:19 +0000 (09:34 +0100)] 
util: Move glib event loop workaround to glibcompat

This way it can be used from other places as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoutil: Drop virFileMakePath() and virFileMakePathWithMode()
Michal Privoznik [Fri, 26 Feb 2021 08:30:07 +0000 (09:30 +0100)] 
util: Drop virFileMakePath() and virFileMakePathWithMode()

These functions are now unused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agolib: Replace virFileMakePath() with g_mkdir_with_parents()
Michal Privoznik [Fri, 26 Feb 2021 08:37:10 +0000 (09:37 +0100)] 
lib: Replace virFileMakePath() with g_mkdir_with_parents()

Generated using the following spatch:

  @@
  expression path;
  @@
  - virFileMakePath(path)
  + g_mkdir_with_parents(path, 0777)

However, 14 occurrences were not replaced, e.g. in
virHostdevManagerNew(). I don't really understand why.
Fixed by hand afterwards.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agolib: Replace virFileMakePathWithMode() with g_mkdir_with_parents()
Michal Privoznik [Fri, 26 Feb 2021 08:17:30 +0000 (09:17 +0100)] 
lib: Replace virFileMakePathWithMode() with g_mkdir_with_parents()

These functions are identical. Made using this spatch:

  @@
  expression path, mode;
  @@
  - virFileMakePathWithMode(path, mode)
  + g_mkdir_with_parents(path, mode)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agobuild: Require glib >= 2.56
Jim Fehlig [Mon, 1 Mar 2021 22:57:05 +0000 (15:57 -0700)] 
build:  Require glib >= 2.56

There are a few uses of g_autoslist in the qemu driver and likely more
will come throughout the codebase in the future. g_autoslist first
appeared in glib 2.56, so bump the minimum version

https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autoslist

Bumping the minimum version is an opportune time to update the list of
minimum glib versions found on the distros targeted by libvirt's
platform support policy

   RHEL-7: 2.56.1
   RHEL-8: 2.56.4
   Debian (Buster): 2.58.3
   OpenBSD (Ports): 2.66.7
   FreeBSD (Ports): 2.66.7
   openSUSE Leap 15.2, SLE15-SP2: 2.62.6
   Ubuntu (Bionic): 2.56.1
   macOS (Homebrew): 2.66.7

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agodocs: Spell out our policy concerning minor releases
Andrea Bolognani [Wed, 3 Mar 2021 09:36:10 +0000 (10:36 +0100)] 
docs: Spell out our policy concerning minor releases

We've already applied this policy on multiple occasions, but it's
good to have it written down so that there can be no confusion.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agonetdev_bandwidth_conf: Remove redundant variables/labels
Kristina Hanicova [Wed, 3 Mar 2021 10:48:20 +0000 (11:48 +0100)] 
netdev_bandwidth_conf: Remove redundant variables/labels

In functions: virNetDevBandwidthParseRate(),
virNetDevBandwidthParse()

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoUse g_autoptr instead of virNetDevBandwidthFree where possible
Kristina Hanicova [Wed, 3 Mar 2021 10:48:19 +0000 (11:48 +0100)] 
Use g_autoptr instead of virNetDevBandwidthFree where possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoUse g_steal_pointer where possible
Kristina Hanicova [Wed, 3 Mar 2021 10:48:18 +0000 (11:48 +0100)] 
Use g_steal_pointer where possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agonetdev_bandwidth_conf: Refractor virNetDevBandwidthParse()
Kristina Hanicova [Wed, 3 Mar 2021 10:48:17 +0000 (11:48 +0100)] 
netdev_bandwidth_conf: Refractor virNetDevBandwidthParse()

Refractoring includes:
* removal of VIR_FREE
* inversion of the condition

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agonetdev_bandwidth_conf: Use g_autofree where possible
Kristina Hanicova [Wed, 3 Mar 2021 10:48:16 +0000 (11:48 +0100)] 
netdev_bandwidth_conf: Use g_autofree where possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agovsh-table: Use g_autofree where possible
Kristina Hanicova [Wed, 3 Mar 2021 10:48:15 +0000 (11:48 +0100)] 
vsh-table: Use g_autofree where possible

In: vshTableRowNew(), vshTablePrint(), vshTablePrintToStdout().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agobuild-aux: require GNU grep on FreeBSD
Roman Bogorodskiy [Tue, 2 Mar 2021 14:31:36 +0000 (18:31 +0400)] 
build-aux: require GNU grep on FreeBSD

FreeBSD 13.x and newer ship BSD grep which apparently has some
performance issues causing certain syntax check tests to run longer than
the default 30 seconds timeout used by meson.

However, GNU grep is still available through the textproc/gnugrep port,
so require it on FreeBSD if /usr/bin/grep is a BSD grep to make checks
pass in a reasonable time.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agonode_device_conf: Remove redundant variables/labels
Kristina Hanicova [Wed, 3 Mar 2021 16:17:27 +0000 (17:17 +0100)] 
node_device_conf: Remove redundant variables/labels

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agonode_device_conf: use g_autoptr in virNodeDevCapPCIDevIommuGroupParseXML()
Kristina Hanicova [Wed, 3 Mar 2021 16:17:26 +0000 (17:17 +0100)] 
node_device_conf: use g_autoptr in virNodeDevCapPCIDevIommuGroupParseXML()

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agonode_device_conf: Refactoring functions in order to remove VIR_FREE
Kristina Hanicova [Wed, 3 Mar 2021 16:17:25 +0000 (17:17 +0100)] 
node_device_conf: Refactoring functions in order to remove VIR_FREE

By:
* declaration of an autofreed variable in for loop
* use of a new variable
* removal of VIR_FREE

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agonode_device_conf: Use g_autofree where possible
Kristina Hanicova [Wed, 3 Mar 2021 16:17:24 +0000 (17:17 +0100)] 
node_device_conf: Use g_autofree where possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_conf: Fix check for hyperv stimer
Tim Wiederhake [Thu, 4 Mar 2021 08:35:31 +0000 (09:35 +0100)] 
domain_conf: Fix check for hyperv stimer

VIR_DOMAIN_HYPERV_STIMER happens to have the same numerical value as
VIR_DOMAIN_FEATURE_HYPERV, resulting in the if-block to always being
executed when a "<hyperv>" tag is found, whether or not it actually
contained a "<stimer>" tag. This had no ill effects, as virXPathNodeSet()
would simply return 0 if that tag does not exist.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_conf: Add missing break in switch
Tim Wiederhake [Thu, 4 Mar 2021 08:35:30 +0000 (09:35 +0100)] 
domain_conf: Add missing break in switch

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_conf: Reduce scope of node in virDomainFeaturesDefParse
Tim Wiederhake [Thu, 4 Mar 2021 08:35:29 +0000 (09:35 +0100)] 
domain_conf: Reduce scope of node in virDomainFeaturesDefParse

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_conf: Reduce scope of gic_version in virDomainFeaturesDefParse
Tim Wiederhake [Thu, 4 Mar 2021 08:35:28 +0000 (09:35 +0100)] 
domain_conf: Reduce scope of gic_version in virDomainFeaturesDefParse

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_conf: Reduce scope of tmp in virDomainFeaturesDefParse
Tim Wiederhake [Thu, 4 Mar 2021 08:35:27 +0000 (09:35 +0100)] 
domain_conf: Reduce scope of tmp in virDomainFeaturesDefParse

Variables using `g_autofree` should not be manually VIR_FREE'd and reused.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: drop unused function virCgroupSetupCpuShares
Pavel Hrdina [Wed, 3 Mar 2021 13:29:22 +0000 (14:29 +0100)] 
vircgroup: drop unused function virCgroupSetupCpuShares

Previous commit removed all usage of this function so we can remove it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agocgroup: use virCgroupSetCpuShares instead of virCgroupSetupCpuShares
Pavel Hrdina [Wed, 3 Mar 2021 13:26:53 +0000 (14:26 +0100)] 
cgroup: use virCgroupSetCpuShares instead of virCgroupSetupCpuShares

Now that we enforce the cpu.shares range kernel will no longer silently
change the value that libvirt configures so there is no need to read
the value back to get the actual configuration.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: enforce range limit for cpu.shares
Pavel Hrdina [Wed, 3 Mar 2021 13:10:15 +0000 (14:10 +0100)] 
vircgroup: enforce range limit for cpu.shares

Before the conversion to using systemd DBus API to set the cpu.shares
there was some magic conversion done by kernel which was documented in
virsh manpage as well. Now systemd errors out if the value is out of
range.

Since we enforce the range for other cpu cgroup attributes 'quota' and
'period' it makes sense to do the same for 'shares' as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agocpu_map: Fix spelling of svme-addr-chk feature
Jiri Denemark [Thu, 4 Mar 2021 07:43:09 +0000 (08:43 +0100)] 
cpu_map: Fix spelling of svme-addr-chk feature

Commit a208176ca1d9eedf8aa6bf12fde6a7a9579ab549 introduced this feature
with an incorrect "svme-addr-check" spelling.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
4 years agolibxl: Fix node device detach when driver unspecified
Jim Fehlig [Mon, 1 Mar 2021 22:41:44 +0000 (15:41 -0700)] 
libxl: Fix node device detach when driver unspecified

Commit 887dd0d331 caused a small regression in NodeDeviceDetach in the libxl
driver when the 'driver' parameter is not specified. E.g.

# virsh nodedev-detach pci_0000_0a_10_0
error: Failed to detach device pci_0000_0a_10_0
error: An error occurred, but the cause is unknown

If the driver name is not specified, NULL is passed to
virDomainDriverNodeDeviceDetachFlags, in which case virPCIDeviceSetStubDriver
is never called to set the stub to pciback. Fix it by setting the driver to
"xen" if it is not specified when invoking NodeDeviceDetach.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Tue, 2 Mar 2021 09:40:22 +0000 (10:40 +0100)] 
Translated using Weblate (Finnish)

Currently translated at 17.1% (1805 of 10545 strings)

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

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agocpu_map: Install x86_EPYC-Milan.xml
Jiri Denemark [Tue, 2 Mar 2021 09:32:42 +0000 (10:32 +0100)] 
cpu_map: Install x86_EPYC-Milan.xml

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agocpu_map: Add EPYC-Milan x86 CPU model
Jiri Denemark [Mon, 1 Mar 2021 18:20:51 +0000 (19:20 +0100)] 
cpu_map: Add EPYC-Milan x86 CPU model

Introduced in QEMU 6.0.0 by 623972ceae091b31331ae4a1dc94fe5cbb891937

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: virerror: Remove virReportOOMError
Peter Krempa [Wed, 24 Feb 2021 10:34:00 +0000 (11:34 +0100)] 
util: virerror: Remove virReportOOMError

Trying to report an OOM error is pointless since our infrastructure to
report error needs to allocate memory to report the error.

In addition our code mistakenly reported OOM errors even in cases where
a function could fail for another reason, which would make issues harder
to debug.

Remove the virReportOOMError and backend so that programmers are forced
to think about what can happen. In case when there's another failure
possible a specific error should be reported and otherwise a direct
abort() is better since the logger would abort on g_new anyways.

This patch also removes the syntas-check which forces use of
virReportOOMError instead of using VIR_ERR_NO_MEMORY with other
functions. This allows possible future use when we'd end up in a
situation where trying to recover from an OOM would make sense, such as
when attempting to allocate a massive buffer.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirVMXConvertToUTF8: Report non-OOM error on failure of xmlBufferCreateStatic
Peter Krempa [Wed, 24 Feb 2021 10:30:24 +0000 (11:30 +0100)] 
virVMXConvertToUTF8: Report non-OOM error on failure of xmlBufferCreateStatic

The function has also non-OOM failure case when the passed string has 0
length, so reporting OOM error is not correct.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agostorage: Don't report OOM error on failure of glfs_new
Peter Krempa [Wed, 24 Feb 2021 09:22:52 +0000 (10:22 +0100)] 
storage: Don't report OOM error on failure of glfs_new

OOM isn't the only failure glfs_new can encounter. Report an error which
might give more insight. libgfapi seems to be setting errno but
reporting a system error migt be misleading.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: json: Report non-OOM error on yajl failure
Peter Krempa [Wed, 24 Feb 2021 09:13:27 +0000 (10:13 +0100)] 
util: json: Report non-OOM error on yajl failure

The yajl library returns a wide range of error codes so reporting OOM on
any failure is wrong. In case the error was really based by memory issue
the error reporting will probably cause an abort anyways. Change the
error message so that we know that it happened in JSON at least.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirVBoxSnapshotConfSaveVboxFile: abort() on failure to allocate xmlDoc and comment
Peter Krempa [Wed, 24 Feb 2021 10:28:56 +0000 (11:28 +0100)] 
virVBoxSnapshotConfSaveVboxFile: abort() on failure to allocate xmlDoc and comment

'xmlNewDoc' and 'xmlNewDocComment' return NULL only on allocation
failure. Attempting to raise an error is pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agolibxl: abort() on failure of libxl_cpu_bitmap_alloc()
Peter Krempa [Wed, 24 Feb 2021 10:32:10 +0000 (11:32 +0100)] 
libxl: abort() on failure of libxl_cpu_bitmap_alloc()

Attempting to report error in case when we ran out of memory is
pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovbox: abort() on allocation failure in UTF8<->UTF16 conversion
Peter Krempa [Wed, 24 Feb 2021 09:20:55 +0000 (10:20 +0100)] 
vbox: abort() on allocation failure in UTF8<->UTF16 conversion

Trying to report an error on OOM is pointless since error handling
allocates memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agohyperv: abort() failure of wsmc_fault_new()
Peter Krempa [Wed, 24 Feb 2021 09:32:38 +0000 (10:32 +0100)] 
hyperv: abort() failure of wsmc_fault_new()

The function just allocates a helper object. Reporting errors would be
pointless when we encounter OOM situation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: iohelper: Don't handle OOM from posix_memalign
Peter Krempa [Tue, 23 Feb 2021 16:15:08 +0000 (17:15 +0100)] 
util: iohelper: Don't handle OOM from posix_memalign

Similarly to other allocation calls abort() on failure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirURIFormat: abort() on failure
Peter Krempa [Tue, 23 Feb 2021 17:28:31 +0000 (18:28 +0100)] 
virURIFormat: abort() on failure

If the argument of 'xmlSaveUri' is non-NULL the function returns NULL on
OOM failure only. Thus we can directly abort rather than try to do the
impossible recovery.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: virprocess: abort() on CPU_ALLOC failure
Peter Krempa [Tue, 23 Feb 2021 17:17:59 +0000 (18:17 +0100)] 
util: virprocess: abort() on CPU_ALLOC failure

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirXMLParseHelper: abort() on allocation failure
Peter Krempa [Wed, 24 Feb 2021 08:53:41 +0000 (09:53 +0100)] 
virXMLParseHelper: abort() on allocation failure

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirXMLXPathContextNew: abort() on allocation failure
Peter Krempa [Wed, 24 Feb 2021 08:53:05 +0000 (09:53 +0100)] 
virXMLXPathContextNew: abort() on allocation failure

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoDon't report OOM error on xmlCopyNode failure
Peter Krempa [Tue, 23 Feb 2021 17:10:41 +0000 (18:10 +0100)] 
Don't report OOM error on xmlCopyNode failure

Out of memory isn't the only reason the function can fail. Add a message
stating that copying of a XML node failed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: xml: Add wrapper for 'xmlNewNode'
Peter Krempa [Wed, 24 Feb 2021 08:35:05 +0000 (09:35 +0100)] 
util: xml: Add wrapper for 'xmlNewNode'

Add a wrapper that will handle the out of memory condition by abort()
and also prevents callers from having to typecast the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: xml: Add virXMLBufferCreate wrapper
Peter Krempa [Tue, 23 Feb 2021 16:57:13 +0000 (17:57 +0100)] 
util: xml: Add virXMLBufferCreate wrapper

'xmlBufferCreate' returns NULL only on allocation failure. Add a wrapper
which will call 'abort()' in such case in a centralised spot. It doesn't
make much sense to continue execution from here.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: virnetlink: Add wrapper for 'nlmsg_alloc_simple'
Peter Krempa [Wed, 24 Feb 2021 08:51:19 +0000 (09:51 +0100)] 
util: virnetlink: Add wrapper for 'nlmsg_alloc_simple'

The function is used in many places and fails only on allocation
failures. Since trying to recover from allocation failure of a small
buffer by reporting error doesn't make sense add a wrapper for
'nlmsg_alloc_simple' which will 'abort()' on failure and replace all
allocations of netlink message with the new helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirfirewall: Remove impossible OOM error reporting
Peter Krempa [Tue, 23 Feb 2021 16:39:50 +0000 (17:39 +0100)] 
virfirewall: Remove impossible OOM error reporting

There's nothing that would set the 'err' field of virFirewallPtr to
ENOMEM so we can remove the checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirfirewall: virFirewallAddRuleFullV: Remove OOM check from VIR_APPEND_ELEMENT
Peter Krempa [Tue, 23 Feb 2021 16:38:18 +0000 (17:38 +0100)] 
virfirewall: virFirewallAddRuleFullV: Remove OOM check from VIR_APPEND_ELEMENT

VIR_APPEND_ELEMENT_COPY will abort the program on OOM so there's no need
to check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirfirewall: Remove OOM checks from virFirewallStartTransaction
Peter Krempa [Tue, 23 Feb 2021 16:36:36 +0000 (17:36 +0100)] 
virfirewall: Remove OOM checks from virFirewallStartTransaction

Neither virFirewallGroupNew nor VIR_EXPAND_N can fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirfirewall: Don't check OOM in ADD_ARG macro
Peter Krempa [Tue, 23 Feb 2021 16:34:35 +0000 (17:34 +0100)] 
virfirewall: Don't check OOM in ADD_ARG macro

VIR_RESIZE_N can't fail nowadays, adjust the macro.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirCloseCallbacksGetForConn: Remove OOM handling
Peter Krempa [Tue, 23 Feb 2021 16:17:10 +0000 (17:17 +0100)] 
virCloseCallbacksGetForConn: Remove OOM handling

VIR_EXPAND_N will abort so we can simplify the hash iterator.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: vircommand: Remove OOM handling
Peter Krempa [Tue, 23 Feb 2021 07:55:32 +0000 (08:55 +0100)] 
util: vircommand: Remove OOM handling

The OOM error handling is dead code nowadays.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirDomainDefSetMetadata: Rework memory handling
Peter Krempa [Wed, 24 Feb 2021 09:46:59 +0000 (10:46 +0100)] 
virDomainDefSetMetadata: Rework memory handling

Switch to use g_autoptr for 'doc' and 'new' local variables.
Additionally report proper error when 'xmlAddChild' fails because OOM is
not the only error it can report.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agolxc_process: Remove OOM handling from logging setup
Peter Krempa [Tue, 23 Feb 2021 16:13:54 +0000 (17:13 +0100)] 
lxc_process: Remove OOM handling from logging setup

'virLogGetFilters' doesn't return failure and 'virLogGetOutputs' reports
it's own errors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirBuildPath: Remove return value
Peter Krempa [Tue, 23 Feb 2021 16:28:09 +0000 (17:28 +0100)] 
virBuildPath: Remove return value

The function can't fail nowadays, remove the return value and adjust
callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirhostcputest: linuxCPUStatsCompareFiles: Don't check return value of virBufferConte...
Peter Krempa [Tue, 23 Feb 2021 15:59:04 +0000 (16:59 +0100)] 
virhostcputest: linuxCPUStatsCompareFiles: Don't check return value of virBufferContentAndReset

The buffer won't encounter OOM condition nowadays

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirCPUx86DataParse: Don't check error from x86FeatureNames
Peter Krempa [Tue, 23 Feb 2021 07:42:13 +0000 (08:42 +0100)] 
virCPUx86DataParse: Don't check error from x86FeatureNames

x86FeatureNames uses virBuffer and thus can't fail nowadays.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirCommandAddArgBuffer: Simplify clearing of @buf
Peter Krempa [Tue, 23 Feb 2021 07:49:42 +0000 (08:49 +0100)] 
virCommandAddArgBuffer: Simplify clearing of @buf

Get the buffer contents into a temporary variable with automatic
clearing so that the error branches don't have to reset the buffer.
Additionally handle the NULL string case before assignment.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirCommandAddEnv: Make stealing of argument more obvious
Peter Krempa [Tue, 23 Feb 2021 07:43:08 +0000 (08:43 +0100)] 
virCommandAddEnv: Make stealing of argument more obvious

The function is supposed to always consume the passed environment
variable string. Use a temp variable with autofree and g_steal_pointer
to prevent having to free it manually.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirDomainDefSetMetadata: Avoid temporary variable for string copy
Peter Krempa [Wed, 24 Feb 2021 09:41:00 +0000 (10:41 +0100)] 
virDomainDefSetMetadata: Avoid temporary variable for string copy

Since error checking was removed when switching to g_strdup, it doesn't
make much sense to have 'tmp' around.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoutil: xml: Introduce autoptr cleanup support for 'xmlNode'
Peter Krempa [Wed, 24 Feb 2021 09:38:04 +0000 (10:38 +0100)] 
util: xml: Introduce autoptr cleanup support for 'xmlNode'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoRemove useless comments for VIR_FROM_THIS definition
Peter Krempa [Tue, 23 Feb 2021 17:14:32 +0000 (18:14 +0100)] 
Remove useless comments for VIR_FROM_THIS definition

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agovirtpm: Fix @path handling in virTPMEmulatorInit()
Michal Privoznik [Thu, 25 Feb 2021 10:58:38 +0000 (11:58 +0100)] 
virtpm: Fix @path handling in virTPMEmulatorInit()

This function finds "swtmp", "swtpm_setup" and "swtpm_ioctl"
binaries in $PATH and stores resolved paths in global variables
so that they can be obtainer later. Anyway, the resolved path is
marked as g_autofree and to avoid its freeing later on in the
function the variable is set to NULL manually. Well, we have
g_steal_pointer() for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_tpm: Generate log file path among with storage path
Michal Privoznik [Wed, 24 Feb 2021 16:28:42 +0000 (17:28 +0100)] 
qemu_tpm: Generate log file path among with storage path

When starting a guest with TPM of type='emulator' an external
process is started with it (swtpm) to emulate TPM. This external
process is passed path to a log file via --logfile. The path to
the log file is generated in qemuTPMEmulatorPrepareHost() which
works, until the daemon is restarted. The problem is that the
path is not stored in private data or anywhere inside live XML
and thus later, when qemuExtTPMStop() is called (when shutting
off the guest) the stored logpath is NULL and thus its seclabel
is not cleaned up (see virSecuritySELinuxRestoreTPMLabels()).

Fortunately, qemuExtDevicesStop() (which calls qemuExtTPMStop()
eventually) does call qemuExtDevicesInitPaths() where the log
path can be generated again.

Basically, tpm->data.emulator.storagepath is generated in
qemuExtTPMInitPaths() and its seclabels are restored properly,
and this commit move logfile onto the same level.

This means, that the log path doesn't have to be generated in
qemuExtDevicesStart() because it was already done in
qemuExtDevicesPrepareHost().

This change also renders @vmname argument of
qemuTPMEmulatorPrepareHost() unused and thus is removed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1769196
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_tpm: Move logfile path generation into a separate function
Michal Privoznik [Thu, 25 Feb 2021 10:41:08 +0000 (11:41 +0100)] 
qemu_tpm: Move logfile path generation into a separate function

Strictly not needed, but the rest of paths is generated in
separate functions. Helps with code readability.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agotools: Fix dry run of libvirt_recover_xattrs.sh
Michal Privoznik [Wed, 24 Feb 2021 16:17:41 +0000 (17:17 +0100)] 
tools: Fix dry run of libvirt_recover_xattrs.sh

The libvirt_recover_xattrs.sh script can be used to remove stale
XATTRs that were left behind by secdrivers (which should happen
only if there's an imbalance between set and restore calls).
Anyway, the script has '-n' switch which is supposed to perform
just a dry run, i.e. just to report which files have XATTRs set
without any attempt to remove them.

But, when rewriting the script a few months ago a typo was
introduced which made the script report no files even if there
were files with XATTRs.

Fixes: 5377177f80da40ee7d47601400b50835f093715a
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoRemove redundant variables/labels
Kristina Hanicova [Thu, 25 Feb 2021 11:51:57 +0000 (12:51 +0100)] 
Remove redundant variables/labels

In files: src/lxc/lxc_native: in lxcAddNetworkRouteDefinition(),
src/conf/networkcommon_conf: in virNetDevIPRouteCreate() and
virNetDevIPRouteParseXML()

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agoUse g_autoptr instead of virNetDevIPRouteFree if possible
Kristina Hanicova [Thu, 25 Feb 2021 11:51:56 +0000 (12:51 +0100)] 
Use g_autoptr instead of virNetDevIPRouteFree if possible

In files: src/conf/domain_conf: in virDomainNetIPInfoParseXML(),
src/lxc/lxc_native: in lxcAddNetworkRouteDefinition(),
src/vz/vz_sdk: in prlsdkGetRoutes(), src/conf/networkcommon_conf:
in virNetDevIPRouteCreate()

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agonetworkcommon_conf: Use g_autofree where possible
Kristina Hanicova [Thu, 25 Feb 2021 11:51:55 +0000 (12:51 +0100)] 
networkcommon_conf: Use g_autofree where possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
4 years agocpumap: Add support for svme-addr-check CPU feature
Tim Wiederhake [Mon, 22 Feb 2021 12:20:10 +0000 (13:20 +0100)] 
cpumap: Add support for svme-addr-check CPU feature

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agocpumap: Add support for ibrs CPU feature
Tim Wiederhake [Mon, 22 Feb 2021 12:20:09 +0000 (13:20 +0100)] 
cpumap: Add support for ibrs CPU feature

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agocpu_map/sync_qemu_i386.py: Add mapping for svme-addr-check
Tim Wiederhake [Mon, 22 Feb 2021 12:20:08 +0000 (13:20 +0100)] 
cpu_map/sync_qemu_i386.py: Add mapping for svme-addr-check

This was added to qemu in commit 5447089c2b3b084b51670af36fc86ee3979e04be.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agocpu_map/sync_qemu_i386.py: Add mapping for ibrs
Tim Wiederhake [Mon, 22 Feb 2021 12:20:07 +0000 (13:20 +0100)] 
cpu_map/sync_qemu_i386.py: Add mapping for ibrs

This was added to qemu in commit 623972ceae091b31331ae4a1dc94fe5cbb891937.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agocpu_map/sync_qemu_i386.py: Add mapping for amd-ssbd
Tim Wiederhake [Mon, 22 Feb 2021 12:20:06 +0000 (13:20 +0100)] 
cpu_map/sync_qemu_i386.py: Add mapping for amd-ssbd

This was added to qemu in commit 623972ceae091b31331ae4a1dc94fe5cbb891937.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agohyperv: Fix 32bit compilation
Cole Robinson [Mon, 1 Mar 2021 18:15:37 +0000 (13:15 -0500)] 
hyperv: Fix 32bit compilation

Example:
../src/hyperv/hyperv_driver.c:3007:54: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘size_t’ {aka ‘unsigned int’} [-Werror=format=]
 3007 |             virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not attach serial port %lu"), i);

Signed-off-by: Cole Robinson <crobinso@redhat.com>
4 years agovirhostdev.c: remove missing PCI devs from hostdev manager
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:44 +0000 (09:54 -0300)] 
virhostdev.c: remove missing PCI devs from hostdev manager

virHostdevReAttachPCIDevices() is called when we want to re-attach
a list of hostdevs back to the host, either on the shutdown path or
via a 'virsh detach-device' call.  This function always count on the
existence of the device in the host to work, but this can lead to
problems. For example, a SR-IOV device can be removed via an admin
"echo 0 > /sys/bus/pci/devices/<addr>/sriov_numvfs", making the kernel
fire up and eventfd_signal() to the process, asking for the process to
release the device. The result might vary depending on the device driver
and OS/arch, but two possible outcomes are:

1) the hypervisor driver will detach the device from the VM, issuing a
delete event to Libvirt. This can be observed in QEMU;

2) the 'echo 0 > ...' will hang waiting for the device to be unplugged.
This means that the VM process failed/refused to release the hostdev back
to the host, and the hostdev will be detached during VM shutdown.

Today we don't behave well for both cases. We'll fail to remove the PCI device
reference from mgr->activePCIHostdevs and mgr->inactivePCIHostdevs because
we rely on the existence of the PCI device conf file in the sysfs. Attempting
to re-utilize the same device (assuming it is now present back in the host)
can result in an error like this:

$ ./run tools/virsh start vm1-sriov --console
error: Failed to start domain vm1-sriov
error: Requested operation is not valid: PCI device 0000:01:00.2 is in use by driver QEMU, domain vm1-sriov

For (1), a VM destroy/start cycle is needed to re-use the VF in the guest.
For (2), the effect is more nefarious, requiring a Libvirtd daemon restart
to use the VF again in any guest.

We can make it a bit better by checking, during virHostdevReAttachPCIDevices(),
if there is any missing PCI device that will be left behind in activePCIHostdevs
and inactivePCIHostdevs lists. Remove any missing device found from both lists,
unconditionally, matching the current state of the host. This change affects
the code path in (1) (processDeviceDeletedEvent into qemuDomainRemoveDevice, all
the way back to qemuHostdevReAttachPCIDevices) and also in (b) (qemuProcessStop
into qemuHostdevReAttachDomainDevices).

NB: Although this patch enables the possibility of 'outside Libvirt' SR-IOV
hotunplug of PCI devices, if the hypervisor and the PCI driver copes with it,
our goal is to mitigate what it is still considered a user oopsie. For all
supported purposes, the admin must remove the SR-IOV VFs from all running domains
before removing the VFs from the host.

Resolves:  https://gitlab.com/libvirt/libvirt/-/issues/72
Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListDel()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:43 +0000 (09:54 -0300)] 
virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListDel()

This change will allow us to remove PCI devices from a list
without the need of a PCI Device object, which will be need
in the next patch.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListSteal()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:42 +0000 (09:54 -0300)] 
virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListSteal()

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFind()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:41 +0000 (09:54 -0300)] 
virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFind()

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFindIndex()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:40 +0000 (09:54 -0300)] 
virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFindIndex()

We're going to need a way to remove a PCI Device from a list without having
a valid virPCIDevicePtr, because the device is missing from the host. This
means that virPCIDevicesListDel() must operate with a PCI Device address
instead.

Turns out that virPCIDevicesListDel() and its related functions only use
the virPCIDeviceAddressPtr of the virPCIDevicePtr, so this change is
simple to do and will not cause hassle in all other callers. Let's
start adapting virPCIDeviceListFindIndex() and crawl our way up to
virPCIDevicesListDel().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu_cgroup.c: skip absent PCI devices in qemuTeardownHostdevCgroup()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:39 +0000 (09:54 -0300)] 
qemu_cgroup.c: skip absent PCI devices in qemuTeardownHostdevCgroup()

There is no need to bother with cgroup tearing down for absent
PCI devices, given that their entries in the sysfs are already
gone.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirhostdev.c: add virHostdevIsPCIDevice() helper
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:38 +0000 (09:54 -0300)] 
virhostdev.c: add virHostdevIsPCIDevice() helper

Add a helper to quickly determine if a hostdev is a PCI device,
instead of doing a tedious 'if' check with hostdev mode and
subsys type.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirsh-domain.c: use g_auto* in cmdDetachDevice()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:37 +0000 (09:54 -0300)] 
virsh-domain.c: use g_auto* in cmdDetachDevice()

Use g_auto* pointers to avoid the need of a cleanup label. The
type of the pointer 'virDomainPtr dom' was changed to its alias
'virshDomainPtr' to allow the use of g_autoptr().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodac, selinux: skip setting/restoring label for absent PCI devices
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:33 +0000 (09:54 -0300)] 
dac, selinux: skip setting/restoring label for absent PCI devices

If the underlying PCI device of a hostdev does not exist in the
host (e.g. a SR-IOV VF that was removed while the domain was
running), skip security label handling for it.

This will avoid errors that happens during qemuProcessStop() time,
where a VF that was being used by the domain is not present anymore.
The restore label functions of both DAC and SELinux drivers will
trigger errors in virPCIDeviceNew().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirhostdev.c: virHostdevGetPCIHostDevice() now reports missing device
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:30 +0000 (09:54 -0300)] 
virhostdev.c: virHostdevGetPCIHostDevice() now reports missing device

Gitlab issue #72 [1] reports that removing SR-IOVs VFs before
removing the devices from the running domains can have strange
consequences. QEMU might be able to hotunplug the device inside the
guest, but Libvirt will not be aware of that, and then the guest is
now inconsistent with the domain definition.

There's also the possibility of the VFs removal not succeeding
while the domain is running but then, as soon as the domain
is shutdown, all the VFs are removed. Libvirt can't handle
the removal of the PCI devices while trying to reattach the
hostdevs, and the Libvirt daemon can be left in an inconsistent
state (see [2]).

This patch starts to address the issue related in Gitlab #72, most
notably the issue described in [2]. When shutting down a domain
with SR-IOV hostdevs that got missing, virHostdevReAttachPCIDevices()
is failing the whole process and failing to reattach all the
PCI devices, including the ones that aren't related to the VFs that
went missing. Let's make it more resilient with host changes by
changing virHostdevGetPCIHostDevice() to return an exclusive error
code '-2' for this case. virHostdevGetPCIHostDeviceList() can then
tell when virHostdevGetPCIHostDevice() failed to find the PCI
device of a hostdev and continue to make the list of PCI devices.

virHostdevReAttachPCIDevices() will now be able to proceed reattaching
all other valid PCI devices, at least. The 'ghost hostdevs' will be
handled later on.

[1] https://gitlab.com/libvirt/libvirt/-/issues/72
[2] https://gitlab.com/libvirt/libvirt/-/issues/72#note_459032148

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci: introduce virPCIDeviceExists()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:29 +0000 (09:54 -0300)] 
virpci: introduce virPCIDeviceExists()

We're going to add logic to handle the case where a previously
existing PCI device does not longer exist in the host.

The logic was copied from virPCIDeviceNew(), which verifies if a
PCI device exists in the host, returning NULL and throwing an
error if it doesn't. The NULL is used for other errors as well
(product/vendor id read errors, dev id overflow), meaning that we
can't re-use virPCIDeviceNew() for the purpose of detecting
if the device exists.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoUse g_steal_pointer where possible
Kristina Hanicova [Tue, 23 Feb 2021 13:58:29 +0000 (14:58 +0100)] 
Use g_steal_pointer where possible

Via coccinelle (not the handbag!)
spatches used:
@ rule1 @
identifier a, b;
symbol NULL;
@@

- b = a;
  ... when != a
- a = NULL;
+ b = g_steal_pointer(&a);

@@

- *b = a;
  ... when != a
- a = NULL;
+ *b = g_steal_pointer(&a);

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemuBackupJobTerminate: Don't calculate backup job stats if VM isn't active
Peter Krempa [Thu, 25 Feb 2021 12:33:39 +0000 (13:33 +0100)] 
qemuBackupJobTerminate: Don't calculate backup job stats if VM isn't active

If the VM isn't active calculating the job stats doesn't make sense.
Additionally this prevents a crash of libvirtd if qemu terminates while
libvirt wasn't running:

Thread 28 "init-backup-tes" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb9310640 (LWP 3201116)]
qemuDomainJobInfoUpdateTime (jobInfo=0x0) at ../../../libvirt/src/qemu/qemu_domainjob.c:275
275     if (!jobInfo->started)
(gdb) bt
 #0  qemuDomainJobInfoUpdateTime (jobInfo=0x0) at ../../../libvirt/src/qemu/qemu_domainjob.c:275
 #1  0x00007fffcba1a12d in qemuBackupJobTerminate (vm=0x7fff9c1bc840, jobstatus=QEMU_DOMAIN_JOB_STATUS_CANCELED) at ../../../libvirt/src/qemu/qemu_backup.c:563
 #2  0x00007fffcbaefcae in qemuProcessStop
    (driver=0x7fff9c144ff0, vm=0x7fff9c1bc840, reason=VIR_DOMAIN_SHUTOFF_DAEMON, asyncJob=QEMU_ASYNC_JOB_NONE, flags=<optimized out>)
    at ../../../libvirt/src/qemu/qemu_process.c:7812
 #3  0x00007fffcbaf2a10 in qemuProcessReconnect (opaque=<optimized out>) at ../../../libvirt/src/qemu/qemu_process.c:8578
 #4  0x00007ffff7c46bb5 in virThreadHelper (data=<optimized out>) at ../../../libvirt/src/util/virthread.c:233
 #5  0x00007ffff6e453f9 in start_thread () at /lib64/libpthread.so.0
 #6  0x00007ffff766fb53 in clone () at /lib64/libc.so.6

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuBackupJobTerminate: Move cleanup of temp files earlier
Peter Krempa [Thu, 25 Feb 2021 12:32:10 +0000 (13:32 +0100)] 
qemuBackupJobTerminate: Move cleanup of temp files earlier

Upcoming patch will remove unnecessary actions if the VM crashed. The
cleanup needs to be performed always, thus needs to be moved earlier.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageVolDefFormat: Don't format empty <source>
Peter Krempa [Thu, 25 Feb 2021 13:11:05 +0000 (14:11 +0100)] 
virStorageVolDefFormat: Don't format empty <source>

If there are no source extents the volume XML has an empty <source>
element. Remove it if there's nothing in it by using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageVolDefFormat: Extract formatting of source extents
Peter Krempa [Thu, 25 Feb 2021 13:03:15 +0000 (14:03 +0100)] 
virStorageVolDefFormat: Extract formatting of source extents

Move the extent formatting code into
virStorageVolDefFormatSourceExtents.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agostorageBackendProbeTarget: Don't fail if backing store can't be parsed
Peter Krempa [Thu, 25 Feb 2021 12:51:51 +0000 (13:51 +0100)] 
storageBackendProbeTarget: Don't fail if backing store can't be parsed

When the backing store of the image can't be parsed
virStorageSourceNewFromBacking returns -1. storageBackendProbeTarget
then also fails which makes the pool refresh fail or even the storage
pool becomes inactive after (re)start of libvirtd.

In situations when we can't access the backing store via network we
just report the backing store string, thus we can do the same thing for
unparsable backing store to prevent the pool from going offline.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agostorageBackendProbeTarget: Check return value of virStorageSourceNewFromBacking
Peter Krempa [Thu, 25 Feb 2021 10:22:58 +0000 (11:22 +0100)] 
storageBackendProbeTarget: Check return value of virStorageSourceNewFromBacking

Commit bc3a78f61a2aaac3 errorneously removed the return value check from
virStorageSourceNewFromBacking. In cases when we e.g. can't parse the
backing store string this leads to a crash:

 #0  virStorageSourceGetActualType (def=0x0) at ../../../libvirt/src/conf/storage_source_conf.c:1014
 #1  0x00007ffff7cee4f9 in virStorageSourceIsLocalStorage (src=<optimized out>) at ../../../libvirt/src/conf/storage_source_conf.c:1026
 #2  0x00007ffff455c97c in storageBackendProbeTarget (encryption=0x7fff9c122ce8, target=0x7fff9c122c68) at ../../../libvirt/src/storage/storage_util.c:3443
 #3  virStorageBackendRefreshVolTargetUpdate (vol=0x7fff9c122c30) at ../../../libvirt/src/storage/storage_util.c:3519
 #4  0x00007ffff455cdc0 in virStorageBackendRefreshLocal (pool=0x7fff9c010ea0) at ../../../libvirt/src/storage/storage_util.c:3593
 #5  0x00007ffff454f0a1 in storagePoolRefreshImpl
    (backend=backend@entry=0x7ffff4711180 <virStorageBackendDirectory>, obj=obj@entry=0x7fff9c010ea0, stateFile=stateFile@entry=0x7fff9c111a90 "/var/run/libvirt/storage/tmp.xml") at ../../../libvirt/src/storage/storage_driver.c:103
 #6  0x00007ffff4550ea5 in storagePoolUpdateStateCallback (obj=0x7fff9c010ea0, opaque=<optimized out>) at ../../../libvirt/src/storage/storage_driver.c:165
 #7  0x00007ffff7cefef4 in virStoragePoolObjListForEachCb (payload=<optimized out>, name=<optimized out>, opaque=0x7fffc8a489c0)
    at ../../../libvirt/src/conf/virstorageobj.c:435
 #8  0x00007ffff7c03195 in virHashForEachSafe
    (table=<optimized out>, iter=iter@entry=0x7ffff7cefec0 <virStoragePoolObjListForEachCb>, opaque=opaque@entry=0x7fffc8a489c0)
    at ../../../libvirt/src/util/virhash.c:414
 #9  0x00007ffff7cf0520 in virStoragePoolObjListForEach
    (pools=<optimized out>, iter=iter@entry=0x7ffff4550e10 <storagePoolUpdateStateCallback>, opaque=opaque@entry=0x0)
    at ../../../libvirt/src/conf/virstorageobj.c:468
 #10 0x00007ffff454f43a in storagePoolUpdateAllState () at ../../../libvirt/src/storage/storage_driver.c:184
 #11 storageStateInitialize (privileged=<optimized out>, root=<optimized out>, callback=<optimized out>, opaque=<optimized out>)
    at ../../../libvirt/src/storage/storage_driver.c:315
 #12 0x00007ffff7e10c04 in virStateInitialize
    (opaque=0x555555621820, callback=0x55555557b1d0 <daemonInhibitCallback>, root=0x0, mandatory=<optimized out>, privileged=true)
    at ../../../libvirt/src/libvirt.c:656
 #13 virStateInitialize
    (privileged=<optimized out>, mandatory=mandatory@entry=false, root=root@entry=0x0, callback=callback@entry=0x55555557b1d0 <daemonInhibitCallback>, opaque=opaque@entry=0x555555621820) at ../../../libvirt/src/libvirt.c:638
 #14 0x000055555557b230 in daemonRunStateInit (opaque=0x555555621820) at ../../../libvirt/src/remote/remote_daemon.c:605
 #15 0x00007ffff7c46bb5 in virThreadHelper (data=<optimized out>) at ../../../libvirt/src/util/virthread.c:233
 #16 0x00007ffff6e453f9 in start_thread () at /lib64/libpthread.so.0
 #17 0x00007ffff766fb53 in clone () at /lib64/libc.so

An invalid image can be easily created by:

$ qemu-img create -f qcow2 -F qcow2 -b 'json:{' -u img.qcow2 10M

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoPost-release version bump to 7.2.0
Jiri Denemark [Mon, 1 Mar 2021 10:58:58 +0000 (11:58 +0100)] 
Post-release version bump to 7.2.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoRelease of libvirt-7.1.0 v7.1.0
Jiri Denemark [Mon, 1 Mar 2021 10:55:46 +0000 (11:55 +0100)] 
Release of libvirt-7.1.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Thu, 25 Feb 2021 10:40:18 +0000 (11:40 +0100)] 
Translated using Weblate (Finnish)

Currently translated at 15.5% (1638 of 10545 strings)

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

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agoqemu_monitor: Document qemuMonitorUnregister() v7.1.0-rc2
Michal Privoznik [Wed, 24 Feb 2021 12:55:33 +0000 (13:55 +0100)] 
qemu_monitor: Document qemuMonitorUnregister()

The most important bit is that the caller is expected to pass
locked monitor.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>