qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 17/23] live migration: Allow cleanup after cancellat


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH 17/23] live migration: Allow cleanup after cancellation or error
Date: Mon, 30 Nov 2009 18:21:21 +0100
User-agent: StGIT/0.14.3

Introduce qemu_savevm_state_cancel and inject a stage -1 to cancel a
live migration. This gives the involved subsystems a chance to clean up
dynamically allocated resources. Namely, the block migration layer can
now free its device descriptors and pending blocks.

Signed-off-by: Jan Kiszka <address@hidden>
---

 block-migration.c |   36 ++++++++++++++++++++++++++++++------
 migration.c       |    1 +
 savevm.c          |   19 +++++++++++++++++--
 sysemu.h          |    1 +
 vl.c              |    5 +++++
 5 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 5997f9b..5274c5e 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -317,11 +317,37 @@ static int is_stage2_completed(void)
     return 1;
 }
 
+static void blk_mig_cleanup(void)
+{
+    BlkMigDevState *bmds, *next_bmds;
+    BlkMigBlock *blk, *next_blk;
+
+    QTAILQ_FOREACH_SAFE(bmds, &block_mig_state.dev_list, entry, next_bmds) {
+        QTAILQ_REMOVE(&block_mig_state.dev_list, bmds, entry);
+        qemu_free(bmds);
+    }
+
+    QTAILQ_FOREACH_SAFE(blk, &block_mig_state.blk_list, entry, next_blk) {
+        QTAILQ_REMOVE(&block_mig_state.blk_list, blk, entry);
+        qemu_free(blk->buf);
+        qemu_free(blk);
+    }
+
+    set_dirty_tracking(0);
+
+    printf("\n");
+}
+
 static int block_save_live(QEMUFile *f, int stage, void *opaque)
 {
     dprintf("Enter save live stage %d submitted %d transferred %d\n",
             stage, block_mig_state.submitted, block_mig_state.transferred);
 
+    if (stage < 0) {
+        blk_mig_cleanup();
+        return 0;
+    }
+
     if (block_mig_state.blk_enable != 1) {
         /* no need to migrate storage */
         qemu_put_be64(f, BLK_MIG_FLAG_EOS);
@@ -338,7 +364,7 @@ static int block_save_live(QEMUFile *f, int stage, void 
*opaque)
     flush_blks(f);
 
     if (qemu_file_has_error(f)) {
-        set_dirty_tracking(0);
+        blk_mig_cleanup();
         return 0;
     }
 
@@ -355,7 +381,7 @@ static int block_save_live(QEMUFile *f, int stage, void 
*opaque)
     flush_blks(f);
 
     if (qemu_file_has_error(f)) {
-        set_dirty_tracking(0);
+        blk_mig_cleanup();
         return 0;
     }
 
@@ -365,15 +391,13 @@ static int block_save_live(QEMUFile *f, int stage, void 
*opaque)
         }
 
         blk_mig_save_dirty_blocks(f);
-
-        /* stop track dirty blocks */
-        set_dirty_tracking(0);
+        blk_mig_cleanup();
 
         if (qemu_file_has_error(f)) {
             return 0;
         }
 
-        printf("\nBlock migration completed\n");
+        printf("Block migration completed\n");
     }
 
     qemu_put_be64(f, BLK_MIG_FLAG_EOS);
diff --git a/migration.c b/migration.c
index d7fb756..f8a15fb 100644
--- a/migration.c
+++ b/migration.c
@@ -324,6 +324,7 @@ void migrate_fd_cancel(MigrationState *mig_state)
     dprintf("cancelling migration\n");
 
     s->state = MIG_STATE_CANCELLED;
+    qemu_savevm_state_cancel(s->file);
 
     migrate_fd_cleanup(s);
 }
diff --git a/savevm.c b/savevm.c
index 4668843..70f8578 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1271,8 +1271,10 @@ int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, 
int shared)
         se->save_live_state(f, QEMU_VM_SECTION_START, se->opaque);
     }
 
-    if (qemu_file_has_error(f))
+    if (qemu_file_has_error(f)) {
+        qemu_savevm_state_cancel(f);
         return -EIO;
+    }
 
     return 0;
 }
@@ -1296,8 +1298,10 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     if (ret)
         return 1;
 
-    if (qemu_file_has_error(f))
+    if (qemu_file_has_error(f)) {
+        qemu_savevm_state_cancel(f);
         return -EIO;
+    }
 
     return 0;
 }
@@ -1346,6 +1350,17 @@ int qemu_savevm_state_complete(QEMUFile *f)
     return 0;
 }
 
+void qemu_savevm_state_cancel(QEMUFile *f)
+{
+    SaveStateEntry *se;
+
+    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+        if (se->save_live_state) {
+            se->save_live_state(f, -1, se->opaque);
+        }
+    }
+}
+
 int qemu_savevm_state(QEMUFile *f)
 {
     int saved_vm_running;
diff --git a/sysemu.h b/sysemu.h
index b1887ef..907a344 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -64,6 +64,7 @@ void main_loop_wait(int timeout);
 int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared);
 int qemu_savevm_state_iterate(QEMUFile *f);
 int qemu_savevm_state_complete(QEMUFile *f);
+void qemu_savevm_state_cancel(QEMUFile *f);
 int qemu_savevm_state(QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
diff --git a/vl.c b/vl.c
index 64426aa..5cc75a4 100644
--- a/vl.c
+++ b/vl.c
@@ -2935,6 +2935,11 @@ static int ram_save_live(QEMUFile *f, int stage, void 
*opaque)
     double bwidth = 0;
     uint64_t expected_time = 0;
 
+    if (stage < 0) {
+        cpu_physical_memory_set_dirty_tracking(0);
+        return 0;
+    }
+
     if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
         qemu_file_set_error(f);
         return 0;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]