Commit Graph

6922 Commits

Author SHA1 Message Date
John Ferlan
5870f95a7a qemu: Add dump completed event to the capabilities
Add the DUMP_COMPLETED check to the capabilities. This is the
mechanism used to determine whether the dump-guest-memory command
can support the "-detach" option and thus be able to wait on the
event and allow for a query of the progress of the dump.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-02 15:19:14 -05:00
John Ferlan
3f99bb06d1 qemu: Introduce qemuDomainGetJobInfoMigrationStats
Extract out the parts of qemuDomainGetJobStatsInternal that get
the migration stats. We're about to add the ability to get just
dump information.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-02 15:19:14 -05:00
Marc Hartmayer
b0fc6a69d0 qemu: Use switch statement for address types in qemuBuildControllerDevStr
Use a switch statement instead of if-else-if statements. Move the
command line building of the iothread attribute into the common path
as the SCSI controller attributes are already validated.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
2018-02-02 14:52:23 -05:00
John Ferlan
5775089e14 qemu: Introduce qemuDomainDeviceDefValidateControllerSATA
Move the SATA controller check from command line building to
controller def validation. This includes copying the SATA
skip check found in qemuBuildSkipController.
2018-02-02 14:52:23 -05:00
John Ferlan
7de841cc8e qemu: Complete PCI command checks to controller def validate
Move the qemuCaps checks over to qemuDomainControllerDefValidatePCI.

This requires two test updates in order to set the correct capability
bit for an xml2xml test as well as setting up the similar capability
for the pseries memlocktest.
2018-02-02 14:52:23 -05:00
John Ferlan
2461476022 qemu: Move more PCI command checks to controller def validate
Excluding the qemuCaps checks, move the remainder of the checks
that validate whether the PCI definition is valid or not into
qemuDomainControllerDefValidatePCI.
2018-02-02 14:52:06 -05:00
John Ferlan
13b2083c42 qemu: Move PCI command modelName TypeToString to controller def validate
Similar to the checking the modelName vs. NAME_NONE, let's make the
ModelNameTypeToString check more generic too within the checking done
in controller validation (with the same ignore certain models.

NB: We need to keep the ModelNameTypeToString fetch in command line
validation since we use it, but at least we can assume it returns
something valid now.
2018-02-02 14:35:26 -05:00
John Ferlan
4d7f9bf0ef qemu: Move PCI command modelName check to controller def validate
Move the various modelName == NAME_NONE from the command line
generation into domain controller validation.  Also rather than
have multiple cases with the same check, let's make the code
more generic, but also note that it was the modelName option
that caused the failure. We also have to be sure not to check
the PCI models that we don't care about.

For the remaining checks in command line building, we can use
the field name in the error message to be more specific about
what causes the failure.
2018-02-02 14:35:26 -05:00
John Ferlan
c44ba1d4d1 qemu: Use virDomainPCIControllerOpts in qemuBuildControllerDevStr
Shorten up a few characters and reference the pciopts pointer
2018-02-02 14:35:26 -05:00
Andrea Bolognani
e1f7c354f0 qemu: Add missing checks for pcie-root-port options
We format the 'chassis' and 'port' properties on the QEMU command
line later on, so we should make sure they've been set.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-02 14:35:26 -05:00
John Ferlan
d84caf9b50 qemu: Introduce qemuDomainDeviceDefValidateControllerPCI
Move PCI validation checks out of qemu_command into the proper
qemu_domain validation helper.

Since there's a lot to move, we'll start slow by replicating the
pcie-root and pci-root avoidance from qemuBuildSkipController and
the first switch found in qemuBuildControllerDevStr.
2018-02-02 14:35:26 -05:00
John Ferlan
2d32fc81da qemu: Introduce qemuDomainDeviceDefValidateControllerSCSI
Move SCSI validation from qemu_command into qemu_domain.

Rename/reorder the args in qemuCheckSCSIControllerIOThreads
to match the caller as well as fixing up the comments to
remove the previously removed qemuCaps arg.
2018-02-02 14:35:26 -05:00
John Ferlan
cd8df1e6de qemu: Add check for iothread attribute in validate controller
Let's make sure that non SCSI virtio-scsi isn't used for any type
other than a virtio-scsi controller.
2018-02-02 14:35:26 -05:00
John Ferlan
b61ae99b6d qemu: Adjust SCSI controller switch in qemuBuildControllerDevStr
Modify the SCSI controller switch during command line building
to account for all virDomainControllerModelSCSI types rather
than using the default label.
2018-02-02 14:35:26 -05:00
John Ferlan
bbe6466692 qemu: Move and rename qemuBuildCheckSCSIControllerModel
Move to qemu_domain during the validation of controller options and
rename qemuDomainCheckSCSIControllerModel.
2018-02-02 14:35:26 -05:00
John Ferlan
d92f2efbed qemu: Introduce qemuDomainDeviceDefValidateControllerAttributes
Move the checks that various attributes are not set on any controller
other than SCSI controller using virtio-scsi model into the common
controller validate checks.
2018-02-02 14:35:26 -05:00
Michal Privoznik
4d83a6722f qemuDomainRemoveMemoryDevice: unlink() memory backing file
https://bugzilla.redhat.com/show_bug.cgi?id=1461214

Since fec8f9c49a we try to use predictable file names for
'memory-backend-file' objects. But that made us provide full path
to qemu when hot plugging the object while previously we provided
merely a directory. But this makes qemu behave differently. If
qemu sees a path terminated with a directory it calls mkstemp()
and unlinks the file immediately. But if it sees full path it
just calls open(path, O_CREAT ..); and never unlinks the file.
Therefore it's up to libvirt to unlink the file and not leave it
behind.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-02-02 11:03:15 +01:00
Peter Krempa
93db7eea1b qemu: migration: Refresh device information after transferring state
In my first approach in 4b480d1076 I overlooked the comment in
qemuMigrationRunIncoming stating that during actual migration the
qemuMigrationRunIncoming does not wait until the migration is complete
but rather offloads that to the Finish phase of migration.

This means that during actual migration qemuProcessRefreshState was
called prior to qemu actually transferring the full state and thus the
queries did not get the correct information. The approach worked only
for restore, where we wait for the migration to finish during qemu
startup.

Fix the issue by calling qemuProcessRefreshState both from
qemuProcessStart if there's no incomming migration and from
qemuMigrationFinish so that the code actually works as expected.
2018-02-02 10:39:32 +01:00
Michal Privoznik
038eb472a0 qemu: Expose rx/tx_queue_size in qemu.conf too
In 2074ef6cd4 and c56cdf259 (and friends) we've added two
attributes to virtio NICs: rx_queue_size and tx_queue_size.
However, sysadmins might want to set these on per-host basis but
don't necessarily have an access to domain XML (e.g. because they
are generated by some other app). So let's expose them under
qemu.conf (the settings from domain XML still take precedence as
they are more specific ones).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-02 07:09:22 +01:00
Jie Wang
75fd48b945 blockjob: Fix a error checking of blockjob status in some case
Commit id 'bc444666f' added a check if the returned data
buffer had an error, but failed to adjust the event from
VIR_DOMAIN_BLOCK_JOB_COMPLETED to VIR_DOMAIN_BLOCK_JOB_FAILED
in order to propagate an error such as "File descriptor in bad
state" that may be returned from QEMU when both @offset and
@len are set to 0 such as is the case when performing an async
block job read on a read only filesystem.

Signed-off-by: Jie Wang <wangjie88@huawei.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-01 09:48:17 -05:00
Chen Hanxiao
2f54eab7c7 qemu: Use VIR_ERR_DEVICE_MISSING for various coldplug messages
Use the DEVICE_MISSING error code when helpers fail to find
the requested device. This makes it easier for consumers to
key off the error code rather than the error message.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-01 07:17:01 -05:00
Chen Hanxiao
126db34a81 qemu: Use VIR_ERR_DEVICE_MISSING for various hotplug messages
Modify OPERATION_FAILED and INTERNAL_ERROR error codes to
use DEVICE_MISSING instead for failures associated with the
inability to find the device. This makes it easier for consumers
to key off the error code rather than the error message.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-01 07:17:01 -05:00
Chen Hanxiao
f0f2a5ec21 qemu: Add some more details for hotplug errors when device not found
More proper/detail error messages updated.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-01 07:17:01 -05:00
John Ferlan
5b5bff35a8 qemu: Update qemuDomainFindSCSIControllerModel return
Now that the controller model is updated during post parse callback,
this code no longer needs to fetch the model based on the capabilities
and can just return the model directly if the controller is found.

Removal of @qemuCaps cascades through various callers which are now
updated to not pass the capabilities.
2018-01-31 11:32:04 -05:00
John Ferlan
de8fac5f21 qemu: Reduce need to call qemuDomainGetSCSIControllerModel
Now that post parse processing handles setting the SCSI controller
model, there's no need to call qemuDomainGetSCSIControllerModel to
get the "default controller" when building the command line controller
string or when assigning the spaprvio address since the controller
model value will already be filled in.
2018-01-31 11:32:04 -05:00
John Ferlan
62f8c94732 qemu: Introduce qemuDomainSetSCSIControllerModel
During post parse processing, let's force setting the controller
model to default value if not already set for defined controllers
(e.g. the non implicit ones).
2018-01-31 11:32:04 -05:00
John Ferlan
13d216617d qemu: Fetch/save the default SCSI controller model during hotplug
If we're going to add a controller to the domain, let's set the
default SCSI model value if we cannot find another SCSI controller
already present.

NB: Requires updating the live output test data since the model
will now be formatted.
2018-01-31 11:32:04 -05:00
John Ferlan
fadfb4f9b3 qemu: Introduce qemuDomainGetSCSIControllerModel
Rename and rework qemuDomainSetSCSIControllerModel since we're
really not setting the SCSI controller model. Instead the code
is either returning the existing SCSI controller model value, the
default value based on the capabilities, or -1 with the error set.
2018-01-31 11:32:04 -05:00
John Ferlan
6ae6ffd88e qemu: Introduce qemuDomainFindSCSIControllerModel
Rather than repeat multiple steps in order to find the SCSI
controller model, let's combine them into one helper that will
return either the model from the definition or the default
model based on the capabilities.

This patch adds an extra check/error that the controller
that's being found actually exists. This just clarifies that
the error was because the controller doesn't exist rather
than the more generic error that we were unable to determine
the model from qemuDomainSetSCSIControllerModel when a -1
was passed in and the capabilities were unable to find one.
2018-01-31 11:32:04 -05:00
John Ferlan
932862b8bf conf: Rework and rename virDomainDeviceFindControllerModel
As it turns out virDomainDeviceFindControllerModel was only ever
called for SCSI controllers using VIR_DOMAIN_CONTROLLER_TYPE_SCSI
as a parameter.

So rename to virDomainDeviceFindSCSIController and rather than
return a model, let's return a virDomainControllerDefPtr to let
the caller reference whatever it wants.
2018-01-31 11:32:04 -05:00
John Ferlan
e37540f459 qemu: Split qemuDomainSetSCSIControllerModel
Rather than one function serving two purposes, let's split out the
else condition which is checking whether the model can be used
during command line building based on the capabilities.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-01-31 11:32:04 -05:00
Martin Kletzander
6c44013b17 qemu: Restore resctrl alloc data after restart
During reconnect we need to reconstruct the paths of all cachetunes so that they
get cleaned up when the domain is stopped.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
272649a1d7 qemu: Restore machinename even without cgroups
The virresctrl will use this as well and we need to have that info after restart
to properly clean up /sys/fs/resctrl.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
ebafc603c1 util: Use "resctrl" instead of "resctrlfs" spelling
Pointed out during review on one or two places, but it actually appears in lot
more places.  So let's be consistent.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:54 +01:00
John Ferlan
6b7c5c4726 qemu: Fix memory leak in processGuestPanicEvent
After processing the processEvent->data for a qemuProcessEventHandler
callout, it's expected that the called processEvent->eventType helper
will perform the proper free on the data field. In this case it's
a qemuMonitorEventPanicInfoPtr.
2018-01-29 11:44:20 -05:00
Martin Kletzander
9a2fc2db8f qemu: Add support for resctrl
We've been building up to this.  This adds support for cputune/cachetune
settings for domains in the QEMU driver.  The addition into
qemuProcessSetupVcpu() automatically adds support for hotplug.  For hot-unplug
we need to remove the allocation only if all the vCPUs were unplugged.  But
since the threads are left running, we can't really do much about it now.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Daniel P. Berrange
7697706135 qemu: add support for generating SMBIOS OEM strings command line
This wires up the previously added OEM strings XML schema to be able to
generate comamnd line args for QEMU. This requires QEMU >= 2.12 release
containing this patch:

  commit 2d6dcbf93fb01b4a7f45a93d276d4d74b16392dd
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Sat Oct 28 21:51:36 2017 +0100

    smbios: support setting OEM strings table

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-25 14:48:56 +00:00
Laine Stump
ed2049ea19 qemu: auto-add generic xhci rather than NEC xhci to Q35 domains
We recently added a generic XHCI USB3 controller to QEMU, and libvirt
supports adding that controller rather than the NEC XHCI USB3
controller, but when auto-adding a USB controller to Q35 domains we
were still adding the vendor-specific NEC controller. This patch
changes to add the generic controller instead, if it's available in
the QEMU binary that will be used.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-22 10:13:16 -05:00
Jiri Denemark
ba9ea2ad7d qemu: Don't initialize struct utsname
It breaks the build and it is not really useful for anything.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-22 14:53:39 +01:00
Jiri Denemark
52b7d910b6 qemu: Refresh caps cache after booting a different kernel
Whenever a different kernel is booted, some capabilities related to KVM
(such as CPUID bits) may change. We need to refresh the cache to see the
changes.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-22 14:11:58 +01:00
Laine Stump
7ce8ff0f88 qemu: move qemuDomainDefValidateVideo into qemuDomainDeviceDefValidateVideo
qemuDomainDefValidateVideo() (called from qemuDomainDefValidate()) is
just a loop performing various checks on each video device. Rather
than maintaining this separate function, just fold the validations
into qemuDomainDeviceDefValidateVideo(), which is called once for each
video device.
2018-01-21 11:10:03 -05:00
Laine Stump
18c24bc686 qemu: assign correct type of PCI address for vhost-scsi when using pcie-root
Commit 10c73bf1 fixed a bug that I had introduced back in commit
70249927 - if a vhost-scsi device had no manually assigned PCI
address, one wouldn't be assigned automatically. There was a slight
problem with the logic of the fix though - in the case of domains with
pcie-root (e.g. those with a q35 machinetype),
qemuDomainDeviceCalculatePCIConnectFlags() will attempt to determine
if the host-side PCI device is Express or legacy by examining sysfs
based on the host-side PCI address stored in
hostdev->source.subsys.u.pci.addr, but that part of the union is only
valid for PCI hostdevs, *not* for SCSI hostdevs. So we end up trying
to read sysfs for some probably-non-existent device, which fails, and
the function virPCIDeviceIsPCIExpress() returns failure (-1).

By coincidence, the return value is being examined as a boolean, and
since -1 is true, we still end up assigning the vhost-scsi device to
an Express slot, but that is just by chance (and could fail in the
case that the gibberish in the "hostside PCI address" was the address
of a real device that happened to be legacy PCI).

Since (according to Paolo Bonzini) vhost-scsi devices appear just like
virtio-scsi devices in the guest, they should follow the same rules as
virtio devices when deciding whether they should be placed in an
Express or a legacy slot. That's accomplished in this patch by
returning early with virtioFlags, rather than erroneously using
hostdev->source.subsys.u.pci.addr. It also adds a test case for PCIe
to assure it doesn't get broken in the future.
2018-01-20 22:01:24 -05:00
Michal Privoznik
72adaf2f10 Revert "qemu: monitor: do not report error on shutdown"
https://bugzilla.redhat.com/show_bug.cgi?id=1536461

This reverts commit aeda1b8c56.

Problem is that we need mon->lastError to be set because it's
used all over the place. Also, there's nothing wrong with
reporting error if one occurred. I mean, if there's a thread
executing an API and which currently is talking on monitor it
definitely wants the error reported.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-19 14:31:03 +01:00
Jiri Denemark
bcc5710708 qemu: Fix crash in offline migration
When migrating a shutoff domain (i.e., offline migration), we have no
statistics to report and thus jobInfo will be NULL in
qemuMigrationFinish.

Broken by me in v3.10.0-183-ge8784e7868.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-19 10:51:19 +01:00
Daniel P. Berrange
bc251ea91b qemu: avoid denial of service reading from QEMU monitor (CVE-2018-5748)
We read from QEMU until seeing a \r\n pair to indicate a completed reply
or event. To avoid memory denial-of-service though, we must have a size
limit on amount of data we buffer. 10 MB is large enough that it ought
to cope with normal QEMU replies, and small enough that we're not
consuming unreasonable mem.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-18 09:04:27 +00:00
Marc Hartmayer
029e024770 qemu: qemuDomainNamespaceUnlinkPaths: Return 0 in case of success
Commit 7a931a4204 refactored the code and probably forgot to add
this line.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-01-17 17:08:53 +01:00
Marc Hartmayer
97202988d9 qemu: Fix segmentation fault when attaching a non iSCSI host device
Add a check if it's a iSCSI hostdev and if it's not then don't use the
union member 'iscsi'. The segmentation fault occured when accessing
secinfo->type, but this can vary from case to case.

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>
2018-01-17 09:57:53 -05:00
Jiri Denemark
e8784e7868 qemu: Fix type of a completed job
Libvirt 3.7.0 and earlier libvirt reported a migration job as completed
immediately after QEMU finished sending migration data at which point
migration was not really complete yet. Commit v3.7.0-29-g3f2d6d829e
fixed this, but caused a regression in reporting statistics for
completed jobs which started reporting the job as still running. This
happened because the completed job statistics including the job status
are copied from the running job before we finally mark it as completed.

Let's make sure QEMU_DOMAIN_JOB_STATUS_COMPLETED is always set in the
completed job info even when the job has not finished yet.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-12 10:45:31 +01:00
Jiri Denemark
237f045d9a qemu: Ignore fallback CPU attribute on reconnect
When reconnecting to a running domain with host-model CPU started by old
libvirt which did not store the actual CPU in the status XML, we need to
ignore the fallback attribute to make sure we can translate the detected
host CPU model to a model which is supported by the running QEMU.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-12 10:45:31 +01:00
Christian Ehrhardt
a5486e57f5 security: full path option for DomainSetPathLabel
virSecurityManagerDomainSetPathLabel is used to make a path known
to the security modules, but today is used interchangably for
 - paths to files/dirs to be accessed directly
 - paths to a dir, but the access will actually be to files therein

Depending on the security module it is important to know which of
these types it will be.

The argument allowSubtree augments the call to the implementations of
DomainSetPathLabel that can - per security module - decide if extra
actions shall be taken.

For now dac/selinux handle this as before, but apparmor will make
use of it to add a wildcard to the path that was passed.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-09 17:29:52 +01:00