Remove conn parameter from USB functions

It was used for error reporting only.
This commit is contained in:
Matthias Bolte 2010-02-05 00:25:16 +01:00
parent 46ef463135
commit 314ced3951
5 changed files with 30 additions and 40 deletions

View File

@ -210,8 +210,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
usbDevice *usb = usbGetDevice(conn,
dev->source.subsys.u.usb.bus,
usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
dev->source.subsys.u.usb.vendor,
dev->source.subsys.u.usb.product);
@ -220,7 +219,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = usbDeviceFileIterate(conn, usb, qemuSecurityDACSetSecurityUSBLabel, vm);
usbFreeDevice(conn, usb);
usbFreeDevice(usb);
break;
}
@ -285,8 +284,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
usbDevice *usb = usbGetDevice(conn,
dev->source.subsys.u.usb.bus,
usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
dev->source.subsys.u.usb.vendor,
dev->source.subsys.u.usb.product);
@ -295,7 +293,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = usbDeviceFileIterate(conn, usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL);
usbFreeDevice(conn, usb);
usbFreeDevice(usb);
break;
}

View File

@ -498,8 +498,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
usbDevice *usb = usbGetDevice(conn,
dev->source.subsys.u.usb.bus,
usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
dev->source.subsys.u.usb.vendor,
dev->source.subsys.u.usb.product);
@ -508,7 +507,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = usbDeviceFileIterate(conn, usb, SELinuxSetSecurityUSBLabel, vm);
usbFreeDevice(conn, usb);
usbFreeDevice(usb);
break;
}
@ -572,8 +571,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
usbDevice *usb = usbGetDevice(conn,
dev->source.subsys.u.usb.bus,
usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
dev->source.subsys.u.usb.vendor,
dev->source.subsys.u.usb.product);
@ -582,7 +580,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
goto done;
ret = usbDeviceFileIterate(conn, usb, SELinuxRestoreSecurityUSBLabel, NULL);
usbFreeDevice(conn, usb);
usbFreeDevice(usb);
break;
}

View File

@ -836,8 +836,7 @@ get_files(vahControl * ctl)
virDomainHostdevDefPtr dev = ctl->def->hostdevs[i];
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
usbDevice *usb = usbGetDevice(NULL,
dev->source.subsys.u.usb.bus,
usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
dev->source.subsys.u.usb.vendor,
dev->source.subsys.u.usb.product);
@ -847,14 +846,14 @@ get_files(vahControl * ctl)
rc = usbDeviceFileIterate(NULL, usb,
file_iterate_cb, &buf);
usbFreeDevice(NULL, usb);
usbFreeDevice(usb);
if (rc != 0)
goto clean;
break;
}
/* TODO: update so files in /sys are readonly
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
pciDevice *pci = pciGetDevice(NULL,
pciDevice *pci = pciGetDevice(
dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
@ -864,7 +863,7 @@ get_files(vahControl * ctl)
continue;
rc = pciDeviceFileIterate(NULL, pci, file_iterate_cb, &buf);
pciFreeDevice(NULL, pci);
pciFreeDevice(pci);
break;
}

View File

@ -54,12 +54,11 @@ struct _usbDevice {
/* For virReportOOMError() and virReportSystemError() */
#define VIR_FROM_THIS VIR_FROM_NONE
#define usbReportError(conn, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
#define usbReportError(code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
static int usbSysReadFile(virConnectPtr conn,
const char *f_name, const char *d_name,
static int usbSysReadFile(const char *f_name, const char *d_name,
int base, unsigned *value)
{
int ret = -1, tmp;
@ -77,7 +76,7 @@ static int usbSysReadFile(virConnectPtr conn,
goto cleanup;
if (virStrToLong_ui(buf, &ignore, base, value) < 0) {
usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
usbReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse usb file %s"), filename);
goto cleanup;
}
@ -89,8 +88,7 @@ cleanup:
return ret;
}
static int usbFindBusByVendor(virConnectPtr conn,
unsigned vendor, unsigned product,
static int usbFindBusByVendor(unsigned vendor, unsigned product,
unsigned *bus, unsigned *devno)
{
DIR *dir = NULL;
@ -111,10 +109,10 @@ static int usbFindBusByVendor(virConnectPtr conn,
if (de->d_name[0] == '.' || strchr(de->d_name, ':'))
continue;
if (usbSysReadFile(conn, "idVendor", de->d_name,
if (usbSysReadFile("idVendor", de->d_name,
16, &found_vend) < 0)
goto cleanup;
if (usbSysReadFile(conn, "idProduct", de->d_name,
if (usbSysReadFile("idProduct", de->d_name,
16, &found_prod) < 0)
goto cleanup;
@ -127,13 +125,13 @@ static int usbFindBusByVendor(virConnectPtr conn,
tmpstr += 3;
if (virStrToLong_ui(tmpstr, &ignore, 10, &found_bus) < 0) {
usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
usbReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse dir name '%s'"),
de->d_name);
goto cleanup;
}
if (usbSysReadFile(conn, "devnum", de->d_name,
if (usbSysReadFile("devnum", de->d_name,
10, &found_addr) < 0)
goto cleanup;
@ -145,7 +143,7 @@ static int usbFindBusByVendor(virConnectPtr conn,
}
if (!found)
usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
usbReportError(VIR_ERR_INTERNAL_ERROR,
_("Did not find USB device %x:%x"), vendor, product);
else
ret = 0;
@ -160,8 +158,7 @@ cleanup:
}
usbDevice *
usbGetDevice(virConnectPtr conn,
unsigned bus,
usbGetDevice(unsigned bus,
unsigned devno,
unsigned vendor,
unsigned product)
@ -175,7 +172,7 @@ usbGetDevice(virConnectPtr conn,
if (vendor) {
/* Look up bus.dev by vendor:product */
if (usbFindBusByVendor(conn, vendor, product, &bus, &devno) < 0) {
if (usbFindBusByVendor(vendor, product, &bus, &devno) < 0) {
VIR_FREE(dev);
return NULL;
}
@ -198,7 +195,7 @@ usbGetDevice(virConnectPtr conn,
}
void
usbFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, usbDevice *dev)
usbFreeDevice(usbDevice *dev)
{
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
VIR_FREE(dev);

View File

@ -26,13 +26,11 @@
typedef struct _usbDevice usbDevice;
usbDevice *usbGetDevice (virConnectPtr conn,
unsigned bus,
usbDevice *usbGetDevice (unsigned bus,
unsigned devno,
unsigned vendor,
unsigned product);
void usbFreeDevice (virConnectPtr conn,
usbDevice *dev);
void usbFreeDevice (usbDevice *dev);
/*
* Callback that will be invoked once for each file