for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
if (pciDeviceGetManaged(dev) &&
- pciDettachDevice(dev, driver->activePciHostdevs, NULL) < 0)
+ pciDettachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub") < 0)
goto reattachdevs;
}
reattachdevs:
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
- pciReAttachDevice(dev, driver->activePciHostdevs, NULL);
+ pciReAttachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub");
}
cleanup:
}
if (pciReAttachDevice(dev, driver->activePciHostdevs,
- driver->inactivePciHostdevs) < 0) {
+ driver->inactivePciHostdevs, "pci-stub") < 0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
err ? err->message : _("unknown error"));
return 0;
}
-
-static const char *
-pciFindStubDriver(void)
+static int
+pciProbeStubDriver(const char *driver)
{
char *drvpath = NULL;
int probed = 0;
recheck:
- if (pciDriverDir(&drvpath, "pci-stub") < 0) {
- return NULL;
- }
-
- if (virFileExists(drvpath)) {
- VIR_FREE(drvpath);
- return "pci-stub";
- }
-
- if (pciDriverDir(&drvpath, "pciback") < 0) {
- return NULL;
- }
-
- if (virFileExists(drvpath)) {
+ if (pciDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) {
+ /* driver already loaded, return */
VIR_FREE(drvpath);
- return "pciback";
+ return 0;
}
VIR_FREE(drvpath);
if (!probed) {
- const char *const stubprobe[] = { MODPROBE, "pci-stub", NULL };
- const char *const backprobe[] = { MODPROBE, "pciback", NULL };
-
+ const char *const probecmd[] = { MODPROBE, driver, NULL };
probed = 1;
- /*
- * Probing for pci-stub will succeed regardless of whether
- * on native or Xen kernels.
- * On Xen though, we want to prefer pciback, so probe
- * for that first, because that will only work on Xen
- */
- if (virRun(backprobe, NULL) < 0 &&
- virRun(stubprobe, NULL) < 0) {
+ if (virRun(probecmd, NULL) < 0) {
char ebuf[1024];
- VIR_WARN("failed to load pci-stub or pciback drivers: %s",
+ VIR_WARN("failed to load driver %s: %s", driver,
virStrerror(errno, ebuf, sizeof(ebuf)));
- return NULL;
+ return -1;
}
goto recheck;
}
- return NULL;
+ return -1;
}
static int
int
pciDettachDevice(pciDevice *dev,
pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs)
+ pciDeviceList *inactiveDevs,
+ const char *driver)
{
- const char *driver = pciFindStubDriver();
- if (!driver) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot find any PCI stub module"));
+ if (pciProbeStubDriver(driver) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to load PCI stub module %s"), driver);
return -1;
}
int
pciReAttachDevice(pciDevice *dev,
pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs)
+ pciDeviceList *inactiveDevs,
+ const char *driver)
{
- const char *driver = pciFindStubDriver();
- if (!driver) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot find any PCI stub module"));
+ if (pciProbeStubDriver(driver) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to load PCI stub module %s"), driver);
return -1;
}
const char *pciDeviceGetName (pciDevice *dev);
int pciDettachDevice (pciDevice *dev,
pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs);
+ pciDeviceList *inactiveDevs,
+ const char *driver);
int pciReAttachDevice (pciDevice *dev,
pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs);
+ pciDeviceList *inactiveDevs,
+ const char *driver);
int pciResetDevice (pciDevice *dev,
pciDeviceList *activeDevs,
pciDeviceList *inactiveDevs);