[PATCH v2 07/11] qemu_migration: Move port allocation to a separate func

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

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]