virsh command domxml-to-native failed with below error but start
command suceed for same domain xml.
"internal error: invalid PCI passthrough type 'default'"
If host pci device's driver attribute isn't defined in domain xml,
qemu driver will choose a proper value based on host environment
before starting qemu process. But this is missed in domxml-to-native
command, add the same logic so domxml-to-native could pass.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan(a)intel.com>
---
src/qemu/qemu_domain.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 63b13b6875c9..517c90f93f0a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11274,6 +11274,17 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *hostdev,
}
}
}
+ if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+ hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+ bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
+ virDomainHostdevSubsysPCIBackendType *backend =
&hostdev->source.subsys.u.pci.backend;
+
+ if (*backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT &&
+ supportsPassthroughVFIO &&
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+ *backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
+ }
+ }
return 0;
}
--
2.25.1