[Spice-devel] [spice-gtk v1 5/6] channel-main: migration: set target session info early

Victor Toso victortoso at redhat.com
Tue Sep 24 09:15:01 UTC 2019


From: Victor Toso <me at victortoso.com>

There is no need to wait till migrate_connect() being called to set
information about target host. We create new SpiceSession and can set
related info similar place.

Moved to a utility function.
This is a preparatory patch on refactoring migration code.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/channel-main.c | 56 +++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/channel-main.c b/src/channel-main.c
index 3fe8d64..3dba399 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -2284,8 +2284,6 @@ static gboolean migrate_connect(gpointer data)
 {
     spice_migrate *mig = data;
     SpiceChannelPrivate  *c;
-    int port, sport;
-    const char *host;
 
     g_return_val_if_fail(mig != NULL, FALSE);
     g_return_val_if_fail(mig->info != NULL, FALSE);
@@ -2299,43 +2297,49 @@ static gboolean migrate_connect(gpointer data)
     SpiceMigrationDstInfo *info = mig->info;
     SPICE_DEBUG("migrate_begin %u %s %d %d",
                 info->host_size, info->host_data, info->port, info->sport);
-    port = info->port;
-    sport = info->sport;
-    host = (char*)info->host_data;
+
+    g_signal_connect(mig->session, "channel-new",
+                     G_CALLBACK(migrate_channel_new_cb), mig);
+
+    g_signal_emit(mig->src_channel, signals[SPICE_MIGRATION_STARTED], 0,
+                  mig->session);
+
+    /* the migration process is in 2 steps, first the main channel and
+       then the rest of the channels */
+    migrate_channel_connect(mig, SPICE_CHANNEL_MAIN, 0);
+
+    return FALSE;
+}
+
+static void
+migration_session_set_destination_info(SpiceSession *target_session,
+                                       SpiceMigrationDstInfo *info)
+{
+    const char *host = (const char *) info->host_data;
+
+    if (g_getenv("SPICE_MIG_HOST")) {
+        host = g_getenv("SPICE_MIG_HOST");
+    }
+
+    g_object_set(target_session, "host", host, NULL);
+    spice_session_set_port(target_session, info->port, FALSE);
+    spice_session_set_port(target_session, info->sport, TRUE);
 
     if (info->cert_subject_size == 0 ||
                strlen((const char*)info->cert_subject_data) == 0) {
         /* only verify hostname if no cert subject */
-        g_object_set(mig->session, "verify", SPICE_SESSION_VERIFY_HOSTNAME, NULL);
+        g_object_set(target_session, "verify", SPICE_SESSION_VERIFY_HOSTNAME, NULL);
     } else {
         gchar *subject = g_alloca(info->cert_subject_size + 1);
         strncpy(subject, (const char*)info->cert_subject_data, info->cert_subject_size);
         subject[info->cert_subject_size] = '\0';
 
         // session data are already copied
-        g_object_set(mig->session,
+        g_object_set(target_session,
                      "cert-subject", subject,
                      "verify", SPICE_SESSION_VERIFY_SUBJECT,
                      NULL);
     }
-
-    if (g_getenv("SPICE_MIG_HOST"))
-        host = g_getenv("SPICE_MIG_HOST");
-
-    g_object_set(mig->session, "host", host, NULL);
-    spice_session_set_port(mig->session, port, FALSE);
-    spice_session_set_port(mig->session, sport, TRUE);
-    g_signal_connect(mig->session, "channel-new",
-                     G_CALLBACK(migrate_channel_new_cb), mig);
-
-    g_signal_emit(mig->src_channel, signals[SPICE_MIGRATION_STARTED], 0,
-                  mig->session);
-
-    /* the migration process is in 2 steps, first the main channel and
-       then the rest of the channels */
-    migrate_channel_connect(mig, SPICE_CHANNEL_MAIN, 0);
-
-    return FALSE;
 }
 
 /* coroutine context */
@@ -2363,6 +2367,8 @@ static void main_migrate_connect(SpiceChannel *channel,
         goto end;
     }
 
+    migration_session_set_destination_info(mig.session, dst_info);
+
     main_priv->migrate_data = &mig;
 
     /* no need to track idle, call is sync for this coroutine */
-- 
2.21.0



More information about the Spice-devel mailing list