2010-12-16 15:07:07 +00:00
|
|
|
/*
|
|
|
|
* qemu_capabilities.c: QEMU capabilities generation
|
|
|
|
*
|
2016-01-08 10:45:06 +00:00
|
|
|
* Copyright (C) 2006-2016 Red Hat, Inc.
|
2010-12-16 15:07:07 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-16 15:07:07 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "qemu_capabilities.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2014-03-05 16:51:59 +00:00
|
|
|
#include "vircrypto.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-10-02 08:59:56 +00:00
|
|
|
#include "virpidfile.h"
|
|
|
|
#include "virprocess.h"
|
2010-12-16 15:07:07 +00:00
|
|
|
#include "nodeinfo.h"
|
|
|
|
#include "cpu/cpu.h"
|
|
|
|
#include "domain_conf.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2012-12-04 11:56:32 +00:00
|
|
|
#include "virbitmap.h"
|
2011-11-29 14:42:58 +00:00
|
|
|
#include "virnodesuspend.h"
|
2014-06-06 14:50:39 +00:00
|
|
|
#include "virnuma.h"
|
2012-08-22 17:05:08 +00:00
|
|
|
#include "qemu_monitor.h"
|
2013-04-12 20:55:45 +00:00
|
|
|
#include "virstring.h"
|
2014-06-25 16:39:29 +00:00
|
|
|
#include "qemu_hostdev.h"
|
2015-03-10 13:23:43 +00:00
|
|
|
#include "qemu_domain.h"
|
2015-09-09 14:03:14 +00:00
|
|
|
#define __QEMU_CAPSRIV_H_ALLOW__
|
|
|
|
#include "qemu_capspriv.h"
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-01-29 16:52:17 +00:00
|
|
|
#include <fcntl.h>
|
2010-12-16 15:07:07 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
2011-02-08 14:22:39 +00:00
|
|
|
#include <stdarg.h>
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("qemu.qemu_capabilities");
|
|
|
|
|
2011-05-04 11:55:38 +00:00
|
|
|
/* While not public, these strings must not change. They
|
|
|
|
* are used in domain status files which are read on
|
|
|
|
* daemon restarts
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
|
2011-05-04 11:55:38 +00:00
|
|
|
"kqemu", /* 0 */
|
|
|
|
"vnc-colon",
|
|
|
|
"no-reboot",
|
|
|
|
"drive",
|
|
|
|
"drive-boot",
|
|
|
|
|
|
|
|
"name", /* 5 */
|
|
|
|
"uuid",
|
|
|
|
"domid",
|
|
|
|
"vnet-hdr",
|
|
|
|
"migrate-kvm-stdio",
|
|
|
|
|
|
|
|
"migrate-qemu-tcp", /* 10 */
|
|
|
|
"migrate-qemu-exec",
|
|
|
|
"drive-cache-v2",
|
|
|
|
"kvm",
|
|
|
|
"drive-format",
|
|
|
|
|
|
|
|
"vga", /* 15 */
|
|
|
|
"0.10",
|
|
|
|
"pci-device",
|
|
|
|
"mem-path",
|
|
|
|
"drive-serial",
|
|
|
|
|
|
|
|
"xen-domid", /* 20 */
|
|
|
|
"migrate-qemu-unix",
|
|
|
|
"chardev",
|
|
|
|
"enable-kvm",
|
|
|
|
"monitor-json",
|
|
|
|
|
|
|
|
"balloon", /* 25 */
|
|
|
|
"device",
|
|
|
|
"sdl",
|
|
|
|
"smp-topology",
|
|
|
|
"netdev",
|
|
|
|
|
|
|
|
"rtc", /* 30 */
|
2011-05-23 17:38:32 +00:00
|
|
|
"vhost-net",
|
2011-05-04 11:55:38 +00:00
|
|
|
"rtc-td-hack",
|
|
|
|
"no-hpet",
|
|
|
|
"no-kvm-pit",
|
|
|
|
|
|
|
|
"tdf", /* 35 */
|
|
|
|
"pci-configfd",
|
|
|
|
"nodefconfig",
|
|
|
|
"boot-menu",
|
|
|
|
"enable-kqemu",
|
|
|
|
|
|
|
|
"fsdev", /* 40 */
|
|
|
|
"nesting",
|
|
|
|
"name-process",
|
|
|
|
"drive-readonly",
|
|
|
|
"smbios-type",
|
|
|
|
|
|
|
|
"vga-qxl", /* 45 */
|
|
|
|
"spice",
|
|
|
|
"vga-none",
|
|
|
|
"migrate-qemu-fd",
|
|
|
|
"boot-index",
|
|
|
|
|
|
|
|
"hda-duplex", /* 50 */
|
|
|
|
"drive-aio",
|
|
|
|
"pci-multibus",
|
|
|
|
"pci-bootindex",
|
|
|
|
"ccid-emulated",
|
|
|
|
|
|
|
|
"ccid-passthru", /* 55 */
|
|
|
|
"chardev-spicevmc",
|
|
|
|
"device-spicevmc",
|
|
|
|
"virtio-tx-alg",
|
|
|
|
"device-qxl-vga",
|
2011-05-09 06:59:16 +00:00
|
|
|
|
|
|
|
"pci-multifunction", /* 60 */
|
2011-06-20 08:26:47 +00:00
|
|
|
"virtio-blk-pci.ioeventfd",
|
2011-07-08 07:56:17 +00:00
|
|
|
"sga",
|
2011-08-13 06:32:45 +00:00
|
|
|
"virtio-blk-pci.event_idx",
|
|
|
|
"virtio-net-pci.event_idx",
|
2011-09-02 12:56:50 +00:00
|
|
|
|
|
|
|
"cache-directsync", /* 65 */
|
|
|
|
"piix3-usb-uhci",
|
|
|
|
"piix4-usb-uhci",
|
|
|
|
"usb-ehci",
|
|
|
|
"ich9-usb-ehci1",
|
|
|
|
|
|
|
|
"vt82c686b-usb-uhci", /* 70 */
|
|
|
|
"pci-ohci",
|
|
|
|
"usb-redir",
|
2011-09-02 14:20:40 +00:00
|
|
|
"usb-hub",
|
2011-09-21 08:25:29 +00:00
|
|
|
"no-shutdown",
|
2011-09-22 19:33:47 +00:00
|
|
|
|
|
|
|
"cache-unsafe", /* 75 */
|
2011-09-20 17:31:52 +00:00
|
|
|
"rombar",
|
2011-09-28 03:46:08 +00:00
|
|
|
"ich9-ahci",
|
2011-12-20 01:08:29 +00:00
|
|
|
"no-acpi",
|
2011-12-21 15:51:29 +00:00
|
|
|
"fsdev-readonly",
|
2011-11-29 18:37:27 +00:00
|
|
|
|
2011-12-21 12:47:17 +00:00
|
|
|
"virtio-blk-pci.scsi", /* 80 */
|
2011-11-29 18:37:27 +00:00
|
|
|
"blk-sg-io",
|
2012-01-12 09:31:14 +00:00
|
|
|
"drive-copy-on-read",
|
2011-12-21 12:47:17 +00:00
|
|
|
"cpu-host",
|
2012-01-17 12:44:18 +00:00
|
|
|
"fsdev-writeout",
|
2012-01-18 16:42:33 +00:00
|
|
|
|
|
|
|
"drive-iotune", /* 85 */
|
2012-02-13 11:19:24 +00:00
|
|
|
"system_wakeup",
|
2012-02-27 10:20:21 +00:00
|
|
|
"scsi-disk.channel",
|
2012-03-12 14:19:56 +00:00
|
|
|
"scsi-block",
|
2012-03-14 22:29:21 +00:00
|
|
|
"transaction",
|
2012-04-11 21:40:16 +00:00
|
|
|
|
|
|
|
"block-job-sync", /* 90 */
|
|
|
|
"block-job-async",
|
2012-04-17 09:08:05 +00:00
|
|
|
"scsi-cd",
|
2012-04-17 09:16:52 +00:00
|
|
|
"ide-cd",
|
2012-04-26 10:11:49 +00:00
|
|
|
"no-user-config",
|
2012-05-15 22:55:08 +00:00
|
|
|
|
|
|
|
"hda-micro", /* 95 */
|
2012-06-12 03:06:33 +00:00
|
|
|
"dump-guest-memory",
|
2012-06-21 13:45:25 +00:00
|
|
|
"nec-usb-xhci",
|
2012-06-29 15:02:05 +00:00
|
|
|
"virtio-s390",
|
2012-07-12 15:45:57 +00:00
|
|
|
"balloon-event",
|
2012-05-15 22:55:08 +00:00
|
|
|
|
2012-08-03 20:33:05 +00:00
|
|
|
"bridge", /* 100 */
|
2012-08-08 06:25:24 +00:00
|
|
|
"lsi",
|
|
|
|
"virtio-scsi-pci",
|
2012-09-04 14:30:55 +00:00
|
|
|
"blockio",
|
2012-08-02 10:14:39 +00:00
|
|
|
"disable-s3",
|
2012-08-03 20:33:05 +00:00
|
|
|
|
2012-08-02 10:14:39 +00:00
|
|
|
"disable-s4", /* 105 */
|
2012-08-19 15:42:44 +00:00
|
|
|
"usb-redir.filter",
|
2012-09-18 02:12:11 +00:00
|
|
|
"ide-drive.wwn",
|
|
|
|
"scsi-disk.wwn",
|
2012-09-18 07:24:51 +00:00
|
|
|
"seccomp-sandbox",
|
2012-09-18 10:31:30 +00:00
|
|
|
|
|
|
|
"reboot-timeout", /* 110 */
|
2012-08-15 07:59:24 +00:00
|
|
|
"dump-guest-core",
|
2012-09-20 09:15:31 +00:00
|
|
|
"seamless-migration",
|
2012-10-03 21:13:21 +00:00
|
|
|
"block-commit",
|
2012-10-19 19:40:52 +00:00
|
|
|
"vnc",
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
|
|
|
|
"drive-mirror", /* 115 */
|
2012-11-14 14:51:30 +00:00
|
|
|
"usb-redir.bootindex",
|
|
|
|
"usb-host.bootindex",
|
2012-12-03 21:25:30 +00:00
|
|
|
"blockdev-snapshot-sync",
|
2012-12-14 07:06:31 +00:00
|
|
|
"qxl",
|
|
|
|
|
|
|
|
"VGA", /* 120 */
|
|
|
|
"cirrus-vga",
|
|
|
|
"vmware-svga",
|
|
|
|
"device-video-primary",
|
2013-01-07 17:17:15 +00:00
|
|
|
"s390-sclp",
|
2013-01-11 16:43:49 +00:00
|
|
|
|
|
|
|
"usb-serial", /* 125 */
|
2013-01-03 07:13:05 +00:00
|
|
|
"usb-net",
|
2013-01-29 16:52:17 +00:00
|
|
|
"add-fd",
|
2012-11-21 13:28:44 +00:00
|
|
|
"nbd-server",
|
2013-01-11 16:48:21 +00:00
|
|
|
"virtio-rng",
|
|
|
|
|
|
|
|
"rng-random", /* 130 */
|
2013-02-13 10:22:23 +00:00
|
|
|
"rng-egd",
|
2013-03-14 04:49:43 +00:00
|
|
|
"virtio-ccw",
|
|
|
|
"dtb",
|
2013-03-21 14:11:39 +00:00
|
|
|
"megasas",
|
2013-03-22 13:52:25 +00:00
|
|
|
|
|
|
|
"ipv6-migration", /* 135 */
|
2013-03-29 05:22:46 +00:00
|
|
|
"machine-opt",
|
2013-04-07 08:31:57 +00:00
|
|
|
"machine-usb-opt",
|
2013-04-12 20:55:45 +00:00
|
|
|
"tpm-passthrough",
|
|
|
|
"tpm-tis",
|
2013-04-25 08:46:04 +00:00
|
|
|
|
|
|
|
"nvram", /* 140 */
|
2013-05-03 18:07:21 +00:00
|
|
|
"pci-bridge",
|
|
|
|
"vfio-pci",
|
|
|
|
"vfio-pci.bootindex",
|
|
|
|
"scsi-generic",
|
|
|
|
|
|
|
|
"scsi-generic.bootindex", /* 145 */
|
2013-05-14 05:25:49 +00:00
|
|
|
"mem-merge",
|
2013-04-30 14:26:43 +00:00
|
|
|
"vnc-websocket",
|
2013-05-14 12:44:54 +00:00
|
|
|
"drive-discard",
|
2013-05-16 20:01:05 +00:00
|
|
|
"mlock",
|
2013-05-21 14:31:47 +00:00
|
|
|
|
|
|
|
"vnc-share-policy", /* 150 */
|
2013-07-11 15:07:26 +00:00
|
|
|
"device-del-event",
|
qemu: add dmi-to-pci-bridge controller
This PCI controller, named "dmi-to-pci-bridge" in the libvirt config,
and implemented with qemu's "i82801b11-bridge" device, connects to a
PCI Express slot (e.g. one of the slots provided by the pcie-root
controller, aka "pcie.0" on the qemu commandline), and provides 31
*non-hot-pluggable* PCI (*not* PCIe) slots, numbered 1-31.
Any time a machine is defined which has a pcie-root controller
(i.e. any q35-based machinetype), libvirt will automatically add a
dmi-to-pci-bridge controller if one doesn't exist, and also add a
pci-bridge controller. The reasoning here is that any useful domain
will have either an immediate (startup time) or eventual (subsequent
hot-plug) need for a standard PCI slot; since the pcie-root controller
only provides PCIe slots, we need to connect a dmi-to-pci-bridge
controller to it in order to get a non-hot-plug PCI slot that we can
then use to connect a pci-bridge - the slots provided by the
pci-bridge will be both standard PCI and hot-pluggable.
Since pci-bridge devices themselves can not be hot-plugged into a
running system (although you can hot-plug other devices into a
pci-bridge's slots), any new pci-bridge controller that is added can
(and will) be plugged into the dmi-to-pci-bridge as long as it has
empty slots available.
This patch is also changing the qemuxml2xml-pcie test from a "DO_TEST"
to a "DO_DIFFERENT_TEST". This is so that the "before" xml can omit
the automatically added dmi-to-pci-bridge and pci-bridge devices, and
the "after" xml can include it - this way we are testing if libvirt is
properly adding these devices.
2013-07-31 01:37:32 +00:00
|
|
|
"dmi-to-pci-bridge",
|
2013-08-12 11:48:34 +00:00
|
|
|
"i440fx-pci-hole64-size",
|
|
|
|
"q35-pci-hole64-size",
|
2013-08-23 10:38:10 +00:00
|
|
|
|
|
|
|
"usb-storage", /* 155 */
|
2013-08-23 10:38:11 +00:00
|
|
|
"usb-storage.removable",
|
2013-08-01 01:40:35 +00:00
|
|
|
"virtio-mmio",
|
2013-09-24 14:17:38 +00:00
|
|
|
"ich9-intel-hda",
|
2013-07-01 16:28:50 +00:00
|
|
|
"kvm-pit-lost-tick-policy",
|
qemu: add "-boot strict" to commandline whenever possible
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=888635
(which was already closed as CANTFIX because the qemu "-boot strict"
commandline option wasn't available at the time).
Problem: you couldn't have a domain that used PXE to boot, but also
had an un-bootable disk device *even if that disk wasn't listed in the
boot order*, because if PXE timed out (e.g. due to the bridge
forwarding delay), the BIOS would move on to the next target, which
would be the unbootable disk device (again - even though it wasn't
given a boot order), and get stuck at a "BOOT DISK FAILURE, PRESS ANY
KEY" message until a user intervened.
The solution available since sometime around QEMU 1.5, is to add
"-boot strict=on" to *every* qemu command. When this is done, if any
devices have a boot order specified, then QEMU will *only* attempt to
boot from those devices that have an explicit boot order, ignoring the
rest.
2013-12-02 12:07:12 +00:00
|
|
|
|
|
|
|
"boot-strict", /* 160 */
|
qemu: ask for -enable-fips when FIPS is required
On a system that is enforcing FIPS, most libraries honor the
current mode by default. Qemu, on the other hand, refused to
honor FIPS mode unless you add the '-enable-fips' command
line option; worse, this option is not discoverable via QMP,
and is only present on binaries built for Linux. So, if we
detect FIPS mode, then we unconditionally ask for FIPS; either
qemu is new enough to have the option and then correctly
cripple insecure VNC passwords, or it is so old that we are
correctly avoiding a FIPS violation by preventing qemu from
starting. Meanwhile, if we don't detect FIPS mode, then
omitting the argument is safe whether the qemu has the option
(but it would do nothing because FIPS is disabled) or whether
qemu lacks the option (including in the case where we are not
running on Linux).
The testsuite was a bit interesting: we don't want our test
to depend on whether it is being run in FIPS mode, so I had
to tweak things to set the capability bit outside of our
normal interaction with capability parsing.
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1035474
* src/qemu/qemu_capabilities.h (QEMU_CAPS_ENABLE_FIPS): New bit.
* src/qemu/qemu_capabilities.c (virQEMUCapsInitQMP): Conditionally
set capability according to detection of FIPS mode.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Use it.
* tests/qemucapabilitiestest.c (testQemuCaps): Conditionally set
capability to test expected output.
* tests/qemucapabilitiesdata/caps_1.2.2-1.caps: Update list.
* tests/qemucapabilitiesdata/caps_1.6.0-1.caps: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-05 21:47:09 +00:00
|
|
|
"pvpanic",
|
|
|
|
"enable-fips",
|
2014-01-30 11:19:12 +00:00
|
|
|
"spice-file-xfer-disable",
|
|
|
|
"spiceport",
|
2014-02-17 10:17:55 +00:00
|
|
|
|
|
|
|
"usb-kbd", /* 165 */
|
qemu: add host-pci-multidomain capability
Quite a long time ago, (apparently between qemu 0.12 and 0.13) qemu
quietly began supporting the optional specification of a domain in the
host-side address of all pci passthrough commands (by simply
prepending it to the bus:slot.function format, as
"dddd:bb:ss.f"). Since machines with multiple PCI domains are very
rare, this never came up in practice, so libvirt was never updated to
support it.
This patch takes the first step to supporting specification of a non-0
domain in the host-side address of PCI devices being assigned to a
domain, by adding a capability bit to indicate support
"QEMU_CAPS_HOST_PCI_MULTIDOMAIN", and detect it. Since this support
was added in a version prior to the minimum version required for
QMP-style capabilities detection, the capability is always enabled for
any qemu that uses QMP for capabilities detection. For older qemus,
the only clue that a domain can be specified in the host pci address
is the presence of the string "[seg:]" in the help string for
-pcidevice. (Ironically, libvirt will not be modified to support
specification of domain for -pcidevice, since any qemu new enough for
us to care about also supports "-device pci-assign" or "-device
vfio-pci", which are greatly preferred).
2014-04-29 15:11:45 +00:00
|
|
|
"host-pci-multidomain",
|
2014-04-09 13:23:45 +00:00
|
|
|
"msg-timestamp",
|
2014-06-17 03:42:49 +00:00
|
|
|
"active-commit",
|
2014-05-26 12:09:22 +00:00
|
|
|
"change-backing-file",
|
2014-05-07 15:20:15 +00:00
|
|
|
|
|
|
|
"memory-backend-ram", /* 170 */
|
2014-06-17 11:43:19 +00:00
|
|
|
"numa",
|
2014-07-23 15:37:21 +00:00
|
|
|
"memory-backend-file",
|
2014-07-24 15:32:31 +00:00
|
|
|
"usb-audio",
|
2014-08-13 12:28:24 +00:00
|
|
|
"rtc-reset-reinjection",
|
2014-08-22 11:42:46 +00:00
|
|
|
|
|
|
|
"splash-timeout", /* 175 */
|
2014-08-22 22:15:30 +00:00
|
|
|
"iothread",
|
2014-09-11 12:11:54 +00:00
|
|
|
"migrate-rdma",
|
2014-08-22 10:47:02 +00:00
|
|
|
"ivshmem",
|
2014-10-29 12:16:01 +00:00
|
|
|
"drive-iotune-max",
|
2014-11-12 12:58:33 +00:00
|
|
|
|
|
|
|
"VGA.vgamem_mb", /* 180 */
|
|
|
|
"vmware-svga.vgamem_mb",
|
|
|
|
"qxl.vgamem_mb",
|
|
|
|
"qxl-vga.vgamem_mb",
|
2014-10-06 12:16:47 +00:00
|
|
|
"pc-dimm",
|
2015-04-02 16:43:47 +00:00
|
|
|
|
|
|
|
"machine-vmport-opt", /* 185 */
|
2015-04-27 21:57:29 +00:00
|
|
|
"aes-key-wrap",
|
|
|
|
"dea-key-wrap",
|
2015-05-06 15:50:03 +00:00
|
|
|
"pci-serial",
|
2015-05-21 22:18:20 +00:00
|
|
|
"aarch64-off",
|
2015-06-04 09:37:37 +00:00
|
|
|
|
2015-06-15 08:38:21 +00:00
|
|
|
"vhost-user-multiqueue", /* 190 */
|
2015-05-28 11:35:52 +00:00
|
|
|
"migration-event",
|
2015-07-17 11:27:44 +00:00
|
|
|
"gpex-pcihost",
|
2015-06-17 17:13:28 +00:00
|
|
|
"ioh3420",
|
2015-06-16 18:54:21 +00:00
|
|
|
"x3130-upstream",
|
2015-09-04 14:23:46 +00:00
|
|
|
|
|
|
|
"xio3130-downstream", /* 195 */
|
|
|
|
"rtl8139",
|
2015-09-04 14:40:37 +00:00
|
|
|
"e1000",
|
2015-09-01 12:38:19 +00:00
|
|
|
"virtio-net",
|
2015-09-30 11:04:09 +00:00
|
|
|
"gic-version",
|
2015-11-11 17:02:23 +00:00
|
|
|
|
|
|
|
"incoming-defer", /* 200 */
|
2015-11-25 08:42:32 +00:00
|
|
|
"virtio-gpu",
|
2015-11-25 08:42:33 +00:00
|
|
|
"virtio-gpu.virgl",
|
2015-11-13 10:26:37 +00:00
|
|
|
"virtio-keyboard",
|
|
|
|
"virtio-mouse",
|
|
|
|
|
|
|
|
"virtio-tablet", /* 205 */
|
2015-11-13 14:41:20 +00:00
|
|
|
"virtio-input-host",
|
2015-12-24 14:27:55 +00:00
|
|
|
"chardev-file-append",
|
2016-01-09 20:58:50 +00:00
|
|
|
"ich9-disable-s3",
|
|
|
|
"ich9-disable-s4",
|
2016-01-05 13:05:15 +00:00
|
|
|
|
|
|
|
"vserport-change-event", /* 210 */
|
2016-01-08 10:45:06 +00:00
|
|
|
"virtio-balloon-pci.deflate-on-oom",
|
2016-02-11 10:48:20 +00:00
|
|
|
"mptsas1068",
|
2016-02-19 14:30:15 +00:00
|
|
|
"spice-gl",
|
2016-03-01 12:46:37 +00:00
|
|
|
"qxl.vram64_size_mb",
|
|
|
|
|
|
|
|
"qxl-vga.vram64_size_mb", /* 215 */
|
2016-02-23 11:56:34 +00:00
|
|
|
"chardev-logfile",
|
2016-03-10 19:46:38 +00:00
|
|
|
"debug-threads",
|
2016-03-21 15:49:12 +00:00
|
|
|
"secret",
|
2016-02-24 21:40:49 +00:00
|
|
|
"pxb",
|
2016-03-08 21:25:22 +00:00
|
|
|
|
|
|
|
"pxb-pcie", /* 220 */
|
2016-04-29 11:49:13 +00:00
|
|
|
"device-tray-moved-event",
|
2016-04-24 14:52:38 +00:00
|
|
|
"nec-usb-xhci-ports",
|
2016-04-20 18:43:04 +00:00
|
|
|
"virtio-scsi-pci.iothread",
|
2016-04-22 22:39:09 +00:00
|
|
|
"name-guest",
|
2011-05-04 11:55:38 +00:00
|
|
|
);
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the XML parser/formatter when adding more
|
|
|
|
* information to this struct so that it gets cached
|
|
|
|
* correctly. It does not have to be ABI-stable, as
|
|
|
|
* the cache will be discarded & repopulated if the
|
|
|
|
* timestamp on the libvirtd binary changes.
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
struct _virQEMUCaps {
|
2012-08-20 16:44:14 +00:00
|
|
|
virObject object;
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
bool usedQMP;
|
|
|
|
|
2012-09-10 10:47:56 +00:00
|
|
|
char *binary;
|
2014-03-10 15:50:19 +00:00
|
|
|
time_t ctime;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2012-08-20 16:44:14 +00:00
|
|
|
virBitmapPtr flags;
|
2012-08-22 10:11:28 +00:00
|
|
|
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int kvmVersion;
|
2015-02-02 10:28:30 +00:00
|
|
|
char *package;
|
2012-08-22 10:11:28 +00:00
|
|
|
|
2012-12-11 13:06:45 +00:00
|
|
|
virArch arch;
|
2012-08-22 10:11:28 +00:00
|
|
|
|
|
|
|
size_t ncpuDefinitions;
|
|
|
|
char **cpuDefinitions;
|
|
|
|
|
|
|
|
size_t nmachineTypes;
|
|
|
|
char **machineTypes;
|
|
|
|
char **machineAliases;
|
2013-06-26 15:46:35 +00:00
|
|
|
unsigned int *machineMaxCpus;
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
size_t ngicCapabilities;
|
|
|
|
virGICCapability *gicCapabilities;
|
2012-08-20 16:44:14 +00:00
|
|
|
};
|
|
|
|
|
2014-06-30 14:12:07 +00:00
|
|
|
struct virQEMUCapsSearchData {
|
|
|
|
virArch arch;
|
|
|
|
};
|
|
|
|
|
2012-08-20 16:44:14 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static virClassPtr virQEMUCapsClass;
|
|
|
|
static void virQEMUCapsDispose(void *obj);
|
2012-08-20 16:44:14 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static int virQEMUCapsOnceInit(void)
|
2012-08-20 16:44:14 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(virQEMUCapsClass = virClassNew(virClassForObject(),
|
|
|
|
"virQEMUCaps",
|
|
|
|
sizeof(virQEMUCaps),
|
|
|
|
virQEMUCapsDispose)))
|
2012-08-20 16:44:14 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virQEMUCaps)
|
2012-08-20 16:44:14 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static virArch virQEMUCapsArchFromString(const char *arch)
|
2012-12-11 13:06:45 +00:00
|
|
|
{
|
|
|
|
if (STREQ(arch, "i386"))
|
|
|
|
return VIR_ARCH_I686;
|
|
|
|
if (STREQ(arch, "arm"))
|
|
|
|
return VIR_ARCH_ARMV7L;
|
2015-06-11 14:26:45 +00:00
|
|
|
if (STREQ(arch, "or32"))
|
|
|
|
return VIR_ARCH_OR32;
|
2012-12-11 13:06:45 +00:00
|
|
|
|
|
|
|
return virArchFromString(arch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static const char *virQEMUCapsArchToString(virArch arch)
|
2012-12-11 13:06:45 +00:00
|
|
|
{
|
|
|
|
if (arch == VIR_ARCH_I686)
|
|
|
|
return "i386";
|
|
|
|
else if (arch == VIR_ARCH_ARMV7L)
|
|
|
|
return "arm";
|
2015-06-11 14:26:45 +00:00
|
|
|
else if (arch == VIR_ARCH_OR32)
|
|
|
|
return "or32";
|
2012-12-11 13:06:45 +00:00
|
|
|
|
|
|
|
return virArchToString(arch);
|
|
|
|
}
|
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
/* Given a host and guest architectures, find a suitable QEMU target.
|
|
|
|
*
|
|
|
|
* This is meant to be used as a second attempt if qemu-system-$guestarch
|
|
|
|
* can't be found, eg. on a x86_64 host you want to use qemu-system-i386,
|
|
|
|
* if available, instead of qemu-system-x86_64 to run i686 guests */
|
|
|
|
static virArch
|
|
|
|
virQEMUCapsFindTarget(virArch hostarch,
|
|
|
|
virArch guestarch)
|
|
|
|
{
|
|
|
|
/* Both ppc64 and ppc64le guests can use the ppc64 target */
|
|
|
|
if (ARCH_IS_PPC64(guestarch))
|
|
|
|
guestarch = VIR_ARCH_PPC64;
|
|
|
|
|
|
|
|
/* armv7l guests on aarch64 hosts can use the aarch64 target
|
|
|
|
* i686 guests on x86_64 hosts can use the x86_64 target */
|
|
|
|
if ((guestarch == VIR_ARCH_ARMV7L && hostarch == VIR_ARCH_AARCH64) ||
|
|
|
|
(guestarch == VIR_ARCH_I686 && hostarch == VIR_ARCH_X86_64)) {
|
|
|
|
return hostarch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return guestarch;
|
|
|
|
}
|
2012-12-11 13:06:45 +00:00
|
|
|
|
2012-08-20 15:05:45 +00:00
|
|
|
static virCommandPtr
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeCommand(const char *qemu,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
2013-01-30 20:07:03 +00:00
|
|
|
uid_t runUid, gid_t runGid)
|
2012-08-20 15:05:45 +00:00
|
|
|
{
|
|
|
|
virCommandPtr cmd = virCommandNew(qemu);
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (qemuCaps) {
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_USER_CONFIG))
|
2012-08-20 15:05:45 +00:00
|
|
|
virCommandAddArg(cmd, "-no-user-config");
|
2013-02-01 13:48:58 +00:00
|
|
|
else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NODEFCONFIG))
|
2012-08-20 15:05:45 +00:00
|
|
|
virCommandAddArg(cmd, "-nodefconfig");
|
|
|
|
}
|
|
|
|
|
|
|
|
virCommandAddEnvPassCommon(cmd);
|
|
|
|
virCommandClearCaps(cmd);
|
2013-01-30 20:07:03 +00:00
|
|
|
virCommandSetGID(cmd, runGid);
|
|
|
|
virCommandSetUID(cmd, runUid);
|
2012-08-20 15:05:45 +00:00
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-30 18:22:42 +00:00
|
|
|
static void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetDefaultMachine(virQEMUCapsPtr qemuCaps,
|
|
|
|
size_t defIdx)
|
2012-11-30 18:22:42 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
char *name = qemuCaps->machineTypes[defIdx];
|
|
|
|
char *alias = qemuCaps->machineAliases[defIdx];
|
2013-06-26 15:46:35 +00:00
|
|
|
unsigned int maxCpus = qemuCaps->machineMaxCpus[defIdx];
|
2013-02-01 13:48:58 +00:00
|
|
|
|
|
|
|
memmove(qemuCaps->machineTypes + 1,
|
|
|
|
qemuCaps->machineTypes,
|
|
|
|
sizeof(qemuCaps->machineTypes[0]) * defIdx);
|
|
|
|
memmove(qemuCaps->machineAliases + 1,
|
|
|
|
qemuCaps->machineAliases,
|
|
|
|
sizeof(qemuCaps->machineAliases[0]) * defIdx);
|
2013-06-26 15:46:35 +00:00
|
|
|
memmove(qemuCaps->machineMaxCpus + 1,
|
|
|
|
qemuCaps->machineMaxCpus,
|
|
|
|
sizeof(qemuCaps->machineMaxCpus[0]) * defIdx);
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->machineTypes[0] = name;
|
|
|
|
qemuCaps->machineAliases[0] = alias;
|
2013-06-26 15:46:35 +00:00
|
|
|
qemuCaps->machineMaxCpus[0] = maxCpus;
|
2012-11-30 18:22:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 15:07:07 +00:00
|
|
|
/* Format is:
|
|
|
|
* <machine> <desc> [(default)|(alias of <canonical>)]
|
|
|
|
*/
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseMachineTypesStr(const char *output,
|
|
|
|
virQEMUCapsPtr qemuCaps)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
const char *p = output;
|
|
|
|
const char *next;
|
2012-08-22 16:23:00 +00:00
|
|
|
size_t defIdx = 0;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
const char *t;
|
2012-08-22 16:23:00 +00:00
|
|
|
char *name;
|
|
|
|
char *canonical = NULL;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if ((next = strchr(p, '\n')))
|
|
|
|
++next;
|
|
|
|
|
|
|
|
if (STRPREFIX(p, "Supported machines are:"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(t = strchr(p, ' ')) || (next && t >= next))
|
|
|
|
continue;
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(name, p, t - p) < 0)
|
|
|
|
return -1;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
p = t;
|
2012-10-17 14:48:42 +00:00
|
|
|
if ((t = strstr(p, "(default)")) && (!next || t < next))
|
2013-02-01 13:48:58 +00:00
|
|
|
defIdx = qemuCaps->nmachineTypes;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if ((t = strstr(p, "(alias of ")) && (!next || t < next)) {
|
|
|
|
p = t + strlen("(alias of ");
|
2014-08-28 10:20:58 +00:00
|
|
|
if (!(t = strchr(p, ')')) || (next && t >= next)) {
|
|
|
|
VIR_FREE(name);
|
2010-12-16 15:07:07 +00:00
|
|
|
continue;
|
2014-08-28 10:20:58 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(canonical, p, t - p) < 0) {
|
2012-08-22 16:23:00 +00:00
|
|
|
VIR_FREE(name);
|
2013-05-20 09:23:13 +00:00
|
|
|
return -1;
|
2012-08-22 16:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (VIR_REALLOC_N(qemuCaps->machineTypes, qemuCaps->nmachineTypes + 1) < 0 ||
|
2013-06-26 15:46:35 +00:00
|
|
|
VIR_REALLOC_N(qemuCaps->machineAliases, qemuCaps->nmachineTypes + 1) < 0 ||
|
|
|
|
VIR_REALLOC_N(qemuCaps->machineMaxCpus, qemuCaps->nmachineTypes + 1) < 0) {
|
2012-08-22 16:23:00 +00:00
|
|
|
VIR_FREE(name);
|
|
|
|
VIR_FREE(canonical);
|
2013-05-20 09:23:13 +00:00
|
|
|
return -1;
|
2012-08-22 16:23:00 +00:00
|
|
|
}
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->nmachineTypes++;
|
2012-08-22 16:23:00 +00:00
|
|
|
if (canonical) {
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->machineTypes[qemuCaps->nmachineTypes-1] = canonical;
|
|
|
|
qemuCaps->machineAliases[qemuCaps->nmachineTypes-1] = name;
|
2012-08-22 16:23:00 +00:00
|
|
|
} else {
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->machineTypes[qemuCaps->nmachineTypes-1] = name;
|
|
|
|
qemuCaps->machineAliases[qemuCaps->nmachineTypes-1] = NULL;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
2013-06-26 15:46:35 +00:00
|
|
|
/* When parsing from command line we don't have information about maxCpus */
|
|
|
|
qemuCaps->machineMaxCpus[qemuCaps->nmachineTypes-1] = 0;
|
2010-12-16 15:07:07 +00:00
|
|
|
} while ((p = next));
|
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
|
2012-11-30 18:22:42 +00:00
|
|
|
if (defIdx)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
static int
|
2013-01-30 20:07:03 +00:00
|
|
|
virQEMUCapsProbeMachineTypes(virQEMUCapsPtr qemuCaps,
|
|
|
|
uid_t runUid, gid_t runGid)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
char *output;
|
2011-01-12 23:26:34 +00:00
|
|
|
int ret = -1;
|
|
|
|
virCommandPtr cmd;
|
2011-02-14 20:00:22 +00:00
|
|
|
int status;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-02-02 12:35:31 +00:00
|
|
|
/* Make sure the binary we are about to try exec'ing exists.
|
|
|
|
* Technically we could catch the exec() failure, but that's
|
|
|
|
* in a sub-process so it's hard to feed back a useful error.
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!virFileIsExecutable(qemuCaps->binary)) {
|
2012-08-22 16:23:00 +00:00
|
|
|
virReportSystemError(errno, _("Cannot find QEMU binary %s"),
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->binary);
|
2011-02-02 12:35:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-30 20:07:03 +00:00
|
|
|
cmd = virQEMUCapsProbeCommand(qemuCaps->binary, qemuCaps, runUid, runGid);
|
2012-04-26 13:10:22 +00:00
|
|
|
virCommandAddArgList(cmd, "-M", "?", NULL);
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-02-14 20:00:22 +00:00
|
|
|
/* Ignore failure from older qemu that did not understand '-M ?'. */
|
|
|
|
if (virCommandRun(cmd, &status) < 0)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsParseMachineTypesStr(output, qemuCaps) < 0)
|
2011-01-12 23:26:34 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-01-12 23:26:34 +00:00
|
|
|
VIR_FREE(output);
|
|
|
|
virCommandFree(cmd);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef int
|
2013-02-01 13:48:58 +00:00
|
|
|
(*virQEMUCapsParseCPUModels)(const char *output,
|
|
|
|
virQEMUCapsPtr qemuCaps);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
/* Format:
|
|
|
|
* <arch> <model>
|
|
|
|
* qemu-0.13 encloses some model names in []:
|
|
|
|
* <arch> [<model>]
|
|
|
|
*/
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseX86Models(const char *output,
|
|
|
|
virQEMUCapsPtr qemuCaps)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
const char *p = output;
|
|
|
|
const char *next;
|
2012-08-22 16:23:00 +00:00
|
|
|
int ret = -1;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
const char *t;
|
2012-08-22 16:23:00 +00:00
|
|
|
size_t len;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if ((next = strchr(p, '\n')))
|
|
|
|
next++;
|
|
|
|
|
|
|
|
if (!(t = strchr(p, ' ')) || (next && t >= next))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!STRPREFIX(p, "x86"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = t;
|
|
|
|
while (*p == ' ')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if (*p == '\0' || *p == '\n')
|
|
|
|
continue;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0)
|
2012-08-22 16:23:00 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
if (next)
|
|
|
|
len = next - p - 1;
|
|
|
|
else
|
|
|
|
len = strlen(p);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
if (len > 2 && *p == '[' && p[len - 1] == ']') {
|
|
|
|
p++;
|
|
|
|
len -= 2;
|
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0)
|
2012-08-22 16:23:00 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
} while ((p = next));
|
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
ret = 0;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-08-22 16:23:00 +00:00
|
|
|
return ret;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 13:01:33 +00:00
|
|
|
/* ppc64 parser.
|
|
|
|
* Format : PowerPC <machine> <description>
|
|
|
|
*/
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParsePPCModels(const char *output,
|
|
|
|
virQEMUCapsPtr qemuCaps)
|
2011-10-03 13:01:33 +00:00
|
|
|
{
|
|
|
|
const char *p = output;
|
|
|
|
const char *next;
|
2012-08-22 16:23:00 +00:00
|
|
|
int ret = -1;
|
2011-10-03 13:01:33 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
const char *t;
|
2012-08-22 16:23:00 +00:00
|
|
|
size_t len;
|
2011-10-03 13:01:33 +00:00
|
|
|
|
|
|
|
if ((next = strchr(p, '\n')))
|
|
|
|
next++;
|
|
|
|
|
|
|
|
if (!STRPREFIX(p, "PowerPC "))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Skip the preceding sub-string "PowerPC " */
|
|
|
|
p += 8;
|
|
|
|
|
|
|
|
/*Malformed string, does not obey the format 'PowerPC <model> <desc>'*/
|
|
|
|
if (!(t = strchr(p, ' ')) || (next && t >= next))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*p == '\n')
|
|
|
|
continue;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0)
|
2012-08-22 16:23:00 +00:00
|
|
|
goto cleanup;
|
2011-10-03 13:01:33 +00:00
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
len = t - p - 1;
|
2011-10-03 13:01:33 +00:00
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0)
|
2012-08-22 16:23:00 +00:00
|
|
|
goto cleanup;
|
2011-10-03 13:01:33 +00:00
|
|
|
} while ((p = next));
|
|
|
|
|
2011-12-09 17:18:58 +00:00
|
|
|
ret = 0;
|
2011-10-03 13:01:33 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-12-09 17:18:58 +00:00
|
|
|
return ret;
|
2011-10-03 13:01:33 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:23:00 +00:00
|
|
|
static int
|
2013-01-30 20:07:03 +00:00
|
|
|
virQEMUCapsProbeCPUModels(virQEMUCapsPtr qemuCaps, uid_t runUid, gid_t runGid)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
char *output = NULL;
|
|
|
|
int ret = -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseCPUModels parse;
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandPtr cmd;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (qemuCaps->arch == VIR_ARCH_I686 ||
|
2014-09-03 19:32:36 +00:00
|
|
|
qemuCaps->arch == VIR_ARCH_X86_64) {
|
2013-02-01 13:48:58 +00:00
|
|
|
parse = virQEMUCapsParseX86Models;
|
2014-11-04 17:21:26 +00:00
|
|
|
} else if ARCH_IS_PPC64(qemuCaps->arch) {
|
2013-02-01 13:48:58 +00:00
|
|
|
parse = virQEMUCapsParsePPCModels;
|
2014-09-03 19:32:36 +00:00
|
|
|
} else {
|
2012-08-22 16:23:00 +00:00
|
|
|
VIR_DEBUG("don't know how to parse %s CPU models",
|
2013-02-01 13:48:58 +00:00
|
|
|
virArchToString(qemuCaps->arch));
|
2010-12-16 15:07:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-30 20:07:03 +00:00
|
|
|
cmd = virQEMUCapsProbeCommand(qemuCaps->binary, qemuCaps, runUid, runGid);
|
2012-04-26 13:10:22 +00:00
|
|
|
virCommandAddArgList(cmd, "-cpu", "?", NULL);
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-01-12 23:26:34 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (parse(output, qemuCaps) < 0)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-12-16 15:07:07 +00:00
|
|
|
VIR_FREE(output);
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandFree(cmd);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-22 16:59:39 +00:00
|
|
|
static char *
|
2015-09-15 13:58:09 +00:00
|
|
|
virQEMUCapsFindBinary(const char *format,
|
|
|
|
const char *archstr)
|
2012-08-22 16:59:39 +00:00
|
|
|
{
|
2015-09-15 13:58:09 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
char *binary = NULL;
|
2015-02-15 04:18:00 +00:00
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
if (virAsprintf(&binary, format, archstr) < 0)
|
|
|
|
goto out;
|
2012-12-11 13:06:45 +00:00
|
|
|
|
|
|
|
ret = virFindFileInPath(binary);
|
|
|
|
VIR_FREE(binary);
|
2015-09-15 13:58:09 +00:00
|
|
|
if (ret && virFileIsExecutable(ret))
|
|
|
|
goto out;
|
2012-12-11 13:06:45 +00:00
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
VIR_FREE(ret);
|
2015-05-21 22:06:09 +00:00
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
virQEMUCapsFindBinaryForArch(virArch hostarch,
|
|
|
|
virArch guestarch)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
const char *archstr;
|
|
|
|
virArch target;
|
|
|
|
|
|
|
|
/* First attempt: try the guest architecture as it is */
|
|
|
|
archstr = virQEMUCapsArchToString(guestarch);
|
|
|
|
if ((ret = virQEMUCapsFindBinary("qemu-system-%s", archstr)) != NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Second attempt: try looking up by target instead */
|
|
|
|
target = virQEMUCapsFindTarget(hostarch, guestarch);
|
|
|
|
if (target != guestarch) {
|
|
|
|
archstr = virQEMUCapsArchToString(target);
|
|
|
|
if ((ret = virQEMUCapsFindBinary("qemu-system-%s", archstr)) != NULL)
|
|
|
|
goto out;
|
2012-12-11 13:06:45 +00:00
|
|
|
}
|
2012-08-22 16:59:39 +00:00
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
/* Third attempt, i686 only: try 'qemu' */
|
|
|
|
if (guestarch == VIR_ARCH_I686) {
|
|
|
|
if ((ret = virQEMUCapsFindBinary("%s", "qemu")) != NULL)
|
|
|
|
goto out;
|
2012-08-22 16:59:39 +00:00
|
|
|
}
|
2012-12-11 13:06:45 +00:00
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
out:
|
2012-08-22 16:59:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-16 15:07:07 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsInitGuest(virCapsPtr caps,
|
|
|
|
virQEMUCapsCachePtr cache,
|
|
|
|
virArch hostarch,
|
|
|
|
virArch guestarch)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-16 15:07:07 +00:00
|
|
|
char *kvmbin = NULL;
|
|
|
|
char *binary = NULL;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr qemubinCaps = NULL;
|
|
|
|
virQEMUCapsPtr kvmbinCaps = NULL;
|
2015-09-30 15:58:58 +00:00
|
|
|
bool native_kvm, x86_32on64_kvm, arm_32on64_kvm, ppc64_kvm;
|
2010-12-16 15:07:07 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2012-10-11 16:31:20 +00:00
|
|
|
/* Check for existence of base emulator, or alternate base
|
2010-12-16 15:07:07 +00:00
|
|
|
* which can be used with magic cpu choice
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
binary = virQEMUCapsFindBinaryForArch(hostarch, guestarch);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-07-13 14:30:55 +00:00
|
|
|
/* Ignore binary if extracting version info fails */
|
2012-08-22 13:37:05 +00:00
|
|
|
if (binary) {
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(qemubinCaps = virQEMUCapsCacheLookup(cache, binary))) {
|
2012-08-22 13:37:05 +00:00
|
|
|
virResetLastError();
|
|
|
|
VIR_FREE(binary);
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 14:30:55 +00:00
|
|
|
|
|
|
|
/* qemu-kvm/kvm binaries can only be used if
|
2010-12-16 15:07:07 +00:00
|
|
|
* - host & guest arches match
|
2015-05-21 22:18:30 +00:00
|
|
|
* - hostarch is x86_64 and guest arch is i686 (needs -cpu qemu32)
|
|
|
|
* - hostarch is aarch64 and guest arch is armv7l (needs -cpu aarch64=off)
|
2015-09-30 15:58:58 +00:00
|
|
|
* - hostarch and guestarch are both ppc64*
|
2010-12-16 15:07:07 +00:00
|
|
|
*/
|
2015-05-21 22:18:30 +00:00
|
|
|
native_kvm = (hostarch == guestarch);
|
|
|
|
x86_32on64_kvm = (hostarch == VIR_ARCH_X86_64 &&
|
|
|
|
guestarch == VIR_ARCH_I686);
|
|
|
|
arm_32on64_kvm = (hostarch == VIR_ARCH_AARCH64 &&
|
|
|
|
guestarch == VIR_ARCH_ARMV7L);
|
2015-09-30 15:58:58 +00:00
|
|
|
ppc64_kvm = (ARCH_IS_PPC64(hostarch) && ARCH_IS_PPC64(guestarch));
|
2015-05-21 22:18:30 +00:00
|
|
|
|
2015-09-30 15:58:58 +00:00
|
|
|
if (native_kvm || x86_32on64_kvm || arm_32on64_kvm || ppc64_kvm) {
|
2015-05-21 22:18:30 +00:00
|
|
|
const char *kvmbins[] = {
|
|
|
|
"/usr/libexec/qemu-kvm", /* RHEL */
|
|
|
|
"qemu-kvm", /* Fedora */
|
|
|
|
"kvm", /* Debian/Ubuntu */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* x86 32-on-64 can be used with qemu-system-i386 and
|
|
|
|
* qemu-system-x86_64, so if we don't find a specific kvm binary,
|
|
|
|
* we can just fall back to the host arch native binary and
|
|
|
|
* everything works fine.
|
|
|
|
*
|
|
|
|
* arm is different in that 32-on-64 _only_ works with
|
|
|
|
* qemu-system-aarch64. So we have to add it to the kvmbins list
|
|
|
|
*/
|
|
|
|
if (arm_32on64_kvm)
|
|
|
|
kvmbins[3] = "qemu-system-aarch64";
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-07-13 14:30:55 +00:00
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(kvmbins); ++i) {
|
2015-05-21 22:18:30 +00:00
|
|
|
if (!kvmbins[i])
|
|
|
|
continue;
|
|
|
|
|
2012-07-13 14:30:55 +00:00
|
|
|
kvmbin = virFindFileInPath(kvmbins[i]);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-07-13 14:30:55 +00:00
|
|
|
if (!kvmbin)
|
|
|
|
continue;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(kvmbinCaps = virQEMUCapsCacheLookup(cache, kvmbin))) {
|
2012-08-22 13:37:05 +00:00
|
|
|
virResetLastError();
|
2012-07-13 14:30:55 +00:00
|
|
|
VIR_FREE(kvmbin);
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-07-13 14:30:55 +00:00
|
|
|
if (!binary) {
|
|
|
|
binary = kvmbin;
|
2012-08-20 16:44:14 +00:00
|
|
|
qemubinCaps = kvmbinCaps;
|
2012-07-13 14:30:55 +00:00
|
|
|
kvmbin = NULL;
|
2012-08-20 16:44:14 +00:00
|
|
|
kvmbinCaps = NULL;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
2012-07-13 14:30:55 +00:00
|
|
|
break;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:19:45 +00:00
|
|
|
ret = virQEMUCapsInitGuestFromBinary(caps,
|
|
|
|
binary, qemubinCaps,
|
|
|
|
kvmbin, kvmbinCaps,
|
|
|
|
guestarch);
|
|
|
|
|
|
|
|
VIR_FREE(binary);
|
|
|
|
VIR_FREE(kvmbin);
|
|
|
|
virObjectUnref(qemubinCaps);
|
|
|
|
virObjectUnref(kvmbinCaps);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
|
|
|
|
const char *binary,
|
|
|
|
virQEMUCapsPtr qemubinCaps,
|
|
|
|
const char *kvmbin,
|
|
|
|
virQEMUCapsPtr kvmbinCaps,
|
|
|
|
virArch guestarch)
|
|
|
|
{
|
|
|
|
virCapsGuestPtr guest;
|
|
|
|
bool haskvm = false;
|
|
|
|
virCapsGuestMachinePtr *machines = NULL;
|
|
|
|
size_t nmachines = 0;
|
|
|
|
int ret = -1;
|
|
|
|
bool hasdisksnapshot = false;
|
|
|
|
|
2010-12-16 15:07:07 +00:00
|
|
|
if (!binary)
|
|
|
|
return 0;
|
|
|
|
|
2013-09-13 13:32:43 +00:00
|
|
|
if (virFileExists("/dev/kvm") &&
|
2013-02-01 13:48:58 +00:00
|
|
|
(virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KVM) ||
|
|
|
|
virQEMUCapsGet(qemubinCaps, QEMU_CAPS_ENABLE_KVM) ||
|
2012-07-13 14:30:55 +00:00
|
|
|
kvmbin))
|
2013-05-24 10:14:02 +00:00
|
|
|
haskvm = true;
|
2012-07-13 14:30:55 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGetMachineTypesCaps(qemubinCaps, &nmachines, &machines) < 0)
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
/* We register kvm as the base emulator too, since we can
|
|
|
|
* just give -no-kvm to disable acceleration if required */
|
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
2015-04-17 22:09:16 +00:00
|
|
|
VIR_DOMAIN_OSTYPE_HVM,
|
2012-08-22 16:59:39 +00:00
|
|
|
guestarch,
|
2010-12-16 15:07:07 +00:00
|
|
|
binary,
|
|
|
|
NULL,
|
|
|
|
nmachines,
|
|
|
|
machines)) == NULL)
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
machines = NULL;
|
|
|
|
nmachines = 0;
|
|
|
|
|
2016-05-16 08:08:29 +00:00
|
|
|
/* CPU selection is always available, because all QEMU versions
|
|
|
|
* we support can use at least '-cpu host' */
|
|
|
|
if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false))
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemubinCaps, QEMU_CAPS_BOOTINDEX) &&
|
2014-07-14 12:56:13 +00:00
|
|
|
!virCapabilitiesAddGuestFeature(guest, "deviceboot", true, false))
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2011-01-12 10:33:34 +00:00
|
|
|
|
2014-03-17 15:19:44 +00:00
|
|
|
if (virQEMUCapsGet(qemubinCaps, QEMU_CAPS_DISK_SNAPSHOT))
|
|
|
|
hasdisksnapshot = true;
|
|
|
|
|
2014-07-14 12:56:13 +00:00
|
|
|
if (!virCapabilitiesAddGuestFeature(guest, "disksnapshot", hasdisksnapshot,
|
|
|
|
false))
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2014-03-17 15:19:44 +00:00
|
|
|
|
2012-08-22 16:29:01 +00:00
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
2015-04-17 22:38:10 +00:00
|
|
|
VIR_DOMAIN_VIRT_QEMU,
|
2012-08-22 16:29:01 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:29:01 +00:00
|
|
|
if (haskvm) {
|
|
|
|
virCapsGuestDomainPtr dom;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:29:01 +00:00
|
|
|
if (kvmbin &&
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsGetMachineTypesCaps(kvmbinCaps, &nmachines, &machines) < 0)
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:29:01 +00:00
|
|
|
if ((dom = virCapabilitiesAddGuestDomain(guest,
|
2015-04-17 22:38:10 +00:00
|
|
|
VIR_DOMAIN_VIRT_KVM,
|
2012-08-22 16:29:01 +00:00
|
|
|
kvmbin ? kvmbin : binary,
|
|
|
|
NULL,
|
|
|
|
nmachines,
|
|
|
|
machines)) == NULL) {
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2012-08-22 16:29:01 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-22 16:29:01 +00:00
|
|
|
machines = NULL;
|
|
|
|
nmachines = 0;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if (((guestarch == VIR_ARCH_I686) ||
|
|
|
|
(guestarch == VIR_ARCH_X86_64)) &&
|
2014-07-14 12:56:13 +00:00
|
|
|
(virCapabilitiesAddGuestFeature(guest, "acpi", true, true) == NULL ||
|
|
|
|
virCapabilitiesAddGuestFeature(guest, "apic", true, false) == NULL))
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2012-08-22 16:59:39 +00:00
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((guestarch == VIR_ARCH_I686) &&
|
2014-07-14 12:56:13 +00:00
|
|
|
(virCapabilitiesAddGuestFeature(guest, "pae", true, false) == NULL ||
|
|
|
|
virCapabilitiesAddGuestFeature(guest, "nonpae", true, false) == NULL))
|
2014-03-17 15:19:45 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
virCapabilitiesFreeMachines(machines, nmachines);
|
|
|
|
|
2014-03-17 15:19:45 +00:00
|
|
|
return ret;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsInitCPU(virCapsPtr caps,
|
|
|
|
virArch arch)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
virCPUDefPtr cpu = NULL;
|
2012-12-18 18:44:23 +00:00
|
|
|
virCPUDataPtr data = NULL;
|
2010-12-16 15:07:07 +00:00
|
|
|
virNodeInfo nodeinfo;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC(cpu) < 0)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto error;
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
cpu->arch = arch;
|
|
|
|
|
2015-07-07 11:27:53 +00:00
|
|
|
if (nodeGetInfo(NULL, &nodeinfo))
|
2010-12-16 15:07:07 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
cpu->type = VIR_CPU_TYPE_HOST;
|
|
|
|
cpu->sockets = nodeinfo.sockets;
|
|
|
|
cpu->cores = nodeinfo.cores;
|
|
|
|
cpu->threads = nodeinfo.threads;
|
2012-10-16 19:11:29 +00:00
|
|
|
caps->host.cpu = cpu;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
if (!(data = cpuNodeData(arch))
|
2010-12-16 15:07:07 +00:00
|
|
|
|| cpuDecode(cpu, data, NULL, 0, NULL) < 0)
|
2012-10-16 19:11:29 +00:00
|
|
|
goto cleanup;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-07-16 12:39:40 +00:00
|
|
|
cpuDataFree(data);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2010-12-16 15:07:07 +00:00
|
|
|
virCPUDefFree(cpu);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-06 16:12:51 +00:00
|
|
|
static int
|
|
|
|
virQEMUCapsInitPages(virCapsPtr caps)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
unsigned int *pages_size = NULL;
|
|
|
|
size_t npages;
|
|
|
|
|
|
|
|
if (virNumaGetPages(-1 /* Magic constant for overall info */,
|
|
|
|
&pages_size, NULL, NULL, &npages) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
caps->host.pagesSize = pages_size;
|
|
|
|
pages_size = NULL;
|
|
|
|
caps->host.nPagesSize = npages;
|
|
|
|
npages = 0;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(pages_size);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
virCapsPtr caps;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-04-08 12:33:07 +00:00
|
|
|
virArch hostarch = virArchFromHost();
|
2012-12-10 22:28:09 +00:00
|
|
|
|
2013-04-08 12:33:07 +00:00
|
|
|
if ((caps = virCapabilitiesNew(hostarch,
|
2014-07-14 12:56:13 +00:00
|
|
|
true, true)) == NULL)
|
2012-08-22 16:59:39 +00:00
|
|
|
goto error;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
/* Some machines have problematic NUMA toplogy causing
|
|
|
|
* unexpected failures. We don't want to break the QEMU
|
|
|
|
* driver in this scenario, so log errors & carry on
|
|
|
|
*/
|
2015-07-07 21:22:28 +00:00
|
|
|
if (nodeCapsInitNUMA(NULL, caps) < 0) {
|
2010-12-16 15:07:07 +00:00
|
|
|
virCapabilitiesFreeNUMAInfo(caps);
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 12:33:07 +00:00
|
|
|
if (virQEMUCapsInitCPU(caps, hostarch) < 0)
|
2012-08-22 13:37:05 +00:00
|
|
|
VIR_WARN("Failed to get host CPU");
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-11-22 03:31:22 +00:00
|
|
|
/* Add the power management features of the host */
|
2011-11-29 14:50:04 +00:00
|
|
|
if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0)
|
2011-11-22 03:31:22 +00:00
|
|
|
VIR_WARN("Failed to get host power management capabilities");
|
|
|
|
|
2014-06-06 16:12:51 +00:00
|
|
|
/* Add huge pages info */
|
|
|
|
if (virQEMUCapsInitPages(caps) < 0)
|
|
|
|
VIR_WARN("Failed to get pages info");
|
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
/* Add domain migration transport URIs */
|
|
|
|
virCapabilitiesAddHostMigrateTransport(caps, "tcp");
|
|
|
|
virCapabilitiesAddHostMigrateTransport(caps, "rdma");
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
/* QEMU can support pretty much every arch that exists,
|
|
|
|
* so just probe for them all - we gracefully fail
|
|
|
|
* if a qemu-system-$ARCH binary can't be found
|
|
|
|
*/
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < VIR_ARCH_LAST; i++)
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsInitGuest(caps, cache,
|
2013-04-08 12:33:07 +00:00
|
|
|
hostarch,
|
2013-02-01 13:48:58 +00:00
|
|
|
i) < 0)
|
2012-08-22 16:59:39 +00:00
|
|
|
goto error;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2010-12-16 15:07:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 04:57:38 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsComputeCmdFlags(const char *help,
|
|
|
|
unsigned int version,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
bool check_yajl ATTRIBUTE_UNUSED)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
const char *p;
|
2012-08-03 20:33:05 +00:00
|
|
|
const char *fsdev, *netdev;
|
2015-11-06 14:28:57 +00:00
|
|
|
const char *cache;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if (strstr(help, "-no-kvm"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-enable-kvm"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_ENABLE_KVM);
|
2015-11-06 14:29:41 +00:00
|
|
|
if (strstr(help, ",process="))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NAME_PROCESS);
|
2015-11-06 14:28:57 +00:00
|
|
|
|
|
|
|
cache = strstr(help, "cache=");
|
|
|
|
if (cache && (p = strchr(cache, ']'))) {
|
|
|
|
if (memmem(cache, p - cache, "directsync", sizeof("directsync") - 1))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC);
|
|
|
|
if (memmem(cache, p - cache, "unsafe", sizeof("unsafe") - 1))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_UNSAFE);
|
|
|
|
}
|
|
|
|
if (strstr(help, "readonly="))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_READONLY);
|
|
|
|
if (strstr(help, "aio=threads|native"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_AIO);
|
|
|
|
if (strstr(help, "copy-on-read=on|off"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_COPY_ON_READ);
|
|
|
|
if (strstr(help, "bps="))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE);
|
|
|
|
|
2010-12-16 15:07:07 +00:00
|
|
|
if ((p = strstr(help, "-vga")) && !strstr(help, "-std-vga")) {
|
|
|
|
const char *nl = strstr(p, "\n");
|
|
|
|
if (strstr(p, "|qxl"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VGA_QXL);
|
2010-12-16 15:07:07 +00:00
|
|
|
if ((p = strstr(p, "|none")) && p < nl)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VGA_NONE);
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
if (strstr(help, "-spice"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SPICE);
|
2012-10-19 19:40:52 +00:00
|
|
|
if (strstr(help, "-vnc"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC);
|
2012-09-20 09:15:31 +00:00
|
|
|
if (strstr(help, "seamless-migration="))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SEAMLESS_MIGRATION);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "boot=on"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_BOOT);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "serial=s"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-pcidevice"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCIDEVICE);
|
qemu: add host-pci-multidomain capability
Quite a long time ago, (apparently between qemu 0.12 and 0.13) qemu
quietly began supporting the optional specification of a domain in the
host-side address of all pci passthrough commands (by simply
prepending it to the bus:slot.function format, as
"dddd:bb:ss.f"). Since machines with multiple PCI domains are very
rare, this never came up in practice, so libvirt was never updated to
support it.
This patch takes the first step to supporting specification of a non-0
domain in the host-side address of PCI devices being assigned to a
domain, by adding a capability bit to indicate support
"QEMU_CAPS_HOST_PCI_MULTIDOMAIN", and detect it. Since this support
was added in a version prior to the minimum version required for
QMP-style capabilities detection, the capability is always enabled for
any qemu that uses QMP for capabilities detection. For older qemus,
the only clue that a domain can be specified in the host pci address
is the presence of the string "[seg:]" in the help string for
-pcidevice. (Ironically, libvirt will not be modified to support
specification of domain for -pcidevice, since any qemu new enough for
us to care about also supports "-device pci-assign" or "-device
vfio-pci", which are greatly preferred).
2014-04-29 15:11:45 +00:00
|
|
|
if (strstr(help, "host=[seg:]bus"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-mem-path"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MEM_PATH);
|
2011-01-13 15:54:33 +00:00
|
|
|
if (strstr(help, "-chardev")) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV);
|
2011-01-13 15:54:33 +00:00
|
|
|
if (strstr(help, "-chardev spicevmc"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEVMC);
|
2014-01-30 11:19:12 +00:00
|
|
|
if (strstr(help, "-chardev spiceport"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEPORT);
|
2011-01-13 15:54:33 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-device")) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE);
|
2010-12-16 15:07:07 +00:00
|
|
|
/*
|
|
|
|
* When -device was introduced, qemu already supported drive's
|
|
|
|
* readonly option but didn't advertise that.
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_READONLY);
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
if (strstr(help, "-nodefconfig"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NODEFCONFIG);
|
2012-04-26 10:11:49 +00:00
|
|
|
if (strstr(help, "-no-user-config"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_USER_CONFIG);
|
2010-12-16 15:07:07 +00:00
|
|
|
/* The trailing ' ' is important to avoid a bogus match */
|
|
|
|
if (strstr(help, "-rtc "))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_RTC);
|
2010-12-16 15:07:07 +00:00
|
|
|
/* to wit */
|
|
|
|
if (strstr(help, "-rtc-td-hack"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_RTC_TD_HACK);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-no-hpet"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_HPET);
|
2011-12-20 01:08:29 +00:00
|
|
|
if (strstr(help, "-no-acpi"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_ACPI);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-no-kvm-pit-reinjection"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-tdf"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_TDF);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-enable-nesting"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NESTING);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, ",menu=on"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_BOOT_MENU);
|
2012-09-18 10:31:30 +00:00
|
|
|
if (strstr(help, ",reboot-timeout=rb_time"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_REBOOT_TIMEOUT);
|
2014-08-22 11:42:46 +00:00
|
|
|
if (strstr(help, ",splash-time=sp_time"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SPLASH_TIMEOUT);
|
2011-12-21 15:51:29 +00:00
|
|
|
if ((fsdev = strstr(help, "-fsdev"))) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV);
|
2011-12-21 15:51:29 +00:00
|
|
|
if (strstr(fsdev, "readonly"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV_READONLY);
|
2012-01-17 12:44:18 +00:00
|
|
|
if (strstr(fsdev, "writeout"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV_WRITEOUT);
|
2011-12-21 15:51:29 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "-smbios type"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SMBIOS_TYPE);
|
2012-09-18 07:24:51 +00:00
|
|
|
if (strstr(help, "-sandbox"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SECCOMP_SANDBOX);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-08-03 20:33:05 +00:00
|
|
|
if ((netdev = strstr(help, "-netdev"))) {
|
2010-12-16 15:07:07 +00:00
|
|
|
/* Disable -netdev on 0.12 since although it exists,
|
|
|
|
* the corresponding netdev_add/remove monitor commands
|
2012-01-26 04:33:21 +00:00
|
|
|
* do not, and we need them to be able to do hotplug.
|
|
|
|
* But see below about RHEL build. */
|
2012-08-03 20:33:05 +00:00
|
|
|
if (version >= 13000) {
|
|
|
|
if (strstr(netdev, "bridge"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV_BRIDGE);
|
2015-06-22 08:54:56 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV);
|
2012-08-03 20:33:05 +00:00
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(help, "-sdl"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SDL);
|
2010-12-16 15:07:07 +00:00
|
|
|
if (strstr(help, "cores=") &&
|
|
|
|
strstr(help, "threads=") &&
|
|
|
|
strstr(help, "sockets="))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2014-11-13 14:25:30 +00:00
|
|
|
if (strstr(help, ",vhost="))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VHOST_NET);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-09-21 08:25:29 +00:00
|
|
|
/* Do not use -no-shutdown if qemu doesn't support it or SIGTERM handling
|
|
|
|
* is most likely buggy when used with -no-shutdown (which applies for qemu
|
2011-10-17 10:15:20 +00:00
|
|
|
* 0.14.* and 0.15.0)
|
2011-09-21 08:25:29 +00:00
|
|
|
*/
|
2011-10-17 10:15:20 +00:00
|
|
|
if (strstr(help, "-no-shutdown") && (version < 14000 || version > 15000))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_SHUTDOWN);
|
2011-09-21 08:25:29 +00:00
|
|
|
|
2012-08-15 07:59:24 +00:00
|
|
|
if (strstr(help, "dump-guest-core=on|off"))
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
|
2012-08-15 07:59:24 +00:00
|
|
|
|
2013-03-14 04:49:43 +00:00
|
|
|
if (strstr(help, "-dtb"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
|
|
|
|
|
2013-03-29 05:22:46 +00:00
|
|
|
if (strstr(help, "-machine"))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
|
|
|
|
|
2010-12-16 15:07:07 +00:00
|
|
|
/* While JSON mode was available in 0.12.0, it was too
|
|
|
|
* incomplete to contemplate using. The 0.13.0 release
|
|
|
|
* is good enough to use, even though it lacks one or
|
2012-01-26 04:33:21 +00:00
|
|
|
* two features. This is also true of versions of qemu
|
|
|
|
* built for RHEL, labeled 0.12.1, but with extra text
|
|
|
|
* in the help output that mentions that features were
|
|
|
|
* backported for libvirt. The benefits of JSON mode now
|
|
|
|
* outweigh the downside.
|
2010-12-16 15:07:07 +00:00
|
|
|
*/
|
2012-09-20 11:57:13 +00:00
|
|
|
#if WITH_YAJL
|
2012-01-26 04:33:21 +00:00
|
|
|
if (version >= 13000) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MONITOR_JSON);
|
2012-01-26 04:33:21 +00:00
|
|
|
} else if (version >= 12000 &&
|
|
|
|
strstr(help, "libvirt")) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MONITOR_JSON);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV);
|
2012-01-26 04:33:21 +00:00
|
|
|
}
|
2012-01-26 04:57:38 +00:00
|
|
|
#else
|
|
|
|
/* Starting with qemu 0.15 and newer, upstream qemu no longer
|
|
|
|
* promises to keep the human interface stable, but requests that
|
|
|
|
* we use QMP (the JSON interface) for everything. If the user
|
|
|
|
* forgot to include YAJL libraries when building their own
|
2015-03-19 15:53:00 +00:00
|
|
|
* libvirt but is targeting a newer qemu, we are better off
|
2012-01-26 04:57:38 +00:00
|
|
|
* telling them to recompile (the spec file includes the
|
2012-06-13 16:09:39 +00:00
|
|
|
* dependency, so distros won't hit this). This check is
|
2012-09-20 12:03:27 +00:00
|
|
|
* also in m4/virt-yajl.m4 (see $with_yajl). */
|
2012-01-26 04:57:38 +00:00
|
|
|
if (version >= 15000 ||
|
|
|
|
(version >= 12000 && strstr(help, "libvirt"))) {
|
|
|
|
if (check_yajl) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("this qemu binary requires libvirt to be "
|
|
|
|
"compiled with yajl"));
|
2012-01-26 04:57:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV);
|
2012-01-26 04:57:38 +00:00
|
|
|
}
|
2011-10-20 20:36:32 +00:00
|
|
|
#endif
|
2011-05-09 06:59:16 +00:00
|
|
|
|
|
|
|
if (version >= 13000)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIFUNCTION);
|
2011-09-20 17:31:52 +00:00
|
|
|
|
2013-05-21 14:31:47 +00:00
|
|
|
if (version >= 1001000) {
|
2013-03-22 13:52:25 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
|
2013-05-21 14:31:47 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
|
|
|
|
}
|
2013-03-22 13:52:25 +00:00
|
|
|
|
2012-01-26 04:57:38 +00:00
|
|
|
return 0;
|
2010-12-16 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We parse the output of 'qemu -help' to get the QEMU
|
|
|
|
* version number. The first bit is easy, just parse
|
|
|
|
* 'QEMU PC emulator version x.y.z'
|
|
|
|
* or
|
|
|
|
* 'QEMU emulator version x.y.z'.
|
|
|
|
*
|
|
|
|
* With qemu-kvm, however, that is followed by a string
|
|
|
|
* in parenthesis as follows:
|
|
|
|
* - qemu-kvm-x.y.z in stable releases
|
|
|
|
* - kvm-XX for kvm versions up to kvm-85
|
|
|
|
* - qemu-kvm-devel-XX for kvm version kvm-86 and later
|
|
|
|
*
|
|
|
|
* For qemu-kvm versions before 0.10.z, we need to detect
|
|
|
|
* the KVM version number for some features. With 0.10.z
|
|
|
|
* and later, we just need the QEMU version number and
|
|
|
|
* whether it is KVM QEMU or mainline QEMU.
|
|
|
|
*/
|
|
|
|
#define QEMU_VERSION_STR_1 "QEMU emulator version"
|
|
|
|
#define QEMU_VERSION_STR_2 "QEMU PC emulator version"
|
|
|
|
#define QEMU_KVM_VER_PREFIX "(qemu-kvm-"
|
|
|
|
#define KVM_VER_PREFIX "(kvm-"
|
|
|
|
|
|
|
|
#define SKIP_BLANKS(p) do { while ((*(p) == ' ') || (*(p) == '\t')) (p)++; } while (0)
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
int virQEMUCapsParseHelpStr(const char *qemu,
|
|
|
|
const char *help,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
unsigned int *version,
|
2013-05-24 10:47:17 +00:00
|
|
|
bool *is_kvm,
|
2013-02-01 13:48:58 +00:00
|
|
|
unsigned int *kvm_version,
|
2014-12-04 15:26:41 +00:00
|
|
|
bool check_yajl,
|
|
|
|
const char *qmperr)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
|
|
|
unsigned major, minor, micro;
|
|
|
|
const char *p = help;
|
2011-02-08 14:22:39 +00:00
|
|
|
char *strflags;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2013-05-24 10:47:17 +00:00
|
|
|
*version = *kvm_version = 0;
|
|
|
|
*is_kvm = false;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if (STRPREFIX(p, QEMU_VERSION_STR_1))
|
|
|
|
p += strlen(QEMU_VERSION_STR_1);
|
|
|
|
else if (STRPREFIX(p, QEMU_VERSION_STR_2))
|
|
|
|
p += strlen(QEMU_VERSION_STR_2);
|
|
|
|
else
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
SKIP_BLANKS(p);
|
|
|
|
|
|
|
|
major = virParseNumber(&p);
|
|
|
|
if (major == -1 || *p != '.')
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
++p;
|
|
|
|
|
|
|
|
minor = virParseNumber(&p);
|
2011-12-02 20:20:15 +00:00
|
|
|
if (minor == -1)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto fail;
|
|
|
|
|
2011-12-02 20:20:15 +00:00
|
|
|
if (*p != '.') {
|
|
|
|
micro = 0;
|
|
|
|
} else {
|
|
|
|
++p;
|
|
|
|
micro = virParseNumber(&p);
|
|
|
|
if (micro == -1)
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
SKIP_BLANKS(p);
|
|
|
|
|
|
|
|
if (STRPREFIX(p, QEMU_KVM_VER_PREFIX)) {
|
2013-05-24 10:47:17 +00:00
|
|
|
*is_kvm = true;
|
2010-12-16 15:07:07 +00:00
|
|
|
p += strlen(QEMU_KVM_VER_PREFIX);
|
|
|
|
} else if (STRPREFIX(p, KVM_VER_PREFIX)) {
|
|
|
|
int ret;
|
|
|
|
|
2013-05-24 10:47:17 +00:00
|
|
|
*is_kvm = true;
|
2010-12-16 15:07:07 +00:00
|
|
|
p += strlen(KVM_VER_PREFIX);
|
|
|
|
|
|
|
|
ret = virParseNumber(&p);
|
|
|
|
if (ret == -1)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*kvm_version = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*version = (major * 1000 * 1000) + (minor * 1000) + micro;
|
|
|
|
|
2015-11-05 10:51:48 +00:00
|
|
|
if (*version < 12000) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("QEMU version >= 0.12.00 is required, but %d.%d.%d found"),
|
|
|
|
major, minor, micro);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-12 15:49:59 +00:00
|
|
|
/* Refuse to parse -help output for QEMU releases >= 1.2.0 that should be
|
|
|
|
* using QMP probing.
|
|
|
|
*/
|
|
|
|
if (*version >= 1002000) {
|
2014-12-04 15:26:41 +00:00
|
|
|
if (qmperr && *qmperr) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("QEMU / QMP failed: %s"),
|
|
|
|
qmperr);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("QEMU %u.%u.%u is too new for help parsing"),
|
|
|
|
major, minor, micro);
|
|
|
|
}
|
2014-11-12 15:49:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:50:26 +00:00
|
|
|
if (virQEMUCapsComputeCmdFlags(help, *version,
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps, check_yajl) < 0)
|
2012-01-26 04:57:38 +00:00
|
|
|
goto cleanup;
|
2011-02-08 14:22:39 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
strflags = virBitmapString(qemuCaps->flags);
|
2011-02-08 14:22:39 +00:00
|
|
|
VIR_DEBUG("Version %u.%u.%u, cooked version %u, flags %s",
|
|
|
|
major, minor, micro, *version, NULLSTR(strflags));
|
|
|
|
VIR_FREE(strflags);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if (*kvm_version)
|
|
|
|
VIR_DEBUG("KVM version %d detected", *kvm_version);
|
|
|
|
else if (*is_kvm)
|
|
|
|
VIR_DEBUG("qemu-kvm version %u.%u.%u detected", major, minor, micro);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
fail:
|
2010-12-16 15:07:07 +00:00
|
|
|
p = strchr(help, '\n');
|
2012-01-27 20:53:11 +00:00
|
|
|
if (!p)
|
|
|
|
p = strchr(help, '\0');
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot parse %s version number in '%.*s'"),
|
|
|
|
qemu, (int) (p - help), help);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-12-16 15:07:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-09-13 17:04:24 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
struct virQEMUCapsStringFlags {
|
2012-09-13 17:04:24 +00:00
|
|
|
const char *value;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-19 08:00:10 +00:00
|
|
|
struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
|
|
|
|
{ "system_wakeup", QEMU_CAPS_WAKEUP },
|
|
|
|
{ "transaction", QEMU_CAPS_TRANSACTION },
|
qemu: better error message when block job can't succeed
https://bugzilla.redhat.com/show_bug.cgi?id=1140981 reports that
the qemu-kvm shipped as part of RHEL 7.0 intentionally[1] cripples
block jobs by removing the 'block-stream' QMP command, while still
leaving 'block-job-cancel' as an unusable no-op. Meanwhile, we
already had existing code that checked whether block jobs were
completely missing (such as qemu 0.15), old style (cancel is
synchronous, and all commands spelled with '_'), or new style
(cancel is asynchronous, and all commands spelled with '-'), and
used that three-way probe to give decent error messages. At the
time that code was added, all existing qemu versions fell in one
of three buckets, and the code was using the presence of
'block-job-cancel' as the witness of which of the three buckets.
But now that RHEL qemu has shipped with intentionally crippled
'block-stream', we have a fourth bucket, which results in ugly
error messages when trying 'virsh blockpull':
error: Requested operation is not valid: Command 'block-stream' is not found
In reality, the fourth bucket should be treated the same as the
first bucket (no block job support); we can do that by realizing
that no existing build of qemu has working block-stream while
lacking block-job-cancel, so it is easiest to change our witness
to the command that starts a job rather than ends one. We still
act correctly regarding command spelling and whether cancel is
asynchronous. And on crippled RHEL builds, we now get the desired:
error: unsupported configuration: block jobs not supported with this qemu binary
[1] The intentional cripple is limited to qemu-kvm of RHEL; when using
qemu-kvm-rhev of RHEV, block job functionality is supported. Don't ask
me to explain the "why" behind it all - I'm just dealing with fallout
from someone else's decision.
* src/qemu/qemu_capabilities.h (QEMU_CAPS_BLOCKJOB_SYNC): Tweak comment.
* src/qemu/qemu_capabilities.c (virQEMUCapsCommands): Look for stream
rather than cancel when determining the flavor of block jobs supported.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-24 20:49:13 +00:00
|
|
|
{ "block_stream", QEMU_CAPS_BLOCKJOB_SYNC },
|
|
|
|
{ "block-stream", QEMU_CAPS_BLOCKJOB_ASYNC },
|
2013-06-19 08:00:10 +00:00
|
|
|
{ "dump-guest-memory", QEMU_CAPS_DUMP_GUEST_MEMORY },
|
|
|
|
{ "query-spice", QEMU_CAPS_SPICE },
|
|
|
|
{ "query-kvm", QEMU_CAPS_KVM },
|
|
|
|
{ "block-commit", QEMU_CAPS_BLOCK_COMMIT },
|
|
|
|
{ "query-vnc", QEMU_CAPS_VNC },
|
|
|
|
{ "drive-mirror", QEMU_CAPS_DRIVE_MIRROR },
|
|
|
|
{ "blockdev-snapshot-sync", QEMU_CAPS_DISK_SNAPSHOT },
|
|
|
|
{ "add-fd", QEMU_CAPS_ADD_FD },
|
|
|
|
{ "nbd-server-start", QEMU_CAPS_NBD_SERVER },
|
2014-05-26 12:09:22 +00:00
|
|
|
{ "change-backing-file", QEMU_CAPS_CHANGE_BACKING_FILE },
|
2014-08-13 12:28:24 +00:00
|
|
|
{ "rtc-reset-reinjection", QEMU_CAPS_RTC_RESET_REINJECTION },
|
2015-11-11 17:02:23 +00:00
|
|
|
{ "migrate-incoming", QEMU_CAPS_INCOMING_DEFER },
|
2013-06-19 08:00:10 +00:00
|
|
|
};
|
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
struct virQEMUCapsStringFlags virQEMUCapsMigration[] = {
|
|
|
|
{ "rdma-pin-all", QEMU_CAPS_MIGRATE_RDMA },
|
|
|
|
};
|
|
|
|
|
2013-06-19 07:24:54 +00:00
|
|
|
struct virQEMUCapsStringFlags virQEMUCapsEvents[] = {
|
|
|
|
{ "BALLOON_CHANGE", QEMU_CAPS_BALLOON_EVENT },
|
|
|
|
{ "SPICE_MIGRATE_COMPLETED", QEMU_CAPS_SEAMLESS_MIGRATION },
|
2013-07-11 15:07:26 +00:00
|
|
|
{ "DEVICE_DELETED", QEMU_CAPS_DEVICE_DEL_EVENT },
|
2015-05-28 11:35:52 +00:00
|
|
|
{ "MIGRATION", QEMU_CAPS_MIGRATION_EVENT },
|
2016-01-05 13:05:15 +00:00
|
|
|
{ "VSERPORT_CHANGE", QEMU_CAPS_VSERPORT_CHANGE },
|
2016-04-29 11:49:13 +00:00
|
|
|
{ "DEVICE_TRAY_MOVED", QEMU_CAPS_DEVICE_TRAY_MOVED },
|
2013-06-19 07:24:54 +00:00
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "hda-duplex", QEMU_CAPS_HDA_DUPLEX },
|
|
|
|
{ "hda-micro", QEMU_CAPS_HDA_MICRO },
|
|
|
|
{ "ccid-card-emulated", QEMU_CAPS_CCID_EMULATED },
|
|
|
|
{ "ccid-card-passthru", QEMU_CAPS_CCID_PASSTHRU },
|
|
|
|
{ "piix3-usb-uhci", QEMU_CAPS_PIIX3_USB_UHCI },
|
|
|
|
{ "piix4-usb-uhci", QEMU_CAPS_PIIX4_USB_UHCI },
|
|
|
|
{ "usb-ehci", QEMU_CAPS_USB_EHCI },
|
|
|
|
{ "ich9-usb-ehci1", QEMU_CAPS_ICH9_USB_EHCI1 },
|
|
|
|
{ "vt82c686b-usb-uhci", QEMU_CAPS_VT82C686B_USB_UHCI },
|
|
|
|
{ "pci-ohci", QEMU_CAPS_PCI_OHCI },
|
|
|
|
{ "nec-usb-xhci", QEMU_CAPS_NEC_USB_XHCI },
|
|
|
|
{ "usb-redir", QEMU_CAPS_USB_REDIR },
|
|
|
|
{ "usb-hub", QEMU_CAPS_USB_HUB },
|
|
|
|
{ "ich9-ahci", QEMU_CAPS_ICH9_AHCI },
|
|
|
|
{ "virtio-blk-s390", QEMU_CAPS_VIRTIO_S390 },
|
2013-03-05 15:44:21 +00:00
|
|
|
{ "virtio-blk-ccw", QEMU_CAPS_VIRTIO_CCW },
|
2013-01-07 17:17:15 +00:00
|
|
|
{ "sclpconsole", QEMU_CAPS_SCLP_S390 },
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "lsi53c895a", QEMU_CAPS_SCSI_LSI },
|
2013-03-14 18:32:24 +00:00
|
|
|
{ "virtio-scsi-pci", QEMU_CAPS_VIRTIO_SCSI },
|
2013-03-14 18:32:25 +00:00
|
|
|
{ "virtio-scsi-s390", QEMU_CAPS_VIRTIO_SCSI },
|
|
|
|
{ "virtio-scsi-ccw", QEMU_CAPS_VIRTIO_SCSI },
|
2015-04-10 09:22:05 +00:00
|
|
|
{ "virtio-scsi-device", QEMU_CAPS_VIRTIO_SCSI },
|
2013-03-21 14:11:39 +00:00
|
|
|
{ "megasas", QEMU_CAPS_SCSI_MEGASAS },
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "spicevmc", QEMU_CAPS_DEVICE_SPICEVMC },
|
|
|
|
{ "qxl-vga", QEMU_CAPS_DEVICE_QXL_VGA },
|
2012-12-14 07:06:31 +00:00
|
|
|
{ "qxl", QEMU_CAPS_DEVICE_QXL },
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "sga", QEMU_CAPS_SGA },
|
|
|
|
{ "scsi-block", QEMU_CAPS_SCSI_BLOCK },
|
|
|
|
{ "scsi-cd", QEMU_CAPS_SCSI_CD },
|
|
|
|
{ "ide-cd", QEMU_CAPS_IDE_CD },
|
2012-12-14 07:06:31 +00:00
|
|
|
{ "VGA", QEMU_CAPS_DEVICE_VGA },
|
|
|
|
{ "cirrus-vga", QEMU_CAPS_DEVICE_CIRRUS_VGA },
|
|
|
|
{ "vmware-svga", QEMU_CAPS_DEVICE_VMWARE_SVGA },
|
2013-05-03 18:07:21 +00:00
|
|
|
{ "usb-serial", QEMU_CAPS_DEVICE_USB_SERIAL },
|
|
|
|
{ "usb-net", QEMU_CAPS_DEVICE_USB_NET },
|
2013-01-11 16:48:21 +00:00
|
|
|
{ "virtio-rng-pci", QEMU_CAPS_DEVICE_VIRTIO_RNG },
|
2013-03-14 18:32:25 +00:00
|
|
|
{ "virtio-rng-s390", QEMU_CAPS_DEVICE_VIRTIO_RNG },
|
|
|
|
{ "virtio-rng-ccw", QEMU_CAPS_DEVICE_VIRTIO_RNG },
|
2015-04-10 09:22:05 +00:00
|
|
|
{ "virtio-rng-device", QEMU_CAPS_DEVICE_VIRTIO_RNG },
|
2013-01-11 16:48:21 +00:00
|
|
|
{ "rng-random", QEMU_CAPS_OBJECT_RNG_RANDOM },
|
2013-02-13 10:22:23 +00:00
|
|
|
{ "rng-egd", QEMU_CAPS_OBJECT_RNG_EGD },
|
2013-04-25 08:46:04 +00:00
|
|
|
{ "spapr-nvram", QEMU_CAPS_DEVICE_NVRAM },
|
2013-03-07 11:03:41 +00:00
|
|
|
{ "pci-bridge", QEMU_CAPS_DEVICE_PCI_BRIDGE },
|
2013-04-17 18:16:28 +00:00
|
|
|
{ "vfio-pci", QEMU_CAPS_DEVICE_VFIO_PCI },
|
2013-05-03 18:07:21 +00:00
|
|
|
{ "scsi-generic", QEMU_CAPS_DEVICE_SCSI_GENERIC },
|
qemu: add dmi-to-pci-bridge controller
This PCI controller, named "dmi-to-pci-bridge" in the libvirt config,
and implemented with qemu's "i82801b11-bridge" device, connects to a
PCI Express slot (e.g. one of the slots provided by the pcie-root
controller, aka "pcie.0" on the qemu commandline), and provides 31
*non-hot-pluggable* PCI (*not* PCIe) slots, numbered 1-31.
Any time a machine is defined which has a pcie-root controller
(i.e. any q35-based machinetype), libvirt will automatically add a
dmi-to-pci-bridge controller if one doesn't exist, and also add a
pci-bridge controller. The reasoning here is that any useful domain
will have either an immediate (startup time) or eventual (subsequent
hot-plug) need for a standard PCI slot; since the pcie-root controller
only provides PCIe slots, we need to connect a dmi-to-pci-bridge
controller to it in order to get a non-hot-plug PCI slot that we can
then use to connect a pci-bridge - the slots provided by the
pci-bridge will be both standard PCI and hot-pluggable.
Since pci-bridge devices themselves can not be hot-plugged into a
running system (although you can hot-plug other devices into a
pci-bridge's slots), any new pci-bridge controller that is added can
(and will) be plugged into the dmi-to-pci-bridge as long as it has
empty slots available.
This patch is also changing the qemuxml2xml-pcie test from a "DO_TEST"
to a "DO_DIFFERENT_TEST". This is so that the "before" xml can omit
the automatically added dmi-to-pci-bridge and pci-bridge devices, and
the "after" xml can include it - this way we are testing if libvirt is
properly adding these devices.
2013-07-31 01:37:32 +00:00
|
|
|
{ "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE },
|
2013-08-23 10:38:10 +00:00
|
|
|
{ "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE },
|
2013-08-01 01:40:35 +00:00
|
|
|
{ "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO },
|
2013-09-24 14:17:38 +00:00
|
|
|
{ "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA },
|
2013-12-09 09:11:15 +00:00
|
|
|
{ "pvpanic", QEMU_CAPS_DEVICE_PANIC },
|
2014-02-17 10:17:55 +00:00
|
|
|
{ "usb-kbd", QEMU_CAPS_DEVICE_USB_KBD },
|
2014-05-07 15:20:15 +00:00
|
|
|
{ "memory-backend-ram", QEMU_CAPS_OBJECT_MEMORY_RAM },
|
2014-07-23 15:37:21 +00:00
|
|
|
{ "memory-backend-file", QEMU_CAPS_OBJECT_MEMORY_FILE },
|
2014-07-24 15:32:31 +00:00
|
|
|
{ "usb-audio", QEMU_CAPS_OBJECT_USB_AUDIO },
|
2014-08-22 22:15:30 +00:00
|
|
|
{ "iothread", QEMU_CAPS_OBJECT_IOTHREAD},
|
2014-08-22 10:47:02 +00:00
|
|
|
{ "ivshmem", QEMU_CAPS_DEVICE_IVSHMEM },
|
2014-10-06 12:16:47 +00:00
|
|
|
{ "pc-dimm", QEMU_CAPS_DEVICE_PC_DIMM },
|
2015-05-06 15:50:03 +00:00
|
|
|
{ "pci-serial", QEMU_CAPS_DEVICE_PCI_SERIAL },
|
2015-07-17 11:27:44 +00:00
|
|
|
{ "gpex-pcihost", QEMU_CAPS_OBJECT_GPEX},
|
2015-06-17 17:13:28 +00:00
|
|
|
{ "ioh3420", QEMU_CAPS_DEVICE_IOH3420 },
|
2015-06-16 18:54:21 +00:00
|
|
|
{ "x3130-upstream", QEMU_CAPS_DEVICE_X3130_UPSTREAM },
|
2015-06-17 18:24:29 +00:00
|
|
|
{ "xio3130-downstream", QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM },
|
2015-09-04 14:23:46 +00:00
|
|
|
{ "rtl8139", QEMU_CAPS_DEVICE_RTL8139 },
|
2015-09-04 14:40:37 +00:00
|
|
|
{ "e1000", QEMU_CAPS_DEVICE_E1000 },
|
2015-09-01 12:38:19 +00:00
|
|
|
{ "virtio-net-pci", QEMU_CAPS_DEVICE_VIRTIO_NET },
|
|
|
|
{ "virtio-net-ccw", QEMU_CAPS_DEVICE_VIRTIO_NET },
|
|
|
|
{ "virtio-net-s390", QEMU_CAPS_DEVICE_VIRTIO_NET },
|
|
|
|
{ "virtio-net-device", QEMU_CAPS_DEVICE_VIRTIO_NET },
|
2015-11-25 08:42:32 +00:00
|
|
|
{ "virtio-gpu-pci", QEMU_CAPS_DEVICE_VIRTIO_GPU },
|
|
|
|
{ "virtio-gpu-device", QEMU_CAPS_DEVICE_VIRTIO_GPU },
|
2015-11-13 10:26:37 +00:00
|
|
|
{ "virtio-keyboard-device", QEMU_CAPS_VIRTIO_KEYBOARD },
|
|
|
|
{ "virtio-keyboard-pci", QEMU_CAPS_VIRTIO_KEYBOARD },
|
|
|
|
{ "virtio-mouse-device", QEMU_CAPS_VIRTIO_MOUSE },
|
|
|
|
{ "virtio-mouse-pci", QEMU_CAPS_VIRTIO_MOUSE },
|
|
|
|
{ "virtio-tablet-device", QEMU_CAPS_VIRTIO_TABLET },
|
|
|
|
{ "virtio-tablet-pci", QEMU_CAPS_VIRTIO_TABLET },
|
2015-11-13 14:41:20 +00:00
|
|
|
{ "virtio-input-host-device", QEMU_CAPS_VIRTIO_INPUT_HOST },
|
|
|
|
{ "virtio-input-host-pci", QEMU_CAPS_VIRTIO_INPUT_HOST },
|
2016-02-11 10:48:20 +00:00
|
|
|
{ "mptsas1068", QEMU_CAPS_SCSI_MPTSAS1068 },
|
2016-03-21 15:49:12 +00:00
|
|
|
{ "secret", QEMU_CAPS_OBJECT_SECRET },
|
2016-02-24 21:40:49 +00:00
|
|
|
{ "pxb", QEMU_CAPS_DEVICE_PXB },
|
2016-03-08 21:25:22 +00:00
|
|
|
{ "pxb-pcie", QEMU_CAPS_DEVICE_PXB_PCIE },
|
2012-09-13 17:04:24 +00:00
|
|
|
};
|
|
|
|
|
2016-01-08 10:45:06 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBalloon[] = {
|
|
|
|
{ "deflate-on-oom", QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE },
|
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "multifunction", QEMU_CAPS_PCI_MULTIFUNCTION },
|
|
|
|
{ "bootindex", QEMU_CAPS_BOOTINDEX },
|
|
|
|
{ "ioeventfd", QEMU_CAPS_VIRTIO_IOEVENTFD },
|
|
|
|
{ "event_idx", QEMU_CAPS_VIRTIO_BLK_EVENT_IDX },
|
|
|
|
{ "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI },
|
|
|
|
{ "logical_block_size", QEMU_CAPS_BLOCKIO },
|
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioNet[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "tx", QEMU_CAPS_VIRTIO_TX_ALG },
|
|
|
|
{ "event_idx", QEMU_CAPS_VIRTIO_NET_EVENT_IDX },
|
|
|
|
};
|
|
|
|
|
2016-04-20 18:43:04 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioSCSI[] = {
|
|
|
|
{ "iothread", QEMU_CAPS_VIRTIO_SCSI_IOTHREAD },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:59:32 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsPCIAssign[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "configfd", QEMU_CAPS_PCI_CONFIGFD },
|
|
|
|
{ "bootindex", QEMU_CAPS_PCI_BOOTINDEX },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:59:32 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVfioPCI[] = {
|
2013-04-17 18:16:28 +00:00
|
|
|
{ "bootindex", QEMU_CAPS_VFIO_PCI_BOOTINDEX },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:55:46 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsSCSIDisk[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "channel", QEMU_CAPS_SCSI_DISK_CHANNEL },
|
|
|
|
{ "wwn", QEMU_CAPS_SCSI_DISK_WWN },
|
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsIDEDrive[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "wwn", QEMU_CAPS_IDE_DRIVE_WWN },
|
|
|
|
};
|
|
|
|
|
2016-01-04 22:54:25 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsPiix4PM[] = {
|
2016-01-04 22:57:06 +00:00
|
|
|
{ "disable_s3", QEMU_CAPS_PIIX_DISABLE_S3 },
|
|
|
|
{ "disable_s4", QEMU_CAPS_PIIX_DISABLE_S4 },
|
2012-09-13 17:04:24 +00:00
|
|
|
};
|
|
|
|
|
2014-03-13 11:58:17 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsUSBRedir[] = {
|
2012-09-13 17:04:24 +00:00
|
|
|
{ "filter", QEMU_CAPS_USB_REDIR_FILTER },
|
2012-11-14 14:51:30 +00:00
|
|
|
{ "bootindex", QEMU_CAPS_USB_REDIR_BOOTINDEX },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:58:17 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsUSBHost[] = {
|
2012-11-14 14:51:30 +00:00
|
|
|
{ "bootindex", QEMU_CAPS_USB_HOST_BOOTINDEX },
|
2012-09-13 17:04:24 +00:00
|
|
|
};
|
|
|
|
|
2014-03-13 11:55:46 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsSCSIGeneric[] = {
|
2013-05-03 18:07:21 +00:00
|
|
|
{ "bootindex", QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:59:32 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsI440FXPCIHost[] = {
|
2013-08-12 11:48:34 +00:00
|
|
|
{ "pci-hole64-size", QEMU_CAPS_I440FX_PCI_HOLE64_SIZE },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:59:32 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsQ35PCIHost[] = {
|
2013-08-12 11:48:34 +00:00
|
|
|
{ "pci-hole64-size", QEMU_CAPS_Q35_PCI_HOLE64_SIZE },
|
|
|
|
};
|
|
|
|
|
2014-03-13 11:58:17 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsUSBStorage[] = {
|
2013-08-23 10:38:11 +00:00
|
|
|
{ "removable", QEMU_CAPS_USB_STORAGE_REMOVABLE },
|
|
|
|
};
|
|
|
|
|
2013-07-01 16:28:50 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsKVMPit[] = {
|
|
|
|
{ "lost_tick_policy", QEMU_CAPS_KVM_PIT_TICK_POLICY },
|
|
|
|
};
|
|
|
|
|
2014-11-12 12:58:33 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVGA[] = {
|
|
|
|
{ "vgamem_mb", QEMU_CAPS_VGA_VGAMEM },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVmwareSvga[] = {
|
|
|
|
{ "vgamem_mb", QEMU_CAPS_VMWARE_SVGA_VGAMEM },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsQxl[] = {
|
|
|
|
{ "vgamem_mb", QEMU_CAPS_QXL_VGAMEM },
|
2016-03-01 12:46:37 +00:00
|
|
|
{ "vram64_size_mb", QEMU_CAPS_QXL_VRAM64 },
|
2014-11-12 12:58:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsQxlVga[] = {
|
|
|
|
{ "vgamem_mb", QEMU_CAPS_QXL_VGA_VGAMEM },
|
2016-03-01 12:46:37 +00:00
|
|
|
{ "vram64_size_mb", QEMU_CAPS_QXL_VGA_VRAM64 },
|
2014-11-12 12:58:33 +00:00
|
|
|
};
|
|
|
|
|
2015-11-25 08:42:33 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioGpu[] = {
|
|
|
|
{ "virgl", QEMU_CAPS_DEVICE_VIRTIO_GPU_VIRGL },
|
|
|
|
};
|
|
|
|
|
2016-01-09 20:58:50 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsICH9[] = {
|
|
|
|
{ "disable_s3", QEMU_CAPS_ICH9_DISABLE_S3 },
|
|
|
|
{ "disable_s4", QEMU_CAPS_ICH9_DISABLE_S4 },
|
|
|
|
};
|
|
|
|
|
2016-04-24 14:52:38 +00:00
|
|
|
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsUSBNECXHCI[] = {
|
|
|
|
{ "p3", QEMU_CAPS_NEC_USB_XHCI_PORTS },
|
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
struct virQEMUCapsObjectTypeProps {
|
2012-09-13 17:04:24 +00:00
|
|
|
const char *type;
|
2013-02-01 13:48:58 +00:00
|
|
|
struct virQEMUCapsStringFlags *props;
|
2012-09-13 17:04:24 +00:00
|
|
|
size_t nprops;
|
|
|
|
};
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static struct virQEMUCapsObjectTypeProps virQEMUCapsObjectProps[] = {
|
|
|
|
{ "virtio-blk-pci", virQEMUCapsObjectPropsVirtioBlk,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBlk) },
|
|
|
|
{ "virtio-net-pci", virQEMUCapsObjectPropsVirtioNet,
|
2013-03-05 15:44:21 +00:00
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioNet) },
|
2016-04-20 18:43:04 +00:00
|
|
|
{ "virtio-scsi-pci", virQEMUCapsObjectPropsVirtioSCSI,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioSCSI) },
|
2013-03-05 15:44:21 +00:00
|
|
|
{ "virtio-blk-ccw", virQEMUCapsObjectPropsVirtioBlk,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBlk) },
|
|
|
|
{ "virtio-net-ccw", virQEMUCapsObjectPropsVirtioNet,
|
2013-02-01 13:48:58 +00:00
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioNet) },
|
2016-04-20 18:43:04 +00:00
|
|
|
{ "virtio-scsi-ccw", virQEMUCapsObjectPropsVirtioSCSI,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioSCSI) },
|
2013-02-01 13:48:58 +00:00
|
|
|
{ "virtio-blk-s390", virQEMUCapsObjectPropsVirtioBlk,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBlk) },
|
|
|
|
{ "virtio-net-s390", virQEMUCapsObjectPropsVirtioNet,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioNet) },
|
2014-03-13 11:59:32 +00:00
|
|
|
{ "pci-assign", virQEMUCapsObjectPropsPCIAssign,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsPCIAssign) },
|
|
|
|
{ "kvm-pci-assign", virQEMUCapsObjectPropsPCIAssign,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsPCIAssign) },
|
|
|
|
{ "vfio-pci", virQEMUCapsObjectPropsVfioPCI,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVfioPCI) },
|
2014-03-13 11:55:46 +00:00
|
|
|
{ "scsi-disk", virQEMUCapsObjectPropsSCSIDisk,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsSCSIDisk) },
|
2013-02-01 13:48:58 +00:00
|
|
|
{ "ide-drive", virQEMUCapsObjectPropsIDEDrive,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsIDEDrive) },
|
2016-01-04 22:54:25 +00:00
|
|
|
{ "PIIX4_PM", virQEMUCapsObjectPropsPiix4PM,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsPiix4PM) },
|
2014-03-13 11:58:17 +00:00
|
|
|
{ "usb-redir", virQEMUCapsObjectPropsUSBRedir,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsUSBRedir) },
|
|
|
|
{ "usb-host", virQEMUCapsObjectPropsUSBHost,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsUSBHost) },
|
2014-03-13 11:55:46 +00:00
|
|
|
{ "scsi-generic", virQEMUCapsObjectPropsSCSIGeneric,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsSCSIGeneric) },
|
2014-03-13 11:59:32 +00:00
|
|
|
{ "i440FX-pcihost", virQEMUCapsObjectPropsI440FXPCIHost,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsI440FXPCIHost) },
|
|
|
|
{ "q35-pcihost", virQEMUCapsObjectPropsQ35PCIHost,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsQ35PCIHost) },
|
2014-03-13 11:58:17 +00:00
|
|
|
{ "usb-storage", virQEMUCapsObjectPropsUSBStorage,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsUSBStorage) },
|
2013-07-01 16:28:50 +00:00
|
|
|
{ "kvm-pit", virQEMUCapsObjectPropsKVMPit,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsKVMPit) },
|
2014-11-12 12:58:33 +00:00
|
|
|
{ "VGA", virQEMUCapsObjectPropsVGA,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVGA) },
|
|
|
|
{ "vmware-svga", virQEMUCapsObjectPropsVmwareSvga,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVmwareSvga) },
|
|
|
|
{ "qxl", virQEMUCapsObjectPropsQxl,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsQxl) },
|
|
|
|
{ "qxl-vga", virQEMUCapsObjectPropsQxlVga,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsQxlVga) },
|
2015-11-25 08:42:33 +00:00
|
|
|
{ "virtio-gpu-pci", virQEMUCapsObjectPropsVirtioGpu,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioGpu) },
|
2016-01-09 20:58:50 +00:00
|
|
|
{ "ICH9-LPC", virQEMUCapsObjectPropsICH9,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsICH9) },
|
2016-01-08 10:45:06 +00:00
|
|
|
{ "virtio-balloon-pci", virQEMUCapsObjectPropsVirtioBalloon,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBalloon) },
|
|
|
|
{ "virtio-balloon-ccw", virQEMUCapsObjectPropsVirtioBalloon,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBalloon) },
|
|
|
|
{ "virtio-balloon-device", virQEMUCapsObjectPropsVirtioBalloon,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtioBalloon) },
|
2016-04-24 14:52:38 +00:00
|
|
|
{ "nec-usb-xhci", virQEMUCapsObjectPropsUSBNECXHCI,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectPropsUSBNECXHCI) },
|
2012-09-13 17:04:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProcessStringFlags(virQEMUCapsPtr qemuCaps,
|
|
|
|
size_t nflags,
|
|
|
|
struct virQEMUCapsStringFlags *flags,
|
|
|
|
size_t nvalues,
|
|
|
|
char *const*values)
|
2012-09-13 17:04:24 +00:00
|
|
|
{
|
|
|
|
size_t i, j;
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < nflags; i++) {
|
|
|
|
for (j = 0; j < nvalues; j++) {
|
2012-09-13 17:04:24 +00:00
|
|
|
if (STREQ(values[j], flags[i].value)) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, flags[i].flag);
|
2012-09-13 17:04:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsFreeStringList(size_t len,
|
|
|
|
char **values)
|
2012-09-13 17:04:24 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2015-05-05 10:59:56 +00:00
|
|
|
if (!values)
|
|
|
|
return;
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2012-09-13 17:04:24 +00:00
|
|
|
VIR_FREE(values[i]);
|
|
|
|
VIR_FREE(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define OBJECT_TYPE_PREFIX "name \""
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseDeviceStrObjectTypes(const char *str,
|
|
|
|
char ***types)
|
2012-09-13 17:04:24 +00:00
|
|
|
{
|
|
|
|
const char *tmp = str;
|
|
|
|
int ret = -1;
|
|
|
|
size_t ntypelist = 0;
|
|
|
|
char **typelist = NULL;
|
|
|
|
|
|
|
|
*types = NULL;
|
|
|
|
|
|
|
|
while ((tmp = strstr(tmp, OBJECT_TYPE_PREFIX))) {
|
|
|
|
char *end;
|
|
|
|
tmp += strlen(OBJECT_TYPE_PREFIX);
|
|
|
|
end = strstr(tmp, "\"");
|
|
|
|
if (!end) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed QEMU device list string, missing quote"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_EXPAND_N(typelist, ntypelist, 1) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
goto cleanup;
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(typelist[ntypelist - 1], tmp, end-tmp) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
*types = typelist;
|
|
|
|
ret = ntypelist;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-09-13 17:04:24 +00:00
|
|
|
if (ret < 0)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsFreeStringList(ntypelist, typelist);
|
2012-09-13 17:04:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseDeviceStrObjectProps(const char *str,
|
|
|
|
const char *type,
|
|
|
|
char ***props)
|
2012-09-13 17:04:24 +00:00
|
|
|
{
|
|
|
|
const char *tmp = str;
|
|
|
|
int ret = -1;
|
|
|
|
size_t nproplist = 0;
|
|
|
|
char **proplist = NULL;
|
|
|
|
|
|
|
|
VIR_DEBUG("Extract type %s", type);
|
|
|
|
*props = NULL;
|
|
|
|
|
|
|
|
while ((tmp = strchr(tmp, '\n'))) {
|
|
|
|
char *end;
|
|
|
|
tmp += 1;
|
|
|
|
|
|
|
|
if (*tmp == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (STRPREFIX(tmp, OBJECT_TYPE_PREFIX))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!STRPREFIX(tmp, type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp += strlen(type);
|
|
|
|
if (*tmp != '.')
|
|
|
|
continue;
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
end = strstr(tmp, "=");
|
|
|
|
if (!end) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed QEMU device list string, missing '='"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_EXPAND_N(proplist, nproplist, 1) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
goto cleanup;
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRNDUP(proplist[nproplist - 1], tmp, end-tmp) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
*props = proplist;
|
|
|
|
ret = nproplist;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2015-05-05 10:59:56 +00:00
|
|
|
if (ret < 0)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsFreeStringList(nproplist, proplist);
|
2012-09-13 17:04:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsParseDeviceStr(virQEMUCapsPtr qemuCaps, const char *str)
|
2012-09-13 17:04:24 +00:00
|
|
|
{
|
|
|
|
int nvalues;
|
|
|
|
char **values;
|
|
|
|
size_t i;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if ((nvalues = virQEMUCapsParseDeviceStrObjectTypes(str, &values)) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
return -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectTypes),
|
|
|
|
virQEMUCapsObjectTypes,
|
|
|
|
nvalues, values);
|
|
|
|
virQEMUCapsFreeStringList(nvalues, values);
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsObjectProps); i++) {
|
2013-02-01 13:48:58 +00:00
|
|
|
const char *type = virQEMUCapsObjectProps[i].type;
|
|
|
|
if ((nvalues = virQEMUCapsParseDeviceStrObjectProps(str,
|
|
|
|
type,
|
|
|
|
&values)) < 0)
|
2012-09-13 17:04:24 +00:00
|
|
|
return -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
virQEMUCapsObjectProps[i].nprops,
|
|
|
|
virQEMUCapsObjectProps[i].props,
|
|
|
|
nvalues, values);
|
|
|
|
virQEMUCapsFreeStringList(nvalues, values);
|
2012-09-13 17:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prefer -chardev spicevmc (detected earlier) over -device spicevmc */
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEVMC))
|
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC);
|
2012-09-13 17:04:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-13 16:09:15 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsExtractDeviceStr(const char *qemu,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
2013-01-30 20:07:03 +00:00
|
|
|
uid_t runUid, gid_t runGid)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
2011-01-13 16:09:15 +00:00
|
|
|
char *output = NULL;
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandPtr cmd;
|
2011-01-13 16:09:15 +00:00
|
|
|
int ret = -1;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-01-13 16:09:15 +00:00
|
|
|
/* Cram together all device-related queries into one invocation;
|
|
|
|
* the output format makes it possible to distinguish what we
|
2011-01-18 16:47:30 +00:00
|
|
|
* need. With qemu 0.13.0 and later, unrecognized '-device
|
|
|
|
* bogus,?' cause an error in isolation, but are silently ignored
|
2011-01-13 15:54:33 +00:00
|
|
|
* in combination with '-device ?'. Upstream qemu 0.12.x doesn't
|
2011-01-18 16:47:30 +00:00
|
|
|
* understand '-device name,?', and always exits with status 1 for
|
|
|
|
* the simpler '-device ?', so this function is really only useful
|
2011-01-13 15:54:33 +00:00
|
|
|
* if -help includes "device driver,?". */
|
2013-01-30 20:07:03 +00:00
|
|
|
cmd = virQEMUCapsProbeCommand(qemu, qemuCaps, runUid, runGid);
|
2012-04-26 13:10:22 +00:00
|
|
|
virCommandAddArgList(cmd,
|
|
|
|
"-device", "?",
|
|
|
|
"-device", "pci-assign,?",
|
|
|
|
"-device", "virtio-blk-pci,?",
|
|
|
|
"-device", "virtio-net-pci,?",
|
|
|
|
"-device", "scsi-disk,?",
|
2012-08-02 10:14:39 +00:00
|
|
|
"-device", "PIIX4_PM,?",
|
2012-08-19 15:42:44 +00:00
|
|
|
"-device", "usb-redir,?",
|
2012-09-18 02:12:11 +00:00
|
|
|
"-device", "ide-drive,?",
|
2012-11-14 14:51:30 +00:00
|
|
|
"-device", "usb-host,?",
|
2013-05-03 18:07:21 +00:00
|
|
|
"-device", "scsi-generic,?",
|
2013-08-23 10:38:11 +00:00
|
|
|
"-device", "usb-storage,?",
|
2014-11-12 12:58:33 +00:00
|
|
|
"-device", "VGA,?",
|
|
|
|
"-device", "vmware-svga,?",
|
|
|
|
"-device", "qxl,?",
|
|
|
|
"-device", "qxl-vga,?",
|
2012-04-26 13:10:22 +00:00
|
|
|
NULL);
|
2011-01-12 23:26:34 +00:00
|
|
|
/* qemu -help goes to stdout, but qemu -device ? goes to stderr. */
|
2011-01-13 16:09:15 +00:00
|
|
|
virCommandSetErrorBuffer(cmd, &output);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2011-01-12 23:26:34 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2010-12-16 15:07:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
ret = virQEMUCapsParseDeviceStr(qemuCaps, output);
|
2010-12-16 15:07:07 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-01-13 16:09:15 +00:00
|
|
|
VIR_FREE(output);
|
2011-01-12 23:26:34 +00:00
|
|
|
virCommandFree(cmd);
|
2011-01-13 16:09:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
int virQEMUCapsGetDefaultVersion(virCapsPtr caps,
|
|
|
|
virQEMUCapsCachePtr capsCache,
|
|
|
|
unsigned int *version)
|
2010-12-16 15:07:07 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr qemucaps;
|
2013-04-08 12:33:07 +00:00
|
|
|
virArch hostarch;
|
2015-04-18 00:15:25 +00:00
|
|
|
virCapsDomainDataPtr capsdata;
|
2010-12-16 15:07:07 +00:00
|
|
|
|
|
|
|
if (*version > 0)
|
|
|
|
return 0;
|
|
|
|
|
2013-04-08 12:33:07 +00:00
|
|
|
hostarch = virArchFromHost();
|
2015-04-18 00:15:25 +00:00
|
|
|
if (!(capsdata = virCapabilitiesDomainDataLookup(caps,
|
|
|
|
VIR_DOMAIN_OSTYPE_HVM, hostarch, VIR_DOMAIN_VIRT_QEMU,
|
|
|
|
NULL, NULL))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2012-12-10 22:28:09 +00:00
|
|
|
_("Cannot find suitable emulator for %s"),
|
2013-04-08 12:33:07 +00:00
|
|
|
virArchToString(hostarch));
|
2010-12-16 15:07:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-18 00:15:25 +00:00
|
|
|
qemucaps = virQEMUCapsCacheLookup(capsCache, capsdata->emulator);
|
|
|
|
VIR_FREE(capsdata);
|
|
|
|
if (!qemucaps)
|
2010-12-16 15:07:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
*version = virQEMUCapsGetVersion(qemucaps);
|
2012-08-22 14:39:54 +00:00
|
|
|
virObjectUnref(qemucaps);
|
2010-12-16 15:07:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-08 14:08:12 +00:00
|
|
|
|
|
|
|
|
2012-08-20 16:44:14 +00:00
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr
|
|
|
|
virQEMUCapsNew(void)
|
2011-02-08 14:22:39 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr qemuCaps;
|
2011-02-08 14:22:39 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsInitialize() < 0)
|
2012-08-20 16:44:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(qemuCaps = virObjectNew(virQEMUCapsClass)))
|
2012-08-20 16:44:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST)))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2011-02-08 14:22:39 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps;
|
2012-08-20 16:44:14 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-02-01 13:48:58 +00:00
|
|
|
virObjectUnref(qemuCaps);
|
2012-08-20 16:44:14 +00:00
|
|
|
return NULL;
|
2011-02-08 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
|
2012-09-11 12:42:20 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr ret = virQEMUCapsNew();
|
2012-09-11 12:42:20 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virBitmapCopy(ret->flags, qemuCaps->flags);
|
2012-09-11 12:42:20 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
ret->usedQMP = qemuCaps->usedQMP;
|
|
|
|
ret->version = qemuCaps->version;
|
|
|
|
ret->kvmVersion = qemuCaps->kvmVersion;
|
2015-02-02 10:28:30 +00:00
|
|
|
|
|
|
|
if (VIR_STRDUP(ret->package, qemuCaps->package) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
ret->arch = qemuCaps->arch;
|
2012-09-11 12:42:20 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (VIR_ALLOC_N(ret->cpuDefinitions, qemuCaps->ncpuDefinitions) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-02-01 13:48:58 +00:00
|
|
|
ret->ncpuDefinitions = qemuCaps->ncpuDefinitions;
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < qemuCaps->ncpuDefinitions; i++) {
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(ret->cpuDefinitions[i], qemuCaps->cpuDefinitions[i]) < 0)
|
|
|
|
goto error;
|
2012-09-11 12:42:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-02-01 13:48:58 +00:00
|
|
|
if (VIR_ALLOC_N(ret->machineAliases, qemuCaps->nmachineTypes) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-06-26 15:46:35 +00:00
|
|
|
if (VIR_ALLOC_N(ret->machineMaxCpus, qemuCaps->nmachineTypes) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2013-02-01 13:48:58 +00:00
|
|
|
ret->nmachineTypes = qemuCaps->nmachineTypes;
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0 ||
|
|
|
|
VIR_STRDUP(ret->machineAliases[i], qemuCaps->machineAliases[i]) < 0)
|
|
|
|
goto error;
|
2013-06-26 15:46:35 +00:00
|
|
|
ret->machineMaxCpus[i] = qemuCaps->machineMaxCpus[i];
|
2012-09-11 12:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2012-09-11 12:42:20 +00:00
|
|
|
virObjectUnref(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
void virQEMUCapsDispose(void *obj)
|
2012-08-20 16:44:14 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr qemuCaps = obj;
|
2012-08-22 10:11:28 +00:00
|
|
|
size_t i;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_FREE(qemuCaps->machineTypes[i]);
|
|
|
|
VIR_FREE(qemuCaps->machineAliases[i]);
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_FREE(qemuCaps->machineTypes);
|
|
|
|
VIR_FREE(qemuCaps->machineAliases);
|
2013-06-26 15:46:35 +00:00
|
|
|
VIR_FREE(qemuCaps->machineMaxCpus);
|
2012-08-22 10:11:28 +00:00
|
|
|
|
2014-11-13 14:25:30 +00:00
|
|
|
for (i = 0; i < qemuCaps->ncpuDefinitions; i++)
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_FREE(qemuCaps->cpuDefinitions[i]);
|
|
|
|
VIR_FREE(qemuCaps->cpuDefinitions);
|
2012-08-20 16:44:14 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virBitmapFree(qemuCaps->flags);
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2015-02-02 10:28:30 +00:00
|
|
|
VIR_FREE(qemuCaps->package);
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_FREE(qemuCaps->binary);
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
VIR_FREE(qemuCaps->gicCapabilities);
|
2012-08-20 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 14:08:12 +00:00
|
|
|
void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(virQEMUCapsPtr qemuCaps,
|
2014-06-15 16:32:56 +00:00
|
|
|
virQEMUCapsFlags flag)
|
2011-02-08 14:08:12 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
ignore_value(virBitmapSetBit(qemuCaps->flags, flag));
|
2011-02-08 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetList(virQEMUCapsPtr qemuCaps, ...)
|
2011-02-08 14:22:39 +00:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
int flag;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
va_start(list, qemuCaps);
|
2011-02-08 14:22:39 +00:00
|
|
|
while ((flag = va_arg(list, int)) < QEMU_CAPS_LAST)
|
2013-02-01 13:48:58 +00:00
|
|
|
ignore_value(virBitmapSetBit(qemuCaps->flags, flag));
|
2011-02-08 14:22:39 +00:00
|
|
|
va_end(list);
|
2011-02-08 14:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsClear(virQEMUCapsPtr qemuCaps,
|
2014-06-15 16:32:56 +00:00
|
|
|
virQEMUCapsFlags flag)
|
2011-02-08 14:08:12 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
ignore_value(virBitmapClearBit(qemuCaps->flags, flag));
|
2012-08-20 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
char *virQEMUCapsFlagsString(virQEMUCapsPtr qemuCaps)
|
2012-08-20 16:44:14 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
return virBitmapString(qemuCaps->flags);
|
2011-02-08 14:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsGet(virQEMUCapsPtr qemuCaps,
|
2014-06-15 16:32:56 +00:00
|
|
|
virQEMUCapsFlags flag)
|
2011-02-08 14:08:12 +00:00
|
|
|
{
|
2015-03-11 15:41:57 +00:00
|
|
|
return qemuCaps && virBitmapIsBitSet(qemuCaps->flags, flag);
|
2011-02-08 14:08:12 +00:00
|
|
|
}
|
2012-08-22 10:11:28 +00:00
|
|
|
|
|
|
|
|
2014-04-23 15:35:37 +00:00
|
|
|
bool virQEMUCapsHasPCIMultiBus(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
bool hasMultiBus = virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
|
|
|
|
|
|
|
|
if (hasMultiBus)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (def->os.arch == VIR_ARCH_PPC ||
|
2014-11-04 17:21:26 +00:00
|
|
|
ARCH_IS_PPC64(def->os.arch)) {
|
2014-04-23 15:35:37 +00:00
|
|
|
/*
|
|
|
|
* Usage of pci.0 naming:
|
|
|
|
*
|
|
|
|
* ref405ep: no pci
|
|
|
|
* taihu: no pci
|
|
|
|
* bamboo: 1.1.0
|
|
|
|
* mac99: 2.0.0
|
|
|
|
* g3beige: 2.0.0
|
|
|
|
* prep: 1.4.0
|
|
|
|
* pseries: 2.0.0
|
|
|
|
* mpc8544ds: forever
|
|
|
|
* virtex-m507: no pci
|
|
|
|
* ppce500: 1.6.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (qemuCaps->version >= 2000000)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (qemuCaps->version >= 1006000 &&
|
|
|
|
STREQ(def->os.machine, "ppce500"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (qemuCaps->version >= 1004000 &&
|
|
|
|
STREQ(def->os.machine, "prep"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (qemuCaps->version >= 1001000 &&
|
|
|
|
STREQ(def->os.machine, "bamboo"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (STREQ(def->os.machine, "mpc8544ds"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:27:45 +00:00
|
|
|
if (ARCH_IS_ARM(def->os.arch)) {
|
|
|
|
/* If 'virt' supports PCI, it supports multibus.
|
|
|
|
* No extra conditions here for simplicity.
|
|
|
|
*/
|
2016-05-03 08:49:40 +00:00
|
|
|
if (qemuDomainMachineIsVirt(def))
|
2015-07-17 11:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-23 15:35:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
const char *virQEMUCapsGetBinary(virQEMUCapsPtr qemuCaps)
|
2012-08-22 13:37:05 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps->binary;
|
2012-08-22 13:37:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virArch virQEMUCapsGetArch(virQEMUCapsPtr qemuCaps)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps->arch;
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
unsigned int virQEMUCapsGetVersion(virQEMUCapsPtr qemuCaps)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps->version;
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps->kvmVersion;
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-02 10:28:30 +00:00
|
|
|
const char *virQEMUCapsGetPackage(virQEMUCapsPtr qemuCaps)
|
|
|
|
{
|
|
|
|
return qemuCaps->package;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *name)
|
2012-08-22 15:28:55 +00:00
|
|
|
{
|
2013-05-20 09:23:13 +00:00
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(tmp, name) < 0)
|
2012-08-22 15:28:55 +00:00
|
|
|
return -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) {
|
2012-08-22 15:28:55 +00:00
|
|
|
VIR_FREE(tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions-1] = tmp;
|
2012-08-22 15:28:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
size_t virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
|
|
|
|
char ***names)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
2012-08-22 13:37:05 +00:00
|
|
|
if (names)
|
2013-02-01 13:48:58 +00:00
|
|
|
*names = qemuCaps->cpuDefinitions;
|
|
|
|
return qemuCaps->ncpuDefinitions;
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
size_t virQEMUCapsGetMachineTypes(virQEMUCapsPtr qemuCaps,
|
|
|
|
char ***names)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
2012-08-22 13:37:05 +00:00
|
|
|
if (names)
|
2013-02-01 13:48:58 +00:00
|
|
|
*names = qemuCaps->machineTypes;
|
|
|
|
return qemuCaps->nmachineTypes;
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
size_t *nmachines,
|
|
|
|
virCapsGuestMachinePtr **machines)
|
2012-08-22 13:37:05 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*machines = NULL;
|
2013-02-01 13:48:58 +00:00
|
|
|
*nmachines = qemuCaps->nmachineTypes;
|
2012-08-22 13:37:05 +00:00
|
|
|
|
2014-03-27 11:38:56 +00:00
|
|
|
if (*nmachines &&
|
|
|
|
VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
2012-08-22 13:37:05 +00:00
|
|
|
virCapsGuestMachinePtr mach;
|
|
|
|
if (VIR_ALLOC(mach) < 0)
|
2013-05-20 09:23:13 +00:00
|
|
|
goto error;
|
2014-08-27 18:57:08 +00:00
|
|
|
(*machines)[i] = mach;
|
2013-02-01 13:48:58 +00:00
|
|
|
if (qemuCaps->machineAliases[i]) {
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0 ||
|
|
|
|
VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
|
|
|
|
goto error;
|
2012-08-22 13:37:05 +00:00
|
|
|
} else {
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i]) < 0)
|
|
|
|
goto error;
|
2012-08-22 13:37:05 +00:00
|
|
|
}
|
2013-06-26 15:46:35 +00:00
|
|
|
mach->maxCpus = qemuCaps->machineMaxCpus[i];
|
2012-08-22 13:37:05 +00:00
|
|
|
}
|
|
|
|
|
qemu: Report all supported machine types in capabilities
Some machine types are only reported as canonical names for other
machine types, which make it a bit harder to find what machine types are
supported by a specific QEMU binary. Ideally, one would just use
/capabilities/guest/arch[@name='...']/machine/text() XPath to get a list
of all supported machine types, but it doesn't work right now.
For example, we report
<machine canonical='pc-i440fx-2.3' maxCpus='255'>pc</machine>
in guest capabilities, but the corresponding
<machine maxCpus='255'>pc-i440fx-2.3</machine>
is missing.
This is a result of QMP probing. With "-machine ?" parsing QEMU sends
us two lines:
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-2.3)
pc-i440fx-2.3 Standard PC (i440FX + PIIX, 1996) (default)
while query-machines QMP command reports both in the same entry:
{"name": "pc-i440fx-2.3", "is-default": true, "cpu-max": 255, "alias": "pc"}
Let's make sure we always report separate <machine/> for both the
canonical name and its alias and using the canonical name as the default
machine type (i.e., inserting it before its alias) in case is-default is
true.
https://bugzilla.redhat.com/show_bug.cgi?id=1229666
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-06-12 12:36:51 +00:00
|
|
|
/* Make sure all canonical machine types also have their own entry so that
|
|
|
|
* /capabilities/guest/arch[@name='...']/machine/text() XPath selects all
|
|
|
|
* supported machine types.
|
|
|
|
*/
|
|
|
|
i = 0;
|
|
|
|
while (i < *nmachines) {
|
|
|
|
size_t j;
|
|
|
|
bool found = false;
|
|
|
|
virCapsGuestMachinePtr machine = (*machines)[i];
|
|
|
|
|
|
|
|
if (!machine->canonical) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < *nmachines; j++) {
|
|
|
|
if (STREQ(machine->canonical, (*machines)[j]->name)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
virCapsGuestMachinePtr mach;
|
|
|
|
if (VIR_ALLOC(mach) < 0)
|
|
|
|
goto error;
|
|
|
|
if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
|
|
|
|
VIR_FREE(mach);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (VIR_STRDUP(mach->name, machine->canonical) < 0)
|
|
|
|
goto error;
|
|
|
|
mach->maxCpus = machine->maxCpus;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2012-08-22 13:37:05 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2012-08-22 13:37:05 +00:00
|
|
|
virCapabilitiesFreeMachines(*machines, *nmachines);
|
|
|
|
*nmachines = 0;
|
|
|
|
*machines = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-22 10:11:28 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *name)
|
2012-08-22 10:11:28 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2012-11-01 11:43:03 +00:00
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!qemuCaps->machineAliases[i])
|
2012-08-22 10:11:28 +00:00
|
|
|
continue;
|
2013-02-01 13:48:58 +00:00
|
|
|
if (STREQ(qemuCaps->machineAliases[i], name))
|
|
|
|
return qemuCaps->machineTypes[i];
|
2012-08-22 10:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2012-09-10 10:47:56 +00:00
|
|
|
|
|
|
|
|
2013-06-26 15:46:35 +00:00
|
|
|
int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
|
|
|
if (!qemuCaps->machineMaxCpus[i])
|
|
|
|
continue;
|
|
|
|
if (STREQ(qemuCaps->machineTypes[i], name))
|
|
|
|
return qemuCaps->machineMaxCpus[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 08:50:34 +00:00
|
|
|
/**
|
|
|
|
* virQEMUCapsSetGICCapabilities:
|
|
|
|
* @qemuCaps: QEMU capabilities
|
|
|
|
* @capabilities: GIC capabilities
|
|
|
|
* @ncapabilities: number of GIC capabilities
|
|
|
|
*
|
|
|
|
* Set the GIC capabilities for @qemuCaps.
|
|
|
|
*
|
|
|
|
* The ownership of @capabilities is taken away from the caller, ie. this
|
|
|
|
* function will not make a copy of @capabilities, so releasing that memory
|
|
|
|
* after it's been called is a bug.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps,
|
|
|
|
virGICCapability *capabilities,
|
|
|
|
size_t ncapabilities)
|
|
|
|
{
|
|
|
|
VIR_FREE(qemuCaps->gicCapabilities);
|
|
|
|
|
|
|
|
qemuCaps->gicCapabilities = capabilities;
|
|
|
|
qemuCaps->ngicCapabilities = ncapabilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-13 14:54:02 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPCommands(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-09-13 14:54:02 +00:00
|
|
|
{
|
|
|
|
char **commands = NULL;
|
|
|
|
int ncommands;
|
|
|
|
|
|
|
|
if ((ncommands = qemuMonitorGetCommands(mon, &commands)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-06-19 08:00:10 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsCommands),
|
|
|
|
virQEMUCapsCommands,
|
|
|
|
ncommands, commands);
|
|
|
|
virQEMUCapsFreeStringList(ncommands, commands);
|
2012-09-13 14:54:02 +00:00
|
|
|
|
2013-01-29 16:52:17 +00:00
|
|
|
/* QMP add-fd was introduced in 1.2, but did not support
|
|
|
|
* management control of set numbering, and did not have a
|
|
|
|
* counterpart -add-fd command line option. We require the
|
|
|
|
* add-fd features from 1.3 or later. */
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ADD_FD)) {
|
2013-01-29 16:52:17 +00:00
|
|
|
int fd = open("/dev/null", O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unable to probe for add-fd"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (qemuMonitorAddFd(mon, 0, fd, "/dev/null") < 0)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_ADD_FD);
|
2013-01-29 16:52:17 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
}
|
|
|
|
|
2014-06-17 03:42:49 +00:00
|
|
|
/* Probe for active commit of qemu 2.1 (for now, we are choosing
|
|
|
|
* to ignore the fact that qemu 2.0 can also do active commit) */
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCK_COMMIT) &&
|
|
|
|
qemuMonitorSupportsActiveCommit(mon))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_ACTIVE_COMMIT);
|
|
|
|
|
2012-09-13 14:54:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPEvents(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-09-13 14:54:02 +00:00
|
|
|
{
|
|
|
|
char **events = NULL;
|
|
|
|
int nevents;
|
|
|
|
|
|
|
|
if ((nevents = qemuMonitorGetEvents(mon, &events)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-06-19 07:24:54 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsEvents),
|
|
|
|
virQEMUCapsEvents,
|
|
|
|
nevents, events);
|
|
|
|
virQEMUCapsFreeStringList(nevents, events);
|
2012-09-13 14:54:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPObjects(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
|
|
|
int nvalues;
|
|
|
|
char **values;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if ((nvalues = qemuMonitorGetObjectTypes(mon, &values)) < 0)
|
|
|
|
return -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsObjectTypes),
|
|
|
|
virQEMUCapsObjectTypes,
|
|
|
|
nvalues, values);
|
|
|
|
virQEMUCapsFreeStringList(nvalues, values);
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsObjectProps); i++) {
|
2013-02-01 13:48:58 +00:00
|
|
|
const char *type = virQEMUCapsObjectProps[i].type;
|
2012-08-22 17:05:08 +00:00
|
|
|
if ((nvalues = qemuMonitorGetObjectProps(mon,
|
|
|
|
type,
|
|
|
|
&values)) < 0)
|
|
|
|
return -1;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
virQEMUCapsObjectProps[i].nprops,
|
|
|
|
virQEMUCapsObjectProps[i].props,
|
|
|
|
nvalues, values);
|
|
|
|
virQEMUCapsFreeStringList(nvalues, values);
|
2012-08-22 17:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prefer -chardev spicevmc (detected earlier) over -device spicevmc */
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEVMC))
|
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC);
|
2013-01-04 08:47:55 +00:00
|
|
|
/* If qemu supports newer -device qxl it supports -vga qxl as well */
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QXL))
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VGA_QXL);
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
|
|
|
qemuMonitorMachineInfoPtr *machines = NULL;
|
|
|
|
int nmachines = 0;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2012-11-30 18:22:42 +00:00
|
|
|
size_t defIdx = 0;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
if ((nmachines = qemuMonitorGetMachines(mon, &machines)) < 0)
|
2014-09-04 21:15:51 +00:00
|
|
|
return -1;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(qemuCaps->machineTypes, nmachines) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(qemuCaps->machineAliases, nmachines) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(qemuCaps->machineMaxCpus, nmachines) < 0)
|
2013-06-26 15:46:35 +00:00
|
|
|
goto cleanup;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < nmachines; i++) {
|
2013-11-06 07:31:24 +00:00
|
|
|
if (STREQ(machines[i]->name, "none"))
|
|
|
|
continue;
|
2013-11-06 07:30:16 +00:00
|
|
|
qemuCaps->nmachineTypes++;
|
|
|
|
if (VIR_STRDUP(qemuCaps->machineAliases[qemuCaps->nmachineTypes -1],
|
|
|
|
machines[i]->alias) < 0 ||
|
|
|
|
VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1],
|
|
|
|
machines[i]->name) < 0)
|
2012-12-07 16:30:34 +00:00
|
|
|
goto cleanup;
|
2012-11-30 18:22:42 +00:00
|
|
|
if (machines[i]->isDefault)
|
2013-12-17 08:33:19 +00:00
|
|
|
defIdx = qemuCaps->nmachineTypes - 1;
|
2013-11-06 07:30:16 +00:00
|
|
|
qemuCaps->machineMaxCpus[qemuCaps->nmachineTypes - 1] =
|
|
|
|
machines[i]->maxCpus;
|
2012-08-22 17:05:08 +00:00
|
|
|
}
|
2012-11-30 18:22:42 +00:00
|
|
|
|
|
|
|
if (defIdx)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < nmachines; i++)
|
2012-08-22 17:05:08 +00:00
|
|
|
qemuMonitorMachineInfoFree(machines[i]);
|
|
|
|
VIR_FREE(machines);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
|
|
|
int ncpuDefinitions;
|
|
|
|
char **cpuDefinitions;
|
|
|
|
|
|
|
|
if ((ncpuDefinitions = qemuMonitorGetCPUDefinitions(mon, &cpuDefinitions)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->ncpuDefinitions = ncpuDefinitions;
|
|
|
|
qemuCaps->cpuDefinitions = cpuDefinitions;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 20:55:45 +00:00
|
|
|
struct tpmTypeToCaps {
|
|
|
|
int type;
|
2014-06-15 16:32:56 +00:00
|
|
|
virQEMUCapsFlags caps;
|
2013-04-12 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tpmTypeToCaps virQEMUCapsTPMTypesToCaps[] = {
|
|
|
|
{
|
|
|
|
.type = VIR_DOMAIN_TPM_TYPE_PASSTHROUGH,
|
|
|
|
.caps = QEMU_CAPS_DEVICE_TPM_PASSTHROUGH,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct tpmTypeToCaps virQEMUCapsTPMModelsToCaps[] = {
|
|
|
|
{
|
|
|
|
.type = VIR_DOMAIN_TPM_MODEL_TIS,
|
|
|
|
.caps = QEMU_CAPS_DEVICE_TPM_TIS,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virQEMUCapsProbeQMPTPM(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int nentries;
|
|
|
|
size_t i;
|
2013-04-12 20:55:45 +00:00
|
|
|
char **entries = NULL;
|
2013-04-15 20:46:53 +00:00
|
|
|
|
2013-04-12 20:55:45 +00:00
|
|
|
if ((nentries = qemuMonitorGetTPMModels(mon, &entries)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nentries > 0) {
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsTPMModelsToCaps); i++) {
|
|
|
|
const char *needle = virDomainTPMModelTypeToString(
|
|
|
|
virQEMUCapsTPMModelsToCaps[i].type);
|
|
|
|
if (virStringArrayHasString(entries, needle))
|
|
|
|
virQEMUCapsSet(qemuCaps,
|
|
|
|
virQEMUCapsTPMModelsToCaps[i].caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virStringFreeList(entries);
|
|
|
|
|
|
|
|
if ((nentries = qemuMonitorGetTPMTypes(mon, &entries)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nentries > 0) {
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsTPMTypesToCaps); i++) {
|
|
|
|
const char *needle = virDomainTPMBackendTypeToString(
|
|
|
|
virQEMUCapsTPMTypesToCaps[i].type);
|
|
|
|
if (virStringArrayHasString(entries, needle))
|
|
|
|
virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virStringFreeList(entries);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsProbeQMPKVMState(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
{
|
|
|
|
bool enabled = false;
|
|
|
|
bool present = false;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (qemuMonitorGetKVMState(mon, &enabled, &present) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* The QEMU_CAPS_KVM flag was initially set according to the QEMU
|
2013-01-25 10:46:49 +00:00
|
|
|
* reporting the recognition of 'query-kvm' QMP command. That merely
|
2014-04-20 20:07:46 +00:00
|
|
|
* indicates existence of the command though, not whether KVM support
|
2013-01-25 10:46:49 +00:00
|
|
|
* is actually available, nor whether it is enabled by default.
|
|
|
|
*
|
|
|
|
* If it is not present we need to clear the flag, and if it is
|
|
|
|
* not enabled by default we need to change the flag.
|
|
|
|
*/
|
|
|
|
if (!present) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_KVM);
|
2013-01-25 10:46:49 +00:00
|
|
|
} else if (!enabled) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_KVM);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_ENABLE_KVM);
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-14 05:25:49 +00:00
|
|
|
struct virQEMUCapsCommandLineProps {
|
|
|
|
const char *option;
|
|
|
|
const char *param;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
|
|
|
|
{ "machine", "mem-merge", QEMU_CAPS_MEM_MERGE },
|
2015-04-02 16:43:47 +00:00
|
|
|
{ "machine", "vmport", QEMU_CAPS_MACHINE_VMPORT_OPT },
|
2013-05-14 12:44:54 +00:00
|
|
|
{ "drive", "discard", QEMU_CAPS_DRIVE_DISCARD },
|
2013-05-16 20:01:05 +00:00
|
|
|
{ "realtime", "mlock", QEMU_CAPS_MLOCK },
|
qemu: add "-boot strict" to commandline whenever possible
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=888635
(which was already closed as CANTFIX because the qemu "-boot strict"
commandline option wasn't available at the time).
Problem: you couldn't have a domain that used PXE to boot, but also
had an un-bootable disk device *even if that disk wasn't listed in the
boot order*, because if PXE timed out (e.g. due to the bridge
forwarding delay), the BIOS would move on to the next target, which
would be the unbootable disk device (again - even though it wasn't
given a boot order), and get stuck at a "BOOT DISK FAILURE, PRESS ANY
KEY" message until a user intervened.
The solution available since sometime around QEMU 1.5, is to add
"-boot strict=on" to *every* qemu command. When this is done, if any
devices have a boot order specified, then QEMU will *only* attempt to
boot from those devices that have an explicit boot order, ignoring the
rest.
2013-12-02 12:07:12 +00:00
|
|
|
{ "boot-opts", "strict", QEMU_CAPS_BOOT_STRICT },
|
2013-12-13 13:51:24 +00:00
|
|
|
{ "boot-opts", "reboot-timeout", QEMU_CAPS_REBOOT_TIMEOUT },
|
2014-08-22 11:42:46 +00:00
|
|
|
{ "boot-opts", "splash-time", QEMU_CAPS_SPLASH_TIMEOUT },
|
2014-01-16 16:11:14 +00:00
|
|
|
{ "spice", "disable-agent-file-xfer", QEMU_CAPS_SPICE_FILE_XFER_DISABLE },
|
2014-04-09 13:23:45 +00:00
|
|
|
{ "msg", "timestamp", QEMU_CAPS_MSG_TIMESTAMP },
|
2014-06-17 11:43:19 +00:00
|
|
|
{ "numa", NULL, QEMU_CAPS_NUMA },
|
2014-10-29 12:16:01 +00:00
|
|
|
{ "drive", "throttling.bps-total-max", QEMU_CAPS_DRIVE_IOTUNE_MAX},
|
2015-04-27 21:57:29 +00:00
|
|
|
{ "machine", "aes-key-wrap", QEMU_CAPS_AES_KEY_WRAP },
|
|
|
|
{ "machine", "dea-key-wrap", QEMU_CAPS_DEA_KEY_WRAP },
|
2015-12-24 14:27:55 +00:00
|
|
|
{ "chardev", "append", QEMU_CAPS_CHARDEV_FILE_APPEND },
|
2016-02-19 14:30:15 +00:00
|
|
|
{ "spice", "gl", QEMU_CAPS_SPICE_GL },
|
2016-02-23 11:56:34 +00:00
|
|
|
{ "chardev", "logfile", QEMU_CAPS_CHARDEV_LOGFILE },
|
2016-03-10 19:46:38 +00:00
|
|
|
{ "name", "debug-threads", QEMU_CAPS_NAME_DEBUG_THREADS },
|
2016-04-22 22:39:09 +00:00
|
|
|
{ "name", "guest", QEMU_CAPS_NAME_GUEST },
|
2013-05-14 05:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
2014-06-17 11:41:16 +00:00
|
|
|
bool found = false;
|
2013-05-14 05:25:49 +00:00
|
|
|
int nvalues;
|
|
|
|
char **values;
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsCommandLine); i++) {
|
|
|
|
if ((nvalues = qemuMonitorGetCommandLineOptionParameters(mon,
|
|
|
|
virQEMUCapsCommandLine[i].option,
|
2014-06-17 11:41:16 +00:00
|
|
|
&values,
|
|
|
|
&found)) < 0)
|
2013-05-14 05:25:49 +00:00
|
|
|
return -1;
|
2014-06-17 11:41:16 +00:00
|
|
|
|
|
|
|
if (found && !virQEMUCapsCommandLine[i].param)
|
|
|
|
virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag);
|
|
|
|
|
2013-05-14 05:25:49 +00:00
|
|
|
for (j = 0; j < nvalues; j++) {
|
2014-06-17 11:41:16 +00:00
|
|
|
if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, values[j])) {
|
2013-05-14 05:25:49 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virStringFreeList(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
static int
|
|
|
|
virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
char **caps = NULL;
|
|
|
|
int ncaps;
|
|
|
|
|
|
|
|
if ((ncaps = qemuMonitorGetMigrationCapabilities(mon, &caps)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsMigration),
|
|
|
|
virQEMUCapsMigration,
|
|
|
|
ncaps, caps);
|
|
|
|
virQEMUCapsFreeStringList(ncaps, caps);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-08 17:24:18 +00:00
|
|
|
/**
|
|
|
|
* virQEMUCapsProbeQMPGICCapabilities:
|
|
|
|
* @qemuCaps: QEMU binary capabilities
|
|
|
|
* @mon: QEMU monitor
|
|
|
|
*
|
|
|
|
* Use @mon to obtain information about the GIC capabilities for the
|
|
|
|
* corresponding QEMU binary, and store them in @qemuCaps.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, <0 on failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virQEMUCapsProbeQMPGICCapabilities(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virGICCapability *caps = NULL;
|
|
|
|
int ncaps;
|
|
|
|
|
|
|
|
if ((ncaps = qemuMonitorGetGICCapabilities(mon, &caps)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-10 08:50:34 +00:00
|
|
|
virQEMUCapsSetGICCapabilities(qemuCaps, caps, ncaps);
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
2012-09-13 14:54:02 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_DEBUG("qemuCaps=%p mon=%p", qemuCaps, mon);
|
2012-09-13 14:54:02 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (qemuCaps->usedQMP)
|
2012-08-22 17:05:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0)
|
2012-09-13 14:54:02 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0)
|
2012-09-13 14:54:02 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
/*
|
|
|
|
* Parsing a doc that looks like
|
|
|
|
*
|
|
|
|
* <qemuCaps>
|
|
|
|
* <qemuctime>234235253</qemuctime>
|
|
|
|
* <selfctime>234235253</selfctime>
|
2015-05-23 14:19:20 +00:00
|
|
|
* <selfvers>1002016</selfvers>
|
2014-03-05 16:51:59 +00:00
|
|
|
* <usedQMP/>
|
|
|
|
* <flag name='foo'/>
|
|
|
|
* <flag name='bar'/>
|
|
|
|
* ...
|
|
|
|
* <cpu name="pentium3"/>
|
|
|
|
* ...
|
|
|
|
* <machine name="pc-1.0" alias="pc" maxCpus="4"/>
|
|
|
|
* ...
|
|
|
|
* </qemuCaps>
|
|
|
|
*/
|
2016-04-28 13:01:02 +00:00
|
|
|
int
|
2014-03-05 16:51:59 +00:00
|
|
|
virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename,
|
2015-05-23 14:19:20 +00:00
|
|
|
time_t *qemuctime, time_t *selfctime,
|
|
|
|
unsigned long *selfvers)
|
2014-03-05 16:51:59 +00:00
|
|
|
{
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
int n;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
2014-03-19 16:13:19 +00:00
|
|
|
char *str = NULL;
|
2014-03-05 16:51:59 +00:00
|
|
|
long long int l;
|
2015-05-23 14:19:20 +00:00
|
|
|
unsigned long lu;
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
if (!(doc = virXMLParseFile(filename)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(ctxt = xmlXPathNewContext(doc))) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->node = xmlDocGetRootElement(doc);
|
|
|
|
|
|
|
|
if (STRNEQ((const char *)ctxt->node->name, "qemuCaps")) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unexpected root element <%s>, "
|
|
|
|
"expecting <qemuCaps>"),
|
|
|
|
ctxt->node->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXPathLongLong("string(./qemuctime)", ctxt, &l) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing qemuctime in QEMU capabilities XML"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*qemuctime = (time_t)l;
|
|
|
|
|
|
|
|
if (virXPathLongLong("string(./selfctime)", ctxt, &l) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing selfctime in QEMU capabilities XML"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*selfctime = (time_t)l;
|
|
|
|
|
2015-05-23 14:19:20 +00:00
|
|
|
*selfvers = 0;
|
|
|
|
if (virXPathULong("string(./selfvers)", ctxt, &lu) == 0)
|
|
|
|
*selfvers = lu;
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->usedQMP = virXPathBoolean("count(./usedQMP) > 0",
|
|
|
|
ctxt) > 0;
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./flag", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to parse qemu capabilities flags"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Got flags %d", n);
|
2016-02-22 10:04:38 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
int flag;
|
|
|
|
if (!(str = virXMLPropString(nodes[i], "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing flag name in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
flag = virQEMUCapsTypeFromString(str);
|
|
|
|
if (flag < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown qemu capabilities flag %s"), str);
|
|
|
|
goto cleanup;
|
2014-03-05 16:51:59 +00:00
|
|
|
}
|
2016-02-22 10:04:38 +00:00
|
|
|
VIR_FREE(str);
|
|
|
|
virQEMUCapsSet(qemuCaps, flag);
|
2014-03-05 16:51:59 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
|
|
|
|
if (virXPathUInt("string(./version)", ctxt, &qemuCaps->version) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing version in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXPathUInt("string(./kvmVersion)", ctxt, &qemuCaps->kvmVersion) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing version in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-02 10:28:30 +00:00
|
|
|
/* Don't check for NULL, since it is optional and thus may be missing */
|
|
|
|
qemuCaps->package = virXPathString("string(./package)", ctxt);
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
if (!(str = virXPathString("string(./arch)", ctxt))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing arch in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!(qemuCaps->arch = virArchFromString(str))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown arch %s in QEMU capabilities cache"), str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-19 16:13:19 +00:00
|
|
|
VIR_FREE(str);
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./cpu", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to parse qemu capabilities cpus"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
qemuCaps->ncpuDefinitions = n;
|
|
|
|
if (VIR_ALLOC_N(qemuCaps->cpuDefinitions,
|
|
|
|
qemuCaps->ncpuDefinitions) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-03-19 16:13:19 +00:00
|
|
|
if (!(qemuCaps->cpuDefinitions[i] = virXMLPropString(nodes[i], "name"))) {
|
2014-03-05 16:51:59 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing cpu name in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./machine", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to parse qemu capabilities machines"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
qemuCaps->nmachineTypes = n;
|
|
|
|
if (VIR_ALLOC_N(qemuCaps->machineTypes,
|
|
|
|
qemuCaps->nmachineTypes) < 0 ||
|
|
|
|
VIR_ALLOC_N(qemuCaps->machineAliases,
|
|
|
|
qemuCaps->nmachineTypes) < 0 ||
|
|
|
|
VIR_ALLOC_N(qemuCaps->machineMaxCpus,
|
|
|
|
qemuCaps->nmachineTypes) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-03-19 16:13:19 +00:00
|
|
|
if (!(qemuCaps->machineTypes[i] = virXMLPropString(nodes[i], "name"))) {
|
2014-03-05 16:51:59 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing machine name in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
qemuCaps->machineAliases[i] = virXMLPropString(nodes[i], "alias");
|
|
|
|
|
|
|
|
str = virXMLPropString(nodes[i], "maxCpus");
|
|
|
|
if (str &&
|
|
|
|
virStrToLong_ui(str, NULL, 10, &(qemuCaps->machineMaxCpus[i])) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed machine cpu count in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-19 16:13:19 +00:00
|
|
|
VIR_FREE(str);
|
2014-03-05 16:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
|
2016-03-10 16:59:51 +00:00
|
|
|
if ((n = virXPathNodeSet("./gic", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to parse qemu capabilities gic"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
unsigned int uintValue;
|
|
|
|
bool boolValue;
|
|
|
|
|
|
|
|
qemuCaps->ngicCapabilities = n;
|
|
|
|
if (VIR_ALLOC_N(qemuCaps->gicCapabilities, n) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
virGICCapabilityPtr cap = &qemuCaps->gicCapabilities[i];
|
|
|
|
|
|
|
|
if (!(str = virXMLPropString(nodes[i], "version"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing GIC version "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virStrToLong_ui(str, NULL, 10, &uintValue) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed GIC version "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
cap->version = uintValue;
|
|
|
|
VIR_FREE(str);
|
|
|
|
|
|
|
|
if (!(str = virXMLPropString(nodes[i], "kernel"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing in-kernel GIC information "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!(boolValue = STREQ(str, "yes")) && STRNEQ(str, "no")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed in-kernel GIC information "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (boolValue)
|
|
|
|
cap->implementation |= VIR_GIC_IMPLEMENTATION_KERNEL;
|
|
|
|
VIR_FREE(str);
|
|
|
|
|
|
|
|
if (!(str = virXMLPropString(nodes[i], "emulated"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing emulated GIC information "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!(boolValue = STREQ(str, "yes")) && STRNEQ(str, "no")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed emulated GIC information "
|
|
|
|
"in QEMU capabilities cache"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (boolValue)
|
|
|
|
cap->implementation |= VIR_GIC_IMPLEMENTATION_EMULATED;
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2014-03-19 16:13:19 +00:00
|
|
|
VIR_FREE(str);
|
2014-03-05 16:51:59 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-28 13:01:02 +00:00
|
|
|
char *
|
2016-04-28 12:59:15 +00:00
|
|
|
virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
|
|
|
|
time_t selfCTime,
|
|
|
|
unsigned long selfVersion)
|
2014-03-05 16:51:59 +00:00
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2016-04-28 12:59:15 +00:00
|
|
|
char *ret = NULL;
|
2014-03-05 16:51:59 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "<qemuCaps>\n");
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2014-03-05 16:51:59 +00:00
|
|
|
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<qemuctime>%llu</qemuctime>\n",
|
2016-04-28 12:59:15 +00:00
|
|
|
(long long) qemuCaps->ctime);
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<selfctime>%llu</selfctime>\n",
|
2016-04-28 12:59:15 +00:00
|
|
|
(long long) selfCTime);
|
2015-05-23 14:19:20 +00:00
|
|
|
virBufferAsprintf(&buf, "<selfvers>%lu</selfvers>\n",
|
2016-04-28 12:59:15 +00:00
|
|
|
(unsigned long) selfVersion);
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
if (qemuCaps->usedQMP)
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAddLit(&buf, "<usedQMP/>\n");
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
for (i = 0; i < QEMU_CAPS_LAST; i++) {
|
|
|
|
if (virQEMUCapsGet(qemuCaps, i)) {
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<flag name='%s'/>\n",
|
2014-03-05 16:51:59 +00:00
|
|
|
virQEMUCapsTypeToString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<version>%d</version>\n",
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->version);
|
|
|
|
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<kvmVersion>%d</kvmVersion>\n",
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->kvmVersion);
|
|
|
|
|
2015-02-02 10:28:30 +00:00
|
|
|
if (qemuCaps->package)
|
|
|
|
virBufferAsprintf(&buf, "<package>%s</package>\n",
|
|
|
|
qemuCaps->package);
|
|
|
|
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAsprintf(&buf, "<arch>%s</arch>\n",
|
2014-03-05 16:51:59 +00:00
|
|
|
virArchToString(qemuCaps->arch));
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->ncpuDefinitions; i++) {
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferEscapeString(&buf, "<cpu name='%s'/>\n",
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->cpuDefinitions[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferEscapeString(&buf, "<machine name='%s'",
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->machineTypes[i]);
|
|
|
|
if (qemuCaps->machineAliases[i])
|
|
|
|
virBufferEscapeString(&buf, " alias='%s'",
|
|
|
|
qemuCaps->machineAliases[i]);
|
|
|
|
virBufferAsprintf(&buf, " maxCpus='%u'/>\n",
|
|
|
|
qemuCaps->machineMaxCpus[i]);
|
|
|
|
}
|
|
|
|
|
2016-03-10 16:59:51 +00:00
|
|
|
for (i = 0; i < qemuCaps->ngicCapabilities; i++) {
|
|
|
|
virGICCapabilityPtr cap;
|
|
|
|
bool kernel;
|
|
|
|
bool emulated;
|
|
|
|
|
|
|
|
cap = &qemuCaps->gicCapabilities[i];
|
|
|
|
kernel = (cap->implementation & VIR_GIC_IMPLEMENTATION_KERNEL);
|
|
|
|
emulated = (cap->implementation & VIR_GIC_IMPLEMENTATION_EMULATED);
|
|
|
|
|
|
|
|
virBufferAsprintf(&buf,
|
|
|
|
"<gic version='%d' kernel='%s' emulated='%s'/>\n",
|
|
|
|
cap->version,
|
|
|
|
kernel ? "yes" : "no",
|
|
|
|
emulated ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2014-03-13 00:35:01 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
2014-03-05 16:51:59 +00:00
|
|
|
virBufferAddLit(&buf, "</qemuCaps>\n");
|
|
|
|
|
2016-04-28 12:59:15 +00:00
|
|
|
if (virBufferCheckError(&buf) == 0)
|
|
|
|
ret = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename)
|
|
|
|
{
|
|
|
|
char *xml = NULL;
|
|
|
|
int ret = -1;
|
2014-03-05 16:51:59 +00:00
|
|
|
|
2016-04-28 12:59:15 +00:00
|
|
|
xml = virQEMUCapsFormatCache(qemuCaps,
|
|
|
|
virGetSelfLastChanged(),
|
|
|
|
LIBVIR_VERSION_NUMBER);
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
if (virFileWriteStr(filename, xml, 0600) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to save '%s' for '%s'"),
|
|
|
|
filename, qemuCaps->binary);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Saved caps '%s' for '%s' with (%lld, %lld)",
|
|
|
|
filename, qemuCaps->binary,
|
|
|
|
(long long)qemuCaps->ctime,
|
|
|
|
(long long)virGetSelfLastChanged());
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virQEMUCapsRememberCached(virQEMUCapsPtr qemuCaps, const char *cacheDir)
|
|
|
|
{
|
|
|
|
char *capsdir = NULL;
|
|
|
|
char *capsfile = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
char *binaryhash = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256,
|
|
|
|
qemuCaps->binary,
|
|
|
|
&binaryhash) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&capsfile, "%s/%s.xml", capsdir, binaryhash) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virFileMakePath(capsdir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create directory '%s'"),
|
|
|
|
capsdir);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virQEMUCapsSaveCache(qemuCaps, capsfile) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(binaryhash);
|
|
|
|
VIR_FREE(capsfile);
|
|
|
|
VIR_FREE(capsdir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virQEMUCapsReset(virQEMUCapsPtr qemuCaps)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
virBitmapClearAll(qemuCaps->flags);
|
|
|
|
qemuCaps->version = qemuCaps->kvmVersion = 0;
|
2015-02-02 10:28:30 +00:00
|
|
|
VIR_FREE(qemuCaps->package);
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->arch = VIR_ARCH_NONE;
|
|
|
|
qemuCaps->usedQMP = false;
|
|
|
|
|
2014-11-13 14:25:30 +00:00
|
|
|
for (i = 0; i < qemuCaps->ncpuDefinitions; i++)
|
2014-03-05 16:51:59 +00:00
|
|
|
VIR_FREE(qemuCaps->cpuDefinitions[i]);
|
|
|
|
VIR_FREE(qemuCaps->cpuDefinitions);
|
|
|
|
qemuCaps->ncpuDefinitions = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
|
|
|
VIR_FREE(qemuCaps->machineTypes[i]);
|
|
|
|
VIR_FREE(qemuCaps->machineAliases[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(qemuCaps->machineTypes);
|
|
|
|
VIR_FREE(qemuCaps->machineAliases);
|
2014-03-19 16:13:19 +00:00
|
|
|
VIR_FREE(qemuCaps->machineMaxCpus);
|
2014-03-05 16:51:59 +00:00
|
|
|
qemuCaps->nmachineTypes = 0;
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
VIR_FREE(qemuCaps->gicCapabilities);
|
|
|
|
qemuCaps->ngicCapabilities = 0;
|
2014-03-05 16:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virQEMUCapsInitCached(virQEMUCapsPtr qemuCaps, const char *cacheDir)
|
|
|
|
{
|
|
|
|
char *capsdir = NULL;
|
|
|
|
char *capsfile = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
char *binaryhash = NULL;
|
|
|
|
struct stat sb;
|
|
|
|
time_t qemuctime;
|
|
|
|
time_t selfctime;
|
2015-05-23 14:19:20 +00:00
|
|
|
unsigned long selfvers;
|
2014-03-05 16:51:59 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256,
|
|
|
|
qemuCaps->binary,
|
|
|
|
&binaryhash) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&capsfile, "%s/%s.xml", capsdir, binaryhash) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virFileMakePath(capsdir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create directory '%s'"),
|
|
|
|
capsdir);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(capsfile, &sb) < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
VIR_DEBUG("No cached capabilities '%s' for '%s'",
|
|
|
|
capsfile, qemuCaps->binary);
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to access cache '%s' for '%s'"),
|
|
|
|
capsfile, qemuCaps->binary);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-05-23 14:19:20 +00:00
|
|
|
if (virQEMUCapsLoadCache(qemuCaps, capsfile, &qemuctime, &selfctime,
|
|
|
|
&selfvers) < 0) {
|
2014-03-05 16:51:59 +00:00
|
|
|
VIR_WARN("Failed to load cached caps from '%s' for '%s': %s",
|
2016-03-23 18:31:50 +00:00
|
|
|
capsfile, qemuCaps->binary, virGetLastErrorMessage());
|
2014-03-05 16:51:59 +00:00
|
|
|
virResetLastError();
|
|
|
|
ret = 0;
|
|
|
|
virQEMUCapsReset(qemuCaps);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-05-20 12:05:17 +00:00
|
|
|
/* Discard cache if QEMU binary or libvirtd changed */
|
2014-03-05 16:51:59 +00:00
|
|
|
if (qemuctime != qemuCaps->ctime ||
|
2015-05-23 14:19:20 +00:00
|
|
|
selfctime != virGetSelfLastChanged() ||
|
|
|
|
selfvers != LIBVIR_VERSION_NUMBER) {
|
2014-03-05 16:51:59 +00:00
|
|
|
VIR_DEBUG("Outdated cached capabilities '%s' for '%s' "
|
2015-05-23 14:19:20 +00:00
|
|
|
"(%lld vs %lld, %lld vs %lld, %lu vs %lu)",
|
2014-03-05 16:51:59 +00:00
|
|
|
capsfile, qemuCaps->binary,
|
|
|
|
(long long)qemuctime, (long long)qemuCaps->ctime,
|
2015-05-23 14:19:20 +00:00
|
|
|
(long long)selfctime, (long long)virGetSelfLastChanged(),
|
|
|
|
selfvers, (unsigned long)LIBVIR_VERSION_NUMBER);
|
2014-03-05 16:51:59 +00:00
|
|
|
ignore_value(unlink(capsfile));
|
|
|
|
virQEMUCapsReset(qemuCaps);
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=%d",
|
|
|
|
capsfile, qemuCaps->binary,
|
|
|
|
(long long)qemuCaps->ctime, qemuCaps->usedQMP);
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(binaryhash);
|
|
|
|
VIR_FREE(capsfile);
|
|
|
|
VIR_FREE(capsdir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-10 10:47:56 +00:00
|
|
|
#define QEMU_SYSTEM_PREFIX "qemu-system-"
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
static int
|
2014-12-04 15:26:41 +00:00
|
|
|
virQEMUCapsInitHelp(virQEMUCapsPtr qemuCaps, uid_t runUid, gid_t runGid, const char *qmperr)
|
2012-09-10 10:47:56 +00:00
|
|
|
{
|
2012-08-22 17:05:08 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2013-05-24 10:47:17 +00:00
|
|
|
bool is_kvm;
|
2012-09-10 10:47:56 +00:00
|
|
|
char *help = NULL;
|
2012-08-22 17:05:08 +00:00
|
|
|
int ret = -1;
|
|
|
|
const char *tmp;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_DEBUG("qemuCaps=%p", qemuCaps);
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
tmp = strstr(qemuCaps->binary, QEMU_SYSTEM_PREFIX);
|
2012-09-10 10:47:56 +00:00
|
|
|
if (tmp) {
|
|
|
|
tmp += strlen(QEMU_SYSTEM_PREFIX);
|
2012-09-26 12:48:31 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->arch = virQEMUCapsArchFromString(tmp);
|
2012-09-10 10:47:56 +00:00
|
|
|
} else {
|
2013-02-01 13:48:58 +00:00
|
|
|
qemuCaps->arch = virArchFromHost();
|
2012-09-10 10:47:56 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 20:07:03 +00:00
|
|
|
cmd = virQEMUCapsProbeCommand(qemuCaps->binary, NULL, runUid, runGid);
|
2012-09-10 10:47:56 +00:00
|
|
|
virCommandAddArgList(cmd, "-help", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &help);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsParseHelpStr(qemuCaps->binary,
|
|
|
|
help, qemuCaps,
|
|
|
|
&qemuCaps->version,
|
|
|
|
&is_kvm,
|
|
|
|
&qemuCaps->kvmVersion,
|
2014-12-04 15:26:41 +00:00
|
|
|
false,
|
|
|
|
qmperr) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2014-04-23 15:35:37 +00:00
|
|
|
/* x86_64 and i686 support PCI-multibus on all machine types
|
|
|
|
* since forever. For other architectures, it has been changing
|
|
|
|
* across releases, per machine type, so we can't simply detect
|
|
|
|
* it here. Thus the rest of the logic is provided in a separate
|
|
|
|
* helper virQEMUCapsHasPCIMultiBus() which keys off the machine
|
|
|
|
* stored in virDomainDef and QEMU version number
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
if (qemuCaps->arch == VIR_ARCH_X86_64 ||
|
2014-04-23 15:35:37 +00:00
|
|
|
qemuCaps->arch == VIR_ARCH_I686)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
|
2014-04-23 15:35:37 +00:00
|
|
|
|
|
|
|
/* -no-acpi is not supported on non-x86
|
|
|
|
* even if qemu reports it in -help */
|
|
|
|
if (qemuCaps->arch != VIR_ARCH_X86_64 &&
|
|
|
|
qemuCaps->arch != VIR_ARCH_I686)
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsClear(qemuCaps, QEMU_CAPS_NO_ACPI);
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
/* virQEMUCapsExtractDeviceStr will only set additional caps if qemu
|
2012-09-10 10:47:56 +00:00
|
|
|
* understands the 0.13.0+ notion of "-device driver,". */
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) &&
|
2012-09-10 10:47:56 +00:00
|
|
|
strstr(help, "-device driver,?") &&
|
2013-01-30 20:07:03 +00:00
|
|
|
virQEMUCapsExtractDeviceStr(qemuCaps->binary,
|
|
|
|
qemuCaps, runUid, runGid) < 0) {
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2013-01-30 20:07:03 +00:00
|
|
|
}
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-01-30 20:07:03 +00:00
|
|
|
if (virQEMUCapsProbeCPUModels(qemuCaps, runUid, runGid) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-01-30 20:07:03 +00:00
|
|
|
if (virQEMUCapsProbeMachineTypes(qemuCaps, runUid, runGid) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-08-22 17:05:08 +00:00
|
|
|
virCommandFree(cmd);
|
2012-09-10 10:47:56 +00:00
|
|
|
VIR_FREE(help);
|
2012-08-22 17:05:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
static void virQEMUCapsMonitorNotify(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
2013-07-25 17:26:15 +00:00
|
|
|
virDomainObjPtr vm ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static qemuMonitorCallbacks callbacks = {
|
2013-02-01 13:48:58 +00:00
|
|
|
.eofNotify = virQEMUCapsMonitorNotify,
|
|
|
|
.errorNotify = virQEMUCapsMonitorNotify,
|
2012-08-22 17:05:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Capabilities that we assume are always enabled
|
|
|
|
* for QEMU >= 1.2.0
|
|
|
|
*/
|
|
|
|
static void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MEM_PATH);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MONITOR_JSON);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SDL);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_RTC);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VHOST_NET);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NODEFCONFIG);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_BOOT_MENU);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NAME_PROCESS);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_READONLY);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SMBIOS_TYPE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VGA_NONE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_AIO);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEVMC);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_QXL_VGA);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_SHUTDOWN);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_UNSAFE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV_READONLY);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_COPY_ON_READ);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_FSDEV_WRITEOUT);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_WAKEUP);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_USER_CONFIG);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV_BRIDGE);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_SECCOMP_SANDBOX);
|
2013-03-14 04:49:43 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
|
2013-03-22 13:52:25 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
|
2013-03-29 05:22:46 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
|
2013-05-21 14:31:47 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
|
qemu: add host-pci-multidomain capability
Quite a long time ago, (apparently between qemu 0.12 and 0.13) qemu
quietly began supporting the optional specification of a domain in the
host-side address of all pci passthrough commands (by simply
prepending it to the bus:slot.function format, as
"dddd:bb:ss.f"). Since machines with multiple PCI domains are very
rare, this never came up in practice, so libvirt was never updated to
support it.
This patch takes the first step to supporting specification of a non-0
domain in the host-side address of PCI devices being assigned to a
domain, by adding a capability bit to indicate support
"QEMU_CAPS_HOST_PCI_MULTIDOMAIN", and detect it. Since this support
was added in a version prior to the minimum version required for
QMP-style capabilities detection, the capability is always enabled for
any qemu that uses QMP for capabilities detection. For older qemus,
the only clue that a domain can be specified in the host pci address
is the presence of the string "[seg:]" in the help string for
-pcidevice. (Ironically, libvirt will not be modified to support
specification of domain for -pcidevice, since any qemu new enough for
us to care about also supports "-device pci-assign" or "-device
vfio-pci", which are greatly preferred).
2014-04-29 15:11:45 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
|
2012-08-22 17:05:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 11:34:27 +00:00
|
|
|
/* Capabilities that are architecture depending
|
|
|
|
* initialized for QEMU.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virQEMUCapsInitArchQMPBasic(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
char *archstr = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(archstr = qemuMonitorGetTargetArch(mon)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((qemuCaps->arch = virQEMUCapsArchFromString(archstr)) == VIR_ARCH_NONE) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown QEMU arch %s"), archstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-04-23 15:35:37 +00:00
|
|
|
/* x86_64 and i686 support PCI-multibus on all machine types
|
|
|
|
* since forever. For other architectures, it has been changing
|
|
|
|
* across releases, per machine type, so we can't simply detect
|
|
|
|
* it here. Thus the rest of the logic is provided in a separate
|
|
|
|
* helper virQEMUCapsHasPCIMultiBus() which keys off the machine
|
|
|
|
* stored in virDomainDef and QEMU version number
|
|
|
|
*
|
|
|
|
* ACPI/HPET/KVM PIT are also x86 specific
|
2013-05-07 11:34:27 +00:00
|
|
|
*/
|
|
|
|
if (qemuCaps->arch == VIR_ARCH_X86_64 ||
|
|
|
|
qemuCaps->arch == VIR_ARCH_I686) {
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_ACPI);
|
2014-04-17 14:50:43 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_HPET);
|
2013-05-07 11:34:27 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-05-07 11:34:27 +00:00
|
|
|
VIR_FREE(archstr);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-09-19 11:14:25 +00:00
|
|
|
int
|
|
|
|
virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
|
|
|
qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int major, minor, micro;
|
|
|
|
char *package = NULL;
|
|
|
|
|
|
|
|
/* @mon is supposed to be locked by callee */
|
|
|
|
|
|
|
|
if (qemuMonitorSetCapabilities(mon) < 0) {
|
|
|
|
VIR_DEBUG("Failed to set monitor capabilities %s",
|
2016-03-23 18:31:50 +00:00
|
|
|
virGetLastErrorMessage());
|
2013-09-19 11:14:25 +00:00
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuMonitorGetVersion(mon,
|
|
|
|
&major, &minor, µ,
|
|
|
|
&package) < 0) {
|
|
|
|
VIR_DEBUG("Failed to query monitor version %s",
|
2016-03-23 18:31:50 +00:00
|
|
|
virGetLastErrorMessage());
|
2013-09-19 11:14:25 +00:00
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Got version %d.%d.%d (%s)",
|
|
|
|
major, minor, micro, NULLSTR(package));
|
|
|
|
|
|
|
|
if (major < 1 || (major == 1 && minor < 2)) {
|
|
|
|
VIR_DEBUG("Not new enough for QMP capabilities detection");
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuCaps->version = major * 1000000 + minor * 1000 + micro;
|
2015-02-02 10:28:30 +00:00
|
|
|
qemuCaps->package = package;
|
2013-09-19 11:14:25 +00:00
|
|
|
qemuCaps->usedQMP = true;
|
|
|
|
|
|
|
|
virQEMUCapsInitQMPBasic(qemuCaps);
|
|
|
|
|
|
|
|
if (virQEMUCapsInitArchQMPBasic(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* USB option is supported v1.3.0 onwards */
|
|
|
|
if (qemuCaps->version >= 1003000)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT);
|
|
|
|
|
|
|
|
/* WebSockets were introduced between 1.3.0 and 1.3.1 */
|
|
|
|
if (qemuCaps->version >= 1003001)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET);
|
|
|
|
|
2014-01-30 11:19:12 +00:00
|
|
|
/* -chardev spiceport is supported from 1.4.0, but usable through
|
|
|
|
* qapi only since 1.5.0, however, it still cannot be queried
|
|
|
|
* for as a capability */
|
|
|
|
if (qemuCaps->version >= 1005000)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEPORT);
|
|
|
|
|
2013-09-19 11:14:25 +00:00
|
|
|
if (qemuCaps->version >= 1006000)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
|
|
|
|
|
2015-04-02 16:43:47 +00:00
|
|
|
/* vmport option is supported v2.2.0 onwards */
|
|
|
|
if (qemuCaps->version >= 2002000)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_VMPORT_OPT);
|
|
|
|
|
2015-05-21 22:18:20 +00:00
|
|
|
/* -cpu ...,aarch64=off supported in v2.3.0 and onwards. But it
|
|
|
|
isn't detectable via qmp at this point */
|
|
|
|
if (qemuCaps->arch == VIR_ARCH_AARCH64 &&
|
|
|
|
qemuCaps->version >= 2003000)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF);
|
|
|
|
|
2015-06-04 09:37:37 +00:00
|
|
|
/* vhost-user supports multi-queue from v2.4.0 onwards,
|
|
|
|
* but there is no way to query for that capability */
|
|
|
|
if (qemuCaps->version >= 2004000)
|
2015-06-15 08:38:21 +00:00
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VHOSTUSER_MULTIQUEUE);
|
2015-06-04 09:37:37 +00:00
|
|
|
|
2015-09-30 11:04:09 +00:00
|
|
|
/* Since 2.4.50 ARM virt machine supports gic-version option */
|
|
|
|
if (qemuCaps->version >= 2004050)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACH_VIRT_GIC_VERSION);
|
|
|
|
|
2013-09-19 11:14:25 +00:00
|
|
|
if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPObjects(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPKVMState(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPTPM(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virQEMUCapsProbeQMPCommandLine(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
2014-09-11 12:11:54 +00:00
|
|
|
if (virQEMUCapsProbeQMPMigrationCapabilities(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
2013-09-19 11:14:25 +00:00
|
|
|
|
2016-03-08 17:24:18 +00:00
|
|
|
/* GIC capabilities, eg. available GIC versions */
|
|
|
|
if ((qemuCaps->arch == VIR_ARCH_AARCH64 ||
|
|
|
|
qemuCaps->arch == VIR_ARCH_ARMV7L) &&
|
|
|
|
virQEMUCapsProbeQMPGICCapabilities(qemuCaps, mon) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-09-19 11:14:25 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-09-19 11:14:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
static int
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *libDir,
|
|
|
|
uid_t runUid,
|
2014-12-04 15:26:41 +00:00
|
|
|
gid_t runGid,
|
|
|
|
char **qmperr)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
qemuMonitorPtr mon = NULL;
|
|
|
|
int status = 0;
|
|
|
|
virDomainChrSourceDef config;
|
|
|
|
char *monarg = NULL;
|
|
|
|
char *monpath = NULL;
|
2012-10-02 08:59:56 +00:00
|
|
|
char *pidfile = NULL;
|
2013-01-07 16:19:36 +00:00
|
|
|
pid_t pid = 0;
|
2013-10-08 14:50:33 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainXMLOptionPtr xmlopt = NULL;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2012-10-02 08:59:56 +00:00
|
|
|
/* the ".sock" sufix is important to avoid a possible clash with a qemu
|
|
|
|
* domain called "capabilities"
|
|
|
|
*/
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&monpath, "%s/%s", libDir, "capabilities.monitor.sock") < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&monarg, "unix:%s,server,nowait", monpath) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-10-02 08:59:56 +00:00
|
|
|
/* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash
|
|
|
|
* with a qemu domain called "capabilities"
|
2013-01-24 18:21:23 +00:00
|
|
|
* Normally we'd use runDir for pid files, but because we're using
|
|
|
|
* -daemonize we need QEMU to be allowed to create them, rather
|
|
|
|
* than libvirtd. So we're using libDir which QEMU can write to
|
2012-10-02 08:59:56 +00:00
|
|
|
*/
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0)
|
2012-10-02 08:59:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
memset(&config, 0, sizeof(config));
|
|
|
|
config.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
|
|
|
config.data.nix.path = monpath;
|
|
|
|
config.data.nix.listen = false;
|
|
|
|
|
2014-10-09 06:18:33 +00:00
|
|
|
virPidFileForceCleanupPath(pidfile);
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
VIR_DEBUG("Try to get caps via QMP qemuCaps=%p", qemuCaps);
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-01-24 18:21:23 +00:00
|
|
|
/*
|
|
|
|
* We explicitly need to use -daemonize here, rather than
|
|
|
|
* virCommandDaemonize, because we need to synchronize
|
|
|
|
* with QEMU creating its monitor socket API. Using
|
|
|
|
* daemonize guarantees control won't return to libvirt
|
|
|
|
* until the socket is present.
|
|
|
|
*/
|
2013-02-01 13:48:58 +00:00
|
|
|
cmd = virCommandNewArgList(qemuCaps->binary,
|
2012-08-22 17:05:08 +00:00
|
|
|
"-S",
|
|
|
|
"-no-user-config",
|
|
|
|
"-nodefaults",
|
|
|
|
"-nographic",
|
|
|
|
"-M", "none",
|
|
|
|
"-qmp", monarg,
|
2013-01-24 18:21:23 +00:00
|
|
|
"-pidfile", pidfile,
|
|
|
|
"-daemonize",
|
2012-08-22 17:05:08 +00:00
|
|
|
NULL);
|
|
|
|
virCommandAddEnvPassCommon(cmd);
|
|
|
|
virCommandClearCaps(cmd);
|
2013-01-30 20:07:03 +00:00
|
|
|
virCommandSetGID(cmd, runGid);
|
|
|
|
virCommandSetUID(cmd, runUid);
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2014-12-04 15:26:41 +00:00
|
|
|
virCommandSetErrorBuffer(cmd, qmperr);
|
|
|
|
|
2014-02-20 00:32:19 +00:00
|
|
|
/* Log, but otherwise ignore, non-zero status. */
|
2012-08-22 17:05:08 +00:00
|
|
|
if (virCommandRun(cmd, &status) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != 0) {
|
|
|
|
ret = 0;
|
2014-12-04 15:26:41 +00:00
|
|
|
VIR_DEBUG("QEMU %s exited with status %d: %s",
|
|
|
|
qemuCaps->binary, status, *qmperr);
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-01-07 16:19:36 +00:00
|
|
|
if (virPidFileReadPath(pidfile, &pid) < 0) {
|
|
|
|
VIR_DEBUG("Failed to read pidfile %s", pidfile);
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:50:33 +00:00
|
|
|
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) ||
|
|
|
|
!(vm = virDomainObjNew(xmlopt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vm->pid = pid;
|
2013-01-07 16:19:36 +00:00
|
|
|
|
2013-10-08 14:50:33 +00:00
|
|
|
if (!(mon = qemuMonitorOpen(vm, &config, true, &callbacks, NULL))) {
|
2012-11-29 12:08:40 +00:00
|
|
|
ret = 0;
|
2012-08-22 17:05:08 +00:00
|
|
|
goto cleanup;
|
2012-11-29 12:08:40 +00:00
|
|
|
}
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectLock(mon);
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2013-09-19 11:14:25 +00:00
|
|
|
if (virQEMUCapsInitQMPMonitor(qemuCaps, mon) < 0)
|
2013-05-14 05:25:49 +00:00
|
|
|
goto cleanup;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-08-22 17:05:08 +00:00
|
|
|
if (mon)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-08-22 17:05:08 +00:00
|
|
|
qemuMonitorClose(mon);
|
|
|
|
virCommandAbort(cmd);
|
2012-09-10 10:47:56 +00:00
|
|
|
virCommandFree(cmd);
|
2012-08-22 17:05:08 +00:00
|
|
|
VIR_FREE(monarg);
|
2014-09-25 08:30:58 +00:00
|
|
|
if (monpath)
|
|
|
|
ignore_value(unlink(monpath));
|
2012-08-22 17:05:08 +00:00
|
|
|
VIR_FREE(monpath);
|
2015-04-23 15:27:58 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-10-08 14:50:33 +00:00
|
|
|
virObjectUnref(xmlopt);
|
2012-10-02 08:59:56 +00:00
|
|
|
|
2013-01-07 16:19:36 +00:00
|
|
|
if (pid != 0) {
|
2012-10-02 08:59:56 +00:00
|
|
|
char ebuf[1024];
|
|
|
|
|
2013-01-07 16:19:36 +00:00
|
|
|
VIR_DEBUG("Killing QMP caps process %lld", (long long) pid);
|
|
|
|
if (virProcessKill(pid, SIGKILL) < 0 && errno != ESRCH)
|
|
|
|
VIR_ERROR(_("Failed to kill process %lld: %s"),
|
|
|
|
(long long) pid,
|
|
|
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
2014-12-04 15:26:41 +00:00
|
|
|
|
|
|
|
VIR_FREE(*qmperr);
|
2013-01-07 16:19:36 +00:00
|
|
|
}
|
|
|
|
if (pidfile) {
|
2012-10-02 08:59:56 +00:00
|
|
|
unlink(pidfile);
|
|
|
|
VIR_FREE(pidfile);
|
|
|
|
}
|
2012-08-22 17:05:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-21 17:16:07 +00:00
|
|
|
#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
|
|
|
|
|
|
|
|
static void
|
|
|
|
virQEMUCapsLogProbeFailure(const char *binary)
|
|
|
|
{
|
|
|
|
virLogMetadata meta[] = {
|
|
|
|
{ .key = "MESSAGE_ID", .s = MESSAGE_ID_CAPS_PROBE_FAILURE, .iv = 0 },
|
|
|
|
{ .key = "LIBVIRT_QEMU_BINARY", .s = binary, .iv = 0 },
|
|
|
|
{ .key = NULL },
|
|
|
|
};
|
|
|
|
|
2014-02-27 17:44:53 +00:00
|
|
|
virLogMessage(&virLogSelf,
|
2014-02-21 17:16:07 +00:00
|
|
|
VIR_LOG_WARN,
|
|
|
|
__FILE__, __LINE__, __func__,
|
|
|
|
meta,
|
|
|
|
_("Failed to probe capabilities for %s: %s"),
|
2016-03-23 18:31:50 +00:00
|
|
|
binary, virGetLastErrorMessage());
|
2014-02-21 17:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-26 13:03:06 +00:00
|
|
|
virQEMUCapsPtr
|
|
|
|
virQEMUCapsNewForBinaryInternal(const char *binary,
|
|
|
|
const char *libDir,
|
|
|
|
const char *cacheDir,
|
|
|
|
uid_t runUid,
|
|
|
|
gid_t runGid,
|
|
|
|
bool qmpOnly)
|
2012-08-22 17:05:08 +00:00
|
|
|
{
|
2014-08-27 13:43:52 +00:00
|
|
|
virQEMUCapsPtr qemuCaps;
|
2012-08-22 17:05:08 +00:00
|
|
|
struct stat sb;
|
|
|
|
int rv;
|
2014-12-04 15:26:41 +00:00
|
|
|
char *qmperr = NULL;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2014-08-27 13:43:52 +00:00
|
|
|
if (!(qemuCaps = virQEMUCapsNew()))
|
|
|
|
goto error;
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(qemuCaps->binary, binary) < 0)
|
|
|
|
goto error;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
/* We would also want to check faccessat if we cared about ACLs,
|
|
|
|
* but we don't. */
|
|
|
|
if (stat(binary, &sb) < 0) {
|
|
|
|
virReportSystemError(errno, _("Cannot check QEMU binary %s"),
|
|
|
|
binary);
|
|
|
|
goto error;
|
|
|
|
}
|
2014-03-10 15:50:19 +00:00
|
|
|
qemuCaps->ctime = sb.st_ctime;
|
2012-08-22 17:05:08 +00:00
|
|
|
|
|
|
|
/* Make sure the binary we are about to try exec'ing exists.
|
|
|
|
* Technically we could catch the exec() failure, but that's
|
|
|
|
* in a sub-process so it's hard to feed back a useful error.
|
|
|
|
*/
|
|
|
|
if (!virFileIsExecutable(binary)) {
|
|
|
|
virReportSystemError(errno, _("QEMU binary %s is not executable"),
|
|
|
|
binary);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-04-26 13:03:06 +00:00
|
|
|
if (!cacheDir)
|
|
|
|
rv = 0;
|
|
|
|
else if ((rv = virQEMUCapsInitCached(qemuCaps, cacheDir)) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
if (rv == 0) {
|
2014-12-04 15:26:41 +00:00
|
|
|
if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0) {
|
2014-03-05 16:51:59 +00:00
|
|
|
virQEMUCapsLogProbeFailure(binary);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-04-26 13:03:06 +00:00
|
|
|
if (qmpOnly && !qemuCaps->usedQMP) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to probe QEMU binary with QMP: %s"),
|
|
|
|
qmperr ? qmperr : _("unknown error"));
|
|
|
|
virQEMUCapsLogProbeFailure(binary);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:51:59 +00:00
|
|
|
if (!qemuCaps->usedQMP &&
|
2014-12-04 15:26:41 +00:00
|
|
|
virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) {
|
2014-03-05 16:51:59 +00:00
|
|
|
virQEMUCapsLogProbeFailure(binary);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-04-26 13:03:06 +00:00
|
|
|
if (cacheDir &&
|
|
|
|
virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
|
2014-03-05 16:51:59 +00:00
|
|
|
goto error;
|
2014-02-21 17:16:07 +00:00
|
|
|
}
|
2012-08-22 17:05:08 +00:00
|
|
|
|
2014-12-04 15:26:41 +00:00
|
|
|
VIR_FREE(qmperr);
|
2013-02-01 13:48:58 +00:00
|
|
|
return qemuCaps;
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2014-12-04 15:26:41 +00:00
|
|
|
VIR_FREE(qmperr);
|
2013-02-01 13:48:58 +00:00
|
|
|
virObjectUnref(qemuCaps);
|
|
|
|
qemuCaps = NULL;
|
2012-08-22 17:05:08 +00:00
|
|
|
return NULL;
|
2012-09-10 10:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 13:03:06 +00:00
|
|
|
virQEMUCapsPtr
|
|
|
|
virQEMUCapsNewForBinary(const char *binary,
|
|
|
|
const char *libDir,
|
|
|
|
const char *cacheDir,
|
|
|
|
uid_t runUid,
|
|
|
|
gid_t runGid)
|
|
|
|
{
|
|
|
|
return virQEMUCapsNewForBinaryInternal(binary, libDir, cacheDir,
|
|
|
|
runUid, runGid, false);
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:47:56 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps)
|
2012-09-10 10:47:56 +00:00
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!qemuCaps->binary)
|
2012-09-10 10:47:56 +00:00
|
|
|
return true;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (stat(qemuCaps->binary, &sb) < 0)
|
2012-09-10 10:47:56 +00:00
|
|
|
return false;
|
|
|
|
|
2014-03-10 15:50:19 +00:00
|
|
|
return sb.st_ctime == qemuCaps->ctime;
|
2012-09-10 10:47:56 +00:00
|
|
|
}
|
2012-08-22 12:54:13 +00:00
|
|
|
|
|
|
|
|
2015-02-12 13:50:31 +00:00
|
|
|
struct virQEMUCapsMachineTypeFilter {
|
|
|
|
const char *machineType;
|
|
|
|
virQEMUCapsFlags *flags;
|
|
|
|
size_t nflags;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct virQEMUCapsMachineTypeFilter virQEMUCapsMachineFilter[] = {
|
|
|
|
/* { "blah", virQEMUCapsMachineBLAHFilter,
|
|
|
|
ARRAY_CARDINALITY(virQEMUCapsMachineBLAHFilter) }, */
|
|
|
|
{ "", NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *machineType)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!machineType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsMachineFilter); i++) {
|
|
|
|
const struct virQEMUCapsMachineTypeFilter *filter = &virQEMUCapsMachineFilter[i];
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
if (STRNEQ(filter->machineType, machineType))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < filter->nflags; j++)
|
|
|
|
virQEMUCapsClear(qemuCaps, filter->flags[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsCachePtr
|
|
|
|
virQEMUCapsCacheNew(const char *libDir,
|
2014-03-05 16:51:59 +00:00
|
|
|
const char *cacheDir,
|
2013-02-01 13:48:58 +00:00
|
|
|
uid_t runUid,
|
|
|
|
gid_t runGid)
|
2012-08-22 12:54:13 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsCachePtr cache;
|
2012-08-22 12:54:13 +00:00
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC(cache) < 0)
|
2012-08-22 12:54:13 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virMutexInit(&cache->lock) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to initialize mutex"));
|
|
|
|
VIR_FREE(cache);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-04 23:36:25 +00:00
|
|
|
if (!(cache->binaries = virHashCreate(10, virObjectFreeHashData)))
|
2012-08-22 12:54:13 +00:00
|
|
|
goto error;
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(cache->libDir, libDir) < 0)
|
2012-08-22 17:05:08 +00:00
|
|
|
goto error;
|
2014-03-05 16:51:59 +00:00
|
|
|
if (VIR_STRDUP(cache->cacheDir, cacheDir) < 0)
|
|
|
|
goto error;
|
2012-08-22 12:54:13 +00:00
|
|
|
|
2012-11-26 14:17:13 +00:00
|
|
|
cache->runUid = runUid;
|
|
|
|
cache->runGid = runGid;
|
|
|
|
|
2012-08-22 12:54:13 +00:00
|
|
|
return cache;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsCacheFree(cache);
|
2012-08-22 12:54:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:03:14 +00:00
|
|
|
const char *qemuTestCapsName;
|
2012-08-22 12:54:13 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr
|
|
|
|
virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary)
|
2012-08-22 12:54:13 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr ret = NULL;
|
2015-09-09 14:03:14 +00:00
|
|
|
|
|
|
|
/* This is used only by test suite!!! */
|
|
|
|
if (qemuTestCapsName)
|
|
|
|
binary = qemuTestCapsName;
|
|
|
|
|
2012-08-22 12:54:13 +00:00
|
|
|
virMutexLock(&cache->lock);
|
|
|
|
ret = virHashLookup(cache->binaries, binary);
|
|
|
|
if (ret &&
|
2013-02-01 13:48:58 +00:00
|
|
|
!virQEMUCapsIsValid(ret)) {
|
2012-08-22 12:54:13 +00:00
|
|
|
VIR_DEBUG("Cached capabilities %p no longer valid for %s",
|
|
|
|
ret, binary);
|
|
|
|
virHashRemoveEntry(cache->binaries, binary);
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
VIR_DEBUG("Creating capabilities for %s",
|
|
|
|
binary);
|
2013-02-01 13:48:58 +00:00
|
|
|
ret = virQEMUCapsNewForBinary(binary, cache->libDir,
|
2014-03-05 16:51:59 +00:00
|
|
|
cache->cacheDir,
|
2013-02-01 13:48:58 +00:00
|
|
|
cache->runUid, cache->runGid);
|
2012-08-22 12:54:13 +00:00
|
|
|
if (ret) {
|
|
|
|
VIR_DEBUG("Caching capabilities %p for %s",
|
|
|
|
ret, binary);
|
|
|
|
if (virHashAddEntry(cache->binaries, binary, ret) < 0) {
|
|
|
|
virObjectUnref(ret);
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Returning caps %p for %s", ret, binary);
|
|
|
|
virObjectRef(ret);
|
|
|
|
virMutexUnlock(&cache->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr
|
2015-02-12 12:48:42 +00:00
|
|
|
virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache,
|
|
|
|
const char *binary,
|
2015-02-12 13:50:31 +00:00
|
|
|
const char *machineType)
|
2012-08-22 12:54:13 +00:00
|
|
|
{
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr qemuCaps = virQEMUCapsCacheLookup(cache, binary);
|
|
|
|
virQEMUCapsPtr ret;
|
2012-08-22 12:54:13 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!qemuCaps)
|
2012-08-22 12:54:13 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
ret = virQEMUCapsNewCopy(qemuCaps);
|
|
|
|
virObjectUnref(qemuCaps);
|
2015-02-12 13:50:31 +00:00
|
|
|
virQEMUCapsFilterByMachineType(ret, machineType);
|
2012-08-22 12:54:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 14:12:07 +00:00
|
|
|
static int
|
|
|
|
virQEMUCapsCompareArch(const void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
|
|
|
struct virQEMUCapsSearchData *data = (struct virQEMUCapsSearchData *) opaque;
|
|
|
|
const virQEMUCaps *qemuCaps = payload;
|
|
|
|
|
|
|
|
return qemuCaps->arch == data->arch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virQEMUCapsPtr
|
|
|
|
virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
|
|
|
|
virArch arch)
|
|
|
|
{
|
|
|
|
virQEMUCapsPtr ret = NULL;
|
2015-09-15 13:58:09 +00:00
|
|
|
virArch target;
|
2014-06-30 14:12:07 +00:00
|
|
|
struct virQEMUCapsSearchData data = { .arch = arch };
|
|
|
|
|
|
|
|
virMutexLock(&cache->lock);
|
|
|
|
ret = virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data);
|
2015-09-15 13:58:09 +00:00
|
|
|
if (!ret) {
|
|
|
|
/* If the first attempt at finding capabilities has failed, try
|
|
|
|
* again using the QEMU target as lookup key instead */
|
|
|
|
target = virQEMUCapsFindTarget(virArchFromHost(), data.arch);
|
|
|
|
if (target != data.arch) {
|
|
|
|
data.arch = target;
|
|
|
|
ret = virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data);
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 14:12:07 +00:00
|
|
|
virObjectRef(ret);
|
|
|
|
virMutexUnlock(&cache->lock);
|
|
|
|
|
2015-09-15 13:58:09 +00:00
|
|
|
VIR_DEBUG("Returning caps %p for arch %s", ret, virArchToString(arch));
|
|
|
|
|
2014-06-30 14:12:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 12:54:13 +00:00
|
|
|
void
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsCacheFree(virQEMUCapsCachePtr cache)
|
2012-08-22 12:54:13 +00:00
|
|
|
{
|
|
|
|
if (!cache)
|
|
|
|
return;
|
|
|
|
|
2012-08-22 17:05:08 +00:00
|
|
|
VIR_FREE(cache->libDir);
|
2014-03-05 16:51:59 +00:00
|
|
|
VIR_FREE(cache->cacheDir);
|
2012-08-22 12:54:13 +00:00
|
|
|
virHashFree(cache->binaries);
|
|
|
|
virMutexDestroy(&cache->lock);
|
|
|
|
VIR_FREE(cache);
|
|
|
|
}
|
2013-01-02 14:36:33 +00:00
|
|
|
|
2013-07-30 21:49:11 +00:00
|
|
|
|
|
|
|
bool
|
2016-02-18 15:46:48 +00:00
|
|
|
virQEMUCapsSupportsChardev(const virDomainDef *def,
|
2013-07-30 21:49:11 +00:00
|
|
|
virQEMUCapsPtr qemuCaps,
|
2013-08-01 01:40:35 +00:00
|
|
|
virDomainChrDefPtr chr)
|
2013-07-30 21:49:11 +00:00
|
|
|
{
|
|
|
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV) ||
|
|
|
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
|
|
|
|
return false;
|
|
|
|
|
2014-11-04 17:21:26 +00:00
|
|
|
if ((def->os.arch == VIR_ARCH_PPC) || ARCH_IS_PPC64(def->os.arch)) {
|
2014-05-27 05:44:14 +00:00
|
|
|
/* only pseries need -device spapr-vty with -chardev */
|
|
|
|
return (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
|
|
|
|
chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO);
|
|
|
|
}
|
|
|
|
|
2014-01-02 10:42:56 +00:00
|
|
|
if ((def->os.arch != VIR_ARCH_ARMV7L) && (def->os.arch != VIR_ARCH_AARCH64))
|
2013-08-01 01:40:35 +00:00
|
|
|
return true;
|
2013-07-30 21:49:11 +00:00
|
|
|
|
2013-08-01 01:40:35 +00:00
|
|
|
/* This may not be true for all ARM machine types, but at least
|
|
|
|
* the only supported non-virtio serial devices of vexpress and versatile
|
|
|
|
* don't have the -chardev property wired up. */
|
|
|
|
return (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO ||
|
|
|
|
(chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
|
|
|
|
chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO));
|
2013-07-30 21:49:11 +00:00
|
|
|
}
|
2014-06-30 14:31:51 +00:00
|
|
|
|
|
|
|
|
2015-04-21 11:28:40 +00:00
|
|
|
bool
|
|
|
|
virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps,
|
|
|
|
const virDomainDef *def)
|
|
|
|
{
|
|
|
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_VMPORT_OPT))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return qemuDomainMachineIsI440FX(def) ||
|
|
|
|
qemuDomainMachineIsQ35(def) ||
|
|
|
|
STREQ(def->os.machine, "isapc");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 14:31:51 +00:00
|
|
|
bool
|
|
|
|
virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
|
|
|
|
const char *canonical_machine)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->nmachineTypes; i++) {
|
|
|
|
if (STREQ(canonical_machine, qemuCaps->machineTypes[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-30 14:39:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps)
|
|
|
|
{
|
|
|
|
if (!qemuCaps->nmachineTypes)
|
|
|
|
return NULL;
|
|
|
|
return qemuCaps->machineTypes[0];
|
|
|
|
}
|
2014-06-25 16:39:29 +00:00
|
|
|
|
|
|
|
|
2014-09-17 09:33:35 +00:00
|
|
|
static int
|
2014-09-16 12:47:47 +00:00
|
|
|
virQEMUCapsFillDomainLoaderCaps(virQEMUCapsPtr qemuCaps,
|
2014-09-18 06:30:40 +00:00
|
|
|
virDomainCapsLoaderPtr capsLoader,
|
|
|
|
char **loader,
|
|
|
|
size_t nloader)
|
2014-09-16 12:47:47 +00:00
|
|
|
{
|
2014-09-16 23:52:54 +00:00
|
|
|
size_t i;
|
|
|
|
|
2016-03-10 18:52:52 +00:00
|
|
|
capsLoader->supported = true;
|
2014-09-16 12:47:47 +00:00
|
|
|
|
2014-09-18 06:30:40 +00:00
|
|
|
if (VIR_ALLOC_N(capsLoader->values.values, nloader) < 0)
|
2014-09-16 23:52:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-09-18 06:30:40 +00:00
|
|
|
for (i = 0; i < nloader; i++) {
|
|
|
|
const char *filename = loader[i];
|
2014-09-16 23:52:54 +00:00
|
|
|
|
|
|
|
if (!virFileExists(filename)) {
|
|
|
|
VIR_DEBUG("loader filename=%s does not exist", filename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-18 06:30:40 +00:00
|
|
|
if (VIR_STRDUP(capsLoader->values.values[capsLoader->values.nvalues],
|
2014-09-16 23:52:54 +00:00
|
|
|
filename) < 0)
|
|
|
|
return -1;
|
2014-09-18 06:30:40 +00:00
|
|
|
capsLoader->values.nvalues++;
|
2014-09-16 23:52:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 06:30:40 +00:00
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(capsLoader->type,
|
2014-09-16 12:47:47 +00:00
|
|
|
VIR_DOMAIN_LOADER_TYPE_ROM);
|
|
|
|
|
2015-11-06 18:20:20 +00:00
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(capsLoader->type,
|
|
|
|
VIR_DOMAIN_LOADER_TYPE_PFLASH);
|
2014-09-16 12:47:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_READONLY))
|
2014-09-18 06:30:40 +00:00
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(capsLoader->readonly,
|
2014-09-16 12:47:47 +00:00
|
|
|
VIR_TRISTATE_BOOL_YES,
|
|
|
|
VIR_TRISTATE_BOOL_NO);
|
2014-09-17 09:33:35 +00:00
|
|
|
return 0;
|
2014-09-16 12:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-17 09:33:35 +00:00
|
|
|
static int
|
2014-09-16 12:47:47 +00:00
|
|
|
virQEMUCapsFillDomainOSCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainCapsOSPtr os,
|
2014-09-18 06:30:40 +00:00
|
|
|
char **loader,
|
|
|
|
size_t nloader)
|
2014-09-16 12:47:47 +00:00
|
|
|
{
|
2014-09-18 06:30:40 +00:00
|
|
|
virDomainCapsLoaderPtr capsLoader = &os->loader;
|
2014-09-16 12:47:47 +00:00
|
|
|
|
2016-03-10 18:52:52 +00:00
|
|
|
os->supported = true;
|
2014-11-19 17:16:12 +00:00
|
|
|
if (virQEMUCapsFillDomainLoaderCaps(qemuCaps, capsLoader,
|
2014-09-18 06:30:40 +00:00
|
|
|
loader, nloader) < 0)
|
2014-09-17 09:33:35 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2014-09-16 12:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-17 09:33:35 +00:00
|
|
|
static int
|
2014-06-25 16:39:29 +00:00
|
|
|
virQEMUCapsFillDomainDeviceDiskCaps(virQEMUCapsPtr qemuCaps,
|
2015-07-30 11:54:26 +00:00
|
|
|
const char *machine,
|
2014-06-25 16:39:29 +00:00
|
|
|
virDomainCapsDeviceDiskPtr disk)
|
|
|
|
{
|
2016-03-10 18:52:52 +00:00
|
|
|
disk->supported = true;
|
2014-06-25 16:39:29 +00:00
|
|
|
/* QEMU supports all of these */
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(disk->diskDevice,
|
|
|
|
VIR_DOMAIN_DISK_DEVICE_DISK,
|
2016-05-16 08:29:57 +00:00
|
|
|
VIR_DOMAIN_DISK_DEVICE_CDROM,
|
|
|
|
VIR_DOMAIN_DISK_DEVICE_LUN);
|
2015-07-30 11:54:26 +00:00
|
|
|
|
|
|
|
/* PowerPC pseries based VMs do not support floppy device */
|
|
|
|
if (!(ARCH_IS_PPC64(qemuCaps->arch) && STRPREFIX(machine, "pseries")))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(disk->diskDevice, VIR_DOMAIN_DISK_DEVICE_FLOPPY);
|
2014-06-25 16:39:29 +00:00
|
|
|
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(disk->bus,
|
|
|
|
VIR_DOMAIN_DISK_BUS_IDE,
|
|
|
|
VIR_DOMAIN_DISK_BUS_SCSI,
|
|
|
|
VIR_DOMAIN_DISK_BUS_VIRTIO,
|
|
|
|
/* VIR_DOMAIN_DISK_BUS_SD */);
|
|
|
|
|
2015-07-30 11:54:26 +00:00
|
|
|
/* PowerPC pseries based VMs do not support floppy device */
|
|
|
|
if (!(ARCH_IS_PPC64(qemuCaps->arch) && STRPREFIX(machine, "pseries")))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(disk->bus, VIR_DOMAIN_DISK_BUS_FDC);
|
|
|
|
|
2014-06-25 16:39:29 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(disk->bus, VIR_DOMAIN_DISK_BUS_USB);
|
2014-09-17 09:33:35 +00:00
|
|
|
return 0;
|
2014-06-25 16:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-08 15:57:20 +00:00
|
|
|
static int
|
|
|
|
virQEMUCapsFillDomainDeviceGraphicsCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainCapsDeviceGraphicsPtr dev)
|
|
|
|
{
|
|
|
|
dev->supported = true;
|
|
|
|
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_GRAPHICS_TYPE_SDL);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_GRAPHICS_TYPE_VNC);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_GRAPHICS_TYPE_SPICE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-08 16:11:39 +00:00
|
|
|
static int
|
|
|
|
virQEMUCapsFillDomainDeviceVideoCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainCapsDeviceVideoPtr dev)
|
|
|
|
{
|
|
|
|
dev->supported = true;
|
|
|
|
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VGA))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_VGA);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_CIRRUS);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMWARE_SVGA))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_VMVGA);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QXL_VGA))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_QXL);
|
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_GPU))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_VIRTIO);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-17 09:33:35 +00:00
|
|
|
static int
|
2014-06-25 16:39:29 +00:00
|
|
|
virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainCapsDeviceHostdevPtr hostdev)
|
|
|
|
{
|
|
|
|
bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
|
|
|
|
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
|
|
|
|
|
2016-03-10 18:52:52 +00:00
|
|
|
hostdev->supported = true;
|
2014-06-25 16:39:29 +00:00
|
|
|
/* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->mode,
|
|
|
|
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS);
|
|
|
|
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->startupPolicy,
|
|
|
|
VIR_DOMAIN_STARTUP_POLICY_DEFAULT,
|
|
|
|
VIR_DOMAIN_STARTUP_POLICY_MANDATORY,
|
|
|
|
VIR_DOMAIN_STARTUP_POLICY_REQUISITE,
|
|
|
|
VIR_DOMAIN_STARTUP_POLICY_OPTIONAL);
|
|
|
|
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->subsysType,
|
|
|
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB,
|
|
|
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI);
|
2015-11-06 14:28:57 +00:00
|
|
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) &&
|
2014-06-25 16:39:29 +00:00
|
|
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC))
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->subsysType,
|
|
|
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI);
|
|
|
|
|
|
|
|
/* No virDomainHostdevCapsType for QEMU */
|
|
|
|
virDomainCapsEnumClear(&hostdev->capsType);
|
|
|
|
|
|
|
|
virDomainCapsEnumClear(&hostdev->pciBackend);
|
|
|
|
if (supportsPassthroughVFIO &&
|
|
|
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->pciBackend,
|
|
|
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT,
|
|
|
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (supportsPassthroughKVM &&
|
|
|
|
(virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCIDEVICE) ||
|
|
|
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->pciBackend,
|
|
|
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT,
|
|
|
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM);
|
|
|
|
}
|
2014-09-17 09:33:35 +00:00
|
|
|
return 0;
|
2014-06-25 16:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-16 11:23:01 +00:00
|
|
|
/**
|
|
|
|
* virQEMUCapsSupportsGICVersion:
|
|
|
|
* @qemuCaps: QEMU capabilities
|
|
|
|
* @virtType: domain type
|
|
|
|
* @version: GIC version
|
|
|
|
*
|
|
|
|
* Checks the QEMU binary with capabilities @qemuCaps supports a specific
|
|
|
|
* GIC version for a domain of type @virtType.
|
|
|
|
*
|
|
|
|
* Returns: true if the binary supports the requested GIC version, false
|
|
|
|
* otherwise
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
virQEMUCapsSupportsGICVersion(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainVirtType virtType,
|
|
|
|
virGICVersion version)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < qemuCaps->ngicCapabilities; i++) {
|
|
|
|
virGICCapabilityPtr cap = &(qemuCaps->gicCapabilities[i]);
|
|
|
|
|
|
|
|
if (cap->version != version)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (virtType == VIR_DOMAIN_VIRT_KVM &&
|
|
|
|
cap->implementation & VIR_GIC_IMPLEMENTATION_KERNEL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (virtType == VIR_DOMAIN_VIRT_QEMU &&
|
|
|
|
cap->implementation & VIR_GIC_IMPLEMENTATION_EMULATED)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 18:18:24 +00:00
|
|
|
/**
|
|
|
|
* virQEMUCapsFillDomainFeatureGICCaps:
|
|
|
|
* @qemuCaps: QEMU capabilities
|
|
|
|
* @domCaps: domain capabilities
|
|
|
|
*
|
|
|
|
* Take the information about GIC capabilities that has been obtained
|
|
|
|
* using the 'query-gic-capabilities' QMP command and stored in @qemuCaps
|
|
|
|
* and convert it to a form suitable for @domCaps.
|
|
|
|
*
|
|
|
|
* @qemuCaps contains complete information about the GIC capabilities for
|
|
|
|
* the corresponding QEMU binary, stored as custom objects; @domCaps, on
|
|
|
|
* the other hand, should only contain information about the GIC versions
|
|
|
|
* available for the specific combination of architecture, machine type
|
|
|
|
* and virtualization type. Moreover, a common format is used to store
|
|
|
|
* information about enumerations in @domCaps, so further processing is
|
|
|
|
* required.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, <0 on failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virQEMUCapsFillDomainFeatureGICCaps(virQEMUCapsPtr qemuCaps,
|
|
|
|
virDomainCapsPtr domCaps)
|
|
|
|
{
|
|
|
|
virDomainCapsFeatureGICPtr gic = &domCaps->gic;
|
2016-05-16 11:23:01 +00:00
|
|
|
virGICVersion version;
|
2016-03-09 18:18:24 +00:00
|
|
|
|
|
|
|
if (domCaps->arch != VIR_ARCH_ARMV7L &&
|
|
|
|
domCaps->arch != VIR_ARCH_AARCH64)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (STRNEQ(domCaps->machine, "virt") &&
|
|
|
|
!STRPREFIX(domCaps->machine, "virt-"))
|
|
|
|
return 0;
|
|
|
|
|
2016-05-16 11:23:01 +00:00
|
|
|
for (version = VIR_GIC_VERSION_LAST - 1;
|
|
|
|
version > VIR_GIC_VERSION_NONE;
|
|
|
|
version--) {
|
|
|
|
if (!virQEMUCapsSupportsGICVersion(qemuCaps,
|
|
|
|
domCaps->virttype,
|
|
|
|
version))
|
2016-03-09 18:18:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
gic->supported = true;
|
|
|
|
VIR_DOMAIN_CAPS_ENUM_SET(gic->version,
|
2016-05-16 11:23:01 +00:00
|
|
|
version);
|
2016-03-09 18:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-17 09:33:35 +00:00
|
|
|
int
|
2014-06-25 16:39:29 +00:00
|
|
|
virQEMUCapsFillDomainCaps(virDomainCapsPtr domCaps,
|
2014-09-16 23:52:54 +00:00
|
|
|
virQEMUCapsPtr qemuCaps,
|
2014-09-18 06:30:40 +00:00
|
|
|
char **loader,
|
|
|
|
size_t nloader)
|
2014-06-25 16:39:29 +00:00
|
|
|
{
|
2014-09-16 12:47:47 +00:00
|
|
|
virDomainCapsOSPtr os = &domCaps->os;
|
2014-06-25 16:39:29 +00:00
|
|
|
virDomainCapsDeviceDiskPtr disk = &domCaps->disk;
|
|
|
|
virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
|
2016-05-08 15:57:20 +00:00
|
|
|
virDomainCapsDeviceGraphicsPtr graphics = &domCaps->graphics;
|
2016-05-08 16:11:39 +00:00
|
|
|
virDomainCapsDeviceVideoPtr video = &domCaps->video;
|
2014-06-25 16:39:29 +00:00
|
|
|
int maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, domCaps->machine);
|
|
|
|
|
|
|
|
domCaps->maxvcpus = maxvcpus;
|
|
|
|
|
2014-11-19 17:16:12 +00:00
|
|
|
if (virQEMUCapsFillDomainOSCaps(qemuCaps, os,
|
2014-09-18 06:30:40 +00:00
|
|
|
loader, nloader) < 0 ||
|
2016-05-08 15:57:20 +00:00
|
|
|
virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps,
|
|
|
|
domCaps->machine, disk) < 0 ||
|
|
|
|
virQEMUCapsFillDomainDeviceGraphicsCaps(qemuCaps, graphics) < 0 ||
|
2016-05-08 16:11:39 +00:00
|
|
|
virQEMUCapsFillDomainDeviceVideoCaps(qemuCaps, video) < 0 ||
|
2016-03-09 18:18:24 +00:00
|
|
|
virQEMUCapsFillDomainDeviceHostdevCaps(qemuCaps, hostdev) < 0 ||
|
|
|
|
virQEMUCapsFillDomainFeatureGICCaps(qemuCaps, domCaps) < 0)
|
2014-09-17 09:33:35 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2014-06-25 16:39:29 +00:00
|
|
|
}
|