From 6db8dc63bc6078cb8509af7a7110f23f2ed8e464 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 12 May 2025 15:21:07 +0200 Subject: [PATCH] qemuDomainPrepareHostdevPCI: Simplify error messages 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 Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 73869fcfac..5603feaa05 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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; } -- 2.47.3