]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
port allocator: drop skip bind check flag
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Tue, 6 Feb 2018 09:09:09 +0000 (12:09 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Feb 2018 12:52:45 +0000 (13:52 +0100)
This flag is only used for tests. Let's instead overload bind syscall
in mocks where it is not done yet.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
src/bhyve/bhyve_driver.c
src/libxl/libxl_driver.c
src/qemu/qemu_driver.c
src/util/virportallocator.c
src/util/virportallocator.h
tests/bhyvexml2argvmock.c
tests/bhyvexml2argvtest.c
tests/libxlxml2domconfigtest.c
tests/virmocklibxl.c
tests/virportallocatortest.c

index 913c7b121fcaed37078f4a915afc736279b485ac..849d3abcd3d62fdc3a47be6517daa04b6f32dafb 100644 (file)
@@ -1268,7 +1268,7 @@ bhyveStateInitialize(bool privileged,
         goto cleanup;
 
     if (!(bhyve_driver->remotePorts = virPortAllocatorRangeNew(_("display"),
-                                                               5900, 65535, 0)))
+                                                               5900, 65535)))
         goto cleanup;
 
     bhyve_driver->hostsysinfo = virSysinfoRead();
index a91a0d2ba2fc0438597efcca7ddb9c79c0fe2920..c3616a86d7f4c20ff626aa652f6692534b48bfa3 100644 (file)
@@ -658,15 +658,14 @@ libxlStateInitialize(bool privileged,
     if (!(libxl_driver->reservedGraphicsPorts =
           virPortAllocatorRangeNew(_("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 =
           virPortAllocatorRangeNew(_("migration"),
                                    LIBXL_MIGRATION_PORT_MIN,
-                                   LIBXL_MIGRATION_PORT_MAX, 0)))
+                                   LIBXL_MIGRATION_PORT_MAX)))
         goto error;
 
     if (!(libxl_driver->domains = virDomainObjListNew()))
index 921121d1929f0c3eda16b6e911bb82145908d2ec..14c39b2610dda9a6661730305debeee022647972 100644 (file)
@@ -727,22 +727,19 @@ qemuStateInitialize(bool privileged,
     if ((qemu_driver->remotePorts =
          virPortAllocatorRangeNew(_("display"),
                                   cfg->remotePortMin,
-                                  cfg->remotePortMax,
-                                  0)) == NULL)
+                                  cfg->remotePortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->webSocketPorts =
          virPortAllocatorRangeNew(_("webSocket"),
                                   cfg->webSocketPortMin,
-                                  cfg->webSocketPortMax,
-                                  0)) == NULL)
+                                  cfg->webSocketPortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->migrationPorts =
          virPortAllocatorRangeNew(_("migration"),
                                   cfg->migrationPortMin,
-                                  cfg->migrationPortMax,
-                                  0)) == NULL)
+                                  cfg->migrationPortMax)) == NULL)
         goto error;
 
     if (qemuSecurityInit(qemu_driver) < 0)
index 040d8238b94d94f13ce3b415c5e38fbdb2be15d6..d800fdfd41265684bb0e30b7371859d23d5a78ec 100644 (file)
@@ -47,8 +47,6 @@ struct _virPortAllocatorRange {
 
     unsigned short start;
     unsigned short end;
-
-    unsigned int flags;
 };
 
 static virClassPtr virPortAllocatorClass;
@@ -99,8 +97,7 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator)
 virPortAllocatorRangePtr
 virPortAllocatorRangeNew(const char *name,
                          unsigned short start,
-                         unsigned short end,
-                         unsigned int flags)
+                         unsigned short end)
 {
     virPortAllocatorRangePtr range;
 
@@ -113,7 +110,6 @@ virPortAllocatorRangeNew(const char *name,
     if (VIR_ALLOC(range) < 0)
         return NULL;
 
-    range->flags = flags;
     range->start = start;
     range->end = end;
 
@@ -237,11 +233,9 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr 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 */
index 2e0ba466ef3dd908b7611c353f9bfbcd8e823252..1d7505fcf8f0c06382870837bbe3386ba13d4ffd 100644 (file)
 typedef struct _virPortAllocatorRange virPortAllocatorRange;
 typedef virPortAllocatorRange *virPortAllocatorRangePtr;
 
-typedef enum {
-    VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK = (1 << 0),
-} virPortAllocatorFlags;
-
 virPortAllocatorRangePtr
 virPortAllocatorRangeNew(const char *name,
                          unsigned short start,
-                         unsigned short end,
-                         unsigned int flags);
+                         unsigned short end);
 
 void virPortAllocatorRangeFree(virPortAllocatorRangePtr range);
 
index 7afa0e34c43ca0ff6f8cecccfb4ca5a402fccd27..f4fac092a5be42e30f057785f1f4fd6ca5d11989 100644 (file)
@@ -53,3 +53,10 @@ int virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
 {
     return 0;
 }
+
+int bind(int sockfd ATTRIBUTE_UNUSED,
+         const struct sockaddr *addr ATTRIBUTE_UNUSED,
+         socklen_t addrlen ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
index a7d5ce4c45dd6de7bc989df251f4a89e437fa364..eb0f548f17e17477f11905fb10206b4f0e0dbf83 100644 (file)
@@ -154,8 +154,7 @@ mymain(void)
     if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
         return EXIT_FAILURE;
 
-    if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535,
-                                                        VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+    if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535)))
         return EXIT_FAILURE;
 
 
index 2a678b8d6234197223036994cc6a7acdbe34faee..1f7411c57c3e0b094377b2cc4590086cdb361e63 100644 (file)
@@ -74,8 +74,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
     if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
         goto cleanup;
 
-    if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000,
-                                            VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+    if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000)))
         goto cleanup;
 
     if (!(xmlopt = libxlCreateXMLConf()))
index 747f9f8f8e37ccdc18367eb9f14b295d3aef7849..973595659b0dc5e1f220a0c66d77505bbb5d68ea 100644 (file)
@@ -29,6 +29,7 @@
 # include <libxl.h>
 # include <xenstore.h>
 # include <xenctrl.h>
+# include <sys/socket.h>
 
 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
                        struct xs_handle *)
@@ -68,6 +69,12 @@ VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
 VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
                         struct xs_handle *, handle)
 
+VIR_MOCK_STUB_RET_ARGS(bind,
+                       int, 0,
+                       int, sockfd,
+                       const struct sockaddr *, addr,
+                       socklen_t, addrlen)
+
 VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
                        int, ver,
                        const char *, path,
index 86dd3bcfa3221fb2c552364657121f713796be6e..5e30b415e044883f1228857e8307bb351b8b3931 100644 (file)
@@ -42,7 +42,7 @@ VIR_LOG_INIT("tests.portallocatortest");
 
 static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5909, 0);
+    virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5909);
     int ret = -1;
     unsigned short p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0;
 
@@ -114,7 +114,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 
 static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5910, 0);
+    virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5910);
     int ret = -1;
     unsigned short p1 = 0, p2 = 0, p3 = 0, p4 = 0;