]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agonss: refactor code for processing mac addresses
Daniel P. Berrangé [Tue, 30 Jul 2019 16:10:33 +0000 (17:10 +0100)]
nss: refactor code for processing mac addresses

Build a list of mac addresses immediately, so that later code
searching for leases can be simplified and avoid needing to
use the virMacMap object.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonss: remove use for virFile helper APIs
Daniel P. Berrangé [Tue, 30 Jul 2019 14:33:20 +0000 (15:33 +0100)]
nss: remove use for virFile helper APIs

Use the plain libc APIs to avoid a dependancy on the main libvirt
code from the nss module.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonss: remove use for virString helper APIs
Daniel P. Berrangé [Tue, 30 Jul 2019 14:33:20 +0000 (15:33 +0100)]
nss: remove use for virString helper APIs

Use the plain libc APIs to avoid a dependancy on the main libvirt
code from the nss module.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonss: remove use for virDir helper APIs
Daniel P. Berrangé [Tue, 30 Jul 2019 14:33:20 +0000 (15:33 +0100)]
nss: remove use for virDir helper APIs

Use the plain libc APIs to avoid a dependancy on the main libvirt
code from the nss module.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: get rid of virGetEnv{Allow,Block}SUID functions
Daniel P. Berrangé [Thu, 1 Aug 2019 12:35:56 +0000 (13:35 +0100)]
util: get rid of virGetEnv{Allow,Block}SUID functions

Now that 100% of libvirt code is forbidden in a SUID environment,
we no longer need to worry about whether env variables are
trustworthy or not. The virt-login-shell setuid program, which
does not link to any libvirt code, will purge all environment
variables, except $TERM, before invoking the virt-login-shell-helper
program which uses libvirt.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: simplify virCommand APIs for env passthrough.
Daniel P. Berrangé [Thu, 1 Aug 2019 12:52:00 +0000 (13:52 +0100)]
util: simplify virCommand APIs for env passthrough.

Now that 100% of libvirt code is forbidden in a SUID environment,
we no longer need to worry about whether env variables are
trustworthy or not. The virt-login-shell setuid program, which
does not link to any libvirt code, will purge all environment
variables, except $TERM, before invoking the virt-login-shell-helper
program which uses libvirt.

Thus we only need one API for env passthrough in virCommand.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: get rid of virIsSUID method
Daniel P. Berrangé [Thu, 1 Aug 2019 13:13:20 +0000 (14:13 +0100)]
util: get rid of virIsSUID method

Now that none of the libvirt.so code will ever run in a setuid
context, we can remove the virIsSUID() method. The global
initializer function can just inline the check itself. The new
inlined check is slightly stronger as it also looks for a
setgid situation.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobuild: drop libvirt setuid library build
Daniel P. Berrangé [Tue, 30 Jul 2019 12:44:37 +0000 (13:44 +0100)]
build: drop libvirt setuid library build

The virt-login-shell setuid program is now a tiny piece of code
that only uses standard libc functions, and santizes the execution
environment before invoking the real virt-login-shell-helper.
The latter is thus able to use the normal libvirt.so build,
allowing us to delete the special cut down setuid library build.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: split virt-login-shell into two binaries
Daniel P. Berrangé [Thu, 1 Aug 2019 09:58:31 +0000 (10:58 +0100)]
tools: split virt-login-shell into two binaries

The virt-login-shell binary is a setuid program that takes
no arguments. When invoked it looks at the invoking uid,
resolves it to a username, and finds an LXC guest with the
same name. It then starts the guest and runs the shell in
side the namespaces of the container.

Given this set of tasks the virt-login-shell binary needs
to connect to libvirtd, make various other libvirt API calls.
This is a problem for setuid binaries as various libraries
that libvirt.so links to are not safe. For example, they have
constructor functions which execute an unknown amount of code
that can be influenced by env variables.

For this reason virt-login-shell doesn't use libvirt.so,
but instead links to a custom, cut down, set of source files
sufficient to be a local client only.

This introduces a problem for integrating glib2 into libvirt
though, as once integrated, there would be no way to build
virt-login-shell without an external dependancy on glib2 and
this is definitely not setuid safe.

To resolve this problem, we split the virt-login-shell binary
into two parts. The first part is setuid and does almost
nothing. It simply records the original uid+gid, and then
invokes the virt-login-shell-helper binary. Crucially when
it does this it completes scrubs all environment variables.
It is thus safe for virt-login-shell-helper to link to the
normal libvirt.so. Any things that constructor functions
do cannot be influenced by user control env vars or cli
args.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: rename source for virt-login-shell
Daniel P. Berrangé [Thu, 1 Aug 2019 09:57:39 +0000 (10:57 +0100)]
tools: rename source for virt-login-shell

We'll shortly be renaming the binary to virt-login-shell-helper
and introducing a new tool as virt-login-shell. Renaming the
source file first gives a much more usefull diff for the next
commit.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: fix double error reporting in virt-login-shell
Daniel P. Berrangé [Thu, 1 Aug 2019 12:02:57 +0000 (13:02 +0100)]
tools: fix double error reporting in virt-login-shell

The public API entry points will call virDispatchError which
will print to stderr by default. We then jump to a cleanup
path which calls virDispatchError again.

We tried to stop the entry points printing to stderr, but
incorrectly called virSetErrorFunc. It needs a real function
that is a no-op, not a NULL function.

Once we fix virSetErrorFunc, then we need to use fprintf in
the cleanup path instead of virDispatchError.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: fix crash in virt-login-shell if config doesn't exist
Daniel P. Berrangé [Thu, 1 Aug 2019 11:07:47 +0000 (12:07 +0100)]
tools: fix crash in virt-login-shell if config doesn't exist

If the 'allowed_users' config setting in virt-login-shell.conf
does not exist, we dereference a NULL pointer resulting in a
crash. We should check for this case and thus ensure the user
is denied access gracefully.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Fix memory leak in mymain
John Ferlan [Wed, 7 Aug 2019 13:57:46 +0000 (09:57 -0400)]
tests: Fix memory leak in mymain

Commit d2899a648 added a new exit path, but didn't free @fakerootdir.
Let's just use VIR_AUTOFREE instead to make life easier.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Fix possible NULL deref in qemuDomainGetResctrlMonData
John Ferlan [Wed, 7 Aug 2019 13:54:06 +0000 (09:54 -0400)]
qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData

If virQEMUDriverGetCapabilities returns NULL, then a subsequent
deref of @caps would cause an error, so we just return failure.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agobuild: bump min required gcc to 4.8
Daniel P. Berrangé [Tue, 30 Jul 2019 13:07:24 +0000 (14:07 +0100)]
build: bump min required gcc to 4.8

The previous bump to 4.4 was done in:

  commit 24241c236e5e0b0b51a33ba539b40f5429a0df0e
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Jul 5 10:35:32 2017 +0100

    Require use of GCC 4.4 or CLang compilers

with 4.4 picked due to RHEL-6. Since we dropped RHEL-6, the
next oldest distro is RHEL-7 (4.8.5), and thus we pick 4.8
as the new min.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotest_driver: implement virDomainSetTime
Ilias Stamatis [Wed, 7 Aug 2019 10:22:56 +0000 (12:22 +0200)]
test_driver: implement virDomainSetTime

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: make testDomainGetTime read time from vm-private data
Ilias Stamatis [Wed, 7 Aug 2019 10:22:55 +0000 (12:22 +0200)]
test_driver: make testDomainGetTime read time from vm-private data

Until now, testDomainGetTime would always return the same fixed values
everytime it was called. By using domain-private data we can make this
API return the values previously set with testDomainSetTime, or use the
same old fixed values in case testDomainSetTime hasn't been called at all.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agosrc: security: Replace bitwise OR with logical OR
Erik Skultety [Wed, 7 Aug 2019 10:08:46 +0000 (12:08 +0200)]
src: security: Replace bitwise OR with logical OR

Typo introduced by commit d73f3f58360.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: implement virDomainReset
Ilias Stamatis [Tue, 6 Aug 2019 15:56:23 +0000 (17:56 +0200)]
test_driver: implement virDomainReset

The qemu and vz implementations don't emit any signals when this API is
called, so we can do the same here for now and succeed by doing nothing.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoqemu: Move rng model validation to domcaps
Cole Robinson [Sun, 31 Mar 2019 21:56:48 +0000 (17:56 -0400)]
qemu: Move rng model validation to domcaps

The qemu driver already does some <rng> model validation, based on
qemuCaps. However, the logic for exposing <rng> model values in domcaps
is basically identical. This drops the qemuCaps checking and compares
against the domCaps data directly.

This approach makes it basically impossible to add a new <rng> model to
the qemu driver without extending domcaps. The validation can also
be shared with other drivers eventually.

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: domain: Call virDomainCapsDeviceDefValidate
Cole Robinson [Sun, 31 Mar 2019 21:42:08 +0000 (17:42 -0400)]
qemu: domain: Call virDomainCapsDeviceDefValidate

Fill in virDomainCaps at Validate time and use it to call
virDomainCapsDeviceDefValidate

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: domcaps: Add virDomainCapsDeviceDefValidate
Cole Robinson [Thu, 4 Apr 2019 17:09:18 +0000 (13:09 -0400)]
conf: domcaps: Add virDomainCapsDeviceDefValidate

This is an entrypoint to validate a virDomainDeviceDef against
values filled into virDomainCaps.

Currently it's just a stub

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: conf: Cache domCaps in qemuCaps
Cole Robinson [Thu, 4 Apr 2019 21:06:12 +0000 (17:06 -0400)]
qemu: conf: Cache domCaps in qemuCaps

qemuCaps is tied to a binary on disk. domCaps is tied to a combo
of binary+machine+arch+virttype values. For the qemu driver this almost
entirely translates to a permutation of qemuCaps though

Upcoming patches want to use the domCaps data store at XML validate
time, but we need to cache the data so we aren't repeatedly
regenerating it.

Add a domCapsCache hash table to qemuCaps. This ensures that the domCaps
cache is blown away whenever qemuCaps needs to be regenerated. Similarly
when qemuCaps is invalidated, the next call to virQEMUCapsCacheLookup
will unref qemuCaps and free our cache as well.

Adjust virQEMUDriverGetDomainCapabilities to search the cache and add
to it if we don't find a hit.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: conf: add virQEMUDriverGetDomainCapabilities
Cole Robinson [Thu, 4 Apr 2019 21:31:00 +0000 (17:31 -0400)]
qemu: conf: add virQEMUDriverGetDomainCapabilities

For now it's just a helper for building a qemu virDomainCapsPtr,
used in qemuConnectGetDomainCapabilities

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: capabilities: fill in domcaps <rng>
Cole Robinson [Sun, 31 Mar 2019 21:19:40 +0000 (17:19 -0400)]
qemu: capabilities: fill in domcaps <rng>

The model logic is taken from qemuDomainRNGDefValidate

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: domcaps: Report device <rng>
Cole Robinson [Sun, 31 Mar 2019 21:19:33 +0000 (17:19 -0400)]
conf: domcaps: Report device <rng>

This adds device <rng> reporting. Example output:

    <rng supported='yes'>
      <enum name='model'>
        <value>virtio</value>
        <value>virtio-transitional</value>
        <value>virtio-non-transitional</value>
      </enum>
      <enum name='backendModel'>
        <value>random</value>
        <value>egd</value>
      </enum>
     </rng>

Reviewed-by: Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuDomainGetResctrlMonData: Switch to switch()
Michal Privoznik [Tue, 6 Aug 2019 11:45:42 +0000 (13:45 +0200)]
qemuDomainGetResctrlMonData: Switch to switch()

This way it is obvious when adding a new resource control type
that stats helper func needs to be updated too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainGetResctrlMonData: Dereference resctrl monitor iff not NULL
Michal Privoznik [Tue, 6 Aug 2019 11:44:17 +0000 (13:44 +0200)]
qemuDomainGetResctrlMonData: Dereference resctrl monitor iff not NULL

If the host doesn't have resctrl then the monitor is going to be
NULL and we must avoid dereferencing it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainGetResctrlMonData: Don't leak @caps
Michal Privoznik [Tue, 6 Aug 2019 11:42:55 +0000 (13:42 +0200)]
qemuDomainGetResctrlMonData: Don't leak @caps

The capabilities object must be unrefed when no longer needed.
Use VIR_AUTOUNREF() for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: change the way how Hyper-V features are printed out
Vitaly Kuznetsov [Tue, 6 Aug 2019 05:52:33 +0000 (07:52 +0200)]
conf: change the way how Hyper-V features are printed out

Current code doesn't allow us to add sub-features as we always print the
closing '/>'. As a preparatory change to implementing 'direct' sub-feature
for 'stimer' feature switch to printing closing tag individually.

No functional change.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu_x86: add Edx to KVM_FEATURE_DEF()
Vitaly Kuznetsov [Tue, 6 Aug 2019 05:52:32 +0000 (07:52 +0200)]
cpu_x86: add Edx to KVM_FEATURE_DEF()

Some Hyper-V features (like the upcoming Direct Synthetic timers) are
announced by feature bits in Edx but KVM_FEATURE_DEF() supports only Eax.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu_domain: Separate VFIO code
Michal Privoznik [Mon, 24 Jun 2019 08:01:16 +0000 (10:01 +0200)]
qemu_domain: Separate VFIO code

This piece of code will be re-used later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirhostdevtest: s/CHECK_LIST_COUNT/CHECK_PCI_LIST_COUNT/
Michal Privoznik [Fri, 14 Jun 2019 12:30:13 +0000 (14:30 +0200)]
virhostdevtest: s/CHECK_LIST_COUNT/CHECK_PCI_LIST_COUNT/

In near future we will need to check for number of members of two
different types of lists: PCI and NVMe. Rename CHECK_LIST_COUNT
to CHECK_PCI_LIST_COUNT to mark explicitly what type of list it
is working with.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirhostdevtest: Don't proceed to test cases if init failed
Michal Privoznik [Fri, 14 Jun 2019 08:39:24 +0000 (10:39 +0200)]
virhostdevtest: Don't proceed to test cases if init failed

The myInit() function is called before any of the test cases
because it prepares all internal structures for individual cases.
Well, if it fails there's no point in proceeding with testing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemuDomainDeviceDefValidateDisk: Reorder some checks
Michal Privoznik [Wed, 5 Jun 2019 11:45:35 +0000 (13:45 +0200)]
qemuDomainDeviceDefValidateDisk: Reorder some checks

I find this function more readable if checks for passed storage
source are done first and backing chain is done last. Mixing them
together does not hurt, but is less readable.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirPCIDeviceAddressAsString: Fix const correctness
Michal Privoznik [Thu, 6 Jun 2019 15:02:11 +0000 (17:02 +0200)]
virPCIDeviceAddressAsString: Fix const correctness

This function does not change any of the passed addresses. It
just reads them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirPCIDeviceAddressEqual: Fix const correctness
Michal Privoznik [Tue, 4 Jun 2019 08:43:40 +0000 (10:43 +0200)]
virPCIDeviceAddressEqual: Fix const correctness

This function does not change any of the passed addresses. It
just reads them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agotest_driver: implement virDomainFSTrim
Ilias Stamatis [Sun, 4 Aug 2019 13:27:18 +0000 (15:27 +0200)]
test_driver: implement virDomainFSTrim

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: implement virDomainFSThaw
Ilias Stamatis [Sun, 4 Aug 2019 13:27:17 +0000 (15:27 +0200)]
test_driver: implement virDomainFSThaw

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: implement virDomainFSFreeze
Ilias Stamatis [Sun, 4 Aug 2019 13:27:16 +0000 (15:27 +0200)]
test_driver: implement virDomainFSFreeze

On success update the domain-private data. Consider / and /boot to be
the only mountpoints avaiable in order to be consistent with the other
FS-related calls.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: introduce domain-private data
Ilias Stamatis [Sun, 4 Aug 2019 13:27:15 +0000 (15:27 +0200)]
test_driver: introduce domain-private data

vm-specific data can be used by APIs that need to preserve some state
between calls

Some of them are:
- FS-related APIs for remembering which mountpoints are frozen
- virDomainSetTime / virDomainGetTime for maintaining time information
- virDomainSetIOThreadParams for storing the I/O thread parameters
- virDomainManagedSaveDefineXML for internally storing the VM definition

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: implement virDomainMemoryStats
Ilias Stamatis [Fri, 2 Aug 2019 11:13:31 +0000 (13:13 +0200)]
test_driver: implement virDomainMemoryStats

The main value here is the current balloon value which taken from the
config. All the other values (except for period) are derived by 2^n
division so that compiler prefers bitwise operations. Period value was
kept fixed in order to produce predictable results in a test environment.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: add a memballoon device in the default config
Ilias Stamatis [Fri, 2 Aug 2019 11:13:30 +0000 (13:13 +0200)]
test_driver: add a memballoon device in the default config

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotest_driver: implement virDomainCreateXMLWithFile
Ilias Stamatis [Mon, 5 Aug 2019 09:02:23 +0000 (11:02 +0200)]
test_driver: implement virDomainCreateXMLWithFile

This should just forward the call to testDomainCreateXML since we
can't do anything with the provided file descriptors in the test driver.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
5 years agotest_driver: implement virDomainCreateWithFiles
Ilias Stamatis [Mon, 5 Aug 2019 09:02:22 +0000 (11:02 +0200)]
test_driver: implement virDomainCreateWithFiles

This should just forward the call to testDomainCreateWithFlags since we
can't do anything with the provided file descriptors in the test driver.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
5 years agodaemon: improve Xen support in systemd service
Jim Fehlig [Wed, 31 Jul 2019 18:02:48 +0000 (12:02 -0600)]
daemon: improve Xen support in systemd service

The xencommons service provides all the essential services such as
xenstored, xenconsoled, etc. needed by the libvirt Xen driver, so
libvirtd should be started after xencommons.

The xendomains service uses Xen's xl tool to operate on any domains it
finds running, even those managed by libvirt. Add a conflicts on the
xendomains service to ensure it is not enabled when libvirtd is enabled.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirhostdev: introduce virHostdevReattachAllPCIDevices
Daniel Henrique Barboza [Tue, 23 Jul 2019 17:35:41 +0000 (14:35 -0300)]
virhostdev: introduce virHostdevReattachAllPCIDevices

This code that executes virPCIDeviceReattach in all
virPCIDevicePtr objects of a given virPCIDeviceListPtr
list is replicated twice in the code. Putting it in a helper
function helps with readability.

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 agovirhostdev: remove virHostdevReattachPCIDevice
Daniel Henrique Barboza [Tue, 23 Jul 2019 17:35:40 +0000 (14:35 -0300)]
virhostdev: remove virHostdevReattachPCIDevice

virHostdevReattachPCIDevice() is a static that simply does
a wait loop with virPCIDeviceWaitForCleanup() before
calling virPCIDeviceReattach().

This loop traces back to commit d1e5676c0d, aiming to
solve a race condition between Libvirt returning the
device back to the host and QEMU trying to access it in
the meantime, which resulted in QEMU exiting on error
and killing the guest. This happens because device_del
is asynchronous, returning OK even if the guest didn't
release the device. Commit 01abc8a1b8 moved this code
to qemu_hostdev.c, 82e8dd4cf8 added the pci-stub conditional
for the loop, 899b261127 moved the code to virhostdev.c
where it stood until now.

The intent of this wait loop is still valid: device_del
is still not bullet proof into preventing the conditions
that commit d1e5676c0d aimed to fix, especially when considering
all the architectures we must support. However, this loop
is executed only in virHostdevReattachPCIDevice(), leaving
every other virPCIDeviceReattach() call prone to that error.

Let's move the wait loop code to virPCIDeviceReattach(). This
will:

-  make every reattach call safe from this race condition
with the pci-stub;

-  allow for a bit of code cleanup (virHostdevReattachPCIDevice()
can be erased, and virHostdevReAttachPCIDevices() can use
virPCIDeviceReattach() directly);

- make it easier to understand the overall reattach mechanisms in
Libvirt, without the risk of a newcomer wondering why reattach
is done slightly different in some instances.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirhostdev: introduce virHostdevResetAllPCIDevices
Daniel Henrique Barboza [Tue, 23 Jul 2019 17:35:39 +0000 (14:35 -0300)]
virhostdev: introduce virHostdevResetAllPCIDevices

This code that executes virPCIDeviceReset in all virPCIDevicePtr
objects of a given virPCIDeviceListPtr list is replicated twice
in the code. Putting it in a helper function helps with
readability.

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 agovirpci: Allow greater PCI domain value in virPCIDeviceAddressIsValid
Michal Privoznik [Tue, 30 Jul 2019 14:37:20 +0000 (16:37 +0200)]
virpci: Allow greater PCI domain value in virPCIDeviceAddressIsValid

There is no restriction on maximum value of PCI domain. In fact,
Linux kernel uses plain atomic inc when assigning PCI domains:

drivers/pci/pci.c:static int pci_get_new_domain_nr(void)
drivers/pci/pci.c-{
drivers/pci/pci.c-      return atomic_inc_return(&__domain_nr);
drivers/pci/pci.c-}

Of course, this function is called only if kernel was compiled
without PCI domain support or ACPI did not provide PCI domain.

However, QEMU still has the same restriction as us: in
set_pci_host_devaddr() QEMU checks if domain isn't greater than
0xffff. But one can argue that that's a QEMU limitation. We still
want to be able to cope with other hypervisors that don't have
this limitation (possibly).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agolib: Format PCI address differently
Michal Privoznik [Tue, 30 Jul 2019 14:24:39 +0000 (16:24 +0200)]
lib: Format PCI address differently

Currently, the way we format PCI address is using printf-s
precision, e.g. "%.4x". This works if we don't want to print any
value outside of bounds (which is usually the case). However,
turns out, PCI domain can be 0x10000 which doesn't work well with
our format strings. However, if we change the format string to
"%04x" then we still pad small values with zeroes but also we are
able to print values that are larger than four digits. In fact,
this format string used by kernel to print a PCI address:

  "%04x:%02x:%02x.%d"

The other three format strings (for bus, device and function) are
changed too, so that we use the same format string as kernel.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agolib: Unify PCI address formatting
Michal Privoznik [Tue, 30 Jul 2019 12:43:44 +0000 (14:43 +0200)]
lib: Unify PCI address formatting

The format string for a PCI address is copied over and over
again, often with slight adjustments. Introduce global
VIR_PCI_DEVICE_ADDRESS_FMT macro that holds the formatting string
and use it wherever possible.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirPCIDevice: Make @name dynamically allocated
Michal Privoznik [Tue, 30 Jul 2019 09:37:43 +0000 (11:37 +0200)]
virPCIDevice: Make @name dynamically allocated

In near future, the length restriction of PCI domain is going to
be lifted. This means that our assumption that PCI address is 13
bytes long is no longer true. We can avoid this problem by making
@name dynamically allocated and thus not bother with actual
length of stringified PCI address.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirPCIDeviceNew: Prefer VIR_RETURN_PTR
Michal Privoznik [Tue, 30 Jul 2019 09:31:53 +0000 (11:31 +0200)]
virPCIDeviceNew: Prefer VIR_RETURN_PTR

This function declares @ret variable and then uses
VIR_STEAL_PTR() to avoid freeing temporary variable @dev which is
constructed. Well, as of 267f1e6da53 we have VIR_RETURN_PTR()
macro so that we can avoid this pattern.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuBuildPCIHostdevDevStr: Always format PCI domain onto cmd line
Michal Privoznik [Tue, 30 Jul 2019 11:34:45 +0000 (13:34 +0200)]
qemuBuildPCIHostdevDevStr: Always format PCI domain onto cmd line

While it's true that older QEMUs were not able to deal with PCI
domains, we don't support those versions anymore (see
4a42ece13a538). Therefore it is safe to always format fully
expanded PCI address. Format PCI domain always as it will
simplify next commits.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Refactor and rename the function to validate a new resctrl monitor
Wang Huaqiang [Tue, 11 Jun 2019 03:31:16 +0000 (11:31 +0800)]
conf: Refactor and rename the function to validate a new resctrl monitor

A new algorithm for detecting the vcpus and monitor type conflicts
between new monitor an existing allocation and monitor groups.

After refactoring, since we are verifying both @vcpus and monitor
type @tag at the same time, the validating function name has been
renamed from virDomainResctrlMonValidateVcpus to
virDomainResctrlValidateMonitor.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: Remove unused virResctrlMonitorGetCacheOccupancy
Wang Huaqiang [Tue, 11 Jun 2019 03:31:15 +0000 (11:31 +0800)]
util: Remove unused virResctrlMonitorGetCacheOccupancy

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: Extend virresctl API to retrieve multiple monitor statistics
Wang Huaqiang [Tue, 11 Jun 2019 03:31:14 +0000 (11:31 +0800)]
util: Extend virresctl API to retrieve multiple monitor statistics

Export virResctrlMonitorGetStats and make
virResctrlMonitorGetCacheOccupancy obsoleted.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: Refactor 'virResctrlMonitorStats'
Wang Huaqiang [Tue, 11 Jun 2019 03:31:13 +0000 (11:31 +0800)]
util: Refactor 'virResctrlMonitorStats'

Refactor 'virResctrlMonitorStats' to track multiple statistical
records.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: Refactor and rename 'virResctrlMonitorFreeStats'
Wang Huaqiang [Tue, 11 Jun 2019 03:31:12 +0000 (11:31 +0800)]
util: Refactor and rename 'virResctrlMonitorFreeStats'

Refactor and rename 'virResctrlMonitorFreeStats' to
'virResctrlMonitorStatsFree' to free one
'virResctrlMonitorStatsPtr' object.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: Append 'resctrl' object according to number of monitor group directly
Wang Huaqiang [Tue, 11 Jun 2019 03:31:11 +0000 (11:31 +0800)]
conf: Append 'resctrl' object according to number of monitor group directly

'virResctrlAllocIsEmpty' checks if cache allocation or memory
bandwidth allocation settings are specified in configuration
file. It is not proper to be used in checking memory bandwidth
allocation is specified in XML settings because this function
could not distinguish memory bandwidth allocations from cache
allocations.

Here using the local variable @n, which indicates the cache
allocation groups or memory bandwidth groups depending on the
context it is in, to decide if append a new @resctrl object.

If @n is zero and no monitors groups specified in XML, then
we should not append a new @resctrl object to @def->resctrls.

This kind of replacement is also more efficient and avoiding
a long function calling path.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: refactor 'virDomainResctrlVcpuMatch' and some code cleanup
Wang Huaqiang [Tue, 11 Jun 2019 03:31:10 +0000 (11:31 +0800)]
conf: refactor 'virDomainResctrlVcpuMatch' and some code cleanup

Let 'virDomainResctrlVcpuMatch' to retrieve a pointer of
virDomainResctrlDefPtr in its third parameter instead
of virResctrlAllocPtr, if @vcpus is matched with the vcpus
of some resctrl allocation in list of @def->resctrls.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: some code cleanup
Wang Huaqiang [Tue, 11 Jun 2019 03:31:09 +0000 (11:31 +0800)]
conf: some code cleanup

Creating object and judging if it is successfully created in fewer
lines.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: code cleanup for return error code directly
Wang Huaqiang [Tue, 11 Jun 2019 03:31:08 +0000 (11:31 +0800)]
conf: code cleanup for return error code directly

code cleanup for 'virDomainCachetuneDefParse' and
'virDomainMemorytuneDefParse'.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: code cleanup, remove empty line and one space
Wang Huaqiang [Tue, 11 Jun 2019 03:31:07 +0000 (11:31 +0800)]
conf: code cleanup, remove empty line and one space

Remove some redundant space and line.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil, conf: Handle default monitor group of an allocation properly
Wang Huaqiang [Tue, 11 Jun 2019 03:31:06 +0000 (11:31 +0800)]
util, conf: Handle default monitor group of an allocation properly

'default monitor of an allocation' is defined as the resctrl
monitor group that created along with an resctrl allocation,
which is created by resctrl file system. If the monitor group
specified in domain configuration file is happened to be a
default monitor group of an allocation, then it is not necessary
to create monitor group since it is already created. But if
an monitor group is not an allocation default group, you
should create the group under folder
'/sys/fs/resctrl/mon_groups' and fill the vcpu PIDs to 'tasks'
file.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolibxl: Implement domain metadata getter/setter
Michal Privoznik [Mon, 5 Aug 2019 08:42:49 +0000 (10:42 +0200)]
libxl: Implement domain metadata getter/setter

Fortunately, the code that handles metadata getting or setting is
driver agnostic, so all that is needed from individual hypervisor
drivers is to call the right functions.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotools: console: Use proper constructor
Roman Bolshakov [Mon, 5 Aug 2019 16:03:45 +0000 (19:03 +0300)]
tools: console: Use proper constructor

"virsh console" on macOS cannot attach to a domain and it doesn't matter if
it's local or remote domain:
  $ ~ virsh console vm
  Connected to domain vm
  Escape character is ^]
  error: internal error: unable to wait on console condition

The error comes from pthread_cond_wait that fails with EINVAL. The mutex
in the parent is not initialized with pthread_mutex_init and it results
in silent failure of pthead_mutex_lock and the attach failure.

Fixes: 98361cc3b95 ("tools: console: make console virLockableObject")
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonews.xml: Restore blank news example
Michal Privoznik [Mon, 5 Aug 2019 17:33:25 +0000 (19:33 +0200)]
news.xml: Restore blank news example

In v5.6.0-rc1~347 I've mistakenly messed up news.xml as the
change I wanted to promote was added into a comment (I blame git
rebase for that). Anyway, restore the original state of the
comment so it can be copied again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agomaint: Post-release version bump to 5.7.0
Michal Privoznik [Mon, 5 Aug 2019 17:23:46 +0000 (19:23 +0200)]
maint: Post-release version bump to 5.7.0

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoRelease of libvirt-5.6.0
Daniel Veillard [Mon, 5 Aug 2019 17:17:01 +0000 (19:17 +0200)]
Release of libvirt-5.6.0

* docs/news.xml: updated for release

Signed-off-by: Daniel Veillard <veillard@redhat.com>
5 years agonews: Update for 5.6.0 release
Andrea Bolognani [Fri, 2 Aug 2019 17:42:21 +0000 (19:42 +0200)]
news: Update for 5.6.0 release

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Acked-by: Daniel Veillard <veillard@redhat.com>
5 years agotests: Fix virsh-snapshot/checkpoint without readline-devel
Eric Blake [Fri, 2 Aug 2019 13:20:08 +0000 (08:20 -0500)]
tests: Fix virsh-snapshot/checkpoint without readline-devel

readline-devel is an optional build dependency; when it is not
present, the output of 'virsh <<EOF ... EOF' is different in that the
input provided by the user is not echoed, and prompts become
interleaved on the same line as actual output, which in turn causes
the sed doing prompt filtering to mess up:

| ./virsh-snapshot
| --- exp 2019-07-31 18:42:31.107399428 -0300
| +++ out.cooked 2019-07-31 18:42:31.108399437 -0300
| @@ -1,8 +1,3 @@
| -
| -
| -Domain snapshot s3 created from 's3.xml'
| -Domain snapshot s2 created from 's2.xml'
| -Name:           s2
|  Domain:         test
|  Current:        yes
|  State:          running

Maybe we should fix virsh in interactive mode to echo regardless of
whether readline-devel was used, but the quicker fix is to make the
test use 'virsh "..."' rather than reading its input from stdin.

Reported-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agonews: add entry for new max_threads_per_process option in qemu.conf
Jim Fehlig [Wed, 31 Jul 2019 17:56:17 +0000 (11:56 -0600)]
news: add entry for new max_threads_per_process option in qemu.conf

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agonews: Add news entry for checkpoints
Eric Blake [Tue, 30 Jul 2019 21:51:48 +0000 (16:51 -0500)]
news: Add news entry for checkpoints

Checkpoints are definitely a news-worthy addition, even if the
virDomainBackup API is not going to make it until a later release.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agonews: Grammar tweaks
Eric Blake [Wed, 31 Jul 2019 13:09:57 +0000 (08:09 -0500)]
news: Grammar tweaks

Wording improvements in the recent patches.

Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agonews: Support encrypted soft TPM
Han Han [Wed, 31 Jul 2019 03:57:42 +0000 (11:57 +0800)]
news: Support encrypted soft TPM

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agonews: Allow XML validation for snapshot creation
Han Han [Wed, 31 Jul 2019 03:57:41 +0000 (11:57 +0800)]
news: Allow XML validation for snapshot creation

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agogitdm: Add some more companies
Andrea Bolognani [Wed, 31 Jul 2019 09:43:04 +0000 (11:43 +0200)]
gitdm: Add some more companies

Employees from these companies have made contributions to
libvirt over the past few releases.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
5 years agobackup: remote: Trivial whitespace fix
Eric Blake [Tue, 30 Jul 2019 21:46:55 +0000 (16:46 -0500)]
backup: remote: Trivial whitespace fix

I messed up formatting during conflict resolution across rebasing
while preparing my checkpoint patches :)

Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agocpu: Drop CPUID definition for hv-spinlocks
Jiri Denemark [Tue, 30 Jul 2019 10:33:42 +0000 (12:33 +0200)]
cpu: Drop CPUID definition for hv-spinlocks

hv-spinlocks is not a CPUID feature and should not be checked as such.
While starting a domain with hv-spinlocks enabled, we would report a
warning about unsupported hyperv spinlocks feature even though it was
set properly.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agopo: refresh translations from zanata
Daniel P. Berrangé [Tue, 30 Jul 2019 11:38:48 +0000 (12:38 +0100)]
po: refresh translations from zanata

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: formatdomain: move 'msrs' out of Hyper-V Enlightenments
Vitaly Kuznetsov [Tue, 30 Jul 2019 10:13:43 +0000 (12:13 +0200)]
docs: formatdomain: move 'msrs' out of Hyper-V Enlightenments

Introduced by: commit e9528f41c612fff334e958d5e5df197aa8e83792

'msrs' is a feature unrelated to Hyper-V Enlightenments, the commit message
which added it and the test have it right:

    <features>
      ...
      <msrs unknown='ignore'>
      ...
    </features>

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: formatdomain: fix 'SynIC' spelling
Vitaly Kuznetsov [Tue, 30 Jul 2019 10:13:42 +0000 (12:13 +0200)]
docs: formatdomain: fix 'SynIC' spelling

SynIC stands for 'Synthetic Interrupt Controller', it is not a NIC. Fix the
spelling in accordance with Hypervisor Top Level Functional Specification.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: formatdomain: add stimer flag to the example xml
Vitaly Kuznetsov [Tue, 30 Jul 2019 10:13:41 +0000 (12:13 +0200)]
docs: formatdomain: add stimer flag to the example xml

The example XML we have contains all other Hyper-V Enlightenments but
'stimer' is missing.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agobuild: Fix checkpoint_conf on mingw
Eric Blake [Mon, 29 Jul 2019 18:00:44 +0000 (13:00 -0500)]
build: Fix checkpoint_conf on mingw

CI flagged a failing mingw build, due to:
In file included from ../../src/conf/checkpoint_conf.c:24:
../gnulib/lib/configmake.h:8:17: error: expected identifier or '(' before string constant
    8 | #define DATADIR "/usr/i686-w64-mingw32/sys-root/mingw/share"
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As previously learned in commits bd205a90 and 976abdf6, gnulib's
configmake.h header does #define DATADIR "string...", while mingw's
<winsock2.h> expects to declare a type named DATADIR. As long as the
mingw system header is included first before configmake.h, the two
uses do not conflict, but until gnulib is patched to make configmake.h
automatically work around the issue, our immediate fix is the
workaround of rearranging our include order to insure no conflict.
Copy the paradigm used in domain_conf.c of using <unistd.h> to trigger
the indirect inclusion of <winsock2.h> on mingw.

Fixes: 1a4df34a
Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agoutil: Fix comment for virGetEnvAllowSUID()
Andrea Bolognani [Mon, 29 Jul 2019 17:17:52 +0000 (19:17 +0200)]
util: Fix comment for virGetEnvAllowSUID()

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
5 years agolibvirt: correctly print out URI returned from probing
Daniel P. Berrangé [Tue, 23 Jul 2019 10:06:33 +0000 (11:06 +0100)]
libvirt: correctly print out URI returned from probing

Turning a NULL URI instead the empty string is very misleading when
reading the debug logs as the distinction between the two is
functionally important.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agocommandtest: Remove commandhelper.log in test27
Michal Privoznik [Mon, 29 Jul 2019 14:11:29 +0000 (16:11 +0200)]
commandtest: Remove commandhelper.log in test27

The recently added test27 spawns commandhelper. This is fine,
except, one of the things that commandhelper does is it records
arguments it was spawn with into commandhelper.log. Other test
cases then use checkoutput() to compare the arguments against the
expected ones and also unlink() the log file. However, test27()
is not doing that and thus it leaves the file behind. This
breaks distcheck.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotest_driver: implement virDomainGetCPUStats
Ilias Stamatis [Sun, 28 Jul 2019 10:02:21 +0000 (12:02 +0200)]
test_driver: implement virDomainGetCPUStats

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotests: virsh-optparse: Drop obsolete cpu-stats test cases
Ilias Stamatis [Sun, 28 Jul 2019 10:02:20 +0000 (12:02 +0200)]
tests: virsh-optparse: Drop obsolete cpu-stats test cases

These test cases will start failing once the test driver provides
implementation for the virDomainGetCPUStats API.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoqemumonitorjsontest: Don't leak 'query-jobs' info
Michal Privoznik [Mon, 29 Jul 2019 12:12:22 +0000 (14:12 +0200)]
qemumonitorjsontest: Don't leak 'query-jobs' info

The returned array of qemuMonitorJobInfo structs must be freed.

164 (16 direct, 148 indirect) bytes in 1 blocks are definitely lost in loss record 64 of 84
   at 0x4A3568B: realloc (vg_replace_malloc.c:826)
   by 0x4D888BD: virReallocN (viralloc.c:244)
   by 0x4D889B3: virExpandN (viralloc.c:293)
   by 0x4D88C87: virInsertElementsN (viralloc.c:435)
   by 0x214004: qemuMonitorJSONGetJobInfo (qemu_monitor_json.c:9185)
   by 0x148B3F: testQueryJobs (qemumonitorjsontest.c:2979)
   by 0x14C192: virTestRun (testutils.c:174)
   by 0x14BF36: mymain (qemumonitorjsontest.c:3286)
   by 0x14E256: virTestMain (testutils.c:1096)
   by 0x14BFD9: main (qemumonitorjsontest.c:3298)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: Fix KVM features with QEMU 4.1
Jiri Denemark [Fri, 26 Jul 2019 14:34:55 +0000 (16:34 +0200)]
qemu: Fix KVM features with QEMU 4.1

Originally the names of the KVM CPU features were only used internally
for looking up their CPUID bits. So we used "__kvm_" prefix for them to
make sure the names do not collide with normal CPU features stored in
our CPU map.

But with QEMU 4.1 we check which features were enabled or disabled by a
freshly started QEMU process using their names rather than their CPUID
bits (mostly because of MSR features). Thus we need to change our made
up internal names into the actual names used by QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu: Drop unused KVM features
Jiri Denemark [Fri, 26 Jul 2019 13:44:59 +0000 (15:44 +0200)]
cpu: Drop unused KVM features

Most of the internally defined KVM CPUID features are not actually used
by libvirt. The QEMU driver may enable or disable them on the command
line, but we don't check for the associated CPU properties or CPUID
bits. They would be useless with QEMU 4.1 anyway since their names were
only remotely similar to the actual feature names.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocpu: Drop KVM_ from hyperv feature macros
Jiri Denemark [Thu, 25 Jul 2019 15:07:18 +0000 (17:07 +0200)]
cpu: Drop KVM_ from hyperv feature macros

All the features are hyperv features even though they are provided by
KVM with QEMU. The "KVM" part in the macro names does not make a lot of
sense.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Prefer dashes for hyperv features
Jiri Denemark [Thu, 25 Jul 2019 13:36:14 +0000 (15:36 +0200)]
qemu: Prefer dashes for hyperv features

Starting with QEMU 4.1, we're using the canonical feature names on the
command line and avoid aliases to prepare for possible deprecation of
all aliases in QEMU. But we do so only for features from our CPU map,
hyperv features defined in the code were unchanged and this patch fixes
it. Some features use "hv-" prefix unconditionally because they were
introduced recently enough to always support spelling with a dash.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Fix hyperv features with QEMU 4.1
Jiri Denemark [Thu, 25 Jul 2019 11:50:57 +0000 (13:50 +0200)]
qemu: Fix hyperv features with QEMU 4.1

Originally the names of the hyperv CPU features were only used
internally for looking up their CPUID bits. So we used "__kvm_hv_"
prefix for them to make sure the names do not collide with normal CPU
features stored in our CPU map.

But with QEMU 4.1 we check which features were enabled or disabled by a
freshly started QEMU process using their names rather than their CPUID
bits (mostly because of MSR features). Thus we need to change our made
up internal names into the actual names used by QEMU. Most of the names
are only used with QEMU 4.1 and newer and the reset was introduced with
QEMU recently enough to already support spelling with "-". Thus we don't
need to define them as "hv_*" with a translation to "hv-*" for new QEMU.

Without this patch libvirt would mistakenly report all hyperv features
as unavailable and refuse to start any domain using them with QEMU 4.1.

Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agobackup: Prevent snapshots and checkpoints at same time
Eric Blake [Wed, 24 Jul 2019 05:17:23 +0000 (00:17 -0500)]
backup: Prevent snapshots and checkpoints at same time

Earlier patches mentioned that the initial implementation will prevent
snapshots and checkpoints from being used on the same domain at once.
However, the actual restriction is done in this separate patch to make
it easier to lift that restriction via a revert, when we are finally
ready to tackle that integration in the future.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Wire up qemu checkpoint commands over QMP
Eric Blake [Fri, 26 Jul 2019 20:52:08 +0000 (15:52 -0500)]
backup: Wire up qemu checkpoint commands over QMP

Time to actually issue the QMP transactions that create and delete
persistent checkpoints, resolving TODOs intentionally left earlier in
the series.  For create, we only need one transaction: inside, we
visit all disks affected by the checkpoint, and create a new enabled
bitmap, as well as disabling the bitmap of the first ancestor
checkpoint (if any) that also had a bitmap.  For deletion, we need
multiple QMP calls: for each disk, if there is an ancestor checkpoint
with a bitmap, then the bitmap must be merged (including activating
the ancestor bitmap if the leaf node changes), all before deleting the
bitmap from the checkpoint being removed.

Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agobackup: qemu: Add helper API for looking up node name
Eric Blake [Mon, 22 Jul 2019 16:22:05 +0000 (11:22 -0500)]
backup: qemu: Add helper API for looking up node name

Qemu bitmap operations require knowing the node name associated with
the format layer (the qcow2 file); as upcoming patches will be
grabbing that information frequently, make a helper function to access
it.

Another potential benefit of this function is that we have a single
place where we could insert a QMP node-name scraping call if we don't
currently know the node name, when -blockdev is not supported;
however, the goal is that we hopefully don't ever have to do that
because we instead scrape node names only at the point where they
change.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>