[PATCH v2.1 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 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 81a48a4..5a716fd 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
@@ -1929,7 +1940,6 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
                            const char *dom_xml,
                            unsigned long flags)
 {
-    static int port = 0;
     int this_port;
     char *hostname = NULL;
     char migrateFrom [64];
@@ -1954,8 +1964,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)
@@ -1994,9 +2003,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.8.0.2

--
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]