[libvirt] [PATCH 4/6] port allocator: drop skip flag

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Wed Dec 20 06:35:36 UTC 2017


This flag is only used for tests and tests overload socket and bind
functions using virportallocatormock.c already in a suitable fashion
so we don't need this flag at all.
---
 src/bhyve/bhyve_driver.c       |  2 +-
 src/libxl/libxl_driver.c       |  5 ++---
 src/qemu/qemu_driver.c         |  9 +++------
 src/util/virportallocator.c    | 14 ++++----------
 src/util/virportallocator.h    |  7 +------
 tests/bhyvexml2argvtest.c      |  3 +--
 tests/libxlxml2domconfigtest.c |  3 +--
 tests/virportallocatortest.c   |  4 ++--
 8 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 43487f5..19c86e2 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1267,7 +1267,7 @@ bhyveStateInitialize(bool privileged,
     if (!(bhyve_driver->domainEventState = virObjectEventStateNew()))
         goto cleanup;
 
-    if (!(bhyve_driver->remotePorts = virPortRangeNew(_("display"), 5900, 65535, 0)))
+    if (!(bhyve_driver->remotePorts = virPortRangeNew(_("display"), 5900, 65535)))
         goto cleanup;
 
     bhyve_driver->hostsysinfo = virSysinfoRead();
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5209ea7..18126e4 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -659,15 +659,14 @@ libxlStateInitialize(bool privileged,
     if (!(libxl_driver->reservedGraphicsPorts =
           virPortRangeNew(_("VNC"),
                           LIBXL_VNC_PORT_MIN,
-                          LIBXL_VNC_PORT_MAX,
-                          0)))
+                          LIBXL_VNC_PORT_MAX)))
         goto error;
 
     /* Allocate bitmap for migration port reservation */
     if (!(libxl_driver->migrationPorts =
           virPortRangeNew(_("migration"),
                           LIBXL_MIGRATION_PORT_MIN,
-                          LIBXL_MIGRATION_PORT_MAX, 0)))
+                          LIBXL_MIGRATION_PORT_MAX)))
         goto error;
 
     if (!(libxl_driver->domains = virDomainObjListNew()))
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 254ccd1..edde4e2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -748,22 +748,19 @@ qemuStateInitialize(bool privileged,
     if ((qemu_driver->remotePorts =
          virPortRangeNew(_("display"),
                          cfg->remotePortMin,
-                         cfg->remotePortMax,
-                         0)) == NULL)
+                         cfg->remotePortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->webSocketPorts =
          virPortRangeNew(_("webSocket"),
                          cfg->webSocketPortMin,
-                         cfg->webSocketPortMax,
-                         0)) == NULL)
+                         cfg->webSocketPortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->migrationPorts =
          virPortRangeNew(_("migration"),
                          cfg->migrationPortMin,
-                         cfg->migrationPortMax,
-                         0)) == NULL)
+                         cfg->migrationPortMax)) == NULL)
         goto error;
 
     if (qemuSecurityInit(qemu_driver) < 0)
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index a154806..76fac49 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -47,8 +47,6 @@ struct _virPortRange {
 
     unsigned short start;
     unsigned short end;
-
-    unsigned int flags;
 };
 
 static virClassPtr virPortAllocatorClass;
@@ -96,8 +94,7 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator)
 
 virPortRangePtr virPortRangeNew(const char *name,
                                 unsigned short start,
-                                unsigned short end,
-                                unsigned int flags)
+                                unsigned short end)
 {
     virPortRangePtr range;
 
@@ -110,7 +107,6 @@ virPortRangePtr virPortRangeNew(const char *name,
     if (VIR_ALLOC(range) < 0)
         return NULL;
 
-    range->flags = flags;
     range->start = start;
     range->end = end;
 
@@ -231,11 +227,9 @@ int virPortAllocatorAcquire(virPortRangePtr range,
         if (virBitmapIsBitSet(pa->bitmap, i))
             continue;
 
-        if (!(range->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) {
-            if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
-                virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
-                goto cleanup;
-        }
+        if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
+            virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
+            goto cleanup;
 
         if (!used && !v6used) {
             /* Add port to bitmap of reserved ports */
diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h
index ae00edc..bddeadd 100644
--- a/src/util/virportallocator.h
+++ b/src/util/virportallocator.h
@@ -28,14 +28,9 @@
 typedef struct _virPortRange virPortRange;
 typedef virPortRange *virPortRangePtr;
 
-typedef enum {
-    VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK = (1 << 0),
-} virPortAllocatorFlags;
-
 virPortRangePtr virPortRangeNew(const char *name,
                                 unsigned short start,
-                                unsigned short end,
-                                unsigned int flags);
+                                unsigned short end);
 
 void virPortRangeFree(virPortRangePtr range);
 
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index 93c8026..4edf921 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -145,8 +145,7 @@ mymain(void)
     if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
         return EXIT_FAILURE;
 
-    if (!(driver.remotePorts = virPortRangeNew("display", 5900, 65535,
-                                               VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+    if (!(driver.remotePorts = virPortRangeNew("display", 5900, 65535)))
         return EXIT_FAILURE;
 
 
diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index b3bdcaf..375fac3 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -74,8 +74,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
     if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
         goto cleanup;
 
-    if (!(gports = virPortRangeNew("vnc", 5900, 6000,
-                                   VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+    if (!(gports = virPortRangeNew("vnc", 5900, 6000)))
         goto cleanup;
 
     if (!(xmlopt = libxlCreateXMLConf()))
diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index cd792ad..25641d1 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -42,7 +42,7 @@ VIR_LOG_INIT("tests.portallocatortest");
 
 static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortRangePtr ports = virPortRangeNew("test", 5900, 5909, 0);
+    virPortRangePtr ports = virPortRangeNew("test", 5900, 5909);
     int ret = -1;
     unsigned short p1, p2, p3, p4, p5, p6, p7;
 
@@ -114,7 +114,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 
 static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortRangePtr ports = virPortRangeNew("test", 5900, 5910, 0);
+    virPortRangePtr ports = virPortRangeNew("test", 5900, 5910);
     int ret = -1;
     unsigned short p1, p2, p3, p4;
 
-- 
1.8.3.1




More information about the libvir-list mailing list