[PATCH v2 2/8] hostdev: Introduce virDomainHostdevSubsysPCI

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

 



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

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/domain_audit.c          |  9 ++++----
 src/conf/domain_conf.c           | 29 +++++++++++++++----------
 src/conf/domain_conf.h           | 12 ++++++----
 src/libxl/libxl_conf.c           |  9 ++++----
 src/libxl/libxl_domain.c         |  6 +++--
 src/libxl/libxl_driver.c         | 34 ++++++++++++++---------------
 src/qemu/qemu_cgroup.c           | 24 ++++++++++----------
 src/qemu/qemu_command.c          | 47 ++++++++++++++++++----------------------
 src/qemu/qemu_hotplug.c          | 11 +++++-----
 src/security/security_apparmor.c | 10 ++++-----
 src/security/security_dac.c      | 20 +++++++----------
 src/security/security_selinux.c  | 20 +++++++----------
 src/util/virhostdev.c            | 34 ++++++++++++-----------------
 13 files changed, 128 insertions(+), 137 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 8277b06..d3f0449 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -389,6 +389,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
     char *device = NULL;
     const char *virt;
     virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
 
     virUUIDFormat(vm->def->uuid, uuidstr);
     if (!(vmname = virAuditEncode("vm", vm->def->name))) {
@@ -406,10 +407,10 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
         switch (hostdev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
             if (virAsprintfQuiet(&address, "%.4x:%.2x:%.2x.%.1x",
-                                 hostdev->source.subsys.u.pci.addr.domain,
-                                 hostdev->source.subsys.u.pci.addr.bus,
-                                 hostdev->source.subsys.u.pci.addr.slot,
-                                 hostdev->source.subsys.u.pci.addr.function) < 0) {
+                                 pcisrc->addr.domain,
+                                 pcisrc->addr.bus,
+                                 pcisrc->addr.slot,
+                                 pcisrc->addr.function) < 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 f23f271..1c8b85a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4260,6 +4260,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
     char *backendStr = NULL;
     int backend;
     int ret = -1;
+    virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci;
 
     /* @managed can be read from the xml document - it is always an
      * attribute of the toplevel element, no matter what type of
@@ -4339,7 +4340,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
                              "has been specified"), backendStr);
             goto error;
         }
-        def->source.subsys.u.pci.backend = backend;
+        pcisrc->backend = backend;
 
         break;
 
@@ -10224,13 +10225,16 @@ virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr first,
 }
 
 static int
-virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr a,
-                               virDomainHostdevDefPtr b)
+virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr first,
+                               virDomainHostdevDefPtr second)
 {
-    if (a->source.subsys.u.pci.addr.domain == b->source.subsys.u.pci.addr.domain &&
-        a->source.subsys.u.pci.addr.bus == b->source.subsys.u.pci.addr.bus &&
-        a->source.subsys.u.pci.addr.slot == b->source.subsys.u.pci.addr.slot &&
-        a->source.subsys.u.pci.addr.function == b->source.subsys.u.pci.addr.function)
+    virDomainHostdevSubsysPCIPtr first_pcisrc = &first->source.subsys.u.pci;
+    virDomainHostdevSubsysPCIPtr second_pcisrc = &second->source.subsys.u.pci;
+
+    if (first_pcisrc->addr.domain == second_pcisrc->addr.domain &&
+        first_pcisrc->addr.bus == second_pcisrc->addr.bus &&
+        first_pcisrc->addr.slot == second_pcisrc->addr.slot &&
+        first_pcisrc->addr.function == second_pcisrc->addr.function)
         return 1;
     return 0;
 }
@@ -15471,15 +15475,17 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
                                 bool includeTypeInAddr)
 {
     virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci;
 
     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);
+        pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
+        const char *backend =
+            virDomainHostdevSubsysPCIBackendTypeToString(pcisrc->backend);
 
         if (!backend) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unexpected pci hostdev driver name type %d"),
-                           def->source.subsys.u.pci.backend);
+                           pcisrc->backend);
             return -1;
         }
         virBufferAsprintf(buf, "<driver name='%s'/>\n", backend);
@@ -15515,8 +15521,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
         }
         break;
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-        if (virDevicePCIAddressFormat(buf,
-                                      def->source.subsys.u.pci.addr,
+        if (virDevicePCIAddressFormat(buf, pcisrc->addr,
                                       includeTypeInAddr) != 0)
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("PCI address Formatting failed"));
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 47b739c..62d0f36 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -408,16 +408,20 @@ struct _virDomainHostdevSubsysUSB {
     unsigned product;
 };
 
+typedef struct _virDomainHostdevSubsysPCI virDomainHostdevSubsysPCI;
+typedef virDomainHostdevSubsysPCI *virDomainHostdevSubsysPCIPtr;
+struct _virDomainHostdevSubsysPCI {
+    virDevicePCIAddress addr; /* host address */
+    int backend; /* enum virDomainHostdevSubsysPCIBackendType */
+};
+
 typedef struct _virDomainHostdevSubsys virDomainHostdevSubsys;
 typedef virDomainHostdevSubsys *virDomainHostdevSubsysPtr;
 struct _virDomainHostdevSubsys {
     int type; /* enum virDomainHostdevSubsysType */
     union {
         virDomainHostdevSubsysUSB usb;
-        struct {
-            virDevicePCIAddress addr; /* host address */
-            int backend; /* enum virDomainHostdevSubsysPCIBackendType */
-        } pci;
+        virDomainHostdevSubsysPCI pci;
         struct {
             char *adapter;
             unsigned bus;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 488ce2a..3afce69 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1274,15 +1274,16 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver)
 int
 libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev)
 {
+    virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
     if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
         return -1;
     if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
         return -1;
 
-    pcidev->domain = hostdev->source.subsys.u.pci.addr.domain;
-    pcidev->bus = hostdev->source.subsys.u.pci.addr.bus;
-    pcidev->dev = hostdev->source.subsys.u.pci.addr.slot;
-    pcidev->func = hostdev->source.subsys.u.pci.addr.function;
+    pcidev->domain = pcisrc->addr.domain;
+    pcidev->bus = pcisrc->addr.bus;
+    pcidev->dev = pcisrc->addr.slot;
+    pcidev->func = pcisrc->addr.function;
 
     return 0;
 }
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 6780e34..cdac82c 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -487,11 +487,13 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
          dev->data.net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)) {
 
         virDomainHostdevDefPtr hostdev;
+        virDomainHostdevSubsysPCIPtr pcisrc;
 
         if (dev->type == VIR_DOMAIN_DEVICE_NET)
             hostdev = &(dev->data.net)->data.hostdev.def;
         else
             hostdev = dev->data.hostdev;
+        pcisrc = &hostdev->source.subsys.u.pci;
 
         /* forbid capabilities mode hostdev in this kind of hypervisor */
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
@@ -504,8 +506,8 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-            hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)
-            hostdev->source.subsys.u.pci.backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+            pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)
+            pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
     }
 
     return 0;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5fbff1c..67fd7bc6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2627,6 +2627,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
     libxl_device_pci pcidev;
     virDomainHostdevDefPtr found;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+    virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
 
     if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
         return -1;
@@ -2634,10 +2635,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
     if (virDomainHostdevFind(vm->def, hostdev, &found) >= 0) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("target pci device %.4x:%.2x:%.2x.%.1x already exists"),
-                       hostdev->source.subsys.u.pci.addr.domain,
-                       hostdev->source.subsys.u.pci.addr.bus,
-                       hostdev->source.subsys.u.pci.addr.slot,
-                       hostdev->source.subsys.u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         return -1;
     }
 
@@ -2655,10 +2654,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
     if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("libxenlight failed to attach pci device %.4x:%.2x:%.2x.%.1x"),
-                       hostdev->source.subsys.u.pci.addr.domain,
-                       hostdev->source.subsys.u.pci.addr.bus,
-                       hostdev->source.subsys.u.pci.addr.slot,
-                       hostdev->source.subsys.u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         goto error;
     }
 
@@ -2854,6 +2851,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
     virDomainNetDefPtr net;
     virDomainHostdevDefPtr hostdev;
     virDomainHostdevDefPtr found;
+    virDomainHostdevSubsysPCIPtr pcisrc;
 
     switch (dev->type) {
         case VIR_DOMAIN_DEVICE_DISK:
@@ -2883,13 +2881,12 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
                 return -1;
 
             if (virDomainHostdevFind(vmdef, hostdev, &found) >= 0) {
+                pcisrc = &hostdev->source.subsys.u.pci;
                 virReportError(VIR_ERR_OPERATION_FAILED,
                                _("target pci device %.4x:%.2x:%.2x.%.1x\
                                   already exists"),
-                               hostdev->source.subsys.u.pci.addr.domain,
-                               hostdev->source.subsys.u.pci.addr.bus,
-                               hostdev->source.subsys.u.pci.addr.slot,
-                               hostdev->source.subsys.u.pci.addr.function);
+                               pcisrc->addr.domain, pcisrc->addr.bus,
+                               pcisrc->addr.slot, pcisrc->addr.function);
                 return -1;
             }
 
@@ -2940,6 +2937,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
                                virDomainHostdevDefPtr hostdev)
 {
     virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
+    virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
     libxl_device_pci pcidev;
     virDomainHostdevDefPtr detach;
     int idx;
@@ -2952,16 +2950,16 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
     if (idx < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
-                       subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                       subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         return -1;
     }
 
     if (libxlIsMultiFunctionDevice(vm->def, detach->info)) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
-                       subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                       subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         goto error;
     }
 
@@ -2975,8 +2973,8 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("libxenlight failed to detach pci device\
                           %.4x:%.2x:%.2x.%.1x"),
-                       subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                       subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         goto error;
     }
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 1b2c633..8a7e640 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -243,6 +243,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     virPCIDevicePtr pci = NULL;
     virUSBDevicePtr usb = NULL;
     virSCSIDevicePtr scsi = NULL;
@@ -260,14 +261,13 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
 
         switch (dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-            if (dev->source.subsys.u.pci.backend
-                == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+            if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
                 int rv;
 
-                pci = virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                                      dev->source.subsys.u.pci.addr.bus,
-                                      dev->source.subsys.u.pci.addr.slot,
-                                      dev->source.subsys.u.pci.addr.function);
+                pci = virPCIDeviceNew(pcisrc->addr.domain,
+                                      pcisrc->addr.bus,
+                                      pcisrc->addr.slot,
+                                      pcisrc->addr.function);
                 if (!pci)
                     goto cleanup;
 
@@ -340,6 +340,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
 {
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     virPCIDevicePtr pci = NULL;
     char *path = NULL;
 
@@ -355,14 +356,13 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
 
         switch (dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-            if (dev->source.subsys.u.pci.backend
-                == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+            if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
                 int rv;
 
-                pci = virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                                      dev->source.subsys.u.pci.addr.bus,
-                                      dev->source.subsys.u.pci.addr.slot,
-                                      dev->source.subsys.u.pci.addr.function);
+                pci = virPCIDeviceNew(pcisrc->addr.domain,
+                                      pcisrc->addr.bus,
+                                      pcisrc->addr.slot,
+                                      pcisrc->addr.function);
                 if (!pci)
                     goto cleanup;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8b0d400..5362b09 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -554,18 +554,16 @@ qemuNetworkPrepareDevices(virDomainDefPtr def)
              * separately.
              */
             virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+            virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
 
             if (virDomainHostdevFind(def, hostdev, NULL) >= 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("PCI device %04x:%02x:%02x.%x "
                                  "allocated from network %s is already "
                                  "in use by domain %s"),
-                               hostdev->source.subsys.u.pci.addr.domain,
-                               hostdev->source.subsys.u.pci.addr.bus,
-                               hostdev->source.subsys.u.pci.addr.slot,
-                               hostdev->source.subsys.u.pci.addr.function,
-                               net->data.network.name,
-                               def->name);
+                               pcisrc->addr.domain, pcisrc->addr.bus,
+                               pcisrc->addr.slot, pcisrc->addr.function,
+                               net->data.network.name, def->name);
                 goto cleanup;
             }
             if (virDomainHostdevInsert(def, hostdev) < 0)
@@ -4834,14 +4832,13 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def,
 int
 qemuOpenPCIConfig(virDomainHostdevDefPtr dev)
 {
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     char *path = NULL;
     int configfd = -1;
 
     if (virAsprintf(&path, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/config",
-                    dev->source.subsys.u.pci.addr.domain,
-                    dev->source.subsys.u.pci.addr.bus,
-                    dev->source.subsys.u.pci.addr.slot,
-                    dev->source.subsys.u.pci.addr.function) < 0)
+                    pcisrc->addr.domain, pcisrc->addr.bus,
+                    pcisrc->addr.slot, pcisrc->addr.function) < 0)
         return -1;
 
     configfd = open(path, O_RDWR, 0);
@@ -4861,7 +4858,8 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
                           virQEMUCapsPtr qemuCaps)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    int backend = dev->source.subsys.u.pci.backend;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
+    int backend = pcisrc->backend;
 
     /* caller has to assign proper passthrough backend type */
     switch ((virDomainHostdevSubsysPCIBackendType) backend) {
@@ -4883,20 +4881,19 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
     }
 
     virBufferAddLit(&buf, ",host=");
-    if (dev->source.subsys.u.pci.addr.domain) {
+    if (pcisrc->addr.domain) {
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("non-zero domain='%.4x' in host device PCI address "
                              "not supported in this QEMU binary"),
-                           dev->source.subsys.u.pci.addr.domain);
+                           pcisrc->addr.domain);
             goto error;
         }
-        virBufferAsprintf(&buf, "%.4x:", dev->source.subsys.u.pci.addr.domain);
+        virBufferAsprintf(&buf, "%.4x:", pcisrc->addr.domain);
     }
     virBufferAsprintf(&buf, "%.2x:%.2x.%.1x",
-                      dev->source.subsys.u.pci.addr.bus,
-                      dev->source.subsys.u.pci.addr.slot,
-                      dev->source.subsys.u.pci.addr.function);
+                      pcisrc->addr.bus, pcisrc->addr.slot,
+                      pcisrc->addr.function);
     virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
     if (dev->info->bootIndex)
         virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
@@ -4921,25 +4918,23 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev,
                              virQEMUCapsPtr qemuCaps)
 {
     char *ret = NULL;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
 
-    if (dev->source.subsys.u.pci.addr.domain) {
+    if (pcisrc->addr.domain) {
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("non-zero domain='%.4x' in host device PCI address "
                              "not supported in this QEMU binary"),
-                           dev->source.subsys.u.pci.addr.domain);
+                           pcisrc->addr.domain);
             goto cleanup;
         }
         ignore_value(virAsprintf(&ret, "host=%.4x:%.2x:%.2x.%.1x",
-                                 dev->source.subsys.u.pci.addr.domain,
-                                 dev->source.subsys.u.pci.addr.bus,
-                                 dev->source.subsys.u.pci.addr.slot,
-                                 dev->source.subsys.u.pci.addr.function));
+                                 pcisrc->addr.domain, pcisrc->addr.bus,
+                                 pcisrc->addr.slot, pcisrc->addr.function));
     } else {
         ignore_value(virAsprintf(&ret, "host=%.2x:%.2x.%.1x",
-                                 dev->source.subsys.u.pci.addr.bus,
-                                 dev->source.subsys.u.pci.addr.slot,
-                                 dev->source.subsys.u.pci.addr.function));
+                                 pcisrc->addr.bus, pcisrc->addr.slot,
+                                 pcisrc->addr.function));
     }
  cleanup:
     return ret;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0427930..f94e42d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3204,14 +3204,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
                               virDomainHostdevDefPtr detach)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    virDomainHostdevSubsysPtr subsys = &detach->source.subsys;
+    virDomainHostdevSubsysPCIPtr pcisrc = &detach->source.subsys.u.pci;
     int ret;
 
     if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
-                       subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                       subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+                       pcisrc->addr.domain, pcisrc->addr.bus,
+                       pcisrc->addr.slot, pcisrc->addr.function);
         return -1;
     }
 
@@ -3361,6 +3361,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
     virDomainHostdevDefPtr hostdev = dev->data.hostdev;
     virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
     virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
     virDomainHostdevDefPtr detach = NULL;
     int idx;
 
@@ -3378,8 +3379,8 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
             virReportError(VIR_ERR_OPERATION_FAILED,
                            _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
-                           subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                           subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+                           pcisrc->addr.domain, pcisrc->addr.bus,
+                           pcisrc->addr.slot, pcisrc->addr.function);
             break;
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
             if (usbsrc->bus && usbsrc->device) {
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 43f86ce..a45ca6f 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -813,6 +813,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
     virSecurityLabelDefPtr secdef =
         virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME);
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
 
     if (!secdef)
         return -1;
@@ -845,16 +846,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
         virPCIDevicePtr pci =
-            virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                            dev->source.subsys.u.pci.addr.bus,
-                            dev->source.subsys.u.pci.addr.slot,
-                            dev->source.subsys.u.pci.addr.function);
+            virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                            pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!pci)
             goto done;
 
-        if (dev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 0caeae6..0844219 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -467,6 +467,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
     virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
     virSecurityDACCallbackData cbdata;
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     int ret = -1;
 
     if (!priv->dynamicOwnership)
@@ -500,16 +501,13 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
         virPCIDevicePtr pci =
-            virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                            dev->source.subsys.u.pci.addr.bus,
-                            dev->source.subsys.u.pci.addr.slot,
-                            dev->source.subsys.u.pci.addr.function);
+            virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                            pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!pci)
             goto done;
 
-        if (dev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
@@ -596,6 +594,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
     virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
     virSecurityLabelDefPtr secdef;
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     int ret = -1;
 
     secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
@@ -624,16 +623,13 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
         virPCIDevicePtr pci =
-            virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                            dev->source.subsys.u.pci.addr.bus,
-                            dev->source.subsys.u.pci.addr.slot,
-                            dev->source.subsys.u.pci.addr.function);
+            virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                            pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!pci)
             goto done;
 
-        if (dev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index a96b224..27300ed 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1320,6 +1320,7 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
 
 {
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     int ret = -1;
 
     switch (dev->source.subsys.type) {
@@ -1342,16 +1343,13 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
         virPCIDevicePtr pci =
-            virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                            dev->source.subsys.u.pci.addr.bus,
-                            dev->source.subsys.u.pci.addr.slot,
-                            dev->source.subsys.u.pci.addr.function);
+            virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                            pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!pci)
             goto done;
 
-        if (dev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
@@ -1510,6 +1508,7 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
 
 {
     virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
+    virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
     int ret = -1;
 
     switch (dev->source.subsys.type) {
@@ -1533,16 +1532,13 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
         virPCIDevicePtr pci =
-            virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain,
-                            dev->source.subsys.u.pci.addr.bus,
-                            dev->source.subsys.u.pci.addr.slot,
-                            dev->source.subsys.u.pci.addr.function);
+            virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                            pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!pci)
             goto done;
 
-        if (dev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 3c93758..f0a1193 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -168,6 +168,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
 
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = hostdevs[i];
+        virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
         virPCIDevicePtr dev;
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
@@ -175,10 +176,8 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
         if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
             continue;
 
-        dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain,
-                              hostdev->source.subsys.u.pci.addr.bus,
-                              hostdev->source.subsys.u.pci.addr.slot,
-                              hostdev->source.subsys.u.pci.addr.function);
+        dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                              pcisrc->addr.slot, pcisrc->addr.function);
         if (!dev) {
             virObjectUnref(list);
             return NULL;
@@ -191,14 +190,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
         }
 
         virPCIDeviceSetManaged(dev, hostdev->managed);
-        if (hostdev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) {
                 virObjectUnref(list);
                 return NULL;
             }
-        } else if (hostdev->source.subsys.u.pci.backend
-                   == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
+        } else if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
             if (virPCIDeviceSetStubDriver(dev, "pciback") < 0) {
                 virObjectUnref(list);
                 return NULL;
@@ -619,16 +616,15 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
         virPCIDevicePtr dev;
         virPCIDevicePtr pcidev;
         virDomainHostdevDefPtr hostdev = hostdevs[i];
+        virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
             continue;
         if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
             continue;
 
-        dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain,
-                              hostdev->source.subsys.u.pci.addr.bus,
-                              hostdev->source.subsys.u.pci.addr.slot,
-                              hostdev->source.subsys.u.pci.addr.function);
+        dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                              pcisrc->addr.slot, pcisrc->addr.function);
 
         /* original states "unbind_from_stub", "remove_slot",
          * "reprobe" were already set by pciDettachDevice in
@@ -832,28 +828,26 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
     virObjectLock(mgr->inactivePCIHostdevs);
 
     for (i = 0; i < nhostdevs; i++) {
+        virDomainHostdevSubsysPCIPtr pcisrc;
         hostdev = hostdevs[i];
+        pcisrc = &hostdev->source.subsys.u.pci;
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
             continue;
         if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
             continue;
 
-        dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain,
-                              hostdev->source.subsys.u.pci.addr.bus,
-                              hostdev->source.subsys.u.pci.addr.slot,
-                              hostdev->source.subsys.u.pci.addr.function);
+        dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
+                              pcisrc->addr.slot, pcisrc->addr.function);
 
         if (!dev)
             goto cleanup;
 
         virPCIDeviceSetManaged(dev, hostdev->managed);
-        if (hostdev->source.subsys.u.pci.backend
-            == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+        if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
             if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0)
                 goto cleanup;
-        } else if (hostdev->source.subsys.u.pci.backend
-                   == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
+        } else if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
             if (virPCIDeviceSetStubDriver(dev, "pciback") < 0)
                 goto cleanup;
         } else {
-- 
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]