Commit Graph

6793 Commits

Author SHA1 Message Date
Peter Krempa
bb15ac4599 qemu: block: Break out early on invalid storage sources
Return NULL right away in qemuBlockStorageSourceGetBackendProps when an
invalid storage source is presented so that virJSONValueObjectAdd isn't
called with a NULL argument.

Found by coverity.
2017-11-13 13:18:34 +01:00
Michal Privoznik
9324f67a57 qemuBuildDriveDevStr: Prefer default aliases for IDE bus
https://bugzilla.redhat.com/show_bug.cgi?id=1434451

When testing user aliases it was discovered that for 440fx
machine type which has default IDE bus builtin, domain cannot
start if IDE controller has the user provided alias. This is
because for 440fx we don't put the IDE controller onto the
command line (since it is builtin) and therefore any device that
is plugged onto the bus must use the default alias.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-10 15:23:55 +01:00
Peter Krempa
5af63c9aa3 conf: Fix type for @liveStatus in virDomainObjListLoadAllConfigs
Use bool instead of an int.
2017-11-09 10:37:58 +01:00
Michal Privoznik
3d899b9965 qemu-ns: Detect /dev/* mount point duplicates even better
In 4f15707202 I've tried to make duplicates detection for
nested /dev mount better. However, I've missed the obvious case
when there are two same mount points. For instance if:

  # mount --bind /dev/blah /dev/blah
  # mount --bind /dev/blah /dev/blah

Yeah, very unlikely (in qemu driver world) but possible.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-08 16:38:26 +01:00
Michal Privoznik
fec8f9c49a qemu: Use predictable file names for memory-backend-file
In some cases management application needs to allocate memory for
qemu upfront and then just let qemu use that. Since we don't want
to expose path for memory-backend-file anywhere in the domain
XML, we can generate predictable paths. In this case:

  $memoryBackingDir/libvirt/qemu/$shortName/$alias

where $shortName is result of virDomainDefGetShortName().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:17 +01:00
Michal Privoznik
bb3de478a6 qemu: Destroy whole memory tree
When removing path where huge pages are call virFileDeleteTree
instead of plain rmdir(). The reason is that in the near future
there's going to be more in the path than just files - some
subdirs. Therefore plain rmdir() is not going to be enough.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:11 +01:00
Michal Privoznik
eff2b2edb1 qemu: Rename qemuProcessBuildDestroyHugepagesPath
At the same time, move its internals into a separate function so
that they can be reused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:10 +01:00
Michal Privoznik
d52e6043bc qemu: Set alias for memory cell in qemuBuildMemoryCellBackendStr
Very soon qemuBuildMemoryBackendStr() is going to use memory cell
aliases. Therefore set one. At the same time, move it a bit
further - if virAsprintf() fails, there's no point in setting
rest of the members.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:08 +01:00
Peter Krempa
31bbb15884 qemu: block: Add node-names to JSON backing storage strings
Format out the node-name if it was assigned for JSON-based storage
specification.
2017-11-07 16:12:52 +01:00
Peter Krempa
caf71b64fe qemu: block: Add JSON props generator for ssh storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
8da68d87ff qemu: block: Add JSON props generator for sheepdog storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
5e9e693262 qemu: block: Add JSON props generator for RBD storage backing 2017-11-07 16:12:29 +01:00
Peter Krempa
84955c6257 qemu: block: Add JSON props generator for NBD storage backing 2017-11-07 16:11:38 +01:00
John Ferlan
ea0cc4f4b0 qemu: block: Add JSON props generator for iSCSI protocol 2017-11-07 16:04:53 +01:00
Peter Krempa
97ee821a17 qemu: block: Add JSON props generator for 'curl' based storage backends
QEMU uses curl for accessing files using http(s) and ftp(s). They share
common options so let's generate them in one helper.
2017-11-07 14:58:48 +01:00
Peter Krempa
90521d0754 storage: Store RBD image name as pool and image name
Similarly to how we store gluster names, split the name into a pool and
image portions when paring the XML and store them separately.
2017-11-07 14:58:04 +01:00
Peter Krempa
bb14d9897b storage: Don't store leading '/' in image name when splitting out volume
Libvirt historically stores storage source path including the volume as
one string in the XML, but that is not really flexible enough when
dealing with the fields in the code. Previously we'd store the slash
separating the two as part of the image name. This was fine for gluster
but it's not necessary and does not scale well when converting other
protocols.

Don't store the slash as part of the path. The resulting change from
absolute to relative path within the gluster driver should be okay,
as the root directory is the default when accessing gluster.
2017-11-07 14:58:04 +01:00
Peter Krempa
1ee7d4d972 qemu: process: Split out useful parts from qemuBuildNetworkDriveURI
Extract the part formatting the basic URI part so that it can be reused
to format JSON backing definitions. Parts specific to the command line
format will remain in qemuBuildNetworkDriveURI. The new function is
called qemuBlockStorageSourceGetURI.
2017-11-07 14:57:58 +01:00
Peter Krempa
bd37213786 qemu: block: Use proper type for servers for VxHS disks
Original implementation used 'SocketAddress' equivalent from qemu for
the disk server field, while qemu documentation specifies
'InetSocketAddress'. The backing store parser uses the correct parsing
function but the formatter used the incorrect one (and also with the
legacy mode enabled which was wrong).
2017-11-07 14:43:12 +01:00
Peter Krempa
1f467d1ab1 qemu: command: Move disk serial validation to qemuCheckDiskConfig 2017-11-07 14:38:11 +01:00
Peter Krempa
cf1fcd7b51 qemu: command: Move blkiotune checks to qemuCheckDiskConfig 2017-11-07 14:33:38 +01:00
Peter Krempa
5121457cad qemu: command: Refactor blkiotune checks to tolerate NULL qemuCaps
To allow aggregating the checks, refactor the code to check capabilities
only if they were provided.
2017-11-07 14:33:23 +01:00
Peter Krempa
1055c1bf24 qemu: command: Merge checks from qemuBuildDriveStrValidate to qemuCheckDiskConfig
Stash all the disk definition and capability checks into one function.
2017-11-07 14:33:18 +01:00
Peter Krempa
5fb7ab2c9e qemu: command: Refactor qemuBuildDriveStrValidate to make qemuCaps optional
To allow merging this with other disk type checks we need to check
qemuCaps only when available, since some of the checks are executed on
disk cold-plug and thus capabilities should not be checked.

Make the checks optional by making them conditional on qemuCaps not
being NULL.
2017-11-07 14:31:21 +01:00
Peter Krempa
f15ed22757 qemu: command: Directly report bus type in qemuBuildDriveStrValidate
All of the error message are already in a conditional block with known
bus type. Inline the bus type rather than formatting it from a separate
variable.
2017-11-07 14:31:15 +01:00
Peter Krempa
dfd300a71d qemu: command: Move disk index validation closer to usage
The disk index validation is used only in very specific cases and does
not need to be performed otherwise. Move it out of the global check into
the usage place.
2017-11-07 14:29:37 +01:00
Peter Krempa
b60ce7b122 qemu: command: Remove dead code when formatting -drive
busid and unitid are ever used only if the device is an SD card due to
the check in qemuDiskBusNeedsDeviceArg. Since the SD card does not have
an bus or unit number, most of the code and command line formatter can
be removed since it will never be used.
2017-11-07 14:29:37 +01:00
Michal Privoznik
ae1b5d47e5 qemu: Move memPath generation from memoryBackingDir to a separate function
In near future we will need more than just a plain VIR_STRDUP().
Better implement that in a separate function and in
qemuBuildMemoryBackendStr() which is complicated enough already.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:06 +01:00
Michal Privoznik
fe70fd0c10 conf: s/virDomainObjGetShortName/virDomainDefGetShortName/
This function works over domain definition and not domain object.
Its name is thus misleading.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:00 +01:00
Andrea Bolognani
3e7db8d3e8 Remove backslash alignment attempts
Right-aligning backslashes when defining macros or using complex
commands in Makefiles looks cute, but as soon as any changes is
required to the code you end up with either distractingly broken
alignment or unnecessarily big diffs where most of the changes
are just pushing all backslashes a few characters to one side.

Generated using

  $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
    grep -E '*\.([chx]|am|mk)$$' | \
    while read f; do \
      sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
    done

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:12 +01:00
Peter Krempa
a92c4f7537 qemu: domain: skip chain detection to end of backing chain
When a user provides the backing chain, we will not need to re-detect
all the backing stores again, but should move to the end of the user
specified chain. Additionally if a user provides a full terminated chain
we should not attempt any further detection.
2017-11-03 10:27:32 +01:00
Peter Krempa
b0a46b609e qemu: domain: Prepare TLS data for the whole backing chain
Iterate through the backing chain when setting up TLS for disks.
2017-11-03 10:23:21 +01:00
Peter Krempa
beb1661f3d qemu: domain: Remove pointless alias check
When attaching the disks, aliases are always generated.
2017-11-03 10:23:21 +01:00
Peter Krempa
d565877312 qemu: domain: Destroy secrets for complete backing chain 2017-11-03 10:23:21 +01:00
Peter Krempa
e53a42f0f6 qemu: domain: Extract setup for disk source secrets
Separate it so that it deals only with single virStorageSource, so that
it can later be reused for full backing chain support.

Two aliases are passed since authentication is more relevant to the
'storage backend' whereas encryption is more relevant to the protocol
layer. When using node names, the aliases will be different.
2017-11-03 10:23:16 +01:00
Peter Krempa
2b757b964b qemu: domain: Simplify using DAC permissions of top of backing chain
qemuDomainGetImageIds and qemuDomainStorageFileInit are helpful when
trying to access a virStorageSource from the qemu driver since they
figure out the correct uid and gid for the image.

When accessing members of a backing chain the permissions for the top
level would be used. To allow using specific permissions per backing
chain level but still allow inheritance from the parent of the chain we
need to add a new parameter to the image ID APIs.
2017-11-03 09:15:41 +01:00
Jiri Denemark
a1e3e8ddbd qemu: Add support for block-incremental migration parameter
We handle incremental storage migration in a different way. The support
for this new (as of QEMU 2.10) parameter is only needed for full
coverage of migration parameters used by QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
f6e2a70ae2 qemu: Add support for max-bandwidth migration parameter
We already support several ways of setting migration bandwidth and this
is not adding another one. With this patch we are able to read and write
this parameter using query-migrate-parameters and migrate-set-parameters
in one call with all other parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
af1d2fe270 qemu: Rename TLS related migration parameters
The parameters used "migrate" prefix which is pretty redundant and
qemuMonitorMigrationParams structure is our internal representation of
QEMU migration parameters and it is supposed to use names which match
QEMU names.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
2384b6f019 qemu: Add support for setting downtime-limit migration parameter
We already support setting the maximum downtime with a dedicated
virDomainMigrateSetMaxDowntime API. This patch does not implement
another way of setting the downtime by adding a new public migration
parameter. It just makes sure any parameter we are able to get from a
QEMU monitor by query-migrate-parameters can be passed back to QEMU via
migrate-set-parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
487759126b qemu: Drop giant if statement from qemuMonitorSetMigrationParams
The check can be easily replaced with a simple test in the JSON
implementation and we don't need to update it every time a new parameter
is added.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
6bc3d06700 qemu: Use macro for setting string migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
27e5633724 qemu: Generalize APPEND macro in qemuMonitorJSONSetMigrationParams
The APPEND macro is now be usable for any type.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
7ddcab891e qemu: Use macro for parsing ull migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
4fabc0caa0 qemu: Use macro for parsing string migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
c04fbbd9c9 qemu: Generalize PARSE macro in qemuMonitorJSONGetMigrationParams
The macro (now called PARSE_SET) is now usable for any type which needs
a *_set bool for indicating a valid value.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Michal Privoznik
98696fd170 qemuDomainSetInterfaceParameters: Explicitly reject unsupported net types
For instance, NET_TYPE_MCAST doesn't support setting QoS. Instead
of claiming success and doing nothing, we should be explicit
about that and report an error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-27 14:59:29 +02:00
John Ferlan
c9f7a04e28 qemu.conf: Clarify the various _tls_x509_cert_dir descriptions
https://bugzilla.redhat.com/show_bug.cgi?id=1458630

Apparantly commit id 'dc4c2f75a' wasn't specific enough, so here's
a few more clarifications.
2017-10-27 05:53:45 -04:00
Marc Hartmayer
a50b45a297 qemu: Fix memory leak in virQEMUCapsLoadCPUModels
Don't leak @blockNodes in the loop.

==226576== 7,120 bytes in 60 blocks are definitely lost in loss record 122 of 125
==226576==    at 0x4835214: calloc (vg_replace_malloc.c:711)
==226576==    by 0x4950D7B: virAllocN (viralloc.c:191)
==226576==    by 0x49EB5BB: virXPathNodeSet (virxml.c:676)
==226576==    by 0x104DB67: virQEMUCapsLoadCPUModels (qemu_capabilities.c:3738)
==226576==    by 0x105510D: virQEMUCapsLoadCache (qemu_capabilities.c:3929)
==226576==    by 0x104459F: qemuTestParseCapabilities (testutilsqemu.c:498)
==226576==    by 0x1040DC9: testQemuCapsCopy (qemucapabilitiestest.c:105)
==226576==    by 0x1041F07: virTestRun (testutils.c:180)
==226576==    by 0x1040B45: mymain (qemucapabilitiestest.c:181)
==226576==    by 0x104320F: virTestMain (testutils.c:1119)
==226576==    by 0x1041149: main (qemucapabilitiestest.c:193)

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-27 10:13:43 +02:00
Jiri Denemark
32c29f10db qemu: Enabled pause-before-switchover migration capability
QEMU identified a race condition between the device state serialization
and the end of storage migration. Both QEMU and libvirt needs to be
updated to fix this.

Our migration work flow is modified so that after starting the migration
we to wait for QEMU to enter "pre-switchover", "postcopy-active", or
"completed" state. Once there, we cancel all block jobs as usual. But if
QEMU is in "pre-switchover", we need to resume the migration afterwards
and wait again for the real end (either "postcopy-active" or
"completed" state).

Old QEMU will just enter either "postcopy-active" or "completed"
directly, which is still correctly handled even by new libvirt. The
"pre-switchover" state will only be entered if QEMU supports it and the
pause-before-switchover capability was enabled. Thus all combinations of
libvirt and QEMU will work, but only new QEMU with new libvirt will
avoid the race condition.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-26 10:36:02 +02:00
Jiri Denemark
6addde24be qemu: Add pause-before-switchover migration capability
This new capability enables a pause before device state serialization so
that we can finish all block jobs without racing with the end of the
migration. The pause is indicated by "pre-switchover" state. Once we're
done QEMU enters "device" migration state.

This patch just defines the new capability and QEMU migration states and
their mapping to our job states.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-26 10:36:02 +02:00
Jiri Denemark
b5ec33b832 qemu: Add support for migrate-continue QMP command
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-26 10:36:02 +02:00
Jiri Denemark
f26636887f qemu: Reset hasManagedSave after removing a corrupted image
When starting a domain with managed save image, we try to restore it
first. If the image is corrupted, we silently unlink it and just
normally start the domain. At this point the domain has no managed save
image, yet we did not reset the hasManagedSave flag.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-24 11:07:10 +02:00
Jiri Denemark
55ac6a5d44 qemu: Set correct job status when qemuMigrationRun fails
Instead of enumerating all states which need to be turned into
QEMU_DOMAIN_JOB_STATUS_FAILED (and failing to add all of them), it's
better to mention just the one which needs to be left alone.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
73a352263c qemu: Consistently use exit_monitor in qemuMigrationRun
Almost every failure in qemuMigrationRun while we are talking to QEMU
monitor results in a jump to exit_monitor label. The only exception is
removed by this patch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
af32e57f8e qemu: Don't misuse "ret" in qemuMigrationRun
The "ret" variable is used for storing the return value of a function
and should not be used as a temporary variable.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
7d2fbabcaf qemu: Unite error handling in qemuMigrationRun
Merge cancel and cancelPostCopy sections with the generic error section,
where we can easily decide whether canceling the ongoing migration is
required.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
c1a643b68f qemu: Split cleanup and error code in qemuMigrationRun
Let cleanup only do things common to both failure and success paths and
move error handling code inside the new "error" section.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
f8ede9cc23 qemu: Refactor qemuMigrationRun a bit
Some code which was supposed to be executed only when migration
succeeded was buried inside the cleanup code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Jiri Denemark
9603262377 qemu: Use switch in qemuMigrationCompleted
When adding a new job state it's useful to let the compiler complain
about places where we need to think about what to do with the new
state.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-23 10:08:29 +02:00
Michal Privoznik
f3bc68e221 qemu: Parse alias from inactive XMLs
https://bugzilla.redhat.com/show_bug.cgi?id=1434451

This way users can uniquely identify devices at define time.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-23 09:01:46 +02:00
Michal Privoznik
92f41b3297 qemuDomainABIStabilityCheck: Check for memory aliases too
Since we will be allowing users to set device aliases and memory
devices are fragile when it comes to aliases we have to make sure
they won't change during migration. Other devices should be fine.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-23 08:52:08 +02:00
Michal Privoznik
e2797e3256 conf: Validate user supplied aliases
They have to be unique within the domain. As usual, backwards
compatibility takes its price. In this particular situation we
have a device that is represented twice in a domain and so is its
alias.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-23 08:52:01 +02:00
Michal Privoznik
ad30f069d1 qemu_alias: Be more tolerant if alias don't follow our format
When assigning alias to a device we usually iterate over other
devices of its kind trying to find next index. We do this by
stripping down the prefix and then parsing number at the end,
Usually, if the prefix doesn't match the one we are expecting, we
just continue with next iteration. Except for couple of
functions: qemuGetNextChrDevIndex(),
qemuAssignDeviceRedirdevAlias() and qemuAssignDeviceShmemAlias().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-22 13:49:46 +02:00
Jiri Denemark
58c1e16951 qemu: Enhance debug message in qemuMonitorSetMigrationCapability
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-20 13:37:03 +02:00
Jiri Denemark
38b0e4f58f qemu: Drop qemuMonitorGetMigrationCapability
The only remaining user of qemuMonitorGetMigrationCapability is our test
suite. Let's replace qemuMonitorGetMigrationCapability with
qemuMonitorGetMigrationCapabilities there and drop the unused function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-20 13:37:03 +02:00
Jiri Denemark
310287b1c9 qemu: Use bitmap with migration capabilities
All calls to qemuMonitorGetMigrationCapability in QEMU driver are
replaced with qemuMigrationCapsGet.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-20 13:37:03 +02:00
Jiri Denemark
765d9b1245 qemu: Store supported migration capabilities in a bitmap
Each time we need to check whether a given migration capability is
supported by QEMU, we call query-migrate-capabilities QMP command and
lookup the capability in the returned list. Asking for the list of
supported capabilities once when we connect to QEMU and storing the
result in a bitmap is much better and we don't need to enter a monitor
just to check whether a migration capability is supported.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-20 13:36:56 +02:00
Jiri Denemark
19bade7ad9 qemu: Create a wrapper around qemuMonitorSetCapabilities
The new function is called qemuProcessInitMonitor and it will enter/exit
the monitor so that the caller doesn't have to deal with this.

The goal of this patch is to simplify the code in qemuConnectMonitor
which would otherwise be a bit hairy after the following patch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-20 09:08:45 +02:00
John Ferlan
0e2e22485e qemu: Move encinfo from private disk to private disk src
Since the encryption information can also be disk source specific
move it from qemuDomainDiskPrivate to qemuDomainStorageSourcePrivate

Since the last allocated element from qemuDomainDiskPrivate is
removed, that means we no longer need qemuDomainDiskPrivateDispose.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2017-10-19 18:20:30 +02:00
John Ferlan
ab0e32fbdf qemu: Relocate qemuDomainSecretInfoPtr to qemuDomainStorageSourcePrivate
Since the secret information is really virStorageSource specific
piece of data, let's manage the privateData from there instead of
at the Disk level.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2017-10-19 18:20:30 +02:00
John Ferlan
3ff3eb70c7 qemu: Introduce privateData object for virStorageSource
Add the object definition and helpers to store security-related private
data for virStorageSources.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2017-10-19 18:20:30 +02:00
John Ferlan
76a5ca62fb qemu: Add missing encinfo cleanup
When commit id 'da86c6c22' added support for diskPriv->encinfo in
qemuDomainSecretDiskPrepare a change to qemuDomainSecretDiskDestroy
to was missed. Although qemuDomainDiskPrivateDispose probably would
do the trick.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-19 18:20:30 +02:00
Michal Privoznik
4f15707202 qemu-ns: Detect /dev/* mount point duplicates better
https://bugzilla.redhat.com/show_bug.cgi?id=1495511

When creating new /dev for domain ran in namespace we try to
preserve all sub-mounts of /dev. Well, not quite all. For
instance if /dev/foo/bar and /dev/foo are both mount points, only
/dev/foo needs preserving. /dev/foo/bar is preserved with it too.
Now, to identify such cases like this one STRPREFIX() is used.
That is not good enough. While it works for [/dev/foo/bar;
/dev/foo] case, it fails for [/dev/prefix; /dev/prefix2] where
the strings share the same prefix but are in fact two different
paths. The solution is to use STRSKIP().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 17:33:31 +02:00
Michal Privoznik
6bc4a371cf qemu: Be tolerant to preexisting aliases
In the future, some aliases might be already parsed therefore we
should avoid overwriting them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:33:27 +02:00
Michal Privoznik
215ab7aa03 qemu: Move device alias assignment to separate functions
Let's move all the virAsprintf()-s into separate functions for
better structure of the code. Later, when somebody wants to
generate a device alias, all they need is to expose the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:32:50 +02:00
Michal Privoznik
16bb5a710e qemuAssignDeviceAliases: Use qemuAssignDeviceRNGAlias for assigning RNG aliases
We have a special function for assigning aliases to RNG devices.
Use that instead of plain virAsprintf().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:28:56 +02:00
Peter Krempa
05d4323989 qemu: hotplug: Reuse qemuDomainAttachDiskGeneric in qemuDomainAttachUSBMassStorageDevice
Apart from killing a lot of code this also "implements" authentication
and encryption for USB disks.
2017-10-19 15:04:00 +02:00
Peter Krempa
4e6ac368a5 qemu: hotplug: Reuse qemuDomainAttachDiskGeneric in qemuDomainAttachSCSIDisk
Get rid of the first copy of the mess.
2017-10-19 15:02:44 +02:00
Peter Krempa
5b0dc7fdfd qemu: hotplug: extract disk hotplug worker code
This horrible piece of spaghetti code is copy-past(ae)d in the SCSI and
USB disk hotplug code with minimal changes. Extract it for further
reuse.
2017-10-19 15:00:58 +02:00
Peter Krempa
3c437ebf40 qemu: hotplug: Use disk target in debug/warning messages where appropriate
Some messages deal with the disk itself thus using the disk target is
better than using the disk source name which can be NULL in some cases.
2017-10-19 14:50:50 +02:00
Peter Krempa
c01a2e057f qemu: hotplug: Remove wrong check for empty disks
The check if the disk is empty is wrong and would spuriously reject NBD
sources. Remove it.
2017-10-19 14:50:50 +02:00
Peter Krempa
a4bac46c96 qemu: address: Remove dead code when un-reserving PCI address
The code can't fail so having error handling is pointless.
2017-10-19 14:50:50 +02:00
Ján Tomko
537e86f031 fix error message spacing in qemuDomainDetachNetDevice
Move the space after the colon.
2017-10-19 14:46:13 +02:00
Ján Tomko
311f4069f9 qemu: remove pointless address validation on hot unplug
Back in the times of using 'pci_del', unplugging a device without
a PCI address was not wired up.

After completely removing support for qemu without QEMU_CAPS_DEVICE,
aliases are used to uniquely identify devices in all cases.

Remove the pointless validation of data that was already present
in the domain definition.
2017-10-19 14:45:15 +02:00
Ján Tomko
8a0d84e25b qemuIsMultiFunctionDevice: return early for non-PCI addresses
There is no point in iterating over all devices if none of them
could possibly match.
2017-10-19 14:45:15 +02:00
Ján Tomko
67486bb295 qemu: implement input device hotunplug
Allow unplugging USB and virtio USB devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:43:22 +02:00
Ján Tomko
bc9ffafcc7 qemu: implement input device hotplug
For both virtio input devices and USB input devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:43:22 +02:00
Ján Tomko
c547a5f8d8 Introduce qemuBuildInputDevStr
A function that builds the -device string for input devices.
2017-10-19 14:43:22 +02:00
Ján Tomko
d059b24aea split out qemuAssignDeviceInputAlias
Move assignment of input device alias into a separate function,
for reuse on hotplug.
2017-10-19 14:43:20 +02:00
Ján Tomko
513a8d4588 qemu: allow cold unplugging of input devices
https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:42:10 +02:00
Ján Tomko
ba589d88bc qemu: allow coldplugging input devices
https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:42:10 +02:00
Ján Tomko
f0cab974af Use qemuDomainEnsureVirtioAddress where possible
There are two more cases where we set an S390/CCW/PCI address
type based on the machine type.

Reuse qemuDomainEnsureVirtioAddress to reduce repetition.
2017-10-19 14:41:55 +02:00
Ján Tomko
f16600ff91 Split out qemuDomainEnsureVirtioAddress
Split out the common code responsible for reserving/assigning
PCI/CCW addresses for virtio disks into a helper function
for reuse by other virtio devices.
2017-10-19 14:41:51 +02:00
Ján Tomko
5ec76b0cb4 Move qemuCheckCCWS390AddressSupport to qemu_domain
Let it be reused in qemu_domain_address.
2017-10-19 14:39:05 +02:00
Ján Tomko
fef2855366 qemuDomainAttachRNGDevice: do not access source.file randomly
We pass the source.file to qemuCheckCCWS390AddressSupport for
the purpose of reporting an error message without actually checking
that the rng device is of type VIR_DOMAIN_RNG_BACKEND_RANDOM.

Change it to a hardcoded "rng" string, which also avoids
referring to the device by a host-side attribute.
2017-10-19 14:34:21 +02:00
Ján Tomko
7afaaa934b qemuDomainAttachControllerDevice: remove dead code
After a successful attach, the device address has already been set.
Remove the pointless assignment.
2017-10-19 14:34:21 +02:00
Pavel Hrdina
d66fc71d31 qemu: implement virDomainSetLifecycleAction() API
There is one limitation for using this API, when the guest is started
with all actions set to "destroy" we put "-no-reboot" on the QEMU
command line.  That cannot be changed while QEMU is running and
the QEMU process is always terminated no matter what is configured
for any action.

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:38 +02:00
Pavel Hrdina
e859da6f42 qemu: send allowReboot in migration cookie
We need to send allowReboot in the migration cookie to ensure the same
behavior of the virDomainSetLifecycleAction() API on the destination.

Consider this scenario:

    1. On the source the domain is started with:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>restart</on_reboot>
        <on_crash>destroy</on_crash>

    2. User calls an API to set "destroy" for <on_reboot>:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>destroy</on_reboot>
        <on_crash>destroy</on_crash>

    3. The guest is migrated to a different host

    4a. Without the allowReboot in the migration cookie the QEMU
        process on destination would be started with -no-reboot
        which would prevent using the virDomainSetLifecycleAction() API
        for the rest of the guest lifetime.

    4b. With the allowReboot in the migration cookie the QEMU process
        on destination is started without -no-reboot like it was started
        on the source host and the virDomainSetLifecycleAction() API
        continues to work.

The following patch adds a QEMU implementation of the
virDomainSetLifecycleAction() API and that implementation disallows
using the API if all actions are set to "destroy" because we add
"-no-reboot" on the QEMU command line.  Changing the lifecycle action
is in this case pointless because the QEMU process is always terminated.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:34 +02:00
Pavel Hrdina
a9d637e71e qemu: move detection whether to use -no-reboot to qemu_domain
This will be used later on in implementation of new API
virDomainSetLifecycleAction().  In order to use it, we need to store
the value in status XML to not lose the information if libvirtd is
restarted.

If some guest was started by old libvirt where it was not possible
to change the lifecycle action for running guest, we can safely
detect it based on the current actions from the status XML.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:30 +02:00