[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/4] qemu: allow searching for all open ports



This patch allows to specify a flag 'rotate' saying that the search
for next port should not be limited from the 'startPort' upwards.

This is subsequently used in the search for open SPICE TLS port when
none is specified and TLS is enabled.
---
 src/qemu/qemu_process.c |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c13d203..4af0028 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2422,10 +2422,12 @@ qemuProcessInitPCIAddresses(struct qemud_driver *driver,


 static int qemuProcessNextFreePort(struct qemud_driver *driver,
-                                   int startPort)
+                                   int startPort,
+                                   bool rotate)
 {
     int i;

+ retry:
     for (i = startPort ; i < driver->remotePortMax; i++) {
         int fd;
         int reuse = 1;
@@ -2471,6 +2473,14 @@ static int qemuProcessNextFreePort(struct qemud_driver *driver,
         /* Some other bad failure, get out.. */
         break;
     }
+
+    /* In case we want to search for any open port and the spartPort
+     * parameter is just a preference */
+    if (rotate && startPort != driver->remotePortMin) {
+        startPort = driver->remotePortMin;
+        goto retry;
+    }
+
     return -1;
 }

@@ -3394,9 +3404,9 @@ int qemuProcessStart(virConnectPtr conn,
             vm->def->graphics[0]->data.vnc.autoport) {
             int port;
             if (vm->def->graphics[0]->data.vnc.port > 0)
-                port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.vnc.port);
+                port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.vnc.port, false);
             else
-                port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN);
+                port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN, false);

             if (port < 0) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3408,9 +3418,9 @@ int qemuProcessStart(virConnectPtr conn,
                    vm->def->graphics[0]->data.spice.autoport) {
             int port;
             if (vm->def->graphics[0]->data.spice.port > 0)
-                port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.port);
+                port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.port, false);
             else
-                port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN);
+                port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN, false);

             if (port < 0) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3421,9 +3431,9 @@ int qemuProcessStart(virConnectPtr conn,

             if (driver->spiceTLS) {
                 if (vm->def->graphics[0]->data.spice.tlsPort > 0)
-                    port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.tlsPort);
+                    port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.tlsPort, false);
                 else
-                    port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.port + 1);
+                    port = qemuProcessNextFreePort(driver, vm->def->graphics[0]->data.spice.port + 1, true);
                 if (port < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
                                     "%s", _("Unable to find an unused port for SPICE TLS"));
-- 
1.7.8.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]