From: Shalini Chellathurai Saroja <shalini(a)linux.vnet.ibm.com>
Add the function virHostdevIsMdevDevice() which detects whether a
hostdev is a mediated device or not. Also, replace all existing
conditionals.
Signed-off-by: Shalini Chellathurai Saroja <shalini(a)linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk(a)linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy(a)linux.ibm.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_command.c | 4 +---
src/qemu/qemu_domain_address.c | 8 ++++----
src/qemu/qemu_hostdev.c | 3 +--
src/util/virhostdev.c | 26 +++++++++++++++++---------
src/util/virhostdev.h | 3 +++
6 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 92b5e0f..36150a3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1925,6 +1925,7 @@ virHostCPUStatsAssign;
# util/virhostdev.h
virHostdevFindUSBDevice;
+virHostdevIsMdevDevice;
virHostdevIsSCSIDevice;
virHostdevManagerGetDefault;
virHostdevPCINodeDeviceDetach;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 50b0ffc..df1c046 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5294,9 +5294,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
}
/* MDEV */
- if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
-
+ if (virHostdevIsMdevDevice(hostdev)) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO PCI device assignment is not "
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 8a5ff74..50f815c 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -655,10 +655,10 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
virPCIDevicePtr pciDev;
virPCIDeviceAddressPtr hostAddr = &hostdev->source.subsys.u.pci.addr;
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
- (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI
&&
- hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV
&&
- hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST))
{
+ if (!virHostdevIsMdevDevice(hostdev) &&
+ (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+ (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI
&&
+ hostdev->source.subsys.type !=
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST))) {
return 0;
}
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index d2b5460..955b5df 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -339,8 +339,7 @@ qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
supportsVFIO = virFileExists("/dev/vfio/vfio");
for (i = 0; i < nhostdevs; i++) {
- if (hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- hostdevs[i]->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+ if (virHostdevIsMdevDevice(hostdevs[i])) {
if (!supportsVFIO) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Mediated host device assignment requires "
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index db10b7a..f4bd19d 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -372,6 +372,20 @@ virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev)
}
+/**
+ * virHostdevIsMdevDevice:
+ * @hostdev: host device to check
+ *
+ * Returns true if @hostdev is a Mediated device, false otherwise.
+ */
+bool
+virHostdevIsMdevDevice(virDomainHostdevDefPtr hostdev)
+{
+ return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+ hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV;
+}
+
+
static int
virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
virNetDevVPortProfilePtr virtPort,
@@ -1330,10 +1344,8 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManagerPtr mgr,
mdevsrc = &hostdev->source.subsys.u.mdev;
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
- hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+ if (!virHostdevIsMdevDevice(hostdev))
continue;
- }
if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr, mdevsrc->model)))
goto cleanup;
@@ -1828,9 +1840,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr mgr,
virDomainHostdevSubsysMediatedDevPtr src =
&hostdev->source.subsys.u.mdev;
virMediatedDevicePtr mdev;
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
- continue;
- if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+ if (!virHostdevIsMdevDevice(hostdev))
continue;
if (!(mdev = virMediatedDeviceNew(src->uuidstr, src->model)))
@@ -2087,10 +2097,8 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
mdevsrc = &hostdev->source.subsys.u.mdev;
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
- hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+ if (!virHostdevIsMdevDevice(hostdev))
continue;
- }
if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model)))
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 54e1c66..8f77c00 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -191,6 +191,9 @@ virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr,
bool
virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev)
ATTRIBUTE_NONNULL(1);
+bool
+virHostdevIsMdevDevice(virDomainHostdevDefPtr hostdev)
+ ATTRIBUTE_NONNULL(1);
/* functions used by NodeDevDetach/Reattach/Reset */
int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
--
2.9.4