]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
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>
6 years agodocs: Add news mention of default fs/netfs storage pool mount options
John Ferlan [Thu, 17 Jan 2019 20:50:41 +0000 (15:50 -0500)]
docs: Add news mention of default fs/netfs storage pool mount options

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: Add default mount options for fs/netfs storage pools
John Ferlan [Fri, 11 Jan 2019 15:53:35 +0000 (10:53 -0500)]
storage: Add default mount options for fs/netfs storage pools

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

Modify the command generation to add some default options to the
fs/netfs storage pools based on the OS type. For Linux, it'll be
the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec".
For others, just leave the options alone.

Modify the storagepoolxml2argvtest to handle the fact that the
same input XML could generate different output XML based on whether
Linux, FreeBSD, or other was being built.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Alter virCapabilitiesFormatGuestXML to take virCapsGuestPtr
John Ferlan [Wed, 9 Jan 2019 18:31:50 +0000 (13:31 -0500)]
conf: Alter virCapabilitiesFormatGuestXML to take virCapsGuestPtr

Rather than deref off of "caps->guests", let's pass "caps->guests" and
caps->nguests to have the helper use "guests[i]->" instead.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Extract guest XML formatting from virCapabilitiesFormatXML
John Ferlan [Wed, 9 Jan 2019 17:00:28 +0000 (12:00 -0500)]
conf: Extract guest XML formatting from virCapabilitiesFormatXML

Let's extract out the <guest> code into it's own method/helper.

NB: One minor change between the two is usage of "buf" instead
of "&buf" in the new code since we pass the address of &buf to
the helper.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Alter virCapabilitiesFormatHostXML to take virCapsHostPtr
John Ferlan [Wed, 9 Jan 2019 17:10:59 +0000 (12:10 -0500)]
conf: Alter virCapabilitiesFormatHostXML to take virCapsHostPtr

Rather than deref off of "caps->host.", let's pass "&caps->host"
and make the helper use "host->" instead.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Extract host XML formatting from virCapabilitiesFormatXML
John Ferlan [Wed, 9 Jan 2019 16:51:17 +0000 (11:51 -0500)]
conf: Extract host XML formatting from virCapabilitiesFormatXML

Let's extract out the <host> code into it's own method/helper.

NB: One minor change between the two is usage of "buf" instead
of "&buf" in the new code since we pass the address of &buf to
the helper.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoRevert "qemu: Forbid pinning vCPUs for TCG domain"
Daniel P. Berrangé [Wed, 17 Oct 2018 13:59:52 +0000 (14:59 +0100)]
Revert "qemu: Forbid pinning vCPUs for TCG domain"

This reverts commit 8b035c84d8a7362a87a95e6114b8e7f959685ed9.

The MTTCG impl in QEMU does allow pinning vCPUs.

When the guest is running we already check if pinning is
possible in the qemuDomainPinVcpuLive method, so this
check was adding no benefit.

When the guest is not running, we cannot know whether the
subsequent launch will use MTTCG or TCG, so we must allow
the pinning request. If the guest does use TCG on the next
launch it will fail, but this is no worse than if the user
had done a virDomainDefineXML with an XML doc specifying
vCPU pinning.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: fix recording of vCPU pids for MTTCG
Daniel P. Berrangé [Wed, 17 Oct 2018 13:14:32 +0000 (14:14 +0100)]
qemu: fix recording of vCPU pids for MTTCG

MTTCG is the new multi-threaded impl of TCG which follows
KVM in having one host OS thread per vCPU. Historically
we have discarded all PIDs reported for TCG guests, but
we must now selectively honour this data.

We don't have anything in the domain XML that indicates
whether a guest is using TCG or MTTCG. While QEMU does
have an option (-accel tcg,thread=single|multi), it is
not desirable to expose this in libvirt. QEMU will
automatically use MTTCG when the host/guest architecture
pairing is known to be safe. Only developers of QEMU TCG
have a strong reason to override this logic.

Thus we use two sanity checks to decide if the vCPU
PID information is usable. First we see if the PID
duplicates the main emulator PID, and second we see
if the PID duplicates any other vCPUs.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agolib: domain: Emphasise that users should wait for block job READY state via events
Peter Krempa [Mon, 21 Jan 2019 15:01:57 +0000 (16:01 +0100)]
lib: domain: Emphasise that users should wait for block job READY state via events

The transition to the ready state is best observed by events as it's
ansynchronous and does not hint users to do polling. As currently only
the qemu driver supports block copy and block commit and the ready state
event was introduced by qemu 1.3 we can fully switch to the new
approach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agolib: Clarify that any block job may block VM save or device detach
Peter Krempa [Mon, 21 Jan 2019 11:36:17 +0000 (12:36 +0100)]
lib: Clarify that any block job may block VM save or device detach

The documentation was only referring to a copy job, but in fact any
running blockjob will have the same results.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Don't reject making domain persistent if block copy is running
Peter Krempa [Mon, 21 Jan 2019 11:28:25 +0000 (12:28 +0100)]
qemu: Don't reject making domain persistent if block copy is running

Add documentation that the 'VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB' flag
is auto-assumed if the block copy job is started while the VM is
transient and remove the restriction to define the domain when copy
is running.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: move virtual network firwall rules into private chains
Daniel P. Berrangé [Wed, 5 Dec 2018 15:53:55 +0000 (15:53 +0000)]
util: move virtual network firwall rules into private chains

The previous commit created new chains to hold the firewall rules. This
commit changes the code that creates rules to place them in the new
private chains instead of the builtin top level chains.

With two networks running, the rules in the filter table now look like

  -N LIBVIRT_FWI
  -N LIBVIRT_FWO
  -N LIBVIRT_FWX
  -N LIBVIRT_INP
  -N LIBVIRT_OUT
  -A INPUT -j LIBVIRT_INP
  -A FORWARD -j LIBVIRT_FWX
  -A FORWARD -j LIBVIRT_FWI
  -A FORWARD -j LIBVIRT_FWO
  -A OUTPUT -j LIBVIRT_OUT
  -A LIBVIRT_FWI -d 192.168.0.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A LIBVIRT_FWI -o virbr0 -j REJECT --reject-with icmp-port-unreachable
  -A LIBVIRT_FWI -d 192.168.1.0/24 -o virbr1 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A LIBVIRT_FWI -o virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A LIBVIRT_FWO -s 192.168.0.0/24 -i virbr0 -j ACCEPT
  -A LIBVIRT_FWO -i virbr0 -j REJECT --reject-with icmp-port-unreachable
  -A LIBVIRT_FWO -s 192.168.1.0/24 -i virbr1 -j ACCEPT
  -A LIBVIRT_FWO -i virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A LIBVIRT_FWX -i virbr0 -o virbr0 -j ACCEPT
  -A LIBVIRT_FWX -i virbr1 -o virbr1 -j ACCEPT
  -A LIBVIRT_INP -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
  -A LIBVIRT_INP -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
  -A LIBVIRT_INP -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
  -A LIBVIRT_INP -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
  -A LIBVIRT_INP -i virbr1 -p udp -m udp --dport 53 -j ACCEPT
  -A LIBVIRT_INP -i virbr1 -p tcp -m tcp --dport 53 -j ACCEPT
  -A LIBVIRT_INP -i virbr1 -p udp -m udp --dport 67 -j ACCEPT
  -A LIBVIRT_INP -i virbr1 -p tcp -m tcp --dport 67 -j ACCEPT
  -A LIBVIRT_OUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
  -A LIBVIRT_OUT -o virbr1 -p udp -m udp --dport 68 -j ACCEPT

While in the nat table:

  -N LIBVIRT_PRT
  -A POSTROUTING -j LIBVIRT_PRT
  -A LIBVIRT_PRT -s 192.168.0.0/24 -d 224.0.0.0/24 -j RETURN
  -A LIBVIRT_PRT -s 192.168.0.0/24 -d 255.255.255.255/32 -j RETURN
  -A LIBVIRT_PRT -s 192.168.0.0/24 ! -d 192.168.0.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
  -A LIBVIRT_PRT -s 192.168.0.0/24 ! -d 192.168.0.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
  -A LIBVIRT_PRT -s 192.168.0.0/24 ! -d 192.168.0.0/24 -j MASQUERADE
  -A LIBVIRT_PRT -s 192.168.1.0/24 -d 224.0.0.0/24 -j RETURN
  -A LIBVIRT_PRT -s 192.168.1.0/24 -d 255.255.255.255/32 -j RETURN
  -A LIBVIRT_PRT -s 192.168.1.0/24 ! -d 192.168.1.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
  -A LIBVIRT_PRT -s 192.168.1.0/24 ! -d 192.168.1.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
  -A LIBVIRT_PRT -s 192.168.1.0/24 ! -d 192.168.1.0/24 -j MASQUERADE

And finally the mangle table:

  -N LIBVIRT_PRT
  -A POSTROUTING -j LIBVIRT_PRT
  -A LIBVIRT_PRT -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
  -A LIBVIRT_PRT -o virbr1 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: create private chains for virtual network firewall rules
Daniel P. Berrangé [Wed, 31 Oct 2018 19:33:21 +0000 (19:33 +0000)]
util: create private chains for virtual network firewall rules

Historically firewall rules for virtual networks were added straight
into the base chains. This works but has a number of bugs and design
limitations:

  - It is inflexible for admins wanting to add extra rules ahead
    of libvirt's rules, via hook scripts.

  - It is not clear to the admin that the rules were created by
    libvirt

  - Each rule must be deleted by libvirt individually since they
    are all directly in the builtin chains

  - The ordering of rules in the forward chain is incorrect
    when multiple networks are created, allowing traffic to
    mistakenly flow between networks in one direction.

To address all of these problems, libvirt needs to move to creating
rules in its own private chains. In the top level builtin chains,
libvirt will add links to its own private top level chains.

Addressing the traffic ordering bug requires some extra steps. With
everything going into the FORWARD chain there was interleaving of rules
for outbound traffic and inbound traffic for each network:

  -A FORWARD -d 192.168.3.0/24 -o virbr1 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A FORWARD -s 192.168.3.0/24 -i virbr1 -j ACCEPT
  -A FORWARD -i virbr1 -o virbr1 -j ACCEPT
  -A FORWARD -o virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A FORWARD -i virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A FORWARD -d 192.168.2.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A FORWARD -s 192.168.2.0/24 -i virbr0 -j ACCEPT
  -A FORWARD -i virbr0 -o virbr0 -j ACCEPT
  -A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
  -A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable

The rule allowing outbound traffic from virbr1 would mistakenly
allow packets from virbr1 to virbr0, before the rule denying input
to virbr0 gets a chance to run.

What we really need todo is group the forwarding rules into three
distinct sets:

 * Cross rules - LIBVIRT_FWX

  -A FORWARD -i virbr1 -o virbr1 -j ACCEPT
  -A FORWARD -i virbr0 -o virbr0 -j ACCEPT

 * Incoming rules - LIBVIRT_FWI

  -A FORWARD -d 192.168.3.0/24 -o virbr1 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A FORWARD -o virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A FORWARD -d 192.168.2.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  -A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable

 * Outgoing rules - LIBVIRT_FWO

  -A FORWARD -s 192.168.3.0/24 -i virbr1 -j ACCEPT
  -A FORWARD -i virbr1 -j REJECT --reject-with icmp-port-unreachable
  -A FORWARD -s 192.168.2.0/24 -i virbr0 -j ACCEPT
  -A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable

There is thus no risk of outgoing rules for one network mistakenly
allowing incoming traffic for another network, as all incoming rules
are evalated first.

With this in mind, we'll thus need three distinct chains linked from
the FORWARD chain, so we end up with:

        INPUT --> LIBVIRT_INP   (filter)

       OUTPUT --> LIBVIRT_OUT   (filter)

      FORWARD +-> LIBVIRT_FWX   (filter)
              +-> LIBVIRT_FWO
              \-> LIBVIRT_FWI

  POSTROUTING --> LIBVIRT_PRT   (nat & mangle)

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: pass layer into firewall query callback
Daniel P. Berrangé [Tue, 4 Dec 2018 16:33:28 +0000 (16:33 +0000)]
util: pass layer into firewall query callback

Some of the query callbacks want to know the firewall layer that was
being used for triggering the query to avoid duplicating that data.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: add platform driver callbacks around firewall reload
Daniel P. Berrangé [Wed, 5 Dec 2018 13:29:07 +0000 (13:29 +0000)]
network: add platform driver callbacks around firewall reload

Allow the platform driver impls to run logic before and after the
firewall reload process.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: Don't double-free disk->mirror if block commit initialization fails
Peter Krempa [Thu, 24 Jan 2019 09:35:48 +0000 (10:35 +0100)]
qemu: Don't double-free disk->mirror if block commit initialization fails

disk->mirror would not be cleared while the local pointer was freed in
qemuDomainBlockCommit if qemuDomainObjExitMonitor or qemuBlockJobDiskNew
would return a failure.

Since block job handling is executed in the separate handler which needs
a qemu job, we don't need to pre-set the mirror state prior to starting
the job. Similarly the block copy job does not do that.

Move the setting of the data after starting the job so that we avoid
this problem.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Clear block copy mirror state explicitly
Peter Krempa [Thu, 24 Jan 2019 09:49:34 +0000 (10:49 +0100)]
qemu: Clear block copy mirror state explicitly

While this should not be necessary as we clear it in the event handler,
let's be sure and clear it prior to starting the job.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: blockjob: Mark job as started only when it's new
Peter Krempa [Thu, 24 Jan 2019 09:31:38 +0000 (10:31 +0100)]
qemu: blockjob: Mark job as started only when it's new

Switching a block job to some states (e.g. QEMU_BLOCKJOB_STATE_READY)
might not require a job, thus if it will become ready asynchronously we
should not overwrite the state any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: blockjob: Make sure that internal states are not reported as event
Peter Krempa [Thu, 24 Jan 2019 08:49:26 +0000 (09:49 +0100)]
qemu: blockjob: Make sure that internal states are not reported as event

While the callers should make sure that they don't call
qemuBlockJobEmitEvents for any internal state or job, let's add checks
that prevents us from emitting wrong events altogether.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agolib: Fix docs generated for enum virDomainBlockJobType
Peter Krempa [Thu, 24 Jan 2019 08:46:57 +0000 (09:46 +0100)]
lib: Fix docs generated for enum virDomainBlockJobType

Mixing documentation strings trailing the enum value and preceeding the
enum value ends in a big mixup. Fix docs string for
VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN so that it's not squished together
with the next one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agovirfile: Detect ceph as shared FS
Michal Privoznik [Thu, 24 Jan 2019 08:52:42 +0000 (09:52 +0100)]
virfile: Detect ceph as shared FS

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

Ceph can be mounted just like any other filesystem and in fact is
a shared and cluster filesystem. The filesystem magic constant
was taken from kernel sources as it is not in magic.h yet.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolib: Use more of VIR_STEAL_PTR()
Michal Privoznik [Mon, 28 Jan 2019 13:41:37 +0000 (14:41 +0100)]
lib: Use more of VIR_STEAL_PTR()

We have this very handy macro called VIR_STEAL_PTR() which steals
one pointer into the other and sets the other to NULL. The
following coccinelle patch was used to create this commit:

  @ rule1 @
  identifier a, b;
  @@

  - b = a;
    ...
  - a = NULL;
  + VIR_STEAL_PTR(b, a);

Some places were clean up afterwards to make syntax-check happy
(e.g. some curly braces were removed where the body become a one
liner).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agonews: document bhyve custom commandline support
Roman Bogorodskiy [Fri, 18 Jan 2019 15:20:26 +0000 (19:20 +0400)]
news: document bhyve custom commandline support

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: bhyve: document commandline element
Roman Bogorodskiy [Fri, 18 Jan 2019 14:42:02 +0000 (18:42 +0400)]
docs: bhyve: document commandline element

Document the <bhyve:commandline> element which allows
to inject custom command line arguments for bhyve.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agobhyve: implement support for commandline args
Roman Bogorodskiy [Thu, 17 Jan 2019 15:07:20 +0000 (19:07 +0400)]
bhyve: implement support for commandline args

Implement support for passing custom command line arguments
to bhyve using the 'bhyve:commandline' element:

  <bhyve:commandline>
    <bhyve:arg value='-newarg'/>
  </bhyve:commandline>

 * Define virDomainXMLNamespace for the bhyve driver, which
   at this point supports only the 'commandline' element
   described above,
 * Update command generation code to inject these command line
   arguments between driver-generated arguments and the vmname
   positional argument.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: add forgotten mentions of forward mode "open"
Laine Stump [Wed, 9 Jan 2019 23:45:49 +0000 (18:45 -0500)]
docs: add forgotten mentions of forward mode "open"

A couple places in the docs didn't get updated when the forward mode
"open" was added.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: remove stale function
Laine Stump [Thu, 10 Jan 2019 00:42:41 +0000 (19:42 -0500)]
network: remove stale function

networkMigrateStateFiles was added nearly 5 years ago when the network
state directory was moved from /var/lib/libvirt to /var/run/libvirt
just prior to libvirt-1.2.4). It was only required to maintain proper
state information for networks that were active during an upgrade that
didn't involve rebooting the host. At this point the likelyhood of
anyone upgrading their libvirt from pre-1.2.4 directly to 5.0.0 or
later *without rebooting the host* is probably so close to 0 that no
properly informed bookie would take *any* odds on it happening, so it
seems appropriate to remove this pointless code.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agovirjson: add convenience wrapper for appending string to array
Eric Blake [Fri, 25 Jan 2019 03:32:55 +0000 (21:32 -0600)]
virjson: add convenience wrapper for appending string to array

Upcoming patches need an array of strings for use in QMP
block-dirty-bitmap-merge.  A convenience wrapper cuts down
on the verbosity of creating the array, similar to the
existing virJSONValueObjectAppendString().

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirjson: always raise vir error on append failures
Eric Blake [Fri, 25 Jan 2019 03:28:23 +0000 (21:28 -0600)]
virjson: always raise vir error on append failures

A function that returns -1 for multiple possible failures, but only
raises a libvirt error for some of those failures, can be hard to
use correctly. Yet both of our JSON object/array appenders fall in
that pattern.  True, the silent errors represent coding bugs that
none of the callers should ever trigger, while the noisy errors
represent memory failures that can happen anywhere, so we happened
to never end up failing without an error. But it is better to
either use the _QUIET memory allocation variants, and make callers
decide to report failure; or make all failure paths noisy. This
patch takes the latter approach.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotools: Document completer callback
Michal Privoznik [Tue, 22 Jan 2019 11:23:07 +0000 (12:23 +0100)]
tools: Document completer callback

Strictly speaking, this should go near vshCompleter typedef
declaration. However, I find it more useful near actual completer
implementations.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemuBuildControllersCommandLine: use i instead of j as the counter
Ján Tomko [Wed, 16 Jan 2019 07:47:06 +0000 (08:47 +0100)]
qemuBuildControllersCommandLine: use i instead of j as the counter

Now that the nested loop is gone.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agorename qemuBuildControllerDevCommandLine
Ján Tomko [Wed, 16 Jan 2019 07:46:29 +0000 (08:46 +0100)]
rename qemuBuildControllerDevCommandLine

Use qemuBuildControllersCommandLine since it builds the command line
for (nearly) all controllers, not just one.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemuBuildControllersByTypeCommandLine: free devstr in the cleanup
Ján Tomko [Tue, 15 Jan 2019 16:59:17 +0000 (17:59 +0100)]
qemuBuildControllersByTypeCommandLine: free devstr in the cleanup
section

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: format CCID controllers after USB hubs
Ján Tomko [Tue, 15 Jan 2019 15:50:22 +0000 (16:50 +0100)]
qemu: format CCID controllers after USB hubs

Since they go on the USB bus, format them after USB hubs.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: Introduce qemuBuildControllersByTypeCommandLine
Ján Tomko [Tue, 15 Jan 2019 15:44:41 +0000 (16:44 +0100)]
qemu: Introduce qemuBuildControllersByTypeCommandLine

Now that the inner loop does not require any other variables,
it can be easily separated. Apart from reducing the indentation
level this will allow it to be called from different code paths.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemuBuildControllerDevStr: remove nusbcontroller argument
Ján Tomko [Tue, 15 Jan 2019 15:31:54 +0000 (16:31 +0100)]
qemuBuildControllerDevStr: remove nusbcontroller argument

Now that it's no longer needed, remove the argument.
This removes the last helper variable in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: separate counting of USB controllers
Ján Tomko [Tue, 15 Jan 2019 15:28:55 +0000 (16:28 +0100)]
qemu: separate counting of USB controllers

qemuBuildLegacyUSBControllerCommandLine is the only place where
we need to count the USB controllers.

Count them again instead of keeping track in a variable passed to
qemuBuildControllerDevStr.

This removes the need for another variable in the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: separate counting of legacy USB controllers
Ján Tomko [Tue, 15 Jan 2019 15:15:39 +0000 (16:15 +0100)]
qemu: separate counting of legacy USB controllers

Count them in qemuBuildLegacyUSBControllerCommandLine to remove
yet another variable accessed from the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoAdd qemuBuildDomainForbidLegacyUSBController
Ján Tomko [Tue, 15 Jan 2019 15:08:48 +0000 (16:08 +0100)]
Add qemuBuildDomainForbidLegacyUSBController

Shorten some long conditions.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: exit early if USB_CONTROLLER_MODEL_NONE is present
Ján Tomko [Tue, 15 Jan 2019 14:46:39 +0000 (15:46 +0100)]
qemu: exit early if USB_CONTROLLER_MODEL_NONE is present

This removes the need to mark it in the 'usbcontroller' variable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: move out legacy USB controller formatting
Ján Tomko [Tue, 15 Jan 2019 14:33:10 +0000 (15:33 +0100)]
qemu: move out legacy USB controller formatting

Move out the code formatting "-usb" on the QEMU command line.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agovirPortAllocatorSetUsed: ignore port 0
Ján Tomko [Mon, 21 Jan 2019 14:49:23 +0000 (15:49 +0100)]
virPortAllocatorSetUsed: ignore port 0

Similar to what commit 86dba8f3 did for virPortAllocatorRelease,
ignore port 0 in virPortAllocatorSetUsed.

For all the reasonable use cases the callers already check that
the port is non-zero, however if the port from the XML overflows
unsigned short and turns into 0, it can be set as used by
virPortAllocatorSetUsed but not released by virPortAllocatorRelease.

Also skip port '0' in virPortAllocatorSetUsed to make this behavior
symmetric.

The serenity was disturbed by commit 5dbda5e9 which started using
virPortAllocatorRelease instead of virPortAllocatorSetUsed (false).

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agodocs/governance: Clarify the version number of the LGPL
Thomas Huth [Fri, 25 Jan 2019 09:50:28 +0000 (10:50 +0100)]
docs/governance: Clarify the version number of the LGPL

There is no "GNU Lesser General Public License, version 2",
only version 2.1 and later. In "version 2", the license was
still called "Library" instead of "Lesser". So assume that
version 2.1 is meant here.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotools/virt-xml-validate: Fix GPL information
Thomas Huth [Fri, 25 Jan 2019 09:50:27 +0000 (10:50 +0100)]
tools/virt-xml-validate: Fix GPL information

The tools/virt-xml-validate.in file is licensed under the terms of
the GPL, but then says "You should have received a copy of the
GNU *Lesser* General Public License". Thus scratch the "Lesser" here.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agobootstrap.conf: Fix LGPL information
Thomas Huth [Fri, 25 Jan 2019 09:50:26 +0000 (10:50 +0100)]
bootstrap.conf: Fix LGPL information

The bootstrap.conf is licensed under the terms of the LGPL, but then
suggests to "See the GNU General Public License for more details".
That should be the "GNU Lesser General Public License" instead, of
course.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: command: Make BuildVirtioDevStr more generic
Cole Robinson [Tue, 22 Jan 2019 21:15:03 +0000 (16:15 -0500)]
qemu: command: Make BuildVirtioDevStr more generic

Switch qemuBuildVirtioDevStr to use virDomainDeviceSetData: callers
pass in the virDomainDeviceType and the void * DefPtr. This will
save us from having to repeatedly extend the function argument
list in subsequent patches.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: Add virDomainDeviceSetData
Cole Robinson [Tue, 22 Jan 2019 20:19:29 +0000 (15:19 -0500)]
conf: Add virDomainDeviceSetData

This is essentially a wrapper for easily setting the variable
name in virDomainDeviceDef that matches its associated
VIR_DOMAIN_DEVICE_TYPE.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: command: Convert vhost-{vsock,scsi} to qemuBuildVirtioDevStr
Cole Robinson [Tue, 22 Jan 2019 19:25:22 +0000 (14:25 -0500)]
qemu: command: Convert vhost-{vsock,scsi} to qemuBuildVirtioDevStr

Current code essentially duplicates the same logic, but misses
some cases (like vhost-vsock-device).

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: command: Make vhost-scsi device string depend on address
Cole Robinson [Tue, 22 Jan 2019 19:20:06 +0000 (14:20 -0500)]
qemu: command: Make vhost-scsi device string depend on address

The vhost-scsi device string should depend on the requested
address type, not strictly on the emulated arch. This is the
same logic used by qemuBuildVirtioDevStr, and this particular
path is already tested in the hostdev-scsi-vhost-scsi-ccw tests

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: Move <rng> validation out of qemu_command.c
Cole Robinson [Tue, 22 Jan 2019 19:02:27 +0000 (14:02 -0500)]
qemu: Move <rng> validation out of qemu_command.c

Move the rng->model == VIRTIO check to parse time. This also
allows us to remove similar checks throughout the qemu driver

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: Move <memballoon> validation out of qemu_command.c
Cole Robinson [Thu, 17 Jan 2019 17:52:38 +0000 (12:52 -0500)]
qemu: Move <memballoon> validation out of qemu_command.c

If we validate that memballoon is NONE|VIRTIO at parse time,
we can drop similar checks elsewhere in the qemu driver

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: Add virDomainNetIsVirtioModel
Cole Robinson [Mon, 21 Jan 2019 22:59:02 +0000 (17:59 -0500)]
conf: Add virDomainNetIsVirtioModel

This will be extended in the future, so let's simplify things by
centralizing the checks.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: Set net->model earlier
Cole Robinson [Mon, 21 Jan 2019 22:53:15 +0000 (17:53 -0500)]
conf: Set net->model earlier

So later code can more easily access def->model

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agodocs: Add more iscsi-direct references to storage pages
John Ferlan [Thu, 17 Jan 2019 17:49:00 +0000 (12:49 -0500)]
docs: Add more iscsi-direct references to storage pages

Found that it was missing in formatstorage and had a few typos
in the storage driver page.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: Add check to avoid a NULL compare for SysfsPath
Cheng Lin [Fri, 18 Jan 2019 07:49:37 +0000 (15:49 +0800)]
conf: Add check to avoid a NULL compare for SysfsPath

If the two sysfs_path are both NULL, there may be an incorrect
object returned for virNodeDeviceObjListFindBySysfsPath().

This check exists in old interface virNodeDeviceFindBySysfsPath().
e.g.
virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
                             const char *sysfs_path)
{
    ...
        if ((devs->objs[i]->def->sysfs_path != NULL) &&
            (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) {
    ...
}

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Cheng Lin <cheng.lin130@zte.com.cn>
6 years agodomain_conf: Free egl render node in virDomainGraphicsDefFree
Michal Privoznik [Wed, 23 Jan 2019 15:33:46 +0000 (16:33 +0100)]
domain_conf: Free egl render node in virDomainGraphicsDefFree

 13 bytes in 1 blocks are definitely lost in loss record 44 of 179
    at 0x4C2EE6F: malloc (vg_replace_malloc.c:299)
    by 0x9514A69: strdup (in /lib64/libc-2.27.so)
    by 0x5E60C0B: virStrdup (virstring.c:956)
    by 0x54C856F: virHostGetDRMRenderNode (qemuxml2argvmock.c:190)
    by 0x57CB4E3: qemuProcessGraphicsSetupRenderNode (qemu_process.c:4860)
    by 0x57CB571: qemuProcessSetupGraphics (qemu_process.c:4881)
    by 0x57CE01B: qemuProcessPrepareDomain (qemu_process.c:6040)
    by 0x57D102E: qemuProcessCreatePretendCmd (qemu_process.c:6975)
    by 0x114C1C: testCompareXMLToArgv (qemuxml2argvtest.c:611)
    by 0x134B90: virTestRun (testutils.c:174)
    by 0x123478: mymain (qemuxml2argvtest.c:1697)
    by 0x136BFA: virTestMain (testutils.c:1112)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirpci: Fix memleak in virPCIDeviceIterDevices
Michal Privoznik [Wed, 23 Jan 2019 15:32:59 +0000 (16:32 +0100)]
virpci: Fix memleak in virPCIDeviceIterDevices

This partially reverts 00dc991ca167302c7a72f4fb16be061d05b12a32.

 2,030 (1,456 direct, 574 indirect) bytes in 14 blocks are definitely lost in loss record 77 of 80
    at 0x4C30E96: calloc (vg_replace_malloc.c:711)
    by 0x50F83AA: virAlloc (viralloc.c:143)
    by 0x5178DFA: virPCIDeviceNew (virpci.c:1753)
    by 0x51753E9: virPCIDeviceIterDevices (virpci.c:468)
    by 0x5175EB5: virPCIDeviceGetParent (virpci.c:759)
    by 0x517AB55: virPCIDeviceIsBehindSwitchLackingACS (virpci.c:2476)
    by 0x517AC24: virPCIDeviceIsAssignable (virpci.c:2494)
    by 0x10BF27: testVirPCIDeviceIsAssignable (virpcitest.c:229)
    by 0x10D14C: virTestRun (testutils.c:174)
    by 0x10C535: mymain (virpcitest.c:422)
    by 0x10F1B6: virTestMain (testutils.c:1112)
    by 0x10CF93: main (virpcitest.c:455)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirPCIGetNetName: Initialize @netname to NULL
Michal Privoznik [Wed, 23 Jan 2019 09:38:48 +0000 (10:38 +0100)]
virPCIGetNetName: Initialize @netname to NULL

This is a return argument that is to be compared against NULL on
successful return. However, it is not initialized and therefore
relies on callers setting it to NULL prior calling the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: improve compile-time check of qemuBlockjobState mapping
Eric Blake [Wed, 23 Jan 2019 19:38:41 +0000 (13:38 -0600)]
qemu: improve compile-time check of qemuBlockjobState mapping

Asserting the value we set four lines earlier in qemuBlockjobState
doesn't buy us any safety (if the public header adds a value, we end
up skipping that value without the compiler warning us of our gap);
what we really want is to assert that the value auto-assigned by the
compiler matches the actual last value in the public headers (as was
done below for qemuBlockJobType).  Add useful comments while at it.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoapparmor: convert libvirtd profile to a named profile
Jim Fehlig [Sat, 12 Jan 2019 00:59:59 +0000 (17:59 -0700)]
apparmor: convert libvirtd profile to a named profile

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
6 years agoapparmor: Add support for named profiles
Jim Fehlig [Sat, 12 Jan 2019 00:26:03 +0000 (17:26 -0700)]
apparmor: Add support for named profiles

Upstream apparmor is switching to named profiles. In short,

/usr/sbin/dnsmasq {

becomes

profile dnsmasq /usr/sbin/dnsmasq {

Consequently, any profiles that reference profiles in a peer= condition
need to be updated if the referenced profile switches to a named profile.
Apparmor commit 9ab45d81 switched dnsmasq to a named profile. ATM it is
the only named profile switch that has affected libvirt. Add rules to the
libvirtd profile to reference dnsmasq in peer= conditions by profile name.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
6 years agolibxl: Set current memory value after successful balloon
Jim Fehlig [Thu, 10 Jan 2019 22:18:36 +0000 (15:18 -0700)]
libxl: Set current memory value after successful balloon

The libxl driver does not set the new memory value in the active domain def
after a successful balloon. This results in the old memory value in
<currentMemory>. E.g.

virsh dumpxml test | grep currentMemory
  <currentMemory unit='KiB'>20971520</currentMemory>
virsh setmem test 16777216 --live
virsh dumpxml test | grep currentMemory
  <currentMemory unit='KiB'>20971520</currentMemory>

Set the new memory value in active domain def after a successful call to
libxl_set_memory_target().

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: process: Handle all failure values for dimms in qemuProcessHandleAcpiOstInfo
Peter Krempa [Tue, 22 Jan 2019 11:14:39 +0000 (12:14 +0100)]
qemu: process: Handle all failure values for dimms in qemuProcessHandleAcpiOstInfo

Hanlde all the possible failure codes as per ACPI standard documented in
the function header.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: process: Improve documentation of values handled by qemuProcessHandleAcpiOstInfo
Peter Krempa [Tue, 22 Jan 2019 09:35:53 +0000 (10:35 +0100)]
qemu: process: Improve documentation of values handled by qemuProcessHandleAcpiOstInfo

We forgot to document the specific fields for the 0x103 and 0x200
sources which are tied to device removal and device hotplug
respectively.

The value description is based on the ACPI 6.2A standard Table 6-207 and
Table 6-208. At the time of writing of this patch the standard can be
accessed e.g. at:

https://www.uefi.org/sites/default/files/resources/ACPI%206_2_A_Sept29.pdf

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