]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Return -1 in virPortAllocatorAcquire if all ports are used
authorJán Tomko <jtomko@redhat.com>
Thu, 31 Oct 2013 11:49:04 +0000 (12:49 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 18 Nov 2013 11:28:07 +0000 (12:28 +0100)
Report the error in virPortAllocatorAcquire instead
of doing it in every caller.

The error contains the port range name instead of the intended
use for the port, e.g.:
Unable to find an unused port in range 'display' (65534-65535)
instead of:
Unable to find an unused port for SPICE

This also adds error reporting when the QEMU driver could not
find an unused port for VNC, VNC WebSockets or NBD migration.

src/libxl/libxl_conf.c
src/qemu/qemu_migration.c
src/qemu/qemu_process.c
src/util/virportallocator.c
tests/virportallocatortest.c

index 79cf2b6cf714501a537ff53fc4b014bb5423f9db..aaeb00e992c69b6f0b1f1d62ac5a5044c6fb9d40 100644 (file)
@@ -950,11 +950,6 @@ libxlMakeVfb(libxlDriverPrivatePtr driver,
 
                 if (virPortAllocatorAcquire(driver->reservedVNCPorts, &port) < 0)
                     return -1;
-                if (port == 0) {
-                    virReportError(VIR_ERR_INTERNAL_ERROR,
-                                   "%s", _("Unable to find an unused VNC port"));
-                    return -1;
-                }
                 l_vfb->data.vnc.port = port;
             }
             x_vfb->vnc.display = l_vfb->data.vnc.port - LIBXL_VNC_PORT_MIN;
index 4b5fdba585bd6373aa6583f34c5d0400a574eed8..e87ea8533431ab76b65d28adcdda73627d5be7db 100644 (file)
@@ -2561,14 +2561,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
      * to be a correct hostname which refers to the target machine).
      */
     if (uri_in == NULL) {
-        if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0) {
+        if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
             goto cleanup;
-        } else if (!port) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("No migration port available within the "
-                             "configured range"));
-            goto cleanup;
-        }
 
         if ((hostname = virGetHostname()) == NULL)
             goto cleanup;
@@ -2623,14 +2617,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
         }
 
         if (uri->port == 0) {
-            if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0) {
+            if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
                 goto cleanup;
-            } else if (!port) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("No migration port available within the "
-                                 "configured range"));
-                goto cleanup;
-            }
 
             if (well_formed_uri) {
                 uri->port = port;
index 22a89a40a21e0dcb365ee9c32eeb4ba5f3197054..a26c079de78ad59c253362426479abb09acb507c 100644 (file)
@@ -3397,12 +3397,6 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
         if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
             goto error;
 
-        if (port == 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Unable to find an unused port for SPICE"));
-            goto error;
-        }
-
         graphics->data.spice.port = port;
     }
 
@@ -3428,11 +3422,6 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
             if (virPortAllocatorAcquire(driver->remotePorts, &tlsPort) < 0)
                 goto error;
 
-            if (tlsPort == 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("Unable to find an unused port for SPICE TLS"));
-                goto error;
-            }
             graphics->data.spice.tlsPort = tlsPort;
         }
     }
index e653e8c9207bfa4ddd09b1ee76cf668be3057fe3..694f1916f4bda604204f77f06caa337ab282ce88 100644 (file)
@@ -157,10 +157,15 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
                 goto cleanup;
             }
             *port = i;
+            ret = 0;
         }
     }
 
-    ret = 0;
+    if (*port == 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to find an unused port in range '%s' (%d-%d)"),
+                       pa->name, pa->start, pa->end);
+    }
 cleanup:
     virObjectUnlock(pa);
     VIR_FORCE_CLOSE(fd);
index 33de78204c960d370f428a465a0f7901ace8af7c..721356e9d6843ee0417da039232143617224395d 100644 (file)
@@ -118,11 +118,9 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    if (virPortAllocatorAcquire(alloc, &p7) < 0)
-        goto cleanup;
-    if (p7 != 0) {
+    if (virPortAllocatorAcquire(alloc, &p7) == 0) {
         if (virTestGetDebug())
-            fprintf(stderr, "Expected 0, got %d", p7);
+            fprintf(stderr, "Expected error, got %d", p7);
         goto cleanup;
     }