File f830674b-libxl-release-mig-port.patch of Package libvirt.11696

commit f830674bf320522f50a09759fbc568c9f2f436f1
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Fri Oct 14 11:55:52 2016 -0600

    libxl: fix leaking of allocated migration ports
    
    Although the migration port is immediately released in the
    finish phase of migration, it was never set in the domain
    private object when allocated in the prepare phase. So
    libxlDomainMigrationFinish() always released a 0-initialized
    migrationPort, leaking any allocated port. After enough
    migrations to exhaust the migration port pool, migration would
    fail with
    
    error: internal error: Unable to find an unused port in range
           'migration' (49152-49216)
    
    Fix it by setting libxlDomainObjPrivate->migrationPort to the
    port allocated in the prepare phase. While at it, also fix
    leaking an allocated port if the prepare phase fails.

Index: libvirt-1.2.18.4/src/libxl/libxl_migration.c
===================================================================
--- libvirt-1.2.18.4.orig/src/libxl/libxl_migration.c
+++ libvirt-1.2.18.4/src/libxl/libxl_migration.c
@@ -319,6 +319,7 @@ libxlDomainMigrationPrepare(virConnectPt
     size_t nsocks = 0;
     int nsocks_listen = 0;
     libxlMigrationDstArgs *args = NULL;
+    libxlDomainObjPrivatePtr priv = NULL;
     size_t i;
     int ret = -1;
 
@@ -329,6 +330,7 @@ libxlDomainMigrationPrepare(virConnectPt
                                    NULL)))
         goto error;
     *def = NULL;
+    priv = vm->privateData;
 
     /* Create socket connection to receive migration data */
     if (!uri_in) {
@@ -345,6 +347,7 @@ libxlDomainMigrationPrepare(virConnectPt
         if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
             goto error;
 
+        priv->migrationPort = port;
         if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
             goto error;
     } else {
@@ -379,6 +382,7 @@ libxlDomainMigrationPrepare(virConnectPt
             if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
                 goto error;
 
+            priv->migrationPort = port;
         } else {
             port = uri->port;
         }
@@ -439,6 +443,8 @@ libxlDomainMigrationPrepare(virConnectPt
     }
     VIR_FREE(socks);
     virObjectUnref(args);
+    virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
+    priv->migrationPort = 0;
 
     /* Remove virDomainObj from domain list */
     if (vm) {
openSUSE Build Service is sponsored by