mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
qemu: bind/unbind stub driver according to config <driver name='x'/>
If the config for a device has specified <driver name='vfio'/>, "backend" in the pci part of the hostdev object will be set to ..._VFIO. In this case, when creating a virPCIDevice set the stubDriver to "vfio-pci", otherwise set it to "pci-stub". We will rely on the lower levels to report an error if the vfio driver isn't loaded. The detach/attach functions in virpci.c will pay attention to the stubDriver setting in the device, and bind/unbind the appropriate driver when preparing hostdevs for the domain. Note that we don't yet attempt to do anything to mark active any other devices in the same vfio "group" as a single device that is being marked active. We do need to do that, but in order to get basic VFIO functionality testing sooner rather than later, initially we'll just live with more cryptic errors when someone tries to do that.
This commit is contained in:
parent
be64199e17
commit
cc0a918872
@ -67,6 +67,12 @@ qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
|
||||
}
|
||||
|
||||
virPCIDeviceSetManaged(dev, hostdev->managed);
|
||||
if (hostdev->source.subsys.u.pci.backend
|
||||
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_VFIO) {
|
||||
virPCIDeviceSetStubDriver(dev, "vfio-pci");
|
||||
} else {
|
||||
virPCIDeviceSetStubDriver(dev, "pci-stub");
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -150,6 +156,12 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
|
||||
goto cleanup;
|
||||
|
||||
virPCIDeviceSetManaged(dev, hostdev->managed);
|
||||
if (hostdev->source.subsys.u.pci.backend
|
||||
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_VFIO) {
|
||||
virPCIDeviceSetStubDriver(dev, "vfio-pci");
|
||||
} else {
|
||||
virPCIDeviceSetStubDriver(dev, "pci-stub");
|
||||
}
|
||||
virPCIDeviceSetUsedBy(dev, def->name);
|
||||
|
||||
/* Setup the original states for the PCI device */
|
||||
@ -472,11 +484,11 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop 2: detach managed devices */
|
||||
/* Loop 2: detach managed devices (i.e. bind to appropriate stub driver) */
|
||||
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
|
||||
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
|
||||
if (virPCIDeviceGetManaged(dev) &&
|
||||
virPCIDeviceDetach(dev, driver->activePciHostdevs, NULL, "pci-stub") < 0)
|
||||
virPCIDeviceDetach(dev, driver->activePciHostdevs, NULL, NULL) < 0)
|
||||
goto reattachdevs;
|
||||
}
|
||||
|
||||
@ -593,7 +605,11 @@ resetvfnetconfig:
|
||||
reattachdevs:
|
||||
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
|
||||
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
|
||||
virPCIDeviceReattach(dev, driver->activePciHostdevs, NULL, "pci-stub");
|
||||
|
||||
/* NB: This doesn't actually re-bind to original driver, just
|
||||
* unbinds from the stub driver
|
||||
*/
|
||||
virPCIDeviceReattach(dev, driver->activePciHostdevs, NULL, NULL);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
Loading…
x
Reference in New Issue
Block a user