From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH9Yb-0007um-OZ 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 1aH9YY-0004Kd-8d for qemu-devel@nongnu.org; Thu, 07 Jan 2016 07:20:45 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:20970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH9YX-0004If-Eu for qemu-devel@nongnu.org; Thu, 07 Jan 2016 07:20:42 -0500 From: zhanghailiang Date: Thu, 7 Jan 2016 20:19:59 +0800 Message-ID: <1452169208-840-5-git-send-email-zhang.zhanghailiang@huawei.com> 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 Content-Type: text/plain Subject: [Qemu-devel] [RFC 04/13] migration: Create a snapshot thread to realize saving memory snapshot List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, zhanghailiang , hanweidong@huawei.com, quintela@redhat.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, amit.shah@redhat.com If users use migrate file:url command, we consider it as creating live memory snapshot command. Besides, we only support tcg accel for now. Signed-off-by: zhanghailiang --- include/migration/migration.h | 2 ++ migration/fd.c | 4 ++++ migration/migration.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 3f372a5..1316d22 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -171,6 +171,7 @@ struct MigrationState QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests; /* The RAMBlock used in the last src_page_request */ RAMBlock *last_req_rb; + bool in_snapshot; /* for snapshot */ }; void process_incoming_migration(QEMUFile *f); @@ -215,6 +216,7 @@ void add_migration_state_change_notifier(Notifier *notify); void remove_migration_state_change_notifier(Notifier *notify); MigrationState *migrate_init(const MigrationParams *params); bool migration_in_setup(MigrationState *); +bool migration_in_snapshot(MigrationState *); bool migration_has_finished(MigrationState *); bool migration_has_failed(MigrationState *); /* True if outgoing migration has entered postcopy phase */ diff --git a/migration/fd.c b/migration/fd.c index ac38256..6036560 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -69,6 +69,10 @@ void file_start_outgoing_migration(MigrationState *s, const char *filename, error_setg_errno(errp, errno, "Failed to open file: %s", filename); return; } + /* Fix me: just for test + * we shouldn't use this to identify if we are do snapshot. + */ + s->in_snapshot = true; fd_start_outgoing_migration(s, NULL, fd, errp); } diff --git a/migration/migration.c b/migration/migration.c index e54910d..7633043 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -33,6 +33,7 @@ #include "qom/cpu.h" #include "exec/memory.h" #include "exec/address-spaces.h" +#include "hw/boards.h" /* Fix me: Remove this if we support snapshot for KVM */ #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */ @@ -901,6 +902,11 @@ bool migration_in_postcopy(MigrationState *s) return (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE); } +bool migration_in_snapshot(MigrationState *s) +{ + return s->in_snapshot; +} + MigrationState *migrate_init(const MigrationParams *params) { MigrationState *s = migrate_get_current(); @@ -1732,6 +1738,21 @@ static void *migration_thread(void *opaque) return NULL; } +static void *snapshot_thread(void *opaque) +{ + rcu_register_thread(); + /* Fix me: Remove this if we support snapshot for KVM */ + if (strcmp(current_machine->accel, "tcg")) { + error_report("snapshot only support 'tcg' accel for now"); + goto error; + } + + /* TODO: create memory snapshot */ + +error: + rcu_unregister_thread(); + return NULL; +} void migrate_fd_connect(MigrationState *s) { /* This is a best 1st approximation. ns to ms */ @@ -1759,8 +1780,13 @@ void migrate_fd_connect(MigrationState *s) } migrate_compress_threads_create(); - qemu_thread_create(&s->thread, "migration", migration_thread, s, - QEMU_THREAD_JOINABLE); + if (!s->in_snapshot) { + qemu_thread_create(&s->thread, "migration", migration_thread, s, + QEMU_THREAD_JOINABLE); + } else { + qemu_thread_create(&s->thread, "snapshot", snapshot_thread, s, + QEMU_THREAD_JOINABLE); + } s->migration_thread_running = true; } -- 1.8.3.1