Commit Graph

8273 Commits

Author SHA1 Message Date
Chris Venteicher
468841eabd qemu_process: Use consistent name for stop process function
s/qemuProcessQMPAbort/qemuProcessQMPStop/ applied to change function
name used to stop QEMU processes in process code moved from
qemu_capabilities.

No functionality change.

The new name, qemuProcessQMPStop, is consistent with the existing
function qemuProcessStop used to stop Domain processes.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-19 18:41:06 +01:00
Chris Venteicher
3dcdd18b6b qemu_process: Refer to proc not cmd in process code
s/cmd/proc/ in process code imported from qemu_capabilities.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-19 18:40:58 +01:00
Chris Venteicher
1aa4257569 qemu_process: Limit qemuProcessQMPNew to const input strings
Add the const qualifier on non modified strings
(string only copied inside qemuProcessQMPNew)
so that const strings can be used directly in calls to
qemuProcessQMPNew in future patches.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-19 18:40:49 +01:00
Chris Venteicher
3bdb6e826f qemu_process: Rename identifiers moved from qemu_capabilities
s/virQEMUCapsInitQMPCommand/qemuProcessQMP/

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-19 18:40:11 +01:00
Chris Venteicher
16058045d0 qemu_process: Move process code from qemu_capabilities
QEMU process code in qemu_capabilities.c is moved to qemu_process.c in
order to make the code usable outside the original capabilities use
cases.

The moved code activates and manages QEMU processes without establishing
a guest domain.

This patch is a straight cut/paste move between files.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-19 18:40:02 +01:00
Ján Tomko
060e07c3ca Remove remaining references to kqemu
We dropped support in commit 8e91a40 (November 2015), but some
occurrences still remained, even in live code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-19 08:33:50 +01:00
Peter Krempa
44601a0e96 util: Replace virStorageSourceFree with virObjectUnref
Now that virStorageSource is a subclass of virObject we can use
virObjectUnref and remove virStorageSourceFree which was a thin wrapper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-18 10:31:21 +01:00
Peter Krempa
e1c01b2252 util: Remove the AUTOPTR func for virStorageSource
Since virStorageSource is now a subclass of virObject, we can use
VIR_AUTOUNREF instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-18 10:31:21 +01:00
Peter Krempa
dcda2bf4c1 util: Introduce function for allocating virStorageSource
Add virStorageSourceNew and refactor places allocating that structure to
use the helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-18 10:27:30 +01:00
Michal Privoznik
4b23f18d2c qemu_hotplug: Initialize @charAlias in qemuDomainRemoveChrDevice
My change in 112f3a8d0f was too drastic. The @charAlias
variable is initialized only if @monitor == true. However, it is
used even outside of that condition, at which point it's just
uninitialized pointer.

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 15:23:53 +01:00
Ján Tomko
0f110d5ac8 Use NULLSTR_EMPTY
Instead of repetitive:
  s ? s : ""
use NULLSTR_EMPTY.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2019-02-14 14:09:38 +01:00
Michal Privoznik
5657e22212 qemu_hotplug: Assume chardev alias always exists in qemuDomainDetachChrDevice
The @tmpChr is looked up in domain definition based on user
provided chardev XML. Therefore, the alias must have been
allocated already when domain was started up.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 13:44:56 +01:00
Michal Privoznik
0c17685760 qemu_hotplug: Don't build device string in qemuDomainDetachChrDevice
This is basically an old artefact from 24b0821926 when the idea
was:

1) Build device string only to see if chardev has any -device
associated with it and thus if device_del is needed
2) Detach chardev using chardev_del

Now, that DEVICE and DEVICE_DELETED capabilities are assumed for
every domain 1) does not make sense anymore.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 13:42:07 +01:00
Michal Privoznik
112f3a8d0f qemu_hotplug: Detach guestfwd using netdev_del
https://bugzilla.redhat.com/show_bug.cgi?id=1624204

The guestfwd channels are -netdevs really. Hotunplug them as
such. Also, DEVICE_DELETED event is not triggered (surprisingly,
since we're not issuing device_del rather than netdev_del) and
associated chardev is removed automagically too. This means that
we need to do qemuDomainRemoveChrDevice() minus monitor call to
remove the chardev.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 09:20:40 +01:00
Michal Privoznik
903315dc8f qemu_hotplug: Attach guestfwd using netdev_add
https://bugzilla.redhat.com/show_bug.cgi?id=1624204

The guestfwd channels are -netdevs really. Hotplug them as such.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 09:19:33 +01:00
Michal Privoznik
18b8f67745 qemuL: Drop "user-" prefix for guestfwd netdev
Introduced by d86c876a66.

There is no real need to have "user-" prefix for chardev.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 09:18:31 +01:00
Michal Privoznik
f538f5ed3a qemu: Use @tmpChr in qemuDomainDetachChrDevice to build device string
So far we are passing @chr to qemuBuildChrDeviceStr. This is
suboptimal (in fact wrong) because @chr is just parsed XML
definition provided by user which by definition may lack some
information. On the other hand, @tmpChr is the one that was found
using @chr in domain definition so it contains the same amount of
information or more.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-14 09:15:02 +01:00
Eric Blake
174309a1f8 qemu: Escape external snapshot names containing comma
The code for creating external snapshots for an offline domain
called out to qemu-img without escaping commas in the manner
that qemu-img expects. This also fixes a typo in the comment.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-13 16:36:05 -06:00
John Ferlan
bf688a0067 util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageSource
Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-12 13:19:26 -05:00
John Ferlan
13395548b2 util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageAuthDef
Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-12 08:51:23 -05:00
John Ferlan
a98d9daf07 conf,util,qemu: Use VIR_STEAL_PTR for authdef processing
Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-12 08:51:23 -05:00
Ján Tomko
b4a4e8f71a qemu: do not format <usedQMP/> in qemu caps XML
Since commit a7424faff QMP is always used.

Also, commit 932534e8 removed the last use of this apart from:
* parsing/formatting this in the caps cache
* using it as a temporary variable to know when to report an error

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-02-12 14:02:38 +01:00
Andrea Bolognani
df2b31ffea qemu: Unify style for qemuDomain*()
These functions do mostly the same things, and it would be
preferrable if they did them in mostly the same ways. This
also fixes a few violations to our code style guidelines.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:25 +01:00
Andrea Bolognani
0440d5e90f qemu: Move qemuDomainSupportsPCI() to qemu_domain
The function operates on a virDomainDef and is not tied to
device address assignment in any way, so it makes more sense
for it to live along with qemuDomainIs*() and the like.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:22 +01:00
Andrea Bolognani
68e26a9ea2 qemu: Make most qemuDomainMachine*() functions static
Ideally we'd make all of them static, but there are a few
cases where we don't have a virDomainDef instance handy and
so they are the only option.

For the few ones we're forced to keep exporting, document
through comments that the alternative is preferred.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:20 +01:00
Andrea Bolognani
8a8b14718e qemu: Remove useless ARCH_IS_X86() call
Now that we have added architecture checks to all
qemuDomainIs*() functions, we no longer need to perform the
same checks separately.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:18 +01:00
Andrea Bolognani
aa2da99ee8 qemu: Add arch checks to qemuDomainMachine*()
There is very little overlap in the machine types available
on different architectures, so broadly speaking checking the
machine type is usually enough; regardless, it's better to
check the architecture as well.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:16 +01:00
Andrea Bolognani
9a5ce5cb29 qemu: Add arch parameter to qemuDomainMachine*()
We want the signatures to be consistent, and also we're
going to start using the additional parameter next.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:14 +01:00
Andrea Bolognani
4028d7a46a qemu: Move functions around
Make sure related functions, eg. all qemuDomainIs*(), are
close together instead of being sprinkled throughout both
the header and implementation file, and also that all
qemuDomainMachine*() functions are declared first since
we're going to make a bunch of them static later on.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:12 +01:00
Andrea Bolognani
616beb17d4 qemu: Use more specific prefixes
While the chances of the current checks resulting in false
positives are basically zero, it's still nicer to check for
the full prefix instead of the prefix's prefix.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:10 +01:00
Andrea Bolognani
629fdca0d0 qemu: Remove redundant condition
No need to check whether we're dealing with a pSeries guest
twice within just a few lines.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2019-02-08 16:16:05 +01:00
John Ferlan
73b9b8fe36 util: Use a semicolon for all VIR_DEFINE_AUTOPTR_FUNC
For consistency, let's use the semicolon for all definitions.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-08 06:57:23 -05:00
Peter Krempa
22d7222ec0 qemu: caps: Don't call 'query-events' when we probe events from QMP schema
Avoid calling the command and fix test fallout.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
398d5766b3 qemu: caps: Probe events from 'query-qmp-schema' rather than 'query-events'
QEMU plans to deprecate 'query-events' as it's non-extensible. Events
are also described by 'query-qmp-schema' so we can use that one instead.

This patch adds detection of events to
virQEMUCapsProbeQMPSchemaCapabilities using the same structure declaring
them for the old approach (virQEMUCapsEvents). This is possible as the
name is the same in the QMP schema and our detector supports that
trivially.

For any complex queries virQEMUCapsQMPSchemaQueries can be used in the
future.

For now we still call 'query-events' and discard the result so that it's
obvious that the tests pass. This will be cleaned up later.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
850bb78a6e qemu: caps: Always assume QEMU_CAPS_DEVICE_TRAY_MOVED
The event was added by qemu commit 6f382ed226f3 released in v1.1.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
8c191a9061 qemu: caps: Always assume QEMU_CAPS_DEVICE_DEL_EVENT
DEVICE_DELETED was added in qemu commit 0402a5d65ec00 which was released
in v1.5.0.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
ea34af1f35 qemu: caps: Always assume QEMU_CAPS_SEAMLESS_MIGRATION
The event was added by qemu commit 2fdd16e239c2a2 released in v1.3.0.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
3b0856c4ba qemu: Clean up usage of qemuDomainUpdateCurrentMemorySize
Remove the uneeded attribute and return value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:20 +01:00
Peter Krempa
3f2fa8f303 qemu: caps: Always assume QEMU_CAPS_BALLOON_EVENT
The event was added to qemu by commit 973603a813c5d60 which is contained
in the 1.2.0 release.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:19 +01:00
Peter Krempa
6d3c96f0d9 qemu: caps: Add lockout for -blockdev if QEMU_CAPS_SCSI_DISK_DEVICE_ID is not present
Avoid regressions by disallowing the BLOCKDEV capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:19 +01:00
Peter Krempa
a1dce96236 qemu: Use the 'device_id' property of SCSI disks to avoid regressing
QEMU accidentally exposed the id of -drive (or same value as disk
serial, if provided) in one of the identifiers visible from the guest.

To avoid regression in case when -blockdev will be used we need to
always specify it ourselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 10:11:12 +01:00
Peter Krempa
85a8e364f3 qemu: caps: Introduce capability for 'device_id' property of 'scsi-disk'
The property allows to control the guest-visible content of the vendor
specific designator of the 'Device Identification' page of a SCSI
device's VPD (vital product data).

QEMU was leaking the id string of -drive as the value if the 'serial' of
the disk was not specified. Switching to -blockdev would impose an ABI
change.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:48:33 +01:00
Peter Krempa
1328a830ce qemu: command: Drop formatting of 'media=cdrom' from -drive
For SCSI, IDE, and AHCI cdroms the appropriate device types which select
the correct media are used. In qemu there's one other code path that
looks at -drive media=cdrom in the XEN pv code. Thankfully we don't
support it with qemu (see qemuBuildDiskDeviceStr). All other devices
ignore it as the comment states, thus we can drop that code.

The test fallout is expectedly only in the test added for uncommon cdrom
types.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:48:33 +01:00
Peter Krempa
5d884f3d3c qemu: Forbid cdroms on virtio bus
Attempting to create an empty virtio-blk drive results into:
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0xc,drive=drive-virtio-disk1,id=virtio-disk1: Device needs media, but drive is empty

Attempting to eject media from virtio-blk based drive results into:
error: internal error: unable to execute QEMU command 'eject': Device 'drive-virtio-disk0' is not removable

Forbid configurations where users would attempt to use cdroms in virtio
bus.

Fix few wrong examples which are not really relevant to the tested code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:41:40 +01:00
Peter Krempa
6b67eeef8c qemu: command: Use correct type for switch in qemuBuildDiskDeviceStr
Cast disk->bus to proper type and add missing values to the enum so it's
more obvious what types are supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:34:26 +01:00
Peter Krempa
1dcba456fa qemu: caps: Always assume presence of 'ide-hd' and 'ide-cd' devices
The split of ide-disk into the two separate devices was introduced by
qemu commit 1f56e32a7f4b3 released in qemu v0.15.

Note that when compared to the previous commit which made sure that no
disk related tests were touched, in this case it's not as careful.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:34:17 +01:00
Peter Krempa
4bf49bc566 qemu: caps: Always assume presence of 'scsi-hd' and 'scsi-cd' device
The split of scsi-disk into the two separate devices was introduced by
qemu commit b443ae67 released in qemu v0.15.

All changes to test files are not really related to disk testing thanks
to previous refactors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:34:17 +01:00
Peter Krempa
e67b6dcf36 qemu: capabilities: Probe caps for 'ide-hd' instead of 'ide-drive'
Since commit a4cda054e7 we are using 'ide-hd' and 'ide-cd' instead of
'ide-drive'. We also should probe capabilities for 'ide-hd' instead of
'ide-drive'. It is safe to do as 'ide-drive' is the common denominator
of both 'ide-hd' and 'ide-cd' so all the properties were common.

For now the test data are modified by just changing the appropriate type
when probing for caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:30:38 +01:00
Peter Krempa
7d114e1b72 qemu: capabilities: Probe caps for 'scsi-hd' instead of 'scsi-disk'
Since commit 02e8d0cfdf we are using 'scsi-hd' and 'scsi-cd' instead of
'scsi-disk'. We also should probe capabilities for 'scsi-hd' instead of
'scsi-disk'. It is safe to do as 'scsi-disk' is the common denominator
of both 'scsi-hd' and 'scsi-cd' so all the properties were common.

For now the test data are modified by just changing the appropriate type
when probing for caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-02-08 08:23:26 +01:00
Jiri Denemark
12977fba8b qemu: Implement VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag
This flag tells virDomainMigrateSetMaxSpeed and
virDomainMigrateGetMaxSpeed APIs to work on post-copy migration
bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Jiri Denemark
c830187a01 qemu: Implement VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY
This typed parameter for virDomainMigrate3 and virDomainMigrateToURI3
APIs may be used for setting maximum post-copy migration bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Jiri Denemark
08d44263c8 qemu: Make migration params usable outside migration
So far migration parameters were changed only at the beginning of
migration mostly via an automatic translation from flags and typed
parameters. We need to export a few more functions to support APIs which
may set migration parameters while migration is already running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Jiri Denemark
54e969c538 qemu: Rework qemuDomainMigrateSetMaxSpeed
Let's make the code flow easier to follow and get rid of the ugly endjob
label inside if branch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Jiri Denemark
c160275d9c qemu: Add optional unit to qemuMigrationParamsTPMapItem
Some migration parameters supported by libvirt may use units that differ
from the units used by QEMU for the corresponding parameters. For
example, libvirt defines migration bandwidth in MiB/s while QEMU expects
B/s. Let's add a unit field to qemuMigrationParamsTPMapItem for
automatic conversion when translating between libvirt's migration typed
parameters and QEMU's migration paramteres.

This patch is a preparation for future parameters as the existing
VIR_MIGRATE_PARAM_BANDWIDTH parameter is set using "migrate_set_speed"
QMP command rather than "migrate-set-parameters" for backward
compatibility.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Jiri Denemark
9e7a163b13 qemu: Use C99 initializers for qemuMigrationParamsTPMap
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 16:25:59 +01:00
Peter Krempa
b9e8a6f7e5 qemu: Use data in qemuBlockJobDataPtr instead of re-generating job name
qemuDomainBlockPivot and qemuDomainBlockJobAbort need the job name for
cancelling or pivoting but were generating it locally instead of
accessing the existing copy in the job data structure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 14:32:32 +01:00
Peter Krempa
a26cc472ff qemu: Remove unused 'cfg' qemuDomainBlockPivot
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 14:32:32 +01:00
Peter Krempa
023d69dfc8 qemu: Move shareable disk check for block copy
The writing to an image actually starts when the copy job is initiated,
so checking this at the time of the pivot operation is too late.

Move the check to qemuDomainBlockCopyCommon. Note that modern qemu would
have prevented two writers with qcow2 so the slim possibility of a job
started with libvirtd without this patch missing the check is not really
worth worrying about.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 14:32:32 +01:00
Peter Krempa
ef8a87a09d qemu: Always save status XML in qemuDomainBlockJobAbort
For copy and active commit jobs we record the state of the mirror so
that we can recover. The status XML was not saved in case of
qemuDomainBlockPivot due to an oversight.

Save the XML always when invoking qemuDomainBlockJobAbort even if
the job is not currently tracking any state. This will change later and
also this is not a particularly hot code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-07 14:32:32 +01:00
Andrea Bolognani
3d23a434d2 qemu: Refactor virtio-input capabilities checks
The checks and error messages are mostly the same across
all virtio-input devices, so we can avoid having multiple
copies of the same code.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-05 17:50:42 +01:00
Peter Krempa
620d9dd598 qemu: caps: Don't try to ask for CAP_DAC_OVERRIDE if non-root
It will not work. This breaks qemu capabilities probing as a user.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-05 08:57:35 +01:00
Marc Hartmayer
41d37d31b3 qemu: Refresh state before starting the VCPUs
For normal starts (no incoming migration) the refresh of the QEMU
state must be done before the VCPUs getting started since otherwise
there might be a race condition between a possible shutdown of the
guest OS and the QEMU monitor queries.

This fixes "qemu: migration: Refresh device information after
transferring state" (93db7eea1b).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2019-02-04 15:51:48 +01:00
Michal Privoznik
86caae3953 qemu: Assume migration with a network disk migration is safe
If a domain has a disk that is type='network' we require specific
cache mode to allow migration with it (either 'directsync' or
'none'). This doesn't make much sense since network disks are
supposed to be safe to migrate by default.

At the same time, we should be checking for the actual source
type, not apparent type set in the domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-02-04 14:03:42 +01:00
Peter Krempa
3bc3cca7bb qemu: domain: Use 'raw' for 'volume' disks without format
Storage pools might want to specify format of the image when translating
the volume thus we can't add any default format when parsing the XML.

Add a explicit format when starting the VM and format is not present
neither by user specifying it nor by the storage pool translation
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-04 13:42:11 +01:00
Peter Krempa
2f78ca803a qemu: domain: Assume 'raw' default storage format also for network storage
Post parse callback adds the 'raw' type only for local files. Remote
files can also have backing store (even local) so we should do this also
for network backed storage.

Note that virStorageFileGetMetadata always considers files with no type
as raw so we will not accidentally traverse the backing chain and allow
unexpected files being labelled with svirt labels.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-04 13:42:11 +01:00
Peter Krempa
6db0d03383 qemu: command: Don't skip 'readonly' and throttling info for empty drive
In commit f80eae8c2a I was too agresive in removing properties of
-drive for empty drives. It turns out that qemu actually persists the
state of 'readonly' and the throttling information even for the empty
drive.

Removing 'readonly' thus made qemu open any subsequent images added via
the 'change' command as RW which was forbidden by selinux thanks to the
restrictive sVirt label for readonly media.

Fix this by formating the property again and bump the tests and leave a
note detailing why the rest of the properties needs to be skipped.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-04 09:49:37 +01:00
Cole Robinson
af36f8a641 Require a semicolon for VIR_ONCE_GLOBAL_INIT calls
Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>). VIR_ONCE_GLOBAL_INIT is almost
exclusively called without an ending semicolon, but let's
standardize on using one like the other macros.

Add a dummy struct definition at the end of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-02-03 17:46:29 -05:00
Cole Robinson
8bec5488a6 Require a semicolon for VIR_LOG_INIT calls
Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_LOG_INIT calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-02-03 17:46:29 -05:00
Cole Robinson
6a4d938dd3 Require a semicolon for VIR_ENUM_IMPL calls
Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_IMPL calls.

Move the verify() statement to the end of the macro and drop
the semicolon, so the compiler will require callers to add a
semicolon.

While we are touching these call sites, standardize on putting
the closing parenth on its own line, as discussed here:
https://www.redhat.com/archives/libvir-list/2019-January/msg00750.html

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-02-03 17:46:29 -05:00
Cole Robinson
7662194bf3 Require a semicolon to VIR_ENUM_DECL calls
Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_DECL calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-02-03 17:46:29 -05:00
Michal Privoznik
f136b83139 qemu: Rework setting process affinity
https://bugzilla.redhat.com/show_bug.cgi?id=1503284

The way we currently start qemu from CPU affinity POV is as
follows:

  1) the child process is set affinity to all online CPUs (unless
  some vcpu pinning was given in the domain XML)

  2) Once qemu is running, cpuset cgroup is configured taking
  memory pinning into account

Problem is that we let qemu allocate its memory just anywhere in
1) and then rely in 2) to be able to move the memory to
configured NUMA nodes. This might not be always possible (e.g.
qemu might lock some parts of its memory) and is very suboptimal
(copying large memory between NUMA nodes takes significant amount
of time).

The solution is to set affinity to one of (in priority order):
  - The CPUs associated with NUMA memory affinity mask
  - The CPUs associated with emulator pinning
  - All online host CPUs

Later (once QEMU has allocated its memory) we then change this
again to (again in priority order):
  - The CPUs associated with emulator pinning
  - The CPUs returned by numad
  - The CPUs associated with vCPU pinning
  - All online host CPUs

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-01 12:53:46 +01:00
Erik Skultety
a2d3dea9d4 qemu: caps: Use CAP_DAC_OVERRIDE for probing to avoid permission issues
This is mainly about /dev/sev and its default permissions 0600. Of
course, rule of 'tinfoil' would be that we can't trust anything, but the
probing code in QEMU is considered safe from security's perspective + we
can't create an udev rule for this at the moment, because ioctls and
file system permissions aren't cross-checked in kernel and therefore a
user with read permissions could issue a 'privileged' operation on SEV
which is currently only limited to root.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-01 12:44:28 +01:00
Erik Skultety
6fd4c8f878 qemu: domain: Add /dev/sev into the domain mount namespace selectively
Instead of exposing /dev/sev to every domain, do it selectively.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-01 12:40:20 +01:00
Erik Skultety
a404ac3476 qemu: cgroup: Expose /dev/sev/ only to domains that require SEV
SEV has a limit on number of concurrent guests. From security POV we
should only expose resources (any resources for that matter) to domains
that truly need them.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-01 12:40:18 +01:00
Erik Skultety
b644011918 qemu: conf: Remove /dev/sev from the default cgroup device acl list
We should not give domains access to something they don't necessarily
need by default. Remove it from the qemu driver docs too.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-01 12:39:41 +01:00
Andrea Bolognani
e266a41f1e qemu: Add PCI support for RISC-V guests
virtio-mmio is still used by default, so if PCI is desired
it's necessary to explicitly opt-in by adding an appropriate

  <address type='pci' domain='0x0000' ... />

element to the corresponding device.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-01 11:57:50 +01:00
Daniel P. Berrangé
6bb582bff8 qemu: remove check for 'qemu' binary
The 'qemu' binary used to provide the i386 emulator until it was renamed
to qemu-system-i386 in QEMU 1.0. Since we don't support such old
versions we don't need to check for 'qemu' when probing capabilities.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-01-31 13:28:40 +00:00
Peter Krempa
73ce3911aa qemu: blockjob: Don't report block job progress at 100% if job isn't ready
Some clients poll virDomainGetBlockJobInfo rather than wait for the
VIR_DOMAIN_BLOCK_JOB_READY event. In some cases qemu can get to 100% and
still not reach the synchronised phase. Initiating a pivot in that case
will fail.

Given that computers are interacting here, the error that the job
can't be finalized yet is not handled very well by those specific
implementations.

Our docs now correctly state to use the event. We already do a similar
output adjustment in case when the progress is not available from qemu
as in that case we'd report 0 out of 0, which some apps also incorrectly
considered as 100% complete.

In this case we subtract 1 from the progress if the ready state is not
signalled by qemu if the progress was at 100% otherwise.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-01-31 13:03:01 +01:00
Daniel P. Berrangé
a507edef33 qemu: pass virDomainDeviceInfo by reference
The virDomainDeviceInfo parameter is a large struct so it is preferrable
to pass it by reference instead of by value.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-01-31 10:38:36 +00:00
Peter Krempa
d56afb8e39 qemu: Label backing chain of user-provided target of blockCopy when starting the job
Be more sensible when setting labels of the target of a
virDomainBlockCopy operation. Previously we'd relabel everything in case
it's a copy job even if there's no unlabelled backing chain. Since we
are also not sure whether the backing chain is shared we don't relabel
the chain on completion of the blockjob. This certainly won't play nice
with the image permission relabelling feature.

While this does not fix the case where the image is reused and has
backing chain it certainly sanitizes all the other cases. Later on it
will also allow to do the correct thing in cases where only one layer
was introduced.

The change is necessary as in case when -blockdev will be used we will
need to hotplug the backing chain and thus labeling needs to be setup in
advance and not only at the time of pivot.  To avoid multiple code paths
move the labeling now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
9b197f0e36 qemu: hotplug: Refactor qemuHotplugPrepareDiskAccess to work on virStorageSource
Rather than passing in a virStorageSource which would override the
originally passed disk->src we can now drop passing in a disk completely
as all functions called inside here require a virStorageSource.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
083b74cd20 locking: Use virDomainLockImage[Attach|Detach] instead of *Disk
Use the functions designed to deal with single images as the *Disk
functions were just wrappers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
93a1659171 qemu: driver: Remove disk source munging in qemuDomainBlockPivot
Previously there weren't any suitable functions which would allow
setting up host side of a full disk chain so we've opted to replace the
'src' in a virDomainDiskDef by the new image source.

That is now no longer necessary so remove the munging.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
787e4a3dc8 qemu: security: Replace and remove qemuSecurity[Set|Restore]DiskLabel
The same can be achieved by using qemuSecurity[Set|Restore]ImageLabel.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
81594afb05 qemu: security: Add 'backingChain' flag to qemuSecurity[Set|Restore]ImageLabel
The flag will control the VIR_SECURITY_DOMAIN_IMAGE_LABEL_BACKING_CHAIN
flag of the security driver image labeling APIs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
43479005ee security: Remove security driver internals for disk labeling
Security labeling of disks consists of labeling of the disk image
itself and it's backing chain. Modify
virSecurityManager[Set|Restore]ImageLabel to take a boolean flag that
will label the full chain rather than the top image itself.

This allows to delete/unify some parts of the code and will also
simplify callers in some cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
e7d14bf965 qemu: cgroup: Change qemu[Setup|Teardown]DiskCgroup to take virStorageSource
Since the disk is necessary only to get the source modify the functions
to take the source directly and rename them to
qemu[Setup|Teardown]ImageChainCgroup.

Additionally drop a pointless comment containing the old function name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
33b0a3bab8 qemu: domain: Allow overriding disk source in qemuDomainDetermineDiskChain
When we need to detect a chain for a image which will become the new
source for a disk (e.g. after a disk media change or a blockjob) we'd
need to replace disk->src temporarily to do so.

Move the 'disksrc' temporary variable to an argument and adjust callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:38 +01:00
Peter Krempa
73163a0e86 qemu: domain: Clarify temp variable scope in qemuDomainDetermineDiskChain
The function at first validates the top image of the chain, then
traverses the chain as declared in the XML (if any) and then procedes to
detect the rest of the chain from images. All of the steps have their
own temporary iterator.

Clarify the use scope of the steps by introducing a new temp variable
holding the top level source and adding comments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-30 17:20:37 +01:00
Daniel P. Berrangé
9047b9aec0 Revert "qemu: Forbid pinning vCPUs for TCG domain"
This reverts commit 8b035c84d8.

The MTTCG impl in QEMU does allow pinning vCPUs.

When the guest is running we already check if pinning is
possible in the qemuDomainPinVcpuLive method, so this
check was adding no benefit.

When the guest is not running, we cannot know whether the
subsequent launch will use MTTCG or TCG, so we must allow
the pinning request. If the guest does use TCG on the next
launch it will fail, but this is no worse than if the user
had done a virDomainDefineXML with an XML doc specifying
vCPU pinning.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-01-29 17:19:10 +00:00
Daniel P. Berrangé
34f77437da qemu: fix recording of vCPU pids for MTTCG
MTTCG is the new multi-threaded impl of TCG which follows
KVM in having one host OS thread per vCPU. Historically
we have discarded all PIDs reported for TCG guests, but
we must now selectively honour this data.

We don't have anything in the domain XML that indicates
whether a guest is using TCG or MTTCG. While QEMU does
have an option (-accel tcg,thread=single|multi), it is
not desirable to expose this in libvirt. QEMU will
automatically use MTTCG when the host/guest architecture
pairing is known to be safe. Only developers of QEMU TCG
have a strong reason to override this logic.

Thus we use two sanity checks to decide if the vCPU
PID information is usable. First we see if the PID
duplicates the main emulator PID, and second we see
if the PID duplicates any other vCPUs.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-01-29 16:31:04 +00:00
Peter Krempa
5ea24bbb54 qemu: Don't reject making domain persistent if block copy is running
Add documentation that the 'VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB' flag
is auto-assumed if the block copy job is started while the VM is
transient and remove the restriction to define the domain when copy
is running.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-01-29 17:11:02 +01:00
Peter Krempa
f04bdf5368 qemu: Don't double-free disk->mirror if block commit initialization fails
disk->mirror would not be cleared while the local pointer was freed in
qemuDomainBlockCommit if qemuDomainObjExitMonitor or qemuBlockJobDiskNew
would return a failure.

Since block job handling is executed in the separate handler which needs
a qemu job, we don't need to pre-set the mirror state prior to starting
the job. Similarly the block copy job does not do that.

Move the setting of the data after starting the job so that we avoid
this problem.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-29 13:41:16 +01:00
Peter Krempa
06fa3366c6 qemu: Clear block copy mirror state explicitly
While this should not be necessary as we clear it in the event handler,
let's be sure and clear it prior to starting the job.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-29 13:41:16 +01:00
Peter Krempa
c6db273082 qemu: blockjob: Mark job as started only when it's new
Switching a block job to some states (e.g. QEMU_BLOCKJOB_STATE_READY)
might not require a job, thus if it will become ready asynchronously we
should not overwrite the state any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-29 13:41:16 +01:00
Peter Krempa
8d5df64449 qemu: blockjob: Make sure that internal states are not reported as event
While the callers should make sure that they don't call
qemuBlockJobEmitEvents for any internal state or job, let's add checks
that prevents us from emitting wrong events altogether.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-29 13:41:16 +01:00
Michal Privoznik
5772885d28 lib: Use more of VIR_STEAL_PTR()
We have this very handy macro called VIR_STEAL_PTR() which steals
one pointer into the other and sets the other to NULL. The
following coccinelle patch was used to create this commit:

  @ rule1 @
  identifier a, b;
  @@

  - b = a;
    ...
  - a = NULL;
  + VIR_STEAL_PTR(b, a);

Some places were clean up afterwards to make syntax-check happy
(e.g. some curly braces were removed where the body become a one
liner).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-28 14:46:58 +01:00
Ján Tomko
49ec5769c9 qemuBuildControllersCommandLine: use i instead of j as the counter
Now that the nested loop is gone.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:58:43 +01:00
Ján Tomko
a6d3357c8b rename qemuBuildControllerDevCommandLine
Use qemuBuildControllersCommandLine since it builds the command line
for (nearly) all controllers, not just one.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:58:43 +01:00
Ján Tomko
fc1c16bccd qemuBuildControllersByTypeCommandLine: free devstr in the cleanup
section

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:58:43 +01:00
Ján Tomko
c7e03df8c0 qemu: format CCID controllers after USB hubs
Since they go on the USB bus, format them after USB hubs.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:58:35 +01:00
Ján Tomko
421e0eeec7 qemu: Introduce qemuBuildControllersByTypeCommandLine
Now that the inner loop does not require any other variables,
it can be easily separated. Apart from reducing the indentation
level this will allow it to be called from different code paths.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:51 +01:00
Ján Tomko
75ecfd2521 qemuBuildControllerDevStr: remove nusbcontroller argument
Now that it's no longer needed, remove the argument.
This removes the last helper variable in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:51 +01:00
Ján Tomko
8f5e50e003 qemu: separate counting of USB controllers
qemuBuildLegacyUSBControllerCommandLine is the only place where
we need to count the USB controllers.

Count them again instead of keeping track in a variable passed to
qemuBuildControllerDevStr.

This removes the need for another variable in the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:51 +01:00
Ján Tomko
dab3d5d350 qemu: separate counting of legacy USB controllers
Count them in qemuBuildLegacyUSBControllerCommandLine to remove
yet another variable accessed from the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:51 +01:00
Ján Tomko
95049d7054 Add qemuBuildDomainForbidLegacyUSBController
Shorten some long conditions.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:50 +01:00
Ján Tomko
79c7cbaf46 qemu: exit early if USB_CONTROLLER_MODEL_NONE is present
This removes the need to mark it in the 'usbcontroller' variable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:50 +01:00
Ján Tomko
a98c0a2fef qemu: move out legacy USB controller formatting
Move out the code formatting "-usb" on the QEMU command line.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-01-25 14:54:50 +01:00
Cole Robinson
429f5454d5 qemu: command: Make BuildVirtioDevStr more generic
Switch qemuBuildVirtioDevStr to use virDomainDeviceSetData: callers
pass in the virDomainDeviceType and the void * DefPtr. This will
save us from having to repeatedly extend the function argument
list in subsequent patches.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Cole Robinson
028f9a6886 qemu: command: Convert vhost-{vsock,scsi} to qemuBuildVirtioDevStr
Current code essentially duplicates the same logic, but misses
some cases (like vhost-vsock-device).

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Cole Robinson
5ac9889a69 qemu: command: Make vhost-scsi device string depend on address
The vhost-scsi device string should depend on the requested
address type, not strictly on the emulated arch. This is the
same logic used by qemuBuildVirtioDevStr, and this particular
path is already tested in the hostdev-scsi-vhost-scsi-ccw tests

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Cole Robinson
0ba9786d8a qemu: Move <rng> validation out of qemu_command.c
Move the rng->model == VIRTIO check to parse time. This also
allows us to remove similar checks throughout the qemu driver

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Cole Robinson
6427bfc8b3 qemu: Move <memballoon> validation out of qemu_command.c
If we validate that memballoon is NONE|VIRTIO at parse time,
we can drop similar checks elsewhere in the qemu driver

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Cole Robinson
ea72bc65df conf: Add virDomainNetIsVirtioModel
This will be extended in the future, so let's simplify things by
centralizing the checks.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-01-24 18:59:38 -05:00
Eric Blake
7b6116fb89 qemu: improve compile-time check of qemuBlockjobState mapping
Asserting the value we set four lines earlier in qemuBlockjobState
doesn't buy us any safety (if the public header adds a value, we end
up skipping that value without the compiler warning us of our gap);
what we really want is to assert that the value auto-assigned by the
compiler matches the actual last value in the public headers (as was
done below for qemuBlockJobType).  Add useful comments while at it.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-01-23 16:20:25 -06:00
Peter Krempa
ab5d49d46c qemu: process: Handle all failure values for dimms in qemuProcessHandleAcpiOstInfo
Hanlde all the possible failure codes as per ACPI standard documented in
the function header.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-01-23 10:30:09 +01:00
Peter Krempa
f2f14e3f45 qemu: process: Improve documentation of values handled by qemuProcessHandleAcpiOstInfo
We forgot to document the specific fields for the 0x103 and 0x200
sources which are tied to device removal and device hotplug
respectively.

The value description is based on the ACPI 6.2A standard Table 6-207 and
Table 6-208. At the time of writing of this patch the standard can be
accessed e.g. at:

https://www.uefi.org/sites/default/files/resources/ACPI%206_2_A_Sept29.pdf

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-01-23 10:30:09 +01:00
Radoslaw Biernacki
8fac64db5e util: Fix for NULL dereference
The device xml parser code does not set "model" while parsing the
following XML:

  <interface type='hostdev'>
    <source>
      <address type='pci' domain='0x0002' bus='0x01' slot='0x00' function='0x2'/>
    </source>
  </interface>

The net->model can be NULL and therefore must be compared using
STREQ_NULLABLE instead of plain STREQ.

Fixes: ac47e4a622 (qemu: replace "def->nets[i]" with "net" and "def->sounds[i]" with "sound")
Fixes: c7fc151eec (qemu: assign virtio devices to PCIe slot when appropriate)
Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-01-23 10:18:36 +01:00
Ján Tomko
4fb769f5e0 qemu: error out when vnc vncTLSx509secretUUID is unsupported
Add a capability check to qemuDomainDefValidate and refuse to start
a domain with VNC graphics if the TLS secret was set in qemu.conf
and it's not supported.

Note that qemuDomainSecretGraphicsPrepare does not generate any
secret data if the capability is not present and qemuBuildTLSx509BackendProps
is not called at all.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
2e2b0d69a9 qemu: add support for encrypted VNC TLS keys
Use the password stored in the secret driver under
the uuid specified by the vnc_tls_x509_secret_uuid
option in qemu.conf.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
2c5dd1ee4c qemu.conf: add vnc_tls_x509_secret_uuid
Add an option that lets the user specify the secret
that unlocks the server TLS key.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
0b3fc37e61 qemu_process: fix debug message
Be generic instead of trying to enumerate all the involved
device types.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
2c7791a869 qemu: prepare secret for the graphics upfront
Instead of hardcoding the TLS creds alias in
qemuBuildGraphicsVNCCommandLine, store it
in the domain private data.

Given that we only support one VNC graphics
and thus have only one alias per-domain,
this is overengineered, but it will allow us
to prepare the secret upfront when we start
supporting encrypted server TLS keys.

Note that the alias is not formatted anywhere
since we won't need to access it after domain
startup.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
ea3c3f8846 qemu: add qemuDomainGraphicsPrivate data with a tlsAlias
Also introduce the necessary callbacks.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-22 12:18:28 +01:00
Ján Tomko
5de4d410a2 virQEMUDriverConfigLoadSWTPMEntry: use VIR_AUTOFREE
Switch the function to use VIR_AUTOFREE and VIR_AUTOPTR macros
to get rid of the cleanup section.

Requested-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-21 17:14:29 +01:00
Ján Tomko
784e690ecb virQEMUDriverConfigLoadSecurityEntry: use VIR_AUTOFREE
Switch the function to use VIR_AUTOFREE and VIR_AUTOPTR macros
to get rid of the cleanup section.

Requested-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-21 17:14:29 +01:00
Ján Tomko
2a33dc41bb virQEMUDriverConfigLoadNVRAMEntry: use VIR_AUTOFREE
Switch the function to use VIR_AUTOFREE and VIR_AUTOPTR macros
to get rid of the cleanup section.

Requested-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-21 17:14:29 +01:00
Ján Tomko
92e601d08c virQEMUDriverConfigLoadProcessEntry: use VIR_AUTOFREE
Switch the function to use VIR_AUTOFREE and VIR_AUTOPTR macros
to get rid of the cleanup section.

Requested-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-21 17:14:29 +01:00
Peter Krempa
f80eae8c2a qemu: command: Don't format image properties for empty -drive
If a -drive has no image, using image properties makes qemu whine that
they should not be used.

This patch stops formating cache/readonly/... for empty drives
for the pre-blockdev syntax. Unfortunately those parameters can't be
added later when inserting media, but on the other hand qemu will start
with an empty drive.

Since we already were able to start a VM with such config previously due
to qemu ignoring them I've opted just to skip formatting them.
Additionally with -blockdev support it will work as expected as the
image properties will be formatted when adding the image itself which is
not possible without it.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-01-21 17:04:26 +01:00
Laine Stump
40136bd316 qemu: fix i6300esb watchdog hotplug on Q35
When commit 361c8dc17 added support for hotplugging the i6300esb
watchdog device (first in libvirt-3.9.0), it accidentally contstructed
the commandline for the device_add command before allocating a PCI
address for the device. With no PCI address specified in the command,
the watchdog would simply be placed at the lowest unused PCI slot.

On a 440fx guest, this doesn't cause a problem, because libvirt's PCI
address allocation algorithm would most likely give the same address
anyway (usually a slot on pci-root), so nobody noticed the omission of
address from the command.

But on a Q35 guest, the lowest unused PCI slot is on pcie-root, which
doesn't support hotplug; libvirt knows enough to assign a PCI address
that is on a pcie-to-pci-bridge (because its slots *do* support
hotplug), but qemu doesn't, so if there is no PCI address in the
command, qemu just tries to plug the new device into pcie-root, and
fails because it doesn't support hotplug, e.g.:

  error: Failed to attach device from watchdog.xml
  error: internal error: unable to execute QEMU command 'device_add':
  Bus 'pcie.0' does not support hotplugging

The solution is simply to build the command string after assigning a
PCI address, not before.

Resolves: https://bugzilla.redhat.com/1666559
Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 14:12:02 -05:00
Wang Yechao
01ca4010d8 qemu: Assign device addresses earlier in qemuDomainAttachNetDevice
If code in the @actualType switch needs to have/know which PCI
Address is being used, then we must assign it earlier. In particular
a vhost-user device needs to call qemuDomainSupportsNicdev which
requires an address to be defined.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 10:11:50 -05:00
Ján Tomko
e6df863294 qemu_conf: rename checkdefaultTLSx509certdir
Use defaultTLSx509certdirPresent for consistencty.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
4079f47677 qemu_conf: split out virQEMUDriverConfigLoadDefaultTLSEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
cfe99a336d qemu_conf: split out virQEMUDriverConfigLoadVNCEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
53680aa379 qemu_conf: split out virQEMUDriverConfigLoadNographicsEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
da3dc5a382 qemu_conf: split out virQEMUDriverConfigLoadSPICEEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
a0ac0b913e qemu_conf: split out virQEMUDriverConfigLoadSpecificTLS
Split out parts of the config parsing code to make
the parent function easier to read.

This is the only patch that mixes various augeas entry
groups in one function.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
de100ceddb qemu_conf: split out virQEMUDriverConfigLoadRemoteDisplayEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:07 +01:00
Ján Tomko
1195e10b98 qemu_conf: split out virQEMUDriverConfigLoadSaveEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
0ebe4e60e6 qemu_conf: split out virQEMUDriverConfigLoadProcessEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
00063c2c95 qemu_conf: split out virQEMUDriverConfigLoadDeviceEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
e79e0cacc5 qemu_conf: split out virQEMUDriverConfigLoadRPCEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
a780ee8ab5 qemu_conf: split out virQEMUDriverConfigLoadNetworkEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
f78c3dde57 qemu_conf: split out virQEMUDriverConfigLoadLogEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
627595641d qemu_conf: split out virQEMUDriverConfigLoadNVRAMEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:06 +01:00
Ján Tomko
fad7036ad4 qemu_conf: split out virQEMUDriverConfigLoadGlusterDebugEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:05 +01:00
Ján Tomko
632dab43b4 qemu_conf: split out virQEMUDriverConfigLoadSecurityEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:05 +01:00
Ján Tomko
6427aca725 qemu_conf: split out virQEMUDriverConfigLoadMemoryEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:05 +01:00
Ján Tomko
d447293893 qemu_conf: split out virQEMUDriverConfigLoadSWTPMEntry
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-01-18 12:55:05 +01:00
Peter Krempa
b70fb35d81 qemu: process: Use enum belonging to correct type
GCC was unhappy about comparison between two distinct enum types. Use
the correct value instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-01-18 08:39:40 +01:00