From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQfDM-0001Mn-Ci for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQfDH-0001OC-CX for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:53:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQfDH-0001Nx-5G for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:53:31 -0500 From: "Dr. David Alan Gilbert (git)" Date: Wed, 25 Feb 2015 16:51:54 +0000 Message-Id: <1424883128-9841-32-git-send-email-dgilbert@redhat.com> In-Reply-To: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> Subject: [Qemu-devel] [PATCH v5 31/45] Postcopy end in migration_thread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, yanghy@cn.fujitsu.com, david@gibson.dropbear.id.au From: "Dr. David Alan Gilbert" 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 --- 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