]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agovirsh: Add support for setting post-copy migration bandwidth
Jiri Denemark [Thu, 31 Jan 2019 09:45:35 +0000 (10:45 +0100)]
virsh: Add support for setting post-copy migration bandwidth

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Implement VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag
Jiri Denemark [Mon, 4 Feb 2019 16:10:38 +0000 (17:10 +0100)]
qemu: Implement VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag

This flag tells virDomainMigrateSetMaxSpeed and
virDomainMigrateGetMaxSpeed APIs to work on post-copy migration
bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Implement VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY
Jiri Denemark [Thu, 31 Jan 2019 09:25:11 +0000 (10:25 +0100)]
qemu: Implement VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY

This typed parameter for virDomainMigrate3 and virDomainMigrateToURI3
APIs may be used for setting maximum post-copy migration bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoPublic API for post-copy migration bandwidth
Jiri Denemark [Mon, 4 Feb 2019 16:08:36 +0000 (17:08 +0100)]
Public API for post-copy migration bandwidth

This patch adds a new VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY typed
parameter for virDomainMigrate3 and virDomainMigrateToURI3 for setting
maximum post-copy migration bandwidth.

In case the initial VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY value turns out
to be suboptimal a new VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag for
virDomainMigrateSetMaxSpeed and virDomainMigrateGetMaxSpeed may be used
to set/get the maximum post-copy migration bandwidth while migration is
already running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Make migration params usable outside migration
Jiri Denemark [Mon, 4 Feb 2019 16:11:42 +0000 (17:11 +0100)]
qemu: Make migration params usable outside migration

So far migration parameters were changed only at the beginning of
migration mostly via an automatic translation from flags and typed
parameters. We need to export a few more functions to support APIs which
may set migration parameters while migration is already running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Rework qemuDomainMigrateSetMaxSpeed
Jiri Denemark [Mon, 4 Feb 2019 15:52:05 +0000 (16:52 +0100)]
qemu: Rework qemuDomainMigrateSetMaxSpeed

Let's make the code flow easier to follow and get rid of the ugly endjob
label inside if branch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add optional unit to qemuMigrationParamsTPMapItem
Jiri Denemark [Thu, 31 Jan 2019 09:02:17 +0000 (10:02 +0100)]
qemu: Add optional unit to qemuMigrationParamsTPMapItem

Some migration parameters supported by libvirt may use units that differ
from the units used by QEMU for the corresponding parameters. For
example, libvirt defines migration bandwidth in MiB/s while QEMU expects
B/s. Let's add a unit field to qemuMigrationParamsTPMapItem for
automatic conversion when translating between libvirt's migration typed
parameters and QEMU's migration paramteres.

This patch is a preparation for future parameters as the existing
VIR_MIGRATE_PARAM_BANDWIDTH parameter is set using "migrate_set_speed"
QMP command rather than "migrate-set-parameters" for backward
compatibility.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Use C99 initializers for qemuMigrationParamsTPMap
Jiri Denemark [Thu, 31 Jan 2019 08:32:42 +0000 (09:32 +0100)]
qemu: Use C99 initializers for qemuMigrationParamsTPMap

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirinitctl: Provide a stub list of init fifos for non-Linux
Michal Privoznik [Thu, 7 Feb 2019 11:47:26 +0000 (12:47 +0100)]
virinitctl: Provide a stub list of init fifos for non-Linux

The virInitctlFifos list is exported, but lacks definition for
non-Linux and/or non-BSD case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu: Use data in qemuBlockJobDataPtr instead of re-generating job name
Peter Krempa [Thu, 24 Jan 2019 16:50:59 +0000 (17:50 +0100)]
qemu: Use data in qemuBlockJobDataPtr instead of re-generating job name

qemuDomainBlockPivot and qemuDomainBlockJobAbort need the job name for
cancelling or pivoting but were generating it locally instead of
accessing the existing copy in the job data structure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Remove unused 'cfg' qemuDomainBlockPivot
Peter Krempa [Thu, 24 Jan 2019 16:37:48 +0000 (17:37 +0100)]
qemu: Remove unused 'cfg' qemuDomainBlockPivot

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Move shareable disk check for block copy
Peter Krempa [Thu, 24 Jan 2019 16:24:56 +0000 (17:24 +0100)]
qemu: Move shareable disk check for block copy

The writing to an image actually starts when the copy job is initiated,
so checking this at the time of the pivot operation is too late.

Move the check to qemuDomainBlockCopyCommon. Note that modern qemu would
have prevented two writers with qcow2 so the slim possibility of a job
started with libvirtd without this patch missing the check is not really
worth worrying about.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Always save status XML in qemuDomainBlockJobAbort
Peter Krempa [Thu, 24 Jan 2019 16:13:58 +0000 (17:13 +0100)]
qemu: Always save status XML in qemuDomainBlockJobAbort

For copy and active commit jobs we record the state of the mirror so
that we can recover. The status XML was not saved in case of
qemuDomainBlockPivot due to an oversight.

Save the XML always when invoking qemuDomainBlockJobAbort even if
the job is not currently tracking any state. This will change later and
also this is not a particularly hot code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agolxc: Don't reboot host on virDomainReboot
Michal Privoznik [Fri, 25 Jan 2019 11:42:54 +0000 (12:42 +0100)]
lxc: Don't reboot host on virDomainReboot

If the container is really a simple one (init is just bash and
the whole root is passed through) then virDomainReboot and
virDomainShutdown will talk to the actual init within the host.
Therefore, 'virsh shutdown $dom' will result in shutting down the
host. True, at that point the container is shut down too but
looks a bit harsh to me.

The solution is to check if the init inside the container is or
is not the same as the init running on the host.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirinitctl: Expose fifo paths and allow caller to chose one
Michal Privoznik [Fri, 25 Jan 2019 11:37:53 +0000 (12:37 +0100)]
virinitctl: Expose fifo paths and allow caller to chose one

So far the virInitctlSetRunLevel() is fully automatic. It finds
the correct fifo to use to talk to the init and it will set the
desired runlevel. Well, callers (so far there is just one) will
need to inspect the fifo a bit just before the runlevel is set.
Therefore, expose the internal list of fifos and also allow
caller to explicitly use one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolxc: Restore seclabels after the container is killed
Michal Privoznik [Thu, 24 Jan 2019 16:38:10 +0000 (17:38 +0100)]
lxc: Restore seclabels after the container is killed

Due to a bug the seclabels are restored before any PID in the
container is killed. This should be done afterwards in
virLXCProcessCleanup.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovircgroup: Try harder to kill cgroup
Michal Privoznik [Thu, 24 Jan 2019 16:20:58 +0000 (17:20 +0100)]
vircgroup: Try harder to kill cgroup

Prior to rewrite of cgroup code we only had one backend to try.
After the rewrite the virCgroupBackendGetAll() returns both
backends (for v1 and v2). However, not both have to really be
present on the system which results in killRecursive callback
failing which in turn might mean we won't try the other backend.

At the same time, this function reports no error as it should.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolxc: Use correct job type for destroying a domain
Michal Privoznik [Thu, 24 Jan 2019 07:32:27 +0000 (08:32 +0100)]
lxc: Use correct job type for destroying a domain

Not that it would matter because LXC driver doesn't differentiate
the job types so far, but nevertheless the Destroy() should grab
LXC_JOB_DESTROY.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoconf: Remove iothreads restriction in virDomainDefCheckABIStabilityFlags
Jie Wang [Thu, 31 Jan 2019 12:50:31 +0000 (20:50 +0800)]
conf: Remove iothreads restriction in virDomainDefCheckABIStabilityFlags

The number of iothreads is not part of the vm state sent during
migration, nor exposed to the guest ABI, so this restriction is
a mistake in libvirt. Let's remove that bit of code.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jie Wang <wangjie88@huawei.com>
6 years agodosc: schema: fix usb source address device attribute format
Nikolay Shirokovskiy [Mon, 21 Jan 2019 08:40:09 +0000 (11:40 +0300)]
dosc: schema: fix usb source address device attribute format

Device attribute does not have dotted "portAddr" format. Instead it
has single number format described but "usbAddr" which corresponds
to device parsing code in virDomainHostdevSubsysUSBDefParseXML.

Looks like [1] mistakenly changed device format for hostdev devices.
And [2] copy-n-paste this for hostdev network interfaces.

[1] 31710a53 Modify USB port to be defined as a port path
[2] 3b1c191f conf: parse/format type='hostdev' network interfaces

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Refactor virtio-input capabilities checks
Andrea Bolognani [Wed, 5 Sep 2018 16:28:58 +0000 (18:28 +0200)]
qemu: Refactor virtio-input capabilities checks

The checks and error messages are mostly the same across
all virtio-input devices, so we can avoid having multiple
copies of the same code.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Unify qemucaps2xml output files
Andrea Bolognani [Fri, 1 Feb 2019 12:16:18 +0000 (13:16 +0100)]
tests: Unify qemucaps2xml output files

Turns out different versions of QEMU on the same architecture
produce the same output, so we can have a single output file
per architecture instead of duplicating the same data over and
over again.

Spotted-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agoqemu: caps: Don't try to ask for CAP_DAC_OVERRIDE if non-root
Peter Krempa [Mon, 4 Feb 2019 15:24:15 +0000 (16:24 +0100)]
qemu: caps: Don't try to ask for CAP_DAC_OVERRIDE if non-root

It will not work. This breaks qemu capabilities probing as a user.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: Refresh state before starting the VCPUs
Marc Hartmayer [Mon, 4 Feb 2019 12:36:24 +0000 (13:36 +0100)]
qemu: Refresh state before starting the VCPUs

For normal starts (no incoming migration) the refresh of the QEMU
state must be done before the VCPUs getting started since otherwise
there might be a race condition between a possible shutdown of the
guest OS and the QEMU monitor queries.

This fixes "qemu: migration: Refresh device information after
transferring state" (93db7eea1b864).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: Assume migration with a network disk migration is safe
Michal Privoznik [Thu, 24 Jan 2019 08:58:38 +0000 (09:58 +0100)]
qemu: Assume migration with a network disk migration is safe

If a domain has a disk that is type='network' we require specific
cache mode to allow migration with it (either 'directsync' or
'none'). This doesn't make much sense since network disks are
supposed to be safe to migrate by default.

At the same time, we should be checking for the actual source
type, not apparent type set in the domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: domain: Use 'raw' for 'volume' disks without format
Peter Krempa [Thu, 31 Jan 2019 14:37:53 +0000 (15:37 +0100)]
qemu: domain: Use 'raw' for 'volume' disks without format

Storage pools might want to specify format of the image when translating
the volume thus we can't add any default format when parsing the XML.

Add a explicit format when starting the VM and format is not present
neither by user specifying it nor by the storage pool translation
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Assume 'raw' default storage format also for network storage
Peter Krempa [Thu, 4 Oct 2018 12:43:46 +0000 (14:43 +0200)]
qemu: domain: Assume 'raw' default storage format also for network storage

Post parse callback adds the 'raw' type only for local files. Remote
files can also have backing store (even local) so we should do this also
for network backed storage.

Note that virStorageFileGetMetadata always considers files with no type
as raw so we will not accidentally traverse the backing chain and allow
unexpected files being labelled with svirt labels.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemu: Test network disks without format specified explicitly
Peter Krempa [Mon, 8 Oct 2018 13:30:36 +0000 (15:30 +0200)]
tests: qemu: Test network disks without format specified explicitly

Modify some existing tests of network-based disks to omit the storage
format specification.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: command: Don't skip 'readonly' and throttling info for empty drive
Peter Krempa [Fri, 1 Feb 2019 16:54:46 +0000 (17:54 +0100)]
qemu: command: Don't skip 'readonly' and throttling info for empty drive

In commit f80eae8c2ae I was too agresive in removing properties of
-drive for empty drives. It turns out that qemu actually persists the
state of 'readonly' and the throttling information even for the empty
drive.

Removing 'readonly' thus made qemu open any subsequent images added via
the 'change' command as RW which was forbidden by selinux thanks to the
restrictive sVirt label for readonly media.

Fix this by formating the property again and bump the tests and leave a
note detailing why the rest of the properties needs to be skipped.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: Fix typo
Andrea Bolognani [Mon, 4 Feb 2019 08:22:31 +0000 (09:22 +0100)]
news: Fix typo

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agoRequire a semicolon for VIR_ONCE_GLOBAL_INIT calls
Cole Robinson [Sun, 20 Jan 2019 17:23:29 +0000 (12:23 -0500)]
Require a semicolon for VIR_ONCE_GLOBAL_INIT calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>). VIR_ONCE_GLOBAL_INIT is almost
exclusively called without an ending semicolon, but let's
standardize on using one like the other macros.

Add a dummy struct definition at the end of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon for VIR_LOG_INIT calls
Cole Robinson [Sun, 20 Jan 2019 16:32:42 +0000 (11:32 -0500)]
Require a semicolon for VIR_LOG_INIT calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_LOG_INIT calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon for VIR_ENUM_IMPL calls
Cole Robinson [Sun, 20 Jan 2019 16:30:15 +0000 (11:30 -0500)]
Require a semicolon for VIR_ENUM_IMPL calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_IMPL calls.

Move the verify() statement to the end of the macro and drop
the semicolon, so the compiler will require callers to add a
semicolon.

While we are touching these call sites, standardize on putting
the closing parenth on its own line, as discussed here:
https://www.redhat.com/archives/libvir-list/2019-January/msg00750.html

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon to VIR_ENUM_DECL calls
Cole Robinson [Sun, 20 Jan 2019 16:04:56 +0000 (11:04 -0500)]
Require a semicolon to VIR_ENUM_DECL calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_DECL calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoutil: remove test code accidentally committed to virFirewallDZoneExists
Laine Stump [Sun, 3 Feb 2019 04:21:42 +0000 (23:21 -0500)]
util: remove test code accidentally committed to virFirewallDZoneExists

Just before pushing the series containing commit 3bba4825 I had added
a "return true" to the top of virFirewallDZoneExists() to measure the
impact of calling that function once per network during startup. I
found that the effect was minimal, but forgot to remove the "return
true" before pushing. This unfortunately causes a failure to start
networks on systems that have a firewalld version that doesn't support
our libvirt zone file (i.e. pretty much everyone).

This patch removes the unintended line.

Signed-off-by: Laine Stump <laine@laine.org>
6 years agodocs: bhyve: warn about bhyve:commandline risks
Roman Bogorodskiy [Thu, 31 Jan 2019 12:38:01 +0000 (16:38 +0400)]
docs: bhyve: warn about bhyve:commandline risks

Document that using bhyve:commandline is not fully
supported and may cause issues.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agobhyve: emit warning when using bhyve:commandline
Roman Bogorodskiy [Thu, 31 Jan 2019 12:37:01 +0000 (16:37 +0400)]
bhyve: emit warning when using bhyve:commandline

When using custom command line arguments, warn that
this configuration is not fully supported.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agobhyve: bhyveDomainDefNamespaceFormatXML cleanup
Roman Bogorodskiy [Thu, 31 Jan 2019 12:05:17 +0000 (16:05 +0400)]
bhyve: bhyveDomainDefNamespaceFormatXML cleanup

 - Remove ATTRIBUTE_UNUSED for the "buf" argument, it's
   not unused
 - Indent fix

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: update news.xml for firewalld zone changes
Laine Stump [Wed, 30 Jan 2019 18:18:09 +0000 (13:18 -0500)]
docs: update news.xml for firewalld zone changes

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: allow configuring firewalld zone for virtual network bridge device
Laine Stump [Wed, 9 Jan 2019 21:51:31 +0000 (16:51 -0500)]
network: allow configuring firewalld zone for virtual network bridge device

Since we're setting the zone anyway, it will be useful to allow
setting a different (custom) zone for each network. This will be done
by adding a "zone" attribute to the "bridge" element, e.g.:

   ...
   <bridge name='virbr0' zone='myzone'/>
   ...

If a zone is specified in the config and it can't be honored, this
will be an error.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: set firewalld zone of bridges to "libvirt" zone when appropriate
Laine Stump [Tue, 16 Oct 2018 00:31:02 +0000 (20:31 -0400)]
network: set firewalld zone of bridges to "libvirt" zone when appropriate

This patch restores broken guest network connectivity after a host
firewalld is switched to using an nftables backend. It does this by
adding libvirt networks' bridge interfaces to the new "libvirt" zone
in firewalld.

After this patch, the bridge interface of any network created by
libvirt (when firewalld is active) will be added to the firewalld
zone called "libvirt" if it exists (regardless of the firewalld
backend setting). This behavior does *not* depend on whether or not
libvirt has installed the libvirt zone file (set with
"--with[out]-firewalld-zone" during the configure phase of the package
build).

If the libvirt zone doesn't exist (either because the package was
configured to not install it, or possibly it was installed, but
firewalld doesn't support rule priorities, resulting in a parse
error), the bridge will remain in firewalld's default zone, which
could be innocuous (in the case that the firewalld backend is
iptables, guest networking will still function properly with the
bridge in the default zone), or it could be disastrous (if the
firewalld backend is nftables, we can be assured that guest networking
will fail). In order to be unobtrusive in the former case, and
informative in the latter, when the libvirt zone doesn't exist we
then check the firewalld version to see if it's new enough to support
the nftables backend, and then if the backend is actually set to
nftables, before logging an error (and failing the net-start
operation, since the network couldn't possibly work anyway).

When the libvirt zone is used, network behavior is *slightly*
different from behavior of previous libvirt. In the past, libvirt
network behavior would be affected by the configuration of firewalld's
default zone (usually "public"), but now it is affected only by the
"libvirt" zone), and thus almost surely warrants a release note for
any distro upgrading to libvirt 5.1 or above. Although it's
unfortunate that we have to deal with a mandatory behavior change, the
architecture of multiple hooks makes it impossible to *not* change
behavior in some way, and the new behavior is arguably better (since
it will now be possible to manage access to the host from virtual
machines vs from public interfaces separately).

Creates-and-Resolves: https://bugzilla.redhat.com/1650320
Resolves: https://bugzilla.redhat.com/1638342
Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconfigure: selectively install a firewalld 'libvirt' zone
Laine Stump [Sat, 26 Jan 2019 04:52:37 +0000 (23:52 -0500)]
configure: selectively install a firewalld 'libvirt' zone

In the past (when both libvirt and firewalld used iptables), if either
libvirt's rules *OR* firewalld's rules accepted a packet, it would
be accepted. This was because libvirt and firewalld rules were
processed during the same kernel hook, and a single ACCEPT result
would terminate the rule traversal and cause the packet to be
accepted.

But now firewalld can use nftables for its backend, while libvirt's
firewall rules are still using iptables; iptables rules are still
processed, but at a different time during packet processing
(i.e. during a different hook) than the firewalld nftables rules. The
result is that a packet must be accepted by *BOTH* the libvirt
iptables rules *AND* the firewalld nftable rules in order to be
accepted.

This causes pain because

1) libvirt always adds rules to permit DNS and DHCP (and sometimes
TFTP) from guests to the host network's bridge interface. But
libvirt's bridges are in firewalld's "default" zone (which is usually
the zone called "public"). The public zone allows ssh, but doesn't
allow DNS, DHCP, or TFTP. So even though libvirt's rules allow the
DHCP and DNS traffic, the firewalld rules (now processed during a
different hook) dont, thus guests connected to libvirt's bridges can't
acquire an IP address from DHCP, nor can they make DNS queries to the
DNS server libvirt has setup on the host. (This could be solved by
modifying the default firewalld zone to allow DNS and DHCP, but that
would open *all* interfaces in the default zone to those services,
which is most likely not what the host's admin wants.)

2) Even though libvirt adds iptables rules to allow forwarded traffic
to pass the iptables hook, firewalld's higher level "rich rules" don't
yet have the ability to configure the acceptance of forwarded traffic
(traffic that is going somewhere beyond the host), so any traffic that
needs to be forwarded from guests to the network beyond the host is
rejected during the nftables hook by the default zone's "default
reject" policy (which rejects all traffic in the zone not specifically
allowed by the rules in the zone, whether that traffic is destined to
be forwarded or locally received by the host).

libvirt can't send "direct" nftables rules (firewalld only supports
direct/passthrough rules for iptables), so we can't solve this problem
by just sending explicit nftables rules instead of explicit iptables
rules (which, if it could be done, would place libvirt's rules in the
same hook as firewalld's native rules, and thus eliminate the need for
packets to be accepted by both libvirt's and firewalld's own rules).

However, we can take advantage of a quirk in firewalld zones that have
a default policy of "accept" (meaning any packet that doesn't match a
specific rule in the zone will be *accepted*) - this default accept will
also accept forwarded traffic (not just traffic destined for the host).

Of course we don't want to modify firewalld's default zone in that
way, because that would affect the filtering of traffic coming into
the host from other interfaces using that zone. Instead, we will
create a new zone called "libvirt". The libvirt zone will have a
default policy of accept so that forwarded traffic can pass and list
specific services that will be allowed into the host from guests (DNS,
DHCP, SSH, and TFTP).

But the same default accept policy that fixes forwarded traffic also
causes *all* traffic from guest to host to be accepted. To close this
new hole, the libvirt zone can take advantage of a new feature in
firewalld (currently slated for firewalld-0.7.0) - priorities for rich
rules - to add a low priority rule that rejects all local traffic (but
leaves alone all forwarded traffic).

So, our new zone will start with a list of services that are allowed
(dhcp, dns, tftp, and ssh to start, but configurable via any firewalld
management application, or direct editing of the zone file in
/etc/firewalld/zones/libvirt.xml), followed by a low priority
<reject/> rule (to reject all other traffic from guest to host), and
finally with a default policy of accept (to allow forwarded traffic).

This patch only creates the zonefile for the new zone, and implements
a configure.ac option to selectively enable/disable installation of
the new zone. A separate patch contains the necessary code to actually
place bridge interfaces in the libvirt zone.

Why do we need a configure option to disable installation of the new
libvirt zone? It uses a new firewalld attribute that sets the priority
of a rich rule; this feature first appears in firewalld-0.7.0 (unless
it has been backported to am earlier firewalld by a downstream
maintainer). If the file were installed on a system with firewalld
that didn't support rule priorities, firewalld would log an error
every time it restarted, causing confusion and lots of extra bug
reports.

So we add two new configure.ac switches to avoid polluting the system
logs with this error on systems that don't support rule priorities -
"--with-firewalld-zone" and "--without-firewalld-zone". A package
builder can use these to include/exclude the libvirt zone file in the
installation. If firewalld is enabled (--with-firewalld), the default
is --with-firewalld-zone, but it can be disabled during configure
(using --without-firewalld-zone). Targets that are using a firewalld
version too old to support the rule priority setting in the libvirt
zone file can simply add --without-firewalld-zone to their configure
commandline.

These switches only affect whether or not the libvirt zone file is
*installed* in /usr/lib/firewalld/zones, but have no effect on whether
or not libvirt looks for a zone called libvirt and tries to use it.

NB: firewalld zones can only be added to the permanent config of
firewalld, and won't be loaded/enabled until firewalld is restarted,
so at package install/upgrade time we have to restart firewalld. For
rpm-based distros, this is done in the libvirt.spec file by calling
the %firewalld_restart rpm macro, which is a part of the
firewalld-filesystem package. (For distros that don't use rpm
packages, the command "firewalld-cmd --reload" will have the same
effect).

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: new virFirewallD APIs + docs
Laine Stump [Wed, 9 Jan 2019 19:40:51 +0000 (14:40 -0500)]
util: new virFirewallD APIs + docs

virFirewallDGetBackend() reports whether firewalld is currently using
an iptables or an nftables backend.

virFirewallDGetVersion() learns the version of the firewalld running
on this system and returns it as 1000000*major + 1000*minor + micro.

virFirewallDGetZones() gets a list of all currently active firewalld
zones.

virFirewallDInterfaceSetZone() sets the firewalld zone of the given
interface.

virFirewallDZoneExists() can be used to learn whether or not a
particular zone is present and active in firewalld.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: move all firewalld-specific stuff into its own files
Laine Stump [Wed, 9 Jan 2019 19:11:32 +0000 (14:11 -0500)]
util: move all firewalld-specific stuff into its own files

In preparation for adding several other firewalld-specific functions,
separate the code that's unique to firewalld from the more-generic
"firewall" file.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconfigure: change HAVE_FIREWALLD to WITH_FIREWALLD
Laine Stump [Sat, 26 Jan 2019 04:46:18 +0000 (23:46 -0500)]
configure: change HAVE_FIREWALLD to WITH_FIREWALLD

Support for firewalld is a feature that can be selectively enabled or
disabled (using --with-firewalld/--without-firewalld), not merely
something that must be accounted for in the code if it is present with
no exceptions. It is more consistent with other usage in libvirt to
use WITH_FIREWALLD rather than HAVE_FIREWALLD.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: Fix build issue with virStorageFileGetNPIVKey
John Ferlan [Fri, 1 Feb 2019 16:32:56 +0000 (11:32 -0500)]
util: Fix build issue with virStorageFileGetNPIVKey

Signed-off-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: news: Update the release notes with the SEV permission fix
Erik Skultety [Fri, 1 Feb 2019 12:05:56 +0000 (13:05 +0100)]
docs: news: Update the release notes with the SEV permission fix

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostorage: Fetch a unique key for vHBA/NPIV LUNs
John Ferlan [Fri, 18 Jan 2019 13:33:10 +0000 (08:33 -0500)]
storage: Fetch a unique key for vHBA/NPIV LUNs

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

Commit be1bb6c95 changed the way volumes were stored from a forward
linked list to a hash table. In doing so, it required that each vol
object would have 3 unique values as keys into tables - key, name,
and path. Due to how vHBA/NPIV LUNs are created/used this resulted
in a failure to utilize all the LUN's found during processing.

During virStorageBackendSCSINewLun processing fetch the key (or
serial value) for NPIV LUN's using virStorageFileGetNPIVKey which
will formulate a more unique key based on the serial value and
the port for the LUN.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Introduce virStorageFileGetNPIVKey
John Ferlan [Wed, 16 Jan 2019 00:07:07 +0000 (19:07 -0500)]
util: Introduce virStorageFileGetNPIVKey

The vHBA/NPIV LUNs created via the udev processing of the
VPORT_CREATE command end up using the same serial value
as seen/generated by the /lib/udev/scsi_id as returned
during virStorageFileGetSCSIKey. Therefore, in order to
generate a unique enough key to be used when adding the
LUN as a volume during virStoragePoolObjAddVol a more
unique key needs to be generated for an NPIV volume.

The problem is illustrated by the following example, where
scsi_host5 is a vHBA used with the following LUNs:

$ lsscsi -tg
...
[5:0:4:0]    disk    fc:0x5006016844602198,0x101f00  /dev/sdh   /dev/sg23
[5:0:5:0]    disk    fc:0x5006016044602198,0x102000  /dev/sdi   /dev/sg24
...

Calling virStorageFileGetSCSIKey would return:

/lib/udev/scsi_id --device /dev/sdh --whitelisted --replace-whitespace /dev/sdh
350060160c460219850060160c4602198
/lib/udev/scsi_id --device /dev/sdh --whitelisted --replace-whitespace /dev/sdi
350060160c460219850060160c4602198

Note that althrough /dev/sdh and /dev/sdi are separate LUNs, they
end up with the same serial number used for the vol->key value.
When virStoragePoolFCRefreshThread calls virStoragePoolObjAddVol
the second LUN fails to be added with the following message
getting logged:

    virHashAddOrUpdateEntry:341 : internal error: Duplicate key

To resolve this, virStorageFileGetNPIVKey will use a similar call
sequence as virStorageFileGetSCSIKey, except that it will add the
"--export" option to the call. This results in more detailed output
which needs to be parsed in order to formulate a unique enough key
to be used. In order to be unique enough, the returned value will
concatenate the target port as returned in the "ID_TARGET_PORT"
field from the command to the "ID_SERIAL" value.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agostorage: Rework virStorageBackendSCSISerial
John Ferlan [Tue, 15 Jan 2019 20:59:21 +0000 (15:59 -0500)]
storage: Rework virStorageBackendSCSISerial

Alter the code to use the virStorageFileGetSCSIKey helper
to fetch the unique key for the SCSI disk. Alter the logic
to follow the former code which would return a duplicate
of @dev when either the virCommandRun succeeded, but returned
an empty string or when WITH_UDEV was not true.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Modify virStorageFileGetSCSIKey return
John Ferlan [Tue, 15 Jan 2019 21:11:48 +0000 (16:11 -0500)]
util: Modify virStorageFileGetSCSIKey return

Alter the "real" code to return -2 on virCommandRun failure.
Alter the comments and function header to describe the function
and its returns.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Rework setting process affinity
Michal Privoznik [Wed, 30 Jan 2019 08:46:23 +0000 (09:46 +0100)]
qemu: Rework setting process affinity

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

The way we currently start qemu from CPU affinity POV is as
follows:

  1) the child process is set affinity to all online CPUs (unless
  some vcpu pinning was given in the domain XML)

  2) Once qemu is running, cpuset cgroup is configured taking
  memory pinning into account

Problem is that we let qemu allocate its memory just anywhere in
1) and then rely in 2) to be able to move the memory to
configured NUMA nodes. This might not be always possible (e.g.
qemu might lock some parts of its memory) and is very suboptimal
(copying large memory between NUMA nodes takes significant amount
of time).

The solution is to set affinity to one of (in priority order):
  - The CPUs associated with NUMA memory affinity mask
  - The CPUs associated with emulator pinning
  - All online host CPUs

Later (once QEMU has allocated its memory) we then change this
again to (again in priority order):
  - The CPUs associated with emulator pinning
  - The CPUs returned by numad
  - The CPUs associated with vCPU pinning
  - All online host CPUs

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: caps: Use CAP_DAC_OVERRIDE for probing to avoid permission issues
Erik Skultety [Thu, 24 Jan 2019 09:33:01 +0000 (10:33 +0100)]
qemu: caps: Use CAP_DAC_OVERRIDE for probing to avoid permission issues

This is mainly about /dev/sev and its default permissions 0600. Of
course, rule of 'tinfoil' would be that we can't trust anything, but the
probing code in QEMU is considered safe from security's perspective + we
can't create an udev rule for this at the moment, because ioctls and
file system permissions aren't cross-checked in kernel and therefore a
user with read permissions could issue a 'privileged' operation on SEV
which is currently only limited to root.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosecurity: dac: Relabel /dev/sev in the namespace
Erik Skultety [Thu, 31 Jan 2019 14:16:50 +0000 (15:16 +0100)]
security: dac: Relabel /dev/sev in the namespace

The default permissions (0600 root:root) are of no use to the qemu
process so we need to change the owner to qemu iff running with
namespaces.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: domain: Add /dev/sev into the domain mount namespace selectively
Erik Skultety [Tue, 22 Jan 2019 12:46:16 +0000 (13:46 +0100)]
qemu: domain: Add /dev/sev into the domain mount namespace selectively

Instead of exposing /dev/sev to every domain, do it selectively.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: cgroup: Expose /dev/sev/ only to domains that require SEV
Erik Skultety [Mon, 21 Jan 2019 13:50:11 +0000 (14:50 +0100)]
qemu: cgroup: Expose /dev/sev/ only to domains that require SEV

SEV has a limit on number of concurrent guests. From security POV we
should only expose resources (any resources for that matter) to domains
that truly need them.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: conf: Remove /dev/sev from the default cgroup device acl list
Erik Skultety [Mon, 21 Jan 2019 13:48:02 +0000 (14:48 +0100)]
qemu: conf: Remove /dev/sev from the default cgroup device acl list

We should not give domains access to something they don't necessarily
need by default. Remove it from the qemu driver docs too.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotests: Update qemucaps2xml for QEMU 4.0.0 on x86_64
Andrea Bolognani [Thu, 31 Jan 2019 13:02:47 +0000 (14:02 +0100)]
tests: Update qemucaps2xml for QEMU 4.0.0 on x86_64

Commit fb0d0d6c5492 added capabilities data and updated
qemucapabilitiestest but forgot to update qemucaps2xmltest
at the same time.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonews: Update for PCI support on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 14:20:09 +0000 (15:20 +0100)]
news: Update for PCI support on RISC-V

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add test for PCI usage on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 13:54:11 +0000 (14:54 +0100)]
tests: Add test for PCI usage on RISC-V

This shows users can now use PCI for RISC-V guests, as long
as they opt into it by manually assigning addresses.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add PCI support for RISC-V guests
Andrea Bolognani [Fri, 21 Sep 2018 13:29:38 +0000 (15:29 +0200)]
qemu: Add PCI support for RISC-V guests

virtio-mmio is still used by default, so if PCI is desired
it's necessary to explicitly opt-in by adding an appropriate

  <address type='pci' domain='0x0000' ... />

element to the corresponding device.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add capabilities data for QEMU 4.0.0 on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 13:07:34 +0000 (14:07 +0100)]
tests: Add capabilities data for QEMU 4.0.0 on RISC-V

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonetwork: set mtu as a DHCP option when specified
Casey Callendrello [Tue, 11 Dec 2018 16:05:43 +0000 (17:05 +0100)]
network: set mtu as a DHCP option when specified

This adds an additional directive to the dnsmasq configuration file that
notifies clients via dhcp about the link's MTU. Guests can then choose
adjust their link accordingly.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agostoragepoolxml2argvtest: run mountopts test conditionally
Ján Tomko [Thu, 31 Jan 2019 14:43:40 +0000 (15:43 +0100)]
storagepoolxml2argvtest: run mountopts test conditionally

This test relies on namespace support, which is only compiled in
if we have the 'fs' and 'netfs' backends.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostoragepoolxml2argvtest: introduce DO_TEST_PLATFORM
Ján Tomko [Thu, 31 Jan 2019 14:40:22 +0000 (15:40 +0100)]
storagepoolxml2argvtest: introduce DO_TEST_PLATFORM

Instead of repeating the same platform for every test,
set it once, since we do the same tests with the same
input for all platforms, it's just the output that differs.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostoragepoolxml2argvtest: pass the platform suffix as a string
Ján Tomko [Thu, 31 Jan 2019 14:10:58 +0000 (15:10 +0100)]
storagepoolxml2argvtest: pass the platform suffix as a string

Instead of a pair of bools.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agodocs: Drop /dev/net/tun from the list of shared devices
Erik Skultety [Thu, 31 Jan 2019 15:04:36 +0000 (16:04 +0100)]
docs: Drop /dev/net/tun from the list of shared devices

This was a left-over that should have been dropped along the change in
qemu.conf.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
6 years agotests: Fix storagepoolxml2xmltest execution for XML namespaces
John Ferlan [Wed, 30 Jan 2019 15:26:48 +0000 (10:26 -0500)]
tests: Fix storagepoolxml2xmltest execution for XML namespaces

Only run the pool-netfs-ns-mountopts if built WITH_STORAGE_FS and only
run pool-rbd-ns-configopts if built with WITH_STORAGE_RBD since the
namespace support is only enabled if the pool is enabled.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: remove check for 'qemu' binary
Daniel P. Berrangé [Thu, 31 Jan 2019 13:18:39 +0000 (13:18 +0000)]
qemu: remove check for 'qemu' binary

The 'qemu' binary used to provide the i386 emulator until it was renamed
to qemu-system-i386 in QEMU 1.0. Since we don't support such old
versions we don't need to check for 'qemu' when probing capabilities.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: change custom namespace URIs to drop '/source' component
Daniel P. Berrangé [Thu, 31 Jan 2019 11:14:09 +0000 (11:14 +0000)]
storage: change custom namespace URIs to drop '/source' component

The custom namespaces were originally registered against the storage
pool source struct, but during review this was changed to the top level
storage pool struct. The namespace URIs were not updated to match, so
had a redundant '/source' component.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: blockjob: Don't report block job progress at 100% if job isn't ready
Peter Krempa [Tue, 29 Jan 2019 16:17:29 +0000 (17:17 +0100)]
qemu: blockjob: Don't report block job progress at 100% if job isn't ready

Some clients poll virDomainGetBlockJobInfo rather than wait for the
VIR_DOMAIN_BLOCK_JOB_READY event. In some cases qemu can get to 100% and
still not reach the synchronised phase. Initiating a pivot in that case
will fail.

Given that computers are interacting here, the error that the job
can't be finalized yet is not handled very well by those specific
implementations.

Our docs now correctly state to use the event. We already do a similar
output adjustment in case when the progress is not available from qemu
as in that case we'd report 0 out of 0, which some apps also incorrectly
considered as 100% complete.

In this case we subtract 1 from the progress if the ready state is not
signalled by qemu if the progress was at 100% otherwise.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agodocs: css: Make docs page wider while still accomodating narrow screens
Peter Krempa [Tue, 29 Jan 2019 15:25:40 +0000 (16:25 +0100)]
docs: css: Make docs page wider while still accomodating narrow screens

Bump the width to 70em while keeping a maximum width of 95% to allow for
some border.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agodocs: Format bit shift and hex notation for bitwise flag enums
Peter Krempa [Thu, 24 Jan 2019 11:23:15 +0000 (12:23 +0100)]
docs: Format bit shift and hex notation for bitwise flag enums

Big number itself does not make much sense in some cases. Format the
bitshift format as well.

Changes our web page docs from:

VIR_MIGRATE_POSTCOPY = 32768 : Setting the VIR_MIGRATE_POSTCOPY...
VIR_MIGRATE_TLS      = 65536 : Setting the VIR_MIGRATE_TLS flag...

to:

VIR_MIGRATE_POSTCOPY = 32768 (0x8000; 1 << 15)  : Setting the VIR_MIGRATE_POSTCOPY...
VIR_MIGRATE_TLS      = 65536 (0x10000; 1 << 16) : Setting the VIR_MIGRATE_TLS flag...

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoconf: fix enum convertor function for feature capability errors
Daniel P. Berrangé [Thu, 31 Jan 2019 10:53:18 +0000 (10:53 +0000)]
conf: fix enum convertor function for feature capability errors

A copy+paste mistaken meant the wrong enum -> string convertor
function was used for the error when an incorrect feature capability was
used.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agohyperv: use "is None" not "== None" for PEP-8 compliance
Daniel P. Berrangé [Fri, 25 Jan 2019 11:18:55 +0000 (11:18 +0000)]
hyperv: use "is None" not "== None" for PEP-8 compliance

PEP 8 says:

    "Comparisons to singletons like None should always be done
     with 'is' or 'is not', never the equality operators."

There are potentially semantics differences, though in the case of this
libvirt code its merely a style change:

  http://jaredgrubb.blogspot.com/2009/04/python-is-none-vs-none.html

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agohyperv: remove unused 'total' variable
Daniel P. Berrangé [Fri, 25 Jan 2019 11:17:33 +0000 (11:17 +0000)]
hyperv: remove unused 'total' variable

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: pass virDomainDeviceInfo by reference
Daniel P. Berrangé [Fri, 25 Jan 2019 11:11:21 +0000 (11:11 +0000)]
qemu: pass virDomainDeviceInfo by reference

The virDomainDeviceInfo parameter is a large struct so it is preferrable
to pass it by reference instead of by value.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: pass struct _virStorageBackendQemuImgInfo by reference
Daniel P. Berrangé [Fri, 25 Jan 2019 11:09:55 +0000 (11:09 +0000)]
storage: pass struct _virStorageBackendQemuImgInfo by reference

The struct _virStorageBackendQemuImgInfo is quite large so it is
preferrable to pass it by reference instead of by value. This requires
us to stop modifying the "compat" field.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoremote: remove variable whose value is a constant
Daniel P. Berrangé [Fri, 25 Jan 2019 11:09:10 +0000 (11:09 +0000)]
remote: remove variable whose value is a constant

The 'rv' variable is never changed after being declared, so can be
removed.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: remove pointless check on enum value
Daniel P. Berrangé [Fri, 25 Jan 2019 11:07:20 +0000 (11:07 +0000)]
conf: remove pointless check on enum value

'val' is initialized from virDomainCapsFeatureTypeFromString and a
few lines earlier there was already a check for 'val < 0'.

The 'val >= 0' is thus always true. The enum conversion similarly
ensures that the val will be less than VIR_DOMAIN_CAPS_FEATURE_LAST,
so "val < VIR_DOMAIN_CAPS_FEATURE_LAST' is thus always true too.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: Label backing chain of user-provided target of blockCopy when starting the job
Peter Krempa [Wed, 23 Jan 2019 14:54:53 +0000 (15:54 +0100)]
qemu: Label backing chain of user-provided target of blockCopy when starting the job

Be more sensible when setting labels of the target of a
virDomainBlockCopy operation. Previously we'd relabel everything in case
it's a copy job even if there's no unlabelled backing chain. Since we
are also not sure whether the backing chain is shared we don't relabel
the chain on completion of the blockjob. This certainly won't play nice
with the image permission relabelling feature.

While this does not fix the case where the image is reused and has
backing chain it certainly sanitizes all the other cases. Later on it
will also allow to do the correct thing in cases where only one layer
was introduced.

The change is necessary as in case when -blockdev will be used we will
need to hotplug the backing chain and thus labeling needs to be setup in
advance and not only at the time of pivot.  To avoid multiple code paths
move the labeling now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: hotplug: Refactor qemuHotplugPrepareDiskAccess to work on virStorageSource
Peter Krempa [Wed, 23 Jan 2019 13:28:31 +0000 (14:28 +0100)]
qemu: hotplug: Refactor qemuHotplugPrepareDiskAccess to work on virStorageSource

Rather than passing in a virStorageSource which would override the
originally passed disk->src we can now drop passing in a disk completely
as all functions called inside here require a virStorageSource.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agolocking: Use virDomainLockImage[Attach|Detach] instead of *Disk
Peter Krempa [Wed, 23 Jan 2019 12:58:46 +0000 (13:58 +0100)]
locking: Use virDomainLockImage[Attach|Detach] instead of *Disk

Use the functions designed to deal with single images as the *Disk
functions were just wrappers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: driver: Remove disk source munging in qemuDomainBlockPivot
Peter Krempa [Wed, 23 Jan 2019 12:53:14 +0000 (13:53 +0100)]
qemu: driver: Remove disk source munging in qemuDomainBlockPivot

Previously there weren't any suitable functions which would allow
setting up host side of a full disk chain so we've opted to replace the
'src' in a virDomainDiskDef by the new image source.

That is now no longer necessary so remove the munging.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosecurity: Remove disk labeling functions and fix callers
Peter Krempa [Wed, 23 Jan 2019 12:28:43 +0000 (13:28 +0100)]
security: Remove disk labeling functions and fix callers

Now that we have replacement in the form of the image labeling function
we can drop the unnecessary functions by replacing all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: security: Replace and remove qemuSecurity[Set|Restore]DiskLabel
Peter Krempa [Wed, 23 Jan 2019 12:39:32 +0000 (13:39 +0100)]
qemu: security: Replace and remove qemuSecurity[Set|Restore]DiskLabel

The same can be achieved by using qemuSecurity[Set|Restore]ImageLabel.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: security: Add 'backingChain' flag to qemuSecurity[Set|Restore]ImageLabel
Peter Krempa [Wed, 23 Jan 2019 12:37:00 +0000 (13:37 +0100)]
qemu: security: Add 'backingChain' flag to qemuSecurity[Set|Restore]ImageLabel

The flag will control the VIR_SECURITY_DOMAIN_IMAGE_LABEL_BACKING_CHAIN
flag of the security driver image labeling APIs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosecurity: Remove security driver internals for disk labeling
Peter Krempa [Wed, 23 Jan 2019 10:50:33 +0000 (11:50 +0100)]
security: Remove security driver internals for disk labeling

Security labeling of disks consists of labeling of the disk image
itself and it's backing chain. Modify
virSecurityManager[Set|Restore]ImageLabel to take a boolean flag that
will label the full chain rather than the top image itself.

This allows to delete/unify some parts of the code and will also
simplify callers in some cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: cgroup: Change qemu[Setup|Teardown]DiskCgroup to take virStorageSource
Peter Krempa [Wed, 16 Jan 2019 14:49:07 +0000 (15:49 +0100)]
qemu: cgroup: Change qemu[Setup|Teardown]DiskCgroup to take virStorageSource

Since the disk is necessary only to get the source modify the functions
to take the source directly and rename them to
qemu[Setup|Teardown]ImageChainCgroup.

Additionally drop a pointless comment containing the old function name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: domain: Allow overriding disk source in qemuDomainDetermineDiskChain
Peter Krempa [Wed, 16 Jan 2019 14:33:07 +0000 (15:33 +0100)]
qemu: domain: Allow overriding disk source in qemuDomainDetermineDiskChain

When we need to detect a chain for a image which will become the new
source for a disk (e.g. after a disk media change or a blockjob) we'd
need to replace disk->src temporarily to do so.

Move the 'disksrc' temporary variable to an argument and adjust callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: domain: Clarify temp variable scope in qemuDomainDetermineDiskChain
Peter Krempa [Wed, 16 Jan 2019 14:17:24 +0000 (15:17 +0100)]
qemu: domain: Clarify temp variable scope in qemuDomainDetermineDiskChain

The function at first validates the top image of the chain, then
traverses the chain as declared in the XML (if any) and then procedes to
detect the rest of the chain from images. All of the steps have their
own temporary iterator.

Clarify the use scope of the steps by introducing a new temp variable
holding the top level source and adding comments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: Add storagepoolxml2argvtest source to EXTRA_DIST
John Ferlan [Wed, 30 Jan 2019 14:31:31 +0000 (09:31 -0500)]
tests: Add storagepoolxml2argvtest source to EXTRA_DIST

Commit f2f84b4d4 added storagepoolxml2argvtest processing; however,
it didn't follow alter the else to !WITH_STORAGE and add the source
itself to the EXTRA_DIST like the other WITH_STORAGE options for
virstorageutiltest and storagevolxml2argvtest.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agotests: Fix build issue with storagevolxml2xmltest
John Ferlan [Wed, 30 Jan 2019 14:29:37 +0000 (09:29 -0500)]
tests: Fix build issue with storagevolxml2xmltest

Commit 7a227688a caused a build failure on mingw. Following
other uses of including ../src/libvirt_driver_storage_impl.la
I moved to under the WITH_STORAGE conditional.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agorbd: Utilize storage pool namespace to manage config options
John Ferlan [Tue, 8 Jan 2019 14:28:03 +0000 (09:28 -0500)]
rbd: Utilize storage pool namespace to manage config options

Allow for adjustment of RBD configuration options via Storage
Pool XML Namespace adjustments. When namespace arguments are
used to start the pool, add a VIR_WARN to indicate that the
startup was tainted by custom config_opts.

Based off original patch/concept:

https://www.redhat.com/archives/libvir-list/2014-May/msg00940.html

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: Add storage pool namespace options to fs and netfs command lines
John Ferlan [Wed, 12 Dec 2018 22:41:14 +0000 (17:41 -0500)]
storage: Add storage pool namespace options to fs and netfs command lines

If the Storage Pool Namespace XML data exists, format the mount
options on the MOUNT command line and issue a VIR_WARN to indicate
that the storage pool was tainted by custom mount_opts.

When the pool is started, the options will be generated on the
command line along with the options already defined.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: Add infrastructure to manage XML namespace options
John Ferlan [Mon, 7 Jan 2019 22:14:57 +0000 (17:14 -0500)]
storage: Add infrastructure to manage XML namespace options

Introduce the virStoragePoolFSMountOptionsDef to be used to
manage the Storage Pool XML Namespace for mount options.

Using a new virStorageBackendNamespaceInit function, set the
virStoragePoolXMLNamespace into the _virStoragePoolOptions when
the storage backend is loaded.

Modify the storagepool.rng to allow for the usage of a different
XML namespace to parse the fs_mount_opts to be included with
the fs and netfs storage pool definitions.

Modify the storagepoolxml2xmltest to utilize a properly modified
XML file to parse and format the namespace for a netfs storage pool.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Introduce virStoragePoolXMLNamespace
John Ferlan [Thu, 3 Jan 2019 16:47:48 +0000 (11:47 -0500)]
conf: Introduce virStoragePoolXMLNamespace

Introduce the infrastructure necessary to manage a Storage Pool XML
Namespace. The general concept is similar to virDomainXMLNamespace,
except that for Storage Pools the storage backend specific details
can be stored within the _virStoragePoolOptions unlike the domain
processing code which manages its xmlopt's via the virDomainXMLOption
which is allocated/passed around for each domain.

This patch defines the add the parse, format, free, and href methods
required to process the XML and callout from the Storage Pool Def
parse, format, and free API's to perform the action on the XML data
for/from the backend.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovirsh: Add source-protocol-ver for pool commands
John Ferlan [Fri, 11 Jan 2019 19:48:31 +0000 (14:48 -0500)]
virsh: Add source-protocol-ver for pool commands

Allow the addition of the <protocol ver='n'/> to the provided XML.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: Add the nfsvers to the command line
John Ferlan [Fri, 11 Jan 2019 18:42:18 +0000 (13:42 -0500)]
storage: Add the nfsvers to the command line

If protocolVer present, add the -o nfsvers=# to the command
line for the NFS Storage Pool

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Add optional NFS Source Pool <protocol ver='n'/> option
John Ferlan [Fri, 11 Jan 2019 00:23:27 +0000 (19:23 -0500)]
conf: Add optional NFS Source Pool <protocol ver='n'/> option

Add an optional way to define which NFS Server version will be
used to content the target NFS server.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>