[Spice-devel] [RFC PATCH spice 0.8 07/19] server: send SPICE_MSG_MAIN_MIGRATE_END on spice_server_migrate_end

Yonit Halperin yhalperi at redhat.com
Mon Sep 19 02:47:00 PDT 2011


Signed-off-by: Yonit Halperin <yhalperi at redhat.com>
---
 server/reds.c |   79 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 4aa2afb..a0a4924 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -275,6 +275,7 @@ typedef struct RedsState {
     int mig_wait_connect;
     int mig_wait_disconnect;
     int mig_inprogress;
+    int expect_migrate;
     int mig_target;
     RedsMigSpice *mig_spice;
     int num_of_channels;
@@ -4038,13 +4039,21 @@ static void reds_mig_continue(void)
     core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT);
 }
 
-static void reds_mig_started(void)
+static void reds_listen_start(void)
 {
-    red_printf("");
-    ASSERT(reds->mig_spice);
+    ASSERT(reds);
+    if (reds->listen_watch != NULL) {
+        core->watch_update_mask(reds->listen_watch, SPICE_WATCH_EVENT_READ);
+    }
 
-    reds->mig_inprogress = TRUE;
+    if (reds->secure_listen_watch != NULL) {
+        core->watch_update_mask(reds->secure_listen_watch, SPICE_WATCH_EVENT_READ);
+    }
+}
 
+static void reds_listen_stop(void)
+{
+    ASSERT(reds);
     if (reds->listen_watch != NULL) {
         core->watch_update_mask(reds->listen_watch, 0);
     }
@@ -4052,6 +4061,14 @@ static void reds_mig_started(void)
     if (reds->secure_listen_watch != NULL) {
         core->watch_update_mask(reds->secure_listen_watch, 0);
     }
+}
+
+static void reds_mig_started(void)
+{
+    red_printf("");
+    ASSERT(reds->mig_spice);
+
+    reds->mig_inprogress = TRUE;
 
     if (reds->stream == NULL) {
         red_printf("not connected to stream");
@@ -4071,13 +4088,6 @@ static void reds_mig_finished(int completed)
     RedsOutItem *item;
 
     red_printf("");
-    if (reds->listen_watch != NULL) {
-        core->watch_update_mask(reds->listen_watch, SPICE_WATCH_EVENT_READ);
-    }
-
-    if (reds->secure_listen_watch != NULL) {
-        core->watch_update_mask(reds->secure_listen_watch, SPICE_WATCH_EVENT_READ);
-    }
 
     if (reds->stream == NULL) {
         red_printf("no stream connected");
@@ -4086,22 +4096,25 @@ static void reds_mig_finished(int completed)
     reds->mig_inprogress = TRUE;
 
     if (completed) {
+#ifdef SPICE_SEAMLESS_MIGRATION
         Channel *channel;
         SpiceMsgMigrate migrate;
 
-        reds->mig_wait_disconnect = TRUE;
-        core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT);
-
         item = new_out_item(SPICE_MSG_MIGRATE);
         migrate.flags = SPICE_MIGRATE_NEED_FLUSH | SPICE_MIGRATE_NEED_DATA_TRANSFER;
         spice_marshall_msg_migrate(item->m, &migrate);
-
         reds_push_pipe_item(item);
         channel = reds->channels;
         while (channel) {
             channel->migrate(channel);
             channel = channel->next;
         }
+#else
+        item = new_out_item(SPICE_MSG_MAIN_MIGRATE_END);
+        reds_push_pipe_item(item);
+#endif
+        reds->mig_wait_disconnect = TRUE;
+        core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT);
     } else {
         item = new_out_item(SPICE_MSG_MAIN_MIGRATE_CANCEL);
         reds_push_pipe_item(item);
@@ -4116,6 +4129,8 @@ static void reds_mig_switch(void)
     RedsOutItem *item;
 
     if (s == NULL) {
+        red_printf("warning: migration target was not set. disconnecting client");
+        reds_disconnect();
         return;
     }
 
@@ -4928,12 +4943,19 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_info(SpiceServer *s, const char* des
     RedsMigSpice *spice_migration = NULL;
     SpiceMigrateInterface *sif = NULL;
 
+    red_printf("");
     ASSERT(reds == s);
 
     if (migration_interface) {
         sif = SPICE_CONTAINEROF(migration_interface->base.sif, SpiceMigrateInterface, base);
+        if (reds->expect_migrate && reds->client_semi_mig_cap) {
+            red_printf("warning: consecutive calls without migration. Canceling previous call");
+            reds_mig_finished(FALSE);
+        }
+
     }
 
+    reds_mig_release();
     if ((port == -1 && secure_port == -1) || !dest) {
         if (sif) {
             sif->migrate_info_complete(migration_interface);
@@ -4941,6 +4963,7 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_info(SpiceServer *s, const char* des
         return -1;
     }
 
+    reds->expect_migrate = TRUE;
     spice_migration = spice_new0(RedsMigSpice, 1);
     spice_migration->port = port;
     spice_migration->sport = secure_port;
@@ -4949,9 +4972,12 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_info(SpiceServer *s, const char* des
         spice_migration->cert_subject = strdup(cert_subject);
     }
 
-    reds_mig_release();
     reds->mig_spice = spice_migration;
 
+    if (migration_interface) {
+        reds_listen_stop();
+    }
+
     if (migration_interface && reds->client_semi_mig_cap) {
         reds_mig_started();
     } else if (sif) {
@@ -4993,7 +5019,21 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_client_state(SpiceServer *s)
 SPICE_GNUC_VISIBLE int spice_server_migrate_end(SpiceServer *s, int completed)
 {
     ASSERT(reds == s);
-    reds_mig_finished(completed);
+    red_printf("");
+
+    reds_listen_start();
+    if (!reds->expect_migrate && reds->stream) {
+        red_printf("spice_server_migrate_info was not called, disconnecting client");
+        reds_disconnect("");
+        return -1;
+    }
+
+    reds->expect_migrate = FALSE;
+    if (reds->client_semi_mig_cap) {
+        reds_mig_finished(completed);
+    } else {
+        return spice_server_migrate_switch(s);
+    }
     return 0;
 }
 
@@ -5001,6 +5041,11 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_end(SpiceServer *s, int completed)
 SPICE_GNUC_VISIBLE int spice_server_migrate_switch(SpiceServer *s)
 {
     ASSERT(reds == s);
+    red_printf("");
+    if (!reds->stream) {
+       return 0;
+    }
+    reds->expect_migrate = FALSE;
     reds_mig_switch();
     return 0;
 }
-- 
1.7.4.4



More information about the Spice-devel mailing list