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