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(a)redhat.com>
---
src/conf/domain_audit.c | 9 ++++----
src/conf/domain_conf.c | 25 ++++++++++++---------
src/conf/domain_conf.h | 12 ++++++----
src/libxl/libxl_conf.c | 9 ++++----
src/libxl/libxl_domain.c | 5 +++--
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, 125 insertions(+), 135 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 046b4f8..f1b9a46 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4253,6 +4253,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
@@ -4332,7 +4333,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
"has been specified"), backendStr);
goto error;
}
- def->source.subsys.u.pci.backend = backend;
+ pcisrc->backend = backend;
break;
@@ -10123,10 +10124,13 @@ static int
virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr a,
virDomainHostdevDefPtr b)
{
- 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 apcisrc = &a->source.subsys.u.pci;
+ virDomainHostdevSubsysPCIPtr bpcisrc = &b->source.subsys.u.pci;
+
+ if (apcisrc->addr.domain == bpcisrc->addr.domain &&
+ apcisrc->addr.bus == bpcisrc->addr.bus &&
+ apcisrc->addr.slot == bpcisrc->addr.slot &&
+ apcisrc->addr.function == bpcisrc->addr.function)
return 1;
return 0;
}
@@ -15486,15 +15490,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);
@@ -15530,8 +15536,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 d955491..f1f1929 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -402,16 +402,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 0b4a0b5..b52c65f 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1273,15 +1273,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 0c86601..2596cc7 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -484,6 +484,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
virDomainHostdevDefPtr hostdev = dev->data.hostdev;
+ virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
@@ -496,8 +497,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 b27581e..ca10f6a 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2626,6 +2626,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;
@@ -2633,10 +2634,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;
}
@@ -2654,10 +2653,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;
}
@@ -2792,6 +2789,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef,
virDomainDeviceDefPtr dev)
virDomainDiskDefPtr disk;
virDomainHostdevDefPtr hostdev;
virDomainHostdevDefPtr found;
+ virDomainHostdevSubsysPCIPtr pcisrc;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
@@ -2813,13 +2811,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;
}
@@ -2870,6 +2867,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
virDomainHostdevDefPtr hostdev)
{
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
+ virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
libxl_device_pci pcidev;
virDomainHostdevDefPtr detach;
int idx;
@@ -2882,16 +2880,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;
}
@@ -2905,8 +2903,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 8f03078..c18af84 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 208d49d..d95566f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -549,18 +549,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)
@@ -4829,14 +4827,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);
@@ -4856,7 +4853,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) {
@@ -4878,20 +4876,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);
@@ -4916,25 +4913,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 563de4f..c2c4389 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -802,6 +802,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;
@@ -834,16 +835,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