The functions in question are qemuHostdevHostSupportsPassthroughLegacy and qemuHostdevHostSupportsPassthroughVFIO. At the same time the functions are renamed to match 'vir' prefix instead of 'qemu' one. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/libvirt_private.syms | 2 ++ src/qemu/qemu_driver.c | 4 +-- src/qemu/qemu_hostdev.c | 76 ++---------------------------------------------- src/qemu/qemu_hostdev.h | 2 -- src/util/virhostdev.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 4 +++ 6 files changed, 83 insertions(+), 78 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ac56782..1d29f15 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1345,6 +1345,8 @@ virHookPresent; # util/virhostdev.h +virHostdevHostSupportsPassthroughLegacy; +virHostdevHostSupportsPassthroughVFIO; virHostdevManagerGetDefault; virHostdevPCINodeDeviceDetach; virHostdevPCINodeDeviceReAttach; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 22a8ca5..ac6aee5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11355,8 +11355,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, int ret = -1; virNodeDeviceDefPtr def = NULL; char *xml = NULL; - bool legacy = qemuHostdevHostSupportsPassthroughLegacy(); - bool vfio = qemuHostdevHostSupportsPassthroughVFIO(); + bool legacy = virHostdevHostSupportsPassthroughLegacy(); + bool vfio = virHostdevHostSupportsPassthroughVFIO(); virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virCheckFlags(0, -1); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 706db0c..39dacb2 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -23,7 +23,6 @@ #include <config.h> -#include <dirent.h> #include <fcntl.h> #include <sys/ioctl.h> #include <errno.h> @@ -84,84 +83,13 @@ qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver, } -bool -qemuHostdevHostSupportsPassthroughVFIO(void) -{ - DIR *iommuDir = NULL; - struct dirent *iommuGroup = NULL; - bool ret = false; - int direrr; - - /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ - if (!(iommuDir = opendir("/sys/kernel/iommu_groups/"))) - goto cleanup; - - while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { - /* skip ./ ../ */ - if (STRPREFIX(iommuGroup->d_name, ".")) - continue; - - /* assume we found a group */ - break; - } - - if (direrr < 0 || !iommuGroup) - goto cleanup; - /* okay, iommu is on and recognizes groups */ - - /* condition 2 - /dev/vfio/vfio exists */ - if (!virFileExists("/dev/vfio/vfio")) - goto cleanup; - - ret = true; - - cleanup: - if (iommuDir) - closedir(iommuDir); - - return ret; -} - - -#if HAVE_LINUX_KVM_H -# include <linux/kvm.h> -bool -qemuHostdevHostSupportsPassthroughLegacy(void) -{ - int kvmfd = -1; - bool ret = false; - - if ((kvmfd = open("/dev/kvm", O_RDONLY)) < 0) - goto cleanup; - -# ifdef KVM_CAP_IOMMU - if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <= 0) - goto cleanup; - - ret = true; -# endif - - cleanup: - VIR_FORCE_CLOSE(kvmfd); - - return ret; -} -#else -bool -qemuHostdevHostSupportsPassthroughLegacy(void) -{ - return false; -} -#endif - - static bool qemuPrepareHostdevPCICheckSupport(virDomainHostdevDefPtr *hostdevs, size_t nhostdevs, virQEMUCapsPtr qemuCaps) { - bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy(); - bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); + bool supportsPassthroughKVM = virHostdevHostSupportsPassthroughLegacy(); + bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO(); size_t i; /* assign defaults for hostdev passthrough */ diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 05bd965..75cec9c 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -33,8 +33,6 @@ int qemuUpdateActiveUSBHostdevs(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver, virDomainDefPtr def); -bool qemuHostdevHostSupportsPassthroughLegacy(void); -bool qemuHostdevHostSupportsPassthroughVFIO(void); int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver, const char *name, const unsigned char *uuid, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 9dd1df2..f791a10 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -24,6 +24,7 @@ #include <config.h> +#include <dirent.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/types.h> @@ -32,6 +33,10 @@ #include <stdlib.h> #include <stdio.h> +#if HAVE_LINUX_KVM_H +# include <linux/kvm.h> +#endif + #include "virhostdev.h" #include "viralloc.h" #include "virstring.h" @@ -1635,3 +1640,71 @@ virHostdevUpdateDomainActiveDevices(virHostdevManagerPtr mgr, return 0; } + +#if HAVE_LINUX_KVM_H +bool +virHostdevHostSupportsPassthroughLegacy(void) +{ + int kvmfd = -1; + bool ret = false; + + if ((kvmfd = open("/dev/kvm", O_RDONLY)) < 0) + goto cleanup; + +# ifdef KVM_CAP_IOMMU + if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <= 0) + goto cleanup; + + ret = true; +# endif + + cleanup: + VIR_FORCE_CLOSE(kvmfd); + + return ret; +} +#else +bool +virHostdevHostSupportsPassthroughLegacy(void) +{ + return false; +} +#endif + +bool +virHostdevHostSupportsPassthroughVFIO(void) +{ + DIR *iommuDir = NULL; + struct dirent *iommuGroup = NULL; + bool ret = false; + int direrr; + + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ + if (!(iommuDir = opendir("/sys/kernel/iommu_groups/"))) + goto cleanup; + + while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { + /* skip ./ ../ */ + if (STRPREFIX(iommuGroup->d_name, ".")) + continue; + + /* assume we found a group */ + break; + } + + if (direrr < 0 || !iommuGroup) + goto cleanup; + /* okay, iommu is on and recognizes groups */ + + /* condition 2 - /dev/vfio/vfio exists */ + if (!virFileExists("/dev/vfio/vfio")) + goto cleanup; + + ret = true; + + cleanup: + if (iommuDir) + closedir(iommuDir); + + return ret; +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 2036430..99640f5 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -155,4 +155,8 @@ int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +/* KVM related functions */ +bool virHostdevHostSupportsPassthroughLegacy(void); +bool virHostdevHostSupportsPassthroughVFIO(void); + #endif /* __VIR_HOSTDEV_H__ */ -- 1.8.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list