#include <config.h>
-#include <dirent.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
bool
qemuHostdevHostSupportsPassthroughVFIO(void)
{
- DIR *iommuDir = NULL;
- struct dirent *iommuGroup = NULL;
- bool ret = false;
- int direrr;
-
- /* condition 1 - /sys/kernel/iommu_groups/ contains entries */
- if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
- goto cleanup;
-
- while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
- /* assume we found a group */
- break;
- }
-
- if (direrr < 0 || !iommuGroup)
- goto cleanup;
- /* okay, iommu is on and recognizes groups */
+ /* condition 1 - host has IOMMU */
+ if (!virHostHasIOMMU())
+ return false;
/* condition 2 - /dev/vfio/vfio exists */
if (!virFileExists("/dev/vfio/vfio"))
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- VIR_DIR_CLOSE(iommuDir);
- return ret;
+ return true;
}
else
return LLONG_MAX;
}
+
+
+bool
+virHostHasIOMMU(void)
+{
+ DIR *iommuDir = NULL;
+ struct dirent *iommuGroup = NULL;
+ bool ret = false;
+ int direrr;
+
+ if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
+ goto cleanup;
+
+ while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0)
+ break;
+
+ if (direrr < 0 || !iommuGroup)
+ goto cleanup;
+
+ ret = true;
+
+ cleanup:
+ VIR_DIR_CLOSE(iommuDir);
+ return ret;
+}
bool virMemoryLimitIsSet(unsigned long long value);
unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE;
+bool virHostHasIOMMU(void);
+
/**
* VIR_ASSIGN_IS_OVERFLOW:
* @rvalue: value that is checked (evaluated twice)