There's a code snippet which allocates a port for incoming
migration. We will need this for allocating a port for
incoming disks as well. Hence, move this snippet into
a separate function called qemuMigrationNextPort().
---
src/qemu/qemu_migration.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d785e75..9ad3ee7 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1078,6 +1078,17 @@ error:
return NULL;
}
+static int
+qemuMigrationNextPort(void) {
+ static int port = 0;
+ int ret = QEMUD_MIGRATION_FIRST_PORT + port++;
+
+ if (port == QEMUD_MIGRATION_NUM_PORTS)
+ port = 0;
+
+ return ret;
+}
+
/**
* qemuMigrationStartNBDServer:
* @driver: qemu driver
@@ -1866,7 +1877,6 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
const char *dom_xml,
unsigned long flags)
{
- static int port = 0;
int this_port;
char *hostname = NULL;
char migrateFrom [64];
@@ -1891,8 +1901,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
* to be a correct hostname which refers to the target machine).
*/
if (uri_in == NULL) {
- this_port = QEMUD_MIGRATION_FIRST_PORT + port++;
- if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
+ this_port = qemuMigrationNextPort();
/* Get hostname */
if ((hostname = virGetHostname(NULL)) == NULL)
@@ -1931,9 +1940,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
p = strrchr(uri_in, ':');
if (p == strchr(uri_in, ':')) {
/* Generate a port */
- this_port = QEMUD_MIGRATION_FIRST_PORT + port++;
- if (port == QEMUD_MIGRATION_NUM_PORTS)
- port = 0;
+ this_port = qemuMigrationNextPort();
/* Caller frees */
if (virAsprintf(uri_out, "%s:%d", uri_in, this_port) < 0) {
--
1.7.8.6