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.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy(a)linux.vnet.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 cab324c4d7..fe35640af1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1926,6 +1926,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 514c3ab2ef..e47f915fc8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5346,9 +5346,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 ae6c59bb01..8acd5a7b71 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 afe445d4e7..ab76e35a23 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 a12224c58f..b28dc29a41 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -375,6 +375,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,
@@ -1333,10 +1347,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;
@@ -1831,9 +1843,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)))
@@ -2090,10 +2100,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 54e1c66be3..8f77c00221 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.13.4