Commit Graph

6861 Commits

Author SHA1 Message Date
Michal Privoznik
6534b3c4bb qemuBuildMemPathStr: Forbid memoryBacking/access for non-numa case
https://bugzilla.redhat.com/show_bug.cgi?id=1448149

If a domain has no numa nodes, that means we don't put any
memory-backend-file onto the qemu command line. That in turn
means we can't set access='shared'. Therefore, we should produce
an error instead of ignoring the setting silently.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-03 15:53:00 +01:00
Peter Krempa
f10bb3347b qemu: monitor: Decrease logging verbosity
The PROBE macro used in qemuMonitorIOProcess and the VIR_DEBUG message
in qemuMonitorJSONIOProcess create a lot of logging churn when debug
logging is enabled during monitor communication.

The messages logged from the PROBE macro are rather useless since they
are reporting the partial state of receiving the reply from qemu. The
actual full reply is still logged in qemuMonitorJSONIOProcessLine once
the full message is received.
2018-01-03 15:21:30 +01:00
Andrea Bolognani
a38aa340fe qemu: Enforce vCPU hotplug granularity constraints
QEMU 2.7 and newer don't allow guests to start unless the initial
vCPUs count is a multiple of the vCPU hotplug granularity, so
validate it and report an error if needed.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-02 14:22:06 +01:00
Andrea Bolognani
54acfac4a5 qemu: Invert condition nesting in qemuDomainDefValidate()
While at the moment we're only performing a single check that is
connected to vCPU hotplugging, we're going to introduce a second
one soon. Move the topology check underneath the capability check
to make that easier; since, after this change, the 'topologycpus'
variable doesn't need to have function scope, we move its
declaration to the inner scope as well.

The comments around the check are modified in order to explain
the different QEMU versions involved.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-02 14:22:05 +01:00
John Ferlan
715b321da1 qemu: Move TCP and haveTLS checks into qemuDomainDelChardevTLSObjects
Similar to qemuDomainAddChardevTLSObjects let's move the chardev
source must be TCP and it has the @haveTLS flag set checks before
trying to delete the TLS objects.

For the Chr device this represents no change; however, for RNG device
this is an additionaly check that was missed in commit id '68808516'.
Before adding the objects, TCP and haveTLS are checked.
2017-12-21 10:05:31 -05:00
John Ferlan
10dcdfa32a qemu: Introduce qemuDomainDelChardevTLSObjects
Let's make a comment deletion helper similar to the Add helper
that can be called after the ExitMonitor.

The modify qemuDomainRemoveChrDevice and qemuDomainRemoveRNGDevice
to call the helper instead of inlining the copy and pasted code.
2017-12-21 10:05:31 -05:00
Laine Stump
16a9a28129 qemu: log error on attempts to set filterref on an OVS-connected interface
ebtables/iptables processing is skipped for any interface connected to
Open vSwitch (they have their own packet filtering), likewise for
midonet (according to
http://blog.midokura.com/2016/04/midonet-rule-chains), but libvirt
would allow adding a <filterref> to interfaces connected in these
ways, so the user might mistakenly believe they were being protected.

This patch checks for a non-NULL <virtualport> element for an
interface (or its network) and logs an error if <virtualport> and
<filterref> are both present. This could cause some previously working
domains to no longer start, but that's really the whole point of this
patch - to warn people that their filterref isn't protecting them as
they might have thought.

I don't bother checking this during post-parse validation, because
such a check would be incomplete - it's possible that a network would
have a <virtualport> that would be applied to an interface, and you
can't know that until the domain is started.

Resolves: https://bugzilla.redhat.com/1502754
2017-12-14 14:31:28 -05:00
Laine Stump
b21163bd11 qemu: delete exist bandwidth restrictions when they are removed from config
When the <bandwidth> of an interface is changed with update-device,
the old settings are cleared with tc, then new settings added with
tc. But if the <bandwidth has been removed, the old settings weren't
being removed, so the bandwidth restrictions would still be active on
the interface although the interface status in libvirt showed that
they had been removed.

This patch fixes it by calling virNetDevBandwidthClear() if the
"modification" to the interface bandwidth was to completely clear
it.

An alternative could have been to modify virNetDevBandwidthSet() to
always clear existing bandwith settings at the beginning of the
function (currently it short circuits in that case, doing nothing),
but that would have led to cases where virNetDevBandwidthClear() was
now being called in cases where it previously wasn't, and while many
of those cases would be NOPs, there could be cases where it would
cause an error. The way this patch works, the ...Clear() function is
only called in cases where the ...Set() function had previously been
called successfully, so the risk of regression is minimized.

  Resolves: https://bugzilla.redhat.com/1454709
2017-12-14 13:52:34 -05:00
Ján Tomko
8d51042ef8 qemu: remove input device after receiving the event
Also call qemuDomainRemoveInputDevice if we receive the
event after the Detach API ends.

Commit 67486bb failed to include this.

https://bugzilla.redhat.com/show_bug.cgi?id=1524837
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-12-14 16:36:03 +01:00
Peter Krempa
b3d0270c44 qemu: domain: Parse and format relPath into disk source private data
Register the helpers directly to format and parse the data.

https://bugzilla.redhat.com/show_bug.cgi?id=1523261
2017-12-14 10:29:10 +01:00
Peter Krempa
aed3d038a6 conf: Add infrastructure for disk source private data XML
VM drivers may need to store additional private data to the status XML
so that it can be restored after libvirtd restart. Since not everything
is needed add a callback infrastructure, where VM drivers can add only
stuff they need.

Note that the private data is formatted as a <privateData> sub-element
of the <disk> or <backingStore> <source> sub-element. This is done since
storing it out of band (in the VM private data) would require a complex
matching process to allow to put the data into correct place.
2017-12-14 10:24:36 +01:00
John Ferlan
10c73bf18a qemu: Need to assign PCI address to vhost-scsi
Commit id '70249927b' neglected to cover this case because the test
had taken the "shortcut" to already add the <address>; however, when
the PCI address assignment code was adjusted by commit id '70249927'
the vhost-scsi (VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) wasn't
covered thus returning a 0 for pciFlags. So I altered the tests too
to make sure it doesn't happen again.

Previously the qemuxml2xmloutdata was a softlink to the source
qemuxml2argvdata, so I unlinked and recreated the output file to
force generation of the adddress. Without the test changes, an
address generation returns:

    libvirt: Domain Config error : internal error: Cannot automatically
    add a new PCI bus for a device with connect flags 00

if an address was supplied in the test, a restart of libvirtd or
edit of a guest would display the following opaque message:

    warning : qemuDomainCollectPCIAddress:1237 :
    qemuDomainDeviceCalculatePCIConnectFlags() thinks that the device
     with PCI address 0000:00:09.0 should not have a PCI address

where the address is related to the guest PCI address provided.
2017-12-13 15:37:30 -05:00
John Ferlan
6050affb7f qemu: Tolerate storage source private data being NULL for hotplug SCSI hostdev
Commit id 'c5c96545' neglected to validate that the srcPriv was
non-NULL before dereferencing. Similar problem to what was fixed
by commit id '8056721c' but missed during multiple rebases and
code reworks.
2017-12-13 15:16:15 -05:00
Yuri Chornoivan
ca18914e8a Fix minor typos 2017-12-12 09:13:43 +01:00
Jiri Denemark
fd754cb69c qemu: Avoid comparing size_t with -1
ncpus would be -1 on error and the cleanup for loop would not be skipped
in this case.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-12-11 14:56:22 +01:00
Michal Privoznik
3446750bab qemuDomainUndefineFlags: Fix error message
https://bugzilla.redhat.com/show_bug.cgi?id=1522706

If domain is active, but the undefine API was called without the
VIR_DOMAIN_UNDEFINE_KEEP_NVRAM flag set, the following incorrect
error message is produced:

error: Requested operation is not valid: cannot delete inactive domain with nvram

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-11 13:23:30 +01:00
Lin Ma
07adbd4b1f qemu: Introduce qemuDomainDeviceDefValidateControllerIDE
Move the IDE controller check from command line building to
controller def validation. Also explicitly include the avoidance
check for the implicit IDE controller from qemuBuildSkipController.

Cause the IDE case for command line building to generate a
failure if called to add an IDE since that shouldn't happen
if the Validate code did the right thing.
2017-12-09 11:16:58 -05:00
John Ferlan
29d8c17b98 qemu: Move CCW S390 Address check to controller def validate
Move the call to qemuDomainCheckCCWS390AddressSupport from
qemuBuildControllerDevStr to qemuDomainDeviceDefValidateController.

This means we will get the qemuCaps from the driver opaque
variable passed to qemuDomainDeviceDefValidate.
2017-12-09 11:16:58 -05:00
John Ferlan
3ba921869a qemu: Introduce qemuDomainDeviceDefValidateController
Introduce the bare bones helper to validate whether the controller
definition is valid.
2017-12-09 11:16:58 -05:00
John Ferlan
ac0fb44afa qemu: Introduce qemuBuildSkipController
Move the non USB implicit controller checks into their own
helper to reduce the cruft in qemuBuildControllerDevCommandLine.
2017-12-09 11:16:58 -05:00
Jiri Denemark
ce73de441d qemu: Make sure host-model uses CPU model supported by QEMU
When reconnecting to a running domain started by old libvirt, which did
not change host-model into a custom CPU definition, we replace the CPU
definition with a specific CPU model from host capabilities. However,
that CPU model may not be supported by the running qemu process. We need
to translate the CPU model to one of the models which libvirt could have
used when starting the domain.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-08 15:50:52 +01:00
Jiri Denemark
4486dcdb4a qemu: Separate fetching CPU definitions from filling qemuCaps
virQEMUCapsProbeQMPCPUDefinitions is now a small wrapper which fills in
qemuCaps with CPU models fetched by virQEMUCapsFetchCPUDefinitions.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-08 15:50:52 +01:00
Peter Krempa
fac8724ceb qemu: blockjob: Reset disk source index after pivot
Since we are re-detecting the backing chain after pivoting to the active
block commit target (or block copy target) the disk index needs to be
reset to 0. This is necessary since we move a member of the backing
chain to disk->src but clear indexes only starting from
disk->src->backingStore. The freshly detected images have indexes
starting from 1, but since we've pivoted into an image which was
previously a backing store it would have a non-0 index.
The lookup function would then return the top of the chain for queries
like 'vda[1]' instead of the first backing store.

This problem will not be present once we keep the disk indexes stable.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1519745
2017-12-08 10:13:57 +01:00
Ján Tomko
e2ad8e5993 qemuDomainNamespaceSetupDisk: initialize npaths
Introduced by commit d3db304.

Reported-by: John Ferlan <jferlan@redhat.com>
2017-12-07 14:36:02 +01:00
John Ferlan
cc9d272478 qemu: Use virDomainControllerType in qemuBuildControllerDevStr switch
Make sure all types of virDomainControllerType are handled in the
switch statement.
2017-12-06 19:50:11 -05:00
Ján Tomko
a6f7c1b04c Do not pass driver to qemuDomainNamespace{Setup,Teardown} functions
The underlying function which needs the driver gets it from the
passed virDomainObj object anyway.
2017-12-06 16:47:08 +01:00
Ján Tomko
c317328976 Introduce qemuDomainNamespaceUnlinkPath
Use it in every qemuDomainNamespaceTeardown* function that only
wants to unlink one device.
2017-12-06 16:47:08 +01:00
Ján Tomko
7a931a4204 Introduce qemuDomainNamespaceUnlinkPaths
Split out the logic of unlinking devices from
qemuDomainNamespaceTeardownHostdev for reuse in other functions.
2017-12-06 16:47:05 +01:00
Ján Tomko
323b9f72ef Introduce qemuDomainNamespaceMknodPath
Use this function in qemuDomainNamespaceSetup* functions which
only require creating one device.
2017-12-06 15:21:49 +01:00
Ján Tomko
d3db304d2e Introduce qemuDomainNamespaceMknodPaths
Separate the logic of creating devices from their gathering.

Use this new function in qemuDomainNamespaceSetupHostdev and
qemuDomainNamespaceSetupDisk.
2017-12-06 15:21:49 +01:00
Ján Tomko
bc50c99edf qemuDomainNamespaceSetupHostdev: rename path to paths
To match the "things/nthings" pattern used in virDomainDef.
2017-12-06 15:21:49 +01:00
Ján Tomko
be97d8496a qemuDomainNamespaceTeardownHostdev: rename path to paths
To match the "things/nthings" pattern used in virDomainDef.
2017-12-06 15:21:49 +01:00
Nikolay Shirokovskiy
5b0451ab57 qemu: report drive mirror errors on migration
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-06 12:43:57 +01:00
Nikolay Shirokovskiy
bc444666f7 qemu: prepare blockjob complete event error usage
This patch pass event error up to the place where we can
use it. Error is passed only for sync blockjob event mode
as we can't use the error in async mode. In async mode we
just pass the event details to the client thru event API
but current blockjob event API can not carry extra parameter.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-06 12:43:57 +01:00
Pavel Hrdina
1c57eea362 qemu: fix security labeling for attach/detach of char devices
Commit e93d844b90 was not enough to fix the permission denied
issue.  We need to apply security labels as well.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-12-05 13:54:48 +01:00
Michal Privoznik
3eb840904a qemuStateInitialize: Don't leak @memoryBackingPath
==899== 39 bytes in 1 blocks are definitely lost in loss record 732 of 1,003
==899==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==899==    by 0x8B68CE7: vasprintf (in /lib64/libc-2.25.so)
==899==    by 0x55498D2: virVasprintfInternal (virstring.c:708)
==899==    by 0x55499E7: virAsprintfInternal (virstring.c:729)
==899==    by 0x2BECFFF0: qemuGetMemoryBackingBasePath (qemu_conf.c:1757)
==899==    by 0x2BF23225: qemuStateInitialize (qemu_driver.c:893)
==899==    by 0x563073D: virStateInitialize (libvirt.c:770)
==899==    by 0x124CC4: daemonRunStateInit (libvirtd.c:834)
==899==    by 0x55521CD: virThreadHelper (virthread.c:206)
==899==    by 0x88D9686: start_thread (in /lib64/libpthread-2.25.so)
==899==    by 0x8BEAEFE: clone (in /lib64/libc-2.25.so)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:06:19 +01:00
Peter Krempa
adcc31bb89 qemu: domain: Fix backing store terminator for non-backing local files
Raw local files do not pass through the backing store detector and thus
the code did not allocate the required backing store terminator for
them. Previously the terminating element would be formatted into the XML
since the default values used for the metadata allowed that. This is a
regression since a693fdba01 which was not detected in the review.

This patch also reverts all the changes in the test files.
2017-11-30 22:40:23 +01:00
Peter Krempa
24e47ee2b9 qemu: process: Move handling of non-backing files into qemuDomainDetermineDiskChain
Until now we would skip loading of the backing chain for files which
don't support backing chains only when starting up the VM. Move the
check from qemuProcessPrepareHostStorage with some adaptations so that's
always applied.
2017-11-30 22:40:23 +01:00
Peter Krempa
b19710b9b6 qemu: domain: Refactor control flow in qemuDomainDetermineDiskChain
Split out clearing of the backing chain prior to other code since it
will be required later and optimize few layers of nested conditions and
loops.
2017-11-30 22:40:23 +01:00
Ján Tomko
65108d94d0 virQEMUCapsHasPCIMultiBus: assume true if we have no version information
In status XML, we do not store the QEMU version information, we only
format all the capabilities. We dropped QEMU_CAPS_PCI_MULTIBUS
in commit 5b783379 which was released in libvirt 3.2.0.

Therefore the only way of telling if the already running domain
at the time of daemon restart has been started with a QEMU that does
use 'pci.0' or not on PPC is to look at the pci-root controller's
alias. This is not an option if the domain has a user-specified alias
for the pci-root.

Instead of reintroducing the capability, assume 'pci.0' when we have
no version information. That way the only left broken use case would
be the combination of user aliases and very old QEMU.

Partially reverts commit 3a37af1e4.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Ján Tomko
fdf354fb51 virQEMUCapsHasPCIMultiBus: use def->os.arch
We do not fill out qemuCaps->arch when parsing status XML.

Use def->os.arch like we do for PPC.

This fixes hotplug after daemon restart for domains that use
a user alias for the implicit pci-root on x86.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Ján Tomko
dacfc6b10b qemu: prefer the PCI bus alias from status XML
For some corner cases, virQEMUCapsHasPCIMultiBus depends on the QEMU
version, which is by design not stored in the status XML and therefore
it cannot be fixed for all existing running domains.

Prefer the controller alias read from the status XML when formatting
PCI addresses and only fall back to using virQEMUCapsHasPCIMultiBus
if the alias is a user alias.

This fixes hotplug after daemon restart for domains not using user
aliases.

Partially reverts commit 937f3195.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Boris Fiuczynski
681bc423e8 qemu-capabilities: Adjust function header comments of virQEMUCapsInitCPUModel*
Adjust function descriptions of virQEMUCapsInitCPUModelS390 and
virQEMUCapsInitCPUModel to the changes introduced with
commitID 74fc32a955.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-11-29 17:40:31 +01:00
Andrea Bolognani
b2fb483c34 qemu: Require QEMU_CAPS_DEVICE_PL011 for pl011
Even though we never format the device on the QEMU command line,
as it's a platform serial device that's not user-instantiable,
we should still make sure it's available before using it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:41 +01:00
Andrea Bolognani
a45ecb7bf6 qemu: Add QEMU_CAPS_DEVICE_PL011
All serial devices shoule have an associated capability.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:37 +01:00
Andrea Bolognani
b9be657b68 qemu: Require QEMU_CAPS_DEVICE_ISA_SERIAL for isa-serial
We should make sure the isa-serial device is available before
formatting it on the QEMU command line.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:35 +01:00
Andrea Bolognani
b0f1c291a0 qemu: Add QEMU_CAPS_DEVICE_ISA_SERIAL
All serial devices shoule have an associated capability.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:51:33 +01:00
Pino Toscano
220c1f70dc qemu: switch s390/s390x default console back to serial
Now that <serial> and <console> on s390/s390x behave a bit more like the
other architectures, remove this extra differentation, and use sclp
console by default for new guests.  New virtio consoles can still be
added, and it is actually needed because of the limited number of
instances for sclp and sclplm.

This reverts commit b1c88c1476, whose
reasons are not totally clear.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2017-11-28 15:48:59 +01:00
Pino Toscano
21332bf658 conf: add VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP
Introduce specific a target types with two models for the console
devices (sclp and sclplm) used in s390 and s390x guests, so isa-serial
is no more used for them.

This makes <serial> usable on s390 and s390x guests, with at most only
a single sclpconsole and one sclplmconsole devices usable in a single
guest (due to limitations in QEMU, which will enforce already at
runtime).

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

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00
Andrea Bolognani
eccdcb81fc conf: Add target type and model for pl011
We can finally introduce a specific target model for the pl011 device
used by mach-virt guests, which means isa-serial will no longer show
up to confuse users.

We make sure migration works in both directions by interpreting the
isa-serial target type, or the lack of target type, appropriately
when parsing the guest XML, and skipping the newly-introduced type
when formatting if for migration. We also verify that pl011 is not
used for non-mach-virt guests and add a bunch of test cases.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00