From d7e2761eba3655f898fca5388be26ab5c0469d48 Mon Sep 17 00:00:00 2001
Message-Id: <d7e2761eba3655f898fca5388be26ab5c0469d48.1390394206.git.jdenemar@redhat.com>
From: Jincheng Miao <jmiao@redhat.com>
Date: Mon, 20 Jan 2014 14:41:13 +0100
Subject: [PATCH] qemu: Don't detach devices if passthrough doesn't work
https://bugzilla.redhat.com/show_bug.cgi?id=1046919
If none (KVM, VFIO) of the supported PCI passthrough methods is known to
work on a host, it's better to fail right away with a nice error message
rather than letting attachment fail with a more cryptic message such as
Failed to bind PCI device '0000:07:05.0' to vfio-pci: No such device
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit df8022721ef09b2e0bd06e16c7d45ff99034f761)
---
src/qemu/qemu_driver.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a9368b1..b542414 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11065,6 +11065,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
int ret = -1;
virNodeDeviceDefPtr def = NULL;
char *xml = NULL;
+ bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
+ bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virCheckFlags(0, -1);
@@ -11087,22 +11089,34 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
goto cleanup;
if (!driverName) {
- /* prefer vfio */
- if (qemuHostdevHostSupportsPassthroughVFIO())
+ if (vfio) {
driverName = "vfio";
- else if (qemuHostdevHostSupportsPassthroughLegacy())
+ } else if (legacy) {
driverName = "kvm";
+ } else {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("neither VFIO nor KVM device assignment is "
+ "currently supported on this system"));
+ goto cleanup;
+ }
}
- if (!driverName) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("neither VFIO nor kvm device assignment is "
- "currently supported on this system"));
- goto cleanup;
- } else if (STREQ(driverName, "vfio")) {
+ if (STREQ(driverName, "vfio")) {
+ if (!vfio) {
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+ _("VFIO device assignment is currently not "
+ "supported on this system"));
+ goto cleanup;
+ }
if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
goto cleanup;
} else if (STREQ(driverName, "kvm")) {
+ if (!legacy) {
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+ _("KVM device assignment is currently not "
+ "supported on this system"));
+ goto cleanup;
+ }
if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
goto cleanup;
} else {
--
1.8.5.3