[PATCH] libxl: Release auto-allocated spice ports

Jim Fehlig posted 1 patch 2 years, 2 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220207210624.6096-1-jfehlig@suse.com
src/libxl/libxl_domain.c | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
[PATCH] libxl: Release auto-allocated spice ports
Posted by Jim Fehlig 2 years, 2 months ago
While VNC ports auto-allocated by the libxl driver are released in
libxlDomainCleanup, spice ports are overlooked. Rework the existing
logic to release any auto-allocated graphics ports, not just the VNC
port of the first graphics device.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_domain.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 577985b5ea..b995f20a64 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -906,10 +906,10 @@ libxlDomainCleanup(libxlDriverPrivate *driver,
 {
     libxlDomainObjPrivate *priv = vm->privateData;
     g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
-    int vnc_port;
     char *file;
     virHostdevManager *hostdev_mgr = driver->hostdevMgr;
     unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
+    size_t i;
 
     VIR_DEBUG("Cleaning up domain with id '%d' and name '%s'",
               vm->def->id, vm->def->name);
@@ -944,13 +944,31 @@ libxlDomainCleanup(libxlDriverPrivate *driver,
     if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCallback)
         driver->inhibitCallback(false, driver->inhibitOpaque);
 
-    if ((vm->def->ngraphics == 1) &&
-        vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-        vm->def->graphics[0]->data.vnc.autoport) {
-        vnc_port = vm->def->graphics[0]->data.vnc.port;
-        if (vnc_port >= LIBXL_VNC_PORT_MIN) {
-            if (virPortAllocatorRelease(vnc_port) < 0)
-                VIR_DEBUG("Could not mark port %d as unused", vnc_port);
+    /* Release auto-allocated graphics ports */
+    for (i = 0; i < vm->def->ngraphics; i++) {
+        virDomainGraphicsDef *graphics = vm->def->graphics[i];
+        int gport = -1;
+
+        switch (graphics->type) {
+        case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+            if (graphics->data.vnc.autoport &&
+                graphics->data.vnc.port >= LIBXL_VNC_PORT_MIN)
+                gport = graphics->data.vnc.port;
+            break;
+        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+            if (graphics->data.spice.autoport)
+                gport = graphics->data.spice.port;
+            break;
+        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
+        case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
+        case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+        case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+        case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
+            break;
+        }
+        if (gport != -1) {
+            if (virPortAllocatorRelease(gport) < 0)
+                VIR_DEBUG("Could not mark port %d as unused", gport);
         }
     }
 
-- 
2.34.1


Re: [PATCH] libxl: Release auto-allocated spice ports
Posted by Ján Tomko 2 years, 2 months ago
On a Monday in 2022, Jim Fehlig wrote:
>While VNC ports auto-allocated by the libxl driver are released in
>libxlDomainCleanup, spice ports are overlooked. Rework the existing
>logic to release any auto-allocated graphics ports, not just the VNC
>port of the first graphics device.
>
>Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>---
> src/libxl/libxl_domain.c | 34 ++++++++++++++++++++++++++--------
> 1 file changed, 26 insertions(+), 8 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano