From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPrPT-0000De-MK for qemu-devel@nongnu.org; Thu, 13 Aug 2015 08:15:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZPrPQ-0007nN-Cu for qemu-devel@nongnu.org; Thu, 13 Aug 2015 08:15:03 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:10373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPrPP-0007dO-K2 for qemu-devel@nongnu.org; Thu, 13 Aug 2015 08:15:00 -0400 References: <1439463094-5394-1-git-send-email-dgilbert@redhat.com> <1439463094-5394-3-git-send-email-dgilbert@redhat.com> From: zhanghailiang Message-ID: <55CC8A19.2070505@huawei.com> Date: Thu, 13 Aug 2015 20:14:17 +0800 MIME-Version: 1.0 In-Reply-To: <1439463094-5394-3-git-send-email-dgilbert@redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/5] Split out end of migration code from migration_thread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" , qemu-devel@nongnu.org Cc: amit.shah@redhat.com, peter.huangpeng@huawei.com, quintela@redhat.com On 2015/8/13 18:51, Dr. David Alan Gilbert (git) wrote: > From: "Dr. David Alan Gilbert" > > The code that gets run at the end of the migration process > is getting large, and I'm about to add more for postcopy. > Split it into a separate function. > > Signed-off-by: Dr. David Alan Gilbert > --- Reviewed-by: zhanghailiang > migration/migration.c | 75 ++++++++++++++++++++++++++++++++------------------- > trace-events | 2 ++ > 2 files changed, 49 insertions(+), 28 deletions(-) > > diff --git a/migration/migration.c b/migration/migration.c > index 662e77e..46bb410 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -913,6 +913,50 @@ int64_t migrate_xbzrle_cache_size(void) > return s->xbzrle_cache_size; > } > > +/** > + * migration_completion: Used by migration_thread when there's not much left. > + * The caller 'breaks' the loop when this returns. > + * > + * @s: Current migration state > + * @*old_vm_running: Pointer to old_vm_running flag > + * @*start_time: Pointer to time to update > + */ > +static void migration_completion(MigrationState *s, bool *old_vm_running, > + int64_t *start_time) > +{ > + 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 = global_state_store(); > + if (!ret) { > + 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; > + } > + > + if (qemu_file_get_error(s->file)) { > + trace_migration_completion_file_err(); > + goto fail; > + } > + > + migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COMPLETED); > + return; > + > +fail: > + migrate_set_state(s, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); > +} > + > /* migration thread support */ > > static void *migration_thread(void *opaque) > @@ -943,34 +987,9 @@ static void *migration_thread(void *opaque) > if (pending_size && pending_size >= max_size) { > 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 = global_state_store(); > - if (!ret) { > - 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) { > - migrate_set_state(s, MIGRATION_STATUS_ACTIVE, > - MIGRATION_STATUS_FAILED); > - break; > - } > - > - if (!qemu_file_get_error(s->file)) { > - migrate_set_state(s, MIGRATION_STATUS_ACTIVE, > - MIGRATION_STATUS_COMPLETED); > - break; > - } > + trace_migration_thread_low_pending(pending_size); > + migration_completion(s, &old_vm_running, &start_time); > + break; > } > } > > diff --git a/trace-events b/trace-events > index 94bf3bb..1509e5b 100644 > --- a/trace-events > +++ b/trace-events > @@ -1406,6 +1406,8 @@ migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, > migrate_state_too_big(void) "" > migrate_global_state_post_load(const char *state) "loaded state: %s" > migrate_global_state_pre_save(const char *state) "saved state: %s" > +migration_completion_file_err(void) "" > +migration_thread_low_pending(uint64_t pending) "%" PRIu64 > > # migration/rdma.c > qemu_rdma_accept_incoming_migration(void) "" >