1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

pci: change stubDriver from const char* to char*

Previously stubDriver was always set from a string literal, so it was
okay to use a const char * that wasn't freed when the virPCIDevice was
freed. This will not be the case in the near future, so it is now a
char* that is allocated in virPCIDeviceSetStubDriver() and freed
during virPCIDeviceFree().
This commit is contained in:
Laine Stump 2013-05-31 14:26:56 -04:00
parent d80d0d5d40
commit 53e52b4ac3
5 changed files with 34 additions and 20 deletions

View File

@ -10575,10 +10575,10 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
unsigned int flags) unsigned int flags)
{ {
virQEMUDriverPtr driver = dev->conn->privateData; virQEMUDriverPtr driver = dev->conn->privateData;
virPCIDevicePtr pci; virPCIDevicePtr pci = NULL;
unsigned domain, bus, slot, function; unsigned domain, bus, slot, function;
int ret = -1; int ret = -1;
bool in_inactive_list = false; bool in_inactive_list = true;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *xml = NULL; char *xml = NULL;
@ -10603,13 +10603,15 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
goto cleanup; goto cleanup;
if (!driverName || STREQ(driverName, "kvm")) { if (!driverName || STREQ(driverName, "kvm")) {
virPCIDeviceSetStubDriver(pci, "pci-stub"); if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
goto cleanup;
} else if (STREQ(driverName, "vfio")) { } else if (STREQ(driverName, "vfio")) {
virPCIDeviceSetStubDriver(pci, "vfio-pci"); if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
goto cleanup;
} else { } else {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unknown driver name '%s'"), driverName); _("unknown driver name '%s'"), driverName);
goto out; goto cleanup;
} }
virObjectLock(driver->activePciHostdevs); virObjectLock(driver->activePciHostdevs);
@ -10624,9 +10626,9 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
out: out:
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(driver->inactivePciHostdevs);
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(driver->activePciHostdevs);
cleanup:
if (in_inactive_list) if (in_inactive_list)
virPCIDeviceFree(pci); virPCIDeviceFree(pci);
cleanup:
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
VIR_FREE(xml); VIR_FREE(xml);
return ret; return ret;

View File

@ -70,9 +70,15 @@ qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
virPCIDeviceSetManaged(dev, hostdev->managed); virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend if (hostdev->source.subsys.u.pci.backend
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
virPCIDeviceSetStubDriver(dev, "vfio-pci"); if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) {
virObjectUnref(list);
return NULL;
}
} else { } else {
virPCIDeviceSetStubDriver(dev, "pci-stub"); if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0) {
virObjectUnref(list);
return NULL;
}
} }
} }
@ -130,6 +136,7 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
virDomainDefPtr def) virDomainDefPtr def)
{ {
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
virPCIDevicePtr dev = NULL;
int i; int i;
int ret = -1; int ret = -1;
@ -140,7 +147,6 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
virObjectLock(driver->inactivePciHostdevs); virObjectLock(driver->inactivePciHostdevs);
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < def->nhostdevs; i++) {
virPCIDevicePtr dev = NULL;
hostdev = def->hostdevs[i]; hostdev = def->hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
@ -159,9 +165,12 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
virPCIDeviceSetManaged(dev, hostdev->managed); virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend if (hostdev->source.subsys.u.pci.backend
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
virPCIDeviceSetStubDriver(dev, "vfio-pci"); if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0)
goto cleanup;
} else { } else {
virPCIDeviceSetStubDriver(dev, "pci-stub"); if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
goto cleanup;
} }
virPCIDeviceSetUsedBy(dev, def->name); virPCIDeviceSetUsedBy(dev, def->name);
@ -170,14 +179,14 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
virPCIDeviceSetRemoveSlot(dev, hostdev->origstates.states.pci.remove_slot); virPCIDeviceSetRemoveSlot(dev, hostdev->origstates.states.pci.remove_slot);
virPCIDeviceSetReprobe(dev, hostdev->origstates.states.pci.reprobe); virPCIDeviceSetReprobe(dev, hostdev->origstates.states.pci.reprobe);
if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0) { if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0)
virPCIDeviceFree(dev);
goto cleanup; goto cleanup;
} dev = NULL;
} }
ret = 0; ret = 0;
cleanup: cleanup:
virPCIDeviceFree(dev);
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(driver->activePciHostdevs);
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(driver->inactivePciHostdevs);
return ret; return ret;

View File

@ -69,7 +69,7 @@ struct _virPCIDevice {
bool has_flr; bool has_flr;
bool has_pm_reset; bool has_pm_reset;
bool managed; bool managed;
const char *stubDriver; char *stubDriver;
/* used by reattach function */ /* used by reattach function */
bool unbind_from_stub; bool unbind_from_stub;
@ -1480,6 +1480,7 @@ virPCIDeviceFree(virPCIDevicePtr dev)
return; return;
VIR_DEBUG("%s %s: freeing", dev->id, dev->name); VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
VIR_FREE(dev->path); VIR_FREE(dev->path);
VIR_FREE(dev->stubDriver);
VIR_FREE(dev); VIR_FREE(dev);
} }
@ -1500,10 +1501,11 @@ virPCIDeviceGetManaged(virPCIDevicePtr dev)
return dev->managed; return dev->managed;
} }
void int
virPCIDeviceSetStubDriver(virPCIDevicePtr dev, const char *driver) virPCIDeviceSetStubDriver(virPCIDevicePtr dev, const char *driver)
{ {
dev->stubDriver = driver; VIR_FREE(dev->stubDriver);
return driver ? VIR_STRDUP(dev->stubDriver, driver) : 0;
} }
const char * const char *

View File

@ -62,7 +62,7 @@ int virPCIDeviceReset(virPCIDevicePtr dev,
void virPCIDeviceSetManaged(virPCIDevice *dev, void virPCIDeviceSetManaged(virPCIDevice *dev,
bool managed); bool managed);
unsigned int virPCIDeviceGetManaged(virPCIDevice *dev); unsigned int virPCIDeviceGetManaged(virPCIDevice *dev);
void virPCIDeviceSetStubDriver(virPCIDevicePtr dev, int virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
const char *driver); const char *driver);
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev); const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
void virPCIDeviceSetUsedBy(virPCIDevice *dev, void virPCIDeviceSetUsedBy(virPCIDevice *dev,

View File

@ -2432,7 +2432,8 @@ xenUnifiedNodeDeviceDetachFlags(virNodeDevicePtr dev,
return -1; return -1;
if (!driverName) { if (!driverName) {
virPCIDeviceSetStubDriver(pci, "pciback"); if (virPCIDeviceSetStubDriver(pci, "pciback") < 0)
goto out;
} else { } else {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unknown driver name '%s'"), driverName); _("unknown driver name '%s'"), driverName);