[PATCH RFC 3/5] remove qemuDomainReleaseDeviceAddress and its uses

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

 



There is no need to release addresses anymore, because the address sets
are now recalculated.
---
 src/qemu/qemu_domain.c         |  3 +--
 src/qemu/qemu_domain.h         |  2 --
 src/qemu/qemu_domain_address.c | 31 ++---------------------
 src/qemu/qemu_domain_address.h |  5 ----
 src/qemu/qemu_hotplug.c        | 57 ++++--------------------------------------
 src/qemu/qemu_process.c        |  6 ++---
 tests/qemuhotplugtest.c        |  2 +-
 7 files changed, 12 insertions(+), 94 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 24e594b..424300a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1328,7 +1328,6 @@ qemuDomainObjPrivateFree(void *data)
     virObjectUnref(priv->qemuCaps);
 
     virCgroupFree(&priv->cgroup);
-    virDomainUSBAddressSetFree(priv->usbaddrs);
     virDomainChrSourceDefFree(priv->monConfig);
     qemuDomainObjFreeJob(priv);
     VIR_FREE(priv->lockState);
@@ -2660,7 +2659,7 @@ qemuDomainDefAssignAddresses(virDomainDef *def,
                                             def->emulator)))
         goto cleanup;
 
-    if (qemuDomainAssignAddresses(def, qemuCaps, NULL, newDomain) < 0)
+    if (qemuDomainAssignAddresses(def, qemuCaps, newDomain) < 0)
         goto cleanup;
 
     ret = 0;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index af96d4a..21b4869 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -184,8 +184,6 @@ struct _qemuDomainObjPrivate {
     bool beingDestroyed;
     char *pidfile;
 
-    virDomainUSBAddressSetPtr usbaddrs;
-
     virQEMUCapsPtr qemuCaps;
     char *lockState;
 
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 99df92c..88c4ab9 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -1780,22 +1780,14 @@ qemuDomainUSBAddrSetCreateFromDomain(virDomainDefPtr def)
 
 
 static int
-qemuDomainAssignUSBAddresses(virDomainDefPtr def,
-                             virDomainObjPtr obj)
+qemuDomainAssignUSBAddresses(virDomainDefPtr def)
 {
     int ret = -1;
     virDomainUSBAddressSetPtr addrs = NULL;
-    qemuDomainObjPrivatePtr priv = NULL;
 
     if (!(addrs = qemuDomainUSBAddrSetCreateFromDomain(def)))
         goto cleanup;
 
-    if (obj && obj->privateData) {
-        priv = obj->privateData;
-        priv->usbaddrs = addrs;
-        addrs = NULL;
-    }
-
     ret = 0;
 
  cleanup:
@@ -1807,7 +1799,6 @@ qemuDomainAssignUSBAddresses(virDomainDefPtr def,
 int
 qemuDomainAssignAddresses(virDomainDefPtr def,
                           virQEMUCapsPtr qemuCaps,
-                          virDomainObjPtr obj,
                           bool newDomain)
 {
     if (qemuDomainAssignVirtioSerialAddresses(def) < 0)
@@ -1824,26 +1815,8 @@ qemuDomainAssignAddresses(virDomainDefPtr def,
     if (qemuDomainAssignPCIAddresses(def, qemuCaps) < 0)
         return -1;
 
-    if (newDomain && qemuDomainAssignUSBAddresses(def, obj) < 0)
+    if (newDomain && qemuDomainAssignUSBAddresses(def) < 0)
         return -1;
 
     return 0;
 }
-
-
-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_USB &&
-        priv->usbaddrs &&
-        virDomainUSBAddressRelease(priv->usbaddrs, info) < 0)
-        VIR_WARN("Unable to release USB address on %s",
-                 NULLSTR(devstr));
-}
diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h
index dfa76d2..adf163c 100644
--- a/src/qemu/qemu_domain_address.h
+++ b/src/qemu/qemu_domain_address.h
@@ -33,14 +33,9 @@ int qemuDomainSetSCSIControllerModel(const virDomainDef *def,
 
 int qemuDomainAssignAddresses(virDomainDefPtr def,
                               virQEMUCapsPtr qemuCaps,
-                              virDomainObjPtr obj,
                               bool newDomain)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
-void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
-                                    virDomainDeviceInfoPtr info,
-                                    const char *devstr);
-
 virDomainCCWAddressSetPtr
 qemuDomainCCWAddrSetCreateFromDomain(virDomainDefPtr def)
     ATTRIBUTE_NONNULL(1);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 078d936..6fb73d0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -309,14 +309,12 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     char *devstr = NULL;
     char *drivestr = NULL;
     char *drivealias = NULL;
-    bool releaseaddr = false;
     bool driveAdded = false;
     bool secobjAdded = false;
     bool encobjAdded = false;
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
     virDomainPCIAddressSetPtr pciaddrs = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    const char *src = virDomainDiskGetSource(disk);
     virJSONValuePtr secobjProps = NULL;
     virJSONValuePtr encobjProps = NULL;
     qemuDomainDiskPrivatePtr diskPriv;
@@ -352,7 +350,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
         if (virDomainPCIAddressEnsureAddr(pciaddrs, &disk->info) < 0)
             goto error;
     }
-    releaseaddr = true;
     if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
         goto error;
 
@@ -409,10 +406,8 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
         goto exit_monitor;
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
-        releaseaddr = false;
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto error;
-    }
 
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
 
@@ -446,15 +441,11 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
         virFreeError(orig_err);
     }
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
-        releaseaddr = false;
+    ignore_value(qemuDomainObjExitMonitor(driver, vm) < 0);
 
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
 
  error:
-    if (releaseaddr)
-        qemuDomainReleaseDeviceAddress(vm, &disk->info, src);
-
     ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
     goto cleanup;
 }
@@ -470,7 +461,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
     virDomainPCIAddressSetPtr pciaddrs = NULL;
-    bool releaseaddr = false;
 
     if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
@@ -520,7 +510,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
                                       !controller->info.addr.ccw.assigned) < 0)
             goto cleanup;
     }
-    releaseaddr = true;
     if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controller) < 0)
         goto cleanup;
 
@@ -533,7 +522,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     qemuDomainObjEnterMonitor(driver, vm);
     ret = qemuMonitorAddDevice(priv->mon, devstr);
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
-        releaseaddr = false;
         ret = -1;
         goto cleanup;
     }
@@ -545,9 +533,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     }
 
  cleanup:
-    if (ret != 0 && releaseaddr)
-        qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL);
-
     VIR_FREE(devstr);
     virDomainCCWAddressSetFree(ccwaddrs);
     virDomainPCIAddressSetFree(pciaddrs);
@@ -935,7 +920,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     virNetDevVPortProfilePtr vport = NULL;
     int ret = -1;
     int vlan;
-    bool releaseaddr = false;
     bool iface_connected = false;
     int actualType;
     virNetDevBandwidthPtr actualBandwidth;
@@ -1096,8 +1080,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
             goto cleanup;
     }
 
-    releaseaddr = true;
-
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV)) {
         vlan = -1;
     } else {
@@ -1210,9 +1192,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     if (!ret) {
         vm->def->nets[vm->def->nnets++] = net;
     } else {
-        if (releaseaddr)
-            qemuDomainReleaseDeviceAddress(vm, &net->info, NULL);
-
         if (iface_connected) {
             virDomainConfNWFilterTeardown(net);
 
@@ -1307,7 +1286,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     char *devstr = NULL;
     int configfd = -1;
     char *configfd_name = NULL;
-    bool releaseaddr = false;
     bool teardowncgroup = false;
     bool teardownlabel = false;
     int backend;
@@ -1382,7 +1360,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     if (virDomainPCIAddressEnsureAddr(pciaddrs, hostdev->info) < 0)
         goto error;
 
-    releaseaddr = true;
     if (backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) {
         configfd = qemuOpenPCIConfig(hostdev);
@@ -1430,9 +1407,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
                                               vm->def, hostdev, NULL) < 0)
         VIR_WARN("Unable to restore host device labelling on hotplug fail");
 
-    if (releaseaddr)
-        qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
-
     qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
 
     VIR_FREE(devstr);
@@ -1682,7 +1656,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
     char *devstr = NULL;
     char *charAlias = NULL;
     bool chardevAttached = false;
-    bool need_release = false;
 
     if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
         qemuDomainPrepareChannel(chr, priv->channelTargetDir) < 0)
@@ -1693,8 +1666,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
 
     if ((rc = qemuDomainAttachChrDeviceAssignAddr(vm->def, priv, chr)) < 0)
         goto cleanup;
-    if (rc == 1)
-        need_release = true;
 
     if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
         goto cleanup;
@@ -1723,8 +1694,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
  cleanup:
     if (ret < 0 && virDomainObjIsActive(vm))
         qemuDomainChrInsertPreAllocCleanup(vmdef, chr);
-    if (ret < 0 && need_release)
-        qemuDomainReleaseDeviceAddress(vm, &chr->info, NULL);
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
     return ret;
@@ -1754,7 +1723,6 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     char *devstr = NULL;
     char *charAlias = NULL;
     char *objAlias = NULL;
-    bool releaseaddr = false;
     bool chardevAdded = false;
     bool objAdded = false;
     virJSONValuePtr props = NULL;
@@ -1783,7 +1751,6 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
                                             rng->source.file))
             return -1;
     }
-    releaseaddr = true;
 
     if (rng->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
         rng->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
@@ -1830,10 +1797,8 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
         goto exit_monitor;
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
-        releaseaddr = false;
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto cleanup;
-    }
 
     VIR_APPEND_ELEMENT_INPLACE(vm->def->rngs, vm->def->nrngs, rng);
 
@@ -1843,8 +1808,6 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     virDomainAuditRNG(vm, NULL, rng, "attach", ret == 0);
  cleanup:
     virJSONValueFree(props);
-    if (ret < 0 && releaseaddr)
-        qemuDomainReleaseDeviceAddress(vm, &rng->info, NULL);
     VIR_FREE(charAlias);
     VIR_FREE(objAlias);
     VIR_FREE(devstr);
@@ -1863,8 +1826,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
         virFreeError(orig_err);
     }
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
-        releaseaddr = false;
+    ignore_value(qemuDomainObjExitMonitor(driver, vm) < 0);
     goto audit;
 }
 
@@ -3090,8 +3052,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
         }
     }
 
-    qemuDomainReleaseDeviceAddress(vm, &disk->info, src);
-
     if (virSecurityManagerRestoreDiskLabel(driver->securityManager,
                                            vm->def, disk) < 0)
         VIR_WARN("Unable to restore security label on %s", src);
@@ -3132,7 +3092,6 @@ qemuDomainRemoveControllerDevice(virQEMUDriverPtr driver,
         }
     }
 
-    qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL);
     virDomainControllerDefFree(controller);
     return 0;
 }
@@ -3192,7 +3151,6 @@ qemuDomainRemovePCIHostDevice(virQEMUDriverPtr driver,
                               virDomainHostdevDefPtr hostdev)
 {
     qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
-    qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
 }
 
 static void
@@ -3201,7 +3159,6 @@ qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver,
                               virDomainHostdevDefPtr hostdev)
 {
     qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
-    qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
 }
 
 static void
@@ -3372,7 +3329,6 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
         }
     }
 
-    qemuDomainReleaseDeviceAddress(vm, &net->info, NULL);
     virDomainConfNWFilterTeardown(net);
 
     if (cfg->macFilter && (net->ifname != NULL)) {
@@ -3493,7 +3449,6 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
 
     if ((idx = virDomainRNGFind(vm->def, rng)) >= 0)
         virDomainRNGRemove(vm->def, idx);
-    qemuDomainReleaseDeviceAddress(vm, &rng->info, NULL);
     virDomainRNGDefFree(rng);
     ret = 0;
 
@@ -4349,10 +4304,8 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto cleanup;
 
-    if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) {
-        qemuDomainReleaseDeviceAddress(vm, &tmpChr->info, NULL);
+    if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
         ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
-    }
 
  cleanup:
     qemuDomainResetDeviceRemoval(vm);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 907da30..607d73c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3345,7 +3345,7 @@ qemuProcessReconnect(void *opaque)
         goto cleanup;
     }
 
-    if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps, obj, false)) < 0)
+    if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps, false)) < 0)
         goto error;
 
     /* if domain requests security driver we haven't loaded, report error, but
@@ -4824,7 +4824,7 @@ qemuProcessPrepareDomain(virConnectPtr conn,
      * use in hotplug
      */
     VIR_DEBUG("Assigning domain PCI addresses");
-    if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, vm,
+    if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps,
                                    !!(flags & VIR_QEMU_PROCESS_START_NEW))) < 0)
         goto cleanup;
 
@@ -6002,7 +6002,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
      * use in hotplug
      */
     VIR_DEBUG("Assigning domain PCI addresses");
-    if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, vm, false)) < 0)
+    if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, false)) < 0)
         goto error;
 
     if ((timestamp = virTimeStringNow()) == NULL)
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 0a5f068..e0a7d70 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -87,7 +87,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
                                                VIR_DOMAIN_DEF_PARSE_INACTIVE)))
         goto cleanup;
 
-    if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps, *vm, true) < 0)
+    if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps, true) < 0)
         goto cleanup;
 
     if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)
-- 
1.9.1

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