]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
4 years agoci: Specify the shebang sequence for build.sh
Erik Skultety [Wed, 10 Feb 2021 06:27:49 +0000 (07:27 +0100)]
ci: Specify the shebang sequence for build.sh

This is necessary for the follow up patch, because the default
entrypoint for a Dockerfile is exec.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoci: Move ppc64le build from Debian sid to Debian 10
Andrea Bolognani [Thu, 11 Feb 2021 11:45:53 +0000 (12:45 +0100)]
ci: Move ppc64le build from Debian sid to Debian 10

Debian sid is currently broken on ppc64le, so move the build to
Debian 10; do the opposite for the aarch64 and mips64el builds to
try and restore the 10/sid balance.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Mark container build jobs as required/optional correctly
Andrea Bolognani [Thu, 11 Feb 2021 11:55:37 +0000 (12:55 +0100)]
ci: Mark container build jobs as required/optional correctly

Whether a container build job is considered required depends on
whether the corresponding cross-build job exists, and in a few
cases the two got out of sync over time.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Shuffle cross-building jobs around
Andrea Bolognani [Thu, 11 Feb 2021 11:57:51 +0000 (12:57 +0100)]
ci: Shuffle cross-building jobs around

Keep them ordered by architecture, the same way the corresponding
container jobs are, to make it easier to jump between the two
sections and compare them.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotools: report messages for 'dominfo' command
Daniel P. Berrangé [Fri, 22 Jan 2021 15:06:52 +0000 (15:06 +0000)]
tools: report messages for 'dominfo' command

$ virsh dominfo demo
Id:             2
Name:           demo
UUID:           eadf8ef0-bf14-4c5f-9708-4a19bacf9e81
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       15.8s
Max memory:     1536000 KiB
Used memory:    1536000 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: unconfined_u:unconfined_r:svirt_t:s0:c443,c956 (permissive)
Messages:       tainted: custom monitor control commands issued
                tainted: use of deprecated configuration settings
                deprecated configuration: machine type 'pc-1.2'

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: implement virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 15:06:35 +0000 (15:06 +0000)]
qemu: implement virDomainGetMessages API

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoremote: add RPC support for the virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 14:50:10 +0000 (14:50 +0000)]
remote: add RPC support for the virDomainGetMessages API

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agosrc: define virDomainGetMessages API
Daniel P. Berrangé [Fri, 22 Jan 2021 14:48:49 +0000 (14:48 +0000)]
src: define virDomainGetMessages API

This API allows fetching a list of informational messages recorded
against the domain. This provides a way to give information about
tainting of the guest due to undesirable actions/configs, as well
as provide details of deprecated features.

The output of this API is explicitly targetted at humans, not
machines, so it is inappropriate to attempt to pattern match on
the strings and take action off them, not least because the messages
are marked for translation.

Should there be a demand for machine targetted information, this
would have to be addressed via a new API, and is not planned at
this point in time.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: record deprecation messages against the domain
Daniel P. Berrangé [Fri, 22 Jan 2021 14:48:03 +0000 (14:48 +0000)]
qemu: record deprecation messages against the domain

These messages are only valid while the domain is running.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: record deprecation messages against the domain
Daniel P. Berrangé [Fri, 22 Jan 2021 14:47:32 +0000 (14:47 +0000)]
conf: record deprecation messages against the domain

These messages will be stored in the live status XML.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agonews: document support for <teaming> in <hostdev>
Laine Stump [Thu, 11 Feb 2021 07:47:29 +0000 (02:47 -0500)]
news: document support for <teaming> in <hostdev>

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: plug <teaming> config from <hostdev> into qemu commandline
Laine Stump [Thu, 11 Feb 2021 07:05:15 +0000 (02:05 -0500)]
qemu: plug <teaming> config from <hostdev> into qemu commandline

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: parse/format <teaming> element in plain <hostdev>
Laine Stump [Thu, 11 Feb 2021 05:58:29 +0000 (00:58 -0500)]
conf: parse/format <teaming> element in plain <hostdev>

The <teaming> element in <interface> allows pairing two interfaces
together as a simple "failover bond" network device in a guest. One of
the devices is the "transient" interface - it will be preferred for
all network traffic when it is present, but may be removed when
necessary, in particular during migration, when traffic will instead
go through the other interface of the pair - the "persistent"
interface. As it happens, in the QEMU implementation of this teaming
pair (called "virtio failover" in QEMU) the transient interface is
always a host network device assigned to the guest using VFIO (aka
"hostdev"); the persistent interface is always an emulated virtio NIC.

When support was initially added for <teaming>, it was written to
require that the transient/hostdev device be defined using <interface
type='hostdev'>; this was done because the virtio failover
implementation in QEMU and the virtio guest driver demands that the
two interfaces in the pair have matching MAC addresses, and the only
way libvirt can guarantee the MAC address of a hostdev network device
is to use <interface type='hostdev'>, whose main purpose is to
configure the device's MAC address before handing the device to
QEMU. (note that <interface type='hostdev'> in turn requires that the
network device be an SRIOV VF (Virtual Function), as that is the only
type of network device whose MAC address we can set in a way that will
survive the device's driver init in the guest).

It has recently come up that some users are unable to use <teaming>
because they are running in a container environment where libvirt
doesn't have the necessary privileges or resources to set the VF's MAC
address (because setting the VF MAC is done via the same device's PF
(Physical Function), and the PF is not exposed to libvirt's container).

At the same time, these users *are* able to set the VF's MAC address
themselves in advance of staring up libvirt in the container. So they
could theoretically use the <teaming> feature if libvirt just skipped
the "setting the MAC address" part.

Fortunately, that is *exactly* the difference between <interface
type='hostdev'> (which must be a "hostdev VF") and <hostdev> (a "plain
hostdev" - it could be *any* PCI device; libvirt doesn't know what type
of PCI device it is, and doesn't care).

But what is still needed is for libvirt to provide a small bit of
information on the QEMU commandline argument for the hostdev, telling
QEMU that this device will be part of a team ("failover pair"), and
the id of the other device in the pair.

To make both of those goals simultaneously possible, this patch adds
support for the <teaming> element to plain <hostdev> - libvirt doesn't
try to set any MAC addresses, and QEMU gets the extra commandline
argument it needs)

(actually, this patch adds only the parsing/formatting of the
<teaming> element in <hostdev>. The next patch will actually wire that
into the qemu driver.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoschema: separate teaming element definition from interface element
Laine Stump [Thu, 11 Feb 2021 03:59:31 +0000 (22:59 -0500)]
schema: separate teaming element definition from interface element

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: separate Parse/Format functions for virDomainNetTeamingInfo
Laine Stump [Thu, 11 Feb 2021 03:44:08 +0000 (22:44 -0500)]
conf: separate Parse/Format functions for virDomainNetTeamingInfo

In preparation for using the same element in two places, split the
parsing/formating for that subelement out of the virDomainNetDef
functions into their own functions.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo
Laine Stump [Thu, 11 Feb 2021 02:09:58 +0000 (21:09 -0500)]
conf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo

To make it easier to split out the parsing/formatting of the <teaming>
element into separate functions (so we can more easily add the
<teaming> element to <hostdev>, change its virDomainNetDef so that it
points to a virDomainNetTeamingInfo rather than containing one.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoconf: make teaming info an official type
Laine Stump [Thu, 11 Feb 2021 01:08:29 +0000 (20:08 -0500)]
conf: make teaming info an official type

This struct was previously defined only within virDomainNetDef where
it was used, but I need to also use it in virDomainHostdevDef, so move
the internal struct out to its own "official" struct and give it the
standard typedef duo and *Free() function.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: match alias when looking for proper <interface> to detach.
Laine Stump [Wed, 10 Feb 2021 19:52:25 +0000 (14:52 -0500)]
qemu: match alias when looking for proper <interface> to detach.

Previously we only checked MAC address and PCI address (or CCW
address). This is not enough information in cases where PCI address
isn't provided and multiple interfaces have the same MAC address (for
example, a virtio + hostdev "teaming" pair - their MAC addresses are
always the same).

Resolves: https://bugzilla.redhat.com/1926190
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agoqemu: Validate TPM TIS device
Jim Fehlig [Tue, 9 Feb 2021 22:47:30 +0000 (15:47 -0700)]
qemu: Validate TPM TIS device

TPM devices with model='tpm-tis' are only valid with x86 and aarch64
virt machines. Add a check to qemuValidateDomainDeviceDefTPM() to
ensure VIR_DOMAIN_TPM_MODEL_TIS is only used with these architectures.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoqemu: Fix swtpm device with aarch64
Jim Fehlig [Tue, 9 Feb 2021 21:57:22 +0000 (14:57 -0700)]
qemu: Fix swtpm device with aarch64

Starting a VM with swtpm device fails with qemu-system-aarch64.
E.g. with TPM device config

     <tpm model='tpm-tis'>
       <backend type='emulator' version='2.0'/>
      </tpm>

QEMU reports the following error

error: internal error: process exited while connecting to monitor:
2021-02-07T05:15:35.378927Z qemu-system-aarch64: -device
tpm-tis,tpmdev=tpm-tpm0,id=tpm0: 'tpm-tis' is not a valid device model name

Indeed the TPM device name is 'tpm-tis-device' [1][2] for aarch64,
versus the shorter 'tpm-tis' for x86. The devices are the same from
a functional POV, i.e. they both emulate a TPM device conforming to
the TIS specification. Account for the unfortunate name difference
when building the TPM device option in qemuBuildTPMDevStr(). Also
include a test case for 'tpm-tis-device'.

[1] https://qemu.readthedocs.io/en/latest/specs/tpm.html
[2] https://github.com/qemu/qemu/commit/c294ac327ca99342b90bd3a83d2cef9b447afaa7

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agovirstringtest: Remove testing of virStringSplitCount
Peter Krempa [Fri, 5 Feb 2021 20:36:53 +0000 (21:36 +0100)]
virstringtest: Remove testing of virStringSplitCount

The function is a wrapper on top of glibs g_strsplit, so is covered by
glibs testing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListJoin
Peter Krempa [Fri, 5 Feb 2021 20:35:21 +0000 (21:35 +0100)]
util: virstring: Remove virStringListJoin

The glib alternative is now used everywhere.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListJoin by g_strjoinv
Peter Krempa [Fri, 5 Feb 2021 20:33:47 +0000 (21:33 +0100)]
Replace virStringListJoin by g_strjoinv

Our implementation was inspired by glib anyways. The difference is only
the order of arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStringSplitCount: Reimplement using g_strsplit and g_strv_length
Peter Krempa [Tue, 6 Oct 2020 10:04:22 +0000 (12:04 +0200)]
virStringSplitCount: Reimplement using g_strsplit and g_strv_length

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringSplit
Peter Krempa [Fri, 5 Feb 2021 17:39:19 +0000 (18:39 +0100)]
util: virstring: Remove virStringSplit

Callers were replaced by g_strsplit.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringSplit with g_strsplit
Peter Krempa [Fri, 5 Feb 2021 17:35:07 +0000 (18:35 +0100)]
Replace virStringSplit with g_strsplit

Our implementation was heavily inspired by the glib version so it's a
drop-in replacement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListLength
Peter Krempa [Fri, 5 Feb 2021 17:29:58 +0000 (18:29 +0100)]
util: virstring: Remove virStringListLength

glib provides g_strv_length.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListLength by g_strv_length
Peter Krempa [Fri, 5 Feb 2021 17:03:26 +0000 (18:03 +0100)]
Replace virStringListLength by g_strv_length

The glib implementation doesn't tolerate NULL but in most cases we check
before anyways. The rest of the callers adds a NULL check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirPolkitCheckAuth: Avoid virStringListLength in loop condition
Peter Krempa [Fri, 5 Feb 2021 16:53:05 +0000 (17:53 +0100)]
virPolkitCheckAuth: Avoid virStringListLength in loop condition

Don't re-calculate the string list length on every iteration. Convert
the loop to NULL-terminated iteration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListLength where actual lenght is not needed
Peter Krempa [Fri, 5 Feb 2021 16:39:52 +0000 (17:39 +0100)]
Replace virStringListLength where actual lenght is not needed

Some callers don't need to know the actual lenght of the list but only
care whether the required element is present or the list is non-empty.
Don't calculate the list length in those cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuvhostusertest: Base iteration on string lists
Peter Krempa [Fri, 5 Feb 2021 16:34:13 +0000 (17:34 +0100)]
qemuvhostusertest: Base iteration on string lists

Remove the need to calculate list lengths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemufirmwaretest: Base iteration on string lists
Peter Krempa [Fri, 5 Feb 2021 16:34:13 +0000 (17:34 +0100)]
qemufirmwaretest: Base iteration on string lists

Remove the need to calculate list lengths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageBackendSheepdogAddVolume: Clean up memory handling
Peter Krempa [Fri, 5 Feb 2021 16:03:14 +0000 (17:03 +0100)]
virStorageBackendSheepdogAddVolume: Clean up memory handling

'cells' can be pushed into the loop removing the need for manual
cleanup, the check whether 'line' is NULL inside of the loop is always
false since the loop checks it right before and 'line' variable is
unnecessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListHasString
Peter Krempa [Wed, 3 Feb 2021 17:39:32 +0000 (18:39 +0100)]
util: virstring: Remove virStringListHasString

All callers were converted to the glib alternative. Providing our own
just to have NULL tolerance doesn't make sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoReplace virStringListHasString by g_strv_contains
Peter Krempa [Wed, 3 Feb 2021 17:39:47 +0000 (18:39 +0100)]
Replace virStringListHasString by g_strv_contains

The glib variant doesn't accept NULL list, but there's just one caller
where it wasn't checked explicitly, thus there's no need for our own
wrapper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuProcessUpdateDevices: Refactor cleanup and memory handling
Peter Krempa [Wed, 3 Feb 2021 17:39:01 +0000 (18:39 +0100)]
qemuProcessUpdateDevices: Refactor cleanup and memory handling

Use automatic memory freeing and remove the 'cleanup' label. Also make
it a bit more obvious that nothing happens if the 'old' list wasn't
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovz: Replace virStringSplitCount(, , , NULL) with virStringSplit
Peter Krempa [Tue, 20 Oct 2020 08:08:43 +0000 (10:08 +0200)]
vz: Replace virStringSplitCount(, , , NULL) with virStringSplit

The caller doesn't care about the number of tokens so use the function
which doesn't return it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStringListGetFirstWithPrefix: Remove unused helper
Peter Krempa [Fri, 5 Feb 2021 13:34:31 +0000 (14:34 +0100)]
virStringListGetFirstWithPrefix: Remove unused helper

This is a uncommon and trivial operation, so having an utility function
for it is pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirCgroupGetValueForBlkDev: Rewrite lookup of returned string
Peter Krempa [Fri, 5 Feb 2021 13:33:12 +0000 (14:33 +0100)]
virCgroupGetValueForBlkDev: Rewrite lookup of returned string

Lookup the string with prefix locally so that we can remove the helper
which isn't universal at all.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virstring: Remove virStringListAdd and virStringListRemove
Peter Krempa [Fri, 5 Feb 2021 13:26:57 +0000 (14:26 +0100)]
util: virstring: Remove virStringListAdd and virStringListRemove

virStringListAdd hides the fact that a O(n) count of elements is
performed every time it's called which makes it inefficient.

Stop supporting such semantics and remove the helpers. Users have a
choice of using GSList or an array with a counter variable rather than
repeated lookups.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemusecuritytest: Store 'notRestored' files in a hash table
Peter Krempa [Fri, 5 Feb 2021 08:53:36 +0000 (09:53 +0100)]
qemusecuritytest: Store 'notRestored' files in a hash table

The validation code looks whether certain paths are in the 'notRestored'
list. For the purpose of lookup it's better to use a hash table rather
than a string list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirfirewalltest: Avoid use of 'virStringListAdd'
Peter Krempa [Thu, 4 Feb 2021 21:43:40 +0000 (22:43 +0100)]
virfirewalltest: Avoid use of 'virStringListAdd'

To allow later removal of 'virStringListAdd' add an arbitrary upper
limit on the number of args we care about and don't store more than
that until necessary later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirfirewalltest: Shuffle the code around to remove a loop
Peter Krempa [Fri, 5 Feb 2021 14:45:52 +0000 (15:45 +0100)]
virfirewalltest: Shuffle the code around to remove a loop

We are already looping over the arguments to construct the list, so we
can add them to fwBuf right away rather than in an extra loop if we move
some of the 'fwBuf' parts earlier and merge the two loops.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoxenParseXLNamespaceData: Pre-calculate the length of array
Peter Krempa [Thu, 4 Feb 2021 21:53:45 +0000 (22:53 +0100)]
xenParseXLNamespaceData: Pre-calculate the length of array

Precalculate the lenght to avoid use of 'virStringListAdd' in a loop.
The code is also simplified by using APIs which don't return errors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: macmap: Convert to use GSList for storing macs instead of string lists
Peter Krempa [Fri, 5 Feb 2021 13:25:16 +0000 (14:25 +0100)]
util: macmap: Convert to use GSList for storing macs instead of string lists

Since adding and removing is the main use case for the macmap module,
convert the code to a more efficient data structure.

The refactor also optimizes the loading from file where previously we'd
do a hash lookup + list lenght calculation for every entry.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: Convert 'priv->dbusVMStateIds' to a GSList
Peter Krempa [Fri, 5 Feb 2021 09:48:51 +0000 (10:48 +0100)]
qemu: Convert 'priv->dbusVMStateIds' to a GSList

The conversion removes the use of virStringListAdd/virStringListRemove
which try to add dynamic properties to a string list which is really
inefficient.

Storing the dbus VMState ids in a GSList is pretty straightforward and
the slightly increased complexity of the code will be paid back by
removing the string list helpers later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlMonitorGetStats: Don't use 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:30:02 +0000 (15:30 +0100)]
virResctrlMonitorGetStats: Don't use 'virStringListAdd'

The iner loop copies the 'resources' array multiple times using
'virStringListAdd' which has O(n^2) complexity.

Pre-calculate the length so we can allocate the array upfront and just
copy the strings in the loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:28:46 +0000 (15:28 +0100)]
virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list

Pre-allocate a buffer for the upper limit and shrink it afterwards to
avoid use of 'virStringListAdd' in a loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agox86ModelParseFeatures: Don't construct list using 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:20:44 +0000 (15:20 +0100)]
x86ModelParseFeatures: Don't construct list using 'virStringListAdd'

Pre-allocate the list to the upper bound and fill it gradually. Since
the data is kept long-term and the list won't be populated much shrink
it to the actual size after parsing.

While using 'virStringListAdd' here wouldn't be as expensive as this
function is used just once, the removal will allow to remove
'virStringListAdd' altogether to discourage the antipattern it promotes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:13:28 +0000 (15:13 +0100)]
virCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list

We already know the upper bound of items we might need so we can
allocate the array upfront and avoid the quadratic complexity of
'virStringListAdd'.

In this instance the returned data is kept only temporarily so a
potential unused space due to filtered-out entries doesn't impose a
long-term burden on memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:09:12 +0000 (15:09 +0100)]
qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list

'virHashGetItems' already returns the number of entries which will be
considered for addition to the list so we can allocate it to the upper
bound upfront rather than growing it in a loop. This avoids the
quadratic complexity of 'virStringListAdd'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirHookCall: Don't use 'virStringListAdd' to construct list in loop
Peter Krempa [Thu, 4 Feb 2021 19:27:05 +0000 (20:27 +0100)]
virHookCall: Don't use 'virStringListAdd' to construct list in loop

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: namespace: Don't use 'virStringListAdd' inside loops
Peter Krempa [Thu, 4 Feb 2021 13:10:42 +0000 (14:10 +0100)]
qemu: namespace: Don't use 'virStringListAdd' inside loops

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Use a GSList which has cheap insertion and iteration and doesn't need
failure handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: Add helpers for auto-freeing GSList filled with strings
Peter Krempa [Thu, 4 Feb 2021 16:58:23 +0000 (17:58 +0100)]
util: Add helpers for auto-freeing GSList filled with strings

glib's 'g_autoslist()' doesn't support lists of 'char *' strings. Add a
type alias 'virGSListString' so that we can register an 'autoptr'
function for it for simple usage of GSList with strings.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling
Peter Krempa [Thu, 4 Feb 2021 14:12:57 +0000 (15:12 +0100)]
qemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling

Some code paths return -1 directly while others jump to 'cleanup' which
cleans the list of mounts. Since qemuDomainGetPreservedMounts now
returns a NULL-terminated list, convert devMountsPath to g_auto(GStrv)
and remove the cleanup altoghether.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix wrong use of iterator variable
Peter Krempa [Thu, 4 Feb 2021 13:27:19 +0000 (14:27 +0100)]
qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable

'i' is used in both outer and inner loop. Since 'devMountsPath' is now a
NULL-terminated list, we can use a GStrv to iterate it;

Additionally rewrite the conditional of adding to the 'unlinkPaths'
array so that it's more clear what's happening.

Fixes: 5c86fbb72d6e90025481db7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists
Peter Krempa [Thu, 4 Feb 2021 14:09:57 +0000 (15:09 +0100)]
qemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists

Refactor the handling of internals so that NULL-terminated lists are
always returned.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: macmap: Remove unused cleanup labels and 'ret' variables
Peter Krempa [Fri, 5 Feb 2021 10:14:43 +0000 (11:14 +0100)]
util: macmap: Remove unused cleanup labels and 'ret' variables

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virmacmap: Use g_autofree for virJSONValue
Peter Krempa [Fri, 5 Feb 2021 10:14:09 +0000 (11:14 +0100)]
util: virmacmap: Use g_autofree for virJSONValue

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Jan Kuparinen [Thu, 11 Feb 2021 07:45:28 +0000 (08:45 +0100)]
Translated using Weblate (Finnish)

Currently translated at 14.0% (1468 of 10451 strings)

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

Translated using Weblate (Finnish)

Currently translated at 13.8% (1447 of 10451 strings)

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

Co-authored-by: Jan Kuparinen <copper_fin@hotmail.com>
Signed-off-by: Jan Kuparinen <copper_fin@hotmail.com>
4 years agoqemu: Do not Use canonical path for system memory
Michal Privoznik [Fri, 8 Jan 2021 15:35:26 +0000 (16:35 +0100)]
qemu: Do not Use canonical path for system memory

In commit 88957116c9d3cb4705380c3702c9d4315fb500bb I've adapted
libvirt to QEMU's deprecation of -mem-path and -mem-prealloc and
switched to memory-backend-* even for system memory. My claim was
that that's what QEMU does under the hood anyway. And indeed it
was: see QEMU commit 900c0ba373aada4c13d47d95330aa72ec4067ba5 and
look at function create_default_memdev().

However, then commit d96c4d5f193e0e45beec80a6277728b32875bddb was
merged into QEMU. While it was fixing a bug, it also changed the
create_default_memdev() function in which it started turning off
use of canonical path (by setting
"x-use-canonical-path-for-ramblock-id" attribute to false). This
wasn't documented until QEMU commit
8db0b20415c129cf5e577a593a4a0372d90b7cc9. The path affects
migration - the same path has to be used on the source and on the
destination. Therefore, if there is old guest started with '-m X'
it has "pc.ram" block which doesn't use canonical path and thus
when migrating to newer QEMU which uses memory-backend-* we have
to turn off the canonical path explicitly. Otherwise,
"/objects/pc.ram" path would be expected by QEMU which doesn't
match the source.

Ideally, we would need to set it only for some machine types
(4.0 and older) because newer machine types already do what we
are doing. However, we treat machine types as opaque strings and
therefore we don't want to parse nor inspect their versions. But
then again, newer machine types already do what we are doing in
this commit, so when old machine types are deprecated and removed
we can remove our hack and forget it ever happened.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1912201
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID
Michal Privoznik [Mon, 11 Jan 2021 17:15:57 +0000 (18:15 +0100)]
qemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID

This capability tracks whether memory-backend-file has
"x-use-canonical-path-for-ramblock-id" attribute. Introduced into
QEMU by commit fa0cb34d2210cc749b9a70db99bb41c56ad20831. As of
QEMU commit 8db0b20415c129cf5e577a593a4a0372d90b7cc9 the property
is considered stable by qemu despite the 'x-' prefix to preserve
compatibility with released qemu versions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agobuild: Remove unused 'conflicts' key from virt_daemon_unit
Jim Fehlig [Tue, 9 Feb 2021 18:21:04 +0000 (11:21 -0700)]
build: Remove unused 'conflicts' key from virt_daemon_unit

The 'conflict' key in a virt_daemon_unit dictionary is not used when
generating systemd service and socket files. The comment associated
with the key claims the default is 'true', and a few build files
needlessly set it to 'true' when defining their virt_daemon_unit.
Remove the 'conflict' key and its use in the affect build files.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoschemas: Add support for maximum CPU mode
Jiri Denemark [Wed, 10 Feb 2021 13:08:49 +0000 (14:08 +0100)]
schemas: Add support for maximum CPU mode

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotests: add cgroup nested tests
Pavel Hrdina [Thu, 5 Nov 2020 17:39:10 +0000 (18:39 +0100)]
tests: add cgroup nested tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce nested cgroup to properly work with systemd
Pavel Hrdina [Tue, 9 Feb 2021 11:33:53 +0000 (12:33 +0100)]
vircgroup: introduce nested cgroup to properly work with systemd

When running on host with systemd we register VMs with machined.
In this case systemd creates the root VM cgroup for us. This has some
implications where one of them is that systemd owns all files inside
the root VM cgroup and we should not touch them.

We already use DBus calls for some of the APIs but for the remaining
ones we will continue accessing the files directly. Systemd doesn't
support threaded cgroups so we need to do this.

The reason why we don't use DBus for most of the APIs is that we already
have a code that works with files and we would have to check if systemd
supports each API.

This change introduces new topology on systemd hosts:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- libvirt
           |
           +- emulator
           +- vcpu0
           +- vcpu0

compared to the previous topology:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- emulator
        +- vcpu0
        +- vcpu0

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce virCgroupV1Exists and virCgroupV2Exists
Pavel Hrdina [Tue, 9 Feb 2021 11:31:13 +0000 (12:31 +0100)]
vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists

This will check if the cgroup actually exists on the system.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroupv2: move task into cgroup before enabling controllers
Pavel Hrdina [Wed, 4 Nov 2020 18:55:44 +0000 (19:55 +0100)]
vircgroupv2: move task into cgroup before enabling controllers

When we create a new child cgroup and the parent cgroup has any process
attached to it enabling controllers for the child cgroup fails with
error. We need to move the process into the child cgroup first before
enabling any controllers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroupv1: refactor virCgroupV1DetectPlacement
Pavel Hrdina [Wed, 4 Nov 2020 18:46:24 +0000 (19:46 +0100)]
vircgroupv1: refactor virCgroupV1DetectPlacement

Remove one level of indentation by splitting the condition.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: use DBus call to systemd for some APIs
Pavel Hrdina [Fri, 5 Feb 2021 15:17:35 +0000 (16:17 +0100)]
vircgroup: use DBus call to systemd for some APIs

When running on host with systemd we register VMs with machined.
In this case systemd creates the root VM cgroup for us. This has some
implications where one of them is that systemd owns all files inside
the root VM cgroup and we should not touch them.

If we change any value in file that systemd knows about it will be
changed to what systemd thinks it should be when executing
`systemctl daemon-reload`.

These are the APIs that we need to call using systemd because they set
limits that are proportional to sibling cgroups.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: introduce virSystemdGetMachineUnitByPID
Pavel Hrdina [Tue, 27 Oct 2020 13:15:03 +0000 (14:15 +0100)]
virsystemd: introduce virSystemdGetMachineUnitByPID

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: introduce virSystemdGetMachineByPID
Pavel Hrdina [Fri, 30 Oct 2020 11:06:56 +0000 (12:06 +0100)]
virsystemd: introduce virSystemdGetMachineByPID

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: export virSystemdHasMachined
Pavel Hrdina [Tue, 27 Oct 2020 13:14:08 +0000 (14:14 +0100)]
virsystemd: export virSystemdHasMachined

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: wire up support for maximum CPU model
Daniel P. Berrangé [Fri, 5 Feb 2021 18:35:10 +0000 (18:35 +0000)]
qemu: wire up support for maximum CPU model

The "max" model can be treated the same way as "host" model in general.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: probe for "-cpu max" support
Daniel P. Berrangé [Fri, 5 Feb 2021 18:21:14 +0000 (18:21 +0000)]
qemu: probe for "-cpu max" support

This is a special CPU model similar to "-cpu host", so won't use our
normal CPU model detection logic.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agocpu: wire up support for maximum CPU mode
Daniel P. Berrangé [Fri, 5 Feb 2021 16:19:33 +0000 (16:19 +0000)]
cpu: wire up support for maximum CPU mode

The logic applied in the ppc64 case isn't quite correct, as the
interpretation of maximum mode depends on whether hardware virt
is used or not. This is information the CPU driver doesn't have.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: add reporting of "maximum" CPU mode in domain caps
Daniel P. Berrangé [Fri, 5 Feb 2021 15:59:35 +0000 (15:59 +0000)]
conf: add reporting of "maximum" CPU mode in domain caps

The data reported is the same as for "host-passthrough"

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: define a new "maximum" CPU mode
Daniel P. Berrangé [Fri, 5 Feb 2021 15:51:09 +0000 (15:51 +0000)]
conf: define a new "maximum" CPU mode

For hardware virtualization this is functionally identical to the
existing host-passthrough mode so the same caveats apply.

For emulated guest this exposes the maximum featureset supported by
the emulator. Note that despite being emulated this is not guaranteed
to be migration safe, especially if different emulator software versions
are used on each host.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agovirStorageSourceClear: Unref @vhostuser
Michal Privoznik [Tue, 9 Feb 2021 19:16:03 +0000 (20:16 +0100)]
virStorageSourceClear: Unref @vhostuser

The @vhostuser member of virStorageSource structure is allocated
during parsing in virDomainDiskSourceVHostUserParse() but never
freed leading to a memleak. Since the member is an object it has
to be unrefed instead of g_free()-d.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agovsh: Drop unused @text arg from readline generators
Michal Privoznik [Thu, 4 Feb 2021 12:46:12 +0000 (13:46 +0100)]
vsh: Drop unused @text arg from readline generators

After previous patches neither vshReadlineCommandGenerator() nor
vshReadlineOptionsGenerator() use prefix that user wants to
complete. The argument is marked as unused in both functions.
Drop it then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Rework vshReadlineCommandGenerator()
Michal Privoznik [Tue, 26 Jan 2021 16:22:00 +0000 (17:22 +0100)]
vsh: Rework vshReadlineCommandGenerator()

Firstly, move variable declarations into the inner most block
they are used. Secondly, use for() loop instead of while so that
we don't have to advance loop counter explicitly on 'continue'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Simplify condition for calling completer callback
Michal Privoznik [Tue, 2 Feb 2021 10:52:27 +0000 (11:52 +0100)]
vsh: Simplify condition for calling completer callback

The way we currently call completer callbacks is that if we've
found --option that user wants to complete value for and it has
callback set then the callback is called.

And just before that, if no --option to have the value completed
is found or is found and is of boolean type then a list of
--option is generated (for given command).

But these two conditions can never be true at the same time
because boolean type of --options do not accept values. Therefore
the calling of completer callback can be promoted onto the same
level as the --option list generation.

This means that merging of two lists can be dropped to and
completer callback can store its retval directly into @list (but
as shown earlier one of the string lists to merge is always
empty).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Deduplicate filtering in vshReadlineCommandGenerator()
Michal Privoznik [Wed, 3 Feb 2021 06:08:19 +0000 (07:08 +0100)]
vsh: Deduplicate filtering in vshReadlineCommandGenerator()

Completer callbacks generate all possible outputs ignoring any partial
input (e.g. prefix of a domain name) and then use vshCompleterFilter() to
filter out those strings which don't fit the partial input (prefix).

In contrast, vshReadlineCommandGenerator() does some internal filtering and
only generates completions that match a given prefix. Rather than treating
these scenarios differently, simply generate all possible options and
filter them all at the end.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Deduplicate filtering in vshReadlineOptionsGenerator()
Michal Privoznik [Tue, 2 Feb 2021 10:38:17 +0000 (11:38 +0100)]
vsh: Deduplicate filtering in vshReadlineOptionsGenerator()

Completer callbacks generate all possible outputs ignoring any partial
input (e.g. prefix of a domain name) and then use vshCompleterFilter() to
filter out those strings which don't fit the partial input (prefix).

In contrast, vshReadlineOptionsGenerator() does some internal filtering and
only generates completions that match a given prefix. Rather than treating
these scenarios differently, simply generate all possible options and
filter them all at the end.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Rewrite opt->type check in vshReadlineParse()
Michal Privoznik [Tue, 2 Feb 2021 10:32:22 +0000 (11:32 +0100)]
vsh: Rewrite opt->type check in vshReadlineParse()

The vshReadlineParse() function is called whenever user hits
<TAB><TAB>. If there is no command (or a partially written one),
then a list of possible commands is printed to the user. But, if
there is a command then its --options are generated. But
obviously, we can not generate --options if there already is an
--option that's expecting a value. For instance, consider:

  virsh # start --domain <TAB><TAB>

In this case we want to call completer for --domain option, but
that's a different story.

Anyway, the way that we currently check whether --options list
should be generated is checking the type of the last --option. If
it isn't DATA, STRING, INT, or ARGV (all these expect a value),
then we can generate --option list. Well, writing the condition
this way is needlessly verbose and also prone to errors (see
d9a320bf97 for example).

We know that boolean type does not require a value. This leaves
us with the only type that was not mentioned yet - VSH_OT_ALIAS.
This is a special type for backwards compatibility and it refers
to another --option which can be just any type.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Use g_auto() for string lists returned in readline command/options generators
Michal Privoznik [Tue, 2 Feb 2021 10:09:01 +0000 (11:09 +0100)]
vsh: Use g_auto() for string lists returned in readline command/options generators

There are two functions that are used to generate completion
lists: vshReadlineCommandGenerator() for command names and
vshReadlineOptionsGenerator() for --options for given command.
Both return a string list, but may also fail while constructing
it. For that case, they call g_strfreev() explicitly, which is
needless since we have g_auto(GStrv).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator()
Michal Privoznik [Tue, 2 Feb 2021 10:05:47 +0000 (11:05 +0100)]
vsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator()

The vshReadlineOptionsGenerator() function returns a string list
of all --options for given command. But the way that individual
items on the list are allocated can be written better.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Accept NULL @list in vshCompleterFilter()
Michal Privoznik [Tue, 2 Feb 2021 09:39:19 +0000 (10:39 +0100)]
vsh: Accept NULL @list in vshCompleterFilter()

The aim of vshCompleterFilter() is to take a string list and a
prefix and remove all strings from the list that don't have the
desired prefix. The function is used to filter out those strings
returned by a completer callback that don't correspond with
user's (partial) input. For instance, domain name completer
virshDomainNameCompleter() returns all domain names and then
vshCompleterFilter() refines the list so that only domains with
correct prefix of their name are offered to user. This was a
design choice - it allows us to have shorter completers as they
do not have to copy the list filtering over and over.

Having said all of that, it may happen that a completer does not
return anything (e.g. there is no domain in requested state,
virsh is not connected and thus completer exited early, etc.). In
that case, the string list is NULL and vshCompleterFilter() can
simply return early.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Use g_auto(GStrv) to free string list returned by completer callback
Michal Privoznik [Tue, 26 Jan 2021 16:12:50 +0000 (17:12 +0100)]
vsh: Use g_auto(GStrv) to free string list returned by completer callback

This saves us explicit call of g_strfreev() in error path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Don't put VSH_OT_ALIAS onto list of completions
Michal Privoznik [Tue, 2 Feb 2021 13:55:28 +0000 (14:55 +0100)]
vsh: Don't put VSH_OT_ALIAS onto list of completions

We've invented VSH_OT_ALIAS type for --option so that we can
rewrite some --options (e.g. fix spelling). For instance
blkdeviotune command uses this feature heavily:
--options-with-dash are preferred over old
--options_with_underscore. Both versions are supported but only
the new ones (not aliased) are documented and reported in --help.

Except for options completer, which happily put also aliased
versions in front of user's eyes.

Note, there is a second (gross) way we use aliases: to rewrite
options from --oldoption to --newoption=value (for instance
--shareable option of attach-disk is an alias of
--mode=shareable). And just like with the previous group - don't
generate them into the list of possible options.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agolib: Substitute some STREQLEN with STRPREFIX
Michal Privoznik [Tue, 26 Jan 2021 16:06:50 +0000 (17:06 +0100)]
lib: Substitute some STREQLEN with STRPREFIX

There are few cases where STREQLEN() is called like this:

  STREQLEN(var, string, strlen(string))

which is the same as STRPREFIX(var, string). Use STRPREFIX()
because it is more obvious what the check is doing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agotests: Only mock $INODE64 symbols on x86_64 macOS
Andrea Bolognani [Thu, 4 Feb 2021 14:48:18 +0000 (15:48 +0100)]
tests: Only mock $INODE64 symbols on x86_64 macOS

The version of macOS running on Apple Silicon doesn't need to
concern itself with backwards compatibility with 32-bit
applications, and so it could jettison all the symbol aliasing
shenanigans involved.

https://gitlab.com/libvirt/libvirt/-/issues/121

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Tested-by: Roman Bolshakov <r.bolshakov@yadro.com>
4 years agoqemu_capabilities: Parse "deprecated" in virQEMUCapsLoadMachines() properly
Michal Privoznik [Tue, 9 Feb 2021 15:36:17 +0000 (16:36 +0100)]
qemu_capabilities: Parse "deprecated" in virQEMUCapsLoadMachines() properly

A <machine/> element can have "deprecated" attribute that
corresponds to 'deprecated' member of _virQEMUCapsMachineType
struct. But the member is of boolean type. Therefore, the string
returned by virXMLPropString() must be freed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_capabilities: Don't leak @str in virQEMUCapsLoadMachines()
Michal Privoznik [Tue, 9 Feb 2021 15:29:39 +0000 (16:29 +0100)]
qemu_capabilities: Don't leak @str in virQEMUCapsLoadMachines()

If parsing "maxCpus" attribute of <machine/> element fails an
error is printed but the corresponding string is not freed. While
it is very unlikely to happen (parsed XML is not user provided
and we are the ones generating it), it is possible. Instead of
freeing the variable in the error path explicitly, let's declare
it as g_autofree. And while I'm at it, let's bring it into the
loop where it's used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agobuild: Fix generation of virtproxyd socket files
Jim Fehlig [Tue, 9 Feb 2021 15:55:41 +0000 (08:55 -0700)]
build: Fix generation of virtproxyd socket files

The various virtproxyd socket files are generated with invalid syntax,
e.g. from virtproxyd.socket

[Unit]
Description=Libvirt proxy local socket
Before=virtproxyd.service
libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket libvirtd-tcp.socket libvirtd-tls.socket

Note the missing 'Conflicts=' in the last line. Fix it by prepending
'Conflicts=' to libvirtd_socket_conflicts when adding virtproxyd
to virt_daemon_units.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemucapabilitiesdata: Update 6.0.0 x86_64 capability test data
Peter Krempa [Sat, 6 Feb 2021 11:06:53 +0000 (12:06 +0100)]
qemucapabilitiesdata: Update 6.0.0 x86_64 capability test data

Update to qemu commit v5.2.0-1684-gd0dddab40e which includes the removal
of pc-1.0/pc-1.1/pc-1.2 machine types, adds the new QMP commands for
internal snapshots as well as includes the background-snapshot
capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: luks-disks-source-qcow2: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 12:05:04 +0000 (13:05 +0100)]
qemuxml2argvdata: luks-disks-source-qcow2: Remove specific machine type

The test doesn't depend on any specific machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: disk-cache: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 12:02:51 +0000 (13:02 +0100)]
qemuxml2argvdata: disk-cache: Remove specific machine type

The test doesn't depend on any specific machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: disk-cdrom-network: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 11:12:08 +0000 (12:12 +0100)]
qemuxml2argvdata: disk-cdrom-network: Remove specific machine type

The test doesn't depend on a specific machine type.

The test uses a machine type which is becoming deprecated so it would
break the _LATEST version of the test once we update the qemu data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agogitlab: Fix build container dependencies for build jobs
Andrea Bolognani [Tue, 9 Feb 2021 09:26:55 +0000 (10:26 +0100)]
gitlab: Fix build container dependencies for build jobs

A couple of these were wrong, resulting in the build job not
waiting for the correct container to be built before starting.

Fixes: 77296c807b18d22286be4b0ba5595d13103910a1
Signed-off-by: Andrea Bolognani <abologna@redhat.com>