]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Don't detach devices if passthrough doesn't work
authorJincheng Miao <jmiao@redhat.com>
Thu, 16 Jan 2014 08:59:50 +0000 (16:59 +0800)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 20 Jan 2014 12:58:04 +0000 (13:58 +0100)
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>
src/qemu/qemu_driver.c

index df4f5b56c6eea42315524caf814f8c882fab67d7..46dad90ad135b6281e562b9dfb9c80563546f9cf 100644 (file)
@@ -11155,6 +11155,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
     char *xml = NULL;
+    bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
+    bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
 
     virCheckFlags(0, -1);
 
@@ -11177,22 +11179,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 {