Remove conn parameter from PCI functions

It was used for error reporting only.
This commit is contained in:
Matthias Bolte 2010-02-05 00:16:34 +01:00
parent 0a5befc4c0
commit 9140756d30
6 changed files with 134 additions and 172 deletions

View File

@ -1105,7 +1105,7 @@ qemudStartup(int privileged) {
qemu_driver->securityDriver)) == NULL)
goto error;
if ((qemu_driver->activePciHostdevs = pciDeviceListNew(NULL)) == NULL)
if ((qemu_driver->activePciHostdevs = pciDeviceListNew()) == NULL)
goto error;
if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
@ -1268,7 +1268,7 @@ qemudShutdown(void) {
return -1;
qemuDriverLock(qemu_driver);
pciDeviceListFree(NULL, qemu_driver->activePciHostdevs);
pciDeviceListFree(qemu_driver->activePciHostdevs);
virCapabilitiesFree(qemu_driver->caps);
virDomainObjListDeinit(&qemu_driver->domains);
@ -2111,13 +2111,12 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
}
static pciDeviceList *
qemuGetPciHostDeviceList(virConnectPtr conn,
virDomainDefPtr def)
qemuGetPciHostDeviceList(virDomainDefPtr def)
{
pciDeviceList *list;
int i;
if (!(list = pciDeviceListNew(conn)))
if (!(list = pciDeviceListNew()))
return NULL;
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)
continue;
dev = pciGetDevice(conn,
hostdev->source.subsys.u.pci.domain,
dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
hostdev->source.subsys.u.pci.bus,
hostdev->source.subsys.u.pci.slot,
hostdev->source.subsys.u.pci.function);
if (!dev) {
pciDeviceListFree(conn, list);
pciDeviceListFree(list);
return NULL;
}
if (pciDeviceListAdd(conn, list, dev) < 0) {
pciFreeDevice(conn, dev);
pciDeviceListFree(conn, list);
if (pciDeviceListAdd(list, dev) < 0) {
pciFreeDevice(dev);
pciDeviceListFree(list);
return NULL;
}
@ -2162,16 +2160,14 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
if (!def->nhostdevs)
return 0;
if (!(pcidevs = qemuGetPciHostDeviceList(NULL, def)))
if (!(pcidevs = qemuGetPciHostDeviceList(def)))
return -1;
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
pciDeviceListSteal(NULL, pcidevs, dev);
if (pciDeviceListAdd(NULL,
driver->activePciHostdevs,
dev) < 0) {
pciFreeDevice(NULL, dev);
pciDeviceListSteal(pcidevs, dev);
if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
pciFreeDevice(dev);
goto cleanup;
}
}
@ -2179,13 +2175,12 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
ret = 0;
cleanup:
pciDeviceListFree(NULL, pcidevs);
pciDeviceListFree(pcidevs);
return ret;
}
static int
qemuPrepareHostDevices(virConnectPtr conn,
struct qemud_driver *driver,
qemuPrepareHostDevices(struct qemud_driver *driver,
virDomainDefPtr def)
{
pciDeviceList *pcidevs;
@ -2195,7 +2190,7 @@ qemuPrepareHostDevices(virConnectPtr conn,
if (!def->nhostdevs)
return 0;
if (!(pcidevs = qemuGetPciHostDeviceList(conn, def)))
if (!(pcidevs = qemuGetPciHostDeviceList(def)))
return -1;
/* We have to use 3 loops here. *All* devices must
@ -2212,11 +2207,11 @@ qemuPrepareHostDevices(virConnectPtr conn,
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
if (!pciDeviceIsAssignable(conn, dev, !driver->relaxedACS))
if (!pciDeviceIsAssignable(dev, !driver->relaxedACS))
goto cleanup;
if (pciDeviceGetManaged(dev) &&
pciDettachDevice(conn, dev) < 0)
pciDettachDevice(dev) < 0)
goto cleanup;
}
@ -2224,19 +2219,16 @@ qemuPrepareHostDevices(virConnectPtr conn,
* reset them */
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
if (pciResetDevice(conn, dev,
driver->activePciHostdevs) < 0)
if (pciResetDevice(dev, driver->activePciHostdevs) < 0)
goto cleanup;
}
/* Now mark all the devices as active */
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
pciDeviceListSteal(NULL, pcidevs, dev);
if (pciDeviceListAdd(conn,
driver->activePciHostdevs,
dev) < 0) {
pciFreeDevice(NULL, dev);
pciDeviceListSteal(pcidevs, dev);
if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
pciFreeDevice(dev);
goto cleanup;
}
}
@ -2244,7 +2236,7 @@ qemuPrepareHostDevices(virConnectPtr conn,
ret = 0;
cleanup:
pciDeviceListFree(conn, pcidevs);
pciDeviceListFree(pcidevs);
return ret;
}
@ -2259,7 +2251,7 @@ qemudReattachManagedDevice(pciDevice *dev)
usleep(100*1000);
retries--;
}
if (pciReAttachDevice(NULL, dev) < 0) {
if (pciReAttachDevice(dev) < 0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
err ? err->message : "");
@ -2269,8 +2261,7 @@ qemudReattachManagedDevice(pciDevice *dev)
}
static void
qemuDomainReAttachHostDevices(virConnectPtr conn,
struct qemud_driver *driver,
qemuDomainReAttachHostDevices(struct qemud_driver *driver,
virDomainDefPtr def)
{
pciDeviceList *pcidevs;
@ -2279,7 +2270,7 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
if (!def->nhostdevs)
return;
if (!(pcidevs = qemuGetPciHostDeviceList(conn, def))) {
if (!(pcidevs = qemuGetPciHostDeviceList(def))) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to allocate pciDeviceList: %s"),
err ? err->message : "");
@ -2292,13 +2283,12 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
pciDeviceListDel(conn, driver->activePciHostdevs, dev);
pciDeviceListDel(driver->activePciHostdevs, dev);
}
for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
pciDevice *dev = pciDeviceListGet(pcidevs, i);
if (pciResetDevice(conn, dev,
driver->activePciHostdevs) < 0) {
if (pciResetDevice(dev, driver->activePciHostdevs) < 0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to reset PCI device: %s"),
err ? err->message : "");
@ -2311,7 +2301,7 @@ qemuDomainReAttachHostDevices(virConnectPtr conn,
qemudReattachManagedDevice(dev);
}
pciDeviceListFree(conn, pcidevs);
pciDeviceListFree(pcidevs);
}
static const char *const defaultDeviceACL[] = {
@ -2611,7 +2601,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
if (qemuSetupCgroup(driver, vm) < 0)
goto cleanup;
if (qemuPrepareHostDevices(conn, driver, vm->def) < 0)
if (qemuPrepareHostDevices(driver, vm->def) < 0)
goto cleanup;
if (VIR_ALLOC(priv->monConfig) < 0) {
@ -2784,7 +2774,7 @@ cleanup:
/* We jump here if we failed to start the VM for any reason
* XXX investigate if we can kill this block and safely call
* qemudShutdownVMDaemon even though no PID is running */
qemuDomainReAttachHostDevices(conn, driver, vm->def);
qemuDomainReAttachHostDevices(driver, vm->def);
if (driver->securityDriver &&
driver->securityDriver->domainRestoreSecurityAllLabel)
@ -2889,7 +2879,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn,
qemuDomainPCIAddressSetFree(priv->pciaddrs);
priv->pciaddrs = NULL;
qemuDomainReAttachHostDevices(conn, driver, vm->def);
qemuDomainReAttachHostDevices(driver, vm->def);
retry:
if ((ret = qemuRemoveCgroup(conn, driver, vm, 0)) < 0) {
@ -5739,8 +5729,7 @@ no_memory:
}
static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
struct qemud_driver *driver,
static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev,
int qemuCmdFlags)
@ -5756,23 +5745,22 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
return -1;
}
pci = pciGetDevice(conn,
hostdev->source.subsys.u.pci.domain,
pci = pciGetDevice(hostdev->source.subsys.u.pci.domain,
hostdev->source.subsys.u.pci.bus,
hostdev->source.subsys.u.pci.slot,
hostdev->source.subsys.u.pci.function);
if (!pci)
return -1;
if (!pciDeviceIsAssignable(conn, pci, !driver->relaxedACS) ||
(hostdev->managed && pciDettachDevice(conn, pci) < 0) ||
pciResetDevice(conn, pci, driver->activePciHostdevs) < 0) {
pciFreeDevice(conn, pci);
if (!pciDeviceIsAssignable(pci, !driver->relaxedACS) ||
(hostdev->managed && pciDettachDevice(pci) < 0) ||
pciResetDevice(pci, driver->activePciHostdevs) < 0) {
pciFreeDevice(pci);
return -1;
}
if (pciDeviceListAdd(conn, driver->activePciHostdevs, pci) < 0) {
pciFreeDevice(conn, pci);
if (pciDeviceListAdd(driver->activePciHostdevs, pci) < 0) {
pciFreeDevice(pci);
return -1;
}
@ -5810,7 +5798,7 @@ error:
VIR_WARN0("Unable to release PCI address on host device");
VIR_FREE(devstr);
pciDeviceListDel(conn, driver->activePciHostdevs, pci);
pciDeviceListDel(driver->activePciHostdevs, pci);
return -1;
}
@ -5877,7 +5865,7 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn,
switch (hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (qemudDomainAttachHostPciDevice(conn, driver, vm,
if (qemudDomainAttachHostPciDevice(driver, vm,
hostdev, qemuCmdFlags) < 0)
goto error;
break;
@ -6333,8 +6321,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
ret = 0;
pci = pciGetDevice(conn,
detach->source.subsys.u.pci.domain,
pci = pciGetDevice(detach->source.subsys.u.pci.domain,
detach->source.subsys.u.pci.bus,
detach->source.subsys.u.pci.slot,
detach->source.subsys.u.pci.function);
@ -6342,11 +6329,11 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
ret = -1;
else {
pciDeviceSetManaged(pci, detach->managed);
pciDeviceListDel(conn, driver->activePciHostdevs, pci);
if (pciResetDevice(conn, pci, driver->activePciHostdevs) < 0)
pciDeviceListDel(driver->activePciHostdevs, pci);
if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
ret = -1;
qemudReattachManagedDevice(pci);
pciFreeDevice(conn, pci);
pciFreeDevice(pci);
}
if (vm->def->nhostdevs > 1) {
@ -8463,16 +8450,16 @@ qemudNodeDeviceDettach (virNodeDevicePtr dev)
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
if (pciDettachDevice(dev->conn, pci) < 0)
if (pciDettachDevice(pci) < 0)
goto out;
ret = 0;
out:
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}
@ -8486,16 +8473,16 @@ qemudNodeDeviceReAttach (virNodeDevicePtr dev)
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
if (pciReAttachDevice(dev->conn, pci) < 0)
if (pciReAttachDevice(pci) < 0)
goto out;
ret = 0;
out:
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}
@ -8510,19 +8497,19 @@ qemudNodeDeviceReset (virNodeDevicePtr dev)
if (qemudNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
qemuDriverLock(driver);
if (pciResetDevice(dev->conn, pci, driver->activePciHostdevs) < 0)
if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
goto out;
ret = 0;
out:
qemuDriverUnlock(driver);
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}

View File

@ -225,8 +225,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
pciDevice *pci = pciGetDevice(conn,
dev->source.subsys.u.pci.domain,
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
dev->source.subsys.u.pci.function);
@ -235,7 +234,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACSetSecurityPCILabel, vm);
pciFreeDevice(conn, pci);
pciFreeDevice(pci);
break;
}
@ -302,8 +301,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
pciDevice *pci = pciGetDevice(conn,
dev->source.subsys.u.pci.domain,
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
dev->source.subsys.u.pci.function);
@ -312,7 +310,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = pciDeviceFileIterate(conn, pci, qemuSecurityDACRestoreSecurityPCILabel, NULL);
pciFreeDevice(conn, pci);
pciFreeDevice(pci);
break;
}

View File

@ -513,8 +513,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
pciDevice *pci = pciGetDevice(conn,
dev->source.subsys.u.pci.domain,
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
dev->source.subsys.u.pci.function);
@ -523,7 +522,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = pciDeviceFileIterate(conn, pci, SELinuxSetSecurityPCILabel, vm);
pciFreeDevice(conn, pci);
pciFreeDevice(pci);
break;
}
@ -589,8 +588,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
pciDevice *pci = pciGetDevice(conn,
dev->source.subsys.u.pci.domain,
pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
dev->source.subsys.u.pci.function);
@ -599,7 +597,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = pciDeviceFileIterate(conn, pci, SELinuxRestoreSecurityPCILabel, NULL);
pciFreeDevice(conn, pci);
pciFreeDevice(pci);
break;
}

View File

@ -75,8 +75,8 @@ struct _pciDeviceList {
/* For virReportOOMError() and virReportSystemError() */
#define VIR_FROM_THIS VIR_FROM_NONE
#define pciReportError(conn, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
#define pciReportError(code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
/* Specifications referenced in comments:
@ -262,8 +262,7 @@ typedef int (*pciIterPredicate)(pciDevice *, pciDevice *, void *);
* safe to reset if there is an error.
*/
static int
pciIterDevices(virConnectPtr conn,
pciIterPredicate predicate,
pciIterDevices(pciIterPredicate predicate,
pciDevice *dev,
pciDevice **matched,
void *data)
@ -296,7 +295,7 @@ pciIterDevices(virConnectPtr conn,
continue;
}
check = pciGetDevice(conn, domain, bus, slot, function);
check = pciGetDevice(domain, bus, slot, function);
if (!check) {
ret = -1;
break;
@ -307,7 +306,7 @@ pciIterDevices(virConnectPtr conn,
*matched = check;
break;
}
pciFreeDevice(conn, check);
pciFreeDevice(check);
}
closedir(dir);
return ret;
@ -452,12 +451,11 @@ pciSharesBusWithActive(pciDevice *dev, pciDevice *check, void *data)
}
static pciDevice *
pciBusContainsActiveDevices(virConnectPtr conn,
pciDevice *dev,
pciBusContainsActiveDevices(pciDevice *dev,
pciDeviceList *activeDevs)
{
pciDevice *active = NULL;
if (pciIterDevices(conn, pciSharesBusWithActive,
if (pciIterDevices(pciSharesBusWithActive,
dev, &active, activeDevs) < 0)
return NULL;
return active;
@ -493,10 +491,10 @@ pciIsParent(pciDevice *dev, pciDevice *check, void *data ATTRIBUTE_UNUSED)
}
static pciDevice *
pciGetParentDevice(virConnectPtr conn, pciDevice *dev)
pciGetParentDevice(pciDevice *dev)
{
pciDevice *parent = NULL;
pciIterDevices(conn, pciIsParent, dev, &parent, NULL);
pciIterDevices(pciIsParent, dev, &parent, NULL);
return parent;
}
@ -504,8 +502,7 @@ pciGetParentDevice(virConnectPtr conn, pciDevice *dev)
* devices behind a bus.
*/
static int
pciTrySecondaryBusReset(virConnectPtr conn,
pciDevice *dev,
pciTrySecondaryBusReset(pciDevice *dev,
pciDeviceList *activeDevs)
{
pciDevice *parent, *conflict;
@ -518,17 +515,17 @@ pciTrySecondaryBusReset(virConnectPtr conn,
* In future, we could allow it so long as those devices
* are not in use by the host or other guests.
*/
if ((conflict = pciBusContainsActiveDevices(conn, dev, activeDevs))) {
pciReportError(conn, VIR_ERR_NO_SUPPORT,
if ((conflict = pciBusContainsActiveDevices(dev, activeDevs))) {
pciReportError(VIR_ERR_NO_SUPPORT,
_("Active %s devices on bus with %s, not doing bus reset"),
conflict->name, dev->name);
return -1;
}
/* Find the parent bus */
parent = pciGetParentDevice(conn, dev);
parent = pciGetParentDevice(dev);
if (!parent) {
pciReportError(conn, VIR_ERR_NO_SUPPORT,
pciReportError(VIR_ERR_NO_SUPPORT,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@ -541,7 +538,7 @@ pciTrySecondaryBusReset(virConnectPtr conn,
* are multiple devices/functions
*/
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"),
dev->name);
goto out;
@ -561,14 +558,14 @@ pciTrySecondaryBusReset(virConnectPtr conn,
usleep(200 * 1000); /* sleep 200ms */
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"),
dev->name);
goto out;
}
ret = 0;
out:
pciFreeDevice(conn, parent);
pciFreeDevice(parent);
return ret;
}
@ -577,7 +574,7 @@ out:
* above we require the device supports a full internal reset.
*/
static int
pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
pciTryPowerManagementReset(pciDevice *dev)
{
uint8_t config_space[PCI_CONF_LEN];
uint32_t ctl;
@ -587,7 +584,7 @@ pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
/* Save and restore the device's config space. */
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"),
dev->name);
return -1;
@ -607,7 +604,7 @@ pciTryPowerManagementReset(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
usleep(10 * 1000); /* sleep 10ms */
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"),
dev->name);
return -1;
@ -635,14 +632,13 @@ pciInitDevice(pciDevice *dev)
}
int
pciResetDevice(virConnectPtr conn,
pciDevice *dev,
pciResetDevice(pciDevice *dev,
pciDeviceList *activeDevs)
{
int ret = -1;
if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
pciReportError(conn, VIR_ERR_INTERNAL_ERROR,
pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Not resetting active device %s"), dev->name);
return -1;
}
@ -661,15 +657,15 @@ pciResetDevice(virConnectPtr conn,
* the function, not the whole device.
*/
if (dev->has_pm_reset)
ret = pciTryPowerManagementReset(conn, dev);
ret = pciTryPowerManagementReset(dev);
/* Bus reset is not an option with the root bus */
if (ret < 0 && dev->bus != 0)
ret = pciTrySecondaryBusReset(conn, dev, activeDevs);
ret = pciTrySecondaryBusReset(dev, activeDevs);
if (ret < 0) {
virErrorPtr err = virGetLastError();
pciReportError(conn, VIR_ERR_NO_SUPPORT,
pciReportError(VIR_ERR_NO_SUPPORT,
_("Unable to reset PCI device %s: %s"),
dev->name,
err ? err->message : _("no FLR, PM reset or bus reset available"));
@ -810,11 +806,11 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
}
int
pciDettachDevice(virConnectPtr conn, pciDevice *dev)
pciDettachDevice(pciDevice *dev)
{
const char *driver = pciFindStubDriver();
if (!driver) {
pciReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot find any PCI stub module"));
return -1;
}
@ -871,11 +867,11 @@ pciUnBindDeviceFromStub(pciDevice *dev, const char *driver)
}
int
pciReAttachDevice(virConnectPtr conn, pciDevice *dev)
pciReAttachDevice(pciDevice *dev)
{
const char *driver = pciFindStubDriver();
if (!driver) {
pciReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot find any PCI stub module"));
return -1;
}
@ -1006,8 +1002,7 @@ pciReadDeviceID(pciDevice *dev, const char *id_name)
}
pciDevice *
pciGetDevice(virConnectPtr conn,
unsigned domain,
pciGetDevice(unsigned domain,
unsigned bus,
unsigned slot,
unsigned function)
@ -1035,12 +1030,12 @@ pciGetDevice(virConnectPtr conn,
product = pciReadDeviceID(dev, "device");
if (!vendor || !product) {
pciReportError(conn, VIR_ERR_NO_SUPPORT,
pciReportError(VIR_ERR_NO_SUPPORT,
_("Failed to read product/vendor ID for %s"),
dev->name);
VIR_FREE(product);
VIR_FREE(vendor);
pciFreeDevice(conn, dev);
pciFreeDevice(dev);
return NULL;
}
@ -1056,7 +1051,7 @@ pciGetDevice(virConnectPtr conn,
}
void
pciFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
pciFreeDevice(pciDevice *dev)
{
if (!dev)
return;
@ -1077,7 +1072,7 @@ unsigned pciDeviceGetManaged(pciDevice *dev)
}
pciDeviceList *
pciDeviceListNew(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/)
pciDeviceListNew(void)
{
pciDeviceList *list;
@ -1090,8 +1085,7 @@ pciDeviceListNew(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/)
}
void
pciDeviceListFree(virConnectPtr conn,
pciDeviceList *list)
pciDeviceListFree(pciDeviceList *list)
{
int i;
@ -1099,7 +1093,7 @@ pciDeviceListFree(virConnectPtr conn,
return;
for (i = 0; i < list->count; i++) {
pciFreeDevice(conn, list->devs[i]);
pciFreeDevice(list->devs[i]);
list->devs[i] = NULL;
}
@ -1109,12 +1103,11 @@ pciDeviceListFree(virConnectPtr conn,
}
int
pciDeviceListAdd(virConnectPtr conn,
pciDeviceList *list,
pciDeviceListAdd(pciDeviceList *list,
pciDevice *dev)
{
if (pciDeviceListFind(list, dev)) {
pciReportError(conn, VIR_ERR_INTERNAL_ERROR,
pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is already in use"), dev->name);
return -1;
}
@ -1148,8 +1141,7 @@ pciDeviceListCount(pciDeviceList *list)
}
pciDevice *
pciDeviceListSteal(virConnectPtr conn ATTRIBUTE_UNUSED,
pciDeviceList *list,
pciDeviceListSteal(pciDeviceList *list,
pciDevice *dev)
{
pciDevice *ret = NULL;
@ -1179,13 +1171,12 @@ pciDeviceListSteal(virConnectPtr conn ATTRIBUTE_UNUSED,
}
void
pciDeviceListDel(virConnectPtr conn,
pciDeviceList *list,
pciDeviceListDel(pciDeviceList *list,
pciDevice *dev)
{
pciDevice *ret = pciDeviceListSteal(conn, list, dev);
pciDevice *ret = pciDeviceListSteal(list, dev);
if (ret)
pciFreeDevice(conn, ret);
pciFreeDevice(ret);
}
pciDevice *
@ -1289,12 +1280,11 @@ pciDeviceDownstreamLacksACS(pciDevice *dev)
}
static int
pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
pciDevice *dev)
pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
{
pciDevice *parent;
parent = pciGetParentDevice(conn, dev);
parent = pciGetParentDevice(dev);
if (!parent) {
/* 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
@ -1303,7 +1293,7 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
if (dev->bus == 0)
return 0;
else {
pciReportError(conn, VIR_ERR_NO_SUPPORT,
pciReportError(VIR_ERR_NO_SUPPORT,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@ -1321,7 +1311,7 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
acs = pciDeviceDownstreamLacksACS(parent);
if (acs) {
pciFreeDevice(conn, parent);
pciFreeDevice(parent);
if (acs < 0)
return -1;
else
@ -1329,15 +1319,14 @@ pciDeviceIsBehindSwitchLackingACS(virConnectPtr conn,
}
tmp = parent;
parent = pciGetParentDevice(conn, parent);
pciFreeDevice(conn, tmp);
parent = pciGetParentDevice(parent);
pciFreeDevice(tmp);
} while (parent);
return 0;
}
int pciDeviceIsAssignable(virConnectPtr conn,
pciDevice *dev,
int pciDeviceIsAssignable(pciDevice *dev,
int strict_acs_check)
{
int ret;
@ -1347,7 +1336,7 @@ int pciDeviceIsAssignable(virConnectPtr conn,
* or bound to a stub driver.
*/
ret = pciDeviceIsBehindSwitchLackingACS(conn, dev);
ret = pciDeviceIsBehindSwitchLackingACS(dev);
if (ret < 0)
return 0;
@ -1356,7 +1345,7 @@ int pciDeviceIsAssignable(virConnectPtr conn,
VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
dev->id, dev->name);
} else {
pciReportError(conn, VIR_ERR_NO_SUPPORT,
pciReportError(VIR_ERR_NO_SUPPORT,
_("Device %s is behind a switch lacking ACS and "
"cannot be assigned"),
dev->name);

View File

@ -27,38 +27,29 @@
typedef struct _pciDevice pciDevice;
typedef struct _pciDeviceList pciDeviceList;
pciDevice *pciGetDevice (virConnectPtr conn,
unsigned domain,
pciDevice *pciGetDevice (unsigned domain,
unsigned bus,
unsigned slot,
unsigned function);
void pciFreeDevice (virConnectPtr conn,
pciDevice *dev);
int pciDettachDevice (virConnectPtr conn,
pciDevice *dev);
int pciReAttachDevice (virConnectPtr conn,
pciDevice *dev);
int pciResetDevice (virConnectPtr conn,
pciDevice *dev,
void pciFreeDevice (pciDevice *dev);
int pciDettachDevice (pciDevice *dev);
int pciReAttachDevice (pciDevice *dev);
int pciResetDevice (pciDevice *dev,
pciDeviceList *activeDevs);
void pciDeviceSetManaged(pciDevice *dev,
unsigned managed);
unsigned pciDeviceGetManaged(pciDevice *dev);
pciDeviceList *pciDeviceListNew (virConnectPtr conn);
void pciDeviceListFree (virConnectPtr conn,
pciDeviceList *list);
int pciDeviceListAdd (virConnectPtr conn,
pciDeviceList *list,
pciDeviceList *pciDeviceListNew (void);
void pciDeviceListFree (pciDeviceList *list);
int pciDeviceListAdd (pciDeviceList *list,
pciDevice *dev);
pciDevice * pciDeviceListGet (pciDeviceList *list,
int idx);
int pciDeviceListCount (pciDeviceList *list);
pciDevice * pciDeviceListSteal (virConnectPtr conn,
pciDeviceList *list,
pciDevice * pciDeviceListSteal (pciDeviceList *list,
pciDevice *dev);
void pciDeviceListDel (virConnectPtr conn,
pciDeviceList *list,
void pciDeviceListDel (pciDeviceList *list,
pciDevice *dev);
pciDevice * pciDeviceListFind (pciDeviceList *list,
pciDevice *dev);
@ -78,8 +69,7 @@ int pciDeviceFileIterate(virConnectPtr conn,
pciDeviceFileActor actor,
void *opaque);
int pciDeviceIsAssignable(virConnectPtr conn,
pciDevice *dev,
int pciDeviceIsAssignable(pciDevice *dev,
int strict_acs_check);
int pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher);

View File

@ -1763,16 +1763,16 @@ xenUnifiedNodeDeviceDettach (virNodeDevicePtr dev)
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
if (pciDettachDevice(dev->conn, pci) < 0)
if (pciDettachDevice(pci) < 0)
goto out;
ret = 0;
out:
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}
@ -1786,16 +1786,16 @@ xenUnifiedNodeDeviceReAttach (virNodeDevicePtr dev)
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
if (pciReAttachDevice(dev->conn, pci) < 0)
if (pciReAttachDevice(pci) < 0)
goto out;
ret = 0;
out:
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}
@ -1809,16 +1809,16 @@ xenUnifiedNodeDeviceReset (virNodeDevicePtr dev)
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
return -1;
pci = pciGetDevice(dev->conn, domain, bus, slot, function);
pci = pciGetDevice(domain, bus, slot, function);
if (!pci)
return -1;
if (pciResetDevice(dev->conn, pci, NULL) < 0)
if (pciResetDevice(pci, NULL) < 0)
goto out;
ret = 0;
out:
pciFreeDevice(dev->conn, pci);
pciFreeDevice(pci);
return ret;
}