From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/3] move vm stop/start to migrate_set_state
Date: Thu, 9 Jul 2009 13:47:38 +0200 [thread overview]
Message-ID: <1247140059-5034-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1247140059-5034-1-git-send-email-pbonzini@redhat.com>
With this patch, the state machine grows a new state, COMPLETING.
This new state corresponds to the VM being stopped while migration
is finalized. Stopping and starting the machine is driven
exclusively by the state machine mechanisms.
Two rare bugs are fixed. The first is a race; the VM used to remain
stopped if a migration was canceled exactly in what corresponds
to the new COMPLETING state. A bit worse is that if an error occurred
exactly during the final stage (for example due to disk full)
the VM was unconditionally restarted, even if it was paused before
the beginning of the migration.
---
migration.c | 36 +++++++++++++++++++++++++-----------
migration.h | 2 ++
2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/migration.c b/migration.c
index 5abce0c..96585dd 100644
--- a/migration.c
+++ b/migration.c
@@ -150,6 +150,11 @@ void do_info_migrate(Monitor *mon)
monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", ram_bytes_remaining() >> 10);
monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", ram_bytes_total() >> 10);
break;
+ case MIG_STATE_COMPLETING:
+ monitor_printf(mon, "completing\n");
+ monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", ram_bytes_transferred() >> 10);
+ monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", ram_bytes_total() >> 10);
+ break;
case MIG_STATE_COMPLETED:
monitor_printf(mon, "completed\n");
break;
@@ -267,18 +272,13 @@ void migrate_fd_put_ready(void *opaque)
dprintf("iterate\n");
if (qemu_savevm_state_iterate(s->file) == 1) {
- int state;
dprintf("done iterating\n");
- vm_stop(0);
- bdrv_flush_all();
- if ((qemu_savevm_state_complete(s->file)) < 0) {
- vm_start();
- state = MIG_STATE_ERROR;
- } else {
- state = MIG_STATE_COMPLETED;
- }
- migrate_set_state(&s->mig_state, state);
+ migrate_set_state(&s->mig_state, MIG_STATE_COMPLETING);
+ if ((qemu_savevm_state_complete(s->file)) < 0)
+ migrate_set_state(&s->mig_state, MIG_STATE_ERROR);
+ else
+ migrate_set_state(&s->mig_state, MIG_STATE_COMPLETED);
}
}
@@ -286,11 +286,25 @@ void migrate_set_state(MigrationState *s, int state)
{
s->state = state;
- if (state != MIG_STATE_ACTIVE) {
+ switch (state) {
+ case MIG_STATE_COMPLETING:
+ s->save_vm_running = vm_running;
+ vm_stop(0);
+ bdrv_flush_all();
+ break;
+
+ case MIG_STATE_ACTIVE:
+ break;
+
+ default:
s->cleanup (s);
/* Don't resume monitor until we've flushed all of the buffers */
if (s->mon_resume)
monitor_resume(s->mon_resume);
+
+ if (s->save_vm_running && state != MIG_STATE_COMPLETED)
+ vm_start();
+ break;
}
}
diff --git a/migration.h b/migration.h
index 81ac361..c44bd75 100644
--- a/migration.h
+++ b/migration.h
@@ -20,6 +20,7 @@
#define MIG_STATE_COMPLETED 0
#define MIG_STATE_CANCELLED 1
#define MIG_STATE_ACTIVE 2
+#define MIG_STATE_COMPLETING 3
typedef struct MigrationState MigrationState;
@@ -27,6 +28,7 @@ struct MigrationState
{
Monitor *mon_resume;
int state;
+ int save_vm_running;
/* FIXME: add more accessors to print migration info */
void (*cleanup)(MigrationState *s);
--
1.5.5.6
next prev parent reply other threads:[~2009-07-09 11:47 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-09 11:47 [Qemu-devel] [PATCH 0/3] add "core dump"-like capability Paolo Bonzini
2009-07-09 11:47 ` [Qemu-devel] [PATCH 1/3] move state and mon_resume to struct MigrationState Paolo Bonzini
2009-07-09 11:47 ` Paolo Bonzini [this message]
2009-07-09 13:45 ` [Qemu-devel] [PATCH 2/3] move vm stop/start to migrate_set_state Anthony Liguori
2009-07-09 13:48 ` Paolo Bonzini
2009-07-09 13:53 ` Anthony Liguori
2009-07-09 13:58 ` Paolo Bonzini
2009-07-09 14:41 ` Anthony Liguori
2009-07-10 23:14 ` Jamie Lokier
2009-07-11 0:04 ` malc
2009-07-11 0:42 ` Jamie Lokier
2009-07-11 0:55 ` Anthony Liguori
2009-07-11 0:58 ` Anthony Liguori
2009-07-11 1:42 ` Jamie Lokier
2009-07-12 3:31 ` Anthony Liguori
2009-07-12 14:22 ` Avi Kivity
2009-07-12 19:10 ` Anthony Liguori
2009-07-12 19:30 ` Avi Kivity
2009-07-13 5:31 ` Gleb Natapov
2009-07-13 8:05 ` Gleb Natapov
2009-07-13 14:52 ` Anthony Liguori
2009-07-14 8:48 ` Dor Laor
2009-07-14 14:41 ` Paolo Bonzini
2009-07-09 11:47 ` [Qemu-devel] [PATCH 3/3] add live dumping capability Paolo Bonzini
2009-07-09 13:49 ` Anthony Liguori
2009-07-09 14:06 ` Paolo Bonzini
2009-07-09 14:43 ` Anthony Liguori
2009-07-10 8:32 ` Paolo Bonzini
2009-07-10 12:51 ` Anthony Liguori
2009-07-09 13:42 ` [Qemu-devel] [PATCH 0/3] add "core dump"-like capability Anthony Liguori
2009-07-09 13:46 ` Paolo Bonzini
2009-07-09 13:51 ` Anthony Liguori
2009-07-09 14:46 ` Gerd Hoffmann
2009-07-09 16:20 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1247140059-5034-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).