mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 03:42:19 +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);
|
in_inactive_list = pciDeviceListFind(driver->inactivePciHostdevs, pci);
|
||||||
|
|
||||||
if (pciDettachDevice(pci, driver->activePciHostdevs,
|
if (pciDettachDevice(pci, driver->activePciHostdevs,
|
||||||
driver->inactivePciHostdevs) < 0)
|
driver->inactivePciHostdevs, "pci-stub") < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -10067,7 +10067,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
|
|||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
if (pciReAttachDevice(pci, driver->activePciHostdevs,
|
if (pciReAttachDevice(pci, driver->activePciHostdevs,
|
||||||
driver->inactivePciHostdevs) < 0)
|
driver->inactivePciHostdevs, "pci-stub") < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -458,7 +458,7 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
||||||
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
||||||
if (pciDeviceGetManaged(dev) &&
|
if (pciDeviceGetManaged(dev) &&
|
||||||
pciDettachDevice(dev, driver->activePciHostdevs, NULL) < 0)
|
pciDettachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub") < 0)
|
||||||
goto reattachdevs;
|
goto reattachdevs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +574,7 @@ resetvfnetconfig:
|
|||||||
reattachdevs:
|
reattachdevs:
|
||||||
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
||||||
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
||||||
pciReAttachDevice(dev, driver->activePciHostdevs, NULL);
|
pciReAttachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub");
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -830,7 +830,7 @@ void qemuReattachPciDevice(pciDevice *dev, virQEMUDriverPtr driver)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pciReAttachDevice(dev, driver->activePciHostdevs,
|
if (pciReAttachDevice(dev, driver->activePciHostdevs,
|
||||||
driver->inactivePciHostdevs) < 0) {
|
driver->inactivePciHostdevs, "pci-stub") < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
|
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
|
||||||
err ? err->message : _("unknown error"));
|
err ? err->message : _("unknown error"));
|
||||||
|
@ -855,57 +855,35 @@ pciDeviceFile(char **buffer, const char *device, const char *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
static const char *
|
pciProbeStubDriver(const char *driver)
|
||||||
pciFindStubDriver(void)
|
|
||||||
{
|
{
|
||||||
char *drvpath = NULL;
|
char *drvpath = NULL;
|
||||||
int probed = 0;
|
int probed = 0;
|
||||||
|
|
||||||
recheck:
|
recheck:
|
||||||
if (pciDriverDir(&drvpath, "pci-stub") < 0) {
|
if (pciDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) {
|
||||||
return NULL;
|
/* driver already loaded, return */
|
||||||
}
|
|
||||||
|
|
||||||
if (virFileExists(drvpath)) {
|
|
||||||
VIR_FREE(drvpath);
|
VIR_FREE(drvpath);
|
||||||
return "pci-stub";
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (pciDriverDir(&drvpath, "pciback") < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virFileExists(drvpath)) {
|
|
||||||
VIR_FREE(drvpath);
|
|
||||||
return "pciback";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(drvpath);
|
VIR_FREE(drvpath);
|
||||||
|
|
||||||
if (!probed) {
|
if (!probed) {
|
||||||
const char *const stubprobe[] = { MODPROBE, "pci-stub", NULL };
|
const char *const probecmd[] = { MODPROBE, driver, NULL };
|
||||||
const char *const backprobe[] = { MODPROBE, "pciback", NULL };
|
|
||||||
|
|
||||||
probed = 1;
|
probed = 1;
|
||||||
/*
|
if (virRun(probecmd, NULL) < 0) {
|
||||||
* 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) {
|
|
||||||
char ebuf[1024];
|
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)));
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
goto recheck;
|
goto recheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1149,12 +1127,12 @@ cleanup:
|
|||||||
int
|
int
|
||||||
pciDettachDevice(pciDevice *dev,
|
pciDettachDevice(pciDevice *dev,
|
||||||
pciDeviceList *activeDevs,
|
pciDeviceList *activeDevs,
|
||||||
pciDeviceList *inactiveDevs)
|
pciDeviceList *inactiveDevs,
|
||||||
|
const char *driver)
|
||||||
{
|
{
|
||||||
const char *driver = pciFindStubDriver();
|
if (pciProbeStubDriver(driver) < 0) {
|
||||||
if (!driver) {
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
_("Failed to load PCI stub module %s"), driver);
|
||||||
_("cannot find any PCI stub module"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1179,12 +1157,12 @@ pciDettachDevice(pciDevice *dev,
|
|||||||
int
|
int
|
||||||
pciReAttachDevice(pciDevice *dev,
|
pciReAttachDevice(pciDevice *dev,
|
||||||
pciDeviceList *activeDevs,
|
pciDeviceList *activeDevs,
|
||||||
pciDeviceList *inactiveDevs)
|
pciDeviceList *inactiveDevs,
|
||||||
|
const char *driver)
|
||||||
{
|
{
|
||||||
const char *driver = pciFindStubDriver();
|
if (pciProbeStubDriver(driver) < 0) {
|
||||||
if (!driver) {
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
_("Failed to load PCI stub module %s"), driver);
|
||||||
_("cannot find any PCI stub module"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +44,12 @@ void pciFreeDevice (pciDevice *dev);
|
|||||||
const char *pciDeviceGetName (pciDevice *dev);
|
const char *pciDeviceGetName (pciDevice *dev);
|
||||||
int pciDettachDevice (pciDevice *dev,
|
int pciDettachDevice (pciDevice *dev,
|
||||||
pciDeviceList *activeDevs,
|
pciDeviceList *activeDevs,
|
||||||
pciDeviceList *inactiveDevs);
|
pciDeviceList *inactiveDevs,
|
||||||
|
const char *driver);
|
||||||
int pciReAttachDevice (pciDevice *dev,
|
int pciReAttachDevice (pciDevice *dev,
|
||||||
pciDeviceList *activeDevs,
|
pciDeviceList *activeDevs,
|
||||||
pciDeviceList *inactiveDevs);
|
pciDeviceList *inactiveDevs,
|
||||||
|
const char *driver);
|
||||||
int pciResetDevice (pciDevice *dev,
|
int pciResetDevice (pciDevice *dev,
|
||||||
pciDeviceList *activeDevs,
|
pciDeviceList *activeDevs,
|
||||||
pciDeviceList *inactiveDevs);
|
pciDeviceList *inactiveDevs);
|
||||||
|
@ -2113,7 +2113,7 @@ xenUnifiedNodeDeviceDettach(virNodeDevicePtr dev)
|
|||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciDettachDevice(pci, NULL, NULL) < 0)
|
if (pciDettachDevice(pci, NULL, NULL, "pciback") < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -2203,7 +2203,7 @@ xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pciReAttachDevice(pci, NULL, NULL) < 0)
|
if (pciReAttachDevice(pci, NULL, NULL, "pciback") < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user