]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
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>

5 years agotpm: Set transationStarted to false if commit failed
Stefan Berger [Fri, 26 Jul 2019 21:07:05 +0000 (17:07 -0400)]
tpm: Set transationStarted to false if commit failed

Set the transactionStarted to false if the commit failed. If this is not
done, then the failure path will report 'no transaction is set' and hide
more useful error reports.

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

5 years agosnapshot: Fix tests/virsh-snapshot
Eric Blake [Fri, 26 Jul 2019 20:32:02 +0000 (15:32 -0500)]
snapshot: Fix tests/virsh-snapshot

Creating an 'exp' output file, but never comparing it against the
actual output, does not actually constitute testing the output. :)

Fixes: 280a2b41e
Signed-off-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: Translate features in virQEMUCapsGetCPUFeatures
Jiri Denemark [Thu, 25 Jul 2019 08:27:45 +0000 (10:27 +0200)]
qemu: Translate features in virQEMUCapsGetCPUFeatures

Starting with QEMU 4.1 qemuMonitorCPUModelInfo structure in virQEMUCaps
stores only canonical feature names which may differ from the name used
by libvirt. We need translate these canonical names into libvirt names
for further consumption.

This fixes a bug in qemuConnectBaselineHypervisorCPU which would remove
all features for which libvirt's spelling differs from the QEMU's
preferred name. For example, the following result of
qemuConnectBaselineHypervisorCPU on my host with QEMU 4.1 is wrong:

    <cpu mode='custom' match='exact'>
      <model fallback='forbid'>Skylake-Client</model>
      <vendor>Intel</vendor>
      <feature policy='require' name='ss'/>
      <feature policy='require' name='vmx'/>
      <feature policy='require' name='hypervisor'/>
      <feature policy='require' name='clflushopt'/>
      <feature policy='require' name='umip'/>
      <feature policy='require' name='arch-capabilities'/>
      <feature policy='require' name='xsaves'/>
      <feature policy='require' name='pdpe1gb'/>
      <feature policy='require' name='invtsc'/>
      <feature policy='disable' name='pclmuldq'/>
      <feature policy='disable' name='lahf_lm'/>
    </cpu>

The 'pclmuldq' and 'lahf_lm' should not be disabled in the baseline CPU
as they are supported by QEMU on this host.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agotest_driver: implement virDomainPinEmulator
Ilias Stamatis [Tue, 23 Jul 2019 11:37:44 +0000 (13:37 +0200)]
test_driver: implement virDomainPinEmulator

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
5 years agotest_driver: implement virDomainGetEmulatorPinInfo
Ilias Stamatis [Tue, 23 Jul 2019 11:37:43 +0000 (13:37 +0200)]
test_driver: implement virDomainGetEmulatorPinInfo

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
5 years agodocs: Extend TPM docs with new encryption element
Stefan Berger [Thu, 25 Jul 2019 18:22:15 +0000 (14:22 -0400)]
docs: Extend TPM docs with new encryption element

Describe the encryption element in the TPM's domain XML.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agodocs: Extend Secret XML documentation with vtpm usage type
Stefan Berger [Thu, 25 Jul 2019 18:22:14 +0000 (14:22 -0400)]
docs: Extend Secret XML documentation with vtpm usage type

Extend the Secret XML documentation with vtpm usage type.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Check TPM XML device configuration changes after edit
Stefan Berger [Thu, 25 Jul 2019 18:22:13 +0000 (14:22 -0400)]
tpm: Check TPM XML device configuration changes after edit

Since swtpm does not support getting started without password
once it was created with encryption enabled, we don't allow
encryption to be removed. Similarly, we do not allow encryption
to be added once swtpm has run. We also prevent chaning the type
of the TPM backend since the encrypted state is still around and
the next time one was to switch back to the emulator backend
and forgot the encryption the TPM would not work.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Pass migration key passphrase via fd to swtpm
Stefan Berger [Thu, 25 Jul 2019 18:22:12 +0000 (14:22 -0400)]
tpm: Pass migration key passphrase via fd to swtpm

This patch now passes the passphrase as a migration key to swtpm.
This now encrypts the state of the TPM while a VM is migrated between
hosts or when suspended into a file. Since the migration key secret
is the same as the state encryption secret, this now requires that
the migration destination host has the same secret value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Use fd to pass password to swtpm_setup and swtpm
Stefan Berger [Thu, 25 Jul 2019 18:22:11 +0000 (14:22 -0400)]
tpm: Use fd to pass password to swtpm_setup and swtpm

Allow vTPM state encryption when swtpm_setup and swtpm support
passing a passphrase using a file descriptor.

This patch enables the encryption of the vTPM state only. It does
not encrypt the state during migration, so the destination secret
does not need to have the same password at this point.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Extend command test to transfer large data to process on multiple fds
Stefan Berger [Thu, 25 Jul 2019 18:22:10 +0000 (14:22 -0400)]
tests: Extend command test to transfer large data to process on multiple fds

Add a test case to commandtest.c to test the transfer of data to a
process who received the read-end of pipes' file descriptors. Transfer
large (128 kb) byte streams.

Extend the commandhelper.c with support for --readfd <fd> command line
parameter and convert the data receive loop to use poll and receive data
on multiple file descriptors (up to 3) and read data into distinct buffers
that we grow while adding more (string) data.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutils: Extend virCommandProcessIO to include the send buffers
Stefan Berger [Thu, 25 Jul 2019 18:22:09 +0000 (14:22 -0400)]
utils: Extend virCommandProcessIO to include the send buffers

Extend virCommandProcessIO to include the send buffers in the poll
loop.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutils: Mark inpipe as non-blocking
Stefan Berger [Thu, 25 Jul 2019 18:22:08 +0000 (14:22 -0400)]
utils: Mark inpipe as non-blocking

Mark a virCommand's inpipe (write-end of pipe) as non-blocking so that it
will never block when we were to try to write too many bytes to it while
it doesn't have the capacity to hold them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutils: Convert pollfd array to be allocated
Stefan Berger [Thu, 25 Jul 2019 18:22:07 +0000 (14:22 -0400)]
utils: Convert pollfd array to be allocated

Convert the struct pollfd *fds to be allocated rather than residing
on the stack. This prepares it for the next patch where the size of
the array of fds becomes dynamic.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutils: Implement function to pass a buffer to send via a fd to virCommand
Stefan Berger [Thu, 25 Jul 2019 18:22:06 +0000 (14:22 -0400)]
utils: Implement function to pass a buffer to send via a fd to virCommand

Implement virCommandSetSendBuffer() that allows the caller to pass a
file descriptor and buffer to virCommand. virCommand will write the
buffer into the file descriptor. That file descriptor could be the
write end of a pipe or one of the file descriptors of a socketpair.
The other file descriptor should be passed to the launched process to
read the data from.

Only implement the function to allocate memory for send buffers
and to free them later on.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Parse the capabilities supported by swtpm and swtpm_setup
Stefan Berger [Thu, 25 Jul 2019 18:22:05 +0000 (14:22 -0400)]
tpm: Parse the capabilities supported by swtpm and swtpm_setup

Run 'swtpm socket --print-capabilities' and
'swtpm_setup --print-capabilities' to get the JSON object of the
features the programs are supporting and parse them into a bitmap.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Check whether previously found executables were updated
Stefan Berger [Thu, 25 Jul 2019 18:22:04 +0000 (14:22 -0400)]
tpm: Check whether previously found executables were updated

Check whether previously found executables were updated and if
so look for them again. This helps to use updated features of
swtpm and its tools upon updating them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Refactor virTPMEmulatorInit to use loop
Stefan Berger [Thu, 25 Jul 2019 18:22:03 +0000 (14:22 -0400)]
tpm: Refactor virTPMEmulatorInit to use loop

Refactor virTPMEmulatorInit to use a loop with parameters. This allows
for easier extension later on.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotpm: Move qemuTPMEmulatorInit to virTPMEmulatorInit in virtpm.c
Stefan Berger [Thu, 25 Jul 2019 18:22:02 +0000 (14:22 -0400)]
tpm: Move qemuTPMEmulatorInit to virTPMEmulatorInit in virtpm.c

Move qemuTPMEmulatorInit to virTPMEmulatorInit in virtpm.c and introduce
a few functions to query the executables needed for virCommands.

Add locking to protect the tool paths and return a copy of the tool paths
to callers wanting to access them so that we can run the initialization
function multiples time later on and detect when the executable gets updated.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Add tests for QEMU command line generation with encrypted TPM
Stefan Berger [Thu, 25 Jul 2019 18:22:01 +0000 (14:22 -0400)]
tests: Add tests for QEMU command line generation with encrypted TPM

The QEMU command line does not change when TPM state is encrypted
compared to when it is plain.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Add test for TPM XML encryption parser and formatter
Stefan Berger [Thu, 25 Jul 2019 18:22:00 +0000 (14:22 -0400)]
tests: Add test for TPM XML encryption parser and formatter

Add a test case for the TPM XML encryption parser and formatter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: Extend TPM XML parser with encryption support
Stefan Berger [Thu, 25 Jul 2019 18:21:59 +0000 (14:21 -0400)]
conf: Extend TPM XML parser with encryption support

Extend the TPM device XML parser and XML generator with emulator
state encryption support.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Add already existing test case tpm-emulator-tpm2
Stefan Berger [Thu, 25 Jul 2019 18:21:58 +0000 (14:21 -0400)]
tests: Add already existing test case tpm-emulator-tpm2

Add an already existing test case tpm-emulator-tpm2 to qemuxml2xmltest.c

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosecret: Add support for usage type vTPM, extend schema and test case
Stefan Berger [Thu, 25 Jul 2019 18:21:57 +0000 (14:21 -0400)]
secret: Add support for usage type vTPM, extend schema and test case

Add support for usage type vTPM to secret.
Extend the schema for the Secret to support the vTPM usage type
and add a test case for parsing the Secret with usage type vTPM.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoREADME: fix license typo
Jim Fehlig [Thu, 25 Jul 2019 14:51:33 +0000 (08:51 -0600)]
README: fix license typo

The README contains a reference to GPL 2.1, which does not exist.
COPYING contains 2.0 so change the README to follow.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: remove reference to VIR_DOMAIN_RNG_BACKEND_POOL
Ján Tomko [Tue, 23 Jul 2019 15:41:17 +0000 (17:41 +0200)]
conf: remove reference to VIR_DOMAIN_RNG_BACKEND_POOL

Sadly, this idea never got implemented.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
5 years agoconf: remove outdated comment
Ján Tomko [Tue, 23 Jul 2019 12:59:58 +0000 (14:59 +0200)]
conf: remove outdated comment

When using the ENUM macros, the compiler guards that the declaration
and implementation are in sync.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirsh: clean up includes
Ján Tomko [Fri, 19 Jul 2019 11:36:58 +0000 (13:36 +0200)]
virsh: clean up includes

We don't need domain_conf or libvirt-{qemu,lxc} in these generic files.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: blockjob: Ensure that config disk source is identical when modifying it
Peter Krempa [Wed, 24 Jul 2019 15:33:38 +0000 (17:33 +0200)]
qemu: blockjob: Ensure that config disk source is identical when modifying it

qemuBlockJobRewriteConfigDiskSource rewrites the disk source only
according to the 'target'. This means that if someone would change the
inactive config of the VM to refer to a different disk a block job would
rewrite it when finishing a job which modifies the disk source.

Make sure that this does not happen by verifying that the source of the
config disk is the same.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Clear out any irrelevant data in copied source
Peter Krempa [Wed, 24 Jul 2019 15:22:05 +0000 (17:22 +0200)]
qemu: blockjob: Clear out any irrelevant data in copied source

Since we copy everything from the original storage source including some
runtime data which are not relevant for the config we should clear them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Split out update of persistent XML disk's source on mirror jobs
Peter Krempa [Wed, 24 Jul 2019 15:17:17 +0000 (17:17 +0200)]
qemu: blockjob: Split out update of persistent XML disk's source on mirror jobs

Both active block commit and block copy modify the disk source of the
active definition and thus also must modify the corresponding inactive
definition source so that the VM starts up later. This is currently
implemented in the legacy block job handler but the logic will be useful
also for the new handlers. Split it out which also simplifies it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Register disk->mirror with a job only when required
Peter Krempa [Wed, 24 Jul 2019 12:50:33 +0000 (14:50 +0200)]
qemu: blockjob: Register disk->mirror with a job only when required

The <mirror> subelement is used in two ways: in a commit job to point to
existing storage, and in a block-copy job to point to additional
storage. We need a way to track only the distinct storage.

This patch introduces qemuBlockJobDiskRegisterMirror which registers the
mirror chain separately only for jobs which require it. This also comes
with remembering that in the status XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Document qemuBlockJobRegister
Peter Krempa [Wed, 24 Jul 2019 12:50:03 +0000 (14:50 +0200)]
qemu: blockjob: Document qemuBlockJobRegister

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agotests: qemustatusxml: Add few disks with backing chains for blockdev job testing
Peter Krempa [Tue, 23 Jul 2019 12:52:00 +0000 (14:52 +0200)]
tests: qemustatusxml: Add few disks with backing chains for blockdev job testing

Add 4 disks to the blockjob-blockdev-in.xml test case to allow adding
data for block pull, block copy, block commit, and active block commit
jobs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Use proper value when setting disk's READY state
Peter Krempa [Wed, 24 Jul 2019 20:44:11 +0000 (22:44 +0200)]
qemu: blockjob: Use proper value when setting disk's READY state

Commit c412383796c used a value from wrong enum when setting the disk's
mirrorState variable. This meant that a 'READY' job would show up as
'PIVOTING'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: blockjob: Reset 'synchronous' block job handling flag prior to flushing events
Peter Krempa [Mon, 22 Jul 2019 16:15:38 +0000 (18:15 +0200)]
qemu: blockjob: Reset 'synchronous' block job handling flag prior to flushing events

When returning to asynchronous block job handling the flag which
determines the handling method should be reset prior to flushing
outstanding events. If there's an event to process the handler may
invoke the monitor and another event may be received. We'd not process
that one. Reset the flag earlier.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Initialize data for inactive config of snapshot earlier
Peter Krempa [Mon, 22 Jul 2019 16:40:25 +0000 (18:40 +0200)]
qemu: snapshot: Initialize data for inactive config of snapshot earlier

qemuDomainSnapshotDiskDataCollect copies the source of the disk from the
live config into the inactive config. Move this operation earlier so
that if we initialize it for use for the particular instance the
run-time-only data is not copied.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Use simple backing stores string format if possible
Peter Krempa [Mon, 22 Jul 2019 15:36:05 +0000 (17:36 +0200)]
qemu: block: Use simple backing stores string format if possible

In case when the backing store can be represented with something
simpler such as a URI we can use it rather than falling back to the
json: pseudo-protocol.

In cases when it's not worth it (e.g. with the old ugly NBD or RBD
strings) let's switch to json.

The function is exported as we'll need it when overwriting the ugly
strings qemu would come up with during blockjobs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virStorageSourceIsEmpty in qemuDomainBlockCommit
Peter Krempa [Mon, 22 Jul 2019 11:53:59 +0000 (13:53 +0200)]
qemu: Use virStorageSourceIsEmpty in qemuDomainBlockCommit

The block commit API checked 'disk->src->path' to see whether there
is a reasonable disk source to be committed. As the top image can be
e.g. backed by NBD the check is not good enough. Replace it by
virStorageSourceIsEmpty.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Add helper for generating snapshot transaction for -blockdev
Peter Krempa [Fri, 7 Sep 2018 09:33:54 +0000 (11:33 +0200)]
qemu: block: Add helper for generating snapshot transaction for -blockdev

For the modern use cases we are going to use 'blockdev-snapshot' instead
of 'blockdev-snapshot-sync'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add possibility to prepare top image only for attachment via blockdev
Peter Krempa [Mon, 22 Jul 2019 08:35:09 +0000 (10:35 +0200)]
qemu: Add possibility to prepare top image only for attachment via blockdev

qemuBuildStorageSourceChainAttachPrepareBlockdev prepares the full
backing chain for attachment via blockdev. For snapshots we'll need to
prepare one image only as it needs to be plugged on top of the existing
chain.

This patch introduces qemuBuildStorageSourceChainAttachPrepareBlockdevTop
which prepares only @top similarly to the original function by splitting
out the functionality into an internal function so that the API does not
change.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: command: Fix function name in comment
Peter Krempa [Mon, 22 Jul 2019 08:20:10 +0000 (10:20 +0200)]
qemu: command: Fix function name in comment

In commit 042c95bd194 qemuBuildStorageSourceChainAttachPrepareBlockdev
was added but the comment for the function mentions
qemuBuildStorageSourceChainAttachPrepareDrive. Fix the mistake.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Remove semi-stale comment about asynchronous job abort
Peter Krempa [Thu, 18 Jul 2019 16:31:43 +0000 (18:31 +0200)]
qemu: driver: Remove semi-stale comment about asynchronous job abort

Now that we track the job separately we watch only for the abort of the
one single block job so the comment is no longer accurate. Also
describing asynchronous operation is not really necessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>