]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 years agoqemu: Remove stale comment outlining how to extend qemuDomainBlockPivot
Peter Krempa [Tue, 12 Feb 2019 14:12:03 +0000 (15:12 +0100)] 
qemu: Remove stale comment outlining how to extend qemuDomainBlockPivot

With -blockdev:

- we track the job and check it after restart
- have the ability to ask qemu to persist it to collect result
- have the ability to report errors.

This solves all points the comment outlined so remove it. Also all jobs
handle the disk state modification along with the event so there's
nothing special the comment says.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Blockdevize qemuDomainBlockJobAbort/Pivot
Peter Krempa [Fri, 25 Jan 2019 11:48:53 +0000 (12:48 +0100)] 
qemu: driver: Blockdevize qemuDomainBlockJobAbort/Pivot

Use job-complete/job-abort instead of the blockjob-* variants for
blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Report error if pivoting fails in qemuDomainBlockJobAbort
Peter Krempa [Thu, 18 Jul 2019 16:31:40 +0000 (18:31 +0200)] 
qemu: driver: Report error if pivoting fails in qemuDomainBlockJobAbort

As the error message is now available and we know whether the job failed
we can report an error straight away rather than having the user check
the event.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Use QEMU_BLOCKJOB_STATE_PIVOTING/ABORTING in qemuDomainBlockJobAbort
Peter Krempa [Tue, 12 Feb 2019 13:50:24 +0000 (14:50 +0100)] 
qemu: Use QEMU_BLOCKJOB_STATE_PIVOTING/ABORTING in qemuDomainBlockJobAbort

Set the correct job states after the operation is requested in qemu.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add block job states for abort and pivot operations
Peter Krempa [Mon, 11 Feb 2019 13:36:24 +0000 (14:36 +0100)] 
qemu: blockjob: Add block job states for abort and pivot operations

When initiating a pivot or abort of a block job we need to track which
one was initiated. Currently it was done via data stashed in
virDomainDiskDef. Add possibility to track this also together with the
job itself.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Make checks in qemuDomainBlockPivot depend on data of the job
Peter Krempa [Tue, 12 Feb 2019 12:29:46 +0000 (13:29 +0100)] 
qemu: Make checks in qemuDomainBlockPivot depend on data of the job

Do decisions based on the configuration of the job rather than the data
stored with the disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: blockdevize qemuDomainGetBlockJobInfo
Peter Krempa [Fri, 31 May 2019 16:51:05 +0000 (18:51 +0200)] 
qemu: driver: blockdevize qemuDomainGetBlockJobInfo

Use the stored job name rather than passing in the disk alias when
referring to the job which allows the same code to work also when
-blockdev will be used.

Note that this API does not require the change to use 'query-job' as it
will ever only work with blockjobs bound to disks due to the arguments
which allow only referring to a disk. For the disk-less jobs we'll need
to add a separate API later.

The change to qemuMonitorGetBlockJobInfo is required as the API was
stripping the 'drive-' prefix when returning the data which is not
desired any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovircgroupv2: remove ATTRIBUTE_UNUSED for used attribute
Pavel Hrdina [Mon, 22 Jul 2019 12:46:34 +0000 (14:46 +0200)] 
vircgroupv2: remove ATTRIBUTE_UNUSED for used attribute

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agovircgroupv2: store enabled controllers
Pavel Hrdina [Mon, 22 Jul 2019 12:44:05 +0000 (14:44 +0200)] 
vircgroupv2: store enabled controllers

In cgroups v2 when a new group is created by default no controller is
enabled so the detection code will not detect any controllers.

When enabling the controllers we should also store them for the group.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agovircgroup: fix cgroups v2 controllers detection
Pavel Hrdina [Mon, 22 Jul 2019 12:37:36 +0000 (14:37 +0200)] 
vircgroup: fix cgroups v2 controllers detection

When creating new group for cgroups v2 the we cannot check
cgroups.controllers for that cgroup because the directory is created
later.  In that case we should check cgroups.subtree_control of parent
group to get list of controllers enabled for child cgroups.

In order to achieve that we will prefer the parent group if it exists,
the current group will be used only for root group.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: optparse: Use --config with the setmaxmem command
Erik Skultety [Thu, 25 Jul 2019 07:35:01 +0000 (09:35 +0200)] 
tests: optparse: Use --config with the setmaxmem command

The virsh-optparse test broke after commit 6ac402c456a because it
always assumed the max memory limit can be adjusted on a running domain
which used to be the case in the old code.
This is only a hot fix for the CI build. The proper fix here is to
re-write the whole test in a self-test/unit-test manner where we only
test virsh's ability to parse various values, not running actual
commands.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agotest_driver: Fix testDomainSetMemoryFlags' behaviour on config change
Erik Skultety [Thu, 25 Jul 2019 07:29:36 +0000 (09:29 +0200)] 
test_driver: Fix testDomainSetMemoryFlags' behaviour on config change

When commit 6ac402c456a added the API whenever VIR_DOMAIN_MEM_MAXIMUM
was passed the code always checked whether the domain was active and
therefore failed with an error even though only a config change was
requested. Fix the issue by replacing virDomainObjGetOneDef with
virDomainObjGetOneDefState which tells us what definition we're
performing the change on.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: cgroup: Add missing parameter maxthreads to virCgroupNewMachine
Erik Skultety [Thu, 25 Jul 2019 07:51:50 +0000 (09:51 +0200)] 
util: cgroup: Add missing parameter maxthreads to virCgroupNewMachine

Commit d5572f62e32 forgot to add maxthreads to the non-Linux definition
of the function, thus breaking the MinGW build.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
6 years agosnapshot: Documentation and comment improvements
Eric Blake [Fri, 12 Jul 2019 20:43:01 +0000 (15:43 -0500)] 
snapshot: Documentation and comment improvements

Changes noticed while copying to similar aspects of checkpoints.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosnapshot: Saner error message for duplicate create
Eric Blake [Wed, 24 Jul 2019 05:03:24 +0000 (00:03 -0500)] 
snapshot: Saner error message for duplicate create

Any message that is easy to trigger (as evidenced by the testsuite
update) should not use 'internal error' as its category.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosnapshot: Don't leak moment obj list metaroot to callers
Eric Blake [Wed, 24 Jul 2019 03:26:05 +0000 (22:26 -0500)] 
snapshot: Don't leak moment obj list metaroot to callers

virDomainSnapshotFindByName(list, NULL) should return NULL, rather
than the internal-use-only metaroot.  Most existing callers pass in a
non-NULL name; the few external callers that don't are immediately
calling virDomainMomentSetParent (which indeed needs the metaroot
rather than NULL if the parent name is NULL); but as the leaky
abstraction is ugly, it is worth instead making
virDomainMomentSetParent static and adding a new function for
resolving the parent link of a brand new moment within its list.  The
existing external uses of virDomainMomentSetParent always succeed
(either the new moment has parent_name of NULL to become a new root,
or has parent_name set to a strdup of the previous current moment);
hence, our new function does not need a return value (but it still has
a VIR_WARN in case future uses break our assumptions about failure
being impossible).

Missed when commit 02c4e24d refactored things to attempt to remove
direct metaroot manipulations out of the qemu and test drivers into
internal-only details, and made more obvious when commit dc8d3dc6
factored it out into a separate file.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: Add support for overriding max threads per process limit
Jim Fehlig [Wed, 22 May 2019 23:12:14 +0000 (17:12 -0600)] 
qemu: Add support for overriding max threads per process limit

Some VM configurations may result in a large number of threads created by
the associated qemu process which can exceed the system default limit. The
maximum number of threads allowed per process is controlled by the pids
cgroup controller and is set to 16k when creating VMs with systemd's
machined service. The maximum number of threads per process is recorded
in the pids.max file under the machine's pids controller cgroup hierarchy,
e.g.

$cgrp-mnt/pids/machine.slice/machine-qemu\\x2d1\\x2dtest.scope/pids.max

Maximum threads per process is controlled with the TasksMax property of
the systemd scope for the machine. This patch adds an option to qemu.conf
which can be used to override the maximum number of threads allowed per
qemu process. If the value of option is greater than zero, it will be set
in the TasksMax property of the machine's scope after creating the machine.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotest_driver: testDomainSetMaxMemory should simply forward the call
Ilias Stamatis [Fri, 12 Jul 2019 05:55:35 +0000 (07:55 +0200)] 
test_driver: testDomainSetMaxMemory should simply forward the call

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: testDomainSetMemory should forward the call with VIR_DOMAIN_AFFECT_LIVE
Ilias Stamatis [Fri, 12 Jul 2019 05:55:34 +0000 (07:55 +0200)] 
test_driver: testDomainSetMemory should forward the call with VIR_DOMAIN_AFFECT_LIVE

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: consider flags in testDomainSetMemoryFlags
Ilias Stamatis [Fri, 12 Jul 2019 05:55:33 +0000 (07:55 +0200)] 
test_driver: consider flags in testDomainSetMemoryFlags

Update the current or max memory, on the persistent or live definition
depending on the flags which are currently ignored.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: implement virDomainSetNumaParameters
Ilias Stamatis [Wed, 24 Jul 2019 14:31:34 +0000 (16:31 +0200)] 
test_driver: implement virDomainSetNumaParameters

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: implement virConnectSupportsFeature
Ilias Stamatis [Wed, 24 Jul 2019 14:31:33 +0000 (16:31 +0200)] 
test_driver: implement virConnectSupportsFeature

Make the test driver only support the VIR_TYPED_PARAM_STRING flag for
now.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: implement virDomainSetInterfaceParameters
Ilias Stamatis [Wed, 24 Jul 2019 14:07:29 +0000 (16:07 +0200)] 
test_driver: implement virDomainSetInterfaceParameters

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: implement virDomainInjectNMI
Ilias Stamatis [Thu, 18 Jul 2019 10:29:53 +0000 (12:29 +0200)] 
test_driver: implement virDomainInjectNMI

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotest_driver: implement virDomainSetMemoryStatsPeriod
Ilias Stamatis [Thu, 11 Jul 2019 11:22:02 +0000 (13:22 +0200)] 
test_driver: implement virDomainSetMemoryStatsPeriod

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agotests: Avoid possible error in testExecRestart
John Ferlan [Tue, 23 Jul 2019 12:14:50 +0000 (08:14 -0400)] 
tests: Avoid possible error in testExecRestart

If the dup2 fails, then we aren't going to get the correct result.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Avoid possible error in virCommandMassClose
John Ferlan [Tue, 23 Jul 2019 12:12:48 +0000 (08:12 -0400)] 
util: Avoid possible error in virCommandMassClose

Avoid the chance that sysconf(_SC_OPEN_MAX) returns -1 and thus
would cause virBitmapNew would attempt to allocate a very large
bitmap.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agotest: Return early in testQueryJobs
John Ferlan [Tue, 23 Jul 2019 12:09:19 +0000 (08:09 -0400)] 
test: Return early in testQueryJobs

Avoid the chance that qemuMonitorTestNewSimple could return NULL

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: Remove unnecessary check in qemuMonitorJSONGetJobInfoOne
John Ferlan [Tue, 23 Jul 2019 12:03:21 +0000 (08:03 -0400)] 
qemu: Remove unnecessary check in qemuMonitorJSONGetJobInfoOne

It's already dereffed in the initialization and shouldn't be NULL
unless virJSONValueArraySize after a virJSONValueObjectGetArray
could return a NULL data entry.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agovirsh migrate: Properly check for --parallel-connections
Jiri Denemark [Fri, 19 Jul 2019 13:46:33 +0000 (15:46 +0200)] 
virsh migrate: Properly check for --parallel-connections

Ever since --parallel-connections option for virsh migrate was
introduced we did not properly check the return value of
vshCommandOptInt. We would set VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS
parameter even if vshCommandOptInt returned 0 (which means
--parallel-connections was not specified) when another int option which
was checked earlier was specified with a nonzero value.

Specifically, running virsh migrate with either
--auto-converge-increment, --auto-converge-initial, --comp-mt-dthreads,
--comp-mt-threads, or --comp-mt-level would set
VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS parameter and if --parallel
option was not used, libvirt would complain

    error: invalid argument: Turn parallel migration on to tune it

even though --parallel-connections option was not used at all.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu: driver: Add debug message when we conjure block job data object
Peter Krempa [Thu, 18 Jul 2019 16:17:50 +0000 (18:17 +0200)] 
qemu: driver: Add debug message when we conjure block job data object

Report in logs when we don't find existing block job data and create it
just to handle the job.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Don't use qemuBlockJobStartupFinalize in processBlockJobEvent
Peter Krempa [Thu, 18 Jul 2019 16:14:44 +0000 (18:14 +0200)] 
qemu: driver: Don't use qemuBlockJobStartupFinalize in processBlockJobEvent

While this function does start a block job in case when we'd not be able
to get our internal data for it, the handler sets the job state to
QEMU_BLOCKJOB_STATE_RUNNING anyways, thus qemuBlockJobStartupFinalize
would just unref the job.

Since the other usage of qemuBlockJobStartupFinalize in the other part
of the event handler was a bug replace this one anyways even if it would
not cause problems.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: process: Don't use qemuBlockJobStartupFinalize in qemuProcessHandleBlockJob
Peter Krempa [Thu, 18 Jul 2019 16:08:11 +0000 (18:08 +0200)] 
qemu: process: Don't use qemuBlockJobStartupFinalize in qemuProcessHandleBlockJob

The block job event handler qemuProcessHandleBlockJob looks at the block
job data to see whether the job requires synchronous handling. Since the
block job event may arrive before we continue the job handling (if the
job has no data to copy) we could hit the state when the job is still
set as QEMU_BLOCKJOB_STATE_NEW (as we move it to the
QEMU_BLOCKJOB_STATE_RUNNING state only after returning from monitor).

If the event handler uses qemuBlockJobStartupFinalize it would
unregister and free the job. Thankfully this is not a big problem for
legacy blockjobs as we don't need much data for them but since we'd
re-instantiate the job data structure we'd report wrong job type for
active commit as qemu reports it as a regular commit job.

Fix it by not using qemuBlockJobStartupFinalize function in
qemuProcessHandleBlockJob as it is not starting the job anyways.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: change the return value of virCgroupRemove if failed
Wang Yechao [Fri, 19 Jul 2019 03:19:38 +0000 (11:19 +0800)] 
util: change the return value of virCgroupRemove if failed

virCgroupRemove return -1 when removing cgroup failed.
But there are retry code to remove cgroup in QemuProcessStop:

 retry:
    if ((ret = qemuRemoveCgroup(vm)) < 0) {
        if (ret == -EBUSY && (retries++ < 5)) {
            usleep(200*1000);
            goto retry;
        }
        VIR_WARN("Failed to remove cgroup for %s",
                 vm->def->name);
    }

The return value of qemuRemoveCgroup will never be equal to "-EBUSY",
so change the return value of virCgroupRemove if failed.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoremote: increase daemon shutdown timer to 2 minutes
Daniel P. Berrangé [Thu, 18 Jul 2019 14:50:42 +0000 (15:50 +0100)] 
remote: increase daemon shutdown timer to 2 minutes

Shutting down the daemon after 30 seconds of being idle is a little bit
too aggressive. Especially when using 'virsh' in single-shot mode, as
opposed to interactive shell mode, it would not be unusual to have
more than 30 seconds between commands. This will lead to the daemon
shutting down and starting up between a series of commands.

Increasing the shutdown timer to 2 minutes will make it less likely that
the daemon will shutdown while the user is in the middle of a series of
commands.

Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agologging: pass binary name not logfile name when enabling logging
Daniel P. Berrangé [Fri, 21 Jun 2019 15:40:02 +0000 (16:40 +0100)] 
logging: pass binary name not logfile name when enabling logging

Instead of having each caller pass in the desired logfile name, pass in
the binary name instead. The logging code can then just derive a logfile
name by appending ".log".

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: mention new bochs display device
Jonathon Jongsma [Thu, 18 Jul 2019 19:16:46 +0000 (14:16 -0500)] 
news: mention new bochs display device

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirfile: Add Quobyte as a shared fs
Silvan Kaiser [Tue, 28 May 2019 12:55:29 +0000 (14:55 +0200)] 
virfile: Add Quobyte as a shared fs

This adds detection of a Quobyte as a shared file system for live
migration.

Signed-off-by: Silvan Kaiser <silvan@quobyte.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirpci: Drop duplicate function
Michal Privoznik [Thu, 18 Jul 2019 18:28:15 +0000 (20:28 +0200)] 
virpci: Drop duplicate function

We have two functions: virPCIDeviceAddressIsEqual() defined only
on Linux and virPCIDeviceAddressEqual() defined everywhere. And
both of them do the same. Drop the former in favour of the
latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: blockjob: Adjust ATTRIBUTE_NONNULL statements for qemuBlockJobDiskNew
Peter Krempa [Fri, 19 Jul 2019 06:47:39 +0000 (08:47 +0200)] 
qemu: blockjob: Adjust ATTRIBUTE_NONNULL statements for qemuBlockJobDiskNew

Commit 5ff46aaa7f added a new parameter but neglected to fix the NONNULL
declarations.

Reported-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: Fix broken MinGW builds caused by commit 9bc01ad8
Erik Skultety [Fri, 19 Jul 2019 06:10:12 +0000 (08:10 +0200)] 
util: Fix broken MinGW builds caused by commit 9bc01ad8

virPCIGetSysfsFile is conditionally compiled only on Linux platforms.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: hotplug: Transfer ownership of backing chain to block job on disk unplug
Peter Krempa [Mon, 25 Mar 2019 15:30:28 +0000 (16:30 +0100)] 
qemu: hotplug: Transfer ownership of backing chain to block job on disk unplug

When removing the disk fronted while any block job is still active we
need to transfer the ownership of the backing chain to the job itself as
the job still holds the reference to the chain members and thus attempts
to remove them would fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Unplug inherited storage chains when concluding blockjob
Peter Krempa [Fri, 29 Mar 2019 07:47:38 +0000 (08:47 +0100)] 
qemu: blockjob: Unplug inherited storage chains when concluding blockjob

In cases when the disk frontend was unplugged while a blockjob was
running the blockjob inherits the backing chain. When the blockjob is
then terminated we need to unplug the chain as it will not be used any
more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Detect managed persistent reservations in block job orphan chains
Peter Krempa [Thu, 21 Mar 2019 12:54:20 +0000 (13:54 +0100)] 
qemu: Detect managed persistent reservations in block job orphan chains

The PR manager is a property of the format layer in qemu so we need to
be able to track it also in the chains of orphaned block jobs.

Add a helper for qemu to look also into the blockjob state.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Track orphaned backing chains in blockjob status XML
Peter Krempa [Tue, 19 Mar 2019 06:54:12 +0000 (07:54 +0100)] 
qemu: blockjob: Track orphaned backing chains in blockjob status XML

When the guest unplugs the disk frontend libvirt is responsible for
deleting the backend. Since a blockjob may still have a reference to the
backing chain when it is running we'll have to store the metadata for
the unplugged disk for future reference.

This patch adds 'chain' and 'mirrorChain' fields to 'qemuBlockJobData'
to keep them around with the job along with status XML machinery and
tests. Later patches will then add code to change the ownership of the
chain when unplugging the disk backend.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: export virDomainDiskBackingStoreFormat
Peter Krempa [Thu, 21 Mar 2019 09:29:53 +0000 (10:29 +0100)] 
conf: export virDomainDiskBackingStoreFormat

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: export virDomainDiskBackingStoreParse
Peter Krempa [Thu, 21 Mar 2019 09:16:36 +0000 (10:16 +0100)] 
conf: export virDomainDiskBackingStoreParse

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: process: Refresh -blockdev based blockjobs on reconnect to qemu
Peter Krempa [Tue, 11 Dec 2018 17:13:35 +0000 (18:13 +0100)] 
qemu: process: Refresh -blockdev based blockjobs on reconnect to qemu

Refresh the state of the jobs and process any events that might have
happened while libvirt was not running.

The job state processing requires some care to figure out if a job
needs to be bumped.

For any invalid job try doing our best to cancel it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add modern block job event handler
Peter Krempa [Fri, 7 Dec 2018 09:21:22 +0000 (10:21 +0100)] 
qemu: blockjob: Add modern block job event handler

Add the infrastructure to handle block job events in the -blockdev era.

Some complexity is required as qemu does not bother to notify whether
the job was concluded successfully or failed. Thus it's necessary to
re-query the monitor.

To minimize the possibility of stuck jobs save the state into the XML
prior to handling everything so that the reconnect code can potentially
continue with the cleanup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add handler for job state change event
Peter Krempa [Wed, 5 Dec 2018 09:40:45 +0000 (10:40 +0100)] 
qemu: Add handler for job state change event

Add support for handling the event either synchronously or
asynchronously using the event thread.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add helper to convert monitor job status to internal state
Peter Krempa [Mon, 10 Dec 2018 15:56:53 +0000 (16:56 +0100)] 
qemu: blockjob: Add helper to convert monitor job status to internal state

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: process: Don't trigger BLOCK_JOB* events with -blockdev
Peter Krempa [Wed, 5 Sep 2018 14:16:17 +0000 (16:16 +0200)] 
qemu: process: Don't trigger BLOCK_JOB* events with -blockdev

With blockdev we'll need to use the JOB_STATUS_CHANGE so gate the old
events by the blockdev capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add 'concluded' state for a block job
Peter Krempa [Fri, 7 Dec 2018 16:40:30 +0000 (17:40 +0100)] 
qemu: blockjob: Add 'concluded' state for a block job

This new state is entered when qemu finished the job but libvirt does
not know whether it was successful or not.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemustatusxml2xml: Add test case for block job tracking
Peter Krempa [Fri, 30 Nov 2018 16:40:40 +0000 (17:40 +0100)] 
tests: qemustatusxml2xml: Add test case for block job tracking

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Remove unnecessary saving of status XML
Peter Krempa [Wed, 15 May 2019 09:07:53 +0000 (11:07 +0200)] 
qemu: driver: Remove unnecessary saving of status XML

Now that the blockjob handling code deals with the status XML we don't
need to save it explicitly when starting blockjobs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Save status XML when modifying job state
Peter Krempa [Wed, 15 May 2019 08:58:42 +0000 (10:58 +0200)] 
qemu: blockjob: Save status XML when modifying job state

Now that block job data is stored in the status XML portion we need to
make sure that everything which changes the state also saves the status
XML. The job registering function is used while parsing the status XML
so in that case we need to skip the XML saving.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Store blockjob data in the status XML
Peter Krempa [Fri, 30 Nov 2018 09:36:22 +0000 (10:36 +0100)] 
qemu: domain: Store blockjob data in the status XML

We need to store the block job state in the status XML so that we can
properly recover any data when reconnecting after startup and also in
the end to be able to do any transition of the backing chain that
happened while libvirt was not connected to the monitor.

First step is to note the name, type, state and corresponding disk into
the status XML.

We also need to make sure that a broken blockjob does not make libvirt
lose the VM, thus many of the errors just mark the job as invalid.
Later on we'll cancel all invalid jobs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add flag for invalid block job data
Peter Krempa [Fri, 5 Jul 2019 07:02:21 +0000 (09:02 +0200)] 
qemu: blockjob: Add flag for invalid block job data

The job data saved in the XML may be partially invalid e.g. if something
is missing. To prevent losing a domain with such a job add a flag to the
job data so that job APIs can ignore such a job and we can just cancel
it.

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