[libvirt] [PATCH 4/5] qemu: Check if PCI passhtrough is available in the host when starting

Peter Krempa pkrempa at redhat.com
Fri Sep 20 09:06:59 UTC 2013


Check the presence of the selected PCI passthrough option when starting
a VM.
---
 src/qemu/qemu_process.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index dd16f6c..e36ab99 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3481,6 +3481,8 @@ int qemuProcessStart(virConnectPtr conn,
     unsigned int stop_flags;
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
+    int supportsPassthroughKVM = -1;
+    int supportsPassthroughVFIO = -1;

     /* Okay, these are just internal flags,
      * but doesn't hurt to check */
@@ -3713,6 +3715,45 @@ int qemuProcessStart(virConnectPtr conn,
         goto cleanup;
     }

+    /* assign defaults for hostdev passthrough */
+    for (i = 0; i < vm->def->nhostdevs; i++) {
+        virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
+
+        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+            hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+            int *backend = &hostdev->source.subsys.u.pci.backend;
+
+            /* cache host state of passthrough support */
+            if (supportsPassthroughKVM == -1 || supportsPassthroughVFIO == -1) {
+                supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
+                supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
+            }
+
+            switch ((virDomainHostdevSubsysPciBackendType) *backend) {
+            case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
+                if (!supportsPassthroughVFIO) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("host doesn't support VFIO PCI passthrough"));
+                    goto cleanup;
+                }
+                break;
+
+            case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
+            case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
+                if (!supportsPassthroughKVM) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("host doesn't support legacy PCI passthrough"));
+                    goto cleanup;
+                }
+
+                break;
+
+            case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
+                break;
+            }
+        }
+    }
+
     /*
      * Normally PCI addresses are assigned in the virDomainCreate
      * or virDomainDefine methods. We might still need to assign
-- 
1.8.3.2




More information about the libvir-list mailing list