[libvirt] [PATCH] qemu: Return SPICE ports on domain shutdown

Commit ed0d9f6c0cdd56f38ce31b8d9b5293162addaa23 added support for automatic port allocation for SPICE but forgot to mark such ports as unused when they are not used anymore. --- src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1a26a50..1de6f4a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2491,6 +2491,19 @@ static int qemudNextFreePort(struct qemud_driver *driver, } +static void +qemudReturnPort(struct qemud_driver *driver, + int port) +{ + if (port < QEMU_VNC_PORT_MIN) + return; + + if (virBitmapClearBit(driver->reservedVNCPorts, + port - QEMU_VNC_PORT_MIN) < 0) + VIR_DEBUG("Could not mark port %d as unused", port); +} + + static int qemuAssignPCIAddresses(virDomainDefPtr def) { @@ -2696,6 +2709,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, if (tlsPort < 0) { qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find an unused SPICE TLS port")); + qemudReturnPort(driver, port); goto cleanup; } } @@ -3099,14 +3113,14 @@ retry: */ if ((vm->def->ngraphics == 1) && vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC && - vm->def->graphics[0]->data.vnc.autoport && - vm->def->graphics[0]->data.vnc.port >= QEMU_VNC_PORT_MIN) { - if (virBitmapClearBit(driver->reservedVNCPorts, - vm->def->graphics[0]->data.vnc.port - \ - QEMU_VNC_PORT_MIN) < 0) { - VIR_DEBUG("virBitmapClearBit failed on bit %d", - vm->def->graphics[0]->data.vnc.port - QEMU_VNC_PORT_MIN); - } + vm->def->graphics[0]->data.vnc.autoport) { + qemudReturnPort(driver, vm->def->graphics[0]->data.vnc.port); + } + if ((vm->def->ngraphics == 1) && + vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE && + vm->def->graphics[0]->data.spice.autoport) { + qemudReturnPort(driver, vm->def->graphics[0]->data.spice.port); + qemudReturnPort(driver, vm->def->graphics[0]->data.spice.tlsPort); } vm->pid = -1; -- 1.7.3.4

On 23/12/2010, at 12:42 AM, Jiri Denemark wrote:
Commit ed0d9f6c0cdd56f38ce31b8d9b5293162addaa23 added support for automatic port allocation for SPICE but forgot to mark such ports as unused when they are not used anymore.
From memory, they needed updating to understand the libvirt TLS ports,
Out of curiosity, any idea if the Red Hat "system-config-firewall" or "system-config-firewall-tui" utils need any kind of updating for SPICE? though I'm not sure if the same kind of scenario applies. Any ideas? Regards and best wishes, Justin Clift

Commit ed0d9f6c0cdd56f38ce31b8d9b5293162addaa23 added support for automatic port allocation for SPICE but forgot to mark such ports as unused when they are not used anymore.
Out of curiosity, any idea if the Red Hat "system-config-firewall" or "system-config-firewall-tui" utils need any kind of updating for SPICE?
Heh, I guess they don't need any update. As far as automatic ports are concerned SPICE is handled in the same way as VNC, which has been supported for a long time now. So I guess the tools should already count with this scenario if the need to. In any case, one can always use one's favorite editor to edit the firewall configuration files :-) Jirka

On 12/22/2010 06:42 AM, Jiri Denemark wrote:
Commit ed0d9f6c0cdd56f38ce31b8d9b5293162addaa23 added support for automatic port allocation for SPICE but forgot to mark such ports as unused when they are not used anymore. --- src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1a26a50..1de6f4a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2491,6 +2491,19 @@ static int qemudNextFreePort(struct qemud_driver *driver, }
+static void +qemudReturnPort(struct qemud_driver *driver, + int port)
As part of the qemu refactoring, we've been doing s/qemud/qemu/ for internal function names. ACK with that change. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1a26a50..1de6f4a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2491,6 +2491,19 @@ static int qemudNextFreePort(struct qemud_driver *driver, }
+static void +qemudReturnPort(struct qemud_driver *driver, + int port)
As part of the qemu refactoring, we've been doing s/qemud/qemu/ for internal function names.
I noticed but wanted to be consistent with the unchanged qemudNextFreePort :-) I think we will need a mass renaming patch for the functions which were not renamed.
ACK with that change.
Thanks. I made that change and pushed. Jirka
participants (3)
-
Eric Blake
-
Jiri Denemark
-
Justin Clift