mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Add a name to virPortAllocator
This allows its error messages to be more specific.
This commit is contained in:
parent
28ea39a004
commit
d16d90fd40
@ -844,7 +844,8 @@ libxlStateInitialize(bool privileged,
|
|||||||
|
|
||||||
/* Allocate bitmap for vnc port reservation */
|
/* Allocate bitmap for vnc port reservation */
|
||||||
if (!(libxl_driver->reservedVNCPorts =
|
if (!(libxl_driver->reservedVNCPorts =
|
||||||
virPortAllocatorNew(LIBXL_VNC_PORT_MIN,
|
virPortAllocatorNew(_("VNC"),
|
||||||
|
LIBXL_VNC_PORT_MIN,
|
||||||
LIBXL_VNC_PORT_MAX)))
|
LIBXL_VNC_PORT_MAX)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -678,17 +678,20 @@ qemuStateInitialize(bool privileged,
|
|||||||
* do this before the config is loaded properly, since the port
|
* do this before the config is loaded properly, since the port
|
||||||
* numbers are configurable now */
|
* numbers are configurable now */
|
||||||
if ((qemu_driver->remotePorts =
|
if ((qemu_driver->remotePorts =
|
||||||
virPortAllocatorNew(cfg->remotePortMin,
|
virPortAllocatorNew(_("display"),
|
||||||
|
cfg->remotePortMin,
|
||||||
cfg->remotePortMax)) == NULL)
|
cfg->remotePortMax)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((qemu_driver->webSocketPorts =
|
if ((qemu_driver->webSocketPorts =
|
||||||
virPortAllocatorNew(cfg->webSocketPortMin,
|
virPortAllocatorNew(_("webSocket"),
|
||||||
|
cfg->webSocketPortMin,
|
||||||
cfg->webSocketPortMax)) == NULL)
|
cfg->webSocketPortMax)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((qemu_driver->migrationPorts =
|
if ((qemu_driver->migrationPorts =
|
||||||
virPortAllocatorNew(cfg->migrationPortMin,
|
virPortAllocatorNew(_("migration"),
|
||||||
|
cfg->migrationPortMin,
|
||||||
cfg->migrationPortMax)) == NULL)
|
cfg->migrationPortMax)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "virthread.h"
|
#include "virthread.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
|
#include "virstring.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ struct _virPortAllocator {
|
|||||||
virObjectLockable parent;
|
virObjectLockable parent;
|
||||||
virBitmapPtr bitmap;
|
virBitmapPtr bitmap;
|
||||||
|
|
||||||
|
char *name;
|
||||||
|
|
||||||
unsigned short start;
|
unsigned short start;
|
||||||
unsigned short end;
|
unsigned short end;
|
||||||
};
|
};
|
||||||
@ -50,6 +53,7 @@ virPortAllocatorDispose(void *obj)
|
|||||||
virPortAllocatorPtr pa = obj;
|
virPortAllocatorPtr pa = obj;
|
||||||
|
|
||||||
virBitmapFree(pa->bitmap);
|
virBitmapFree(pa->bitmap);
|
||||||
|
VIR_FREE(pa->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virPortAllocatorOnceInit(void)
|
static int virPortAllocatorOnceInit(void)
|
||||||
@ -65,7 +69,8 @@ static int virPortAllocatorOnceInit(void)
|
|||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(virPortAllocator)
|
VIR_ONCE_GLOBAL_INIT(virPortAllocator)
|
||||||
|
|
||||||
virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
|
virPortAllocatorPtr virPortAllocatorNew(const char *name,
|
||||||
|
unsigned short start,
|
||||||
unsigned short end)
|
unsigned short end)
|
||||||
{
|
{
|
||||||
virPortAllocatorPtr pa;
|
virPortAllocatorPtr pa;
|
||||||
@ -85,7 +90,8 @@ virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
|
|||||||
pa->start = start;
|
pa->start = start;
|
||||||
pa->end = end;
|
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);
|
virObjectUnref(pa);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
typedef struct _virPortAllocator virPortAllocator;
|
typedef struct _virPortAllocator virPortAllocator;
|
||||||
typedef virPortAllocator *virPortAllocatorPtr;
|
typedef virPortAllocator *virPortAllocatorPtr;
|
||||||
|
|
||||||
virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
|
virPortAllocatorPtr virPortAllocatorNew(const char *name,
|
||||||
|
unsigned short start,
|
||||||
unsigned short end);
|
unsigned short end);
|
||||||
|
|
||||||
int virPortAllocatorAcquire(virPortAllocatorPtr pa,
|
int virPortAllocatorAcquire(virPortAllocatorPtr pa,
|
||||||
|
@ -63,7 +63,7 @@ int bind(int sockfd ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
|
static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
virPortAllocatorPtr alloc = virPortAllocatorNew(5900, 5909);
|
virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned short p1, p2, p3, p4, p5, p6, p7;
|
unsigned short p1, p2, p3, p4, p5, p6, p7;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ cleanup:
|
|||||||
|
|
||||||
static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
|
static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
virPortAllocatorPtr alloc = virPortAllocatorNew(5900, 5910);
|
virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned short p1, p2, p3, p4;
|
unsigned short p1, p2, p3, p4;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user