]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
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>
5 years agobackup: qemu: Implement metadata tracking for checkpoint APIs
Eric Blake [Wed, 10 Apr 2019 15:42:11 +0000 (10:42 -0500)]
backup: qemu: Implement metadata tracking for checkpoint APIs

A lot of this work heavily copies from the existing snapshot APIs.
What's more, this patch is (intentionally) very similar to the
checkpoint code just added in the test driver, to the point that qemu
checkpoints are not fully usable in this patch, but it at least
bisects and builds cleanly.  The separation between patches is done
because the grunt work of saving and restoring XML and tracking
relations between checkpoints is common to the test driver, while the
later patch adding integration with QMP is specific to qemu.

Also note that the interlocking to prevent checkpoints and snapshots
from existing at the same time will be a separate patch, to make it
easier to revert that restriction when we finally round out the design
for supporting interaction between the two concepts.

Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agobackup: qemu: Add directory for tracking checkpoints
Eric Blake [Mon, 22 Jul 2019 14:44:12 +0000 (09:44 -0500)]
backup: qemu: Add directory for tracking checkpoints

This is similar to the existing directory for snapshots; the domain
will save one xml file per checkpoint, for reloading on the next
libvirtd restart.  Fortunately, since checkpoints mandate RNG
validation, we are assured that the checkpoint name will be usable as
a file name (no abuse of '../escape' as a checkpoint name, for
example).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Add -blockdev support for block commit job
Peter Krempa [Mon, 22 Jul 2019 11:39:24 +0000 (13:39 +0200)]
qemu: Add -blockdev support for block commit job

Introduce the handler for finalizing a block commit and active bloc
commit job which will allow to use it with blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add -blockdev support for block pull job
Peter Krempa [Mon, 22 Jul 2019 11:39:24 +0000 (13:39 +0200)]
qemu: Add -blockdev support for block pull job

Introduce the handler for finalizing a block pull job which will allow
to use it with blockdev.

This patch also contains some additional machinery which is required to
store all the relevant job data in the status XML which will also be
reused with other block job types.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Remove unnecessary declaration in virDomainCheckpointDefParse
John Ferlan [Sun, 28 Jul 2019 13:20:24 +0000 (09:20 -0400)]
conf: Remove unnecessary declaration in virDomainCheckpointDefParse

The @creation variable wasn't used - caused a Travis build failure.

Signed-off-by: John Ferlan <jferlan@redhat.com>
5 years agotpm: Run swtpm_setup with less parameters on incoming migration
Stefan Berger [Fri, 26 Jul 2019 20:41:10 +0000 (16:41 -0400)]
tpm: Run swtpm_setup with less parameters on incoming migration

In case of an incoming migration we do not need to run swtpm_setup
with all the parameters but only want to get the benefit of it
creating a TPM state file for us that we can then label with an
SELinux label. The actual state will be overwritten by the in-
coming state. So we have to pass an indicator for incomingMigration
all the way to the command line parameter generation for swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agobackup: Add virsh-checkpoints test
Eric Blake [Sat, 6 Jul 2019 15:48:59 +0000 (10:48 -0500)]
backup: Add virsh-checkpoints test

Similar to virsh-snapshots. Provides decent coverage of the checkpoint
API, the test driver implementation, and the virsh access to the API.
A later patch will worry about testing that snapshots and checkpoints
are mutually exclusive (in part so it is easier to revert that when we
finally implement the interaction and lift that restriction).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: test: Implement metadata tracking for checkpoint APIs
Eric Blake [Wed, 10 Apr 2019 15:42:11 +0000 (10:42 -0500)]
backup: test: Implement metadata tracking for checkpoint APIs

A lot of this work heavily copies from the existing snapshot APIs.
The test driver doesn't really have to do anything more than just
expose an interface into libvirt metadata, making it possible to test
saving and restoring XML, and tracking relations between multiple
checkpoints.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Implement virsh support for checkpoints
Eric Blake [Wed, 13 Mar 2019 21:04:51 +0000 (16:04 -0500)]
backup: Implement virsh support for checkpoints

Introduce a bunch of new virsh commands for managing checkpoints in
isolation. More commands are needed for performing incremental
backups, but these commands were easy to implement by modeling heavily
after virsh-snapshot.c. There is no need for checkpoint-revert or
checkpoint-current since those snapshot APIs have no checkpoint
counterpart.  Similarly, it is not necessary to change which
checkpoint is current when redefining from XML, since until we
integrate checkpoints with snapshots, there is only a linear chain
(and you can deduce the current checkpoint by instead using
'checkpoint-list --leaves').  Other aspects of checkpoint-list are
also a bit simpler than the snapshot counterpart, in part because we
don't have to cater to back-compat to older API.

Upcoming patches will test these interfaces once the test driver
supports checkpoints.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Implement checkpoint APIs for remote driver
Eric Blake [Wed, 6 Mar 2019 17:54:47 +0000 (11:54 -0600)]
backup: Implement checkpoint APIs for remote driver

The remote code generator had to be taught about the new
virDomainCheckpointPtr type, at which point the remote driver code for
checkpoints can be generated.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Add new domain:checkpoint access control
Eric Blake [Wed, 13 Jun 2018 12:04:57 +0000 (07:04 -0500)]
backup: Add new domain:checkpoint access control

Creating a checkpoint does not modify guest-visible state,
but does modify host resources.  Rather than reuse existing
domain:write, domain:block_write, or domain:snapshot access
controls, it seems better to introduce a new access control
specific to tasks related to checkpoints and incremental
backups of guest disk state.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Add list of checkpoints to domain
Eric Blake [Fri, 26 Jul 2019 19:28:44 +0000 (14:28 -0500)]
backup: Add list of checkpoints to domain

Wire up the use of a checkpoint list into each domain, similar to the
existing snapshot list.  This includes adding a function for checking
that a redefine operation fits in with the existing list, as well as
various filtering capabilities over the list contents.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Allow for lists of checkpoint objects
Eric Blake [Fri, 19 Jul 2019 02:24:54 +0000 (21:24 -0500)]
backup: Allow for lists of checkpoint objects

Create a new file for managing a list of checkpoint objects, borrowing
heavily from existing virDomainSnapshotObjList paradigms.

Note that while snapshots definitely have a use case for multiple
children to a single parent (create a base snapshot, create a child
snapshot, revert to the base, then create another child snapshot),
it's harder to predict how checkpoints will play out with reverting to
prior points in time. Thus, in initial use, given a list of
checkpoints, you never have more than one child, and we can treat the
most-recent leaf node as the parent of the next node creation, without
having to expose a notion of a current node in XML or public API.
However, as the snapshot machinery is already generic, it is easier to
reuse the generic machinery that tracks relations between domain
moments than it is to open-code a new list-management scheme just for
checkpoints (hence, we still have internal functions related to a
current checkpoint, even though that has no observable effect
externally, as well as the addition of a function to easily find the
lone leaf in the list to use as the current checkpoint).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Parse and output checkpoint XML
Eric Blake [Sun, 8 Jul 2018 02:01:14 +0000 (21:01 -0500)]
backup: Parse and output checkpoint XML

Add a new file checkpoint_conf.c that performs the translation to and
from new XML describing a checkpoint. The code shares a common base
class with snapshots, since a checkpoint similarly represents the
domain state at a moment in time. Add some basic testing of round trip
XML handling through the new code.

Of note - this code intentionally differs from snapshots in that XML
schema validation is unconditional, rather than based on a public API
flag.  We have many existing interfaces that still need to add a flag
for opt-in schema validation, but those interfaces have existing
clients that may not have been producing strictly-compliant XML, or we
may still uncover bugs where our RNG grammar is inconsistent with our
code (where omitting the opt-in flag allows existing apps to keep
working while waiting for an RNG patch).  But since checkpoints are
brand-new, it's easier to ensure the code matches the schema by always
using the schema.  If needed, a later patch could extend the API and
add a flag to turn on to request schema validation, rather than having
it forced (possibly just the validation of the <domain> sub-element
during REDEFINE) - but if a user encounters XML that looks like it
should be good but fails to validate with our RNG schema, they would
either have to upgrade to a new libvirt that adds the new flag, or
upgrade to a new libvirt that fixes the RNG schema, which implies
adding such a flag won't help much.

Also, the redefine flag requires the <domain> sub-element to be
present, rather than catering to historical back-compat to older
versions.

Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agobackup: Document nuances between different state capture APIs
Eric Blake [Wed, 10 Jul 2019 17:09:22 +0000 (12:09 -0500)]
backup: Document nuances between different state capture APIs

Now that various new API have been added or are coming soon, it is
worth a landing page that gives an overview of capturing various
pieces of guest state, and which APIs are best suited to which tasks.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Introduce virDomainCheckpoint APIs
Eric Blake [Wed, 13 Mar 2019 19:35:26 +0000 (14:35 -0500)]
backup: Introduce virDomainCheckpoint APIs

Introduce a bunch of new public APIs related to backup checkpoints.
Checkpoints are modeled heavily after virDomainSnapshotPtr (both
represent a point in time of the guest), although a snapshot exists
with the intent of rolling back to that state, while a checkpoint
exists to make it possible to create an incremental backup at a later
time.  We may have a future hypervisor that can completely manage
checkpoints without libvirt metadata, but the first two planned
hypervisors (qemu and test) both always use libvirt for tracking
metadata relations between checkpoints, so for now, I've deferred
the counterpart of virDomainSnapshotHasMetadata for a separate
API addition at a later date if there is ever a need for it.

Note that until we allow snapshots and checkpoints to exist
simultaneously on the same domain (although the actual prevention of
this will be in a separate patch for the sake of an easier revert down
the road), that it is not possible to branch out to create more than
one checkpoint child to a given parent, although it may become
possible later when we revert to a snapshot that coincides with a
checkpoint.  This also means that for now, the decision of which
checkpoint becomes the parent of a newly created one is the only
checkpoint with no child (so while there are APIs for dealing with a
current snapshot, we do not need those for checkpoints).  We may end
up exposing a notion of a current checkpoint later, but it's easier to
add stuff when proven needed than to blindly support it now and wish
we hadn't exposed it.

The following map shows the API relations to snapshots, with new APIs
on the right:

Operate on a domain object to create/redefine a child:
virDomainSnapshotCreateXML          virDomainCheckpointCreateXML

Operate on a child object for lifetime management:
virDomainSnapshotDelete             virDomainCheckpointDelete
virDomainSnapshotFree               virDomainCheckpointFree
virDomainSnapshotRef                virDomainCheckpointRef

Operate on a child object to learn more about it:
virDomainSnapshotGetXMLDesc         virDomainCheckpointGetXMLDesc
virDomainSnapshotGetConnect         virDomainCheckpointGetConnect
virDomainSnapshotGetDomain          virDomainCheckpointGetDomain
virDomainSnapshotGetName            virDomainCheckpiontGetName
virDomainSnapshotGetParent          virDomainCheckpiontGetParent
virDomainSnapshotHasMetadata        (deferred for later)
virDomainSnapshotIsCurrent          (no counterpart, see note above)

Operate on a domain object to list all children:
virDomainSnapshotNum                (no counterparts, these are the old
virDomainSnapshotListNames           racy interfaces)
virDomainSnapshotListAllSnapshots   virDomainListAllCheckpoints

Operate on a child object to list descendents:
virDomainSnapshotNumChildren        (no counterparts, these are the old
virDomainSnapshotListChildrenNames   racy interfaces)
virDomainSnapshotListAllChildren    virDomainCheckpointListAllChildren

Operate on a domain to locate a particular child:
virDomainSnapshotLookupByName       virDomainCheckpointLookupByName
virDomainSnapshotCurrent            (no counterpart, see note above)
virDomainHasCurrentSnapshot         (no counterpart, old racy interface)

Operate on a snapshot to roll back to earlier state:
virDomainSnapshotRevert             (no counterpart, instead checkpoints
                                     are used in incremental backups via
     XML to virDomainBackupBegin)

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: Document new XML for checkpoints
Eric Blake [Tue, 12 Jun 2018 03:12:21 +0000 (22:12 -0500)]
backup: Document new XML for checkpoints

Prepare for new checkpoint APIs by describing the XML that will
represent a checkpoint.  The checkpoint XML is modeled heavily after
virDomainSnapshotPtr. See the docs for more details.

Add testsuite coverage for some minimal uses of the XML (bare minimum,
the sample from html, and a full dumpxml, and some counter-examples
that should fail schema validation). Although use of the REDEFINE flag
will require the <domain> subelement to be present, it is easier for
most of the tests to provide counterpart output produced with the
NO_DOMAIN flag (particularly since synthesizing a valid <domain>
during testing is not trivial).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agobackup: qemu: Detect node names at domain startup
Eric Blake [Wed, 24 Jul 2019 03:04:25 +0000 (22:04 -0500)]
backup: qemu: Detect node names at domain startup

If we are using -blockdev, then node names are always available
(because we set them).  But when not using it, we have to scrape node
names from QMP, and want to do so as infrequently as possible.  We
were scraping node names after reconnecting a new libvirtd to an
existing guest (see qemuProcessReconnect), and after any block job
that may have changed the set of node names we care about (legacy
block jobs), but forgot to scrape the names when first starting a
guest.  Do so now in order to allow the checkpoint code to always have
access to a node name without having to repeat a node name scrape
itself.

Future patches may need to clean up qemuDomainSetBlockThreshold (if
node names are always available, then it doesn't need to repeat a
scrape) and/or hotplug and media changes (if the addition of new nodes
can result in a null node name, then scraping at that point in time
would be appropriate).  But for now, this patch addresses only the
most common instance of a missing node name.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: Remove ATTRIBUTE_NONNULL(2) from virDomainCheckDeviceChanges()
Stefan Berger [Fri, 26 Jul 2019 20:56:33 +0000 (16:56 -0400)]
conf: Remove ATTRIBUTE_NONNULL(2) from virDomainCheckDeviceChanges()

Since we are checking the 2nd parameter in the function for NULL,
we need to remove ATTRIBUTE_NONNULL(2) from the prototype.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Message-Id: <20190726205633.2041912-5-stefanb@linux.vnet.ibm.com>

5 years agoutils: Remove ATTRIBUTE_NONNULL(1) from virCommandSetSendBuffer
Stefan Berger [Fri, 26 Jul 2019 20:56:32 +0000 (16:56 -0400)]
utils: Remove ATTRIBUTE_NONNULL(1) from virCommandSetSendBuffer

Remove the ATTRIBUTE_NONNULL(1) from virCommandSetSendBuffer()
prototype since we are checking for '!cmd' and move the initialization
if 'i' after the test for '!cmd'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Message-Id: <20190726205633.2041912-4-stefanb@linux.vnet.ibm.com>

5 years agotests: Call virCommandFree() in cleanup section
Stefan Berger [Fri, 26 Jul 2019 20:56:31 +0000 (16:56 -0400)]
tests: Call virCommandFree() in cleanup section

Fix a potential memory leak by calling virCommandFree() in the cleanup
section.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Message-Id: <20190726205633.2041912-3-stefanb@linux.vnet.ibm.com>

5 years agotpm: Fix memory leak and use existing variable instead
Stefan Berger [Fri, 26 Jul 2019 20:56:30 +0000 (16:56 -0400)]
tpm: Fix memory leak and use existing variable instead

Use the existing variables rather then calling virTPMSwtpmXYZ().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Message-Id: <20190726205633.2041912-2-stefanb@linux.vnet.ibm.com>

5 years agotpm: Create empty log file if file was removed
Stefan Berger [Fri, 26 Jul 2019 21:07:06 +0000 (17:07 -0400)]
tpm: Create empty log file if file was removed

Create an empty log file if the log file was removed, otherwise the
transaction to set the security labels on the file will fail.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20190726210706.24440-3-stefanb@linux.ibm.com>