mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
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: Chunyan Liu <cyliu@suse.com>
This commit is contained in:
parent
fc66c1603c
commit
66b4693269
@ -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)) {
|
||||
if (pciDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) {
|
||||
/* driver already loaded, return */
|
||||
VIR_FREE(drvpath);
|
||||
return "pci-stub";
|
||||
}
|
||||
|
||||
if (pciDriverDir(&drvpath, "pciback") < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virFileExists(drvpath)) {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user