[PATCH 3/6] port allocator: remove range check in release function

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

 



Range check in virPortAllocatorSetUsed is not useful anymore
when we manage ports for entire unsigned short range values.
---
 src/bhyve/bhyve_process.c    |  3 +--
 src/libxl/libxl_domain.c     |  3 +--
 src/libxl/libxl_migration.c  |  4 ++--
 src/qemu/qemu_migration.c    | 12 ++++++------
 src/qemu/qemu_process.c      | 14 +++++---------
 src/util/virportallocator.c  | 10 +---------
 src/util/virportallocator.h  |  3 +--
 tests/virportallocatortest.c | 23 +++++++++++------------
 8 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index e215f6a..5e682fa 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -296,8 +296,7 @@ virBhyveProcessStop(bhyveConnPtr driver,
     /* VNC autoport cleanup */
     if ((vm->def->ngraphics == 1) &&
         vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-        if (virPortAllocatorRelease(driver->remotePorts,
-                                    vm->def->graphics[0]->data.vnc.port) < 0) {
+        if (virPortAllocatorRelease(vm->def->graphics[0]->data.vnc.port) < 0) {
             VIR_WARN("Failed to release VNC port for '%s'",
                      vm->def->name);
         }
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 395c8a9..f69d60a 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -778,8 +778,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
         vm->def->graphics[0]->data.vnc.autoport) {
         vnc_port = vm->def->graphics[0]->data.vnc.port;
         if (vnc_port >= LIBXL_VNC_PORT_MIN) {
-            if (virPortAllocatorRelease(driver->reservedGraphicsPorts,
-                                        vnc_port) < 0)
+            if (virPortAllocatorRelease(vnc_port) < 0)
                 VIR_DEBUG("Could not mark port %d as unused", vnc_port);
         }
     }
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 228c850..9c03488 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -805,7 +805,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
     }
     VIR_FREE(socks);
     virObjectUnref(args);
-    virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
+    virPortAllocatorRelease(priv->migrationPort);
     priv->migrationPort = 0;
 
     /* Remove virDomainObj from domain list */
@@ -1256,7 +1256,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
     virObjectEventPtr event = NULL;
     virDomainPtr dom = NULL;
 
-    virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
+    virPortAllocatorRelease(priv->migrationPort);
     priv->migrationPort = 0;
 
     if (cancelled)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index c1ceb16..a19abd0 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -552,7 +552,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
  cleanup:
     VIR_FREE(diskAlias);
     if (ret < 0 && nbdPort == 0)
-        virPortAllocatorRelease(driver->migrationPorts, port);
+        virPortAllocatorRelease(port);
     return ret;
 
  exit_monitor:
@@ -580,7 +580,7 @@ qemuMigrationStopNBDServer(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         return -1;
 
-    virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
+    virPortAllocatorRelease(priv->nbdPort);
     priv->nbdPort = 0;
     return 0;
 }
@@ -2227,7 +2227,7 @@ qemuMigrationPrepareCleanup(virQEMUDriverPtr driver,
               qemuDomainJobTypeToString(priv->job.active),
               qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
 
-    virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
+    virPortAllocatorRelease(priv->migrationPort);
     priv->migrationPort = 0;
 
     if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_IN))
@@ -2907,7 +2907,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
          * it is given in parameters
          */
         if (nbdPort == 0)
-            virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
+            virPortAllocatorRelease(priv->nbdPort);
         priv->nbdPort = 0;
         virDomainObjRemoveTransientDef(vm);
         qemuDomainRemoveInactiveJob(driver, vm);
@@ -3150,7 +3150,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
     if (ret != 0) {
         VIR_FREE(*uri_out);
         if (autoPort)
-            virPortAllocatorRelease(driver->migrationPorts, port);
+            virPortAllocatorRelease(port);
     }
     return ret;
 }
@@ -5500,7 +5500,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
 
  cleanup:
     VIR_FREE(jobInfo);
-    virPortAllocatorRelease(driver->migrationPorts, port);
+    virPortAllocatorRelease(port);
     if (priv->mon)
         qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
     VIR_FREE(priv->origname);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b0f8ea8..0777922 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6384,7 +6384,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         }
     }
 
-    virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
+    virPortAllocatorRelease(priv->nbdPort);
     priv->nbdPort = 0;
 
     if (priv->agent) {
@@ -6539,15 +6539,13 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
         if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
             if (graphics->data.vnc.autoport) {
-                virPortAllocatorRelease(driver->remotePorts,
-                                        graphics->data.vnc.port);
+                virPortAllocatorRelease(graphics->data.vnc.port);
             } else if (graphics->data.vnc.portReserved) {
                 virPortAllocatorSetUsed(graphics->data.spice.port, false);
                 graphics->data.vnc.portReserved = false;
             }
             if (graphics->data.vnc.websocketGenerated) {
-                virPortAllocatorRelease(driver->webSocketPorts,
-                                        graphics->data.vnc.websocket);
+                virPortAllocatorRelease(graphics->data.vnc.websocket);
                 graphics->data.vnc.websocketGenerated = false;
                 graphics->data.vnc.websocket = -1;
             } else if (graphics->data.vnc.websocket) {
@@ -6556,10 +6554,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         }
         if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
             if (graphics->data.spice.autoport) {
-                virPortAllocatorRelease(driver->remotePorts,
-                                        graphics->data.spice.port);
-                virPortAllocatorRelease(driver->remotePorts,
-                                        graphics->data.spice.tlsPort);
+                virPortAllocatorRelease(graphics->data.spice.port);
+                virPortAllocatorRelease(graphics->data.spice.tlsPort);
             } else {
                 if (graphics->data.spice.portReserved) {
                     virPortAllocatorSetUsed(graphics->data.spice.port, false);
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index 76346c7..a154806 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -259,8 +259,7 @@ int virPortAllocatorAcquire(virPortRangePtr range,
     return ret;
 }
 
-int virPortAllocatorRelease(virPortRangePtr range,
-                            unsigned short port)
+int virPortAllocatorRelease(unsigned short port)
 {
     int ret = -1;
     virPortAllocatorPtr pa = virPortAllocatorGet();
@@ -273,13 +272,6 @@ int virPortAllocatorRelease(virPortRangePtr range,
 
     virObjectLock(pa);
 
-    if (port < range->start ||
-        port > range->end) {
-        virReportInvalidArg(port, "port %d must be in range (%d, %d)",
-                            port, range->start, range->end);
-        goto cleanup;
-    }
-
     if (virBitmapClearBit(pa->bitmap, port) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to release port %d"),
diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h
index 8511eca..ae00edc 100644
--- a/src/util/virportallocator.h
+++ b/src/util/virportallocator.h
@@ -42,8 +42,7 @@ void virPortRangeFree(virPortRangePtr range);
 int virPortAllocatorAcquire(virPortRangePtr range,
                             unsigned short *port);
 
-int virPortAllocatorRelease(virPortRangePtr range,
-                            unsigned short port);
+int virPortAllocatorRelease(unsigned short port);
 
 int virPortAllocatorSetUsed(unsigned short port, bool value);
 
diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index 972b579..cd792ad 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -96,13 +96,13 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    virPortAllocatorRelease(ports, p1);
-    virPortAllocatorRelease(ports, p2);
-    virPortAllocatorRelease(ports, p3);
-    virPortAllocatorRelease(ports, p4);
-    virPortAllocatorRelease(ports, p5);
-    virPortAllocatorRelease(ports, p6);
-    virPortAllocatorRelease(ports, p7);
+    virPortAllocatorRelease(p1);
+    virPortAllocatorRelease(p2);
+    virPortAllocatorRelease(p3);
+    virPortAllocatorRelease(p4);
+    virPortAllocatorRelease(p5);
+    virPortAllocatorRelease(p6);
+    virPortAllocatorRelease(p7);
 
     ret = 0;
  cleanup:
@@ -142,8 +142,7 @@ static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-
-    if (virPortAllocatorRelease(ports, p2) < 0)
+    if (virPortAllocatorRelease(p2) < 0)
         goto cleanup;
 
     if (virPortAllocatorAcquire(ports, &p4) < 0)
@@ -153,9 +152,9 @@ static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    virPortAllocatorRelease(ports, p1);
-    virPortAllocatorRelease(ports, p3);
-    virPortAllocatorRelease(ports, p4);
+    virPortAllocatorRelease(p1);
+    virPortAllocatorRelease(p3);
+    virPortAllocatorRelease(p4);
 
     ret = 0;
  cleanup:
-- 
1.8.3.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]
  Powered by Linux