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

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



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 7e86c33..7a2d0a2 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1074,6 +1074,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
@@ -1857,7 +1868,6 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
                            const char *dom_xml,
                            unsigned long flags)
 {
-    static int port = 0;
     int this_port;
     char *hostname = NULL;
     char migrateFrom [64];
@@ -1882,8 +1892,7 @@ qemuMigrationPrepareDirect(struct qemud_driver *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)
@@ -1922,9 +1931,7 @@ qemuMigrationPrepareDirect(struct qemud_driver *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


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