Move HostdevHostSupportsPassthroughVFIO method to hypervisor to be shared between qemu and ch drivers. Signed-off-by: Praveen K Paladugu <prapal@xxxxxxxxxxxxxxxxxxx> --- src/hypervisor/virhostdev.c | 16 ++++++++++++++++ src/hypervisor/virhostdev.h | 2 ++ src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_hostdev.c | 15 --------------- src/qemu/qemu_hostdev.h | 2 -- tests/domaincapstest.c | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 4b06e74894..220578f0c0 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -29,12 +29,14 @@ #include "virhostdev.h" #include "viralloc.h" #include "virerror.h" +#include "virfile.h" #include "virlog.h" #include "virutil.h" #include "virnetdev.h" #include "configmake.h" #define VIR_FROM_THIS VIR_FROM_NONE +#define VIR_DEV_VFIO "/dev/vfio/vfio" VIR_LOG_INIT("util.hostdev"); @@ -2519,3 +2521,17 @@ virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev) return virHostdevIsPCIDevice(hostdev) || virHostdevIsMdevDevice(hostdev); } + +bool +virHostdevHostSupportsPassthroughVFIO(void) +{ + /* condition 1 - host has IOMMU */ + if (!virHostHasIOMMU()) + return false; + + /* condition 2 - /dev/vfio/vfio exists */ + if (!virFileExists(VIR_DEV_VFIO)) + return false; + + return true; +} diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index b9e6108816..b7f8473560 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -235,3 +235,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManager *hostdev_mgr, bool virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev); + +bool virHostdevHostSupportsPassthroughVFIO(void); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cca071f866..39988cf0f4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1669,6 +1669,7 @@ virCloseCallbacksDomainRunForConn; # hypervisor/virhostdev.h virHostdevFindUSBDevice; +virHostdevHostSupportsPassthroughVFIO; virHostdevManagerGetDefault; virHostdevNeedsVFIO; virHostdevPCINodeDeviceDetach; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ac135aa301..e2f97c3d9a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -6378,7 +6378,7 @@ static void virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCaps *qemuCaps, virDomainCapsDeviceHostdev *hostdev) { - bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); + bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO(); hostdev->supported = VIR_TRISTATE_BOOL_YES; hostdev->mode.report = true; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fda4439b0b..065a37445e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11698,7 +11698,7 @@ static int qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev, virQEMUCaps *qemuCaps) { - bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); + bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO(); virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name; /* assign defaults for hostdev passthrough */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f27c21ca8c..e0adebf7ea 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11482,7 +11482,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, * further validation until then. */ - if (!qemuHostdevHostSupportsPassthroughVFIO()) { + if (!virHostdevHostSupportsPassthroughVFIO()) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("VFIO device assignment is currently not supported on this system")); return -1; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index f25ccaf1a4..ab2769d482 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -130,21 +130,6 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriver *driver, } -bool -qemuHostdevHostSupportsPassthroughVFIO(void) -{ - /* condition 1 - host has IOMMU */ - if (!virHostHasIOMMU()) - return false; - - /* condition 2 - /dev/vfio/vfio exists */ - if (!virFileExists(QEMU_DEV_VFIO)) - return false; - - return true; -} - - int qemuHostdevPrepareOneNVMeDisk(virQEMUDriver *driver, const char *name, diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index bbf7bb11e7..b6dd2e0207 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -23,8 +23,6 @@ #include "qemu_conf.h" -bool qemuHostdevHostSupportsPassthroughVFIO(void); - int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriver *driver, virDomainDef *def); int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriver *driver, diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index e557337617..e520c7d7bc 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -105,7 +105,7 @@ fillQemuCaps(virDomainCaps *domCaps, return -1; /* The function above tries to query host's VFIO capabilities by calling - * qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be + * virHostdevHostSupportsPassthroughVFIO() which, however, can't be * successfully mocked as they are not exposed as internal APIs. Therefore, * instead of mocking set the expected values here by hand. */ VIR_DOMAIN_CAPS_ENUM_SET(domCaps->hostdev.pciBackend, -- 2.44.0