[PATCH 04/12] qemu: Add qemuDomainReleaseDeviceAddress to remove any address

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

 



---
 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 d6ef9cd..b46462b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1144,8 +1144,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;
@@ -1784,8 +1785,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;
@@ -1878,6 +1880,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 88d7099..e15fe64 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 ac9350b..2a57fef 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);
 
@@ -2213,16 +2185,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);
 
@@ -2437,13 +2400,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:
@@ -2515,10 +2474,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);
@@ -2841,14 +2797,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);
 
-- 
1.8.3.2

--
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]