From: Jim Fehlig <jfehlig@suse.com>
To: libvir-list@redhat.com
Cc: Jim Fehlig <jfehlig@suse.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
xen-devel@lists.xen.org
Subject: [PATCH V3 2/5] util: Allow port allocator to skip bind() check
Date: Wed, 3 Sep 2014 21:07:36 -0600 [thread overview]
Message-ID: <1409800059-16884-3-git-send-email-jfehlig@suse.com> (raw)
In-Reply-To: <1409800059-16884-1-git-send-email-jfehlig@suse.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Test suites using the port allocator don't want to have different
behaviour depending on whether a port is in use on the host. Add
a VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK which test suites can use
to skip the bind() test. The port allocator will thus only track
ports in use by the test suite process itself. This is fine when
using the port allocator to generate guest configs which won't
actually be launched
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
src/libxl/libxl_driver.c | 5 +++--
src/qemu/qemu_driver.c | 9 ++++++---
src/util/virportallocator.c | 14 ++++++++++----
src/util/virportallocator.h | 7 ++++++-
tests/virportallocatortest.c | 4 ++--
5 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 67fd7bc6..17d6257 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -301,14 +301,15 @@ libxlStateInitialize(bool privileged,
if (!(libxl_driver->reservedVNCPorts =
virPortAllocatorNew(_("VNC"),
LIBXL_VNC_PORT_MIN,
- LIBXL_VNC_PORT_MAX)))
+ LIBXL_VNC_PORT_MAX,
+ 0)))
goto error;
/* Allocate bitmap for migration port reservation */
if (!(libxl_driver->migrationPorts =
virPortAllocatorNew(_("migration"),
LIBXL_MIGRATION_PORT_MIN,
- LIBXL_MIGRATION_PORT_MAX)))
+ LIBXL_MIGRATION_PORT_MAX, 0)))
goto error;
if (!(libxl_driver->domains = virDomainObjListNew()))
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 239a300..6b4dbf3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -731,19 +731,22 @@ qemuStateInitialize(bool privileged,
if ((qemu_driver->remotePorts =
virPortAllocatorNew(_("display"),
cfg->remotePortMin,
- cfg->remotePortMax)) == NULL)
+ cfg->remotePortMax,
+ 0)) == NULL)
goto error;
if ((qemu_driver->webSocketPorts =
virPortAllocatorNew(_("webSocket"),
cfg->webSocketPortMin,
- cfg->webSocketPortMax)) == NULL)
+ cfg->webSocketPortMax,
+ 0)) == NULL)
goto error;
if ((qemu_driver->migrationPorts =
virPortAllocatorNew(_("migration"),
cfg->migrationPortMin,
- cfg->migrationPortMax)) == NULL)
+ cfg->migrationPortMax,
+ 0)) == NULL)
goto error;
if (qemuSecurityInit(qemu_driver) < 0)
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index ff5691a..d40c6b1 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -43,6 +43,8 @@ struct _virPortAllocator {
unsigned short start;
unsigned short end;
+
+ unsigned int flags;
};
static virClassPtr virPortAllocatorClass;
@@ -71,7 +73,8 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator)
virPortAllocatorPtr virPortAllocatorNew(const char *name,
unsigned short start,
- unsigned short end)
+ unsigned short end,
+ unsigned int flags)
{
virPortAllocatorPtr pa;
@@ -87,6 +90,7 @@ virPortAllocatorPtr virPortAllocatorNew(const char *name,
if (!(pa = virObjectLockableNew(virPortAllocatorClass)))
return NULL;
+ pa->flags = flags;
pa->start = start;
pa->end = end;
@@ -193,9 +197,11 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
if (used)
continue;
- if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
- virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
- goto cleanup;
+ if (!(pa->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) {
+ 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 e5ee56d..14c3b24 100644
--- a/src/util/virportallocator.h
+++ b/src/util/virportallocator.h
@@ -28,9 +28,14 @@
typedef struct _virPortAllocator virPortAllocator;
typedef virPortAllocator *virPortAllocatorPtr;
+typedef enum {
+ VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK = (1 << 0),
+} virPortAllocatorFlags;
+
virPortAllocatorPtr virPortAllocatorNew(const char *name,
unsigned short start,
- unsigned short end);
+ unsigned short end,
+ unsigned int flags);
int virPortAllocatorAcquire(virPortAllocatorPtr pa,
unsigned short *port);
diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index 48d2c9a..96d2ade 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -122,7 +122,7 @@ VIR_LOG_INIT("tests.portallocatortest");
static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
{
- virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909);
+ virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909, 0);
int ret = -1;
unsigned short p1, p2, p3, p4, p5, p6, p7;
@@ -193,7 +193,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
{
- virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910);
+ virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910, 0);
int ret = -1;
unsigned short p1, p2, p3, p4;
--
1.8.4.5
next prev parent reply other threads:[~2014-09-04 3:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-04 3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
2014-09-04 3:07 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Jim Fehlig
2014-09-04 3:07 ` Jim Fehlig [this message]
2014-09-11 10:46 ` [PATCH V3 2/5] util: Allow port allocator to skip bind() check Daniel P. Berrange
2014-09-04 3:07 ` [PATCH V3 3/5] tests: Add more test suite mock helpers Jim Fehlig
2014-09-11 10:46 ` Daniel P. Berrange
2014-09-04 3:07 ` [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Jim Fehlig
2014-09-04 3:07 ` [PATCH V3 5/5] libxl: Add a test suite for libxl option generator Jim Fehlig
2014-09-11 10:58 ` Daniel P. Berrange
[not found] ` <20140911105842.GE7035@redhat.com>
2014-09-11 22:01 ` Jim Fehlig
[not found] ` <1409800059-16884-2-git-send-email-jfehlig@suse.com>
2014-09-11 10:45 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Daniel P. Berrange
[not found] ` <20140911104519.GA7035@redhat.com>
2014-09-11 21:57 ` Jim Fehlig
[not found] ` <1409800059-16884-5-git-send-email-jfehlig@suse.com>
2014-09-11 10:47 ` [libvirt] [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Daniel P. Berrange
[not found] ` <20140911104716.GD7035@redhat.com>
2014-09-11 21:56 ` Jim Fehlig
2014-09-11 21:59 ` Jim Fehlig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409800059-16884-3-git-send-email-jfehlig@suse.com \
--to=jfehlig@suse.com \
--cc=berrange@redhat.com \
--cc=libvir-list@redhat.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).