]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
5 years agoqemu: handle unassigned PCI hostdevs in command line
Daniel Henrique Barboza [Tue, 17 Dec 2019 20:35:03 +0000 (17:35 -0300)] 
qemu: handle unassigned PCI hostdevs in command line

Previous patch made it possible for the QEMU driver to check if
a given PCI hostdev is unassigned, by checking if dev->info->type is
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED, meaning that this device
shouldn't be part of the actual guest launch.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoIntroducing new address type='unassigned' for PCI hostdevs
Daniel Henrique Barboza [Tue, 17 Dec 2019 20:35:02 +0000 (17:35 -0300)] 
Introducing new address type='unassigned' for PCI hostdevs

This patch introduces a new PCI hostdev address type called
'unassigned'. This new type gives users the option to add
PCI hostdevs to the domain XML in an 'unassigned' state, meaning
that the device exists in the domain, is managed by Libvirt
like any regular PCI hostdev, but the guest does not have
access to it.

This adds extra options for managing PCI device binding
inside Libvirt, for example, making all the managed PCI hostdevs
declared in the domain XML to be detached from the host and bind
to the chosen driver and, at the same time, allowing just a
subset of these devices to be usable by the guest.

Next patch will use this new address type in the QEMU driver to
avoid adding unassigned devices to the QEMU launch command line.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move validation of vmcoreinfo to qemu_domain.c
Daniel Henrique Barboza [Wed, 18 Dec 2019 00:36:03 +0000 (21:36 -0300)] 
qemu: command: move validation of vmcoreinfo to qemu_domain.c

Move the validation of vmcoreinfo from qemuBuildVMCoreInfoCommandLine()
to qemuDomainDefValidateFeatures(), allowing for validation
at domain define time.

qemuxml2xmltest.c was changed to account for this caps being
now validated at this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildSmartcardCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Wed, 18 Dec 2019 00:36:02 +0000 (21:36 -0300)] 
qemu: command: move qemuBuildSmartcardCommandLine validation to qemu_domain.c

Move smartcard validation being done by qemuBuildSmartcardCommandLine()
to the existing qemuDomainSmartcardDefValidate() function. This
function is called by qemuDomainDeviceDefValidate(), allowing smartcard
validation in domain define time.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildGraphicsEGLHeadlessCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Wed, 18 Dec 2019 00:36:01 +0000 (21:36 -0300)] 
qemu: command: move qemuBuildGraphicsEGLHeadlessCommandLine validation to qemu_domain.c

Move EGL Headless validation from qemuBuildGraphicsEGLHeadlessCommandLine()
to qemuDomainDeviceDefValidateGraphics(). This function is called by
qemuDomainDefValidate(), validating the graphics parameters in domain
define time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move NVDIMM validation to qemu_domain.c
Daniel Henrique Barboza [Wed, 18 Dec 2019 00:36:00 +0000 (21:36 -0300)] 
qemu: command: move NVDIMM validation to qemu_domain.c

Move the NVDIMM validation from qemuBuildMachineCommandLine()
to a new function in qemu_domain.c, qemuDomainDeviceDefValidateMemory(),
which is called by qemuDomainDeviceDefValidate(). This allows
NVDIMM validation to occur in domain define time.

It also increments memory hotplug validation, which can be seen
by the failures in the hotplug tests in qemuxml2xmltest.c that
needed to be adjusted after the move.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoutil: Rewrite virGetUserRuntimeDirectory() using g_get_user_runtime_dir()
Fabiano Fidêncio [Tue, 17 Dec 2019 15:42:09 +0000 (16:42 +0100)] 
util: Rewrite virGetUserRuntimeDirectory() using g_get_user_runtime_dir()

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoutil: Rewrite virGetUserCacheDirectory() using g_get_user_cache_dir()
Fabiano Fidêncio [Tue, 17 Dec 2019 15:34:28 +0000 (16:34 +0100)] 
util: Rewrite virGetUserCacheDirectory() using g_get_user_cache_dir()

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoutil: Rewrite virGetUserConfigDirectory() using g_get_user_config_dir()
Fabiano Fidêncio [Tue, 17 Dec 2019 15:31:11 +0000 (16:31 +0100)] 
util: Rewrite virGetUserConfigDirectory() using g_get_user_config_dir()

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoutil: Rewrite virGetUserDirectory() using g_get_home_dir()
Fabiano Fidêncio [Tue, 17 Dec 2019 15:24:38 +0000 (16:24 +0100)] 
util: Rewrite virGetUserDirectory() using g_get_home_dir()

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: fix populating of fake NUMA in multi-node hosts
Daniel P. Berrangé [Wed, 18 Dec 2019 11:31:53 +0000 (06:31 -0500)] 
conf: fix populating of fake NUMA in multi-node hosts

If the host OS doesn't have NUMA present, we fallback to
populating fake NUMA info and the code thus assumes only a
single NUMA node.

Unfortunately we also fallback to fake NUMA if numactl-devel
was not present, and in this case we can still have multiple
NUMA nodes. In this case we create all CPUs, but only the
CPUs in the first node have any data filled in, resulting in
capabilities like:

    <topology>
      <cells num='1'>
        <cell id='0'>
          <memory unit='KiB'>15977572</memory>
          <cpus num='48'>
            <cpu id='0' socket_id='0' core_id='0' siblings='0'/>
            <cpu id='1' socket_id='0' core_id='0' siblings='1'/>
            <cpu id='2' socket_id='0' core_id='1' siblings='2'/>
            <cpu id='3' socket_id='0' core_id='1' siblings='3'/>
            <cpu id='4' socket_id='0' core_id='2' siblings='4'/>
            <cpu id='5' socket_id='0' core_id='2' siblings='5'/>
            <cpu id='6' socket_id='0' core_id='3' siblings='6'/>
            <cpu id='7' socket_id='0' core_id='3' siblings='7'/>
            <cpu id='8' socket_id='0' core_id='4' siblings='8'/>
            <cpu id='9' socket_id='0' core_id='4' siblings='9'/>
            <cpu id='10' socket_id='0' core_id='5' siblings='10'/>
            <cpu id='11' socket_id='0' core_id='5' siblings='11'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
            <cpu id='0'/>
          </cpus>
        </cell>
      </cells>
    </topology>

With this new code we get something slightly less broken

    <topology>
      <cells num='4'>
        <cell id='0'>
          <memory unit='KiB'>15977572</memory>
          <cpus num='12'>
            <cpu id='0' socket_id='0' core_id='0' siblings='0-1'/>
            <cpu id='1' socket_id='0' core_id='0' siblings='0-1'/>
            <cpu id='2' socket_id='0' core_id='1' siblings='2-3'/>
            <cpu id='3' socket_id='0' core_id='1' siblings='2-3'/>
            <cpu id='4' socket_id='0' core_id='2' siblings='4-5'/>
            <cpu id='5' socket_id='0' core_id='2' siblings='4-5'/>
            <cpu id='6' socket_id='0' core_id='3' siblings='6-7'/>
            <cpu id='7' socket_id='0' core_id='3' siblings='6-7'/>
            <cpu id='8' socket_id='0' core_id='4' siblings='8-9'/>
            <cpu id='9' socket_id='0' core_id='4' siblings='8-9'/>
            <cpu id='10' socket_id='0' core_id='5' siblings='10-11'/>
            <cpu id='11' socket_id='0' core_id='5' siblings='10-11'/>
          </cpus>
        </cell>
        <cell id='0'>
          <memory unit='KiB'>15977572</memory>
          <cpus num='12'>
            <cpu id='12' socket_id='0' core_id='0' siblings='12-13'/>
            <cpu id='13' socket_id='0' core_id='0' siblings='12-13'/>
            <cpu id='14' socket_id='0' core_id='1' siblings='14-15'/>
            <cpu id='15' socket_id='0' core_id='1' siblings='14-15'/>
            <cpu id='16' socket_id='0' core_id='2' siblings='16-17'/>
            <cpu id='17' socket_id='0' core_id='2' siblings='16-17'/>
            <cpu id='18' socket_id='0' core_id='3' siblings='18-19'/>
            <cpu id='19' socket_id='0' core_id='3' siblings='18-19'/>
            <cpu id='20' socket_id='0' core_id='4' siblings='20-21'/>
            <cpu id='21' socket_id='0' core_id='4' siblings='20-21'/>
            <cpu id='22' socket_id='0' core_id='5' siblings='22-23'/>
            <cpu id='23' socket_id='0' core_id='5' siblings='22-23'/>
          </cpus>
        </cell>
      </cells>
    </topology>

The topology at least now reflects what 'virsh nodeinfo' reports.
The main bug is that the CPU "id" values won't match what the Linux
host actually uses.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: avoid mem leak re-allocating fake NUMA capabilities
Daniel P. Berrangé [Tue, 17 Dec 2019 16:29:03 +0000 (11:29 -0500)] 
conf: avoid mem leak re-allocating fake NUMA capabilities

The 'caps' object is already allocated when the fake NUMA
initialization takes place.

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu_command: tidy up qemuBuildHostdevCommandLine loop
Daniel Henrique Barboza [Wed, 18 Dec 2019 09:28:39 +0000 (06:28 -0300)] 
qemu_command: tidy up qemuBuildHostdevCommandLine loop

The current 'for' loop with 5 consecutive 'ifs' inside
qemuBuildHostdevCommandLine can be a bit smarter:

- all 5 'ifs' fails if hostdev->mode is not equal to
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS. This check can be moved to the
start of the loop, failing to the next element immediately
in case it fails;

- all 5 'ifs' checks for a specific subsys->type to build the proper
command line argument (virHostdevIsSCSIDevice and virHostdevIsMdevDevice
do that but within a helper). Problem is that the code will keep
checking for matches even if one was already found, and there is
no way a hostdev will fit more than one 'if' (i.e. a hostdev can't
have 2+ different types). This means that a SUBSYS_TYPE_USB will
create its command line argument in the first 'if', then all other
conditionals will surely fail but will end up being checked anyway.

All of this can be avoided by moving the hostdev->mode comparing
to the start of the loop and using a switch statement with
subsys->type to execute the proper code for a given hostdev
type.

Suggested-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoevent: add API for requiring an event loop impl to be registered
Daniel P. Berrangé [Thu, 23 May 2019 10:51:48 +0000 (11:51 +0100)] 
event: add API for requiring an event loop impl to be registered

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoaccess: report an error if no access manager is present
Daniel P. Berrangé [Fri, 17 May 2019 11:28:27 +0000 (12:28 +0100)] 
access: report an error if no access manager is present

The code calling this method expects it to have reported an error on
failure.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Don't leak hostcpu or hostnuma on driver cleanup
Michal Privoznik [Tue, 17 Dec 2019 18:34:41 +0000 (19:34 +0100)] 
qemu: Don't leak hostcpu or hostnuma on driver cleanup

When freeing qemu driver struct members, we forgot to free
@hostcpu and @hostnuma members.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: Reorder cleanup in qemuStateCleanup()
Michal Privoznik [Wed, 18 Dec 2019 05:39:09 +0000 (06:39 +0100)] 
qemu: Reorder cleanup in qemuStateCleanup()

This function is supposed to clean up virQEMUDriver structure and
free individual members. However, it's doing that in random order
which makes it hard to track which members are being freed and
which are not. Do the free in reverse order than the structure
definition - assuming that the most important members (like
mutex) are declared first and freed last.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirCapabilitiesHostNUMAUnref: Accept NULL
Michal Privoznik [Wed, 18 Dec 2019 06:40:17 +0000 (07:40 +0100)] 
virCapabilitiesHostNUMAUnref: Accept NULL

Fortunately, this is not causing any problems now because glib
does this check for us when calling this function via attribute
cleanup. But in a future commit we will explicitly call this
function over a struct member that might be NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agotestutilsxen: Avoid double free of driver caps
Michal Privoznik [Wed, 11 Dec 2019 09:17:30 +0000 (10:17 +0100)] 
testutilsxen: Avoid double free of driver caps

In testXLInitDriver() a dummy driver structure is filled and it
is freed later in testXLFreeDriver(). However, it is sufficient
to unref just driver->config because that results in
libxlDriverConfigDispose() being called which unrefs
driver->config->caps. There is no need to unref it again in
testXLFreeDriver() - in fact it's undesired.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agodomaincapstest: Don't leak cpu definitions
Michal Privoznik [Wed, 11 Dec 2019 09:13:15 +0000 (10:13 +0100)] 
domaincapstest: Don't leak cpu definitions

When generating domain capabilities, we need to fake host CPU to
get reproducible result. We do this by copying a pre-existent CPU
config and setting VIR_TEST_MOCK_FAKE_HOST_CPU env variable which
is then consumed by qemucpumock. However, we forget to free the
CPU copy afterwards.

 2,196 (2,016 direct, 180 indirect) bytes in 18 blocks are definitely lost in loss record 291 of 297
    at 0x4838B86: calloc (vg_replace_malloc.c:762)
    by 0x57CB6A0: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6000.7)
    by 0x4A0F72D: virCPUDefNew (cpu_conf.c:87)
    by 0x4A0FAC7: virCPUDefCopyWithoutModel (cpu_conf.c:235)
    by 0x4A0FBBE: virCPUDefCopy (cpu_conf.c:273)
    by 0x10E3C0: testUtilsHostCpusGetDefForArch (testutilshostcpus.h:157)
    by 0x10E3C0: fakeHostCPU (domaincapstest.c:61)
    by 0x10E3C0: fillQemuCaps (domaincapstest.c:86)
    by 0x10E3C0: test_virDomainCapsFormat (domaincapstest.c:234)
    by 0x10F4BC: virTestRun (testutils.c:146)
    by 0x10DE93: doTestQemuInternal (domaincapstest.c:301)
    by 0x10E13D: doTestQemu (domaincapstest.c:332)
    by 0x1124CF: testQemuCapsIterate (testutilsqemu.c:635)
    by 0x10DCE3: mymain (domaincapstest.c:435)
    by 0x10FD8B: virTestMain (testutils.c:916)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agosrc: warn against virNodeGetInfo() API call due to inaccurate info
Daniel P. Berrangé [Mon, 16 Dec 2019 10:35:50 +0000 (10:35 +0000)] 
src: warn against virNodeGetInfo() API call due to inaccurate info

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotest: qemucaps: Refresh x86_64 caps probe data for the qemu-4.2 release
Peter Krempa [Wed, 18 Dec 2019 08:48:00 +0000 (09:48 +0100)] 
test: qemucaps: Refresh x86_64 caps probe data for the qemu-4.2 release

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
5 years agokbase: Add document outlining backing chain XML config and troubleshooting
Peter Krempa [Tue, 17 Dec 2019 17:50:18 +0000 (18:50 +0100)] 
kbase: Add document outlining backing chain XML config and troubleshooting

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: storage: Don't treat files with missing backing store format as 'raw'
Peter Krempa [Tue, 17 Dec 2019 16:04:04 +0000 (17:04 +0100)] 
util: storage: Don't treat files with missing backing store format as 'raw'

Assuming that the backing image format is raw is wrong when doing image
detection:

1) In -drive mode qemu will still probe the image format of the backing
   image. This means it will try to open a backing file of the image
   which will fail if a more advanced security model is in use.

2) In blockdev mode the image will be opened as raw actually which is
   wrong since it might be qcow. Not opening the backing images will
   also end up in the guest seeing corrupted data.

Rather than attempt to solve various corner cases when us assuming the
storage file being raw and actually being right forbid startup when the
guest image doesn't have the format specified in the metadata.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: storage: Remove unused test modes
Peter Krempa [Tue, 17 Dec 2019 16:49:36 +0000 (17:49 +0100)] 
tests: storage: Remove unused test modes

EXP_WARN and ALLOW_PROBE flags for the testStorageChain cases are no
longer used so we can remove them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: storage: Use strict version of virStorageFileGetMetadata
Peter Krempa [Tue, 17 Dec 2019 16:46:18 +0000 (17:46 +0100)] 
tests: storage: Use strict version of virStorageFileGetMetadata

Pass in 'true' as '@report_broken' of virStorageFileGetMetadata to make
it fail in the tests. The most important code paths (when starting the
VM) expect this function to fail rather than silently return partial
data. Switch the test to exercise this more important code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: homogenize MAC address in live & config when hotplugging a netdev
Laine Stump [Tue, 17 Dec 2019 15:24:00 +0000 (10:24 -0500)] 
qemu: homogenize MAC address in live & config when hotplugging a netdev

Prior to commit 55ce6564634 (first in libvirt 4.6.0), the XML sent to
virDomainAttachDeviceFlags() was parsed only once, and the results of
that parse were inserted into both the live object of the running
domain and into the persistent config. Thus, if MAC address was
omitted from in XML for a network device (<interface>), both the live
and config object would have the same MAC address.

Commit 55ce6564634 changed the code to parse the incoming XML twice -
once for live and once for config. This does eliminate the problem of
PCI (/scsi/sata) address conflicts caused by allocating an address
based on existing devices in live object, but then inserting the
result into the config (which may already have a device using that
address), BUT it also means that when the MAC address of a network
device hasn't been specified in the XML, each copy will get a
different auto-generated MAC address.

This results in the MAC address of the device changing the next time
the domain is shutdown and restarted, which creates havoc with the
guest OS's network config.

There have been several discussions about this in the last > 1 year,
attempting to find the ideal solution to this problem that makes MAC
addresses consistent and accounts for all sorts of corner cases with
PCI/scsi/sata addresses. All of these discussions fizzled out because
every proposal was either too difficult to implement or failed to fix
some esoteric case someone thought up.

So, in the interest of solving the MAC address problem while not
making the "other address" situation any worse than before, this patch
simply adds a qemuDomainAttachDeviceLiveAndConfigHomogenize() function
that (for now) copies the MAC address from the config object to the
live object (if the original xml had <mac address='blah'/> then this
will be an effective NOP (as the macs already match)).

Any downstream libvirt containing upstream commit
55ce6564634 should have this patch as well.

https://bugzilla.redhat.com/1783411

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoget_nonnull_domain: Drop useless comment
Michal Privoznik [Tue, 3 Dec 2019 17:11:32 +0000 (18:11 +0100)] 
get_nonnull_domain: Drop useless comment

The intent of get_nonnull_domain() is not to validate virDomain
as sent by the client but just to construct the virDomain
structure. The validation is then done in each API when looking
up the domain in our internal hash tables.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agolxc: Cleanup virConnectPtr usage
Michal Privoznik [Wed, 4 Dec 2019 08:08:17 +0000 (09:08 +0100)] 
lxc: Cleanup virConnectPtr usage

There are some functions which pass virConnectPtr around for one
reason and one reason only: to obtain virLXCDriverPtr in the end.
Might replace the argument and pass a pointer to the driver right
from the start.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agolibxlGetDHCPInterfaces: Switch to GLib
Michal Privoznik [Wed, 4 Dec 2019 09:26:58 +0000 (10:26 +0100)] 
libxlGetDHCPInterfaces: Switch to GLib

If we use glib alloc functions, we can drop the 'cleanup' label
and @rv variable and also simplify the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agolibxlGetDHCPInterfaces: Move some variables inside the loop
Michal Privoznik [Wed, 4 Dec 2019 09:22:13 +0000 (10:22 +0100)] 
libxlGetDHCPInterfaces: Move some variables inside the loop

Some variables are not used outside of the for() loop. Move their
declaration to clean up the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agolibxl: Don't use dom->conn to lookup virNetwork
Michal Privoznik [Wed, 4 Dec 2019 09:18:22 +0000 (10:18 +0100)] 
libxl: Don't use dom->conn to lookup virNetwork

When using the monolithic daemon, then dom->conn has all driver
tables filled in properly and thus it's safe to call an API other
than virDomain*(). However, when using split daemons then
dom->conn has only hypervisor driver table set
(dom->conn->driver) and the rest is NULL. Therefore, if we want
to call a non-domain API (virNetworkLookupByName() in this case),
we have obtain the cached connection object accessible via
virGetConnectNetwork().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuGetDHCPInterfaces: Switch to GLib
Michal Privoznik [Tue, 3 Dec 2019 17:01:31 +0000 (18:01 +0100)] 
qemuGetDHCPInterfaces: Switch to GLib

If we use glib alloc functions, we can drop the 'cleanup' label
and @rv variable and also simplify the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuGetDHCPInterfaces: Move some variables inside the loop
Michal Privoznik [Wed, 4 Dec 2019 08:55:52 +0000 (09:55 +0100)] 
qemuGetDHCPInterfaces: Move some variables inside the loop

Some variables are not used outside of the for() loop. Move their
declaration to clean up the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Don't use dom->conn to lookup virNetwork
Michal Privoznik [Wed, 4 Dec 2019 08:16:50 +0000 (09:16 +0100)] 
qemu: Don't use dom->conn to lookup virNetwork

When using the monolithic daemon, then dom->conn has all driver
tables filled in properly and thus it's safe to call an API other
than virDomain*(). However, when using split daemons then
dom->conn has only hypervisor driver table set
(dom->conn->driver) and the rest is NULL. Therefore, if we want
to call a non-domain API (virNetworkLookupByName() in this case),
we have obtain the cached connection object accessible via
virGetConnectNetwork().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_driver: Push qemuDomainInterfaceAddresses() a few lines down
Michal Privoznik [Tue, 3 Dec 2019 16:38:26 +0000 (17:38 +0100)] 
qemu_driver: Push qemuDomainInterfaceAddresses() a few lines down

If we place qemuDomainInterfaceAddresses() a few lines below the
two functions its using then we can drop forward declarations of
those functions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()
Pavel Mores [Fri, 6 Dec 2019 09:11:28 +0000 (10:11 +0100)] 
qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()

While at bugfixing, convert the whole function to the new-style memory
allocation handling.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
5 years agobuild: relax the relaxed stack frame limit further
Ján Tomko [Sat, 14 Dec 2019 21:26:26 +0000 (22:26 +0100)] 
build: relax the relaxed stack frame limit further

Pick 256k as the limit.

While -Wno-frame-larger-than would make more sense for usage
in our test suite, the -Wno version seems to have no effect
if -Wframe-larger-than was already specified.

Use an (un)reasonably large value instead.

Fixes the build with clang:
../../tests/cputest.c:964:1: error: stack frame size of 33176 bytes
in function 'mymain' [-Werror,-Wframe-larger-than=]
mymain(void)
^
1 error generated.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agobuild: warn on a large frame by default
Ján Tomko [Sat, 14 Dec 2019 21:10:15 +0000 (22:10 +0100)] 
build: warn on a large frame by default

My commit e73889b6311f5b43d859caa4bae84bfdb299967a
split the -Wframe-larger-than warning setting into
two different variables - STRICT_FRAME_LIMIT_CFLAGS
for the library code and RELAXED_FRAME_LIMIT_CFLAGS
which was needed for tests.

Use the strict limit by default and specify the warning
flag twice for the parts that require a larger stack
frame, relying on the fact that the compiler will pick
up the latter value.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirsh: Introduce nvme disk to domblklist
Michal Privoznik [Fri, 20 Sep 2019 13:23:56 +0000 (15:23 +0200)] 
virsh: Introduce nvme disk to domblklist

This is slightly more complicated because NVMe disk source is not
a simple attribute to <source/> element. The format in which the
PCI address and namespace ID are printed is the same as QEMU
accepts them:

  nvme://XXXX:XX:XX.X/X

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_hotplug: Prepare NVMe disks on hotplug
Michal Privoznik [Tue, 9 Jul 2019 15:39:33 +0000 (17:39 +0200)] 
qemu_hotplug: Prepare NVMe disks on hotplug

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Allow forcing VFIO when computing memlock limit
Michal Privoznik [Thu, 26 Sep 2019 11:15:47 +0000 (13:15 +0200)] 
qemu: Allow forcing VFIO when computing memlock limit

With NVMe disks, one can start a blockjob with a NVMe disk
that is not visible in domain XML (at least right away). Usually,
it's fairly easy to override this limitation of
qemuDomainGetMemLockLimitBytes() - for instance for hostdevs we
temporarily add the device to domain def, let the function
calculate the limit and then remove the device. But it's not so
easy with virStorageSourcePtr - in some cases they don't
necessarily are attached to a disk. And even if they are it's
done later in the process and frankly, I find it too complicated
to be able to use the simple trick we use with hostdevs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Don't leak storage perms on failure in qemuDomainAttachDiskGeneric
Michal Privoznik [Fri, 28 Jun 2019 06:17:45 +0000 (08:17 +0200)] 
qemu: Don't leak storage perms on failure in qemuDomainAttachDiskGeneric

At the very beginning of the attach function the
qemuDomainStorageSourceChainAccessAllow() is called which
modifies CGroups, locks and seclabels for new disk and its
backing chain. This must be followed by a counterpart which
reverts back all the changes if something goes wrong. This boils
down to calling qemuDomainStorageSourceChainAccessRevoke() which
is done under 'error' label. But not all failure branches jump
there. They just jump onto 'cleanup' label where no revoke is
done. Such mistake is easy to do because 'cleanup' label does
exist. Therefore, dissolve 'error' block in 'cleanup' and have
everything jump onto 'cleanup' label.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_monitor_text: Catch IOMMU/VFIO related errors in qemuMonitorTextAddDrive
Michal Privoznik [Thu, 26 Sep 2019 06:25:50 +0000 (08:25 +0200)] 
qemu_monitor_text: Catch IOMMU/VFIO related errors in qemuMonitorTextAddDrive

Because this is a HMP we're dealing with, there is nothing like
class of reply message, so we have to do some string comparison
to guess if the command fails. Well, with NVMe disks whole new
class of errors comes to play because qemu needs to initialize
IOMMU and VFIO for them. You can see all the messages it may
produce in qemu_vfio_init_pci().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Generate command line of NVMe disks
Michal Privoznik [Fri, 21 Jun 2019 13:07:22 +0000 (15:07 +0200)] 
qemu: Generate command line of NVMe disks

Now, that we have everything prepared, we can generate command
line for NVMe disks.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_capabilities: Introduce QEMU_CAPS_DRIVE_NVME
Michal Privoznik [Wed, 5 Jun 2019 14:11:03 +0000 (16:11 +0200)] 
qemu_capabilities: Introduce QEMU_CAPS_DRIVE_NVME

This capability tracks if qemu is capable of:

  -drive file.driver=nvme

The feature was added in QEMU's commit of v2.12.0-rc0~104^2~2.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirSecuritySELinuxRestoreImageLabelInt: Don't skip non-local storage
Michal Privoznik [Thu, 27 Jun 2019 09:17:52 +0000 (11:17 +0200)] 
virSecuritySELinuxRestoreImageLabelInt: Don't skip non-local storage

This function is currently not called for any type of storage
source that is not considered 'local' (as defined by
virStorageSourceIsLocalStorage()). Well, NVMe disks are not
'local' from that point of view and therefore we will need to
call this function more frequently.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Allow NVMe disk in CGroups
Michal Privoznik [Mon, 24 Jun 2019 10:34:45 +0000 (12:34 +0200)] 
qemu: Allow NVMe disk in CGroups

If a domain has an NVMe disk configured, then we need to allow it
on devices CGroup so that qemu can access it. There is one caveat
though - if an NVMe disk is read only we need CGroup to allow
write too. This is because when opening the device, qemu does
couple of ioctl()-s which are considered as write.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Mark NVMe disks as 'need VFIO'
Michal Privoznik [Wed, 18 Sep 2019 09:36:18 +0000 (11:36 +0200)] 
qemu: Mark NVMe disks as 'need VFIO'

There are couple of places where a domain with a VFIO device gets
special treatment: in CGroups when enabling/disabling access to
/dev/vfio/vfio, and when creating/removing nodes in domain mount
namespace. Well, a NVMe disk is a VFIO device too. Fortunately,
we have this qemuDomainNeedsVFIO() function which is the only
place that needs adjustment.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Create NVMe disk in domain namespace
Michal Privoznik [Fri, 21 Jun 2019 13:28:24 +0000 (15:28 +0200)] 
qemu: Create NVMe disk in domain namespace

If a domain has an NVMe disk configured, then we need to create
/dev/vfio/* paths in domain's namespace so that qemu can open
them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Take NVMe disks into account when calculating memlock limit
Michal Privoznik [Tue, 25 Jun 2019 13:36:44 +0000 (15:36 +0200)] 
qemu: Take NVMe disks into account when calculating memlock limit

We have this beautiful function that does crystal ball
divination. The function is named
qemuDomainGetMemLockLimitBytes() and it calculates the upper
limit of how much locked memory is given guest going to need. The
function bases its guess on devices defined for a domain. For
instance, if there is a VFIO hostdev defined then it adds 1GiB to
the guessed maximum. Since NVMe disks are pretty much VFIO
hostdevs (but not quite), we have to do the same sorcery.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: prepare NVMe devices too
Michal Privoznik [Thu, 6 Jun 2019 09:58:42 +0000 (11:58 +0200)] 
qemu: prepare NVMe devices too

The qemu driver has its own wrappers around virHostdev module (so
that some arguments are filled in automatically). Extend these to
include NVMe devices too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirhostdevtest: Test virNVMeDevice assignment
Michal Privoznik [Thu, 13 Jun 2019 07:41:15 +0000 (09:41 +0200)] 
virhostdevtest: Test virNVMeDevice assignment

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirpcimock: Introduce NVMe driver and devices
Michal Privoznik [Fri, 14 Jun 2019 12:32:10 +0000 (14:32 +0200)] 
virpcimock: Introduce NVMe driver and devices

The device configs (which are actually the same one config)
come from a NVMe disk of mine.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirhostdev: Include virNVMeDevice module
Michal Privoznik [Thu, 6 Jun 2019 09:58:12 +0000 (11:58 +0200)] 
virhostdev: Include virNVMeDevice module

Now that we have virNVMeDevice module (introduced in previous
commit), let's use it int virHostdev to track which NVMe devices
are free to be used by a domain and which are taken.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoutil: Introduce virNVMeDevice module
Michal Privoznik [Thu, 6 Jun 2019 09:57:23 +0000 (11:57 +0200)] 
util: Introduce virNVMeDevice module

This module will be used by virHostdevManager and it's inspired
by virPCIDevice module. They are very similar except instead of
what makes a NVMe device: PCI address AND namespace ID. This
means that a NVMe device can appear in a domain multiple times,
each time with a different namespace.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agodomain_conf: Introduce virDomainDefHasNVMeDisk
Michal Privoznik [Fri, 21 Jun 2019 16:00:01 +0000 (18:00 +0200)] 
domain_conf: Introduce virDomainDefHasNVMeDisk

This function will return true if any of disks (or their backing
chain) for given domain contains an NVMe disk.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirstoragefile: Introduce virStorageSourceChainHasNVMe
Michal Privoznik [Fri, 21 Jun 2019 15:59:29 +0000 (17:59 +0200)] 
virstoragefile: Introduce virStorageSourceChainHasNVMe

This function will return true if there's a storage source of
type VIR_STORAGE_TYPE_NVME, or false otherwise.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: Format and parse NVMe type disk
Michal Privoznik [Mon, 3 Jun 2019 15:31:13 +0000 (17:31 +0200)] 
conf: Format and parse NVMe type disk

To simplify implementation, some restrictions are added. For
instance, an NVMe disk can't go to any bus but virtio and has to
be type of 'disk' and can't have startupPolicy set.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoschemas: Introduce disk type NVMe
Michal Privoznik [Mon, 3 Jun 2019 08:46:18 +0000 (10:46 +0200)] 
schemas: Introduce disk type NVMe

There is this class of PCI devices that act like disks: NVMe.
Therefore, they are both PCI devices and disks. While we already
have <hostdev/> (and can assign a NVMe device to a domain
successfully) we don't have disk representation. There are three
problems with PCI assignment in case of a NVMe device:

1) domains with <hostdev/> can't be migrated

2) NVMe device is assigned whole, there's no way to assign only a
   namespace

3) Because hypervisors see <hostdev/> they don't put block layer
   on top of it - users don't get all the fancy features like
   snapshots

NVMe namespaces are way of splitting one continuous NVDIMM memory
into smaller ones, effectively creating smaller NVMe-s (which can
then be partitioned, LVMed, etc.)

Because of all of this the following XML was chosen to model a
NVMe device:

  <disk type='nvme' device='disk'>
    <driver name='qemu' type='raw'/>
    <source type='pci' managed='yes' namespace='1'>
      <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </source>
    <target dev='vda' bus='virtio'/>
  </disk>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuMigrationSrcIsSafe: Rework slightly
Michal Privoznik [Thu, 1 Aug 2019 08:12:49 +0000 (10:12 +0200)] 
qemuMigrationSrcIsSafe: Rework slightly

There are going to be more disk types that are considered unsafe
with respect to migration. Therefore, move the error reporting
call outside of if() body and rework if-else combo to switch().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirpci: Introduce virPCIDeviceAddressCopy
Michal Privoznik [Fri, 7 Jun 2019 14:32:37 +0000 (16:32 +0200)] 
virpci: Introduce virPCIDeviceAddressCopy

This helper is cleaner than plain memcpy() because one doesn't
have to look into virPCIDeviceAddress struct to see if it
contains any strings / pointers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirHostdevReAttachPCIDevices: Separate out function body
Michal Privoznik [Tue, 11 Jun 2019 08:24:04 +0000 (10:24 +0200)] 
virHostdevReAttachPCIDevices: Separate out function body

In near future we will have a list of PCI devices we want to
re-attach to the host (held in virPCIDeviceListPtr) but we don't
have virDomainHostdevDefPtr. That's okay because
virHostdevReAttachPCIDevices() works with virPCIDeviceListPtr
mostly anyway. And in very few places where it needs
virDomainHostdevDefPtr are not interesting for our case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirHostdevPreparePCIDevices: Separate out function body
Michal Privoznik [Fri, 7 Jun 2019 12:13:24 +0000 (14:13 +0200)] 
virHostdevPreparePCIDevices: Separate out function body

In near future we will have a list of PCI devices we want to
detach (held in virPCIDeviceListPtr) but we don't have
virDomainHostdevDefPtr. That's okay because
virHostdevPreparePCIDevices() works with virPCIDeviceListPtr
mostly anyway. And in very few places where it needs
virDomainHostdevDefPtr are not interesting for our case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev
Michal Privoznik [Thu, 19 Sep 2019 12:43:13 +0000 (14:43 +0200)] 
virpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev

Sometimes, we have a PCI address and not fully allocated
virPCIDevice and yet we still want to know its /dev/vfio/N path.
Introduce virPCIDeviceAddressGetIOMMUGroupDev() function exactly
for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Drop some 'cleanup' labels
Michal Privoznik [Tue, 17 Sep 2019 09:57:04 +0000 (11:57 +0200)] 
qemu: Drop some 'cleanup' labels

Previous patches rendered some of 'cleanup' labels needless.
Drop them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuDomainGetHostdevPath: Don't include /dev/vfio/vfio in returned paths
Michal Privoznik [Tue, 17 Sep 2019 09:47:59 +0000 (11:47 +0200)] 
qemuDomainGetHostdevPath: Don't include /dev/vfio/vfio in returned paths

Now that all callers of qemuDomainGetHostdevPath() handle
/dev/vfio/vfio on their own, we can safely drop handling in this
function. In near future the decision whether domain needs VFIO
file is going to include more device types than just
virDomainHostdev.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuDomainGetHostdevPath: Use more g_autoptr()/g_autofree
Michal Privoznik [Tue, 17 Sep 2019 09:31:24 +0000 (11:31 +0200)] 
qemuDomainGetHostdevPath: Use more g_autoptr()/g_autofree

There are several variables which could be automatically freed
upon return from the function. I'm not changing @tmpPaths (which
is a string list) because it is going to be removed in next
commit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: Explicitly add/remove /dev/vfio/vfio to/from NS/CGroups
Michal Privoznik [Tue, 17 Sep 2019 08:06:26 +0000 (10:06 +0200)] 
qemu: Explicitly add/remove /dev/vfio/vfio to/from NS/CGroups

In near future, the decision what to do with /dev/vfio/vfio with
respect to domain namespace and CGroup is going to be moved out
of qemuDomainGetHostdevPath() because there will be some other
types of devices than hostdevs that need access to VFIO.

All functions that I'm changing (except qemuSetupHostdevCgroup())
assume that hostdev we are adding/removing to VM is not in the
definition yet (because of how qemuDomainNeedsVFIO() is written).
Fortunately, this assumption is true.

For qemuSetupHostdevCgroup(), the worst thing that may happen is
that we allow /dev/vfio/vfio which was already allowed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agotests: securityselinuxlabel: Add QEMU_CAPS_VNC to fake qemuCaps
Peter Krempa [Tue, 17 Dec 2019 09:02:10 +0000 (10:02 +0100)] 
tests: securityselinuxlabel: Add QEMU_CAPS_VNC to fake qemuCaps

In commit 45270337f057f26ce484f6e forgot to make sure that tests pass.
Add the missing capability to fix the test.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: command: move sound codec validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:15 +0000 (20:15 -0300)] 
qemu: command: move sound codec validation to qemu_domain.c

qemuBuildSoundCodecStr() validates if a given QEMU binary
supports the sound codec. This validation can be moved to
qemu_domain.c to be executed in domain define time.

The codec validation was moved to the existing
qemuDomainDeviceDefValidateSound() function.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildSoundDevStr caps validation to qemu_domain
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:14 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildSoundDevStr caps validation to qemu_domain

Move QEMU caps validation of QEMU_CAPS_OBJECT_USB_AUDIO and
QEMU_CAPS_DEVICE_ICH9_INTEL_HDA to a new function in qemu_domain.c,
qemuDomainDeviceDefValidateSound(). This function is called by
qemuDomainDeviceDefValidate() to validate the sound device
in domain define time.

qemuxml2xmltest.c was adjusted to add the now required caps for
domain definition.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildTPMDevStr TPM validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:31 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildTPMDevStr TPM validation to qemu_domain.c

qemuBuildTPMDevStr() does TPM model validation that can be moved to
qemu_domain.c, allowing validation in domain define time. This patch
moves it to the existing qemuDomainDeviceDefValidateTPM() function.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildConsoleCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:30 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildConsoleCommandLine validation to qemu_domain.c

Console validation is currently being done by qemuBuildConsoleCommandLine().
This patch moves it to a new qemuDomainDefValidateConsole() function. This
new function is then called by qemuDomainDefValidate(), validating the
console in domain define time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildGraphicsSPICECommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:27 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildGraphicsSPICECommandLine validation to qemu_domain.c

Move the SPICE caps validation from qemuBuildGraphicsSPICECommandLine()
to a new function called qemuDomainDeviceDefValidateSPICEGraphics().
This function is called by qemuDomainDeviceDefValidateGraphics(),
which in turn is called by qemuDomainDefValidate(), validating the graphics
parameters in domain define time.

This validation move exposed a flaw in the 'default-video-type' tests
for PPC64, AARCH64 and s390 archs. The XML was considering 'spice' as
the default video type, which isn't true for those architectures.
This was flying under the radar until now because the SPICE validation
was being made in 'virsh start' time, while the XML validation done in
qemuxml2xmltest.c considers define time.

All other tests were adapted to consider SPICE validation in this
earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildGraphicsVNCCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:26 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildGraphicsVNCCommandLine validation to qemu_domain.c

Move the VNC cap validation from qemuBuildGraphicsVNCCommandLine()
to qemuDomainDeviceDefValidateGraphics(). This function is called by
qemuDomainDefValidate(), validating the graphics parameters in domain
define time.

Tests were adapted to consider SDL validation in this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildGraphicsSDLCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:25 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildGraphicsSDLCommandLine validation to qemu_domain.c

There are validations for SDL, VNC, SPICE and EGL_HEADLESS
around several BuildGraphics*CommandLine in qemu_command.c. This
patch starts to move all of them to qemu_domain.c, inside the
existent qemuDomainDeviceDefValidateGraphics() function. This
function is called by qemuDomainDefValidate(), validating the
graphics parameters in domain define time.

In this patch we'll move the SDL validation code from
qemuBuildGraphicsSDLCommandLine(). Tests were adapted to consider
SDL validation in this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move pcihole64 validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:24 +0000 (20:15 -0300)] 
qemu: command: move pcihole64 validation to qemu_domain.c

Move the pcihole64 validation being done by
qemuBuildGlobalControllerCommandLine() to the existing function
qemuDomainDeviceDefValidateControllerPCI(), which provides
domain define time validation.

The existing pcihole64 validations in qemu_domain.c were replaced
by the ones moved from qemu_command.c. The reason is that they
are more specific, allowing VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT
and VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT to have distinct validation,
with exclusive QEMU caps and machine types.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildBootCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:23 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildBootCommandLine validation to qemu_domain.c

Move the boot validation being done by qemuBuildBootCommandLine()
to to a new qemuDomainDefValidateBoot() function. This new function
is called by qemuDomainDefValidate(), allowing boot validation in
domain define time.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildPMCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:22 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildPMCommandLine validation to qemu_domain.c

Move the PM validation being done by qemuBuildPMCommandLine() to
to a new qemuDomainDefValidatePM() function. This new function
is called by qemuDomainDefValidate(), promoting PM validation in
domain define time.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move virDomainClockDef validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:21 +0000 (20:15 -0300)] 
qemu: command: move virDomainClockDef validation to qemu_domain.c

@def->clock validation is done by qemuBuildClockCommandLine() and
qemuBuildClockArgStr(). This patch centralize the validation done
in both these functions to a new qemuDomainDefValidateClockTimers()
function. This new function is then called by qemuDomainDefValidate(),
promoting clock validation in domain define time.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildSgaCommandLine validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:20 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildSgaCommandLine validation to qemu_domain.c

Move QEMU caps validation of qemuBuildSgaCommandLine() to
qemuDomainDefValidate(), allowing validation at domain define
time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move vmGenID validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:19 +0000 (20:15 -0300)] 
qemu: command: move vmGenID validation to qemu_domain.c

QEMU_CAPS_DEVICE_VMGENID is now being validated by
qemuDomainDefValidate().

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildHostdevCommandLine caps validation to qemu_domain
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:18 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildHostdevCommandLine caps validation to qemu_domain

Move QEMU caps validation of qemuBuildHostdevCommandLine() to
qemuDomainDeviceDefValidateHostdev() and qemuDomainMdevDefValidate(),
allowing them to be validated at domain define time.

Tests were adapted to consider the new caps being needed in
this earlier stage.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildChrChardevStr caps validation to qemu_domain
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:17 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildChrChardevStr caps validation to qemu_domain

Move QEMU caps validation of QEMU_CAPS_CHARDEV_FILE_APPEND and
QEMU_CAPS_CHARDEV_LOGFILE to qemuDomainChrSourceDefValidate().

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move qemuBuildHubDevStr caps validation to qemu_domain
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:16 +0000 (20:15 -0300)] 
qemu: command: move qemuBuildHubDevStr caps validation to qemu_domain

Move QEMU caps validation of QEMU_CAPS_USB_HUB to a new function in
qemu_domain.c, qemuDomainDeviceDefValidateHub(). This function is
called by qemuDomainDeviceDefValidate() to validate the sound device
in domain define time.

qemuxml2xmltest.c was adjusted to add the now required caps for
domain definition.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move NVRAM validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:13 +0000 (20:15 -0300)] 
qemu: command: move NVRAM validation to qemu_domain.c

A new function qemuDomainDeviceDefValidateNVRAM() was created
to validate the NVRAM in domain define time. Unit test was
adjusted to account for the extra QEMU_CAPS_DEVICE_NVRAM required
during domain define.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move NUMA validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:12 +0000 (20:15 -0300)] 
qemu: command: move NUMA validation to qemu_domain.c

A new qemuDomainDefValidateNuma() function was created to host
all the QEMU caps validation being done inside qemuBuildNumaArgStr().
This new function is called by qemuDomainValidateCpuCount()
to allow NUMA validation in domain define time.

Tests were changed to account for the QEMU capabilities
that need to be present at domain define time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agonuma_conf: add virDomainNumaNodesDistancesAreBeingSet() helper
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:11 +0000 (20:15 -0300)] 
numa_conf: add virDomainNumaNodesDistancesAreBeingSet() helper

Next patch will validate QEMU_CAPS_NUMA_DIST in a new qemu_domain.c
function. The code to verify if a NUMA node distance is being
set will still be needed in qemuBuildNumaArgStr() though.

To avoid code repetition, let's put this logic in a helper to be
used in qemuBuildNumaArgStr() and in the new function.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move I/O APIC validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:10 +0000 (20:15 -0300)] 
qemu: command: move I/O APIC validation to qemu_domain.c

Validation of MACHINE_KERNEL_IRQCHIP and MACHINE_KERNEL_IRQCHIP_SPLIT
QEMU caps are now being done in qemuDomainDefValidateFeatures().

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move validation of vmport to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:08 +0000 (20:15 -0300)] 
qemu: command: move validation of vmport to qemu_domain.c

virQEMUCapsSupportsVmport() is now being called inside
qemuDomainDefValidateFeatures() for VIR_DOMAIN_FEATURE_VMPORT
feature.

qemuxml2xmltest.c was changed to account for this caps being
now validated at domain define time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move mem.nosharepages validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:07 +0000 (20:15 -0300)] 
qemu: command: move mem.nosharepages validation to qemu_domain.c

Move QEMU_CAPS_MEM_MERGE validation from qemuBuildMachineCommandLine()
to qemuDomainDefValidateMemory().

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: command: move PSeries features validation to qemu_domain.c
Daniel Henrique Barboza [Mon, 9 Dec 2019 23:15:06 +0000 (20:15 -0300)] 
qemu: command: move PSeries features validation to qemu_domain.c

Introduce a new function called qemuDomainDefValidatePSeriesFeature()
that will center all the PSeries validation done in qemu_command.c.
qemuDomainDefValidatePSeriesFeature() is then called during domain
define time, in qemuDomainDefValidateFeatures().

qemuxml2argvtest.c is also changed to include all the caps that now
are being validated in define time.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agopo: refresh translations from zanata
Daniel P. Berrangé [Mon, 16 Dec 2019 17:09:03 +0000 (17:09 +0000)] 
po: refresh translations from zanata

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agocpu: add CLZERO CPUID support for AMD platforms
Ani Sinha [Tue, 3 Dec 2019 11:09:12 +0000 (03:09 -0800)] 
cpu: add CLZERO CPUID support for AMD platforms

Qemu commit e900135dcfb67 ("i386: Add CPUID bit for CLZERO and XSAVEERPTR")
adds support for CLZERO CPUID bit.
This commit extends support for this CPUID bit into libvirt.

Signed-off-by: Ani Sinha <ani.sinha@nutanix.com>
Message-Id: <1575371352-99055-1-git-send-email-ani.sinha@nutanix.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agotools: do not loop in libvirt-guests test_connect
Christian Ehrhardt [Mon, 16 Dec 2019 07:20:59 +0000 (08:20 +0100)] 
tools: do not loop in libvirt-guests test_connect

These days libvirt is pretty reliable and even remote connections
(not the default for libvirt-guests anyway) either work or fail but are
uncommon to be flaky.

On the other hand users might have disabled the service and while we are
After=libvirtd for ordering we are not Requiring it. Adding that or any
harder dependency might break our ordering. But if people have disabled
libvirt they will do a full retry loop until timeout.

Lets drop the loop to be much faster if a remote is not reachable.

Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1854653
This reverts

  commit 4e7fc8305a53676ba2362bfaa8ca05c4851b7e12
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Fri Feb 21 12:46:08 2014 +0100

    libvirt-guests: Wait for libvirtd to initialize

The race described in that commit no longer exists using systemd as
we now have socket activation. If not using systemd, then it is also
safe if using the libvirtd --daemon flag, since the parent process
won't return to the caller until the child is accepting connections.

Reported-by: Doug Smythies <dsmythies@telus.net>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agonews: Document init scripts
Michal Privoznik [Tue, 26 Nov 2019 13:55:15 +0000 (14:55 +0100)] 
news: Document init scripts

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconfigure: Provide OpenRC scripts for sub-daemons
Michal Privoznik [Thu, 31 Oct 2019 17:59:19 +0000 (18:59 +0100)] 
configure: Provide OpenRC scripts for sub-daemons

There is plenty of distributions that haven't switched to
systemd nor they force their users to (Gentoo, Alpine Linux to
name a few). With the daemon split merged their only option is to
still use the monolithic daemon which will go away eventually.
Provide init scripts for these distros too.

For now, I'm not introducing config files which would correspond
to the init files except for libvirtd and virtproxyd init scripts
where it might be desirable to tweak the command line of
corresponding daemons.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh.pod: Mention iscsi-direct is supported in find-storage-pool-sources
Han Han [Wed, 4 Dec 2019 09:19:05 +0000 (17:19 +0800)] 
virsh.pod: Mention iscsi-direct is supported in find-storage-pool-sources

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Han Han <hhan@redhat.com>
5 years agoremote: shrink the critical sections
Marc Hartmayer [Thu, 14 Nov 2019 17:44:24 +0000 (18:44 +0100)] 
remote: shrink the critical sections

To free the structs and save the error, it is not necessary to hold @priv->lock,
therefore move these parts after the mutex unlock.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>