提交 1c8da0d4 编写于 作者: J John Ferlan

hostdev: Introduce virDomainHostdevSubsysPCI

Create a separate typedef for the hostdev union data describing PCI.
Then adjust the code to use the new pointer
上级 7540d07f
...@@ -389,6 +389,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, ...@@ -389,6 +389,7 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
char *device = NULL; char *device = NULL;
const char *virt; const char *virt;
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
virUUIDFormat(vm->def->uuid, uuidstr); virUUIDFormat(vm->def->uuid, uuidstr);
if (!(vmname = virAuditEncode("vm", vm->def->name))) { if (!(vmname = virAuditEncode("vm", vm->def->name))) {
...@@ -406,10 +407,10 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, ...@@ -406,10 +407,10 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
switch (hostdev->source.subsys.type) { switch (hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (virAsprintfQuiet(&address, "%.4x:%.2x:%.2x.%.1x", if (virAsprintfQuiet(&address, "%.4x:%.2x:%.2x.%.1x",
hostdev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.slot, pcisrc->addr.slot,
hostdev->source.subsys.u.pci.addr.function) < 0) { pcisrc->addr.function) < 0) {
VIR_WARN("OOM while encoding audit message"); VIR_WARN("OOM while encoding audit message");
goto cleanup; goto cleanup;
} }
......
...@@ -4246,6 +4246,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, ...@@ -4246,6 +4246,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
char *backendStr = NULL; char *backendStr = NULL;
int backend; int backend;
int ret = -1; int ret = -1;
virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci;
/* @managed can be read from the xml document - it is always an /* @managed can be read from the xml document - it is always an
* attribute of the toplevel element, no matter what type of * attribute of the toplevel element, no matter what type of
...@@ -4325,7 +4326,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, ...@@ -4325,7 +4326,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
"has been specified"), backendStr); "has been specified"), backendStr);
goto error; goto error;
} }
def->source.subsys.u.pci.backend = backend; pcisrc->backend = backend;
break; break;
...@@ -10215,13 +10216,16 @@ virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr first, ...@@ -10215,13 +10216,16 @@ virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr first,
} }
static int static int
virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr a, virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr first,
virDomainHostdevDefPtr b) virDomainHostdevDefPtr second)
{ {
if (a->source.subsys.u.pci.addr.domain == b->source.subsys.u.pci.addr.domain && virDomainHostdevSubsysPCIPtr first_pcisrc = &first->source.subsys.u.pci;
a->source.subsys.u.pci.addr.bus == b->source.subsys.u.pci.addr.bus && virDomainHostdevSubsysPCIPtr second_pcisrc = &second->source.subsys.u.pci;
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) 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 1;
return 0; return 0;
} }
...@@ -15516,15 +15520,17 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, ...@@ -15516,15 +15520,17 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
bool includeTypeInAddr) bool includeTypeInAddr)
{ {
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb; 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 && if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
def->source.subsys.u.pci.backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) { pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
const char *backend = virDomainHostdevSubsysPCIBackendTypeToString(def->source.subsys.u.pci.backend); const char *backend =
virDomainHostdevSubsysPCIBackendTypeToString(pcisrc->backend);
if (!backend) { if (!backend) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected pci hostdev driver name type %d"), _("unexpected pci hostdev driver name type %d"),
def->source.subsys.u.pci.backend); pcisrc->backend);
return -1; return -1;
} }
virBufferAsprintf(buf, "<driver name='%s'/>\n", backend); virBufferAsprintf(buf, "<driver name='%s'/>\n", backend);
...@@ -15560,8 +15566,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, ...@@ -15560,8 +15566,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
} }
break; break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (virDevicePCIAddressFormat(buf, if (virDevicePCIAddressFormat(buf, pcisrc->addr,
def->source.subsys.u.pci.addr,
includeTypeInAddr) != 0) includeTypeInAddr) != 0)
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("PCI address Formatting failed")); _("PCI address Formatting failed"));
......
...@@ -400,16 +400,20 @@ struct _virDomainHostdevSubsysUSB { ...@@ -400,16 +400,20 @@ struct _virDomainHostdevSubsysUSB {
unsigned product; unsigned product;
}; };
typedef struct _virDomainHostdevSubsysPCI virDomainHostdevSubsysPCI;
typedef virDomainHostdevSubsysPCI *virDomainHostdevSubsysPCIPtr;
struct _virDomainHostdevSubsysPCI {
virDevicePCIAddress addr; /* host address */
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
};
typedef struct _virDomainHostdevSubsys virDomainHostdevSubsys; typedef struct _virDomainHostdevSubsys virDomainHostdevSubsys;
typedef virDomainHostdevSubsys *virDomainHostdevSubsysPtr; typedef virDomainHostdevSubsys *virDomainHostdevSubsysPtr;
struct _virDomainHostdevSubsys { struct _virDomainHostdevSubsys {
int type; /* enum virDomainHostdevSubsysType */ int type; /* enum virDomainHostdevSubsysType */
union { union {
virDomainHostdevSubsysUSB usb; virDomainHostdevSubsysUSB usb;
struct { virDomainHostdevSubsysPCI pci;
virDevicePCIAddress addr; /* host address */
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
} pci;
struct { struct {
char *adapter; char *adapter;
unsigned bus; unsigned bus;
......
...@@ -1274,15 +1274,16 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver) ...@@ -1274,15 +1274,16 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver)
int int
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev) libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev)
{ {
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
return -1; return -1;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
return -1; return -1;
pcidev->domain = hostdev->source.subsys.u.pci.addr.domain; pcidev->domain = pcisrc->addr.domain;
pcidev->bus = hostdev->source.subsys.u.pci.addr.bus; pcidev->bus = pcisrc->addr.bus;
pcidev->dev = hostdev->source.subsys.u.pci.addr.slot; pcidev->dev = pcisrc->addr.slot;
pcidev->func = hostdev->source.subsys.u.pci.addr.function; pcidev->func = pcisrc->addr.function;
return 0; return 0;
} }
......
...@@ -487,11 +487,13 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ...@@ -487,11 +487,13 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
dev->data.net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)) { dev->data.net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)) {
virDomainHostdevDefPtr hostdev; virDomainHostdevDefPtr hostdev;
virDomainHostdevSubsysPCIPtr pcisrc;
if (dev->type == VIR_DOMAIN_DEVICE_NET) if (dev->type == VIR_DOMAIN_DEVICE_NET)
hostdev = &(dev->data.net)->data.hostdev.def; hostdev = &(dev->data.net)->data.hostdev.def;
else else
hostdev = dev->data.hostdev; hostdev = dev->data.hostdev;
pcisrc = &hostdev->source.subsys.u.pci;
/* forbid capabilities mode hostdev in this kind of hypervisor */ /* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
...@@ -504,8 +506,8 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ...@@ -504,8 +506,8 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) pcisrc->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_XEN;
} }
return 0; return 0;
......
...@@ -2627,6 +2627,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2627,6 +2627,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
libxl_device_pci pcidev; libxl_device_pci pcidev;
virDomainHostdevDefPtr found; virDomainHostdevDefPtr found;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
return -1; return -1;
...@@ -2634,10 +2635,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2634,10 +2635,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
if (virDomainHostdevFind(vm->def, hostdev, &found) >= 0) { if (virDomainHostdevFind(vm->def, hostdev, &found) >= 0) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("target pci device %.4x:%.2x:%.2x.%.1x already exists"), _("target pci device %.4x:%.2x:%.2x.%.1x already exists"),
hostdev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
return -1; return -1;
} }
...@@ -2655,10 +2654,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2655,10 +2654,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) { if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to attach pci device %.4x:%.2x:%.2x.%.1x"), _("libxenlight failed to attach pci device %.4x:%.2x:%.2x.%.1x"),
hostdev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
goto error; goto error;
} }
...@@ -2854,6 +2851,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev) ...@@ -2854,6 +2851,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
virDomainNetDefPtr net; virDomainNetDefPtr net;
virDomainHostdevDefPtr hostdev; virDomainHostdevDefPtr hostdev;
virDomainHostdevDefPtr found; virDomainHostdevDefPtr found;
virDomainHostdevSubsysPCIPtr pcisrc;
switch (dev->type) { switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK: case VIR_DOMAIN_DEVICE_DISK:
...@@ -2883,13 +2881,12 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev) ...@@ -2883,13 +2881,12 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
return -1; return -1;
if (virDomainHostdevFind(vmdef, hostdev, &found) >= 0) { if (virDomainHostdevFind(vmdef, hostdev, &found) >= 0) {
pcisrc = &hostdev->source.subsys.u.pci;
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("target pci device %.4x:%.2x:%.2x.%.1x\ _("target pci device %.4x:%.2x:%.2x.%.1x\
already exists"), already exists"),
hostdev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
return -1; return -1;
} }
...@@ -2940,6 +2937,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2940,6 +2937,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
virDomainHostdevDefPtr hostdev) virDomainHostdevDefPtr hostdev)
{ {
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys; virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
libxl_device_pci pcidev; libxl_device_pci pcidev;
virDomainHostdevDefPtr detach; virDomainHostdevDefPtr detach;
int idx; int idx;
...@@ -2952,16 +2950,16 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2952,16 +2950,16 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
if (idx < 0) { if (idx < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("host pci device %.4x:%.2x:%.2x.%.1x not found"), _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, pcisrc->addr.domain, pcisrc->addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); pcisrc->addr.slot, pcisrc->addr.function);
return -1; return -1;
} }
if (libxlIsMultiFunctionDevice(vm->def, detach->info)) { if (libxlIsMultiFunctionDevice(vm->def, detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"), _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, pcisrc->addr.domain, pcisrc->addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); pcisrc->addr.slot, pcisrc->addr.function);
goto error; goto error;
} }
...@@ -2975,8 +2973,8 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2975,8 +2973,8 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to detach pci device\ _("libxenlight failed to detach pci device\
%.4x:%.2x:%.2x.%.1x"), %.4x:%.2x:%.2x.%.1x"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, pcisrc->addr.domain, pcisrc->addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); pcisrc->addr.slot, pcisrc->addr.function);
goto error; goto error;
} }
......
...@@ -243,6 +243,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm, ...@@ -243,6 +243,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
int ret = -1; int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virPCIDevicePtr pci = NULL; virPCIDevicePtr pci = NULL;
virUSBDevicePtr usb = NULL; virUSBDevicePtr usb = NULL;
virSCSIDevicePtr scsi = NULL; virSCSIDevicePtr scsi = NULL;
...@@ -260,14 +261,13 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm, ...@@ -260,14 +261,13 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
switch (dev->source.subsys.type) { switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
int rv; int rv;
pci = virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, pci = virPCIDeviceNew(pcisrc->addr.domain,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.slot, pcisrc->addr.slot,
dev->source.subsys.u.pci.addr.function); pcisrc->addr.function);
if (!pci) if (!pci)
goto cleanup; goto cleanup;
...@@ -340,6 +340,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, ...@@ -340,6 +340,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
{ {
int ret = -1; int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virPCIDevicePtr pci = NULL; virPCIDevicePtr pci = NULL;
char *path = NULL; char *path = NULL;
...@@ -355,14 +356,13 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, ...@@ -355,14 +356,13 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
switch (dev->source.subsys.type) { switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
int rv; int rv;
pci = virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, pci = virPCIDeviceNew(pcisrc->addr.domain,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.slot, pcisrc->addr.slot,
dev->source.subsys.u.pci.addr.function); pcisrc->addr.function);
if (!pci) if (!pci)
goto cleanup; goto cleanup;
......
...@@ -554,18 +554,16 @@ qemuNetworkPrepareDevices(virDomainDefPtr def) ...@@ -554,18 +554,16 @@ qemuNetworkPrepareDevices(virDomainDefPtr def)
* separately. * separately.
*/ */
virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net); virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
if (virDomainHostdevFind(def, hostdev, NULL) >= 0) { if (virDomainHostdevFind(def, hostdev, NULL) >= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("PCI device %04x:%02x:%02x.%x " _("PCI device %04x:%02x:%02x.%x "
"allocated from network %s is already " "allocated from network %s is already "
"in use by domain %s"), "in use by domain %s"),
hostdev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function,
hostdev->source.subsys.u.pci.addr.slot, net->data.network.name, def->name);
hostdev->source.subsys.u.pci.addr.function,
net->data.network.name,
def->name);
goto cleanup; goto cleanup;
} }
if (virDomainHostdevInsert(def, hostdev) < 0) if (virDomainHostdevInsert(def, hostdev) < 0)
...@@ -4834,14 +4832,13 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def, ...@@ -4834,14 +4832,13 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def,
int int
qemuOpenPCIConfig(virDomainHostdevDefPtr dev) qemuOpenPCIConfig(virDomainHostdevDefPtr dev)
{ {
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
char *path = NULL; char *path = NULL;
int configfd = -1; int configfd = -1;
if (virAsprintf(&path, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/config", if (virAsprintf(&path, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/config",
dev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function) < 0)
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function) < 0)
return -1; return -1;
configfd = open(path, O_RDWR, 0); configfd = open(path, O_RDWR, 0);
...@@ -4861,7 +4858,8 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def, ...@@ -4861,7 +4858,8 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; 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 */ /* caller has to assign proper passthrough backend type */
switch ((virDomainHostdevSubsysPCIBackendType) backend) { switch ((virDomainHostdevSubsysPCIBackendType) backend) {
...@@ -4883,20 +4881,19 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def, ...@@ -4883,20 +4881,19 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
} }
virBufferAddLit(&buf, ",host="); virBufferAddLit(&buf, ",host=");
if (dev->source.subsys.u.pci.addr.domain) { if (pcisrc->addr.domain) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("non-zero domain='%.4x' in host device PCI address " _("non-zero domain='%.4x' in host device PCI address "
"not supported in this QEMU binary"), "not supported in this QEMU binary"),
dev->source.subsys.u.pci.addr.domain); pcisrc->addr.domain);
goto error; goto error;
} }
virBufferAsprintf(&buf, "%.4x:", dev->source.subsys.u.pci.addr.domain); virBufferAsprintf(&buf, "%.4x:", pcisrc->addr.domain);
} }
virBufferAsprintf(&buf, "%.2x:%.2x.%.1x", virBufferAsprintf(&buf, "%.2x:%.2x.%.1x",
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.bus, pcisrc->addr.slot,
dev->source.subsys.u.pci.addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.function);
virBufferAsprintf(&buf, ",id=%s", dev->info->alias); virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
if (dev->info->bootIndex) if (dev->info->bootIndex)
virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex); virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
...@@ -4921,25 +4918,23 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, ...@@ -4921,25 +4918,23 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
char *ret = NULL; 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)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("non-zero domain='%.4x' in host device PCI address " _("non-zero domain='%.4x' in host device PCI address "
"not supported in this QEMU binary"), "not supported in this QEMU binary"),
dev->source.subsys.u.pci.addr.domain); pcisrc->addr.domain);
goto cleanup; goto cleanup;
} }
ignore_value(virAsprintf(&ret, "host=%.4x:%.2x:%.2x.%.1x", ignore_value(virAsprintf(&ret, "host=%.4x:%.2x:%.2x.%.1x",
dev->source.subsys.u.pci.addr.domain, pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function));
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function));
} else { } else {
ignore_value(virAsprintf(&ret, "host=%.2x:%.2x.%.1x", ignore_value(virAsprintf(&ret, "host=%.2x:%.2x.%.1x",
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.bus, pcisrc->addr.slot,
dev->source.subsys.u.pci.addr.slot, pcisrc->addr.function));
dev->source.subsys.u.pci.addr.function));
} }
cleanup: cleanup:
return ret; return ret;
......
...@@ -3204,14 +3204,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver, ...@@ -3204,14 +3204,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
virDomainHostdevDefPtr detach) virDomainHostdevDefPtr detach)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysPtr subsys = &detach->source.subsys; virDomainHostdevSubsysPCIPtr pcisrc = &detach->source.subsys.u.pci;
int ret; int ret;
if (qemuIsMultiFunctionDevice(vm->def, detach->info)) { if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"), _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, pcisrc->addr.domain, pcisrc->addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); pcisrc->addr.slot, pcisrc->addr.function);
return -1; return -1;
} }
...@@ -3361,6 +3361,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, ...@@ -3361,6 +3361,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
virDomainHostdevDefPtr hostdev = dev->data.hostdev; virDomainHostdevDefPtr hostdev = dev->data.hostdev;
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys; virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
virDomainHostdevDefPtr detach = NULL; virDomainHostdevDefPtr detach = NULL;
int idx; int idx;
...@@ -3378,8 +3379,8 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, ...@@ -3378,8 +3379,8 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
_("host pci device %.4x:%.2x:%.2x.%.1x not found"), _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, pcisrc->addr.domain, pcisrc->addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); pcisrc->addr.slot, pcisrc->addr.function);
break; break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
if (usbsrc->bus && usbsrc->device) { if (usbsrc->bus && usbsrc->device) {
......
...@@ -813,6 +813,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -813,6 +813,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
virSecurityLabelDefPtr secdef = virSecurityLabelDefPtr secdef =
virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME); virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME);
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
if (!secdef) if (!secdef)
return -1; return -1;
...@@ -845,16 +846,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -845,16 +846,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevicePtr pci = virPCIDevicePtr pci =
virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function);
if (!pci) if (!pci)
goto done; goto done;
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci); char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) { if (!vfioGroupDev) {
......
...@@ -510,6 +510,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -510,6 +510,7 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr); virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
virSecurityDACCallbackData cbdata; virSecurityDACCallbackData cbdata;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
int ret = -1; int ret = -1;
if (!priv->dynamicOwnership) if (!priv->dynamicOwnership)
...@@ -543,16 +544,13 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -543,16 +544,13 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevicePtr pci = virPCIDevicePtr pci =
virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function);
if (!pci) if (!pci)
goto done; goto done;
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci); char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) { if (!vfioGroupDev) {
...@@ -639,6 +637,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -639,6 +637,7 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr); virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
int ret = -1; int ret = -1;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
...@@ -667,16 +666,13 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -667,16 +666,13 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevicePtr pci = virPCIDevicePtr pci =
virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function);
if (!pci) if (!pci)
goto done; goto done;
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci); char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) { if (!vfioGroupDev) {
......
...@@ -1320,6 +1320,7 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def, ...@@ -1320,6 +1320,7 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
{ {
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
int ret = -1; int ret = -1;
switch (dev->source.subsys.type) { switch (dev->source.subsys.type) {
...@@ -1342,16 +1343,13 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def, ...@@ -1342,16 +1343,13 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevicePtr pci = virPCIDevicePtr pci =
virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function);
if (!pci) if (!pci)
goto done; goto done;
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci); char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) { if (!vfioGroupDev) {
...@@ -1510,6 +1508,7 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -1510,6 +1508,7 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
{ {
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
int ret = -1; int ret = -1;
switch (dev->source.subsys.type) { switch (dev->source.subsys.type) {
...@@ -1533,16 +1532,13 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -1533,16 +1532,13 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevicePtr pci = virPCIDevicePtr pci =
virPCIDeviceNew(dev->source.subsys.u.pci.addr.domain, virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
dev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
dev->source.subsys.u.pci.addr.slot,
dev->source.subsys.u.pci.addr.function);
if (!pci) if (!pci)
goto done; goto done;
if (dev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci); char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) { if (!vfioGroupDev) {
......
...@@ -168,6 +168,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) ...@@ -168,6 +168,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i]; virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
virPCIDevicePtr dev; virPCIDevicePtr dev;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
...@@ -175,10 +176,8 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) ...@@ -175,10 +176,8 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue; continue;
dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain, dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
if (!dev) { if (!dev) {
virObjectUnref(list); virObjectUnref(list);
return NULL; return NULL;
...@@ -191,14 +190,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) ...@@ -191,14 +190,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
} }
virPCIDeviceSetManaged(dev, hostdev->managed); virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) { if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) {
virObjectUnref(list); virObjectUnref(list);
return NULL; return NULL;
} }
} else if (hostdev->source.subsys.u.pci.backend } else if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
if (virPCIDeviceSetStubDriver(dev, "pciback") < 0) { if (virPCIDeviceSetStubDriver(dev, "pciback") < 0) {
virObjectUnref(list); virObjectUnref(list);
return NULL; return NULL;
...@@ -619,16 +616,15 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr, ...@@ -619,16 +616,15 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
virPCIDevicePtr dev; virPCIDevicePtr dev;
virPCIDevicePtr pcidev; virPCIDevicePtr pcidev;
virDomainHostdevDefPtr hostdev = hostdevs[i]; virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue; continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue; continue;
dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain, dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
/* original states "unbind_from_stub", "remove_slot", /* original states "unbind_from_stub", "remove_slot",
* "reprobe" were already set by pciDettachDevice in * "reprobe" were already set by pciDettachDevice in
...@@ -832,28 +828,26 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, ...@@ -832,28 +828,26 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->inactivePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs);
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
virDomainHostdevSubsysPCIPtr pcisrc;
hostdev = hostdevs[i]; hostdev = hostdevs[i];
pcisrc = &hostdev->source.subsys.u.pci;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue; continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue; continue;
dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.addr.domain, dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
hostdev->source.subsys.u.pci.addr.bus, pcisrc->addr.slot, pcisrc->addr.function);
hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function);
if (!dev) if (!dev)
goto cleanup; goto cleanup;
virPCIDeviceSetManaged(dev, hostdev->managed); virPCIDeviceSetManaged(dev, hostdev->managed);
if (hostdev->source.subsys.u.pci.backend if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0) if (virPCIDeviceSetStubDriver(dev, "vfio-pci") < 0)
goto cleanup; goto cleanup;
} else if (hostdev->source.subsys.u.pci.backend } else if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN) {
if (virPCIDeviceSetStubDriver(dev, "pciback") < 0) if (virPCIDeviceSetStubDriver(dev, "pciback") < 0)
goto cleanup; goto cleanup;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册