From patchwork Thu Jan 7 12:20:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 564260 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C02EF1402DE for ; Thu, 7 Jan 2016 23:22:56 +1100 (AEDT) Received: from localhost ([::1]:58131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH9ag-000391-Gf for incoming@patchwork.ozlabs.org; Thu, 07 Jan 2016 07:22:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH9Yb-0007ug-6I for qemu-devel@nongnu.org; Thu, 07 Jan 2016 07:20:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aH9YZ-0004LZ-EQ for qemu-devel@nongnu.org; Thu, 07 Jan 2016 07:20:45 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:36935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH9YY-0004Il-St for qemu-devel@nongnu.org; Thu, 07 Jan 2016 07:20:43 -0500 Received: from 172.24.1.48 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BUD76751; Thu, 07 Jan 2016 20:20:25 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Thu, 7 Jan 2016 20:20:17 +0800 From: zhanghailiang To: Date: Thu, 7 Jan 2016 20:20:00 +0800 Message-ID: <1452169208-840-6-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1452169208-840-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1452169208-840-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.568E580A.003A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 367d5ae3fd33567d44bb71209a469a65 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: aarcange@redhat.com, zhanghailiang , hanweidong@huawei.com, quintela@redhat.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, amit.shah@redhat.com Subject: [Qemu-devel] [RFC 05/13] migration: implement initialization work for snapshot X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We re-use some migration helper fucntions to realize setup work for snapshot, besides, we need to do some initialization work (for example, save VM's device state) with VM pausing. Signed-off-by: zhanghailiang --- migration/migration.c | 36 +++++++++++++++++++++++++++++++++++- migration/ram.c | 8 +++++--- trace-events | 1 + 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 7633043..7413e0d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1740,6 +1740,10 @@ static void *migration_thread(void *opaque) static void *snapshot_thread(void *opaque) { + MigrationState *ms = opaque;; + bool old_vm_running = false; + int ret; + rcu_register_thread(); /* Fix me: Remove this if we support snapshot for KVM */ if (strcmp(current_machine->accel, "tcg")) { @@ -1747,8 +1751,38 @@ static void *snapshot_thread(void *opaque) goto error; } - /* TODO: create memory snapshot */ + qemu_savevm_state_header(ms->file); + qemu_savevm_state_begin(ms->file, &ms->params); + + qemu_mutex_lock_iothread(); + 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_SAVE_VM); + if (ret < 0) { + error_report("Failed to stop VM"); + goto error; + } + } + + /* TODO: other setup work */ + if (old_vm_running) { + vm_start(); + } + qemu_mutex_unlock_iothread(); + + migrate_set_state(ms, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); + + trace_snapshot_thread_setup_complete(); + + /* Save VM's state */ + + qemu_mutex_lock_iothread(); + qemu_savevm_state_cleanup(); + qemu_bh_schedule(ms->cleanup_bh); + qemu_mutex_unlock_iothread(); error: rcu_unregister_thread(); return NULL; diff --git a/migration/ram.c b/migration/ram.c index 0490f00..c87663f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1935,9 +1935,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque) * gaps due to alignment or unplugs. */ migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS; - - memory_global_dirty_log_start(); - migration_bitmap_sync(); + /* For snapshot, we don't need to enable global dirty log */ + if (!migration_in_snapshot(migrate_get_current())) { + memory_global_dirty_log_start(); + migration_bitmap_sync(); + } qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); diff --git a/trace-events b/trace-events index ea5872d..cfebbed 100644 --- a/trace-events +++ b/trace-events @@ -1495,6 +1495,7 @@ migrate_state_too_big(void) "" migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d" process_incoming_migration_co_postcopy_end_main(void) "" +snapshot_thread_setup_complete(void) "" # migration/rdma.c qemu_rdma_accept_incoming_migration(void) ""