From de5f3b88fb0023ed2e76db2fe5c28effab398804 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 3 Aug 2010 13:02:15 -0300
Subject: [PATCH 1/3] Fix migration with spice enabled.

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1280840535-14453-1-git-send-email-kraxel@redhat.com>
Patchwork-id: 11156
O-Subject: [RHEL-6 kvm PATCH] Fix migration with spice enabled.
Bugzilla: 618168
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

spice hooks into migrate_fd_cleanup() to tell the spice server that
the migration is finished and whenever it was successful or not.

commit 911f1e1368db72694a6590cf8a70c7efb29a899c changes the ordering
of setting FdMigrationState->state and calling migrate_fd_cleanup(),
which trips up spice because it can't figure whenever the migration
worked or not.

This patch restores the old ordering.  It also moves the
FdMigrationState->state update for the close() failure case into the
migrate_fd_cleanup() function, so spice will see those failures too.

bugzilla: #618168
upstream: n/a

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 migration.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 migration.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/migration.c b/migration.c
index 1dbb1d5..137bacf 100644
--- a/migration.c
+++ b/migration.c
@@ -290,6 +290,7 @@ int migrate_fd_cleanup(FdMigrationState *s)
         dprintf("closing file\n");
         if (qemu_fclose(s->file) != 0) {
             ret = -1;
+            s->state = MIG_STATE_ERROR;
         }
         s->file = NULL;
     }
@@ -400,13 +401,12 @@ void migrate_fd_put_ready(void *opaque)
         } else {
             state = MIG_STATE_COMPLETED;
         }
+        s->state = state;
         if (migrate_fd_cleanup(s) < 0) {
             if (old_vm_running) {
                 vm_start();
             }
-            state = MIG_STATE_ERROR;
         }
-        s->state = state;
     }
 }
 
-- 
1.7.2.1

