mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Remove conn parameter from PCI functions
It was used for error reporting only.
This commit is contained in:
parent
0a5befc4c0
commit
9140756d30
@ -1105,7 +1105,7 @@ qemudStartup(int privileged) {
|
|||||||
qemu_driver->securityDriver)) == NULL)
|
qemu_driver->securityDriver)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((qemu_driver->activePciHostdevs = pciDeviceListNew(NULL)) == NULL)
|
if ((qemu_driver->activePciHostdevs = pciDeviceListNew()) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
|
if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
|
||||||
@ -1268,7 +1268,7 @@ qemudShutdown(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
qemuDriverLock(qemu_driver);
|
qemuDriverLock(qemu_driver);
|
||||||
pciDeviceListFree(NULL, qemu_driver->activePciHostdevs);
|
pciDeviceListFree(qemu_driver->activePciHostdevs);
|
||||||
virCapabilitiesFree(qemu_driver->caps);
|
virCapabilitiesFree(qemu_driver->caps);
|
||||||
|
|
||||||
virDomainObjListDeinit(&qemu_driver->domains);
|
virDomainObjListDeinit(&qemu_driver->domains);
|
||||||
@ -2111,13 +2111,12 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static pciDeviceList *
|
static pciDeviceList *
|
||||||
qemuGetPciHostDeviceList(virConnectPtr conn,
|
qemuGetPciHostDeviceList(virDomainDefPtr def)
|
||||||
virDomainDefPtr def)
|
|
||||||
{
|
{
|
||||||
pciDeviceList *list;
|
pciDeviceList *list;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!(list = pciDeviceListNew(conn)))
|
if (!(list = pciDeviceListNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0 ; i < def->nhostdevs ; i++) {
|
for (i = 0 ; i < def->nhostdevs ; i++) {
|
||||||
@ -2129,19 +2128,18 @@ qemuGetPciHostDeviceList(virConnectPtr conn,
|
|||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dev = pciGetDevice(conn,
|
dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
|
||||||
hostdev->source.subsys.u.pci.domain,
|
|
||||||
hostdev->source.subsys.u.pci.bus,
|
hostdev->source.subsys.u.pci.bus,
|
||||||
hostdev->source.subsys.u.pci.slot,
|
hostdev->source.subsys.u.pci.slot,
|
||||||
hostdev->source.subsys.u.pci.function);
|
hostdev->source.subsys.u.pci.function);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
pciDeviceListFree(conn, list);
|
pciDeviceListFree(list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pciDeviceListAdd(conn, list, dev) < 0) {
|
if (pciDeviceListAdd(list, dev) < 0) {
|
||||||
pciFreeDevice(conn, dev);
|
pciFreeDevice(dev);
|
||||||
pciDeviceListFree(conn, list);
|
pciDeviceListFree(list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2162,16 +2160,14 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
|
|||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(pcidevs = qemuGetPciHostDeviceList(NULL, def)))
|
if (!(pcidevs = qemuGetPciHostDeviceList(def)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
||||||
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
||||||
pciDeviceListSteal(NULL, pcidevs, dev);
|
pciDeviceListSteal(pcidevs, dev);
|
||||||
if (pciDeviceListAdd(NULL,
|
if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
|
||||||
driver->activePciHostdevs,
|
pciFreeDevice(dev);
|
||||||
dev) < 0) {
|
|
||||||
pciFreeDevice(NULL, dev);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2179,13 +2175,12 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
pciDeviceListFree(NULL, pcidevs);
|
pciDeviceListFree(pcidevs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuPrepareHostDevices(virConnectPtr conn,
|
qemuPrepareHostDevices(struct qemud_driver *driver,
|
||||||
struct qemud_driver *driver,
|
|
||||||
virDomainDefPtr def)
|
virDomainDefPtr def)
|
||||||
{
|
{
|
||||||
pciDeviceList *pcidevs;
|
pciDeviceList *pcidevs;
|
||||||
@ -2195,7 +2190,7 @@ qemuPrepareHostDevices(virConnectPtr conn,
|
|||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(pcidevs = qemuGetPciHostDeviceList(conn, def)))
|
if (!(pcidevs = qemuGetPciHostDeviceList(def)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* We have to use 3 loops here. *All* devices must
|
/* We have to use 3 loops here. *All* devices must
|
||||||
@ -2212,11 +2207,11 @@ qemuPrepareHostDevices(virConnectPtr conn,
|
|||||||
|
|
||||||
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 (!pciDeviceIsAssignable(conn, dev, !driver->relaxedACS))
|
if (!pciDeviceIsAssignable(dev, !driver->relaxedACS))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (pciDeviceGetManaged(dev) &&
|
if (pciDeviceGetManaged(dev) &&
|
||||||
pciDettachDevice(conn, dev) < 0)
|
pciDettachDevice(dev) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2224,19 +2219,16 @@ qemuPrepareHostDevices(virConnectPtr conn,
|
|||||||
* reset them */
|
* reset them */
|
||||||
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 (pciResetDevice(conn, dev,
|
if (pciResetDevice(dev, driver->activePciHostdevs) < 0)
|
||||||
driver->activePciHostdevs) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now mark all the devices as active */
|
/* Now mark all the devices as active */
|
||||||
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
||||||
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
||||||
pciDeviceListSteal(NULL, pcidevs, dev);
|
pciDeviceListSteal(pcidevs, dev);
|
||||||
if (pciDeviceListAdd(conn,
|
if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
|
||||||
driver->activePciHostdevs,
|
pciFreeDevice(dev);
|
||||||
dev) < 0) {
|
|
||||||
pciFreeDevice(NULL, dev);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2244,7 +2236,7 @@ qemuPrepareHostDevices(virConnectPtr conn,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
pciDeviceListFree(conn, pcidevs);
|
pciDeviceListFree(pcidevs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2259,7 +2251,7 @@ qemudReattachManagedDevice(pciDevice *dev)
|
|||||||
usleep(100*1000);
|
usleep(100*1000);
|
||||||
retries--;
|
retries--;
|
||||||
}
|
}
|
||||||
if (pciReAttachDevice(NULL, dev) < 0) {
|
if (pciReAttachDevice(dev) < 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 : "");
|
err ? err->message : "");
|
||||||
@ -2269,8 +2261,7 @@ qemudReattachManagedDevice(pciDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
qemuDomainReAttachHostDevices(virConnectPtr conn,
|
qemuDomainReAttachHostDevices(struct qemud_driver *driver,
|
||||||
struct qemud_driver *driver,
|
|
||||||
virDomainDefPtr def)
|
virDomainDefPtr def)
|
||||||
{
|
{
|
||||||
pciDeviceList *pcidevs;
|
pciDeviceList *pcidevs;
|
||||||
@ -2279,7 +2270,7 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
|
|||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(pcidevs = qemuGetPciHostDeviceList(conn, def))) {
|
if (!(pcidevs = qemuGetPciHostDeviceList(def))) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
VIR_ERROR(_("Failed to allocate pciDeviceList: %s"),
|
VIR_ERROR(_("Failed to allocate pciDeviceList: %s"),
|
||||||
err ? err->message : "");
|
err ? err->message : "");
|
||||||
@ -2292,13 +2283,12 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
|
|||||||
|
|
||||||
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
|
||||||
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
pciDevice *dev = pciDeviceListGet(pcidevs, i);
|
||||||
pciDeviceListDel(conn, driver->activePciHostdevs, dev);
|
pciDeviceListDel(driver->activePciHostdevs, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (pciResetDevice(conn, dev,
|
if (pciResetDevice(dev, driver->activePciHostdevs) < 0) {
|
||||||
driver->activePciHostdevs) < 0) {
|
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
VIR_ERROR(_("Failed to reset PCI device: %s"),
|
VIR_ERROR(_("Failed to reset PCI device: %s"),
|
||||||
err ? err->message : "");
|
err ? err->message : "");
|
||||||
@ -2311,7 +2301,7 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
|
|||||||
qemudReattachManagedDevice(dev);
|
qemudReattachManagedDevice(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
pciDeviceListFree(conn, pcidevs);
|
pciDeviceListFree(pcidevs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *const defaultDeviceACL[] = {
|
static const char *const defaultDeviceACL[] = {
|
||||||
@ -2611,7 +2601,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
if (qemuSetupCgroup(driver, vm) < 0)
|
if (qemuSetupCgroup(driver, vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuPrepareHostDevices(conn, driver, vm->def) < 0)
|
if (qemuPrepareHostDevices(driver, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC(priv->monConfig) < 0) {
|
if (VIR_ALLOC(priv->monConfig) < 0) {
|
||||||
@ -2784,7 +2774,7 @@ cleanup:
|
|||||||
/* We jump here if we failed to start the VM for any reason
|
/* We jump here if we failed to start the VM for any reason
|
||||||
* XXX investigate if we can kill this block and safely call
|
* XXX investigate if we can kill this block and safely call
|
||||||
* qemudShutdownVMDaemon even though no PID is running */
|
* qemudShutdownVMDaemon even though no PID is running */
|
||||||
qemuDomainReAttachHostDevices(conn, driver, vm->def);
|
qemuDomainReAttachHostDevices(driver, vm->def);
|
||||||
|
|
||||||
if (driver->securityDriver &&
|
if (driver->securityDriver &&
|
||||||
driver->securityDriver->domainRestoreSecurityAllLabel)
|
driver->securityDriver->domainRestoreSecurityAllLabel)
|
||||||
@ -2889,7 +2879,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn,
|
|||||||
qemuDomainPCIAddressSetFree(priv->pciaddrs);
|
qemuDomainPCIAddressSetFree(priv->pciaddrs);
|
||||||
priv->pciaddrs = NULL;
|
priv->pciaddrs = NULL;
|
||||||
|
|
||||||
qemuDomainReAttachHostDevices(conn, driver, vm->def);
|
qemuDomainReAttachHostDevices(driver, vm->def);
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if ((ret = qemuRemoveCgroup(conn, driver, vm, 0)) < 0) {
|
if ((ret = qemuRemoveCgroup(conn, driver, vm, 0)) < 0) {
|
||||||
@ -5739,8 +5729,7 @@ no_memory:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
|
static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
|
||||||
struct qemud_driver *driver,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainHostdevDefPtr hostdev,
|
virDomainHostdevDefPtr hostdev,
|
||||||
int qemuCmdFlags)
|
int qemuCmdFlags)
|
||||||
@ -5756,23 +5745,22 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pci = pciGetDevice(conn,
|
pci = pciGetDevice(hostdev->source.subsys.u.pci.domain,
|
||||||
hostdev->source.subsys.u.pci.domain,
|
|
||||||
hostdev->source.subsys.u.pci.bus,
|
hostdev->source.subsys.u.pci.bus,
|
||||||
hostdev->source.subsys.u.pci.slot,
|
hostdev->source.subsys.u.pci.slot,
|
||||||
hostdev->source.subsys.u.pci.function);
|
hostdev->source.subsys.u.pci.function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!pciDeviceIsAssignable(conn, pci, !driver->relaxedACS) ||
|
if (!pciDeviceIsAssignable(pci, !driver->relaxedACS) ||
|
||||||
(hostdev->managed && pciDettachDevice(conn, pci) < 0) ||
|
(hostdev->managed && pciDettachDevice(pci) < 0) ||
|
||||||
pciResetDevice(conn, pci, driver->activePciHostdevs) < 0) {
|
pciResetDevice(pci, driver->activePciHostdevs) < 0) {
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pciDeviceListAdd(conn, driver->activePciHostdevs, pci) < 0) {
|
if (pciDeviceListAdd(driver->activePciHostdevs, pci) < 0) {
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5810,7 +5798,7 @@ error:
|
|||||||
VIR_WARN0("Unable to release PCI address on host device");
|
VIR_WARN0("Unable to release PCI address on host device");
|
||||||
|
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
pciDeviceListDel(conn, driver->activePciHostdevs, pci);
|
pciDeviceListDel(driver->activePciHostdevs, pci);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -5877,7 +5865,7 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn,
|
|||||||
|
|
||||||
switch (hostdev->source.subsys.type) {
|
switch (hostdev->source.subsys.type) {
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
||||||
if (qemudDomainAttachHostPciDevice(conn, driver, vm,
|
if (qemudDomainAttachHostPciDevice(driver, vm,
|
||||||
hostdev, qemuCmdFlags) < 0)
|
hostdev, qemuCmdFlags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
@ -6333,8 +6321,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
pci = pciGetDevice(conn,
|
pci = pciGetDevice(detach->source.subsys.u.pci.domain,
|
||||||
detach->source.subsys.u.pci.domain,
|
|
||||||
detach->source.subsys.u.pci.bus,
|
detach->source.subsys.u.pci.bus,
|
||||||
detach->source.subsys.u.pci.slot,
|
detach->source.subsys.u.pci.slot,
|
||||||
detach->source.subsys.u.pci.function);
|
detach->source.subsys.u.pci.function);
|
||||||
@ -6342,11 +6329,11 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
else {
|
else {
|
||||||
pciDeviceSetManaged(pci, detach->managed);
|
pciDeviceSetManaged(pci, detach->managed);
|
||||||
pciDeviceListDel(conn, driver->activePciHostdevs, pci);
|
pciDeviceListDel(driver->activePciHostdevs, pci);
|
||||||
if (pciResetDevice(conn, pci, driver->activePciHostdevs) < 0)
|
if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
qemudReattachManagedDevice(pci);
|
qemudReattachManagedDevice(pci);
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->def->nhostdevs > 1) {
|
if (vm->def->nhostdevs > 1) {
|
||||||
@ -8463,16 +8450,16 @@ qemudNodeDeviceDettach (virNodeDevicePtr dev)
|
|||||||
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciDettachDevice(dev->conn, pci) < 0)
|
if (pciDettachDevice(pci) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8486,16 +8473,16 @@ qemudNodeDeviceReAttach (virNodeDevicePtr dev)
|
|||||||
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciReAttachDevice(dev->conn, pci) < 0)
|
if (pciReAttachDevice(pci) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8510,19 +8497,19 @@ qemudNodeDeviceReset (virNodeDevicePtr dev)
|
|||||||
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
|
|
||||||
if (pciResetDevice(dev->conn, pci, driver->activePciHostdevs) < 0)
|
if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,8 +225,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||||
pciDevice *pci = pciGetDevice(conn,
|
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
|
||||||
dev->source.subsys.u.pci.domain,
|
|
||||||
dev->source.subsys.u.pci.bus,
|
dev->source.subsys.u.pci.bus,
|
||||||
dev->source.subsys.u.pci.slot,
|
dev->source.subsys.u.pci.slot,
|
||||||
dev->source.subsys.u.pci.function);
|
dev->source.subsys.u.pci.function);
|
||||||
@ -235,7 +234,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACSetSecurityPCILabel, vm);
|
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACSetSecurityPCILabel, vm);
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -302,8 +301,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||||
pciDevice *pci = pciGetDevice(conn,
|
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
|
||||||
dev->source.subsys.u.pci.domain,
|
|
||||||
dev->source.subsys.u.pci.bus,
|
dev->source.subsys.u.pci.bus,
|
||||||
dev->source.subsys.u.pci.slot,
|
dev->source.subsys.u.pci.slot,
|
||||||
dev->source.subsys.u.pci.function);
|
dev->source.subsys.u.pci.function);
|
||||||
@ -312,7 +310,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACRestoreSecurityPCILabel, NULL);
|
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACRestoreSecurityPCILabel, NULL);
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -513,8 +513,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||||
pciDevice *pci = pciGetDevice(conn,
|
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
|
||||||
dev->source.subsys.u.pci.domain,
|
|
||||||
dev->source.subsys.u.pci.bus,
|
dev->source.subsys.u.pci.bus,
|
||||||
dev->source.subsys.u.pci.slot,
|
dev->source.subsys.u.pci.slot,
|
||||||
dev->source.subsys.u.pci.function);
|
dev->source.subsys.u.pci.function);
|
||||||
@ -523,7 +522,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = pciDeviceFileIterate(conn, pci, SELinuxSetSecurityPCILabel, vm);
|
ret = pciDeviceFileIterate(conn, pci, SELinuxSetSecurityPCILabel, vm);
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -589,8 +588,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||||
pciDevice *pci = pciGetDevice(conn,
|
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
|
||||||
dev->source.subsys.u.pci.domain,
|
|
||||||
dev->source.subsys.u.pci.bus,
|
dev->source.subsys.u.pci.bus,
|
||||||
dev->source.subsys.u.pci.slot,
|
dev->source.subsys.u.pci.slot,
|
||||||
dev->source.subsys.u.pci.function);
|
dev->source.subsys.u.pci.function);
|
||||||
@ -599,7 +597,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = pciDeviceFileIterate(conn, pci, SELinuxRestoreSecurityPCILabel, NULL);
|
ret = pciDeviceFileIterate(conn, pci, SELinuxRestoreSecurityPCILabel, NULL);
|
||||||
pciFreeDevice(conn, pci);
|
pciFreeDevice(pci);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
113
src/util/pci.c
113
src/util/pci.c
@ -75,8 +75,8 @@ struct _pciDeviceList {
|
|||||||
/* For virReportOOMError() and virReportSystemError() */
|
/* For virReportOOMError() and virReportSystemError() */
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
#define pciReportError(conn, code, fmt...) \
|
#define pciReportError(code, fmt...) \
|
||||||
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
|
virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \
|
||||||
__FUNCTION__, __LINE__, fmt)
|
__FUNCTION__, __LINE__, fmt)
|
||||||
|
|
||||||
/* Specifications referenced in comments:
|
/* Specifications referenced in comments:
|
||||||
@ -262,8 +262,7 @@ typedef int (*pciIterPredicate)(pciDevice *, pciDevice *, void *);
|
|||||||
* safe to reset if there is an error.
|
* safe to reset if there is an error.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
pciIterDevices(virConnectPtr conn,
|
pciIterDevices(pciIterPredicate predicate,
|
||||||
pciIterPredicate predicate,
|
|
||||||
pciDevice *dev,
|
pciDevice *dev,
|
||||||
pciDevice **matched,
|
pciDevice **matched,
|
||||||
void *data)
|
void *data)
|
||||||
@ -296,7 +295,7 @@ pciIterDevices(virConnectPtr conn,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
check = pciGetDevice(conn, domain, bus, slot, function);
|
check = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!check) {
|
if (!check) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
@ -307,7 +306,7 @@ pciIterDevices(virConnectPtr conn,
|
|||||||
*matched = check;
|
*matched = check;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pciFreeDevice(conn, check);
|
pciFreeDevice(check);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return ret;
|
return ret;
|
||||||
@ -452,12 +451,11 @@ pciSharesBusWithActive(pciDevice *dev, pciDevice *check, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static pciDevice *
|
static pciDevice *
|
||||||
pciBusContainsActiveDevices(virConnectPtr conn,
|
pciBusContainsActiveDevices(pciDevice *dev,
|
||||||
pciDevice *dev,
|
|
||||||
pciDeviceList *activeDevs)
|
pciDeviceList *activeDevs)
|
||||||
{
|
{
|
||||||
pciDevice *active = NULL;
|
pciDevice *active = NULL;
|
||||||
if (pciIterDevices(conn, pciSharesBusWithActive,
|
if (pciIterDevices(pciSharesBusWithActive,
|
||||||
dev, &active, activeDevs) < 0)
|
dev, &active, activeDevs) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return active;
|
return active;
|
||||||
@ -493,10 +491,10 @@ pciIsParent(pciDevice *dev, pciDevice *check, void *data ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static pciDevice *
|
static pciDevice *
|
||||||
pciGetParentDevice(virConnectPtr conn, pciDevice *dev)
|
pciGetParentDevice(pciDevice *dev)
|
||||||
{
|
{
|
||||||
pciDevice *parent = NULL;
|
pciDevice *parent = NULL;
|
||||||
pciIterDevices(conn, pciIsParent, dev, &parent, NULL);
|
pciIterDevices(pciIsParent, dev, &parent, NULL);
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,8 +502,7 @@ pciGetParentDevice(virConnectPtr conn, pciDevice *dev)
|
|||||||
* devices behind a bus.
|
* devices behind a bus.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
pciTrySecondaryBusReset(virConnectPtr conn,
|
pciTrySecondaryBusReset(pciDevice *dev,
|
||||||
pciDevice *dev,
|
|
||||||
pciDeviceList *activeDevs)
|
pciDeviceList *activeDevs)
|
||||||
{
|
{
|
||||||
pciDevice *parent, *conflict;
|
pciDevice *parent, *conflict;
|
||||||
@ -518,17 +515,17 @@ pciTrySecondaryBusReset(virConnectPtr conn,
|
|||||||
* In future, we could allow it so long as those devices
|
* In future, we could allow it so long as those devices
|
||||||
* are not in use by the host or other guests.
|
* are not in use by the host or other guests.
|
||||||
*/
|
*/
|
||||||
if ((conflict = pciBusContainsActiveDevices(conn, dev, activeDevs))) {
|
if ((conflict = pciBusContainsActiveDevices(dev, activeDevs))) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Active %s devices on bus with %s, not doing bus reset"),
|
_("Active %s devices on bus with %s, not doing bus reset"),
|
||||||
conflict->name, dev->name);
|
conflict->name, dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the parent bus */
|
/* Find the parent bus */
|
||||||
parent = pciGetParentDevice(conn, dev);
|
parent = pciGetParentDevice(dev);
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to find parent device for %s"),
|
_("Failed to find parent device for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
@ -541,7 +538,7 @@ pciTrySecondaryBusReset(virConnectPtr conn,
|
|||||||
* are multiple devices/functions
|
* are multiple devices/functions
|
||||||
*/
|
*/
|
||||||
if (pciRead(dev, 0, config_space, PCI_CONF_LEN) < 0) {
|
if (pciRead(dev, 0, config_space, PCI_CONF_LEN) < 0) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to save PCI config space for %s"),
|
_("Failed to save PCI config space for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
goto out;
|
goto out;
|
||||||
@ -561,14 +558,14 @@ pciTrySecondaryBusReset(virConnectPtr conn,
|
|||||||
usleep(200 * 1000); /* sleep 200ms */
|
usleep(200 * 1000); /* sleep 200ms */
|
||||||
|
|
||||||
if (pciWrite(dev, 0, config_space, PCI_CONF_LEN) < 0) {
|
if (pciWrite(dev, 0, config_space, PCI_CONF_LEN) < 0) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to restore PCI config space for %s"),
|
_("Failed to restore PCI config space for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(conn, parent);
|
pciFreeDevice(parent);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +574,7 @@ out:
|
|||||||
* above we require the device supports a full internal reset.
|
* above we require the device supports a full internal reset.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
|
pciTryPowerManagementReset(pciDevice *dev)
|
||||||
{
|
{
|
||||||
uint8_t config_space[PCI_CONF_LEN];
|
uint8_t config_space[PCI_CONF_LEN];
|
||||||
uint32_t ctl;
|
uint32_t ctl;
|
||||||
@ -587,7 +584,7 @@ pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
|
|||||||
|
|
||||||
/* Save and restore the device's config space. */
|
/* Save and restore the device's config space. */
|
||||||
if (pciRead(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
|
if (pciRead(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to save PCI config space for %s"),
|
_("Failed to save PCI config space for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
@ -607,7 +604,7 @@ pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
|
|||||||
usleep(10 * 1000); /* sleep 10ms */
|
usleep(10 * 1000); /* sleep 10ms */
|
||||||
|
|
||||||
if (pciWrite(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
|
if (pciWrite(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to restore PCI config space for %s"),
|
_("Failed to restore PCI config space for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
@ -635,14 +632,13 @@ pciInitDevice(pciDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pciResetDevice(virConnectPtr conn,
|
pciResetDevice(pciDevice *dev,
|
||||||
pciDevice *dev,
|
|
||||||
pciDeviceList *activeDevs)
|
pciDeviceList *activeDevs)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
|
if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
|
||||||
pciReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
pciReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Not resetting active device %s"), dev->name);
|
_("Not resetting active device %s"), dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -661,15 +657,15 @@ pciResetDevice(virConnectPtr conn,
|
|||||||
* the function, not the whole device.
|
* the function, not the whole device.
|
||||||
*/
|
*/
|
||||||
if (dev->has_pm_reset)
|
if (dev->has_pm_reset)
|
||||||
ret = pciTryPowerManagementReset(conn, dev);
|
ret = pciTryPowerManagementReset(dev);
|
||||||
|
|
||||||
/* Bus reset is not an option with the root bus */
|
/* Bus reset is not an option with the root bus */
|
||||||
if (ret < 0 && dev->bus != 0)
|
if (ret < 0 && dev->bus != 0)
|
||||||
ret = pciTrySecondaryBusReset(conn, dev, activeDevs);
|
ret = pciTrySecondaryBusReset(dev, activeDevs);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Unable to reset PCI device %s: %s"),
|
_("Unable to reset PCI device %s: %s"),
|
||||||
dev->name,
|
dev->name,
|
||||||
err ? err->message : _("no FLR, PM reset or bus reset available"));
|
err ? err->message : _("no FLR, PM reset or bus reset available"));
|
||||||
@ -810,11 +806,11 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pciDettachDevice(virConnectPtr conn, pciDevice *dev)
|
pciDettachDevice(pciDevice *dev)
|
||||||
{
|
{
|
||||||
const char *driver = pciFindStubDriver();
|
const char *driver = pciFindStubDriver();
|
||||||
if (!driver) {
|
if (!driver) {
|
||||||
pciReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
|
pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("cannot find any PCI stub module"));
|
_("cannot find any PCI stub module"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -871,11 +867,11 @@ pciUnBindDeviceFromStub(pciDevice *dev, const char *driver)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pciReAttachDevice(virConnectPtr conn, pciDevice *dev)
|
pciReAttachDevice(pciDevice *dev)
|
||||||
{
|
{
|
||||||
const char *driver = pciFindStubDriver();
|
const char *driver = pciFindStubDriver();
|
||||||
if (!driver) {
|
if (!driver) {
|
||||||
pciReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
|
pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("cannot find any PCI stub module"));
|
_("cannot find any PCI stub module"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1006,8 +1002,7 @@ pciReadDeviceID(pciDevice *dev, const char *id_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pciDevice *
|
pciDevice *
|
||||||
pciGetDevice(virConnectPtr conn,
|
pciGetDevice(unsigned domain,
|
||||||
unsigned domain,
|
|
||||||
unsigned bus,
|
unsigned bus,
|
||||||
unsigned slot,
|
unsigned slot,
|
||||||
unsigned function)
|
unsigned function)
|
||||||
@ -1035,12 +1030,12 @@ pciGetDevice(virConnectPtr conn,
|
|||||||
product = pciReadDeviceID(dev, "device");
|
product = pciReadDeviceID(dev, "device");
|
||||||
|
|
||||||
if (!vendor || !product) {
|
if (!vendor || !product) {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to read product/vendor ID for %s"),
|
_("Failed to read product/vendor ID for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
VIR_FREE(product);
|
VIR_FREE(product);
|
||||||
VIR_FREE(vendor);
|
VIR_FREE(vendor);
|
||||||
pciFreeDevice(conn, dev);
|
pciFreeDevice(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1056,7 +1051,7 @@ pciGetDevice(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pciFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
|
pciFreeDevice(pciDevice *dev)
|
||||||
{
|
{
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return;
|
return;
|
||||||
@ -1077,7 +1072,7 @@ unsigned pciDeviceGetManaged(pciDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pciDeviceList *
|
pciDeviceList *
|
||||||
pciDeviceListNew(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/)
|
pciDeviceListNew(void)
|
||||||
{
|
{
|
||||||
pciDeviceList *list;
|
pciDeviceList *list;
|
||||||
|
|
||||||
@ -1090,8 +1085,7 @@ pciDeviceListNew(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pciDeviceListFree(virConnectPtr conn,
|
pciDeviceListFree(pciDeviceList *list)
|
||||||
pciDeviceList *list)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1099,7 +1093,7 @@ pciDeviceListFree(virConnectPtr conn,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < list->count; i++) {
|
for (i = 0; i < list->count; i++) {
|
||||||
pciFreeDevice(conn, list->devs[i]);
|
pciFreeDevice(list->devs[i]);
|
||||||
list->devs[i] = NULL;
|
list->devs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,12 +1103,11 @@ pciDeviceListFree(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pciDeviceListAdd(virConnectPtr conn,
|
pciDeviceListAdd(pciDeviceList *list,
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev)
|
pciDevice *dev)
|
||||||
{
|
{
|
||||||
if (pciDeviceListFind(list, dev)) {
|
if (pciDeviceListFind(list, dev)) {
|
||||||
pciReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
pciReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Device %s is already in use"), dev->name);
|
_("Device %s is already in use"), dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1148,8 +1141,7 @@ pciDeviceListCount(pciDeviceList *list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pciDevice *
|
pciDevice *
|
||||||
pciDeviceListSteal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
pciDeviceListSteal(pciDeviceList *list,
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev)
|
pciDevice *dev)
|
||||||
{
|
{
|
||||||
pciDevice *ret = NULL;
|
pciDevice *ret = NULL;
|
||||||
@ -1179,13 +1171,12 @@ pciDeviceListSteal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pciDeviceListDel(virConnectPtr conn,
|
pciDeviceListDel(pciDeviceList *list,
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev)
|
pciDevice *dev)
|
||||||
{
|
{
|
||||||
pciDevice *ret = pciDeviceListSteal(conn, list, dev);
|
pciDevice *ret = pciDeviceListSteal(list, dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
pciFreeDevice(conn, ret);
|
pciFreeDevice(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pciDevice *
|
pciDevice *
|
||||||
@ -1289,12 +1280,11 @@ pciDeviceDownstreamLacksACS(pciDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
|
pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
|
||||||
pciDevice *dev)
|
|
||||||
{
|
{
|
||||||
pciDevice *parent;
|
pciDevice *parent;
|
||||||
|
|
||||||
parent = pciGetParentDevice(conn, dev);
|
parent = pciGetParentDevice(dev);
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
/* if we have no parent, and this is the root bus, ACS doesn't come
|
/* if we have no parent, and this is the root bus, ACS doesn't come
|
||||||
* into play since devices on the root bus can't P2P without going
|
* into play since devices on the root bus can't P2P without going
|
||||||
@ -1303,7 +1293,7 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
|
|||||||
if (dev->bus == 0)
|
if (dev->bus == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Failed to find parent device for %s"),
|
_("Failed to find parent device for %s"),
|
||||||
dev->name);
|
dev->name);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1321,7 +1311,7 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
|
|||||||
acs = pciDeviceDownstreamLacksACS(parent);
|
acs = pciDeviceDownstreamLacksACS(parent);
|
||||||
|
|
||||||
if (acs) {
|
if (acs) {
|
||||||
pciFreeDevice(conn, parent);
|
pciFreeDevice(parent);
|
||||||
if (acs < 0)
|
if (acs < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
@ -1329,15 +1319,14 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
tmp = parent;
|
tmp = parent;
|
||||||
parent = pciGetParentDevice(conn, parent);
|
parent = pciGetParentDevice(parent);
|
||||||
pciFreeDevice(conn, tmp);
|
pciFreeDevice(tmp);
|
||||||
} while (parent);
|
} while (parent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pciDeviceIsAssignable(virConnectPtr conn,
|
int pciDeviceIsAssignable(pciDevice *dev,
|
||||||
pciDevice *dev,
|
|
||||||
int strict_acs_check)
|
int strict_acs_check)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -1347,7 +1336,7 @@ int pciDeviceIsAssignable(virConnectPtr conn,
|
|||||||
* or bound to a stub driver.
|
* or bound to a stub driver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = pciDeviceIsBehindSwitchLackingACS(conn, dev);
|
ret = pciDeviceIsBehindSwitchLackingACS(dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1356,7 +1345,7 @@ int pciDeviceIsAssignable(virConnectPtr conn,
|
|||||||
VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
|
VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
|
||||||
dev->id, dev->name);
|
dev->id, dev->name);
|
||||||
} else {
|
} else {
|
||||||
pciReportError(conn, VIR_ERR_NO_SUPPORT,
|
pciReportError(VIR_ERR_NO_SUPPORT,
|
||||||
_("Device %s is behind a switch lacking ACS and "
|
_("Device %s is behind a switch lacking ACS and "
|
||||||
"cannot be assigned"),
|
"cannot be assigned"),
|
||||||
dev->name);
|
dev->name);
|
||||||
|
@ -27,38 +27,29 @@
|
|||||||
typedef struct _pciDevice pciDevice;
|
typedef struct _pciDevice pciDevice;
|
||||||
typedef struct _pciDeviceList pciDeviceList;
|
typedef struct _pciDeviceList pciDeviceList;
|
||||||
|
|
||||||
pciDevice *pciGetDevice (virConnectPtr conn,
|
pciDevice *pciGetDevice (unsigned domain,
|
||||||
unsigned domain,
|
|
||||||
unsigned bus,
|
unsigned bus,
|
||||||
unsigned slot,
|
unsigned slot,
|
||||||
unsigned function);
|
unsigned function);
|
||||||
void pciFreeDevice (virConnectPtr conn,
|
void pciFreeDevice (pciDevice *dev);
|
||||||
pciDevice *dev);
|
int pciDettachDevice (pciDevice *dev);
|
||||||
int pciDettachDevice (virConnectPtr conn,
|
int pciReAttachDevice (pciDevice *dev);
|
||||||
pciDevice *dev);
|
int pciResetDevice (pciDevice *dev,
|
||||||
int pciReAttachDevice (virConnectPtr conn,
|
|
||||||
pciDevice *dev);
|
|
||||||
int pciResetDevice (virConnectPtr conn,
|
|
||||||
pciDevice *dev,
|
|
||||||
pciDeviceList *activeDevs);
|
pciDeviceList *activeDevs);
|
||||||
void pciDeviceSetManaged(pciDevice *dev,
|
void pciDeviceSetManaged(pciDevice *dev,
|
||||||
unsigned managed);
|
unsigned managed);
|
||||||
unsigned pciDeviceGetManaged(pciDevice *dev);
|
unsigned pciDeviceGetManaged(pciDevice *dev);
|
||||||
|
|
||||||
pciDeviceList *pciDeviceListNew (virConnectPtr conn);
|
pciDeviceList *pciDeviceListNew (void);
|
||||||
void pciDeviceListFree (virConnectPtr conn,
|
void pciDeviceListFree (pciDeviceList *list);
|
||||||
pciDeviceList *list);
|
int pciDeviceListAdd (pciDeviceList *list,
|
||||||
int pciDeviceListAdd (virConnectPtr conn,
|
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev);
|
pciDevice *dev);
|
||||||
pciDevice * pciDeviceListGet (pciDeviceList *list,
|
pciDevice * pciDeviceListGet (pciDeviceList *list,
|
||||||
int idx);
|
int idx);
|
||||||
int pciDeviceListCount (pciDeviceList *list);
|
int pciDeviceListCount (pciDeviceList *list);
|
||||||
pciDevice * pciDeviceListSteal (virConnectPtr conn,
|
pciDevice * pciDeviceListSteal (pciDeviceList *list,
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev);
|
pciDevice *dev);
|
||||||
void pciDeviceListDel (virConnectPtr conn,
|
void pciDeviceListDel (pciDeviceList *list,
|
||||||
pciDeviceList *list,
|
|
||||||
pciDevice *dev);
|
pciDevice *dev);
|
||||||
pciDevice * pciDeviceListFind (pciDeviceList *list,
|
pciDevice * pciDeviceListFind (pciDeviceList *list,
|
||||||
pciDevice *dev);
|
pciDevice *dev);
|
||||||
@ -78,8 +69,7 @@ int pciDeviceFileIterate(virConnectPtr conn,
|
|||||||
pciDeviceFileActor actor,
|
pciDeviceFileActor actor,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
||||||
int pciDeviceIsAssignable(virConnectPtr conn,
|
int pciDeviceIsAssignable(pciDevice *dev,
|
||||||
pciDevice *dev,
|
|
||||||
int strict_acs_check);
|
int strict_acs_check);
|
||||||
int pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher);
|
int pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher);
|
||||||
|
|
||||||
|
@ -1763,16 +1763,16 @@ xenUnifiedNodeDeviceDettach (virNodeDevicePtr dev)
|
|||||||
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciDettachDevice(dev->conn, pci) < 0)
|
if (pciDettachDevice(pci) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1786,16 +1786,16 @@ xenUnifiedNodeDeviceReAttach (virNodeDevicePtr dev)
|
|||||||
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciReAttachDevice(dev->conn, pci) < 0)
|
if (pciReAttachDevice(pci) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1809,16 +1809,16 @@ xenUnifiedNodeDeviceReset (virNodeDevicePtr dev)
|
|||||||
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
|
pci = pciGetDevice(domain, bus, slot, function);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pciResetDevice(dev->conn, pci, NULL) < 0)
|
if (pciResetDevice(pci, NULL) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
pciFreeDevice(dev->conn, pci);
|
pciFreeDevice(pci);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user