提交 89b7bb75 编写于 作者: J Jiri Denemark

qemu: Add qemuDomainReleaseDeviceAddress to remove any address

上级 dc4cdc57
...@@ -1180,8 +1180,9 @@ qemuDomainCCWAddressValidate(virDomainDefPtr def ATTRIBUTE_UNUSED, ...@@ -1180,8 +1180,9 @@ qemuDomainCCWAddressValidate(virDomainDefPtr def ATTRIBUTE_UNUSED,
return qemuDomainCCWAddressAssign(info, data, false); return qemuDomainCCWAddressAssign(info, data, false);
} }
int qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs, static int
virDomainDeviceInfoPtr dev) qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs,
virDomainDeviceInfoPtr dev)
{ {
char *addr; char *addr;
int ret; int ret;
...@@ -1820,8 +1821,9 @@ int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs, ...@@ -1820,8 +1821,9 @@ int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
return 0; return 0;
} }
int qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs, static int
virDevicePCIAddressPtr addr) qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs,
virDevicePCIAddressPtr addr)
{ {
if (!qemuPCIAddressValidate(addrs, addr)) if (!qemuPCIAddressValidate(addrs, addr))
return -1; return -1;
...@@ -1914,6 +1916,31 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs, ...@@ -1914,6 +1916,31 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
} }
void
qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
virDomainDeviceInfoPtr info,
const char *devstr)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
if (!devstr)
devstr = info->alias;
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
STREQLEN(vm->def->os.machine, "s390-ccw", 8) &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW) &&
qemuDomainCCWAddressReleaseAddr(priv->ccwaddrs, info) < 0)
VIR_WARN("Unable to release CCW address on %s",
NULLSTR(devstr));
else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&info->addr.pci) < 0)
VIR_WARN("Unable to release PCI address on %s",
NULLSTR(devstr));
}
#define IS_USB2_CONTROLLER(ctrl) \ #define IS_USB2_CONTROLLER(ctrl) \
(((ctrl)->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) && \ (((ctrl)->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) && \
((ctrl)->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1 || \ ((ctrl)->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1 || \
......
...@@ -221,6 +221,10 @@ int qemuDomainAssignAddresses(virDomainDefPtr def, ...@@ -221,6 +221,10 @@ int qemuDomainAssignAddresses(virDomainDefPtr def,
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def, int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps); virQEMUCapsPtr qemuCaps);
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
virDomainDeviceInfoPtr info,
const char *devstr);
int qemuDomainAssignPCIAddresses(virDomainDefPtr def, int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virDomainObjPtr obj); virDomainObjPtr obj);
...@@ -237,16 +241,12 @@ int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs, ...@@ -237,16 +241,12 @@ int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs,
virDomainDeviceInfoPtr dev); virDomainDeviceInfoPtr dev);
int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs, int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
virDevicePCIAddressPtr addr); virDevicePCIAddressPtr addr);
int qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs,
virDevicePCIAddressPtr addr);
void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs); void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs);
int qemuAssignDevicePCISlots(virDomainDefPtr def, int qemuAssignDevicePCISlots(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
qemuDomainPCIAddressSetPtr addrs); qemuDomainPCIAddressSetPtr addrs);
int qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs,
virDomainDeviceInfoPtr dev);
int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs, int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs,
bool autoassign); bool autoassign);
void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs); void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs);
......
...@@ -327,16 +327,8 @@ cleanup: ...@@ -327,16 +327,8 @@ cleanup:
return ret; return ret;
error: error:
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && releaseaddr) { if (releaseaddr)
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->src);
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&disk->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on %s", disk->src);
else if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
qemuDomainCCWAddressReleaseAddr(priv->ccwaddrs,
&disk->info) < 0)
VIR_WARN("Unable to release CCW address on %s", disk->src);
}
if (virSecurityManagerRestoreImageLabel(driver->securityManager, if (virSecurityManagerRestoreImageLabel(driver->securityManager,
vm->def, disk) < 0) vm->def, disk) < 0)
...@@ -405,13 +397,8 @@ int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver, ...@@ -405,13 +397,8 @@ int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver,
} }
cleanup: cleanup:
if ((ret != 0) && if (ret != 0 && releaseaddr)
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL);
(controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) &&
releaseaddr &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&controller->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on controller");
VIR_FREE(devstr); VIR_FREE(devstr);
return ret; return ret;
...@@ -930,19 +917,8 @@ cleanup: ...@@ -930,19 +917,8 @@ cleanup:
if (!ret) { if (!ret) {
vm->def->nets[vm->def->nnets++] = net; vm->def->nets[vm->def->nnets++] = net;
} else { } else {
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && if (releaseaddr)
net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && qemuDomainReleaseDeviceAddress(vm, &net->info, NULL);
releaseaddr &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&net->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on NIC");
else if (STREQLEN(vm->def->os.machine, "s390-ccw", 8) &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW) &&
net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
releaseaddr &&
qemuDomainCCWAddressReleaseAddr(priv->ccwaddrs,
&net->info) < 0)
VIR_WARN("Unable to release CCW address on NIC");
if (iface_connected) { if (iface_connected) {
virDomainConfNWFilterTeardown(net); virDomainConfNWFilterTeardown(net);
...@@ -1113,12 +1089,8 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver, ...@@ -1113,12 +1089,8 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
return 0; return 0;
error: error:
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && if (releaseaddr)
(hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) && qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
releaseaddr &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&hostdev->info->addr.pci) < 0)
VIR_WARN("Unable to release PCI address on host device");
qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1); qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1);
...@@ -2341,16 +2313,7 @@ int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, ...@@ -2341,16 +2313,7 @@ int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
virDomainAuditDisk(vm, detach->src, NULL, "detach", true); virDomainAuditDisk(vm, detach->src, NULL, "detach", true);
if (detach->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW && qemuDomainReleaseDeviceAddress(vm, &detach->info, dev->data.disk->src);
STREQLEN(vm->def->os.machine, "s390-ccw", 8) &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW) &&
qemuDomainCCWAddressReleaseAddr(priv->ccwaddrs, &detach->info) < 0) {
VIR_WARN("Unable to release CCW address on %s", dev->data.disk->src);
} else if (detach->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&detach->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on %s", dev->data.disk->src);
virDomainDiskRemove(vm->def, idx); virDomainDiskRemove(vm->def, idx);
...@@ -2565,13 +2528,9 @@ int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, ...@@ -2565,13 +2528,9 @@ int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver,
qemuDomainObjExitMonitor(driver, vm); qemuDomainObjExitMonitor(driver, vm);
virDomainControllerRemove(vm->def, idx); virDomainControllerRemove(vm->def, idx);
qemuDomainReleaseDeviceAddress(vm, &detach->info, NULL);
virDomainControllerDefFree(detach); virDomainControllerDefFree(detach);
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&detach->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on controller");
ret = 0; ret = 0;
cleanup: cleanup:
...@@ -2643,10 +2602,7 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver, ...@@ -2643,10 +2602,7 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver,
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(driver->activePciHostdevs);
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(driver->inactivePciHostdevs);
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && qemuDomainReleaseDeviceAddress(vm, detach->info, NULL);
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&detach->info->addr.pci) < 0)
VIR_WARN("Unable to release PCI address on host device");
cleanup: cleanup:
virObjectUnref(cfg); virObjectUnref(cfg);
...@@ -2969,14 +2925,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, ...@@ -2969,14 +2925,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
virDomainAuditNet(vm, detach, NULL, "detach", true); virDomainAuditNet(vm, detach, NULL, "detach", true);
if (STREQLEN(vm->def->os.machine, "s390-ccw", 8) && qemuDomainReleaseDeviceAddress(vm, &detach->info, NULL);
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW)) {
if (qemuDomainCCWAddressReleaseAddr(priv->ccwaddrs, &detach->info) < 0)
VIR_WARN("Unable to release CCW address on NIC");
} else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
&detach->info.addr.pci) < 0)
VIR_WARN("Unable to release PCI address on NIC");
virDomainConfNWFilterTeardown(detach); virDomainConfNWFilterTeardown(detach);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册