提交 df802272 编写于 作者: J Jincheng Miao 提交者: Jiri Denemark

qemu: Don't detach devices if passthrough doesn't work

https://bugzilla.redhat.com/show_bug.cgi?id=1046919

If none (KVM, VFIO) of the supported PCI passthrough methods is known to
work on a host, it's better to fail right away with a nice error message
rather than letting attachment fail with a more cryptic message such as

    Failed to bind PCI device '0000:07:05.0' to vfio-pci: No such device
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 d8ab981b
...@@ -11155,6 +11155,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, ...@@ -11155,6 +11155,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
int ret = -1; int ret = -1;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *xml = NULL; char *xml = NULL;
bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virCheckFlags(0, -1); virCheckFlags(0, -1);
...@@ -11177,22 +11179,34 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, ...@@ -11177,22 +11179,34 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
goto cleanup; goto cleanup;
if (!driverName) { if (!driverName) {
/* prefer vfio */ if (vfio) {
if (qemuHostdevHostSupportsPassthroughVFIO())
driverName = "vfio"; driverName = "vfio";
else if (qemuHostdevHostSupportsPassthroughLegacy()) } else if (legacy) {
driverName = "kvm"; driverName = "kvm";
} else {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("neither VFIO nor KVM device assignment is "
"currently supported on this system"));
goto cleanup;
}
} }
if (!driverName) { if (STREQ(driverName, "vfio")) {
virReportError(VIR_ERR_INVALID_ARG, "%s", if (!vfio) {
_("neither VFIO nor kvm device assignment is " virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
"currently supported on this system")); _("VFIO device assignment is currently not "
goto cleanup; "supported on this system"));
} else if (STREQ(driverName, "vfio")) { goto cleanup;
}
if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0) if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
goto cleanup; goto cleanup;
} else if (STREQ(driverName, "kvm")) { } else if (STREQ(driverName, "kvm")) {
if (!legacy) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("KVM device assignment is currently not "
"supported on this system"));
goto cleanup;
}
if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0) if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
goto cleanup; goto cleanup;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册