render / rpms / libvirt

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