]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: hostdev: Move parts of qemuHostdevHostSupportsPassthroughVFIO() into separate...
authorFilip Alac <filipalac@gmail.com>
Fri, 1 Jun 2018 08:15:58 +0000 (10:15 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Jun 2018 06:33:13 +0000 (08:33 +0200)
Signed-off-by: Filip Alac <filipalac@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_hostdev.c
src/util/virutil.c
src/util/virutil.h

index 059229ff70472146dee5dd5ad3053db09955b10f..9b9970163f57e387246f02d39f0bb91b0f8aa109 100644 (file)
@@ -3076,6 +3076,7 @@ virGetUserName;
 virGetUserRuntimeDirectory;
 virGetUserShell;
 virHexToBin;
+virHostHasIOMMU;
 virIndexToDiskName;
 virIsDevMapperDevice;
 virIsSUID;
index 955b5df1a33e27ebdcc81c56cae2b81ff9ca0c0d..1e040f98b79f656707c96b71a666534ad3b202b2 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <config.h>
 
-#include <dirent.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <errno.h>
@@ -124,33 +123,15 @@ qemuHostdevUpdateActiveDomainDevices(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 (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;
 }
 
 
index bb4474acd53ad98f388fd68067f0e29e29302d65..a908422feb7f2ed4f6a7b33b68ec8c5e8507d6d7 100644 (file)
@@ -2090,3 +2090,28 @@ virMemoryMaxValue(bool capped)
     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;
+}
index be0f6b0ea855c75b792f452a7813186087c2c0be..1ba9635bd9912cd948ac7189f5442a35fdbf6c7e 100644 (file)
@@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value);
 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)