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 654cb51..097d73a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2450,10 +2450,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;
@@ -2499,6 +2501,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 startPort
+ * parameter is just a preference */
+ if (rotate && startPort != driver->remotePortMin) {
+ startPort = driver->remotePortMin;
+ goto retry;
+ }
+
return -1;
}
@@ -3419,9 +3429,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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3434,9 +3444,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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3447,9 +3457,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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to find an unused port
for SPICE TLS"));
--
1.7.8.6