]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agosrc/hypervisor: introduce domain_driver.c
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:16 +0000 (16:29 -0500)]
src/hypervisor: introduce domain_driver.c

lxcDomainMergeBlkioDevice() and qemuDomainMergeBlkioDevice()
are the same functions. This duplicated code can't be put in
the existing domain_cgroup.c since it's not cgroup related.

This patch introduces a new src/hypervisor/domain_driver.c to
host this more generic code that can be shared between virt
drivers. This new file is then used to create a new helper
called virDomainDeivceMergeBlkioDevice() to eliminate the code
repetition mentioned above. Callers in LXC and QEMU files
were updated.

This change is a preliminary step for more code reduction of
cgroup related code inside lxcDomainSetBlkioParameters() and
qemuDomainSetBlkioParameters().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup.c: add virCgroupSetupCpuPeriodQuota()
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:15 +0000 (16:29 -0500)]
vircgroup.c: add virCgroupSetupCpuPeriodQuota()

qemuSetupCgroupVcpuBW() and lxcSetVcpuBWLive() shares the
same code to set CPU CFS period and quota. This code can be
moved to a new virCgroupSetupCpuPeriodQuota() helper to
avoid code repetition.

A similar code is also executed in virLXCCgroupSetupCpuTune(),
but without the rollback on error. Use the new helper in this
function as well since the 'period' rollback, if not a
straight improvement for virLXCCgroupSetupCpuTune(), is
benign. And we end up cutting more code repetition.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup.c: add virCgroupSetupCpuShares()
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:14 +0000 (16:29 -0500)]
vircgroup.c: add virCgroupSetupCpuShares()

The code that calls virCgroupSetCpuShares() and virCgroupGetCpuShares()
is repeated in 4 different places. Let's put it in a new
virCgroupSetupCpuShares() to avoid code repetition.

There's a reason of why we execute a Get in the same value we
just executed Set, explained in detail by commit 97814d8ab3.
Let's add a gist of the reasoning behind it as a comment in
this new function as well.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup.c: add virCgroupSetupCpusetCpus()
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:13 +0000 (16:29 -0500)]
vircgroup.c: add virCgroupSetupCpusetCpus()

The code from qemuSetupCgroupCpusetCpus() and virLXCCgroupSetupCpusetTune()
can be centralized in a new helper called virCgroupSetupCpusetCpus().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodomain_cgroup.c: add virDomainCgroupSetupMemtune()
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:12 +0000 (16:29 -0500)]
domain_cgroup.c: add virDomainCgroupSetupMemtune()

virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares
duplicated code that can be put in a new helper to avoid
code repetition.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agosrc: introduce hypervisor/domain_cgroup.c
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:11 +0000 (16:29 -0500)]
src: introduce hypervisor/domain_cgroup.c

There is duplicated code between virt drivers that needs to
be moved to avoid code repetition. In the case of duplicated
code between lxc_cgroup.c and qemu_cgroup.c a common place
would be utils/vircgroup.c. The problem is that this would
introduce /conf related definitions that shouldn't be imported
to vircgroup.c, which is supposed to be a place for utilitary
cgroups functions only. And syntax-check would forbid it anyway
due to cross-directory includes being used.

An alternative would be to overload domain_conf.c, which already
contains all the definitions required. But that file is already
crowded with XML handling code and we wouldn't do any favors to
it by putting more utilitary, non-XML parsing/formatting code
there.

In [1], Cole suggested a 'domain_cgroup' file to host common code
between lxc_cgroup and qemu_cgroup, and Daniel suggested a
'src/hypervisor' dir to host these type of files. This patch
introduces src/hypervisor/domain_cgroup.c and, to get started,
introduces a new virDomainCgroupSetupBlkio() function to host shared
code between virLXCCgroupSetupBlkioTune() and qemuSetupBlkioCgroup().

[1] https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup.c: turn virCgroup{Get/Set}BlkioDevice* into static
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:10 +0000 (16:29 -0500)]
vircgroup.c: turn virCgroup{Get/Set}BlkioDevice* into static

Previous patch moved all duplicated code that were setting
and getting BlkioDevice parameters to vircgroup.c. We can
turn them into static and spare a few symbols in
libvirt_private.syms.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agolxc,qemu: use virCgroupSetupBlkioDevice* helpers
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:09 +0000 (16:29 -0500)]
lxc,qemu: use virCgroupSetupBlkioDevice* helpers

There are code repetition of set() and get() blkio device
parameters across lxc and qemu files. Use the new vircgroup
helpers to trim the repetition a bit.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup.c: add virCgroupSetupBlkioDevice* helpers
Daniel Henrique Barboza [Mon, 17 Feb 2020 21:29:08 +0000 (16:29 -0500)]
vircgroup.c: add virCgroupSetupBlkioDevice* helpers

The current use of the functions that set and get
BlkioDevice attributes is doing a set(), followed by
a get() of the same parameter right after. This is done
because there is no guarantee that the kernel will accept
the desired value given by the set() call, thus we need to
execute a get() right after to get the actual value.

This patch adds helpers inside vircgroup.c to execute these
operations. Next patch will use these helpers to reduce
code repetition in LXC and QEMU files.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agofix paths to openrc.init.in files
Ján Tomko [Sun, 23 Feb 2020 11:21:02 +0000 (12:21 +0100)]
fix paths to openrc.init.in files

The inc.am Makfiles are included by src/Makefile.am.
Adjust the paths added to OPENRC_INIT_FILES_IN
accordingly.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: f4b1c020a2c8493473bf868231cee6a952d57e6f
5 years agoAdd virtlockd and virtlogd init scripts
Ryan Moeller [Sat, 22 Feb 2020 05:01:39 +0000 (00:01 -0500)]
Add virtlockd and virtlogd init scripts

These are missing files for OpenRC.

Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: Expand documentation for the tickpolicy timer attribute
Andrea Bolognani [Tue, 18 Feb 2020 20:43:08 +0000 (21:43 +0100)]
docs: Expand documentation for the tickpolicy timer attribute

The current documentation is fairly terse and not easy to decode
for someone who's not intimately familiar with the inner workings
of timer devices. Expand on it by providing a somewhat verbose
description of what behavior each policy will result in, as seen
from both the guest OS and host point of view.

This is lifted directly from QEMU commit

  commit 2a7d957596786404c4ed16b089273de95a9580ad
  Author: Andrea Bolognani <abologna@redhat.com>
  Date:   Tue Feb 11 19:37:44 2020 +0100

    qapi: Expand documentation for LostTickPolicy

  v4.2.0-1442-g2a7d957596

The original text also matched word for word the documentation
found in QEMU.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemuTestParseCapabilitiesArch: Free @binary
Michal Privoznik [Fri, 21 Feb 2020 07:28:13 +0000 (08:28 +0100)]
qemuTestParseCapabilitiesArch: Free @binary

The variable is allocated, but never freed.

==119642== 29 bytes in 1 blocks are definitely lost in loss record 409 of 671
==119642==    at 0x483579F: malloc (vg_replace_malloc.c:309)
==119642==    by 0x5AB075F: __vasprintf_internal (in /lib64/libc-2.29.so)
==119642==    by 0x57C1A28: g_vasprintf (in /usr/lib64/libglib-2.0.so.0.6000.7)
==119642==    by 0x579A0CC: g_strdup_vprintf (in /usr/lib64/libglib-2.0.so.0.6000.7)
==119642==    by 0x4AE6D58: vir_g_strdup_printf (glibcompat.c:197)
==119642==    by 0x136EEE: qemuTestParseCapabilitiesArch (testutilsqemu.c:291)
==119642==    by 0x138506: testQemuInfoSetArgs (testutilsqemu.c:763)
==119642==    by 0x135FFF: mymain (qemuxml2argvtest.c:3093)
==119642==    by 0x13A60E: virTestMain (testutils.c:839)
==119642==    by 0x1368C2: main (qemuxml2argvtest.c:3121)

Fixes: 42b3e5b9e4b919644afe55a815992c07fb79b9dc
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirDomainNetDefClear: Free @persistent name
Michal Privoznik [Fri, 21 Feb 2020 07:28:04 +0000 (08:28 +0100)]
virDomainNetDefClear: Free @persistent name

The persistent alias name @persistent is allocated in
virDomainNetDefParseXML() but never freed.

==119642== 22 bytes in 2 blocks are definitely lost in loss record 178 of 671
==119642==    at 0x483579F: malloc (vg_replace_malloc.c:309)
==119642==    by 0x58F89F1: xmlStrndup (in /usr/lib64/libxml2.so.2.9.9)
==119642==    by 0x4BA3B74: virXMLPropString (virxml.c:520)
==119642==    by 0x4BDB0C5: virDomainNetDefParseXML (domain_conf.c:11876)
==119642==    by 0x4BF9EF4: virDomainDefParseXML (domain_conf.c:21196)
==119642==    by 0x4BFCD5B: virDomainDefParseNode (domain_conf.c:21943)
==119642==    by 0x4BFCC36: virDomainDefParse (domain_conf.c:21901)
==119642==    by 0x4BFCCCB: virDomainDefParseFile (domain_conf.c:21924)
==119642==    by 0x114A9D: testCompareXMLToArgv (qemuxml2argvtest.c:452)
==119642==    by 0x13894F: virTestRun (testutils.c:143)
==119642==    by 0x11F46E: mymain (qemuxml2argvtest.c:1316)
==119642==    by 0x13A60E: virTestMain (testutils.c:839

Fixes: fb0509d06ac57434c2edbd81ee63deb32a0e598a
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirDomainFSDefFree: Unref private data
Michal Privoznik [Fri, 21 Feb 2020 07:27:50 +0000 (08:27 +0100)]
virDomainFSDefFree: Unref private data

The privateData object is allocated in virDomainFSDefNew() but
never unref'd.

==119642== 480 bytes in 20 blocks are definitely lost in loss record 656 of 671
==119642==    at 0x4837B86: calloc (vg_replace_malloc.c:762)
==119642==    by 0x57806A0: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6000.7)
==119642==    by 0x4AE7392: virAllocVar (viralloc.c:331)
==119642==    by 0x4B64395: virObjectNew (virobject.c:241)
==119642==    by 0x48F1464: qemuDomainFSPrivateNew (qemu_domain.c:1427)
==119642==    by 0x4BBF004: virDomainFSDefNew (domain_conf.c:2307)
==119642==    by 0x4BD859A: virDomainFSDefParseXML (domain_conf.c:11217)
==119642==    by 0x4BF9DD1: virDomainDefParseXML (domain_conf.c:21179)
==119642==    by 0x4BFCD5B: virDomainDefParseNode (domain_conf.c:21943)
==119642==    by 0x4BFCC36: virDomainDefParse (domain_conf.c:21901)
==119642==    by 0x4BFCCCB: virDomainDefParseFile (domain_conf.c:21924)
==119642==    by 0x114A9D: testCompareXMLToArgv (qemuxml2argvtest.c:452)

Fixes: 5120577ed79f89e172e3deed534fa9b585f4701f
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemumonitorjsontest: add test for cpu baseline
Collin Walling [Thu, 20 Feb 2020 22:01:48 +0000 (17:01 -0500)]
qemumonitorjsontest: add test for cpu baseline

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemumonitorjsontest: add tests for cpu comparison
Collin Walling [Thu, 20 Feb 2020 22:01:47 +0000 (17:01 -0500)]
qemumonitorjsontest: add tests for cpu comparison

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemumonitorjsontest: load schema based on specified arch
Collin Walling [Thu, 20 Feb 2020 22:01:46 +0000 (17:01 -0500)]
qemumonitorjsontest: load schema based on specified arch

There are some architectures that support capabilities that others
do not (e.g. s390x supports cpu comparison and baseline via QEMU).

Let's make testQEMUSchemaLoad accept a string to specify the schema
to load based on the specified arch.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: add info about <portOptions isolated='yes'/> to news file
Laine Stump [Mon, 17 Feb 2020 03:54:45 +0000 (22:54 -0500)]
docs: add info about <portOptions isolated='yes'/> to news file

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: extra validation for <port isolated='yes'/>
Laine Stump [Mon, 17 Feb 2020 03:34:59 +0000 (22:34 -0500)]
conf: extra validation for <port isolated='yes'/>

During the hypervisor-agnostic validation of network devices, verify
that the interface type is either "network" or "bridge", and that if
there is any <virtualport>, that it doesn't have any type associated
with it.

This needs to be done both for the parse-time validation and for
runtime validation (after a port has been acquired from any associated
network), because an interface with type='network' could have an
actual type at runtime of "hostdev" or "direct", neither of which
support isolated='true' (yet). Likewise, if an interface is
type='network', then at runtime a <virtualport> with a type that
doesn't support isolated='yes' (e.g. "openvswitch", "802.1Qbh" -
currently *none* of the available virtualport types support it)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: support updating <port isolated='yes|no'/> during device update
Laine Stump [Fri, 14 Feb 2020 18:51:31 +0000 (13:51 -0500)]
qemu: support updating <port isolated='yes|no'/> during device update

This setting can be updating very easily on an already active
interface by just changing it in sysfs. If the bridge used for
connection is also changed, there is no need to separately update it,
because the new setting isf done as a part of connecting to the bridge
anyway.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu/lxc: plumb isolatedPort from config down through bridge attachment
Laine Stump [Thu, 13 Feb 2020 17:57:47 +0000 (12:57 -0500)]
qemu/lxc: plumb isolatedPort from config down through bridge attachment

This patch pushes the isolatedPort setting from the <interface> down
all the way to the callers of virNetDevBridgeAddPort(), and sets
BR_ISOLATED on the port (using virNetDevBridgePortSetIsolated()) after
the port has been successfully added to the bridge.

Signed-off-by: Laine Stump <laine@redhat.com>
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agonetwork: propagate <port isolated='yes'/> between network and domain
Laine Stump [Thu, 6 Feb 2020 23:15:25 +0000 (18:15 -0500)]
network: propagate <port isolated='yes'/> between network and domain

Similar to the way that the <vlan>, <bandwidth>, and <virtualport>
elements and the trustGuestRxFilters attribute in a <network> (or in
the appropriate <portgroup> element of a <network> can be applied to a
port when it is allocated for a domain's network interface, this patch
checks for a configured value of <port isolated="yes|no"/> in
either the domain <interface> or in the network, setting isolatedPort
in the <networkport> to the first one it finds (the setting from the
domain's <interface> is preferred). This, in turn, is passed back to
the domain when a port is allocated, so that the domain will use that
setting.

(One difference from <vlan>, <bandwidth>, <virtualport>, and
trustGuestRxFilters, is that all of those can be set in a <portgroup>
so that they can be applied only to a subset of interfaces connected
to the network. This didn't really make sense for the isolated setting
due to the way that it's implemented in Linux - the BR_ISOLATED flag
will prevent traffic from passing between two ports that both have
BR_ISOLATED set, but traffic can still go between those ports and
other ports that *don't* have BR_ISOLATED. (It would be nice if all
traffic from a BR_ISOLATED port could be blocked except traffic going
to/from a designated egress port or ports, but instead the entire
feature is implemented as a single flag. Because of this, it's really
only useful if all the ports on a network are isolated, so setting it
for a subset has no practical utility.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: parse/format <port isolated='yes|no'/>
Laine Stump [Wed, 29 Jan 2020 15:29:21 +0000 (10:29 -0500)]
conf: parse/format <port isolated='yes|no'/>

This is a very simple thing to parse and format, but needs to be done
in 4 places, so two trivial utility functions have been made that can
be called from all the higher level parser/formatters:

  <domain><interface>
  <domain><interface><actual> (only in domain status)
  <network>
  <networkport>

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: query/set BR_ISOLATED flag on netdevs attached to bridge
Laine Stump [Mon, 20 Jan 2020 21:27:02 +0000 (16:27 -0500)]
util: query/set BR_ISOLATED flag on netdevs attached to bridge

When this flag is set for an interface attached to a bridge, traffic
to/from the specified interface can only enter/exit the bridge via
another attached interface that *doesn't* have the BR_ISOLATED flag
set. This can be used to permit guests to communicate with the rest of
the network, but not with each other.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: save/restore original error when recovering from failed bridge attach
Laine Stump [Thu, 13 Feb 2020 16:57:43 +0000 (11:57 -0500)]
qemu: save/restore original error when recovering from failed bridge attach

Not only was the original error code destroyed in the case of
encountering an error during recovery from a failed attach to the
bridge (and then *that* error was destroyed by logging a *second*
error about the failure to recover - virNetDevBridgeAddPort() already
logs an error, so the one about failing to recover was redundant), but
if the recovery was successful, the function would then return success
to the caller even though it had failed.

Fixes: 2711ac87160d7ac7d550c57f4339e6c6749942fa
(overwritten errors were introduced along with this functionality)
Fixes: 6bde0a1a37424c84492658223ff845b1ebb0e25c
(the wrong return value was introduced by a refactor)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoschema: add missing vlan element to networkport RNG
Laine Stump [Fri, 14 Feb 2020 23:59:52 +0000 (18:59 -0500)]
schema: add missing vlan element to networkport RNG

This is in the data structure and the parse/format functions, and is
getting passed all around correctly, it just was omitted from the RNG,
which hasn't been noticed because no human is creating <networkport>
XML, and so it's never getting validated against the schema.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoschema: trivial indentation fix
Laine Stump [Sun, 26 Jan 2020 01:11:24 +0000 (20:11 -0500)]
schema: trivial indentation fix

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agom4: libxl: properly fail when libxl is required
Ján Tomko [Thu, 20 Feb 2020 14:53:08 +0000 (15:53 +0100)]
m4: libxl: properly fail when libxl is required

We specify "true" as the fail-action for LIBVIRT_CHECK_PKG.

This was used when we had a fallback to non-pkg-config detection,
then removed in commit 5bdcef13d13560512c7d6d8c9e8822e456889e0c
later re-introduced in commit dc3d2c9f8c7678a950abedd227b1587ca62335c4
and then left in when removing the old detection again in
commit 18981877d2e20390a79d068861a24e716f8ee422

Remove it to properly error out when libxl was requested but not
detected.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 18981877d2e20390a79d068861a24e716f8ee422
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu_migration: Rearrange some checks in qemuMigrationSrcIsAllowed()
Michal Privoznik [Thu, 20 Feb 2020 10:54:44 +0000 (11:54 +0100)]
qemu_migration: Rearrange some checks in qemuMigrationSrcIsAllowed()

Firstly, the check for disk I/O error can be moved into 'if
(!offline)' section a few lines below.
Secondly, checks for vmstate and slirp should be moved under the
same section because they reflect live state of a domain. For
offline migration no QEMU is involved and thus these restrictions
are not valid.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Don't explicitly remove pidfile after virPidFileForceCleanupPath()
Michal Privoznik [Thu, 20 Feb 2020 10:46:24 +0000 (11:46 +0100)]
qemu: Don't explicitly remove pidfile after virPidFileForceCleanupPath()

In two places where virPidFileForceCleanupPath() is called, we
try to unlink() the pidfile again. This is needless because
virPidFileForceCleanupPath() has done just that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirpidfile: Set correct retval in virPidFileReadPath()
Michal Privoznik [Thu, 20 Feb 2020 10:36:07 +0000 (11:36 +0100)]
virpidfile: Set correct retval in virPidFileReadPath()

The virPidFileReadPath() function is supposed to return 0 on
success or a negative value on failure. But the negative value
has a special meaning - it's negated errno. Therefore, when
converting string to int we shouldn't return -1 which translates
to EPERM. Returning EINVAL looks closer to the truth.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Remove 'cleanup' label
Peter Krempa [Mon, 17 Feb 2020 12:04:26 +0000 (13:04 +0100)]
virStorageFileGetMetadataRecurse: Remove 'cleanup' label

There's nothing to clean up. Make it obvious what is returned.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Extract storage access
Peter Krempa [Mon, 17 Feb 2020 11:51:19 +0000 (12:51 +0100)]
virStorageFileGetMetadataRecurse: Extract storage access

Extract the code that directly deals with storage. This allows further
simplification and clarification of virStorageFileGetMetadataRecurse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Use virHashHasEntry instead of fake pointers
Peter Krempa [Mon, 17 Feb 2020 11:36:59 +0000 (12:36 +0100)]
virStorageFileGetMetadataRecurse: Use virHashHasEntry instead of fake pointers

Replacing virHashLookup by virHashHasEntry allows us to use NULL as the
payload of the hash table rather than putting a fake '1' pointer into
the table.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Expect NULL src->path
Peter Krempa [Mon, 17 Feb 2020 11:27:41 +0000 (12:27 +0100)]
virStorageFileGetMetadataRecurse: Expect NULL src->path

The path can be NULL e.g. for NBD disks. Use NULLSTR to prevent use of
NULL in %s.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Shuffle around assignment of backing chain depth
Peter Krempa [Mon, 17 Feb 2020 09:34:47 +0000 (10:34 +0100)]
virStorageFileGetMetadataRecurse: Shuffle around assignment of backing chain depth

Move the assignment to a place where we know that the backing store is
present rather than having to check in the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agovirStorageFileGetMetadataRecurse: Remove impossible error report
Peter Krempa [Fri, 14 Feb 2020 15:36:26 +0000 (16:36 +0100)]
virStorageFileGetMetadataRecurse: Remove impossible error report

We call virStorageFileSupportsBackingChainTraversal which already checks
that the 'storageFileRead' callback is non-NULL, which in turn means
that virStorageFileRead will not return -2.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoutil: storagefile: Drop image format probing by file suffix
Peter Krempa [Mon, 17 Feb 2020 08:26:46 +0000 (09:26 +0100)]
util: storagefile: Drop image format probing by file suffix

Probing by file suffix was meant to be a last resort if probing by
contents fails or is not supported. For most formats we never specified
any suffix. There's a few formats implementing both magic bytes and
suffix and finally DMG which had only suffix probing. Since suffix
probing is nowhere reliable and only one format depends on in which has a
comment that qemu doesn't do the probing either drop the whole
infrastructure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agocpu_conf: Format vendor_id for host-model CPUs
Jiri Denemark [Wed, 19 Feb 2020 12:48:39 +0000 (13:48 +0100)]
cpu_conf: Format vendor_id for host-model CPUs

In commit v5.9.0-400-gaf8e39921a I removed printing model's fallback and
vendor_id attributes when no model is specified. However, vendor_id
makes sense even without a specific CPU model (for host-model CPUs).

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuxml2xmltest: Add case for host-model vendor_id
Jiri Denemark [Wed, 19 Feb 2020 12:10:27 +0000 (13:10 +0100)]
qemuxml2xmltest: Add case for host-model vendor_id

This patch shows a bug in our code: the

    <model vendor_id="Libvirt QEMU"/>

element present in the source XML is lost when the parsed CPU definition
is formatted back to XML.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainGetStatsIOThread: Don't leak array with 0 iothreads
Peter Krempa [Wed, 19 Feb 2020 07:40:59 +0000 (08:40 +0100)]
qemuDomainGetStatsIOThread: Don't leak array with 0 iothreads

qemuMonitorGetIOThreads returns a NULL-terminated list even when 0
iothreads are present. The caller didn't perform cleanup if there were 0
iothreads leaking the array.

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

Fixes: d1eac92784573559b6fd56836e33b215c89308e3
Reported-by: Jing Yan <jiyan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: QoS parameter 'floor' is supported for 'open' networks too
Pavel Mores [Fri, 14 Feb 2020 16:26:24 +0000 (17:26 +0100)]
docs: QoS parameter 'floor' is supported for 'open' networks too

Relevant code seems to treat forward modes 'route', 'nat', 'open' and 'none'
the same but documentation hasn't reflected that so far.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: call networkPlugBandwidth() for all types of network
Pavel Mores [Fri, 14 Feb 2020 16:26:23 +0000 (17:26 +0100)]
qemu: call networkPlugBandwidth() for all types of network

To fix the actual bug, it was necessary to make networkPlugBandwidth() be
called also for 'bridge'-type networks implemented using macvtap's 'bridge'
mode (previously it was only called for those implemented on top of an
existing bridge).

However, it seems beneficial to call it for other network types as well, at
least because it removes an inconsistency in types of bandwidth configuration
changes permissible in inactive and active domain configs.  It should also be
safe as the function pretty much amounts to NOP if no QoS is requested and the
new behaviour should not be any worse than before if it is.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: check if 'floor' is supported for given interface and network
Pavel Mores [Fri, 14 Feb 2020 16:26:20 +0000 (17:26 +0100)]
qemu: check if 'floor' is supported for given interface and network

Even if an interface of type 'network', setting 'floor' is only supported
if the network's forward type is nat, route, open or none.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: fail on attempt to set 'floor' if interface type is not 'network'
Pavel Mores [Fri, 14 Feb 2020 16:26:21 +0000 (17:26 +0100)]
qemu: fail on attempt to set 'floor' if interface type is not 'network'

QoS 'floor' setting is documented to be only supported for interfaces of
type 'network'.  Fail with an error message on attempt to set 'floor' on
an interface of any other type.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: test if bandwidth has 'floor' factored out to separate function
Pavel Mores [Fri, 14 Feb 2020 16:26:19 +0000 (17:26 +0100)]
qemu: test if bandwidth has 'floor' factored out to separate function

This compound condition will be useful in several places so it
makes sense to give it a name for better readability.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes
Peter Krempa [Wed, 5 Feb 2020 17:09:55 +0000 (18:09 +0100)]
virStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes

If the parsed 'raw' format JSON string has 'offset' or 'size' attributes
parse them as the format slice.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: qemu: Add test data for the new <slice> element
Peter Krempa [Wed, 5 Feb 2020 17:18:39 +0000 (18:18 +0100)]
tests: qemu: Add test data for the new <slice> element

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add support for slices of type 'storage'
Peter Krempa [Mon, 10 Feb 2020 13:37:14 +0000 (14:37 +0100)]
qemu: Add support for slices of type 'storage'

Implement support for the slice of type 'storage' which allows to set
the offset and size which modifies where qemu should look for the start
of the format container inside the image.

Since slicing is done using the 'raw' driver we need to add another
layer into the blockdev tree if there's any non-raw image format driver
used to access the data.

This patch adds the blockdev integration and setup of the image data so
that we can use the slices for any backing image.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: qemublock: Add cases for creating image overlays on top of disks with <slice>
Peter Krempa [Wed, 12 Feb 2020 16:26:18 +0000 (17:26 +0100)]
tests: qemublock: Add cases for creating image overlays on top of disks with <slice>

Add a set of test data to see whether the backing store strings are
formatted reasonably. Note that we don't support direct creation of such
images so those tests are not enabled.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Properly format storage slice into backing store strings
Peter Krempa [Wed, 12 Feb 2020 16:25:12 +0000 (17:25 +0100)]
qemu: block: Properly format storage slice into backing store strings

When creating overlay images e.g. for snapshots or when merging
snapshots we often specify the backing store string to use. Make the
formatter aware of backing chain entries which have a <slice>
configured so that we record it properly. Otherwise such images
would not work without the XML (when detecting the backing chain).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: domain: Store nodenames of slice in status XML
Peter Krempa [Mon, 10 Feb 2020 13:26:08 +0000 (14:26 +0100)]
qemu: domain: Store nodenames of slice in status XML

The storage slice will require a specific node name in cases when the
image format is not raw. Store and format them in the status XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Implement support for <slices> of disk source
Peter Krempa [Mon, 3 Feb 2020 16:36:09 +0000 (17:36 +0100)]
conf: Implement support for <slices> of disk source

Implement parsing and formatting of the 'storage' slice.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: Document the new <slices> sub-element of disk's <source>
Peter Krempa [Wed, 5 Feb 2020 17:00:23 +0000 (18:00 +0100)]
docs: Document the new <slices> sub-element of disk's <source>

We are going to add support for specifying offset and size attributes
which will allow controling where the image and where the guest data
itself starts in the source of the disk. This will be represented by
a <slices> element filled with either a <slice type='storage'> for the
offset of the image format data.

Add the XML documentation and RNG schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: forbid creation of storage sources with <slice>
Peter Krempa [Wed, 12 Feb 2020 16:26:47 +0000 (17:26 +0100)]
qemu: block: forbid creation of storage sources with <slice>

Specifically creating such images via libvirt during blockjobs would
be much more hassle than it's worth. Just forbid them for now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainValidateStorageSource: Reject unsupported slices
Peter Krempa [Wed, 5 Feb 2020 13:51:12 +0000 (14:51 +0100)]
qemuDomainValidateStorageSource: Reject unsupported slices

We support explicit storage slices only when using blockdev. Storage
slices expressed via the backing store string are left to qemu to
open correctly.

Reject storage slices configured via the XML for non-blockdev usage.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuBlockStorageSourceGetFormatRawProps: format 'offset' and 'size' for slice
Peter Krempa [Wed, 5 Feb 2020 17:08:55 +0000 (18:08 +0100)]
qemuBlockStorageSourceGetFormatRawProps: format 'offset' and 'size' for slice

If we have a 'format' type slice for a raw driver we can directly format
the values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: virstoragefile: Add data structure for storing storage source slices
Peter Krempa [Mon, 3 Feb 2020 16:14:52 +0000 (17:14 +0100)]
util: virstoragefile: Add data structure for storing storage source slices

Introduce virStorageSourceSlice which will store the 'offset' and 'size'
of a virStorageSource and declare it as 'sliceStorage' and 'sliceFormat'
attributes of a virStorageSource.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: virstorage: Add test data for json specified raw image with offset/size
Peter Krempa [Thu, 16 Jan 2020 15:02:15 +0000 (16:02 +0100)]
tests: virstorage: Add test data for json specified raw image with offset/size

QEMU allows specifying the offset and size into a raw file to expose a
sub-slice of the image to the guest with the raw driver. Libvirt
currently doesn't support it but we can add test case for future
reference.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: formatdomain: Close <source> on one of disk examples
Peter Krempa [Wed, 5 Feb 2020 16:59:38 +0000 (17:59 +0100)]
docs: formatdomain: Close <source> on one of disk examples

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: domain: Refactor formatting of node names into status XML
Peter Krempa [Mon, 10 Feb 2020 13:23:30 +0000 (14:23 +0100)]
qemu: domain: Refactor formatting of node names into status XML

Use virXMLFormatElement to simplify the logic.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu_domain: Modify access to a NVMe disk iff needed
Michal Privoznik [Fri, 14 Feb 2020 12:59:02 +0000 (13:59 +0100)]
qemu_domain: Modify access to a NVMe disk iff needed

If a domain has a NVMe disk it already has the access configured.
Trying to configure it again on a commit or some other operation
is wrong and condemned to failure.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agonews: Mention the armvtimer timer
Andrea Bolognani [Fri, 7 Feb 2020 13:00:22 +0000 (14:00 +0100)]
news: Mention the armvtimer timer

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: List the armvtimer timer among all others
Andrea Bolognani [Fri, 7 Feb 2020 12:35:00 +0000 (13:35 +0100)]
docs: List the armvtimer timer among all others

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: Add test case for the armvtimer timer
Andrea Bolognani [Fri, 7 Feb 2020 12:11:42 +0000 (13:11 +0100)]
tests: Add test case for the armvtimer timer

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Format the armvtimer timer on the command line
Andrea Bolognani [Fri, 7 Feb 2020 11:45:49 +0000 (12:45 +0100)]
qemu: Format the armvtimer timer on the command line

Its behavior is controlled by a KVM-specific CPU feature.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Validate configuration for the armvtimer timer
Andrea Bolognani [Fri, 7 Feb 2020 09:15:02 +0000 (10:15 +0100)]
qemu: Validate configuration for the armvtimer timer

Its use is limited to certain guest types, and it only supports
a subset of all possible tick policies.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Introduce VIR_DOMAIN_TIMER_NAME_ARMVTIMER
Andrea Bolognani [Thu, 6 Feb 2020 15:54:45 +0000 (16:54 +0100)]
conf: Introduce VIR_DOMAIN_TIMER_NAME_ARMVTIMER

This new timer model will be used to control the behavior of the
virtual timer for KVM ARM/virt guests.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add the QEMU_CAPS_CPU_KVM_NO_ADJVTIME capability
Andrea Bolognani [Fri, 31 Jan 2020 13:28:57 +0000 (14:28 +0100)]
qemu: Add the QEMU_CAPS_CPU_KVM_NO_ADJVTIME capability

We will use this capability to detect whether the QEMU binary
supports the kvm-no-adjvtime CPU feature.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use switch statement in qemuBuildCpuCommandLine()
Andrea Bolognani [Fri, 7 Feb 2020 09:22:08 +0000 (10:22 +0100)]
qemu: Use switch statement in qemuBuildCpuCommandLine()

Make sure we are taking all possible virDomainTimerNameType values
into account. This will make upcoming changes easier.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: drop support for monitor connections on PTYs
Daniel P. Berrangé [Wed, 12 Feb 2020 10:50:49 +0000 (10:50 +0000)]
qemu: drop support for monitor connections on PTYs

Libvirt switched to using a UNIX socket for monitors in
2009 for version 0.7.0. It seems unlikely that there is
a running QEMU process that hasn't been restarted for
11 years while also taking a libvirt upgrade. Therefore
we can drop support for opening a PTY for the QEMU
monitor.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: use closefrom() for mass closing of FDs
Your Name [Wed, 12 Feb 2020 10:53:59 +0000 (10:53 +0000)]
src: use closefrom() for mass closing of FDs

On FreeBSD 12 the default ulimit settings allow for 100,000
open file descriptors. As a result spawning processes in
libvirt is abominably slow. Fortunately FreeBSD has long
since provided a good solution in the form of closefrom(),
which closes all FDs equal to or larger than the specified
parameter.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirt-aa-helper: Add support for smartcard host-certificates
Arnaud Patard [Thu, 5 Dec 2019 17:11:41 +0000 (18:11 +0100)]
virt-aa-helper: Add support for smartcard host-certificates

When emulating smartcard with host certificates, qemu needs to
be able to read the certificates files. Add necessary code to
add the smartcard certificates file path to the apparmor profile.

Passthrough support has been tested with spicevmc and remote-viewer.

v2:
- Fix CodingStyle
- Add support for 'host' case.
- Add a comment to mention that the passthrough case doesn't need
  some configuration
- Use one rule with '{,*}' instead of two rules.

Signed-off-by: Arnaud Patard <apatard@hupstream.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agodocs: Improve documentation for <serial> and <console>
Andrea Bolognani [Tue, 11 Feb 2020 14:37:05 +0000 (15:37 +0100)]
docs: Improve documentation for <serial> and <console>

Users expect to be able to configure the <console> element and see
that configuration reflected into the <serial> element or at least
sticking, however due to our crazy back-compat code that doesn't
always happen.

There's really not much we can do to make this kind of corner cases
work as the user would expect, especially not without introducing
additional complexity in a part of libvirt that already has more
than a fair share of it; we can, however, improve the documentation
so that it will nudge said users in the right direction.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotestutils: remove now unused virTestCaptureProgramOutput
Ján Tomko [Sun, 9 Feb 2020 01:04:13 +0000 (02:04 +0100)]
testutils: remove now unused virTestCaptureProgramOutput

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirshtest: use virCommand instead of custom impl
Ján Tomko [Sun, 9 Feb 2020 01:00:06 +0000 (02:00 +0100)]
virshtest: use virCommand instead of custom impl

Our virCommand helper API already has the ability to capture
program output, there's no need to open-code it.

Apart from simplifying the code, the test is marginally faster
due to recent improvements in virCommandMassClose.

Until now, both stderr and stdout were stored in the same buffer.
This change stores stderr separately and expects it to be empty
for all the tests we currently run.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirshtest: refactor testCompareOutputLit
Ján Tomko [Sun, 9 Feb 2020 01:07:19 +0000 (02:07 +0100)]
virshtest: refactor testCompareOutputLit

Use g_autofree and get rid of the cleanup label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotestutils: remove unnecessary labels
Ján Tomko [Sun, 9 Feb 2020 00:57:06 +0000 (01:57 +0100)]
testutils: remove unnecessary labels

The cleanups made some labels redundant.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotestutils: use g_autoptr
Ján Tomko [Sun, 9 Feb 2020 00:51:37 +0000 (01:51 +0100)]
testutils: use g_autoptr

Use g_autoptr where possible.

virTestCapsBuildNUMATopology is not converted completely,
because while the VIR_FREE call on cell_cpus is technically
wrong, neither VIR_ALLOC_N nor virBitmapNew can return
an allocation error now so it is effectively dead code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotestutils: use g_autofree
Ján Tomko [Sun, 9 Feb 2020 00:47:22 +0000 (01:47 +0100)]
testutils: use g_autofree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotestutils: check return value of g_setenv
Ján Tomko [Sun, 9 Feb 2020 00:26:08 +0000 (01:26 +0100)]
testutils: check return value of g_setenv

The function returns gboolean.
Compare against the FALSE value from GLib.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 2c3353242337bb50fe5abc9454fd5fc98236d4ef
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosyntax-check: remove some exception mechanisms
Ján Tomko [Tue, 11 Feb 2020 00:05:21 +0000 (01:05 +0100)]
syntax-check: remove some exception mechanisms

Do not look for exception patterns in ${srcdir}./x-$@
nor the VC_LIST_EXCEPT_DEFAULT variable.

This also removes the default exception for ChangeLog.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: remove README
Ján Tomko [Tue, 11 Feb 2020 00:11:11 +0000 (01:11 +0100)]
syntax-check: remove README

This exception is no longer useful since README is just a symlink
to README.md, which is a subject to this check already.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: exclude: remove virstring
Ján Tomko [Tue, 11 Feb 2020 00:10:47 +0000 (01:10 +0100)]
syntax-check: exclude: remove virstring

We no longer implement a wrapper over strdup - g_strdup
is preferred.

The use of strncpy was removed in:
commit 7d70a63b947e9a654a4e3fffa0ffa355f5549ec7
    util: Improve virStrncpy() implementation

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: exclude: remove deleted files
Ján Tomko [Tue, 11 Feb 2020 00:10:29 +0000 (01:10 +0100)]
syntax-check: exclude: remove deleted files

Both xen/xend_internal and bootstrap.conf have been deleted from git.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: drop update-NEWS-hash
Ján Tomko [Tue, 11 Feb 2020 00:08:36 +0000 (01:08 +0100)]
syntax-check: drop update-NEWS-hash

NEWS was replaced by docs/news.html, so the pre-requisite for this
rule is not fulfilled.

Also, PREV_VERSION_REGEXP does not seem to be defined anywhere.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: drop CVS keyword expansion check
Ján Tomko [Tue, 11 Feb 2020 00:08:03 +0000 (01:08 +0100)]
syntax-check: drop CVS keyword expansion check

  $ date +%Y
  2020

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: drop vulnerable Makefile checks
Ján Tomko [Tue, 11 Feb 2020 00:07:08 +0000 (01:07 +0100)]
syntax-check: drop vulnerable Makefile checks

As foretold, fixed automake is so common nowadays even Ubuntu 16.04
and Debian 9 have 1.11.6 as the oldest available version.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: fix sc-prohibit-cross-inclusion
Ján Tomko [Tue, 11 Feb 2020 00:07:29 +0000 (01:07 +0100)]
syntax-check: fix sc-prohibit-cross-inclusion

Using '^' in in_vc_files assumes the build is happening
in srcdir, which is no longer possible as of:
commit f96395e78eaccffbf128336382c74b1250f04032

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: do not enforce ChangeLog syntax
Ján Tomko [Tue, 11 Feb 2020 00:07:57 +0000 (01:07 +0100)]
syntax-check: do not enforce ChangeLog syntax

Our last conforming ChangeLog was removed from git in 2009 by:
commit 27b175b9a254d5dc4bbc1d6f198f58b287e516a2
    generate ChangeLog from git logs into distribution tarball

Ten years later, it reappeared in:
commit ce97c33a795dec053f1e85c65ecd924b8c6ec4ba
    maint: Stop generating ChangeLog from git
which does not have a single line complying to this syntax
check rule.

At some point between the two commits VC_LIST_EXCEPT gained
a default exception for ChangeLog and it did not seem to be
overriden anywhere.

Just remove the rule.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: virstorage: Add test cases for "json:" pseudo-URI without 'file' wrapper
Peter Krempa [Mon, 3 Feb 2020 15:40:16 +0000 (16:40 +0100)]
tests: virstorage: Add test cases for "json:" pseudo-URI without 'file' wrapper

Add few cases that prove the second format of "json:" pseudo-URIs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageSourceParseBackingJSON: Prevent arbitrary nesting with format drivers
Peter Krempa [Mon, 3 Feb 2020 15:25:48 +0000 (16:25 +0100)]
virStorageSourceParseBackingJSON: Prevent arbitrary nesting with format drivers

Since we parse attributes for 'raw' which is a format driver and thus
has nested 'file' structure we must prevent that this isn't nested
arbitrarily.

Add a flag for the function which allows parsing of 'format' type
drivers only on the first pass.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageSourceParseBackingJSON: Allow 'json:' pseudo URIs without 'file' wrapper
Peter Krempa [Mon, 3 Feb 2020 13:07:35 +0000 (14:07 +0100)]
virStorageSourceParseBackingJSON: Allow 'json:' pseudo URIs without 'file' wrapper

There are two possibilities:
1) json:{"file":{"driver":...}}
2) json:{"driver":...}

Our code didn't work properly with the second one as it was expecting
the 'file' wrapper. Conditionalize the removal to only the situation
when the top level doesn't have "driver".

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageSourceJSONDriverParser: annotate 'format' drivers
Peter Krempa [Mon, 3 Feb 2020 13:13:50 +0000 (14:13 +0100)]
virStorageSourceJSONDriverParser: annotate 'format' drivers

The parser was originally designed only for protocol parsers. Since
we already have 'raw' format driver in the list we'll need to be able
to parse it too. In later patches this will be used to prevent parsing
nested format drivers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageSourceParseBackingJSON: Move deflattening of json: URIs out of recursion
Peter Krempa [Mon, 3 Feb 2020 12:21:42 +0000 (13:21 +0100)]
virStorageSourceParseBackingJSON: Move deflattening of json: URIs out of recursion

Originally virStorageSourceParseBackingJSON didn't recurse, but when
the 'raw' driver support was added we need to parse it's information
which contains nested 'file' object.

Since the deflattening helper recurses already there's no need to call
it again. Move it one level up to the entry point.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirStorageSourceParseBackingJSON: Pass around original backing file string
Peter Krempa [Mon, 3 Feb 2020 12:33:06 +0000 (13:33 +0100)]
virStorageSourceParseBackingJSON: Pass around original backing file string

There are a few error messages which might want to report the original
backing store string. Pass it around rather than trying to re-generate
it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: hotplug: Fix handling of the 'copy-on-read' layer with blockdev
Peter Krempa [Thu, 6 Feb 2020 11:14:32 +0000 (12:14 +0100)]
qemu: hotplug: Fix handling of the 'copy-on-read' layer with blockdev

My original implementation was completely broken because it attempted to
use object-add/del instead of blockdev-add/del.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemuMonitorBlockdevAdd: Take double pointer argument
Peter Krempa [Thu, 6 Feb 2020 12:13:32 +0000 (13:13 +0100)]
qemuMonitorBlockdevAdd: Take double pointer argument

Modify qemuMonitorBlockdevAdd so that it takes a double pointer for the
@props argument so that it's cleared inside the call. This allows
writing cleaner callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemuMonitorJSONBlockdevDel: Refactor cleanup
Peter Krempa [Thu, 6 Feb 2020 12:03:07 +0000 (13:03 +0100)]
qemuMonitorJSONBlockdevDel: Refactor cleanup

Use automatic variable freeing and get rid of the cleanup section.

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