[libvirt] [PATCH 1/2] Add a name to virPortAllocator

Ján Tomko jtomko at redhat.com
Thu Oct 31 12:07:26 UTC 2013


This allows its error messages to be more specific.
---
 src/libxl/libxl_driver.c     | 3 ++-
 src/qemu/qemu_driver.c       | 9 ++++++---
 src/util/virportallocator.c  | 9 +++++++--
 src/util/virportallocator.h  | 3 ++-
 tests/virportallocatortest.c | 4 ++--
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 4928695..a166689 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -834,7 +834,8 @@ libxlStateInitialize(bool privileged,
 
     /* Allocate bitmap for vnc port reservation */
     if (!(libxl_driver->reservedVNCPorts =
-          virPortAllocatorNew(LIBXL_VNC_PORT_MIN,
+          virPortAllocatorNew("VNC",
+                              LIBXL_VNC_PORT_MIN,
                               LIBXL_VNC_PORT_MAX)))
         goto error;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9c3daad..9dc887f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -678,17 +678,20 @@ qemuStateInitialize(bool privileged,
      * do this before the config is loaded properly, since the port
      * numbers are configurable now */
     if ((qemu_driver->remotePorts =
-         virPortAllocatorNew(cfg->remotePortMin,
+         virPortAllocatorNew("display",
+                             cfg->remotePortMin,
                              cfg->remotePortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->webSocketPorts =
-         virPortAllocatorNew(cfg->webSocketPortMin,
+         virPortAllocatorNew("webSocket",
+                             cfg->webSocketPortMin,
                              cfg->webSocketPortMax)) == NULL)
         goto error;
 
     if ((qemu_driver->migrationPorts =
-         virPortAllocatorNew(cfg->migrationPortMin,
+         virPortAllocatorNew("migration",
+                             cfg->migrationPortMin,
                              cfg->migrationPortMax)) == NULL)
         goto error;
 
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index 5b7ad41..0497978 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -31,6 +31,7 @@
 #include "virthread.h"
 #include "virerror.h"
 #include "virfile.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -38,6 +39,8 @@ struct _virPortAllocator {
     virObjectLockable parent;
     virBitmapPtr bitmap;
 
+    char *name;
+
     unsigned short start;
     unsigned short end;
 };
@@ -65,7 +68,8 @@ static int virPortAllocatorOnceInit(void)
 
 VIR_ONCE_GLOBAL_INIT(virPortAllocator)
 
-virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
+virPortAllocatorPtr virPortAllocatorNew(const char *name,
+                                        unsigned short start,
                                         unsigned short end)
 {
     virPortAllocatorPtr pa;
@@ -85,7 +89,8 @@ virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
     pa->start = start;
     pa->end = end;
 
-    if (!(pa->bitmap = virBitmapNew((end-start)+1))) {
+    if (!(pa->bitmap = virBitmapNew((end-start)+1)) ||
+        VIR_STRDUP(pa->name, name) < 0) {
         virObjectUnref(pa);
         return NULL;
     }
diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h
index a5e68f7..c8aa6de 100644
--- a/src/util/virportallocator.h
+++ b/src/util/virportallocator.h
@@ -28,7 +28,8 @@
 typedef struct _virPortAllocator virPortAllocator;
 typedef virPortAllocator *virPortAllocatorPtr;
 
-virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
+virPortAllocatorPtr virPortAllocatorNew(const char *name,
+                                        unsigned short start,
                                         unsigned short end);
 
 int virPortAllocatorAcquire(virPortAllocatorPtr pa,
diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index 4d0518a..33de782 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -63,7 +63,7 @@ int bind(int sockfd ATTRIBUTE_UNUSED,
 
 static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorPtr alloc = virPortAllocatorNew(5900, 5909);
+    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909);
     int ret = -1;
     unsigned short p1, p2, p3, p4, p5, p6, p7;
 
@@ -136,7 +136,7 @@ cleanup:
 
 static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorPtr alloc = virPortAllocatorNew(5900, 5910);
+    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910);
     int ret = -1;
     unsigned short p1, p2, p3, p4;
 
-- 
1.8.1.5




More information about the libvir-list mailing list