提交 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,
goto cleanup;
if (!(bhyve_driver->remotePorts = virPortAllocatorRangeNew(_("display"),
5900, 65535, 0)))
5900, 65535)))
goto cleanup;
bhyve_driver->hostsysinfo = virSysinfoRead();
......
......@@ -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()))
......
......@@ -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)
......
......@@ -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 */
......
......@@ -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);
......
......@@ -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;
}
......@@ -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;
......
......@@ -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()))
......
......@@ -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,
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册