Whenever virPortAllocatorRelease is called with port == 0, it complains
that the port is not in an allowed range, which is expectable as the
port was never allocated. Let's make virPortAllocatorRelease ignore 0
ports in a similar way free() ignores NULL pointers.
---
src/qemu/qemu_migration.c | 4 ++--
src/qemu/qemu_process.c | 27 +++++++++++----------------
src/util/virportallocator.c | 4 ++++
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 6b488ca..a6b7acb 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1159,7 +1159,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
cleanup:
VIR_FREE(diskAlias);
- if ((ret < 0) && port)
+ if (ret < 0)
virPortAllocatorRelease(driver->remotePorts, port);
return ret;
}
@@ -2448,7 +2448,7 @@ cleanup:
virObjectUnlock(vm);
else
qemuDomainRemoveInactive(driver, vm);
- if (ret < 0 && priv->nbdPort) {
+ if (ret < 0) {
virPortAllocatorRelease(driver->remotePorts, priv->nbdPort);
priv->nbdPort = 0;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 114e885..f8c652f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3368,8 +3368,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
return 0;
error:
- if (port)
- virPortAllocatorRelease(driver->remotePorts, port);
+ virPortAllocatorRelease(driver->remotePorts, port);
return -1;
}
@@ -4093,10 +4092,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
}
}
- if (priv->nbdPort) {
- virPortAllocatorRelease(driver->remotePorts, priv->nbdPort);
- priv->nbdPort = 0;
- }
+ virPortAllocatorRelease(driver->remotePorts, priv->nbdPort);
+ priv->nbdPort = 0;
if (priv->agent) {
qemuAgentClose(priv->agent);
@@ -4217,20 +4214,18 @@ retry:
virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
if (graphics->data.vnc.autoport) {
- ignore_value(virPortAllocatorRelease(driver->remotePorts,
- graphics->data.vnc.port));
- }
- if (graphics->data.vnc.websocket) {
- ignore_value(virPortAllocatorRelease(driver->webSocketPorts,
- graphics->data.vnc.websocket));
+ virPortAllocatorRelease(driver->remotePorts,
+ graphics->data.vnc.port);
}
+ virPortAllocatorRelease(driver->webSocketPorts,
+ graphics->data.vnc.websocket);
}
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
graphics->data.spice.autoport) {
- ignore_value(virPortAllocatorRelease(driver->remotePorts,
- graphics->data.spice.port));
- ignore_value(virPortAllocatorRelease(driver->remotePorts,
- graphics->data.spice.tlsPort));
+ virPortAllocatorRelease(driver->remotePorts,
+ graphics->data.spice.port);
+ virPortAllocatorRelease(driver->remotePorts,
+ graphics->data.spice.tlsPort);
}
}
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index c7be10f..0757966 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -166,6 +166,10 @@ int virPortAllocatorRelease(virPortAllocatorPtr pa,
unsigned short port)
{
int ret = -1;
+
+ if (!port)
+ return 0;
+
virObjectLock(pa);
if (port < pa->start ||
--
1.8.2.1
Show replies by date
On 04.07.2013 21:46, Jiri Denemark wrote:
Whenever virPortAllocatorRelease is called with port == 0, it
complains
that the port is not in an allowed range, which is expectable as the
port was never allocated. Let's make virPortAllocatorRelease ignore 0
ports in a similar way free() ignores NULL pointers.
---
src/qemu/qemu_migration.c | 4 ++--
src/qemu/qemu_process.c | 27 +++++++++++----------------
src/util/virportallocator.c | 4 ++++
3 files changed, 17 insertions(+), 18 deletions(-)
Since making an application to listen on port 0 on Linux is almost
impossible I feel confident enough to give ACK.
Michal
On Fri, Jul 05, 2013 at 09:46:26AM +0200, Michal Privoznik wrote:
On 04.07.2013 21:46, Jiri Denemark wrote:
> Whenever virPortAllocatorRelease is called with port == 0, it complains
> that the port is not in an allowed range, which is expectable as the
> port was never allocated. Let's make virPortAllocatorRelease ignore 0
> ports in a similar way free() ignores NULL pointers.
> ---
> src/qemu/qemu_migration.c | 4 ++--
> src/qemu/qemu_process.c | 27 +++++++++++----------------
> src/util/virportallocator.c | 4 ++++
> 3 files changed, 17 insertions(+), 18 deletions(-)
Since making an application to listen on port 0 on Linux is almost
impossible I feel confident enough to give ACK.
s/almost//
If you specify a port==0 in a listen() call, the kernel will
auto-allocate a random non-zero port for you.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|
On Fri, Jul 05, 2013 at 09:46:26 +0200, Michal Privoznik wrote:
On 04.07.2013 21:46, Jiri Denemark wrote:
> Whenever virPortAllocatorRelease is called with port == 0, it complains
> that the port is not in an allowed range, which is expectable as the
> port was never allocated. Let's make virPortAllocatorRelease ignore 0
> ports in a similar way free() ignores NULL pointers.
> ---
> src/qemu/qemu_migration.c | 4 ++--
> src/qemu/qemu_process.c | 27 +++++++++++----------------
> src/util/virportallocator.c | 4 ++++
> 3 files changed, 17 insertions(+), 18 deletions(-)
Since making an application to listen on port 0 on Linux is almost
impossible I feel confident enough to give ACK.
Pushed, thanks.
Jirka