提交 7540d07f 编写于 作者: J John Ferlan

hostdev: Introduce virDomainHostdevSubsysUSB

Create a separate typedef for the hostdev union data describing USB.
Then adjust the code to use the new pointer
上级 185e07a5
......@@ -388,6 +388,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
char *address = NULL;
char *device = NULL;
const char *virt;
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
virUUIDFormat(vm->def->uuid, uuidstr);
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
......@@ -415,8 +416,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
if (virAsprintfQuiet(&address, "%.3d.%.3d",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device) < 0) {
usbsrc->bus, usbsrc->device) < 0) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
......
......@@ -3793,6 +3793,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
xmlNodePtr cur;
char *startupPolicy = NULL;
char *autoAddress;
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) {
def->startupPolicy =
......@@ -3809,7 +3810,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
if ((autoAddress = virXMLPropString(node, "autoAddress"))) {
if (STREQ(autoAddress, "yes"))
def->source.subsys.u.usb.autoAddress = true;
usbsrc->autoAddress = true;
VIR_FREE(autoAddress);
}
......@@ -3826,8 +3827,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
if (vendor) {
got_vendor = true;
if (virStrToLong_ui(vendor, NULL, 0,
&def->source.subsys.u.usb.vendor) < 0) {
if (virStrToLong_ui(vendor, NULL, 0, &usbsrc->vendor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse vendor id %s"), vendor);
VIR_FREE(vendor);
......@@ -3845,7 +3845,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
if (product) {
got_product = true;
if (virStrToLong_ui(product, NULL, 0,
&def->source.subsys.u.usb.product) < 0) {
&usbsrc->product) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse product %s"),
product);
......@@ -3863,8 +3863,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
bus = virXMLPropString(cur, "bus");
if (bus) {
if (virStrToLong_ui(bus, NULL, 0,
&def->source.subsys.u.usb.bus) < 0) {
if (virStrToLong_ui(bus, NULL, 0, &usbsrc->bus) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse bus %s"), bus);
VIR_FREE(bus);
......@@ -3879,8 +3878,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
device = virXMLPropString(cur, "device");
if (device) {
if (virStrToLong_ui(device, NULL, 0,
&def->source.subsys.u.usb.device) < 0) {
if (virStrToLong_ui(device, NULL, 0, &usbsrc->device) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse device %s"),
device);
......@@ -3903,7 +3901,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
cur = cur->next;
}
if (got_vendor && def->source.subsys.u.usb.vendor == 0) {
if (got_vendor && usbsrc->vendor == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("vendor cannot be 0."));
goto out;
......@@ -10196,18 +10194,21 @@ virDomainHostdevRemove(virDomainDefPtr def, size_t i)
static int
virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr a,
virDomainHostdevDefPtr b)
virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr first,
virDomainHostdevDefPtr second)
{
if (a->source.subsys.u.usb.bus && a->source.subsys.u.usb.device) {
virDomainHostdevSubsysUSBPtr first_usbsrc = &first->source.subsys.u.usb;
virDomainHostdevSubsysUSBPtr second_usbsrc = &second->source.subsys.u.usb;
if (first_usbsrc->bus && first_usbsrc->device) {
/* specified by bus location on host */
if (a->source.subsys.u.usb.bus == b->source.subsys.u.usb.bus &&
a->source.subsys.u.usb.device == b->source.subsys.u.usb.device)
if (first_usbsrc->bus == second_usbsrc->bus &&
first_usbsrc->device == second_usbsrc->device)
return 1;
} else {
/* specified by product & vendor id */
if (a->source.subsys.u.usb.product == b->source.subsys.u.usb.product &&
a->source.subsys.u.usb.vendor == b->source.subsys.u.usb.vendor)
if (first_usbsrc->product == second_usbsrc->product &&
first_usbsrc->vendor == second_usbsrc->vendor)
return 1;
}
return 0;
......@@ -15514,6 +15515,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
unsigned int flags,
bool includeTypeInAddr)
{
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
def->source.subsys.u.pci.backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
const char *backend = virDomainHostdevSubsysPCIBackendTypeToString(def->source.subsys.u.pci.backend);
......@@ -15533,8 +15536,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
policy = virDomainStartupPolicyTypeToString(def->startupPolicy);
virBufferAsprintf(buf, " startupPolicy='%s'", policy);
}
if (def->source.subsys.u.usb.autoAddress &&
(flags & VIR_DOMAIN_XML_MIGRATABLE))
if (usbsrc->autoAddress && (flags & VIR_DOMAIN_XML_MIGRATABLE))
virBufferAddLit(buf, " autoAddress='yes'");
if (def->missing &&
......@@ -15547,18 +15549,14 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
switch (def->source.subsys.type)
{
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
if (def->source.subsys.u.usb.vendor) {
virBufferAsprintf(buf, "<vendor id='0x%.4x'/>\n",
def->source.subsys.u.usb.vendor);
virBufferAsprintf(buf, "<product id='0x%.4x'/>\n",
def->source.subsys.u.usb.product);
}
if (def->source.subsys.u.usb.bus ||
def->source.subsys.u.usb.device) {
if (usbsrc->vendor) {
virBufferAsprintf(buf, "<vendor id='0x%.4x'/>\n", usbsrc->vendor);
virBufferAsprintf(buf, "<product id='0x%.4x'/>\n", usbsrc->product);
}
if (usbsrc->bus || usbsrc->device) {
virBufferAsprintf(buf, "<address %sbus='%d' device='%d'/>\n",
includeTypeInAddr ? "type='usb' " : "",
def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device);
usbsrc->bus, usbsrc->device);
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
......
......@@ -388,20 +388,24 @@ typedef enum {
VIR_ENUM_DECL(virDomainHostdevSubsysPCIBackend)
typedef struct _virDomainHostdevSubsysUSB virDomainHostdevSubsysUSB;
typedef virDomainHostdevSubsysUSB *virDomainHostdevSubsysUSBPtr;
struct _virDomainHostdevSubsysUSB {
bool autoAddress; /* bus/device were filled automatically based
on vendor/product */
unsigned bus;
unsigned device;
unsigned vendor;
unsigned product;
};
typedef struct _virDomainHostdevSubsys virDomainHostdevSubsys;
typedef virDomainHostdevSubsys *virDomainHostdevSubsysPtr;
struct _virDomainHostdevSubsys {
int type; /* enum virDomainHostdevSubsysType */
union {
struct {
bool autoAddress; /* bus/device were filled automatically based
on vedor/product */
unsigned bus;
unsigned device;
unsigned vendor;
unsigned product;
} usb;
virDomainHostdevSubsysUSB usb;
struct {
virDevicePCIAddress addr; /* host address */
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
......
......@@ -401,6 +401,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
VIR_DEBUG("Allowing any hostdev block devs");
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
virUSBDevicePtr usb;
switch (hostdev->mode) {
......@@ -410,8 +411,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
if (hostdev->missing)
continue;
if ((usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
if ((usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device,
NULL)) == NULL)
goto cleanup;
......
......@@ -1347,22 +1347,20 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
char *vroot = NULL;
struct stat sb;
mode_t mode;
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
if (virAsprintf(&src, USB_DEVFS "/%03d/%03d",
def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device) < 0)
usbsrc->bus, usbsrc->device) < 0)
goto cleanup;
if (virAsprintf(&vroot, "/%s/%s.dev/bus/usb/",
LXC_STATE_DIR, vmDef->name) < 0)
goto cleanup;
if (virAsprintf(&dstdir, "%s/%03d/", vroot,
def->source.subsys.u.usb.bus) < 0)
if (virAsprintf(&dstdir, "%s/%03d/", vroot, usbsrc->bus) < 0)
goto cleanup;
if (virAsprintf(&dstfile, "%s/%03d", dstdir,
def->source.subsys.u.usb.device) < 0)
if (virAsprintf(&dstfile, "%s/%03d", dstdir, usbsrc->device) < 0)
goto cleanup;
if (stat(src, &sb) < 0) {
......
......@@ -4264,6 +4264,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
char *src = NULL;
struct stat sb;
virUSBDevicePtr usb = NULL;
virDomainHostdevSubsysUSBPtr usbsrc;
if (virDomainHostdevFind(vm->def, def, NULL) >= 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
......@@ -4271,13 +4272,12 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
return -1;
}
usbsrc = &def->source.subsys.u.usb;
if (virAsprintf(&src, "/dev/bus/usb/%03d/%03d",
def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device) < 0)
usbsrc->bus, usbsrc->device) < 0)
goto cleanup;
if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device, NULL)))
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))
goto cleanup;
if (stat(src, &sb) < 0) {
......@@ -4708,6 +4708,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
char *dst = NULL;
virUSBDevicePtr usb = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virDomainHostdevSubsysUSBPtr usbsrc;
if ((idx = virDomainHostdevFind(vm->def,
dev->data.hostdev,
......@@ -4717,9 +4718,9 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
goto cleanup;
}
usbsrc = &def->source.subsys.u.usb;
if (virAsprintf(&dst, "/dev/bus/usb/%03d/%03d",
def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device) < 0)
usbsrc->bus, usbsrc->device) < 0)
goto cleanup;
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
......@@ -4728,8 +4729,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
goto cleanup;
}
if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device, NULL)))
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))
goto cleanup;
if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
......
......@@ -242,6 +242,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
{
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virPCIDevicePtr pci = NULL;
virUSBDevicePtr usb = NULL;
virSCSIDevicePtr scsi = NULL;
......@@ -290,8 +291,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
*/
if (dev->missing)
break;
if ((usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
if ((usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device,
NULL)) == NULL) {
goto cleanup;
}
......
......@@ -5040,10 +5040,9 @@ qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
if (!dev->missing &&
!dev->source.subsys.u.usb.bus &&
!dev->source.subsys.u.usb.device) {
if (!dev->missing && !usbsrc->bus && !usbsrc->device) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("USB host device is missing bus/device information"));
return NULL;
......@@ -5052,8 +5051,7 @@ qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
virBufferAddLit(&buf, "usb-host");
if (!dev->missing) {
virBufferAsprintf(&buf, ",hostbus=%d,hostaddr=%d",
dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device);
usbsrc->bus, usbsrc->device);
}
virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
if (dev->info->bootIndex)
......@@ -5113,6 +5111,7 @@ char *
qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev)
{
char *ret = NULL;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
if (dev->missing) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
......@@ -5120,16 +5119,13 @@ qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev)
return NULL;
}
if (!dev->source.subsys.u.usb.bus &&
!dev->source.subsys.u.usb.device) {
if (!usbsrc->bus && !usbsrc->device) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("USB host device is missing bus/device information"));
return NULL;
}
ignore_value(virAsprintf(&ret, "host:%d.%d",
dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device));
ignore_value(virAsprintf(&ret, "host:%d.%d", usbsrc->bus, usbsrc->device));
return ret;
}
......@@ -10216,12 +10212,14 @@ static virDomainHostdevDefPtr
qemuParseCommandLineUSB(const char *val)
{
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
virDomainHostdevSubsysUSBPtr usbsrc;
int first = 0, second = 0;
const char *start;
char *end;
if (!def)
goto error;
usbsrc = &def->source.subsys.u.usb;
if (!STRPREFIX(val, "host:")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -10260,11 +10258,11 @@ qemuParseCommandLineUSB(const char *val)
def->managed = false;
def->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
if (*end == '.') {
def->source.subsys.u.usb.bus = first;
def->source.subsys.u.usb.device = second;
usbsrc->bus = first;
usbsrc->device = second;
} else {
def->source.subsys.u.usb.vendor = first;
def->source.subsys.u.usb.product = second;
usbsrc->vendor = first;
usbsrc->product = second;
}
return def;
......
......@@ -3360,6 +3360,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
{
virDomainHostdevDefPtr hostdev = dev->data.hostdev;
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb;
virDomainHostdevDefPtr detach = NULL;
int idx;
......@@ -3381,14 +3382,14 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
if (subsys->u.usb.bus && subsys->u.usb.device) {
if (usbsrc->bus && usbsrc->device) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("host usb device %03d.%03d not found"),
subsys->u.usb.bus, subsys->u.usb.device);
usbsrc->bus, usbsrc->device);
} else {
virReportError(VIR_ERR_OPERATION_FAILED,
_("host usb device vendor=0x%.4x product=0x%.4x not found"),
subsys->u.usb.vendor, subsys->u.usb.product);
usbsrc->vendor, usbsrc->product);
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
......
......@@ -812,6 +812,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
int ret = -1;
virSecurityLabelDefPtr secdef =
virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME);
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
if (!secdef)
return -1;
......@@ -833,10 +834,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
virUSBDevicePtr usb =
virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
vroot);
virUSBDeviceNew(usbsrc->bus, usbsrc->device, vroot);
if (!usb)
goto done;
......
......@@ -509,6 +509,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
{
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
virSecurityDACCallbackData cbdata;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
int ret = -1;
if (!priv->dynamicOwnership)
......@@ -530,10 +531,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
if (dev->missing)
return 0;
usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
vroot);
if (!usb)
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, vroot)))
goto done;
ret = virUSBDeviceFileIterate(usb,
......@@ -640,6 +638,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
{
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
virSecurityLabelDefPtr secdef;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
int ret = -1;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
......@@ -657,10 +656,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
if (dev->missing)
return 0;
usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
vroot);
if (!usb)
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, vroot)))
goto done;
ret = virUSBDeviceFileIterate(usb, virSecurityDACRestoreSecurityUSBLabel, mgr);
......
......@@ -1319,6 +1319,7 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
const char *vroot)
{
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
int ret = -1;
switch (dev->source.subsys.type) {
......@@ -1328,8 +1329,8 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
if (dev->missing)
return 0;
usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
usb = virUSBDeviceNew(usbsrc->bus,
usbsrc->device,
vroot);
if (!usb)
goto done;
......@@ -1508,6 +1509,7 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
const char *vroot)
{
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
int ret = -1;
switch (dev->source.subsys.type) {
......@@ -1517,8 +1519,8 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
if (dev->missing)
return 0;
usb = virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
usb = virUSBDeviceNew(usbsrc->bus,
usbsrc->device,
vroot);
if (!usb)
goto done;
......
......@@ -1026,12 +1026,11 @@ get_files(vahControl * ctl)
for (i = 0; i < ctl->def->nhostdevs; i++)
if (ctl->def->hostdevs[i]) {
virDomainHostdevDefPtr dev = ctl->def->hostdevs[i];
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
virUSBDevicePtr usb =
virUSBDeviceNew(dev->source.subsys.u.usb.bus,
dev->source.subsys.u.usb.device,
NULL);
virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL);
if (usb == NULL)
continue;
......
......@@ -897,22 +897,19 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->activeUSBHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevSubsysUSBPtr usbsrc;
virUSBDevicePtr usb = NULL;
hostdev = hostdevs[i];
usbsrc = &hostdev->source.subsys.u.usb;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
NULL);
if (!usb) {
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL))) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
dom_name);
usbsrc->bus, usbsrc->device, dom_name);
continue;
}
......@@ -1047,11 +1044,12 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
bool mandatory,
virUSBDevicePtr *usb)
{
unsigned vendor = hostdev->source.subsys.u.usb.vendor;
unsigned product = hostdev->source.subsys.u.usb.product;
unsigned bus = hostdev->source.subsys.u.usb.bus;
unsigned device = hostdev->source.subsys.u.usb.device;
bool autoAddress = hostdev->source.subsys.u.usb.autoAddress;
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
unsigned vendor = usbsrc->vendor;
unsigned product = usbsrc->product;
unsigned bus = usbsrc->bus;
unsigned device = usbsrc->device;
bool autoAddress = usbsrc->autoAddress;
int rc;
*usb = NULL;
......@@ -1106,16 +1104,15 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
return -1;
}
hostdev->source.subsys.u.usb.bus = virUSBDeviceGetBus(*usb);
hostdev->source.subsys.u.usb.device = virUSBDeviceGetDevno(*usb);
hostdev->source.subsys.u.usb.autoAddress = true;
usbsrc->bus = virUSBDeviceGetBus(*usb);
usbsrc->device = virUSBDeviceGetDevno(*usb);
usbsrc->autoAddress = true;
if (autoAddress) {
VIR_INFO("USB device %x:%x found at bus:%u device:%u (moved"
" from bus:%u device:%u)",
vendor, product,
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
usbsrc->bus, usbsrc->device,
bus, device);
}
} else if (!vendor && bus) {
......@@ -1332,6 +1329,7 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr,
virObjectLock(hostdev_mgr->activeUSBHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
virUSBDevicePtr usb, tmp;
const char *usedby_drvname;
const char *usedby_domname;
......@@ -1343,15 +1341,9 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr,
if (hostdev->missing)
continue;
usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
NULL);
if (!usb) {
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL))) {
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
dom_name);
usbsrc->bus, usbsrc->device, dom_name);
continue;
}
......@@ -1367,8 +1359,7 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr,
if (!tmp) {
VIR_WARN("Unable to find device %03d.%03d "
"in list of active USB devices",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device);
usbsrc->bus, usbsrc->device);
continue;
}
......@@ -1376,10 +1367,7 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr,
if (STREQ_NULLABLE(drv_name, usedby_drvname) &&
STREQ_NULLABLE(dom_name, usedby_domname)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUSBHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
dom_name);
usbsrc->bus, usbsrc->device, dom_name);
virUSBDeviceListDel(hostdev_mgr->activeUSBHostdevs, tmp);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册