Commit Graph

3834 Commits

Author SHA1 Message Date
Pavel Hrdina
13554a9e7f tests: rewrite host CPU mocking
Move all the host CPU data into a separate file and rewrite qemucpumock
to not use passed @caps.  This is preparation for following patch which
will replace virCaps argument with virArch.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-26 15:35:02 +02:00
Pavel Hrdina
478f0c5b85 tests: add virfilecachetest
Implements 3 test cases that covers how the cache is used.

We have to mock unlink() function because the caching code unlinks
files that are no longer valid and we don't want to do it in our tests.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-26 15:33:45 +02:00
Scott Garfinkle
a7bc2c8cfd Generate unique socket file
It's possible to have more than one unnamed virtio-serial unix channel.
We need to generate a unique name for each channel. Currently, we use
".../unknown.sock" for all of them. Better practice would be to specify
an explicit target path name; however, in the absence of that, we need
uniqueness in the names we generate internally.

Before the changes we'd get /var/lib/libvirt/qemu/channel/target/unknown.sock
for each instance of
    <channel type='unix'>
        <source mode='bind'/>
        <target type='virtio'/>
    </channel>

Now, we get vioser-00-00-01.sock, vioser-00-00-02.sock, etc.

Signed-off-by: Scott Garfinkle <seg@us.ibm.com>
2017-07-25 22:38:35 +02:00
Martin Kletzander
eaf2c9f891 Move machineName generation from virsystemd into domain_conf
It is more related to a domain as we might use it even when there is
no systemd and it does not use any dbus/systemd functions.  In order
not to use code from conf/ in util/ pass machineName in cgroups code
as a parameter.  That also fixes a leak of machineName in the lxc
driver and cleans up and de-duplicates some code.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-07-25 17:02:27 +02:00
Martin Kletzander
64bebb2ba4 testutils: Remove unneeded variable
virDomainXMLOptionNew() gladly accepts NULL and it is used in some
drivers.  There is no need for additional variable with no members set

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-07-24 15:49:54 +02:00
Peter Krempa
8444419f8c util: storage: fill in default ports when parsing backing chain
Similarly to when parsing XML we need to fill in default ports for the
backing chain. This was missed in commit 5bda835466
2017-07-24 10:55:43 +02:00
dann frazier
0937f1e2a4 virt-aa-helper-test: Add test for aarch32 UEFI image path
Signed-off-by: dann frazier <dann.frazier@canonical.com>
2017-07-21 14:36:54 -04:00
dann frazier
123880d333 qemu: Add AAVMF32 to the list of known UEFIs
Add a path for UEFI VMs for AArch32 VMs, based on the path Debian is using.
libvirt is the de facto canonical location for defining where distros
should place these firmware images, so let's define this path here to try
and minimize distro fragmentation.
2017-07-21 14:36:54 -04:00
Andrea Bolognani
1d0c6f59b6 conf: Rename virDomainHostdevDefAlloc() to virDomainHostdevDefNew()
All other virDomain*Def follow this naming convention for
their allocation function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 17:03:43 +02:00
Shivaprasad G Bhat
e5a0579996 qemu: Enable NUMA node tag in pci-root for PPC64
This patch addresses the same aspects on PPC the bug 1103314 addressed
on x86.

PCI expander bus creates multiple primary PCI busses, where each of these
busses can be assigned a specific NUMA affinity, which, on x86 is
advertised through ACPI on a per-bus basis.

For SPAPR, a PHB's NUMA affinities are assigned on a per-PHB basis, and
there is no mechanism for advertising NUMA affinities to a guest on a
per-bus basis. So, even if qemu-ppc manages to get some sort of multi-bus
topology working using PXB, there is no way to expose the affinities
of these busses to the guest. It can only be exposed on a per-PHB/per-domain
basis.

So patch enables NUMA node tag in pci-root controller on PPC.

The way to set the NUMA node is through the numa_node option of
spapr-pci-host-bridge device. However for the implicit PHB, the only way
to set the numa_node is from the -global option. The -global option applies
to all the PHBs unless explicitly specified with the option on the
respective PHB of CLI. The default PHB has the emulated devices only, so
the patch prevents setting the NUMA node for the default PHB.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 15:46:29 +02:00
Shivaprasad G Bhat
11b2ebf3e1 qemu: capabilitity: Introduce QEMU_CAPS_SPAPR_PCI_HOST_BRIDGE_NUMA_NODE
The patch adds a capability for spapr-pci-host-bridge.numa_node.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 15:46:29 +02:00
Shivaprasad G Bhat
eb56cc6f88 Add capabilities for qemu-2.9.0 ppc64
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 15:46:29 +02:00
Peter Krempa
95d5601018 qemu: domain: Store and restore autoCpuset to status XML
Decouple them by storing them in the XML separately rather than
regenerating them. This will simplify upcoming fixes.
2017-07-20 16:14:50 +02:00
Peter Krempa
a908e9e45e util: bitmap: Modify virBitmapSubtract to virBitmapIntersect
Since virBitmapSubtract is unused modify it to perform bitmap
intersection.
2017-07-20 16:14:50 +02:00
John Ferlan
f4258298d3 tests: Free @fakerootdir in error path
Commit id 'dd9b29dad' added this new variable, but didn't free it in
one instance where status was returned to the caller.

Found by Coverity
2017-07-20 10:08:27 -04:00
Pavel Hrdina
7fb4c471d1 qemu: separate virQEMUCapsInitCached out of virQEMUCapsNewForBinaryInternal
Preparation for switching to virFileCache where there are two callbacks,
one to get a new data and second one to load a cached data.

This also removes virQEMUCapsReset which is no longer required.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-20 14:02:53 +02:00
Pavel Hrdina
a63ef87709 qemu: move libvirt ctime and version into _virQEMUCaps struct
Cleanups the code a little bit and reduces amount of arguments passed
throughout the functions.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-20 14:02:14 +02:00
Pavel Hrdina
38e516a524 util/virhash: add name parameter to virHashSearch
While searching for an element using a function it may be
desirable to know the element key for future operation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-20 14:02:14 +02:00
Peter Krempa
99eac2668c tests: virjson: Test nesting of JSON string into a JSON (string) property
Test that we are able to create a JSON object and nest it into a string
property of a JSON object and then correctly extract and parse it back.
2017-07-19 17:59:09 +02:00
Peter Krempa
6e51642bd2 tests: virjson: Test parsing and formatting of strings with escaped chars
Make sure that JSON strings can contain characters which need to be
escaped (double quotes, backslashes, tabs, etc.).
2017-07-19 17:59:09 +02:00
Peter Krempa
0c02071b56 tests: virjson: Test formatting along with parsing of JSON objects
Format the parsed string back and compare it to the original (or
modified) string for back and forth comparison.
2017-07-19 15:24:10 +02:00
Peter Krempa
85f7620212 tests: virjson: Remove spaces from 'very-hard' parsing example
The example is rather long and upcomming patch will check whether the
string can be formatted back. As the formatted string lacks spaces and
adding the 'expect' string with spaces would be rather long, just drop
spaces from this test case.

There are other test cases which do contain spaces.
2017-07-19 15:24:10 +02:00
Peter Krempa
0a2866b42a tests: virjson: Modify logic in testJSONFromString
To allow better testing in case where the string was parsed, modify the
logic so that the regular code path is not included in a conditional
block.
2017-07-19 15:24:10 +02:00
Ján Tomko
255cd95aab test/Makefile.am: drop WARN_CFLAGS from LDFLAGS
Introduced by commit 0832c58, with the intention to link with
the stack protector library.

Another instance introduced by commit 4cbc15d which separated
commandhelper_LDADD from LDADDS.

Not needed because per commit 71b54636, automake should pass
all the CFLAGS to the linker.
2017-07-19 10:27:07 +02:00
Boris Fiuczynski
d2f6bebf5c tests: enable qemu 2.9 capabilities test for s390
Adjust qemu 2.9 s390 capabilites xml and enable qemu capabilities test.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2017-07-18 13:52:48 +02:00
Andrea Bolognani
b84b6ab502 qemu: Isolate hostdevs on pSeries guests
All the pieces are now in place, so we can finally start
using isolation groups to achieve our initial goal, which is
separating hostdevs from emulated PCI devices while keeping
hostdevs that belong to the same host IOMMU group together.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-18 09:00:13 +02:00
ZhiPeng Lu
3c3c3e3613 virpcimock: Fix memory leak in pci_driver_new
driverpath, allocated by virAsprintfQuiet, was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhipeng@zte.com.cn>
2017-07-16 17:06:45 -04:00
Andrea Bolognani
64645b78a4 qemu: Use PHBs when extending the guest PCI topology
When looking for slots suitable for a PCI device, libvirt
might need to add an extra PCI controller: for pSeries guests,
we want that extra controller to be a PHB (pci-root) rather
than a PCI bridge.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
045515d369 qemu: Use PHBs to fill holes in PCI bus numbering
PCI bus has to be numbered sequentially, and no index can be
missing, so libvirt will fill in the blanks automatically for
the user.

Up until now, it has done so using either pci-bridge, for machine
types based on legacy PCI, or pcie-root-port, for machine types
based on PCI Express. Neither choice is good for pSeries guests,
where PHBs (pci-root) should be used instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
ca1c362a30 tests: Add baseline tests for automatic PHB usage
These tests demonstrate that, while it's now possible for the
user to create PHB explicitly and manually assign devices to
them, libvirt still defaults to extending the guest PCI
topology using PCI bridges and making suboptimal device
placement choices.

The next few commits will improve on these behaviors and the
tests outputs will automatically be updated to reflect this.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
bd01ab8c1f tests: Add tests for pSeries guests with multiple PHBs
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
2e7d491696 qemu: Introduce QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE
This new capability can be used to detect whether a QEMU
binary supports the spapr-pci-host-bridge controller.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
6e42d83f7c qemu: Automatically pick target index and model for pci-root controllers
pSeries guests will soon need the new information; luckily,
we can figure it out automatically most of the time, so
users won't have to worry about it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
dd9b29dad8 tests: Mock IOMMU groups
Later on we're going to need access to information about IOMMU
groups for host devices. Implement the support in virpcimock,
and start using that mock library in a few QEMU test cases.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
19bd1b06ee tests: Update qemumemlock data
Use 0001:01:00.0 instead of 0000:04:02.0 as the source address
for the host device. This doesn't change anything at the moment,
but it will make a difference later on.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Peter Krempa
9756884d14 conf: Pre-fill default ports when parsing network disk sources
Fill them in right away rather than having to figure out at runtime
whether they are necessary or not.

virStorageSourceNetworkDefaultPort does not need to be exported any
more.
2017-07-14 16:05:46 +02:00
Daniel P. Berrange
14c5673d61 tests: add virjsondata to EXTRA_DIST
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-13 10:46:38 +01:00
Jiri Denemark
83e081b8ab cpu_x86: Properly disable unknown CPU features
CPU features unknown to a hypervisor will not be present in dataDisabled
even though the features won't naturally be enabled because.
Thus any features we asked for which are not in dataEnabled should be
considered disabled.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-13 09:53:15 +02:00
Juan Hernandez
dacd160d74 Avoid hidden cgroup mount points
Currently the scan of the /proc/mounts file used to find cgroup mount
points doesn't take into account that mount points may hidden by other
mount points. For, example in certain Kubernetes environments the
/proc/mounts contains the following lines:

  cgroup /sys/fs/cgroup/net_prio,net_cls cgroup ...
  tmpfs /sys/fs/cgroup tmpfs ...
  cgroup /sys/fs/cgroup/net_cls,net_prio cgroup ...

In this particular environment the first mount point is hidden by the
second one. The correct mount point is the third one, but libvirt will
never process it because it only checks the first mount point for each
controller (net_cls in this case). So libvirt will try to use the first
mount point, which doesn't actually exist, and the complete detection
process will fail.

To avoid that issue this patch changes the virCgroupDetectMountsFromFile
function so that when there are duplicates it takes the information from
the last line in /proc/mounts. This requires removing the previous
explicit condition to skip duplicates, and adding code to free the
memory used by the processing of duplicated lines.

Related-To: https://bugzilla.redhat.com/1468214
Related-To: https://github.com/kubevirt/libvirt/issues/4
Signed-off-by: Juan Hernandez <jhernand@redhat.com>
2017-07-13 09:37:52 +02:00
Peter Krempa
9506bd25a3 storage: Split out virStorageSource accessors to separate file
The helper methods for actually accessing the storage objects don't
really belong to the main storage driver implementation file. Split them
out.
2017-07-11 17:07:04 +02:00
Peter Krempa
2117d42c7c tests: storage: Fully register storage driver
Use the full storage driver registration method that also fails if one
of the storage backends is not present. This makes the test fail if a
submodule fails registration, which is useful for testing.

Additionally return EXIT_FAILURE as usual in tests rather than -1.
2017-07-11 17:07:04 +02:00
Ján Tomko
2277edb964 qemu: handle missing bind host/service on chardev hotplug
On domain startup, bind host or bind service can be omitted
and we will format a working command line.

Extend this to hotplug as well and specify the service to QEMU
even if the host is missing.

https://bugzilla.redhat.com/show_bug.cgi?id=1452441
2017-07-11 15:18:31 +02:00
Peter Krempa
a1ac4c880b tests: virjson: Reuse VIR_TEST_VERBOSE in testJSONCopy
Use VIR_TEST_VERBOSE instead of calling virTestGetVerbose and
conditionally fprintf. Additionally remove redundant setting of 'ret' to
-1.
2017-07-11 14:40:05 +02:00
Peter Krempa
ffdf532328 tests: Validate that JSON deflattening fixed nested json pseudo-protocol strings
Sheepdog and possibly others use nested objects for network server and
thus could be specified in a way that libvirt would not parse.

Validates that https://bugzilla.redhat.com/show_bug.cgi?id=1464821
is fixed properly.
2017-07-11 14:24:17 +02:00
Peter Krempa
428d175206 util: json: Recursively deflatten objects virJSONValueObjectDeflatten
If a value of the first level object contains more objects needing
deflattening which would be wrapped in an actual object the function
would not recurse into them.

By this simple addition we can fully deflatten the objects.
2017-07-11 14:20:05 +02:00
Peter Krempa
d40f4b3e67 util: json: Properly implement JSON deflattening
As it turns out sometimes users pass in an arbitrarily nested structure
e.g. for the qemu backing chains JSON pseudo protocol. This new
implementation deflattens now a single object fully even with nested
keys.

Additionally it's not necessary now to stick with the "file." prefix for
the properties.
2017-07-11 14:13:35 +02:00
Peter Krempa
7f1209ad1e tests: json: Add test for the deflattening function
Add a few test cases to verify that the old behaviour does not break and
that new one behaves sanely.
2017-07-11 14:12:55 +02:00
Peter Krempa
9f0b7e99c5 tests: Rename jsontest to virjsontest 2017-07-11 14:02:28 +02:00
Cédric Bosdonnat
426929aea9 lxc: add possibility to define init uid/gid
Users may want to run the init command of a container as a special
user / group. This is achieved by adding <inituser> and <initgroup>
elements. Note that the user can either provide a name or an ID to
specify the user / group to be used.

This commit also fixes a side effect of being able to run the command
as a non-root user: the user needs rights on the tty to allow shell
job control.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-11 10:41:24 +02:00
Cédric Bosdonnat
552f7c139a lxc: allow user to specify command working directory
Some containers may want the application to run in a special directory.
Add <initdir> element in the domain configuration to handle this case
and use it in the lxc driver.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-11 10:41:24 +02:00