diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2009-11-30 18:21:21 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-12-03 10:48:53 -0600 |
commit | 4ec7fcc7da214d48d39b63fd2c6a4d19ac42ae04 (patch) | |
tree | 5bb2081c5fbf6349a8241e715a0cece055105e72 | |
parent | 9a743e5ba32f7a620baa0b3d3808e88d2433e861 (diff) |
live migration: Allow cleanup after cancellation or error
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 <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | block-migration.c | 36 | ||||
-rw-r--r-- | migration.c | 1 | ||||
-rw-r--r-- | savevm.c | 19 | ||||
-rw-r--r-- | sysemu.h | 1 | ||||
-rw-r--r-- | vl.c | 5 |
5 files changed, 54 insertions, 8 deletions
diff --git a/block-migration.c b/block-migration.c index 5997f9bc6b..5274c5ec37 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 d7fb75676e..f8a15fb485 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); } @@ -1299,8 +1299,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; } @@ -1324,8 +1326,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; } @@ -1374,6 +1378,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; @@ -65,6 +65,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); @@ -2934,6 +2934,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; |