virPCIDeviceListDel;
virPCIDeviceListFind;
virPCIDeviceListFindIndex;
-virPCIDeviceListFree;
virPCIDeviceListGet;
virPCIDeviceListNew;
virPCIDeviceListSteal;
virUSBDeviceListCount;
virUSBDeviceListDel;
virUSBDeviceListFind;
-virUSBDeviceListFree;
virUSBDeviceListGet;
virUSBDeviceListNew;
virUSBDeviceListSteal;
*usb = virUSBDeviceListGet(devs, 0);
virUSBDeviceListSteal(devs, *usb);
}
- virUSBDeviceListFree(devs);
+ virObjectUnref(devs);
if (rc == 0) {
goto out;
ret = 0;
cleanup:
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return ret;
}
qemuDriverLock(qemu_driver);
virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver);
- virPCIDeviceListFree(qemu_driver->activePciHostdevs);
- virPCIDeviceListFree(qemu_driver->inactivePciHostdevs);
- virUSBDeviceListFree(qemu_driver->activeUsbHostdevs);
+ virObjectUnref(qemu_driver->activePciHostdevs);
+ virObjectUnref(qemu_driver->inactivePciHostdevs);
+ virObjectUnref(qemu_driver->activeUsbHostdevs);
virHashFree(qemu_driver->sharedDisks);
virCapabilitiesFree(qemu_driver->caps);
qemuCapsCacheFree(qemu_driver->capsCache);
hostdev->source.subsys.u.pci.slot,
hostdev->source.subsys.u.pci.function);
if (!dev) {
- virPCIDeviceListFree(list);
+ virObjectUnref(list);
return NULL;
}
if (virPCIDeviceListAdd(list, dev) < 0) {
virPCIDeviceFree(dev);
- virPCIDeviceListFree(list);
+ virObjectUnref(list);
return NULL;
}
hostdev->source.subsys.u.pci.slot,
hostdev->source.subsys.u.pci.function);
if (!dev) {
- virPCIDeviceListFree(list);
+ virObjectUnref(list);
return NULL;
}
if ((activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev))) {
if (virPCIDeviceListAdd(list, activeDev) < 0) {
virPCIDeviceFree(dev);
- virPCIDeviceListFree(list);
+ virObjectUnref(list);
return NULL;
}
}
inactivedevs:
/* Only steal all the devices from driver->activePciHostdevs. We will
- * free them in virPCIDeviceListFree().
+ * free them in virObjectUnref().
*/
while (virPCIDeviceListCount(pcidevs) > 0) {
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, 0);
}
cleanup:
- virPCIDeviceListFree(pcidevs);
+ virObjectUnref(pcidevs);
virObjectUnref(cfg);
return ret;
}
*usb = virUSBDeviceListGet(devs, 0);
virUSBDeviceListSteal(devs, *usb);
}
- virUSBDeviceListFree(devs);
+ virObjectUnref(devs);
if (rc == 0) {
goto out;
ret = 0;
cleanup:
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return ret;
}
continue;
}
- /* virPCIDeviceListFree() will take care of freeing the dev. */
+ /* virObjectUnref() will take care of freeing the dev. */
virPCIDeviceListSteal(driver->activePciHostdevs, dev);
}
qemuReattachPciDevice(dev, driver);
}
- virPCIDeviceListFree(pcidevs);
+ virObjectUnref(pcidevs);
cleanup:
virObjectUnref(cfg);
}
goto error;
}
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return 0;
error:
VIR_WARN("Unable to restore host device labelling on hotplug fail");
cleanup:
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
if (usb)
virUSBDeviceListSteal(driver->activeUsbHostdevs, usb);
return -1;
};
struct _virPCIDeviceList {
+ virObjectLockable parent;
+
unsigned count;
virPCIDevicePtr *devs;
};
PCI_EXT_CAP_ACS_CR | \
PCI_EXT_CAP_ACS_UF)
+static virClassPtr virPCIDeviceListClass;
+
+static void virPCIDeviceListDispose(void *obj);
+
+static int virPCIOnceInit(void)
+{
+ if (!(virPCIDeviceListClass = virClassNew(virClassForObjectLockable(),
+ "virPCIDeviceList",
+ sizeof(virPCIDeviceList),
+ virPCIDeviceListDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virPCI)
+
static int
virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal)
{
{
virPCIDeviceListPtr list;
- if (VIR_ALLOC(list) < 0) {
- virReportOOMError();
+ if (virPCIInitialize() < 0)
+ return NULL;
+
+ if (!(list = virObjectLockableNew(virPCIDeviceListClass)))
return NULL;
- }
return list;
}
-void
-virPCIDeviceListFree(virPCIDeviceListPtr list)
+static void
+virPCIDeviceListDispose(void *obj)
{
+ virPCIDeviceListPtr list = obj;
int i;
- if (!list)
- return;
-
for (i = 0; i < list->count; i++) {
virPCIDeviceFree(list->devs[i]);
list->devs[i] = NULL;
list->count = 0;
VIR_FREE(list->devs);
- VIR_FREE(list);
}
int
# define __VIR_PCI_H__
# include "internal.h"
+# include "virobject.h"
typedef struct _virPCIDevice virPCIDevice;
typedef virPCIDevice *virPCIDevicePtr;
virPCIDeviceListPtr virPCIDeviceListNew(void);
-void virPCIDeviceListFree(virPCIDeviceListPtr list);
int virPCIDeviceListAdd(virPCIDeviceListPtr list,
virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
};
struct _virUSBDeviceList {
+ virObjectLockable parent;
unsigned int count;
virUSBDevicePtr *devs;
};
USB_DEVICE_FIND_BY_BUS = 1 << 1,
} virUSBDeviceFindFlags;
+static virClassPtr virUSBDeviceListClass;
+
+static void virUSBDeviceListDispose(void *obj);
+
+static int virUSBOnceInit(void)
+{
+ if (!(virUSBDeviceListClass = virClassNew(virClassForObjectLockable(),
+ "virUSBDeviceList",
+ sizeof(virUSBDeviceList),
+ virUSBDeviceListDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virUSB)
+
static int virUSBSysReadFile(const char *f_name, const char *d_name,
int base, unsigned int *value)
{
}
if (!ret)
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return ret;
}
return -1;
if (list->count == 0) {
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device %x:%x",
vendor, product);
if (devices)
*devices = list;
else
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return count;
}
return -1;
if (list->count == 0) {
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device bus:%u device:%u",
bus, devno);
*usb = virUSBDeviceListGet(list, 0);
virUSBDeviceListSteal(list, *usb);
}
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return 0;
}
return -1;
if (list->count == 0) {
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device %x:%x bus:%u device:%u",
vendor, product, bus, devno);
*usb = virUSBDeviceListGet(list, 0);
virUSBDeviceListSteal(list, *usb);
}
- virUSBDeviceListFree(list);
+ virObjectUnref(list);
return 0;
}
{
virUSBDeviceListPtr list;
- if (VIR_ALLOC(list) < 0) {
- virReportOOMError();
+ if (virUSBInitialize() < 0)
+ return NULL;
+
+ if (!(list = virObjectLockableNew(virUSBDeviceListClass)))
return NULL;
- }
return list;
}
-void
-virUSBDeviceListFree(virUSBDeviceListPtr list)
+static void
+virUSBDeviceListDispose(void *obj)
{
+ virUSBDeviceListPtr list = obj;
int i;
- if (!list)
- return;
-
for (i = 0; i < list->count; i++)
virUSBDeviceFree(list->devs[i]);
VIR_FREE(list->devs);
- VIR_FREE(list);
}
int
# define __VIR_USB_H__
# include "internal.h"
+# include "virobject.h"
# define USB_DEVFS "/dev/bus/usb/"
void *opaque);
virUSBDeviceListPtr virUSBDeviceListNew(void);
-void virUSBDeviceListFree(virUSBDeviceListPtr list);
int virUSBDeviceListAdd(virUSBDeviceListPtr list,
virUSBDevicePtr dev);
virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,