]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
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>
6 years agoqemu: blockjob: Export functions for allocating and registering job data
Peter Krempa [Mon, 1 Jul 2019 15:36:38 +0000 (17:36 +0200)] 
qemu: blockjob: Export functions for allocating and registering job data

When parsing the status XML we need to register all existing jobs.
Export the functions so that they are usable in other modules.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Add string convertors for blockjob type and state enums
Peter Krempa [Fri, 30 Nov 2018 15:55:08 +0000 (16:55 +0100)] 
qemu: blockjob: Add string convertors for blockjob type and state enums

Later on we'll format these values into the status XML so the from/to
string functions will come handy. The implementation also notes that
these will be used in the status XML to avoid somebody changing the
values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Register new and running blockjobs in the global table
Peter Krempa [Thu, 29 Nov 2018 16:35:52 +0000 (17:35 +0100)] 
qemu: blockjob: Register new and running blockjobs in the global table

Add the job structure to the table when instantiating a new job and
remove it when it terminates/fails.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Add global table of blockjobs
Peter Krempa [Thu, 29 Nov 2018 11:50:09 +0000 (12:50 +0100)] 
qemu: domain: Add global table of blockjobs

Block jobs currently belong to disks only so we can look up the block
job data for them in the corresponding disks. This won't be the case
when using blockdev as certain jobs don't even correspond to a disk and
most of them can run on a part of the backing chain.

Add a global table of blockjobs which can be used to look up the data
for the blockjobs when the job events need to be processed.

The table is a hash table organized by job name and has a reference to
the job. New and running jobs will later be added to this table.
Reference counting will allow to reap job state for synchronous callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Update new job state earlier in qemuBlockJobEventProcessLegacy
Peter Krempa [Wed, 17 Jul 2019 14:00:32 +0000 (16:00 +0200)] 
qemu: blockjob: Update new job state earlier in qemuBlockJobEventProcessLegacy

The legacy job handler does not look at the old job state so we can
update it earlier.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Save config only in qemuBlockJobEventProcessLegacyCompleted
Peter Krempa [Wed, 17 Jul 2019 13:39:57 +0000 (15:39 +0200)] 
qemu: blockjob: Save config only in qemuBlockJobEventProcessLegacyCompleted

There's no need to do it if the job is not completed. The new helper
allows to do this with much less hassle in the correct place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Separate and unify block job (un)registration
Peter Krempa [Thu, 27 Jun 2019 15:54:24 +0000 (17:54 +0200)] 
qemu: blockjob: Separate and unify block job (un)registration

Rename and move qemuBlockJobTerminate to qemuBlockJobUnregister and
separate bits from qemuBlockJobDiskNew which register the job with the
disk. This creates an unified interface for other APIs to use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: blockjob: Use VIR_AUTOUNREF in qemuBlockJobDataNew
Peter Krempa [Wed, 26 Jun 2019 12:50:25 +0000 (14:50 +0200)] 
qemu: blockjob: Use VIR_AUTOUNREF in qemuBlockJobDataNew

Simplify error paths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Add helper for saving config XML
Peter Krempa [Thu, 4 Jul 2019 16:51:36 +0000 (18:51 +0200)] 
qemu: domain: Add helper for saving config XML

Similarly to qemuDomainSaveStatus add a helper to save the config XML
named qemuDomainSaveConfig.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Repurpose and export helper for saving domain status XML
Peter Krempa [Thu, 27 Jun 2019 13:40:39 +0000 (15:40 +0200)] 
qemu: domain: Repurpose and export helper for saving domain status XML

Rename qemuDomainObjSaveJob and create a wrapper for it which does not
require 'driver' to be passed and export it so that other palces can
easily save the status XML without having to invoke virDomainSaveStatus
which has unpleasing parameters.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemublock: Add testing of 'blockdev-create' generators
Peter Krempa [Tue, 4 Sep 2018 11:40:01 +0000 (13:40 +0200)] 
tests: qemublock: Add testing of 'blockdev-create' generators

Test the output against the schema and also against what we expect.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: snapshot: Provide a function to free virDomainSnapshotDiskDefPtr
Peter Krempa [Tue, 4 Sep 2018 14:02:43 +0000 (16:02 +0200)] 
conf: snapshot: Provide a function to free virDomainSnapshotDiskDefPtr

Tests will need to parse such a definition so it also needs to be freed.
Provide a function for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: snapshot: Export virDomainSnapshotDiskDefParseXML
Peter Krempa [Tue, 4 Sep 2018 13:42:42 +0000 (15:42 +0200)] 
conf: snapshot: Export virDomainSnapshotDiskDefParseXML

Allow using it from the tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Export qemuDomainPrepareStorageSourceBlockdev
Peter Krempa [Tue, 9 Oct 2018 09:06:39 +0000 (11:06 +0200)] 
qemu: domain: Export qemuDomainPrepareStorageSourceBlockdev

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: block: Add generator for creating storage with blockdev-create
Peter Krempa [Thu, 6 Sep 2018 07:09:55 +0000 (09:09 +0200)] 
qemu: block: Add generator for creating storage with blockdev-create

QEMU allows us to create storage on certain network protocols which
allow image creation through their API. Wire up the generator for using
it with libvirt as well as for local files.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: block: Add generator for image format creation properties
Peter Krempa [Mon, 3 Sep 2018 18:08:07 +0000 (20:08 +0200)] 
qemu: block: Add generator for image format creation properties

'blockdev-add' allows us to use qemu to format images to our desired
format. This patch implements helpers which convert a
virStorageSourcePtr into JSON objects describing the required
configuration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: block: Use 'auto-read-only' instead of 'read-only' for backing chain
Peter Krempa [Tue, 4 Sep 2018 17:29:10 +0000 (19:29 +0200)] 
qemu: block: Use 'auto-read-only' instead of 'read-only' for backing chain

To allow using -blockdev with blockjobs QEMU needs to reopen files in
read-write mode when modifying the backing chain. To achieve this we
need to use 'auto-read-only' for the backing files rather than the
normal 'read-only' property. That way qemu knows that the files need to
be reopened.

Note that the format drivers (e.g. qcow2) are still opened with the
read-only property enabled when being a member of the backing chain
since they are supposed to be immutable unless a block job is started.

QEMU v4.0 (since commit 23dece19da4) allows also dynamic behaviour for
auto-read-only which allows us to use sVirt as we only grant write
permissions to files when doing a blockjob.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: block: Extract formatting of 'driver' attribute from child formatters
Peter Krempa [Tue, 5 Feb 2019 15:03:39 +0000 (16:03 +0100)] 
qemu: block: Extract formatting of 'driver' attribute from child formatters

To allow reusing the formatters in the code for creating JSON properties
for 'blockdev-create' we need to create everything except the 'driver'
attribute.

Use the new helper virJSONValueObjectPrependString to put the driver at
the same place so that we don't change any output.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: json: Introduce helper to prepend string into a virJSONValueObject
Peter Krempa [Tue, 5 Feb 2019 17:45:05 +0000 (18:45 +0100)] 
util: json: Introduce helper to prepend string into a virJSONValueObject

Libvirt treats the JSON objects as lists thus the values appear in the
order they were added. To avoid too much changes introduce a helper
which allows to prepend a string which will allow to keep certain
outputs in order.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemublock: Add testing of pure disk source specification JSON generator
Peter Krempa [Mon, 17 Dec 2018 15:29:05 +0000 (16:29 +0100)] 
tests: qemublock: Add testing of pure disk source specification JSON generator

Add testing of the host specification part so that we can be sure that
no image/host specific data will be present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: block: Allow skipping non-target related data when formating disk JSON
Peter Krempa [Tue, 4 Sep 2018 16:52:02 +0000 (18:52 +0200)] 
qemu: block: Allow skipping non-target related data when formating disk JSON

When formatting new qcow2 images we need to provide the backing store
string which should not contain any authentication or irrelevant data.

Add a flag for qemuBlockStorageSourceGetBackendProps which allows to
skip the irrelevant data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: monitor: Add APIs for 'blockdev-create'
Peter Krempa [Mon, 3 Sep 2018 12:45:16 +0000 (14:45 +0200)] 
qemu: monitor: Add APIs for 'blockdev-create'

The 'blockdev-create' starts a job which creates a storage volume using
the given protocol or formats an existing (added) volume with one of the
supported storage formats.

This patch adds the monitor interaction bits.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: monitor: Implement support for 'JOB_STATUS_CHANGE' event
Peter Krempa [Tue, 4 Dec 2018 16:57:23 +0000 (17:57 +0100)] 
qemu: monitor: Implement support for 'JOB_STATUS_CHANGE' event

This new event is a superset of the BLOCK_JOB* events and also covers
jobs which don't bind to a VM disk.

In this patch the monitor part is implemented.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: monitor: Add infrastructure for 'query-jobs'
Peter Krempa [Tue, 4 Dec 2018 16:58:38 +0000 (17:58 +0100)] 
qemu: monitor: Add infrastructure for 'query-jobs'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: monitor: Add support for 'job-complete' command
Peter Krempa [Thu, 16 Aug 2018 09:48:41 +0000 (11:48 +0200)] 
qemu: monitor: Add support for 'job-complete' command

This belongs to the new job management API which can manage also
non-block based jobs.

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