mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
qemu: hostdev: Move parts of qemuHostdevHostSupportsPassthroughVFIO() into separate function
Signed-off-by: Filip Alac <filipalac@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
134c3ddb43
commit
1597e155b2
@ -3076,6 +3076,7 @@ virGetUserName;
|
|||||||
virGetUserRuntimeDirectory;
|
virGetUserRuntimeDirectory;
|
||||||
virGetUserShell;
|
virGetUserShell;
|
||||||
virHexToBin;
|
virHexToBin;
|
||||||
|
virHostHasIOMMU;
|
||||||
virIndexToDiskName;
|
virIndexToDiskName;
|
||||||
virIsDevMapperDevice;
|
virIsDevMapperDevice;
|
||||||
virIsSUID;
|
virIsSUID;
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -124,33 +123,15 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver,
|
|||||||
bool
|
bool
|
||||||
qemuHostdevHostSupportsPassthroughVFIO(void)
|
qemuHostdevHostSupportsPassthroughVFIO(void)
|
||||||
{
|
{
|
||||||
DIR *iommuDir = NULL;
|
/* condition 1 - host has IOMMU */
|
||||||
struct dirent *iommuGroup = NULL;
|
if (!virHostHasIOMMU())
|
||||||
bool ret = false;
|
return 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 2 - /dev/vfio/vfio exists */
|
/* condition 2 - /dev/vfio/vfio exists */
|
||||||
if (!virFileExists("/dev/vfio/vfio"))
|
if (!virFileExists("/dev/vfio/vfio"))
|
||||||
goto cleanup;
|
return false;
|
||||||
|
|
||||||
ret = true;
|
return true;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_DIR_CLOSE(iommuDir);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2090,3 +2090,28 @@ virMemoryMaxValue(bool capped)
|
|||||||
else
|
else
|
||||||
return LLONG_MAX;
|
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;
|
||||||
|
}
|
||||||
|
@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value);
|
|||||||
bool virMemoryLimitIsSet(unsigned long long value);
|
bool virMemoryLimitIsSet(unsigned long long value);
|
||||||
unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE;
|
unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE;
|
||||||
|
|
||||||
|
bool virHostHasIOMMU(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VIR_ASSIGN_IS_OVERFLOW:
|
* VIR_ASSIGN_IS_OVERFLOW:
|
||||||
* @rvalue: value that is checked (evaluated twice)
|
* @rvalue: value that is checked (evaluated twice)
|
||||||
|
Loading…
Reference in New Issue
Block a user