From 89b7bb75d7ef03edd2f127449f0f0ed2bf79e4fe Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 9 Jul 2013 22:30:57 +0200 Subject: [PATCH] qemu: Add qemuDomainReleaseDeviceAddress to remove any address --- src/qemu/qemu_command.c | 35 ++++++++++++++++--- src/qemu/qemu_command.h | 8 ++--- src/qemu/qemu_hotplug.c | 75 +++++++---------------------------------- 3 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 735f300560..71e37f3894 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1180,8 +1180,9 @@ qemuDomainCCWAddressValidate(virDomainDefPtr def ATTRIBUTE_UNUSED, return qemuDomainCCWAddressAssign(info, data, false); } -int qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs, - virDomainDeviceInfoPtr dev) +static int +qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs, + virDomainDeviceInfoPtr dev) { char *addr; int ret; @@ -1820,8 +1821,9 @@ int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs, return 0; } -int qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs, - virDevicePCIAddressPtr addr) +static int +qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs, + virDevicePCIAddressPtr addr) { if (!qemuPCIAddressValidate(addrs, addr)) return -1; @@ -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) \ (((ctrl)->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) && \ ((ctrl)->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1 || \ diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 88d70999ee..e15fe647fe 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -221,6 +221,10 @@ int qemuDomainAssignAddresses(virDomainDefPtr def, int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def, virQEMUCapsPtr qemuCaps); +void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm, + virDomainDeviceInfoPtr info, + const char *devstr); + int qemuDomainAssignPCIAddresses(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, virDomainObjPtr obj); @@ -237,16 +241,12 @@ int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs, virDomainDeviceInfoPtr dev); int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs, virDevicePCIAddressPtr addr); -int qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs, - virDevicePCIAddressPtr addr); void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs); int qemuAssignDevicePCISlots(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, qemuDomainPCIAddressSetPtr addrs); -int qemuDomainCCWAddressReleaseAddr(qemuDomainCCWAddressSetPtr addrs, - virDomainDeviceInfoPtr dev); int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs, bool autoassign); void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0b7fed6452..688aca35fd 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -327,16 +327,8 @@ cleanup: return ret; error: - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && releaseaddr) { - if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && - 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 (releaseaddr) + qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->src); if (virSecurityManagerRestoreImageLabel(driver->securityManager, vm->def, disk) < 0) @@ -405,13 +397,8 @@ int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver, } cleanup: - if ((ret != 0) && - virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && - (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"); + if (ret != 0 && releaseaddr) + qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL); VIR_FREE(devstr); return ret; @@ -930,19 +917,8 @@ cleanup: if (!ret) { vm->def->nets[vm->def->nnets++] = net; } else { - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && - net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && - 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 (releaseaddr) + qemuDomainReleaseDeviceAddress(vm, &net->info, NULL); if (iface_connected) { virDomainConfNWFilterTeardown(net); @@ -1113,12 +1089,8 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver, return 0; error: - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && - (hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) && - releaseaddr && - qemuDomainPCIAddressReleaseSlot(priv->pciaddrs, - &hostdev->info->addr.pci) < 0) - VIR_WARN("Unable to release PCI address on host device"); + if (releaseaddr) + qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL); qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1); @@ -2341,16 +2313,7 @@ int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, virDomainAuditDisk(vm, detach->src, NULL, "detach", true); - if (detach->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, &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); + qemuDomainReleaseDeviceAddress(vm, &detach->info, dev->data.disk->src); virDomainDiskRemove(vm->def, idx); @@ -2565,13 +2528,9 @@ int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, qemuDomainObjExitMonitor(driver, vm); virDomainControllerRemove(vm->def, idx); + qemuDomainReleaseDeviceAddress(vm, &detach->info, NULL); 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; cleanup: @@ -2643,10 +2602,7 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver, virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(driver->inactivePciHostdevs); - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) && - qemuDomainPCIAddressReleaseSlot(priv->pciaddrs, - &detach->info->addr.pci) < 0) - VIR_WARN("Unable to release PCI address on host device"); + qemuDomainReleaseDeviceAddress(vm, detach->info, NULL); cleanup: virObjectUnref(cfg); @@ -2969,14 +2925,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainAuditNet(vm, detach, NULL, "detach", true); - if (STREQLEN(vm->def->os.machine, "s390-ccw", 8) && - 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"); + qemuDomainReleaseDeviceAddress(vm, &detach->info, NULL); virDomainConfNWFilterTeardown(detach); -- GitLab