]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hypervisor: move HostdevHostSupportsPassthroughVFIO
authorPraveen K Paladugu <praveenkpaladugu@gmail.com>
Fri, 11 Oct 2024 18:13:03 +0000 (13:13 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 15 Nov 2024 12:15:22 +0000 (13:15 +0100)
Move HostdevHostSupportsPassthroughVFIO method to hypervisor to be
shared between qemu and ch drivers.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hypervisor/virhostdev.c
src/hypervisor/virhostdev.h
src/libvirt_private.syms
src/qemu/qemu_capabilities.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/qemu/qemu_hostdev.c
src/qemu/qemu_hostdev.h
tests/domaincapstest.c

index 4b06e74894420faed9e119d7929acbe889c08f48..db94a2e056a32e60896e228d63f1b1ee73da4af0 100644 (file)
@@ -29,6 +29,7 @@
 #include "virhostdev.h"
 #include "viralloc.h"
 #include "virerror.h"
+#include "virfile.h"
 #include "virlog.h"
 #include "virutil.h"
 #include "virnetdev.h"
@@ -38,6 +39,7 @@
 
 VIR_LOG_INIT("util.hostdev");
 
+#define VIR_DEV_VFIO "/dev/vfio/vfio"
 #define HOSTDEV_STATE_DIR RUNSTATEDIR "/libvirt/hostdevmgr"
 
 static virHostdevManager *manager; /* global hostdev manager, never freed */
@@ -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;
+}
index b9e6108816b3a899ea35f33ccb61740215ab87f6..b7f84735601b2948425186ffc78798ba4687bd67 100644 (file)
@@ -235,3 +235,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManager *hostdev_mgr,
 
 bool
 virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev);
+
+bool virHostdevHostSupportsPassthroughVFIO(void);
index 6616f96712d3452f64a8a7228d1bcf19807f04d2..2f1ccc9d998ee0a666e51f3238fe6027f52265c7 100644 (file)
@@ -1673,6 +1673,7 @@ virCloseCallbacksDomainRunForConn;
 
 # hypervisor/virhostdev.h
 virHostdevFindUSBDevice;
+virHostdevHostSupportsPassthroughVFIO;
 virHostdevManagerGetDefault;
 virHostdevNeedsVFIO;
 virHostdevPCINodeDeviceDetach;
index 6b67da30ec9c0e413b76eccb3709bddc2eae2350..9cdcec8efadc73731417f82401c65dad1ea6377d 100644 (file)
@@ -6430,7 +6430,7 @@ static void
 virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCaps *qemuCaps,
                                        virDomainCapsDeviceHostdev *hostdev)
 {
-    bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
+    bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
 
     hostdev->supported = VIR_TRISTATE_BOOL_YES;
     hostdev->mode.report = true;
index 772ca5578c9456985eed1d4841d917bd247851e0..f3b810a5648180a1caa37c9e45ebb6f0b5f302b5 100644 (file)
@@ -9865,7 +9865,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 */
index 72a9542c0be02f487af54e41eccd0b9be92f02b6..aa8a78da699bc71d8c1c7892db3cbf6d8a73285e 100644 (file)
@@ -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;
index f25ccaf1a40abebf13bd47233230759927789c8c..ab2769d482855bab4e45e8973d387ae50790a0e8 100644 (file)
@@ -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,
index bbf7bb11e782e365d3fa315ca7755539cc836ff6..b6dd2e0207d729dc8f556d74a7e891bf7eea7b08 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "qemu_conf.h"
 
-bool qemuHostdevHostSupportsPassthroughVFIO(void);
-
 int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriver *driver,
                                      virDomainDef *def);
 int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriver *driver,
index e557337617e9011388e5758c8387dbbde29ff607..e520c7d7bcd73728acab9819616aaed1ce880858 100644 (file)
@@ -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,