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

View File

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

View File

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

View File

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

View File

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