On 9/26/19 12:11 PM, Michal Privoznik wrote:
In some places we need to check if a hostdev has VFIO backend.
Because of how complicated virDomainHostdevDef structure is, the
check consists of three lines. Move them to a function and
replace all checks with the function call.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 5 +----
src/libvirt_private.syms | 1 +
src/qemu/qemu_cgroup.c | 4 +---
src/qemu/qemu_domain.c | 12 +++---------
src/qemu/qemu_hotplug.c | 8 +-------
src/util/virhostdev.c | 15 +++++++++++++++
src/util/virhostdev.h | 3 +++
7 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c290baf953..adf8455579 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31550,10 +31550,7 @@ virDomainDefHasVFIOHostdev(const virDomainDef *def)
size_t i;
for (i = 0; i < def->nhostdevs; i++) {
- const virDomainHostdevDef *tmp = def->hostdevs[i];
- if (tmp->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- tmp->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
- tmp->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)
+ if (virHostdevIsVFIODevice(def->hostdevs[i]))
return true;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 287e63bffa..ac37aea626 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2104,6 +2104,7 @@ virHostCPUStatsAssign;
virHostdevFindUSBDevice;
virHostdevIsMdevDevice;
virHostdevIsSCSIDevice;
+virHostdevIsVFIODevice;
virHostdevManagerGetDefault;
virHostdevPCINodeDeviceDetach;
virHostdevPCINodeDeviceReAttach;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 740a1b33dc..318157dab0 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -413,9 +413,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES))
return 0;
- if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
- dev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO
&&
+ if (virHostdevIsVFIODevice(dev) &&
qemuDomainGetHostdevPath(vm->def, dev, true,
&npaths, &path, NULL) < 0)
goto cleanup;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2aa2164953..824bca89f4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11871,9 +11871,7 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def)
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDefPtr dev = def->hostdevs[i];
- if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
- dev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)
{
+ if (virHostdevIsVFIODevice(dev)) {
usesVFIO = true;
pciAddr = &dev->source.subsys.u.pci.addr;
@@ -12025,12 +12023,8 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
* Note that this may not be valid for all platforms.
*/
for (i = 0; i < def->nhostdevs; i++) {
- virDomainHostdevSubsysPtr subsys = &def->hostdevs[i]->source.subsys;
-
- if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV ||
- (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
- subsys->u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO))) {
+ if (virHostdevIsVFIODevice(def->hostdevs[i]) ||
+ virHostdevIsMdevDevice(def->hostdevs[i])) {
memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
goto done;
}
I see a sneaky IsMdev conversion in there, but I don't mind ;)
Reviewed-by: Cole Robinson <crobinso(a)redhat.com>
- Cole