From 4c9c7a5ba2af8e1a221a4e7907a7187bcac70d6f Mon Sep 17 00:00:00 2001 From: Nikolay Shirokovskiy Date: Feb 22 2018 12:52:45 +0000 Subject: port allocator: drop skip bind check flag 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 --- diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 913c7b1..849d3ab 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -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(); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index a91a0d2..c3616a8 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -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())) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 921121d..14c39b2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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) diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 040d823..d800fdf 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -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 */ diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h index 2e0ba46..1d7505f 100644 --- a/src/util/virportallocator.h +++ b/src/util/virportallocator.h @@ -28,15 +28,10 @@ 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); diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index 7afa0e3..f4fac09 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -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; +} diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index a7d5ce4..eb0f548 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -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; diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 2a678b8..1f7411c 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 = virPortAllocatorRangeNew("vnc", 5900, 6000, - VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK))) + if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000))) goto cleanup; if (!(xmlopt = libxlCreateXMLConf())) diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c index 747f9f8..9735956 100644 --- a/tests/virmocklibxl.c +++ b/tests/virmocklibxl.c @@ -29,6 +29,7 @@ # include # include # include +# include 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, diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 86dd3bc..5e30b41 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) { - 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;