Commit Graph

24037 Commits

Author SHA1 Message Date
Martin Kletzander
8563560026 tests: Use fixedcontent variable
Commit ca32929908 added function
virTestCompareToFile(), but forgot to use a fixedcontent value for the
actual comparison.  That lead to VIR_TEST_DEBUG=1 showing (for some
tests) all the actual output from the first error to the end of the
string due to the difference being an endline in the end.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-15 11:24:32 +02:00
Jason Miesionczek
ead3cfc68d hyperv: additional server 2008 wmi classes 2016-09-15 09:27:48 +02:00
Michal Privoznik
4a457adda6 tests: Self test virt-admin
Just like we are running 'virsh self-test' from within our test
suite, we should run 'virt-admin self-test' too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-14 13:18:07 +02:00
Michal Privoznik
d920090c72 virsh: Move cmdSelfTest to vsh
This command should be exposed to other shells of ours.
They are gonna need it as soon as we want to test them too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-14 13:18:07 +02:00
Peter Krempa
64bc75f756 qemu: domain: Don't infer vcpu state
Use the state information (online, hotpluggable) provided by the monitor
code rather than trying to infer it. This fixes an issue where on
architectures that require hotplug of multiple threads at once the
sub-cores would get updated as offline on daemon restart thus creating
an invalid configuration.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1375783
2016-09-14 12:56:57 +02:00
Peter Krempa
2a0e68be91 qemu: monitor: Add vcpu state information to monitor data
Return whether a vcpu entry is hotpluggable or online so that upper
layers don't have to infer the information from other data.

Advantage is that this code can be tested by unit tests.
2016-09-14 12:55:33 +02:00
Peter Krempa
66da0356cd qemu: monitor: qemuMonitorGetCPUInfoHotplug: Add iterator 'anycpu'
Add separate iterator for iterating all the entries
2016-09-14 12:55:33 +02:00
Peter Krempa
03376b6da0 qemu: monitor: Use a more obvious iterator name
The algorithm that matches data from query-cpus and
query-hotpluggable-cpus is quite complex. Start using descriptive
iterator names to avoid confusion.
2016-09-14 12:55:33 +02:00
Michal Privoznik
988218ca3f virDomainGetBlockJobInfo: Fix corner case when qemu reports no info
https://bugzilla.redhat.com/show_bug.cgi?id=1372613

Apparently, some management applications use the following code
pattern when waiting for a block job to finish:

  while (1) {
    virDomainGetBlockJobInfo(dom, disk, info, flags);

    if (info.cur == info.end)
        break;

    sleep(1);
  }

Problem with this approach is in its corner cases. In case of
QEMU, libvirt merely pass what has been reported on the monitor.
However, if the block job hasn't started yet, qemu reports cur ==
end == 0 which tricks mgmt apps into thinking job is complete.

The solution is to mangle cur/end values as described here [1].

1: https://www.redhat.com/archives/libvir-list/2016-September/msg00017.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-14 12:44:42 +02:00
Michal Privoznik
5d213b34de qemuDomainGetBlockJobInfo: Move info translation into separate func
Even though we merely just pass to users whatever qemu provided
on the monitor, we still do some translation. For instance we
turn bytes into mebibytes, or fix job type if needed. However, in
the future there is more fixing to be done so this code deserves
its own function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-14 12:44:42 +02:00
Daniel P. Berrange
e043ecc82d tests: use a fixed chardev TLS path
The test qemuxml2argv-serial-tcp-tlsx509-chardev.args
will fail if libvirt is built with a --sysconfdir
arg that is not /etc.  Fix this by setting a hardcoded
path in the test code.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-09-14 10:46:09 +01:00
Peter Krempa
77cb01bc0f numa: Rename virNumaGetHostNodeset and make it return only nodes with memory
Name it virNumaGetHostMemoryNodeset and return only NUMA nodes which
have memory installed. This is necessary as the kernel is not very happy
to set the memory cgroup setting for nodes which do not have any memory.

This would break vcpu hotplug with following message on such
configruation:

  Invalid value '0,8' for 'cpuset.mems': Invalid argument

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1375268
2016-09-14 08:41:41 +02:00
Peter Krempa
5555dc0d7f util: numa: Remove impossible error handling
The code guarantees that virBitmapSetBit won't be called with out of
range values. Just ignore the return value and remove dead error
handling.
2016-09-14 08:41:41 +02:00
Michal Privoznik
d53fa838e1 configure: Check for major() more strictly
Thing is, in f3f15cc24 I'm trying to adapt libvirt to the newest
glibc where major()/minor()/makedev() are moved from sys/types.h
to sys/sysmacros.h. However, my commit back then expect autoconf
to be fixed too as we already use AC_HEADER_MAJOR to determine
which header file the functions are in, but because the header
files just trigger a warning and not a compile error, the
autoconf macro detects the bad header file.

This is just a workaround until autoconf macro is fixed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-13 18:09:55 +02:00
Erik Skultety
419bc8cf65 tests: fix incorrect status handling by virsh-self-test
The virsh-self-test script compared the test's return code with 1 and only if
the return code matched this value then the test was marked as failed. Problem
is that SIGSEGV returns 139 (or 11 to be precise, since shell reserves the MSB
for abnormal exit signaling) which passes the check just fine and test then
appears as successful which it most certainly wasn't.
Therefore, flip the logic to compare against 0 instead and every other result
will be treated as a failed test case.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-09-13 15:19:39 +02:00
Peter Krempa
f428ff8ad4 qemu: Add missing 'p' to qemuCgrouEmulatorAllNodesRestore 2016-09-13 12:24:02 +02:00
Nikolay Shirokovskiy
34a6e84748 virsh: add --keep-nvram option to undefine command
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-09-13 09:31:50 +02:00
Nikolay Shirokovskiy
048e5c64f7 qemu: add VIR_DOMAIN_UNDEFINE_KEEP_NVRAM support
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-09-13 09:31:50 +02:00
Nikolay Shirokovskiy
bdf83c011d api: add VIR_DOMAIN_UNDEFINE_KEEP_NVRAM flag
This flags specifies to keep nvram file if it is existed for inactive
domains.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-09-13 09:31:50 +02:00
Laine Stump
b87703cf79 conf: allow hotplugging "legacy PCI" device to manually addressed PCIe slot
In a full domain config, libvirt allows overriding the normal PCI
vs. PCI Express rules when a device address is explicitly provided
(so, e.g., you can force a legacy PCI device to plug into a PCIe port,
although libvirt would never do that on its own). However, due to a
bug libvirt doesn't give this same leeway when hotplugging devices. On
top of that, current libvirt assumes that *all* devices are legacy
PCI. The result of all this is that it's impossible to hotplug a
device into a PCIe port, even if you manually add the PCI address.

This can all be traced to the function
virDomainPCIAddressEnsureAddr(), and the fact that it calls
virDomainPCIaddressReserveSlot() for manually set addresses, and that
function hardcodes the argument "fromConfig" to false (meaning "this
address was auto-assigned, so it should be subject to stricter
validation").

Since virDomainPCIAddressReserveSlot() is just a one line simple
wrapper around virDomainPCIAddressReserveAddr() (adding in a hardcoded
reserveEntireSlot = true and fromConfig = false), all that's needed to
solve the problem with no unwanted side effects is to replace that
call for virDomainPCIAddressReserveSlot() with a direct call to
virDomainPCIAddressReserveAddr(), but with reserveEntireSlot = true,
fromConfig = true. That's what this patch does.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1337490
2016-09-12 14:46:10 -04:00
Laine Stump
0276015325 qemu: fix improper initialization of cgroupControllers bitmap
virQEMUDriverConfigNew() always initializes the bitmap in its
cgroupControllers member to -1 (i.e. all 1's).

Prior to commit a9331394, if qemu.conf had a line with
"cgroup_controllers", cgroupControllers would get reset to 0 before
going through a loop setting a bit for each named cgroup controller.
commit a9331394 left out the "reset to 0" part, so cgroupControllers
would always be -1; if you didn't want a controller included, there
was no longer a way to make that happen.

This was discovered by users who were using qemu commandline
passthrough to use the "input-linux" method of directing
keyboard/mouse input to a virtual machine:

 https://www.redhat.com/archives/vfio-users/2016-April/msg00105.html

Here's the first report I found of the problem encountered after
upgrading libvirt beyond v2.0.0:

 https://www.redhat.com/archives/vfio-users/2016-August/msg00053.html

Thanks to sL1pKn07 SpinFlo <sl1pkn07@gmail.com> for bringing the
problem up in IRC, and then taking the time to do a git bisect and
find the patch that started the problem.
2016-09-12 14:40:22 -04:00
Martin Kletzander
94e2be8424 audit: Audit information about shmem devices
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1218603

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-12 19:41:43 +02:00
Daniel P. Berrange
92513bc23a qemu: avoid parameter named 'listen'
previous commit:

  commit 2c3223785c
  Author: John Ferlan <jferlan@redhat.com>
  Date:   Mon Jun 13 12:30:34 2016 -0400

    qemu: Add the ability to hotplug the TLS X.509 environment

added a parameter "bool listen" in some methods. This
unfortunately clashes with the listen() method, causing
compile failures on certain platforms (RHEL-6 for example)

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-09-12 15:49:28 +01:00
John Ferlan
2f6b750eca storage: Need to properly read the crypt offset value
Commit id 'a48c7141' altered how to determine if a volume was encrypted
by adding a peek at an offset into the file at a specific buffer location.
Unfortunately, all that was compared was the first "char" of the buffer
against the expect "int" value.

Restore the virReadBufInt32BE to get the complete field in order to
compare against the expected value from the qcow2EncryptionInfo or
qcow1EncryptionInfo "modeValue" field.

This restores the capability to create a volume with encryption, then
refresh the pool, and still find the encryption for the volume.
2016-09-12 10:05:21 -04:00
John Ferlan
b68487c917 storage: Need to refresh secret for luks volume after volume refresh
A LUKS volume uses the volume secret type just like the QCOW2 secret, so
adjust the loading of the default secrets to handle any volume that the
virStorageFileGetMetadataFromBuf code has deemed to be an encrypted volume
to search for the volume's secret. This lookup is done by volume usage
where the usage is expected to be the path to volume.
2016-09-12 10:05:21 -04:00
Nikolay Shirokovskiy
b6daacf6ce log: Fix reporting OOM error incorrectly when defining a logging filter
When a new filter is being defined, the return code is not handled properly,
thus triggering OOM error reporting routine (bug introduced by 51b2606f).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-09-12 15:59:35 +02:00
Jiri Denemark
56258a388f qemu: Don't use query-migrate on destination
When migration fails, we need to poke QEMU monitor to check for a reason
of the failure. We did this using query-migrate QMP command, which is
not supposed to return any meaningful result on the destination side.
Thus if the monitor was still functional when we detected the migration
failure, parsing the answer from query-migrate always failed with the
following error message:

    "info migration reply was missing return status"

This irrelevant message was then used as the reason for the migration
failure replacing any message we might have had.

Let's use harmless query-status for poking the monitor to make sure we
only get an error if the monitor connection is broken.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-12 15:56:10 +02:00
John Ferlan
c8b8bbc366 util: Quiet the logging if perf file doesn't exist
Commit id 'b00d7f29' shifted the opening of the /sys/devices/intel_cqm/type
file from event enable to perf event initialization. If the file did not
exist, then an error would be written to the domain log:

2016-09-06 20:51:21.677+0000: 7310: error : virFileReadAll:1360 : Failed to open file '/sys/devices/intel_cqm/type': No such file or directory

Since the error is now handled in virPerfEventEnable by checking if the
event_attr->attrType == 0 for CMT, MBML, and MBMT events - we can just
use the Quiet API in order to not log the error we're going to throw away.

Additionally, rather than using virReportSystemError, use virReportError
and VIR_ERR_ARGUMENT_UNSUPPORTED in order to signify that support isn't there
for that type of perf event - adjust the error message as well.
2016-09-12 06:53:48 -04:00
Joao Martins
69f4030aad libxl: implement virConnectBaselineCPU
Akin to previous commit but for "virsh cpu-baseline" which
computes a baseline CPU for a set of host cpu elements.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-12 12:49:03 +02:00
Joao Martins
5822b740ad libxl: implement virConnectCompareCPU
Implement support for "virsh cpu-compare" so that we can calculate
common cpu element between a pool of hosts, which had a requirement
of providing host cpu description.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-12 12:49:03 +02:00
Joao Martins
17322e5518 libxl: describe host cpu features based on hwcaps
Parse libxl_hwcap accounting for versions since Xen 4.4 - Xen 4.7.
libxl_hwcaps is a set of cpuid leaves output that is described in [0] or
[1] in Xen 4.7. This is a collection of CPUID leaves that we version
in libvirt whenever feature words are reordered or added. Thus we keep the
common ones in one struct and others for each version. Since
libxl_hwcaps doesn't appear to have a stable format across all supported
versions thus we need to keep track of changes as a compromise until it's
exported in xen libxl API. We don't fail in initializing the driver in case
parsing of hwcaps failed for that reason. In addition, change the notation
on PAE feature such that is easier to read which bit it corresponds.

[0] xen/include/asm-x86/cpufeature.h
[1] xen/include/public/arch-x86/cpufeatureset.h

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-09-12 12:49:03 +02:00
Joao Martins
3d54305e1c libxl: describe host topology in capabilities
Add support for describing cpu topology in host cpu element.  In doing
so, refactor hwcaps part to its own helper namely libxlCapsInitCPU to
handle all host cpu related operations, including topology.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-09-12 12:49:03 +02:00
Peter Krempa
85c826129b qemu: hotplug: Don't wait if cdrom tray is opened forcibly
Qemu always opens the tray if forced to. Skip the waiting step in such
case.

This also helps if qemu does not report the tray change event when
opening the cdrom forcibly (the documentation says that the event will
not be sent although qemu in fact does trigger it even if @force is
selceted).

This is a workaround for a qemu issue where qemu does not send the tray
change event in some cases (after migration with empty closed locked
drive) and thus renders the cdrom useless from libvirt's point of view.

Partially resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1368368
2016-09-12 09:54:36 +02:00
Peter Krempa
6e19cc59a6 qemu: domain: Clear startup policy for dropped removable media
When a source image is dropped when missing due to startup policy the
policy needs to be cleared since it was relevant only for the given
storage source. New sources need to update it if needed.
2016-09-12 09:54:36 +02:00
Michal Privoznik
2692304c94 qemu: Implement virtio-net rx_queue_size
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-09 16:16:59 +02:00
Michal Privoznik
06d0969655 qemu_capabilities: Introduce virtio-net-*.rx_queue_size
Just like in the previous commit, teach qemu driver to detect
whether qemu supports this configuration knob or not.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-09 16:16:59 +02:00
Michal Privoznik
c56cdf2593 conf: Add support for virtio-net.rx_queue_size
https://bugzilla.redhat.com/show_bug.cgi?id=1366989

QEMU added another virtio-net tunable [1]. It basically allows
users to set the size of RX virtio ring. But because virtio-net
uses two separate ring buffers to pass data from/to guest they
named it explicitly rx_queue_size. We should expose it in our XML
too.

1: http://lists.nongnu.org/archive/html/qemu-devel/2016-08/msg02029.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-09 16:16:59 +02:00
John Ferlan
13350a17e4 conf: Add new secret type "tls"
Add a new secret usage type known as "tls" - it will handle adding the
secret objects for various TLS objects that need to provide some sort
of passphrase in order to access the credentials.

The format is:

   <secret ephemeral='no' private='no'>
     <description>Sample TLS secret</description>
     <usage type='tls'>
       <name>mumblyfratz</name>
     </usage>
</secret>

Once defined and a passphrase set, future patches will allow the UUID
to be set in the qemu.conf file and thus used as a secret for various
TLS options such as a chardev serial TCP connection, a NBD client/server
connection, and migration.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-09-09 08:20:05 -04:00
John Ferlan
2c3223785c qemu: Add the ability to hotplug the TLS X.509 environment
If the incoming XML defined a path to a TLS X.509 certificate environment,
add the necessary 'tls-creds-x509' object to the VIR_DOMAIN_CHR_TYPE_TCP
character device.

Likewise, if the environment exists the hot unplug needs adjustment as
well.  Note that all the return ret were changed to goto cleanup since
the cfg needs to be unref'd

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-09-09 08:09:47 -04:00
John Ferlan
ce61c16450 qemu: Add support for TLS X.509 path to TCP chardev backend
When building a chardev device string for tcp, add the necessary pieces to
access provide the TLS X.509 path to qemu.  This includes generating the
'tls-creds-x509' object and then adding the 'tls-creds' parameter to the
VIR_DOMAIN_CHR_TYPE_TCP command line.

Finally add the tests for the qemu command line. This test will make use
of the "new(ish)" /etc/pki/qemu setting for a TLS certificate environment
by *not* "resetting" the chardevTLSx509certdir prior to running the test.
Also use the default "verify" option (which is "no").

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-09-09 08:09:47 -04:00
John Ferlan
3f60a9c32f conf: Introduce chartcp_tls_x509_cert_dir
Add a new TLS X.509 certificate type - "chardev". This will handle the
creation of a TLS certificate capability (and possibly repository) for
properly configured character device TCP backends.

Unlike the vnc and spice there is no "listen" or "passwd" associated. The
credentials eventually will be handled via a libvirt secret provided to
a specific backend.

Make use of the default verify option as well.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-09-09 08:09:03 -04:00
John Ferlan
c12cb5ed73 conf: Add new default TLS X.509 certificate default directory
Rather than specify perhaps multiple TLS X.509 certificate directories,
let's create a "default" directory which can then be used if the service
(e.g. for now vnc and spice) does not supply a default directory.

Since the default for vnc and spice may have existed before without being
supplied, the default check will first check if the service specific path
exists and if so, set the cfg entry to that; otherwise, the default will
be set to the (now) new defaultTLSx509certdir.

Additionally add a "default_tls_x509_verify" entry which can also be used
to force the peer verification option (for vnc it's a x509verify option).
Add/alter the macro for the option being found in the config file to accept
the default value.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-09-09 07:09:49 -04:00
Jiri Denemark
66278d4bc3 qemu: Remove stale transient def when migration fails
If a migration of a domain which is already defined on the destination
host failed early (before we tried to start QEMU), we would forget to
remove the incoming transient definition. Later on when someone starts
the domain on the destination host, we will use the stale incoming
definition and the persistent definition will just be ignored.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-08 22:25:22 +02:00
Jiri Denemark
97a87333a0 Add helper for removing transient definition
The code for replacing domain's transient definition with the persistent
one is repeated in several places and we'll need to add one more. Let's
make a nice helper for it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-08 22:25:22 +02:00
Erik Skultety
10aec4b046 virt-admin: Fix some English grammar in the manpage
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-09-08 10:59:43 +02:00
Erik Skultety
4ba03a8e8a virt-admin: Document srv-list command in virt-admin's man page
srv-list command was missing in the man page.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-09-08 10:58:39 +02:00
Christophe Fergeau
184654117e virsh: Fix *-event error string
When using
virsh net-event non-existing-net
the error message says that 'either --list or event type is required'
This is misleading as 'virsh net-event $valid-event-type' is not going
to work either. What is expected is 'virsh net-event --event
$valid-event-type'

This commit fixes the string in pool-event, nodedev-event, event, and
net-event.
2016-09-08 09:54:12 +02:00
Julio Faracco
fe94ee5db5 security: Fixing wrong label in virt-aa-helper.c.
There is an issue with a wrong label inside vah_add_path().
The compilation fails with the error:
make[3]: Entering directory '/tmp/libvirt/src'
  CC       security/virt_aa_helper-virt-aa-helper.o
security/virt-aa-helper.c: In function 'vah_add_path':
security/virt-aa-helper.c:769:9: error: label 'clean' used but not defined
         goto clean;

This patch moves 'clean' label to 'cleanup' label.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2016-09-07 18:06:31 -04:00
Rufo Dogav
b3c1bcb9fd Avoid segfault in virt-aa-helper when handling read-only filesystems
This patch fixes a segfault in virt-aa-helper caused by attempting to
modify a static string literal. It is triggered when a domain has a
<filesystem> with type='mount' configured read-only and libvirt is
using the AppArmor security driver for sVirt confinement. An "R" is
passed into the function and converted to 'r'.
2016-09-07 16:29:02 -04:00
Yanqiu Zhang
ed8ba91ef2 storage: Delete extra wrap after vol-resize error
This patch is to delete the extra wrap "\n" after failed vol-resize
error for both "Failed to change size of volume to" and "Failed to change
size of volume by". For error with wrap, there will be an extra wrap
between two errors, such as:

   (1)# virsh vol-resize --pool default --vol vol-test 5M
        error: Failed to change size of volume 'vol-test' to 5M

        error: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified

   (2)# virsh vol-resize /var/lib/libvirt/images/volds --shrink --delta 10M
        error: Failed to change size of volume 'volds' by 10M

        error: invalid argument: can't shrink capacity below existing allocation
2016-09-07 11:11:30 -04:00