提交 2b9690b6 编写于 作者: S Shalini Chellathurai Saroja 提交者: John Ferlan

util: virhostdev: add virHostdevIsMdevDevice()

Add the function virHostdevIsMdevDevice() which detects whether a
hostdev is a mediated device or not. Also, replace all existing
conditionals.
Signed-off-by: NShalini Chellathurai Saroja <shalini@linux.vnet.ibm.com>
Reviewed-by: NBjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: NBoris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 263e65fd
......@@ -1928,6 +1928,7 @@ virHostCPUStatsAssign;
# util/virhostdev.h
virHostdevFindUSBDevice;
virHostdevIsMdevDevice;
virHostdevIsSCSIDevice;
virHostdevManagerGetDefault;
virHostdevPCINodeDeviceDetach;
......
......@@ -5326,9 +5326,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 "
......
......@@ -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;
}
......
......@@ -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 "
......
......@@ -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)))
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册