提交 66b46932 编写于 作者: C Chunyan Liu 提交者: Laine Stump

pass stub driver name instead of pciFindStubDriver

Pass stub driver name directly to pciDettachDevice and pciReAttachDevice to fit
for different libvirt drivers. For example, qemu driver prefers pci-stub, but
Xen prefers pciback.
Signed-off-by: NChunyan Liu <cyliu@suse.com>
上级 fc66c160
......@@ -10022,7 +10022,7 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
in_inactive_list = pciDeviceListFind(driver->inactivePciHostdevs, pci);
if (pciDettachDevice(pci, driver->activePciHostdevs,
driver->inactivePciHostdevs) < 0)
driver->inactivePciHostdevs, "pci-stub") < 0)
goto out;
ret = 0;
......@@ -10067,7 +10067,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
qemuDriverLock(driver);
if (pciReAttachDevice(pci, driver->activePciHostdevs,
driver->inactivePciHostdevs) < 0)
driver->inactivePciHostdevs, "pci-stub") < 0)
goto out;
ret = 0;
......
......@@ -458,7 +458,7 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
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;
}
......@@ -574,7 +574,7 @@ resetvfnetconfig:
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:
......@@ -830,7 +830,7 @@ void qemuReattachPciDevice(pciDevice *dev, virQEMUDriverPtr driver)
}
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"));
......
......@@ -855,57 +855,35 @@ pciDeviceFile(char **buffer, const char *device, const char *file)
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
......@@ -1149,12 +1127,12 @@ cleanup:
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;
}
......@@ -1179,12 +1157,12 @@ pciDettachDevice(pciDevice *dev,
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;
}
......
......@@ -44,10 +44,12 @@ void pciFreeDevice (pciDevice *dev);
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);
......
......@@ -2113,7 +2113,7 @@ xenUnifiedNodeDeviceDettach(virNodeDevicePtr dev)
if (!pci)
return -1;
if (pciDettachDevice(pci, NULL, NULL) < 0)
if (pciDettachDevice(pci, NULL, NULL, "pciback") < 0)
goto out;
ret = 0;
......@@ -2203,7 +2203,7 @@ xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev)
goto out;
}
if (pciReAttachDevice(pci, NULL, NULL) < 0)
if (pciReAttachDevice(pci, NULL, NULL, "pciback") < 0)
goto out;
ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册