[PATCH v2 1/8] hostdev: Introduce virDomainHostdevSubsysUSB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create a separate typedef for the hostdev union data describing USB.
Then adjust the code to use the new pointer

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/domain_audit.c          |  4 +--
 src/conf/domain_conf.c           | 54 +++++++++++++++++++---------------------
 src/conf/domain_conf.h           | 22 +++++++++-------
 src/lxc/lxc_cgroup.c             |  4 +--
 src/lxc/lxc_controller.c         | 10 +++-----
 src/lxc/lxc_driver.c             | 16 ++++++------
 src/qemu/qemu_cgroup.c           |  4 +--
 src/qemu/qemu_command.c          | 26 +++++++++----------
 src/qemu/qemu_hotplug.c          |  7 +++---
 src/security/security_apparmor.c |  6 ++---
 src/security/security_dac.c      | 12 +++------
 src/security/security_selinux.c  | 10 +++++---
 src/security/virt-aa-helper.c    |  5 ++--
 src/util/virhostdev.c            | 50 ++++++++++++++-----------------------
 14 files changed, 106 insertions(+), 124 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index a3d6c67..8277b06 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -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;
             }
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1e27165..f23f271 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3807,6 +3807,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 =
@@ -3823,7 +3824,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);
     }
 
@@ -3840,8 +3841,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);
@@ -3859,7 +3859,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);
@@ -3877,8 +3877,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);
@@ -3893,8 +3892,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);
@@ -3917,7 +3915,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;
@@ -10205,18 +10203,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;
@@ -15469,6 +15470,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);
@@ -15488,8 +15491,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 &&
@@ -15502,18 +15504,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:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cd3293b..47b739c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -396,20 +396,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 */
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 395ea05..0b60f5a 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -393,6 +393,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) {
@@ -402,8 +403,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;
 
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index fd93f47..2d220eb 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -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) {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index b7b4b02..43a10bf 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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) {
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 62a8f81..1b2c633 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -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;
             }
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8062510..8b0d400 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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;
 
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1fc28b8..0427930 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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:
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index e6563de..43f86ce 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -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;
 
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 4d2a9d6..0caeae6 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -466,6 +466,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
 {
     virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
     virSecurityDACCallbackData cbdata;
+    virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
     int ret = -1;
 
     if (!priv->dynamicOwnership)
@@ -487,10 +488,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,
@@ -597,6 +595,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);
@@ -614,10 +613,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);
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index a0e89b7..a96b224 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -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;
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index fe9ad59..f25a7df7 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -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;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 9dd1df2..3c93758 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -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);
         }
     }
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]