提交 4c9c7a5b 编写于 作者: N Nikolay Shirokovskiy 提交者: Michal Privoznik

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: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
上级 56def261
...@@ -1268,7 +1268,7 @@ bhyveStateInitialize(bool privileged, ...@@ -1268,7 +1268,7 @@ bhyveStateInitialize(bool privileged,
goto cleanup; goto cleanup;
if (!(bhyve_driver->remotePorts = virPortAllocatorRangeNew(_("display"), if (!(bhyve_driver->remotePorts = virPortAllocatorRangeNew(_("display"),
5900, 65535, 0))) 5900, 65535)))
goto cleanup; goto cleanup;
bhyve_driver->hostsysinfo = virSysinfoRead(); bhyve_driver->hostsysinfo = virSysinfoRead();
......
...@@ -658,15 +658,14 @@ libxlStateInitialize(bool privileged, ...@@ -658,15 +658,14 @@ libxlStateInitialize(bool privileged,
if (!(libxl_driver->reservedGraphicsPorts = if (!(libxl_driver->reservedGraphicsPorts =
virPortAllocatorRangeNew(_("VNC"), virPortAllocatorRangeNew(_("VNC"),
LIBXL_VNC_PORT_MIN, LIBXL_VNC_PORT_MIN,
LIBXL_VNC_PORT_MAX, LIBXL_VNC_PORT_MAX)))
0)))
goto error; goto error;
/* Allocate bitmap for migration port reservation */ /* Allocate bitmap for migration port reservation */
if (!(libxl_driver->migrationPorts = if (!(libxl_driver->migrationPorts =
virPortAllocatorRangeNew(_("migration"), virPortAllocatorRangeNew(_("migration"),
LIBXL_MIGRATION_PORT_MIN, LIBXL_MIGRATION_PORT_MIN,
LIBXL_MIGRATION_PORT_MAX, 0))) LIBXL_MIGRATION_PORT_MAX)))
goto error; goto error;
if (!(libxl_driver->domains = virDomainObjListNew())) if (!(libxl_driver->domains = virDomainObjListNew()))
......
...@@ -727,22 +727,19 @@ qemuStateInitialize(bool privileged, ...@@ -727,22 +727,19 @@ qemuStateInitialize(bool privileged,
if ((qemu_driver->remotePorts = if ((qemu_driver->remotePorts =
virPortAllocatorRangeNew(_("display"), virPortAllocatorRangeNew(_("display"),
cfg->remotePortMin, cfg->remotePortMin,
cfg->remotePortMax, cfg->remotePortMax)) == NULL)
0)) == NULL)
goto error; goto error;
if ((qemu_driver->webSocketPorts = if ((qemu_driver->webSocketPorts =
virPortAllocatorRangeNew(_("webSocket"), virPortAllocatorRangeNew(_("webSocket"),
cfg->webSocketPortMin, cfg->webSocketPortMin,
cfg->webSocketPortMax, cfg->webSocketPortMax)) == NULL)
0)) == NULL)
goto error; goto error;
if ((qemu_driver->migrationPorts = if ((qemu_driver->migrationPorts =
virPortAllocatorRangeNew(_("migration"), virPortAllocatorRangeNew(_("migration"),
cfg->migrationPortMin, cfg->migrationPortMin,
cfg->migrationPortMax, cfg->migrationPortMax)) == NULL)
0)) == NULL)
goto error; goto error;
if (qemuSecurityInit(qemu_driver) < 0) if (qemuSecurityInit(qemu_driver) < 0)
......
...@@ -47,8 +47,6 @@ struct _virPortAllocatorRange { ...@@ -47,8 +47,6 @@ struct _virPortAllocatorRange {
unsigned short start; unsigned short start;
unsigned short end; unsigned short end;
unsigned int flags;
}; };
static virClassPtr virPortAllocatorClass; static virClassPtr virPortAllocatorClass;
...@@ -99,8 +97,7 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator) ...@@ -99,8 +97,7 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator)
virPortAllocatorRangePtr virPortAllocatorRangePtr
virPortAllocatorRangeNew(const char *name, virPortAllocatorRangeNew(const char *name,
unsigned short start, unsigned short start,
unsigned short end, unsigned short end)
unsigned int flags)
{ {
virPortAllocatorRangePtr range; virPortAllocatorRangePtr range;
...@@ -113,7 +110,6 @@ virPortAllocatorRangeNew(const char *name, ...@@ -113,7 +110,6 @@ virPortAllocatorRangeNew(const char *name,
if (VIR_ALLOC(range) < 0) if (VIR_ALLOC(range) < 0)
return NULL; return NULL;
range->flags = flags;
range->start = start; range->start = start;
range->end = end; range->end = end;
...@@ -237,11 +233,9 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr range, ...@@ -237,11 +233,9 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr range,
if (virBitmapIsBitSet(pa->bitmap, i)) if (virBitmapIsBitSet(pa->bitmap, i))
continue; continue;
if (!(range->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) {
if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 || if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
virPortAllocatorBindToPort(&used, i, AF_INET) < 0) virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
goto cleanup; goto cleanup;
}
if (!used && !v6used) { if (!used && !v6used) {
/* Add port to bitmap of reserved ports */ /* Add port to bitmap of reserved ports */
......
...@@ -28,15 +28,10 @@ ...@@ -28,15 +28,10 @@
typedef struct _virPortAllocatorRange virPortAllocatorRange; typedef struct _virPortAllocatorRange virPortAllocatorRange;
typedef virPortAllocatorRange *virPortAllocatorRangePtr; typedef virPortAllocatorRange *virPortAllocatorRangePtr;
typedef enum {
VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK = (1 << 0),
} virPortAllocatorFlags;
virPortAllocatorRangePtr virPortAllocatorRangePtr
virPortAllocatorRangeNew(const char *name, virPortAllocatorRangeNew(const char *name,
unsigned short start, unsigned short start,
unsigned short end, unsigned short end);
unsigned int flags);
void virPortAllocatorRangeFree(virPortAllocatorRangePtr range); void virPortAllocatorRangeFree(virPortAllocatorRangePtr range);
......
...@@ -53,3 +53,10 @@ int virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED, ...@@ -53,3 +53,10 @@ int virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
{ {
return 0; return 0;
} }
int bind(int sockfd ATTRIBUTE_UNUSED,
const struct sockaddr *addr ATTRIBUTE_UNUSED,
socklen_t addrlen ATTRIBUTE_UNUSED)
{
return 0;
}
...@@ -154,8 +154,7 @@ mymain(void) ...@@ -154,8 +154,7 @@ mymain(void)
if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL) if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
return EXIT_FAILURE; return EXIT_FAILURE;
if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535, if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535)))
VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -74,8 +74,7 @@ testCompareXMLToDomConfig(const char *xmlfile, ...@@ -74,8 +74,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0) if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
goto cleanup; goto cleanup;
if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000, if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000)))
VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
goto cleanup; goto cleanup;
if (!(xmlopt = libxlCreateXMLConf())) if (!(xmlopt = libxlCreateXMLConf()))
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
# include <libxl.h> # include <libxl.h>
# include <xenstore.h> # include <xenstore.h>
# include <xenctrl.h> # include <xenctrl.h>
# include <sys/socket.h>
VIR_MOCK_IMPL_RET_VOID(xs_daemon_open, VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
struct xs_handle *) struct xs_handle *)
...@@ -68,6 +69,12 @@ VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames, ...@@ -68,6 +69,12 @@ VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close, VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
struct xs_handle *, handle) 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, VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
int, ver, int, ver,
const char *, path, const char *, path,
......
...@@ -42,7 +42,7 @@ VIR_LOG_INIT("tests.portallocatortest"); ...@@ -42,7 +42,7 @@ VIR_LOG_INIT("tests.portallocatortest");
static int testAllocAll(const void *args ATTRIBUTE_UNUSED) static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
{ {
virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5909, 0); virPortAllocatorRangePtr ports = virPortAllocatorRangeNew("test", 5900, 5909);
int ret = -1; int ret = -1;
unsigned short p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0; 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) ...@@ -114,7 +114,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
static int testAllocReuse(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; int ret = -1;
unsigned short p1 = 0, p2 = 0, p3 = 0, p4 = 0; unsigned short p1 = 0, p2 = 0, p3 = 0, p4 = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册