# usb.h
-usbDeviceFileIterate;
-usbDeviceGetBus;
-usbDeviceGetDevno;
-usbDeviceGetName;
-usbDeviceGetUsedBy;
-usbDeviceListAdd;
-usbDeviceListCount;
-usbDeviceListDel;
-usbDeviceListFind;
-usbDeviceListFree;
-usbDeviceListGet;
-usbDeviceListNew;
-usbDeviceListSteal;
-usbDeviceSetUsedBy;
-usbFindDevice;
-usbFindDeviceByBus;
-usbFindDeviceByVendor;
-usbFreeDevice;
-usbGetDevice;
+virUSBDeviceFileIterate;
+virUSBDeviceFind;
+virUSBDeviceFindByBus;
+virUSBDeviceFindByVendor;
+virUSBDeviceFree;
+virUSBDeviceGetBus;
+virUSBDeviceGetDevno;
+virUSBDeviceGetName;
+virUSBDeviceGetUsedBy;
+virUSBDeviceListAdd;
+virUSBDeviceListCount;
+virUSBDeviceListDel;
+virUSBDeviceListFind;
+virUSBDeviceListFree;
+virUSBDeviceListGet;
+virUSBDeviceListNew;
+virUSBDeviceListSteal;
+virUSBDeviceNew;
+virUSBDeviceSetUsedBy;
# util.h
int
-virLXCSetupHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
+virLXCSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *path,
void *opaque)
{
int
-virLXCTeardownHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
+virLXCTeardownHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *path,
void *opaque)
{
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
- usbDevice *usb;
+ virUSBDevicePtr usb;
switch (hostdev->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (hostdev->missing)
continue;
- if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL)) == NULL)
+ if ((usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL)) == NULL)
goto cleanup;
- if (usbDeviceFileIterate(usb, virLXCSetupHostUsbDeviceCgroup,
- cgroup) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceFileIterate(usb, virLXCSetupHostUsbDeviceCgroup,
+ cgroup) < 0) {
+ virUSBDeviceFree(usb);
goto cleanup;
}
- usbFreeDevice(usb);
+ virUSBDeviceFree(usb);
break;
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
switch (hostdev->source.caps.type) {
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo);
int
-virLXCSetupHostUsbDeviceCgroup(usbDevice *dev,
+virLXCSetupHostUsbDeviceCgroup(virUSBDevicePtr dev,
const char *path,
void *opaque);
int
-virLXCTeardownHostUsbDeviceCgroup(usbDevice *dev,
+virLXCTeardownHostUsbDeviceCgroup(virUSBDevicePtr dev,
const char *path,
void *opaque);
int log_libvirtd;
int have_netns;
- usbDeviceList *activeUsbHostdevs;
+ virUSBDeviceListPtr activeUsbHostdevs;
virDomainEventStatePtr domainEventState;
struct stat sb;
mode_t mode;
bool created = false;
- usbDevice *usb = NULL;
+ virUSBDevicePtr usb = NULL;
virCgroupPtr group = NULL;
if (virDomainHostdevFind(vm->def, def, NULL) >= 0) {
goto cleanup;
}
- if (!(usb = usbGetDevice(def->source.subsys.u.usb.bus,
- def->source.subsys.u.usb.device, vroot)))
+ if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
+ def->source.subsys.u.usb.device, vroot)))
goto cleanup;
if (stat(src, &sb) < 0) {
vm->def, def, vroot) < 0)
goto cleanup;
- if (usbDeviceFileIterate(usb,
+ if (virUSBDeviceFileIterate(usb,
virLXCSetupHostUsbDeviceCgroup,
&group) < 0)
goto cleanup;
if (ret < 0 && created)
unlink(dstfile);
- usbFreeDevice(usb);
+ virUSBDeviceFree(usb);
virCgroupFree(&group);
VIR_FREE(src);
VIR_FREE(dstfile);
int idx, ret = -1;
char *dst = NULL;
char *vroot;
- usbDevice *usb = NULL;
+ virUSBDevicePtr usb = NULL;
if ((idx = virDomainHostdevFind(vm->def,
dev->data.hostdev,
goto cleanup;
}
- if (!(usb = usbGetDevice(def->source.subsys.u.usb.bus,
- def->source.subsys.u.usb.device, vroot)))
+ if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
+ def->source.subsys.u.usb.device, vroot)))
goto cleanup;
VIR_DEBUG("Unlinking %s", dst);
}
virDomainAuditHostdev(vm, def, "detach", true);
- if (usbDeviceFileIterate(usb,
+ if (virUSBDeviceFileIterate(usb,
virLXCTeardownHostUsbDeviceCgroup,
&group) < 0)
VIR_WARN("cannot deny device %s for domain %s",
dst, vm->def->name);
- usbDeviceListDel(driver->activeUsbHostdevs, usb);
+ virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
ret = 0;
cleanup:
- usbFreeDevice(usb);
+ virUSBDeviceFree(usb);
VIR_FREE(dst);
virCgroupFree(&group);
return ret;
return 0;
for (i = 0; i < def->nhostdevs; i++) {
- usbDevice *usb = NULL;
+ virUSBDevicePtr usb = NULL;
hostdev = def->hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
- usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
+ usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL);
if (!usb) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
hostdev->source.subsys.u.usb.bus,
continue;
}
- usbDeviceSetUsedBy(usb, def->name);
+ virUSBDeviceSetUsedBy(usb, def->name);
- if (usbDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
+ virUSBDeviceFree(usb);
return -1;
}
}
int
virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
const char *name,
- usbDeviceList *list)
+ virUSBDeviceList *list)
{
size_t i, j;
unsigned int count;
- usbDevice *tmp;
+ virUSBDevicePtr tmp;
- count = usbDeviceListCount(list);
+ count = virUSBDeviceListCount(list);
for (i = 0; i < count; i++) {
- usbDevice *usb = usbDeviceListGet(list, i);
- if ((tmp = usbDeviceListFind(driver->activeUsbHostdevs, usb))) {
- const char *other_name = usbDeviceGetUsedBy(tmp);
+ virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
+ if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
+ const char *other_name = virUSBDeviceGetUsedBy(tmp);
if (other_name)
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is in use by domain %s"),
- usbDeviceGetName(tmp), other_name);
+ virUSBDeviceGetName(tmp), other_name);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is already in use"),
- usbDeviceGetName(tmp));
+ virUSBDeviceGetName(tmp));
goto error;
}
- usbDeviceSetUsedBy(usb, name);
+ virUSBDeviceSetUsedBy(usb, name);
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
- usbDeviceGetBus(usb), usbDeviceGetDevno(usb), name);
+ virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
/*
* The caller is responsible to steal these usb devices
- * from the usbDeviceList that passed in on success,
+ * from the virUSBDeviceList that passed in on success,
* perform rollback on failure.
*/
- if (usbDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
+ if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
goto error;
}
return 0;
error:
for (j = 0; j < i; j++) {
- tmp = usbDeviceListGet(list, i);
- usbDeviceListSteal(driver->activeUsbHostdevs, tmp);
+ tmp = virUSBDeviceListGet(list, i);
+ virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
}
return -1;
}
int
virLXCFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
bool mandatory,
- usbDevice **usb)
+ virUSBDevicePtr *usb)
{
unsigned vendor = hostdev->source.subsys.u.usb.vendor;
unsigned product = hostdev->source.subsys.u.usb.product;
*usb = NULL;
if (vendor && bus) {
- rc = usbFindDevice(vendor, product, bus, device,
- NULL,
- autoAddress ? false : mandatory,
- usb);
+ rc = virUSBDeviceFind(vendor, product, bus, device,
+ NULL,
+ autoAddress ? false : mandatory,
+ usb);
if (rc < 0) {
return -1;
} else if (!autoAddress) {
* automatically found before.
*/
if (vendor) {
- usbDeviceList *devs;
+ virUSBDeviceList *devs;
- rc = usbFindDeviceByVendor(vendor, product,
- NULL,
- mandatory, &devs);
+ rc = virUSBDeviceFindByVendor(vendor, product,
+ NULL,
+ mandatory, &devs);
if (rc < 0)
return -1;
if (rc == 1) {
- *usb = usbDeviceListGet(devs, 0);
- usbDeviceListSteal(devs, *usb);
+ *usb = virUSBDeviceListGet(devs, 0);
+ virUSBDeviceListSteal(devs, *usb);
}
- usbDeviceListFree(devs);
+ virUSBDeviceListFree(devs);
if (rc == 0) {
goto out;
return -1;
}
- hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(*usb);
- hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(*usb);
+ hostdev->source.subsys.u.usb.bus = virUSBDeviceGetBus(*usb);
+ hostdev->source.subsys.u.usb.device = virUSBDeviceGetDevno(*usb);
hostdev->source.subsys.u.usb.autoAddress = true;
if (autoAddress) {
bus, device);
}
} else if (!vendor && bus) {
- if (usbFindDeviceByBus(bus, device,
- NULL,
- mandatory, usb) < 0)
+ if (virUSBDeviceFindByBus(bus, device,
+ NULL,
+ mandatory, usb) < 0)
return -1;
}
{
size_t i;
int ret = -1;
- usbDeviceList *list;
- usbDevice *tmp;
+ virUSBDeviceList *list;
+ virUSBDevicePtr tmp;
virDomainHostdevDefPtr *hostdevs = def->hostdevs;
int nhostdevs = def->nhostdevs;
* This is done in several loops which cannot be joined into one big
* loop. See virLXCPrepareHostdevPCIDevices()
*/
- if (!(list = usbDeviceListNew()))
+ if (!(list = virUSBDeviceListNew()))
goto cleanup;
/* Loop 1: build temporary list
for (i = 0 ; i < nhostdevs ; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
bool required = true;
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (virLXCFindHostdevUSBDevice(hostdev, required, &usb) < 0)
goto cleanup;
- if (usb && usbDeviceListAdd(list, usb) < 0) {
- usbFreeDevice(usb);
+ if (usb && virUSBDeviceListAdd(list, usb) < 0) {
+ virUSBDeviceFree(usb);
goto cleanup;
}
}
* driver list, so steal all items to avoid freeing them
* in cleanup label.
*/
- while (usbDeviceListCount(list) > 0) {
- tmp = usbDeviceListGet(list, 0);
- usbDeviceListSteal(list, tmp);
+ while (virUSBDeviceListCount(list) > 0) {
+ tmp = virUSBDeviceListGet(list, 0);
+ virUSBDeviceListSteal(list, tmp);
}
ret = 0;
cleanup:
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return ret;
}
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
- usbDevice *usb, *tmp;
+ virUSBDevicePtr usb, tmp;
const char *used_by = NULL;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
if (hostdev->missing)
continue;
- usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
+ usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL);
if (!usb) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
* Therefore we want to steal only those devices from
* the list which were taken by @name */
- tmp = usbDeviceListFind(driver->activeUsbHostdevs, usb);
- usbFreeDevice(usb);
+ tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb);
+ virUSBDeviceFree(usb);
if (!tmp) {
VIR_WARN("Unable to find device %03d.%03d "
continue;
}
- used_by = usbDeviceGetUsedBy(tmp);
+ used_by = virUSBDeviceGetUsedBy(tmp);
if (STREQ_NULLABLE(used_by, name)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
name);
- usbDeviceListDel(driver->activeUsbHostdevs, tmp);
+ virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
}
}
}
virDomainDefPtr def);
int virLXCFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
bool mandatory,
- usbDevice **usb);
+ virUSBDevicePtr *usb);
int virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
const char *name,
- usbDeviceList *list);
+ virUSBDeviceListPtr list);
int virLXCPrepareHostDevices(virLXCDriverPtr driver,
virDomainDefPtr def);
void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
}
-int qemuSetupHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
+int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *path,
void *opaque)
{
for (i = 0; i < vm->def->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->missing)
continue;
- if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL)) == NULL)
+ if ((usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL)) == NULL)
goto cleanup;
- if (usbDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup,
- &data) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup,
+ &data) < 0) {
+ virUSBDeviceFree(usb);
goto cleanup;
}
- usbFreeDevice(usb);
+ virUSBDeviceFree(usb);
}
}
int qemuTeardownDiskCgroup(virDomainObjPtr vm,
virCgroupPtr cgroup,
virDomainDiskDefPtr disk);
-int qemuSetupHostUsbDeviceCgroup(usbDevice *dev,
+int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev,
const char *path,
void *opaque);
int qemuSetupCgroup(virQEMUDriverPtr driver,
virPCIDeviceListPtr activePciHostdevs;
virPCIDeviceListPtr inactivePciHostdevs;
- usbDeviceList *activeUsbHostdevs;
+ virUSBDeviceListPtr activeUsbHostdevs;
virHashTablePtr sharedDisks;
if ((qemu_driver->activePciHostdevs = virPCIDeviceListNew()) == NULL)
goto error;
- if ((qemu_driver->activeUsbHostdevs = usbDeviceListNew()) == NULL)
+ if ((qemu_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
goto error;
if ((qemu_driver->inactivePciHostdevs = virPCIDeviceListNew()) == NULL)
virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver);
virPCIDeviceListFree(qemu_driver->activePciHostdevs);
virPCIDeviceListFree(qemu_driver->inactivePciHostdevs);
- usbDeviceListFree(qemu_driver->activeUsbHostdevs);
+ virUSBDeviceListFree(qemu_driver->activeUsbHostdevs);
virHashFree(qemu_driver->sharedDisks);
virCapabilitiesFree(qemu_driver->caps);
qemuCapsCacheFree(qemu_driver->capsCache);
return 0;
for (i = 0; i < def->nhostdevs; i++) {
- usbDevice *usb = NULL;
+ virUSBDevicePtr usb = NULL;
hostdev = def->hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
- usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
+ usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL);
if (!usb) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
hostdev->source.subsys.u.usb.bus,
continue;
}
- usbDeviceSetUsedBy(usb, def->name);
+ virUSBDeviceSetUsedBy(usb, def->name);
- if (usbDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
+ virUSBDeviceFree(usb);
return -1;
}
}
int
qemuPrepareHostdevUSBDevices(virQEMUDriverPtr driver,
const char *name,
- usbDeviceList *list)
+ virUSBDeviceListPtr list)
{
int i, j;
unsigned int count;
- usbDevice *tmp;
+ virUSBDevicePtr tmp;
- count = usbDeviceListCount(list);
+ count = virUSBDeviceListCount(list);
for (i = 0; i < count; i++) {
- usbDevice *usb = usbDeviceListGet(list, i);
- if ((tmp = usbDeviceListFind(driver->activeUsbHostdevs, usb))) {
- const char *other_name = usbDeviceGetUsedBy(tmp);
+ virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
+ if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
+ const char *other_name = virUSBDeviceGetUsedBy(tmp);
if (other_name)
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is in use by domain %s"),
- usbDeviceGetName(tmp), other_name);
+ virUSBDeviceGetName(tmp), other_name);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is already in use"),
- usbDeviceGetName(tmp));
+ virUSBDeviceGetName(tmp));
goto error;
}
- usbDeviceSetUsedBy(usb, name);
+ virUSBDeviceSetUsedBy(usb, name);
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
- usbDeviceGetBus(usb), usbDeviceGetDevno(usb), name);
+ virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
/*
* The caller is responsible to steal these usb devices
- * from the usbDeviceList that passed in on success,
+ * from the virUSBDeviceList that passed in on success,
* perform rollback on failure.
*/
- if (usbDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
+ if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
goto error;
}
return 0;
error:
for (j = 0; j < i; j++) {
- tmp = usbDeviceListGet(list, i);
- usbDeviceListSteal(driver->activeUsbHostdevs, tmp);
+ tmp = virUSBDeviceListGet(list, i);
+ virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
}
return -1;
}
int
qemuFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
bool mandatory,
- usbDevice **usb)
+ virUSBDevicePtr *usb)
{
unsigned vendor = hostdev->source.subsys.u.usb.vendor;
unsigned product = hostdev->source.subsys.u.usb.product;
*usb = NULL;
if (vendor && bus) {
- rc = usbFindDevice(vendor, product, bus, device,
- NULL,
- autoAddress ? false : mandatory,
- usb);
+ rc = virUSBDeviceFind(vendor, product, bus, device,
+ NULL,
+ autoAddress ? false : mandatory,
+ usb);
if (rc < 0) {
return -1;
} else if (!autoAddress) {
* automatically found before.
*/
if (vendor) {
- usbDeviceList *devs;
+ virUSBDeviceListPtr devs;
- rc = usbFindDeviceByVendor(vendor, product, NULL, mandatory, &devs);
+ rc = virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, &devs);
if (rc < 0)
return -1;
if (rc == 1) {
- *usb = usbDeviceListGet(devs, 0);
- usbDeviceListSteal(devs, *usb);
+ *usb = virUSBDeviceListGet(devs, 0);
+ virUSBDeviceListSteal(devs, *usb);
}
- usbDeviceListFree(devs);
+ virUSBDeviceListFree(devs);
if (rc == 0) {
goto out;
return -1;
}
- hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(*usb);
- hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(*usb);
+ hostdev->source.subsys.u.usb.bus = virUSBDeviceGetBus(*usb);
+ hostdev->source.subsys.u.usb.device = virUSBDeviceGetDevno(*usb);
hostdev->source.subsys.u.usb.autoAddress = true;
if (autoAddress) {
bus, device);
}
} else if (!vendor && bus) {
- if (usbFindDeviceByBus(bus, device, NULL, mandatory, usb) < 0)
+ if (virUSBDeviceFindByBus(bus, device, NULL, mandatory, usb) < 0)
return -1;
}
bool coldBoot)
{
int i, ret = -1;
- usbDeviceList *list;
- usbDevice *tmp;
+ virUSBDeviceListPtr list;
+ virUSBDevicePtr tmp;
virDomainHostdevDefPtr *hostdevs = def->hostdevs;
int nhostdevs = def->nhostdevs;
* This is done in several loops which cannot be joined into one big
* loop. See qemuPrepareHostdevPCIDevices()
*/
- if (!(list = usbDeviceListNew()))
+ if (!(list = virUSBDeviceListNew()))
goto cleanup;
/* Loop 1: build temporary list
for (i = 0 ; i < nhostdevs ; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
bool required = true;
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (qemuFindHostdevUSBDevice(hostdev, required, &usb) < 0)
goto cleanup;
- if (usb && usbDeviceListAdd(list, usb) < 0) {
- usbFreeDevice(usb);
+ if (usb && virUSBDeviceListAdd(list, usb) < 0) {
+ virUSBDeviceFree(usb);
goto cleanup;
}
}
* driver list, so steal all items to avoid freeing them
* in cleanup label.
*/
- while (usbDeviceListCount(list) > 0) {
- tmp = usbDeviceListGet(list, 0);
- usbDeviceListSteal(list, tmp);
+ while (virUSBDeviceListCount(list) > 0) {
+ tmp = virUSBDeviceListGet(list, 0);
+ virUSBDeviceListSteal(list, tmp);
}
ret = 0;
cleanup:
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return ret;
}
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
- usbDevice *usb, *tmp;
+ virUSBDevicePtr usb, tmp;
const char *used_by = NULL;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
if (hostdev->missing)
continue;
- usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
+ usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
+ hostdev->source.subsys.u.usb.device,
+ NULL);
if (!usb) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
* Therefore we want to steal only those devices from
* the list which were taken by @name */
- tmp = usbDeviceListFind(driver->activeUsbHostdevs, usb);
- usbFreeDevice(usb);
+ tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb);
+ virUSBDeviceFree(usb);
if (!tmp) {
VIR_WARN("Unable to find device %03d.%03d "
continue;
}
- used_by = usbDeviceGetUsedBy(tmp);
+ used_by = virUSBDeviceGetUsedBy(tmp);
if (STREQ_NULLABLE(used_by, name)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
name);
- usbDeviceListDel(driver->activeUsbHostdevs, tmp);
+ virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
}
}
}
int nhostdevs);
int qemuFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
bool mandatory,
- usbDevice **usb);
+ virUSBDevicePtr *usb);
int qemuPrepareHostdevUSBDevices(virQEMUDriverPtr driver,
const char *name,
- usbDeviceList *list);
+ virUSBDeviceListPtr list);
int qemuPrepareHostDevices(virQEMUDriverPtr driver,
virDomainDefPtr def,
bool coldBoot);
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
virCgroupPtr cgroup = NULL;
- usbDevice *usb;
+ virUSBDevicePtr usb;
qemuCgroupData data;
if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
goto error;
}
- if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
+ if ((usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
NULL)) == NULL)
goto error;
data.vm = vm;
data.cgroup = cgroup;
- if (usbDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup, &data) < 0)
+ if (virUSBDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup, &data) < 0)
goto error;
}
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
- usbDeviceList *list;
- usbDevice *usb = NULL;
+ virUSBDeviceList *list;
+ virUSBDevicePtr usb = NULL;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
return -1;
}
- if (!(list = usbDeviceListNew()))
+ if (!(list = virUSBDeviceListNew()))
goto cleanup;
if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
if (qemuFindHostdevUSBDevice(hostdev, true, &usb) < 0)
goto cleanup;
- if (usbDeviceListAdd(list, usb) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceListAdd(list, usb) < 0) {
+ virUSBDeviceFree(usb);
usb = NULL;
goto cleanup;
}
goto cleanup;
}
- usbDeviceListSteal(list, usb);
+ virUSBDeviceListSteal(list, usb);
}
if (virSecurityManagerSetHostdevLabel(driver->securityManager,
goto error;
}
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return 0;
error:
VIR_WARN("Unable to restore host device labelling on hotplug fail");
cleanup:
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
if (usb)
- usbDeviceListSteal(driver->activeUsbHostdevs, usb);
+ virUSBDeviceListSteal(driver->activeUsbHostdevs, usb);
return -1;
}
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysPtr subsys = &detach->source.subsys;
- usbDevice *usb;
+ virUSBDevicePtr usb;
int ret;
if (!detach->info->alias) {
if (ret < 0)
return -1;
- usb = usbGetDevice(subsys->u.usb.bus, subsys->u.usb.device, NULL);
+ usb = virUSBDeviceNew(subsys->u.usb.bus, subsys->u.usb.device, NULL);
if (usb) {
- usbDeviceListDel(driver->activeUsbHostdevs, usb);
- usbFreeDevice(usb);
+ virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
+ virUSBDeviceFree(usb);
} else {
VIR_WARN("Unable to find device %03d.%03d in list of used USB devices",
subsys->u.usb.bus, subsys->u.usb.device);
}
static int
-AppArmorSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
+AppArmorSetSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
struct SDPDOP *ptr = opaque;
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- vroot);
+ virUSBDevicePtr usb =
+ virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ vroot);
if (!usb)
goto done;
- ret = usbDeviceFileIterate(usb, AppArmorSetSecurityUSBLabel, ptr);
- usbFreeDevice(usb);
+ ret = virUSBDeviceFileIterate(usb, AppArmorSetSecurityUSBLabel, ptr);
+ virUSBDeviceFree(usb);
break;
}
static int
-virSecurityDACSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
+virSecurityDACSetSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque)
{
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (dev->missing)
return 0;
- usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- vroot);
+ usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ vroot);
if (!usb)
goto done;
- ret = usbDeviceFileIterate(usb, virSecurityDACSetSecurityUSBLabel,
- params);
- usbFreeDevice(usb);
+ ret = virUSBDeviceFileIterate(usb, virSecurityDACSetSecurityUSBLabel,
+ params);
+ virUSBDeviceFree(usb);
break;
}
static int
-virSecurityDACRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
- const char *file,
- void *opaque ATTRIBUTE_UNUSED)
+virSecurityDACRestoreSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
+ const char *file,
+ void *opaque ATTRIBUTE_UNUSED)
{
return virSecurityDACRestoreSecurityFileLabel(file);
}
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (dev->missing)
return 0;
- usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- vroot);
+ usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ vroot);
if (!usb)
goto done;
- ret = usbDeviceFileIterate(usb, virSecurityDACRestoreSecurityUSBLabel, mgr);
- usbFreeDevice(usb);
+ ret = virUSBDeviceFileIterate(usb, virSecurityDACRestoreSecurityUSBLabel, mgr);
+ virUSBDeviceFree(usb);
break;
}
}
static int
-virSecuritySELinuxSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
+virSecuritySELinuxSetSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
virSecurityLabelDefPtr secdef;
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (dev->missing)
return 0;
- usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- vroot);
+ usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ vroot);
if (!usb)
goto done;
- ret = usbDeviceFileIterate(usb, virSecuritySELinuxSetSecurityUSBLabel, def);
- usbFreeDevice(usb);
+ ret = virUSBDeviceFileIterate(usb, virSecuritySELinuxSetSecurityUSBLabel, def);
+ virUSBDeviceFree(usb);
break;
}
}
static int
-virSecuritySELinuxRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
+virSecuritySELinuxRestoreSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque)
{
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb;
+ virUSBDevicePtr usb;
if (dev->missing)
return 0;
- usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- vroot);
+ usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ vroot);
if (!usb)
goto done;
- ret = usbDeviceFileIterate(usb, virSecuritySELinuxRestoreSecurityUSBLabel, mgr);
- usbFreeDevice(usb);
+ ret = virUSBDeviceFileIterate(usb, virSecuritySELinuxRestoreSecurityUSBLabel, mgr);
+ virUSBDeviceFree(usb);
break;
}
}
static int
-file_iterate_hostdev_cb(usbDevice *dev ATTRIBUTE_UNUSED,
+file_iterate_hostdev_cb(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
virBufferPtr buf = opaque;
virDomainHostdevDefPtr dev = ctl->def->hostdevs[i];
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
- dev->source.subsys.u.usb.device,
- NULL);
+ virUSBDevicePtr usb =
+ virUSBDeviceNew(dev->source.subsys.u.usb.bus,
+ dev->source.subsys.u.usb.device,
+ NULL);
if (usb == NULL)
continue;
- rc = usbDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf);
- usbFreeDevice(usb);
+ rc = virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf);
+ virUSBDeviceFree(usb);
if (rc != 0)
goto clean;
break;
/* For virReportOOMError() and virReportSystemError() */
#define VIR_FROM_THIS VIR_FROM_NONE
-struct _usbDevice {
+struct _virUSBDevice {
unsigned int bus;
unsigned int dev;
const char *used_by; /* name of the domain using this dev */
};
-struct _usbDeviceList {
+struct _virUSBDeviceList {
unsigned int count;
- usbDevice **devs;
+ virUSBDevicePtr *devs;
};
typedef enum {
USB_DEVICE_ALL = 0,
USB_DEVICE_FIND_BY_VENDOR = 1 << 0,
USB_DEVICE_FIND_BY_BUS = 1 << 1,
-} usbDeviceFindFlags;
+} virUSBDeviceFindFlags;
-static int usbSysReadFile(const char *f_name, const char *d_name,
- int base, unsigned int *value)
+static int virUSBSysReadFile(const char *f_name, const char *d_name,
+ int base, unsigned int *value)
{
int ret = -1, tmp;
char *buf = NULL;
return ret;
}
-static usbDeviceList *
-usbDeviceSearch(unsigned int vendor,
- unsigned int product,
- unsigned int bus,
- unsigned int devno,
- const char *vroot,
- unsigned int flags)
+static virUSBDeviceListPtr
+virUSBDeviceSearch(unsigned int vendor,
+ unsigned int product,
+ unsigned int bus,
+ unsigned int devno,
+ const char *vroot,
+ unsigned int flags)
{
DIR *dir = NULL;
bool found = false;
char *ignore = NULL;
struct dirent *de;
- usbDeviceList *list = NULL, *ret = NULL;
- usbDevice *usb;
+ virUSBDeviceListPtr list = NULL, ret = NULL;
+ virUSBDevicePtr usb;
- if (!(list = usbDeviceListNew()))
+ if (!(list = virUSBDeviceListNew()))
goto cleanup;
dir = opendir(USB_SYSFS "/devices");
if (de->d_name[0] == '.' || strchr(de->d_name, ':'))
continue;
- if (usbSysReadFile("idVendor", de->d_name,
- 16, &found_vend) < 0)
+ if (virUSBSysReadFile("idVendor", de->d_name,
+ 16, &found_vend) < 0)
goto cleanup;
- if (usbSysReadFile("idProduct", de->d_name,
- 16, &found_prod) < 0)
+ if (virUSBSysReadFile("idProduct", de->d_name,
+ 16, &found_prod) < 0)
goto cleanup;
if (STRPREFIX(de->d_name, "usb"))
goto cleanup;
}
- if (usbSysReadFile("devnum", de->d_name,
- 10, &found_devno) < 0)
+ if (virUSBSysReadFile("devnum", de->d_name,
+ 10, &found_devno) < 0)
goto cleanup;
if ((flags & USB_DEVICE_FIND_BY_VENDOR) &&
found = true;
}
- usb = usbGetDevice(found_bus, found_devno, vroot);
+ usb = virUSBDeviceNew(found_bus, found_devno, vroot);
if (!usb)
goto cleanup;
- if (usbDeviceListAdd(list, usb) < 0) {
- usbFreeDevice(usb);
+ if (virUSBDeviceListAdd(list, usb) < 0) {
+ virUSBDeviceFree(usb);
goto cleanup;
}
}
if (!ret)
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return ret;
}
int
-usbFindDeviceByVendor(unsigned int vendor,
- unsigned product,
- const char *vroot,
- bool mandatory,
- usbDeviceList **devices)
+virUSBDeviceFindByVendor(unsigned int vendor,
+ unsigned product,
+ const char *vroot,
+ bool mandatory,
+ virUSBDeviceListPtr *devices)
{
- usbDeviceList *list;
+ virUSBDeviceListPtr list;
int count;
- if (!(list = usbDeviceSearch(vendor, product, 0 , 0,
- vroot,
- USB_DEVICE_FIND_BY_VENDOR)))
+ if (!(list = virUSBDeviceSearch(vendor, product, 0 , 0,
+ vroot,
+ USB_DEVICE_FIND_BY_VENDOR)))
return -1;
if (list->count == 0) {
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device %x:%x",
vendor, product);
if (devices)
*devices = list;
else
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return count;
}
int
-usbFindDeviceByBus(unsigned int bus,
- unsigned devno,
- const char *vroot,
- bool mandatory,
- usbDevice **usb)
+virUSBDeviceFindByBus(unsigned int bus,
+ unsigned devno,
+ const char *vroot,
+ bool mandatory,
+ virUSBDevicePtr *usb)
{
- usbDeviceList *list;
+ virUSBDeviceListPtr list;
- if (!(list = usbDeviceSearch(0, 0, bus, devno,
- vroot,
- USB_DEVICE_FIND_BY_BUS)))
+ if (!(list = virUSBDeviceSearch(0, 0, bus, devno,
+ vroot,
+ USB_DEVICE_FIND_BY_BUS)))
return -1;
if (list->count == 0) {
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device bus:%u device:%u",
bus, devno);
}
if (usb) {
- *usb = usbDeviceListGet(list, 0);
- usbDeviceListSteal(list, *usb);
+ *usb = virUSBDeviceListGet(list, 0);
+ virUSBDeviceListSteal(list, *usb);
}
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return 0;
}
int
-usbFindDevice(unsigned int vendor,
- unsigned int product,
- unsigned int bus,
- unsigned int devno,
- const char *vroot,
- bool mandatory,
- usbDevice **usb)
+virUSBDeviceFind(unsigned int vendor,
+ unsigned int product,
+ unsigned int bus,
+ unsigned int devno,
+ const char *vroot,
+ bool mandatory,
+ virUSBDevicePtr *usb)
{
- usbDeviceList *list;
+ virUSBDeviceListPtr list;
unsigned int flags = USB_DEVICE_FIND_BY_VENDOR|USB_DEVICE_FIND_BY_BUS;
- if (!(list = usbDeviceSearch(vendor, product, bus, devno,
- vroot, flags)))
+ if (!(list = virUSBDeviceSearch(vendor, product, bus, devno,
+ vroot, flags)))
return -1;
if (list->count == 0) {
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
if (!mandatory) {
VIR_DEBUG("Did not find USB device %x:%x bus:%u device:%u",
vendor, product, bus, devno);
}
if (usb) {
- *usb = usbDeviceListGet(list, 0);
- usbDeviceListSteal(list, *usb);
+ *usb = virUSBDeviceListGet(list, 0);
+ virUSBDeviceListSteal(list, *usb);
}
- usbDeviceListFree(list);
+ virUSBDeviceListFree(list);
return 0;
}
-usbDevice *
-usbGetDevice(unsigned int bus,
- unsigned int devno,
- const char *vroot)
+virUSBDevicePtr
+virUSBDeviceNew(unsigned int bus,
+ unsigned int devno,
+ const char *vroot)
{
- usbDevice *dev;
+ virUSBDevicePtr dev;
if (VIR_ALLOC(dev) < 0) {
virReportOOMError();
virReportError(VIR_ERR_INTERNAL_ERROR,
_("dev->name buffer overflow: %.3o:%.3o"),
dev->bus, dev->dev);
- usbFreeDevice(dev);
+ virUSBDeviceFree(dev);
return NULL;
}
if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d",
vroot ? vroot : "",
dev->bus, dev->dev) < 0) {
virReportOOMError();
- usbFreeDevice(dev);
+ virUSBDeviceFree(dev);
return NULL;
}
virReportError(VIR_ERR_INTERNAL_ERROR,
_("dev->id buffer overflow: %d %d"),
dev->bus, dev->dev);
- usbFreeDevice(dev);
+ virUSBDeviceFree(dev);
return NULL;
}
}
void
-usbFreeDevice(usbDevice *dev)
+virUSBDeviceFree(virUSBDevicePtr dev)
{
if (!dev)
return;
}
-void usbDeviceSetUsedBy(usbDevice *dev,
- const char *name)
+void virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
+ const char *name)
{
dev->used_by = name;
}
-const char * usbDeviceGetUsedBy(usbDevice *dev)
+const char * virUSBDeviceGetUsedBy(virUSBDevicePtr dev)
{
return dev->used_by;
}
-const char *usbDeviceGetName(usbDevice *dev)
+const char *virUSBDeviceGetName(virUSBDevicePtr dev)
{
return dev->name;
}
-unsigned int usbDeviceGetBus(usbDevice *dev)
+unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev)
{
return dev->bus;
}
-unsigned int usbDeviceGetDevno(usbDevice *dev)
+unsigned int virUSBDeviceGetDevno(virUSBDevicePtr dev)
{
return dev->dev;
}
-int usbDeviceFileIterate(usbDevice *dev,
- usbDeviceFileActor actor,
- void *opaque)
+int virUSBDeviceFileIterate(virUSBDevicePtr dev,
+ virUSBDeviceFileActor actor,
+ void *opaque)
{
return (actor)(dev, dev->path, opaque);
}
-usbDeviceList *
-usbDeviceListNew(void)
+virUSBDeviceListPtr
+virUSBDeviceListNew(void)
{
- usbDeviceList *list;
+ virUSBDeviceListPtr list;
if (VIR_ALLOC(list) < 0) {
virReportOOMError();
}
void
-usbDeviceListFree(usbDeviceList *list)
+virUSBDeviceListFree(virUSBDeviceListPtr list)
{
int i;
return;
for (i = 0; i < list->count; i++)
- usbFreeDevice(list->devs[i]);
+ virUSBDeviceFree(list->devs[i]);
VIR_FREE(list->devs);
VIR_FREE(list);
}
int
-usbDeviceListAdd(usbDeviceList *list,
- usbDevice *dev)
+virUSBDeviceListAdd(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev)
{
- if (usbDeviceListFind(list, dev)) {
+ if (virUSBDeviceListFind(list, dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is already in use"),
dev->name);
return 0;
}
-usbDevice *
-usbDeviceListGet(usbDeviceList *list,
- int idx)
+virUSBDevicePtr
+virUSBDeviceListGet(virUSBDeviceListPtr list,
+ int idx)
{
if (idx >= list->count ||
idx < 0)
}
int
-usbDeviceListCount(usbDeviceList *list)
+virUSBDeviceListCount(virUSBDeviceListPtr list)
{
return list->count;
}
-usbDevice *
-usbDeviceListSteal(usbDeviceList *list,
- usbDevice *dev)
+virUSBDevicePtr
+virUSBDeviceListSteal(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev)
{
- usbDevice *ret = NULL;
+ virUSBDevicePtr ret = NULL;
int i;
for (i = 0; i < list->count; i++) {
}
void
-usbDeviceListDel(usbDeviceList *list,
- usbDevice *dev)
+virUSBDeviceListDel(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev)
{
- usbDevice *ret = usbDeviceListSteal(list, dev);
- usbFreeDevice(ret);
+ virUSBDevicePtr ret = virUSBDeviceListSteal(list, dev);
+ virUSBDeviceFree(ret);
}
-usbDevice *
-usbDeviceListFind(usbDeviceList *list,
- usbDevice *dev)
+virUSBDevicePtr
+virUSBDeviceListFind(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev)
{
int i;
# define USB_DEVFS "/dev/bus/usb/"
-typedef struct _usbDevice usbDevice;
-typedef struct _usbDeviceList usbDeviceList;
+typedef struct _virUSBDevice virUSBDevice;
+typedef virUSBDevice *virUSBDevicePtr;
+typedef struct _virUSBDeviceList virUSBDeviceList;
+typedef virUSBDeviceList *virUSBDeviceListPtr;
-usbDevice *usbGetDevice(unsigned int bus,
- unsigned int devno,
- const char *vroot);
+virUSBDevicePtr virUSBDeviceNew(unsigned int bus,
+ unsigned int devno,
+ const char *vroot);
-int usbFindDeviceByBus(unsigned int bus,
- unsigned int devno,
- const char *vroot,
- bool mandatory,
- usbDevice **usb);
-
-int usbFindDeviceByVendor(unsigned int vendor,
- unsigned int product,
+int virUSBDeviceFindByBus(unsigned int bus,
+ unsigned int devno,
const char *vroot,
bool mandatory,
- usbDeviceList **devices);
+ virUSBDevicePtr *usb);
+
+int virUSBDeviceFindByVendor(unsigned int vendor,
+ unsigned int product,
+ const char *vroot,
+ bool mandatory,
+ virUSBDeviceListPtr *devices);
-int usbFindDevice(unsigned int vendor,
- unsigned int product,
- unsigned int bus,
- unsigned int devno,
- const char *vroot,
- bool mandatory,
- usbDevice **usb);
+int virUSBDeviceFind(unsigned int vendor,
+ unsigned int product,
+ unsigned int bus,
+ unsigned int devno,
+ const char *vroot,
+ bool mandatory,
+ virUSBDevicePtr *usb);
-void usbFreeDevice (usbDevice *dev);
-void usbDeviceSetUsedBy(usbDevice *dev, const char *name);
-const char *usbDeviceGetUsedBy(usbDevice *dev);
-const char *usbDeviceGetName(usbDevice *dev);
+void virUSBDeviceFree(virUSBDevicePtr dev);
+void virUSBDeviceSetUsedBy(virUSBDevicePtr dev, const char *name);
+const char *virUSBDeviceGetUsedBy(virUSBDevicePtr dev);
+const char *virUSBDeviceGetName(virUSBDevicePtr dev);
-unsigned int usbDeviceGetBus(usbDevice *dev);
-unsigned int usbDeviceGetDevno(usbDevice *dev);
+unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
+unsigned int virUSBDeviceGetDevno(virUSBDevicePtr dev);
/*
* Callback that will be invoked once for each file
* Should return 0 if successfully processed, or
* -1 to indicate error and abort iteration
*/
-typedef int (*usbDeviceFileActor)(usbDevice *dev,
- const char *path, void *opaque);
+typedef int (*virUSBDeviceFileActor)(virUSBDevicePtr dev,
+ const char *path, void *opaque);
-int usbDeviceFileIterate(usbDevice *dev,
- usbDeviceFileActor actor,
- void *opaque);
+int virUSBDeviceFileIterate(virUSBDevicePtr dev,
+ virUSBDeviceFileActor actor,
+ void *opaque);
-usbDeviceList *usbDeviceListNew(void);
-void usbDeviceListFree(usbDeviceList *list);
-int usbDeviceListAdd(usbDeviceList *list,
- usbDevice *dev);
-usbDevice * usbDeviceListGet(usbDeviceList *list,
- int idx);
-int usbDeviceListCount(usbDeviceList *list);
-usbDevice * usbDeviceListSteal(usbDeviceList *list,
- usbDevice *dev);
-void usbDeviceListDel(usbDeviceList *list,
- usbDevice *dev);
-usbDevice * usbDeviceListFind(usbDeviceList *list,
- usbDevice *dev);
+virUSBDeviceListPtr virUSBDeviceListNew(void);
+void virUSBDeviceListFree(virUSBDeviceListPtr list);
+int virUSBDeviceListAdd(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev);
+virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
+ int idx);
+int virUSBDeviceListCount(virUSBDeviceListPtr list);
+virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev);
+void virUSBDeviceListDel(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev);
+virUSBDevicePtr virUSBDeviceListFind(virUSBDeviceListPtr list,
+ virUSBDevicePtr dev);
#endif /* __VIR_USB_H__ */