tests/virhostdevtest.c implements a function called
'virHostdevHostSupportsPassthroughKVM', that is equal to
'qemuHostdevHostSupportsPassthroughLegacy' that is declared
inside qemu/qemu_hostdev.c.
This patch removes the duplicated code from both files and
and puts it inside util/virhostdev.c, under the name
virHostdev...KVM, which represents what the code does better
than using 'Legacy'.
Based-on-work-of: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_capabilities.c | 2 +-
src/qemu/qemu_driver.c | 6 +++---
src/qemu/qemu_hostdev.c | 34 +---------------------------------
src/qemu/qemu_hostdev.h | 1 -
src/util/virhostdev.c | 31 +++++++++++++++++++++++++++++++
src/util/virhostdev.h | 1 +
tests/virhostdevtest.c | 31 -------------------------------
8 files changed, 38 insertions(+), 69 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a03cf0b645..a6747684ea 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2044,6 +2044,7 @@ virHostCPUStatsAssign;
# util/virhostdev.h
virHostdevFindUSBDevice;
+virHostdevHostSupportsPassthroughKVM;
virHostdevIsMdevDevice;
virHostdevIsSCSIDevice;
virHostdevManagerGetDefault;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a0b2ca73fb..515db0112f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -5152,7 +5152,7 @@ static int
virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsDeviceHostdevPtr hostdev)
{
- bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
+ bool supportsPassthroughKVM = virHostdevHostSupportsPassthroughKVM();
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
hostdev->supported = VIR_TRISTATE_BOOL_YES;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b2ac737d1f..c02482337a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13283,7 +13283,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
int ret = -1;
virNodeDeviceDefPtr def = NULL;
char *xml = NULL;
- bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
+ bool kvm = virHostdevHostSupportsPassthroughKVM();
bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
@@ -13310,7 +13310,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
if (!driverName) {
if (vfio) {
driverName = "vfio";
- } else if (legacy) {
+ } else if (kvm) {
driverName = "kvm";
} else {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@@ -13329,7 +13329,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
}
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
} else if (STREQ(driverName, "kvm")) {
- if (!legacy) {
+ if (!kvm) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("KVM device assignment is currently not "
"supported on this system"));
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 4eb3f1d7f1..b6cb4d0980 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -132,44 +132,12 @@ qemuHostdevHostSupportsPassthroughVFIO(void)
}
-#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
qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
size_t nhostdevs,
virQEMUCapsPtr qemuCaps)
{
- bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
+ bool supportsPassthroughKVM = virHostdevHostSupportsPassthroughKVM();
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
size_t i;
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 41f254ab81..be6faa2c35 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -25,7 +25,6 @@
# include "qemu_conf.h"
# include "domain_conf.h"
-bool qemuHostdevHostSupportsPassthroughLegacy(void);
bool qemuHostdevHostSupportsPassthroughVFIO(void);
int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 19ae001971..872528fdb2 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -2245,3 +2245,34 @@ virHostdevUpdateActiveDomainDevices(virHostdevManagerPtr mgr,
return 0;
}
+
+#if HAVE_LINUX_KVM_H
+# include <linux/kvm.h>
+bool
+virHostdevHostSupportsPassthroughKVM(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
+virHostdevHostSupportsPassthroughKVM(void)
+{
+ return false;
+}
+#endif
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 7263f320a2..32fa36cdef 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -203,4 +203,5 @@ int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr,
virPCIDevicePtr pci)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+bool virHostdevHostSupportsPassthroughKVM(void);
#endif /* LIBVIRT_VIRHOSTDEV_H */
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index 4e067b10d1..1258338949 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -126,37 +126,6 @@ myInit(void)
return -1;
}
-# if HAVE_LINUX_KVM_H
-# include <linux/kvm.h>
-static bool
-virHostdevHostSupportsPassthroughKVM(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
-static bool
-virHostdevHostSupportsPassthroughKVM(void)
-{
- return false;
-}
-# endif
-
static int
testVirHostdevPreparePCIHostdevs_unmanaged(void)
{
--
2.20.1