[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 31/45] Postcopy end in migration_thread
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v5 31/45] Postcopy end in migration_thread |
Date: |
Wed, 25 Feb 2015 16:51:54 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
The end of migration in postcopy is a bit different since some of
the things normally done at the end of migration have already been
done on the transition to postcopy.
The end of migration code is getting a bit complciated now, so
move out into its own function.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
migration/migration.c | 85 +++++++++++++++++++++++++++++++++++++--------------
trace-events | 6 ++++
2 files changed, 68 insertions(+), 23 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 6bf9c8d..bd066f6 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -894,7 +894,6 @@ static int open_outgoing_return_path(MigrationState *ms)
return 0;
}
-__attribute__ (( unused )) /* Until later in patch series */
static void await_outgoing_return_path_close(MigrationState *ms)
{
/*
@@ -1010,6 +1009,64 @@ fail:
}
/*
+ * Used by migration_thread when there's not much left pending.
+ * The caller 'breaks' the loop when this returns.
+ */
+static void migration_thread_end_of_iteration(MigrationState *s,
+ int current_active_state,
+ bool *old_vm_running,
+ int64_t *start_time)
+{
+ int ret;
+ if (s->state == MIG_STATE_ACTIVE) {
+ qemu_mutex_lock_iothread();
+ *start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+ qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+ *old_vm_running = runstate_is_running();
+
+ ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+ if (ret >= 0) {
+ qemu_file_set_rate_limit(s->file, INT64_MAX);
+ qemu_savevm_state_complete(s->file);
+ }
+ qemu_mutex_unlock_iothread();
+
+ if (ret < 0) {
+ goto fail;
+ }
+ } else if (s->state == MIG_STATE_POSTCOPY_ACTIVE) {
+ trace_migration_thread_end_of_iteration_postcopy_end();
+
+ qemu_savevm_state_postcopy_complete(s->file);
+ trace_migration_thread_end_of_iteration_postcopy_end_after_complete();
+ }
+
+ /*
+ * If rp was opened we must clean up the thread before
+ * cleaning everything else up (since if there are no failures
+ * it will wait for the destination to send it's status in
+ * a SHUT command).
+ * Postcopy opens rp if enabled (even if it's not avtivated)
+ */
+ if (migrate_postcopy_ram()) {
+ trace_migration_thread_end_of_iteration_postcopy_end_before_rp();
+ await_outgoing_return_path_close(s);
+ trace_migration_thread_end_of_iteration_postcopy_end_after_rp();
+ }
+
+ if (qemu_file_get_error(s->file)) {
+ trace_migration_thread_end_of_iteration_file_err();
+ goto fail;
+ }
+
+ migrate_set_state(s, current_active_state, MIG_STATE_COMPLETED);
+ return;
+
+fail:
+ migrate_set_state(s, current_active_state, MIG_STATE_ERROR);
+}
+
+/*
* Master migration thread on the source VM.
* It drives the migration and pumps the data down the outgoing channel.
*/
@@ -1084,29 +1141,11 @@ static void *migration_thread(void *opaque)
/* Just another iteration step */
qemu_savevm_state_iterate(s->file);
} else {
- int ret;
-
- qemu_mutex_lock_iothread();
- start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
- old_vm_running = runstate_is_running();
-
- ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
- if (ret >= 0) {
- qemu_file_set_rate_limit(s->file, INT64_MAX);
- qemu_savevm_state_complete(s->file);
- }
- qemu_mutex_unlock_iothread();
+ trace_migration_thread_low_pending(pending_size);
- if (ret < 0) {
- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
- break;
- }
-
- if (!qemu_file_get_error(s->file)) {
- migrate_set_state(s, MIG_STATE_ACTIVE,
MIG_STATE_COMPLETED);
- break;
- }
+ migration_thread_end_of_iteration(s, current_active_type,
+ &old_vm_running, &start_time);
+ break;
}
}
diff --git a/trace-events b/trace-events
index ed8bbe2..bcbdef8 100644
--- a/trace-events
+++ b/trace-events
@@ -1407,6 +1407,12 @@ migrate_send_rp_message(int cmd, uint16_t len) "cmd=%d,
len=%d"
migration_thread_after_loop(void) ""
migration_thread_file_err(void) ""
migration_thread_setup_complete(void) ""
+migration_thread_low_pending(uint64_t pending) "%" PRIu64
+migration_thread_end_of_iteration_file_err(void) ""
+migration_thread_end_of_iteration_postcopy_end(void) ""
+migration_thread_end_of_iteration_postcopy_end_after_complete(void) ""
+migration_thread_end_of_iteration_postcopy_end_before_rp(void) ""
+migration_thread_end_of_iteration_postcopy_end_after_rp(void) ""
open_outgoing_return_path(void) ""
open_outgoing_return_path_continue(void) ""
postcopy_start(void) ""
--
2.1.0
- [Qemu-devel] [PATCH v5 20/45] Modify savevm handlers for postcopy, (continued)
- [Qemu-devel] [PATCH v5 20/45] Modify savevm handlers for postcopy, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 24/45] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 22/45] postcopy: OS support test, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 23/45] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 25/45] qemu_savevm_state_complete: Postcopy changes, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 26/45] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 29/45] postcopy: ram_enable_notify to switch on userfault, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 28/45] postcopy: Incoming initialisation, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 27/45] Postcopy: Maintain sentmap and calculate discard, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 30/45] Postcopy: Postcopy startup in migration thread, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 31/45] Postcopy end in migration_thread,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v5 32/45] Page request: Add MIG_RP_CMD_REQ_PAGES reverse command, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 33/45] Page request: Process incoming page request, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 34/45] Page request: Consume pages off the post-copy queue, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 35/45] postcopy_ram.c: place_page and helpers, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 36/45] Postcopy: Use helpers to map pages during migration, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 38/45] Don't sync dirty bitmaps in postcopy, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 39/45] Host page!=target page: Cleanup bitmaps, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 37/45] qemu_ram_block_from_host, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 40/45] Postcopy; Handle userfault requests, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 42/45] postcopy: Wire up loadvm_postcopy_handle_{run, end} commands, Dr. David Alan Gilbert (git), 2015/02/25