Commit Graph

8849 Commits

Author SHA1 Message Date
Peter Krempa
a3f8abb003 qemu: Add -blockdev support for external snapshots
Use the code for creating or attaching new storage source in the
snapshot code and switch to 'blockdev-snapshot' for creating the
snapshot itself.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
b2904cb87b qemu: snapshot: Skip overlay file creation/interogation if unsupported
With blockdev we'll be able to support protocols which are not supported
by the storage backends in libvirt. This means that we have to be able
to skip the creation and relative storage path reading if it's not
supported. This will make it impossible to use relative backing for
network protocols but that would be almost insane anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
e3189f7c0a qemu: Merge use of 'reuse' flag in qemuDomainSnapshotDiskPrepareOne
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
fd8e55ca93 qemu: Disband qemuDomainSnapshotCreateSingleDiskActive
After we always assume support for the 'transaction' command
(c358adc571) and follow-up cleanups
qemuDomainSnapshotCreateSingleDiskActive lost its value. Move the code
into appropriate helpers and remove the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
0d1622a1f4 qemu: snapshot: Rename external disk snapshot handling functions
Fix and unify the naming of external snapshot preparation functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
e1b61f2cd5 qemu: snapshot: Move error preservation to qemuDomainSnapshotDiskDataCleanup
Make qemuDomainSnapshotDiskDataCleanup cleanup section friendly by
moving the error preservation code inside it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
93a0f72ef4 qemu: snapshot: Save status and config XMLs only on success
We changed to always saving the status and config XMLs to simplify
code. After a few more refactors it's now possible to move it to the
appropriate place and save the XMLs only on success again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
e0720fda12 qemu: snapshot: Fix image lock handling when taking a snapshot
When we take a snapshot we must properly remove our locking
infrastructure locks. This was broken by commit 3817fa10c4 which
attempted to properly track the readonly state for the image as the
locking code was executed after this change. Since we forced the image
which was locked as read-write to read-only prior to unlocking it the
write lock was not dropped.

Fix it by moving the locking code prior to modifying the readonly flag.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
805b4aa2e9 qemu: driver: Fix shallow non-reuse block copy
The code preparing data for creating/attaching the target image of block
copy didn't use the correct reference to the existing backing chain in
case when the copy should inherit it. This meant that qemu actually
opened a second copy of the chain and operated on that.

This would de-sync qemu from libvirt's view of node names. Luckily this
is only hypothetical at this point since it happens only when -blockdev
is enabled.

Fix it by passing 'mirrorBacking' which has the proper data as the
backing store when calling
qemuBuildStorageSourceChainAttachPrepareBlockdevTop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
b5e7460b23 qemu: Explicitly pass backing store to qemuBuildStorageSourceChainAttachPrepareBlockdevTop
In some cases we'll need to pass in a backing store which is not
recorded as the backing store of @src. Export backingStore as variable
and fix all callers to pass in the backing store. No semantic changes
for now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
7b47a8f814 qemu: block: explicitly pass backing store to qemuBlockStorageSourceAttachPrepareBlockdev
Pass backing store as an argument rather than extracting it locally and
fix the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
eee85c2349 qemu: command: Refactor qemuBuildStorageSourceChainAttachPrepareBlockdevInternal
Extract the loop and supporting infrastructure to the caller as only one
of the two callers actually cares about looping and rename the helper to
qemuBuildStorageSourceChainAttachPrepareBlockdevOne.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
a7643da82e qemu: block: Explicitly specify backingStore when creating format layer props
Pass in backing store explicitly to qemuBlockStorageSourceGetBlockdevProps
and fix the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
d6f1116091 qemu: block: Unify conditions to format backing store of format node definition
Move all bits of the formatting of the 'backing' attribute to a single
condition and make it use a single extracted copy of the backing store.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
510d154a0b qemu: Prevent storage causing too much nested XML
Since libvirt stores the backing chain into the XML in a nested way it
is the prime possibility to hit libxml2's parsing limit of 256 layers.

Introduce code which will crawl the backing chain and verify that it's
not too deep. The maximum nesting is set to 200 layers so that there's
still some space left for additional properties or nesting into snapshot
XMLs.

The check is applied to all disk use cases (starting, hotplug, media
change) as well as block copy which changes image and snapshots.

We simply report an error and refuse the operation.

Without this check a restart of libvirtd would result in the status XML
failing to be parsed and thus losing the VM.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
7d60b1f45f qemu: domain: Refactor cleanup in qemuDomainDetermineDiskChain
Use VIR_AUTOUNREF and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
3fbaf0587c qemu: hotplug: Setup disk throttling with blockdev
With blockdev we must issue the block_set_io_throttle QMP command to
setup disk throttling as we currently can't do it with the 'throttle'
layer.

Unfortunately there's nothing we can do if it fails.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
f2ac23f245 qemu: hotplug: Use VIR_AUTOFREE in qemuDomainAttachDiskGeneric
Get rid of the last manually freed var.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
5ef886e9bc qemu: hotplug: Simplify cleanup in qemuDomainChangeMediaLegacy
Switch to using VIR_AUTOFREE and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Jiri Denemark
f709377301 qemu: Fix qemuDomainObjTaint with virtlogd
When virtlogd is used to capture QEMU's stdout, qemuDomainObjTaint would
always fail to write the message to the log file when QEMU is already
running (i.e., outside qemuProcessLaunch). This can happen during device
hotplug or by sending a custom QEMU guest agent command:

    warning : qemuDomainObjTaint:8757 : Domain id=9 name='blaf'
        uuid=9cfa4e37-2930-405b-bcb4-faac1829dad8 is tainted:
        custom-ga-command
    error : virLogHandlerDomainOpenLogFile:388 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy
    error : virNetClientProgramDispatchError:172 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy

The fix is easy, we just need to use the right API for appending a
message to QEMU log file instead of creating a new log context.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-05 17:09:34 +02:00
Peter Krempa
a59cb27360 qemu: monitor: Fix formatting of 'offset' in qemuMonitorJSONSaveMemory
The offset is unsigned long long thus 'U' must be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-04 09:13:49 +02:00
Peter Krempa
f009ad6740 qemu: block: Use correct type when creating image size JSON entries
The 'u' modifier creates an unsigned int JSON attribute but the disk size
and capacity fields are unsigned long long. If the size of the created
image would be more than 4GiB we'd overflow and create sub-4G image.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-04 09:13:49 +02:00
Peter Krempa
ed7e342b0a qemu: domain: Fix potential NULL deref when parsing job private data
A specially crafted XML which would reference a non-existing disk but
request the mirror to be registered with the blockjob could potentially
make the parser dereference NULL. Fix it by moving the code slightly and
just treat it as a wrong job XML. Found by Coverity.

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-09-03 14:38:34 +02:00
Michal Privoznik
16fb3c8b83 qemu_blockjob: Remove secdriver metadata more frequently
If a block job reaches failed/cancelled state, or is completed
without pivot then we must remove security driver metadata
associated to the backing chain so that we don't leave any
metadata behind.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-08-31 10:11:37 +02:00
Michal Privoznik
7f99d8a739 qemu_blockjob: Print image path on failed security metadata move too
When a block job is completed, the security image metadata are
moved to the new image. If this fails an warning is printed, but
the message contains only domain name and lacks image paths. Put
them both into the warning message.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-08-31 10:11:37 +02:00
Michal Privoznik
143a0f8b05 qemu_blockjob: Move active commit failed state handling into a function
Currently, there are only a few lines of code so a separate
function was not necessary, but this will change. So instead of
putting all the new code under 'case
QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT' create a separate function.
Just like every other case has one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-08-31 10:11:37 +02:00
Jonathon Jongsma
be9d259ebc qemu: Validate arg in qemuAgentErrorComandUnsupported()
Coverity noted that 'reply' can be NULL after calling
qemuAgentCommand().  Avoid dereferencing reply in
qemuAgentErrorComandUnsupported() in that case.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-08-30 17:23:03 -04:00
Daniel Henrique Barboza
77725439ba qemu_conf.c: removing unused virQEMUDriverConfigPtr variable
'virQEMUDriverConfigPtr cfg' is declared, initiated, but never
used in virQEMUDriverCreateCapabilities().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Christophe de Dinechin <dinechin@redhat.com>
2019-08-30 14:56:11 +02:00
Peter Krempa
c87c42f0eb qemu: command: Use all vCPU properties when creating args for vCPU hotplug
As qemu documents we should use everything in the 'props' sub-object of
the data returned by query-hotpluggable-cpus. Until now we only used
everything we recognized, but that may break in cases when qemu
introduces new fields.

This change requires a fix to the test data as some fields were
reordered.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-08-29 16:36:26 +02:00
Peter Krempa
a0b61591f2 qemu: Extract and store vCPU properties as qemu returned them
In addition to the data that libvirt needs and extracts internally,
copy and store the whole 'props' JSON sub-object of the data returned by
query-hotpluggable-cpus for future use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-08-29 16:36:26 +02:00
Jonathon Jongsma
1b380b89ff qemu: agent: fix potential leak in qemuAgentGetFSInfo()
On error paths, info_ret could potentially leak. Make sure it's freed.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-08-29 16:29:11 +02:00
Jonathon Jongsma
a931486a97 qemu: guestinfo: handle unsupported agent commands
When we're collecting guest information, older agents may not support
all agent commands. In the case where the user requested all info
types (i.e. types == 0), ignore unsupported command errors and gather as
much information as possible. If the agent command failed for some other
reason, or if the user explciitly requested a specific info type (i.e.
types != 0), abort on the first error.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-29 12:03:23 +02:00
Boris Fiuczynski
0c67a11a4a qemu: support bootindex on vfio-ccw mdev devices
Add support to specify a boot order on vfio-ccw passthrough devices.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:26:43 +02:00
Boris Fiuczynski
1219f0cadc qemu: refactor mdev validation method signatures
Refactoring the method signatures in preparation for
checking boot index of the mediated devices.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:26:06 +02:00
Boris Fiuczynski
1aed9d84f9 qemu: make error messages device specific
Changing the error messages to report the problem encountered.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:25:16 +02:00
Boris Fiuczynski
182659d8bd qemu: move hostdev boot validation into domain validation
Moving the hostdev boot support validation from the command line
generator code into the domain validation code.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:22:51 +02:00
Michal Privoznik
3853372659 qemu: Don't duplicate domain def in qemuDomainGetFSInfo
Introduced in v3.0.0-rc1~336, the commit message doesn't really
justifies the expensive domain def copy creation. Now, that
vm->def is guarded in this function by job acquirement we can use
vm->def directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 14:23:29 +02:00
Michal Privoznik
93841cb030 qemu: Acquire domain job in qemuDomainGetFSInfo and qemuDomainGetGuestInfo
These two functions work with vm->def in their critical sections
(i.e. after the job was acquired and before it is released). But
that means, they need QUERY domain job too to prevent vm->def
change.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 14:14:34 +02:00
Daniel P. Berrangé
d29c917ef4 src: honour the RUNSTATEDIR variable in all code
All code using LOCALSTATEDIR "/run" is updated to use RUNSTATEDIR
instead. The exception is the remote driver client which still
uses LOCALSTATEDIR "/run". The client needs to connect to remote
machines which may not be using /run, so /var/run is more portable
due to the /var/run -> /run symlink.

Some duplicate paths in the apparmor code are also purged.

There's no functional change by default yet since both expressions
expand to the same value.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-08-27 10:23:13 +01:00
Daniel P. Berrangé
0824385221 build: honour $(runstatedir) in make rules
Creating various directories using $(runstatedir) instead of
$(localstatedir)/run.

There's no functional change by default yet since both expressions
expand to the same value.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-08-27 10:23:11 +01:00
Ján Tomko
1425a6195c qemu_command: remove unnecessary labels and ret variables
The recent cleanups allow us to clean up the code a bit.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
6ca568e2ab qemuBuildCommandLine: use VIR_RETURN_PTR for cmd
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
18d779c85e qemu_command: use VIR_AUTOUNREF
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
641b649d6d qemuBuildShmemCommandLine: use VIR_AUTOFREE for devstr
Now that it's only used once.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
a74e7270d8 qemuBuildShmemCommandLine: add chardev variable
That way devstr will only be used for the device string.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
d804bde82b qemuBuildSmpCommandLine: use virCommandAddArgBuffer directly
Instead of getting the string then passing it to virCommand.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
6e61843d07 qemuBuildRNGCommandLine: use VIR_AUTOFREE
Use separate variables for the chardev and the device.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
5253def175 qemuBuildControllersByTypeCommandLine: use VIR_AUTOFREE
Reduce the scope of the variable to get it freed for every controller
processed.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
f4bc171676 qemuBuildNetworkDriveURI: use VIR_AUTOPTR for virURI
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00
Ján Tomko
bc27393d43 qemu_command: use VIR_AUTOFREE for variables used once
Remove the VIR_FREE's from the cleanup sections.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-26 22:16:06 +02:00