unsigned int flags)
{
virQEMUDriverPtr driver = dev->conn->privateData;
- virPCIDevicePtr pci;
+ virPCIDevicePtr pci = NULL;
unsigned domain, bus, slot, function;
int ret = -1;
- bool in_inactive_list = false;
+ bool in_inactive_list = true;
virNodeDeviceDefPtr def = NULL;
char *xml = NULL;
goto cleanup;
if (!driverName || STREQ(driverName, "kvm")) {
- virPCIDeviceSetStubDriver(pci, "pci-stub");
+ if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
+ goto cleanup;
} else if (STREQ(driverName, "vfio")) {
- virPCIDeviceSetStubDriver(pci, "vfio-pci");
+ if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
+ goto cleanup;
} else {
virReportError(VIR_ERR_INVALID_ARG,
_("unknown driver name '%s'"), driverName);
- goto out;
+ goto cleanup;
}
virObjectLock(driver->activePciHostdevs);
out:
virObjectUnlock(driver->inactivePciHostdevs);
virObjectUnlock(driver->activePciHostdevs);
+cleanup:
if (in_inactive_list)
virPCIDeviceFree(pci);
-cleanup:
virNodeDeviceDefFree(def);
VIR_FREE(xml);
return ret;
virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
- virPCIDeviceSetStubDriver(dev, "vfio-pci");
+ if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) {
+ virObjectUnref(list);
+ return NULL;
+ }
} else {
- virPCIDeviceSetStubDriver(dev, "pci-stub");
+ if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0) {
+ virObjectUnref(list);
+ return NULL;
+ }
}
}
virDomainDefPtr def)
{
virDomainHostdevDefPtr hostdev = NULL;
+ virPCIDevicePtr dev = NULL;
int i;
int ret = -1;
virObjectLock(driver->inactivePciHostdevs);
for (i = 0; i < def->nhostdevs; i++) {
- virPCIDevicePtr dev = NULL;
hostdev = def->hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
- virPCIDeviceSetStubDriver(dev, "vfio-pci");
+ if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0)
+ goto cleanup;
} else {
- virPCIDeviceSetStubDriver(dev, "pci-stub");
+ if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
+ goto cleanup;
+
}
virPCIDeviceSetUsedBy(dev, def->name);
virPCIDeviceSetRemoveSlot(dev, hostdev->origstates.states.pci.remove_slot);
virPCIDeviceSetReprobe(dev, hostdev->origstates.states.pci.reprobe);
- if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
- virPCIDeviceFree(dev);
+ if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0)
goto cleanup;
- }
+ dev = NULL;
}
ret = 0;
cleanup:
+ virPCIDeviceFree(dev);
virObjectUnlock(driver->activePciHostdevs);
virObjectUnlock(driver->inactivePciHostdevs);
return ret;
bool has_flr;
bool has_pm_reset;
bool managed;
- const char *stubDriver;
+ char *stubDriver;
/* used by reattach function */
bool unbind_from_stub;
return;
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
VIR_FREE(dev->path);
+ VIR_FREE(dev->stubDriver);
VIR_FREE(dev);
}
return dev->managed;
}
-void
+int
virPCIDeviceSetStubDriver(virPCIDevicePtr dev, const char *driver)
{
- dev->stubDriver = driver;
+ VIR_FREE(dev->stubDriver);
+ return driver ? VIR_STRDUP(dev->stubDriver, driver) : 0;
}
const char *
void virPCIDeviceSetManaged(virPCIDevice *dev,
bool managed);
unsigned int virPCIDeviceGetManaged(virPCIDevice *dev);
-void virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
- const char *driver);
+int virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
+ const char *driver);
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
void virPCIDeviceSetUsedBy(virPCIDevice *dev,
const char *used_by);
return -1;
if (!driverName) {
- virPCIDeviceSetStubDriver(pci, "pciback");
+ if (virPCIDeviceSetStubDriver(pci, "pciback") < 0)
+ goto out;
} else {
virReportError(VIR_ERR_INVALID_ARG,
_("unknown driver name '%s'"), driverName);