]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuDomainPrepareHostdevPCI: Simplify error messages
authorPeter Krempa <pkrempa@redhat.com>
Mon, 12 May 2025 13:21:07 +0000 (15:21 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 14 May 2025 14:38:38 +0000 (16:38 +0200)
Rework the error reporting. Unify on one message about device assignment
modes not supported by the qemu driver and move and reword the messages
for VFIO device assignment.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c

index 73869fcfac4d40b6cedfc4b75bf8254940591e9e..5603feaa058ec29b46a980c8c1edeeeac9ccf424 100644 (file)
@@ -9920,40 +9920,19 @@ static int
 qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
                             virQEMUCaps *qemuCaps)
 {
-    bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
     virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name;
 
     /* assign defaults for hostdev passthrough */
     switch (*driverName) {
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
-        if (supportsPassthroughVFIO) {
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
-                *driverName = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
-            } else {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("VFIO PCI device assignment is not supported by this version of QEMU"));
-                return -1;
-            }
-        } else {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("host doesn't support passthrough of host PCI devices"));
-            return -1;
-        }
+        /* Since nowadays only VFIO is supported default to it */
+        *driverName = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
         break;
 
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
-        if (!supportsPassthroughVFIO) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("host doesn't support VFIO PCI passthrough"));
-            return -1;
-        }
         break;
 
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM:
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("host doesn't support legacy PCI passthrough"));
-        return -1;
-
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("QEMU does not support device assignment mode '%1$s'"),
@@ -9966,6 +9945,18 @@ qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
         return -1;
     }
 
+    if (!virHostdevHostSupportsPassthroughVFIO()) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("VFIO PCI device assignment is not supported by the host"));
+        return -1;
+    }
+
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("VFIO PCI device assignment is not supported by this QEMU binary"));
+        return -1;
+    }
+
     return 0;
 }