This piece of code will be re-used later.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 17 +++++++++++++++++
src/conf/domain_conf.h | 3 +++
src/libvirt_private.syms | 1 +
src/qemu/qemu_domain.c | 13 ++-----------
4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1b6ee3bfa6..e71e484a6f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31445,6 +31445,23 @@ virDomainDefHasNVMeDisk(const virDomainDef *def)
}
+bool
+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)
+ return true;
+ }
+
+ return false;
+}
+
+
/**
* virDomainGraphicsDefHasOpenGL:
* @def: domain definition
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2a067633bd..5c6c5b7a33 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3614,6 +3614,9 @@ virDomainDefHasManagedPR(const virDomainDef *def);
bool
virDomainDefHasNVMeDisk(const virDomainDef *def);
+bool
+virDomainDefHasVFIOHostdev(const virDomainDef *def);
+
bool
virDomainGraphicsDefHasOpenGL(const virDomainDef *def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 15bfae115f..4fda747fb3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -287,6 +287,7 @@ virDomainDefHasMemoryHotplug;
virDomainDefHasNVMeDisk;
virDomainDefHasUSB;
virDomainDefHasVcpusOffline;
+virDomainDefHasVFIOHostdev;
virDomainDefLifecycleActionAllowed;
virDomainDefMaybeAddController;
virDomainDefMaybeAddInput;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 09e5ee37f4..2a7f09ce24 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11764,7 +11764,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
bool includeVFIO = false;
char **tmpPaths = NULL;
int *tmpPerms = NULL;
- size_t i, tmpNpaths = 0;
+ size_t tmpNpaths = 0;
int perm = 0;
*npaths = 0;
@@ -11787,16 +11787,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
perm = VIR_CGROUP_DEVICE_RW;
if (teardown) {
- size_t nvfios = 0;
- for (i = 0; i < def->nhostdevs; i++) {
- virDomainHostdevDefPtr 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)
- nvfios++;
- }
-
- if (nvfios == 0)
+ if (!virDomainDefHasVFIOHostdev(def))
includeVFIO = true;
} else {
includeVFIO = true;
--
2.21.0