]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agosnapshots: Support topological visits
Eric Blake [Fri, 8 Mar 2019 04:29:55 +0000 (22:29 -0600)]
snapshots: Support topological visits

Wire up support for VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL in the
domain-agnostic support code.

Clients of snapshot_conf using virDomainSnapshotForEachDescendant()
are using a depth-first visit but with postfix visits of a given
node. Changing this to a prefix visit of the given node instantly
turns this into a topologically-ordered visit.  (A prefix
breadth-first visit would also be topologically sorted, but that
requires a queue while our recursion naturally has a stack).

With that change, we now always have a topological sort for
virDomainSnapshotListAllChildren() regardless of the new public API
flag. Then with one more tweak, we can also get a topological rather
than a faster random hash visit for virDomainListAllSnapshots(), by
doing a descendent walk from our internal metaroot (there, we let the
public API flag control behavior, because a topological sort DOES
require more stack and slightly more time).

Note that virDomainSnapshotForEach() still uses a random hash visit;
we could change that signature to take a tri-state for random, prefix,
or postfix visit if we ever had clients that cared about the
distinctions, but for now, none of the drivers seem to care.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosnapshots: Add flag to guarantee topological sort
Eric Blake [Fri, 8 Mar 2019 03:14:16 +0000 (21:14 -0600)]
snapshots: Add flag to guarantee topological sort

When using virDomainSnapshotCreateXML with the REDEFINE flag on
multiple snapshot metadata XML descriptions, we require that a child
cannot be redefined before its parent.  Since libvirt already tracks a
DAG, it is more convenient if we can ensure that
virDomainListAllSnapshots() and friends have a way to return data in
an order that we can directly reuse, rather than having to
post-process the data ourselves to reconstruct the DAG.

Add VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL as our new guarantee (well, a
guarantee at the time of the API call conclusion; there's always a
possible TOCTTOU race where someone redefining snapshots in between
the API results and the client actually using the list might render
the list out-of-date). Four listing APIs are directly benefitted by
the new flag; additionally, since we document that the older racy
ListNames interfaces should be sized by using the same flags on their
Num counterparts, the Num interfaces must document when they accept
(and ignore) the flag.

We could have supported the new flag just for the ListAll APIs (to
discourage people from using the older racy Num/ListNames APIs), but
it feels weird to special-case this flag value as being applicable to
only a subset of the API while all other List-related flags are
trivially applicable to all 6.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: Enable firmware autoselection
Michal Privoznik [Mon, 25 Feb 2019 13:15:28 +0000 (14:15 +0100)]
qemu: Enable firmware autoselection

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

Now that everything is prepared for qemu driver we can enable
parser feature to allow users define such domains.

At the same time, introduce bunch of tests to test the feature.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemuDomainDefValidate: Don't require SMM if automatic firmware selection enabled
Michal Privoznik [Mon, 25 Feb 2019 10:30:37 +0000 (11:30 +0100)]
qemuDomainDefValidate: Don't require SMM if automatic firmware selection enabled

The firmware selection code will enable the feature if needed.
There's no need to require SMM to be enabled in that case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoqemu_process: Call qemuFirmwareFillDomain
Michal Privoznik [Mon, 25 Feb 2019 13:13:46 +0000 (14:13 +0100)]
qemu_process: Call qemuFirmwareFillDomain

When preparing domain call qemuFirmwareFillDomain() to fill in
desired firmware.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu_firmware: Introduce qemuFirmwareFillDomain()
Michal Privoznik [Fri, 22 Feb 2019 14:25:31 +0000 (15:25 +0100)]
qemu_firmware: Introduce qemuFirmwareFillDomain()

And finally the last missing piece. This is what puts it all
together.

At the beginning, qemuFirmwareFillDomain() loads all possible
firmware description files based on algorithm described earlier.
Then it tries to find description which matches given domain.
The criteria are:

  - firmware is the right type (e.g. it's bios when bios was
    requested in domain XML)
  - firmware is suitable for guest architecture/machine type
  - firmware allows desired guest features to stay enabled (e.g.
    if s3/s4 is enabled for guest then firmware has to support
    it too)

Once the desired description has been found it is then used to
set various bits of virDomainDef so that proper qemu cmd line is
constructed as demanded by the description file. For instance,
secure boot enabled firmware might request SMM -> it will be
enabled if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoqemufirmwaretest: Test qemuFirmwareFetchConfigs()
Michal Privoznik [Thu, 21 Feb 2019 14:24:00 +0000 (15:24 +0100)]
qemufirmwaretest: Test qemuFirmwareFetchConfigs()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu_firmware: Introduce qemuFirmwareFetchConfigs
Michal Privoznik [Thu, 21 Feb 2019 12:16:41 +0000 (13:16 +0100)]
qemu_firmware: Introduce qemuFirmwareFetchConfigs

Implementation for yet another part of firmware description
specification. This one covers selecting which files to parse.

There are three locations from which description files can be
loaded. In order of preference, from most generic to most
specific these are:

  /usr/share/qemu/firmware
  /etc/qemu/firmware
  $XDG_CONFIG_HOME/qemu/firmware

If a file is found in two or more locations then the most specific
one is used. Moreover, if file is empty then it means it is
overriding some generic description and disabling it.

Again, this is described in more details and with nice examples
in firmware.json specification (qemu commit 3a0adfc9bf).

However, there's one slight difference - for the root user the
home directory is not searched. This follows rules laid out by
similar look up processes, e.g. PKI x509 certs are not searched
in /root but they are looked for under /home.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agotest: Introduce qemufirmwaretest
Michal Privoznik [Tue, 19 Feb 2019 16:35:43 +0000 (17:35 +0100)]
test: Introduce qemufirmwaretest

Test firmware description parsing so far.

The test files come from three locations:
1) ovmf-sb-keys.json and ovmf-sb.json come from OVMF
package from RHEL-7 (with slight name change to reflect their
features in filename too),

2) bios.json and aavmf.json come from example JSON documents from
firmware.json from qemu's git (3a0adfc9bf),

3) ovmf.json is then copied from ovmf-sb.json and stripped
of SECURE_BOOT and REQUIRES_SMM flags, OVMF path change,
description update and machine type expanded for both pc and q35
machine types.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
6 years agoqemu: Introduce basic skeleton for parsing firmware description
Michal Privoznik [Tue, 19 Feb 2019 10:07:46 +0000 (11:07 +0100)]
qemu: Introduce basic skeleton for parsing firmware description

The firmware description is a JSON file which follows
specification from qemu.git/docs/interop/firmware.json. The
description file basically says: Firmware file X is {bios|uefi},
supports these targets and machine types, requires these features
to be enabled on qemu cmd line and this is how you put it onto
qemu cmd line.

The firmware.json specification covers more (i.e. how to select
the right firmware) but that will be covered and implemented in
next commits.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Introduce firmware attribute to <os/>
Michal Privoznik [Fri, 22 Feb 2019 14:25:17 +0000 (15:25 +0100)]
conf: Introduce firmware attribute to <os/>

The idea is that using this attribute users enable libvirt to
automagically select firmware image for their domain. For
instance:

  <os firmware='efi'>
    <type arch='x86_64' machine='pc-q35-4.0'>hvm</type>
    <loader secure='no'/>
  </os>

  <os firmware='bios'>
    <type arch='x86_64' machine='pc-q35-4.0'>hvm</type>
  </os>

(The automagic of selecting firmware image will be described in
later commits.)

Accepted values are 'bios' and 'efi' to let libvirt select
corresponding type of firmware.

I know it is a good sign to introduce xml2xml test case when
changing XML config parser but that will have to come later.
Firmware auto selection is not enabled for any driver just yet so
any xml2xml test would fail right away.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Introduce VIR_DOMAIN_LOADER_TYPE_NONE
Michal Privoznik [Mon, 25 Feb 2019 13:46:07 +0000 (14:46 +0100)]
conf: Introduce VIR_DOMAIN_LOADER_TYPE_NONE

This is going to extend virDomainLoader enum. The reason is that
once loader path is NULL its type makes no sense. However, since
value of zero corresponds to VIR_DOMAIN_LOADER_TYPE_ROM the
following XML would be produced:

  <os>
    <loader type='rom'/>
    ...
  </os>

To solve this, introduce VIR_DOMAIN_LOADER_TYPE_NONE which would
correspond to value of zero and then use post parse callback to
set the default loader type to 'rom' if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovirDomainLoaderDefParseXML: Allow loader path to be NULL
Michal Privoznik [Mon, 25 Feb 2019 10:31:17 +0000 (11:31 +0100)]
virDomainLoaderDefParseXML: Allow loader path to be NULL

Except not really. At least for now.

In the future, the firmware will be selected automagically.
Therefore, it makes no sense to require the pathname of a
specific firmware binary in the domain XML. But since it is not
implemented do not really allow the path to be NULL. Only move
code around to prepare it for further expansion.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu_capabilities: Expose qemu <-> libvirt arch translators
Michal Privoznik [Tue, 26 Feb 2019 09:42:38 +0000 (10:42 +0100)]
qemu_capabilities: Expose qemu <-> libvirt arch translators

In some cases, the string representing architecture is different
in qemu and libvirt. That is the reason why we have
virQEMUCapsArchFromString() and virQEMUCapsArchToString(). So
far, we did not need them outside of qemu_capabilities code, but
this will change shortly. Expose them then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu_domain: Separate NVRAM VAR store file name generation
Michal Privoznik [Mon, 25 Feb 2019 15:24:27 +0000 (16:24 +0100)]
qemu_domain: Separate NVRAM VAR store file name generation

Move the code that (possibly) generates filename of NVRAM VAR
store into a single function so that it can be re-used later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotools: vsh: Don't use assert()
Peter Krempa [Tue, 12 Mar 2019 12:16:15 +0000 (13:16 +0100)]
tools: vsh: Don't use assert()

It's meant for testing, not for production builds. Also we have a helper
for reporting OOM errors. Introduced by 23e0bf1c4eb6

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: Drop unnecessary variables
Andrea Bolognani [Tue, 12 Mar 2019 13:07:11 +0000 (14:07 +0100)]
tests: Drop unnecessary variables

In qemuxml2xmltest, both activeVcpus and blockjobs members
of the testInfo struct have been entirely unused ever since
commit d1a7fc8bb303.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agovirsh: Make self-test failures noisy
Eric Blake [Tue, 12 Mar 2019 02:17:33 +0000 (21:17 -0500)]
virsh: Make self-test failures noisy

In local testing, I accidentally introduced a self-test failure,
and spent way too much time debugging it. Make sure the testsuite
log includes some hint as to why command option validation failed.
Lone exception: allocation failure is unlikely during self-test,
and if it happens, we are better off asserting (vsh.c can do this,
even if libvirt.so cannot).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agoresctrl: Fix testing line
Martin Kletzander [Tue, 12 Mar 2019 08:53:48 +0000 (09:53 +0100)]
resctrl: Fix testing line

Forgot to remove this before pushing.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoresctrl: Set MBA defaults properly
Martin Kletzander [Mon, 11 Mar 2019 10:13:32 +0000 (11:13 +0100)]
resctrl: Set MBA defaults properly

Similarly to CAT, when you set some values in an group, remove the group and
recreate it, the previous values will be kept there.  In order to not get values
from a previous setting (a previous VM, for example), we need to set them to
sensible defaults.  The same way we do that for CAT, just set the same values as
the default group has.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoresctrl: Do not calculate free bandwidth for MBA
Martin Kletzander [Mon, 11 Mar 2019 09:23:10 +0000 (10:23 +0100)]
resctrl: Do not calculate free bandwidth for MBA

For CAT we calculate unallocated parts of the cache, however with MBA this does
not make sense as the purpose of that is to limit the bandwidth and the setting
is only proportional relative to bandwidth settings for other groups.

This means it makes sense to set the values to 100% even if there are other
groups with some allocations and that we don't need to find the available
(unallocated) bandwidth in all the groups.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agotests: Run valgrind with absolute path to suppressions file
Shotaro Gotanda [Mon, 11 Mar 2019 13:19:00 +0000 (22:19 +0900)]
tests: Run valgrind with absolute path to suppressions file

So far we are providing the suppressions file with a relative
path to valgrind. This apparently doesn't work on some distros
like Ubuntu and its derivates. Providing the absolute path fixes
the problem.

Signed-off-by: Shotaro Gotanda <g.sho1500@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirfilewrapper: Fix indentation
Martin Kletzander [Wed, 12 Dec 2018 12:39:27 +0000 (13:39 +0100)]
virfilewrapper: Fix indentation

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoqemu: Allow creating ppc64 guests with graphics and no USB mouse
Andrea Bolognani [Wed, 27 Feb 2019 17:41:35 +0000 (18:41 +0100)]
qemu: Allow creating ppc64 guests with graphics and no USB mouse

The existing behavior for ppc64 guests is to always add a USB
keyboard and mouse combo if graphics are present; unfortunately,
this means any attempt to use a USB tablet will cause both pointing
devices to show up in the guest, which in turn will result in poor
user experience.

We can't just stop adding the USB mouse or start adding a USB tablet
instead, because existing applications and users might rely on the
current behavior; however, we can avoid adding the USB mouse if a USB
tablet is already present, thus allowing users and applications to
create guests that contain a single pointing device.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: Add simple guests with graphics to qemuxml2argv
Andrea Bolognani [Wed, 27 Feb 2019 17:08:29 +0000 (18:08 +0100)]
tests: Add simple guests with graphics to qemuxml2argv

These are similar to the existing simple headless guests, but
also include a graphical output and some input devices.

Input files were generated by running

  $ virt-install \
    --name guest --os-variant fedora29 \
    --vcpus 4 --memory 4096 --disk size=5 \
    --graphics vnc \
    --print-xml

followed by minor tweaks.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agodocs: Document configuration quirks for virtio devices
Andrea Bolognani [Wed, 6 Mar 2019 11:10:05 +0000 (12:10 +0100)]
docs: Document configuration quirks for virtio devices

Some devices (namely virtio-scsi, virtio-gpu, virtio-keyboard,
virtio-tablet and virtio-mouse, plus virtio-crypto which is
not supported by libvirt) don't follow the same rules as all
other virtio devices, which is something that ought to be
documented.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: Improve validation for virtio input devices
Andrea Bolognani [Wed, 6 Mar 2019 11:30:25 +0000 (12:30 +0100)]
qemu: Improve validation for virtio input devices

While the parser and schema have to accept all possible models,
virtio-(non-)transitional models are only applicable to
type=passthrough and should be otherwise rejected.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agonews: document virtio-{non-}transitional feature osstest/frozen/xen-4.12-testing
Cole Robinson [Thu, 7 Mar 2019 19:26:56 +0000 (14:26 -0500)]
news: document virtio-{non-}transitional feature

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoutil: skip RDMA detection for non-PCI network devices
Pavel Hrdina [Thu, 7 Mar 2019 16:52:55 +0000 (17:52 +0100)]
util: skip RDMA detection for non-PCI network devices

Only PCI devices have '/sys/class/net/<ifname>/device/resource' so we
need to skip this check for all other network devices.

Without this patch and RDMA enabled libvirt will not detect any network
device that doesn't have the path above which includes 'lo', 'virbr',
'tun', etc.

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

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoconf: fix title and description for virDomainSetMetadata API
Pavel Hrdina [Wed, 27 Feb 2019 14:52:45 +0000 (15:52 +0100)]
conf: fix title and description for virDomainSetMetadata API

If we pass XML to virDomainDefineXML API with these two elements:

    ...
    <title></title>
    <description></description>
    ...

libvirt correctly ignores these two elements and they will not appear
in the parsed XML.

However, if we use virDomainSetMetadata API and with "" as value for
title or description we will end up with the parsed XML that contains
these empty elements.

Let's fix the behavior of this API to behave the same as
virDomainDefineXML.

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agotools/virt-host-validate: Fix IOMMU check on s390x
Thomas Huth [Fri, 1 Mar 2019 11:10:26 +0000 (12:10 +0100)]
tools/virt-host-validate: Fix IOMMU check on s390x

When running virt-host-validate on an s390x host, the tool currently warns
that it is "Unknown if this platform has IOMMU support". We can use the
common check for entries in /sys/kernel/iommu_groups here, too, but it only
makes sense to check it if there are also PCI devices available. It's also
common on s390x that there are no PCI devices assigned to the LPAR, and in
that case there is no need for the PCI-related IOMMU, so without PCI devices
we should simply skip this test.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agosnapshots: Trivial doc improvements
Eric Blake [Fri, 8 Mar 2019 02:52:06 +0000 (20:52 -0600)]
snapshots: Trivial doc improvements

Fix an incorrect @xmlDesc comment, as well as adding more details
about which XML element should be root.

Signed-off-by: Eric Blake <eblake@redhat.com>
6 years agosnapshot: Add virDomainSnapshotObjListParse
Eric Blake [Tue, 5 Mar 2019 03:26:38 +0000 (21:26 -0600)]
snapshot: Add virDomainSnapshotObjListParse

Add a new function to make it possible to parse a list of snapshots
at once.  This is a counterpart to an earlier patch making it
possible to produce all snapshots in a single XML string, and
intentionally parses the same top-level element <snapshots> with
an optional attribute current='name'.

Note that since we know we started with no relations at all, and
since checking parent relationships per-snapshot is not viable as
we don't control which order the snapshots appear in, that we are
fine with doing a final pass to update all parent/child
relationships among the definitions.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Split out virDomainSnapshotRedefineValidate helper
Eric Blake [Thu, 7 Mar 2019 22:12:24 +0000 (16:12 -0600)]
snapshot: Split out virDomainSnapshotRedefineValidate helper

Pull out the portion of virDomainSnapshotRefinePrep() that deals
with definition sanity into a separate helper routine that can
be reused with bulk redefine, leaving behind only the code
specific to loop checking and in-place updates that are only
needed in single-definition handling.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Avoid latent use-after-free when cleaning snapshots
Eric Blake [Tue, 5 Mar 2019 02:38:27 +0000 (20:38 -0600)]
snapshot: Avoid latent use-after-free when cleaning snapshots

Right now, the only callers of qemuDomainSnapshotDiscardAllMetadata()
are right before freeing the virDomainSnapshotObjList, so it did not
matter if the list's metaroot (which points to all the defined root
snapshots) is left inconsistent. But an upcoming patch will want to
clear all snapshots if a bulk redefine fails partway through, in
which case things must be reset.  Make this work by teaching the
existing virDomainSnapshotUpdateRelations() to be safe regardless of
the incoming state of the metaroot (since we don't want to leak that
internal detail into qemu code), then fixing the qemu code to use
it after deleting all snapshots. Additionally, the qemu code must
reset vm->current_snapshot if the current snapshot was removed,
regardless of whether the overall removal succeeded or failed later.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Add virDomainSnapshotObjListFormat
Eric Blake [Sun, 17 Feb 2019 02:13:44 +0000 (20:13 -0600)]
snapshot: Add virDomainSnapshotObjListFormat

Add a new function to output all of the domain's snapshots in one
buffer.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Refactor virDomainSnapshotDefFormat
Eric Blake [Sun, 17 Feb 2019 01:58:58 +0000 (19:58 -0600)]
snapshot: Refactor virDomainSnapshotDefFormat

Split out an internal helper that produces format into a
virBuffer, similar to what domain_conf.c does, and making
the next patch easier to write.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Give virDomainSnapshotDefFormat its own flags
Eric Blake [Fri, 15 Feb 2019 20:43:43 +0000 (14:43 -0600)]
snapshot: Give virDomainSnapshotDefFormat its own flags

virDomainSnapshotDefFormat currently takes two sets of knobs:
an 'unsigned int flags' argument that can currently just be
VIR_DOMAIN_DEF_FORMAT_SECURE, and an 'int internal' argument used as
a bool to determine whether to output an additional element.  It
then reuses the 'flags' knob to call into virDomainDefFormatInternal(),
which takes a different set of flags. In fact, prior to commit 0ecd6851
(1.2.12), the 'flags' argument actually took the public
VIR_DOMAIN_XML_SECURE, which was even more confusing.  Let's borrow
from the style of that earlier commit, by introducing a function
for translating from the public flags (VIR_DOMAIN_SNAPSHOT_XML_SECURE
was just recently introduced) into a new enum specific to snapshot
formatting, and adjust all callers to use snapshot-specific enum
values when formatting, and where the formatter now uses a new
variable 'domainflags' to make it obvious when we are translating
from snapshot flags back to domain flags.  We don't even have to
use the conversion function for drivers that don't accept the
public VIR_DOMAIN_SNAPSHOT_XML_SECURE flag.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Use virDomainSnapshotState for switch statements
Eric Blake [Thu, 7 Mar 2019 21:12:40 +0000 (15:12 -0600)]
qemu: Use virDomainSnapshotState for switch statements

Clean up the previous patch which abused switch on virDomainState
while working with a variable containing virDomainSnapshotState, by
converting the two affected switch statements to now use the right
enum.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Rework virDomainSnapshotState enum
Eric Blake [Tue, 26 Feb 2019 20:14:36 +0000 (14:14 -0600)]
snapshot: Rework virDomainSnapshotState enum

The existing virDomainSnapshotState is a superset of virDomainState,
adding one more state (disk-snapshot) on top of valid domain states.
But as written, the enum cannot be used for gcc validation that all
enum values are covered in a strongly-typed switch condition, because
the enum does not explicitly include the values it is adding to.

Copy the style used in qemu_blockjob.h of creating new enum names
for every inherited value, and update most clients to use the new
enum names anywhere snapshot state is referenced. The exception is
two switch statements in qemu code, which instead gain a fixme
comment about odd type usage (which will be cleaned up in the next
patch). The rest of the patch is fairly mechanical (I actually did
it by temporarily s/state/xstate/ in snapshot_conf.h to let the
compiler find which spots in the code used the field, did the
obvious search and replace in those functions, then undid the rename).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Const-correct snapshot directory name
Eric Blake [Tue, 5 Mar 2019 02:25:33 +0000 (20:25 -0600)]
qemu: Const-correct snapshot directory name

qemuDomainSnapshotWriteMetadata does not modify the directory name,
and making it const-correct aids in writing an upcoming patch.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Refactor snapshot check for _LIVE vs. _REDEFINE
Eric Blake [Tue, 26 Feb 2019 19:44:46 +0000 (13:44 -0600)]
qemu: Refactor snapshot check for _LIVE vs. _REDEFINE

The current qemu code rejects the combination of the two flags
VIR_DOMAIN_SNAPSHOT_CREATE_LIVE in tandem with
VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE, but rather late in the cycle
(after the snapshot was already parsed), and with a rather confusing
message (complaining that live snapshots require external storage,
even if the redefined snapshot already declares external storage).
Hoist the rejection message to occur earlier (before parsing any
XML, which also aids upcoming patches that will implement bulk
redefine), and with a more typical error message about mutually
exclusive flags.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Remove unnecessary checks in virSecurityLabelDefsParseXML
John Ferlan [Thu, 7 Mar 2019 16:06:28 +0000 (11:06 -0500)]
conf: Remove unnecessary checks in virSecurityLabelDefsParseXML

Failure would have occurred for @ctxt before in callers' other
virXPath calls and @def derefs.

Found by Coverity due to commit 66a508d2 using VIR_XPATH_NODE_AUTORESTORE
to access @ctxt before the if condition. The @def was noted by review.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agolxc: Try harder to stop/reboot containers
Maxim Kozin [Wed, 6 Mar 2019 18:39:11 +0000 (21:39 +0300)]
lxc: Try harder to stop/reboot containers

If shutting down a container via setting the runlevel fails, the
control jumps right onto endjob label and doesn't even try
sending the signal. If flags allow it, we should try both
methods.

Signed-off-by: Maxim Kozin <kolomaxes@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoutil: Tweak virStringMatchesNameSuffix()
Andrea Bolognani [Thu, 7 Mar 2019 09:47:21 +0000 (10:47 +0100)]
util: Tweak virStringMatchesNameSuffix()

We can use STRNEQ() instead of STRNEQLEN() since we're only
interested in the trailing part of the string and we've
already verified that the length of file, name and suffix
are those we expect.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Make virStringMatchesNameSuffix() return bool
Andrea Bolognani [Thu, 7 Mar 2019 09:18:58 +0000 (10:18 +0100)]
util: Make virStringMatchesNameSuffix() return bool

It's a predicate, so bool is the appropriate return type.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Make virStringStripSuffix() return bool
Andrea Bolognani [Thu, 7 Mar 2019 09:18:38 +0000 (10:18 +0100)]
util: Make virStringStripSuffix() return bool

While this function is not, strictly speaking, a predicate,
it still mostly behaves like one as evidenced by the vast
majority of its callers, so using bool rather than int as
the return type makes sense.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Make virStringHasCaseSuffix() return bool
Andrea Bolognani [Thu, 7 Mar 2019 09:17:19 +0000 (10:17 +0100)]
util: Make virStringHasCaseSuffix() return bool

It's a predicate, so bool is the appropriate return type.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: Fix query-cpus-fast target architecture detection
Viktor Mihajlovski [Fri, 1 Mar 2019 10:29:51 +0000 (11:29 +0100)]
qemu: Fix query-cpus-fast target architecture detection

Since qemu 2.13 reports the target architecture in a property called
'target' additionally to the property 'arch', that has been used in
qemu 2.12 in the response data of 'query-cpus-fast'.
Libvirts monitor code prefers the 'target' property over 'arch'.

At least for s390(x), target is reported as 's390x' while arch is 's390'.
In a later step a comparison is performed against 's390' which fails for
qemu 2.13 and later.

In consequence the architecture specific data for s390 won't be extracted
from the returned data, leading to incorrect values being reported by
virsh domstats --vcpu.

Changing to check explicitly for 's390' and 's390x'.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
6 years agocpu: Don't access invalid memory in virCPUx86Translate
Michal Privoznik [Thu, 7 Mar 2019 13:17:01 +0000 (14:17 +0100)]
cpu: Don't access invalid memory in virCPUx86Translate

Problem is that if there are no signatures for a CPU, then we
still allocate cpu->signatures (even though with size 0). Later,
we access cpu->signatures[0] if cpu->signatures is not NULL.

 Invalid read of size 4
    at 0x5F439D7: virCPUx86Translate (cpu_x86.c:2930)
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
    ...
  Address 0xf752d40 is 0 bytes after a block of size 0 alloc'd
    at 0x4C30EC6: calloc (vg_replace_malloc.c:711)
    by 0x5DBDE4E: virAllocN (viralloc.c:190)
    by 0x5F3E4FA: x86ModelCopySignatures (cpu_x86.c:990)
    by 0x5F3E60F: x86ModelCopy (cpu_x86.c:1008)
    by 0x5F3E7CB: x86ModelFromCPU (cpu_x86.c:1068)
    by 0x5F4397E: virCPUx86Translate (cpu_x86.c:2922)
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
    ...

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
6 years agoqemu_domain: add a PPC64 memLockLimit helper
Daniel Henrique Barboza [Tue, 5 Mar 2019 12:46:07 +0000 (09:46 -0300)]
qemu_domain: add a PPC64 memLockLimit helper

There is a lot of documentation in the comments about how PPC64 handles
passthrough VFIO devices to calculate the @memLockLimit. And more will
be added with the PPC64 NVLink2 support code.

Let's remove the PPC64 code from qemuDomainGetMemLockLimitBytes()
body and put it into a helper function. This will simplify the
flow of qemuDomainGetMemLockLimitBytes() that handles all the other
platforms and improves readability of the PPC64 specifics.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: domain: Simplify non-VFIO memLockLimit calculation for PPC64
Daniel Henrique Barboza [Tue, 5 Mar 2019 12:46:06 +0000 (09:46 -0300)]
qemu: domain: Simplify non-VFIO memLockLimit calculation for PPC64

@passthroughLimit is being calculated even if @usesVFIO is false. After
that, an if-else conditional is used to check if we're going to sum it
up with @baseLimit.

This patch initializes @passthroughLimit to zero and always returns
@memKB = @baseLimit + @passthroughLimit. The conditional is then used to
calculate @passthroughLimit if @usesVFIO == true. This results in some
cycles being spared for the @usesVFIO == false scenario, but the real
motivation is to make the code simpler to add an alternative formula to
calculate @passthroughLimit for NVLink2.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoutil: enable cgroups v2 cpuset controller for threads
Pavel Hrdina [Wed, 20 Feb 2019 12:50:23 +0000 (13:50 +0100)]
util: enable cgroups v2 cpuset controller for threads

When we create cgroup for qemu threads we need to enable cpuset
controller in order to use it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoutil: implement virCgroupV2(Set|Get)CpusetCpus
Pavel Hrdina [Tue, 19 Feb 2019 14:55:38 +0000 (15:55 +0100)]
util: implement virCgroupV2(Set|Get)CpusetCpus

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoutil: implement virCgroupV2(Set|Get)CpusetMemoryMigrate
Pavel Hrdina [Tue, 19 Feb 2019 14:53:34 +0000 (15:53 +0100)]
util: implement virCgroupV2(Set|Get)CpusetMemoryMigrate

Cgroups v2 don't have memory_migrate interface and the migration is
enabled by default.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoutil: implement virCgroupV2(Set|Get)CpusetMems
Pavel Hrdina [Tue, 19 Feb 2019 14:42:51 +0000 (15:42 +0100)]
util: implement virCgroupV2(Set|Get)CpusetMems

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovirmock: Initialize both symbols in VIR_MOCK_REAL_INIT_ALT
Michal Privoznik [Tue, 26 Feb 2019 09:12:05 +0000 (10:12 +0100)]
virmock: Initialize both symbols in VIR_MOCK_REAL_INIT_ALT

It may happen that both symbols are present. Especially when
chaining mocks. For instance if a test is using virpcimock and
then both stat and __xstat would be present in the address space
as virpcimock implements both. Then, if the test would try to use
say virfilewrapper (which again uses VIR_MOCK_REAL_INIT_ALT() to
init real_stat and real___xstat) it would find stat() from
virpcimock and stop there. The virfilewrapper.c:real___xstat
wouldn't be initialized and thus it may result in a segfault.

The reason for segfault is that sys/stat.h may redefine stat() to
call __xstat().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: remove Google+ link from page footer
Daniel P. Berrangé [Thu, 7 Mar 2019 11:06:37 +0000 (11:06 +0000)]
docs: remove Google+ link from page footer

Google is shutting down Google+, with no replacement, in the very near
future so we are losing the Libvirt community group there.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agorpm: add dep on xfsprogs-devel for reflink support
Daniel P. Berrangé [Tue, 5 Feb 2019 12:12:40 +0000 (12:12 +0000)]
rpm: add dep on xfsprogs-devel for reflink support

Support for XFS reflink clone was added in:

  commit 8ed874b39b3c330bbcdff434e08995dbb4467285
  Author: Julio Faracco <jcfaracco@gmail.com>
  Date:   Fri Jul 6 10:43:01 2018 -0300

    storage: Rename btrfsCloneFile to support other filesystems.

  commit 2e11298f938672c5430193277c98b9474a68b1fb
  Author: Julio Faracco <jcfaracco@gmail.com>
  Date:   Fri Jul 6 10:43:00 2018 -0300

    configure: Adding XFS library/headers check.

But these patches missed that the xfs/xfs.h header is not installed
unless you have xfsprogs-devel present.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotests: use VIR_AUTOUNREF in storagepoolcapstest
Pavel Hrdina [Thu, 7 Mar 2019 11:12:11 +0000 (12:12 +0100)]
tests: use VIR_AUTOUNREF in storagepoolcapstest

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agocaps: drop requiredSourceElements from storage pool capabilities
Pavel Hrdina [Wed, 6 Mar 2019 17:59:39 +0000 (18:59 +0100)]
caps: drop requiredSourceElements from storage pool capabilities

Capabilities should not duplicate data that are obvious from our
documentation and will not change with different QEMU binaries
or the way how we compile libvirt.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agotests: invert the return logic in storagepoolcapstest
Pavel Hrdina [Wed, 6 Mar 2019 18:14:16 +0000 (19:14 +0100)]
tests: invert the return logic in storagepoolcapstest

This way if the first test "full" fails we will run the second test as
well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agotests: use virTestCompareToFile in storagepoolcapstest
Pavel Hrdina [Wed, 6 Mar 2019 18:02:08 +0000 (19:02 +0100)]
tests: use virTestCompareToFile in storagepoolcapstest

This will allow to use VIR_TEST_REGENERATE_OUTPUT.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoUse virStringHasSuffix() where possible
Andrea Bolognani [Thu, 7 Mar 2019 08:40:54 +0000 (09:40 +0100)]
Use virStringHasSuffix() where possible

When dealing with internal paths we don't need to worry about
whether or not suffixes are lowercase since we have full control
over them, which means we can avoid performing case-insensitive
string comparisons.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Add virStringHasSuffix()
Andrea Bolognani [Wed, 6 Mar 2019 16:05:03 +0000 (17:05 +0100)]
util: Add virStringHasSuffix()

This is the case-sensitive counterpart of the existing
virStringHasCaseSuffix() function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Rename virFileMatchesNameSuffix() to virStringMatchesNameSuffix()
Andrea Bolognani [Wed, 6 Mar 2019 14:45:15 +0000 (15:45 +0100)]
util: Rename virFileMatchesNameSuffix() to virStringMatchesNameSuffix()

Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Rename virFileStripSuffix() to virStringStripSuffix()
Andrea Bolognani [Wed, 6 Mar 2019 14:30:04 +0000 (15:30 +0100)]
util: Rename virFileStripSuffix() to virStringStripSuffix()

Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

A few trivial whitespace changes are squashed in.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Rename virFileHasSuffix() to virStringHasCaseSuffix()
Andrea Bolognani [Wed, 6 Mar 2019 14:07:26 +0000 (15:07 +0100)]
util: Rename virFileHasSuffix() to virStringHasCaseSuffix()

Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

In addition to the obvious s/File/String/, also tweak the name
to make it clear that the presence of the suffix is verified
using case-insensitive comparison.

A few trivial whitespace changes are squashed in.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoDrop some useless comparisons and checks
Michal Privoznik [Wed, 27 Feb 2019 14:03:10 +0000 (15:03 +0100)]
Drop some useless comparisons and checks

In these cases the check that is removed has been done a few
lines above already (as can even be seen in the context). Drop
them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoapparmor: Add ptrace and signal rules for named profile
Jim Fehlig [Fri, 1 Mar 2019 22:05:36 +0000 (15:05 -0700)]
apparmor: Add ptrace and signal rules for named profile

Commit a3ab6d42 changed the libvirtd profile to a named profile
but neglected to accommodate the change in the qemu profile
ptrace and signal rules. As a result, libvirtd is unable to
signal confined qemu processes and hence unable to shutdown
or destroy VMs.

Add ptrace and signal rules that reference the libvirtd profile
by name in addition to full binary path.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
6 years agodocs: Add news article
John Ferlan [Thu, 7 Feb 2019 20:33:29 +0000 (15:33 -0500)]
docs: Add news article

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirsh: Expose virConnectGetStoragePoolCapabilities
John Ferlan [Thu, 7 Feb 2019 17:02:53 +0000 (12:02 -0500)]
virsh: Expose virConnectGetStoragePoolCapabilities

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

Add a new storage pool command "pool-capabilities" to output
the storage pool capabilities.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agostorage: Introduce storageConnectGetStoragePoolCapabilities
John Ferlan [Thu, 7 Feb 2019 17:03:08 +0000 (12:03 -0500)]
storage: Introduce storageConnectGetStoragePoolCapabilities

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

Create the storage driver code to generate the output for the
storage pool capabilities XML.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agolibvirt: Introduce virConnectGetStoragePoolCapabilities
John Ferlan [Thu, 7 Feb 2019 17:02:25 +0000 (12:02 -0500)]
libvirt: Introduce virConnectGetStoragePoolCapabilities

Introduce the API to expose the storage pool capabilities along
with all the remote munglement required to hook up the client.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agodocs: Add description for Storage Pool Capabilities
John Ferlan [Thu, 7 Feb 2019 20:26:00 +0000 (15:26 -0500)]
docs: Add description for Storage Pool Capabilities

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agotests: Introduce storage pool capabilites test
John Ferlan [Thu, 7 Feb 2019 17:07:16 +0000 (12:07 -0500)]
tests: Introduce storage pool capabilites test

Add a new test for the storage pool capabilities. There will be
one test mocked with every backend available (full) and one where
only the file system pool is available.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Add storage pool capability formatting
John Ferlan [Thu, 7 Feb 2019 17:29:43 +0000 (12:29 -0500)]
conf: Add storage pool capability formatting

Add support to format the storage pool capabilities using
the virStoragePoolTypeInfoPtr to determine what capabilities
exist for the various pools and the driver capabilities to
determine whether the pool is compiled in and supported.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agodocs: Add schema for storage pool capabilities
John Ferlan [Thu, 7 Feb 2019 17:29:15 +0000 (12:29 -0500)]
docs: Add schema for storage pool capabilities

Define a schema for the storage pool capabilities along with
a test to show the general format.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agostorage: Process storage pool capabilities
John Ferlan [Thu, 10 Jan 2019 12:23:26 +0000 (07:23 -0500)]
storage: Process storage pool capabilities

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

During storage driver backend initialization, let's save
which backends are available in the storage pool capabilities.

In order to format those, we need add a connectGetCapabilities
processor to the storageHypervisorDriver. This allows a storage
connection, such as "storage:///system" to find the API and
format the results, such as:

  virsh -c storage:///system capabilities

  <capabilities>

    <pool>
      <enum name='type'>
        <value>dir</value>
        <value>fs</value>
        <value>netfs</value>
        <value>logical</value>
        <value>iscsi</value>
        <value>iscsi-direct</value>
        <value>scsi</value>
        <value>mpath</value>
        <value>disk</value>
        <value>rbd</value>
        <value>sheepdog</value>
        <value>gluster</value>
        <value>zfs</value>
      </enum>
    </pool>

  </capabilities>

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Introduce storage pool functions into capabilities
John Ferlan [Thu, 10 Jan 2019 12:19:35 +0000 (07:19 -0500)]
conf: Introduce storage pool functions into capabilities

Introduce the bare bones functions to processing capability
data for the storage driver.

Since there will be no need for the <host> output, we need
to filter that data.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agodocs: Fix a few storage.html.in typos
John Ferlan [Thu, 7 Feb 2019 20:23:35 +0000 (15:23 -0500)]
docs: Fix a few storage.html.in typos

Fix the ZFS Valid Volume Format Types label and add the
Valid pool format types for Vstorage pools.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove defaultFormat from VIR_STORAGE_POOL_ZFS
John Ferlan [Thu, 7 Feb 2019 18:48:43 +0000 (13:48 -0500)]
conf: Remove defaultFormat from VIR_STORAGE_POOL_ZFS

The ZFS pool is documented as not using pool format types, so remove
the defaultFormat value.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove volOptions for VIR_STORAGE_POOL_MPATH
John Ferlan [Wed, 6 Feb 2019 22:18:57 +0000 (17:18 -0500)]
conf: Remove volOptions for VIR_STORAGE_POOL_MPATH

The multipath pool is documented as not using the volume type,
so let's just remove it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove volOptions for VIR_STORAGE_POOL_ISCSI[_DIRECT]
John Ferlan [Wed, 6 Feb 2019 22:14:35 +0000 (17:14 -0500)]
conf: Remove volOptions for VIR_STORAGE_POOL_ISCSI[_DIRECT]

The iscsi and iscsi-direct pools are documented as not using
the volume type, so let's just remove it. Besides it would
have produced bad output since formatting uses the Disk types.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove volOptions for VIR_STORAGE_POOL_SCSI
John Ferlan [Wed, 6 Feb 2019 22:05:33 +0000 (17:05 -0500)]
conf: Remove volOptions for VIR_STORAGE_POOL_SCSI

The scsi pool is documented as not using the volume type,
so let's just remove it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove volOptions for VIR_STORAGE_POOL_RBD
John Ferlan [Wed, 6 Feb 2019 22:03:42 +0000 (17:03 -0500)]
conf: Remove volOptions for VIR_STORAGE_POOL_RBD

The rbd pool is documented as not using the volume type,
so let's just remove it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Remove volOptions for VIR_STORAGE_POOL_SHEEPDOG
John Ferlan [Wed, 6 Feb 2019 21:57:28 +0000 (16:57 -0500)]
conf: Remove volOptions for VIR_STORAGE_POOL_SHEEPDOG

The sheepdog pool is documented as not using the volume type,
so let's just remove it.  Besides it would have produced bad
results since the defaultType is FILE but the formatting used
the Disk types.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: domain: Use VIR_XPATH_NODE_AUTORESTORE where appropriate
Peter Krempa [Tue, 5 Mar 2019 15:21:36 +0000 (16:21 +0100)]
conf: domain: Use VIR_XPATH_NODE_AUTORESTORE where appropriate

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Move XPath context node in descendants of virSysinfoParseXML
Peter Krempa [Tue, 5 Mar 2019 14:38:26 +0000 (15:38 +0100)]
conf: Move XPath context node in descendants of virSysinfoParseXML

Rather than moving the XPath root node in the caller and then still
passing it down, make sure that the callees move the node themselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: domain: Use VIR_AUTOCLEAN(virBuffer) where appropriate
Peter Krempa [Tue, 5 Mar 2019 14:10:01 +0000 (15:10 +0100)]
conf: domain: Use VIR_AUTOCLEAN(virBuffer) where appropriate

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Use virXMLFormatElement in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 13:37:11 +0000 (14:37 +0100)]
conf: Use virXMLFormatElement in virDomainDefFormatFeatures

Remove logic necessary to figure out whether to format the 'features'
element by using virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Refactor formating of 'capabilities' features
Peter Krempa [Tue, 5 Mar 2019 12:48:20 +0000 (13:48 +0100)]
conf: Refactor formating of 'capabilities' features

Use virXMLFormatElement for the formatting which allows us to avoid
looking through the array to see if any feature is enabled.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Avoid formatting empty <capabilities> element
Peter Krempa [Tue, 5 Mar 2019 12:56:46 +0000 (13:56 +0100)]
conf: Avoid formatting empty <capabilities> element

If none of the 'capabilities' features are enabled we'd still format the
opening and closing tag for the <capabilities element.

The implementation is suboptimal but will be refactored for a better
approach. This is done prior to the refactor to show that tests are not
impacted.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Avoid extra scope when formatting 'smm' feature
Peter Krempa [Tue, 5 Mar 2019 12:35:21 +0000 (13:35 +0100)]
conf: Avoid extra scope when formatting 'smm' feature

Use an early break and remove the temporary variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Avoid extra set of temp buffers in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 12:33:05 +0000 (13:33 +0100)]
conf: Avoid extra set of temp buffers in virDomainDefFormatFeatures

Use the top level set of temp buffers to do the job.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Simplify lifecycle of temp buffers in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 12:27:45 +0000 (13:27 +0100)]
conf: Simplify lifecycle of temp buffers in virDomainDefFormatFeatures

Use VIR_AUTOCLEAN to avoid leaking the buffer on error path and get rid
of resetting mid loop since virXMLFormatElement does the reset
internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Remove impossible error in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 12:21:39 +0000 (13:21 +0100)]
conf: Remove impossible error in virDomainDefFormatFeatures

'i' is always in range of the enum, thus the name is always populated by
virDomainFeatureTypeToString.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Rename temp buffers in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 12:17:31 +0000 (13:17 +0100)]
conf: Rename temp buffers in virDomainDefFormatFeatures

These buffers are used temporarily for some of the partial formatters
but not globally. Prefix the name with 'tmp' to be explicit.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Refactor control flow in virDomainDefFormatFeatures
Peter Krempa [Tue, 5 Mar 2019 12:07:40 +0000 (13:07 +0100)]
conf: Refactor control flow in virDomainDefFormatFeatures

Use an early return to avoid one level of nesting scopes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Split out domain features formatting from virDomainDefFormatInternal
Peter Krempa [Tue, 5 Mar 2019 12:01:26 +0000 (13:01 +0100)]
conf: Split out domain features formatting from virDomainDefFormatInternal

Pure code motion of code for formatting domain features to a function
called virDomainDefFormatFeatures. Best viewed with the '--patience'
option for git show.

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